diff options
| author | bors <bors@rust-lang.org> | 2017-05-08 12:00:22 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-05-08 12:00:22 +0000 |
| commit | 198917bb4f13daca7225af61d17c6fd4f70487bd (patch) | |
| tree | 4d6b198ad0e356961a8b64603caa847a81b86b68 /src/librustc_errors | |
| parent | 70198a0a44633c7c9d14fce2159c1f750491287b (diff) | |
| parent | dd87eabd83296baa4c2214d2cf3aeef24f753ba7 (diff) | |
| download | rust-198917bb4f13daca7225af61d17c6fd4f70487bd.tar.gz rust-198917bb4f13daca7225af61d17c6fd4f70487bd.zip | |
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.
Diffstat (limited to 'src/librustc_errors')
| -rw-r--r-- | src/librustc_errors/diagnostic.rs | 5 | ||||
| -rw-r--r-- | src/librustc_errors/diagnostic_builder.rs | 6 |
2 files changed, 6 insertions, 5 deletions
diff --git a/src/librustc_errors/diagnostic.rs b/src/librustc_errors/diagnostic.rs index 38fa35ecb12..0822f713499 100644 --- a/src/librustc_errors/diagnostic.rs +++ b/src/librustc_errors/diagnostic.rs @@ -114,9 +114,8 @@ impl Diagnostic { /// all, and you just supplied a `Span` to create the diagnostic, /// then the snippet will just include that `Span`, which is /// called the primary span. - pub fn span_label(&mut self, span: Span, label: &fmt::Display) - -> &mut Self { - self.span.push_span_label(span, format!("{}", label)); + pub fn span_label<T: Into<String>>(&mut self, span: Span, label: T) -> &mut Self { + self.span.push_span_label(span, label.into()); self } diff --git a/src/librustc_errors/diagnostic_builder.rs b/src/librustc_errors/diagnostic_builder.rs index 9dfd47b8464..a9c2bbeba2a 100644 --- a/src/librustc_errors/diagnostic_builder.rs +++ b/src/librustc_errors/diagnostic_builder.rs @@ -112,8 +112,10 @@ impl<'a> DiagnosticBuilder<'a> { /// all, and you just supplied a `Span` to create the diagnostic, /// then the snippet will just include that `Span`, which is /// called the primary span. - forward!(pub fn span_label(&mut self, span: Span, label: &fmt::Display) - -> &mut Self); + pub fn span_label<T: Into<String>>(&mut self, span: Span, label: T) -> &mut Self { + self.diagnostic.span_label(span, label); + self + } forward!(pub fn note_expected_found(&mut self, label: &fmt::Display, |
