}
pub fn span_suggestions_with_applicability(&mut self, sp: Span, msg: &str,
- suggestions: Vec<String>,
- applicability: Applicability) -> &mut Self {
+ suggestions: impl Iterator<Item = String>, applicability: Applicability) -> &mut Self
+ {
self.suggestions.push(CodeSuggestion {
- substitutions: suggestions.into_iter().map(|snippet| Substitution {
+ substitutions: suggestions.map(|snippet| Substitution {
parts: vec![SubstitutionPart {
snippet,
span: sp,
pub fn span_suggestions_with_applicability(&mut self,
sp: Span,
msg: &str,
- suggestions: Vec<String>,
+ suggestions: impl Iterator<Item = String>,
applicability: Applicability)
-> &mut Self {
if !self.allow_suggestions {
err.span_suggestions_with_applicability(
span,
&msg,
- path_strings,
+ path_strings.into_iter(),
Applicability::Unspecified,
);
} else {
if compatible_variants.peek().is_some() {
let expr_text = print::to_string(print::NO_ANN, |s| s.print_expr(expr));
let suggestions = compatible_variants
- .map(|v| format!("{}({})", v, expr_text)).collect::<Vec<_>>();
+ .map(|v| format!("{}({})", v, expr_text));
err.span_suggestions_with_applicability(
expr.span,
"try using a variant of the expected type",
with_crate_prefix(|| self.tcx.item_path_str(*did)),
additional_newline
)
- }).collect();
+ });
err.span_suggestions_with_applicability(
span,
} else if !self.check_for_cast(err, expr, found, expected) {
let methods = self.get_conversion_methods(expr.span, expected, found);
if let Ok(expr_text) = self.sess().source_map().span_to_snippet(expr.span) {
- let suggestions = iter::repeat(&expr_text).zip(methods.iter())
+ let mut suggestions = iter::repeat(&expr_text).zip(methods.iter())
.filter_map(|(receiver, method)| {
let method_call = format!(".{}()", method.ident);
if receiver.ends_with(&method_call) {
Some(format!("{}{}", receiver, method_call))
}
}
- }).collect::<Vec<_>>();
- if !suggestions.is_empty() {
+ }).peekable();
+ if suggestions.peek().is_some() {
err.span_suggestions_with_applicability(
expr.span,
"try using a conversion method",