-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Supress swapping lhs and rhs in equality suggestion in extern macro #144266
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
base: master
Are you sure you want to change the base?
Conversation
If the test can't actually demonstrate the change, then there's no reason to make this into two commits. Please squash this into one. |
Signed-off-by: xizheyin <[email protected]>
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.
Pretty fast review!
@rustbot ready
if rhs_expr.span.in_external_macro(sm) || lhs_expr.span.in_external_macro(sm) { | ||
return; | ||
} | ||
|
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.
Now I checked both.
@@ -3533,6 +3533,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |||
.must_apply_modulo_regions() | |||
{ | |||
let sm = self.tcx.sess.source_map(); | |||
// If the span of rhs_expr or lhs_expr is in an external macro, |
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.
There is another copy of suggest_swapping_lhs_and_rhs
in rustc_trait_selection
. Could you please add this check to that, too, since I think it suffers from the same issue.
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.
Yeah, I'll also look for a test case for that tomorrow.
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 don't really think it needs a test case, but if you want to add one it's probably something like:
upstream crate:
macro_rules! eq {
($a:expr) => { $a == () }
}
downstream crate:
struct Foo;
impl PartialEq<Foo> for () {
fn eq(&self, _: &Foo) -> bool { todo!() }
}
fn main() {
let _ = eq!(Foo);
}
Pay attention to the fact that it's a trait error and there may already be some macro suppression going on there 🤔
I submitted #144268. We can find the correct span with the newly added methods, thus not needing to suppress this suggestion. |
Fixes #139050
I have tried to find the initial call point via
find_oldest_ancestor_in_same_ctxt
, but it terminates inside thedebug_assert_eq
macro and doesn't get the span we were expecting.For this reason #139316 (comment) , the test can not show the diff.
I test it locally.
In master branch:
In this branch: