- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Open
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.Category: This is a bug.L-false-positiveLint: False positive (should not have fired).Lint: False positive (should not have fired).L-unused_parensLint: unused_parensLint: unused_parensT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
I tried this code:
macro_rules! range_array {
    ( $( $num:tt ),* ) => {
        [ $( { let value = $num; value..=value } ),* ]
    };
}
fn foo(x: u8) -> u8 {
    x
}
fn main() {
    // This isn't allowed, need to use a token tree.
    //assert_eq!(range_array![1, foo(4), 5], [1..=1, 4..=4, 5..=5])
    // But this triggers an unused_paren warning.
    assert_eq!(range_array![1, (foo(4)), 5], [1..=1, 4..=4, 5..=5]);
}I expected to see this happen: No warnings
Instead, this happened:
warning: unnecessary parentheses around assigned value
  --> src/main.rs:12:32
   |
12 |     assert_eq!(range_array![1, (foo(4)), 5], [1..=1, 4..=4, 5..=5]);
   |                                ^      ^
   |
   = note: `#[warn(unused_parens)]` on by default
This is an unexpected corner case of #47775 (assignment), and was not fixed by #47896. Assignment-expressions and block-return-expressions are affected:
$num; // OK
let value = $num; // Warn
let value = 0 + $num; // OK
let value = 0 + ($num); // OK
let value = { $num }; // Warn
let value = 0 + { $num }; // Warn
let value = { 0 + $num }; // OK
{ $num }; // Warn
0 + { $num }; // WarnIn my actual use case, I can't do 0 + $num. I don't think I have any idenity function available.
Meta
rustc --version --verbose:
rustc 1.72.0-nightly (83964c156 2023-07-08)
binary: rustc
commit-hash: 83964c156db1f444050a38b2498dbd0da6d5d503
commit-date: 2023-07-08
host: x86_64-pc-windows-msvc
release: 1.72.0-nightly
LLVM version: 16.0.5
I still have a 1.36 install of rust, and that showed the same warning, so I think this has been around for a while.
Metadata
Metadata
Assignees
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.Category: This is a bug.L-false-positiveLint: False positive (should not have fired).Lint: False positive (should not have fired).L-unused_parensLint: unused_parensLint: unused_parensT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.