@@ -1174,6 +1174,33 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11741174 param_mode : ParamMode ,
11751175 itctx : ImplTraitContext ,
11761176 ) -> hir:: Ty < ' hir > {
1177+ // Check whether we should interpret this as a bare trait object.
1178+ // This check mirrors the one in late resolution. We only introduce this special case in
1179+ // the rare occurence we need to lower `Fresh` anonymous lifetimes.
1180+ // The other cases when a qpath should be opportunistically made a trait object are handled
1181+ // by `ty_path`.
1182+ if qself. is_none ( )
1183+ && let Some ( partial_res) = self . resolver . get_partial_res ( t. id )
1184+ && partial_res. unresolved_segments ( ) == 0
1185+ && let Res :: Def ( DefKind :: Trait | DefKind :: TraitAlias , _) = partial_res. base_res ( )
1186+ {
1187+ let ( bounds, lifetime_bound) = self . with_dyn_type_scope ( true , |this| {
1188+ let bound = this. lower_poly_trait_ref (
1189+ & PolyTraitRef {
1190+ bound_generic_params : vec ! [ ] ,
1191+ trait_ref : TraitRef { path : path. clone ( ) , ref_id : t. id } ,
1192+ span : t. span
1193+ } ,
1194+ itctx,
1195+ ) ;
1196+ let bounds = this. arena . alloc_from_iter ( [ bound] ) ;
1197+ let lifetime_bound = this. elided_dyn_bound ( t. span ) ;
1198+ ( bounds, lifetime_bound)
1199+ } ) ;
1200+ let kind = hir:: TyKind :: TraitObject ( bounds, lifetime_bound, TraitObjectSyntax :: None ) ;
1201+ return hir:: Ty { kind, span : self . lower_span ( t. span ) , hir_id : self . next_id ( ) } ;
1202+ }
1203+
11771204 let id = self . lower_node_id ( t. id ) ;
11781205 let qpath = self . lower_qpath ( t. id , qself, path, param_mode, itctx) ;
11791206 self . ty_path ( id, t. span , qpath)
0 commit comments