Skip to content

Commit 1b6afd1

Browse files
author
Jonathan Turner
committed
Update errors to use new error format
1 parent 104fe1c commit 1b6afd1

28 files changed

+219
-163
lines changed

src/librustc/infer/error_reporting.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
482482
trace.origin);
483483

484484
if !is_simple_error {
485-
err = err.note_expected_found(&"type", &expected, &found);
485+
err.note_expected_found(&"type", &expected, &found);
486486
}
487487

488-
err = err.span_label(trace.origin.span(), &terr);
488+
err.span_label(trace.origin.span(), &terr);
489489

490490
self.check_and_note_conflicting_crates(&mut err, terr, trace.origin.span());
491491

src/librustc_borrowck/borrowck/check_loans.rs

+74-67
Original file line numberDiff line numberDiff line change
@@ -475,99 +475,104 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
475475

476476
let mut err = match (new_loan.kind, old_loan.kind) {
477477
(ty::MutBorrow, ty::MutBorrow) => {
478-
struct_span_err!(self.bccx, new_loan.span, E0499,
479-
"cannot borrow `{}`{} as mutable \
480-
more than once at a time",
481-
nl, new_loan_msg)
482-
.span_label(
478+
let mut err =struct_span_err!(self.bccx, new_loan.span, E0499,
479+
"cannot borrow `{}`{} as mutable \
480+
more than once at a time",
481+
nl, new_loan_msg);
482+
err.span_label(
483483
old_loan.span,
484-
&format!("first mutable borrow occurs here{}", old_loan_msg))
485-
.span_label(
484+
&format!("first mutable borrow occurs here{}", old_loan_msg));
485+
err.span_label(
486486
new_loan.span,
487-
&format!("second mutable borrow occurs here{}", new_loan_msg))
488-
.span_label(
487+
&format!("second mutable borrow occurs here{}", new_loan_msg));
488+
err.span_label(
489489
previous_end_span,
490-
&format!("first borrow ends here"))
490+
&format!("first borrow ends here"));
491+
err
491492
}
492493

493494
(ty::UniqueImmBorrow, ty::UniqueImmBorrow) => {
494-
struct_span_err!(self.bccx, new_loan.span, E0524,
495+
let mut err = struct_span_err!(self.bccx, new_loan.span, E0524,
495496
"two closures require unique access to `{}` \
496497
at the same time",
497-
nl)
498-
.span_label(
498+
nl);
499+
err.span_label(
499500
old_loan.span,
500-
&format!("first closure is constructed here"))
501-
.span_label(
501+
&format!("first closure is constructed here"));
502+
err.span_label(
502503
new_loan.span,
503-
&format!("second closure is constructed here"))
504-
.span_label(
504+
&format!("second closure is constructed here"));
505+
err.span_label(
505506
previous_end_span,
506-
&format!("borrow from first closure ends here"))
507+
&format!("borrow from first closure ends here"));
508+
err
507509
}
508510

509511
(ty::UniqueImmBorrow, _) => {
510-
struct_span_err!(self.bccx, new_loan.span, E0500,
511-
"closure requires unique access to `{}` \
512-
but {} is already borrowed{}",
513-
nl, ol_pronoun, old_loan_msg)
514-
.span_label(
512+
let mut err = struct_span_err!(self.bccx, new_loan.span, E0500,
513+
"closure requires unique access to `{}` \
514+
but {} is already borrowed{}",
515+
nl, ol_pronoun, old_loan_msg);
516+
err.span_label(
515517
new_loan.span,
516-
&format!("closure construction occurs here{}", new_loan_msg))
517-
.span_label(
518+
&format!("closure construction occurs here{}", new_loan_msg));
519+
err.span_label(
518520
old_loan.span,
519-
&format!("borrow occurs here{}", old_loan_msg))
520-
.span_label(
521+
&format!("borrow occurs here{}", old_loan_msg));
522+
err.span_label(
521523
previous_end_span,
522-
&format!("borrow ends here"))
524+
&format!("borrow ends here"));
525+
err
523526
}
524527

525528
(_, ty::UniqueImmBorrow) => {
526-
struct_span_err!(self.bccx, new_loan.span, E0501,
527-
"cannot borrow `{}`{} as {} because \
528-
previous closure requires unique access",
529-
nl, new_loan_msg, new_loan.kind.to_user_str())
530-
.span_label(
529+
let mut err = struct_span_err!(self.bccx, new_loan.span, E0501,
530+
"cannot borrow `{}`{} as {} because \
531+
previous closure requires unique access",
532+
nl, new_loan_msg, new_loan.kind.to_user_str());
533+
err.span_label(
531534
new_loan.span,
532-
&format!("borrow occurs here{}", new_loan_msg))
533-
.span_label(
535+
&format!("borrow occurs here{}", new_loan_msg));
536+
err.span_label(
534537
old_loan.span,
535-
&format!("closure construction occurs here{}", old_loan_msg))
536-
.span_label(
538+
&format!("closure construction occurs here{}", old_loan_msg));
539+
err.span_label(
537540
previous_end_span,
538-
&format!("borrow from closure ends here"))
541+
&format!("borrow from closure ends here"));
542+
err
539543
}
540544

541545
(_, _) => {
542-
struct_span_err!(self.bccx, new_loan.span, E0502,
543-
"cannot borrow `{}`{} as {} because \
544-
{} is also borrowed as {}{}",
545-
nl,
546-
new_loan_msg,
547-
new_loan.kind.to_user_str(),
548-
ol_pronoun,
549-
old_loan.kind.to_user_str(),
550-
old_loan_msg)
551-
.span_label(
546+
let mut err = struct_span_err!(self.bccx, new_loan.span, E0502,
547+
"cannot borrow `{}`{} as {} because \
548+
{} is also borrowed as {}{}",
549+
nl,
550+
new_loan_msg,
551+
new_loan.kind.to_user_str(),
552+
ol_pronoun,
553+
old_loan.kind.to_user_str(),
554+
old_loan_msg);
555+
err.span_label(
552556
new_loan.span,
553557
&format!("{} borrow occurs here{}",
554558
new_loan.kind.to_user_str(),
555-
new_loan_msg))
556-
.span_label(
559+
new_loan_msg));
560+
err.span_label(
557561
old_loan.span,
558562
&format!("{} borrow occurs here{}",
559563
old_loan.kind.to_user_str(),
560-
old_loan_msg))
561-
.span_label(
564+
old_loan_msg));
565+
err.span_label(
562566
previous_end_span,
563567
&format!("{} borrow ends here",
564-
old_loan.kind.to_user_str()))
568+
old_loan.kind.to_user_str()));
569+
err
565570
}
566571
};
567572

