Skip to content
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

Fix unused_braces on generic const expr macro call #106563

Merged
merged 1 commit into from
Jan 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_lint/src/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,7 @@ impl UnusedDelimLint for UnusedBraces {
|| matches!(expr.kind, ast::ExprKind::Lit(_)))
&& !cx.sess().source_map().is_multiline(value.span)
&& value.attrs.is_empty()
&& !expr.span.from_expansion()
&& !value.span.from_expansion()
&& !inner.span.from_expansion()
{
Expand Down
7 changes: 7 additions & 0 deletions tests/ui/const-generics/unused_braces.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@
// run-rustfix
#![warn(unused_braces)]

macro_rules! make_1 {
() => {
1
}
}

struct A<const N: usize>;

fn main() {
let _: A<7>; // ok
let _: A<7>; //~ WARN unnecessary braces
let _: A<{ 3 + 5 }>; // ok
let _: A<{make_1!()}>; // ok
}
7 changes: 7 additions & 0 deletions tests/ui/const-generics/unused_braces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@
// run-rustfix
#![warn(unused_braces)]

macro_rules! make_1 {
() => {
1
}
}

struct A<const N: usize>;

fn main() {
let _: A<7>; // ok
let _: A<{ 7 }>; //~ WARN unnecessary braces
let _: A<{ 3 + 5 }>; // ok
let _: A<{make_1!()}>; // ok
}
2 changes: 1 addition & 1 deletion tests/ui/const-generics/unused_braces.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: unnecessary braces around const expression
--> $DIR/unused_braces.rs:9:14
--> $DIR/unused_braces.rs:15:14
|
LL | let _: A<{ 7 }>;
| ^^ ^^
Expand Down