From 426ad8e165aeb70a3d12b8bc870cb0c57a308bc7 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Thu, 28 Jan 2021 19:06:33 +0100 Subject: Classify function calls as functions when shadowed by types --- crates/hir_ty/src/diagnostics/unsafe_check.rs | 12 +++--------- crates/hir_ty/src/lib.rs | 19 ++++++++++++++----- 2 files changed, 17 insertions(+), 14 deletions(-) (limited to 'crates/hir_ty') diff --git a/crates/hir_ty/src/diagnostics/unsafe_check.rs b/crates/hir_ty/src/diagnostics/unsafe_check.rs index 6dc862826..9c506112d 100644 --- a/crates/hir_ty/src/diagnostics/unsafe_check.rs +++ b/crates/hir_ty/src/diagnostics/unsafe_check.rs @@ -12,8 +12,7 @@ use hir_def::{ use hir_expand::diagnostics::DiagnosticSink; use crate::{ - db::HirDatabase, diagnostics::MissingUnsafe, lower::CallableDefId, ApplicationTy, - InferenceResult, Ty, TypeCtor, + db::HirDatabase, diagnostics::MissingUnsafe, ApplicationTy, InferenceResult, Ty, TypeCtor, }; pub(super) struct UnsafeValidator<'a, 'b: 'a> { @@ -87,13 +86,8 @@ fn walk_unsafe( ) { let expr = &body.exprs[current]; match expr { - Expr::Call { callee, .. } => { - let ty = &infer[*callee]; - if let &Ty::Apply(ApplicationTy { - ctor: TypeCtor::FnDef(CallableDefId::FunctionId(func)), - .. - }) = ty - { + &Expr::Call { callee, .. } => { + if let Some(func) = infer[callee].as_fn_def() { if db.function_data(func).is_unsafe { unsafe_exprs.push(UnsafeExpr { expr: current, inside_unsafe_block }); } diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index d47f975d2..6bec389f8 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs @@ -29,8 +29,8 @@ use base_db::{salsa, CrateId}; use hir_def::{ expr::ExprId, type_ref::{Mutability, Rawness}, - AdtId, AssocContainerId, DefWithBodyId, GenericDefId, HasModule, LifetimeParamId, Lookup, - TraitId, TypeAliasId, TypeParamId, + AdtId, AssocContainerId, DefWithBodyId, FunctionId, GenericDefId, HasModule, LifetimeParamId, + Lookup, TraitId, TypeAliasId, TypeParamId, }; use itertools::Itertools; @@ -43,10 +43,9 @@ use crate::{ pub use autoderef::autoderef; pub use infer::{InferTy, InferenceResult}; -pub use lower::CallableDefId; pub use lower::{ - associated_type_shorthand_candidates, callable_item_sig, ImplTraitLoweringMode, TyDefId, - TyLoweringContext, ValueTyDefId, + associated_type_shorthand_candidates, callable_item_sig, CallableDefId, ImplTraitLoweringMode, + TyDefId, TyLoweringContext, ValueTyDefId, }; pub use traits::{InEnvironment, Obligation, ProjectionPredicate, TraitEnvironment}; @@ -824,6 +823,16 @@ impl Ty { } } + pub fn as_fn_def(&self) -> Option { + match self { + &Ty::Apply(ApplicationTy { + ctor: TypeCtor::FnDef(CallableDefId::FunctionId(func)), + .. + }) => Some(func), + _ => None, + } + } + pub fn callable_sig(&self, db: &dyn HirDatabase) -> Option { match self { Ty::Apply(a_ty) => match a_ty.ctor { -- cgit v1.2.3