diff options
| author | David Ross <daboross@daboross.net> | 2020-02-15 16:18:50 -0800 |
|---|---|---|
| committer | David Ross <daboross@daboross.net> | 2020-02-15 19:51:02 -0800 |
| commit | 0cf204930a2ecaa5f7416602fca6054d4fd44b6b (patch) | |
| tree | 30f25ef045c2a590885bcb1300e7c1b9c29b53ea /src/librustc_parse/parser/expr.rs | |
| parent | 4fc0532269f40c2870936faaebcdd14539613411 (diff) | |
| download | rust-0cf204930a2ecaa5f7416602fca6054d4fd44b6b.tar.gz rust-0cf204930a2ecaa5f7416602fca6054d4fd44b6b.zip | |
Keep better fix suggestion if type ascription is likely unintended
Diffstat (limited to 'src/librustc_parse/parser/expr.rs')
| -rw-r--r-- | src/librustc_parse/parser/expr.rs | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/librustc_parse/parser/expr.rs b/src/librustc_parse/parser/expr.rs index 645e680d15f..fe5570f26ab 100644 --- a/src/librustc_parse/parser/expr.rs +++ b/src/librustc_parse/parser/expr.rs @@ -665,17 +665,23 @@ impl<'a> Parser<'a> { ); let mut err = self.struct_span_err(span, &msg); let suggestion = "try surrounding the expression in parentheses"; - if let Ok(expr_str) = expr_str { - err.span_suggestion( - span, - suggestion, - format!("({})", expr_str), - Applicability::MachineApplicable, - ) + // if type ascription is "likely an error", the user will already be getting a useful + // help message, and doesn't need a second. + if self.last_type_ascription.map_or(false, |last_ascription| last_ascription.1) { + self.maybe_annotate_with_ascription(&mut err, false); } 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) } |
