Skip to content

Commit b52cd0b

Browse files
committed
Fix failing tests and fill-in missing details
1 parent 5ef9b2c commit b52cd0b

35 files changed

+845
-1279
lines changed

crates/hir-ty/src/autoderef.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl<'table, 'db> Autoderef<'table, 'db> {
9898
explicit: bool,
9999
use_receiver_trait: bool,
100100
) -> Self {
101-
let ty = table.resolve_ty_shallow(&ty);
101+
let ty = table.structurally_resolve_type(&ty);
102102
Autoderef { table, ty, at_start: true, steps: Vec::new(), explicit, use_receiver_trait }
103103
}
104104

@@ -114,7 +114,7 @@ impl<'table, 'db> Autoderef<'table, 'db, usize> {
114114
explicit: bool,
115115
use_receiver_trait: bool,
116116
) -> Self {
117-
let ty = table.resolve_ty_shallow(&ty);
117+
let ty = table.structurally_resolve_type(&ty);
118118
Autoderef { table, ty, at_start: true, steps: 0, explicit, use_receiver_trait }
119119
}
120120
}
@@ -160,7 +160,7 @@ pub(crate) fn autoderef_step(
160160
use_receiver_trait: bool,
161161
) -> Option<(AutoderefKind, Ty)> {
162162
if let Some(derefed) = builtin_deref(table.db, &ty, explicit) {
163-
Some((AutoderefKind::Builtin, table.resolve_ty_shallow(derefed)))
163+
Some((AutoderefKind::Builtin, table.structurally_resolve_type(derefed)))
164164
} else {
165165
Some((AutoderefKind::Overloaded, deref_by_trait(table, ty, use_receiver_trait)?))
166166
}
@@ -187,7 +187,7 @@ pub(crate) fn deref_by_trait(
187187
use_receiver_trait: bool,
188188
) -> Option<Ty> {
189189
let _p = tracing::info_span!("deref_by_trait").entered();
190-
if table.resolve_ty_shallow(&ty).inference_var(Interner).is_some() {
190+
if table.structurally_resolve_type(&ty).inference_var(Interner).is_some() {
191191
// don't try to deref unknown variables
192192
return None;
193193
}
@@ -232,5 +232,5 @@ pub(crate) fn deref_by_trait(
232232
table.register_obligation(implements_goal);
233233

234234
let result = table.normalize_projection_ty(projection);
235-
Some(table.resolve_ty_shallow(&result))
235+
Some(table.structurally_resolve_type(&result))
236236
}

crates/hir-ty/src/chalk_ext.rs

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -245,26 +245,30 @@ impl TyExt for Ty {
245245
}
246246

247247
fn impl_trait_bounds(&self, db: &dyn HirDatabase) -> Option<Vec<QuantifiedWhereClause>> {
248+
let handle_async_block_type_impl_trait = |def: DefWithBodyId| {
249+
let krate = def.module(db).krate();
250+
if let Some(future_trait) = LangItem::Future.resolve_trait(db, krate) {
251+
// This is only used by type walking.
252+
// Parameters will be walked outside, and projection predicate is not used.
253+
// So just provide the Future trait.
254+
let impl_bound = Binders::empty(
255+
Interner,
256+
WhereClause::Implemented(TraitRef {
257+
trait_id: to_chalk_trait_id(future_trait),
258+
substitution: Substitution::empty(Interner),
259+
}),
260+
);
261+
Some(vec![impl_bound])
262+
} else {
263+
None
264+
}
265+
};
266+
248267
match self.kind(Interner) {
249268
TyKind::OpaqueType(opaque_ty_id, subst) => {
250269
match db.lookup_intern_impl_trait_id((*opaque_ty_id).into()) {
251270
ImplTraitId::AsyncBlockTypeImplTrait(def, _expr) => {
252-
let krate = def.module(db).krate();
253-
if let Some(future_trait) = LangItem::Future.resolve_trait(db, krate) {
254-
// This is only used by type walking.
255-
// Parameters will be walked outside, and projection predicate is not used.
256-
// So just provide the Future trait.
257-
let impl_bound = Binders::empty(
258-
Interner,
259-
WhereClause::Implemented(TraitRef {
260-
trait_id: to_chalk_trait_id(future_trait),
261-
substitution: Substitution::empty(Interner),
262-
}),
263-
);
264-
Some(vec![impl_bound])
265-
} else {
266-
None
267-
}
271+
handle_async_block_type_impl_trait(def)
268272
}
269273
ImplTraitId::ReturnTypeImplTrait(func, idx) => {
270274
db.return_type_impl_traits(func).map(|it| {
@@ -299,8 +303,9 @@ impl TyExt for Ty {
299303
data.substitute(Interner, &opaque_ty.substitution)
300304
})
301305
}
302-
// It always has an parameter for Future::Output type.
303-
ImplTraitId::AsyncBlockTypeImplTrait(..) => unreachable!(),
306+
ImplTraitId::AsyncBlockTypeImplTrait(def, _) => {
307+
return handle_async_block_type_impl_trait(def);
308+
}
304309
};
305310

306311
predicates.map(|it| it.into_value_and_skipped_binders().0)

crates/hir-ty/src/consteval_nextsolver.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::{
2727
next_solver::{
2828
Const, ConstBytes, ConstKind, DbInterner, ErrorGuaranteed, GenericArg, GenericArgs,
2929
ParamConst, SolverDefId, Ty, ValueConst,
30-
mapping::{ChalkToNextSolver, convert_binder_to_early_binder},
30+
mapping::{ChalkToNextSolver, NextSolverToChalk, convert_binder_to_early_binder},
3131
},
3232
};
3333

@@ -145,7 +145,7 @@ pub fn try_const_usize<'db>(db: &'db dyn HirDatabase, c: Const<'db>) -> Option<u
145145
SolverDefId::StaticId(id) => GeneralConstId::StaticId(id),
146146
_ => unreachable!(),
147147
};
148-
let subst = ChalkToNextSolver::from_nextsolver(unevaluated_const.args, interner);
148+
let subst = unevaluated_const.args.to_chalk(interner);
149149
let ec = db.const_eval(c, subst, None).ok()?.to_nextsolver(interner);
150150
try_const_usize(db, ec)
151151
}
@@ -168,7 +168,7 @@ pub fn try_const_isize<'db>(db: &'db dyn HirDatabase, c: &Const<'db>) -> Option<
168168
SolverDefId::StaticId(id) => GeneralConstId::StaticId(id),
169169
_ => unreachable!(),
170170
};
171-
let subst = ChalkToNextSolver::from_nextsolver(unevaluated_const.args, interner);
171+
let subst = unevaluated_const.args.to_chalk(interner);
172172
let ec = db.const_eval(c, subst, None).ok()?.to_nextsolver(interner);
173173
try_const_isize(db, &ec)
174174
}

crates/hir-ty/src/infer.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,7 @@ impl<'db> InferenceContext<'db> {
832832
coercion_casts,
833833
diagnostics: _,
834834
} = &mut result;
835+
table.resolve_obligations_as_possible();
835836
table.fallback_if_possible();
836837

837838
// Comment from rustc:
@@ -1746,7 +1747,7 @@ impl<'db> InferenceContext<'db> {
17461747

17471748
ty = self.table.insert_type_vars(ty);
17481749
ty = self.table.normalize_associated_types_in(ty);
1749-
ty = self.table.resolve_ty_shallow(&ty);
1750+
ty = self.table.structurally_resolve_type(&ty);
17501751
if ty.is_unknown() {
17511752
return (self.err_ty(), None);
17521753
}
@@ -1817,7 +1818,7 @@ impl<'db> InferenceContext<'db> {
18171818
let ty = match ty.kind(Interner) {
18181819
TyKind::Alias(AliasTy::Projection(proj_ty)) => {
18191820
let ty = self.table.normalize_projection_ty(proj_ty.clone());
1820-
self.table.resolve_ty_shallow(&ty)
1821+
self.table.structurally_resolve_type(&ty)
18211822
}
18221823
_ => ty,
18231824
};
@@ -2047,7 +2048,7 @@ impl Expectation {
20472048
fn adjust_for_branches(&self, table: &mut unify::InferenceTable<'_>) -> Expectation {
20482049
match self {
20492050
Expectation::HasType(ety) => {
2050-
let ety = table.resolve_ty_shallow(ety);
2051+
let ety = table.structurally_resolve_type(ety);
20512052
if ety.is_ty_var() { Expectation::None } else { Expectation::HasType(ety) }
20522053
}
20532054
Expectation::RValueLikeUnsized(ety) => Expectation::RValueLikeUnsized(ety.clone()),

crates/hir-ty/src/infer/closure.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,10 @@ impl InferenceContext<'_> {
568568
let supplied_sig = self.supplied_sig_of_closure(body, ret_type, arg_types, closure_kind);
569569

570570
let snapshot = self.table.snapshot();
571-
if !self.table.unify::<_, crate::next_solver::GenericArgs<'_>>(&expected_sig.substitution.0, &supplied_sig.expected_sig.substitution.0) {
571+
if !self.table.unify::<_, crate::next_solver::GenericArgs<'_>>(
572+
&expected_sig.substitution.0,
573+
&supplied_sig.expected_sig.substitution.0,
574+
) {
572575
self.table.rollback_to(snapshot);
573576
}
574577

crates/hir-ty/src/infer/coerce.rs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,21 @@
88
use std::iter;
99

1010
use chalk_ir::{BoundVar, Mutability, TyKind, TyVariableKind, cast::Cast};
11-
use hir_def::{
12-
hir::ExprId,
13-
lang_item::LangItem,
14-
};
11+
use hir_def::{hir::ExprId, lang_item::LangItem};
1512
use rustc_type_ir::solve::Certainty;
1613
use stdx::always;
1714
use triomphe::Arc;
1815

1916
use crate::{
20-
autoderef::{Autoderef, AutoderefKind}, db::HirDatabase, infer::{
17+
Canonical, FnAbi, FnPointer, FnSig, Goal, InEnvironment, Interner, Lifetime, Substitution,
18+
TraitEnvironment, Ty, TyBuilder, TyExt,
19+
autoderef::{Autoderef, AutoderefKind},
20+
db::HirDatabase,
21+
infer::{
2122
Adjust, Adjustment, AutoBorrow, InferOk, InferenceContext, OverloadedDeref, PointerCast,
2223
TypeError, TypeMismatch,
23-
}, utils::ClosureSubst, Canonical, FnAbi, FnPointer, FnSig, Goal, InEnvironment, Interner, Lifetime, Substitution, TraitEnvironment, Ty, TyBuilder, TyExt
24+
},
25+
utils::ClosureSubst,
2426
};
2527

2628
use super::unify::InferenceTable;
@@ -37,11 +39,7 @@ fn simple(kind: Adjust) -> impl FnOnce(Ty) -> Vec<Adjustment> {
3739
}
3840

3941
/// This always returns `Ok(...)`.
40-
fn success(
41-
adj: Vec<Adjustment>,
42-
target: Ty,
43-
goals: Vec<InEnvironment<Goal>>,
44-
) -> CoerceResult {
42+
fn success(adj: Vec<Adjustment>, target: Ty, goals: Vec<InEnvironment<Goal>>) -> CoerceResult {
4543
Ok(InferOk { goals, value: (adj, target) })
4644
}
4745

@@ -285,8 +283,8 @@ impl InferenceTable<'_> {
285283
to_ty: &Ty,
286284
coerce_never: CoerceNever,
287285
) -> Result<(Vec<Adjustment>, Ty), TypeError> {
288-
let from_ty = self.resolve_ty_shallow(from_ty);
289-
let to_ty = self.resolve_ty_shallow(to_ty);
286+
let from_ty = self.structurally_resolve_type(from_ty);
287+
let to_ty = self.structurally_resolve_type(to_ty);
290288
match self.coerce_inner(from_ty, &to_ty, coerce_never) {
291289
Ok(InferOk { value: (adjustments, ty), goals }) => {
292290
self.register_infer_ok(InferOk { value: (), goals });
@@ -302,7 +300,7 @@ impl InferenceTable<'_> {
302300
fn coerce_inner(&mut self, from_ty: Ty, to_ty: &Ty, coerce_never: CoerceNever) -> CoerceResult {
303301
if from_ty.is_never() {
304302
if let TyKind::InferenceVar(tv, TyVariableKind::General) = to_ty.kind(Interner) {
305-
self.set_diverging(*tv, TyVariableKind::General, true);
303+
self.set_diverging(*tv, TyVariableKind::General);
306304
}
307305
if coerce_never == CoerceNever::Yes {
308306
// Subtle: If we are coercing from `!` to `?T`, where `?T` is an unbound
@@ -707,12 +705,9 @@ impl InferenceTable<'_> {
707705

708706
let goal: Goal = coerce_unsized_tref.cast(Interner);
709707

710-
self.commit_if_ok(|table| {
711-
match table.solve_obligation(goal) {
712-
Ok(Certainty::Yes) => Ok(()),
713-
Ok(Certainty::Maybe(_)) => Ok(()),
714-
Err(_) => Err(TypeError),
715-
}
708+
self.commit_if_ok(|table| match table.solve_obligation(goal) {
709+
Ok(Certainty::Yes) => Ok(()),
710+
_ => Err(TypeError),
716711
})?;
717712

718713
let unsize =

0 commit comments

Comments
 (0)