mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Add chalk_ir::Const to TyKind::Array
This commit is contained in:
parent
047b531301
commit
9fbba7bc45
12 changed files with 109 additions and 45 deletions
|
@ -1888,7 +1888,7 @@ impl Type {
|
||||||
substs.iter(&Interner).filter_map(|a| a.ty(&Interner)).any(go)
|
substs.iter(&Interner).filter_map(|a| a.ty(&Interner)).any(go)
|
||||||
}
|
}
|
||||||
|
|
||||||
TyKind::Array(ty)
|
TyKind::Array(ty, _)
|
||||||
| TyKind::Slice(ty)
|
| TyKind::Slice(ty)
|
||||||
| TyKind::Raw(_, ty)
|
| TyKind::Raw(_, ty)
|
||||||
| TyKind::Ref(_, _, ty) => go(ty),
|
| TyKind::Ref(_, _, ty) => go(ty),
|
||||||
|
@ -2151,7 +2151,7 @@ impl Type {
|
||||||
|
|
||||||
TyKind::Ref(_, _, ty)
|
TyKind::Ref(_, _, ty)
|
||||||
| TyKind::Raw(_, ty)
|
| TyKind::Raw(_, ty)
|
||||||
| TyKind::Array(ty)
|
| TyKind::Array(ty, _)
|
||||||
| TyKind::Slice(ty) => {
|
| TyKind::Slice(ty) => {
|
||||||
walk_type(db, &type_.derived(ty.clone()), cb);
|
walk_type(db, &type_.derived(ty.clone()), cb);
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,6 +88,8 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
|
||||||
#[salsa::interned]
|
#[salsa::interned]
|
||||||
fn intern_lifetime_param_id(&self, param_id: LifetimeParamId) -> InternedLifetimeParamId;
|
fn intern_lifetime_param_id(&self, param_id: LifetimeParamId) -> InternedLifetimeParamId;
|
||||||
#[salsa::interned]
|
#[salsa::interned]
|
||||||
|
fn intern_const_param_id(&self, param_id: ConstParamId) -> InternedConstParamId;
|
||||||
|
#[salsa::interned]
|
||||||
fn intern_impl_trait_id(&self, id: ImplTraitId) -> InternedOpaqueTyId;
|
fn intern_impl_trait_id(&self, id: ImplTraitId) -> InternedOpaqueTyId;
|
||||||
#[salsa::interned]
|
#[salsa::interned]
|
||||||
fn intern_closure(&self, id: (DefWithBodyId, ExprId)) -> InternedClosureId;
|
fn intern_closure(&self, id: (DefWithBodyId, ExprId)) -> InternedClosureId;
|
||||||
|
@ -161,6 +163,10 @@ impl_intern_key!(InternedTypeParamId);
|
||||||
pub struct InternedLifetimeParamId(salsa::InternId);
|
pub struct InternedLifetimeParamId(salsa::InternId);
|
||||||
impl_intern_key!(InternedLifetimeParamId);
|
impl_intern_key!(InternedLifetimeParamId);
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
|
pub struct InternedConstParamId(salsa::InternId);
|
||||||
|
impl_intern_key!(InternedConstParamId);
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub struct InternedOpaqueTyId(salsa::InternId);
|
pub struct InternedOpaqueTyId(salsa::InternId);
|
||||||
impl_intern_key!(InternedOpaqueTyId);
|
impl_intern_key!(InternedOpaqueTyId);
|
||||||
|
|
|
@ -5,6 +5,7 @@ use std::{
|
||||||
fmt::{self, Debug},
|
fmt::{self, Debug},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use chalk_ir::BoundVar;
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
db::DefDatabase,
|
db::DefDatabase,
|
||||||
find_path,
|
find_path,
|
||||||
|
@ -18,12 +19,12 @@ use hir_def::{
|
||||||
use hir_expand::name::Name;
|
use hir_expand::name::Name;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
db::HirDatabase, from_assoc_type_id, from_foreign_def_id, from_placeholder_idx,
|
const_from_placeholder_idx, db::HirDatabase, from_assoc_type_id, from_foreign_def_id,
|
||||||
lt_from_placeholder_idx, primitive, subst_prefix, to_assoc_type_id, traits::chalk::from_chalk,
|
from_placeholder_idx, lt_from_placeholder_idx, primitive, subst_prefix, to_assoc_type_id,
|
||||||
utils::generics, AdtId, AliasEq, AliasTy, CallableDefId, CallableSig, DomainGoal, GenericArg,
|
traits::chalk::from_chalk, utils::generics, AdtId, AliasEq, AliasTy, CallableDefId,
|
||||||
ImplTraitId, Interner, Lifetime, LifetimeData, LifetimeOutlives, Mutability, OpaqueTy,
|
CallableSig, Const, ConstValue, DomainGoal, GenericArg, ImplTraitId, Interner, Lifetime,
|
||||||
ProjectionTy, ProjectionTyExt, QuantifiedWhereClause, Scalar, TraitRef, Ty, TyExt, TyKind,
|
LifetimeData, LifetimeOutlives, Mutability, OpaqueTy, ProjectionTy, ProjectionTyExt,
|
||||||
WhereClause,
|
QuantifiedWhereClause, Scalar, TraitRef, Ty, TyExt, TyKind, WhereClause,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct HirFormatter<'a> {
|
pub struct HirFormatter<'a> {
|
||||||
|
@ -290,6 +291,29 @@ impl HirDisplay for GenericArg {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl HirDisplay for Const {
|
||||||
|
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
|
||||||
|
let data = self.interned();
|
||||||
|
match data.value {
|
||||||
|
ConstValue::BoundVar(idx) => idx.hir_fmt(f),
|
||||||
|
ConstValue::InferenceVar(..) => write!(f, "_"),
|
||||||
|
ConstValue::Placeholder(idx) => {
|
||||||
|
let id = const_from_placeholder_idx(f.db, idx);
|
||||||
|
let generics = generics(f.db.upcast(), id.parent);
|
||||||
|
let param_data = &generics.params.consts[id.local_id];
|
||||||
|
write!(f, "{}", param_data.name)
|
||||||
|
}
|
||||||
|
ConstValue::Concrete(_) => write!(f, "_"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl HirDisplay for BoundVar {
|
||||||
|
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
|
||||||
|
write!(f, "?{}.{}", self.debruijn.depth(), self.index)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl HirDisplay for Ty {
|
impl HirDisplay for Ty {
|
||||||
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
|
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
|
||||||
if f.should_truncate() {
|
if f.should_truncate() {
|
||||||
|
@ -309,10 +333,12 @@ impl HirDisplay for Ty {
|
||||||
t.hir_fmt(f)?;
|
t.hir_fmt(f)?;
|
||||||
write!(f, "]")?;
|
write!(f, "]")?;
|
||||||
}
|
}
|
||||||
TyKind::Array(t) => {
|
TyKind::Array(t, c) => {
|
||||||
write!(f, "[")?;
|
write!(f, "[")?;
|
||||||
t.hir_fmt(f)?;
|
t.hir_fmt(f)?;
|
||||||
write!(f, "; _]")?;
|
write!(f, "; ")?;
|
||||||
|
c.hir_fmt(f)?;
|
||||||
|
write!(f, "]")?;
|
||||||
}
|
}
|
||||||
TyKind::Raw(m, t) | TyKind::Ref(m, _, t) => {
|
TyKind::Raw(m, t) | TyKind::Ref(m, _, t) => {
|
||||||
let ty_display =
|
let ty_display =
|
||||||
|
@ -617,7 +643,7 @@ impl HirDisplay for Ty {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TyKind::BoundVar(idx) => write!(f, "?{}.{}", idx.debruijn.depth(), idx.index)?,
|
TyKind::BoundVar(idx) => idx.hir_fmt(f)?,
|
||||||
TyKind::Dyn(dyn_ty) => {
|
TyKind::Dyn(dyn_ty) => {
|
||||||
write_bounds_like_dyn_trait_with_prefix(
|
write_bounds_like_dyn_trait_with_prefix(
|
||||||
"dyn",
|
"dyn",
|
||||||
|
@ -850,7 +876,7 @@ impl HirDisplay for Lifetime {
|
||||||
impl HirDisplay for LifetimeData {
|
impl HirDisplay for LifetimeData {
|
||||||
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
|
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
|
||||||
match self {
|
match self {
|
||||||
LifetimeData::BoundVar(idx) => write!(f, "?{}.{}", idx.debruijn.depth(), idx.index),
|
LifetimeData::BoundVar(idx) => idx.hir_fmt(f),
|
||||||
LifetimeData::InferenceVar(_) => write!(f, "_"),
|
LifetimeData::InferenceVar(_) => write!(f, "_"),
|
||||||
LifetimeData::Placeholder(idx) => {
|
LifetimeData::Placeholder(idx) => {
|
||||||
let id = lt_from_placeholder_idx(f.db, *idx);
|
let id = lt_from_placeholder_idx(f.db, *idx);
|
||||||
|
|
|
@ -15,7 +15,7 @@ use stdx::always;
|
||||||
use syntax::ast::RangeOp;
|
use syntax::ast::RangeOp;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
autoderef,
|
autoderef, dummy_usize_const,
|
||||||
lower::lower_to_chalk_mutability,
|
lower::lower_to_chalk_mutability,
|
||||||
method_resolution, op,
|
method_resolution, op,
|
||||||
primitive::{self, UintTy},
|
primitive::{self, UintTy},
|
||||||
|
@ -702,7 +702,7 @@ impl<'a> InferenceContext<'a> {
|
||||||
}
|
}
|
||||||
Expr::Array(array) => {
|
Expr::Array(array) => {
|
||||||
let elem_ty = match expected.ty.kind(&Interner) {
|
let elem_ty = match expected.ty.kind(&Interner) {
|
||||||
TyKind::Array(st) | TyKind::Slice(st) => st.clone(),
|
TyKind::Array(st, _) | TyKind::Slice(st) => st.clone(),
|
||||||
_ => self.table.new_type_var(),
|
_ => self.table.new_type_var(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -726,7 +726,7 @@ impl<'a> InferenceContext<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TyKind::Array(elem_ty).intern(&Interner)
|
TyKind::Array(elem_ty, dummy_usize_const()).intern(&Interner)
|
||||||
}
|
}
|
||||||
Expr::Literal(lit) => match lit {
|
Expr::Literal(lit) => match lit {
|
||||||
Literal::Bool(..) => TyKind::Scalar(Scalar::Bool).intern(&Interner),
|
Literal::Bool(..) => TyKind::Scalar(Scalar::Bool).intern(&Interner),
|
||||||
|
@ -736,7 +736,8 @@ impl<'a> InferenceContext<'a> {
|
||||||
}
|
}
|
||||||
Literal::ByteString(..) => {
|
Literal::ByteString(..) => {
|
||||||
let byte_type = TyKind::Scalar(Scalar::Uint(UintTy::U8)).intern(&Interner);
|
let byte_type = TyKind::Scalar(Scalar::Uint(UintTy::U8)).intern(&Interner);
|
||||||
let array_type = TyKind::Array(byte_type).intern(&Interner);
|
let array_type =
|
||||||
|
TyKind::Array(byte_type, dummy_usize_const()).intern(&Interner);
|
||||||
TyKind::Ref(Mutability::Not, static_lifetime(), array_type).intern(&Interner)
|
TyKind::Ref(Mutability::Not, static_lifetime(), array_type).intern(&Interner)
|
||||||
}
|
}
|
||||||
Literal::Char(..) => TyKind::Scalar(Scalar::Char).intern(&Interner),
|
Literal::Char(..) => TyKind::Scalar(Scalar::Char).intern(&Interner),
|
||||||
|
|
|
@ -214,17 +214,20 @@ impl<'a> InferenceContext<'a> {
|
||||||
return inner_ty;
|
return inner_ty;
|
||||||
}
|
}
|
||||||
Pat::Slice { prefix, slice, suffix } => {
|
Pat::Slice { prefix, slice, suffix } => {
|
||||||
let (container_ty, elem_ty): (fn(_) -> _, _) = match expected.kind(&Interner) {
|
let elem_ty = match expected.kind(&Interner) {
|
||||||
TyKind::Array(st) => (TyKind::Array, st.clone()),
|
TyKind::Array(st, _) | TyKind::Slice(st) => st.clone(),
|
||||||
TyKind::Slice(st) => (TyKind::Slice, st.clone()),
|
_ => self.err_ty(),
|
||||||
_ => (TyKind::Slice, self.err_ty()),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
for pat_id in prefix.iter().chain(suffix) {
|
for pat_id in prefix.iter().chain(suffix) {
|
||||||
self.infer_pat(*pat_id, &elem_ty, default_bm);
|
self.infer_pat(*pat_id, &elem_ty, default_bm);
|
||||||
}
|
}
|
||||||
|
|
||||||
let pat_ty = container_ty(elem_ty).intern(&Interner);
|
let pat_ty = match expected.kind(&Interner) {
|
||||||
|
TyKind::Array(_, const_) => TyKind::Array(elem_ty, const_.clone()),
|
||||||
|
_ => TyKind::Slice(elem_ty),
|
||||||
|
}
|
||||||
|
.intern(&Interner);
|
||||||
if let Some(slice_pat_id) = slice {
|
if let Some(slice_pat_id) = slice {
|
||||||
self.infer_pat(*slice_pat_id, &pat_ty, default_bm);
|
self.infer_pat(*slice_pat_id, &pat_ty, default_bm);
|
||||||
}
|
}
|
||||||
|
|
|
@ -317,9 +317,11 @@ impl InferenceTable {
|
||||||
| (TyKind::Closure(.., substs1), TyKind::Closure(.., substs2)) => {
|
| (TyKind::Closure(.., substs1), TyKind::Closure(.., substs2)) => {
|
||||||
self.unify_substs(substs1, substs2, depth + 1)
|
self.unify_substs(substs1, substs2, depth + 1)
|
||||||
}
|
}
|
||||||
|
(TyKind::Array(ty1, c1), TyKind::Array(ty2, c2)) if c1 == c2 => {
|
||||||
|
self.unify_inner(ty1, ty2, depth + 1)
|
||||||
|
}
|
||||||
(TyKind::Ref(_, _, ty1), TyKind::Ref(_, _, ty2))
|
(TyKind::Ref(_, _, ty1), TyKind::Ref(_, _, ty2))
|
||||||
| (TyKind::Raw(_, ty1), TyKind::Raw(_, ty2))
|
| (TyKind::Raw(_, ty1), TyKind::Raw(_, ty2))
|
||||||
| (TyKind::Array(ty1), TyKind::Array(ty2))
|
|
||||||
| (TyKind::Slice(ty1), TyKind::Slice(ty2)) => self.unify_inner(ty1, ty2, depth + 1),
|
| (TyKind::Slice(ty1), TyKind::Slice(ty2)) => self.unify_inner(ty1, ty2, depth + 1),
|
||||||
_ => true, /* we checked equals_ctor already */
|
_ => true, /* we checked equals_ctor already */
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,12 +30,13 @@ mod test_db;
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use chalk_ir::UintTy;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
|
||||||
use base_db::salsa;
|
use base_db::salsa;
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
expr::ExprId, type_ref::Rawness, AssocContainerId, FunctionId, GenericDefId, HasModule,
|
expr::ExprId, type_ref::Rawness, AssocContainerId, ConstParamId, FunctionId, GenericDefId,
|
||||||
LifetimeParamId, Lookup, TraitId, TypeAliasId, TypeParamId,
|
HasModule, LifetimeParamId, Lookup, TraitId, TypeAliasId, TypeParamId,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{db::HirDatabase, display::HirDisplay, utils::generics};
|
use crate::{db::HirDatabase, display::HirDisplay, utils::generics};
|
||||||
|
@ -71,6 +72,11 @@ pub type Lifetime = chalk_ir::Lifetime<Interner>;
|
||||||
pub type LifetimeData = chalk_ir::LifetimeData<Interner>;
|
pub type LifetimeData = chalk_ir::LifetimeData<Interner>;
|
||||||
pub type LifetimeOutlives = chalk_ir::LifetimeOutlives<Interner>;
|
pub type LifetimeOutlives = chalk_ir::LifetimeOutlives<Interner>;
|
||||||
|
|
||||||
|
pub type Const = chalk_ir::Const<Interner>;
|
||||||
|
pub type ConstData = chalk_ir::ConstData<Interner>;
|
||||||
|
pub type ConstValue = chalk_ir::ConstValue<Interner>;
|
||||||
|
pub type ConcreteConst = chalk_ir::ConcreteConst<Interner>;
|
||||||
|
|
||||||
pub type ChalkTraitId = chalk_ir::TraitId<Interner>;
|
pub type ChalkTraitId = chalk_ir::TraitId<Interner>;
|
||||||
|
|
||||||
pub type FnSig = chalk_ir::FnSig<Interner>;
|
pub type FnSig = chalk_ir::FnSig<Interner>;
|
||||||
|
@ -227,7 +233,9 @@ impl Ty {
|
||||||
pub fn equals_ctor(&self, other: &Ty) -> bool {
|
pub fn equals_ctor(&self, other: &Ty) -> bool {
|
||||||
match (self.kind(&Interner), other.kind(&Interner)) {
|
match (self.kind(&Interner), other.kind(&Interner)) {
|
||||||
(TyKind::Adt(adt, ..), TyKind::Adt(adt2, ..)) => adt == adt2,
|
(TyKind::Adt(adt, ..), TyKind::Adt(adt2, ..)) => adt == adt2,
|
||||||
(TyKind::Slice(_), TyKind::Slice(_)) | (TyKind::Array(_), TyKind::Array(_)) => true,
|
(TyKind::Slice(_), TyKind::Slice(_)) | (TyKind::Array(_, _), TyKind::Array(_, _)) => {
|
||||||
|
true
|
||||||
|
}
|
||||||
(TyKind::FnDef(def_id, ..), TyKind::FnDef(def_id2, ..)) => def_id == def_id2,
|
(TyKind::FnDef(def_id, ..), TyKind::FnDef(def_id2, ..)) => def_id == def_id2,
|
||||||
(TyKind::OpaqueType(ty_id, ..), TyKind::OpaqueType(ty_id2, ..)) => ty_id == ty_id2,
|
(TyKind::OpaqueType(ty_id, ..), TyKind::OpaqueType(ty_id2, ..)) => ty_id == ty_id2,
|
||||||
(TyKind::AssociatedType(ty_id, ..), TyKind::AssociatedType(ty_id2, ..)) => {
|
(TyKind::AssociatedType(ty_id, ..), TyKind::AssociatedType(ty_id2, ..)) => {
|
||||||
|
@ -488,6 +496,12 @@ pub fn lt_from_placeholder_idx(db: &dyn HirDatabase, idx: PlaceholderIndex) -> L
|
||||||
db.lookup_intern_lifetime_param_id(interned_id)
|
db.lookup_intern_lifetime_param_id(interned_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn const_from_placeholder_idx(db: &dyn HirDatabase, idx: PlaceholderIndex) -> ConstParamId {
|
||||||
|
assert_eq!(idx.ui, chalk_ir::UniverseIndex::ROOT);
|
||||||
|
let interned_id = salsa::InternKey::from_intern_id(salsa::InternId::from(idx.idx));
|
||||||
|
db.lookup_intern_const_param_id(interned_id)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn to_chalk_trait_id(id: TraitId) -> ChalkTraitId {
|
pub fn to_chalk_trait_id(id: TraitId) -> ChalkTraitId {
|
||||||
chalk_ir::TraitId(salsa::InternKey::as_intern_id(&id))
|
chalk_ir::TraitId(salsa::InternKey::as_intern_id(&id))
|
||||||
}
|
}
|
||||||
|
@ -499,3 +513,12 @@ pub fn from_chalk_trait_id(id: ChalkTraitId) -> TraitId {
|
||||||
pub fn static_lifetime() -> Lifetime {
|
pub fn static_lifetime() -> Lifetime {
|
||||||
LifetimeData::Static.intern(&Interner)
|
LifetimeData::Static.intern(&Interner)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn dummy_usize_const() -> Const {
|
||||||
|
let usize_ty = chalk_ir::TyKind::Scalar(Scalar::Uint(UintTy::Usize)).intern(&Interner);
|
||||||
|
chalk_ir::ConstData {
|
||||||
|
ty: usize_ty,
|
||||||
|
value: chalk_ir::ConstValue::Concrete(chalk_ir::ConcreteConst { interned: () }),
|
||||||
|
}
|
||||||
|
.intern(&Interner)
|
||||||
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ use stdx::impl_from;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
db::HirDatabase,
|
db::HirDatabase,
|
||||||
static_lifetime, to_assoc_type_id, to_chalk_trait_id, to_placeholder_idx,
|
dummy_usize_const, static_lifetime, to_assoc_type_id, to_chalk_trait_id, to_placeholder_idx,
|
||||||
traits::chalk::{Interner, ToChalk},
|
traits::chalk::{Interner, ToChalk},
|
||||||
utils::{
|
utils::{
|
||||||
all_super_trait_refs, associated_type_by_name_including_super_traits, generics,
|
all_super_trait_refs, associated_type_by_name_including_super_traits, generics,
|
||||||
|
@ -166,7 +166,7 @@ impl<'a> TyLoweringContext<'a> {
|
||||||
}
|
}
|
||||||
TypeRef::Array(inner) => {
|
TypeRef::Array(inner) => {
|
||||||
let inner_ty = self.lower_ty(inner);
|
let inner_ty = self.lower_ty(inner);
|
||||||
TyKind::Array(inner_ty).intern(&Interner)
|
TyKind::Array(inner_ty, dummy_usize_const()).intern(&Interner)
|
||||||
}
|
}
|
||||||
TypeRef::Slice(inner) => {
|
TypeRef::Slice(inner) => {
|
||||||
let inner_ty = self.lower_ty(inner);
|
let inner_ty = self.lower_ty(inner);
|
||||||
|
|
|
@ -842,7 +842,9 @@ fn autoderef_method_receiver(
|
||||||
) -> Vec<Canonical<Ty>> {
|
) -> Vec<Canonical<Ty>> {
|
||||||
let mut deref_chain: Vec<_> = autoderef::autoderef(db, Some(krate), ty).collect();
|
let mut deref_chain: Vec<_> = autoderef::autoderef(db, Some(krate), ty).collect();
|
||||||
// As a last step, we can do array unsizing (that's the only unsizing that rustc does for method receivers!)
|
// As a last step, we can do array unsizing (that's the only unsizing that rustc does for method receivers!)
|
||||||
if let Some(TyKind::Array(parameters)) = deref_chain.last().map(|ty| ty.value.kind(&Interner)) {
|
if let Some(TyKind::Array(parameters, _)) =
|
||||||
|
deref_chain.last().map(|ty| ty.value.kind(&Interner))
|
||||||
|
{
|
||||||
let kinds = deref_chain.last().unwrap().binders.clone();
|
let kinds = deref_chain.last().unwrap().binders.clone();
|
||||||
let unsized_ty = TyKind::Slice(parameters.clone()).intern(&Interner);
|
let unsized_ty = TyKind::Slice(parameters.clone()).intern(&Interner);
|
||||||
deref_chain.push(Canonical { value: unsized_ty, binders: kinds })
|
deref_chain.push(Canonical { value: unsized_ty, binders: kinds })
|
||||||
|
|
|
@ -10,9 +10,10 @@ use base_db::salsa::InternKey;
|
||||||
use hir_def::{GenericDefId, TypeAliasId};
|
use hir_def::{GenericDefId, TypeAliasId};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
chalk_ext::ProjectionTyExt, db::HirDatabase, primitive::UintTy, static_lifetime, AliasTy,
|
chalk_ext::ProjectionTyExt, db::HirDatabase, dummy_usize_const, static_lifetime, AliasTy,
|
||||||
CallableDefId, Canonical, DomainGoal, FnPointer, GenericArg, InEnvironment, Lifetime, OpaqueTy,
|
CallableDefId, Canonical, Const, DomainGoal, FnPointer, GenericArg, InEnvironment, Lifetime,
|
||||||
ProjectionTy, QuantifiedWhereClause, Scalar, Substitution, TraitRef, Ty, TypeWalk, WhereClause,
|
OpaqueTy, ProjectionTy, QuantifiedWhereClause, Substitution, TraitRef, Ty, TypeWalk,
|
||||||
|
WhereClause,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::interner::*;
|
use super::interner::*;
|
||||||
|
@ -23,7 +24,7 @@ impl ToChalk for Ty {
|
||||||
fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Ty<Interner> {
|
fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Ty<Interner> {
|
||||||
match self.into_inner() {
|
match self.into_inner() {
|
||||||
TyKind::Ref(m, lt, ty) => ref_to_chalk(db, m, lt, ty),
|
TyKind::Ref(m, lt, ty) => ref_to_chalk(db, m, lt, ty),
|
||||||
TyKind::Array(ty) => array_to_chalk(db, ty),
|
TyKind::Array(ty, size) => array_to_chalk(db, ty, size),
|
||||||
TyKind::Function(FnPointer { sig, substitution: substs, .. }) => {
|
TyKind::Function(FnPointer { sig, substitution: substs, .. }) => {
|
||||||
let substitution = chalk_ir::FnSubst(substs.0.to_chalk(db));
|
let substitution = chalk_ir::FnSubst(substs.0.to_chalk(db));
|
||||||
chalk_ir::TyKind::Function(chalk_ir::FnPointer {
|
chalk_ir::TyKind::Function(chalk_ir::FnPointer {
|
||||||
|
@ -110,7 +111,7 @@ impl ToChalk for Ty {
|
||||||
fn from_chalk(db: &dyn HirDatabase, chalk: chalk_ir::Ty<Interner>) -> Self {
|
fn from_chalk(db: &dyn HirDatabase, chalk: chalk_ir::Ty<Interner>) -> Self {
|
||||||
match chalk.data(&Interner).kind.clone() {
|
match chalk.data(&Interner).kind.clone() {
|
||||||
chalk_ir::TyKind::Error => TyKind::Error,
|
chalk_ir::TyKind::Error => TyKind::Error,
|
||||||
chalk_ir::TyKind::Array(ty, _size) => TyKind::Array(from_chalk(db, ty)),
|
chalk_ir::TyKind::Array(ty, size) => TyKind::Array(from_chalk(db, ty), size),
|
||||||
chalk_ir::TyKind::Placeholder(idx) => TyKind::Placeholder(idx),
|
chalk_ir::TyKind::Placeholder(idx) => TyKind::Placeholder(idx),
|
||||||
chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Projection(proj)) => {
|
chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Projection(proj)) => {
|
||||||
let associated_ty = proj.associated_ty_id;
|
let associated_ty = proj.associated_ty_id;
|
||||||
|
@ -203,15 +204,9 @@ fn ref_to_chalk(
|
||||||
|
|
||||||
/// We currently don't model constants, but Chalk does. So, we have to insert a
|
/// We currently don't model constants, but Chalk does. So, we have to insert a
|
||||||
/// fake constant here, because Chalks built-in logic may expect it to be there.
|
/// fake constant here, because Chalks built-in logic may expect it to be there.
|
||||||
fn array_to_chalk(db: &dyn HirDatabase, ty: Ty) -> chalk_ir::Ty<Interner> {
|
fn array_to_chalk(db: &dyn HirDatabase, ty: Ty, _: Const) -> chalk_ir::Ty<Interner> {
|
||||||
let arg = ty.to_chalk(db);
|
let arg = ty.to_chalk(db);
|
||||||
let usize_ty = chalk_ir::TyKind::Scalar(Scalar::Uint(UintTy::Usize)).intern(&Interner);
|
chalk_ir::TyKind::Array(arg, dummy_usize_const()).intern(&Interner)
|
||||||
let const_ = chalk_ir::ConstData {
|
|
||||||
ty: usize_ty,
|
|
||||||
value: chalk_ir::ConstValue::Concrete(chalk_ir::ConcreteConst { interned: () }),
|
|
||||||
}
|
|
||||||
.intern(&Interner);
|
|
||||||
chalk_ir::TyKind::Array(arg, const_).intern(&Interner)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToChalk for GenericArg {
|
impl ToChalk for GenericArg {
|
||||||
|
|
|
@ -10,7 +10,7 @@ use chalk_ir::{
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
AssocTypeId, CanonicalVarKinds, ChalkTraitId, ClosureId, FnDefId, FnSig, ForeignDefId,
|
AssocTypeId, CanonicalVarKinds, ChalkTraitId, ClosureId, Const, FnDefId, FnSig, ForeignDefId,
|
||||||
InferenceVar, Interner, Lifetime, OpaqueTyId, PlaceholderIndex, TypeWalk, VariableKind,
|
InferenceVar, Interner, Lifetime, OpaqueTyId, PlaceholderIndex, TypeWalk, VariableKind,
|
||||||
VariableKinds,
|
VariableKinds,
|
||||||
};
|
};
|
||||||
|
@ -114,7 +114,7 @@ pub enum TyKind {
|
||||||
Tuple(usize, Substitution),
|
Tuple(usize, Substitution),
|
||||||
|
|
||||||
/// An array with the given length. Written as `[T; n]`.
|
/// An array with the given length. Written as `[T; n]`.
|
||||||
Array(Ty),
|
Array(Ty, Const),
|
||||||
|
|
||||||
/// The pointee of an array slice. Written as `[T]`.
|
/// The pointee of an array slice. Written as `[T]`.
|
||||||
Slice(Ty),
|
Slice(Ty),
|
||||||
|
|
|
@ -153,7 +153,10 @@ impl TypeWalk for Ty {
|
||||||
p.walk(f);
|
p.walk(f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TyKind::Slice(ty) | TyKind::Array(ty) | TyKind::Ref(_, _, ty) | TyKind::Raw(_, ty) => {
|
TyKind::Slice(ty)
|
||||||
|
| TyKind::Array(ty, _)
|
||||||
|
| TyKind::Ref(_, _, ty)
|
||||||
|
| TyKind::Raw(_, ty) => {
|
||||||
ty.walk(f);
|
ty.walk(f);
|
||||||
}
|
}
|
||||||
TyKind::Function(fn_pointer) => {
|
TyKind::Function(fn_pointer) => {
|
||||||
|
@ -187,7 +190,10 @@ impl TypeWalk for Ty {
|
||||||
TyKind::Alias(AliasTy::Opaque(o_ty)) => {
|
TyKind::Alias(AliasTy::Opaque(o_ty)) => {
|
||||||
o_ty.substitution.walk_mut_binders(f, binders);
|
o_ty.substitution.walk_mut_binders(f, binders);
|
||||||
}
|
}
|
||||||
TyKind::Slice(ty) | TyKind::Array(ty) | TyKind::Ref(_, _, ty) | TyKind::Raw(_, ty) => {
|
TyKind::Slice(ty)
|
||||||
|
| TyKind::Array(ty, _)
|
||||||
|
| TyKind::Ref(_, _, ty)
|
||||||
|
| TyKind::Raw(_, ty) => {
|
||||||
ty.walk_mut_binders(f, binders);
|
ty.walk_mut_binders(f, binders);
|
||||||
}
|
}
|
||||||
TyKind::Function(fn_pointer) => {
|
TyKind::Function(fn_pointer) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue