From 9ff0f3374882275b8c6b321f94b14440454f8340 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 15 Oct 2018 13:16:05 +0200 Subject: [PATCH] Pass suggestions as impl Iterator instead of Vec --- src/librustc_errors/diagnostic.rs | 6 +++--- src/librustc_errors/diagnostic_builder.rs | 2 +- src/librustc_resolve/lib.rs | 2 +- src/librustc_typeck/check/demand.rs | 2 +- src/librustc_typeck/check/method/suggest.rs | 2 +- src/librustc_typeck/check/mod.rs | 6 +++--- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/librustc_errors/diagnostic.rs b/src/librustc_errors/diagnostic.rs index 870eeadc081e..a323282f2335 100644 --- a/src/librustc_errors/diagnostic.rs +++ b/src/librustc_errors/diagnostic.rs @@ -350,10 +350,10 @@ impl Diagnostic { } pub fn span_suggestions_with_applicability(&mut self, sp: Span, msg: &str, - suggestions: Vec, - applicability: Applicability) -> &mut Self { + suggestions: impl Iterator, 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, diff --git a/src/librustc_errors/diagnostic_builder.rs b/src/librustc_errors/diagnostic_builder.rs index f4289ea2d4b2..2f16470530e4 100644 --- a/src/librustc_errors/diagnostic_builder.rs +++ b/src/librustc_errors/diagnostic_builder.rs @@ -253,7 +253,7 @@ impl<'a> DiagnosticBuilder<'a> { pub fn span_suggestions_with_applicability(&mut self, sp: Span, msg: &str, - suggestions: Vec, + suggestions: impl Iterator, applicability: Applicability) -> &mut Self { if !self.allow_suggestions { diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index ebd87e87ff60..5b10d4341779 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -4944,7 +4944,7 @@ fn show_candidates(err: &mut DiagnosticBuilder, err.span_suggestions_with_applicability( span, &msg, - path_strings, + path_strings.into_iter(), Applicability::Unspecified, ); } else { diff --git a/src/librustc_typeck/check/demand.rs b/src/librustc_typeck/check/demand.rs index 7773e2d57084..0a196834cb49 100644 --- a/src/librustc_typeck/check/demand.rs +++ b/src/librustc_typeck/check/demand.rs @@ -132,7 +132,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { 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::>(); + .map(|v| format!("{}({})", v, expr_text)); err.span_suggestions_with_applicability( expr.span, "try using a variant of the expected type", diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 5a63a2971e49..cd243d414439 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -521,7 +521,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { with_crate_prefix(|| self.tcx.item_path_str(*did)), additional_newline ) - }).collect(); + }); err.span_suggestions_with_applicability( span, diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 4851938653b5..17784a4681d0 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -4744,7 +4744,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } 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) { @@ -4760,8 +4760,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { Some(format!("{}{}", receiver, method_call)) } } - }).collect::>(); - if !suggestions.is_empty() { + }).peekable(); + if suggestions.peek().is_some() { err.span_suggestions_with_applicability( expr.span, "try using a conversion method",