-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #79819 - Aaron1011:feature/macro-trailing-semicolon, …
…r=petrochenkov Add `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` lint cc #79813 This PR adds an allow-by-default future-compatibility lint `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS`. It fires when a trailing semicolon in a macro body is ignored due to the macro being used in expression position: ```rust macro_rules! foo { () => { true; // WARN } } fn main() { let val = match true { true => false, _ => foo!() }; } ``` The lint takes its level from the macro call site, and can be allowed for a particular macro by adding `#[allow(macro_trailing_semicolon)]`. The lint is set to warn for all internal rustc crates (when being built by a stage1 compiler). After the next beta bump, we can enable the lint for the bootstrap compiler as well.
- Loading branch information
Showing
10 changed files
with
150 additions
and
1 deletion.
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
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
15 changes: 15 additions & 0 deletions
15
...i/lint/semicolon-in-expressions-from-macros/allow-semicolon-in-expressions-from-macros.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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// check-pass | ||
// Ensure that trailing semicolons are allowed by default | ||
|
||
macro_rules! foo { | ||
() => { | ||
true; | ||
} | ||
} | ||
|
||
fn main() { | ||
let val = match true { | ||
true => false, | ||
_ => foo!() | ||
}; | ||
} |
30 changes: 30 additions & 0 deletions
30
...test/ui/lint/semicolon-in-expressions-from-macros/semicolon-in-expressions-from-macros.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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// check-pass | ||
#![warn(semicolon_in_expressions_from_macros)] | ||
|
||
#[allow(dead_code)] | ||
macro_rules! foo { | ||
($val:ident) => { | ||
true; //~ WARN trailing | ||
//~| WARN this was previously | ||
//~| WARN trailing | ||
//~| WARN this was previously | ||
} | ||
} | ||
|
||
fn main() { | ||
// This `allow` doesn't work | ||
#[allow(semicolon_in_expressions_from_macros)] | ||
let _ = { | ||
foo!(first) | ||
}; | ||
|
||
// This 'allow' doesn't work either | ||
#[allow(semicolon_in_expressions_from_macros)] | ||
let _ = foo!(second); | ||
|
||
// But this 'allow' does | ||
#[allow(semicolon_in_expressions_from_macros)] | ||
fn inner() { | ||
let _ = foo!(third); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
.../ui/lint/semicolon-in-expressions-from-macros/semicolon-in-expressions-from-macros.stderr
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
warning: trailing semicolon in macro used in expression position | ||
--> $DIR/semicolon-in-expressions-from-macros.rs:7:13 | ||
| | ||
LL | true; | ||
| ^ | ||
... | ||
LL | foo!(first) | ||
| ----------- in this macro invocation | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/semicolon-in-expressions-from-macros.rs:2:9 | ||
| | ||
LL | #![warn(semicolon_in_expressions_from_macros)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #79813 <https://github.com/rust-lang/rust/issues/79813> | ||
= note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
warning: trailing semicolon in macro used in expression position | ||
--> $DIR/semicolon-in-expressions-from-macros.rs:7:13 | ||
| | ||
LL | true; | ||
| ^ | ||
... | ||
LL | let _ = foo!(second); | ||
| ------------ in this macro invocation | ||
| | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #79813 <https://github.com/rust-lang/rust/issues/79813> | ||
= note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
warning: 2 warnings emitted | ||
|