mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Classify function calls as functions when shadowed by types
This commit is contained in:
parent
f421ee6722
commit
426ad8e165
5 changed files with 31 additions and 16 deletions
|
@ -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 });
|
||||
}
|
||||
|
|
|
@ -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<FunctionId> {
|
||||
match self {
|
||||
&Ty::Apply(ApplicationTy {
|
||||
ctor: TypeCtor::FnDef(CallableDefId::FunctionId(func)),
|
||||
..
|
||||
}) => Some(func),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn callable_sig(&self, db: &dyn HirDatabase) -> Option<FnSig> {
|
||||
match self {
|
||||
Ty::Apply(a_ty) => match a_ty.ctor {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue