Update errors to use new error format

This commit is contained in:
Jonathan Turner 2016-05-12 16:39:09 -07:00
parent 104fe1c4db
commit 1b6afd1e42
28 changed files with 219 additions and 163 deletions

View File

@ -482,10 +482,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
trace.origin); trace.origin);
if !is_simple_error { if !is_simple_error {
err = err.note_expected_found(&"type", &expected, &found); err.note_expected_found(&"type", &expected, &found);
} }
err = err.span_label(trace.origin.span(), &terr); err.span_label(trace.origin.span(), &terr);
self.check_and_note_conflicting_crates(&mut err, terr, trace.origin.span()); self.check_and_note_conflicting_crates(&mut err, terr, trace.origin.span());

View File

@ -475,99 +475,104 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
let mut err = match (new_loan.kind, old_loan.kind) { let mut err = match (new_loan.kind, old_loan.kind) {
(ty::MutBorrow, ty::MutBorrow) => { (ty::MutBorrow, ty::MutBorrow) => {
struct_span_err!(self.bccx, new_loan.span, E0499, let mut err =struct_span_err!(self.bccx, new_loan.span, E0499,
"cannot borrow `{}`{} as mutable \ "cannot borrow `{}`{} as mutable \
more than once at a time", more than once at a time",
nl, new_loan_msg) nl, new_loan_msg);
.span_label( err.span_label(
old_loan.span, old_loan.span,
&format!("first mutable borrow occurs here{}", old_loan_msg)) &format!("first mutable borrow occurs here{}", old_loan_msg));
.span_label( err.span_label(
new_loan.span, new_loan.span,
&format!("second mutable borrow occurs here{}", new_loan_msg)) &format!("second mutable borrow occurs here{}", new_loan_msg));
.span_label( err.span_label(
previous_end_span, previous_end_span,
&format!("first borrow ends here")) &format!("first borrow ends here"));
err
} }
(ty::UniqueImmBorrow, ty::UniqueImmBorrow) => { (ty::UniqueImmBorrow, ty::UniqueImmBorrow) => {
struct_span_err!(self.bccx, new_loan.span, E0524, let mut err = struct_span_err!(self.bccx, new_loan.span, E0524,
"two closures require unique access to `{}` \ "two closures require unique access to `{}` \
at the same time", at the same time",
nl) nl);
.span_label( err.span_label(
old_loan.span, old_loan.span,
&format!("first closure is constructed here")) &format!("first closure is constructed here"));
.span_label( err.span_label(
new_loan.span, new_loan.span,
&format!("second closure is constructed here")) &format!("second closure is constructed here"));
.span_label( err.span_label(
previous_end_span, previous_end_span,
&format!("borrow from first closure ends here")) &format!("borrow from first closure ends here"));
err
} }
(ty::UniqueImmBorrow, _) => { (ty::UniqueImmBorrow, _) => {
struct_span_err!(self.bccx, new_loan.span, E0500, let mut err = struct_span_err!(self.bccx, new_loan.span, E0500,
"closure requires unique access to `{}` \ "closure requires unique access to `{}` \
but {} is already borrowed{}", but {} is already borrowed{}",
nl, ol_pronoun, old_loan_msg) nl, ol_pronoun, old_loan_msg);
.span_label( err.span_label(
new_loan.span, new_loan.span,
&format!("closure construction occurs here{}", new_loan_msg)) &format!("closure construction occurs here{}", new_loan_msg));
.span_label( err.span_label(
old_loan.span, old_loan.span,
&format!("borrow occurs here{}", old_loan_msg)) &format!("borrow occurs here{}", old_loan_msg));
.span_label( err.span_label(
previous_end_span, previous_end_span,
&format!("borrow ends here")) &format!("borrow ends here"));
err
} }
(_, ty::UniqueImmBorrow) => { (_, ty::UniqueImmBorrow) => {
struct_span_err!(self.bccx, new_loan.span, E0501, let mut err = struct_span_err!(self.bccx, new_loan.span, E0501,
"cannot borrow `{}`{} as {} because \ "cannot borrow `{}`{} as {} because \
previous closure requires unique access", previous closure requires unique access",
nl, new_loan_msg, new_loan.kind.to_user_str()) nl, new_loan_msg, new_loan.kind.to_user_str());
.span_label( err.span_label(
new_loan.span, new_loan.span,
&format!("borrow occurs here{}", new_loan_msg)) &format!("borrow occurs here{}", new_loan_msg));
.span_label( err.span_label(
old_loan.span, old_loan.span,
&format!("closure construction occurs here{}", old_loan_msg)) &format!("closure construction occurs here{}", old_loan_msg));
.span_label( err.span_label(
previous_end_span, previous_end_span,
&format!("borrow from closure ends here")) &format!("borrow from closure ends here"));
err
} }
(_, _) => { (_, _) => {
struct_span_err!(self.bccx, new_loan.span, E0502, let mut err = struct_span_err!(self.bccx, new_loan.span, E0502,
"cannot borrow `{}`{} as {} because \ "cannot borrow `{}`{} as {} because \
{} is also borrowed as {}{}", {} is also borrowed as {}{}",
nl, nl,
new_loan_msg, new_loan_msg,
new_loan.kind.to_user_str(), new_loan.kind.to_user_str(),
ol_pronoun, ol_pronoun,
old_loan.kind.to_user_str(), old_loan.kind.to_user_str(),
old_loan_msg) old_loan_msg);
.span_label( err.span_label(
new_loan.span, new_loan.span,
&format!("{} borrow occurs here{}", &format!("{} borrow occurs here{}",
new_loan.kind.to_user_str(), new_loan.kind.to_user_str(),
new_loan_msg)) new_loan_msg));
.span_label( err.span_label(
old_loan.span, old_loan.span,
&format!("{} borrow occurs here{}", &format!("{} borrow occurs here{}",
old_loan.kind.to_user_str(), old_loan.kind.to_user_str(),
old_loan_msg)) old_loan_msg));
.span_label( err.span_label(
previous_end_span, previous_end_span,
&format!("{} borrow ends here", &format!("{} borrow ends here",
old_loan.kind.to_user_str())) old_loan.kind.to_user_str()));
err
} }
}; };
match new_loan.cause { match new_loan.cause {
euv::ClosureCapture(span) => { euv::ClosureCapture(span) => {
err = err.span_label( err.span_label(
span, span,
&format!("borrow occurs due to use of `{}` in closure", nl)); &format!("borrow occurs due to use of `{}` in closure", nl));
} }
@ -576,7 +581,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
match old_loan.cause { match old_loan.cause {
euv::ClosureCapture(span) => { euv::ClosureCapture(span) => {
err = err.span_label( err.span_label(
span, span,
&format!("previous borrow occurs due to use of `{}` in closure", &format!("previous borrow occurs due to use of `{}` in closure",
ol)); ol));
@ -664,35 +669,37 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
UseWhileBorrowed(loan_path, loan_span) => { UseWhileBorrowed(loan_path, loan_span) => {
let mut err = match move_kind { let mut err = match move_kind {
move_data::Captured => { move_data::Captured => {
struct_span_err!(self.bccx, span, E0504, let mut err = struct_span_err!(self.bccx, span, E0504,
"cannot move `{}` into closure because it is borrowed", "cannot move `{}` into closure because it is borrowed",
&self.bccx.loan_path_to_string(move_path)) &self.bccx.loan_path_to_string(move_path));
.span_label( err.span_label(
loan_span, loan_span,
&format!("borrow of `{}` occurs here", &format!("borrow of `{}` occurs here",
&self.bccx.loan_path_to_string(&loan_path)) &self.bccx.loan_path_to_string(&loan_path))
) );
.span_label( err.span_label(
span, span,
&format!("move into closure occurs here") &format!("move into closure occurs here")
) );
err
} }
move_data::Declared | move_data::Declared |
move_data::MoveExpr | move_data::MoveExpr |
move_data::MovePat => { move_data::MovePat => {
struct_span_err!(self.bccx, span, E0505, let mut err = struct_span_err!(self.bccx, span, E0505,
"cannot move out of `{}` because it is borrowed", "cannot move out of `{}` because it is borrowed",
&self.bccx.loan_path_to_string(move_path)) &self.bccx.loan_path_to_string(move_path));
.span_label( err.span_label(
loan_span, loan_span,
&format!("borrow of `{}` occurs here", &format!("borrow of `{}` occurs here",
&self.bccx.loan_path_to_string(&loan_path)) &self.bccx.loan_path_to_string(&loan_path))
) );
.span_label( err.span_label(
span, span,
&format!("move out of `{}` occurs here", &format!("move out of `{}` occurs here",
&self.bccx.loan_path_to_string(move_path)) &self.bccx.loan_path_to_string(move_path))
) );
err
} }
}; };

View File

@ -121,22 +121,25 @@ fn report_cannot_move_out_of<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
Categorization::Deref(_, _, mc::Implicit(..)) | Categorization::Deref(_, _, mc::Implicit(..)) |
Categorization::Deref(_, _, mc::UnsafePtr(..)) | Categorization::Deref(_, _, mc::UnsafePtr(..)) |
Categorization::StaticItem => { Categorization::StaticItem => {
struct_span_err!(bccx, move_from.span, E0507, let mut err = struct_span_err!(bccx, move_from.span, E0507,
"cannot move out of {}", "cannot move out of {}",
move_from.descriptive_string(bccx.tcx)) move_from.descriptive_string(bccx.tcx));
.span_label( err.span_label(
move_from.span, move_from.span,
&format!("move occurs here") &format!("move occurs here")
) );
err
} }
Categorization::Interior(ref b, mc::InteriorElement(Kind::Index, _)) => { Categorization::Interior(ref b, mc::InteriorElement(Kind::Index, _)) => {
let expr = bccx.tcx.map.expect_expr(move_from.id); let expr = bccx.tcx.map.expect_expr(move_from.id);
if let hir::ExprIndex(..) = expr.node { if let hir::ExprIndex(..) = expr.node {
struct_span_err!(bccx, move_from.span, E0508, let mut err = struct_span_err!(bccx, move_from.span, E0508,
"cannot move out of type `{}`, \ "cannot move out of type `{}`, \
a non-copy fixed-size array", a non-copy fixed-size array",
b.ty) b.ty);
err.span_label(move_from.span, &format!("can not move out of here"));
err
} else { } else {
span_bug!(move_from.span, "this path should not cause illegal move"); span_bug!(move_from.span, "this path should not cause illegal move");
} }
@ -147,10 +150,12 @@ fn report_cannot_move_out_of<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
match b.ty.sty { match b.ty.sty {
ty::TyStruct(def, _) | ty::TyStruct(def, _) |
ty::TyEnum(def, _) if def.has_dtor() => { ty::TyEnum(def, _) if def.has_dtor() => {
struct_span_err!(bccx, move_from.span, E0509, let mut err = struct_span_err!(bccx, move_from.span, E0509,
"cannot move out of type `{}`, \ "cannot move out of type `{}`, \
which defines the `Drop` trait", which defines the `Drop` trait",
b.ty) b.ty);
err.span_label(move_from.span, &format!("can not move out of here"));
err
}, },
_ => { _ => {
span_bug!(move_from.span, "this path should not cause illegal move"); span_bug!(move_from.span, "this path should not cause illegal move");
@ -168,7 +173,7 @@ fn note_move_destination(mut err: DiagnosticBuilder,
pat_name: ast::Name, pat_name: ast::Name,
is_first_note: bool) -> DiagnosticBuilder { is_first_note: bool) -> DiagnosticBuilder {
if is_first_note { if is_first_note {
err = err.span_label( err.span_label(
move_to_span, move_to_span,
&format!("attempting to move value to here")); &format!("attempting to move value to here"));
err.help( err.help(

View File

@ -624,9 +624,8 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
let mut db = self.struct_span_err( let mut db = self.struct_span_err(
err.span, err.span,
&self.bckerr_to_string(&err)); &self.bckerr_to_string(&err));
self.note_and_explain_bckerr(&mut db, err); self.note_and_explain_bckerr(&mut db, err, span);
db.span_label(span, &format!("cannot borrow")) db.emit();
.emit();
} }
pub fn report_use_of_moved_value(&self, pub fn report_use_of_moved_value(&self,
@ -721,10 +720,12 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
err.span_label( err.span_label(
use_span, use_span,
&format!("value moved{} here in previous iteration of loop", &format!("value moved{} here in previous iteration of loop",
move_note)) move_note));
err
} else { } else {
err.span_label(use_span, &format!("value {} here after move", verb_participle)) err.span_label(use_span, &format!("value {} here after move", verb_participle))
.span_label(move_span, &format!("value moved{} here", move_note)) .span_label(move_span, &format!("value moved{} here", move_note));
err
}; };
err.note(&format!("move occurs because `{}` has type `{}`, \ err.note(&format!("move occurs because `{}` has type `{}`, \
@ -951,7 +952,8 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
.emit(); .emit();
} }
pub fn note_and_explain_bckerr(&self, db: &mut DiagnosticBuilder, err: BckError<'tcx>) { pub fn note_and_explain_bckerr(&self, db: &mut DiagnosticBuilder, err: BckError<'tcx>,
error_span: Span) {
let code = err.code; let code = err.code;
match code { match code {
err_mutbl => { err_mutbl => {
@ -976,13 +978,11 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
let span = self.tcx.map.span(local_id); let span = self.tcx.map.span(local_id);
if let Ok(snippet) = self.tcx.sess.codemap().span_to_snippet(span) { if let Ok(snippet) = self.tcx.sess.codemap().span_to_snippet(span) {
if snippet != "self" { if snippet != "self" {
db.span_suggestion( db.span_label(span,
span, &format!("use `mut {}` here to make mutable", snippet));
&format!("to make the {} mutable, use `mut` as shown:",
self.cmt_to_string(&err.cmt)),
format!("mut {}", snippet));
} }
} }
db.span_label(error_span, &format!("cannot borrow mutably"));
} }
} }
} }
@ -1000,6 +1000,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
super_scope, super_scope,
""); "");
if let Some(span) = statement_scope_span(self.tcx, super_scope) { if let Some(span) = statement_scope_span(self.tcx, super_scope) {
db.span_label(error_span, &format!("does not live long enough"));
db.span_help(span, db.span_help(span,
"consider using a `let` binding to increase its lifetime"); "consider using a `let` binding to increase its lifetime");
} }

View File

@ -123,7 +123,7 @@ enum ResolutionError<'a> {
SelfUsedOutsideImplOrTrait, SelfUsedOutsideImplOrTrait,
/// error E0412: use of undeclared /// error E0412: use of undeclared
UseOfUndeclared(&'a str, &'a str, SuggestedCandidates), UseOfUndeclared(&'a str, &'a str, SuggestedCandidates),
/// error E0413: declaration shadows an enum variant or unit-like struct in scope /// error E0413: cannot be named the same as an enum variant or unit-like struct in scope
DeclarationShadowsEnumVariantOrUnitLikeStruct(Name), DeclarationShadowsEnumVariantOrUnitLikeStruct(Name),
/// error E0414: only irrefutable patterns allowed here /// error E0414: only irrefutable patterns allowed here
ConstantForIrrefutableBinding(Name), ConstantForIrrefutableBinding(Name),
@ -205,7 +205,7 @@ fn resolve_struct_error<'b, 'a: 'b, 'c>(resolver: &'b Resolver<'a>,
E0401, E0401,
"can't use type parameters from outer function; \ "can't use type parameters from outer function; \
try using a local type parameter instead"); try using a local type parameter instead");
err = err.span_label(span, &format!("use of type variable from outer function")); err.span_label(span, &format!("use of type variable from outer function"));
err err
} }
ResolutionError::OuterTypeParameterContext => { ResolutionError::OuterTypeParameterContext => {
@ -232,7 +232,7 @@ fn resolve_struct_error<'b, 'a: 'b, 'c>(resolver: &'b Resolver<'a>,
"trait `{}` is not in scope", "trait `{}` is not in scope",
name); name);
show_candidates(&mut err, &candidates); show_candidates(&mut err, &candidates);
err = err.span_label(span, &format!("`{}` is not in scope", name)); err.span_label(span, &format!("`{}` is not in scope", name));
err err
} }
ResolutionError::UndeclaredAssociatedType => { ResolutionError::UndeclaredAssociatedType => {
@ -285,7 +285,7 @@ fn resolve_struct_error<'b, 'a: 'b, 'c>(resolver: &'b Resolver<'a>,
span, span,
E0411, E0411,
"use of `Self` outside of an impl or trait"); "use of `Self` outside of an impl or trait");
err = err.span_label(span, &format!("Used outside of impl or trait")); err.span_label(span, &format!("Used outside of impl or trait"));
err err
} }
ResolutionError::UseOfUndeclared(kind, name, candidates) => { ResolutionError::UseOfUndeclared(kind, name, candidates) => {
@ -296,7 +296,7 @@ fn resolve_struct_error<'b, 'a: 'b, 'c>(resolver: &'b Resolver<'a>,
kind, kind,
name); name);
show_candidates(&mut err, &candidates); show_candidates(&mut err, &candidates);
err = err.span_label(span, &format!("undefined or not in scope")); err.span_label(span, &format!("undefined or not in scope"));
err err
} }
ResolutionError::DeclarationShadowsEnumVariantOrUnitLikeStruct(name) => { ResolutionError::DeclarationShadowsEnumVariantOrUnitLikeStruct(name) => {
@ -306,7 +306,7 @@ fn resolve_struct_error<'b, 'a: 'b, 'c>(resolver: &'b Resolver<'a>,
"`{}` cannot be named the same as an enum variant \ "`{}` cannot be named the same as an enum variant \
or unit-like struct in scope", or unit-like struct in scope",
name); name);
err = err.span_label(span, err.span_label(span,
&format!("has same name as enum variant or unit-like struct")); &format!("has same name as enum variant or unit-like struct"));
err err
} }
@ -315,13 +315,13 @@ fn resolve_struct_error<'b, 'a: 'b, 'c>(resolver: &'b Resolver<'a>,
span, span,
E0414, E0414,
"let variables cannot be named the same as const variables"); "let variables cannot be named the same as const variables");
err = err.span_label(span, err.span_label(span,
&format!("cannot be named the same as a const variable")); &format!("cannot be named the same as a const variable"));
if let Some(binding) = resolver.current_module if let Some(binding) = resolver.current_module
.resolve_name_in_lexical_scope(name, ValueNS) { .resolve_name_in_lexical_scope(name, ValueNS) {
let participle = if binding.is_import() { "imported" } else { "defined" }; let participle = if binding.is_import() { "imported" } else { "defined" };
err = err.span_label(binding.span, &format!("a constant `{}` is {} here", err.span_label(binding.span, &format!("a constant `{}` is {} here",
name, participle)); name, participle));
} }
err err
} }
@ -331,7 +331,7 @@ fn resolve_struct_error<'b, 'a: 'b, 'c>(resolver: &'b Resolver<'a>,
E0415, E0415,
"identifier `{}` is bound more than once in this parameter list", "identifier `{}` is bound more than once in this parameter list",
identifier); identifier);
err = err.span_label(span, &format!("used as parameter more than once")); err.span_label(span, &format!("used as parameter more than once"));
err err
} }
ResolutionError::IdentifierBoundMoreThanOnceInSamePattern(identifier) => { ResolutionError::IdentifierBoundMoreThanOnceInSamePattern(identifier) => {
@ -340,7 +340,7 @@ fn resolve_struct_error<'b, 'a: 'b, 'c>(resolver: &'b Resolver<'a>,
E0416, E0416,
"identifier `{}` is bound more than once in the same pattern", "identifier `{}` is bound more than once in the same pattern",
identifier); identifier);
err = err.span_label(span, &format!("used in a pattern more than once")); err.span_label(span, &format!("used in a pattern more than once"));
err err
} }
ResolutionError::StaticVariableReference(binding) => { ResolutionError::StaticVariableReference(binding) => {
@ -349,10 +349,10 @@ fn resolve_struct_error<'b, 'a: 'b, 'c>(resolver: &'b Resolver<'a>,
E0417, E0417,
"static variables cannot be referenced in a \ "static variables cannot be referenced in a \
pattern, use a `const` instead"); pattern, use a `const` instead");
err = err.span_label(span, &format!("static variable used in pattern")); err.span_label(span, &format!("static variable used in pattern"));
if binding.span != codemap::DUMMY_SP { if binding.span != codemap::DUMMY_SP {
let participle = if binding.is_import() { "imported" } else { "defined" }; let participle = if binding.is_import() { "imported" } else { "defined" };
err = err.span_label(binding.span, &format!("static variable {} here", participle)); err.span_label(binding.span, &format!("static variable {} here", participle));
} }
err err
} }
@ -1819,8 +1819,8 @@ impl<'a> Resolver<'a> {
// If it's a typedef, give a note // If it's a typedef, give a note
if let Def::TyAlias(..) = path_res.base_def { if let Def::TyAlias(..) = path_res.base_def {
let trait_name = trait_path.segments.last().unwrap().identifier.name; let trait_name = trait_path.segments.last().unwrap().identifier.name;
err = err.span_label(trait_path.span, err.span_label(trait_path.span,
&format!("`{}` is not a trait", trait_name)); &format!("`{}` is not a trait", trait_name));
let definition_site = { let definition_site = {
let segments = &trait_path.segments; let segments = &trait_path.segments;
@ -1832,8 +1832,8 @@ impl<'a> Resolver<'a> {
}; };
if definition_site != codemap::DUMMY_SP { if definition_site != codemap::DUMMY_SP {
err = err.span_label(definition_site, err.span_label(definition_site,
&format!("note: type aliases cannot be used for traits")); &format!("type aliases cannot be used for traits"));
} }
} }
err.emit(); err.emit();
@ -3480,14 +3480,15 @@ impl<'a> Resolver<'a> {
(false, false) => struct_span_err!(self.session, span, E0428, "{}", msg), (false, false) => struct_span_err!(self.session, span, E0428, "{}", msg),
(true, true) => struct_span_err!(self.session, span, E0252, "{}", msg), (true, true) => struct_span_err!(self.session, span, E0252, "{}", msg),
_ => { _ => {
let e = struct_span_err!(self.session, span, E0255, "{}", msg); let mut e = struct_span_err!(self.session, span, E0255, "{}", msg);
e.span_label(span, &format!("`{}` was already imported", name)) e.span_label(span, &format!("`{}` was already imported", name));
e
} }
}, },
}; };
if old_binding.span != codemap::DUMMY_SP { if old_binding.span != codemap::DUMMY_SP {
err = err.span_label(old_binding.span, &format!("previous {} of `{}` here", noun, name)); err.span_label(old_binding.span, &format!("previous {} of `{}` here", noun, name));
} }
err.emit(); err.emit();
} }

