提交 9ff0f337 编写于 作者: L ljedrz

Pass suggestions as impl Iterator instead of Vec

上级 0db7abe5
...@@ -350,10 +350,10 @@ pub fn span_suggestion_with_applicability(&mut self, sp: Span, msg: &str, ...@@ -350,10 +350,10 @@ pub fn span_suggestion_with_applicability(&mut self, sp: Span, msg: &str,
} }
pub fn span_suggestions_with_applicability(&mut self, sp: Span, msg: &str, pub fn span_suggestions_with_applicability(&mut self, sp: Span, msg: &str,
suggestions: Vec<String>, suggestions: impl Iterator<Item = String>, applicability: Applicability) -> &mut Self
applicability: Applicability) -> &mut Self { {
self.suggestions.push(CodeSuggestion { self.suggestions.push(CodeSuggestion {
substitutions: suggestions.into_iter().map(|snippet| Substitution { substitutions: suggestions.map(|snippet| Substitution {
parts: vec![SubstitutionPart { parts: vec![SubstitutionPart {
snippet, snippet,
span: sp, span: sp,
......
...@@ -253,7 +253,7 @@ pub fn span_suggestion_with_applicability(&mut self, ...@@ -253,7 +253,7 @@ pub fn span_suggestion_with_applicability(&mut self,
pub fn span_suggestions_with_applicability(&mut self, pub fn span_suggestions_with_applicability(&mut self,
sp: Span, sp: Span,
msg: &str, msg: &str,
suggestions: Vec<String>, suggestions: impl Iterator<Item = String>,
applicability: Applicability) applicability: Applicability)
-> &mut Self { -> &mut Self {
if !self.allow_suggestions { if !self.allow_suggestions {
......
...@@ -4944,7 +4944,7 @@ fn show_candidates(err: &mut DiagnosticBuilder, ...@@ -4944,7 +4944,7 @@ fn show_candidates(err: &mut DiagnosticBuilder,
err.span_suggestions_with_applicability( err.span_suggestions_with_applicability(
span, span,
&msg, &msg,
path_strings, path_strings.into_iter(),
Applicability::Unspecified, Applicability::Unspecified,
); );
} else { } else {
......
...@@ -132,7 +132,7 @@ pub fn demand_coerce_diag(&self, ...@@ -132,7 +132,7 @@ pub fn demand_coerce_diag(&self,
if compatible_variants.peek().is_some() { if compatible_variants.peek().is_some() {
let expr_text = print::to_string(print::NO_ANN, |s| s.print_expr(expr)); let expr_text = print::to_string(print::NO_ANN, |s| s.print_expr(expr));
let suggestions = compatible_variants let suggestions = compatible_variants
.map(|v| format!("{}({})", v, expr_text)).collect::<Vec<_>>(); .map(|v| format!("{}({})", v, expr_text));
err.span_suggestions_with_applicability( err.span_suggestions_with_applicability(
expr.span, expr.span,
"try using a variant of the expected type", "try using a variant of the expected type",
......
...@@ -521,7 +521,7 @@ fn suggest_use_candidates(&self, ...@@ -521,7 +521,7 @@ fn suggest_use_candidates(&self,
with_crate_prefix(|| self.tcx.item_path_str(*did)), with_crate_prefix(|| self.tcx.item_path_str(*did)),
additional_newline additional_newline
) )
}).collect(); });
err.span_suggestions_with_applicability( err.span_suggestions_with_applicability(
span, span,
......
...@@ -4744,7 +4744,7 @@ pub fn suggest_ref_or_into( ...@@ -4744,7 +4744,7 @@ pub fn suggest_ref_or_into(
} else if !self.check_for_cast(err, expr, found, expected) { } else if !self.check_for_cast(err, expr, found, expected) {
let methods = self.get_conversion_methods(expr.span, expected, found); let methods = self.get_conversion_methods(expr.span, expected, found);
if let Ok(expr_text) = self.sess().source_map().span_to_snippet(expr.span) { 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)| { .filter_map(|(receiver, method)| {
let method_call = format!(".{}()", method.ident); let method_call = format!(".{}()", method.ident);
if receiver.ends_with(&method_call) { if receiver.ends_with(&method_call) {
...@@ -4760,8 +4760,8 @@ pub fn suggest_ref_or_into( ...@@ -4760,8 +4760,8 @@ pub fn suggest_ref_or_into(
Some(format!("{}{}", receiver, method_call)) Some(format!("{}{}", receiver, method_call))
} }
} }
}).collect::<Vec<_>>(); }).peekable();
if !suggestions.is_empty() { if suggestions.peek().is_some() {
err.span_suggestions_with_applicability( err.span_suggestions_with_applicability(
expr.span, expr.span,
"try using a conversion method", "try using a conversion method",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册