diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-02-22 14:57:59 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-02-22 14:57:59 +0100 |
| commit | 894141b57d5a0072eee07a4918db32bfc187e5bb (patch) | |
| tree | c4d035a6888bf9969e1e22c69a821faa1f7557fc /src/libsyntax/parse | |
| parent | 70cc6c980cb4540d05a628f492d365ae422fa22f (diff) | |
| parent | f753d304c6c5d7f2c10147d783d58db7db4ffc4c (diff) | |
| download | rust-894141b57d5a0072eee07a4918db32bfc187e5bb.tar.gz rust-894141b57d5a0072eee07a4918db32bfc187e5bb.zip | |
Rollup merge of #58198 - igorsdv:suggest-removing-parentheses-surrounding-lifetimes, r=estebank
Suggest removing parentheses surrounding lifetimes Fixes #57386. r? @estebank
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index b1fb38d8eaf..e6a48912c48 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -5503,6 +5503,7 @@ impl<'a> Parser<'a> { if is_bound_start { let lo = self.span; let has_parens = self.eat(&token::OpenDelim(token::Paren)); + let inner_lo = self.span; let question = if self.eat(&token::Question) { Some(self.prev_span) } else { None }; if self.token.is_lifetime() { if let Some(question_span) = question { @@ -5511,9 +5512,21 @@ impl<'a> Parser<'a> { } bounds.push(GenericBound::Outlives(self.expect_lifetime())); if has_parens { + let inner_span = inner_lo.to(self.prev_span); self.expect(&token::CloseDelim(token::Paren))?; - self.span_err(self.prev_span, - "parenthesized lifetime bounds are not supported"); + let mut err = self.struct_span_err( + lo.to(self.prev_span), + "parenthesized lifetime bounds are not supported" + ); + if let Ok(snippet) = self.sess.source_map().span_to_snippet(inner_span) { + err.span_suggestion_short( + lo.to(self.prev_span), + "remove the parentheses", + snippet.to_owned(), + Applicability::MachineApplicable + ); + } + err.emit(); } } else { let lifetime_defs = self.parse_late_bound_lifetime_defs()?; |
