-
-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Suggest type next to visibility for const items
#157382
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| //! Regression test for <https://github.com/rust-lang/rust/issues/157368> | ||
| //! Tests suggesting `pub type const` instead of `type pub const`. | ||
| //@ run-rustfix | ||
| #![feature(min_generic_const_args, inherent_associated_types)] | ||
| #![allow(dead_code)] | ||
|
|
||
| mod impl_item { | ||
| pub struct Bar; | ||
| impl Bar { | ||
| pub type const PUBLIC: usize = 1; | ||
| pub(crate) type const RESTRICTED: usize = 1; | ||
| type const PRIVATE: usize = 1; | ||
| } | ||
|
|
||
| pub struct Foo1([u8; Bar::PUBLIC]); | ||
| //~^ ERROR: use of `const` in the type system not defined as `type const` | ||
| pub struct Foo2([u8; Bar::RESTRICTED]); | ||
| //~^ ERROR: use of `const` in the type system not defined as `type const` | ||
| pub struct Foo3([u8; Bar::PRIVATE]); | ||
| //~^ ERROR: use of `const` in the type system not defined as `type const` | ||
| } | ||
|
|
||
| mod top_level_item { | ||
| pub type const PUBLIC: usize = 1; | ||
| pub(crate) type const RESTRICTED: usize = 1; | ||
| type const PRIVATE: usize = 1; | ||
|
|
||
| pub struct Foo1([u8; PUBLIC]); | ||
| //~^ ERROR: use of `const` in the type system not defined as `type const` | ||
| pub struct Foo2([u8; RESTRICTED]); | ||
| //~^ ERROR: use of `const` in the type system not defined as `type const` | ||
| pub struct Foo3([u8; PRIVATE]); | ||
| //~^ ERROR: use of `const` in the type system not defined as `type const` | ||
| } | ||
|
|
||
| mod trait_item { | ||
| pub trait Foo { | ||
| type const PUBLIC: usize; | ||
| //~^ ERROR: [E0449] | ||
| type const RESTRICTED: usize; | ||
| //~^ ERROR: [E0449] | ||
| type const PRIVATE: usize; | ||
| } | ||
|
|
||
| pub struct Bar<T: Foo>([u8; T::PUBLIC]); | ||
| //~^ ERROR: use of `const` in the type system not defined as `type const` | ||
| pub struct Bar2<T: Foo>([u8; T::RESTRICTED]); | ||
| //~^ ERROR: use of `const` in the type system not defined as `type const` | ||
| pub struct Bar3<T: Foo>([u8; T::PRIVATE]); | ||
| //~^ ERROR: use of `const` in the type system not defined as `type const` | ||
| } | ||
|
|
||
| fn main() {} |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| //! Regression test for <https://github.com/rust-lang/rust/issues/157368> | ||
| //! Tests suggesting `pub type const` instead of `type pub const`. | ||
| //@ run-rustfix | ||
| #![feature(min_generic_const_args, inherent_associated_types)] | ||
| #![allow(dead_code)] | ||
|
|
||
| mod impl_item { | ||
| pub struct Bar; | ||
| impl Bar { | ||
| pub const PUBLIC: usize = 1; | ||
| pub(crate) const RESTRICTED: usize = 1; | ||
| const PRIVATE: usize = 1; | ||
| } | ||
|
|
||
| pub struct Foo1([u8; Bar::PUBLIC]); | ||
| //~^ ERROR: use of `const` in the type system not defined as `type const` | ||
| pub struct Foo2([u8; Bar::RESTRICTED]); | ||
| //~^ ERROR: use of `const` in the type system not defined as `type const` | ||
| pub struct Foo3([u8; Bar::PRIVATE]); | ||
| //~^ ERROR: use of `const` in the type system not defined as `type const` | ||
| } | ||
|
|
||
| mod top_level_item { | ||
| pub const PUBLIC: usize = 1; | ||
| pub(crate) const RESTRICTED: usize = 1; | ||
| const PRIVATE: usize = 1; | ||
|
|
||
| pub struct Foo1([u8; PUBLIC]); | ||
| //~^ ERROR: use of `const` in the type system not defined as `type const` | ||
| pub struct Foo2([u8; RESTRICTED]); | ||
| //~^ ERROR: use of `const` in the type system not defined as `type const` | ||
| pub struct Foo3([u8; PRIVATE]); | ||
| //~^ ERROR: use of `const` in the type system not defined as `type const` | ||
| } | ||
|
|
||
| mod trait_item { | ||
| pub trait Foo { | ||
| pub const PUBLIC: usize; | ||
| //~^ ERROR: [E0449] | ||
| pub(crate) const RESTRICTED: usize; | ||
| //~^ ERROR: [E0449] | ||
| const PRIVATE: usize; | ||
| } | ||
|
|
||
| pub struct Bar<T: Foo>([u8; T::PUBLIC]); | ||
| //~^ ERROR: use of `const` in the type system not defined as `type const` | ||
| pub struct Bar2<T: Foo>([u8; T::RESTRICTED]); | ||
| //~^ ERROR: use of `const` in the type system not defined as `type const` | ||
| pub struct Bar3<T: Foo>([u8; T::PRIVATE]); | ||
| //~^ ERROR: use of `const` in the type system not defined as `type const` | ||
| } | ||
|
|
||
| fn main() {} |
118 changes: 118 additions & 0 deletions
118
tests/ui/const-generics/mgca/suggest-pub-type_const.stderr
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| error[E0449]: visibility qualifiers are not permitted here | ||
| --> $DIR/suggest-pub-type_const.rs:38:9 | ||
| | | ||
| LL | pub const PUBLIC: usize; | ||
| | ^^^ help: remove the qualifier | ||
| | | ||
| = note: trait items always share the visibility of their trait | ||
|
|
||
| error[E0449]: visibility qualifiers are not permitted here | ||
| --> $DIR/suggest-pub-type_const.rs:40:9 | ||
| | | ||
| LL | pub(crate) const RESTRICTED: usize; | ||
| | ^^^^^^^^^^ help: remove the qualifier | ||
| | | ||
| = note: trait items always share the visibility of their trait | ||
|
|
||
| error: use of `const` in the type system not defined as `type const` | ||
| --> $DIR/suggest-pub-type_const.rs:15:26 | ||
| | | ||
| LL | pub struct Foo1([u8; Bar::PUBLIC]); | ||
| | ^^^^^^^^^^^ | ||
| | | ||
| help: add `type` before `const` for `impl_item::Bar::PUBLIC` | ||
| | | ||
| LL | pub type const PUBLIC: usize = 1; | ||
| | ++++ | ||
|
|
||
| error: use of `const` in the type system not defined as `type const` | ||
| --> $DIR/suggest-pub-type_const.rs:17:26 | ||
| | | ||
| LL | pub struct Foo2([u8; Bar::RESTRICTED]); | ||
| | ^^^^^^^^^^^^^^^ | ||
| | | ||
| help: add `type` before `const` for `impl_item::Bar::RESTRICTED` | ||
| | | ||
| LL | pub(crate) type const RESTRICTED: usize = 1; | ||
| | ++++ | ||
|
|
||
| error: use of `const` in the type system not defined as `type const` | ||
| --> $DIR/suggest-pub-type_const.rs:19:26 | ||
| | | ||
| LL | pub struct Foo3([u8; Bar::PRIVATE]); | ||
| | ^^^^^^^^^^^^ | ||
| | | ||
| help: add `type` before `const` for `impl_item::Bar::PRIVATE` | ||
| | | ||
| LL | type const PRIVATE: usize = 1; | ||
| | ++++ | ||
|
|
||
| error: use of `const` in the type system not defined as `type const` | ||
| --> $DIR/suggest-pub-type_const.rs:28:26 | ||
| | | ||
| LL | pub struct Foo1([u8; PUBLIC]); | ||
| | ^^^^^^ | ||
| | | ||
| help: add `type` before `const` for `PUBLIC` | ||
| | | ||
| LL | pub type const PUBLIC: usize = 1; | ||
| | ++++ | ||
|
|
||
| error: use of `const` in the type system not defined as `type const` | ||
| --> $DIR/suggest-pub-type_const.rs:30:26 | ||
| | | ||
| LL | pub struct Foo2([u8; RESTRICTED]); | ||
| | ^^^^^^^^^^ | ||
| | | ||
| help: add `type` before `const` for `RESTRICTED` | ||
| | | ||
| LL | pub(crate) type const RESTRICTED: usize = 1; | ||
| | ++++ | ||
|
|
||
| error: use of `const` in the type system not defined as `type const` | ||
| --> $DIR/suggest-pub-type_const.rs:32:26 | ||
| | | ||
| LL | pub struct Foo3([u8; PRIVATE]); | ||
| | ^^^^^^^ | ||
| | | ||
| help: add `type` before `const` for `PRIVATE` | ||
| | | ||
| LL | type const PRIVATE: usize = 1; | ||
| | ++++ | ||
|
|
||
| error: use of `const` in the type system not defined as `type const` | ||
| --> $DIR/suggest-pub-type_const.rs:45:33 | ||
| | | ||
| LL | pub struct Bar<T: Foo>([u8; T::PUBLIC]); | ||
| | ^^^^^^^^^ | ||
| | | ||
| help: add `type` before `const` for `Foo::PUBLIC` | ||
| | | ||
| LL | type pub const PUBLIC: usize; | ||
| | ++++ | ||
|
|
||
| error: use of `const` in the type system not defined as `type const` | ||
| --> $DIR/suggest-pub-type_const.rs:47:34 | ||
| | | ||
| LL | pub struct Bar2<T: Foo>([u8; T::RESTRICTED]); | ||
| | ^^^^^^^^^^^^^ | ||
| | | ||
| help: add `type` before `const` for `Foo::RESTRICTED` | ||
| | | ||
| LL | type pub(crate) const RESTRICTED: usize; | ||
| | ++++ | ||
|
|
||
| error: use of `const` in the type system not defined as `type const` | ||
| --> $DIR/suggest-pub-type_const.rs:49:34 | ||
| | | ||
| LL | pub struct Bar3<T: Foo>([u8; T::PRIVATE]); | ||
| | ^^^^^^^^^^ | ||
| | | ||
| help: add `type` before `const` for `Foo::PRIVATE` | ||
| | | ||
| LL | type const PRIVATE: usize; | ||
| | ++++ | ||
|
|
||
| error: aborting due to 11 previous errors | ||
|
|
||
| For more information about this error, try `rustc --explain E0449`. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.