avoid many &str to String conversions with MultiSpan::push_span_label

This commit is contained in:
Takayuki Maeda 2022-06-29 21:16:43 +09:00
parent 0e1a6fb463
commit 6212e6b339
17 changed files with 38 additions and 66 deletions

View file

@ -2561,7 +2561,7 @@ fn show_candidates(
let span = source_span[local_def_id];
let span = session.source_map().guess_head_span(span);
let mut multi_span = MultiSpan::from_span(span);
multi_span.push_span_label(span, "not accessible".to_string());
multi_span.push_span_label(span, "not accessible");
err.span_note(multi_span, &msg);
} else {
err.note(&msg);

View file

@ -601,10 +601,8 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
};
multi_span.push_span_label(sp, msg);
}
multi_span.push_span_label(
base_error.span,
"expected this type to be a trait...".to_string(),
);
multi_span
.push_span_label(base_error.span, "expected this type to be a trait...");
err.span_help(
multi_span,
"`+` is used to constrain a \"trait object\" type with lifetimes or \
@ -1227,17 +1225,14 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
let mut m: MultiSpan = non_visible_spans.clone().into();
non_visible_spans
.into_iter()
.for_each(|s| m.push_span_label(s, "private field".to_string()));
.for_each(|s| m.push_span_label(s, "private field"));
err.span_note(m, "constructor is not visible here due to private fields");
}
return true;
}
err.span_label(
span,
"constructor is not visible here due to private fields".to_string(),
);
err.span_label(span, "constructor is not visible here due to private fields");
}
(
Res::Def(