Skip to content

Commit 94ab51f

Browse files
committed
BorrowUsedHere|Later
1 parent 3e50a07 commit 94ab51f

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use crate::session_diagnostics::{
2323
BorrowLaterBorrowUsedLaterInLoop, BorrowUsedHere, BorrowUsedLater, BorrowUsedLaterInLoop,
2424
MustValidFor, UsedLaterDropped,
2525
};
26+
use crate::session_diagnostics::{BorrowUsedHere, BorrowUsedLater};
2627
use crate::{
2728
borrow_set::BorrowData, nll::ConstraintDescription, region_infer::Cause, MirBorrowckCtxt,
2829
WriteKind,

compiler/rustc_borrowck/src/session_diagnostics.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,52 @@ pub(crate) enum AddMoveErr {
172172
},
173173
#[note(borrowck::moved_var_cannot_copy)]
174174
MovedNotCopy {},
175+
176+
#[derive(SessionSubdiagnostic)]
177+
pub(crate) enum BorrowUsedHere {
178+
#[label(borrowck::used_here_by_closure)]
179+
ByClosure {
180+
#[primary_span]
181+
path_span: Span,
182+
},
183+
}
184+
185+
#[derive(SessionSubdiagnostic)]
186+
pub(crate) enum BorrowUsedLater<'a> {
187+
#[label(borrowck::borrow_later_captured_by_trait_object)]
188+
TraitCapture {
189+
borrow_desc: &'a str,
190+
#[primary_span]
191+
span: Span,
192+
},
193+
194+
#[label(borrowck::borrow_later_captured_by_closure)]
195+
ClosureCapture {
196+
borrow_desc: &'a str,
197+
#[primary_span]
198+
span: Span,
199+
},
200+
201+
#[label(borrowck::borrow_later_used_by_call)]
202+
Call {
203+
borrow_desc: &'a str,
204+
#[primary_span]
205+
span: Span,
206+
},
207+
208+
#[label(borrowck::borrow_later_stored_here)]
209+
FakeLetRead {
210+
borrow_desc: &'a str,
211+
#[primary_span]
212+
span: Span,
213+
},
214+
215+
#[label(borrowck::borrow_later_used_here)]
216+
Other {
217+
borrow_desc: &'a str,
218+
#[primary_span]
219+
span: Span,
220+
},
175221
}
176222

177223
#[derive(SessionSubdiagnostic)]

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,18 @@ borrowck_bl_used_borrow_in_later_iteration_loop =
115115
borrowck_drop_local_might_cause_borrow =
116116
{$borrow_desc}borrow might be used here, when `{$local_name}` is dropped and runs the {$dtor_desc} for {$type_desc}
117117
118+
borrowck_closure_capture_borrow_in_later_iteration_loop =
119+
{$borrow_desc}borrow later borrow captured here by closure, in later iteration of loop
120+
121+
borrowck_call_used_borrow_in_later_iteration_loop =
122+
{$borrow_desc}borrow later borrow used by call, in later iteration of loop
123+
124+
borrowck_used_borrow_in_later_iteration_loop =
125+
{$borrow_desc}borrow later borrow used here, in later iteration of loop
126+
127+
borrowck_drop_local_might_cause_borrow =
128+
{$borrow_desc}borrow might be used here, when `{$local_name}` is dropped and runs the {$dtor_name} for {$type_name}
129+
118130
borrowck_var_dropped_in_wrong_order =
119131
values in a scope are dropped in the opposite order they are defined
120132
@@ -174,3 +186,5 @@ borrowck_moved_by_call =
174186
175187
borrowck_type_not_impl_Copy =
176188
{$move_prefix}move occurs because {$place_desc} has type `{$ty}`, which does not implement the `Copy` trait
189+
borrowck_outlive_constraint_need_borrow_lasts =
190+
{$category}requires that `{$borrow_desc}` lasts for `{$region_name}`

0 commit comments

Comments
 (0)