Skip to content

Commit f1fcde4

Browse files
committed
intrinsics: deprecate calling them via the unstable std::intrinsics path
1 parent f4235b8 commit f1fcde4

File tree

7 files changed

+61
-36
lines changed

7 files changed

+61
-36
lines changed

Diff for: library/core/src/intrinsics/mod.rs

+20-4
Original file line numberDiff line numberDiff line change
@@ -1909,7 +1909,11 @@ pub const fn forget<T: ?Sized>(_: T) {
19091909
/// }
19101910
/// ```
19111911
#[stable(feature = "rust1", since = "1.0.0")]
1912-
#[rustc_allowed_through_unstable_modules]
1912+
#[cfg_attr(bootstrap, rustc_allowed_through_unstable_modules)]
1913+
#[cfg_attr(
1914+
not(bootstrap),
1915+
rustc_allowed_through_unstable_modules = "import this function via `std::mem` instead"
1916+
)]
19131917
#[rustc_const_stable(feature = "const_transmute", since = "1.56.0")]
19141918
#[rustc_diagnostic_item = "transmute"]
19151919
#[rustc_nounwind]
@@ -4353,7 +4357,11 @@ pub const fn ptr_metadata<P: ptr::Pointee<Metadata = M> + ?Sized, M>(_ptr: *cons
43534357
/// [`Vec::append`]: ../../std/vec/struct.Vec.html#method.append
43544358
#[doc(alias = "memcpy")]
43554359
#[stable(feature = "rust1", since = "1.0.0")]
4356-
#[rustc_allowed_through_unstable_modules]
4360+
#[cfg_attr(bootstrap, rustc_allowed_through_unstable_modules)]
4361+
#[cfg_attr(
4362+
not(bootstrap),
4363+
rustc_allowed_through_unstable_modules = "import this function via `std::mem` instead"
4364+
)]
43574365
#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.83.0")]
43584366
#[inline(always)]
43594367
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
@@ -4457,7 +4465,11 @@ pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: us
44574465
/// ```
44584466
#[doc(alias = "memmove")]
44594467
#[stable(feature = "rust1", since = "1.0.0")]
4460-
#[rustc_allowed_through_unstable_modules]
4468+
#[cfg_attr(bootstrap, rustc_allowed_through_unstable_modules)]
4469+
#[cfg_attr(
4470+
not(bootstrap),
4471+
rustc_allowed_through_unstable_modules = "import this function via `std::mem` instead"
4472+
)]
44614473
#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.83.0")]
44624474
#[inline(always)]
44634475
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
@@ -4540,7 +4552,11 @@ pub const unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
45404552
/// ```
45414553
#[doc(alias = "memset")]
45424554
#[stable(feature = "rust1", since = "1.0.0")]
4543-
#[rustc_allowed_through_unstable_modules]
4555+
#[cfg_attr(bootstrap, rustc_allowed_through_unstable_modules)]
4556+
#[cfg_attr(
4557+
not(bootstrap),
4558+
rustc_allowed_through_unstable_modules = "import this function via `std::mem` instead"
4559+
)]
45444560
#[rustc_const_stable(feature = "const_ptr_write", since = "1.83.0")]
45454561
#[inline(always)]
45464562
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces

Diff for: src/tools/clippy/tests/ui/std_instead_of_core.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@aux-build:proc_macro_derive.rs
22

33
#![warn(clippy::std_instead_of_core)]
4-
#![allow(unused_imports)]
4+
#![allow(unused_imports, deprecated)]
55

66
extern crate alloc;
77

Diff for: src/tools/clippy/tests/ui/std_instead_of_core.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@aux-build:proc_macro_derive.rs
22

33
#![warn(clippy::std_instead_of_core)]
4-
#![allow(unused_imports)]
4+
#![allow(unused_imports, deprecated)]
55

66
extern crate alloc;
77

