mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-06 20:28:33 +00:00
Classify function calls as functions when shadowed by types
This commit is contained in:
parent
f421ee6722
commit
426ad8e165
@ -224,14 +224,18 @@ impl SourceAnalyzer {
|
|||||||
) -> Option<PathResolution> {
|
) -> Option<PathResolution> {
|
||||||
if let Some(path_expr) = path.syntax().parent().and_then(ast::PathExpr::cast) {
|
if let Some(path_expr) = path.syntax().parent().and_then(ast::PathExpr::cast) {
|
||||||
let expr_id = self.expr_id(db, &path_expr.into())?;
|
let expr_id = self.expr_id(db, &path_expr.into())?;
|
||||||
if let Some(assoc) = self.infer.as_ref()?.assoc_resolutions_for_expr(expr_id) {
|
let infer = self.infer.as_ref()?;
|
||||||
|
if let Some(assoc) = infer.assoc_resolutions_for_expr(expr_id) {
|
||||||
return Some(PathResolution::AssocItem(assoc.into()));
|
return Some(PathResolution::AssocItem(assoc.into()));
|
||||||
}
|
}
|
||||||
if let Some(VariantId::EnumVariantId(variant)) =
|
if let Some(VariantId::EnumVariantId(variant)) =
|
||||||
self.infer.as_ref()?.variant_resolution_for_expr(expr_id)
|
infer.variant_resolution_for_expr(expr_id)
|
||||||
{
|
{
|
||||||
return Some(PathResolution::Def(ModuleDef::Variant(variant.into())));
|
return Some(PathResolution::Def(ModuleDef::Variant(variant.into())));
|
||||||
}
|
}
|
||||||
|
if let Some(func) = infer[expr_id].as_fn_def() {
|
||||||
|
return Some(PathResolution::Def(ModuleDef::Function(func.into())));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(path_pat) = path.syntax().parent().and_then(ast::PathPat::cast) {
|
if let Some(path_pat) = path.syntax().parent().and_then(ast::PathPat::cast) {
|
||||||
|
@ -12,8 +12,7 @@ use hir_def::{
|
|||||||
use hir_expand::diagnostics::DiagnosticSink;
|
use hir_expand::diagnostics::DiagnosticSink;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
db::HirDatabase, diagnostics::MissingUnsafe, lower::CallableDefId, ApplicationTy,
|
db::HirDatabase, diagnostics::MissingUnsafe, ApplicationTy, InferenceResult, Ty, TypeCtor,
|
||||||
InferenceResult, Ty, TypeCtor,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(super) struct UnsafeValidator<'a, 'b: 'a> {
|
pub(super) struct UnsafeValidator<'a, 'b: 'a> {
|
||||||
@ -87,13 +86,8 @@ fn walk_unsafe(
|
|||||||
) {
|
) {
|
||||||
let expr = &body.exprs[current];
|
let expr = &body.exprs[current];
|
||||||
match expr {
|
match expr {
|
||||||
Expr::Call { callee, .. } => {
|
&Expr::Call { callee, .. } => {
|
||||||
let ty = &infer[*callee];
|
if let Some(func) = infer[callee].as_fn_def() {
|
||||||
if let &Ty::Apply(ApplicationTy {
|
|
||||||
ctor: TypeCtor::FnDef(CallableDefId::FunctionId(func)),
|
|
||||||
..
|
|
||||||
}) = ty
|
|
||||||
{
|
|
||||||
if db.function_data(func).is_unsafe {
|
if db.function_data(func).is_unsafe {
|
||||||
unsafe_exprs.push(UnsafeExpr { expr: current, inside_unsafe_block });
|
unsafe_exprs.push(UnsafeExpr { expr: current, inside_unsafe_block });
|
||||||
}
|
}
|
||||||
|
@ -29,8 +29,8 @@ use base_db::{salsa, CrateId};
|
|||||||
use hir_def::{
|
use hir_def::{
|
||||||
expr::ExprId,
|
expr::ExprId,
|
||||||
type_ref::{Mutability, Rawness},
|
type_ref::{Mutability, Rawness},
|
||||||
AdtId, AssocContainerId, DefWithBodyId, GenericDefId, HasModule, LifetimeParamId, Lookup,
|
AdtId, AssocContainerId, DefWithBodyId, FunctionId, GenericDefId, HasModule, LifetimeParamId,
|
||||||
TraitId, TypeAliasId, TypeParamId,
|
Lookup, TraitId, TypeAliasId, TypeParamId,
|
||||||
};
|
};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
|
||||||
@ -43,10 +43,9 @@ use crate::{
|
|||||||
|
|
||||||
pub use autoderef::autoderef;
|
pub use autoderef::autoderef;
|
||||||
pub use infer::{InferTy, InferenceResult};
|
pub use infer::{InferTy, InferenceResult};
|
||||||
pub use lower::CallableDefId;
|
|
||||||
pub use lower::{
|
pub use lower::{
|
||||||
associated_type_shorthand_candidates, callable_item_sig, ImplTraitLoweringMode, TyDefId,
|
associated_type_shorthand_candidates, callable_item_sig, CallableDefId, ImplTraitLoweringMode,
|
||||||
TyLoweringContext, ValueTyDefId,
|
TyDefId, TyLoweringContext, ValueTyDefId,
|
||||||
};
|
};
|
||||||
pub use traits::{InEnvironment, Obligation, ProjectionPredicate, TraitEnvironment};
|
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> {
|
pub fn callable_sig(&self, db: &dyn HirDatabase) -> Option<FnSig> {
|
||||||
match self {
|
match self {
|
||||||
Ty::Apply(a_ty) => match a_ty.ctor {
|
Ty::Apply(a_ty) => match a_ty.ctor {
|
||||||
|
@ -108,6 +108,10 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
|||||||
<span class="brace">}</span>
|
<span class="brace">}</span>
|
||||||
<span class="brace">}</span>
|
<span class="brace">}</span>
|
||||||
|
|
||||||
|
<span class="keyword">fn</span> <span class="function declaration">str</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span>
|
||||||
|
<span class="function">str</span><span class="parenthesis">(</span><span class="parenthesis">)</span><span class="semicolon">;</span>
|
||||||
|
<span class="brace">}</span>
|
||||||
|
|
||||||
<span class="keyword">static</span> <span class="keyword">mut</span> <span class="static declaration mutable unsafe">STATIC_MUT</span><span class="colon">:</span> <span class="builtin_type">i32</span> <span class="operator">=</span> <span class="numeric_literal">0</span><span class="semicolon">;</span>
|
<span class="keyword">static</span> <span class="keyword">mut</span> <span class="static declaration mutable unsafe">STATIC_MUT</span><span class="colon">:</span> <span class="builtin_type">i32</span> <span class="operator">=</span> <span class="numeric_literal">0</span><span class="semicolon">;</span>
|
||||||
|
|
||||||
<span class="keyword">fn</span> <span class="function declaration">foo</span><span class="angle"><</span><span class="lifetime declaration">'a</span><span class="comma">,</span> <span class="type_param declaration">T</span><span class="angle">></span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="type_param">T</span> <span class="brace">{</span>
|
<span class="keyword">fn</span> <span class="function declaration">foo</span><span class="angle"><</span><span class="lifetime declaration">'a</span><span class="comma">,</span> <span class="type_param declaration">T</span><span class="angle">></span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="type_param">T</span> <span class="brace">{</span>
|
||||||
|
@ -81,6 +81,10 @@ impl FooCopy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn str() {
|
||||||
|
str();
|
||||||
|
}
|
||||||
|
|
||||||
static mut STATIC_MUT: i32 = 0;
|
static mut STATIC_MUT: i32 = 0;
|
||||||
|
|
||||||
fn foo<'a, T>() -> T {
|
fn foo<'a, T>() -> T {
|
||||||
|
Loading…
Reference in New Issue
Block a user