Skip to content

manual_let_else suggestion expands macros #9940

Closed
@Serial-ATA

Description

@Serial-ATA

Summary

If a macro has a return statement, the suggestion from the lint will contain the expanded macro content, rather than the macro call.

Reproducer

I tried this code:

#![warn(clippy::manual_let_else)]

macro_rules! some_macro {
    () => {
        return ()
    };
}

fn main() {
    let foo = Some(1);

    let _value = match foo {
        Some(value) => value,
        _ => some_macro!()
    };
}

I expected to see this happen:

#![warn(clippy::manual_let_else)]

macro_rules! some_macro {
    () => {
        return ()
    };
}

fn main() {
    let foo = Some(1);

    let Some(value) = foo else { some_macro!() };
}

This is the suggestion it should emit, the macro is not expanded.

Instead, this happened:

#![warn(clippy::manual_let_else)]

macro_rules! some_macro {
    () => {
        return ()
    };
}

fn main() {
    let foo = Some(1);

    let Some(value) = foo else { return () };
}

The suggestion removes the some_macro!(), and replaces it with the expansion.

Version

rustc 1.67.0-nightly (70f8737b2 2022-11-23)
binary: rustc
commit-hash: 70f8737b2f5d3bf7d6b784fad00b663b7ff9feda
commit-date: 2022-11-23
host: x86_64-unknown-linux-gnu
release: 1.67.0-nightly
LLVM version: 15.0.4

Additional Labels

No response

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thing

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions