1
Fork 0

Remove need for &format!(...) or &&"" dances in span_label calls

This commit is contained in:
Oliver Schneider 2017-05-04 14:17:23 +02:00
parent 70198a0a44
commit dd87eabd83
56 changed files with 305 additions and 305 deletions

View file

@ -43,7 +43,7 @@ impl<'a> CheckAttrVisitor<'a> {
fn check_inline(&self, attr: &ast::Attribute, target: Target) { fn check_inline(&self, attr: &ast::Attribute, target: Target) {
if target != Target::Fn { if target != Target::Fn {
struct_span_err!(self.sess, attr.span, E0518, "attribute should be applied to function") struct_span_err!(self.sess, attr.span, E0518, "attribute should be applied to function")
.span_label(attr.span, &format!("requires a function")) .span_label(attr.span, "requires a function")
.emit(); .emit();
} }
} }
@ -123,7 +123,7 @@ impl<'a> CheckAttrVisitor<'a> {
_ => continue, _ => continue,
}; };
struct_span_err!(self.sess, attr.span, E0517, "{}", message) struct_span_err!(self.sess, attr.span, E0517, "{}", message)
.span_label(attr.span, &format!("requires {}", label)) .span_label(attr.span, format!("requires {}", label))
.emit(); .emit();
} }
if conflicting_reprs > 1 { if conflicting_reprs > 1 {

View file

@ -668,9 +668,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
} }
} }
diag.span_label(span, &terr); diag.span_label(span, terr.to_string());
if let Some((sp, msg)) = secondary_span { if let Some((sp, msg)) = secondary_span {
diag.span_label(sp, &msg); diag.span_label(sp, msg);
} }
self.note_error_origin(diag, &cause); self.note_error_origin(diag, &cause);

View file

@ -680,12 +680,12 @@ pub trait LintContext<'tcx>: Sized {
"{}({}) overruled by outer forbid({})", "{}({}) overruled by outer forbid({})",
level.as_str(), lint_name, level.as_str(), lint_name,
lint_name); lint_name);
diag_builder.span_label(span, &format!("overruled by previous forbid")); diag_builder.span_label(span, "overruled by previous forbid");
match now_source { match now_source {
LintSource::Default => &mut diag_builder, LintSource::Default => &mut diag_builder,
LintSource::Node(_, forbid_source_span) => { LintSource::Node(_, forbid_source_span) => {
diag_builder.span_label(forbid_source_span, diag_builder.span_label(forbid_source_span,
&format!("`forbid` level set here")) "`forbid` level set here")
}, },
LintSource::CommandLine(_) => { LintSource::CommandLine(_) => {
diag_builder.note("`forbid` lint level was set on command line") diag_builder.note("`forbid` lint level was set on command line")

View file

@ -197,7 +197,7 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> {
{ {
match self.description() { match self.description() {
ConstEvalErrDescription::Simple(message) => { ConstEvalErrDescription::Simple(message) => {
diag.span_label(self.span, &message); diag.span_label(self.span, message);
} }
} }

View file

@ -74,7 +74,7 @@ impl<'a, 'tcx> EffectCheckVisitor<'a, 'tcx> {
struct_span_err!( struct_span_err!(
self.tcx.sess, span, E0133, self.tcx.sess, span, E0133,
"{} requires unsafe function or block", description) "{} requires unsafe function or block", description)
.span_label(span, &description) .span_label(span, description)
.emit(); .emit();
} }
} }

View file

@ -128,8 +128,8 @@ fn find_item(item: &Item, ctxt: &mut EntryContext, at_root: bool) {
} else { } else {
struct_span_err!(ctxt.session, item.span, E0137, struct_span_err!(ctxt.session, item.span, E0137,
"multiple functions with a #[main] attribute") "multiple functions with a #[main] attribute")
.span_label(item.span, &format!("additional #[main] function")) .span_label(item.span, "additional #[main] function")
.span_label(ctxt.attr_main_fn.unwrap().1, &format!("first #[main] function")) .span_label(ctxt.attr_main_fn.unwrap().1, "first #[main] function")
.emit(); .emit();
} }
}, },
@ -141,8 +141,8 @@ fn find_item(item: &Item, ctxt: &mut EntryContext, at_root: bool) {
ctxt.session, item.span, E0138, ctxt.session, item.span, E0138,
"multiple 'start' functions") "multiple 'start' functions")
.span_label(ctxt.start_fn.unwrap().1, .span_label(ctxt.start_fn.unwrap().1,
&format!("previous `start` function here")) "previous `start` function here")
.span_label(item.span, &format!("multiple `start` functions")) .span_label(item.span, "multiple `start` functions")
.emit(); .emit();
} }
}, },

View file

@ -92,7 +92,7 @@ impl<'a, 'gcx, 'tcx> ExprVisitor<'a, 'gcx, 'tcx> {
struct_span_err!(self.infcx.tcx.sess, span, E0591, struct_span_err!(self.infcx.tcx.sess, span, E0591,
"`{}` is zero-sized and can't be transmuted to `{}`", "`{}` is zero-sized and can't be transmuted to `{}`",
from, to) from, to)
.span_note(span, &format!("cast with `as` to a pointer instead")) .span_note(span, "cast with `as` to a pointer instead")
.emit(); .emit();
return; return;
} }
@ -126,7 +126,7 @@ impl<'a, 'gcx, 'tcx> ExprVisitor<'a, 'gcx, 'tcx> {
from, skeleton_string(from, sk_from), from, skeleton_string(from, sk_from),
to, skeleton_string(to, sk_to)) to, skeleton_string(to, sk_to))
.span_label(span, .span_label(span,
&format!("transmuting between {} and {}", format!("transmuting between {} and {}",
skeleton_string(from, sk_from), skeleton_string(from, sk_from),
skeleton_string(to, sk_to))) skeleton_string(to, sk_to)))
.emit(); .emit();

View file

@ -574,9 +574,9 @@ fn signal_shadowing_problem(sess: &Session, name: ast::Name, orig: Original, sha
{} name that is already in scope", {} name that is already in scope",
shadower.kind.desc(), name, orig.kind.desc())) shadower.kind.desc(), name, orig.kind.desc()))
}; };
err.span_label(orig.span, &"first declared here"); err.span_label(orig.span, "first declared here");
err.span_label(shadower.span, err.span_label(shadower.span,
&format!("lifetime {} already in scope", name)); format!("lifetime {} already in scope", name));
err.emit(); err.emit();
} }
@ -919,7 +919,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
} else { } else {
struct_span_err!(self.sess, lifetime_ref.span, E0261, struct_span_err!(self.sess, lifetime_ref.span, E0261,
"use of undeclared lifetime name `{}`", lifetime_ref.name) "use of undeclared lifetime name `{}`", lifetime_ref.name)
.span_label(lifetime_ref.span, &format!("undeclared lifetime")) .span_label(lifetime_ref.span, "undeclared lifetime")
.emit(); .emit();
} }
} }
@ -1328,7 +1328,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
} else { } else {
format!("expected lifetime parameter") format!("expected lifetime parameter")
}; };
err.span_label(span, &msg); err.span_label(span, msg);
if let Some(params) = error { if let Some(params) = error {
if lifetime_refs.len() == 1 { if lifetime_refs.len() == 1 {
@ -1438,7 +1438,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
let mut err = struct_span_err!(self.sess, lifetime.span, E0262, let mut err = struct_span_err!(self.sess, lifetime.span, E0262,
"invalid lifetime parameter name: `{}`", lifetime.name); "invalid lifetime parameter name: `{}`", lifetime.name);
err.span_label(lifetime.span, err.span_label(lifetime.span,
&format!("{} is a reserved lifetime name", lifetime.name)); format!("{} is a reserved lifetime name", lifetime.name));
err.emit(); err.emit();
} }
} }
@ -1452,9 +1452,9 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
"lifetime name `{}` declared twice in the same scope", "lifetime name `{}` declared twice in the same scope",
lifetime_j.lifetime.name) lifetime_j.lifetime.name)
.span_label(lifetime_j.lifetime.span, .span_label(lifetime_j.lifetime.span,
&format!("declared twice")) "declared twice")
.span_label(lifetime_i.lifetime.span, .span_label(lifetime_i.lifetime.span,
&format!("previous declaration here")) "previous declaration here")
.emit(); .emit();
} }
} }

View file

@ -484,12 +484,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
if let Some(trait_item_span) = self.tcx.hir.span_if_local(trait_item_def_id) { if let Some(trait_item_span) = self.tcx.hir.span_if_local(trait_item_def_id) {
let span = self.tcx.sess.codemap().def_span(trait_item_span); let span = self.tcx.sess.codemap().def_span(trait_item_span);
err.span_label(span, &format!("definition of `{}` from trait", item_name)); err.span_label(span, format!("definition of `{}` from trait", item_name));
} }
err.span_label( err.span_label(
error_span, error_span,
&format!("impl has extra requirement {}", requirement)); format!("impl has extra requirement {}", requirement));
if let Some(node_id) = lint_id { if let Some(node_id) = lint_id {
self.tcx.sess.add_lint_diagnostic(EXTRA_REQUIREMENT_IN_IMPL, self.tcx.sess.add_lint_diagnostic(EXTRA_REQUIREMENT_IN_IMPL,
@ -582,7 +582,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
} }
err.span_label(span, err.span_label(span,
&format!("{}the trait `{}` is not implemented for `{}`", format!("{}the trait `{}` is not implemented for `{}`",
pre_message, pre_message,
trait_ref, trait_ref,
trait_ref.self_ty())); trait_ref.self_ty()));
@ -738,11 +738,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
expected_ref, expected_ref,
found_ref); found_ref);
err.span_label(span, &format!("{}", type_error)); err.span_label(span, format!("{}", type_error));
if let Some(sp) = found_span { if let Some(sp) = found_span {
err.span_label(span, &format!("requires `{}`", found_ref)); err.span_label(span, format!("requires `{}`", found_ref));
err.span_label(sp, &format!("implements `{}`", expected_ref)); err.span_label(sp, format!("implements `{}`", expected_ref));
} }
err err
@ -765,12 +765,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
if expected == 1 { "" } else { "s" }, if expected == 1 { "" } else { "s" },
if expected == 1 { "is" } else { "are" }); if expected == 1 { "is" } else { "are" });
err.span_label(span, &format!("expected {} that takes {} argument{}", err.span_label(span, format!("expected {} that takes {} argument{}",
if is_closure { "closure" } else { "function" }, if is_closure { "closure" } else { "function" },
expected, expected,
if expected == 1 { "" } else { "s" })); if expected == 1 { "" } else { "s" }));
if let Some(span) = found_span { if let Some(span) = found_span {
err.span_label(span, &format!("takes {} argument{}", err.span_label(span, format!("takes {} argument{}",
found, found,
if found == 1 { "" } else { "s" })); if found == 1 { "" } else { "s" }));
} }
@ -789,7 +789,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
let mut err = struct_span_err!(self.sess, span, E0072, let mut err = struct_span_err!(self.sess, span, E0072,
"recursive type `{}` has infinite size", "recursive type `{}` has infinite size",
self.item_path_str(type_def_id)); self.item_path_str(type_def_id));
err.span_label(span, &format!("recursive type has infinite size")); err.span_label(span, "recursive type has infinite size");
err.help(&format!("insert indirection (e.g., a `Box`, `Rc`, or `&`) \ err.help(&format!("insert indirection (e.g., a `Box`, `Rc`, or `&`) \
at some point to make `{}` representable", at some point to make `{}` representable",
self.item_path_str(type_def_id))); self.item_path_str(type_def_id)));
@ -808,7 +808,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
self.sess, span, E0038, self.sess, span, E0038,
"the trait `{}` cannot be made into an object", "the trait `{}` cannot be made into an object",
trait_str); trait_str);
err.span_label(span, &format!("the trait `{}` cannot be made into an object", trait_str)); err.span_label(span, format!("the trait `{}` cannot be made into an object", trait_str));
let mut reported_violations = FxHashSet(); let mut reported_violations = FxHashSet();
for violation in violations { for violation in violations {
@ -1043,7 +1043,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
"type annotations needed"); "type annotations needed");
for (target_span, label_message) in labels { for (target_span, label_message) in labels {
err.span_label(target_span, &label_message); err.span_label(target_span, label_message);
} }
err.emit(); err.emit();

View file

@ -181,7 +181,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
let mut err = let mut err =
struct_span_err!(self.sess, span, E0391, struct_span_err!(self.sess, span, E0391,
"unsupported cyclic reference between types/traits detected"); "unsupported cyclic reference between types/traits detected");
err.span_label(span, &format!("cyclic reference")); err.span_label(span, "cyclic reference");
err.span_note(stack[0].0, &format!("the cycle begins when {}...", err.span_note(stack[0].0, &format!("the cycle begins when {}...",
stack[0].1.describe(self))); stack[0].1.describe(self)));

View file

@ -469,13 +469,13 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
nl, new_loan_msg); nl, new_loan_msg);
err.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));
err.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));
err.span_label( err.span_label(
previous_end_span, previous_end_span,
&format!("first borrow ends here")); "first borrow ends here");
err err
} }
@ -486,13 +486,13 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
nl); nl);
err.span_label( err.span_label(
old_loan.span, old_loan.span,
&format!("first closure is constructed here")); "first closure is constructed here");
err.span_label( err.span_label(
new_loan.span, new_loan.span,
&format!("second closure is constructed here")); "second closure is constructed here");
err.span_label( err.span_label(
previous_end_span, previous_end_span,
&format!("borrow from first closure ends here")); "borrow from first closure ends here");
err err
} }
@ -503,13 +503,13 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
nl, ol_pronoun, old_loan_msg); nl, ol_pronoun, old_loan_msg);
err.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));
err.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));
err.span_label( err.span_label(
previous_end_span, previous_end_span,
&format!("borrow ends here")); "borrow ends here");
err err
} }
@ -520,13 +520,13 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
nl, new_loan_msg, new_loan.kind.to_user_str()); nl, new_loan_msg, new_loan.kind.to_user_str());
err.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));
err.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));
err.span_label( err.span_label(
previous_end_span, previous_end_span,
&format!("borrow from closure ends here")); "borrow from closure ends here");
err err
} }
@ -542,17 +542,17 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
old_loan_msg); old_loan_msg);
err.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));
err.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));
err.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 err
} }
@ -562,7 +562,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
euv::ClosureCapture(span) => { euv::ClosureCapture(span) => {
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));
} }
_ => { } _ => { }
} }
@ -571,7 +571,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
euv::ClosureCapture(span) => { euv::ClosureCapture(span) => {
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));
} }
_ => { } _ => { }
@ -633,11 +633,11 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
"cannot use `{}` because it was mutably borrowed", "cannot use `{}` because it was mutably borrowed",
&self.bccx.loan_path_to_string(copy_path)) &self.bccx.loan_path_to_string(copy_path))
.span_label(loan_span, .span_label(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(span, .span_label(span,
&format!("use of borrowed `{}`", format!("use of borrowed `{}`",
&self.bccx.loan_path_to_string(&loan_path))) &self.bccx.loan_path_to_string(&loan_path)))
.emit(); .emit();
} }
@ -662,12 +662,12 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
&self.bccx.loan_path_to_string(move_path)); &self.bccx.loan_path_to_string(move_path));
err.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))
); );
err.span_label( err.span_label(
span, span,
&format!("move into closure occurs here") "move into closure occurs here"
); );
err err
} }
@ -679,12 +679,12 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
&self.bccx.loan_path_to_string(move_path)); &self.bccx.loan_path_to_string(move_path));
err.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))
); );
err.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 err
@ -857,10 +857,10 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
"cannot assign to `{}` because it is borrowed", "cannot assign to `{}` because it is borrowed",
self.bccx.loan_path_to_string(loan_path)) self.bccx.loan_path_to_string(loan_path))
.span_label(loan.span, .span_label(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(span, .span_label(span,
&format!("assignment to borrowed `{}` occurs here", format!("assignment to borrowed `{}` occurs here",
self.bccx.loan_path_to_string(loan_path))) self.bccx.loan_path_to_string(loan_path)))
.emit(); .emit();
} }

View file

@ -94,7 +94,7 @@ fn report_move_errors<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, errors: &Vec<Move
} }
if let NoteClosureEnv(upvar_id) = error.move_from.note { if let NoteClosureEnv(upvar_id) = error.move_from.note {
err.span_label(bccx.tcx.hir.span(upvar_id.var_id), err.span_label(bccx.tcx.hir.span(upvar_id.var_id),
&"captured outer variable"); "captured outer variable");
} }
err.emit(); err.emit();
@ -147,7 +147,7 @@ fn report_cannot_move_out_of<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
move_from.descriptive_string(bccx.tcx)); move_from.descriptive_string(bccx.tcx));
err.span_label( err.span_label(
move_from.span, move_from.span,
&format!("cannot move out of {}", move_from.descriptive_string(bccx.tcx)) format!("cannot move out of {}", move_from.descriptive_string(bccx.tcx))
); );
err err
} }
@ -160,7 +160,7 @@ fn report_cannot_move_out_of<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
"cannot move out of type `{}`, \ "cannot move out of type `{}`, \
a non-copy array", a non-copy array",
b.ty); b.ty);
err.span_label(move_from.span, &format!("cannot move out of here")); err.span_label(move_from.span, "cannot move out of here");
err err
} }
(_, Kind::Pattern) => { (_, Kind::Pattern) => {
@ -177,7 +177,7 @@ fn report_cannot_move_out_of<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
"cannot move out of type `{}`, \ "cannot move out of type `{}`, \
which implements the `Drop` trait", which implements the `Drop` trait",
b.ty); b.ty);
err.span_label(move_from.span, &format!("cannot move out of here")); err.span_label(move_from.span, "cannot move out of here");
err err
}, },
_ => { _ => {
@ -198,12 +198,12 @@ fn note_move_destination(mut err: DiagnosticBuilder,
if is_first_note { if is_first_note {
err.span_label( err.span_label(
move_to_span, move_to_span,
&format!("hint: to prevent move, use `ref {0}` or `ref mut {0}`", format!("hint: to prevent move, use `ref {0}` or `ref mut {0}`",
pat_name)); pat_name));
err err
} else { } else {
err.span_label(move_to_span, err.span_label(move_to_span,
&format!("...and here (use `ref {0}` or `ref mut {0}`)", format!("...and here (use `ref {0}` or `ref mut {0}`)",
pat_name)); pat_name));
err err
} }

View file

@ -546,7 +546,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
"{} of possibly uninitialized variable: `{}`", "{} of possibly uninitialized variable: `{}`",
verb, verb,
self.loan_path_to_string(lp)) self.loan_path_to_string(lp))
.span_label(use_span, &format!("use of possibly uninitialized `{}`", .span_label(use_span, format!("use of possibly uninitialized `{}`",
self.loan_path_to_string(lp))) self.loan_path_to_string(lp)))
.emit(); .emit();
return; return;
@ -616,12 +616,12 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
err = if use_span == move_span { err = if use_span == move_span {
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 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
}; };
@ -657,9 +657,9 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
self.tcx.sess, span, E0384, self.tcx.sess, span, E0384,
"re-assignment of immutable variable `{}`", "re-assignment of immutable variable `{}`",
self.loan_path_to_string(lp)); self.loan_path_to_string(lp));
err.span_label(span, &format!("re-assignment of immutable variable")); err.span_label(span, "re-assignment of immutable variable");
if span != assign.span { if span != assign.span {
err.span_label(assign.span, &format!("first assignment to `{}`", err.span_label(assign.span, format!("first assignment to `{}`",
self.loan_path_to_string(lp))); self.loan_path_to_string(lp)));
} }
err.emit(); err.emit();
@ -821,7 +821,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
let mut err = struct_span_err!( let mut err = struct_span_err!(
self.tcx.sess, span, E0389, self.tcx.sess, span, E0389,
"{} in a `&` reference", prefix); "{} in a `&` reference", prefix);
err.span_label(span, &"assignment into an immutable reference"); err.span_label(span, "assignment into an immutable reference");
err err
} }
}; };
@ -914,7 +914,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
} }
db.span_label( db.span_label(
let_span, let_span,
&format!("consider changing this to `mut {}`", snippet) format!("consider changing this to `mut {}`", snippet)
); );
} }
} }
@ -927,7 +927,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
if let Ok(snippet) = snippet { if let Ok(snippet) = snippet {
db.span_label( db.span_label(
let_span, let_span,
&format!("consider changing this to `{}`", format!("consider changing this to `{}`",
snippet.replace("ref ", "ref mut ")) snippet.replace("ref ", "ref mut "))
); );
} }
@ -936,7 +936,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
if let (Some(local_ty), is_implicit_self) = self.local_ty(node_id) { if let (Some(local_ty), is_implicit_self) = self.local_ty(node_id) {
if let Some(msg) = if let Some(msg) =
self.suggest_mut_for_immutable(local_ty, is_implicit_self) { self.suggest_mut_for_immutable(local_ty, is_implicit_self) {
db.span_label(local_ty.span, &msg); db.span_label(local_ty.span, msg);
} }
} }
} }
@ -950,7 +950,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
if let hir_map::Node::NodeField(ref field) = self.tcx.hir.get(node_id) { if let hir_map::Node::NodeField(ref field) = self.tcx.hir.get(node_id) {
if let Some(msg) = self.suggest_mut_for_immutable(&field.ty, false) { if let Some(msg) = self.suggest_mut_for_immutable(&field.ty, false) {
db.span_label(field.ty.span, &msg); db.span_label(field.ty.span, msg);
} }
} }
} }
@ -975,10 +975,10 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
which is owned by the current function", which is owned by the current function",
cmt_path_or_string) cmt_path_or_string)
.span_label(capture_span, .span_label(capture_span,
&format!("{} is borrowed here", format!("{} is borrowed here",
cmt_path_or_string)) cmt_path_or_string))
.span_label(err.span, .span_label(err.span,
&format!("may outlive borrowed value {}", format!("may outlive borrowed value {}",
cmt_path_or_string)) cmt_path_or_string))
.span_suggestion(err.span, .span_suggestion(err.span,
&format!("to force the closure to take ownership of {} \ &format!("to force the closure to take ownership of {} \
@ -1029,15 +1029,15 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
match db.span.primary_span() { match db.span.primary_span() {
Some(primary) => { Some(primary) => {
db.span = MultiSpan::from_span(s); db.span = MultiSpan::from_span(s);
db.span_label(primary, &format!("capture occurs here")); db.span_label(primary, "capture occurs here");
db.span_label(s, &"does not live long enough"); db.span_label(s, "does not live long enough");
true true
} }
None => false None => false
} }
} }
_ => { _ => {
db.span_label(error_span, &"does not live long enough"); db.span_label(error_span, "does not live long enough");
false false
} }
}; };
@ -1049,7 +1049,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
(Some(s1), Some(s2)) if s1 == s2 => { (Some(s1), Some(s2)) if s1 == s2 => {
if !is_closure { if !is_closure {
db.span = MultiSpan::from_span(s1); db.span = MultiSpan::from_span(s1);
db.span_label(error_span, &value_msg); db.span_label(error_span, value_msg);
let msg = match opt_loan_path(&err.cmt) { let msg = match opt_loan_path(&err.cmt) {
None => value_kind.to_string(), None => value_kind.to_string(),
Some(lp) => { Some(lp) => {
@ -1057,29 +1057,29 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
} }
}; };
db.span_label(s1, db.span_label(s1,
&format!("{} dropped here while still borrowed", msg)); format!("{} dropped here while still borrowed", msg));
} else { } else {
db.span_label(s1, &format!("{} dropped before borrower", value_kind)); db.span_label(s1, format!("{} dropped before borrower", value_kind));
} }
db.note("values in a scope are dropped in the opposite order \ db.note("values in a scope are dropped in the opposite order \
they are created"); they are created");
} }
(Some(s1), Some(s2)) if !is_closure => { (Some(s1), Some(s2)) if !is_closure => {
db.span = MultiSpan::from_span(s2); db.span = MultiSpan::from_span(s2);
db.span_label(error_span, &value_msg); db.span_label(error_span, value_msg);
let msg = match opt_loan_path(&err.cmt) { let msg = match opt_loan_path(&err.cmt) {
None => value_kind.to_string(), None => value_kind.to_string(),
Some(lp) => { Some(lp) => {
format!("`{}`", self.loan_path_to_string(&lp)) format!("`{}`", self.loan_path_to_string(&lp))
} }
}; };
db.span_label(s2, &format!("{} dropped here while still borrowed", msg)); db.span_label(s2, format!("{} dropped here while still borrowed", msg));
db.span_label(s1, &format!("{} needs to live until here", value_kind)); db.span_label(s1, format!("{} needs to live until here", value_kind));
} }
_ => { _ => {
match sub_span { match sub_span {
Some(s) => { Some(s) => {
db.span_label(s, &format!("{} needs to live until here", db.span_label(s, format!("{} needs to live until here",
value_kind)); value_kind));
} }
None => { None => {
@ -1092,7 +1092,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
} }
match super_span { match super_span {
Some(s) => { Some(s) => {
db.span_label(s, &format!("{} only lives until here", value_kind)); db.span_label(s, format!("{} only lives until here", value_kind));
} }
None => { None => {
self.tcx.note_and_explain_region( self.tcx.note_and_explain_region(
@ -1162,23 +1162,23 @@ before rustc 1.16, this temporary lived longer - see issue #39283 \
} }
_ => { _ => {
if let Categorization::Deref(..) = err.cmt.cat { if let Categorization::Deref(..) = err.cmt.cat {
db.span_label(*error_span, &"cannot borrow as mutable"); db.span_label(*error_span, "cannot borrow as mutable");
} else if let Categorization::Local(local_id) = err.cmt.cat { } else if let Categorization::Local(local_id) = err.cmt.cat {
let span = self.tcx.hir.span(local_id); let span = self.tcx.hir.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.starts_with("ref mut ") || snippet.starts_with("&mut ") { if snippet.starts_with("ref mut ") || snippet.starts_with("&mut ") {
db.span_label(*error_span, &format!("cannot reborrow mutably")); db.span_label(*error_span, "cannot reborrow mutably");
db.span_label(*error_span, &format!("try removing `&mut` here")); db.span_label(*error_span, "try removing `&mut` here");
} else { } else {
db.span_label(*error_span, &format!("cannot borrow mutably")); db.span_label(*error_span, "cannot borrow mutably");
} }
} else { } else {
db.span_label(*error_span, &format!("cannot borrow mutably")); db.span_label(*error_span, "cannot borrow mutably");
} }
} else if let Categorization::Interior(ref cmt, _) = err.cmt.cat { } else if let Categorization::Interior(ref cmt, _) = err.cmt.cat {
if let mc::MutabilityCategory::McImmutable = cmt.mutbl { if let mc::MutabilityCategory::McImmutable = cmt.mutbl {
db.span_label(*error_span, db.span_label(*error_span,
&"cannot mutably borrow immutable field"); "cannot mutably borrow immutable field");
} }
} }
} }

View file

@ -258,7 +258,7 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> {
"refutable pattern in {}: `{}` not covered", "refutable pattern in {}: `{}` not covered",
origin, pattern_string origin, pattern_string
); );
diag.span_label(pat.span, &format!("pattern `{}` not covered", pattern_string)); diag.span_label(pat.span, format!("pattern `{}` not covered", pattern_string));
diag.emit(); diag.emit();
}); });
} }
@ -328,7 +328,7 @@ fn check_arms<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
let span = first_pat.0.span; let span = first_pat.0.span;
struct_span_err!(cx.tcx.sess, span, E0162, struct_span_err!(cx.tcx.sess, span, E0162,
"irrefutable if-let pattern") "irrefutable if-let pattern")
.span_label(span, &format!("irrefutable pattern")) .span_label(span, "irrefutable pattern")
.emit(); .emit();
printed_if_let_err = true; printed_if_let_err = true;
} }
@ -355,7 +355,7 @@ fn check_arms<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
1 => { 1 => {
struct_span_err!(cx.tcx.sess, span, E0165, struct_span_err!(cx.tcx.sess, span, E0165,
"irrefutable while-let pattern") "irrefutable while-let pattern")
.span_label(span, &format!("irrefutable pattern")) .span_label(span, "irrefutable pattern")
.emit(); .emit();
}, },
_ => bug!(), _ => bug!(),
@ -369,7 +369,7 @@ fn check_arms<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
diagnostic.set_span(pat.span); diagnostic.set_span(pat.span);
// if we had a catchall pattern, hint at that // if we had a catchall pattern, hint at that
if let Some(catchall) = catchall { if let Some(catchall) = catchall {
diagnostic.span_label(pat.span, &"this is an unreachable pattern"); diagnostic.span_label(pat.span, "this is an unreachable pattern");
diagnostic.span_note(catchall, "this pattern matches any value"); diagnostic.span_note(catchall, "this pattern matches any value");
} }
cx.tcx.sess.add_lint_diagnostic(lint::builtin::UNREACHABLE_PATTERNS, cx.tcx.sess.add_lint_diagnostic(lint::builtin::UNREACHABLE_PATTERNS,
@ -426,7 +426,7 @@ fn check_exhaustive<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
"refutable pattern in `for` loop binding: \ "refutable pattern in `for` loop binding: \
`{}` not covered", `{}` not covered",
pattern_string) pattern_string)
.span_label(sp, &format!("pattern `{}` not covered", pattern_string)) .span_label(sp, format!("pattern `{}` not covered", pattern_string))
.emit(); .emit();
}, },
_ => { _ => {
@ -453,7 +453,7 @@ fn check_exhaustive<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
create_e0004(cx.tcx.sess, sp, create_e0004(cx.tcx.sess, sp,
format!("non-exhaustive patterns: {} not covered", format!("non-exhaustive patterns: {} not covered",
joined_patterns)) joined_patterns))
.span_label(sp, &label_text) .span_label(sp, label_text)
.emit(); .emit();
}, },
} }
@ -485,18 +485,18 @@ fn check_legality_of_move_bindings(cx: &MatchVisitor,
if sub.map_or(false, |p| p.contains_bindings()) { if sub.map_or(false, |p| p.contains_bindings()) {
struct_span_err!(cx.tcx.sess, p.span, E0007, struct_span_err!(cx.tcx.sess, p.span, E0007,
"cannot bind by-move with sub-bindings") "cannot bind by-move with sub-bindings")
.span_label(p.span, &format!("binds an already bound by-move value by moving it")) .span_label(p.span, "binds an already bound by-move value by moving it")
.emit(); .emit();
} else if has_guard { } else if has_guard {
struct_span_err!(cx.tcx.sess, p.span, E0008, struct_span_err!(cx.tcx.sess, p.span, E0008,
"cannot bind by-move into a pattern guard") "cannot bind by-move into a pattern guard")
.span_label(p.span, &format!("moves value into pattern guard")) .span_label(p.span, "moves value into pattern guard")
.emit(); .emit();
} else if by_ref_span.is_some() { } else if by_ref_span.is_some() {
struct_span_err!(cx.tcx.sess, p.span, E0009, struct_span_err!(cx.tcx.sess, p.span, E0009,
"cannot bind by-move and by-ref in the same pattern") "cannot bind by-move and by-ref in the same pattern")
.span_label(p.span, &format!("by-move pattern here")) .span_label(p.span, "by-move pattern here")
.span_label(by_ref_span.unwrap(), &format!("both by-ref and by-move used")) .span_label(by_ref_span.unwrap(), "both by-ref and by-move used")
.emit(); .emit();
} }
}; };
@ -546,7 +546,7 @@ impl<'a, 'gcx, 'tcx> Delegate<'tcx> for MutationChecker<'a, 'gcx> {
ty::MutBorrow => { ty::MutBorrow => {
struct_span_err!(self.cx.tcx.sess, span, E0301, struct_span_err!(self.cx.tcx.sess, span, E0301,
"cannot mutably borrow in a pattern guard") "cannot mutably borrow in a pattern guard")
.span_label(span, &format!("borrowed mutably in pattern guard")) .span_label(span, "borrowed mutably in pattern guard")
.emit(); .emit();
} }
ty::ImmBorrow | ty::UniqueImmBorrow => {} ty::ImmBorrow | ty::UniqueImmBorrow => {}
@ -557,7 +557,7 @@ impl<'a, 'gcx, 'tcx> Delegate<'tcx> for MutationChecker<'a, 'gcx> {
match mode { match mode {
MutateMode::JustWrite | MutateMode::WriteAndRead => { MutateMode::JustWrite | MutateMode::WriteAndRead => {
struct_span_err!(self.cx.tcx.sess, span, E0302, "cannot assign in a pattern guard") struct_span_err!(self.cx.tcx.sess, span, E0302, "cannot assign in a pattern guard")
.span_label(span, &format!("assignment in pattern guard")) .span_label(span, "assignment in pattern guard")
.emit(); .emit();
} }
MutateMode::Init => {} MutateMode::Init => {}
@ -588,7 +588,7 @@ impl<'a, 'b, 'tcx, 'v> Visitor<'v> for AtBindingPatternVisitor<'a, 'b, 'tcx> {
if !self.bindings_allowed { if !self.bindings_allowed {
struct_span_err!(self.cx.tcx.sess, pat.span, E0303, struct_span_err!(self.cx.tcx.sess, pat.span, E0303,
"pattern bindings are not allowed after an `@`") "pattern bindings are not allowed after an `@`")
.span_label(pat.span, &format!("not allowed after `@`")) .span_label(pat.span, "not allowed after `@`")
.emit(); .emit();
} }

View file

@ -114,9 +114,8 @@ impl Diagnostic {
/// 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<T: Into<String>>(&mut self, span: Span, label: T) -> &mut Self {
-> &mut Self { self.span.push_span_label(span, label.into());
self.span.push_span_label(span, format!("{}", label));
self self
} }

View file

@ -112,8 +112,10 @@ 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.
forward!(pub fn span_label(&mut self, span: Span, label: &fmt::Display) pub fn span_label<T: Into<String>>(&mut self, span: Span, label: T) -> &mut Self {
-> &mut Self); self.diagnostic.span_label(span, label);
self
}
forward!(pub fn note_expected_found(&mut self, forward!(pub fn note_expected_found(&mut self,
label: &fmt::Display, label: &fmt::Display,

View file

@ -154,7 +154,7 @@ impl<'a, 'tcx> IfThisChanged<'a, 'tcx> {
None => { None => {
self.tcx.sess.span_fatal( self.tcx.sess.span_fatal(
attr.span, attr.span,
&format!("missing DepNode variant")); "missing DepNode variant");
} }
}; };
self.then_this_would_need.push((attr.span, self.then_this_would_need.push((attr.span,
@ -201,7 +201,7 @@ fn check_paths<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
for &(target_span, _, _, _) in then_this_would_need { for &(target_span, _, _, _) in then_this_would_need {
tcx.sess.span_err( tcx.sess.span_err(
target_span, target_span,
&format!("no #[rustc_if_this_changed] annotation detected")); "no #[rustc_if_this_changed] annotation detected");
} }
return; return;
@ -219,7 +219,7 @@ fn check_paths<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
} else { } else {
tcx.sess.span_err( tcx.sess.span_err(
target_span, target_span,
&format!("OK")); "OK");
} }
} }
} }

View file

@ -383,7 +383,7 @@ fn check_config(tcx: TyCtxt, attr: &Attribute) -> bool {
tcx.sess.span_fatal( tcx.sess.span_fatal(
attr.span, attr.span,
&format!("no cfg attribute")); "no cfg attribute");
} }
fn expect_associated_value(tcx: TyCtxt, item: &NestedMetaItem) -> ast::Name { fn expect_associated_value(tcx: TyCtxt, item: &NestedMetaItem) -> ast::Name {

View file

@ -215,7 +215,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedUnsafe {
let mut db = cx.struct_span_lint(UNUSED_UNSAFE, blk.span, let mut db = cx.struct_span_lint(UNUSED_UNSAFE, blk.span,
"unnecessary `unsafe` block"); "unnecessary `unsafe` block");
db.span_label(blk.span, &"unnecessary `unsafe` block"); db.span_label(blk.span, "unnecessary `unsafe` block");
if let Some((kind, id)) = is_enclosed(cx, blk.id) { if let Some((kind, id)) = is_enclosed(cx, blk.id) {
db.span_note(cx.tcx.hir.span(id), db.span_note(cx.tcx.hir.span(id),
&format!("because it's nested under this `unsafe` {}", kind)); &format!("because it's nested under this `unsafe` {}", kind));

View file

@ -88,7 +88,7 @@ fn register_native_lib(sess: &Session,
Some(span) => { Some(span) => {
struct_span_err!(sess, span, E0454, struct_span_err!(sess, span, E0454,
"#[link(name = \"\")] given with empty name") "#[link(name = \"\")] given with empty name")
.span_label(span, &format!("empty name given")) .span_label(span, "empty name given")
.emit(); .emit();
} }
None => { None => {
@ -1029,7 +1029,7 @@ impl<'a> CrateLoader<'a> {
Some(k) => { Some(k) => {
struct_span_err!(self.sess, m.span, E0458, struct_span_err!(self.sess, m.span, E0458,
"unknown kind: `{}`", k) "unknown kind: `{}`", k)
.span_label(m.span, &format!("unknown kind")).emit(); .span_label(m.span, "unknown kind").emit();
cstore::NativeUnknown cstore::NativeUnknown
} }
None => cstore::NativeUnknown None => cstore::NativeUnknown
@ -1042,7 +1042,7 @@ impl<'a> CrateLoader<'a> {
None => { None => {
struct_span_err!(self.sess, m.span, E0459, struct_span_err!(self.sess, m.span, E0459,
"#[link(...)] specified without `name = \"foo\"`") "#[link(...)] specified without `name = \"foo\"`")
.span_label(m.span, &format!("missing `name` argument")).emit(); .span_label(m.span, "missing `name` argument").emit();
Symbol::intern("foo") Symbol::intern("foo")
} }
}; };

View file

@ -367,7 +367,7 @@ impl<'a> Context<'a> {
&& self.triple != config::host_triple() { && self.triple != config::host_triple() {
err.note(&format!("the `{}` target may not be installed", self.triple)); err.note(&format!("the `{}` target may not be installed", self.triple));
} }
err.span_label(self.span, &format!("can't find crate")); err.span_label(self.span, "can't find crate");
err err
}; };

View file

@ -242,9 +242,9 @@ impl<'a, 'tcx> Qualifier<'a, 'tcx, 'tcx> {
to the crate attributes to enable"); to the crate attributes to enable");
} else { } else {
self.find_drop_implementation_method_span() self.find_drop_implementation_method_span()
.map(|span| err.span_label(span, &format!("destructor defined here"))); .map(|span| err.span_label(span, "destructor defined here"));
err.span_label(self.span, &format!("constants cannot have destructors")); err.span_label(self.span, "constants cannot have destructors");
} }
err.emit(); err.emit();
@ -291,8 +291,8 @@ impl<'a, 'tcx> Qualifier<'a, 'tcx, 'tcx> {
"cannot refer to statics by value, use a constant instead" "cannot refer to statics by value, use a constant instead"
}; };
struct_span_err!(self.tcx.sess, self.span, E0394, "{}", msg) struct_span_err!(self.tcx.sess, self.span, E0394, "{}", msg)
.span_label(self.span, &format!("referring to another static by value")) .span_label(self.span, "referring to another static by value")
.note(&format!("use the address-of operator or a constant instead")) .note("use the address-of operator or a constant instead")
.emit(); .emit();
// Replace STATIC with NOT_CONST to avoid further errors. // Replace STATIC with NOT_CONST to avoid further errors.
@ -529,7 +529,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
"raw pointers cannot be dereferenced in {}s", "raw pointers cannot be dereferenced in {}s",
this.mode) this.mode)
.span_label(this.span, .span_label(this.span,
&format!("dereference of raw pointer in constant")) "dereference of raw pointer in constant")
.emit(); .emit();
} }
} }
@ -645,7 +645,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
struct_span_err!(self.tcx.sess, self.span, E0017, struct_span_err!(self.tcx.sess, self.span, E0017,
"references in {}s may only refer \ "references in {}s may only refer \
to immutable values", self.mode) to immutable values", self.mode)
.span_label(self.span, &format!("{}s require immutable values", .span_label(self.span, format!("{}s require immutable values",
self.mode)) self.mode))
.emit(); .emit();
} }
@ -713,7 +713,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
self.mode) self.mode)
.span_label( .span_label(
self.span, self.span,
&format!("comparing raw pointers in static")) "comparing raw pointers in static")
.emit(); .emit();
} }
} }
@ -724,7 +724,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
if self.mode != Mode::Fn { if self.mode != Mode::Fn {
struct_span_err!(self.tcx.sess, self.span, E0010, struct_span_err!(self.tcx.sess, self.span, E0010,
"allocations are not allowed in {}s", self.mode) "allocations are not allowed in {}s", self.mode)
.span_label(self.span, &format!("allocation not allowed in {}s", self.mode)) .span_label(self.span, format!("allocation not allowed in {}s", self.mode))
.emit(); .emit();
} }
} }

View file

@ -55,7 +55,7 @@ impl<'a> AstValidator<'a> {
E0449, E0449,
"unnecessary visibility qualifier"); "unnecessary visibility qualifier");
if vis == &Visibility::Public { if vis == &Visibility::Public {
err.span_label(span, &format!("`pub` not needed here")); err.span_label(span, "`pub` not needed here");
} }
if let Some(note) = note { if let Some(note) = note {
err.note(note); err.note(note);
@ -80,7 +80,7 @@ impl<'a> AstValidator<'a> {
Constness::Const => { Constness::Const => {
struct_span_err!(self.session, constness.span, E0379, struct_span_err!(self.session, constness.span, E0379,
"trait fns cannot be declared const") "trait fns cannot be declared const")
.span_label(constness.span, &format!("trait fns cannot be const")) .span_label(constness.span, "trait fns cannot be const")
.emit(); .emit();
} }
_ => {} _ => {}
@ -272,7 +272,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
E0130, E0130,
"patterns aren't allowed in foreign function \ "patterns aren't allowed in foreign function \
declarations"); declarations");
err.span_label(span, &format!("pattern not allowed in foreign function")); err.span_label(span, "pattern not allowed in foreign function");
if is_recent { if is_recent {
err.span_note(span, err.span_note(span,
"this is a recent error, see issue #35203 for more details"); "this is a recent error, see issue #35203 for more details");

View file

@ -180,7 +180,7 @@ impl<'a, 'tcx> Visitor<'tcx> for CheckCrateVisitor<'a, 'tcx> {
Ok(Ordering::Greater) => { Ok(Ordering::Greater) => {
struct_span_err!(self.tcx.sess, start.span, E0030, struct_span_err!(self.tcx.sess, start.span, E0030,
"lower range bound must be less than or equal to upper") "lower range bound must be less than or equal to upper")
.span_label(start.span, &format!("lower bound larger than upper bound")) .span_label(start.span, "lower bound larger than upper bound")
.emit(); .emit();
} }
Err(ErrorReported) => {} Err(ErrorReported) => {}

View file

@ -118,7 +118,7 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
"`break` with value from a `{}` loop", "`break` with value from a `{}` loop",
kind.name()) kind.name())
.span_label(e.span, .span_label(e.span,
&format!("can only break with a value inside `loop`")) "can only break with a value inside `loop`")
.emit(); .emit();
} }
} }
@ -154,12 +154,12 @@ impl<'a, 'hir> CheckLoopVisitor<'a, 'hir> {
Loop(_) => {} Loop(_) => {}
Closure => { Closure => {
struct_span_err!(self.sess, span, E0267, "`{}` inside of a closure", name) struct_span_err!(self.sess, span, E0267, "`{}` inside of a closure", name)
.span_label(span, &format!("cannot break inside of a closure")) .span_label(span, "cannot break inside of a closure")
.emit(); .emit();
} }
Normal => { Normal => {
struct_span_err!(self.sess, span, E0268, "`{}` outside of loop", name) struct_span_err!(self.sess, span, E0268, "`{}` outside of loop", name)
.span_label(span, &format!("cannot break outside of a loop")) .span_label(span, "cannot break outside of a loop")
.emit(); .emit();
} }
} }
@ -169,7 +169,7 @@ impl<'a, 'hir> CheckLoopVisitor<'a, 'hir> {
struct_span_err!(self.sess, span, E0590, struct_span_err!(self.sess, span, E0590,
"`break` or `continue` with no label in the condition of a `while` loop") "`break` or `continue` with no label in the condition of a `while` loop")
.span_label(span, .span_label(span,
&format!("unlabeled `{}` in the condition of a `while` loop", cf_type)) format!("unlabeled `{}` in the condition of a `while` loop", cf_type))
.emit(); .emit();
} }
} }

View file

@ -138,7 +138,7 @@ impl<'a, 'b: 'a, 'hir: 'b> CheckItemRecursionVisitor<'a, 'b, 'hir> {
}); });
if !any_static { if !any_static {
struct_span_err!(self.sess, span, E0265, "recursive constant") struct_span_err!(self.sess, span, E0265, "recursive constant")
.span_label(span, &format!("recursion not allowed in constant")) .span_label(span, "recursion not allowed in constant")
.emit(); .emit();
} }
return; return;

View file

@ -433,7 +433,7 @@ impl<'a, 'tcx> NamePrivacyVisitor<'a, 'tcx> {
if !def.is_enum() && !field.vis.is_accessible_from(self.current_item, self.tcx) { if !def.is_enum() && !field.vis.is_accessible_from(self.current_item, self.tcx) {
struct_span_err!(self.tcx.sess, span, E0451, "field `{}` of {} `{}` is private", struct_span_err!(self.tcx.sess, span, E0451, "field `{}` of {} `{}` is private",
field.name, def.variant_descr(), self.tcx.item_path_str(def.did)) field.name, def.variant_descr(), self.tcx.item_path_str(def.did))
.span_label(span, &format!("field `{}` is private", field.name)) .span_label(span, format!("field `{}` is private", field.name))
.emit(); .emit();
} }
} }
@ -926,7 +926,7 @@ impl<'a, 'tcx: 'a> TypeVisitor<'tcx> for SearchInterfaceForPrivateItemsVisitor<'
if self.has_pub_restricted || self.has_old_errors { if self.has_pub_restricted || self.has_old_errors {
let mut err = struct_span_err!(self.tcx.sess, self.span, E0446, let mut err = struct_span_err!(self.tcx.sess, self.span, E0446,
"private type `{}` in public interface", ty); "private type `{}` in public interface", ty);
err.span_label(self.span, &format!("can't leak private type")); err.span_label(self.span, "can't leak private type");
err.emit(); err.emit();
} else { } else {
self.tcx.sess.add_lint(lint::builtin::PRIVATE_IN_PUBLIC, self.tcx.sess.add_lint(lint::builtin::PRIVATE_IN_PUBLIC,
@ -961,7 +961,7 @@ impl<'a, 'tcx: 'a> TypeVisitor<'tcx> for SearchInterfaceForPrivateItemsVisitor<'
if self.has_pub_restricted || self.has_old_errors { if self.has_pub_restricted || self.has_old_errors {
struct_span_err!(self.tcx.sess, self.span, E0445, struct_span_err!(self.tcx.sess, self.span, E0445,
"private trait `{}` in public interface", trait_ref) "private trait `{}` in public interface", trait_ref)
.span_label(self.span, &format!( .span_label(self.span, format!(
"private trait can't be public")) "private trait can't be public"))
.emit(); .emit();
} else { } else {

View file

@ -183,7 +183,7 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver,
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.span_label(span, &format!("use of type variable from outer function")); err.span_label(span, "use of type variable from outer function");
err err
} }
ResolutionError::OuterTypeParameterContext => { ResolutionError::OuterTypeParameterContext => {
@ -199,8 +199,8 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver,
"the name `{}` is already used for a type parameter \ "the name `{}` is already used for a type parameter \
in this type parameter list", in this type parameter list",
name); name);
err.span_label(span, &format!("already used")); err.span_label(span, "already used");
err.span_label(first_use_span.clone(), &format!("first use of `{}`", name)); err.span_label(first_use_span.clone(), format!("first use of `{}`", name));
err err
} }
ResolutionError::MethodNotMemberOfTrait(method, trait_) => { ResolutionError::MethodNotMemberOfTrait(method, trait_) => {
@ -210,7 +210,7 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver,
"method `{}` is not a member of trait `{}`", "method `{}` is not a member of trait `{}`",
method, method,
trait_); trait_);
err.span_label(span, &format!("not a member of trait `{}`", trait_)); err.span_label(span, format!("not a member of trait `{}`", trait_));
err err
} }
ResolutionError::TypeNotMemberOfTrait(type_, trait_) => { ResolutionError::TypeNotMemberOfTrait(type_, trait_) => {
@ -220,7 +220,7 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver,
"type `{}` is not a member of trait `{}`", "type `{}` is not a member of trait `{}`",
type_, type_,
trait_); trait_);
err.span_label(span, &format!("not a member of trait `{}`", trait_)); err.span_label(span, format!("not a member of trait `{}`", trait_));
err err
} }
ResolutionError::ConstNotMemberOfTrait(const_, trait_) => { ResolutionError::ConstNotMemberOfTrait(const_, trait_) => {
@ -230,7 +230,7 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver,
"const `{}` is not a member of trait `{}`", "const `{}` is not a member of trait `{}`",
const_, const_,
trait_); trait_);
err.span_label(span, &format!("not a member of trait `{}`", trait_)); err.span_label(span, format!("not a member of trait `{}`", trait_));
err err
} }
ResolutionError::VariableNotBoundInPattern(binding_error) => { ResolutionError::VariableNotBoundInPattern(binding_error) => {
@ -239,11 +239,11 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver,
let msg = format!("variable `{}` is not bound in all patterns", binding_error.name); let msg = format!("variable `{}` is not bound in all patterns", binding_error.name);
let mut err = resolver.session.struct_span_err_with_code(msp, &msg, "E0408"); let mut err = resolver.session.struct_span_err_with_code(msp, &msg, "E0408");
for sp in target_sp { for sp in target_sp {
err.span_label(sp, &format!("pattern doesn't bind `{}`", binding_error.name)); err.span_label(sp, format!("pattern doesn't bind `{}`", binding_error.name));
} }
let origin_sp = binding_error.origin.iter().map(|x| *x).collect::<Vec<_>>(); let origin_sp = binding_error.origin.iter().map(|x| *x).collect::<Vec<_>>();
for sp in origin_sp { for sp in origin_sp {
err.span_label(sp, &"variable not in all patterns"); err.span_label(sp, "variable not in all patterns");
} }
err err
} }
@ -255,8 +255,8 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver,
"variable `{}` is bound in inconsistent \ "variable `{}` is bound in inconsistent \
ways within the same match arm", ways within the same match arm",
variable_name); variable_name);
err.span_label(span, &format!("bound in different ways")); err.span_label(span, "bound in different ways");
err.span_label(first_binding_span, &format!("first binding")); err.span_label(first_binding_span, "first binding");
err err
} }
ResolutionError::IdentifierBoundMoreThanOnceInParameterList(identifier) => { ResolutionError::IdentifierBoundMoreThanOnceInParameterList(identifier) => {
@ -265,7 +265,7 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver,
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.span_label(span, &format!("used as parameter more than once")); err.span_label(span, "used as parameter more than once");
err err
} }
ResolutionError::IdentifierBoundMoreThanOnceInSamePattern(identifier) => { ResolutionError::IdentifierBoundMoreThanOnceInSamePattern(identifier) => {
@ -274,7 +274,7 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver,
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.span_label(span, &format!("used in a pattern more than once")); err.span_label(span, "used in a pattern more than once");
err err
} }
ResolutionError::UndeclaredLabel(name) => { ResolutionError::UndeclaredLabel(name) => {
@ -283,7 +283,7 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver,
E0426, E0426,
"use of undeclared label `{}`", "use of undeclared label `{}`",
name); name);
err.span_label(span, &format!("undeclared label `{}`",&name)); err.span_label(span, format!("undeclared label `{}`", name));
err err
} }
ResolutionError::SelfImportsOnlyAllowedWithin => { ResolutionError::SelfImportsOnlyAllowedWithin => {
@ -313,14 +313,14 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver,
}; };
let mut err = struct_span_err!(resolver.session, span, E0432, "{}", msg); let mut err = struct_span_err!(resolver.session, span, E0432, "{}", msg);
if let Some((_, p)) = name { if let Some((_, p)) = name {
err.span_label(span, &p); err.span_label(span, p);
} }
err err
} }
ResolutionError::FailedToResolve(msg) => { ResolutionError::FailedToResolve(msg) => {
let mut err = struct_span_err!(resolver.session, span, E0433, let mut err = struct_span_err!(resolver.session, span, E0433,
"failed to resolve. {}", msg); "failed to resolve. {}", msg);
err.span_label(span, &msg); err.span_label(span, msg);
err err
} }
ResolutionError::CannotCaptureDynamicEnvironmentInFnItem => { ResolutionError::CannotCaptureDynamicEnvironmentInFnItem => {
@ -336,7 +336,7 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver,
span, span,
E0435, E0435,
"attempt to use a non-constant value in a constant"); "attempt to use a non-constant value in a constant");
err.span_label(span, &format!("non-constant used with constant")); err.span_label(span, "non-constant used with constant");
err err
} }
ResolutionError::BindingShadowsSomethingUnacceptable(what_binding, name, binding) => { ResolutionError::BindingShadowsSomethingUnacceptable(what_binding, name, binding) => {
@ -345,9 +345,9 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver,
span, span,
E0530, E0530,
"{}s cannot shadow {}s", what_binding, shadows_what); "{}s cannot shadow {}s", what_binding, shadows_what);
err.span_label(span, &format!("cannot be named the same as a {}", shadows_what)); err.span_label(span, format!("cannot be named the same as a {}", shadows_what));
let participle = if binding.is_import() { "imported" } else { "defined" }; let participle = if binding.is_import() { "imported" } else { "defined" };
let msg = &format!("a {} `{}` is {} here", shadows_what, name, participle); let msg = format!("a {} `{}` is {} here", shadows_what, name, participle);
err.span_label(binding.span, msg); err.span_label(binding.span, msg);
err err
} }
@ -355,7 +355,7 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver,
let mut err = struct_span_err!(resolver.session, span, E0128, let mut err = struct_span_err!(resolver.session, span, E0128,
"type parameters with a default cannot use \ "type parameters with a default cannot use \
forward declared identifiers"); forward declared identifiers");
err.span_label(span, &format!("defaulted type parameters \ err.span_label(span, format!("defaulted type parameters \
cannot be forward declared")); cannot be forward declared"));
err err
} }
@ -2256,13 +2256,13 @@ impl<'a> Resolver<'a> {
if is_self_type(path, ns) { if is_self_type(path, ns) {
__diagnostic_used!(E0411); __diagnostic_used!(E0411);
err.code("E0411".into()); err.code("E0411".into());
err.span_label(span, &format!("`Self` is only available in traits and impls")); err.span_label(span, "`Self` is only available in traits and impls");
return err; return err;
} }
if is_self_value(path, ns) { if is_self_value(path, ns) {
__diagnostic_used!(E0424); __diagnostic_used!(E0424);
err.code("E0424".into()); err.code("E0424".into());
err.span_label(span, &format!("`self` value is only available in \ err.span_label(span, format!("`self` value is only available in \
methods with `self` parameter")); methods with `self` parameter"));
return err; return err;
} }
@ -2294,18 +2294,18 @@ impl<'a> Resolver<'a> {
let self_is_available = this.self_value_is_available(path[0].ctxt); let self_is_available = this.self_value_is_available(path[0].ctxt);
match candidate { match candidate {
AssocSuggestion::Field => { AssocSuggestion::Field => {
err.span_label(span, &format!("did you mean `self.{}`?", path_str)); err.span_label(span, format!("did you mean `self.{}`?", path_str));
if !self_is_available { if !self_is_available {
err.span_label(span, &format!("`self` value is only available in \ err.span_label(span, format!("`self` value is only available in \
methods with `self` parameter")); methods with `self` parameter"));
} }
} }
AssocSuggestion::MethodWithSelf if self_is_available => { AssocSuggestion::MethodWithSelf if self_is_available => {
err.span_label(span, &format!("did you mean `self.{}(...)`?", err.span_label(span, format!("did you mean `self.{}(...)`?",
path_str)); path_str));
} }
AssocSuggestion::MethodWithSelf | AssocSuggestion::AssocItem => { AssocSuggestion::MethodWithSelf | AssocSuggestion::AssocItem => {
err.span_label(span, &format!("did you mean `Self::{}`?", path_str)); err.span_label(span, format!("did you mean `Self::{}`?", path_str));
} }
} }
return err; return err;
@ -2316,7 +2316,7 @@ impl<'a> Resolver<'a> {
// Try Levenshtein. // Try Levenshtein.
if let Some(candidate) = this.lookup_typo_candidate(path, ns, is_expected) { if let Some(candidate) = this.lookup_typo_candidate(path, ns, is_expected) {
err.span_label(ident_span, &format!("did you mean `{}`?", candidate)); err.span_label(ident_span, format!("did you mean `{}`?", candidate));
levenshtein_worked = true; levenshtein_worked = true;
} }
@ -2324,21 +2324,21 @@ impl<'a> Resolver<'a> {
if let Some(def) = def { if let Some(def) = def {
match (def, source) { match (def, source) {
(Def::Macro(..), _) => { (Def::Macro(..), _) => {
err.span_label(span, &format!("did you mean `{}!(...)`?", path_str)); err.span_label(span, format!("did you mean `{}!(...)`?", path_str));
return err; return err;
} }
(Def::TyAlias(..), PathSource::Trait) => { (Def::TyAlias(..), PathSource::Trait) => {
err.span_label(span, &format!("type aliases cannot be used for traits")); err.span_label(span, "type aliases cannot be used for traits");
return err; return err;
} }
(Def::Mod(..), PathSource::Expr(Some(parent))) => match parent.node { (Def::Mod(..), PathSource::Expr(Some(parent))) => match parent.node {
ExprKind::Field(_, ident) => { ExprKind::Field(_, ident) => {
err.span_label(parent.span, &format!("did you mean `{}::{}`?", err.span_label(parent.span, format!("did you mean `{}::{}`?",
path_str, ident.node)); path_str, ident.node));
return err; return err;
} }
ExprKind::MethodCall(ident, ..) => { ExprKind::MethodCall(ident, ..) => {
err.span_label(parent.span, &format!("did you mean `{}::{}(...)`?", err.span_label(parent.span, format!("did you mean `{}::{}(...)`?",
path_str, ident.node)); path_str, ident.node));
return err; return err;
} }
@ -2349,12 +2349,12 @@ impl<'a> Resolver<'a> {
if let Some((ctor_def, ctor_vis)) if let Some((ctor_def, ctor_vis))
= this.struct_constructors.get(&def_id).cloned() { = this.struct_constructors.get(&def_id).cloned() {
if is_expected(ctor_def) && !this.is_accessible(ctor_vis) { if is_expected(ctor_def) && !this.is_accessible(ctor_vis) {
err.span_label(span, &format!("constructor is not visible \ err.span_label(span, format!("constructor is not visible \
here due to private fields")); here due to private fields"));
} }
} }
} }
err.span_label(span, &format!("did you mean `{} {{ /* fields */ }}`?", err.span_label(span, format!("did you mean `{} {{ /* fields */ }}`?",
path_str)); path_str));
return err; return err;
} }
@ -2364,7 +2364,7 @@ impl<'a> Resolver<'a> {
// Fallback label. // Fallback label.
if !levenshtein_worked { if !levenshtein_worked {
err.span_label(base_span, &fallback_label); err.span_label(base_span, fallback_label);
} }
err err
}; };
@ -3374,9 +3374,9 @@ impl<'a> Resolver<'a> {
}, },
}; };
err.span_label(span, &format!("`{}` already {}", name, participle)); err.span_label(span, format!("`{}` already {}", name, participle));
if old_binding.span != syntax_pos::DUMMY_SP { if old_binding.span != syntax_pos::DUMMY_SP {
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();
self.name_already_seen.insert(name, span); self.name_already_seen.insert(name, span);

View file

@ -630,7 +630,7 @@ impl<'a> Resolver<'a> {
err.help(&format!("did you mean `{}`?", suggestion)); err.help(&format!("did you mean `{}`?", suggestion));
} }
} else { } else {
err.help(&format!("have you added the `#[macro_use]` on the module/import?")); err.help("have you added the `#[macro_use]` on the module/import?");
} }
} }
} }

View file

@ -539,7 +539,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
Ok(binding) if !binding.is_importable() => { Ok(binding) if !binding.is_importable() => {
let msg = format!("`{}` is not directly importable", target); let msg = format!("`{}` is not directly importable", target);
struct_span_err!(this.session, directive.span, E0253, "{}", &msg) struct_span_err!(this.session, directive.span, E0253, "{}", &msg)
.span_label(directive.span, &format!("cannot be imported directly")) .span_label(directive.span, "cannot be imported directly")
.emit(); .emit();
// Do not import this illegal binding. Import a dummy binding and pretend // Do not import this illegal binding. Import a dummy binding and pretend
// everything is fine // everything is fine
@ -701,7 +701,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
} else if ns == TypeNS { } else if ns == TypeNS {
struct_span_err!(self.session, directive.span, E0365, struct_span_err!(self.session, directive.span, E0365,
"`{}` is private, and cannot be reexported", ident) "`{}` is private, and cannot be reexported", ident)
.span_label(directive.span, &format!("reexport of private `{}`", ident)) .span_label(directive.span, format!("reexport of private `{}`", ident))
.note(&format!("consider declaring type or module `{}` with `pub`", ident)) .note(&format!("consider declaring type or module `{}` with `pub`", ident))
.emit(); .emit();
} else { } else {
@ -794,7 +794,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
let msg = let msg =
format!("a macro named `{}` has already been exported", ident); format!("a macro named `{}` has already been exported", ident);
self.session.struct_span_err(span, &msg) self.session.struct_span_err(span, &msg)
.span_label(span, &format!("`{}` already exported", ident)) .span_label(span, format!("`{}` already exported", ident))
.span_note(binding.span, "previous macro export here") .span_note(binding.span, "previous macro export here")
.emit(); .emit();
} }

View file

@ -163,7 +163,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
hir::ParenthesizedParameters(..) => { hir::ParenthesizedParameters(..) => {
struct_span_err!(tcx.sess, span, E0214, struct_span_err!(tcx.sess, span, E0214,
"parenthesized parameters may only be used with a trait") "parenthesized parameters may only be used with a trait")
.span_label(span, &format!("only traits may use parentheses")) .span_label(span, "only traits may use parentheses")
.emit(); .emit();
return Substs::for_item(tcx, def_id, |_, _| { return Substs::for_item(tcx, def_id, |_, _| {
@ -294,7 +294,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
struct_span_err!(tcx.sess, span, E0393, struct_span_err!(tcx.sess, span, E0393,
"the type parameter `{}` must be explicitly specified", "the type parameter `{}` must be explicitly specified",
def.name) def.name)
.span_label(span, &format!("missing reference to `{}`", def.name)) .span_label(span, format!("missing reference to `{}`", def.name))
.note(&format!("because of the default `Self` reference, \ .note(&format!("because of the default `Self` reference, \
type parameters must be specified on object types")) type parameters must be specified on object types"))
.emit(); .emit();
@ -635,7 +635,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
let span = b.trait_ref.path.span; let span = b.trait_ref.path.span;
struct_span_err!(self.tcx().sess, span, E0225, struct_span_err!(self.tcx().sess, span, E0225,
"only Send/Sync traits can be used as additional traits in a trait object") "only Send/Sync traits can be used as additional traits in a trait object")
.span_label(span, &format!("non-Send/Sync additional trait")) .span_label(span, "non-Send/Sync additional trait")
.emit(); .emit();
} }
@ -684,7 +684,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
"the value of the associated type `{}` (from the trait `{}`) must be specified", "the value of the associated type `{}` (from the trait `{}`) must be specified",
name, name,
tcx.item_path_str(trait_def_id)) tcx.item_path_str(trait_def_id))
.span_label(span, &format!( .span_label(span, format!(
"missing associated type `{}` value", name)) "missing associated type `{}` value", name))
.emit(); .emit();
} }
@ -730,7 +730,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
trait_str: &str, trait_str: &str,
name: &str) { name: &str) {
struct_span_err!(self.tcx().sess, span, E0223, "ambiguous associated type") struct_span_err!(self.tcx().sess, span, E0223, "ambiguous associated type")
.span_label(span, &format!("ambiguous associated type")) .span_label(span, "ambiguous associated type")
.note(&format!("specify the type using the syntax `<{} as {}>::{}`", .note(&format!("specify the type using the syntax `<{} as {}>::{}`",
type_str, trait_str, name)) type_str, trait_str, name))
.emit(); .emit();
@ -784,7 +784,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
"associated type `{}` not found for `{}`", "associated type `{}` not found for `{}`",
assoc_name, assoc_name,
ty_param_name) ty_param_name)
.span_label(span, &format!("associated type `{}` not found", assoc_name)) .span_label(span, format!("associated type `{}` not found", assoc_name))
.emit(); .emit();
return Err(ErrorReported); return Err(ErrorReported);
} }
@ -797,7 +797,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
"ambiguous associated type `{}` in bounds of `{}`", "ambiguous associated type `{}` in bounds of `{}`",
assoc_name, assoc_name,
ty_param_name); ty_param_name);
err.span_label(span, &format!("ambiguous associated type `{}`", assoc_name)); err.span_label(span, format!("ambiguous associated type `{}`", assoc_name));
for bound in bounds { for bound in bounds {
let bound_span = self.tcx().associated_items(bound.def_id()).find(|item| { let bound_span = self.tcx().associated_items(bound.def_id()).find(|item| {
@ -806,7 +806,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
.and_then(|item| self.tcx().hir.span_if_local(item.def_id)); .and_then(|item| self.tcx().hir.span_if_local(item.def_id));
if let Some(span) = bound_span { if let Some(span) = bound_span {
err.span_label(span, &format!("ambiguous `{}` from `{}`", err.span_label(span, format!("ambiguous `{}` from `{}`",
assoc_name, assoc_name,
bound)); bound));
} else { } else {
@ -951,7 +951,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
for typ in segment.parameters.types() { for typ in segment.parameters.types() {
struct_span_err!(self.tcx().sess, typ.span, E0109, struct_span_err!(self.tcx().sess, typ.span, E0109,
"type parameters are not allowed on this type") "type parameters are not allowed on this type")
.span_label(typ.span, &format!("type parameter not allowed")) .span_label(typ.span, "type parameter not allowed")
.emit(); .emit();
break; break;
} }
@ -959,7 +959,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
struct_span_err!(self.tcx().sess, lifetime.span, E0110, struct_span_err!(self.tcx().sess, lifetime.span, E0110,
"lifetime parameters are not allowed on this type") "lifetime parameters are not allowed on this type")
.span_label(lifetime.span, .span_label(lifetime.span,
&format!("lifetime parameter not allowed on this type")) "lifetime parameter not allowed on this type")
.emit(); .emit();
break; break;
} }
@ -973,7 +973,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
pub fn prohibit_projection(&self, span: Span) { pub fn prohibit_projection(&self, span: Span) {
let mut err = struct_span_err!(self.tcx().sess, span, E0229, let mut err = struct_span_err!(self.tcx().sess, span, E0229,
"associated type bindings are not allowed here"); "associated type bindings are not allowed here");
err.span_label(span, &format!("associate type not allowed here")).emit(); err.span_label(span, "associate type not allowed here").emit();
} }
// Check a type Path and convert it to a Ty. // Check a type Path and convert it to a Ty.
@ -1214,7 +1214,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
hir::TyTypeof(ref _e) => { hir::TyTypeof(ref _e) => {
struct_span_err!(tcx.sess, ast_ty.span, E0516, struct_span_err!(tcx.sess, ast_ty.span, E0516,
"`typeof` is a reserved keyword but unimplemented") "`typeof` is a reserved keyword but unimplemented")
.span_label(ast_ty.span, &format!("reserved keyword")) .span_label(ast_ty.span, "reserved keyword")
.emit(); .emit();
tcx.types.err tcx.types.err
@ -1426,7 +1426,7 @@ fn check_type_argument_count(tcx: TyCtxt, span: Span, supplied: usize,
"wrong number of type arguments: {} {}, found {}", "wrong number of type arguments: {} {}, found {}",
expected, required, supplied) expected, required, supplied)
.span_label(span, .span_label(span,
&format!("{} {} type argument{}", format!("{} {} type argument{}",
expected, expected,
required, required,
arguments_plural)) arguments_plural))
@ -1444,7 +1444,7 @@ fn check_type_argument_count(tcx: TyCtxt, span: Span, supplied: usize,
expected, supplied) expected, supplied)
.span_label( .span_label(
span, span,
&format!("{} type argument{}", format!("{} type argument{}",
if accepted == 0 { "expected no" } else { &expected }, if accepted == 0 { "expected no" } else { &expected },
arguments_plural) arguments_plural)
) )
@ -1470,7 +1470,7 @@ fn report_lifetime_number_error(tcx: TyCtxt, span: Span, number: usize, expected
struct_span_err!(tcx.sess, span, E0107, struct_span_err!(tcx.sess, span, E0107,
"wrong number of lifetime parameters: expected {}, found {}", "wrong number of lifetime parameters: expected {}, found {}",
expected, number) expected, number)
.span_label(span, &label) .span_label(span, label)
.emit(); .emit();
} }

View file

@ -97,7 +97,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
struct_span_err!(tcx.sess, span, E0029, struct_span_err!(tcx.sess, span, E0029,
"only char and numeric types are allowed in range patterns") "only char and numeric types are allowed in range patterns")
.span_label(span, &format!("ranges require char or numeric types")) .span_label(span, "ranges require char or numeric types")
.note(&format!("start type: {}", self.ty_to_string(lhs_ty))) .note(&format!("start type: {}", self.ty_to_string(lhs_ty)))
.note(&format!("end type: {}", self.ty_to_string(rhs_ty))) .note(&format!("end type: {}", self.ty_to_string(rhs_ty)))
.emit(); .emit();
@ -263,7 +263,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
tcx.sess, pat.span, E0527, tcx.sess, pat.span, E0527,
"pattern requires {} elements but array has {}", "pattern requires {} elements but array has {}",
min_len, size) min_len, size)
.span_label(pat.span, &format!("expected {} elements",size)) .span_label(pat.span, format!("expected {} elements",size))
.emit(); .emit();
} }
(inner_ty, tcx.types.err) (inner_ty, tcx.types.err)
@ -274,7 +274,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
"pattern requires at least {} elements but array has {}", "pattern requires at least {} elements but array has {}",
min_len, size) min_len, size)
.span_label(pat.span, .span_label(pat.span,
&format!("pattern cannot match array of {} elements", size)) format!("pattern cannot match array of {} elements", size))
.emit(); .emit();
(inner_ty, tcx.types.err) (inner_ty, tcx.types.err)
} }
@ -297,7 +297,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
} }
err.span_label( pat.span, err.span_label( pat.span,
&format!("pattern cannot match with input type `{}`", expected_ty) format!("pattern cannot match with input type `{}`", expected_ty)
).emit(); ).emit();
} }
(tcx.types.err, tcx.types.err) (tcx.types.err, tcx.types.err)
@ -379,7 +379,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
let type_str = self.ty_to_string(expected); let type_str = self.ty_to_string(expected);
struct_span_err!(self.tcx.sess, span, E0033, struct_span_err!(self.tcx.sess, span, E0033,
"type `{}` cannot be dereferenced", type_str) "type `{}` cannot be dereferenced", type_str)
.span_label(span, &format!("type `{}` cannot be dereferenced", type_str)) .span_label(span, format!("type `{}` cannot be dereferenced", type_str))
.emit(); .emit();
return false return false
} }
@ -593,7 +593,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
def.kind_name(), def.kind_name(),
hir::print::to_string(&tcx.hir, |s| s.print_qpath(qpath, false))); hir::print::to_string(&tcx.hir, |s| s.print_qpath(qpath, false)));
struct_span_err!(tcx.sess, pat.span, E0164, "{}", msg) struct_span_err!(tcx.sess, pat.span, E0164, "{}", msg)
.span_label(pat.span, &format!("not a tuple variant or struct")).emit(); .span_label(pat.span, "not a tuple variant or struct").emit();
on_error(); on_error();
}; };
@ -642,7 +642,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
"this pattern has {} field{}, but the corresponding {} has {} field{}", "this pattern has {} field{}, but the corresponding {} has {} field{}",
subpats.len(), subpats_ending, def.kind_name(), subpats.len(), subpats_ending, def.kind_name(),
variant.fields.len(), fields_ending) variant.fields.len(), fields_ending)
.span_label(pat.span, &format!("expected {} field{}, found {}", .span_label(pat.span, format!("expected {} field{}, found {}",
variant.fields.len(), fields_ending, subpats.len())) variant.fields.len(), fields_ending, subpats.len()))
.emit(); .emit();
on_error(); on_error();
@ -683,8 +683,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
in the pattern", in the pattern",
field.name) field.name)
.span_label(span, .span_label(span,
&format!("multiple uses of `{}` in pattern", field.name)) format!("multiple uses of `{}` in pattern", field.name))
.span_label(*occupied.get(), &format!("first use of `{}`", field.name)) .span_label(*occupied.get(), format!("first use of `{}`", field.name))
.emit(); .emit();
tcx.types.err tcx.types.err
} }
@ -703,7 +703,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
tcx.item_path_str(variant.did), tcx.item_path_str(variant.did),
field.name) field.name)
.span_label(span, .span_label(span,
&format!("{} `{}` does not have field `{}`", format!("{} `{}` does not have field `{}`",
kind_name, kind_name,
tcx.item_path_str(variant.did), tcx.item_path_str(variant.did),
field.name)) field.name))
@ -732,7 +732,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
struct_span_err!(tcx.sess, span, E0027, struct_span_err!(tcx.sess, span, E0027,
"pattern does not mention field `{}`", "pattern does not mention field `{}`",
field.name) field.name)
.span_label(span, &format!("missing field `{}`", field.name)) .span_label(span, format!("missing field `{}`", field.name))
.emit(); .emit();
} }
} }

View file

@ -62,7 +62,7 @@ impl<'a, 'gcx, 'tcx> Iterator for Autoderef<'a, 'gcx, 'tcx> {
E0055, E0055,
"reached the recursion limit while auto-dereferencing {:?}", "reached the recursion limit while auto-dereferencing {:?}",
self.cur_ty) self.cur_ty)
.span_label(self.span, &format!("deref recursion limit reached")) .span_label(self.span, "deref recursion limit reached")
.help(&format!( .help(&format!(
"consider adding a `#[recursion_limit=\"{}\"]` attribute to your crate", "consider adding a `#[recursion_limit=\"{}\"]` attribute to your crate",
suggested_limit)) suggested_limit))

View file

@ -27,7 +27,7 @@ use rustc::hir;
pub fn check_legal_trait_for_method_call(tcx: TyCtxt, span: Span, trait_id: DefId) { pub fn check_legal_trait_for_method_call(tcx: TyCtxt, span: Span, trait_id: DefId) {
if tcx.lang_items.drop_trait() == Some(trait_id) { if tcx.lang_items.drop_trait() == Some(trait_id) {
struct_span_err!(tcx.sess, span, E0040, "explicit use of destructor method") struct_span_err!(tcx.sess, span, E0040, "explicit use of destructor method")
.span_label(span, &format!("explicit destructor calls not allowed")) .span_label(span, "explicit destructor calls not allowed")
.emit(); .emit();
} }
} }

View file

@ -155,7 +155,7 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> {
}, },
self.expr_ty); self.expr_ty);
err.span_label(error_span, err.span_label(error_span,
&format!("cannot cast `{}` as `{}`", format!("cannot cast `{}` as `{}`",
fcx.ty_to_string(self.expr_ty), fcx.ty_to_string(self.expr_ty),
cast_ty)); cast_ty));
if let Ok(snippet) = fcx.sess().codemap().span_to_snippet(self.expr.span) { if let Ok(snippet) = fcx.sess().codemap().span_to_snippet(self.expr.span) {
@ -200,7 +200,7 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> {
} }
CastError::CastToBool => { CastError::CastToBool => {
struct_span_err!(fcx.tcx.sess, self.span, E0054, "cannot cast as `bool`") struct_span_err!(fcx.tcx.sess, self.span, E0054, "cannot cast as `bool`")
.span_label(self.span, &format!("unsupported cast")) .span_label(self.span, "unsupported cast")
.help("compare with zero instead") .help("compare with zero instead")
.emit(); .emit();
} }

View file

@ -1144,7 +1144,7 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E>
db = struct_span_err!( db = struct_span_err!(
fcx.tcx.sess, cause.span, E0069, fcx.tcx.sess, cause.span, E0069,
"`return;` in a function whose return type is not `()`"); "`return;` in a function whose return type is not `()`");
db.span_label(cause.span, &format!("return type is not ()")); db.span_label(cause.span, "return type is not ()");
} }
_ => { _ => {
db = fcx.report_mismatched_types(cause, expected, found, err); db = fcx.report_mismatched_types(cause, expected, found, err);

View file

@ -402,7 +402,7 @@ fn check_region_bounds_on_impl_method<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
"lifetime parameters or bounds on method `{}` do not match the \ "lifetime parameters or bounds on method `{}` do not match the \
trait declaration", trait declaration",
impl_m.name) impl_m.name)
.span_label(span, &format!("lifetimes do not match trait")) .span_label(span, "lifetimes do not match trait")
.emit(); .emit();
return Err(ErrorReported); return Err(ErrorReported);
} }
@ -534,9 +534,9 @@ fn compare_self_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
not in the trait", not in the trait",
trait_m.name, trait_m.name,
self_descr); self_descr);
err.span_label(impl_m_span, &format!("`{}` used in impl", self_descr)); err.span_label(impl_m_span, format!("`{}` used in impl", self_descr));
if let Some(span) = tcx.hir.span_if_local(trait_m.def_id) { if let Some(span) = tcx.hir.span_if_local(trait_m.def_id) {
err.span_label(span, &format!("trait declared without `{}`", self_descr)); err.span_label(span, format!("trait declared without `{}`", self_descr));
} }
err.emit(); err.emit();
return Err(ErrorReported); return Err(ErrorReported);
@ -552,9 +552,9 @@ fn compare_self_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
trait_m.name, trait_m.name,
self_descr); self_descr);
err.span_label(impl_m_span, err.span_label(impl_m_span,
&format!("expected `{}` in impl", self_descr)); format!("expected `{}` in impl", self_descr));
if let Some(span) = tcx.hir.span_if_local(trait_m.def_id) { if let Some(span) = tcx.hir.span_if_local(trait_m.def_id) {
err.span_label(span, &format!("`{}` used in trait", self_descr)); err.span_label(span, format!("`{}` used in trait", self_descr));
} }
err.emit(); err.emit();
return Err(ErrorReported); return Err(ErrorReported);
@ -606,7 +606,7 @@ fn compare_number_of_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
if let Some(span) = trait_item_span { if let Some(span) = trait_item_span {
err.span_label(span, err.span_label(span,
&format!("expected {}", format!("expected {}",
&if num_trait_m_type_params != 1 { &if num_trait_m_type_params != 1 {
format!("{} type parameters", num_trait_m_type_params) format!("{} type parameters", num_trait_m_type_params)
} else { } else {
@ -617,7 +617,7 @@ fn compare_number_of_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
} }
err.span_label(span, err.span_label(span,
&format!("found {}{}", format!("found {}{}",
&if num_impl_m_type_params != 1 { &if num_impl_m_type_params != 1 {
format!("{} type parameters", num_impl_m_type_params) format!("{} type parameters", num_impl_m_type_params)
} else { } else {
@ -696,7 +696,7 @@ fn compare_number_of_method_arguments<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
trait_number_args); trait_number_args);
if let Some(trait_span) = trait_span { if let Some(trait_span) = trait_span {
err.span_label(trait_span, err.span_label(trait_span,
&format!("trait requires {}", format!("trait requires {}",
&if trait_number_args != 1 { &if trait_number_args != 1 {
format!("{} parameters", trait_number_args) format!("{} parameters", trait_number_args)
} else { } else {
@ -704,7 +704,7 @@ fn compare_number_of_method_arguments<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
})); }));
} }
err.span_label(impl_span, err.span_label(impl_span,
&format!("expected {}, found {}", format!("expected {}, found {}",
&if trait_number_args != 1 { &if trait_number_args != 1 {
format!("{} parameters", trait_number_args) format!("{} parameters", trait_number_args)
} else { } else {

View file

@ -57,7 +57,7 @@ fn equate_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
"intrinsic has wrong number of type \ "intrinsic has wrong number of type \
parameters: found {}, expected {}", parameters: found {}, expected {}",
i_n_tps, n_tps) i_n_tps, n_tps)
.span_label(span, &format!("expected {} type parameter", n_tps)) .span_label(span, format!("expected {} type parameter", n_tps))
.emit(); .emit();
} else { } else {
require_same_types(tcx, require_same_types(tcx,
@ -101,7 +101,7 @@ pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
op => { op => {
struct_span_err!(tcx.sess, it.span, E0092, struct_span_err!(tcx.sess, it.span, E0092,
"unrecognized atomic operation function: `{}`", op) "unrecognized atomic operation function: `{}`", op)
.span_label(it.span, &format!("unrecognized atomic operation")) .span_label(it.span, "unrecognized atomic operation")
.emit(); .emit();
return; return;
} }
@ -305,7 +305,7 @@ pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
struct_span_err!(tcx.sess, it.span, E0093, struct_span_err!(tcx.sess, it.span, E0093,
"unrecognized intrinsic function: `{}`", "unrecognized intrinsic function: `{}`",
*other) *other)
.span_label(it.span, &format!("unrecognized intrinsic")) .span_label(it.span, "unrecognized intrinsic")
.emit(); .emit();
return; return;
} }
@ -505,7 +505,7 @@ fn match_intrinsic_type_to_type<'a, 'tcx>(
} }
} }
_ => simple_error(&format!("`{}`", t), _ => simple_error(&format!("`{}`", t),
&format!("tuple")), "tuple"),
} }
} }
} }

View file

@ -285,7 +285,7 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {
self.span, self.span,
E0035, E0035,
"does not take type parameters") "does not take type parameters")
.span_label(self.span, &"called with unneeded type parameters") .span_label(self.span, "called with unneeded type parameters")
.emit(); .emit();
} else { } else {
struct_span_err!(self.tcx.sess, struct_span_err!(self.tcx.sess,
@ -296,7 +296,7 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {
num_method_types, num_method_types,
num_supplied_types) num_supplied_types)
.span_label(self.span, .span_label(self.span,
&format!("Passed {} type argument{}, expected {}", format!("Passed {} type argument{}, expected {}",
num_supplied_types, num_supplied_types,
if num_supplied_types != 1 { "s" } else { "" }, if num_supplied_types != 1 { "s" } else { "" },
num_method_types)) num_method_types))

View file

@ -209,9 +209,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
expr_string, expr_string,
item_name)); item_name));
} }
err.span_label(span, &"field, not a method"); err.span_label(span, "field, not a method");
} else { } else {
err.span_label(span, &"private field, not a method"); err.span_label(span, "private field, not a method");
} }
break; break;
} }
@ -272,7 +272,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
span, span,
E0034, E0034,
"multiple applicable items in scope"); "multiple applicable items in scope");
err.span_label(span, &format!("multiple `{}` found", item_name)); err.span_label(span, format!("multiple `{}` found", item_name));
report_candidates(&mut err, sources); report_candidates(&mut err, sources);
err.emit(); err.emit();

View file

@ -1130,7 +1130,7 @@ fn check_on_unimplemented<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
struct_span_err!( struct_span_err!(
tcx.sess, attr.span, E0232, tcx.sess, attr.span, E0232,
"this attribute must have a value") "this attribute must have a value")
.span_label(attr.span, &format!("attribute requires a value")) .span_label(attr.span, "attribute requires a value")
.note(&format!("eg `#[rustc_on_unimplemented = \"foo\"]`")) .note(&format!("eg `#[rustc_on_unimplemented = \"foo\"]`"))
.emit(); .emit();
} }
@ -1146,12 +1146,12 @@ fn report_forbidden_specialization<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
"`{}` specializes an item from a parent `impl`, but \ "`{}` specializes an item from a parent `impl`, but \
that item is not marked `default`", that item is not marked `default`",
impl_item.name); impl_item.name);
err.span_label(impl_item.span, &format!("cannot specialize default item `{}`", err.span_label(impl_item.span, format!("cannot specialize default item `{}`",
impl_item.name)); impl_item.name));
match tcx.span_of_impl(parent_impl) { match tcx.span_of_impl(parent_impl) {
Ok(span) => { Ok(span) => {
err.span_label(span, &"parent `impl` is here"); err.span_label(span, "parent `impl` is here");
err.note(&format!("to specialize, `{}` in the parent `impl` must be marked `default`", err.note(&format!("to specialize, `{}` in the parent `impl` must be marked `default`",
impl_item.name)); impl_item.name));
} }
@ -1226,11 +1226,11 @@ fn check_impl_items_against_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
which doesn't match its trait `{}`", which doesn't match its trait `{}`",
ty_impl_item.name, ty_impl_item.name,
impl_trait_ref); impl_trait_ref);
err.span_label(impl_item.span, &format!("does not match trait")); err.span_label(impl_item.span, "does not match trait");
// We can only get the spans from local trait definition // We can only get the spans from local trait definition
// Same for E0324 and E0325 // Same for E0324 and E0325
if let Some(trait_span) = tcx.hir.span_if_local(ty_trait_item.def_id) { if let Some(trait_span) = tcx.hir.span_if_local(ty_trait_item.def_id) {
err.span_label(trait_span, &format!("item in trait")); err.span_label(trait_span, "item in trait");
} }
err.emit() err.emit()
} }
@ -1262,9 +1262,9 @@ fn check_impl_items_against_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
which doesn't match its trait `{}`", which doesn't match its trait `{}`",
ty_impl_item.name, ty_impl_item.name,
impl_trait_ref); impl_trait_ref);
err.span_label(impl_item.span, &format!("does not match trait")); err.span_label(impl_item.span, "does not match trait");
if let Some(trait_span) = tcx.hir.span_if_local(ty_trait_item.def_id) { if let Some(trait_span) = tcx.hir.span_if_local(ty_trait_item.def_id) {
err.span_label(trait_span, &format!("item in trait")); err.span_label(trait_span, "item in trait");
} }
err.emit() err.emit()
} }
@ -1280,9 +1280,9 @@ fn check_impl_items_against_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
which doesn't match its trait `{}`", which doesn't match its trait `{}`",
ty_impl_item.name, ty_impl_item.name,
impl_trait_ref); impl_trait_ref);
err.span_label(impl_item.span, &format!("does not match trait")); err.span_label(impl_item.span, "does not match trait");
if let Some(trait_span) = tcx.hir.span_if_local(ty_trait_item.def_id) { if let Some(trait_span) = tcx.hir.span_if_local(ty_trait_item.def_id) {
err.span_label(trait_span, &format!("item in trait")); err.span_label(trait_span, "item in trait");
} }
err.emit() err.emit()
} }
@ -1331,13 +1331,13 @@ fn check_impl_items_against_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
missing_items.iter() missing_items.iter()
.map(|trait_item| trait_item.name.to_string()) .map(|trait_item| trait_item.name.to_string())
.collect::<Vec<_>>().join("`, `")); .collect::<Vec<_>>().join("`, `"));
err.span_label(impl_span, &format!("missing `{}` in implementation", err.span_label(impl_span, format!("missing `{}` in implementation",
missing_items.iter() missing_items.iter()
.map(|trait_item| trait_item.name.to_string()) .map(|trait_item| trait_item.name.to_string())
.collect::<Vec<_>>().join("`, `"))); .collect::<Vec<_>>().join("`, `")));
for trait_item in missing_items { for trait_item in missing_items {
if let Some(span) = tcx.hir.span_if_local(trait_item.def_id) { if let Some(span) = tcx.hir.span_if_local(trait_item.def_id) {
err.span_label(span, &format!("`{}` from trait", trait_item.name)); err.span_label(span, format!("`{}` from trait", trait_item.name));
} else { } else {
err.note(&format!("`{}` from trait: `{}`", err.note(&format!("`{}` from trait: `{}`",
trait_item.name, trait_item.name,
@ -1377,7 +1377,7 @@ fn check_representable<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
Representability::SelfRecursive(spans) => { Representability::SelfRecursive(spans) => {
let mut err = tcx.recursive_type_with_infinite_size_error(item_def_id); let mut err = tcx.recursive_type_with_infinite_size_error(item_def_id);
for span in spans { for span in spans {
err.span_label(span, &"recursive without indirection"); err.span_label(span, "recursive without indirection");
} }
err.emit(); err.emit();
return false return false
@ -1399,7 +1399,7 @@ pub fn check_simd<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, sp: Span, def_id: DefId
let e = fields[0].ty(tcx, substs); let e = fields[0].ty(tcx, substs);
if !fields.iter().all(|f| f.ty(tcx, substs) == e) { if !fields.iter().all(|f| f.ty(tcx, substs) == e) {
struct_span_err!(tcx.sess, sp, E0076, "SIMD vector should be homogeneous") struct_span_err!(tcx.sess, sp, E0076, "SIMD vector should be homogeneous")
.span_label(sp, &format!("SIMD elements must have the same type")) .span_label(sp, "SIMD elements must have the same type")
.emit(); .emit();
return; return;
} }
@ -1471,7 +1471,7 @@ pub fn check_enum<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
struct_span_err!( struct_span_err!(
tcx.sess, sp, E0084, tcx.sess, sp, E0084,
"unsupported representation for zero-variant enum") "unsupported representation for zero-variant enum")
.span_label(sp, &format!("unsupported enum representation")) .span_label(sp, "unsupported enum representation")
.emit(); .emit();
} }
@ -1505,8 +1505,8 @@ pub fn check_enum<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
}; };
struct_span_err!(tcx.sess, span, E0081, struct_span_err!(tcx.sess, span, E0081,
"discriminant value `{}` already exists", disr_vals[i]) "discriminant value `{}` already exists", disr_vals[i])
.span_label(i_span, &format!("first use of `{}`", disr_vals[i])) .span_label(i_span, format!("first use of `{}`", disr_vals[i]))
.span_label(span , &format!("enum already has `{}`", disr_vals[i])) .span_label(span , format!("enum already has `{}`", disr_vals[i]))
.emit(); .emit();
} }
disr_vals.push(discr); disr_vals.push(discr);
@ -2401,12 +2401,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
if arg_count == 1 {" was"} else {"s were"}), if arg_count == 1 {" was"} else {"s were"}),
error_code); error_code);
err.span_label(sp, &format!("expected {}{} parameter{}", err.span_label(sp, format!("expected {}{} parameter{}",
if variadic {"at least "} else {""}, if variadic {"at least "} else {""},
expected_count, expected_count,
if expected_count == 1 {""} else {"s"})); if expected_count == 1 {""} else {"s"}));
if let Some(def_s) = def_span { if let Some(def_s) = def_span {
err.span_label(def_s, &format!("defined here")); err.span_label(def_s, "defined here");
} }
err.emit(); err.emit();
} }
@ -2938,10 +2938,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
if let Some(suggested_field_name) = if let Some(suggested_field_name) =
Self::suggest_field_name(def.struct_variant(), field, vec![]) { Self::suggest_field_name(def.struct_variant(), field, vec![]) {
err.span_label(field.span, err.span_label(field.span,
&format!("did you mean `{}`?", suggested_field_name)); format!("did you mean `{}`?", suggested_field_name));
} else { } else {
err.span_label(field.span, err.span_label(field.span,
&format!("unknown field")); "unknown field");
}; };
} }
ty::TyRawPtr(..) => { ty::TyRawPtr(..) => {
@ -3076,15 +3076,15 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
&field.name, &field.name,
skip_fields.collect()) { skip_fields.collect()) {
err.span_label(field.name.span, err.span_label(field.name.span,
&format!("field does not exist - did you mean `{}`?", field_name)); format!("field does not exist - did you mean `{}`?", field_name));
} else { } else {
match ty.sty { match ty.sty {
ty::TyAdt(adt, ..) if adt.is_enum() => { ty::TyAdt(adt, ..) if adt.is_enum() => {
err.span_label(field.name.span, &format!("`{}::{}` does not have this field", err.span_label(field.name.span, format!("`{}::{}` does not have this field",
ty, variant.name)); ty, variant.name));
} }
_ => { _ => {
err.span_label(field.name.span, &format!("`{}` does not have this field", ty)); err.span_label(field.name.span, format!("`{}` does not have this field", ty));
} }
} }
}; };
@ -3149,10 +3149,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
"field `{}` specified more than once", "field `{}` specified more than once",
field.name.node); field.name.node);
err.span_label(field.name.span, &format!("used more than once")); err.span_label(field.name.span, "used more than once");
if let Some(prev_span) = seen_fields.get(&field.name.node) { if let Some(prev_span) = seen_fields.get(&field.name.node) {
err.span_label(*prev_span, &format!("first use of `{}`", field.name.node)); err.span_label(*prev_span, format!("first use of `{}`", field.name.node));
} }
err.emit(); err.emit();
@ -3199,7 +3199,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
remaining_fields_names, remaining_fields_names,
truncated_fields_error, truncated_fields_error,
adt_ty) adt_ty)
.span_label(span, &format!("missing {}{}", .span_label(span, format!("missing {}{}",
remaining_fields_names, remaining_fields_names,
truncated_fields_error)) truncated_fields_error))
.emit(); .emit();
@ -3266,7 +3266,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
struct_span_err!(self.tcx.sess, path_span, E0071, struct_span_err!(self.tcx.sess, path_span, E0071,
"expected struct, variant or union type, found {}", "expected struct, variant or union type, found {}",
ty.sort_string(self.tcx)) ty.sort_string(self.tcx))
.span_label(path_span, &format!("not a struct")) .span_label(path_span, "not a struct")
.emit(); .emit();
None None
} }
@ -3625,7 +3625,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
"invalid left-hand side expression") "invalid left-hand side expression")
.span_label( .span_label(
expr.span, expr.span,
&format!("left-hand of expression not valid")) "left-hand of expression not valid")
.emit(); .emit();
} }
@ -4517,7 +4517,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
"too many lifetime parameters provided: \ "too many lifetime parameters provided: \
expected at most {}, found {}", expected at most {}, found {}",
expected_text, actual_text) expected_text, actual_text)
.span_label(span, &format!("expected {}", expected_text)) .span_label(span, format!("expected {}", expected_text))
.emit(); .emit();
} else if lifetimes.len() > 0 && lifetimes.len() < lifetime_defs.len() { } else if lifetimes.len() > 0 && lifetimes.len() < lifetime_defs.len() {
let expected_text = count_lifetime_params(lifetime_defs.len()); let expected_text = count_lifetime_params(lifetime_defs.len());
@ -4526,7 +4526,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
"too few lifetime parameters provided: \ "too few lifetime parameters provided: \
expected {}, found {}", expected {}, found {}",
expected_text, actual_text) expected_text, actual_text)
.span_label(span, &format!("expected {}", expected_text)) .span_label(span, format!("expected {}", expected_text))
.emit(); .emit();
} }
@ -4551,7 +4551,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
"too many type parameters provided: \ "too many type parameters provided: \
expected at most {}, found {}", expected at most {}, found {}",
expected_text, actual_text) expected_text, actual_text)
.span_label(span, &format!("expected {}", expected_text)) .span_label(span, format!("expected {}", expected_text))
.emit(); .emit();
// To prevent derived errors to accumulate due to extra // To prevent derived errors to accumulate due to extra
@ -4565,7 +4565,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
"too few type parameters provided: \ "too few type parameters provided: \
expected {}, found {}", expected {}, found {}",
expected_text, actual_text) expected_text, actual_text)
.span_label(span, &format!("expected {}", expected_text)) .span_label(span, format!("expected {}", expected_text))
.emit(); .emit();
} }
@ -4654,7 +4654,7 @@ pub fn check_bounds_are_used<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
struct_span_err!(tcx.sess, param.span, E0091, struct_span_err!(tcx.sess, param.span, E0091,
"type parameter `{}` is unused", "type parameter `{}` is unused",
param.name) param.name)
.span_label(param.span, &format!("unused type parameter")) .span_label(param.span, "unused type parameter")
.emit(); .emit();
} }
} }

View file

@ -50,7 +50,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
E0067, "invalid left-hand side expression") E0067, "invalid left-hand side expression")
.span_label( .span_label(
lhs_expr.span, lhs_expr.span,
&format!("invalid expression for left-hand side")) "invalid expression for left-hand side")
.emit(); .emit();
} }
ty ty
@ -203,7 +203,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
op.node.as_str(), op.node.as_str(),
lhs_ty) lhs_ty)
.span_label(lhs_expr.span, .span_label(lhs_expr.span,
&format!("cannot use `{}=` on type `{}`", format!("cannot use `{}=` on type `{}`",
op.node.as_str(), lhs_ty)) op.node.as_str(), lhs_ty))
.emit(); .emit();
} else { } else {
@ -278,7 +278,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
if let TyRef(_, r_ty) = rhs_ty.sty { if let TyRef(_, r_ty) = rhs_ty.sty {
if l_ty.ty.sty == TyStr && r_ty.ty.sty == TyStr { if l_ty.ty.sty == TyStr && r_ty.ty.sty == TyStr {
err.span_label(expr.span, err.span_label(expr.span,
&"`+` can't be used to concatenate two `&str` strings"); "`+` can't be used to concatenate two `&str` strings");
let codemap = self.tcx.sess.codemap(); let codemap = self.tcx.sess.codemap();
let suggestion = let suggestion =
match codemap.span_to_snippet(lhs_expr.span) { match codemap.span_to_snippet(lhs_expr.span) {

View file

@ -684,7 +684,7 @@ fn error_392<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, span: Span, param_name: ast:
-> DiagnosticBuilder<'tcx> { -> DiagnosticBuilder<'tcx> {
let mut err = struct_span_err!(tcx.sess, span, E0392, let mut err = struct_span_err!(tcx.sess, span, E0392,
"parameter `{}` is never used", param_name); "parameter `{}` is never used", param_name);
err.span_label(span, &format!("unused type parameter")); err.span_label(span, "unused type parameter");
err err
} }
@ -692,7 +692,7 @@ fn error_194(tcx: TyCtxt, span: Span, trait_decl_span: Span, name: ast::Name) {
struct_span_err!(tcx.sess, span, E0194, struct_span_err!(tcx.sess, span, E0194,
"type parameter `{}` shadows another type parameter of the same name", "type parameter `{}` shadows another type parameter of the same name",
name) name)
.span_label(span, &format!("shadows another type parameter")) .span_label(span, "shadows another type parameter")
.span_label(trait_decl_span, &format!("first `{}` declared here", name)) .span_label(trait_decl_span, format!("first `{}` declared here", name))
.emit(); .emit();
} }

View file

@ -74,7 +74,7 @@ fn visit_implementation_of_drop<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
E0120, E0120,
"the Drop trait may only be implemented on \ "the Drop trait may only be implemented on \
structures") structures")
.span_label(span, &format!("implementing Drop requires a struct")) .span_label(span, "implementing Drop requires a struct")
.emit(); .emit();
} }
_ => { _ => {
@ -130,7 +130,7 @@ fn visit_implementation_of_copy<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
"the trait `Copy` may not be implemented for this type") "the trait `Copy` may not be implemented for this type")
.span_label( .span_label(
tcx.def_span(field.did), tcx.def_span(field.did),
&"this field does not implement `Copy`") "this field does not implement `Copy`")
.emit() .emit()
} }
Err(CopyImplementationError::NotAnAdt) => { Err(CopyImplementationError::NotAnAdt) => {
@ -145,7 +145,7 @@ fn visit_implementation_of_copy<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
span, span,
E0206, E0206,
"the trait `Copy` may not be implemented for this type") "the trait `Copy` may not be implemented for this type")
.span_label(span, &format!("type is not a structure or enumeration")) .span_label(span, "type is not a structure or enumeration")
.emit(); .emit();
} }
Err(CopyImplementationError::HasDestructor) => { Err(CopyImplementationError::HasDestructor) => {
@ -154,7 +154,7 @@ fn visit_implementation_of_copy<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
E0184, E0184,
"the trait `Copy` may not be implemented for this type; the \ "the trait `Copy` may not be implemented for this type; the \
type has a destructor") type has a destructor")
.span_label(span, &format!("Copy not allowed on types with destructors")) .span_label(span, "Copy not allowed on types with destructors")
.emit(); .emit();
} }
} }
@ -310,7 +310,7 @@ pub fn coerce_unsized_info<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
}) })
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join(", "))); .join(", ")));
err.span_label(span, &format!("requires multiple coercions")); err.span_label(span, "requires multiple coercions");
err.emit(); err.emit();
return err_info; return err_info;
} }

View file

@ -259,7 +259,7 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for InherentCollect<'a, 'tcx> {
ty.span, ty.span,
E0118, E0118,
"no base type found for inherent implementation") "no base type found for inherent implementation")
.span_label(ty.span, &format!("impl requires a base type")) .span_label(ty.span, "impl requires a base type")
.note(&format!("either implement a trait on it or create a newtype \ .note(&format!("either implement a trait on it or create a newtype \
to wrap it instead")) to wrap it instead"))
.emit(); .emit();
@ -296,7 +296,7 @@ impl<'a, 'tcx> InherentCollect<'a, 'tcx> {
"cannot define inherent `impl` for a type outside of the crate \ "cannot define inherent `impl` for a type outside of the crate \
where the type is defined") where the type is defined")
.span_label(item.span, .span_label(item.span,
&format!("impl for type defined outside of crate.")) "impl for type defined outside of crate.")
.note("define and implement a trait or new type instead") .note("define and implement a trait or new type instead")
.emit(); .emit();
} }

View file

@ -56,9 +56,9 @@ impl<'a, 'tcx> InherentOverlapChecker<'a, 'tcx> {
"duplicate definitions with name `{}`", "duplicate definitions with name `{}`",
name) name)
.span_label(self.tcx.span_of_impl(item1).unwrap(), .span_label(self.tcx.span_of_impl(item1).unwrap(),
&format!("duplicate definitions for `{}`", name)) format!("duplicate definitions for `{}`", name))
.span_label(self.tcx.span_of_impl(item2).unwrap(), .span_label(self.tcx.span_of_impl(item2).unwrap(),
&format!("other definition for `{}`", name)) format!("other definition for `{}`", name))
.emit(); .emit();
} }
} }

View file

@ -62,7 +62,7 @@ fn enforce_trait_manually_implementable(tcx: TyCtxt, impl_def_id: DefId, trait_d
span, span,
E0322, E0322,
"explicit impls for the `Sized` trait are not permitted") "explicit impls for the `Sized` trait are not permitted")
.span_label(span, &format!("impl of 'Sized' not allowed")) .span_label(span, "impl of 'Sized' not allowed")
.emit(); .emit();
return; return;
} }

View file

@ -48,7 +48,7 @@ impl<'cx, 'tcx, 'v> ItemLikeVisitor<'v> for OrphanChecker<'cx, 'tcx> {
E0117, E0117,
"only traits defined in the current crate can be \ "only traits defined in the current crate can be \
implemented for arbitrary types") implemented for arbitrary types")
.span_label(item.span, &format!("impl doesn't use types inside crate")) .span_label(item.span, "impl doesn't use types inside crate")
.note(&format!("the impl does not reference any types defined in \ .note(&format!("the impl does not reference any types defined in \
this crate")) this crate"))
.note("define and implement a trait or new type instead") .note("define and implement a trait or new type instead")
@ -153,7 +153,7 @@ impl<'cx, 'tcx, 'v> ItemLikeVisitor<'v> for OrphanChecker<'cx, 'tcx> {
"cannot create default implementations for traits outside \ "cannot create default implementations for traits outside \
the crate they're defined in; define a new trait instead") the crate they're defined in; define a new trait instead")
.span_label(item_trait_ref.path.span, .span_label(item_trait_ref.path.span,
&format!("`{}` trait not defined in this crate", format!("`{}` trait not defined in this crate",
self.tcx.hir.node_to_pretty_string(item_trait_ref.ref_id))) self.tcx.hir.node_to_pretty_string(item_trait_ref.ref_id)))
.emit(); .emit();
return; return;

View file

@ -60,9 +60,9 @@ pub fn check_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, node_id: ast::NodeId) {
match tcx.span_of_impl(overlap.with_impl) { match tcx.span_of_impl(overlap.with_impl) {
Ok(span) => { Ok(span) => {
err.span_label(span, &format!("first implementation here")); err.span_label(span, "first implementation here");
err.span_label(tcx.span_of_impl(impl_def_id).unwrap(), err.span_label(tcx.span_of_impl(impl_def_id).unwrap(),
&format!("conflicting implementation{}", format!("conflicting implementation{}",
overlap.self_desc overlap.self_desc
.map_or(String::new(), .map_or(String::new(),
|ty| format!(" for `{}`", ty)))); |ty| format!(" for `{}`", ty))));

View file

@ -220,7 +220,7 @@ impl<'a, 'tcx> AstConv<'tcx, 'tcx> for ItemCtxt<'a, 'tcx> {
span, span,
E0121, E0121,
"the type placeholder `_` is not allowed within types on item signatures" "the type placeholder `_` is not allowed within types on item signatures"
).span_label(span, &format!("not allowed in type signatures")) ).span_label(span, "not allowed in type signatures")
.emit(); .emit();
self.tcx().types.err self.tcx().types.err
} }
@ -568,7 +568,7 @@ fn convert_enum_variant_types<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
} else { } else {
struct_span_err!(tcx.sess, variant.span, E0370, struct_span_err!(tcx.sess, variant.span, E0370,
"enum discriminant overflowed") "enum discriminant overflowed")
.span_label(variant.span, &format!("overflowed on value after {}", .span_label(variant.span, format!("overflowed on value after {}",
prev_discr.unwrap())) prev_discr.unwrap()))
.note(&format!("explicitly set `{} = {}` if that is desired outcome", .note(&format!("explicitly set `{} = {}` if that is desired outcome",
variant.node.name, wrapped_discr)) variant.node.name, wrapped_discr))
@ -604,8 +604,8 @@ fn convert_struct_variant<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
struct_span_err!(tcx.sess, f.span, E0124, struct_span_err!(tcx.sess, f.span, E0124,
"field `{}` is already declared", "field `{}` is already declared",
f.name) f.name)
.span_label(f.span, &"field already declared") .span_label(f.span, "field already declared")
.span_label(prev_span, &format!("`{}` first declared here", f.name)) .span_label(prev_span, format!("`{}` first declared here", f.name))
.emit(); .emit();
} else { } else {
seen_fields.insert(f.name, f.span); seen_fields.insert(f.name, f.span);

View file

@ -166,7 +166,7 @@ fn report_unused_parameter(tcx: TyCtxt,
"the {} parameter `{}` is not constrained by the \ "the {} parameter `{}` is not constrained by the \
impl trait, self type, or predicates", impl trait, self type, or predicates",
kind, name) kind, name)
.span_label(span, &format!("unconstrained {} parameter", kind)) .span_label(span, format!("unconstrained {} parameter", kind))
.emit(); .emit();
} }
@ -188,9 +188,9 @@ fn enforce_impl_items_are_distinct<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
"duplicate definitions with name `{}`:", "duplicate definitions with name `{}`:",
impl_item.name); impl_item.name);
err.span_label(*entry.get(), err.span_label(*entry.get(),
&format!("previous definition of `{}` here", format!("previous definition of `{}` here",
impl_item.name)); impl_item.name));
err.span_label(impl_item.span, &format!("duplicate definition")); err.span_label(impl_item.span, "duplicate definition");
err.emit(); err.emit();
} }
Vacant(entry) => { Vacant(entry) => {

View file

@ -143,7 +143,7 @@ fn require_c_abi_if_variadic(tcx: TyCtxt,
if decl.variadic && abi != Abi::C { if decl.variadic && abi != Abi::C {
let mut err = struct_span_err!(tcx.sess, span, E0045, let mut err = struct_span_err!(tcx.sess, span, E0045,
"variadic function must have C calling convention"); "variadic function must have C calling convention");
err.span_label(span, &("variadics require C calling conventions").to_string()) err.span_label(span, "variadics require C calling conventions")
.emit(); .emit();
} }
} }
@ -190,7 +190,7 @@ fn check_main_fn_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
struct_span_err!(tcx.sess, generics.span, E0131, struct_span_err!(tcx.sess, generics.span, E0131,
"main function is not allowed to have type parameters") "main function is not allowed to have type parameters")
.span_label(generics.span, .span_label(generics.span,
&format!("main cannot have type parameters")) "main cannot have type parameters")
.emit(); .emit();
return; return;
} }
@ -240,7 +240,7 @@ fn check_start_fn_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
struct_span_err!(tcx.sess, ps.span, E0132, struct_span_err!(tcx.sess, ps.span, E0132,
"start function is not allowed to have type parameters") "start function is not allowed to have type parameters")
.span_label(ps.span, .span_label(ps.span,
&format!("start function cannot have type parameters")) "start function cannot have type parameters")
.emit(); .emit();
return; return;
} }

View file

@ -687,9 +687,9 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool,
} }
} }
clean::Vector(ref t) if is_not_debug => { clean::Vector(ref t) if is_not_debug => {
primitive_link(f, PrimitiveType::Slice, &format!("["))?; primitive_link(f, PrimitiveType::Slice, "[")?;
fmt::Display::fmt(t, f)?; fmt::Display::fmt(t, f)?;
primitive_link(f, PrimitiveType::Slice, &format!("]")) primitive_link(f, PrimitiveType::Slice, "]")
} }
clean::Vector(ref t) => write!(f, "[{:?}]", t), clean::Vector(ref t) => write!(f, "[{:?}]", t),
clean::FixedVector(ref t, ref s) if is_not_debug => { clean::FixedVector(ref t, ref s) if is_not_debug => {

View file

@ -2412,7 +2412,7 @@ mod tests {
let tmpdir = tmpdir(); let tmpdir = tmpdir();
let unicode = tmpdir.path(); let unicode = tmpdir.path();
let unicode = unicode.join(&format!("test-각丁ー再见")); let unicode = unicode.join("test-각丁ー再见");
check!(fs::create_dir(&unicode)); check!(fs::create_dir(&unicode));
assert!(unicode.exists()); assert!(unicode.exists());
assert!(!Path::new("test/unicode-bogus-path-각丁ー再见").exists()); assert!(!Path::new("test/unicode-bogus-path-각丁ー再见").exists());

View file

@ -511,8 +511,7 @@ pub fn find_export_name_attr(diag: &Handler, attrs: &[Attribute]) -> Option<Symb
} else { } else {
struct_span_err!(diag, attr.span, E0558, struct_span_err!(diag, attr.span, E0558,
"export_name attribute has invalid format") "export_name attribute has invalid format")
.span_label(attr.span, .span_label(attr.span, "did you mean #[export_name=\"*\"]?")
&format!("did you mean #[export_name=\"*\"]?"))
.emit(); .emit();
None None
} }

View file

@ -602,10 +602,10 @@ impl<'a> Parser<'a> {
label_sp label_sp
}; };
if self.span.contains(sp) { if self.span.contains(sp) {
err.span_label(self.span, &label_exp); err.span_label(self.span, label_exp);
} else { } else {
err.span_label(sp, &label_exp); err.span_label(sp, label_exp);
err.span_label(self.span, &"unexpected token"); err.span_label(self.span, "unexpected token");
} }
Err(err) Err(err)
} }
@ -1512,10 +1512,10 @@ impl<'a> Parser<'a> {
err.span_suggestion(sum_span, "try adding parentheses:", sum_with_parens); err.span_suggestion(sum_span, "try adding parentheses:", sum_with_parens);
} }
TyKind::Ptr(..) | TyKind::BareFn(..) => { TyKind::Ptr(..) | TyKind::BareFn(..) => {
err.span_label(sum_span, &"perhaps you forgot parentheses?"); err.span_label(sum_span, "perhaps you forgot parentheses?");
} }
_ => { _ => {
err.span_label(sum_span, &"expected a path"); err.span_label(sum_span, "expected a path");
}, },
} }
err.emit(); err.emit();
@ -2556,7 +2556,7 @@ impl<'a> Parser<'a> {
let fstr = n.as_str(); let fstr = n.as_str();
let mut err = self.diagnostic().struct_span_err(self.prev_span, let mut err = self.diagnostic().struct_span_err(self.prev_span,
&format!("unexpected token: `{}`", n)); &format!("unexpected token: `{}`", n));
err.span_label(self.prev_span, &"unexpected token"); err.span_label(self.prev_span, "unexpected token");
if fstr.chars().all(|x| "0123456789.".contains(x)) { if fstr.chars().all(|x| "0123456789.".contains(x)) {
let float = match fstr.parse::<f64>().ok() { let float = match fstr.parse::<f64>().ok() {
Some(f) => f, Some(f) => f,
@ -2708,7 +2708,7 @@ impl<'a> Parser<'a> {
let span_of_tilde = lo; let span_of_tilde = lo;
let mut err = self.diagnostic().struct_span_err(span_of_tilde, let mut err = self.diagnostic().struct_span_err(span_of_tilde,
"`~` can not be used as a unary operator"); "`~` can not be used as a unary operator");
err.span_label(span_of_tilde, &"did you mean `!`?"); err.span_label(span_of_tilde, "did you mean `!`?");
err.help("use `!` instead of `~` if you meant to perform bitwise negation"); err.help("use `!` instead of `~` if you meant to perform bitwise negation");
err.emit(); err.emit();
(span, self.mk_unary(UnOp::Not, e)) (span, self.mk_unary(UnOp::Not, e))
@ -4792,7 +4792,7 @@ impl<'a> Parser<'a> {
sp, sp,
&format!("missing `fn`, `type`, or `const` for {}-item declaration", &format!("missing `fn`, `type`, or `const` for {}-item declaration",
item_type)); item_type));
err.span_label(sp, &"missing `fn`, `type`, or `const`"); err.span_label(sp, "missing `fn`, `type`, or `const`");
err err
} }