Skip to content

Commit 0acb786

Browse files
committed
Do not suggest borrowing when the span comes from a macro
1 parent 4c27fb1 commit 0acb786

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/librustc_typeck/check/demand.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc::hir::Node;
1010
use rustc::hir::{Item, ItemKind, print};
1111
use rustc::ty::{self, Ty, AssociatedItem};
1212
use rustc::ty::adjustment::AllowTwoPhase;
13-
use errors::{Applicability, DiagnosticBuilder, SourceMapper};
13+
use errors::{Applicability, DiagnosticBuilder};
1414

1515
use super::method::probe;
1616

@@ -271,9 +271,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
271271
expected: Ty<'tcx>)
272272
-> Option<(Span, &'static str, String)> {
273273
let cm = self.sess().source_map();
274-
// Use the callsite's span if this is a macro call. #41858
275-
let sp = cm.call_span_if_macro(expr.span);
274+
let sp = expr.span;
276275
if !cm.span_to_filename(sp).is_real() {
276+
// Ignore if span is from within a macro #41858, #58298. We previously used the macro
277+
// call span, but that breaks down when the type error comes from multiple calls down.
277278
return None;
278279
}
279280

src/test/ui/span/coerce-suggestions.stderr

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@ error[E0308]: mismatched types
5050
--> $DIR/coerce-suggestions.rs:21:9
5151
|
5252
LL | s = format!("foo");
53-
| ^^^^^^^^^^^^^^
54-
| |
55-
| expected mutable reference, found struct `std::string::String`
56-
| help: consider mutably borrowing here: `&mut format!("foo")`
53+
| ^^^^^^^^^^^^^^ expected mutable reference, found struct `std::string::String`
5754
|
5855
= note: expected type `&mut std::string::String`
5956
found type `std::string::String`

0 commit comments

Comments
 (0)