Skip to content

Commit 198917b

Browse files
committed
Auto merge of #41745 - oli-obk:diagnostics, r=jonathandturner
Remove need for &format!(...) or &&"" dances in `span_label` calls These were always a thorn in my eye. Note that this will monomorphize to two impls, one for `String` and one for `&str`. But I think that cost is worth the ergonomics at the call sites that can be seen throughout this PR.
2 parents 70198a0 + dd87eab commit 198917b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+305
-305
lines changed

src/librustc/hir/check_attr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl<'a> CheckAttrVisitor<'a> {
4343
fn check_inline(&self, attr: &ast::Attribute, target: Target) {
4444
if target != Target::Fn {
4545
struct_span_err!(self.sess, attr.span, E0518, "attribute should be applied to function")
46-
.span_label(attr.span, &format!("requires a function"))
46+
.span_label(attr.span, "requires a function")
4747
.emit();
4848
}
4949
}
@@ -123,7 +123,7 @@ impl<'a> CheckAttrVisitor<'a> {
123123
_ => continue,
124124
};
125125
struct_span_err!(self.sess, attr.span, E0517, "{}", message)
126-
.span_label(attr.span, &format!("requires {}", label))
126+
.span_label(attr.span, format!("requires {}", label))
127127
.emit();
128128
}
129129
if conflicting_reprs > 1 {

src/librustc/infer/error_reporting/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -668,9 +668,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
668668
}
669669
}
670670

671-
diag.span_label(span, &terr);
671+
diag.span_label(span, terr.to_string());
672672
if let Some((sp, msg)) = secondary_span {
673-
diag.span_label(sp, &msg);
673+
diag.span_label(sp, msg);
674674
}
675675

676676
self.note_error_origin(diag, &cause);

src/librustc/lint/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -680,12 +680,12 @@ pub trait LintContext<'tcx>: Sized {
680680
"{}({}) overruled by outer forbid({})",
681681
level.as_str(), lint_name,
682682
lint_name);
683-
diag_builder.span_label(span, &format!("overruled by previous forbid"));
683+
diag_builder.span_label(span, "overruled by previous forbid");
684684
match now_source {
685685
LintSource::Default => &mut diag_builder,
686686
LintSource::Node(_, forbid_source_span) => {
687687
diag_builder.span_label(forbid_source_span,
688-
&format!("`forbid` level set here"))
688+
"`forbid` level set here")
689689
},
690690
LintSource::CommandLine(_) => {
691691
diag_builder.note("`forbid` lint level was set on command line")

src/librustc/middle/const_val.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> {
197197
{
198198
match self.description() {
199199
ConstEvalErrDescription::Simple(message) => {
200-
diag.span_label(self.span, &message);
200+
diag.span_label(self.span, message);
201201
}
202202
}
203203

src/librustc/middle/effect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl<'a, 'tcx> EffectCheckVisitor<'a, 'tcx> {
7474
struct_span_err!(
7575
self.tcx.sess, span, E0133,
7676
"{} requires unsafe function or block", description)
77-
.span_label(span, &description)
77+
.span_label(span, description)
7878
.emit();
7979
}
8080
}

src/librustc/middle/entry.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ fn find_item(item: &Item, ctxt: &mut EntryContext, at_root: bool) {
128128
} else {
129129
struct_span_err!(ctxt.session, item.span, E0137,
130130
"multiple functions with a #[main] attribute")
131-
.span_label(item.span, &format!("additional #[main] function"))
132-
.span_label(ctxt.attr_main_fn.unwrap().1, &format!("first #[main] function"))
131+
.span_label(item.span, "additional #[main] function")
132+
.span_label(ctxt.attr_main_fn.unwrap().1, "first #[main] function")
133133
.emit();
134134
}
135135
},
@@ -141,8 +141,8 @@ fn find_item(item: &Item, ctxt: &mut EntryContext, at_root: bool) {
141141
ctxt.session, item.span, E0138,
142142
"multiple 'start' functions")
143143
.span_label(ctxt.start_fn.unwrap().1,
144-
&format!("previous `start` function here"))
145-
.span_label(item.span, &format!("multiple `start` functions"))
144+
"previous `start` function here")
145+
.span_label(item.span, "multiple `start` functions")
146146
.emit();
147147
}
148148
},

src/librustc/middle/intrinsicck.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl<'a, 'gcx, 'tcx> ExprVisitor<'a, 'gcx, 'tcx> {
9292
struct_span_err!(self.infcx.tcx.sess, span, E0591,
9393
"`{}` is zero-sized and can't be transmuted to `{}`",
9494
from, to)
95-
.span_note(span, &format!("cast with `as` to a pointer instead"))
95+
.span_note(span, "cast with `as` to a pointer instead")
9696
.emit();
9797
return;
9898
}
@@ -126,7 +126,7 @@ impl<'a, 'gcx, 'tcx> ExprVisitor<'a, 'gcx, 'tcx> {
126126
from, skeleton_string(from, sk_from),
127127
to, skeleton_string(to, sk_to))
128128
.span_label(span,
129-
&format!("transmuting between {} and {}",
129+
format!("transmuting between {} and {}",
130130
skeleton_string(from, sk_from),
131131
skeleton_string(to, sk_to)))
132132
.emit();

src/librustc/middle/resolve_lifetime.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -574,9 +574,9 @@ fn signal_shadowing_problem(sess: &Session, name: ast::Name, orig: Original, sha
574574
{} name that is already in scope",
575575
shadower.kind.desc(), name, orig.kind.desc()))
576576
};
577-
err.span_label(orig.span, &"first declared here");
577+
err.span_label(orig.span, "first declared here");
578578
err.span_label(shadower.span,
579-
&format!("lifetime {} already in scope", name));
579+
format!("lifetime {} already in scope", name));
580580
err.emit();
581581
}
582582

