-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Rust 2021 (seemingly) mistakenly warns 'panic message contains braces' #87621
Comments
Hm, I'm uncertain how that should be handled. The assert!(expr, concat!("Pre-condition of parse violated: ", stringify!(key.starts_with('{')))) which expands to assert!(expr, "Pre-condition of parse violated: key.starts_with('{')") This ends up with a bare The |
Indeed, I think that proc-macro hygiene doesn't work all that well. To make it work, presumably, one would have to use the proper spans -- and this is a bit questionable, because the span for this time probably comes from the Rust 2021 crate, but the Rust 2018 crate is the one turning it into a string. In general, macro selection etc is not especially hygiene friendly, so I'm not totally sure how this winds up interacting. |
Aw, I put effort into making sure the suggestions are handled correctly in macro expansions as well, but apparently it doesn't work here at all. (Suggesting the
It does see this as a 2015/2018 panic. The hygiene works correctly. This warning is for 2015/2018 code. In 2021 code, such a panic/assert call wouldn't compile at all. |
So, just to clarify: The issue is that Also, I noticed that calling any macro (macro_rules, proc_macro, etc.) from another crate triggers the warning. I don't think it should be doing that, though, since there's nothing the caller can do about it, and it doesn't actually fail? That is, defining a macro in 2018 like this: #[macro_export]
macro_rules! foo {
() => {assert!(true, "{")};
} And calling that from a 2021 crate triggers a warning, but there's nothing to do since it works correctly. |
Testing the playground code in an |
Ah, yes. The span of the format string itself doesn't really matter, but the call site of the assert!() call itself does matter. So if they used quote_spanned only for the format string, but regular quote for the surrounding tokens, it'd be fine.
Yeah it shouldn't give warnings you can't fix in your current crate, so that part is a bug. It's a bit tricky, because if you have e.g. macro_rules! mypanic {
($($t:tt)*) => { assert!(false, $($t:tt)*) };
} then a warning about |
Warning about issues that are entirely in another crate is solved by #87965 The problem with |
…stebank Silence non_fmt_panic from external macros. This stops the non_fmt_panic lint from triggering if a macro from another crate is entirely responsible. In those cases there's nothing that the current crate can/should do. See also rust-lang#87621 (comment)
…pans, r=cjgillot Detect fake spans in non_fmt_panic lint. This addresses rust-lang#87621 Some proc_macros claim that the user wrote all of the tokens it outputs, by applying a span from the input to all of the produced tokens. That can result in confusing suggestions, as in rust-lang#87621. This is a simple patch that avoids suggesting anything for `panic!("{}")` if the span of `"{}"` and `panic!(..)` are identical, which is normally not possible.
…pans, r=cjgillot Detect fake spans in non_fmt_panic lint. This addresses rust-lang#87621 Some proc_macros claim that the user wrote all of the tokens it outputs, by applying a span from the input to all of the produced tokens. That can result in confusing suggestions, as in rust-lang#87621. This is a simple patch that avoids suggesting anything for `panic!("{}")` if the span of `"{}"` and `panic!(..)` are identical, which is normally not possible.
…pans, r=cjgillot Detect fake spans in non_fmt_panic lint. This addresses rust-lang#87621 Some proc_macros claim that the user wrote all of the tokens it outputs, by applying a span from the input to all of the produced tokens. That can result in confusing suggestions, as in rust-lang#87621. This is a simple patch that avoids suggesting anything for `panic!("{}")` if the span of `"{}"` and `panic!(..)` are identical, which is normally not possible.
…pans, r=cjgillot Detect fake spans in non_fmt_panic lint. This addresses rust-lang#87621 Some proc_macros claim that the user wrote all of the tokens it outputs, by applying a span from the input to all of the produced tokens. That can result in confusing suggestions, as in rust-lang#87621. This is a simple patch that avoids suggesting anything for `panic!("{}")` if the span of `"{}"` and `panic!(..)` are identical, which is normally not possible.
…pans, r=cjgillot Detect fake spans in non_fmt_panic lint. This addresses rust-lang#87621 Some proc_macros claim that the user wrote all of the tokens it outputs, by applying a span from the input to all of the produced tokens. That can result in confusing suggestions, as in rust-lang#87621. This is a simple patch that avoids suggesting anything for `panic!("{}")` if the span of `"{}"` and `panic!(..)` are identical, which is normally not possible.
The latest nightly no longer produces the wrong suggestion. The error is still produced, but that's not a problem that rustc can solve. That's up to the Closing this. |
Later versions of rust mistake macros like https://crates.io/crates/contracts
requires
as a panic message.Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=babeae07316ceb37dd7291ff889e9ea3
<code>
The current output is:
Ideally the output should look like:
Nothing, it's not a panic message, it's an expression.
The text was updated successfully, but these errors were encountered: