Skip to content

Commit c7afa8b

Browse files
committed
add test checking that we don't accidentally expose const-unstable intrinsics
1 parent d7a78db commit c7afa8b

File tree

3 files changed

+278
-0
lines changed

3 files changed

+278
-0
lines changed

Diff for: tests/ui/consts/auxiliary/unstable_intrinsic.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#![feature(staged_api, rustc_attrs, intrinsics)]
2+
#![stable(since="1.0.0", feature = "stable")]
3+
4+
#[stable(since="1.0.0", feature = "stable")]
5+
pub mod old_way {
6+
extern "rust-intrinsic" {
7+
#[unstable(feature = "unstable", issue = "42")]
8+
pub fn size_of_val<T>(x: *const T) -> usize;
9+
10+
#[unstable(feature = "unstable", issue = "42")]
11+
#[rustc_const_unstable(feature = "unstable", issue = "42")]
12+
pub fn min_align_of_val<T>(x: *const T) -> usize;
13+
}
14+
}
15+
16+
#[stable(since="1.0.0", feature = "stable")]
17+
pub mod new_way {
18+
#[unstable(feature = "unstable", issue = "42")]
19+
#[rustc_intrinsic]
20+
pub const unsafe fn size_of_val<T>(x: *const T) -> usize { 42 }
21+
22+
#[unstable(feature = "unstable", issue = "42")]
23+
#[rustc_const_unstable(feature = "unstable", issue = "42")]
24+
#[rustc_intrinsic]
25+
pub const unsafe fn min_align_of_val<T>(x: *const T) -> usize { 42 }
26+
}

Diff for: tests/ui/consts/const-unstable-intrinsic.rs

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//! Ensure that unstable intrinsics can actually not be called,
2+
//! neither within a crate nor cross-crate.
3+
//@ aux-build:unstable_intrinsic.rs
4+
#![feature(staged_api, rustc_attrs, intrinsics)]
5+
#![stable(since="1.0.0", feature = "stable")]
6+
#![feature(local)]
7+
8+
extern crate unstable_intrinsic;
9+
10+
fn main() {
11+
const_main();
12+
}
13+
14+
const fn const_main() {
15+
let x = 42;
16+
unsafe {
17+
unstable_intrinsic::old_way::size_of_val(&x);
18+
//~^ERROR: unstable library feature 'unstable'
19+
//~|ERROR: cannot call non-const fn
20+
unstable_intrinsic::old_way::min_align_of_val(&x);
21+
//~^ERROR: unstable library feature 'unstable'
22+
//~|ERROR: not yet stable as a const fn
23+
//~|ERROR: cannot use `#[feature(unstable)]`
24+
unstable_intrinsic::new_way::size_of_val(&x);
25+
//~^ERROR: unstable library feature 'unstable'
26+
//~|ERROR: not yet stable as a const fn
27+
//~|ERROR: cannot use `#[feature(unstable)]`
28+
unstable_intrinsic::new_way::min_align_of_val(&x);
29+
//~^ERROR: unstable library feature 'unstable'
30+
//~|ERROR: not yet stable as a const fn
31+
//~|ERROR: cannot use `#[feature(unstable)]`
32+
33+
old_way::size_of_val(&x);
34+
//~^ERROR: cannot call non-const fn
35+
old_way::min_align_of_val(&x);
36+
//~^ERROR: cannot use `#[feature(local)]`
37+
new_way::size_of_val(&x);
38+
//~^ERROR: cannot use `#[feature(local)]`
39+
new_way::min_align_of_val(&x);
40+
//~^ERROR: cannot use `#[feature(local)]`
41+
}
42+
}
43+
44+
#[stable(since="1.0.0", feature = "stable")]
45+
pub mod old_way {
46+
extern "rust-intrinsic" {
47+
#[unstable(feature = "local", issue = "42")]
48+
pub fn size_of_val<T>(x: *const T) -> usize;
49+
50+
#[unstable(feature = "local", issue = "42")]
51+
#[rustc_const_unstable(feature = "local", issue = "42")]
52+
pub fn min_align_of_val<T>(x: *const T) -> usize;
53+
}
54+
}
55+
56+
#[stable(since="1.0.0", feature = "stable")]
57+
pub mod new_way {
58+
#[unstable(feature = "local", issue = "42")]
59+
#[rustc_intrinsic]
60+
pub const unsafe fn size_of_val<T>(x: *const T) -> usize { 42 }
61+
62+
#[unstable(feature = "local", issue = "42")]
63+
#[rustc_const_unstable(feature = "local", issue = "42")]
64+
#[rustc_intrinsic]
65+
pub const unsafe fn min_align_of_val<T>(x: *const T) -> usize { 42 }
66+
}

Diff for: tests/ui/consts/const-unstable-intrinsic.stderr

+186
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
error[E0658]: use of unstable library feature 'unstable'
2+
--> $DIR/const-unstable-intrinsic.rs:17:9
3+
|
4+
LL | unstable_intrinsic::old_way::size_of_val(&x);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #42 <https://github.com/rust-lang/rust/issues/42> for more information
8+
= help: add `#![feature(unstable)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
11+
error[E0658]: use of unstable library feature 'unstable'
12+
--> $DIR/const-unstable-intrinsic.rs:20:9
13+
|
14+
LL | unstable_intrinsic::old_way::min_align_of_val(&x);
15+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16+
|
17+
= note: see issue #42 <https://github.com/rust-lang/rust/issues/42> for more information
18+
= help: add `#![feature(unstable)]` to the crate attributes to enable
19+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
20+
21+
error[E0658]: use of unstable library feature 'unstable'
22+
--> $DIR/const-unstable-intrinsic.rs:24:9
23+
|
24+
LL | unstable_intrinsic::new_way::size_of_val(&x);
25+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26+
|
27+
= note: see issue #42 <https://github.com/rust-lang/rust/issues/42> for more information
28+
= help: add `#![feature(unstable)]` to the crate attributes to enable
29+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
30+
31+
error[E0658]: use of unstable library feature 'unstable'
32+
--> $DIR/const-unstable-intrinsic.rs:28:9
33+
|
34+
LL | unstable_intrinsic::new_way::min_align_of_val(&x);
35+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
36+
|
37+
= note: see issue #42 <https://github.com/rust-lang/rust/issues/42> for more information
38+
= help: add `#![feature(unstable)]` to the crate attributes to enable
39+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
40+
41+
error[E0015]: cannot call non-const fn `unstable_intrinsic::old_way::size_of_val::<i32>` in constant functions
42+
--> $DIR/const-unstable-intrinsic.rs:17:9
43+
|
44+
LL | unstable_intrinsic::old_way::size_of_val(&x);
45+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
46+
|
47+
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
48+
49+
error: const function that might be (indirectly) exposed to stable cannot use `#[feature(unstable)]`
50+
--> $DIR/const-unstable-intrinsic.rs:20:9
51+
|
52+
LL | unstable_intrinsic::old_way::min_align_of_val(&x);
53+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
54+
|
55+
help: if the function is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this what you probably want to do)
56+
|
57+
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
58+
LL | const fn const_main() {
59+
|
60+
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
61+
|
62+
LL + #[rustc_allow_const_fn_unstable(unstable)]
63+
LL | const fn const_main() {
64+
|
65+
66+
error: `unstable_intrinsic::old_way::min_align_of_val` is not yet stable as a const fn
67+
--> $DIR/const-unstable-intrinsic.rs:20:9
68+
|
69+
LL | unstable_intrinsic::old_way::min_align_of_val(&x);
70+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
71+
|
72+
= help: add `#![feature(unstable)]` to the crate attributes to enable
73+
74+
error: const function that might be (indirectly) exposed to stable cannot use `#[feature(unstable)]`
75+
--> $DIR/const-unstable-intrinsic.rs:24:9
76+
|
77+
LL | unstable_intrinsic::new_way::size_of_val(&x);
78+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
79+
|
80+
help: if the function is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this what you probably want to do)
81+
|
82+
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
83+
LL | const fn const_main() {
84+
|
85+
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
86+
|
87+
LL + #[rustc_allow_const_fn_unstable(unstable)]
88+
LL | const fn const_main() {
89+
|
90+
91+
error: `unstable_intrinsic::new_way::size_of_val` is not yet stable as a const fn
92+
--> $DIR/const-unstable-intrinsic.rs:24:9
93+
|
94+
LL | unstable_intrinsic::new_way::size_of_val(&x);
95+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
96+
|
97+
= help: add `#![feature(unstable)]` to the crate attributes to enable
98+
99+
error: const function that might be (indirectly) exposed to stable cannot use `#[feature(unstable)]`
100+
--> $DIR/const-unstable-intrinsic.rs:28:9
101+
|
102+
LL | unstable_intrinsic::new_way::min_align_of_val(&x);
103+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
104+
|
105+
help: if the function is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this what you probably want to do)
106+
|
107+
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
108+
LL | const fn const_main() {
109+
|
110+
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
111+
|
112+
LL + #[rustc_allow_const_fn_unstable(unstable)]
113+
LL | const fn const_main() {
114+
|
115+
116+
error: `unstable_intrinsic::new_way::min_align_of_val` is not yet stable as a const fn
117+
--> $DIR/const-unstable-intrinsic.rs:28:9
118+
|
119+
LL | unstable_intrinsic::new_way::min_align_of_val(&x);
120+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
121+
|
122+
= help: add `#![feature(unstable)]` to the crate attributes to enable
123+
124+
error[E0015]: cannot call non-const fn `old_way::size_of_val::<i32>` in constant functions
125+
--> $DIR/const-unstable-intrinsic.rs:33:9
126+
|
127+
LL | old_way::size_of_val(&x);
128+
| ^^^^^^^^^^^^^^^^^^^^^^^^
129+
|
130+
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
131+
132+
error: const function that might be (indirectly) exposed to stable cannot use `#[feature(local)]`
133+
--> $DIR/const-unstable-intrinsic.rs:35:9
134+
|
135+
LL | old_way::min_align_of_val(&x);
136+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
137+
|
138+
help: if the function is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this what you probably want to do)
139+
|
140+
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
141+
LL | const fn const_main() {
142+
|
143+
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
144+
|
145+
LL + #[rustc_allow_const_fn_unstable(local)]
146+
LL | const fn const_main() {
147+
|
148+
149+
error: const function that might be (indirectly) exposed to stable cannot use `#[feature(local)]`
150+
--> $DIR/const-unstable-intrinsic.rs:37:9
151+
|
152+
LL | new_way::size_of_val(&x);
153+
| ^^^^^^^^^^^^^^^^^^^^^^^^
154+
|
155+
help: if the function is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this what you probably want to do)
156+
|
157+
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
158+
LL | const fn const_main() {
159+
|
160+
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
161+
|
162+
LL + #[rustc_allow_const_fn_unstable(local)]
163+
LL | const fn const_main() {
164+
|
165+
166+
error: const function that might be (indirectly) exposed to stable cannot use `#[feature(local)]`
167+
--> $DIR/const-unstable-intrinsic.rs:39:9
168+
|
169+
LL | new_way::min_align_of_val(&x);
170+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
171+
|
172+
help: if the function is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this what you probably want to do)
173+
|
174+
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
175+
LL | const fn const_main() {
176+
|
177+
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
178+
|
179+
LL + #[rustc_allow_const_fn_unstable(local)]
180+
LL | const fn const_main() {
181+
|
182+
183+
error: aborting due to 15 previous errors
184+
185+
Some errors have detailed explanations: E0015, E0658.
186+
For more information about an error, try `rustc --explain E0015`.

0 commit comments

Comments
 (0)