Skip to content

Commit cd6ec97

Browse files
committed
Auto merge of rust-lang#116773 - dtolnay:validatestable, r=compiler-errors
Validate `feature` and `since` values inside `#[stable(…)]` Previously the string passed to `#[unstable(feature = "...")]` would be validated as an identifier, but not `#[stable(feature = "...")]`. In the standard library there were `stable` attributes containing the empty string, and kebab-case string, neither of which should be allowed. Pre-existing validation of `unstable`: ```rust // src/lib.rs #![allow(internal_features)] #![feature(staged_api)] #![unstable(feature = "kebab-case", issue = "none")] #[unstable(feature = "kebab-case", issue = "none")] pub struct Struct; ``` ```console error[E0546]: 'feature' is not an identifier --> src/lib.rs:5:1 | 5 | #![unstable(feature = "kebab-case", issue = "none")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ``` For an `unstable` attribute, the need for an identifier is obvious because the downstream code needs to write a `#![feature(...)]` attribute containing that identifier. `#![feature(kebab-case)]` is not valid syntax and `#![feature(kebab_case)]` would not work if that is not the name of the feature. Having a valid identifier even in `stable` is less essential but still useful because it allows for informative diagnostic about the stabilization of a feature. Compare: ```rust // src/lib.rs #![allow(internal_features)] #![feature(staged_api)] #![stable(feature = "kebab-case", since = "1.0.0")] #[stable(feature = "kebab-case", since = "1.0.0")] pub struct Struct; ``` ```rust // src/main.rs #![feature(kebab_case)] use repro::Struct; fn main() {} ``` ```console error[E0635]: unknown feature `kebab_case` --> src/main.rs:3:12 | 3 | #![feature(kebab_case)] | ^^^^^^^^^^ ``` vs the situation if we correctly use `feature = "snake_case"` and `#![feature(snake_case)]`, as enforced by this PR: ```console warning: the feature `snake_case` has been stable since 1.0.0 and no longer requires an attribute to enable --> src/main.rs:3:12 | 3 | #![feature(snake_case)] | ^^^^^^^^^^ | = note: `#[warn(stable_features)]` on by default ```
2 parents 330d7fa + 7ade24e commit cd6ec97

File tree

1 file changed

+2
-2
lines changed
  • tests/ui/missing_const_for_fn/auxiliary

1 file changed

+2
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// This file provides a const function that is unstably const forever.
22

33
#![feature(staged_api)]
4-
#![stable(feature = "1", since = "1.0.0")]
4+
#![stable(feature = "clippytest", since = "1.0.0")]
55

6-
#[stable(feature = "1", since = "1.0.0")]
6+
#[stable(feature = "clippytest", since = "1.0.0")]
77
#[rustc_const_unstable(feature = "foo", issue = "none")]
88
pub const fn unstably_const_fn() {}

0 commit comments

Comments
 (0)