Skip to content

Commit 295f548

Browse files
committed
Fix regression in unused_braces with macros
1 parent 754f6d4 commit 295f548

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

compiler/rustc_lint/src/unused.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -1095,17 +1095,21 @@ impl UnusedDelimLint for UnusedBraces {
10951095
// ```
10961096
// - the block has no attribute and was not created inside a macro
10971097
// - if the block is an `anon_const`, the inner expr must be a literal
1098-
// (do not lint `struct A<const N: usize>; let _: A<{ 2 + 3 }>;`)
1099-
//
1098+
// not created by a macro, i.e. do not lint on:
1099+
// ```
1100+
// struct A<const N: usize>;
1101+
// let _: A<{ 2 + 3 }>;
1102+
// let _: A<{produces_literal!()}>;
1103+
// ```
11001104
// FIXME(const_generics): handle paths when #67075 is fixed.
11011105
if let [stmt] = inner.stmts.as_slice() {
11021106
if let ast::StmtKind::Expr(ref expr) = stmt.kind {
11031107
if !Self::is_expr_delims_necessary(expr, followed_by_block, false)
11041108
&& (ctx != UnusedDelimsCtx::AnonConst
1105-
|| matches!(expr.kind, ast::ExprKind::Lit(_)))
1109+
|| (matches!(expr.kind, ast::ExprKind::Lit(_))
1110+
&& !expr.span.from_expansion()))
11061111
&& !cx.sess().source_map().is_multiline(value.span)
11071112
&& value.attrs.is_empty()
1108-
&& !expr.span.from_expansion()
11091113
&& !value.span.from_expansion()
11101114
&& !inner.span.from_expansion()
11111115
{

tests/ui/lint/unused_braces.fixed

+4
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,8 @@ fn main() {
5050
if { return } {
5151

5252
}
53+
54+
// regression test for https://github.com/rust-lang/rust/issues/106899
55+
return println!("!");
56+
//~^ WARN unnecessary braces
5357
}

tests/ui/lint/unused_braces.rs

+4
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,8 @@ fn main() {
5050
if { return } {
5151

5252
}
53+
54+
// regression test for https://github.com/rust-lang/rust/issues/106899
55+
return { println!("!") };
56+
//~^ WARN unnecessary braces
5357
}

tests/ui/lint/unused_braces.stderr

+13-1
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,17 @@ LL - consume({ 7 });
6868
LL + consume(7);
6969
|
7070

71-
warning: 5 warnings emitted
71+
warning: unnecessary braces around `return` value
72+
--> $DIR/unused_braces.rs:55:12
73+
|
74+
LL | return { println!("!") };
75+
| ^^ ^^
76+
|
77+
help: remove these braces
78+
|
79+
LL - return { println!("!") };
80+
LL + return println!("!");
81+
|
82+
83+
warning: 6 warnings emitted
7284

0 commit comments

Comments
 (0)