@@ -238,18 +238,7 @@ impl<'a> TyLoweringContext<'a> {
238
238
} )
239
239
. intern ( Interner )
240
240
}
241
- TypeRef :: DynTrait ( bounds) => {
242
- let self_ty =
243
- TyKind :: BoundVar ( BoundVar :: new ( DebruijnIndex :: INNERMOST , 0 ) ) . intern ( Interner ) ;
244
- let bounds = self . with_shifted_in ( DebruijnIndex :: ONE , |ctx| {
245
- QuantifiedWhereClauses :: from_iter (
246
- Interner ,
247
- bounds. iter ( ) . flat_map ( |b| ctx. lower_type_bound ( b, self_ty. clone ( ) , false ) ) ,
248
- )
249
- } ) ;
250
- let bounds = crate :: make_single_type_binders ( bounds) ;
251
- TyKind :: Dyn ( DynTy { bounds, lifetime : static_lifetime ( ) } ) . intern ( Interner )
252
- }
241
+ TypeRef :: DynTrait ( bounds) => self . lower_dyn_trait ( bounds) ,
253
242
TypeRef :: ImplTrait ( bounds) => {
254
243
match self . impl_trait_mode {
255
244
ImplTraitLoweringMode :: Opaque => {
@@ -468,29 +457,10 @@ impl<'a> TyLoweringContext<'a> {
468
457
}
469
458
}
470
459
0 => {
471
- let self_ty = Some (
472
- TyKind :: BoundVar ( BoundVar :: new ( DebruijnIndex :: INNERMOST , 0 ) )
473
- . intern ( Interner ) ,
474
- ) ;
475
- let trait_ref = self . with_shifted_in ( DebruijnIndex :: ONE , |ctx| {
476
- ctx. lower_trait_ref_from_resolved_path (
477
- trait_,
478
- resolved_segment,
479
- self_ty,
480
- )
481
- } ) ;
482
- let dyn_ty = DynTy {
483
- bounds : crate :: make_single_type_binders (
484
- QuantifiedWhereClauses :: from_iter (
485
- Interner ,
486
- Some ( crate :: wrap_empty_binders ( WhereClause :: Implemented (
487
- trait_ref,
488
- ) ) ) ,
489
- ) ,
490
- ) ,
491
- lifetime : static_lifetime ( ) ,
492
- } ;
493
- TyKind :: Dyn ( dyn_ty) . intern ( Interner )
460
+ // Trait object type without dyn; this should be handled in upstream. See
461
+ // `lower_path()`.
462
+ stdx:: never!( "unexpected fully resolved trait path" ) ;
463
+ TyKind :: Error . intern ( Interner )
494
464
}
495
465
_ => {
496
466
// FIXME report error (ambiguous associated type)
@@ -555,11 +525,20 @@ impl<'a> TyLoweringContext<'a> {
555
525
let ( ty, res) = self . lower_ty_ext ( type_ref) ;
556
526
return self . lower_ty_relative_path ( ty, res, path. segments ( ) ) ;
557
527
}
528
+
558
529
let ( resolution, remaining_index) =
559
530
match self . resolver . resolve_path_in_type_ns ( self . db . upcast ( ) , path. mod_path ( ) ) {
560
531
Some ( it) => it,
561
532
None => return ( TyKind :: Error . intern ( Interner ) , None ) ,
562
533
} ;
534
+
535
+ if matches ! ( resolution, TypeNs :: TraitId ( _) ) && remaining_index. is_none ( ) {
536
+ // trait object type without dyn
537
+ let bound = TypeBound :: Path ( path. clone ( ) , TraitBoundModifier :: None ) ;
538
+ let ty = self . lower_dyn_trait ( & [ Interned :: new ( bound) ] ) ;
539
+ return ( ty, None ) ;
540
+ }
541
+
563
542
let ( resolved_segment, remaining_segments) = match remaining_index {
564
543
None => (
565
544
path. segments ( ) . last ( ) . expect ( "resolved path has at least one element" ) ,
@@ -987,6 +966,18 @@ impl<'a> TyLoweringContext<'a> {
987
966
} )
988
967
}
989
968
969
+ fn lower_dyn_trait ( & self , bounds : & [ Interned < TypeBound > ] ) -> Ty {
970
+ let self_ty = TyKind :: BoundVar ( BoundVar :: new ( DebruijnIndex :: INNERMOST , 0 ) ) . intern ( Interner ) ;
971
+ let bounds = self . with_shifted_in ( DebruijnIndex :: ONE , |ctx| {
972
+ QuantifiedWhereClauses :: from_iter (
973
+ Interner ,
974
+ bounds. iter ( ) . flat_map ( |b| ctx. lower_type_bound ( b, self_ty. clone ( ) , false ) ) ,
975
+ )
976
+ } ) ;
977
+ let bounds = crate :: make_single_type_binders ( bounds) ;
978
+ TyKind :: Dyn ( DynTy { bounds, lifetime : static_lifetime ( ) } ) . intern ( Interner )
979
+ }
980
+
990
981
fn lower_impl_trait (
991
982
& self ,
992
983
bounds : & [ Interned < TypeBound > ] ,
0 commit comments