2 use rustc::hir::def_id::DefId;
4 self, AggregateKind, BindingForm, BorrowKind, ClearCrossCrate, ConstraintCategory, Local,
5 LocalDecl, LocalKind, Location, Operand, Place, PlaceBase, Projection, PlaceRef,
6 ProjectionElem, Rvalue, Statement, StatementKind, TerminatorKind, VarBindingForm,
8 use rustc::ty::{self, Ty};
9 use rustc_data_structures::fx::FxHashSet;
10 use rustc_data_structures::indexed_vec::Idx;
11 use rustc_errors::{Applicability, DiagnosticBuilder};
13 use syntax::source_map::DesugaringKind;
15 use super::nll::explain_borrow::BorrowExplanation;
16 use super::nll::region_infer::{RegionName, RegionNameSource};
17 use super::prefixes::IsPrefixOf;
19 use super::borrow_set::BorrowData;
20 use super::MirBorrowckCtxt;
21 use super::{InitializationRequiringAction, PrefixSet};
22 use super::error_reporting::{IncludingDowncast, UseSpans};
23 use crate::dataflow::drop_flag_effects;
24 use crate::dataflow::indexes::{MovePathIndex, MoveOutIndex};
25 use crate::util::borrowck_errors;
29 /// Index of the "move out" that we found. The `MoveData` can
30 /// then tell us where the move occurred.
33 /// `true` if we traversed a back edge while walking from the point
34 /// of error to the move site.
35 traversed_back_edge: bool
38 /// Which case a StorageDeadOrDrop is for.
39 #[derive(Copy, Clone, PartialEq, Eq, Debug)]
40 enum StorageDeadOrDrop<'tcx> {
46 impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
47 pub(super) fn report_use_of_moved_or_uninitialized(
50 desired_action: InitializationRequiringAction,
51 (moved_place, used_place, span): (PlaceRef<'cx, 'tcx>, PlaceRef<'cx, 'tcx>, Span),
55 "report_use_of_moved_or_uninitialized: location={:?} desired_action={:?} \
56 moved_place={:?} used_place={:?} span={:?} mpi={:?}",
57 location, desired_action, moved_place, used_place, span, mpi
60 let use_spans = self.move_spans(moved_place, location)
61 .or_else(|| self.borrow_spans(span, location));
62 let span = use_spans.args_or_use();
64 let move_site_vec = self.get_moved_indexes(location, mpi);
66 "report_use_of_moved_or_uninitialized: move_site_vec={:?}",
69 let move_out_indices: Vec<_> = move_site_vec
71 .map(|move_site| move_site.moi)
74 if move_out_indices.is_empty() {
76 .prefixes(used_place, PrefixSet::All)
80 if self.uninitialized_error_reported.contains(&root_place) {
82 "report_use_of_moved_or_uninitialized place: error about {:?} suppressed",
88 self.uninitialized_error_reported.insert(root_place);
90 let item_msg = match self.describe_place_with_options(used_place,
91 IncludingDowncast(true)) {
92 Some(name) => format!("`{}`", name),
93 None => "value".to_owned(),
95 let mut err = self.cannot_act_on_uninitialized_variable(
97 desired_action.as_noun(),
98 &self.describe_place_with_options(moved_place, IncludingDowncast(true))
99 .unwrap_or_else(|| "_".to_owned()),
101 err.span_label(span, format!("use of possibly uninitialized {}", item_msg));
103 use_spans.var_span_label(
105 format!("{} occurs due to use{}", desired_action.as_noun(), use_spans.describe()),
108 err.buffer(&mut self.errors_buffer);
110 if let Some((reported_place, _)) = self.move_error_reported.get(&move_out_indices) {
111 if self.prefixes(*reported_place, PrefixSet::All)
112 .any(|p| p == used_place)
115 "report_use_of_moved_or_uninitialized place: error suppressed \
123 let msg = ""; //FIXME: add "partially " or "collaterally "
125 let mut err = self.cannot_act_on_moved_value(
127 desired_action.as_noun(),
129 self.describe_place_with_options(moved_place, IncludingDowncast(true)),
132 self.add_moved_or_invoked_closure_note(
138 let mut is_loop_move = false;
139 let is_partial_move = move_site_vec.iter().any(|move_site| {
140 let move_out = self.move_data.moves[(*move_site).moi];
141 let moved_place = &self.move_data.move_paths[move_out.path].place;
142 used_place != moved_place.as_ref()
143 && used_place.is_prefix_of(moved_place.as_ref())
145 for move_site in &move_site_vec {
146 let move_out = self.move_data.moves[(*move_site).moi];
147 let moved_place = &self.move_data.move_paths[move_out.path].place;
149 let move_spans = self.move_spans(moved_place.as_ref(), move_out.source);
150 let move_span = move_spans.args_or_use();
152 let move_msg = if move_spans.for_closure() {
158 if span == move_span {
161 format!("value moved{} here, in previous iteration of loop", move_msg),
164 } else if move_site.traversed_back_edge {
168 "value moved{} here, in previous iteration of loop",
173 err.span_label(move_span, format!("value moved{} here", move_msg));
174 move_spans.var_span_label(
176 format!("variable moved due to use{}", move_spans.describe()),
179 if Some(DesugaringKind::ForLoop) == move_span.desugaring_kind() {
180 if let Ok(snippet) = self.infcx.tcx.sess.source_map().span_to_snippet(span) {
183 "consider borrowing to avoid moving into the for loop",
184 format!("&{}", snippet),
185 Applicability::MaybeIncorrect,
191 use_spans.var_span_label(
193 format!("{} occurs due to use{}", desired_action.as_noun(), use_spans.describe()),
201 desired_action.as_verb_in_past_tense(),
202 if is_partial_move { "after partial move" } else { "after move" },
208 Place::ty_from(used_place.base, used_place.projection, self.body, self.infcx.tcx)
210 let needs_note = match ty.sty {
211 ty::Closure(id, _) => {
212 let tables = self.infcx.tcx.typeck_tables_of(id);
213 let hir_id = self.infcx.tcx.hir().as_local_hir_id(id).unwrap();
215 tables.closure_kind_origins().get(hir_id).is_none()
221 let mpi = self.move_data.moves[move_out_indices[0]].path;
222 let place = &self.move_data.move_paths[mpi].place;
224 let ty = place.ty(self.body, self.infcx.tcx).ty;
226 self.describe_place_with_options(place.as_ref(), IncludingDowncast(true));
227 let note_msg = match opt_name {
228 Some(ref name) => format!("`{}`", name),
229 None => "value".to_owned(),
231 if let ty::Param(param_ty) = ty.sty {
232 let tcx = self.infcx.tcx;
233 let generics = tcx.generics_of(self.mir_def_id);
234 let def_id = generics.type_param(¶m_ty, tcx).def_id;
235 if let Some(sp) = tcx.hir().span_if_local(def_id) {
238 "consider adding a `Copy` constraint to this type argument",
242 let span = if let Place {
243 base: PlaceBase::Local(local),
246 let decl = &self.body.local_decls[*local];
247 Some(decl.source_info.span)
251 self.note_type_does_not_implement_copy(
259 if let Some((_, mut old_err)) = self.move_error_reported
260 .insert(move_out_indices, (used_place, err))
262 // Cancel the old error so it doesn't ICE.
268 pub(super) fn report_move_out_while_borrowed(
271 (place, span): (&Place<'tcx>, Span),
272 borrow: &BorrowData<'tcx>,
275 "report_move_out_while_borrowed: location={:?} place={:?} span={:?} borrow={:?}",
276 location, place, span, borrow
278 let value_msg = match self.describe_place(place.as_ref()) {
279 Some(name) => format!("`{}`", name),
280 None => "value".to_owned(),
282 let borrow_msg = match self.describe_place(borrow.borrowed_place.as_ref()) {
283 Some(name) => format!("`{}`", name),
284 None => "value".to_owned(),
287 let borrow_spans = self.retrieve_borrow_spans(borrow);
288 let borrow_span = borrow_spans.args_or_use();
290 let move_spans = self.move_spans(place.as_ref(), location);
291 let span = move_spans.args_or_use();
293 let mut err = self.cannot_move_when_borrowed(
295 &self.describe_place(place.as_ref()).unwrap_or_else(|| "_".to_owned()),
297 err.span_label(borrow_span, format!("borrow of {} occurs here", borrow_msg));
298 err.span_label(span, format!("move out of {} occurs here", value_msg));
300 borrow_spans.var_span_label(
302 format!("borrow occurs due to use{}", borrow_spans.describe())
305 move_spans.var_span_label(
307 format!("move occurs due to use{}", move_spans.describe())
310 self.explain_why_borrow_contains_point(
314 ).add_explanation_to_diagnostic(self.infcx.tcx, self.body, &mut err, "", Some(borrow_span));
315 err.buffer(&mut self.errors_buffer);
318 pub(super) fn report_use_while_mutably_borrowed(
321 (place, _span): (&Place<'tcx>, Span),
322 borrow: &BorrowData<'tcx>,
323 ) -> DiagnosticBuilder<'cx> {
324 let borrow_spans = self.retrieve_borrow_spans(borrow);
325 let borrow_span = borrow_spans.args_or_use();
327 // Conflicting borrows are reported separately, so only check for move
329 let use_spans = self.move_spans(place.as_ref(), location);
330 let span = use_spans.var_or_use();
332 let mut err = self.cannot_use_when_mutably_borrowed(
334 &self.describe_place(place.as_ref()).unwrap_or_else(|| "_".to_owned()),
336 &self.describe_place(borrow.borrowed_place.as_ref())
337 .unwrap_or_else(|| "_".to_owned()),
340 borrow_spans.var_span_label(&mut err, {
341 let place = &borrow.borrowed_place;
343 self.describe_place(place.as_ref()).unwrap_or_else(|| "_".to_owned());
345 format!("borrow occurs due to use of `{}`{}", desc_place, borrow_spans.describe())
348 self.explain_why_borrow_contains_point(location, borrow, None)
349 .add_explanation_to_diagnostic(self.infcx.tcx, self.body, &mut err, "", None);
353 pub(super) fn report_conflicting_borrow(
356 (place, span): (&Place<'tcx>, Span),
357 gen_borrow_kind: BorrowKind,
358 issued_borrow: &BorrowData<'tcx>,
359 ) -> DiagnosticBuilder<'cx> {
360 let issued_spans = self.retrieve_borrow_spans(issued_borrow);
361 let issued_span = issued_spans.args_or_use();
363 let borrow_spans = self.borrow_spans(span, location);
364 let span = borrow_spans.args_or_use();
366 let container_name = if issued_spans.for_generator() || borrow_spans.for_generator() {
372 let (desc_place, msg_place, msg_borrow, union_type_name) =
373 self.describe_place_for_conflicting_borrow(place, &issued_borrow.borrowed_place);
375 let explanation = self.explain_why_borrow_contains_point(location, issued_borrow, None);
376 let second_borrow_desc = if explanation.is_explained() {
382 // FIXME: supply non-"" `opt_via` when appropriate
383 let first_borrow_desc;
384 let mut err = match (
392 (BorrowKind::Shared, lft, _, BorrowKind::Mut { .. }, _, rgt) => {
393 first_borrow_desc = "mutable ";
394 self.cannot_reborrow_already_borrowed(
406 (BorrowKind::Mut { .. }, _, lft, BorrowKind::Shared, rgt, _) => {
407 first_borrow_desc = "immutable ";
408 self.cannot_reborrow_already_borrowed(
421 (BorrowKind::Mut { .. }, _, _, BorrowKind::Mut { .. }, _, _) => {
422 first_borrow_desc = "first ";
423 self.cannot_mutably_borrow_multiply(
433 (BorrowKind::Unique, _, _, BorrowKind::Unique, _, _) => {
434 first_borrow_desc = "first ";
435 self.cannot_uniquely_borrow_by_two_closures(
443 (BorrowKind::Mut { .. }, _, _, BorrowKind::Shallow, _, _)
444 | (BorrowKind::Unique, _, _, BorrowKind::Shallow, _, _) => {
445 let mut err = self.cannot_mutate_in_match_guard(
451 borrow_spans.var_span_label(
454 "borrow occurs due to use of `{}`{}", desc_place, borrow_spans.describe()
461 (BorrowKind::Unique, _, _, _, _, _) => {
462 first_borrow_desc = "first ";
463 self.cannot_uniquely_borrow_by_one_closure(
475 (BorrowKind::Shared, lft, _, BorrowKind::Unique, _, _) => {
476 first_borrow_desc = "first ";
477 self.cannot_reborrow_already_uniquely_borrowed(
490 (BorrowKind::Mut { .. }, _, lft, BorrowKind::Unique, _, _) => {
491 first_borrow_desc = "first ";
492 self.cannot_reborrow_already_uniquely_borrowed(
505 (BorrowKind::Shared, _, _, BorrowKind::Shared, _, _)
506 | (BorrowKind::Shared, _, _, BorrowKind::Shallow, _, _)
507 | (BorrowKind::Shallow, _, _, BorrowKind::Mut { .. }, _, _)
508 | (BorrowKind::Shallow, _, _, BorrowKind::Unique, _, _)
509 | (BorrowKind::Shallow, _, _, BorrowKind::Shared, _, _)
510 | (BorrowKind::Shallow, _, _, BorrowKind::Shallow, _, _) => unreachable!(),
513 if issued_spans == borrow_spans {
514 borrow_spans.var_span_label(
516 format!("borrows occur due to use of `{}`{}", desc_place, borrow_spans.describe()),
519 let borrow_place = &issued_borrow.borrowed_place;
520 let borrow_place_desc = self.describe_place(borrow_place.as_ref())
521 .unwrap_or_else(|| "_".to_owned());
522 issued_spans.var_span_label(
525 "first borrow occurs due to use of `{}`{}",
527 issued_spans.describe(),
531 borrow_spans.var_span_label(
534 "second borrow occurs due to use of `{}`{}",
536 borrow_spans.describe(),
541 if union_type_name != "" {
543 "`{}` is a field of the union `{}`, so it overlaps the field `{}`",
544 msg_place, union_type_name, msg_borrow,
548 explanation.add_explanation_to_diagnostic(
559 /// Returns the description of the root place for a conflicting borrow and the full
560 /// descriptions of the places that caused the conflict.
562 /// In the simplest case, where there are no unions involved, if a mutable borrow of `x` is
563 /// attempted while a shared borrow is live, then this function will return:
567 /// In the simple union case, if a mutable borrow of a union field `x.z` is attempted while
568 /// a shared borrow of another field `x.y`, then this function will return:
570 /// ("x", "x.z", "x.y")
572 /// In the more complex union case, where the union is a field of a struct, then if a mutable
573 /// borrow of a union field in a struct `x.u.z` is attempted while a shared borrow of
574 /// another field `x.u.y`, then this function will return:
576 /// ("x.u", "x.u.z", "x.u.y")
578 /// This is used when creating error messages like below:
580 /// > cannot borrow `a.u` (via `a.u.z.c`) as immutable because it is also borrowed as
581 /// > mutable (via `a.u.s.b`) [E0502]
582 pub(super) fn describe_place_for_conflicting_borrow(
584 first_borrowed_place: &Place<'tcx>,
585 second_borrowed_place: &Place<'tcx>,
586 ) -> (String, String, String, String) {
587 // Define a small closure that we can use to check if the type of a place
589 let union_ty = |place_base, place_projection| {
590 let ty = Place::ty_from(place_base, place_projection, self.body, self.infcx.tcx).ty;
591 ty.ty_adt_def().filter(|adt| adt.is_union()).map(|_| ty)
593 let describe_place = |place| self.describe_place(place).unwrap_or_else(|| "_".to_owned());
595 // Start with an empty tuple, so we can use the functions on `Option` to reduce some
596 // code duplication (particularly around returning an empty description in the failure
600 // If we have a conflicting borrow of the same place, then we don't want to add
601 // an extraneous "via x.y" to our diagnostics, so filter out this case.
602 first_borrowed_place != second_borrowed_place
605 // We're going to want to traverse the first borrowed place to see if we can find
606 // field access to a union. If we find that, then we will keep the place of the
607 // union being accessed and the field that was being accessed so we can check the
608 // second borrowed place for the same union and a access to a different field.
612 } = first_borrowed_place;
614 let mut current = projection;
616 while let Some(box Projection { base: base_proj, elem }) = current {
618 ProjectionElem::Field(field, _) if union_ty(base, base_proj).is_some() => {
619 return Some((PlaceRef {
621 projection: base_proj,
624 _ => current = base_proj,
629 .and_then(|(target_base, target_field)| {
630 // With the place of a union and a field access into it, we traverse the second
631 // borrowed place and look for a access to a different field of the same union.
635 } = second_borrowed_place;
637 let mut current = projection;
639 while let Some(box Projection { base: proj_base, elem }) = current {
640 if let ProjectionElem::Field(field, _) = elem {
641 if let Some(union_ty) = union_ty(base, proj_base) {
642 if field != target_field
643 && base == target_base.base
644 && proj_base == target_base.projection {
645 // FIXME when we avoid clone reuse describe_place closure
646 let describe_base_place = self.describe_place(PlaceRef {
648 projection: proj_base,
649 }).unwrap_or_else(|| "_".to_owned());
653 describe_place(first_borrowed_place.as_ref()),
654 describe_place(second_borrowed_place.as_ref()),
655 union_ty.to_string(),
666 // If we didn't find a field access into a union, or both places match, then
667 // only return the description of the first place.
669 describe_place(first_borrowed_place.as_ref()),
677 /// Reports StorageDeadOrDrop of `place` conflicts with `borrow`.
679 /// This means that some data referenced by `borrow` needs to live
680 /// past the point where the StorageDeadOrDrop of `place` occurs.
681 /// This is usually interpreted as meaning that `place` has too
682 /// short a lifetime. (But sometimes it is more useful to report
683 /// it as a more direct conflict between the execution of a
684 /// `Drop::drop` with an aliasing borrow.)
685 pub(super) fn report_borrowed_value_does_not_live_long_enough(
688 borrow: &BorrowData<'tcx>,
689 place_span: (&Place<'tcx>, Span),
690 kind: Option<WriteKind>,
693 "report_borrowed_value_does_not_live_long_enough(\
694 {:?}, {:?}, {:?}, {:?}\
696 location, borrow, place_span, kind
699 let drop_span = place_span.1;
700 let root_place = self.prefixes(borrow.borrowed_place.as_ref(), PrefixSet::All)
704 let borrow_spans = self.retrieve_borrow_spans(borrow);
705 let borrow_span = borrow_spans.var_or_use();
707 assert!(root_place.projection.is_none());
708 let proper_span = match root_place.base {
709 PlaceBase::Local(local) => self.body.local_decls[*local].source_info.span,
713 if self.access_place_error_reported
715 base: root_place.base.clone(),
716 projection: root_place.projection.clone(),
720 "suppressing access_place error when borrow doesn't live long enough for {:?}",
726 self.access_place_error_reported
728 base: root_place.base.clone(),
729 projection: root_place.projection.clone(),
732 if let StorageDeadOrDrop::Destructor(dropped_ty) =
733 self.classify_drop_access_kind(borrow.borrowed_place.as_ref())
735 // If a borrow of path `B` conflicts with drop of `D` (and
736 // we're not in the uninteresting case where `B` is a
737 // prefix of `D`), then report this as a more interesting
738 // destructor conflict.
739 if !borrow.borrowed_place.as_ref().is_prefix_of(place_span.0.as_ref()) {
740 self.report_borrow_conflicts_with_destructor(
741 location, borrow, place_span, kind, dropped_ty,
747 let place_desc = self.describe_place(borrow.borrowed_place.as_ref());
749 let kind_place = kind.filter(|_| place_desc.is_some()).map(|k| (k, place_span.0));
750 let explanation = self.explain_why_borrow_contains_point(location, &borrow, kind_place);
752 let err = match (place_desc, explanation) {
753 (Some(_), _) if self.is_place_thread_local(root_place) => {
754 self.report_thread_local_value_does_not_live_long_enough(drop_span, borrow_span)
756 // If the outlives constraint comes from inside the closure,
761 // Box::new(|| y) as Box<Fn() -> &'static i32>
763 // then just use the normal error. The closure isn't escaping
764 // and `move` will not help here.
767 BorrowExplanation::MustBeValidFor {
768 category: category @ ConstraintCategory::Return,
777 BorrowExplanation::MustBeValidFor {
778 category: category @ ConstraintCategory::CallArgument,
784 ) if borrow_spans.for_closure() => self.report_escaping_closure_capture(
785 borrow_spans.args_or_use(),
790 &format!("`{}`", name),
794 BorrowExplanation::MustBeValidFor {
795 category: ConstraintCategory::Assignment,
797 region_name: RegionName {
798 source: RegionNameSource::AnonRegionFromUpvar(upvar_span, ref upvar_name),
804 ) => self.report_escaping_data(borrow_span, name, upvar_span, upvar_name, span),
805 (Some(name), explanation) => self.report_local_value_does_not_live_long_enough(
813 (None, explanation) => self.report_temporary_value_does_not_live_long_enough(
823 err.buffer(&mut self.errors_buffer);
826 fn report_local_value_does_not_live_long_enough(
830 borrow: &BorrowData<'tcx>,
832 borrow_spans: UseSpans,
833 explanation: BorrowExplanation,
834 ) -> DiagnosticBuilder<'cx> {
836 "report_local_value_does_not_live_long_enough(\
837 {:?}, {:?}, {:?}, {:?}, {:?}\
839 location, name, borrow, drop_span, borrow_spans
842 let borrow_span = borrow_spans.var_or_use();
843 if let BorrowExplanation::MustBeValidFor {
850 if let Some(diag) = self.try_report_cannot_return_reference_to_local(
855 opt_place_desc.as_ref(),
861 let mut err = self.path_does_not_live_long_enough(
863 &format!("`{}`", name),
866 if let Some(annotation) = self.annotate_argument_and_return_for_borrow(borrow) {
867 let region_name = annotation.emit(self, &mut err);
871 format!("`{}` would have to be valid for `{}`...", name, region_name),
874 if let Some(fn_hir_id) = self.infcx.tcx.hir().as_local_hir_id(self.mir_def_id) {
878 "...but `{}` will be dropped here, when the function `{}` returns",
880 self.infcx.tcx.hir().name(fn_hir_id),
885 "functions cannot return a borrow to data owned within the function's scope, \
886 functions can only return borrows to data passed as arguments",
889 "to learn more, visit <https://doc.rust-lang.org/book/ch04-02-\
890 references-and-borrowing.html#dangling-references>",
895 format!("...but `{}` dropped here while still borrowed", name),
899 if let BorrowExplanation::MustBeValidFor { .. } = explanation {
901 explanation.add_explanation_to_diagnostic(
910 err.span_label(borrow_span, "borrowed value does not live long enough");
913 format!("`{}` dropped here while still borrowed", name),
916 let within = if borrow_spans.for_generator() {
922 borrow_spans.args_span_label(
924 format!("value captured here{}", within),
927 explanation.add_explanation_to_diagnostic(
928 self.infcx.tcx, self.body, &mut err, "", None);
934 fn report_borrow_conflicts_with_destructor(
937 borrow: &BorrowData<'tcx>,
938 (place, drop_span): (&Place<'tcx>, Span),
939 kind: Option<WriteKind>,
940 dropped_ty: Ty<'tcx>,
943 "report_borrow_conflicts_with_destructor(\
944 {:?}, {:?}, ({:?}, {:?}), {:?}\
946 location, borrow, place, drop_span, kind,
949 let borrow_spans = self.retrieve_borrow_spans(borrow);
950 let borrow_span = borrow_spans.var_or_use();
952 let mut err = self.cannot_borrow_across_destructor(borrow_span);
954 let what_was_dropped = match self.describe_place(place.as_ref()) {
955 Some(name) => format!("`{}`", name.as_str()),
956 None => String::from("temporary value"),
959 let label = match self.describe_place(borrow.borrowed_place.as_ref()) {
960 Some(borrowed) => format!(
961 "here, drop of {D} needs exclusive access to `{B}`, \
962 because the type `{T}` implements the `Drop` trait",
963 D = what_was_dropped,
968 "here is drop of {D}; whose type `{T}` implements the `Drop` trait",
969 D = what_was_dropped,
973 err.span_label(drop_span, label);
975 // Only give this note and suggestion if they could be relevant.
977 self.explain_why_borrow_contains_point(location, borrow, kind.map(|k| (k, place)));
979 BorrowExplanation::UsedLater { .. }
980 | BorrowExplanation::UsedLaterWhenDropped { .. } => {
981 err.note("consider using a `let` binding to create a longer lived value");
986 explanation.add_explanation_to_diagnostic(self.infcx.tcx, self.body, &mut err, "", None);
988 err.buffer(&mut self.errors_buffer);
991 fn report_thread_local_value_does_not_live_long_enough(
995 ) -> DiagnosticBuilder<'cx> {
997 "report_thread_local_value_does_not_live_long_enough(\
1000 drop_span, borrow_span
1003 let mut err = self.thread_local_value_does_not_live_long_enough(borrow_span);
1007 "thread-local variables cannot be borrowed beyond the end of the function",
1009 err.span_label(drop_span, "end of enclosing function is here");
1014 fn report_temporary_value_does_not_live_long_enough(
1017 borrow: &BorrowData<'tcx>,
1019 borrow_spans: UseSpans,
1021 explanation: BorrowExplanation,
1022 ) -> DiagnosticBuilder<'cx> {
1024 "report_temporary_value_does_not_live_long_enough(\
1025 {:?}, {:?}, {:?}, {:?}\
1027 location, borrow, drop_span, proper_span
1030 if let BorrowExplanation::MustBeValidFor {
1033 from_closure: false,
1036 if let Some(diag) = self.try_report_cannot_return_reference_to_local(
1047 let mut err = self.temporary_value_borrowed_for_too_long(proper_span);
1050 "creates a temporary which is freed while still in use",
1054 "temporary value is freed at the end of this statement",
1058 BorrowExplanation::UsedLater(..)
1059 | BorrowExplanation::UsedLaterInLoop(..)
1060 | BorrowExplanation::UsedLaterWhenDropped { .. } => {
1061 // Only give this note and suggestion if it could be relevant.
1062 err.note("consider using a `let` binding to create a longer lived value");
1066 explanation.add_explanation_to_diagnostic(self.infcx.tcx, self.body, &mut err, "", None);
1068 let within = if borrow_spans.for_generator() {
1074 borrow_spans.args_span_label(
1076 format!("value captured here{}", within),
1082 fn try_report_cannot_return_reference_to_local(
1084 borrow: &BorrowData<'tcx>,
1087 category: ConstraintCategory,
1088 opt_place_desc: Option<&String>,
1089 ) -> Option<DiagnosticBuilder<'cx>> {
1090 let return_kind = match category {
1091 ConstraintCategory::Return => "return",
1092 ConstraintCategory::Yield => "yield",
1096 // FIXME use a better heuristic than Spans
1097 let reference_desc = if return_span == self.body.source_info(borrow.reserve_location).span {
1103 let (place_desc, note) = if let Some(place_desc) = opt_place_desc {
1104 let local_kind = match borrow.borrowed_place {
1106 base: PlaceBase::Local(local),
1109 match self.body.local_kind(local) {
1110 LocalKind::ReturnPointer
1111 | LocalKind::Temp => bug!("temporary or return pointer with a name"),
1112 LocalKind::Var => "local variable ",
1114 if !self.upvars.is_empty()
1115 && local == Local::new(1) => {
1116 "variable captured by `move` "
1119 "function parameter "
1126 format!("{}`{}`", local_kind, place_desc),
1127 format!("`{}` is borrowed here", place_desc),
1130 let root_place = self.prefixes(borrow.borrowed_place.as_ref(),
1134 let local = if let PlaceRef {
1135 base: PlaceBase::Local(local),
1140 bug!("try_report_cannot_return_reference_to_local: not a local")
1142 match self.body.local_kind(*local) {
1143 LocalKind::ReturnPointer | LocalKind::Temp => {
1145 "temporary value".to_string(),
1146 "temporary value created here".to_string(),
1151 "function parameter".to_string(),
1152 "function parameter borrowed here".to_string(),
1155 LocalKind::Var => bug!("local variable without a name"),
1159 let mut err = self.cannot_return_reference_to_local(
1166 if return_span != borrow_span {
1167 err.span_label(borrow_span, note);
1173 fn report_escaping_closure_capture(
1177 fr_name: &RegionName,
1178 category: ConstraintCategory,
1179 constraint_span: Span,
1181 ) -> DiagnosticBuilder<'cx> {
1182 let tcx = self.infcx.tcx;
1184 let mut err = self.cannot_capture_in_long_lived_closure(
1190 let suggestion = match tcx.sess.source_map().span_to_snippet(args_span) {
1191 Ok(string) => format!("move {}", string),
1192 Err(_) => "move |<args>| <body>".to_string()
1195 err.span_suggestion(
1197 &format!("to force the closure to take ownership of {} (and any \
1198 other referenced variables), use the `move` keyword",
1201 Applicability::MachineApplicable,
1205 ConstraintCategory::Return => {
1206 err.span_note(constraint_span, "closure is returned here");
1208 ConstraintCategory::CallArgument => {
1209 fr_name.highlight_region_name(&mut err);
1212 &format!("function requires argument type to outlive `{}`", fr_name),
1215 _ => bug!("report_escaping_closure_capture called with unexpected constraint \
1216 category: `{:?}`", category),
1221 fn report_escaping_data(
1224 name: &Option<String>,
1228 ) -> DiagnosticBuilder<'cx> {
1229 let tcx = self.infcx.tcx;
1231 let escapes_from = if tcx.is_closure(self.mir_def_id) {
1232 let tables = tcx.typeck_tables_of(self.mir_def_id);
1233 let mir_hir_id = tcx.hir().def_index_to_hir_id(self.mir_def_id.index);
1234 match tables.node_type(mir_hir_id).sty {
1235 ty::Closure(..) => "closure",
1236 ty::Generator(..) => "generator",
1237 _ => bug!("Closure body doesn't have a closure or generator type"),
1243 let mut err = borrowck_errors::borrowed_data_escapes_closure(
1252 "`{}` is declared here, outside of the {} body",
1253 upvar_name, escapes_from
1260 "borrow is only valid in the {} body",
1265 if let Some(name) = name {
1268 format!("reference to `{}` escapes the {} body here", name, escapes_from),
1273 format!("reference escapes the {} body here", escapes_from),
1280 fn get_moved_indexes(&mut self, location: Location, mpi: MovePathIndex) -> Vec<MoveSite> {
1281 let body = self.body;
1283 let mut stack = Vec::new();
1284 stack.extend(body.predecessor_locations(location).map(|predecessor| {
1285 let is_back_edge = location.dominates(predecessor, &self.dominators);
1286 (predecessor, is_back_edge)
1289 let mut visited = FxHashSet::default();
1290 let mut result = vec![];
1292 'dfs: while let Some((location, is_back_edge)) = stack.pop() {
1294 "report_use_of_moved_or_uninitialized: (current_location={:?}, back_edge={})",
1295 location, is_back_edge
1298 if !visited.insert(location) {
1303 let stmt_kind = body[location.block]
1305 .get(location.statement_index)
1307 if let Some(StatementKind::StorageDead(..)) = stmt_kind {
1308 // this analysis only tries to find moves explicitly
1309 // written by the user, so we ignore the move-outs
1310 // created by `StorageDead` and at the beginning
1313 // If we are found a use of a.b.c which was in error, then we want to look for
1314 // moves not only of a.b.c but also a.b and a.
1316 // Note that the moves data already includes "parent" paths, so we don't have to
1317 // worry about the other case: that is, if there is a move of a.b.c, it is already
1318 // marked as a move of a.b and a as well, so we will generate the correct errors
1320 let mut mpis = vec![mpi];
1321 let move_paths = &self.move_data.move_paths;
1322 mpis.extend(move_paths[mpi].parents(move_paths));
1324 for moi in &self.move_data.loc_map[location] {
1325 debug!("report_use_of_moved_or_uninitialized: moi={:?}", moi);
1326 if mpis.contains(&self.move_data.moves[*moi].path) {
1327 debug!("report_use_of_moved_or_uninitialized: found");
1328 result.push(MoveSite {
1330 traversed_back_edge: is_back_edge,
1333 // Strictly speaking, we could continue our DFS here. There may be
1334 // other moves that can reach the point of error. But it is kind of
1335 // confusing to highlight them.
1343 // drop(a); // <-- current point of error
1346 // Because we stop the DFS here, we only highlight `let c = a`,
1347 // and not `let b = a`. We will of course also report an error at
1348 // `let c = a` which highlights `let b = a` as the move.
1355 let mut any_match = false;
1356 drop_flag_effects::for_location_inits(
1371 stack.extend(body.predecessor_locations(location).map(|predecessor| {
1372 let back_edge = location.dominates(predecessor, &self.dominators);
1373 (predecessor, is_back_edge || back_edge)
1380 pub(super) fn report_illegal_mutation_of_borrowed(
1383 (place, span): (&Place<'tcx>, Span),
1384 loan: &BorrowData<'tcx>,
1386 let loan_spans = self.retrieve_borrow_spans(loan);
1387 let loan_span = loan_spans.args_or_use();
1389 if loan.kind == BorrowKind::Shallow {
1390 let mut err = self.cannot_mutate_in_match_guard(
1393 &self.describe_place(place.as_ref()).unwrap_or_else(|| "_".to_owned()),
1396 loan_spans.var_span_label(
1398 format!("borrow occurs due to use{}", loan_spans.describe()),
1401 err.buffer(&mut self.errors_buffer);
1406 let mut err = self.cannot_assign_to_borrowed(
1409 &self.describe_place(place.as_ref()).unwrap_or_else(|| "_".to_owned()),
1412 loan_spans.var_span_label(
1414 format!("borrow occurs due to use{}", loan_spans.describe()),
1417 self.explain_why_borrow_contains_point(location, loan, None)
1418 .add_explanation_to_diagnostic(self.infcx.tcx, self.body, &mut err, "", None);
1420 err.buffer(&mut self.errors_buffer);
1423 /// Reports an illegal reassignment; for example, an assignment to
1424 /// (part of) a non-`mut` local that occurs potentially after that
1425 /// local has already been initialized. `place` is the path being
1426 /// assigned; `err_place` is a place providing a reason why
1427 /// `place` is not mutable (e.g., the non-`mut` local `x` in an
1428 /// assignment to `x.f`).
1429 pub(super) fn report_illegal_reassignment(
1431 _location: Location,
1432 (place, span): (&Place<'tcx>, Span),
1433 assigned_span: Span,
1434 err_place: &Place<'tcx>,
1436 let (from_arg, local_decl) = if let Place {
1437 base: PlaceBase::Local(local),
1440 if let LocalKind::Arg = self.body.local_kind(local) {
1441 (true, Some(&self.body.local_decls[local]))
1443 (false, Some(&self.body.local_decls[local]))
1449 // If root local is initialized immediately (everything apart from let
1450 // PATTERN;) then make the error refer to that local, rather than the
1451 // place being assigned later.
1452 let (place_description, assigned_span) = match local_decl {
1454 is_user_variable: Some(ClearCrossCrate::Clear),
1459 Some(ClearCrossCrate::Set(BindingForm::Var(VarBindingForm {
1460 opt_match_place: None,
1466 is_user_variable: None,
1469 | None => (self.describe_place(place.as_ref()), assigned_span),
1470 Some(decl) => (self.describe_place(err_place.as_ref()), decl.source_info.span),
1473 let mut err = self.cannot_reassign_immutable(
1475 place_description.as_ref().map(AsRef::as_ref).unwrap_or("_"),
1478 let msg = if from_arg {
1479 "cannot assign to immutable argument"
1481 "cannot assign twice to immutable variable"
1483 if span != assigned_span {
1485 let value_msg = match place_description {
1486 Some(name) => format!("`{}`", name),
1487 None => "value".to_owned(),
1489 err.span_label(assigned_span, format!("first assignment to {}", value_msg));
1492 if let Some(decl) = local_decl {
1493 if let Some(name) = decl.name {
1494 if decl.can_be_made_mutable() {
1495 err.span_suggestion(
1496 decl.source_info.span,
1497 "make this binding mutable",
1498 format!("mut {}", name),
1499 Applicability::MachineApplicable,
1504 err.span_label(span, msg);
1505 err.buffer(&mut self.errors_buffer);
1508 fn classify_drop_access_kind(&self, place: PlaceRef<'cx, 'tcx>) -> StorageDeadOrDrop<'tcx> {
1509 let tcx = self.infcx.tcx;
1510 match place.projection {
1512 StorageDeadOrDrop::LocalStorageDead
1514 Some(box Projection { ref base, ref elem }) => {
1515 let base_access = self.classify_drop_access_kind(PlaceRef {
1520 ProjectionElem::Deref => match base_access {
1521 StorageDeadOrDrop::LocalStorageDead
1522 | StorageDeadOrDrop::BoxedStorageDead => {
1524 Place::ty_from(&place.base, base, self.body, tcx).ty.is_box(),
1525 "Drop of value behind a reference or raw pointer"
1527 StorageDeadOrDrop::BoxedStorageDead
1529 StorageDeadOrDrop::Destructor(_) => base_access,
1531 ProjectionElem::Field(..) | ProjectionElem::Downcast(..) => {
1532 let base_ty = Place::ty_from(&place.base, base, self.body, tcx).ty;
1534 ty::Adt(def, _) if def.has_dtor(tcx) => {
1535 // Report the outermost adt with a destructor
1537 StorageDeadOrDrop::Destructor(_) => base_access,
1538 StorageDeadOrDrop::LocalStorageDead
1539 | StorageDeadOrDrop::BoxedStorageDead => {
1540 StorageDeadOrDrop::Destructor(base_ty)
1548 ProjectionElem::ConstantIndex { .. }
1549 | ProjectionElem::Subslice { .. }
1550 | ProjectionElem::Index(_) => base_access,
1556 /// Annotate argument and return type of function and closure with (synthesized) lifetime for
1557 /// borrow of local value that does not live long enough.
1558 fn annotate_argument_and_return_for_borrow(
1560 borrow: &BorrowData<'tcx>,
1561 ) -> Option<AnnotatedBorrowFnSignature<'tcx>> {
1562 // Define a fallback for when we can't match a closure.
1564 let is_closure = self.infcx.tcx.is_closure(self.mir_def_id);
1568 let ty = self.infcx.tcx.type_of(self.mir_def_id);
1570 ty::FnDef(_, _) | ty::FnPtr(_) => self.annotate_fn_sig(
1572 self.infcx.tcx.fn_sig(self.mir_def_id),
1579 // In order to determine whether we need to annotate, we need to check whether the reserve
1580 // place was an assignment into a temporary.
1582 // If it was, we check whether or not that temporary is eventually assigned into the return
1583 // place. If it was, we can add annotations about the function's return type and arguments
1584 // and it'll make sense.
1585 let location = borrow.reserve_location;
1587 "annotate_argument_and_return_for_borrow: location={:?}",
1590 if let Some(&Statement { kind: StatementKind::Assign(ref reservation, _), ..})
1591 = &self.body[location.block].statements.get(location.statement_index)
1594 "annotate_argument_and_return_for_borrow: reservation={:?}",
1597 // Check that the initial assignment of the reserve location is into a temporary.
1598 let mut target = *match reservation {
1600 base: PlaceBase::Local(local),
1602 } if self.body.local_kind(*local) == LocalKind::Temp => local,
1606 // Next, look through the rest of the block, checking if we are assigning the
1607 // `target` (that is, the place that contains our borrow) to anything.
1608 let mut annotated_closure = None;
1609 for stmt in &self.body[location.block].statements[location.statement_index + 1..] {
1611 "annotate_argument_and_return_for_borrow: target={:?} stmt={:?}",
1614 if let StatementKind::Assign(
1616 base: PlaceBase::Local(assigned_to),
1622 "annotate_argument_and_return_for_borrow: assigned_to={:?} \
1626 // Check if our `target` was captured by a closure.
1627 if let Rvalue::Aggregate(
1628 box AggregateKind::Closure(def_id, substs),
1632 for operand in operands {
1633 let assigned_from = match operand {
1634 Operand::Copy(assigned_from) | Operand::Move(assigned_from) => {
1640 "annotate_argument_and_return_for_borrow: assigned_from={:?}",
1644 // Find the local from the operand.
1645 let assigned_from_local = match assigned_from.local_or_deref_local() {
1646 Some(local) => local,
1650 if assigned_from_local != target {
1654 // If a closure captured our `target` and then assigned
1655 // into a place then we should annotate the closure in
1656 // case it ends up being assigned into the return place.
1657 annotated_closure = self.annotate_fn_sig(
1659 self.infcx.closure_sig(*def_id, *substs),
1662 "annotate_argument_and_return_for_borrow: \
1663 annotated_closure={:?} assigned_from_local={:?} \
1665 annotated_closure, assigned_from_local, assigned_to
1668 if *assigned_to == mir::RETURN_PLACE {
1669 // If it was assigned directly into the return place, then
1671 return annotated_closure;
1673 // Otherwise, update the target.
1674 target = *assigned_to;
1678 // If none of our closure's operands matched, then skip to the next
1683 // Otherwise, look at other types of assignment.
1684 let assigned_from = match rvalue {
1685 Rvalue::Ref(_, _, assigned_from) => assigned_from,
1686 Rvalue::Use(operand) => match operand {
1687 Operand::Copy(assigned_from) | Operand::Move(assigned_from) => {
1695 "annotate_argument_and_return_for_borrow: \
1696 assigned_from={:?}",
1700 // Find the local from the rvalue.
1701 let assigned_from_local = match assigned_from.local_or_deref_local() {
1702 Some(local) => local,
1706 "annotate_argument_and_return_for_borrow: \
1707 assigned_from_local={:?}",
1708 assigned_from_local,
1711 // Check if our local matches the target - if so, we've assigned our
1712 // borrow to a new place.
1713 if assigned_from_local != target {
1717 // If we assigned our `target` into a new place, then we should
1718 // check if it was the return place.
1720 "annotate_argument_and_return_for_borrow: \
1721 assigned_from_local={:?} assigned_to={:?}",
1722 assigned_from_local, assigned_to
1724 if *assigned_to == mir::RETURN_PLACE {
1725 // If it was then return the annotated closure if there was one,
1726 // else, annotate this function.
1727 return annotated_closure.or_else(fallback);
1730 // If we didn't assign into the return place, then we just update
1732 target = *assigned_to;
1736 // Check the terminator if we didn't find anything in the statements.
1737 let terminator = &self.body[location.block].terminator();
1739 "annotate_argument_and_return_for_borrow: target={:?} terminator={:?}",
1742 if let TerminatorKind::Call {
1743 destination: Some((Place {
1744 base: PlaceBase::Local(assigned_to),
1749 } = &terminator.kind
1752 "annotate_argument_and_return_for_borrow: assigned_to={:?} args={:?}",
1755 for operand in args {
1756 let assigned_from = match operand {
1757 Operand::Copy(assigned_from) | Operand::Move(assigned_from) => {
1763 "annotate_argument_and_return_for_borrow: assigned_from={:?}",
1767 if let Some(assigned_from_local) = assigned_from.local_or_deref_local() {
1769 "annotate_argument_and_return_for_borrow: assigned_from_local={:?}",
1770 assigned_from_local,
1773 if *assigned_to == mir::RETURN_PLACE && assigned_from_local == target {
1774 return annotated_closure.or_else(fallback);
1781 // If we haven't found an assignment into the return place, then we need not add
1783 debug!("annotate_argument_and_return_for_borrow: none found");
1787 /// Annotate the first argument and return type of a function signature if they are
1792 sig: ty::PolyFnSig<'tcx>,
1793 ) -> Option<AnnotatedBorrowFnSignature<'tcx>> {
1794 debug!("annotate_fn_sig: did={:?} sig={:?}", did, sig);
1795 let is_closure = self.infcx.tcx.is_closure(did);
1796 let fn_hir_id = self.infcx.tcx.hir().as_local_hir_id(did)?;
1797 let fn_decl = self.infcx.tcx.hir().fn_decl_by_hir_id(fn_hir_id)?;
1799 // We need to work out which arguments to highlight. We do this by looking
1800 // at the return type, where there are three cases:
1802 // 1. If there are named arguments, then we should highlight the return type and
1803 // highlight any of the arguments that are also references with that lifetime.
1804 // If there are no arguments that have the same lifetime as the return type,
1805 // then don't highlight anything.
1806 // 2. The return type is a reference with an anonymous lifetime. If this is
1807 // the case, then we can take advantage of (and teach) the lifetime elision
1810 // We know that an error is being reported. So the arguments and return type
1811 // must satisfy the elision rules. Therefore, if there is a single argument
1812 // then that means the return type and first (and only) argument have the same
1813 // lifetime and the borrow isn't meeting that, we can highlight the argument
1816 // If there are multiple arguments then the first argument must be self (else
1817 // it would not satisfy the elision rules), so we can highlight self and the
1819 // 3. The return type is not a reference. In this case, we don't highlight
1821 let return_ty = sig.output();
1822 match return_ty.skip_binder().sty {
1823 ty::Ref(return_region, _, _) if return_region.has_name() && !is_closure => {
1824 // This is case 1 from above, return type is a named reference so we need to
1825 // search for relevant arguments.
1826 let mut arguments = Vec::new();
1827 for (index, argument) in sig.inputs().skip_binder().iter().enumerate() {
1828 if let ty::Ref(argument_region, _, _) = argument.sty {
1829 if argument_region == return_region {
1830 // Need to use the `rustc::ty` types to compare against the
1831 // `return_region`. Then use the `rustc::hir` type to get only
1832 // the lifetime span.
1833 if let hir::TyKind::Rptr(lifetime, _) = &fn_decl.inputs[index].node {
1834 // With access to the lifetime, we can get
1836 arguments.push((*argument, lifetime.span));
1838 bug!("ty type is a ref but hir type is not");
1844 // We need to have arguments. This shouldn't happen, but it's worth checking.
1845 if arguments.is_empty() {
1849 // We use a mix of the HIR and the Ty types to get information
1850 // as the HIR doesn't have full types for closure arguments.
1851 let return_ty = *sig.output().skip_binder();
1852 let mut return_span = fn_decl.output.span();
1853 if let hir::FunctionRetTy::Return(ty) = &fn_decl.output {
1854 if let hir::TyKind::Rptr(lifetime, _) = ty.node {
1855 return_span = lifetime.span;
1859 Some(AnnotatedBorrowFnSignature::NamedFunction {
1865 ty::Ref(_, _, _) if is_closure => {
1866 // This is case 2 from above but only for closures, return type is anonymous
1867 // reference so we select
1868 // the first argument.
1869 let argument_span = fn_decl.inputs.first()?.span;
1870 let argument_ty = sig.inputs().skip_binder().first()?;
1872 // Closure arguments are wrapped in a tuple, so we need to get the first
1874 if let ty::Tuple(elems) = argument_ty.sty {
1875 let argument_ty = elems.first()?.expect_ty();
1876 if let ty::Ref(_, _, _) = argument_ty.sty {
1877 return Some(AnnotatedBorrowFnSignature::Closure {
1886 ty::Ref(_, _, _) => {
1887 // This is also case 2 from above but for functions, return type is still an
1888 // anonymous reference so we select the first argument.
1889 let argument_span = fn_decl.inputs.first()?.span;
1890 let argument_ty = sig.inputs().skip_binder().first()?;
1892 let return_span = fn_decl.output.span();
1893 let return_ty = *sig.output().skip_binder();
1895 // We expect the first argument to be a reference.
1896 match argument_ty.sty {
1897 ty::Ref(_, _, _) => {}
1901 Some(AnnotatedBorrowFnSignature::AnonymousFunction {
1909 // This is case 3 from above, return type is not a reference so don't highlight
1918 enum AnnotatedBorrowFnSignature<'tcx> {
1920 arguments: Vec<(Ty<'tcx>, Span)>,
1921 return_ty: Ty<'tcx>,
1925 argument_ty: Ty<'tcx>,
1926 argument_span: Span,
1927 return_ty: Ty<'tcx>,
1931 argument_ty: Ty<'tcx>,
1932 argument_span: Span,
1936 impl<'tcx> AnnotatedBorrowFnSignature<'tcx> {
1937 /// Annotate the provided diagnostic with information about borrow from the fn signature that
1941 cx: &mut MirBorrowckCtxt<'_, 'tcx>,
1942 diag: &mut DiagnosticBuilder<'_>,
1945 AnnotatedBorrowFnSignature::Closure {
1951 format!("has type `{}`", cx.get_name_for_ty(argument_ty, 0)),
1954 cx.get_region_name_for_ty(argument_ty, 0)
1956 AnnotatedBorrowFnSignature::AnonymousFunction {
1962 let argument_ty_name = cx.get_name_for_ty(argument_ty, 0);
1963 diag.span_label(*argument_span, format!("has type `{}`", argument_ty_name));
1965 let return_ty_name = cx.get_name_for_ty(return_ty, 0);
1966 let types_equal = return_ty_name == argument_ty_name;
1971 if types_equal { "also " } else { "" },
1977 "argument and return type have the same lifetime due to lifetime elision rules",
1980 "to learn more, visit <https://doc.rust-lang.org/book/ch10-03-\
1981 lifetime-syntax.html#lifetime-elision>",
1984 cx.get_region_name_for_ty(return_ty, 0)
1986 AnnotatedBorrowFnSignature::NamedFunction {
1991 // Region of return type and arguments checked to be the same earlier.
1992 let region_name = cx.get_region_name_for_ty(return_ty, 0);
1993 for (_, argument_span) in arguments {
1994 diag.span_label(*argument_span, format!("has lifetime `{}`", region_name));
1999 format!("also has lifetime `{}`", region_name,),
2003 "use data from the highlighted arguments which match the `{}` lifetime of \