@@ -581,11 +581,28 @@ impl<'a> TyLoweringContext<'a> {
581581 match bound {
582582 & TypeBound :: Path ( path, TraitBoundModifier :: None ) | & TypeBound :: ForLifetime ( _, path) => {
583583 // FIXME Don't silently drop the hrtb lifetimes here
584- if let Some ( ( trait_ref, ctx) ) = self . lower_trait_ref_from_path ( path, self_ty) {
585- if !ignore_bindings {
586- assoc_bounds = ctx. assoc_type_bindings_from_type_bound ( trait_ref. clone ( ) ) ;
584+ if let Some ( ( trait_ref, mut ctx) ) =
585+ self . lower_trait_ref_from_path ( path, self_ty. clone ( ) )
586+ {
587+ // FIXME(sized-hierarchy): Remove this bound modifications once we have implemented
588+ // sized-hierarchy correctly.
589+ let meta_sized = LangItem :: MetaSized
590+ . resolve_trait ( ctx. ty_ctx ( ) . db , ctx. ty_ctx ( ) . resolver . krate ( ) ) ;
591+ let pointee_sized = LangItem :: PointeeSized
592+ . resolve_trait ( ctx. ty_ctx ( ) . db , ctx. ty_ctx ( ) . resolver . krate ( ) ) ;
593+ if meta_sized. is_some_and ( |it| it == trait_ref. hir_trait_id ( ) ) {
594+ // Ignore this bound
595+ } else if pointee_sized. is_some_and ( |it| it == trait_ref. hir_trait_id ( ) ) {
596+ // Regard this as `?Sized` bound
597+ ctx. ty_ctx ( ) . unsized_types . insert ( self_ty) ;
598+ } else {
599+ if !ignore_bindings {
600+ assoc_bounds =
601+ ctx. assoc_type_bindings_from_type_bound ( trait_ref. clone ( ) ) ;
602+ }
603+ clause =
604+ Some ( crate :: wrap_empty_binders ( WhereClause :: Implemented ( trait_ref) ) ) ;
587605 }
588- clause = Some ( crate :: wrap_empty_binders ( WhereClause :: Implemented ( trait_ref) ) ) ;
589606 }
590607 }
591608 & TypeBound :: Path ( path, TraitBoundModifier :: Maybe ) => {
@@ -945,8 +962,32 @@ pub(crate) fn generic_predicates_for_param_query(
945962 | WherePredicate :: TypeBound { target, bound, .. } => {
946963 let invalid_target = { ctx. lower_ty_only_param ( * target) != Some ( param_id) } ;
947964 if invalid_target {
948- // If this is filtered out without lowering, `?Sized` is not gathered into `ctx.unsized_types`
949- if let TypeBound :: Path ( _, TraitBoundModifier :: Maybe ) = bound {
965+ // FIXME(sized-hierarchy): Revisit and adjust this properly once we have implemented
966+ // sized-hierarchy correctly.
967+ // If this is filtered out without lowering, `?Sized` or `PointeeSized` is not gathered into
968+ // `ctx.unsized_types`
969+ let lower = || -> bool {
970+ match bound {
971+ TypeBound :: Path ( _, TraitBoundModifier :: Maybe ) => true ,
972+ TypeBound :: Path ( path, _) | TypeBound :: ForLifetime ( _, path) => {
973+ let TypeRef :: Path ( path) = & ctx. store [ path. type_ref ( ) ] else {
974+ return false ;
975+ } ;
976+ let Some ( pointee_sized) =
977+ LangItem :: PointeeSized . resolve_trait ( ctx. db , ctx. resolver . krate ( ) )
978+ else {
979+ return false ;
980+ } ;
981+ // Lower the path directly with `Resolver` instead of PathLoweringContext`
982+ // to prevent diagnostics duplications.
983+ ctx. resolver . resolve_path_in_type_ns_fully ( ctx. db , path) . is_some_and (
984+ |it| matches ! ( it, TypeNs :: TraitId ( tr) if tr == pointee_sized) ,
985+ )
986+ }
987+ _ => false ,
988+ }
989+ } ( ) ;
990+ if lower {
950991 ctx. lower_where_predicate ( pred, true ) . for_each ( drop) ;
951992 }
952993 return false ;
0 commit comments