This commit is contained in:
xizheyin 2025-04-13 13:25:46 +02:00 committed by GitHub
commit 9b46cf0d16
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 68 additions and 0 deletions

View File

@ -449,6 +449,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
err: &mut Diag<'_>,
trait_pred: ty::PolyTraitPredicate<'tcx>,
) -> bool {
if obligation.cause.span.in_external_macro(self.infcx.tcx.sess.source_map()) {
return false;
}
let mut code = obligation.cause.code();
if let ObligationCauseCode::FunctionArg { arg_hir_id, call_hir_id, .. } = code
&& let Some(typeck_results) = &self.typeck_results

View File

@ -0,0 +1,14 @@
#[macro_export]
macro_rules! is_equal {
($left:expr, $right:expr) => {
$left == $right //~ ERROR can't compare `&{integer}` with `{integer}` [E0277]
};
}
fn main() {
let x = 1;
let y = &x;
assert!(y == 1); //~ ERROR can't compare `&{integer}` with `{integer}` [E0277]
assert_eq!(y, 2); //~ ERROR can't compare `&{integer}` with `{integer}` [E0277]
is_equal!(y, 2);
}

View File

@ -0,0 +1,50 @@
error[E0277]: can't compare `&{integer}` with `{integer}`
--> $DIR/dont-suggest-within-macro-issue-139251.rs:11:15
|
LL | assert!(y == 1);
| ^^ no implementation for `&{integer} == {integer}`
|
= help: the trait `PartialEq<{integer}>` is not implemented for `&{integer}`
help: consider dereferencing here
|
LL | assert!(*y == 1);
| +
error[E0277]: can't compare `&{integer}` with `{integer}`
--> $DIR/dont-suggest-within-macro-issue-139251.rs:12:5
|
LL | assert_eq!(y, 2);
| ^^^^^^^^^^^^^^^^ no implementation for `&{integer} == {integer}`
|
= help: the trait `PartialEq<{integer}>` is not implemented for `&{integer}`
= help: the following other types implement trait `PartialEq<Rhs>`:
f128
f16
f32
f64
i128
i16
i32
i64
and 8 others
= note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: can't compare `&{integer}` with `{integer}`
--> $DIR/dont-suggest-within-macro-issue-139251.rs:4:15
|
LL | $left == $right
| ^^ no implementation for `&{integer} == {integer}`
...
LL | is_equal!(y, 2);
| --------------- in this macro invocation
|
= help: the trait `PartialEq<{integer}>` is not implemented for `&{integer}`
= note: this error originates in the macro `is_equal` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider dereferencing here
|
LL | is_equal!(*y, 2);
| +
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0277`.