From a3f5491a1a312393429a44028e7496fe0a12f8c2 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sun, 28 Feb 2021 19:13:37 +0100 Subject: Inline TypeCtor into Ty --- crates/hir_ty/src/diagnostics/expr.rs | 11 ++++------- crates/hir_ty/src/diagnostics/match_check.rs | 8 +++----- crates/hir_ty/src/diagnostics/unsafe_check.rs | 6 ++---- 3 files changed, 9 insertions(+), 16 deletions(-) (limited to 'crates/hir_ty/src/diagnostics') diff --git a/crates/hir_ty/src/diagnostics/expr.rs b/crates/hir_ty/src/diagnostics/expr.rs index d740b7265..66a88e2b6 100644 --- a/crates/hir_ty/src/diagnostics/expr.rs +++ b/crates/hir_ty/src/diagnostics/expr.rs @@ -17,7 +17,7 @@ use crate::{ MissingPatFields, RemoveThisSemicolon, }, utils::variant_data, - ApplicationTy, InferenceResult, Ty, TypeCtor, + InferenceResult, Ty, }; pub(crate) use hir_def::{ @@ -381,14 +381,11 @@ impl<'a, 'b> ExprValidator<'a, 'b> { _ => return, }; - let core_result_ctor = TypeCtor::Adt(AdtId::EnumId(core_result_enum)); - let core_option_ctor = TypeCtor::Adt(AdtId::EnumId(core_option_enum)); - - let (params, required) = match &mismatch.expected { - Ty::Apply(ApplicationTy { ctor, parameters }) if ctor == &core_result_ctor => { + let (params, required) = match mismatch.expected { + Ty::Adt(AdtId::EnumId(enum_id), ref parameters) if enum_id == core_result_enum => { (parameters, "Ok".to_string()) } - Ty::Apply(ApplicationTy { ctor, parameters }) if ctor == &core_option_ctor => { + Ty::Adt(AdtId::EnumId(enum_id), ref parameters) if enum_id == core_option_enum => { (parameters, "Some".to_string()) } _ => return, diff --git a/crates/hir_ty/src/diagnostics/match_check.rs b/crates/hir_ty/src/diagnostics/match_check.rs index 1c1423fbf..86fee0050 100644 --- a/crates/hir_ty/src/diagnostics/match_check.rs +++ b/crates/hir_ty/src/diagnostics/match_check.rs @@ -227,7 +227,7 @@ use hir_def::{ use la_arena::Idx; use smallvec::{smallvec, SmallVec}; -use crate::{db::HirDatabase, ApplicationTy, InferenceResult, Ty, TypeCtor}; +use crate::{db::HirDatabase, InferenceResult, Ty}; #[derive(Debug, Clone, Copy)] /// Either a pattern from the source code being analyzed, represented as @@ -627,14 +627,12 @@ pub(super) fn is_useful( // - `!` type // In those cases, no match arm is useful. match cx.infer[cx.match_expr].strip_references() { - Ty::Apply(ApplicationTy { ctor: TypeCtor::Adt(AdtId::EnumId(enum_id)), .. }) => { + Ty::Adt(AdtId::EnumId(enum_id), ..) => { if cx.db.enum_data(*enum_id).variants.is_empty() { return Ok(Usefulness::NotUseful); } } - Ty::Apply(ApplicationTy { ctor: TypeCtor::Never, .. }) => { - return Ok(Usefulness::NotUseful); - } + Ty::Never => return Ok(Usefulness::NotUseful), _ => (), } diff --git a/crates/hir_ty/src/diagnostics/unsafe_check.rs b/crates/hir_ty/src/diagnostics/unsafe_check.rs index 9c506112d..b439915c7 100644 --- a/crates/hir_ty/src/diagnostics/unsafe_check.rs +++ b/crates/hir_ty/src/diagnostics/unsafe_check.rs @@ -11,9 +11,7 @@ use hir_def::{ }; use hir_expand::diagnostics::DiagnosticSink; -use crate::{ - db::HirDatabase, diagnostics::MissingUnsafe, ApplicationTy, InferenceResult, Ty, TypeCtor, -}; +use crate::{db::HirDatabase, diagnostics::MissingUnsafe, InferenceResult, Ty}; pub(super) struct UnsafeValidator<'a, 'b: 'a> { owner: DefWithBodyId, @@ -112,7 +110,7 @@ fn walk_unsafe( } } Expr::UnaryOp { expr, op: UnaryOp::Deref } => { - if let Ty::Apply(ApplicationTy { ctor: TypeCtor::RawPtr(..), .. }) = &infer[*expr] { + if let Ty::RawPtr(..) = &infer[*expr] { unsafe_exprs.push(UnsafeExpr { expr: current, inside_unsafe_block }); } } -- cgit v1.2.3