forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#116773 - dtolnay:validatestable, r=compiler-e…
…rrors 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 ```
- Loading branch information
Showing
23 changed files
with
138 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/tools/clippy/tests/ui/missing_const_for_fn/auxiliary/helper.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
// This file provides a const function that is unstably const forever. | ||
|
||
#![feature(staged_api)] | ||
#![stable(feature = "1", since = "1.0.0")] | ||
#![stable(feature = "clippytest", since = "1.0.0")] | ||
|
||
#[stable(feature = "1", since = "1.0.0")] | ||
#[stable(feature = "clippytest", since = "1.0.0")] | ||
#[rustc_const_unstable(feature = "foo", issue = "none")] | ||
pub const fn unstably_const_fn() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
#![feature(staged_api)] | ||
#![stable(feature = "deprecated-future-staged-api", since = "1.0.0")] | ||
#![stable(feature = "deprecated_future_staged_api", since = "1.0.0")] | ||
|
||
// @has deprecated_future_staged_api/index.html '//*[@class="stab deprecated"]' \ | ||
// 'Deprecation planned' | ||
// @has deprecated_future_staged_api/struct.S1.html '//*[@class="stab deprecated"]' \ | ||
// 'Deprecating in 99.99.99: effectively never' | ||
#[deprecated(since = "99.99.99", note = "effectively never")] | ||
#[stable(feature = "deprecated-future-staged-api", since = "1.0.0")] | ||
#[stable(feature = "deprecated_future_staged_api", since = "1.0.0")] | ||
pub struct S1; | ||
|
||
// @has deprecated_future_staged_api/index.html '//*[@class="stab deprecated"]' \ | ||
// 'Deprecation planned' | ||
// @has deprecated_future_staged_api/struct.S2.html '//*[@class="stab deprecated"]' \ | ||
// 'Deprecating in a future Rust version: literally never' | ||
#[deprecated(since = "TBD", note = "literally never")] | ||
#[stable(feature = "deprecated-future-staged-api", since = "1.0.0")] | ||
#[stable(feature = "deprecated_future_staged_api", since = "1.0.0")] | ||
pub struct S2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
#![stable(feature = "bar", since = "OLD 1.0")] | ||
#![stable(feature = "bar", since = "3.3.3")] | ||
#![crate_name = "foo"] | ||
|
||
#![feature(staged_api)] | ||
|
||
#[stable(feature = "bar", since = "OLD 1.0")] | ||
#[stable(feature = "bar", since = "3.3.3")] | ||
pub trait Bar {} | ||
|
||
#[stable(feature = "baz", since = "OLD 1.0")] | ||
#[stable(feature = "baz", since = "3.3.3")] | ||
pub trait Baz {} | ||
|
||
#[stable(feature = "baz", since = "OLD 1.0")] | ||
#[stable(feature = "baz", since = "3.3.3")] | ||
pub struct Foo; | ||
|
||
// @has foo/trait.Bar.html '//div[@id="implementors-list"]//span[@class="since"]' 'NEW 2.0' | ||
#[stable(feature = "foobar", since = "NEW 2.0")] | ||
// @has foo/trait.Bar.html '//div[@id="implementors-list"]//span[@class="since"]' '4.4.4' | ||
#[stable(feature = "foobar", since = "4.4.4")] | ||
impl Bar for Foo {} | ||
|
||
// @!has foo/trait.Baz.html '//div[@id="implementors-list"]//span[@class="since"]' 'OLD 1.0' | ||
#[stable(feature = "foobaz", since = "OLD 1.0")] | ||
// @!has foo/trait.Baz.html '//div[@id="implementors-list"]//span[@class="since"]' '3.3.3' | ||
#[stable(feature = "foobaz", since = "3.3.3")] | ||
impl Baz for Foo {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
tests/ui/stability-attribute/stability-attribute-issue-43027.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.