Skip to content

Commit 7fc677b

Browse files
committed
(blessed to pass CI) eager translation question?
1 parent d79da22 commit 7fc677b

File tree

4 files changed

+54
-21
lines changed

4 files changed

+54
-21
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+17-20
Original file line numberDiff line numberDiff line change
@@ -925,27 +925,24 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
925925
}
926926
});
927927
} else {
928-
let borrow_place = &issued_borrow.borrowed_place;
929-
let borrow_place_desc = self.describe_any_place(borrow_place.as_ref());
930-
issued_spans.var_span_label(
931-
&mut err,
932-
format!(
933-
"first borrow occurs due to use of {}{}",
934-
borrow_place_desc,
935-
issued_spans.describe(),
936-
),
937-
issued_borrow.kind.describe_mutability(),
938-
);
928+
//FIXME: (blessed casue) I suppose this demands eager translate?
929+
issued_spans.var_subdiag(&mut err, Some(issued_borrow.kind), |kind, var_span| {
930+
use crate::session_diagnostics::CaptureVarCause::*;
931+
let borrow_place = &issued_borrow.borrowed_place;
932+
let borrow_place_desc = self.describe_any_place(borrow_place.as_ref());
933+
match kind {
934+
Some(_) => FirstBorrowUsePlaceGenerator { place: borrow_place_desc, var_span },
935+
None => FirstBorrowUsePlaceClosure { place: borrow_place_desc, var_span },
936+
}
937+
});
939938

940-
borrow_spans.var_span_label(
941-
&mut err,
942-
format!(
943-
"second borrow occurs due to use of {}{}",
944-
desc_place,
945-
borrow_spans.describe(),
946-
),
947-
gen_borrow_kind.describe_mutability(),
948-
);
939+
borrow_spans.var_subdiag(&mut err, Some(gen_borrow_kind), |kind, var_span| {
940+
use crate::session_diagnostics::CaptureVarCause::*;
941+
match kind {
942+
Some(_) => SecondBorrowUsePlaceGenerator { place: desc_place, var_span },
943+
None => SecondBorrowUsePlaceClosure { place: desc_place, var_span },
944+
}
945+
});
949946
}
950947

951948
if union_type_name != "" {

compiler/rustc_borrowck/src/session_diagnostics.rs

+24
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,30 @@ pub(crate) enum CaptureVarCause {
258258
#[primary_span]
259259
var_span: Span,
260260
},
261+
#[label(borrowck_var_first_borrow_by_use_place_in_generator)]
262+
FirstBorrowUsePlaceGenerator {
263+
place: String,
264+
#[primary_span]
265+
var_span: Span,
266+
},
267+
#[label(borrowck_var_first_borrow_by_use_place_in_closure)]
268+
FirstBorrowUsePlaceClosure {
269+
place: String,
270+
#[primary_span]
271+
var_span: Span,
272+
},
273+
#[label(borrowck_var_second_borrow_by_use_place_in_generator)]
274+
SecondBorrowUsePlaceGenerator {
275+
place: String,
276+
#[primary_span]
277+
var_span: Span,
278+
},
279+
#[label(borrowck_var_second_borrow_by_use_place_in_closure)]
280+
SecondBorrowUsePlaceClosure {
281+
place: String,
282+
#[primary_span]
283+
var_span: Span,
284+
},
261285
#[label(borrowck_var_mutable_borrow_by_use_place_in_closure)]
262286
MutableBorrowUsePlaceClosure {
263287
place: String,

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

+12
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,18 @@ borrowck_var_move_by_use_in_generator =
122122
borrowck_var_move_by_use_in_closure =
123123
move occurs due to use in closure
124124
125+
borrowck_var_first_borrow_by_use_place_in_generator =
126+
first borrow occurs due to use of {$place} in generator
127+
128+
borrowck_var_first_borrow_by_use_place_in_closure =
129+
first borrow occurs due to use of {$place} in closure
130+
131+
borrowck_var_second_borrow_by_use_place_in_generator =
132+
second borrow occurs due to use of {$place} in generator
133+
134+
borrowck_var_second_borrow_by_use_place_in_closure =
135+
second borrow occurs due to use of {$place} in closure
136+
125137
borrowck_var_mutable_borrow_by_use_place_in_closure =
126138
mutable borrow occurs due to use of {$place} in closure
127139

src/test/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-closures-mut-and-imm.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0502]: cannot borrow `p` as mutable because it is also borrowed as immuta
22
--> $DIR/borrowck-closures-mut-and-imm.rs:17:14
33
|
44
LL | let c2 = || p.y * 5;
5-
| -- --- first borrow occurs due to use of `p.y` in closure
5+
| -- --- first borrow occurs due to use of `p` in closure
66
| |
77
| immutable borrow occurs here
88
LL | let c1 = || {

0 commit comments

Comments
 (0)