File tree 2 files changed +19
-6
lines changed 2 files changed +19
-6
lines changed Original file line number Diff line number Diff line change @@ -5502,6 +5502,7 @@ impl<'a> Parser<'a> {
5502
5502
if is_bound_start {
5503
5503
let lo = self . span ;
5504
5504
let has_parens = self . eat ( & token:: OpenDelim ( token:: Paren ) ) ;
5505
+ let inner_lo = self . span ;
5505
5506
let question = if self . eat ( & token:: Question ) { Some ( self . prev_span ) } else { None } ;
5506
5507
if self . token . is_lifetime ( ) {
5507
5508
if let Some ( question_span) = question {
@@ -5510,9 +5511,21 @@ impl<'a> Parser<'a> {
5510
5511
}
5511
5512
bounds. push ( GenericBound :: Outlives ( self . expect_lifetime ( ) ) ) ;
5512
5513
if has_parens {
5514
+ let inner_span = inner_lo. to ( self . prev_span ) ;
5513
5515
self . expect ( & token:: CloseDelim ( token:: Paren ) ) ?;
5514
- self . span_err ( self . prev_span ,
5515
- "parenthesized lifetime bounds are not supported" ) ;
5516
+ let mut err = self . struct_span_err (
5517
+ lo. to ( self . prev_span ) ,
5518
+ "parenthesized lifetime bounds are not supported"
5519
+ ) ;
5520
+ if let Ok ( snippet) = self . sess . source_map ( ) . span_to_snippet ( inner_span) {
5521
+ err. span_suggestion_short (
5522
+ lo. to ( self . prev_span ) ,
5523
+ "remove the parentheses" ,
5524
+ snippet. to_owned ( ) ,
5525
+ Applicability :: MachineApplicable
5526
+ ) ;
5527
+ }
5528
+ err. emit ( ) ;
5516
5529
}
5517
5530
} else {
5518
5531
let lifetime_defs = self . parse_late_bound_lifetime_defs ( ) ?;
Original file line number Diff line number Diff line change 1
1
error: parenthesized lifetime bounds are not supported
2
- --> $DIR/trait-object-lifetime-parens.rs:5:24
2
+ --> $DIR/trait-object-lifetime-parens.rs:5:21
3
3
|
4
4
LL | fn f<'a, T: Trait + ('a)>() {} //~ ERROR parenthesized lifetime bounds are not supported
5
- | ^
5
+ | ^^^^ help: remove the parentheses
6
6
7
7
error: parenthesized lifetime bounds are not supported
8
- --> $DIR/trait-object-lifetime-parens.rs:8:27
8
+ --> $DIR/trait-object-lifetime-parens.rs:8:24
9
9
|
10
10
LL | let _: Box<Trait + ('a)>; //~ ERROR parenthesized lifetime bounds are not supported
11
- | ^
11
+ | ^^^^ help: remove the parentheses
12
12
13
13
error: expected type, found `'a`
14
14
--> $DIR/trait-object-lifetime-parens.rs:9:17
You can’t perform that action at this time.
0 commit comments