From 05c30b0ca5450b2beec0a6e4e034953e216f6bbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Mon, 2 Jan 2023 21:56:19 -0800 Subject: [PATCH] Skip macros to avoid talking about bindings the user can't see --- compiler/rustc_hir_typeck/src/demand.rs | 2 +- src/test/ui/span/coerce-suggestions.stderr | 5 +---- src/test/ui/span/issue-33884.stderr | 5 +---- .../dont-suggest-deref-inside-macro-issue-58298.stderr | 5 +---- 4 files changed, 4 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/demand.rs b/compiler/rustc_hir_typeck/src/demand.rs index c9ee5c6cac8b..5ba0d41ab9d1 100644 --- a/compiler/rustc_hir_typeck/src/demand.rs +++ b/compiler/rustc_hir_typeck/src/demand.rs @@ -260,7 +260,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { })) = map.find(parent) else { return false; }; let ty = self.node_ty(init.hir_id); - if ty.is_closure() || init.span.overlaps(expr.span) { + if ty.is_closure() || init.span.overlaps(expr.span) || pat.span.from_expansion() { return false; } let mut span_labels = vec![( diff --git a/src/test/ui/span/coerce-suggestions.stderr b/src/test/ui/span/coerce-suggestions.stderr index 75d460d7d8ca..db784d5fe6cf 100644 --- a/src/test/ui/span/coerce-suggestions.stderr +++ b/src/test/ui/span/coerce-suggestions.stderr @@ -63,10 +63,7 @@ error[E0308]: mismatched types --> $DIR/coerce-suggestions.rs:21:9 | LL | s = format!("foo"); - | ^^^^^^^^^^^^^^ - | | - | expected `&mut String`, found struct `String` - | here the type of `res` is inferred to be `String` + | ^^^^^^^^^^^^^^ expected `&mut String`, found struct `String` | = note: this error originates in the macro `format` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/span/issue-33884.stderr b/src/test/ui/span/issue-33884.stderr index 30e248f381c6..aee153085177 100644 --- a/src/test/ui/span/issue-33884.stderr +++ b/src/test/ui/span/issue-33884.stderr @@ -2,10 +2,7 @@ error[E0308]: mismatched types --> $DIR/issue-33884.rs:6:22 | LL | stream.write_fmt(format!("message received")) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | expected struct `Arguments`, found struct `String` - | here the type of `res` is inferred to be `String` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `Arguments`, found struct `String` | = note: this error originates in the macro `format` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/suggestions/dont-suggest-deref-inside-macro-issue-58298.stderr b/src/test/ui/suggestions/dont-suggest-deref-inside-macro-issue-58298.stderr index 2546f2515d74..5dc4e64446fb 100644 --- a/src/test/ui/suggestions/dont-suggest-deref-inside-macro-issue-58298.stderr +++ b/src/test/ui/suggestions/dont-suggest-deref-inside-macro-issue-58298.stderr @@ -4,10 +4,7 @@ error[E0308]: mismatched types LL | / intrinsic_match! { LL | | "abc" LL | | }; - | | ^ - | | | - | |_____expected `&str`, found struct `String` - | here the type of `res` is inferred to be `String` + | |_____^ expected `&str`, found struct `String` | = note: this error originates in the macro `format` which comes from the expansion of the macro `intrinsic_match` (in Nightly builds, run with -Z macro-backtrace for more info)