-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Don't expand macros in some suggestions #3366
Conversation
@@ -72,7 +72,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion { | |||
let a = cx.tables.expr_ty(e); | |||
let b = cx.tables.expr_ty(&args[0]); | |||
if same_tys(cx, a, b) { | |||
let sugg = snippet(cx, args[0].span, "<expr>").into_owned(); | |||
let sugg = if in_macro(args[0].span) { | |||
snippet(cx, args[0].span.source_callsite(), "<expr>").into_owned() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we unconditionally call the source callsite methods? if so, can we move it into the snippet function so all lints benefit from it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, I was thinking that this is probably becoming a recurring pattern. I will give it a try!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One problem occurs when span.source_callsite()
is called on a format!
argument. This happens in useless_format
lint (and a few other lints):
Unconditionally calling source_callsite
will result in the wrong suggestion because the source_callsite
exists and is the format!
macro in this case:
help: consider using .to_string(): `format!("foo");.to_string()`
I think it still makes sense to have a separate snippet_with_macro_callsite
function for the other cases, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. This generally only works if the entire situation is outside a macro, but most of our lints are skipping those situations via in_macro
on the full span anyway.
d853b66
to
2be39c0
Compare
I added a separate function called I will also go through all the other issues and try to find more cases that can be fixed easily. edit: Ok, I can't find any more issues that will be fixed by this. |
bde2f49
to
840e50e
Compare
bors r+ |
Build failed |
bors r=oli-obk |
3217: Fix string_lit_as_bytes lint for macros r=phansch a=yaahallo Prior to this change, string_lit_as_bytes would trigger for constructs like `include_str!("filename").as_bytes()` and would recommend fixing it by rewriting as `binclude_str!("filename")`. This change updates the lint to act as an EarlyLintPass lint. It then differentiates between string literals and macros that have bytes yielding alternatives. Closes #3205 3366: Don't expand macros in some suggestions r=oli-obk a=phansch Fixes #1148 Fixes #1628 Fixes #2455 Fixes #3023 Fixes #3333 Fixes #3360 Co-authored-by: Jane Lusby <jlusby42@gmail.com> Co-authored-by: Philipp Hansch <dev@phansch.net>
Fixes #1148
Fixes #1628
Fixes #2455
Fixes #3023
Fixes #3333
Fixes #3360