-
-
Notifications
You must be signed in to change notification settings - Fork 15k
Parser: Recover from attributes applied to types and generic args #144195
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
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
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,29 @@ | ||
| //! Regression test for: <https://github.com/rust-lang/rust/issues/144132> | ||
| //! <https://github.com/rust-lang/rust/issues/135017> | ||
|
|
||
| struct Baz<const N: usize>(i32); | ||
|
|
||
| fn main() { | ||
| let _: Baz<#[cfg(any())]> = todo!(); | ||
| //~^ ERROR attributes cannot be applied here | ||
| } | ||
|
|
||
| fn f(_param: #[attr]) {} | ||
| //~^ ERROR attributes cannot be applied to a function parameter's type | ||
| //~| ERROR expected type, found `)` | ||
|
|
||
| fn g() -> #[attr] { 0 } | ||
| //~^ ERROR attributes cannot be applied here | ||
|
|
||
| struct S { | ||
| field: #[attr], | ||
| //~^ ERROR attributes cannot be applied here | ||
| field1: (#[attr], i32), | ||
| //~^ ERROR attributes cannot be applied here | ||
| } | ||
|
|
||
| type Tuple = (#[attr], String); | ||
| //~^ ERROR attributes cannot be applied here | ||
|
|
||
| impl #[attr] {} | ||
| //~^ ERROR attributes cannot be applied here |
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,52 @@ | ||
| error: attributes cannot be applied here | ||
| --> $DIR/attribute-on-empty.rs:7:16 | ||
| | | ||
| LL | let _: Baz<#[cfg(any())]> = todo!(); | ||
| | - ^^^^^^^^^^^^^ attributes are not allowed here | ||
| | | | ||
| | while parsing the type for `_` | ||
|
|
||
| error: attributes cannot be applied to a function parameter's type | ||
| --> $DIR/attribute-on-empty.rs:11:14 | ||
| | | ||
| LL | fn f(_param: #[attr]) {} | ||
| | ^^^^^^^ attributes are not allowed here | ||
|
|
||
| error: expected type, found `)` | ||
| --> $DIR/attribute-on-empty.rs:11:21 | ||
| | | ||
| LL | fn f(_param: #[attr]) {} | ||
| | ^ expected type | ||
|
|
||
| error: attributes cannot be applied here | ||
| --> $DIR/attribute-on-empty.rs:15:11 | ||
| | | ||
| LL | fn g() -> #[attr] { 0 } | ||
| | ^^^^^^^ attributes are not allowed here | ||
|
|
||
| error: attributes cannot be applied here | ||
| --> $DIR/attribute-on-empty.rs:19:12 | ||
| | | ||
| LL | field: #[attr], | ||
| | ^^^^^^^ attributes are not allowed here | ||
|
|
||
| error: attributes cannot be applied here | ||
| --> $DIR/attribute-on-empty.rs:21:14 | ||
| | | ||
| LL | field1: (#[attr], i32), | ||
| | ^^^^^^^ attributes are not allowed here | ||
|
|
||
| error: attributes cannot be applied here | ||
| --> $DIR/attribute-on-empty.rs:25:15 | ||
| | | ||
| LL | type Tuple = (#[attr], String); | ||
| | ^^^^^^^ attributes are not allowed here | ||
|
|
||
| error: attributes cannot be applied here | ||
| --> $DIR/attribute-on-empty.rs:28:6 | ||
| | | ||
| LL | impl #[attr] {} | ||
| | ^^^^^^^ attributes are not allowed here | ||
|
|
||
| error: aborting due to 8 previous errors | ||
|
|
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,58 @@ | ||
| //! Regression test for: <https://github.com/rust-lang/rust/issues/144132> | ||
| //! <https://github.com/rust-lang/rust/issues/135017> | ||
|
|
||
| //@ run-rustfix | ||
|
|
||
| #![allow(dead_code, unused_variables)] | ||
|
|
||
| struct Foo<T>(T); | ||
| struct Bar<'a>(&'a i32); | ||
| struct Baz<const N: usize>(i32); | ||
|
|
||
| fn main() { | ||
| let foo: Foo<i32> = Foo(2i32); | ||
| //~^ ERROR attributes cannot be applied to generic arguments | ||
|
|
||
| let _: &'static str = "123"; | ||
| //~^ ERROR attributes cannot be applied to types | ||
|
|
||
| let _: Bar<'static> = Bar(&123); | ||
| //~^ ERROR attributes cannot be applied to generic arguments | ||
|
|
||
| let _: Baz<42> = Baz(42); | ||
| //~^ ERROR attributes cannot be applied to generic arguments | ||
|
|
||
| let _: Foo<String> = Foo(String::new()); | ||
| //~^ ERROR attributes cannot be applied to generic arguments | ||
|
|
||
| let _: Bar<'static> = Bar(&456); | ||
| //~^ ERROR attributes cannot be applied to generic arguments | ||
|
|
||
| let _generic: Box<i32> = Box::new(1); | ||
| //~^ ERROR attributes cannot be applied to generic arguments | ||
|
|
||
| let _assignment: i32 = *Box::new(1); | ||
| //~^ ERROR attributes cannot be applied to types | ||
|
|
||
| let _complex: Vec<String> = vec![]; | ||
| //~^ ERROR attributes cannot be applied to generic arguments | ||
|
|
||
| let _nested: Box<Vec<u64>> = Box::new(vec![]); | ||
| //~^ ERROR attributes cannot be applied to generic arguments | ||
| } | ||
|
|
||
| fn g() -> i32 { 0 } | ||
| //~^ ERROR attributes cannot be applied to types | ||
|
|
||
| struct S { | ||
| field: i32, | ||
| //~^ ERROR attributes cannot be applied to types | ||
| field1: (i32, i32), | ||
| //~^ ERROR attributes cannot be applied to types | ||
| } | ||
|
|
||
| type Tuple = (i32, String); | ||
| //~^ ERROR attributes cannot be applied to types | ||
|
|
||
| impl S {} | ||
| //~^ ERROR attributes cannot be applied to types |
|
Kivooeo marked this conversation as resolved.
|
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,58 @@ | ||
| //! Regression test for: <https://github.com/rust-lang/rust/issues/144132> | ||
| //! <https://github.com/rust-lang/rust/issues/135017> | ||
|
|
||
| //@ run-rustfix | ||
|
|
||
| #![allow(dead_code, unused_variables)] | ||
|
|
||
| struct Foo<T>(T); | ||
| struct Bar<'a>(&'a i32); | ||
| struct Baz<const N: usize>(i32); | ||
|
|
||
| fn main() { | ||
| let foo: Foo<#[cfg(not(wrong))] i32> = Foo(2i32); | ||
| //~^ ERROR attributes cannot be applied to generic arguments | ||
|
|
||
| let _: #[attr] &'static str = "123"; | ||
| //~^ ERROR attributes cannot be applied to types | ||
|
|
||
| let _: Bar<#[cfg(any())] 'static> = Bar(&123); | ||
| //~^ ERROR attributes cannot be applied to generic arguments | ||
|
|
||
| let _: Baz<#[cfg(any())] 42> = Baz(42); | ||
| //~^ ERROR attributes cannot be applied to generic arguments | ||
|
|
||
| let _: Foo<#[cfg(not(wrong))]String> = Foo(String::new()); | ||
| //~^ ERROR attributes cannot be applied to generic arguments | ||
|
|
||
| let _: Bar<#[cfg(any())] 'static> = Bar(&456); | ||
| //~^ ERROR attributes cannot be applied to generic arguments | ||
|
|
||
| let _generic: Box<#[attr] i32> = Box::new(1); | ||
| //~^ ERROR attributes cannot be applied to generic arguments | ||
|
|
||
| let _assignment: #[attr] i32 = *Box::new(1); | ||
| //~^ ERROR attributes cannot be applied to types | ||
|
|
||
| let _complex: Vec<#[derive(Debug)] String> = vec![]; | ||
| //~^ ERROR attributes cannot be applied to generic arguments | ||
|
|
||
| let _nested: Box<Vec<#[cfg(feature = "test")] u64>> = Box::new(vec![]); | ||
| //~^ ERROR attributes cannot be applied to generic arguments | ||
| } | ||
|
|
||
| fn g() -> #[attr] i32 { 0 } | ||
| //~^ ERROR attributes cannot be applied to types | ||
|
|
||
| struct S { | ||
| field: #[attr] i32, | ||
| //~^ ERROR attributes cannot be applied to types | ||
| field1: (#[attr] i32, i32), | ||
| //~^ ERROR attributes cannot be applied to types | ||
| } | ||
|
|
||
| type Tuple = (#[attr] i32, String); | ||
| //~^ ERROR attributes cannot be applied to types | ||
|
|
||
| impl #[attr] S {} | ||
| //~^ ERROR attributes cannot be applied to types |
Oops, something went wrong.
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.