Skip to content

Commit 07c3206

Browse files
More carefully consider span context when suggesting remove &mut
1 parent 5adb489 commit 07c3206

File tree

1 file changed

+8
-5
lines changed
  • compiler/rustc_trait_selection/src/error_reporting/traits

1 file changed

+8
-5
lines changed

compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,12 +1511,15 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
15111511
'outer: loop {
15121512
while let hir::ExprKind::AddrOf(_, _, borrowed) = expr.kind {
15131513
count += 1;
1514-
let span = if expr.span.eq_ctxt(borrowed.span) {
1515-
expr.span.until(borrowed.span)
1516-
} else {
1517-
expr.span.with_hi(expr.span.lo() + BytePos(1))
1518-
};
1514+
let span =
1515+
if let Some(borrowed_span) = borrowed.span.find_ancestor_inside(expr.span) {
1516+
expr.span.until(borrowed_span)
1517+
} else {
1518+
break 'outer;
1519+
};
15191520

1521+
// Double check that the span we extracted actually corresponds to a borrow,
1522+
// rather than some macro garbage.
15201523
match self.tcx.sess.source_map().span_to_snippet(span) {
15211524
Ok(snippet) if snippet.starts_with("&") => {}
15221525
_ => break 'outer,

0 commit comments

Comments
 (0)