Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9ff0f33

Browse files
committedOct 31, 2018
Pass suggestions as impl Iterator instead of Vec
1 parent 0db7abe commit 9ff0f33

File tree

6 files changed

+10
-10
lines changed

6 files changed

+10
-10
lines changed
 

‎src/librustc_errors/diagnostic.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,10 @@ impl Diagnostic {
350350
}
351351

352352
pub fn span_suggestions_with_applicability(&mut self, sp: Span, msg: &str,
353-
suggestions: Vec<String>,
354-
applicability: Applicability) -> &mut Self {
353+
suggestions: impl Iterator<Item = String>, applicability: Applicability) -> &mut Self
354+
{
355355
self.suggestions.push(CodeSuggestion {
356-
substitutions: suggestions.into_iter().map(|snippet| Substitution {
356+
substitutions: suggestions.map(|snippet| Substitution {
357357
parts: vec![SubstitutionPart {
358358
snippet,
359359
span: sp,

‎src/librustc_errors/diagnostic_builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ impl<'a> DiagnosticBuilder<'a> {
253253
pub fn span_suggestions_with_applicability(&mut self,
254254
sp: Span,
255255
msg: &str,
256-
suggestions: Vec<String>,
256+
suggestions: impl Iterator<Item = String>,
257257
applicability: Applicability)
258258
-> &mut Self {
259259
if !self.allow_suggestions {

‎src/librustc_resolve/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4944,7 +4944,7 @@ fn show_candidates(err: &mut DiagnosticBuilder,
49444944
err.span_suggestions_with_applicability(
49454945
span,
49464946
&msg,
4947-
path_strings,
4947+
path_strings.into_iter(),
49484948
Applicability::Unspecified,
49494949
);
49504950
} else {

‎src/librustc_typeck/check/demand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
132132
if compatible_variants.peek().is_some() {
133133
let expr_text = print::to_string(print::NO_ANN, |s| s.print_expr(expr));
134134
let suggestions = compatible_variants
135-
.map(|v| format!("{}({})", v, expr_text)).collect::<Vec<_>>();
135+
.map(|v| format!("{}({})", v, expr_text));
136136
err.span_suggestions_with_applicability(
137137
expr.span,
138138
"try using a variant of the expected type",

‎src/librustc_typeck/check/method/suggest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
521521
with_crate_prefix(|| self.tcx.item_path_str(*did)),
522522
additional_newline
523523
)
524-
}).collect();
524+
});
525525

526526
err.span_suggestions_with_applicability(
527527
span,

‎src/librustc_typeck/check/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4744,7 +4744,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
47444744
} else if !self.check_for_cast(err, expr, found, expected) {
47454745
let methods = self.get_conversion_methods(expr.span, expected, found);
47464746
if let Ok(expr_text) = self.sess().source_map().span_to_snippet(expr.span) {
4747-
let suggestions = iter::repeat(&expr_text).zip(methods.iter())
4747+
let mut suggestions = iter::repeat(&expr_text).zip(methods.iter())
47484748
.filter_map(|(receiver, method)| {
47494749
let method_call = format!(".{}()", method.ident);
47504750
if receiver.ends_with(&method_call) {
@@ -4760,8 +4760,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
47604760
Some(format!("{}{}", receiver, method_call))
47614761
}
47624762
}
4763-
}).collect::<Vec<_>>();
4764-
if !suggestions.is_empty() {
4763+
}).peekable();
4764+
if suggestions.peek().is_some() {
47654765
err.span_suggestions_with_applicability(
47664766
expr.span,
47674767
"try using a conversion method",

0 commit comments

Comments
 (0)
Please sign in to comment.