@@ -337,7 +337,8 @@ impl<'a> LoweringContext<'a> {
337
337
return self . lower_ty ( ty) ;
338
338
}
339
339
TyKind :: Path ( ref qself, ref path) => {
340
- hir:: TyPath ( self . lower_qpath ( t. id , qself, path, ParamMode :: Explicit ) )
340
+ let qpath = self . lower_qpath ( t. id , qself, path, ParamMode :: Explicit ) ;
341
+ return self . ty_path ( t. id , t. span , qpath) ;
341
342
}
342
343
TyKind :: ImplicitSelf => {
343
344
hir:: TyPath ( hir:: QPath :: Resolved ( None , P ( hir:: Path {
@@ -470,7 +471,8 @@ impl<'a> LoweringContext<'a> {
470
471
// Otherwise, the base path is an implicit `Self` type path,
471
472
// e.g. `Vec` in `Vec::new` or `<I as Iterator>::Item` in
472
473
// `<I as Iterator>::Item::default`.
473
- self . ty ( p. span , hir:: TyPath ( hir:: QPath :: Resolved ( qself, path) ) )
474
+ let new_id = self . next_id ( ) ;
475
+ self . ty_path ( new_id, p. span , hir:: QPath :: Resolved ( qself, path) )
474
476
} ;
475
477
476
478
// Anything after the base path are associated "extensions",
@@ -493,7 +495,8 @@ impl<'a> LoweringContext<'a> {
493
495
}
494
496
495
497
// Wrap the associated extension in another type node.
496
- ty = self . ty ( p. span , hir:: TyPath ( qpath) ) ;
498
+ let new_id = self . next_id ( ) ;
499
+ ty = self . ty_path ( new_id, p. span , qpath) ;
497
500
}
498
501
499
502
// Should've returned in the for loop above.
@@ -2352,12 +2355,33 @@ impl<'a> LoweringContext<'a> {
2352
2355
self . expr_block ( block, attrs)
2353
2356
}
2354
2357
2355
- fn ty ( & mut self , span : Span , node : hir:: Ty_ ) -> P < hir:: Ty > {
2356
- P ( hir:: Ty {
2357
- id : self . next_id ( ) ,
2358
- node : node,
2359
- span : span,
2360
- } )
2358
+ fn ty_path ( & mut self , id : NodeId , span : Span , qpath : hir:: QPath ) -> P < hir:: Ty > {
2359
+ let mut id = id;
2360
+ let node = match qpath {
2361
+ hir:: QPath :: Resolved ( None , path) => {
2362
+ // Turn trait object paths into `TyTraitObject` instead.
2363
+ if let Def :: Trait ( _) = path. def {
2364
+ let principal = hir:: TraitTyParamBound ( hir:: PolyTraitRef {
2365
+ bound_lifetimes : hir_vec ! [ ] ,
2366
+ trait_ref : hir:: TraitRef {
2367
+ path : path. and_then ( |path| path) ,
2368
+ ref_id : id,
2369
+ } ,
2370
+ span,
2371
+ } , hir:: TraitBoundModifier :: None ) ;
2372
+
2373
+ // The original ID is taken by the `PolyTraitRef`,
2374
+ // so the `Ty` itself needs a different one.
2375
+ id = self . next_id ( ) ;
2376
+
2377
+ hir:: TyTraitObject ( hir_vec ! [ principal] )
2378
+ } else {
2379
+ hir:: TyPath ( hir:: QPath :: Resolved ( None , path) )
2380
+ }
2381
+ }
2382
+ _ => hir:: TyPath ( qpath)
2383
+ } ;
2384
+ P ( hir:: Ty { id, node, span } )
2361
2385
}
2362
2386
2363
2387
fn elided_lifetime ( & mut self , span : Span ) -> hir:: Lifetime {
0 commit comments