Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions tests/ui/macros/suggest-in-extern-macro-issue-139253.rs
Original file line number Diff line number Diff line change
@@ -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);
}
30 changes: 30 additions & 0 deletions tests/ui/macros/suggest-in-extern-macro-issue-139253.stderr
Original file line number Diff line number Diff line change
@@ -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`.
Loading