-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix bad suggestions for deref_addrof
and try_err
lints
#6278
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
764dfe5
to
8d12b64
Compare
deref_addrof
lintderef_addrof
and try_err
lints
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.
I only have one nit and one question, otherwise this looks good to go. 👍
clippy_lints/src/try_err.rs
Outdated
@@ -92,7 +92,7 @@ impl<'tcx> LateLintPass<'tcx> for TryErr { | |||
|
|||
let expr_err_ty = cx.typeck_results().expr_ty(err_arg); | |||
|
|||
let origin_snippet = if err_arg.span.from_expansion() { | |||
let origin_snippet = if err_arg.span.from_expansion() && !in_macro(expr.span) { |
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.
This change seems unrelated?
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.
This !in_macro(expr.span)
is here to prevent the use of the macro callsite for suggestion.
In this example:
macro_rules! try_validation {
($e: expr) => {{
match $e {
Ok(_) => 0,
Err(_) => Err(1)?, // <-- lint here
}
}};
}
fn calling_macro() -> Result<i32, i32> {
try_validation!(Ok::<_, i32>(5));
Ok(5)
}
For information,err_arg.span
is referring to the 1
from Err(1)?
We want the suggestion to be return Err(1)
and not to be the macro call site (try_validation!(Ok::<_, i32>(5));
).
Just saw #6237, it is the same kind of problem we're solving here. |
Ok now it should be good for #6237 as well |
Good work! Thank you. @bors r+ |
📌 Commit 83e75f9 has been approved by |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Fix bad suggestions when in macro expansion for
deref_addrof
andtry_err
lints.Fixes: #6234
Fixes: #6242
Fixes: #6237
changelog: none
r? @llogiq