Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/tests/closure_captures.rs')
-rw-r--r--crates/hir-ty/src/tests/closure_captures.rs33
1 files changed, 30 insertions, 3 deletions
diff --git a/crates/hir-ty/src/tests/closure_captures.rs b/crates/hir-ty/src/tests/closure_captures.rs
index 8425c0dd89..8408c0a7bf 100644
--- a/crates/hir-ty/src/tests/closure_captures.rs
+++ b/crates/hir-ty/src/tests/closure_captures.rs
@@ -7,6 +7,7 @@ use syntax::{AstNode, AstPtr};
use test_fixture::WithFixture;
use crate::{
+ InferenceResult,
db::HirDatabase,
display::{DisplayTarget, HirDisplay},
mir::MirSpan,
@@ -23,7 +24,7 @@ fn check_closure_captures(#[rust_analyzer::rust_fixture] ra_fixture: &str, expec
let def_map = module.def_map(&db);
let mut defs = Vec::new();
- visit_module(&db, def_map, module.local_id, &mut |it| defs.push(it));
+ visit_module(&db, def_map, module, &mut |it| defs.push(it));
let mut captures_info = Vec::new();
for def in defs {
@@ -34,7 +35,7 @@ fn check_closure_captures(#[rust_analyzer::rust_fixture] ra_fixture: &str, expec
hir_def::ModuleDefId::StaticId(it) => it.into(),
_ => continue,
};
- let infer = db.infer(def);
+ let infer = InferenceResult::for_body(&db, def);
let db = &db;
captures_info.extend(infer.closure_info.iter().flat_map(
|(closure_id, (captures, _))| {
@@ -73,8 +74,9 @@ fn check_closure_captures(#[rust_analyzer::rust_fixture] ra_fixture: &str, expec
let place = capture.display_place(closure.0, db);
let capture_ty = capture
.ty
+ .get()
.skip_binder()
- .display_test(db, DisplayTarget::from_crate(db, module.krate()))
+ .display_test(db, DisplayTarget::from_crate(db, module.krate(db)))
.to_string();
let spans = capture
.spans()
@@ -501,3 +503,28 @@ fn main() {
expect!["73..149;37..38;103..104 ByValue b Option<Box>"],
);
}
+
+#[test]
+fn alias_needs_to_be_normalized() {
+ check_closure_captures(
+ r#"
+//- minicore:copy
+trait Trait {
+ type Associated;
+}
+struct A;
+struct B { x: i32 }
+impl Trait for A {
+ type Associated = B;
+}
+struct C { b: <A as Trait>::Associated }
+fn main() {
+ let c: C = C { b: B { x: 1 } };
+ let closure = || {
+ let _move = c.b.x;
+ };
+}
+"#,
+ expect!["220..257;174..175;245..250 ByRef(Shared) c.b.x &'? i32"],
+ );
+}