From f7cd40d8306dfd3f2c55ad97de5167319350a592 Mon Sep 17 00:00:00 2001 From: Unreal Hoang Date: Sun, 7 Jul 2019 16:31:09 +0900 Subject: add projection to infer for loop variable --- crates/ra_hir/src/ty/tests.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'crates/ra_hir/src/ty/tests.rs') diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index aacd94a26..fe5e89f2d 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs @@ -20,6 +20,42 @@ use crate::{ // against snapshots of the expected results using insta. Use cargo-insta to // update the snapshots. +#[test] +fn infer_for_loop() { + let (mut db, pos) = MockDatabase::with_position( + r#" +//- /main.rs +struct Vec {} +impl Vec { + fn new() -> Self { Vec {} } + fn push(&mut self, t: T) { } +} + +impl ::std::iter::IntoIterator for Vec { + type Item=T; +} +fn test() { + let v = Vec::new(); + v.push("foo"); + for x in v { + x<|>; + } +} + +//- /lib.rs +mod iter { + trait IntoIterator { + type Item; + } +} +"#, + ); + db.set_crate_graph_from_fixture(crate_graph! { + "main": ("/main.rs", ["std"]), + "std": ("/lib.rs", []), + }); + assert_eq!("&str", type_at_pos(&db, pos)); +} #[test] fn infer_basics() { assert_snapshot_matches!( -- cgit v1.2.3