-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Emit pre-expansion feature gate warnings for negative impls and specialization #154527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,5 @@ | ||
| // Test that default and negative trait implementations are gated by | ||
| // `auto_traits` feature gate | ||
| auto trait DummyAutoTrait {} //~ ERROR auto traits are experimental and possibly buggy | ||
|
|
||
| struct DummyStruct; | ||
|
|
||
| auto trait AutoDummyTrait {} | ||
| //~^ ERROR auto traits are experimental and possibly buggy | ||
|
|
||
| impl !AutoDummyTrait for DummyStruct {} | ||
| //~^ ERROR negative trait bounds are not fully implemented; use marker types for now | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A gate test for negative impls doesn't belong in a gate test file for auto traits. Likely a remnant of the time when negative impls and auto traits were part of the same feature, |
||
| pub unsafe auto trait AnotherAutoTrait {} //~ ERROR auto traits are experimental and possibly buggy | ||
|
|
||
| fn main() {} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,21 @@ | ||
| error[E0658]: auto traits are experimental and possibly buggy | ||
| --> $DIR/feature-gate-auto-traits.rs:6:1 | ||
| --> $DIR/feature-gate-auto-traits.rs:1:1 | ||
| | | ||
| LL | auto trait AutoDummyTrait {} | ||
| LL | auto trait DummyAutoTrait {} | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = note: see issue #13231 <https://github.com/rust-lang/rust/issues/13231> for more information | ||
| = help: add `#![feature(auto_traits)]` to the crate attributes to enable | ||
| = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
|
||
| error[E0658]: negative trait bounds are not fully implemented; use marker types for now | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the marker types suggestion no longer true? That seems like useful information. |
||
| --> $DIR/feature-gate-auto-traits.rs:9:6 | ||
| error[E0658]: auto traits are experimental and possibly buggy | ||
| --> $DIR/feature-gate-auto-traits.rs:3:1 | ||
| | | ||
| LL | impl !AutoDummyTrait for DummyStruct {} | ||
| | ^^^^^^^^^^^^^^^ | ||
| LL | pub unsafe auto trait AnotherAutoTrait {} | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = note: see issue #68318 <https://github.com/rust-lang/rust/issues/68318> for more information | ||
| = help: add `#![feature(negative_impls)]` to the crate attributes to enable | ||
| = note: see issue #13231 <https://github.com/rust-lang/rust/issues/13231> for more information | ||
| = help: add `#![feature(auto_traits)]` to the crate attributes to enable | ||
| = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
|
||
| error: aborting due to 2 previous errors | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // For historical reasons, negative impls don't have a proper pre-expansion feature gate. | ||
| // We're now at least issuing a *warning* for those that only exist before macro expansion. | ||
| // FIXME(#154045): Turn their post-expansion feature gate into a proper pre-expansion one. | ||
| // As part of this, move these test cases into `feature-gate-negative_impls.rs`. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment confused me. Isn't this PR all about adding a proper pre-expansion feature gate? I guess it's not "proper" yet? I don't understand the difference.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not "proper" yet as it's merely a warning for now (as backed by the MCP). Upgrading it to a hard error is the next step at some point in the future that's gonna be much harder to do (crater, fixing fallout downstream, T-lang nomination).
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you change "proper pre-expansion one" to "a pre-expansion hard error", or similar? |
||
| //@ check-pass | ||
|
|
||
| #[cfg(false)] | ||
| impl !Trait for () {} | ||
| //~^ WARN negative impls are experimental | ||
| //~| WARN unstable syntax can change at any point in the future | ||
|
|
||
| fn main() {} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| warning: negative impls are experimental | ||
| --> $DIR/soft-feature-gate-negative_impls.rs:8:6 | ||
| | | ||
| LL | impl !Trait for () {} | ||
| | ^ | ||
| | | ||
| = note: see issue #68318 <https://github.com/rust-lang/rust/issues/68318> for more information | ||
| = help: add `#![feature(negative_impls)]` to the crate attributes to enable | ||
| = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
| = warning: unstable syntax can change at any point in the future, causing a hard error! | ||
| = note: for more information, see issue #65860 <https://github.com/rust-lang/rust/issues/65860> | ||
|
|
||
| warning: 1 warning emitted | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| //@ check-pass | ||
| #![feature(specialization)] | ||
|
|
||
| fn main() {} | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // The gate for `default impl` is exercised in `defaultimpl/specialization-feature-gate-default.rs`. | ||
|
|
||
| trait Trait { | ||
| type Ty; | ||
| const CT: (); | ||
| fn fn_(&self); | ||
| } | ||
|
|
||
| impl<T> Trait for T { | ||
| default type Ty = (); //~ ERROR specialization is experimental | ||
| default const CT: () = (); //~ ERROR specialization is experimental | ||
| default fn fn_(&self) {} //~ ERROR specialization is experimental | ||
| } | ||
|
|
||
| fn main() {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| error[E0658]: specialization is experimental | ||
| --> $DIR/feature-gate-specialization.rs:10:5 | ||
| | | ||
| LL | default type Ty = (); | ||
| | ^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information | ||
| = help: add `#![feature(specialization)]` to the crate attributes to enable | ||
| = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
|
||
| error[E0658]: specialization is experimental | ||
| --> $DIR/feature-gate-specialization.rs:11:5 | ||
| | | ||
| LL | default const CT: () = (); | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information | ||
| = help: add `#![feature(specialization)]` to the crate attributes to enable | ||
| = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
|
||
| error[E0658]: specialization is experimental | ||
| --> $DIR/feature-gate-specialization.rs:12:5 | ||
| | | ||
| LL | default fn fn_(&self) {} | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information | ||
| = help: add `#![feature(specialization)]` to the crate attributes to enable | ||
| = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
|
||
| error: aborting due to 3 previous errors | ||
|
|
||
| For more information about this error, try `rustc --explain E0658`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| warning: specialization is experimental | ||
| --> $DIR/soft-feature-gate-specialization.rs:21:5 | ||
| | | ||
| LL | default type Ty = (); | ||
| | ^^^^^^^ | ||
| | | ||
| = note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information | ||
| = help: add `#![feature(specialization)]` to the crate attributes to enable | ||
| = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
| = warning: unstable syntax can change at any point in the future, causing a hard error! | ||
| = note: for more information, see issue #65860 <https://github.com/rust-lang/rust/issues/65860> | ||
|
|
||
| warning: specialization is experimental | ||
| --> $DIR/soft-feature-gate-specialization.rs:24:5 | ||
| | | ||
| LL | default const CT: () = (); | ||
| | ^^^^^^^ | ||
| | | ||
| = note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information | ||
| = help: add `#![feature(specialization)]` to the crate attributes to enable | ||
| = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
| = warning: unstable syntax can change at any point in the future, causing a hard error! | ||
| = note: for more information, see issue #65860 <https://github.com/rust-lang/rust/issues/65860> | ||
|
|
||
| warning: specialization is experimental | ||
| --> $DIR/soft-feature-gate-specialization.rs:40:1 | ||
| | | ||
| LL | default impl Trait for () {} | ||
| | ^^^^^^^ | ||
| | | ||
| = note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information | ||
| = help: add `#![feature(specialization)]` to the crate attributes to enable | ||
| = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
| = warning: unstable syntax can change at any point in the future, causing a hard error! | ||
| = note: for more information, see issue #65860 <https://github.com/rust-lang/rust/issues/65860> | ||
|
|
||
| warning: specialization is experimental | ||
| --> $DIR/soft-feature-gate-specialization.rs:27:5 | ||
| | | ||
| LL | default fn fn_(); | ||
| | ^^^^^^^ | ||
| | | ||
| = note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information | ||
| = help: add `#![feature(specialization)]` to the crate attributes to enable | ||
| = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
| = warning: unstable syntax can change at any point in the future, causing a hard error! | ||
| = note: for more information, see issue #65860 <https://github.com/rust-lang/rust/issues/65860> | ||
|
|
||
| warning: specialization is experimental | ||
| --> $DIR/soft-feature-gate-specialization.rs:35:1 | ||
| | | ||
| LL | default fn fn_() {} | ||
| | ^^^^^^^ | ||
| | | ||
| = note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information | ||
| = help: add `#![feature(specialization)]` to the crate attributes to enable | ||
| = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
| = warning: unstable syntax can change at any point in the future, causing a hard error! | ||
| = note: for more information, see issue #65860 <https://github.com/rust-lang/rust/issues/65860> | ||
|
|
||
| warning: 5 warnings emitted | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| warning: specialization is experimental | ||
| --> $DIR/soft-feature-gate-specialization.rs:21:5 | ||
| | | ||
| LL | default type Ty = (); | ||
| | ^^^^^^^ | ||
| | | ||
| = note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information | ||
| = help: add `#![feature(specialization)]` to the crate attributes to enable | ||
| = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
| = warning: unstable syntax can change at any point in the future, causing a hard error! | ||
| = note: for more information, see issue #65860 <https://github.com/rust-lang/rust/issues/65860> | ||
|
|
||
| warning: specialization is experimental | ||
| --> $DIR/soft-feature-gate-specialization.rs:24:5 | ||
| | | ||
| LL | default const CT: () = (); | ||
| | ^^^^^^^ | ||
| | | ||
| = note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information | ||
| = help: add `#![feature(specialization)]` to the crate attributes to enable | ||
| = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
| = warning: unstable syntax can change at any point in the future, causing a hard error! | ||
| = note: for more information, see issue #65860 <https://github.com/rust-lang/rust/issues/65860> | ||
|
|
||
| warning: specialization is experimental | ||
| --> $DIR/soft-feature-gate-specialization.rs:40:1 | ||
| | | ||
| LL | default impl Trait for () {} | ||
| | ^^^^^^^ | ||
| | | ||
| = note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information | ||
| = help: add `#![feature(specialization)]` to the crate attributes to enable | ||
| = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
| = warning: unstable syntax can change at any point in the future, causing a hard error! | ||
| = note: for more information, see issue #65860 <https://github.com/rust-lang/rust/issues/65860> | ||
|
|
||
| warning: 3 warnings emitted | ||
|
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is: Enabling feat
specializationshould implymin_specialization(the latter only supports the specialization of associated functions, not associated constants & types however). That's how the post-expansion feature gate already works (it visits the AST).For the soft pre-expansion feature gate we basically want the same thing. However, I don't want to pass a param to the item parser that tells it if the item is meant to be free, associated or foreign. Instead, all 3 fn item kinds are now part of
min_specializationfrom a pre-expansion perspective if they're markeddefaultwhich is absolutely fine (defaulton free & foreign items gets rejected later on during AST validation).We ungate
specializationhere since later inrustc_ast_passes::feature_gate, a span gated behindspecializationrequiresfeature(specialization)… which is undesirable for assoc fns ofc. Finally, in AST passes we allowfeature(specialization)to unlock spans gated behindspecializationand ones behindmin_specialization. This leads to the desired semantics.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like some/all of this information should be a comment in the code?