@@ -919,7 +919,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
919919
} else {
920920
struct_span_err!(self.sess, lifetime_ref.span, E0261,
921921
"use of undeclared lifetime name `{}`", lifetime_ref.name)
922-
.span_label(lifetime_ref.span, &format!("undeclared lifetime"))
922+
.span_label(lifetime_ref.span, "undeclared lifetime")
923923
.emit();
924924
}
925925
}
@@ -1328,7 +1328,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
13281328
} else {
13291329
format!("expected lifetime parameter")
13301330
};
1331-
err.span_label(span, &msg);
1331+
err.span_label(span, msg);
13321332

13331333
if let Some(params) = error {
13341334
if lifetime_refs.len() == 1 {
@@ -1438,7 +1438,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
14381438
let mut err = struct_span_err!(self.sess, lifetime.span, E0262,
14391439
"invalid lifetime parameter name: `{}`", lifetime.name);
14401440
err.span_label(lifetime.span,
1441-
&format!("{} is a reserved lifetime name", lifetime.name));
1441+
format!("{} is a reserved lifetime name", lifetime.name));
14421442
err.emit();
14431443
}
14441444
}
@@ -1452,9 +1452,9 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
14521452
"lifetime name `{}` declared twice in the same scope",
14531453
lifetime_j.lifetime.name)
14541454
.span_label(lifetime_j.lifetime.span,
1455-
&format!("declared twice"))
1455+
"declared twice")
14561456
.span_label(lifetime_i.lifetime.span,
1457-
&format!("previous declaration here"))
1457+
"previous declaration here")
14581458
.emit();
14591459
}
14601460
}

src/librustc/traits/error_reporting.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -484,12 +484,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
484484

485485
if let Some(trait_item_span) = self.tcx.hir.span_if_local(trait_item_def_id) {
486486
let span = self.tcx.sess.codemap().def_span(trait_item_span);
487-
err.span_label(span, &format!("definition of `{}` from trait", item_name));
487+
err.span_label(span, format!("definition of `{}` from trait", item_name));
488488
}
489489

490490
err.span_label(
491491
error_span,
492-
&format!("impl has extra requirement {}", requirement));
492+
format!("impl has extra requirement {}", requirement));
493493

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

584584
err.span_label(span,
585-
&format!("{}the trait `{}` is not implemented for `{}`",
585+
format!("{}the trait `{}` is not implemented for `{}`",
586586
pre_message,
587587
trait_ref,
588588
trait_ref.self_ty()));
@@ -738,11 +738,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
738738
expected_ref,
739739
found_ref);
740740

741-
err.span_label(span, &format!("{}", type_error));
741+
err.span_label(span, format!("{}", type_error));
742742

743743
if let Some(sp) = found_span {
744-
err.span_label(span, &format!("requires `{}`", found_ref));
745-
err.span_label(sp, &format!("implements `{}`", expected_ref));
744+
err.span_label(span, format!("requires `{}`", found_ref));
745+
err.span_label(sp, format!("implements `{}`", expected_ref));
746746
}
747747

748748
err
@@ -765,12 +765,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
765765
if expected == 1 { "" } else { "s" },
766766
if expected == 1 { "is" } else { "are" });
767767

768-
err.span_label(span, &format!("expected {} that takes {} argument{}",
768+
err.span_label(span, format!("expected {} that takes {} argument{}",
769769
if is_closure { "closure" } else { "function" },
770770
expected,
771771
if expected == 1 { "" } else { "s" }));
772772
if let Some(span) = found_span {
773-
err.span_label(span, &format!("takes {} argument{}",
773+
err.span_label(span, format!("takes {} argument{}",
774774
found,
775775
if found == 1 { "" } else { "s" }));
776776
}
@@ -789,7 +789,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
789789
let mut err = struct_span_err!(self.sess, span, E0072,
790790
"recursive type `{}` has infinite size",
791791
self.item_path_str(type_def_id));
792-
err.span_label(span, &format!("recursive type has infinite size"));
792+
err.span_label(span, "recursive type has infinite size");
793793
err.help(&format!("insert indirection (e.g., a `Box`, `Rc`, or `&`) \
794794
at some point to make `{}` representable",
795795
self.item_path_str(type_def_id)));
@@ -808,7 +808,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
808808
self.sess, span, E0038,
809809
"the trait `{}` cannot be made into an object",
810810
trait_str);
811-
err.span_label(span, &format!("the trait `{}` cannot be made into an object", trait_str));
811+
err.span_label(span, format!("the trait `{}` cannot be made into an object", trait_str));
812812

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

10451045
for (target_span, label_message) in labels {
1046-
err.span_label(target_span, &label_message);
1046+
err.span_label(target_span, label_message);
10471047
}
10481048

10491049
err.emit();

src/librustc/ty/maps.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
181181
let mut err =
182182
struct_span_err!(self.sess, span, E0391,
183183
"unsupported cyclic reference between types/traits detected");
184-
err.span_label(span, &format!("cyclic reference"));
184+
err.span_label(span, "cyclic reference");
185185

186186
err.span_note(stack[0].0, &format!("the cycle begins when {}...",
187187
stack[0].1.describe(self)));

0 commit comments

Comments
 (0)