From 944f71afc692733cbc151bb3113d45a8159de132 Mon Sep 17 00:00:00 2001 From: Unreal Hoang Date: Tue, 9 Jul 2019 00:02:15 +0900 Subject: projection over std::ops::Try::Ok to infer try/? --- crates/ra_hir/src/ty/tests.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 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 fe5e89f2d..d5c03c4bc 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_try() { + let (mut db, pos) = MockDatabase::with_position( + r#" +//- /main.rs +enum Result { + Ok(O), + Err(E) +} + +impl ::std::ops::Try for Result { + type Ok = O; + type Error = E; +} +fn test() { + let r: Result = Result::Ok(1); + let v = r?; + v<|>; +} + +//- /lib.rs +mod ops { + trait Try { + type Ok; + type Error; + } +} +"#, + ); + db.set_crate_graph_from_fixture(crate_graph! { + "main": ("/main.rs", ["std"]), + "std": ("/lib.rs", []), + }); + assert_eq!("i32", type_at_pos(&db, pos)); +} + #[test] fn infer_for_loop() { let (mut db, pos) = MockDatabase::with_position( @@ -56,6 +92,7 @@ mod iter { }); assert_eq!("&str", type_at_pos(&db, pos)); } + #[test] fn infer_basics() { assert_snapshot_matches!( -- cgit v1.2.3