Skip to content

Commit

Permalink
review comments: remove unnecessary &str to String conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Nov 24, 2019
1 parent d92355c commit 9d7774c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
40 changes: 20 additions & 20 deletions src/librustc/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -898,8 +898,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {

// unsafe extern "C" for<'a> fn(&'a T) -> &'a T
// ^^^^^^
values.0.push(sig1.unsafety.prefix_str().to_string(), sig1.unsafety != sig2.unsafety);
values.1.push(sig2.unsafety.prefix_str().to_string(), sig1.unsafety != sig2.unsafety);
values.0.push(sig1.unsafety.prefix_str(), sig1.unsafety != sig2.unsafety);
values.1.push(sig2.unsafety.prefix_str(), sig1.unsafety != sig2.unsafety);

// unsafe extern "C" for<'a> fn(&'a T) -> &'a T
// ^^^^^^^^^^
Expand All @@ -918,8 +918,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {

// unsafe extern "C" for<'a> fn(&'a T) -> &'a T
// ^^^
values.0.push_normal("fn(".to_string());
values.1.push_normal("fn(".to_string());
values.0.push_normal("fn(");
values.1.push_normal("fn(");

// unsafe extern "C" for<'a> fn(&'a T) -> &'a T
// ^^^^^
Expand All @@ -936,46 +936,46 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
for (i, l) in sig1.inputs().iter().enumerate() {
values.0.push_highlighted(l.to_string());
if i != len1 - 1 {
values.0.push_highlighted(", ".to_string());
values.0.push_highlighted(", ");
}
}
for (i, r) in sig2.inputs().iter().enumerate() {
values.1.push_highlighted(r.to_string());
if i != len2 - 1 {
values.1.push_highlighted(", ".to_string());
values.1.push_highlighted(", ");
}
}
}

if sig1.c_variadic {
if len1 > 0 {
values.0.push_normal(", ".to_string());
values.0.push_normal(", ");
}
values.0.push("...".to_string(), !sig2.c_variadic);
values.0.push("...", !sig2.c_variadic);
}
if sig2.c_variadic {
if len2 > 0 {
values.1.push_normal(", ".to_string());
values.1.push_normal(", ");
}
values.1.push("...".to_string(), !sig1.c_variadic);
values.1.push("...", !sig1.c_variadic);
}

// unsafe extern "C" for<'a> fn(&'a T) -> &'a T
// ^
values.0.push_normal(")".to_string());
values.1.push_normal(")".to_string());
values.0.push_normal(")");
values.1.push_normal(")");

// unsafe extern "C" for<'a> fn(&'a T) -> &'a T
// ^^^^^^^^
let output1 = sig1.output();
let output2 = sig2.output();
let (x1, x2) = self.cmp(output1, output2);
if !output1.is_unit() {
values.0.push_normal(" -> ".to_string());
values.0.push_normal(" -> ");
(values.0).0.extend(x1.0);
}
if !output2.is_unit() {
values.1.push_normal(" -> ".to_string());
values.1.push_normal(" -> ");
(values.1).0.extend(x2.0);
}
values
Expand Down Expand Up @@ -1240,8 +1240,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
// When encountering tuples of the same size, highlight only the differing types
(&ty::Tuple(substs1), &ty::Tuple(substs2)) if substs1.len() == substs2.len() => {
let mut values = (
DiagnosticStyledString::normal("(".to_string()),
DiagnosticStyledString::normal("(".to_string()),
DiagnosticStyledString::normal("("),
DiagnosticStyledString::normal("("),
);
let len = substs1.len();
for (i, (left, right)) in substs1.types().zip(substs2.types()).enumerate() {
Expand All @@ -1251,11 +1251,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
self.push_comma(&mut values.0, &mut values.1, len, i);
}
if len == 1 { // Keep the output for single element tuples as `(ty,)`.
values.0.push_normal(",".to_string());
values.1.push_normal(",".to_string());
values.0.push_normal(",");
values.1.push_normal(",");
}
values.0.push_normal(")".to_string());
values.1.push_normal(")".to_string());
values.0.push_normal(")");
values.1.push_normal(")");
values
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_errors/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ impl DiagnosticStyledString {
}
pub fn push<S: Into<String>>(&mut self, t: S, highlight: bool) {
if highlight {
self.0.push(StringPart::Highlighted(t.into()));
self.push_highlighted(t);
} else {
self.0.push(StringPart::Normal(t.into()));
self.push_normal(t);
}
}
pub fn normal<S: Into<String>>(t: S) -> DiagnosticStyledString {
Expand Down

0 comments on commit 9d7774c

Please sign in to comment.