Skip to content

Commit a66ba47

Browse files
committed
Switch generics_require_sized_self to next solver
1 parent 74a9d17 commit a66ba47

File tree

1 file changed

+17
-25
lines changed

1 file changed

+17
-25
lines changed

crates/hir-ty/src/dyn_compatibility.rs

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
33
use std::ops::ControlFlow;
44

5-
use chalk_ir::DebruijnIndex;
65
use hir_def::{
76
AssocItemId, ConstId, CrateRootModuleId, FunctionId, GenericDefId, HasModule, TraitId,
87
TypeAliasId, lang_item::LangItem, signatures::TraitFlags,
@@ -11,23 +10,20 @@ use intern::Symbol;
1110
use rustc_hash::FxHashSet;
1211
use rustc_type_ir::{
1312
AliasTyKind, ClauseKind, PredicatePolarity, TypeSuperVisitable as _, TypeVisitable as _,
14-
Upcast,
13+
Upcast, elaborate,
1514
inherent::{IntoKind, SliceLike},
1615
};
1716
use smallvec::SmallVec;
1817

1918
use crate::{
20-
ImplTraitId, Interner, TyKind, WhereClause, all_super_traits,
19+
ImplTraitId, all_super_traits,
2120
db::{HirDatabase, InternedOpaqueTyId},
22-
from_chalk_trait_id,
23-
generics::trait_self_param_idx,
2421
lower_nextsolver::associated_ty_item_bounds,
2522
next_solver::{
2623
Clause, Clauses, DbInterner, GenericArgs, ParamEnv, SolverDefId, TraitPredicate,
2724
TypingMode, infer::DbInternerInferExt, mk_param,
2825
},
2926
traits::next_trait_solve_in_ctxt,
30-
utils::elaborate_clause_supertraits,
3127
};
3228

3329
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -133,27 +129,23 @@ pub fn generics_require_sized_self(db: &dyn HirDatabase, def: GenericDefId) -> b
133129
return false;
134130
};
135131

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+
}
153146
}
154-
false
147+
_ => false,
155148
}
156-
_ => false,
157149
})
158150
}
159151

0 commit comments

Comments
 (0)