Skip to content

non_fmt_panic warns on 2021 for external macros #88142

Open
@ehuss

Description

@ehuss

I've noticed that non_fmt_panic will raise a warning in 2021 for external macros in some cases. #87965 silenced the case involving a non-string payload, but there are still warnings for strings with braces. I don't think there is anything the caller can do to fix the warning (other than silencing it).

I tried this code:

// Any edition, 2021, 2018, or 2015.
fn main() {
    bar::picnic!("{example}");   // WARNING:  panic message contains an unused formatting placeholder
}

With the macro defined as either macro_rules or proc-macro:

// bar, 2015 or 2018
#[macro_export]
macro_rules! picnic {
    ($e:expr) => {panic!($e)};
}

Or defined as a proc-macro:

// bar, any edition
extern crate proc_macro;

#[proc_macro]
pub fn picnic(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
    let t = input.into_iter().next().unwrap();
    proc_macro::quote! {
        panic!($t);
    }
}

I expected to see this happen: There (probably?) shouldn't be a warning if there is nothing the caller can do.

Instead, this happened: Warning is emitted.

Meta

rustc --version --verbose:

rustc 1.56.0-nightly (30a0a9b69 2021-08-17)
binary: rustc
commit-hash: 30a0a9b694cde95cbab863f7ef4d554f0f46b606
commit-date: 2021-08-17
host: x86_64-apple-darwin
release: 1.56.0-nightly
LLVM version: 12.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-edition-2021Area: The 2021 editionA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions