Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/librustc/hir/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl<'a> CheckAttrVisitor<'a> {
fn check_inline(&self, attr: &ast::Attribute, target: Target) {
if target != Target::Fn {
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();
}
}
Expand Down Expand Up @@ -123,7 +123,7 @@ impl<'a> CheckAttrVisitor<'a> {
_ => continue,
};
struct_span_err!(self.sess, attr.span, E0517, "{}", message)
.span_label(attr.span, &format!("requires {}", label))
.span_label(attr.span, format!("requires {}", label))
.emit();
}
if conflicting_reprs > 1 {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
diag.span_label(sp, &msg);
diag.span_label(sp, msg);
}

self.note_error_origin(diag, &cause);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,12 +680,12 @@ pub trait LintContext<'tcx>: Sized {
"{}({}) overruled by outer forbid({})",
level.as_str(), 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 {
LintSource::Default => &mut diag_builder,
LintSource::Node(_, forbid_source_span) => {
diag_builder.span_label(forbid_source_span,
&format!("`forbid` level set here"))
"`forbid` level set here")
},
LintSource::CommandLine(_) => {
diag_builder.note("`forbid` lint level was set on command line")
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/const_val.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> {
{
match self.description() {
ConstEvalErrDescription::Simple(message) => {
diag.span_label(self.span, &message);
diag.span_label(self.span, message);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl<'a, 'tcx> EffectCheckVisitor<'a, 'tcx> {
struct_span_err!(
self.tcx.sess, span, E0133,
"{} requires unsafe function or block", description)
.span_label(span, &description)
.span_label(span, description)
.emit();
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ fn find_item(item: &Item, ctxt: &mut EntryContext, at_root: bool) {
} else {
struct_span_err!(ctxt.session, item.span, E0137,
"multiple functions with a #[main] attribute")
.span_label(item.span, &format!("additional #[main] function"))
.span_label(ctxt.attr_main_fn.unwrap().1, &format!("first #[main] function"))
.span_label(item.span, "additional #[main] function")
.span_label(ctxt.attr_main_fn.unwrap().1, "first #[main] function")
.emit();
}
},
Expand All @@ -141,8 +141,8 @@ fn find_item(item: &Item, ctxt: &mut EntryContext, at_root: bool) {
ctxt.session, item.span, E0138,
"multiple 'start' functions")
.span_label(ctxt.start_fn.unwrap().1,
&format!("previous `start` function here"))
.span_label(item.span, &format!("multiple `start` functions"))
"previous `start` function here")
.span_label(item.span, "multiple `start` functions")
.emit();
}
},
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/intrinsicck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl<'a, 'gcx, 'tcx> ExprVisitor<'a, 'gcx, 'tcx> {
struct_span_err!(self.infcx.tcx.sess, span, E0591,
"`{}` is zero-sized and can't be transmuted 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();
return;
}
Expand Down Expand Up @@ -126,7 +126,7 @@ impl<'a, 'gcx, 'tcx> ExprVisitor<'a, 'gcx, 'tcx> {
from, skeleton_string(from, sk_from),
to, skeleton_string(to, sk_to))
.span_label(span,
&format!("transmuting between {} and {}",
format!("transmuting between {} and {}",
skeleton_string(from, sk_from),
skeleton_string(to, sk_to)))
.emit();
Expand Down
14 changes: 7 additions & 7 deletions src/librustc/middle/resolve_lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,9 +574,9 @@ fn signal_shadowing_problem(sess: &Session, name: ast::Name, orig: Original, sha
{} name that is already in scope",
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,
&format!("lifetime {} already in scope", name));
format!("lifetime {} already in scope", name));
err.emit();
}

Expand Down Expand Up @@ -919,7 +919,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
} else {
struct_span_err!(self.sess, lifetime_ref.span, E0261,
"use of undeclared lifetime name `{}`", lifetime_ref.name)
.span_label(lifetime_ref.span, &format!("undeclared lifetime"))
.span_label(lifetime_ref.span, "undeclared lifetime")
.emit();
}
}
Expand Down Expand Up @@ -1328,7 +1328,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
} else {
format!("expected lifetime parameter")
};
err.span_label(span, &msg);
err.span_label(span, msg);

if let Some(params) = error {
if lifetime_refs.len() == 1 {
Expand Down Expand Up @@ -1438,7 +1438,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
let mut err = struct_span_err!(self.sess, lifetime.span, E0262,
"invalid lifetime parameter name: `{}`", lifetime.name);
err.span_label(lifetime.span,
&format!("{} is a reserved lifetime name", lifetime.name));
format!("{} is a reserved lifetime name", lifetime.name));
err.emit();
}
}
Expand All @@ -1452,9 +1452,9 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
"lifetime name `{}` declared twice in the same scope",
lifetime_j.lifetime.name)
.span_label(lifetime_j.lifetime.span,
&format!("declared twice"))
"declared twice")
.span_label(lifetime_i.lifetime.span,
&format!("previous declaration here"))
"previous declaration here")
.emit();
}
}
Expand Down
22 changes: 11 additions & 11 deletions src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
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(
error_span,
&format!("impl has extra requirement {}", requirement));
format!("impl has extra requirement {}", requirement));

if let Some(node_id) = lint_id {
self.tcx.sess.add_lint_diagnostic(EXTRA_REQUIREMENT_IN_IMPL,
Expand Down Expand Up @@ -582,7 +582,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
}

err.span_label(span,
&format!("{}the trait `{}` is not implemented for `{}`",
format!("{}the trait `{}` is not implemented for `{}`",
pre_message,
trait_ref,
trait_ref.self_ty()));
Expand Down Expand Up @@ -738,11 +738,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
expected_ref,
found_ref);

err.span_label(span, &format!("{}", type_error));
err.span_label(span, format!("{}", type_error));

if let Some(sp) = found_span {
err.span_label(span, &format!("requires `{}`", found_ref));
err.span_label(sp, &format!("implements `{}`", expected_ref));
err.span_label(span, format!("requires `{}`", found_ref));
err.span_label(sp, format!("implements `{}`", expected_ref));
}

err
Expand All @@ -765,12 +765,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
if expected == 1 { "" } else { "s" },
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" },
expected,
if expected == 1 { "" } else { "s" }));
if let Some(span) = found_span {
err.span_label(span, &format!("takes {} argument{}",
err.span_label(span, format!("takes {} argument{}",
found,
if found == 1 { "" } else { "s" }));
}
Expand All @@ -789,7 +789,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
let mut err = struct_span_err!(self.sess, span, E0072,
"recursive type `{}` has infinite size",
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 `&`) \
at some point to make `{}` representable",
self.item_path_str(type_def_id)));
Expand All @@ -808,7 +808,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
self.sess, span, E0038,
"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));
err.span_label(span, format!("the trait `{}` cannot be made into an object", trait_str));

let mut reported_violations = FxHashSet();
for violation in violations {
Expand Down Expand Up @@ -1043,7 +1043,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
"type annotations needed");

for (target_span, label_message) in labels {
err.span_label(target_span, &label_message);
err.span_label(target_span, label_message);
}

err.emit();
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/maps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
let mut err =
struct_span_err!(self.sess, span, E0391,
"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 {}...",
stack[0].1.describe(self)));
Expand Down
Loading