1
Fork 0

Keep better fix suggestion if type ascription is likely unintended

This commit is contained in:
David Ross 2020-02-15 16:18:50 -08:00
parent 4fc0532269
commit 0cf204930a

View file

@ -665,17 +665,23 @@ impl<'a> Parser<'a> {
); );
let mut err = self.struct_span_err(span, &msg); let mut err = self.struct_span_err(span, &msg);
let suggestion = "try surrounding the expression in parentheses"; let suggestion = "try surrounding the expression in parentheses";
if let Ok(expr_str) = expr_str { // if type ascription is "likely an error", the user will already be getting a useful
err.span_suggestion( // help message, and doesn't need a second.
span, if self.last_type_ascription.map_or(false, |last_ascription| last_ascription.1) {
suggestion, self.maybe_annotate_with_ascription(&mut err, false);
format!("({})", expr_str),
Applicability::MachineApplicable,
)
} else { } else {
err.span_help(span, suggestion) if let Ok(expr_str) = expr_str {
err.span_suggestion(
span,
suggestion,
format!("({})", expr_str),
Applicability::MachineApplicable,
);
} else {
err.span_help(span, suggestion);
}
} }
.emit(); err.emit();
}; };
Ok(with_postfix) Ok(with_postfix)
} }