Rename TyKind::Unknown to Error

This commit is contained in:
Laurențiu Nicola 2021-04-05 15:37:11 +03:00
parent d8ee25bb97
commit 65c2e51940
14 changed files with 48 additions and 48 deletions

View File

@ -1876,7 +1876,7 @@ impl Type {
fn go(ty: &Ty) -> bool {
match ty.kind(&Interner) {
TyKind::Unknown => true,
TyKind::Error => true,
TyKind::Adt(_, substs)
| TyKind::AssociatedType(_, substs)

View File

@ -54,7 +54,7 @@ impl<D> TyBuilder<D> {
}
pub fn fill_with_unknown(self) -> Self {
self.fill(iter::repeat(TyKind::Unknown.intern(&Interner)))
self.fill(iter::repeat(TyKind::Error.intern(&Interner)))
}
pub fn fill(mut self, filler: impl Iterator<Item = impl CastTo<GenericArg>>) -> Self {

View File

@ -476,7 +476,7 @@ impl HirDisplay for Ty {
parameter.assert_ty_ref(&Interner).kind(&Interner),
default_parameters.get(i),
) {
(&TyKind::Unknown, _) | (_, None) => {
(&TyKind::Error, _) | (_, None) => {
default_from = i + 1;
}
(_, Some(default_parameter)) => {
@ -636,7 +636,7 @@ impl HirDisplay for Ty {
}
};
}
TyKind::Unknown => {
TyKind::Error => {
if f.display_target.is_source_code() {
return Err(HirDisplayError::DisplaySourceCodeError(
DisplaySourceCodeError::UnknownType,

View File

@ -120,7 +120,7 @@ struct InternedStandardTypes {
impl Default for InternedStandardTypes {
fn default() -> Self {
InternedStandardTypes { unknown: TyKind::Unknown.intern(&Interner) }
InternedStandardTypes { unknown: TyKind::Error.intern(&Interner) }
}
}
@ -247,7 +247,7 @@ impl<'a> InferenceContext<'a> {
table: unify::InferenceTable::new(),
obligations: Vec::default(),
last_obligations_check: None,
return_ty: TyKind::Unknown.intern(&Interner), // set in collect_fn_signature
return_ty: TyKind::Error.intern(&Interner), // set in collect_fn_signature
trait_env: owner
.as_generic_def_id()
.map_or_else(Default::default, |d| db.trait_environment(d)),
@ -261,7 +261,7 @@ impl<'a> InferenceContext<'a> {
}
fn err_ty(&self) -> Ty {
TyKind::Unknown.intern(&Interner)
TyKind::Error.intern(&Interner)
}
fn resolve_all(mut self) -> InferenceResult {
@ -326,7 +326,7 @@ impl<'a> InferenceContext<'a> {
/// Replaces Ty::Unknown by a new type var, so we can maybe still infer it.
fn insert_type_vars_shallow(&mut self, ty: Ty) -> Ty {
match ty.kind(&Interner) {
TyKind::Unknown => self.table.new_type_var(),
TyKind::Error => self.table.new_type_var(),
_ => ty,
}
}
@ -542,7 +542,7 @@ impl<'a> InferenceContext<'a> {
result
} else {
// FIXME diagnostic
(TyKind::Unknown.intern(&Interner), None)
(TyKind::Error.intern(&Interner), None)
}
}
@ -755,7 +755,7 @@ impl Expectation {
fn none() -> Self {
Expectation {
// FIXME
ty: TyKind::Unknown.intern(&Interner),
ty: TyKind::Error.intern(&Interner),
rvalue_hint: false,
}
}
@ -763,7 +763,7 @@ impl Expectation {
fn coercion_target(&self) -> Ty {
if self.rvalue_hint {
// FIXME
TyKind::Unknown.intern(&Interner)
TyKind::Error.intern(&Interner)
} else {
self.ty.clone()
}

View File

@ -142,7 +142,7 @@ impl<'a> InferenceContext<'a> {
remaining_segments_for_ty,
true,
);
if let TyKind::Unknown = ty.kind(&Interner) {
if let TyKind::Error = ty.kind(&Interner) {
return None;
}
@ -207,7 +207,7 @@ impl<'a> InferenceContext<'a> {
name: &Name,
id: ExprOrPatId,
) -> Option<(ValueNs, Option<Substitution>)> {
if let TyKind::Unknown = ty.kind(&Interner) {
if let TyKind::Error = ty.kind(&Interner) {
return None;
}

View File

@ -214,7 +214,7 @@ impl TypeVariableTable {
fn fallback_value(&self, iv: InferenceVar, kind: TyVariableKind) -> Ty {
match kind {
_ if self.inner[iv.to_inner().0 as usize].diverging => TyKind::Never,
TyVariableKind::General => TyKind::Unknown,
TyVariableKind::General => TyKind::Error,
TyVariableKind::Integer => TyKind::Scalar(Scalar::Int(IntTy::I32)),
TyVariableKind::Float => TyKind::Scalar(Scalar::Float(FloatTy::F64)),
}
@ -327,7 +327,7 @@ impl InferenceTable {
pub(super) fn unify_inner_trivial(&mut self, ty1: &Ty, ty2: &Ty, depth: usize) -> bool {
match (ty1.kind(&Interner), ty2.kind(&Interner)) {
(TyKind::Unknown, _) | (_, TyKind::Unknown) => true,
(TyKind::Error, _) | (_, TyKind::Error) => true,
(TyKind::Placeholder(p1), TyKind::Placeholder(p2)) if *p1 == *p2 => true,

View File

@ -300,7 +300,7 @@ impl Ty {
}
pub fn is_unknown(&self) -> bool {
matches!(self.kind(&Interner), TyKind::Unknown)
matches!(self.kind(&Interner), TyKind::Error)
}
pub fn equals_ctor(&self, other: &Ty) -> bool {

View File

@ -176,7 +176,7 @@ impl<'a> TyLoweringContext<'a> {
let inner_ty = self.lower_ty(inner);
TyKind::Ref(lower_to_chalk_mutability(*mutability), inner_ty).intern(&Interner)
}
TypeRef::Placeholder => TyKind::Unknown.intern(&Interner),
TypeRef::Placeholder => TyKind::Error.intern(&Interner),
TypeRef::Fn(params, is_varargs) => {
let substs =
Substitution::from_iter(&Interner, params.iter().map(|tr| self.lower_ty(tr)));
@ -253,12 +253,12 @@ impl<'a> TyLoweringContext<'a> {
data.provenance == TypeParamProvenance::ArgumentImplTrait
})
.nth(idx as usize)
.map_or(TyKind::Unknown, |(id, _)| {
.map_or(TyKind::Error, |(id, _)| {
TyKind::Placeholder(to_placeholder_idx(self.db, id))
});
param.intern(&Interner)
} else {
TyKind::Unknown.intern(&Interner)
TyKind::Error.intern(&Interner)
}
}
ImplTraitLoweringMode::Variable => {
@ -280,11 +280,11 @@ impl<'a> TyLoweringContext<'a> {
}
ImplTraitLoweringMode::Disallowed => {
// FIXME: report error
TyKind::Unknown.intern(&Interner)
TyKind::Error.intern(&Interner)
}
}
}
TypeRef::Error => TyKind::Unknown.intern(&Interner),
TypeRef::Error => TyKind::Error.intern(&Interner),
};
(ty, res)
}
@ -328,7 +328,7 @@ impl<'a> TyLoweringContext<'a> {
(self.select_associated_type(res, segment), None)
} else if remaining_segments.len() > 1 {
// FIXME report error (ambiguous associated type)
(TyKind::Unknown.intern(&Interner), None)
(TyKind::Error.intern(&Interner), None)
} else {
(ty, res)
}
@ -372,12 +372,12 @@ impl<'a> TyLoweringContext<'a> {
}
None => {
// FIXME: report error (associated type not found)
TyKind::Unknown.intern(&Interner)
TyKind::Error.intern(&Interner)
}
}
} else if remaining_segments.len() > 1 {
// FIXME report error (ambiguous associated type)
TyKind::Unknown.intern(&Interner)
TyKind::Error.intern(&Interner)
} else {
let dyn_ty = DynTy {
bounds: Binders::new(
@ -433,7 +433,7 @@ impl<'a> TyLoweringContext<'a> {
self.lower_path_inner(resolved_segment, it.into(), infer_args)
}
// FIXME: report error
TypeNs::EnumVariantId(_) => return (TyKind::Unknown.intern(&Interner), None),
TypeNs::EnumVariantId(_) => return (TyKind::Error.intern(&Interner), None),
};
self.lower_ty_relative_path(ty, Some(resolution), remaining_segments)
}
@ -447,7 +447,7 @@ impl<'a> TyLoweringContext<'a> {
let (resolution, remaining_index) =
match self.resolver.resolve_path_in_type_ns(self.db.upcast(), path.mod_path()) {
Some(it) => it,
None => return (TyKind::Unknown.intern(&Interner), None),
None => return (TyKind::Error.intern(&Interner), None),
};
let (resolved_segment, remaining_segments) = match remaining_index {
None => (
@ -498,9 +498,9 @@ impl<'a> TyLoweringContext<'a> {
},
);
ty.unwrap_or(TyKind::Unknown.intern(&Interner))
ty.unwrap_or(TyKind::Error.intern(&Interner))
} else {
TyKind::Unknown.intern(&Interner)
TyKind::Error.intern(&Interner)
}
}
@ -569,13 +569,13 @@ impl<'a> TyLoweringContext<'a> {
def_generics.map_or((0, 0, 0, 0), |g| g.provenance_split());
let total_len = parent_params + self_params + type_params + impl_trait_params;
substs.extend(iter::repeat(TyKind::Unknown.intern(&Interner)).take(parent_params));
substs.extend(iter::repeat(TyKind::Error.intern(&Interner)).take(parent_params));
let fill_self_params = || {
substs.extend(
explicit_self_ty
.into_iter()
.chain(iter::repeat(TyKind::Unknown.intern(&Interner)))
.chain(iter::repeat(TyKind::Error.intern(&Interner)))
.take(self_params),
)
};
@ -628,7 +628,7 @@ impl<'a> TyLoweringContext<'a> {
// add placeholders for args that were not provided
// FIXME: emit diagnostics in contexts where this is not allowed
for _ in substs.len()..total_len {
substs.push(TyKind::Unknown.intern(&Interner));
substs.push(TyKind::Error.intern(&Interner));
}
assert_eq!(substs.len(), total_len);
@ -1008,7 +1008,7 @@ pub(crate) fn generic_defaults_query(
.enumerate()
.map(|(idx, (_, p))| {
let mut ty =
p.default.as_ref().map_or(TyKind::Unknown.intern(&Interner), |t| ctx.lower_ty(t));
p.default.as_ref().map_or(TyKind::Error.intern(&Interner), |t| ctx.lower_ty(t));
// Each default can only refer to previous parameters.
ty.walk_mut_binders(
@ -1018,7 +1018,7 @@ pub(crate) fn generic_defaults_query(
// type variable default referring to parameter coming
// after it. This is forbidden (FIXME: report
// diagnostic)
*ty = TyKind::Unknown.intern(&Interner);
*ty = TyKind::Error.intern(&Interner);
}
}
_ => {}
@ -1220,7 +1220,7 @@ pub(crate) fn ty_recover(db: &dyn HirDatabase, _cycle: &[String], def: &TyDefId)
TyDefId::AdtId(it) => generics(db.upcast(), it.into()).len(),
TyDefId::TypeAliasId(it) => generics(db.upcast(), it.into()).len(),
};
Binders::new(num_binders, TyKind::Unknown.intern(&Interner))
Binders::new(num_binders, TyKind::Error.intern(&Interner))
}
pub(crate) fn value_ty_query(db: &dyn HirDatabase, def: ValueTyDefId) -> Binders<Ty> {
@ -1258,7 +1258,7 @@ pub(crate) fn impl_self_ty_recover(
impl_id: &ImplId,
) -> Binders<Ty> {
let generics = generics(db.upcast(), (*impl_id).into());
Binders::new(generics.len(), TyKind::Unknown.intern(&Interner))
Binders::new(generics.len(), TyKind::Error.intern(&Interner))
}
pub(crate) fn impl_trait_query(db: &dyn HirDatabase, impl_id: ImplId) -> Option<Binders<TraitRef>> {

View File

@ -742,7 +742,7 @@ fn fallback_bound_vars(s: Substitution, num_vars_to_keep: usize) -> Substitution
&mut |ty, binders| {
if let TyKind::BoundVar(bound) = ty.kind(&Interner) {
if bound.index >= num_vars_to_keep && bound.debruijn >= binders {
TyKind::Unknown.intern(&Interner)
TyKind::Error.intern(&Interner)
} else {
ty
}

View File

@ -15,7 +15,7 @@ pub(super) fn binary_op_return_ty(op: BinaryOp, lhs_ty: Ty, rhs_ty: Ty) -> Ty {
| TyKind::Scalar(Scalar::Float(_)) => lhs_ty,
TyKind::InferenceVar(_, TyVariableKind::Integer)
| TyKind::InferenceVar(_, TyVariableKind::Float) => lhs_ty,
_ => TyKind::Unknown.intern(&Interner),
_ => TyKind::Error.intern(&Interner),
}
}
BinaryOp::ArithOp(_) => match rhs_ty.kind(&Interner) {
@ -24,7 +24,7 @@ pub(super) fn binary_op_return_ty(op: BinaryOp, lhs_ty: Ty, rhs_ty: Ty) -> Ty {
| TyKind::Scalar(Scalar::Float(_)) => rhs_ty,
TyKind::InferenceVar(_, TyVariableKind::Integer)
| TyKind::InferenceVar(_, TyVariableKind::Float) => rhs_ty,
_ => TyKind::Unknown.intern(&Interner),
_ => TyKind::Error.intern(&Interner),
},
}
}
@ -37,10 +37,10 @@ pub(super) fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty {
TyKind::Scalar(_) | TyKind::Str => lhs_ty,
TyKind::InferenceVar(_, TyVariableKind::Integer)
| TyKind::InferenceVar(_, TyVariableKind::Float) => lhs_ty,
_ => TyKind::Unknown.intern(&Interner),
_ => TyKind::Error.intern(&Interner),
},
BinaryOp::ArithOp(ArithOp::Shl) | BinaryOp::ArithOp(ArithOp::Shr) => {
TyKind::Unknown.intern(&Interner)
TyKind::Error.intern(&Interner)
}
BinaryOp::CmpOp(CmpOp::Ord { .. })
| BinaryOp::Assignment { op: Some(_) }
@ -50,7 +50,7 @@ pub(super) fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty {
| TyKind::Scalar(Scalar::Float(_)) => lhs_ty,
TyKind::InferenceVar(_, TyVariableKind::Integer)
| TyKind::InferenceVar(_, TyVariableKind::Float) => lhs_ty,
_ => TyKind::Unknown.intern(&Interner),
_ => TyKind::Error.intern(&Interner),
},
}
}

View File

@ -265,7 +265,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
fn hidden_opaque_type(&self, _id: chalk_ir::OpaqueTyId<Interner>) -> chalk_ir::Ty<Interner> {
// FIXME: actually provide the hidden type; it is relevant for auto traits
TyKind::Unknown.intern(&Interner).to_chalk(self.db)
TyKind::Error.intern(&Interner).to_chalk(self.db)
}
fn is_object_safe(&self, _trait_id: chalk_ir::TraitId<Interner>) -> bool {

View File

@ -103,12 +103,12 @@ impl ToChalk for Ty {
};
chalk_ir::TyKind::Dyn(bounded_ty).intern(&Interner)
}
TyKind::Unknown => chalk_ir::TyKind::Error.intern(&Interner),
TyKind::Error => chalk_ir::TyKind::Error.intern(&Interner),
}
}
fn from_chalk(db: &dyn HirDatabase, chalk: chalk_ir::Ty<Interner>) -> Self {
match chalk.data(&Interner).kind.clone() {
chalk_ir::TyKind::Error => TyKind::Unknown,
chalk_ir::TyKind::Error => TyKind::Error,
chalk_ir::TyKind::Array(ty, _size) => TyKind::Array(from_chalk(db, ty)),
chalk_ir::TyKind::Placeholder(idx) => TyKind::Placeholder(idx),
chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Projection(proj)) => {
@ -138,7 +138,7 @@ impl ToChalk for Ty {
TyKind::Function(FnPointer { num_args: (substs.len(&Interner) - 1), sig, substs })
}
chalk_ir::TyKind::BoundVar(idx) => TyKind::BoundVar(idx),
chalk_ir::TyKind::InferenceVar(_iv, _kind) => TyKind::Unknown,
chalk_ir::TyKind::InferenceVar(_iv, _kind) => TyKind::Error,
chalk_ir::TyKind::Dyn(where_clauses) => {
assert_eq!(where_clauses.bounds.binders.len(&Interner), 1);
let bounds = where_clauses

View File

@ -179,7 +179,7 @@ pub enum TyKind {
/// variables are inserted before type checking, since we want to try to
/// infer a better type here anyway -- for the IDE use case, we want to try
/// to infer as much as possible even in the presence of type errors.
Unknown,
Error,
}
#[derive(Clone, PartialEq, Eq, Debug, Hash)]

View File

@ -43,7 +43,7 @@ pub trait TypeWalk {
{
self.walk_mut_binders(
&mut |ty_mut, binders| {
let ty = mem::replace(ty_mut, TyKind::Unknown.intern(&Interner));
let ty = mem::replace(ty_mut, TyKind::Error.intern(&Interner));
*ty_mut = f(ty, binders);
},
binders,
@ -56,7 +56,7 @@ pub trait TypeWalk {
Self: Sized,
{
self.walk_mut(&mut |ty_mut| {
let ty = mem::replace(ty_mut, TyKind::Unknown.intern(&Interner));
let ty = mem::replace(ty_mut, TyKind::Error.intern(&Interner));
*ty_mut = f(ty);
});
self