Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit a13809a

Browse files
authored
Rollup merge of rust-lang#103960 - AndyJado:var_path_only_diag, r=davidtwco
piece of diagnostic migrate r? `@davidtwco`
2 parents f00897e + 057d8e5 commit a13809a

32 files changed

+261
-60
lines changed

compiler/rustc_borrowck/src/borrow_set.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![deny(rustc::untranslatable_diagnostic)]
2+
#![deny(rustc::diagnostic_outside_of_impl)]
13
use crate::nll::ToRegionVid;
24
use crate::path_utils::allow_two_phase_borrow;
35
use crate::place_ext::PlaceExt;

compiler/rustc_borrowck/src/borrowck_errors.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,18 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
88
pub(crate) fn cannot_move_when_borrowed(
99
&self,
1010
span: Span,
11-
desc: &str,
11+
borrow_span: Span,
12+
place: &str,
13+
borrow_place: &str,
14+
value_place: &str,
1215
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
13-
struct_span_err!(self, span, E0505, "cannot move out of {} because it is borrowed", desc,)
16+
self.infcx.tcx.sess.create_err(crate::session_diagnostics::MoveBorrow {
17+
place,
18+
span,
19+
borrow_place,
20+
value_place,
21+
borrow_span,
22+
})
1423
}
1524

1625
pub(crate) fn cannot_use_when_mutably_borrowed(

compiler/rustc_borrowck/src/constraint_generation.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![deny(rustc::untranslatable_diagnostic)]
2+
#![deny(rustc::diagnostic_outside_of_impl)]
13
use rustc_infer::infer::InferCtxt;
24
use rustc_middle::mir::visit::TyContext;
35
use rustc_middle::mir::visit::Visitor;

compiler/rustc_borrowck/src/constraints/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#![deny(rustc::untranslatable_diagnostic)]
2+
#![deny(rustc::diagnostic_outside_of_impl)]
3+
14
use rustc_data_structures::graph::scc::Sccs;
25
use rustc_index::vec::IndexVec;
36
use rustc_middle::mir::ConstraintCategory;

compiler/rustc_borrowck/src/consumers.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![deny(rustc::untranslatable_diagnostic)]
2+
#![deny(rustc::diagnostic_outside_of_impl)]
13
//! This file provides API for compiler consumers.
24
35
use rustc_hir::def_id::LocalDefId;

compiler/rustc_borrowck/src/dataflow.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![deny(rustc::untranslatable_diagnostic)]
2+
#![deny(rustc::diagnostic_outside_of_impl)]
13
use rustc_data_structures::fx::FxHashMap;
24
use rustc_index::bit_set::BitSet;
35
use rustc_middle::mir::{self, BasicBlock, Body, Location, Place};

compiler/rustc_borrowck/src/def_use.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![deny(rustc::untranslatable_diagnostic)]
2+
#![deny(rustc::diagnostic_outside_of_impl)]
13
use rustc_middle::mir::visit::{
24
MutatingUseContext, NonMutatingUseContext, NonUseContext, PlaceContext,
35
};

compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#![deny(rustc::untranslatable_diagnostic)]
2+
#![deny(rustc::diagnostic_outside_of_impl)]
3+
14
use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed};
25
use rustc_infer::infer::canonical::Canonical;
36
use rustc_infer::infer::error_reporting::nice_region_error::NiceRegionError;

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
224224
}
225225
}
226226

227-
use_spans.var_span_label_path_only(
228-
&mut err,
229-
format!("{} occurs due to use{}", desired_action.as_noun(), use_spans.describe()),
230-
);
227+
use_spans.var_path_only_subdiag(&mut err, desired_action);
231228

232229
if !is_loop_move {
233230
err.span_label(
@@ -404,10 +401,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
404401
let used = desired_action.as_general_verb_in_past_tense();
405402
let mut err =
406403
struct_span_err!(self, span, E0381, "{used} binding {desc}{isnt_initialized}");
407-
use_spans.var_span_label_path_only(
408-
&mut err,
409-
format!("{} occurs due to use{}", desired_action.as_noun(), use_spans.describe()),
410-
);
404+
use_spans.var_path_only_subdiag(&mut err, desired_action);
411405

412406
if let InitializationRequiringAction::PartialAssignment
413407
| InitializationRequiringAction::Assignment = desired_action
@@ -673,16 +667,16 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
673667
let move_spans = self.move_spans(place.as_ref(), location);
674668
let span = move_spans.args_or_use();
675669

676-
let mut err =
677-
self.cannot_move_when_borrowed(span, &self.describe_any_place(place.as_ref()));
678-
err.span_label(borrow_span, format!("borrow of {} occurs here", borrow_msg));
679-
err.span_label(span, format!("move out of {} occurs here", value_msg));
680-
681-
borrow_spans.var_span_label_path_only(
682-
&mut err,
683-
format!("borrow occurs due to use{}", borrow_spans.describe()),
670+
let mut err = self.cannot_move_when_borrowed(
671+
span,
672+
borrow_span,
673+
&self.describe_any_place(place.as_ref()),
674+
&borrow_msg,
675+
&value_msg,
684676
);
685677

678+
borrow_spans.var_path_only_subdiag(&mut err, crate::InitializationRequiringAction::Borrow);
679+
686680
move_spans.var_span_label(
687681
&mut err,
688682
format!("move occurs due to use{}", move_spans.describe()),
@@ -724,22 +718,15 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
724718
borrow_span,
725719
&self.describe_any_place(borrow.borrowed_place.as_ref()),
726720
);
727-
borrow_spans.var_subdiag(
728-
&mut err,
729-
|var_span| {
730-
use crate::session_diagnostics::CaptureVarCause::*;
731-
let place = &borrow.borrowed_place;
732-
let desc_place = self.describe_any_place(place.as_ref());
733-
match borrow_spans {
734-
UseSpans::ClosureUse { generator_kind, .. } => match generator_kind {
735-
Some(_) => BorrowUsePlaceGenerator { place: desc_place, var_span },
736-
None => BorrowUsePlaceClosure { place: desc_place, var_span },
737-
},
738-
_ => BorrowUsePlace { place: desc_place, var_span },
739-
}
740-
},
741-
"mutable",
742-
);
721+
borrow_spans.var_subdiag(&mut err, Some(borrow.kind), |kind, var_span| {
722+
use crate::session_diagnostics::CaptureVarCause::*;
723+
let place = &borrow.borrowed_place;
724+
let desc_place = self.describe_any_place(place.as_ref());
725+
match kind {
726+
Some(_) => BorrowUsePlaceGenerator { place: desc_place, var_span },
727+
None => BorrowUsePlaceClosure { place: desc_place, var_span },
728+
}
729+
});
743730

744731
self.explain_why_borrow_contains_point(location, borrow, None)
745732
.add_explanation_to_diagnostic(

compiler/rustc_borrowck/src/diagnostics/find_all_local_uses.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#![deny(rustc::untranslatable_diagnostic)]
2+
#![deny(rustc::diagnostic_outside_of_impl)]
3+
14
use std::collections::BTreeSet;
25

36
use rustc_middle::mir::visit::{PlaceContext, Visitor};

0 commit comments

Comments
 (0)