2
2
3
3
use std:: ops:: ControlFlow ;
4
4
5
- use chalk_ir:: DebruijnIndex ;
6
5
use hir_def:: {
7
6
AssocItemId , ConstId , CrateRootModuleId , FunctionId , GenericDefId , HasModule , TraitId ,
8
7
TypeAliasId , lang_item:: LangItem , signatures:: TraitFlags ,
@@ -11,23 +10,20 @@ use intern::Symbol;
11
10
use rustc_hash:: FxHashSet ;
12
11
use rustc_type_ir:: {
13
12
AliasTyKind , ClauseKind , PredicatePolarity , TypeSuperVisitable as _, TypeVisitable as _,
14
- Upcast ,
13
+ Upcast , elaborate ,
15
14
inherent:: { IntoKind , SliceLike } ,
16
15
} ;
17
16
use smallvec:: SmallVec ;
18
17
19
18
use crate :: {
20
- ImplTraitId , Interner , TyKind , WhereClause , all_super_traits,
19
+ ImplTraitId , all_super_traits,
21
20
db:: { HirDatabase , InternedOpaqueTyId } ,
22
- from_chalk_trait_id,
23
- generics:: trait_self_param_idx,
24
21
lower_nextsolver:: associated_ty_item_bounds,
25
22
next_solver:: {
26
23
Clause , Clauses , DbInterner , GenericArgs , ParamEnv , SolverDefId , TraitPredicate ,
27
24
TypingMode , infer:: DbInternerInferExt , mk_param,
28
25
} ,
29
26
traits:: next_trait_solve_in_ctxt,
30
- utils:: elaborate_clause_supertraits,
31
27
} ;
32
28
33
29
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
@@ -133,27 +129,23 @@ pub fn generics_require_sized_self(db: &dyn HirDatabase, def: GenericDefId) -> b
133
129
return false ;
134
130
} ;
135
131
136
- let Some ( trait_self_param_idx) = trait_self_param_idx ( db, def) else {
137
- return false ;
138
- } ;
139
-
140
- let predicates = & * db. generic_predicates ( def) ;
141
- let predicates = predicates. iter ( ) . map ( |p| p. skip_binders ( ) . skip_binders ( ) . clone ( ) ) ;
142
- elaborate_clause_supertraits ( db, predicates) . any ( |pred| match pred {
143
- WhereClause :: Implemented ( trait_ref) => {
144
- if from_chalk_trait_id ( trait_ref. trait_id ) == sized
145
- && let TyKind :: BoundVar ( it) =
146
- * trait_ref. self_type_parameter ( Interner ) . kind ( Interner )
147
- {
148
- // Since `generic_predicates` is `Binder<Binder<..>>`, the `DebrujinIndex` of
149
- // self-parameter is `1`
150
- return it
151
- . index_if_bound_at ( DebruijnIndex :: ONE )
152
- . is_some_and ( |idx| idx == trait_self_param_idx) ;
132
+ let interner = DbInterner :: new_with ( db, Some ( krate) , None ) ;
133
+ let predicates = db. generic_predicates_ns ( def) ;
134
+ elaborate:: elaborate ( interner, predicates. iter ( ) . copied ( ) ) . any ( |pred| {
135
+ match pred. kind ( ) . skip_binder ( ) {
136
+ ClauseKind :: Trait ( trait_pred) => {
137
+ if SolverDefId :: TraitId ( sized) == trait_pred. def_id ( )
138
+ && let rustc_type_ir:: TyKind :: Param ( param_ty) =
139
+ trait_pred. trait_ref . self_ty ( ) . kind ( )
140
+ && param_ty. index == 0
141
+ {
142
+ true
143
+ } else {
144
+ false
145
+ }
153
146
}
154
- false
147
+ _ => false ,
155
148
}
156
- _ => false ,
157
149
} )
158
150
}
159
151
0 commit comments