Make SEMICOLON_IN_EXPRESSIONS_FROM_MACROS warn by default

This commit is contained in:
Aaron Hill 2021-07-22 14:28:02 -05:00
parent 3bc9dd0dd2
commit 886dea2bcd
No known key found for this signature in database
GPG Key ID: B4087E510E98B164
16 changed files with 91 additions and 28 deletions

View File

@ -2799,7 +2799,7 @@ declare_lint! {
/// [issue #79813]: https://github.com/rust-lang/rust/issues/79813
/// [future-incompatible]: ../index.md#future-incompatible-lints
pub SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
Allow,
Warn,
"trailing semicolon in macro body used as expression",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #79813 <https://github.com/rust-lang/rust/issues/79813>",

View File

@ -290,7 +290,7 @@ macro_rules! dbg {
// `$val` expression could be a block (`{ .. }`), in which case the `eprintln!`
// will be malformed.
() => {
$crate::eprintln!("[{}:{}]", $crate::file!(), $crate::line!());
$crate::eprintln!("[{}:{}]", $crate::file!(), $crate::line!())
};
($val:expr $(,)?) => {
// Use of `match` here is intentional because it affects the lifetimes

View File

@ -5,7 +5,7 @@ pub mod foo {
mod bar {
fn f() -> u32 { 1 }
pub macro m() {
f();
f()
}
}
}

View File

@ -3,5 +3,5 @@ macro_rules! foo {
}
pub fn main() {
'x: loop { foo!() }
'x: loop { foo!(); }
}

View File

@ -4,8 +4,8 @@ error[E0426]: use of undeclared label `'x`
LL | () => { break 'x; }
| ^^ undeclared label `'x`
...
LL | 'x: loop { foo!() }
| ------ in this macro invocation
LL | 'x: loop { foo!(); }
| ------- in this macro invocation
|
= note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@ -4,6 +4,6 @@ macro_rules! foo {
pub fn main() {
'x: for _ in 0..1 {
foo!()
foo!();
};
}

View File

@ -4,8 +4,8 @@ error[E0426]: use of undeclared label `'x`
LL | () => { break 'x; }
| ^^ undeclared label `'x`
...
LL | foo!()
| ------ in this macro invocation
LL | foo!();
| ------- in this macro invocation
|
= note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@ -1,15 +0,0 @@
// check-pass
// Ensure that trailing semicolons are allowed by default
macro_rules! foo {
() => {
true;
}
}
fn main() {
let val = match true {
true => false,
_ => foo!()
};
}

View File

@ -0,0 +1,16 @@
// check-pass
// Ensure that trailing semicolons cause warnings by default
macro_rules! foo {
() => {
true; //~ WARN trailing semicolon in macro
//~| WARN this was previously
}
}
fn main() {
let _val = match true {
true => false,
_ => foo!()
};
}

View File

@ -0,0 +1,16 @@
warning: trailing semicolon in macro used in expression position
--> $DIR/warn-semicolon-in-expressions-from-macros.rs:6:13
|
LL | true;
| ^
...
LL | _ => foo!()
| ------ in this macro invocation
|
= note: `#[warn(semicolon_in_expressions_from_macros)]` on by default
= 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 the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
warning: 1 warning emitted

View File

@ -6,6 +6,8 @@ macro_rules! m {
//~| ERROR macro expansion ignores token `;`
//~| ERROR cannot find type `i` in this scope
//~| ERROR cannot find value `i` in this scope
//~| WARN trailing semicolon in macro
//~| WARN this was previously
}
fn main() {

View File

@ -64,7 +64,21 @@ LL | let i = m!();
|
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 6 previous errors
warning: trailing semicolon in macro used in expression position
--> $DIR/macro-context.rs:3:15
|
LL | () => ( i ; typeof );
| ^
...
LL | let i = m!();
| ---- in this macro invocation
|
= note: `#[warn(semicolon_in_expressions_from_macros)]` on by default
= 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 the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 6 previous errors; 1 warning emitted
Some errors have detailed explanations: E0412, E0425.
For more information about an error, try `rustc --explain E0412`.

View File

@ -3,6 +3,10 @@
macro_rules! foo {
() => {
assert_eq!("A", "A");
//~^ WARN trailing semicolon in macro
//~| WARN this was previously
//~| NOTE for more information
//~| NOTE `#[warn(semicolon_in_expressions_from_macros)]` on by default
assert_eq!("B", "B");
}
//~^^ ERROR macro expansion ignores token `assert_eq` and any following
@ -12,4 +16,8 @@ macro_rules! foo {
fn main() {
foo!();
//~^ NOTE caused by the macro expansion here
//~| NOTE in this expansion
//~| NOTE in this expansion
//~| NOTE in this expansion
//~| NOTE in this expansion
}

View File

@ -3,6 +3,10 @@
macro_rules! foo {
() => {
assert_eq!("A", "A");
//~^ WARN trailing semicolon in macro
//~| WARN this was previously
//~| NOTE for more information
//~| NOTE `#[warn(semicolon_in_expressions_from_macros)]` on by default
assert_eq!("B", "B");
}
//~^^ ERROR macro expansion ignores token `assert_eq` and any following
@ -12,4 +16,8 @@ macro_rules! foo {
fn main() {
foo!()
//~^ NOTE caused by the macro expansion here
//~| NOTE in this expansion
//~| NOTE in this expansion
//~| NOTE in this expansion
//~| NOTE in this expansion
}

View File

@ -1,5 +1,5 @@
error: macro expansion ignores token `assert_eq` and any following
--> $DIR/macro-in-expression-context.rs:6:9
--> $DIR/macro-in-expression-context.rs:10:9
|
LL | assert_eq!("B", "B");
| ^^^^^^^^^
@ -11,5 +11,19 @@ LL | foo!()
|
= note: the usage of `foo!` is likely invalid in expression context
error: aborting due to previous error
warning: trailing semicolon in macro used in expression position
--> $DIR/macro-in-expression-context.rs:5:29
|
LL | assert_eq!("A", "A");
| ^
...
LL | foo!()
| ------ in this macro invocation
|
= note: `#[warn(semicolon_in_expressions_from_macros)]` on by default
= 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 the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to previous error; 1 warning emitted

View File

@ -17,7 +17,7 @@ macro_rules! wrap {
(first, $e:expr) => { wrap!(second, $e + 1) };
(second, $e:expr) => { wrap!(third, $e + 2) };
(third, $e:expr) => {
print_bang!($e + 3);
print_bang!($e + 3)
};
}