Diff for: src/tools/clippy/tests/ui/transmute.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,31 @@ fn my_vec() -> MyVec<i32> {
2424
#[warn(clippy::useless_transmute)]
2525
unsafe fn _generic<'a, T, U: 'a>(t: &'a T) {
2626
// FIXME: should lint
27-
// let _: &'a T = core::intrinsics::transmute(t);
27+
// let _: &'a T = core::mem::transmute(t);
2828

29-
let _: &'a U = core::intrinsics::transmute(t);
29+
let _: &'a U = core::mem::transmute(t);
3030

31-
let _: *const T = core::intrinsics::transmute(t);
31+
let _: *const T = core::mem::transmute(t);
3232
//~^ ERROR: transmute from a reference to a pointer
3333
//~| NOTE: `-D clippy::useless-transmute` implied by `-D warnings`
3434

35-
let _: *mut T = core::intrinsics::transmute(t);
35+
let _: *mut T = core::mem::transmute(t);
3636
//~^ ERROR: transmute from a reference to a pointer
3737

38-
let _: *const U = core::intrinsics::transmute(t);
38+
let _: *const U = core::mem::transmute(t);
3939
//~^ ERROR: transmute from a reference to a pointer
4040
}
4141

4242
#[warn(clippy::useless_transmute)]
4343
fn useless() {
4444
unsafe {
45-
let _: Vec<i32> = core::intrinsics::transmute(my_vec());
45+
let _: Vec<i32> = core::mem::transmute(my_vec());
4646
//~^ ERROR: transmute from a type (`std::vec::Vec<i32>`) to itself
4747

4848
let _: Vec<i32> = core::mem::transmute(my_vec());
4949
//~^ ERROR: transmute from a type (`std::vec::Vec<i32>`) to itself
5050

51-
let _: Vec<i32> = std::intrinsics::transmute(my_vec());
51+
let _: Vec<i32> = std::mem::transmute(my_vec());
5252
//~^ ERROR: transmute from a type (`std::vec::Vec<i32>`) to itself
5353

5454
let _: Vec<i32> = std::mem::transmute(my_vec());
@@ -94,17 +94,17 @@ fn crosspointer() {
9494
let int_mut_ptr: *mut Usize = &mut int as *mut Usize;
9595

9696
unsafe {
97-
let _: Usize = core::intrinsics::transmute(int_const_ptr);
97+
let _: Usize = core::mem::transmute(int_const_ptr);
9898
//~^ ERROR: transmute from a type (`*const Usize`) to the type that it points to (
9999
//~| NOTE: `-D clippy::crosspointer-transmute` implied by `-D warnings`
100100

101-
let _: Usize = core::intrinsics::transmute(int_mut_ptr);
101+
let _: Usize = core::mem::transmute(int_mut_ptr);
102102
//~^ ERROR: transmute from a type (`*mut Usize`) to the type that it points to (`U
103103

104-
let _: *const Usize = core::intrinsics::transmute(my_int());
104+
let _: *const Usize = core::mem::transmute(my_int());
105105
//~^ ERROR: transmute from a type (`Usize`) to a pointer to that type (`*const Usi
106106

107-
let _: *mut Usize = core::intrinsics::transmute(my_int());
107+
let _: *mut Usize = core::mem::transmute(my_int());
108108
//~^ ERROR: transmute from a type (`Usize`) to a pointer to that type (`*mut Usize
109109
}
110110
}

Diff for: src/tools/clippy/tests/ui/transmute.stderr

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
error: transmute from a reference to a pointer
22
--> tests/ui/transmute.rs:31:23
33
|
4-
LL | let _: *const T = core::intrinsics::transmute(t);
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `t as *const T`
4+
LL | let _: *const T = core::mem::transmute(t);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `t as *const T`
66
|
77
= note: `-D clippy::useless-transmute` implied by `-D warnings`
88
= help: to override `-D warnings` add `#[allow(clippy::useless_transmute)]`
99

1010
error: transmute from a reference to a pointer
1111
--> tests/ui/transmute.rs:35:21
1212
|
13-
LL | let _: *mut T = core::intrinsics::transmute(t);
14-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `t as *const T as *mut T`
13+
LL | let _: *mut T = core::mem::transmute(t);
14+
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `t as *const T as *mut T`
1515

1616
error: transmute from a reference to a pointer
1717
--> tests/ui/transmute.rs:38:23
1818
|
19-
LL | let _: *const U = core::intrinsics::transmute(t);
20-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `t as *const T as *const U`
19+
LL | let _: *const U = core::mem::transmute(t);
20+
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `t as *const T as *const U`
2121

2222
error: transmute from a type (`std::vec::Vec<i32>`) to itself
2323
--> tests/ui/transmute.rs:45:27
2424
|
25-
LL | let _: Vec<i32> = core::intrinsics::transmute(my_vec());
26-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25+
LL | let _: Vec<i32> = core::mem::transmute(my_vec());
26+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2727

2828
error: transmute from a type (`std::vec::Vec<i32>`) to itself
2929
--> tests/ui/transmute.rs:48:27
@@ -34,8 +34,8 @@ LL | let _: Vec<i32> = core::mem::transmute(my_vec());
3434
error: transmute from a type (`std::vec::Vec<i32>`) to itself
3535
--> tests/ui/transmute.rs:51:27
3636
|
37-
LL | let _: Vec<i32> = std::intrinsics::transmute(my_vec());
38-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
37+
LL | let _: Vec<i32> = std::mem::transmute(my_vec());
38+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3939

4040
error: transmute from a type (`std::vec::Vec<i32>`) to itself
4141
--> tests/ui/transmute.rs:54:27
@@ -64,29 +64,29 @@ LL | let _: *const usize = std::mem::transmute(1 + 1usize);
6464
error: transmute from a type (`*const Usize`) to the type that it points to (`Usize`)
6565
--> tests/ui/transmute.rs:97:24
6666
|
67-
LL | let _: Usize = core::intrinsics::transmute(int_const_ptr);
68-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
67+
LL | let _: Usize = core::mem::transmute(int_const_ptr);
68+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6969
|
7070
= note: `-D clippy::crosspointer-transmute` implied by `-D warnings`
7171
= help: to override `-D warnings` add `#[allow(clippy::crosspointer_transmute)]`
7272

7373
error: transmute from a type (`*mut Usize`) to the type that it points to (`Usize`)
7474
--> tests/ui/transmute.rs:101:24
7575
|
76-
LL | let _: Usize = core::intrinsics::transmute(int_mut_ptr);
77-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
76+
LL | let _: Usize = core::mem::transmute(int_mut_ptr);
77+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7878

7979
error: transmute from a type (`Usize`) to a pointer to that type (`*const Usize`)
8080
--> tests/ui/transmute.rs:104:31
8181
|
82-
LL | let _: *const Usize = core::intrinsics::transmute(my_int());
83-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
82+
LL | let _: *const Usize = core::mem::transmute(my_int());
83+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8484

8585
error: transmute from a type (`Usize`) to a pointer to that type (`*mut Usize`)
8686
--> tests/ui/transmute.rs:107:29
8787
|
88-
LL | let _: *mut Usize = core::intrinsics::transmute(my_int());
89-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
88+
LL | let _: *mut Usize = core::mem::transmute(my_int());
89+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9090

9191
error: transmute from a `u8` to a `bool`
9292
--> tests/ui/transmute.rs:114:28

Diff for: tests/ui/stability-attribute/accidental-stable-in-unstable.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ use core::unicode::UNICODE_VERSION; //~ ERROR use of unstable library feature `u
88
// Known accidental stabilizations with known users
99
// fully stable @ core::mem::transmute
1010
use core::intrinsics::transmute; // depended upon by rand_core
11+
//~^WARN deprecated

Diff for: tests/ui/stability-attribute/accidental-stable-in-unstable.stderr

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ LL | use core::unicode::UNICODE_VERSION;
77
= help: add `#![feature(unicode_internals)]` to the crate attributes to enable
88
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
99

10-
error: aborting due to 1 previous error
10+
warning: use of deprecated module `std::intrinsics`: import this function via `std::mem` instead
11+
--> $DIR/accidental-stable-in-unstable.rs:10:23
12+
|
13+
LL | use core::intrinsics::transmute; // depended upon by rand_core
14+
| ^^^^^^^^^
15+
|
16+
= note: `#[warn(deprecated)]` on by default
17+
18+
error: aborting due to 1 previous error; 1 warning emitted
1119

1220
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)