File tree Expand file tree Collapse file tree 2 files changed +19
-6
lines changed Expand file tree Collapse file tree 2 files changed +19
-6
lines changed Original file line number Diff line number Diff line change @@ -5371,6 +5371,7 @@ impl<'a> Parser<'a> {
53715371 if is_bound_start {
53725372 let lo = self . span ;
53735373 let has_parens = self . eat ( & token:: OpenDelim ( token:: Paren ) ) ;
5374+ let inner_lo = self . span ;
53745375 let question = if self . eat ( & token:: Question ) { Some ( self . prev_span ) } else { None } ;
53755376 if self . token . is_lifetime ( ) {
53765377 if let Some ( question_span) = question {
@@ -5379,9 +5380,21 @@ impl<'a> Parser<'a> {
53795380 }
53805381 bounds. push ( GenericBound :: Outlives ( self . expect_lifetime ( ) ) ) ;
53815382 if has_parens {
5383+ let inner_span = inner_lo. to ( self . prev_span ) ;
53825384 self . expect ( & token:: CloseDelim ( token:: Paren ) ) ?;
5383- self . span_err ( self . prev_span ,
5384- "parenthesized lifetime bounds are not supported" ) ;
5385+ let mut err = self . struct_span_err (
5386+ lo. to ( self . prev_span ) ,
5387+ "parenthesized lifetime bounds are not supported"
5388+ ) ;
5389+ if let Ok ( snippet) = self . sess . source_map ( ) . span_to_snippet ( inner_span) {
5390+ err. span_suggestion_short (
5391+ lo. to ( self . prev_span ) ,
5392+ "remove the parentheses" ,
5393+ snippet. to_owned ( ) ,
5394+ Applicability :: MachineApplicable
5395+ ) ;
5396+ }
5397+ err. emit ( ) ;
53855398 }
53865399 } else {
53875400 let lifetime_defs = self . parse_late_bound_lifetime_defs ( ) ?;
Original file line number Diff line number Diff line change 11error: parenthesized lifetime bounds are not supported
2- --> $DIR/trait-object-lifetime-parens.rs:5:24
2+ --> $DIR/trait-object-lifetime-parens.rs:5:21
33 |
44LL | fn f<'a, T: Trait + ('a)>() {} //~ ERROR parenthesized lifetime bounds are not supported
5- | ^
5+ | ^^^^ help: remove the parentheses
66
77error: parenthesized lifetime bounds are not supported
8- --> $DIR/trait-object-lifetime-parens.rs:8:27
8+ --> $DIR/trait-object-lifetime-parens.rs:8:24
99 |
1010LL | let _: Box<Trait + ('a)>; //~ ERROR parenthesized lifetime bounds are not supported
11- | ^
11+ | ^^^^ help: remove the parentheses
1212
1313error: expected type, found `'a`
1414 --> $DIR/trait-object-lifetime-parens.rs:9:17
You can’t perform that action at this time.
0 commit comments