Skip to content

non_fmt_panic warns on 2021 for external macros #88142

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

Open
ehuss opened this issue Aug 18, 2021 · 1 comment
Open

non_fmt_panic warns on 2021 for external macros #88142

ehuss opened this issue Aug 18, 2021 · 1 comment
Labels
A-edition-2021 Area: The 2021 edition A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug.

Comments

@ehuss
Copy link
Contributor

ehuss commented Aug 18, 2021

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
@ehuss ehuss added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. A-edition-2021 Area: The 2021 edition labels Aug 18, 2021
@m-ou-se
Copy link
Member

m-ou-se commented Aug 18, 2021

That happens mostly on purpose. In this specific example, there's indeed nothing the user can/should do. But in many similar cases, the user can do picnic!("{expr}", expr = 1). The lint simply warns that the braces make it look like a formatting string (and that it's 'amost' used as one), but isn't used as such. E.g. assert_almost_eq!(1.0, 2.0, "{}") is missing an formatting argument, but just panics with the string "{}".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-edition-2021 Area: The 2021 edition A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants