-
Notifications
You must be signed in to change notification settings - Fork 1.7k
don't remove dbg!
in arbitrary expressions
#10725
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
Conversation
r? @Jarcho (rustbot has picked a reviewer for you, use r? to override) |
Does this work properly when |
Hmm it seems like it breaks if the macro_rules! foo {
($x:expr) => { $x; };
}
fn main() {
foo!(dbg!());
}
so perhaps my way of checking if we're allowed to remove the |
I think the only thing you can do here is to start tokenizing from the end of the call site and see if the first non-whitespace token is a semicolon. |
Alright, it's not exactly pretty but it works. |
It works, so... Thank you. @bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Fixes #9914
The
dbg_macro
lint replaces emptydbg!
invocations with the empty string in its suggestion, which is not always valid code in certain contexts (e.g.let _ = dbg!();
becomeslet _ = ;
). This PR changes it to()
, which should always be valid wheredbg!()
is valid (dbg!()
with no arguments evaluates to()
).It also special-cases "standalone"
dbg!();
expression statements, where it will suggest removing the whole statement entirely like it did before.changelog: [
dbg_macro
]: don't removedbg!()
in arbitrary expressions as it sometimes results in syntax errors