Skip to content

Commit 94d6601

Browse files
committed
Suppress suggest swapping the equality in extern macro
Signed-off-by: xizheyin <[email protected]>
1 parent 19331da commit 94d6601

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3636,7 +3636,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
36363636
.must_apply_modulo_regions()
36373637
{
36383638
let sm = self.tcx.sess.source_map();
3639-
if let Ok(rhs_snippet) = sm.span_to_snippet(rhs_expr.span)
3639+
// If the span of rhs_expr or lhs_expr is in an external macro,
3640+
// we just suppress the suggestion. See issue #139050
3641+
if !rhs_expr.span.in_external_macro(sm)
3642+
&& !lhs_expr.span.in_external_macro(sm)
3643+
&& let Ok(rhs_snippet) = sm.span_to_snippet(rhs_expr.span)
36403644
&& let Ok(lhs_snippet) = sm.span_to_snippet(lhs_expr.span)
36413645
{
36423646
err.note(format!("`{rhs_ty}` implements `PartialEq<{lhs_ty}>`"));

tests/ui/typeck/sugg-swap-equality-in-macro-issue-139050.stderr

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,7 @@ LL | ext::eq!(assert iter.next(), Some(value));
1212
|
1313
= note: expected enum `Option<_>`
1414
found enum `Option<&_>`
15-
= note: `Option<&<I as Iterator>::Item>` implements `PartialEq<Option<<I as Iterator>::Item>>`
1615
= note: this error originates in the macro `ext::eq` (in Nightly builds, run with -Z macro-backtrace for more info)
17-
help: consider swapping the equality
18-
--> $DIR/auxiliary/extern-macro-issue-139050.rs:6:22
19-
|
20-
LL - if !(*left_val == *right_val) {
21-
LL + if !(*right_val == *left_val) {
22-
|
2316

2417
error[E0308]: mismatched types
2518
--> $DIR/sugg-swap-equality-in-macro-issue-139050.rs:15:35

0 commit comments

Comments
 (0)