This commit is contained in:
xizheyin 2025-04-13 13:27:35 +02:00 committed by GitHub
commit 908cf1d92d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 50 additions and 1 deletions

View File

@ -1263,7 +1263,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expr_ty: Ty<'tcx>,
expected_ty: Ty<'tcx>,
) -> bool {
if let ty::Ref(_, inner_ty, hir::Mutability::Not) = expr_ty.kind()
if !expr.span.in_external_macro(self.tcx.sess.source_map())
&& let ty::Ref(_, inner_ty, hir::Mutability::Not) = expr_ty.kind()
&& let Some(clone_trait_def) = self.tcx.lang_items().clone_trait()
&& expected_ty == *inner_ty
&& self

View File

@ -0,0 +1,18 @@
#[derive(Clone, Debug)]
struct Point<T> {
v: T,
}
macro_rules! local_macro {
($val:expr $(,)?) => {
match $val {
tmp => tmp, //~ ERROR mismatched types [E0308]
}
};
}
fn main() {
let a: Point<u8> = dbg!(Point { v: 42 });
let b: Point<u8> = dbg!(&a); //~ ERROR mismatched types [E0308]
let c: Point<u8> = local_macro!(&a);
}

View File

@ -0,0 +1,30 @@
error[E0308]: mismatched types
--> $DIR/suggest-in-extern-macro-issue-139253.rs:16:24
|
LL | let b: Point<u8> = dbg!(&a);
| ^^^^^^^^ expected `Point<u8>`, found `&Point<u8>`
|
= note: expected struct `Point<_>`
found reference `&Point<_>`
= note: this error originates in the macro `dbg` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0308]: mismatched types
--> $DIR/suggest-in-extern-macro-issue-139253.rs:9:20
|
LL | tmp => tmp,
| ^^^ expected `Point<u8>`, found `&Point<u8>`
...
LL | let c: Point<u8> = local_macro!(&a);
| ---------------- in this macro invocation
|
= note: expected struct `Point<_>`
found reference `&Point<_>`
= note: this error originates in the macro `local_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider using clone here
|
LL | tmp => tmp.clone(),
| ++++++++
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0308`.