Skip to content

Commit 5b68e1f

Browse files
committed
Add Origin::Ast arguments to all of the migrated AST-borrowck diagnostics.
1 parent cf11ef4 commit 5b68e1f

File tree

2 files changed

+58
-35
lines changed

2 files changed

+58
-35
lines changed

src/librustc_borrowck/borrowck/mod.rs

+18-10
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,8 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
618618
let mut err = self.cannot_act_on_moved_value(use_span,
619619
verb,
620620
msg,
621-
&format!("{}", nl));
621+
&format!("{}", nl),
622+
Origin::Ast);
622623
let need_note = match lp.ty.sty {
623624
ty::TypeVariants::TyClosure(id, _) => {
624625
let node_id = self.tcx.hir.as_local_node_id(id).unwrap();
@@ -698,7 +699,9 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
698699
&self,
699700
span: Span,
700701
lp: &LoanPath<'tcx>) {
701-
self.cannot_partially_reinit_an_uninit_struct(span, &self.loan_path_to_string(lp))
702+
self.cannot_partially_reinit_an_uninit_struct(span,
703+
&self.loan_path_to_string(lp),
704+
Origin::Ast)
702705
.emit();
703706
}
704707

@@ -760,7 +763,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
760763
self.cannot_assign(error_span, &descr, Origin::Ast)
761764
}
762765
BorrowViolation(euv::ClosureCapture(_)) => {
763-
self.closure_cannot_assign_to_borrowed(error_span, &descr)
766+
self.closure_cannot_assign_to_borrowed(error_span, &descr, Origin::Ast)
764767
}
765768
BorrowViolation(euv::OverloadedOperator) |
766769
BorrowViolation(euv::AddrOf) |
@@ -769,7 +772,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
769772
BorrowViolation(euv::AutoUnsafe) |
770773
BorrowViolation(euv::ForLoop) |
771774
BorrowViolation(euv::MatchDiscriminant) => {
772-
self.cannot_borrow_path_as_mutable(error_span, &descr)
775+
self.cannot_borrow_path_as_mutable(error_span, &descr, Origin::Ast)
773776
}
774777
BorrowViolation(euv::ClosureInvocation) => {
775778
span_bug!(err.span,
@@ -851,12 +854,12 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
851854

852855
if let Some((yield_span, _)) = maybe_borrow_across_yield {
853856
debug!("err_out_of_scope: opt_yield_span = {:?}", yield_span);
854-
self.cannot_borrow_across_generator_yield(error_span, yield_span)
857+
self.cannot_borrow_across_generator_yield(error_span, yield_span, Origin::Ast)
855858
.emit();
856859
return;
857860
}
858861

859-
let mut db = self.path_does_not_live_long_enough(error_span, &msg);
862+
let mut db = self.path_does_not_live_long_enough(error_span, &msg, Origin::Ast);
860863
let (value_kind, value_msg) = match err.cmt.cat {
861864
mc::Categorization::Rvalue(..) =>
862865
("temporary value", "temporary value created here"),
@@ -965,7 +968,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
965968
}
966969
err_borrowed_pointer_too_short(loan_scope, ptr_scope) => {
967970
let descr = self.cmt_to_path_or_string(&err.cmt);
968-
let mut db = self.lifetime_too_short_for_reborrow(error_span, &descr);
971+
let mut db = self.lifetime_too_short_for_reborrow(error_span, &descr, Origin::Ast);
969972
let descr = match opt_loan_path(&err.cmt) {
970973
Some(lp) => {
971974
format!("`{}`", self.loan_path_to_string(&lp))
@@ -1050,10 +1053,14 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
10501053
};
10511054
let node_id = self.tcx.hir.def_index_to_node_id(id);
10521055
let help_span = self.tcx.hir.span(node_id);
1053-
self.cannot_act_on_capture_in_sharable_fn(span, prefix, (help_span, help_msg))
1056+
self.cannot_act_on_capture_in_sharable_fn(span,
1057+
prefix,
1058+
(help_span, help_msg),
1059+
Origin::Ast)
10541060
}
10551061
_ => {
1056-
self.cannot_assign_into_immutable_reference(span, prefix)
1062+
self.cannot_assign_into_immutable_reference(span, prefix,
1063+
Origin::Ast)
10571064
}
10581065
};
10591066
self.note_immutability_blame(&mut err, blame);
@@ -1207,7 +1214,8 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
12071214

12081215
self.cannot_capture_in_long_lived_closure(err.span,
12091216
&cmt_path_or_string,
1210-
capture_span)
1217+
capture_span,
1218+
Origin::Ast)
12111219
.span_suggestion(err.span,
12121220
&format!("to force the closure to take ownership of {} \
12131221
(and any other referenced variables), \

src/librustc_mir/util/borrowck_errors.rs

+40-25
Original file line numberDiff line numberDiff line change
@@ -299,115 +299,130 @@ pub trait BorrowckErrors {
299299
use_span: Span,
300300
verb: &str,
301301
optional_adverb_for_moved: &str,
302-
moved_path: &str)
302+
moved_path: &str,
303+
o: Origin)
303304
-> DiagnosticBuilder
304305
{
305306
let err = struct_span_err!(self, use_span, E0382,
306-
"{} of {}moved value: `{}`",
307-
verb, optional_adverb_for_moved, moved_path);
307+
"{} of {}moved value: `{}`{OGN}",
308+
verb, optional_adverb_for_moved, moved_path, OGN=o);
308309
err
309310
}
310311

311312
fn cannot_partially_reinit_an_uninit_struct(&self,
312313
span: Span,
313-
uninit_path: &str)
314+
uninit_path: &str,
315+
o: Origin)
314316
-> DiagnosticBuilder
315317
{
316318
let err = struct_span_err!(self,
317319
span,
318320
E0383,
319-
"partial reinitialization of uninitialized structure `{}`",
320-
uninit_path);
321+
"partial reinitialization of uninitialized structure `{}`{OGN}",
322+
uninit_path, OGN=o);
321323
err
322324
}
323325

