From 0acb7867c21bca6e3ba53e88ef895c2ed2d833a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 27 Mar 2019 17:04:58 -0700 Subject: [PATCH] Do not suggest borrowing when the span comes from a macro --- src/librustc_typeck/check/demand.rs | 7 ++++--- src/test/ui/span/coerce-suggestions.stderr | 5 +---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/librustc_typeck/check/demand.rs b/src/librustc_typeck/check/demand.rs index b1a249d821be..302c093d12fa 100644 --- a/src/librustc_typeck/check/demand.rs +++ b/src/librustc_typeck/check/demand.rs @@ -10,7 +10,7 @@ use rustc::hir::Node; use rustc::hir::{Item, ItemKind, print}; use rustc::ty::{self, Ty, AssociatedItem}; use rustc::ty::adjustment::AllowTwoPhase; -use errors::{Applicability, DiagnosticBuilder, SourceMapper}; +use errors::{Applicability, DiagnosticBuilder}; use super::method::probe; @@ -271,9 +271,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { expected: Ty<'tcx>) -> Option<(Span, &'static str, String)> { let cm = self.sess().source_map(); - // Use the callsite's span if this is a macro call. #41858 - let sp = cm.call_span_if_macro(expr.span); + let sp = expr.span; if !cm.span_to_filename(sp).is_real() { + // Ignore if span is from within a macro #41858, #58298. We previously used the macro + // call span, but that breaks down when the type error comes from multiple calls down. return None; } diff --git a/src/test/ui/span/coerce-suggestions.stderr b/src/test/ui/span/coerce-suggestions.stderr index cda500c3f5db..996d80a07e05 100644 --- a/src/test/ui/span/coerce-suggestions.stderr +++ b/src/test/ui/span/coerce-suggestions.stderr @@ -50,10 +50,7 @@ error[E0308]: mismatched types --> $DIR/coerce-suggestions.rs:21:9 | LL | s = format!("foo"); - | ^^^^^^^^^^^^^^ - | | - | expected mutable reference, found struct `std::string::String` - | help: consider mutably borrowing here: `&mut format!("foo")` + | ^^^^^^^^^^^^^^ expected mutable reference, found struct `std::string::String` | = note: expected type `&mut std::string::String` found type `std::string::String`