]> git.lizzy.rs Git - rust.git/commitdiff
Pass suggestions as impl Iterator instead of Vec
authorljedrz <ljedrz@gmail.com>
Mon, 15 Oct 2018 11:16:05 +0000 (13:16 +0200)
committerljedrz <ljedrz@gmail.com>
Wed, 31 Oct 2018 12:56:20 +0000 (13:56 +0100)
src/librustc_errors/diagnostic.rs
src/librustc_errors/diagnostic_builder.rs
src/librustc_resolve/lib.rs
src/librustc_typeck/check/demand.rs
src/librustc_typeck/check/method/suggest.rs
src/librustc_typeck/check/mod.rs

index 870eeadc081e76b856087c8d2b84c638eaaed545..a323282f2335325896a68fafa95d3bc2c5bd54b3 100644 (file)
@@ -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,
-                                        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,
index f4289ea2d4b26e59b2d3ac2006edc7212d420b6c..2f16470530e4374581750e89c1f2afef8dc6c4fc 100644 (file)
@@ -253,7 +253,7 @@ pub fn span_suggestion_with_applicability(&mut self,
     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 {
index ebd87e87ff60a4c2a72adefc9073d73ac31b5580..5b10d43417799979ec5d92dd31b0049ca8c0fab2 100644 (file)
@@ -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 {
index 7773e2d570844b892d2157b0941d05580c7e7e26..0a196834cb49442635af0176299d45aa6f90dd80 100644 (file)
@@ -132,7 +132,7 @@ pub fn demand_coerce_diag(&self,
                 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",
index 5a63a2971e49deb7f9f159a1d92cd0075b19b90c..cd243d414439447d978d9559591b346a4c499512 100644 (file)
@@ -521,7 +521,7 @@ fn suggest_use_candidates(&self,
                     with_crate_prefix(|| self.tcx.item_path_str(*did)),
                     additional_newline
                 )
-            }).collect();
+            });
 
             err.span_suggestions_with_applicability(
                                                     span,
index 4851938653b53d33eeebd38b78dd083c3a76234d..17784a4681d009fdf5afce6cdb64dbf01b1294cd 100644 (file)
@@ -4744,7 +4744,7 @@ pub fn suggest_ref_or_into(
         } 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 @@ pub fn suggest_ref_or_into(
                                 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",