324326
fn closure_cannot_assign_to_borrowed(&self,
325327
span: Span,
326-
descr: &str)
328+
descr: &str,
329+
o: Origin)
327330
-> DiagnosticBuilder
328331
{
329-
let err = struct_span_err!(self, span, E0595, "closure cannot assign to {}", descr);
332+
let err = struct_span_err!(self, span, E0595, "closure cannot assign to {}{OGN}",
333+
descr, OGN=o);
330334
err
331335
}
332336

333337
fn cannot_borrow_path_as_mutable(&self,
334338
span: Span,
335-
path: &str)
339+
path: &str,
340+
o: Origin)
336341
-> DiagnosticBuilder
337342
{
338-
let err = struct_span_err!(self, span, E0596, "cannot borrow {} as mutable", path);
343+
let err = struct_span_err!(self, span, E0596, "cannot borrow {} as mutable{OGN}",
344+
path, OGN=o);
339345
err
340346
}
341347

342348
fn cannot_borrow_across_generator_yield(&self,
343349
span: Span,
344-
yield_span: Span)
350+
yield_span: Span,
351+
o: Origin)
345352
-> DiagnosticBuilder
346353
{
347354
let mut err = struct_span_err!(self,
348355
span,
349356
E0626,
350-
"borrow may still be in use when generator yields");
357+
"borrow may still be in use when generator yields{OGN}",
358+
OGN=o);
351359
err.span_label(yield_span, "possible yield occurs here");
352360
err
353361
}
354362

355363
fn path_does_not_live_long_enough(&self,
356364
span: Span,
357-
path: &str)
365+
path: &str,
366+
o: Origin)
358367
-> DiagnosticBuilder
359368
{
360-
let err = struct_span_err!(self, span, E0597, "{} does not live long enough", path);
369+
let err = struct_span_err!(self, span, E0597, "{} does not live long enough{OGN}",
370+
path, OGN=o);
361371
err
362372
}
363373

364374
fn lifetime_too_short_for_reborrow(&self,
365375
span: Span,
366-
path: &str)
376+
path: &str,
377+
o: Origin)
367378
-> DiagnosticBuilder
368379
{
369380
let err = struct_span_err!(self, span, E0598,
370381
"lifetime of {} is too short to guarantee \
371-
its contents can be safely reborrowed",
372-
path);
382+
its contents can be safely reborrowed{OGN}",
383+
path, OGN=o);
373384
err
374385
}
375386

376387
fn cannot_act_on_capture_in_sharable_fn(&self,
377388
span: Span,
378389
bad_thing: &str,
379-
help: (Span, &str))
390+
help: (Span, &str),
391+
o: Origin)
380392
-> DiagnosticBuilder
381393
{
382394
let (help_span, help_msg) = help;
383395
let mut err = struct_span_err!(self, span, E0387,
384-
"{} in a captured outer variable in an `Fn` closure",
385-
bad_thing);
396+
"{} in a captured outer variable in an `Fn` closure{OGN}",
397+
bad_thing, OGN=o);
386398
err.span_help(help_span, help_msg);
387399
err
388400
}
389401

390402
fn cannot_assign_into_immutable_reference(&self,
391403
span: Span,
392-
bad_thing: &str)
404+
bad_thing: &str,
405+
o: Origin)
393406
-> DiagnosticBuilder
394407
{
395-
let mut err = struct_span_err!(self, span, E0389, "{} in a `&` reference", bad_thing);
408+
let mut err = struct_span_err!(self, span, E0389, "{} in a `&` reference{OGN}",
409+
bad_thing, OGN=o);
396410
err.span_label(span, "assignment into an immutable reference");
397411
err
398412
}
399413

400414
fn cannot_capture_in_long_lived_closure(&self,
401415
closure_span: Span,
402416
borrowed_path: &str,
403-
capture_span: Span)
417+
capture_span: Span,
418+
o: Origin)
404419
-> DiagnosticBuilder
405420
{
406421
let mut err = struct_span_err!(self, closure_span, E0373,
407422
"closure may outlive the current function, \
408423
but it borrows {}, \
409-
which is owned by the current function",
410-
borrowed_path);
424+
which is owned by the current function{OGN}",
425+
borrowed_path, OGN=o);
411426
err.span_label(capture_span, format!("{} is borrowed here", borrowed_path))
412427
.span_label(closure_span, format!("may outlive borrowed value {}", borrowed_path));
413428
err

0 commit comments

Comments
 (0)