Skip to content

Commit

Permalink
Rollup merge of rust-lang#58198 - igorsdv:suggest-removing-parenthese…
Browse files Browse the repository at this point in the history
…s-surrounding-lifetimes, r=estebank

Suggest removing parentheses surrounding lifetimes

Fixes rust-lang#57386.

r? @estebank
  • Loading branch information
Centril authored Feb 22, 2019
2 parents 82a1763 + f753d30 commit 2b26261
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
17 changes: 15 additions & 2 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()?;
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/parser/trait-object-lifetime-parens.stderr
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 2b26261

Please sign in to comment.