]> git.lizzy.rs Git - rust.git/commitdiff
Add test
authorEdwin Cheng <edwin0cheng@gmail.com>
Thu, 30 Apr 2020 10:12:52 +0000 (18:12 +0800)
committerEdwin Cheng <edwin0cheng@gmail.com>
Fri, 1 May 2020 12:01:17 +0000 (20:01 +0800)
crates/ra_hir_ty/src/tests/macros.rs

index 5ddecbdc6808bb728402d565f7a07c5e5ae03dc7..1f796876da2cc8a01e936b7ae2acc9d387078e20 100644 (file)
@@ -338,6 +338,46 @@ pub fn baz() -> usize { 31usize }
     assert_eq!("(i32, usize)", type_at_pos(&db, pos));
 }
 
+#[test]
+fn infer_macro_with_dollar_crate_is_correct_in_trait_associate_type() {
+    let (db, pos) = TestDB::with_position(
+        r#"
+//- /main.rs crate:main deps:foo
+use foo::Trait;
+
+fn test() {
+    let msg = foo::Message(foo::MessageRef);
+    let r = msg.deref();
+    r<|>;
+}
+
+//- /lib.rs crate:foo
+pub struct MessageRef;
+pub struct Message(MessageRef);
+
+pub trait Trait {
+    type Target;
+    fn deref(&self) -> &Self::Target;
+}
+
+#[macro_export]
+macro_rules! expand {
+    () => {
+        impl Trait for Message {
+            type Target = $crate::MessageRef;
+            fn deref(&self) ->  &Self::Target {
+                &self.0
+            }
+        }
+    }
+}
+
+expand!();
+"#,
+    );
+    assert_eq!("&MessageRef", type_at_pos(&db, pos));
+}
+
 #[test]
 fn infer_type_value_non_legacy_macro_use_as() {
     assert_snapshot!(