Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass suggestions as impl Iterator instead of Vec #55536

Merged
merged 1 commit into from
Nov 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/librustc_errors/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,10 @@ impl Diagnostic {
}

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,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_errors/diagnostic_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ impl<'a> DiagnosticBuilder<'a> {
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 {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>();
.map(|v| format!("{}({})", v, expr_text));
err.span_suggestions_with_applicability(
expr.span,
"try using a variant of the expected type",
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -4760,8 +4760,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
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",
Expand Down