From 65c2e5194034e4f6f556b96e71ce62bc2a465a35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Mon, 5 Apr 2021 15:37:11 +0300 Subject: Rename TyKind::Unknown to Error --- crates/hir/src/lib.rs | 2 +- crates/hir_ty/src/builder.rs | 2 +- crates/hir_ty/src/display.rs | 4 ++-- crates/hir_ty/src/infer.rs | 14 ++++++------ crates/hir_ty/src/infer/path.rs | 4 ++-- crates/hir_ty/src/infer/unify.rs | 4 ++-- crates/hir_ty/src/lib.rs | 2 +- crates/hir_ty/src/lower.rs | 38 +++++++++++++++---------------- crates/hir_ty/src/method_resolution.rs | 2 +- crates/hir_ty/src/op.rs | 10 ++++---- crates/hir_ty/src/traits/chalk.rs | 2 +- crates/hir_ty/src/traits/chalk/mapping.rs | 6 ++--- crates/hir_ty/src/types.rs | 2 +- crates/hir_ty/src/walk.rs | 4 ++-- 14 files changed, 48 insertions(+), 48 deletions(-) diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index e41efb385..76d0e98af 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -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) diff --git a/crates/hir_ty/src/builder.rs b/crates/hir_ty/src/builder.rs index 0bac31e4c..372621f73 100644 --- a/crates/hir_ty/src/builder.rs +++ b/crates/hir_ty/src/builder.rs @@ -54,7 +54,7 @@ impl TyBuilder { } 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>) -> Self { diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index 148eb7506..83d09a8c7 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs @@ -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, diff --git a/crates/hir_ty/src/infer.rs b/crates/hir_ty/src/infer.rs index bb885db35..6151e48cd 100644 --- a/crates/hir_ty/src/infer.rs +++ b/crates/hir_ty/src/infer.rs @@ -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() } diff --git a/crates/hir_ty/src/infer/path.rs b/crates/hir_ty/src/infer/path.rs index 637341b53..89d78e781 100644 --- a/crates/hir_ty/src/infer/path.rs +++ b/crates/hir_ty/src/infer/path.rs @@ -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)> { - if let TyKind::Unknown = ty.kind(&Interner) { + if let TyKind::Error = ty.kind(&Interner) { return None; } diff --git a/crates/hir_ty/src/infer/unify.rs b/crates/hir_ty/src/infer/unify.rs index b7bc48569..8370f2e1c 100644 --- a/crates/hir_ty/src/infer/unify.rs +++ b/crates/hir_ty/src/infer/unify.rs @@ -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, diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index 76609e2df..9e030e775 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs @@ -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 { diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs index 214655807..dd40eb5c3 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs @@ -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 { @@ -1258,7 +1258,7 @@ pub(crate) fn impl_self_ty_recover( impl_id: &ImplId, ) -> Binders { 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> { diff --git a/crates/hir_ty/src/method_resolution.rs b/crates/hir_ty/src/method_resolution.rs index 0e4a620b6..dc6324780 100644 --- a/crates/hir_ty/src/method_resolution.rs +++ b/crates/hir_ty/src/method_resolution.rs @@ -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 } diff --git a/crates/hir_ty/src/op.rs b/crates/hir_ty/src/op.rs index 90dd31a35..0491c5cb4 100644 --- a/crates/hir_ty/src/op.rs +++ b/crates/hir_ty/src/op.rs @@ -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), }, } } diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs index 541e6082f..b7388b98c 100644 --- a/crates/hir_ty/src/traits/chalk.rs +++ b/crates/hir_ty/src/traits/chalk.rs @@ -265,7 +265,7 @@ impl<'a> chalk_solve::RustIrDatabase for ChalkContext<'a> { fn hidden_opaque_type(&self, _id: chalk_ir::OpaqueTyId) -> chalk_ir::Ty { // 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) -> bool { diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs index 5e4f97a46..c5654f17b 100644 --- a/crates/hir_ty/src/traits/chalk/mapping.rs +++ b/crates/hir_ty/src/traits/chalk/mapping.rs @@ -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) -> 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 diff --git a/crates/hir_ty/src/types.rs b/crates/hir_ty/src/types.rs index 53662fcdc..9853ab3be 100644 --- a/crates/hir_ty/src/types.rs +++ b/crates/hir_ty/src/types.rs @@ -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)] diff --git a/crates/hir_ty/src/walk.rs b/crates/hir_ty/src/walk.rs index bfb3f1041..5dfd59746 100644 --- a/crates/hir_ty/src/walk.rs +++ b/crates/hir_ty/src/walk.rs @@ -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 -- cgit v1.2.3