Skip to content

Commit a0cee0a

Browse files
committed
remove old var_span_path_only
doc comment
1 parent e636af7 commit a0cee0a

File tree

4 files changed

+99
-17
lines changed

4 files changed

+99
-17
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+3-12
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
@@ -678,10 +672,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
678672
err.span_label(borrow_span, format!("borrow of {} occurs here", borrow_msg));
679673
err.span_label(span, format!("move out of {} occurs here", value_msg));
680674

681-
borrow_spans.var_span_label_path_only(
682-
&mut err,
683-
format!("borrow occurs due to use{}", borrow_spans.describe()),
684-
);
675+
borrow_spans.var_path_only_subdiag(&mut err, crate::InitializationRequiringAction::Borrow);
685676

686677
move_spans.var_span_label(
687678
&mut err,

compiler/rustc_borrowck/src/diagnostics/mod.rs

+28-5
Original file line numberDiff line numberDiff line change
@@ -595,11 +595,34 @@ impl UseSpans<'_> {
595595
}
596596
}
597597

598-
// Add a span label to the use of the captured variable, if it exists.
599-
// only adds label to the `path_span`
600-
pub(super) fn var_span_label_path_only(self, err: &mut Diagnostic, message: impl Into<String>) {
601-
if let UseSpans::ClosureUse { path_span, .. } = self {
602-
err.span_label(path_span, message);
598+
/// Add a span label to the use of the captured variable, if it exists.
599+
/// only adds label to the `path_span`
600+
pub(super) fn var_path_only_subdiag(
601+
self,
602+
err: &mut Diagnostic,
603+
action: crate::InitializationRequiringAction,
604+
) {
605+
use crate::session_diagnostics::CaptureVarPathUseCause::*;
606+
use crate::InitializationRequiringAction::*;
607+
if let UseSpans::ClosureUse { generator_kind, path_span, .. } = self {
608+
match generator_kind {
609+
Some(_) => {
610+
err.subdiagnostic(match action {
611+
Borrow => BorrowInGenerator { path_span },
612+
MatchOn | Use => UseInGenerator { path_span },
613+
Assignment => AssignInGenerator { path_span },
614+
PartialAssignment => AssignPartInGenerator { path_span },
615+
});
616+
}
617+
None => {
618+
err.subdiagnostic(match action {
619+
Borrow => BorrowInClosure { path_span },
620+
MatchOn | Use => UseInClosure { path_span },
621+
Assignment => AssignInClosure { path_span },
622+
PartialAssignment => AssignPartInClosure { path_span },
623+
});
624+
}
625+
}
603626
}
604627
}
605628

compiler/rustc_borrowck/src/session_diagnostics.rs

+44
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,47 @@ pub(crate) enum CaptureVarCause {
178178
var_span: Span,
179179
},
180180
}
181+
182+
#[derive(Subdiagnostic)]
183+
pub(crate) enum CaptureVarPathUseCause {
184+
#[label(borrowck_borrow_due_to_use_generator)]
185+
BorrowInGenerator {
186+
#[primary_span]
187+
path_span: Span,
188+
},
189+
#[label(borrowck_use_due_to_use_generator)]
190+
UseInGenerator {
191+
#[primary_span]
192+
path_span: Span,
193+
},
194+
#[label(borrowck_assign_due_to_use_generator)]
195+
AssignInGenerator {
196+
#[primary_span]
197+
path_span: Span,
198+
},
199+
#[label(borrowck_assign_part_due_to_use_generator)]
200+
AssignPartInGenerator {
201+
#[primary_span]
202+
path_span: Span,
203+
},
204+
#[label(borrowck_borrow_due_to_use_closure)]
205+
BorrowInClosure {
206+
#[primary_span]
207+
path_span: Span,
208+
},
209+
#[label(borrowck_use_due_to_use_closure)]
210+
UseInClosure {
211+
#[primary_span]
212+
path_span: Span,
213+
},
214+
#[label(borrowck_assign_due_to_use_closure)]
215+
AssignInClosure {
216+
#[primary_span]
217+
path_span: Span,
218+
},
219+
#[label(borrowck_assign_part_due_to_use_closure)]
220+
AssignPartInClosure {
221+
#[primary_span]
222+
path_span: Span,
223+
},
224+
}

compiler/rustc_error_messages/locales/en-US/borrowck.ftl

+24
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,27 @@ borrowck_var_borrow_by_use_place_in_closure =
7070
7171
borrowck_var_borrow_by_use_place =
7272
borrow occurs due to use of {$place}
73+
74+
borrowck_borrow_due_to_use_generator =
75+
borrow occurs due to use in generator
76+
77+
borrowck_use_due_to_use_generator =
78+
use occurs due to use in generator
79+
80+
borrowck_assign_due_to_use_generator =
81+
assign occurs due to use in generator
82+
83+
borrowck_assign_part_due_to_use_generator =
84+
assign to part occurs due to use in generator
85+
86+
borrowck_borrow_due_to_use_closure =
87+
borrow occurs due to use in closure
88+
89+
borrowck_use_due_to_use_closure =
90+
use occurs due to use in closure
91+
92+
borrowck_assign_due_to_use_closure =
93+
assign occurs due to use in closure
94+
95+
borrowck_assign_part_due_to_use_closure =
96+
assign to part occurs due to use in closure

0 commit comments

Comments
 (0)