Skip to content

Commit

Permalink
(blessed to pass CI) eager translation question?
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyJado committed Nov 14, 2022
1 parent d79da22 commit 7fc677b
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 21 deletions.
37 changes: 17 additions & 20 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -925,27 +925,24 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
}
});
} else {
let borrow_place = &issued_borrow.borrowed_place;
let borrow_place_desc = self.describe_any_place(borrow_place.as_ref());
issued_spans.var_span_label(
&mut err,
format!(
"first borrow occurs due to use of {}{}",
borrow_place_desc,
issued_spans.describe(),
),
issued_borrow.kind.describe_mutability(),
);
//FIXME: (blessed casue) I suppose this demands eager translate?
issued_spans.var_subdiag(&mut err, Some(issued_borrow.kind), |kind, var_span| {
use crate::session_diagnostics::CaptureVarCause::*;
let borrow_place = &issued_borrow.borrowed_place;
let borrow_place_desc = self.describe_any_place(borrow_place.as_ref());
match kind {
Some(_) => FirstBorrowUsePlaceGenerator { place: borrow_place_desc, var_span },
None => FirstBorrowUsePlaceClosure { place: borrow_place_desc, var_span },
}
});

borrow_spans.var_span_label(
&mut err,
format!(
"second borrow occurs due to use of {}{}",
desc_place,
borrow_spans.describe(),
),
gen_borrow_kind.describe_mutability(),
);
borrow_spans.var_subdiag(&mut err, Some(gen_borrow_kind), |kind, var_span| {
use crate::session_diagnostics::CaptureVarCause::*;
match kind {
Some(_) => SecondBorrowUsePlaceGenerator { place: desc_place, var_span },
None => SecondBorrowUsePlaceClosure { place: desc_place, var_span },
}
});
}

if union_type_name != "" {
Expand Down
24 changes: 24 additions & 0 deletions compiler/rustc_borrowck/src/session_diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,30 @@ pub(crate) enum CaptureVarCause {
#[primary_span]
var_span: Span,
},
#[label(borrowck_var_first_borrow_by_use_place_in_generator)]
FirstBorrowUsePlaceGenerator {
place: String,
#[primary_span]
var_span: Span,
},
#[label(borrowck_var_first_borrow_by_use_place_in_closure)]
FirstBorrowUsePlaceClosure {
place: String,
#[primary_span]
var_span: Span,
},
#[label(borrowck_var_second_borrow_by_use_place_in_generator)]
SecondBorrowUsePlaceGenerator {
place: String,
#[primary_span]
var_span: Span,
},
#[label(borrowck_var_second_borrow_by_use_place_in_closure)]
SecondBorrowUsePlaceClosure {
place: String,
#[primary_span]
var_span: Span,
},
#[label(borrowck_var_mutable_borrow_by_use_place_in_closure)]
MutableBorrowUsePlaceClosure {
place: String,
Expand Down
12 changes: 12 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/borrowck.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,18 @@ borrowck_var_move_by_use_in_generator =
borrowck_var_move_by_use_in_closure =
move occurs due to use in closure
borrowck_var_first_borrow_by_use_place_in_generator =
first borrow occurs due to use of {$place} in generator
borrowck_var_first_borrow_by_use_place_in_closure =
first borrow occurs due to use of {$place} in closure
borrowck_var_second_borrow_by_use_place_in_generator =
second borrow occurs due to use of {$place} in generator
borrowck_var_second_borrow_by_use_place_in_closure =
second borrow occurs due to use of {$place} in closure
borrowck_var_mutable_borrow_by_use_place_in_closure =
mutable borrow occurs due to use of {$place} in closure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0502]: cannot borrow `p` as mutable because it is also borrowed as immuta
--> $DIR/borrowck-closures-mut-and-imm.rs:17:14
|
LL | let c2 = || p.y * 5;
| -- --- first borrow occurs due to use of `p.y` in closure
| -- --- first borrow occurs due to use of `p` in closure
| |
| immutable borrow occurs here
LL | let c1 = || {
Expand Down

0 comments on commit 7fc677b

Please sign in to comment.