568573
match new_loan.cause {
569574
euv::ClosureCapture(span) => {
570-
err = err.span_label(
575+
err.span_label(
571576
span,
572577
&format!("borrow occurs due to use of `{}` in closure", nl));
573578
}
@@ -576,7 +581,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
576581

577582
match old_loan.cause {
578583
euv::ClosureCapture(span) => {
579-
err = err.span_label(
584+
err.span_label(
580585
span,
581586
&format!("previous borrow occurs due to use of `{}` in closure",
582587
ol));
@@ -664,35 +669,37 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
664669
UseWhileBorrowed(loan_path, loan_span) => {
665670
let mut err = match move_kind {
666671
move_data::Captured => {
667-
struct_span_err!(self.bccx, span, E0504,
672+
let mut err = struct_span_err!(self.bccx, span, E0504,
668673
"cannot move `{}` into closure because it is borrowed",
669-
&self.bccx.loan_path_to_string(move_path))
670-
.span_label(
674+
&self.bccx.loan_path_to_string(move_path));
675+
err.span_label(
671676
loan_span,
672677
&format!("borrow of `{}` occurs here",
673678
&self.bccx.loan_path_to_string(&loan_path))
674-
)
675-
.span_label(
679+
);
680+
err.span_label(
676681
span,
677682
&format!("move into closure occurs here")
678-
)
683+
);
684+
err
679685
}
680686
move_data::Declared |
681687
move_data::MoveExpr |
682688
move_data::MovePat => {
683-
struct_span_err!(self.bccx, span, E0505,
689+
let mut err = struct_span_err!(self.bccx, span, E0505,
684690
"cannot move out of `{}` because it is borrowed",
685-
&self.bccx.loan_path_to_string(move_path))
686-
.span_label(
691+
&self.bccx.loan_path_to_string(move_path));
692+
err.span_label(
687693
loan_span,
688694
&format!("borrow of `{}` occurs here",
689695
&self.bccx.loan_path_to_string(&loan_path))
690-
)
691-
.span_label(
696+
);
697+
err.span_label(
692698
span,
693699
&format!("move out of `{}` occurs here",
694700
&self.bccx.loan_path_to_string(move_path))
695-
)
701+
);
702+
err
696703
}
697704
};
698705

src/librustc_borrowck/borrowck/gather_loans/move_error.rs

+18-13
Original file line numberDiff line numberDiff line change
@@ -121,22 +121,25 @@ fn report_cannot_move_out_of<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
121121
Categorization::Deref(_, _, mc::Implicit(..)) |
122122
Categorization::Deref(_, _, mc::UnsafePtr(..)) |
123123
Categorization::StaticItem => {
124-
struct_span_err!(bccx, move_from.span, E0507,
124+
let mut err = struct_span_err!(bccx, move_from.span, E0507,
125125
"cannot move out of {}",
126-
move_from.descriptive_string(bccx.tcx))
127-
.span_label(
126+
move_from.descriptive_string(bccx.tcx));
127+
err.span_label(
128128
move_from.span,
129129
&format!("move occurs here")
130-
)
130+
);
131+
err
131132
}
132133

133134
Categorization::Interior(ref b, mc::InteriorElement(Kind::Index, _)) => {
134135
let expr = bccx.tcx.map.expect_expr(move_from.id);
135136
if let hir::ExprIndex(..) = expr.node {
136-
struct_span_err!(bccx, move_from.span, E0508,
137-
"cannot move out of type `{}`, \
138-
a non-copy fixed-size array",
139-
b.ty)
137+
let mut err = struct_span_err!(bccx, move_from.span, E0508,
138+
"cannot move out of type `{}`, \
139+
a non-copy fixed-size array",
140+
b.ty);
141+
err.span_label(move_from.span, &format!("can not move out of here"));
142+
err
140143
} else {
141144
span_bug!(move_from.span, "this path should not cause illegal move");
142145
}
@@ -147,10 +150,12 @@ fn report_cannot_move_out_of<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
147150
match b.ty.sty {
148151
ty::TyStruct(def, _) |
149152
ty::TyEnum(def, _) if def.has_dtor() => {
150-
struct_span_err!(bccx, move_from.span, E0509,
151-
"cannot move out of type `{}`, \
152-
which defines the `Drop` trait",
153-
b.ty)
153+
let mut err = struct_span_err!(bccx, move_from.span, E0509,
154+
"cannot move out of type `{}`, \
155+
which defines the `Drop` trait",
156+
b.ty);
157+
err.span_label(move_from.span, &format!("can not move out of here"));
158+
err
154159
},
155160
_ => {
156161
span_bug!(move_from.span, "this path should not cause illegal move");
@@ -168,7 +173,7 @@ fn note_move_destination(mut err: DiagnosticBuilder,
168173
pat_name: ast::Name,
169174
is_first_note: bool) -> DiagnosticBuilder {
170175
if is_first_note {
171-
err = err.span_label(
176+
err.span_label(
172177
move_to_span,
173178
&format!("attempting to move value to here"));
174179
err.help(

src/librustc_borrowck/borrowck/mod.rs

+12-11
Original file line numberDiff line numberDiff line change
@@ -624,9 +624,8 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
624624
let mut db = self.struct_span_err(
625625
err.span,
626626
&self.bckerr_to_string(&err));
627-
self.note_and_explain_bckerr(&mut db, err);
628-
db.span_label(span, &format!("cannot borrow"))
629-
.emit();
627+
self.note_and_explain_bckerr(&mut db, err, span);
628+
db.emit();
630629
}
631630

632631
pub fn report_use_of_moved_value(&self,
@@ -721,10 +720,12 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
721720
err.span_label(
722721
use_span,
723722
&format!("value moved{} here in previous iteration of loop",
724-
move_note))
723+
move_note));
724+
err
725725
} else {
726726
err.span_label(use_span, &format!("value {} here after move", verb_participle))
727-
.span_label(move_span, &format!("value moved{} here", move_note))
727+
.span_label(move_span, &format!("value moved{} here", move_note));
728+
err
728729
};
729730

730731
err.note(&format!("move occurs because `{}` has type `{}`, \
@@ -951,7 +952,8 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
951952
.emit();
952953
}
953954

954-
pub fn note_and_explain_bckerr(&self, db: &mut DiagnosticBuilder, err: BckError<'tcx>) {
955+
pub fn note_and_explain_bckerr(&self, db: &mut DiagnosticBuilder, err: BckError<'tcx>,
956+
error_span: Span) {
955957
let code = err.code;
956958
match code {
957959
err_mutbl => {
@@ -976,13 +978,11 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
976978
let span = self.tcx.map.span(local_id);
977979
if let Ok(snippet) = self.tcx.sess.codemap().span_to_snippet(span) {
978980
if snippet != "self" {
979-
db.span_suggestion(
980-
span,
981-
&format!("to make the {} mutable, use `mut` as shown:",
982-
self.cmt_to_string(&err.cmt)),
983-
format!("mut {}", snippet));
981+
db.span_label(span,
982+
&format!("use `mut {}` here to make mutable", snippet));
984983
}
985984
}
985+
db.span_label(error_span, &format!("cannot borrow mutably"));
986986
}
987987
}
988988
}
@@ -1000,6 +1000,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
10001000
super_scope,
10011001
"");
10021002
if let Some(span) = statement_scope_span(self.tcx, super_scope) {
1003+
db.span_label(error_span, &format!("does not live long enough"));
10031004
db.span_help(span,
10041005
"consider using a `let` binding to increase its lifetime");
10051006
}

0 commit comments

Comments
 (0)