mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Add HasInterner bounds
This commit is contained in:
parent
926bfef0ef
commit
7e541e69b1
6 changed files with 35 additions and 14 deletions
|
@ -5,7 +5,10 @@ use chalk_ir::{
|
||||||
interner::HasInterner,
|
interner::HasInterner,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{AliasEq, DomainGoal, GenericArg, GenericArgData, Interner, TraitRef, Ty, WhereClause};
|
use crate::{
|
||||||
|
AliasEq, CallableSig, DomainGoal, GenericArg, GenericArgData, Interner, PolyFnSig,
|
||||||
|
ReturnTypeImplTraits, TraitRef, Ty, WhereClause,
|
||||||
|
};
|
||||||
|
|
||||||
macro_rules! has_interner {
|
macro_rules! has_interner {
|
||||||
($t:ty) => {
|
($t:ty) => {
|
||||||
|
@ -24,3 +27,6 @@ macro_rules! transitive_impl {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
has_interner!(CallableSig);
|
||||||
|
has_interner!(ReturnTypeImplTraits);
|
||||||
|
|
|
@ -2,7 +2,9 @@
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use chalk_ir::{FloatTy, IntTy, TyVariableKind, UniverseIndex, VariableKind};
|
use chalk_ir::{
|
||||||
|
interner::HasInterner, FloatTy, IntTy, TyVariableKind, UniverseIndex, VariableKind,
|
||||||
|
};
|
||||||
use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue};
|
use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue};
|
||||||
|
|
||||||
use super::{DomainGoal, InferenceContext};
|
use super::{DomainGoal, InferenceContext};
|
||||||
|
@ -34,7 +36,10 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(super) struct Canonicalized<T> {
|
pub(super) struct Canonicalized<T>
|
||||||
|
where
|
||||||
|
T: HasInterner<Interner = Interner>,
|
||||||
|
{
|
||||||
pub(super) value: Canonical<T>,
|
pub(super) value: Canonical<T>,
|
||||||
free_vars: Vec<(InferenceVar, TyVariableKind)>,
|
free_vars: Vec<(InferenceVar, TyVariableKind)>,
|
||||||
}
|
}
|
||||||
|
@ -76,7 +81,10 @@ impl<'a, 'b> Canonicalizer<'a, 'b> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn into_canonicalized<T>(self, result: T) -> Canonicalized<T> {
|
fn into_canonicalized<T: HasInterner<Interner = Interner>>(
|
||||||
|
self,
|
||||||
|
result: T,
|
||||||
|
) -> Canonicalized<T> {
|
||||||
let kinds = self
|
let kinds = self
|
||||||
.free_vars
|
.free_vars
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -108,7 +116,7 @@ impl<'a, 'b> Canonicalizer<'a, 'b> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Canonicalized<T> {
|
impl<T: HasInterner<Interner = Interner>> Canonicalized<T> {
|
||||||
pub(super) fn decanonicalize_ty(&self, ty: Ty) -> Ty {
|
pub(super) fn decanonicalize_ty(&self, ty: Ty) -> Ty {
|
||||||
ty.fold_binders(
|
ty.fold_binders(
|
||||||
&mut |ty, binders| {
|
&mut |ty, binders| {
|
||||||
|
|
|
@ -33,7 +33,11 @@ mod test_db;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use base_db::salsa;
|
use base_db::salsa;
|
||||||
use chalk_ir::UintTy;
|
use chalk_ir::{
|
||||||
|
cast::{CastTo, Caster},
|
||||||
|
interner::HasInterner,
|
||||||
|
UintTy,
|
||||||
|
};
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
expr::ExprId, type_ref::Rawness, ConstParamId, LifetimeParamId, TraitId, TypeAliasId,
|
expr::ExprId, type_ref::Rawness, ConstParamId, LifetimeParamId, TraitId, TypeAliasId,
|
||||||
TypeParamId,
|
TypeParamId,
|
||||||
|
@ -115,12 +119,15 @@ pub fn param_idx(db: &dyn HirDatabase, id: TypeParamId) -> Option<usize> {
|
||||||
|
|
||||||
pub fn wrap_empty_binders<T>(value: T) -> Binders<T>
|
pub fn wrap_empty_binders<T>(value: T) -> Binders<T>
|
||||||
where
|
where
|
||||||
T: TypeWalk,
|
T: TypeWalk + HasInterner<Interner = Interner>,
|
||||||
{
|
{
|
||||||
Binders::empty(&Interner, value.shifted_in_from(DebruijnIndex::ONE))
|
Binders::empty(&Interner, value.shifted_in_from(DebruijnIndex::ONE))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn make_only_type_binders<T>(num_vars: usize, value: T) -> Binders<T> {
|
pub fn make_only_type_binders<T: HasInterner<Interner = Interner>>(
|
||||||
|
num_vars: usize,
|
||||||
|
value: T,
|
||||||
|
) -> Binders<T> {
|
||||||
Binders::new(
|
Binders::new(
|
||||||
VariableKinds::from_iter(
|
VariableKinds::from_iter(
|
||||||
&Interner,
|
&Interner,
|
||||||
|
@ -132,7 +139,7 @@ pub fn make_only_type_binders<T>(num_vars: usize, value: T) -> Binders<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: get rid of this
|
// FIXME: get rid of this
|
||||||
pub fn make_canonical<T>(
|
pub fn make_canonical<T: HasInterner<Interner = Interner>>(
|
||||||
value: T,
|
value: T,
|
||||||
kinds: impl IntoIterator<Item = TyVariableKind>,
|
kinds: impl IntoIterator<Item = TyVariableKind>,
|
||||||
) -> Canonical<T> {
|
) -> Canonical<T> {
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
use std::{iter, sync::Arc};
|
use std::{iter, sync::Arc};
|
||||||
|
|
||||||
use base_db::CrateId;
|
use base_db::CrateId;
|
||||||
use chalk_ir::{cast::Cast, Mutability, Safety};
|
use chalk_ir::{cast::Cast, interner::HasInterner, Mutability, Safety};
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
adt::StructKind,
|
adt::StructKind,
|
||||||
builtin_type::BuiltinType,
|
builtin_type::BuiltinType,
|
||||||
|
@ -1307,6 +1307,6 @@ pub(crate) fn lower_to_chalk_mutability(m: hir_def::type_ref::Mutability) -> Mut
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_binders<T>(generics: &Generics, value: T) -> Binders<T> {
|
fn make_binders<T: HasInterner<Interner = Interner>>(generics: &Generics, value: T) -> Binders<T> {
|
||||||
crate::make_only_type_binders(generics.len(), value)
|
crate::make_only_type_binders(generics.len(), value)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ use std::sync::Arc;
|
||||||
|
|
||||||
use log::debug;
|
use log::debug;
|
||||||
|
|
||||||
use chalk_ir::{fold::shift::Shift, CanonicalVarKinds};
|
use chalk_ir::{fold::shift::Shift, interner::HasInterner, CanonicalVarKinds};
|
||||||
use chalk_solve::rust_ir::{self, OpaqueTyDatumBound, WellKnownTrait};
|
use chalk_solve::rust_ir::{self, OpaqueTyDatumBound, WellKnownTrait};
|
||||||
|
|
||||||
use base_db::{salsa::InternKey, CrateId};
|
use base_db::{salsa::InternKey, CrateId};
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
use chalk_ir::DebruijnIndex;
|
use chalk_ir::{interner::HasInterner, DebruijnIndex};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
utils::make_mut_slice, AliasEq, AliasTy, Binders, CallableSig, FnSubst, GenericArg,
|
utils::make_mut_slice, AliasEq, AliasTy, Binders, CallableSig, FnSubst, GenericArg,
|
||||||
|
@ -320,7 +320,7 @@ impl TypeWalk for Substitution {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: TypeWalk> TypeWalk for Binders<T> {
|
impl<T: TypeWalk + HasInterner<Interner = Interner>> TypeWalk for Binders<T> {
|
||||||
fn walk(&self, f: &mut impl FnMut(&Ty)) {
|
fn walk(&self, f: &mut impl FnMut(&Ty)) {
|
||||||
self.skip_binders().walk(f);
|
self.skip_binders().walk(f);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue