aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-01-30 15:23:21 +0000
committerGitHub <[email protected]>2021-01-30 15:23:21 +0000
commitf408ff50130eae0eb56e7f9668e9df39f7baa6dd (patch)
tree099e32b0fb1f94bef58d6d9a23d45d2e8b890ae1 /crates/hir_ty
parent557c1e36ddbb19cc76f7a1f04d1b327942aafcb9 (diff)
parente3eeccf8ef2029bb54ba05af420a65b429763477 (diff)
Merge #7483
7483: Classify function calls as functions when shadowed by types r=matklad a=Veykril Fixes #7479 Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/hir_ty')
-rw-r--r--crates/hir_ty/src/diagnostics/unsafe_check.rs12
-rw-r--r--crates/hir_ty/src/lib.rs19
2 files changed, 17 insertions, 14 deletions
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::{
12use hir_expand::diagnostics::DiagnosticSink; 12use hir_expand::diagnostics::DiagnosticSink;
13 13
14use crate::{ 14use crate::{
15 db::HirDatabase, diagnostics::MissingUnsafe, lower::CallableDefId, ApplicationTy, 15 db::HirDatabase, diagnostics::MissingUnsafe, ApplicationTy, InferenceResult, Ty, TypeCtor,
16 InferenceResult, Ty, TypeCtor,
17}; 16};
18 17
19pub(super) struct UnsafeValidator<'a, 'b: 'a> { 18pub(super) struct UnsafeValidator<'a, 'b: 'a> {
@@ -87,13 +86,8 @@ fn walk_unsafe(
87) { 86) {
88 let expr = &body.exprs[current]; 87 let expr = &body.exprs[current];
89 match expr { 88 match expr {
90 Expr::Call { callee, .. } => { 89 &Expr::Call { callee, .. } => {
91 let ty = &infer[*callee]; 90 if let Some(func) = infer[callee].as_fn_def() {
92 if let &Ty::Apply(ApplicationTy {
93 ctor: TypeCtor::FnDef(CallableDefId::FunctionId(func)),
94 ..
95 }) = ty
96 {
97 if db.function_data(func).is_unsafe { 91 if db.function_data(func).is_unsafe {
98 unsafe_exprs.push(UnsafeExpr { expr: current, inside_unsafe_block }); 92 unsafe_exprs.push(UnsafeExpr { expr: current, inside_unsafe_block });
99 } 93 }
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};
29use hir_def::{ 29use hir_def::{
30 expr::ExprId, 30 expr::ExprId,
31 type_ref::{Mutability, Rawness}, 31 type_ref::{Mutability, Rawness},
32 AdtId, AssocContainerId, DefWithBodyId, GenericDefId, HasModule, LifetimeParamId, Lookup, 32 AdtId, AssocContainerId, DefWithBodyId, FunctionId, GenericDefId, HasModule, LifetimeParamId,
33 TraitId, TypeAliasId, TypeParamId, 33 Lookup, TraitId, TypeAliasId, TypeParamId,
34}; 34};
35use itertools::Itertools; 35use itertools::Itertools;
36 36
@@ -43,10 +43,9 @@ use crate::{
43 43
44pub use autoderef::autoderef; 44pub use autoderef::autoderef;
45pub use infer::{InferTy, InferenceResult}; 45pub use infer::{InferTy, InferenceResult};
46pub use lower::CallableDefId;
47pub use lower::{ 46pub use lower::{
48 associated_type_shorthand_candidates, callable_item_sig, ImplTraitLoweringMode, TyDefId, 47 associated_type_shorthand_candidates, callable_item_sig, CallableDefId, ImplTraitLoweringMode,
49 TyLoweringContext, ValueTyDefId, 48 TyDefId, TyLoweringContext, ValueTyDefId,
50}; 49};
51pub use traits::{InEnvironment, Obligation, ProjectionPredicate, TraitEnvironment}; 50pub use traits::{InEnvironment, Obligation, ProjectionPredicate, TraitEnvironment};
52 51
@@ -824,6 +823,16 @@ impl Ty {
824 } 823 }
825 } 824 }
826 825
826 pub fn as_fn_def(&self) -> Option<FunctionId> {
827 match self {
828 &Ty::Apply(ApplicationTy {
829 ctor: TypeCtor::FnDef(CallableDefId::FunctionId(func)),
830 ..
831 }) => Some(func),
832 _ => None,
833 }
834 }
835
827 pub fn callable_sig(&self, db: &dyn HirDatabase) -> Option<FnSig> { 836 pub fn callable_sig(&self, db: &dyn HirDatabase) -> Option<FnSig> {
828 match self { 837 match self {
829 Ty::Apply(a_ty) => match a_ty.ctor { 838 Ty::Apply(a_ty) => match a_ty.ctor {