Skip to content

Commit a9f01a5

Browse files
committed
Add feature gate for rustc_const_stable attribute
rustc_const_stable attributes are used within the core library but were not properly feature gated. The compiler now rejects their usage when the feature has not been explicitly enabled. gcc/rust/ChangeLog: * checks/errors/feature/rust-feature-gate.cc (FeatureGate::visit): Add a feature gate around rustc_const_stable attributes. gcc/testsuite/ChangeLog: * rust/compile/const-issue1440.rs: Enable staged_api feature. * rust/compile/for-loop1.rs: Likewise. * rust/compile/for-loop2.rs: Likewise. * rust/compile/issue-1031.rs: Likewise. * rust/compile/issue-1289.rs: Likewise. * rust/compile/iterators1.rs: Likewise. * rust/compile/rustc_const_stable.rs: Likewise. * rust/compile/torture/issue-1075.rs: Likewise. * rust/compile/torture/issue-1432.rs: Likewise. * rust/execute/torture/const-generics-7.rs: Likewise. * rust/execute/torture/for-loop1.rs: Likewise. * rust/execute/torture/for-loop2.rs: Likewise. * rust/execute/torture/issue-1120.rs: Likewise. * rust/execute/torture/issue-1133.rs: Likewise. * rust/execute/torture/issue-1232.rs: Likewise. * rust/execute/torture/issue-1436.rs: Likewise. * rust/execute/torture/iter1.rs: Likewise. * rust/execute/torture/slice-magic.rs: Likewise. * rust/execute/torture/slice-magic2.rs: Likewise. * rust/execute/torture/str-layout1.rs: Likewise. * rust/compile/missing_staged_api.rs: New test. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
1 parent afb19b7 commit a9f01a5

22 files changed

Lines changed: 42 additions & 47 deletions

gcc/rust/checks/errors/feature/rust-feature-gate.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,16 @@ FeatureGate::visit (AST::Function &function)
234234
if (!function.is_external ())
235235
check_rustc_attri (function.get_outer_attrs ());
236236

237+
for (const AST::Attribute &attr : function.get_outer_attrs ())
238+
{
239+
if (attr.get_path ().as_string () == "rustc_const_stable")
240+
{
241+
gate (Feature::Name::STAGED_API, attr.get_locus (),
242+
"stability attributes may not be used outside of the standard "
243+
"library");
244+
}
245+
}
246+
237247
check_lang_item_attribute (function.get_outer_attrs ());
238248

239249
note_stability_attribute (function.get_outer_attrs ());

gcc/testsuite/rust/compile/const-issue1440.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
// { dg-additional-options "-w" }
22
#![feature(no_core)]
33
#![no_core]
4-
54
#![feature(intrinsics)]
6-
5+
#![feature(staged_api)]
76
#![feature(lang_items)]
87
#[lang = "sized"]
98
pub trait Sized {}

gcc/testsuite/rust/compile/for-loop1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// { dg-output "loop\r*\nloop\r*\n" }
22
#![feature(no_core)]
33
#![no_core]
4-
54
#![feature(intrinsics, lang_items)]
5+
#![feature(staged_api)]
66

77
pub use option::Option::{self, None, Some};
88
pub use result::Result::{self, Err, Ok};

gcc/testsuite/rust/compile/for-loop2.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// { dg-output "1\r*\n2\r*\n" }
22
#![feature(no_core)]
33
#![no_core]
4-
5-
#![feature(intrinsics, lang_items)]
4+
#![feature(intrinsics, lang_items, staged_api)]
65

76
pub use option::Option::{self, None, Some};
87
pub use result::Result::{self, Err, Ok};

gcc/testsuite/rust/compile/issue-1031.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#![feature(no_core)]
22
#![no_core]
3-
4-
#![feature(intrinsics)]
5-
3+
#![feature(intrinsics, staged_api)]
64
#![feature(lang_items)]
75
#[lang = "sized"]
86
pub trait Sized {}

gcc/testsuite/rust/compile/issue-1289.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#![feature(no_core)]
22
#![no_core]
3-
4-
#![feature(intrinsics)]
5-
3+
#![feature(intrinsics, staged_api)]
64
#![feature(lang_items)]
75
#[lang = "sized"]
86
pub trait Sized {}

gcc/testsuite/rust/compile/iterators1.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#![feature(no_core)]
22
#![no_core]
3-
4-
#![feature(intrinsics, lang_items)]
3+
#![feature(intrinsics, lang_items, staged_api)]
54

65
pub use option::Option::{self, None, Some};
76
pub use result::Result::{self, Err, Ok};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![feature(no_core)]
2+
#![feature(intrinsics)]
3+
#![no_core]
4+
5+
pub mod intrinsics {
6+
7+
extern "rust-intrinsic" {
8+
// { dg-error "stability attributes may not be used outside of the standard library" "" { target *-*-* } .+1 }
9+
#[rustc_const_stable(feature = "const_size_of", since = "1.40.0")]
10+
pub fn size_of<T>() -> usize;
11+
}
12+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![feature(no_core)]
22
#![no_core]
3-
43
#![feature(rustc_attrs)]
4+
#![feature(staged_api)]
55

66
#[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")]
77
pub fn foo() {}

gcc/testsuite/rust/compile/torture/issue-1075.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
// { dg-additional-options "-w" }
22
#![feature(no_core)]
33
#![no_core]
4-
54
#![feature(intrinsics)]
6-
5+
#![feature(staged_api)]
76
#![feature(lang_items)]
87
#[lang = "sized"]
98
pub trait Sized {}

0 commit comments

Comments
 (0)