aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src')
-rw-r--r--crates/hir_ty/src/diagnostics/decl_check.rs11
-rw-r--r--crates/hir_ty/src/infer/path.rs2
-rw-r--r--crates/hir_ty/src/method_resolution.rs2
-rw-r--r--crates/hir_ty/src/tests.rs20
-rw-r--r--crates/hir_ty/src/tests/traits.rs33
-rw-r--r--crates/hir_ty/src/utils.rs2
6 files changed, 58 insertions, 12 deletions
diff --git a/crates/hir_ty/src/diagnostics/decl_check.rs b/crates/hir_ty/src/diagnostics/decl_check.rs
index e230f9765..3605ca581 100644
--- a/crates/hir_ty/src/diagnostics/decl_check.rs
+++ b/crates/hir_ty/src/diagnostics/decl_check.rs
@@ -99,9 +99,14 @@ impl<'a, 'b> DeclValidator<'a, 'b> {
99 let body = self.db.body(func.into()); 99 let body = self.db.body(func.into());
100 100
101 // Recursively validate inner scope items, such as static variables and constants. 101 // Recursively validate inner scope items, such as static variables and constants.
102 for (item_id, _) in body.item_scope.values() { 102 let db = self.db;
103 let mut validator = DeclValidator::new(self.db, self.krate, self.sink); 103 for block_def_map in body.block_scopes.iter().filter_map(|block| db.block_def_map(*block)) {
104 validator.validate_item(item_id); 104 for (_, module) in block_def_map.modules() {
105 for (def_id, _) in module.scope.values() {
106 let mut validator = DeclValidator::new(self.db, self.krate, self.sink);
107 validator.validate_item(def_id);
108 }
109 }
105 } 110 }
106 111
107 // Check whether non-snake case identifiers are allowed for this function. 112 // Check whether non-snake case identifiers are allowed for this function.
diff --git a/crates/hir_ty/src/infer/path.rs b/crates/hir_ty/src/infer/path.rs
index 5d541104e..ae3554bac 100644
--- a/crates/hir_ty/src/infer/path.rs
+++ b/crates/hir_ty/src/infer/path.rs
@@ -260,7 +260,7 @@ impl<'a> InferenceContext<'a> {
260 })); 260 }));
261 Some(trait_substs) 261 Some(trait_substs)
262 } 262 }
263 AssocContainerId::ContainerId(_) => None, 263 AssocContainerId::ModuleId(_) => None,
264 }; 264 };
265 265
266 self.write_assoc_resolution(id, item); 266 self.write_assoc_resolution(id, item);
diff --git a/crates/hir_ty/src/method_resolution.rs b/crates/hir_ty/src/method_resolution.rs
index 24db33c49..248367267 100644
--- a/crates/hir_ty/src/method_resolution.rs
+++ b/crates/hir_ty/src/method_resolution.rs
@@ -715,7 +715,7 @@ fn transform_receiver_ty(
715 .fill_with_unknown() 715 .fill_with_unknown()
716 .build() 716 .build()
717 } 717 }
718 AssocContainerId::ContainerId(_) => unreachable!(), 718 AssocContainerId::ModuleId(_) => unreachable!(),
719 }; 719 };
720 let sig = db.callable_item_signature(function_id.into()); 720 let sig = db.callable_item_signature(function_id.into());
721 Some(sig.value.params()[0].clone().subst_bound_vars(&substs)) 721 Some(sig.value.params()[0].clone().subst_bound_vars(&substs))
diff --git a/crates/hir_ty/src/tests.rs b/crates/hir_ty/src/tests.rs
index 7386a4e7b..fc770ea60 100644
--- a/crates/hir_ty/src/tests.rs
+++ b/crates/hir_ty/src/tests.rs
@@ -13,7 +13,7 @@ use std::{env, sync::Arc};
13use base_db::{fixture::WithFixture, FileRange, SourceDatabase, SourceDatabaseExt}; 13use base_db::{fixture::WithFixture, FileRange, SourceDatabase, SourceDatabaseExt};
14use expect_test::Expect; 14use expect_test::Expect;
15use hir_def::{ 15use hir_def::{
16 body::{BodySourceMap, SyntheticSyntax}, 16 body::{Body, BodySourceMap, SyntheticSyntax},
17 child_by_source::ChildBySource, 17 child_by_source::ChildBySource,
18 db::DefDatabase, 18 db::DefDatabase,
19 item_scope::ItemScope, 19 item_scope::ItemScope,
@@ -234,13 +234,13 @@ fn visit_module(
234 let def = it.into(); 234 let def = it.into();
235 cb(def); 235 cb(def);
236 let body = db.body(def); 236 let body = db.body(def);
237 visit_scope(db, crate_def_map, &body.item_scope, cb); 237 visit_body(db, &body, cb);
238 } 238 }
239 AssocItemId::ConstId(it) => { 239 AssocItemId::ConstId(it) => {
240 let def = it.into(); 240 let def = it.into();
241 cb(def); 241 cb(def);
242 let body = db.body(def); 242 let body = db.body(def);
243 visit_scope(db, crate_def_map, &body.item_scope, cb); 243 visit_body(db, &body, cb);
244 } 244 }
245 AssocItemId::TypeAliasId(_) => (), 245 AssocItemId::TypeAliasId(_) => (),
246 } 246 }
@@ -259,19 +259,19 @@ fn visit_module(
259 let def = it.into(); 259 let def = it.into();
260 cb(def); 260 cb(def);
261 let body = db.body(def); 261 let body = db.body(def);
262 visit_scope(db, crate_def_map, &body.item_scope, cb); 262 visit_body(db, &body, cb);
263 } 263 }
264 ModuleDefId::ConstId(it) => { 264 ModuleDefId::ConstId(it) => {
265 let def = it.into(); 265 let def = it.into();
266 cb(def); 266 cb(def);
267 let body = db.body(def); 267 let body = db.body(def);
268 visit_scope(db, crate_def_map, &body.item_scope, cb); 268 visit_body(db, &body, cb);
269 } 269 }
270 ModuleDefId::StaticId(it) => { 270 ModuleDefId::StaticId(it) => {
271 let def = it.into(); 271 let def = it.into();
272 cb(def); 272 cb(def);
273 let body = db.body(def); 273 let body = db.body(def);
274 visit_scope(db, crate_def_map, &body.item_scope, cb); 274 visit_body(db, &body, cb);
275 } 275 }
276 ModuleDefId::TraitId(it) => { 276 ModuleDefId::TraitId(it) => {
277 let trait_data = db.trait_data(it); 277 let trait_data = db.trait_data(it);
@@ -288,6 +288,14 @@ fn visit_module(
288 } 288 }
289 } 289 }
290 } 290 }
291
292 fn visit_body(db: &TestDB, body: &Body, cb: &mut dyn FnMut(DefWithBodyId)) {
293 for def_map in body.block_scopes.iter().filter_map(|block| db.block_def_map(*block)) {
294 for (mod_id, _) in def_map.modules() {
295 visit_module(db, &def_map, mod_id, cb);
296 }
297 }
298 }
291} 299}
292 300
293fn ellipsize(mut text: String, max_len: usize) -> String { 301fn ellipsize(mut text: String, max_len: usize) -> String {
diff --git a/crates/hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs
index 528092082..e185b1c0a 100644
--- a/crates/hir_ty/src/tests/traits.rs
+++ b/crates/hir_ty/src/tests/traits.rs
@@ -3174,6 +3174,39 @@ fn f() {
3174} 3174}
3175 3175
3176#[test] 3176#[test]
3177fn trait_in_scope_with_inner_item() {
3178 check_infer(
3179 r#"
3180mod m {
3181 pub trait Tr {
3182 fn method(&self) -> u8 { 0 }
3183 }
3184
3185 impl Tr for () {}
3186}
3187
3188use m::Tr;
3189
3190fn f() {
3191 fn inner() {
3192 ().method();
3193 //^^^^^^^^^^^ u8
3194 }
3195}
3196 "#,
3197 expect![[r#"
3198 46..50 'self': &Self
3199 58..63 '{ 0 }': u8
3200 60..61 '0': u8
3201 115..185 '{ ... } }': ()
3202 132..183 '{ ... }': ()
3203 142..144 '()': ()
3204 142..153 '().method()': u8
3205 "#]],
3206 );
3207}
3208
3209#[test]
3177fn inner_use_in_block() { 3210fn inner_use_in_block() {
3178 check_types( 3211 check_types(
3179 r#" 3212 r#"
diff --git a/crates/hir_ty/src/utils.rs b/crates/hir_ty/src/utils.rs
index 65b79df0d..7351e4e54 100644
--- a/crates/hir_ty/src/utils.rs
+++ b/crates/hir_ty/src/utils.rs
@@ -259,6 +259,6 @@ fn parent_generic_def(db: &dyn DefDatabase, def: GenericDefId) -> Option<Generic
259 match container { 259 match container {
260 AssocContainerId::ImplId(it) => Some(it.into()), 260 AssocContainerId::ImplId(it) => Some(it.into()),
261 AssocContainerId::TraitId(it) => Some(it.into()), 261 AssocContainerId::TraitId(it) => Some(it.into()),
262 AssocContainerId::ContainerId(_) => None, 262 AssocContainerId::ModuleId(_) => None,
263 } 263 }
264} 264}