about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-02-22 14:57:59 +0100
committerGitHub <noreply@github.com>2019-02-22 14:57:59 +0100
commit894141b57d5a0072eee07a4918db32bfc187e5bb (patch)
treec4d035a6888bf9969e1e22c69a821faa1f7557fc /src
parent70cc6c980cb4540d05a628f492d365ae422fa22f (diff)
parentf753d304c6c5d7f2c10147d783d58db7db4ffc4c (diff)
downloadrust-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')
-rw-r--r--src/libsyntax/parse/parser.rs17
-rw-r--r--src/test/ui/parser/trait-object-lifetime-parens.stderr8
2 files changed, 19 insertions, 6 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()?;
diff --git a/src/test/ui/parser/trait-object-lifetime-parens.stderr b/src/test/ui/parser/trait-object-lifetime-parens.stderr
index a9b542ddcc4..94ca66aef72 100644
--- a/src/test/ui/parser/trait-object-lifetime-parens.stderr
+++ b/src/test/ui/parser/trait-object-lifetime-parens.stderr
@@ -1,14 +1,14 @@
 error: parenthesized lifetime bounds are not supported
-  --> $DIR/trait-object-lifetime-parens.rs:5:24
+  --> $DIR/trait-object-lifetime-parens.rs:5:21
    |
 LL | fn f<'a, T: Trait + ('a)>() {} //~ ERROR parenthesized lifetime bounds are not supported
-   |                        ^
+   |                     ^^^^ help: remove the parentheses
 
 error: parenthesized lifetime bounds are not supported
-  --> $DIR/trait-object-lifetime-parens.rs:8:27
+  --> $DIR/trait-object-lifetime-parens.rs:8:24
    |
 LL |     let _: Box<Trait + ('a)>; //~ ERROR parenthesized lifetime bounds are not supported
-   |                           ^
+   |                        ^^^^ help: remove the parentheses
 
 error: expected type, found `'a`
   --> $DIR/trait-object-lifetime-parens.rs:9:17