diff options
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/hir/map/mod.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_typeck/src/check/upvar.rs | 12 |
3 files changed, 9 insertions, 10 deletions
diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs index 3c5dd32d281..8134e122662 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs @@ -861,7 +861,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { let arg_pos = args .iter() .enumerate() - .filter(|(_, arg)| arg.span == self.body.span) + .filter(|(_, arg)| arg.hir_id == closure_id) .map(|(pos, _)| pos) .next(); let def_id = hir.local_def_id(item_id); @@ -903,9 +903,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { if let Some(span) = arg { err.span_label(span, "change this to accept `FnMut` instead of `Fn`"); err.span_label(func.span, "expects `Fn` instead of `FnMut`"); - if self.infcx.tcx.sess.source_map().is_multiline(self.body.span) { - err.span_label(self.body.span, "in this closure"); - } + err.span_label(self.body.span, "in this closure"); look_at_return = false; } } diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index cc831f7b03b..3e99ba5742a 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -1021,6 +1021,7 @@ impl<'hir> Map<'hir> { _ => named_span(item.span, item.ident, None), }, Node::Ctor(_) => return self.opt_span(self.get_parent_node(hir_id)), + Node::Expr(Expr { kind: ExprKind::Closure { fn_decl_span, .. }, .. }) => *fn_decl_span, _ => self.span_with_body(hir_id), }; Some(span) diff --git a/compiler/rustc_typeck/src/check/upvar.rs b/compiler/rustc_typeck/src/check/upvar.rs index 87f85a9842f..74546ed9080 100644 --- a/compiler/rustc_typeck/src/check/upvar.rs +++ b/compiler/rustc_typeck/src/check/upvar.rs @@ -747,14 +747,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let (migration_string, migrated_variables_concat) = migration_suggestion_for_2229(self.tcx, &need_migrations); - let local_def_id = closure_def_id.expect_local(); - let closure_hir_id = self.tcx.hir().local_def_id_to_hir_id(local_def_id); - let closure_span = self.tcx.hir().span(closure_hir_id); - let closure_head_span = self.tcx.sess.source_map().guess_head_span(closure_span); + let closure_hir_id = + self.tcx.hir().local_def_id_to_hir_id(closure_def_id.expect_local()); + let closure_head_span = self.tcx.def_span(closure_def_id); self.tcx.struct_span_lint_hir( lint::builtin::RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES, closure_hir_id, - closure_head_span, + closure_head_span, |lint| { let mut diagnostics_builder = lint.build( &reasons.migration_message(), @@ -827,12 +826,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { migrated_variables_concat ); + let closure_span = self.tcx.hir().span_with_body(closure_hir_id); let mut closure_body_span = { // If the body was entirely expanded from a macro // invocation, i.e. the body is not contained inside the // closure span, then we walk up the expansion until we // find the span before the expansion. - let s = self.tcx.hir().span(body_id.hir_id); + let s = self.tcx.hir().span_with_body(body_id.hir_id); s.find_ancestor_inside(closure_span).unwrap_or(s) }; |
