@@ -337,7 +337,8 @@ impl<'a> LoweringContext<'a> {
337337 return self . lower_ty ( ty) ;
338338 }
339339 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) ;
341342 }
342343 TyKind :: ImplicitSelf => {
343344 hir:: TyPath ( hir:: QPath :: Resolved ( None , P ( hir:: Path {
@@ -470,7 +471,8 @@ impl<'a> LoweringContext<'a> {
470471 // Otherwise, the base path is an implicit `Self` type path,
471472 // e.g. `Vec` in `Vec::new` or `<I as Iterator>::Item` in
472473 // `<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) )
474476 } ;
475477
476478 // Anything after the base path are associated "extensions",
@@ -493,7 +495,8 @@ impl<'a> LoweringContext<'a> {
493495 }
494496
495497 // 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) ;
497500 }
498501
499502 // Should've returned in the for loop above.
@@ -2352,12 +2355,33 @@ impl<'a> LoweringContext<'a> {
23522355 self . expr_block ( block, attrs)
23532356 }
23542357
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 } )
23612385 }
23622386
23632387 fn elided_lifetime ( & mut self , span : Span ) -> hir:: Lifetime {
0 commit comments