Skip to content

Commit 886dea2

Browse files
committed
Make SEMICOLON_IN_EXPRESSIONS_FROM_MACROS warn by default
1 parent 3bc9dd0 commit 886dea2

16 files changed

+91
-28
lines changed

compiler/rustc_lint_defs/src/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2799,7 +2799,7 @@ declare_lint! {
27992799
/// [issue #79813]: https://github.com/rust-lang/rust/issues/79813
28002800
/// [future-incompatible]: ../index.md#future-incompatible-lints
28012801
pub SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
2802-
Allow,
2802+
Warn,
28032803
"trailing semicolon in macro body used as expression",
28042804
@future_incompatible = FutureIncompatibleInfo {
28052805
reference: "issue #79813 <https://github.com/rust-lang/rust/issues/79813>",

library/std/src/macros.rs

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

src/test/ui/hygiene/auxiliary/intercrate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub mod foo {
55
mod bar {
66
fn f() -> u32 { 1 }
77
pub macro m() {
8-
f();
8+
f()
99
}
1010
}
1111
}

src/test/ui/hygiene/hygienic-label-1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ macro_rules! foo {
33
}
44

55
pub fn main() {
6-
'x: loop { foo!() }
6+
'x: loop { foo!(); }
77
}

src/test/ui/hygiene/hygienic-label-1.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error[E0426]: use of undeclared label `'x`
44
LL | () => { break 'x; }
55
| ^^ undeclared label `'x`
66
...
7-
LL | 'x: loop { foo!() }
8-
| ------ in this macro invocation
7+
LL | 'x: loop { foo!(); }
8+
| ------- in this macro invocation
99
|
1010
= note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
1111

src/test/ui/hygiene/hygienic-label-3.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ macro_rules! foo {
44

55
pub fn main() {
66
'x: for _ in 0..1 {
7-
foo!()
7+
foo!();
88
};
99
}

src/test/ui/hygiene/hygienic-label-3.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error[E0426]: use of undeclared label `'x`
44
LL | () => { break 'x; }
55
| ^^ undeclared label `'x`
66
...
7-
LL | foo!()
8-
| ------ in this macro invocation
7+
LL | foo!();
8+
| ------- in this macro invocation
99
|
1010
= note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
1111

src/test/ui/lint/semicolon-in-expressions-from-macros/allow-semicolon-in-expressions-from-macros.rs

-15
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// check-pass
2+
// Ensure that trailing semicolons cause warnings by default
3+
4+
macro_rules! foo {
5+
() => {
6+
true; //~ WARN trailing semicolon in macro
7+
//~| WARN this was previously
8+
}
9+
}
10+
11+
fn main() {
12+
let _val = match true {
13+
true => false,
14+
_ => foo!()
15+
};
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
warning: trailing semicolon in macro used in expression position
2+
--> $DIR/warn-semicolon-in-expressions-from-macros.rs:6:13
3+
|
4+
LL | true;
5+
| ^
6+
...
7+
LL | _ => foo!()
8+
| ------ in this macro invocation
9+
|
10+
= note: `#[warn(semicolon_in_expressions_from_macros)]` on by default
11+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
12+
= note: for more information, see issue #79813 <https://github.com/rust-lang/rust/issues/79813>
13+
= note: this warning originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
14+
15+
warning: 1 warning emitted
16+

src/test/ui/macros/macro-context.rs

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ macro_rules! m {
66
//~| ERROR macro expansion ignores token `;`
77
//~| ERROR cannot find type `i` in this scope
88
//~| ERROR cannot find value `i` in this scope
9+
//~| WARN trailing semicolon in macro
10+
//~| WARN this was previously
911
}
1012

1113
fn main() {

src/test/ui/macros/macro-context.stderr

+15-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,21 @@ LL | let i = m!();
6464
|
6565
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
6666

67-
error: aborting due to 6 previous errors
67+
warning: trailing semicolon in macro used in expression position
68+
--> $DIR/macro-context.rs:3:15
69+
|
70+
LL | () => ( i ; typeof );
71+
| ^
72+
...
73+
LL | let i = m!();
74+
| ---- in this macro invocation
75+
|
76+
= note: `#[warn(semicolon_in_expressions_from_macros)]` on by default
77+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
78+
= note: for more information, see issue #79813 <https://github.com/rust-lang/rust/issues/79813>
79+
= note: this warning originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
80+
81+
error: aborting due to 6 previous errors; 1 warning emitted
6882

6983
Some errors have detailed explanations: E0412, E0425.
7084
For more information about an error, try `rustc --explain E0412`.

src/test/ui/macros/macro-in-expression-context.fixed

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
macro_rules! foo {
44
() => {
55
assert_eq!("A", "A");
6+
//~^ WARN trailing semicolon in macro
7+
//~| WARN this was previously
8+
//~| NOTE for more information
9+
//~| NOTE `#[warn(semicolon_in_expressions_from_macros)]` on by default
610
assert_eq!("B", "B");
711
}
812
//~^^ ERROR macro expansion ignores token `assert_eq` and any following
@@ -12,4 +16,8 @@ macro_rules! foo {
1216
fn main() {
1317
foo!();
1418
//~^ NOTE caused by the macro expansion here
19+
//~| NOTE in this expansion
20+
//~| NOTE in this expansion
21+
//~| NOTE in this expansion
22+
//~| NOTE in this expansion
1523
}

src/test/ui/macros/macro-in-expression-context.rs

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
macro_rules! foo {
44
() => {
55
assert_eq!("A", "A");
6+
//~^ WARN trailing semicolon in macro
7+
//~| WARN this was previously
8+
//~| NOTE for more information
9+
//~| NOTE `#[warn(semicolon_in_expressions_from_macros)]` on by default
610
assert_eq!("B", "B");
711
}
812
//~^^ ERROR macro expansion ignores token `assert_eq` and any following
@@ -12,4 +16,8 @@ macro_rules! foo {
1216
fn main() {
1317
foo!()
1418
//~^ NOTE caused by the macro expansion here
19+
//~| NOTE in this expansion
20+
//~| NOTE in this expansion
21+
//~| NOTE in this expansion
22+
//~| NOTE in this expansion
1523
}

src/test/ui/macros/macro-in-expression-context.stderr

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: macro expansion ignores token `assert_eq` and any following
2-
--> $DIR/macro-in-expression-context.rs:6:9
2+
--> $DIR/macro-in-expression-context.rs:10:9
33
|
44
LL | assert_eq!("B", "B");
55
| ^^^^^^^^^
@@ -11,5 +11,19 @@ LL | foo!()
1111
|
1212
= note: the usage of `foo!` is likely invalid in expression context
1313

14-
error: aborting due to previous error
14+
warning: trailing semicolon in macro used in expression position
15+
--> $DIR/macro-in-expression-context.rs:5:29
16+
|
17+
LL | assert_eq!("A", "A");
18+
| ^
19+
...
20+
LL | foo!()
21+
| ------ in this macro invocation
22+
|
23+
= note: `#[warn(semicolon_in_expressions_from_macros)]` on by default
24+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
25+
= note: for more information, see issue #79813 <https://github.com/rust-lang/rust/issues/79813>
26+
= note: this warning originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
27+
28+
error: aborting due to previous error; 1 warning emitted
1529

src/test/ui/proc-macro/nested-nonterminal-tokens.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ macro_rules! wrap {
1717
(first, $e:expr) => { wrap!(second, $e + 1) };
1818
(second, $e:expr) => { wrap!(third, $e + 2) };
1919
(third, $e:expr) => {
20-
print_bang!($e + 3);
20+
print_bang!($e + 3)
2121
};
2222
}
2323

0 commit comments

Comments
 (0)