File tree Expand file tree Collapse file tree 1 file changed +30
-1
lines changed Expand file tree Collapse file tree 1 file changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -363,11 +363,40 @@ fn validate_trait_object_ty(ty: ast::DynTraitType) -> Option<SyntaxError> {
363
363
}
364
364
365
365
fn validate_impl_object_ty ( ty : ast:: ImplTraitType , errors : & mut Vec < SyntaxError > ) {
366
- if ty . type_bound_list ( ) . map_or ( 0 , |tbl| tbl . bounds ( ) . count ( ) ) == 0 {
366
+ let Some ( bound_list ) = ty . type_bound_list ( ) else {
367
367
errors. push ( SyntaxError :: new (
368
368
"At least one trait must be specified" ,
369
369
ty. syntax ( ) . text_range ( ) ,
370
370
) ) ;
371
+ return ;
372
+ } ;
373
+
374
+ let bounds: Vec < _ > = bound_list. bounds ( ) . collect ( ) ;
375
+
376
+ if !bounds. iter ( ) . any ( |b| !matches ! ( b. kind( ) , ast:: TypeBoundKind :: Lifetime ( _) ) ) {
377
+ errors. push ( SyntaxError :: new (
378
+ "At least one trait must be specified" ,
379
+ ty. syntax ( ) . text_range ( ) ,
380
+ ) ) ;
381
+ return ;
382
+ }
383
+
384
+ if bounds. len ( ) == 1 {
385
+ return ;
386
+ }
387
+
388
+ let Some ( preceding_token) = ty
389
+ . impl_token ( )
390
+ . and_then ( |token| token. prev_token ( ) )
391
+ . and_then ( |prev| algo:: skip_trivia_token ( prev, Direction :: Prev ) )
392
+ else {
393
+ return ;
394
+ } ;
395
+
396
+ if !matches ! ( preceding_token. kind( ) , T ![ '(' ] | T ![ <] | T ![ =] )
397
+ && matches ! ( preceding_token. kind( ) , T ![ & ] )
398
+ {
399
+ errors. push ( SyntaxError :: new ( "ambiguous `+` in a type" , ty. syntax ( ) . text_range ( ) ) ) ;
371
400
}
372
401
}
373
402
You can’t perform that action at this time.
0 commit comments