diff options
Diffstat (limited to 'crates/hir_ty/src/diagnostics')
-rw-r--r-- | crates/hir_ty/src/diagnostics/expr.rs | 21 | ||||
-rw-r--r-- | crates/hir_ty/src/diagnostics/match_check.rs | 8 | ||||
-rw-r--r-- | crates/hir_ty/src/diagnostics/unsafe_check.rs | 6 |
3 files changed, 17 insertions, 18 deletions
diff --git a/crates/hir_ty/src/diagnostics/expr.rs b/crates/hir_ty/src/diagnostics/expr.rs index 2751cd304..b2bfd68d4 100644 --- a/crates/hir_ty/src/diagnostics/expr.rs +++ b/crates/hir_ty/src/diagnostics/expr.rs | |||
@@ -15,7 +15,7 @@ use crate::{ | |||
15 | MissingPatFields, RemoveThisSemicolon, | 15 | MissingPatFields, RemoveThisSemicolon, |
16 | }, | 16 | }, |
17 | utils::variant_data, | 17 | utils::variant_data, |
18 | AdtId, InferenceResult, Ty, | 18 | AdtId, InferenceResult, Interner, Ty, TyKind, |
19 | }; | 19 | }; |
20 | 20 | ||
21 | pub(crate) use hir_def::{ | 21 | pub(crate) use hir_def::{ |
@@ -289,11 +289,10 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
289 | let (body, source_map): (Arc<Body>, Arc<BodySourceMap>) = | 289 | let (body, source_map): (Arc<Body>, Arc<BodySourceMap>) = |
290 | db.body_with_source_map(self.owner.into()); | 290 | db.body_with_source_map(self.owner.into()); |
291 | 291 | ||
292 | let match_expr_ty = match infer.type_of_expr.get(match_expr) { | 292 | let match_expr_ty = if infer.type_of_expr[match_expr].is_unknown() { |
293 | // If we can't resolve the type of the match expression | 293 | return; |
294 | // we cannot perform exhaustiveness checks. | 294 | } else { |
295 | None | Some(Ty::Unknown) => return, | 295 | &infer.type_of_expr[match_expr] |
296 | Some(ty) => ty, | ||
297 | }; | 296 | }; |
298 | 297 | ||
299 | let cx = MatchCheckCtx { match_expr, body, infer: infer.clone(), db }; | 298 | let cx = MatchCheckCtx { match_expr, body, infer: infer.clone(), db }; |
@@ -379,14 +378,14 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
379 | _ => return, | 378 | _ => return, |
380 | }; | 379 | }; |
381 | 380 | ||
382 | let (params, required) = match mismatch.expected { | 381 | let (params, required) = match mismatch.expected.interned(&Interner) { |
383 | Ty::Adt(AdtId(hir_def::AdtId::EnumId(enum_id)), ref parameters) | 382 | TyKind::Adt(AdtId(hir_def::AdtId::EnumId(enum_id)), ref parameters) |
384 | if enum_id == core_result_enum => | 383 | if *enum_id == core_result_enum => |
385 | { | 384 | { |
386 | (parameters, "Ok".to_string()) | 385 | (parameters, "Ok".to_string()) |
387 | } | 386 | } |
388 | Ty::Adt(AdtId(hir_def::AdtId::EnumId(enum_id)), ref parameters) | 387 | TyKind::Adt(AdtId(hir_def::AdtId::EnumId(enum_id)), ref parameters) |
389 | if enum_id == core_option_enum => | 388 | if *enum_id == core_option_enum => |
390 | { | 389 | { |
391 | (parameters, "Some".to_string()) | 390 | (parameters, "Some".to_string()) |
392 | } | 391 | } |
diff --git a/crates/hir_ty/src/diagnostics/match_check.rs b/crates/hir_ty/src/diagnostics/match_check.rs index 04d39c571..5a5cdcbf3 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::{ | |||
227 | use la_arena::Idx; | 227 | use la_arena::Idx; |
228 | use smallvec::{smallvec, SmallVec}; | 228 | use smallvec::{smallvec, SmallVec}; |
229 | 229 | ||
230 | use crate::{db::HirDatabase, AdtId, InferenceResult, Ty}; | 230 | use crate::{db::HirDatabase, AdtId, InferenceResult, Interner, TyKind}; |
231 | 231 | ||
232 | #[derive(Debug, Clone, Copy)] | 232 | #[derive(Debug, Clone, Copy)] |
233 | /// Either a pattern from the source code being analyzed, represented as | 233 | /// Either a pattern from the source code being analyzed, represented as |
@@ -626,13 +626,13 @@ pub(super) fn is_useful( | |||
626 | // - enum with no variants | 626 | // - enum with no variants |
627 | // - `!` type | 627 | // - `!` type |
628 | // In those cases, no match arm is useful. | 628 | // In those cases, no match arm is useful. |
629 | match cx.infer[cx.match_expr].strip_references() { | 629 | match cx.infer[cx.match_expr].strip_references().interned(&Interner) { |
630 | Ty::Adt(AdtId(hir_def::AdtId::EnumId(enum_id)), ..) => { | 630 | TyKind::Adt(AdtId(hir_def::AdtId::EnumId(enum_id)), ..) => { |
631 | if cx.db.enum_data(*enum_id).variants.is_empty() { | 631 | if cx.db.enum_data(*enum_id).variants.is_empty() { |
632 | return Ok(Usefulness::NotUseful); | 632 | return Ok(Usefulness::NotUseful); |
633 | } | 633 | } |
634 | } | 634 | } |
635 | Ty::Never => return Ok(Usefulness::NotUseful), | 635 | TyKind::Never => return Ok(Usefulness::NotUseful), |
636 | _ => (), | 636 | _ => (), |
637 | } | 637 | } |
638 | 638 | ||
diff --git a/crates/hir_ty/src/diagnostics/unsafe_check.rs b/crates/hir_ty/src/diagnostics/unsafe_check.rs index e77a20fea..20bb64827 100644 --- a/crates/hir_ty/src/diagnostics/unsafe_check.rs +++ b/crates/hir_ty/src/diagnostics/unsafe_check.rs | |||
@@ -11,7 +11,7 @@ use hir_def::{ | |||
11 | }; | 11 | }; |
12 | use hir_expand::diagnostics::DiagnosticSink; | 12 | use hir_expand::diagnostics::DiagnosticSink; |
13 | 13 | ||
14 | use crate::{db::HirDatabase, diagnostics::MissingUnsafe, InferenceResult, Ty}; | 14 | use crate::{db::HirDatabase, diagnostics::MissingUnsafe, InferenceResult, Interner, TyKind}; |
15 | 15 | ||
16 | pub(super) struct UnsafeValidator<'a, 'b: 'a> { | 16 | pub(super) struct UnsafeValidator<'a, 'b: 'a> { |
17 | owner: DefWithBodyId, | 17 | owner: DefWithBodyId, |
@@ -85,7 +85,7 @@ fn walk_unsafe( | |||
85 | let expr = &body.exprs[current]; | 85 | let expr = &body.exprs[current]; |
86 | match expr { | 86 | match expr { |
87 | &Expr::Call { callee, .. } => { | 87 | &Expr::Call { callee, .. } => { |
88 | if let Some(func) = infer[callee].as_fn_def() { | 88 | if let Some(func) = infer[callee].as_fn_def(db) { |
89 | if db.function_data(func).is_unsafe { | 89 | if db.function_data(func).is_unsafe { |
90 | unsafe_exprs.push(UnsafeExpr { expr: current, inside_unsafe_block }); | 90 | unsafe_exprs.push(UnsafeExpr { expr: current, inside_unsafe_block }); |
91 | } | 91 | } |
@@ -110,7 +110,7 @@ fn walk_unsafe( | |||
110 | } | 110 | } |
111 | } | 111 | } |
112 | Expr::UnaryOp { expr, op: UnaryOp::Deref } => { | 112 | Expr::UnaryOp { expr, op: UnaryOp::Deref } => { |
113 | if let Ty::Raw(..) = &infer[*expr] { | 113 | if let TyKind::Raw(..) = &infer[*expr].interned(&Interner) { |
114 | unsafe_exprs.push(UnsafeExpr { expr: current, inside_unsafe_block }); | 114 | unsafe_exprs.push(UnsafeExpr { expr: current, inside_unsafe_block }); |
115 | } | 115 | } |
116 | } | 116 | } |