Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir/src/term_search/tactics.rs')
-rw-r--r--crates/hir/src/term_search/tactics.rs87
1 files changed, 48 insertions, 39 deletions
diff --git a/crates/hir/src/term_search/tactics.rs b/crates/hir/src/term_search/tactics.rs
index 67b6fd64c1..2b7f7da3bf 100644
--- a/crates/hir/src/term_search/tactics.rs
+++ b/crates/hir/src/term_search/tactics.rs
@@ -10,18 +10,13 @@
use std::iter;
-use hir_ty::{
- db::HirDatabase,
- mir::BorrowKind,
- next_solver::{DbInterner, Ty},
-};
+use hir_ty::{db::HirDatabase, mir::BorrowKind};
use itertools::Itertools;
use rustc_hash::FxHashSet;
-use rustc_type_ir::inherent::Ty as _;
use crate::{
- Adt, AssocItem, GenericDef, GenericParam, HasAttrs, HasVisibility, Impl, ModuleDef, ScopeDef,
- Type, TypeParam, term_search::Expr,
+ Adt, AssocItem, BuiltinType, GenericDef, GenericParam, HasAttrs, HasVisibility, Impl,
+ ModuleDef, ScopeDef, Type, TypeParam, term_search::Expr,
};
use super::{LookupTable, NewTypesKey, TermSearchCtx};
@@ -87,7 +82,7 @@ pub(super) fn trivial<'a, 'lt, 'db, DB: HirDatabase>(
return None;
}
- ty.could_unify_with_deeply(db, &ctx.goal).then_some(expr)
+ ty.instantiate_with_errors().could_unify_with_deeply(db, &ctx.goal).then_some(expr)
})
}
@@ -137,7 +132,7 @@ pub(super) fn assoc_const<'a, 'lt, 'db, DB: HirDatabase>(
lookup.insert(ty.clone(), std::iter::once(expr.clone()));
- ty.could_unify_with_deeply(db, &ctx.goal).then_some(expr)
+ ty.instantiate_with_errors().could_unify_with_deeply(db, &ctx.goal).then_some(expr)
})
}
@@ -202,7 +197,9 @@ pub(super) fn data_constructor<'a, 'lt, 'db, DB: HirDatabase>(
// Early exit if some param cannot be filled from lookup
let param_exprs: Vec<Vec<Expr<'_>>> = fields
.into_iter()
- .map(|field| lookup.find(db, &field.ty_with_args(db, generics.iter().cloned())))
+ .map(|field| {
+ lookup.find(db, &field.ty(db).instantiate(generics.iter().cloned()))
+ })
.collect::<Option<_>>()?;
// Note that we need special case for 0 param constructors because of multi cartesian
@@ -252,7 +249,7 @@ pub(super) fn data_constructor<'a, 'lt, 'db, DB: HirDatabase>(
.fields(db)
.into_iter()
.map(|field| {
- lookup.find(db, &field.ty_with_args(db, generics.iter().cloned()))
+ lookup.find(db, &field.ty(db).instantiate(generics.iter().cloned()))
})
.collect::<Option<_>>()?;
@@ -285,7 +282,9 @@ pub(super) fn data_constructor<'a, 'lt, 'db, DB: HirDatabase>(
}
Adt::Union(_) => None,
})
- .filter_map(|(ty, exprs)| ty.could_unify_with_deeply(db, &ctx.goal).then_some(exprs))
+ .filter_map(|(ty, exprs)| {
+ ty.instantiate_with_errors().could_unify_with_deeply(db, &ctx.goal).then_some(exprs)
+ })
.flatten()
}
@@ -364,7 +363,7 @@ pub(super) fn free_function<'a, 'lt, 'db, DB: HirDatabase>(
})
.collect::<Option<_>>()?;
- let ret_ty = it.ret_type_with_args(db, generics.iter().cloned());
+ let ret_ty = it.ret_type(db).instantiate(generics.iter().cloned());
// Filter out private and unsafe functions
if !it.is_visible_from(db, module)
|| it.is_unsafe_to_call(
@@ -381,10 +380,10 @@ pub(super) fn free_function<'a, 'lt, 'db, DB: HirDatabase>(
// Early exit if some param cannot be filled from lookup
let param_exprs: Vec<Vec<Expr<'_>>> = it
- .params_without_self_with_args(db, generics.iter().cloned())
+ .params_without_self(db)
.into_iter()
.map(|field| {
- let ty = field.ty();
+ let ty = &field.ty().instantiate(&generics);
match ty.is_mutable_reference() {
true => None,
false => lookup.find_autoref(db, ty),
@@ -418,7 +417,9 @@ pub(super) fn free_function<'a, 'lt, 'db, DB: HirDatabase>(
_ => None,
})
.flatten()
- .filter_map(|(ty, exprs)| ty.could_unify_with_deeply(db, &ctx.goal).then_some(exprs))
+ .filter_map(|(ty, exprs)| {
+ ty.instantiate_with_errors().could_unify_with_deeply(db, &ctx.goal).then_some(exprs)
+ })
.flatten()
}
@@ -493,7 +494,7 @@ pub(super) fn impl_method<'a, 'lt, 'db, DB: HirDatabase>(
return None;
}
- let ret_ty = it.ret_type_with_args(db, ty.type_arguments());
+ let ret_ty = it.ret_type(db).instantiate(ty.type_arguments());
// Filter out functions that return references
if ctx.config.enable_borrowcheck && ret_ty.contains_reference(db) || ret_ty.is_raw_ptr()
{
@@ -501,12 +502,12 @@ pub(super) fn impl_method<'a, 'lt, 'db, DB: HirDatabase>(
}
// Ignore functions that do not change the type
- if ty.could_unify_with_deeply(db, &ret_ty) {
+ if ty.instantiate_with_errors().could_unify_with_deeply(db, &ret_ty) {
return None;
}
let self_ty =
- it.self_param(db).expect("No self param").ty_with_args(db, ty.type_arguments());
+ it.self_param(db).expect("No self param").ty(db).instantiate(ty.type_arguments());
// Ignore functions that have different self type
if !self_ty.autoderef(db).any(|s_ty| ty == s_ty) {
@@ -517,9 +518,9 @@ pub(super) fn impl_method<'a, 'lt, 'db, DB: HirDatabase>(
// Early exit if some param cannot be filled from lookup
let param_exprs: Vec<Vec<Expr<'_>>> = it
- .params_without_self_with_args(db, ty.type_arguments())
+ .params_without_self(db)
.into_iter()
- .map(|field| lookup.find_autoref(db, field.ty()))
+ .map(|field| lookup.find_autoref(db, &field.ty().instantiate(ty.type_arguments())))
.collect::<Option<_>>()?;
let generics: Vec<_> = ty.type_arguments().collect();
@@ -540,7 +541,9 @@ pub(super) fn impl_method<'a, 'lt, 'db, DB: HirDatabase>(
Some((ret_ty, fn_exprs))
})
- .filter_map(|(ty, exprs)| ty.could_unify_with_deeply(db, &ctx.goal).then_some(exprs))
+ .filter_map(|(ty, exprs)| {
+ ty.instantiate_with_errors().could_unify_with_deeply(db, &ctx.goal).then_some(exprs)
+ })
.flatten()
}
@@ -581,7 +584,9 @@ pub(super) fn struct_projection<'a, 'lt, 'db, DB: HirDatabase>(
Some((filed_ty, exprs))
})
})
- .filter_map(|(ty, exprs)| ty.could_unify_with_deeply(db, &ctx.goal).then_some(exprs))
+ .filter_map(|(ty, exprs)| {
+ ty.instantiate_with_errors().could_unify_with_deeply(db, &ctx.goal).then_some(exprs)
+ })
.flatten()
}
@@ -604,20 +609,18 @@ pub(super) fn famous_types<'a, 'lt, 'db, DB: HirDatabase>(
lookup: &'lt mut LookupTable<'db>,
) -> impl Iterator<Item = Expr<'db>> + use<'a, 'db, 'lt, DB> {
let db = ctx.sema.db;
- let module = ctx.scope.module();
- let interner = DbInterner::new_no_crate(db);
- let bool_ty = Ty::new_bool(interner);
- let unit_ty = Ty::new_unit(interner);
+ let bool_ty = BuiltinType::bool().ty(db);
+ let unit_ty = Type::new_unit();
[
- Expr::FamousType { ty: Type::new(db, module.id, bool_ty), value: "true" },
- Expr::FamousType { ty: Type::new(db, module.id, bool_ty), value: "false" },
- Expr::FamousType { ty: Type::new(db, module.id, unit_ty), value: "()" },
+ Expr::FamousType { ty: bool_ty.clone(), value: "true" },
+ Expr::FamousType { ty: bool_ty, value: "false" },
+ Expr::FamousType { ty: unit_ty, value: "()" },
]
.into_iter()
.inspect(|exprs| {
lookup.insert(exprs.ty(db), std::iter::once(exprs.clone()));
})
- .filter(|expr| expr.ty(db).could_unify_with_deeply(db, &ctx.goal))
+ .filter(|expr| expr.ty(db).instantiate_with_errors().could_unify_with_deeply(db, &ctx.goal))
}
/// # Impl static method (without self type) tactic
@@ -691,7 +694,7 @@ pub(super) fn impl_static_method<'a, 'lt, 'db, DB: HirDatabase>(
return None;
}
- let ret_ty = it.ret_type_with_args(db, ty.type_arguments());
+ let ret_ty = it.ret_type(db).instantiate(ty.type_arguments());
// Filter out functions that return references
if ctx.config.enable_borrowcheck && ret_ty.contains_reference(db) || ret_ty.is_raw_ptr()
{
@@ -700,9 +703,9 @@ pub(super) fn impl_static_method<'a, 'lt, 'db, DB: HirDatabase>(
// Early exit if some param cannot be filled from lookup
let param_exprs: Vec<Vec<Expr<'_>>> = it
- .params_without_self_with_args(db, ty.type_arguments())
+ .params_without_self(db)
.into_iter()
- .map(|field| lookup.find_autoref(db, field.ty()))
+ .map(|field| lookup.find_autoref(db, &field.ty().instantiate(ty.type_arguments())))
.collect::<Option<_>>()?;
// Note that we need special case for 0 param constructors because of multi cartesian
@@ -722,7 +725,9 @@ pub(super) fn impl_static_method<'a, 'lt, 'db, DB: HirDatabase>(
Some((ret_ty, fn_exprs))
})
- .filter_map(|(ty, exprs)| ty.could_unify_with_deeply(db, &ctx.goal).then_some(exprs))
+ .filter_map(|(ty, exprs)| {
+ ty.instantiate_with_errors().could_unify_with_deeply(db, &ctx.goal).then_some(exprs)
+ })
.flatten()
}
@@ -745,7 +750,6 @@ pub(super) fn make_tuple<'a, 'lt, 'db, DB: HirDatabase>(
should_continue: &'a dyn std::ops::Fn() -> bool,
) -> impl Iterator<Item = Expr<'db>> + use<'a, 'db, 'lt, DB> {
let db = ctx.sema.db;
- let module = ctx.scope.module();
lookup
.types_wishlist()
@@ -774,7 +778,7 @@ pub(super) fn make_tuple<'a, 'lt, 'db, DB: HirDatabase>(
.filter(|_| should_continue())
.map(|params| {
let tys: Vec<Type<'_>> = params.iter().map(|it| it.ty(db)).collect();
- let tuple_ty = Type::new_tuple(db, module.krate(db).into(), &tys);
+ let tuple_ty = Type::new_tuple(db, &tys);
let expr = Expr::Tuple { ty: tuple_ty.clone(), params };
lookup.insert(tuple_ty, iter::once(expr.clone()));
@@ -785,5 +789,10 @@ pub(super) fn make_tuple<'a, 'lt, 'db, DB: HirDatabase>(
Some(exprs)
})
.flatten()
- .filter_map(|expr| expr.ty(db).could_unify_with_deeply(db, &ctx.goal).then_some(expr))
+ .filter_map(|expr| {
+ expr.ty(db)
+ .instantiate_with_errors()
+ .could_unify_with_deeply(db, &ctx.goal)
+ .then_some(expr)
+ })
}