View File

@ -235,17 +235,17 @@ impl<'a> DiagnosticBuilder<'a> {
/// all, and you just supplied a `Span` to create the diagnostic, /// all, and you just supplied a `Span` to create the diagnostic,
/// then the snippet will just include that `Span`, which is /// then the snippet will just include that `Span`, which is
/// called the primary span. /// called the primary span.
pub fn span_label(mut self, span: Span, label: &fmt::Display) pub fn span_label(&mut self, span: Span, label: &fmt::Display)
-> DiagnosticBuilder<'a> { -> &mut DiagnosticBuilder<'a> {
self.span.push_span_label(span, format!("{}", label)); self.span.push_span_label(span, format!("{}", label));
self self
} }
pub fn note_expected_found(mut self, pub fn note_expected_found(&mut self,
label: &fmt::Display, label: &fmt::Display,
expected: &fmt::Display, expected: &fmt::Display,
found: &fmt::Display) found: &fmt::Display)
-> DiagnosticBuilder<'a> -> &mut DiagnosticBuilder<'a>
{ {
// For now, just attach these as notes // For now, just attach these as notes
self.note(&format!("expected {} `{}`", label, expected)); self.note(&format!("expected {} `{}`", label, expected));

View File

@ -27,7 +27,9 @@ fn main() {
x; //~ value moved here x; //~ value moved here
let y = Int(2); let y = Int(2);
//~^use `mut y` here to make mutable
y //~ error: cannot borrow immutable local variable `y` as mutable y //~ error: cannot borrow immutable local variable `y` as mutable
//~| cannot borrow
+= +=
Int(1); Int(1);
} }

View File

@ -12,6 +12,6 @@ mod foo { pub struct bar; }
fn main() { fn main() {
let bar = 5; let bar = 5;
//~^ ERROR declaration of `bar` shadows an enum variant or unit-like struct in scope //~^ ERROR cannot be named the same
use foo::bar; use foo::bar;
} }

View File

@ -10,6 +10,8 @@
mod foo { pub mod foo { } } //~ NOTE previous definition of `foo` here mod foo { pub mod foo { } } //~ NOTE previous definition of `foo` here
use foo::foo; //~ ERROR a module named `foo` has already been defined in this module use foo::foo;
//~^ ERROR a module named `foo` has already been defined in this module
//~| was already imported
fn main() {} fn main() {}

View File

@ -61,7 +61,9 @@ fn move_after_borrow() {
let a: Box<_> = box B { x: box 0, y: box 1 }; let a: Box<_> = box B { x: box 0, y: box 1 };
let _x = &a.x; let _x = &a.x;
//~^ NOTE borrow of `a.x` occurs here //~^ NOTE borrow of `a.x` occurs here
let _y = a.y; //~ ERROR cannot move let _y = a.y;
//~^ ERROR cannot move
//~| move out of
} }
fn copy_after_mut_borrow() { fn copy_after_mut_borrow() {
@ -75,7 +77,9 @@ fn move_after_mut_borrow() {
let mut a: Box<_> = box B { x: box 0, y: box 1 }; let mut a: Box<_> = box B { x: box 0, y: box 1 };
let _x = &mut a.x; let _x = &mut a.x;
//~^ NOTE borrow of `a.x` occurs here //~^ NOTE borrow of `a.x` occurs here
let _y = a.y; //~ ERROR cannot move let _y = a.y;
//~^ ERROR cannot move
//~| move out of
} }
fn borrow_after_mut_borrow() { fn borrow_after_mut_borrow() {
@ -127,7 +131,9 @@ fn move_after_borrow_nested() {
let a: Box<_> = box D { x: box A { x: box 0, y: 1 }, y: box 2 }; let a: Box<_> = box D { x: box A { x: box 0, y: 1 }, y: box 2 };
let _x = &a.x.x; let _x = &a.x.x;
//~^ borrow of `a.x.x` occurs here //~^ borrow of `a.x.x` occurs here
let _y = a.y; //~ ERROR cannot move let _y = a.y;
//~^ ERROR cannot move
//~| move out of
} }
fn copy_after_mut_borrow_nested() { fn copy_after_mut_borrow_nested() {
@ -141,7 +147,9 @@ fn move_after_mut_borrow_nested() {
let mut a: Box<_> = box D { x: box A { x: box 0, y: 1 }, y: box 2 }; let mut a: Box<_> = box D { x: box A { x: box 0, y: 1 }, y: box 2 };
let _x = &mut a.x.x; let _x = &mut a.x.x;
//~^ NOTE borrow of `a.x.x` occurs here //~^ NOTE borrow of `a.x.x` occurs here
let _y = a.y; //~ ERROR cannot move let _y = a.y;
//~^ ERROR cannot move
//~| move out of
} }
fn borrow_after_mut_borrow_nested() { fn borrow_after_mut_borrow_nested() {

View File

@ -26,6 +26,7 @@ fn f() {
v3.push(&'x'); // statement 6 v3.push(&'x'); // statement 6
//~^ ERROR borrowed value does not live long enough //~^ ERROR borrowed value does not live long enough
//~| does not live long enough
//~| NOTE ...but borrowed value is only valid for the statement //~| NOTE ...but borrowed value is only valid for the statement
//~| HELP consider using a `let` binding to increase its lifetime //~| HELP consider using a `let` binding to increase its lifetime
@ -36,6 +37,7 @@ fn f() {
v4.push(&'y'); v4.push(&'y');
//~^ ERROR borrowed value does not live long enough //~^ ERROR borrowed value does not live long enough
//~| does not live long enough
//~| NOTE ...but borrowed value is only valid for the statement //~| NOTE ...but borrowed value is only valid for the statement
//~| HELP consider using a `let` binding to increase its lifetime //~| HELP consider using a `let` binding to increase its lifetime
@ -46,6 +48,7 @@ fn f() {
v5.push(&'z'); v5.push(&'z');
//~^ ERROR borrowed value does not live long enough //~^ ERROR borrowed value does not live long enough
//~| does not live long enough
//~| NOTE ...but borrowed value is only valid for the statement //~| NOTE ...but borrowed value is only valid for the statement
//~| HELP consider using a `let` binding to increase its lifetime //~| HELP consider using a `let` binding to increase its lifetime

View File

@ -9,10 +9,12 @@
// except according to those terms. // except according to those terms.
fn f() { fn f() {
let x = [1].iter(); //~ ERROR borrowed value does not live long enough let x = [1].iter();
//~^ NOTE reference must be valid for the block suffix following statement //~^ ERROR borrowed value does not live long enough
//~^^ HELP consider using a `let` binding to increase its lifetime //~|does not live long enough
//~^^^ NOTE ...but borrowed value is only valid for the statement at 12:4 //~| NOTE reference must be valid for the block suffix following statement
//~| HELP consider using a `let` binding to increase its lifetime
//~| NOTE ...but borrowed value is only valid for the statement at 12:4
} }
fn main() { fn main() {

View File

@ -19,6 +19,7 @@ enum Foo {
fn blah() { fn blah() {
let f = &Foo::Foo1(box 1, box 2); let f = &Foo::Foo1(box 1, box 2);
match *f { //~ ERROR cannot move out of match *f { //~ ERROR cannot move out of
//~| move occurs here
Foo::Foo1(num1, //~ NOTE attempting to move value to here Foo::Foo1(num1, //~ NOTE attempting to move value to here
num2) => (), //~ NOTE and here num2) => (), //~ NOTE and here
Foo::Foo2(num) => (), //~ NOTE and here Foo::Foo2(num) => (), //~ NOTE and here
@ -37,6 +38,7 @@ impl Drop for S {
fn move_in_match() { fn move_in_match() {
match (S {f: "foo".to_string(), g: "bar".to_string()}) { match (S {f: "foo".to_string(), g: "bar".to_string()}) {
S { //~ ERROR cannot move out of type `S`, which defines the `Drop` trait S { //~ ERROR cannot move out of type `S`, which defines the `Drop` trait
//~| can not move out of here
f: _s, //~ NOTE attempting to move value to here f: _s, //~ NOTE attempting to move value to here
g: _t //~ NOTE and here g: _t //~ NOTE and here
} => {} } => {}
@ -53,6 +55,7 @@ fn free<T>(_: T) {}
fn blah2() { fn blah2() {
let a = &A { a: box 1 }; let a = &A { a: box 1 };
match a.a { //~ ERROR cannot move out of match a.a { //~ ERROR cannot move out of
//~| move occurs here
n => { //~ NOTE attempting to move value to here n => { //~ NOTE attempting to move value to here
free(n) free(n)
} }

View File

@ -27,10 +27,12 @@ pub fn main() {
match x { match x {
[_, tail..] => { [_, tail..] => {
match tail { match tail {
[Foo { string: a }, //~ ERROR cannot move out of borrowed content [Foo { string: a },
//~^ ERROR cannot move out of borrowed content
//~| move occurs here
//~| attempting to move value to here
Foo { string: b }] => { Foo { string: b }] => {
//~^^ NOTE attempting to move value to here //~^ NOTE and here
//~^^ NOTE and here
} }
_ => { _ => {
unreachable!(); unreachable!();

View File

@ -19,6 +19,7 @@ fn a() {
[box ref _a, _, _] => { [box ref _a, _, _] => {
//~^ borrow of `vec[..]` occurs here //~^ borrow of `vec[..]` occurs here
vec[0] = box 4; //~ ERROR cannot assign vec[0] = box 4; //~ ERROR cannot assign
//~^ assignment to `vec[..]` occurs here
} }
} }
} }
@ -30,6 +31,7 @@ fn b() {
[_b..] => { [_b..] => {
//~^ borrow of `vec[..]` occurs here //~^ borrow of `vec[..]` occurs here
vec[0] = box 4; //~ ERROR cannot assign vec[0] = box 4; //~ ERROR cannot assign
//~^ assignment to `vec[..]` occurs here
} }
} }
} }
@ -39,8 +41,9 @@ fn c() {
let vec: &mut [Box<isize>] = &mut vec; let vec: &mut [Box<isize>] = &mut vec;
match vec { match vec {
[_a, //~ ERROR cannot move out [_a, //~ ERROR cannot move out
_b..] => { //~^ NOTE attempting to move value to here //~| move occurs here
//~| attempting to move value to here
_b..] => {
// Note: `_a` is *moved* here, but `b` is borrowing, // Note: `_a` is *moved* here, but `b` is borrowing,
// hence illegal. // hence illegal.
// //
@ -51,6 +54,7 @@ fn c() {
} }
let a = vec[0]; //~ ERROR cannot move out let a = vec[0]; //~ ERROR cannot move out
//~^ NOTE attempting to move value to here //~^ NOTE attempting to move value to here
//~| can not move out of here
} }
fn d() { fn d() {
@ -58,11 +62,13 @@ fn d() {
let vec: &mut [Box<isize>] = &mut vec; let vec: &mut [Box<isize>] = &mut vec;
match vec { match vec {
[_a.., //~ ERROR cannot move out [_a.., //~ ERROR cannot move out
//~^ move occurs here
_b] => {} //~ NOTE attempting to move value to here _b] => {} //~ NOTE attempting to move value to here
_ => {} _ => {}
} }
let a = vec[0]; //~ ERROR cannot move out let a = vec[0]; //~ ERROR cannot move out
//~^ NOTE attempting to move value to here //~^ NOTE attempting to move value to here
//~| can not move out of here
} }
fn e() { fn e() {
@ -70,13 +76,15 @@ fn e() {
let vec: &mut [Box<isize>] = &mut vec; let vec: &mut [Box<isize>] = &mut vec;
match vec { match vec {
[_a, _b, _c] => {} //~ ERROR cannot move out [_a, _b, _c] => {} //~ ERROR cannot move out
//~^ NOTE attempting to move value to here //~| move occurs here
//~^^ NOTE and here //~| NOTE attempting to move value to here
//~^^^ NOTE and here //~| NOTE and here
//~| NOTE and here
_ => {} _ => {}
} }
let a = vec[0]; //~ ERROR cannot move out let a = vec[0]; //~ ERROR cannot move out
//~^ NOTE attempting to move value to here //~^ NOTE attempting to move value to here
//~| can not move out of here
} }
fn main() {} fn main() {}

View File

@ -13,16 +13,16 @@ mod foo {
pub const d: u8 = 2; pub const d: u8 = 2;
} }
use foo::b as c; //~ NOTE constant imported here use foo::b as c; //~ NOTE is imported here
use foo::d; //~ NOTE constant imported here use foo::d; //~ NOTE is imported here
const a: u8 = 2; //~ NOTE constant defined here const a: u8 = 2; //~ NOTE is defined here
fn main() { fn main() {
let a = 4; //~ ERROR variable bindings cannot let a = 4; //~ ERROR let variables cannot
//~^ NOTE there already is a constant in scope //~^ NOTE cannot be named the same as a const variable
let c = 4; //~ ERROR variable bindings cannot let c = 4; //~ ERROR let variables cannot
//~^ NOTE there already is a constant in scope //~^ NOTE cannot be named the same as a const variable
let d = 4; //~ ERROR variable bindings cannot let d = 4; //~ ERROR let variables cannot
//~^ NOTE there already is a constant in scope //~^ NOTE cannot be named the same as a const variable
} }

View File

@ -11,5 +11,5 @@
struct hello(isize); struct hello(isize);
fn main() { fn main() {
let hello = 0; //~ERROR declaration of `hello` shadows let hello = 0; //~ERROR cannot be named the same
} }

View File

@ -11,11 +11,13 @@
use self::A; //~ NOTE previous import of `A` here use self::A; //~ NOTE previous import of `A` here
use self::B; //~ NOTE previous import of `B` here use self::B; //~ NOTE previous import of `B` here
mod A {} //~ ERROR a module named `A` has already been imported in this module mod A {} //~ ERROR a module named `A` has already been imported in this module
//~| `A` was already imported
pub mod B {} //~ ERROR a module named `B` has already been imported in this module pub mod B {} //~ ERROR a module named `B` has already been imported in this module
//~| `B` was already imported
mod C { mod C {
use C::D; //~ NOTE previous import of `D` here use C::D; //~ NOTE previous import of `D` here
mod D {} //~ ERROR a module named `D` has already been imported in this module mod D {} //~ ERROR a module named `D` has already been imported in this module
//~| `D` was already imported
} }
fn main() {} fn main() {}

View File

@ -13,6 +13,7 @@ static foo: i32 = 0;
fn bar(foo: i32) {} fn bar(foo: i32) {}
//~^ ERROR static variables cannot be referenced in a pattern, use a `const` instead //~^ ERROR static variables cannot be referenced in a pattern, use a `const` instead
//~| static variable used in pattern
mod submod { mod submod {
pub static answer: i32 = 42; pub static answer: i32 = 42;
@ -23,6 +24,6 @@ use self::submod::answer;
fn question(answer: i32) {} fn question(answer: i32) {}
//~^ ERROR static variables cannot be referenced in a pattern, use a `const` instead //~^ ERROR static variables cannot be referenced in a pattern, use a `const` instead
//~| static variable used in pattern
fn main() { fn main() {
} }

View File

@ -15,9 +15,14 @@ use std::ops::Div; //~ NOTE previous import
use std::ops::Rem; //~ NOTE previous import use std::ops::Rem; //~ NOTE previous import
type Add = bool; //~ ERROR a trait named `Add` has already been imported in this module type Add = bool; //~ ERROR a trait named `Add` has already been imported in this module
//~| was already imported
struct Sub { x: f32 } //~ ERROR a trait named `Sub` has already been imported in this module struct Sub { x: f32 } //~ ERROR a trait named `Sub` has already been imported in this module
//~| was already imported
enum Mul { A, B } //~ ERROR a trait named `Mul` has already been imported in this module enum Mul { A, B } //~ ERROR a trait named `Mul` has already been imported in this module
//~| was already imported
mod Div { } //~ ERROR a trait named `Div` has already been imported in this module mod Div { } //~ ERROR a trait named `Div` has already been imported in this module
//~| was already imported
trait Rem { } //~ ERROR a trait named `Rem` has already been imported in this module trait Rem { } //~ ERROR a trait named `Rem` has already been imported in this module
//~| was already imported
fn main() {} fn main() {}

View File

@ -10,11 +10,11 @@
fn main() { fn main() {
match Some(1) { match Some(1) {
None @ _ => {} //~ ERROR declaration of `None` shadows an enum variant None @ _ => {} //~ ERROR cannot be named the same
}; };
const C: u8 = 1; const C: u8 = 1;
match 1 { match 1 {
C @ 2 => { //~ ERROR variable bindings cannot shadow constants C @ 2 => { //~ ERROR cannot be named the same
println!("{}", C); println!("{}", C);
} }
_ => {} _ => {}

View File

@ -11,14 +11,14 @@
// aux-build:issue_3907.rs // aux-build:issue_3907.rs
extern crate issue_3907; extern crate issue_3907;
type Foo = issue_3907::Foo; //~ NOTE: type defined here type Foo = issue_3907::Foo; //~ NOTE: type aliases cannot be used for traits
struct S { struct S {
name: isize name: isize
} }
impl Foo for S { //~ ERROR: `Foo` is not a trait impl Foo for S { //~ ERROR: `Foo` is not a trait
//~^ NOTE: `type` aliases cannot be used for traits //~| `Foo` is not a trait
fn bar() { } fn bar() { }
} }

View File

@ -9,7 +9,8 @@
// except according to those terms. // except according to those terms.
trait I {} trait I {}
type K = I; //~ NOTE: type defined here type K = I;
//~^ NOTE: aliases cannot be used for traits
impl K for isize {} //~ ERROR: `K` is not a trait impl K for isize {} //~ ERROR: `K` is not a trait
//~^ NOTE: `type` aliases cannot be used for traits //~| is not a trait
fn main() {} fn main() {}

View File

@ -32,6 +32,7 @@ fn main() {
loop { loop {
f(&s, |hellothere| { f(&s, |hellothere| {
match hellothere.x { //~ ERROR cannot move out match hellothere.x { //~ ERROR cannot move out
//~| move occurs here
box E::Foo(_) => {} box E::Foo(_) => {}
box E::Bar(x) => println!("{}", x.to_string()), //~ NOTE attempting to move value to here box E::Bar(x) => println!("{}", x.to_string()), //~ NOTE attempting to move value to here
box E::Baz => {} box E::Baz => {}

View File

@ -17,14 +17,16 @@ impl S {
} }
fn func(arg: S) { fn func(arg: S) {
//~^ HELP use `mut` as shown //~^ here to make mutable
//~| SUGGESTION fn func(mut arg: S) { arg.mutate();
arg.mutate(); //~ ERROR cannot borrow immutable argument //~^ ERROR cannot borrow immutable argument
//~| cannot borrow mutably
} }
fn main() { fn main() {
let local = S; let local = S;
//~^ HELP use `mut` as shown //~^ here to make mutable
//~| SUGGESTION let mut local = S; local.mutate();
local.mutate(); //~ ERROR cannot borrow immutable local variable //~^ ERROR cannot borrow immutable local variable
//~| cannot borrow mutably
} }

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
// error-pattern:declaration of `None` shadows // error-pattern:cannot be named the same
use std::option::*; use std::option::*;
fn main() { fn main() {

View File

@ -11,5 +11,5 @@
struct foo(usize); struct foo(usize);
fn main() { fn main() {
let (foo, _) = (2, 3); //~ ERROR declaration of `foo` shadows let (foo, _) = (2, 3); //~ ERROR `foo` cannot be named the same as
} }

View File

@ -13,6 +13,6 @@ use std::mem::transmute;
fn transmute() {} fn transmute() {}
//~^ ERROR a value named `transmute` has already been imported in this module //~^ ERROR a value named `transmute` has already been imported in this module
//~| was already imported
fn main() { fn main() {
} }