aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/hir/src/source_analyzer.rs8
-rw-r--r--crates/hir_ty/src/diagnostics/unsafe_check.rs12
-rw-r--r--crates/hir_ty/src/lib.rs19
-rw-r--r--crates/ide/src/syntax_highlighting/test_data/highlighting.html4
-rw-r--r--crates/ide/src/syntax_highlighting/tests.rs4
5 files changed, 31 insertions, 16 deletions
diff --git a/crates/hir/src/source_analyzer.rs b/crates/hir/src/source_analyzer.rs
index 30a8e513d..524120d08 100644
--- a/crates/hir/src/source_analyzer.rs
+++ b/crates/hir/src/source_analyzer.rs
@@ -224,14 +224,18 @@ impl SourceAnalyzer {
224 ) -> Option<PathResolution> { 224 ) -> Option<PathResolution> {
225 if let Some(path_expr) = path.syntax().parent().and_then(ast::PathExpr::cast) { 225 if let Some(path_expr) = path.syntax().parent().and_then(ast::PathExpr::cast) {
226 let expr_id = self.expr_id(db, &path_expr.into())?; 226 let expr_id = self.expr_id(db, &path_expr.into())?;
227 if let Some(assoc) = self.infer.as_ref()?.assoc_resolutions_for_expr(expr_id) { 227 let infer = self.infer.as_ref()?;
228 if let Some(assoc) = infer.assoc_resolutions_for_expr(expr_id) {
228 return Some(PathResolution::AssocItem(assoc.into())); 229 return Some(PathResolution::AssocItem(assoc.into()));
229 } 230 }
230 if let Some(VariantId::EnumVariantId(variant)) = 231 if let Some(VariantId::EnumVariantId(variant)) =
231 self.infer.as_ref()?.variant_resolution_for_expr(expr_id) 232 infer.variant_resolution_for_expr(expr_id)
232 { 233 {
233 return Some(PathResolution::Def(ModuleDef::Variant(variant.into()))); 234 return Some(PathResolution::Def(ModuleDef::Variant(variant.into())));
234 } 235 }
236 if let Some(func) = infer[expr_id].as_fn_def() {
237 return Some(PathResolution::Def(ModuleDef::Function(func.into())));
238 }
235 } 239 }
236 240
237 if let Some(path_pat) = path.syntax().parent().and_then(ast::PathPat::cast) { 241 if let Some(path_pat) = path.syntax().parent().and_then(ast::PathPat::cast) {
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 {
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlighting.html b/crates/ide/src/syntax_highlighting/test_data/highlighting.html
index 237149566..2f983c0b8 100644
--- a/crates/ide/src/syntax_highlighting/test_data/highlighting.html
+++ b/crates/ide/src/syntax_highlighting/test_data/highlighting.html
@@ -108,6 +108,10 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
108 <span class="brace">}</span> 108 <span class="brace">}</span>
109<span class="brace">}</span> 109<span class="brace">}</span>
110 110
111<span class="keyword">fn</span> <span class="function declaration">str</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span>
112 <span class="function">str</span><span class="parenthesis">(</span><span class="parenthesis">)</span><span class="semicolon">;</span>
113<span class="brace">}</span>
114
111<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> 115<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>
112 116
113<span class="keyword">fn</span> <span class="function declaration">foo</span><span class="angle">&lt;</span><span class="lifetime declaration">'a</span><span class="comma">,</span> <span class="type_param declaration">T</span><span class="angle">&gt;</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="operator">-&gt;</span> <span class="type_param">T</span> <span class="brace">{</span> 117<span class="keyword">fn</span> <span class="function declaration">foo</span><span class="angle">&lt;</span><span class="lifetime declaration">'a</span><span class="comma">,</span> <span class="type_param declaration">T</span><span class="angle">&gt;</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="operator">-&gt;</span> <span class="type_param">T</span> <span class="brace">{</span>
diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs
index a62704c39..1854da914 100644
--- a/crates/ide/src/syntax_highlighting/tests.rs
+++ b/crates/ide/src/syntax_highlighting/tests.rs
@@ -81,6 +81,10 @@ impl FooCopy {
81 } 81 }
82} 82}
83 83
84fn str() {
85 str();
86}
87
84static mut STATIC_MUT: i32 = 0; 88static mut STATIC_MUT: i32 = 0;
85 89
86fn foo<'a, T>() -> T { 90fn foo<'a, T>() -> T {