aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty
diff options
context:
space:
mode:
authorEdwin Cheng <[email protected]>2020-05-03 15:08:39 +0100
committerEdwin Cheng <[email protected]>2020-05-03 15:08:39 +0100
commit8b6216df05a1d17e58f789bbd323ce2679f9ab4a (patch)
tree73e62b8c63857249d2e0419ba0c38ebe67aefab8 /crates/ra_hir_ty
parent2474f42ae95bffea7c0bc713f92322bfec4d59a7 (diff)
Support macro for trait items
Diffstat (limited to 'crates/ra_hir_ty')
-rw-r--r--crates/ra_hir_ty/src/tests/traits.rs40
1 files changed, 21 insertions, 19 deletions
diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs
index e555c879a..23f682eff 100644
--- a/crates/ra_hir_ty/src/tests/traits.rs
+++ b/crates/ra_hir_ty/src/tests/traits.rs
@@ -2055,7 +2055,7 @@ fn test<I: Iterator<Item: Iterator<Item = u32>>>() {
2055#[test] 2055#[test]
2056fn proc_macro_server_types() { 2056fn proc_macro_server_types() {
2057 assert_snapshot!( 2057 assert_snapshot!(
2058 infer_with_mismatches(r#" 2058 infer(r#"
2059macro_rules! with_api { 2059macro_rules! with_api {
2060 ($S:ident, $self:ident, $m:ident) => { 2060 ($S:ident, $self:ident, $m:ident) => {
2061 $m! { 2061 $m! {
@@ -2069,9 +2069,9 @@ macro_rules! with_api {
2069} 2069}
2070macro_rules! associated_item { 2070macro_rules! associated_item {
2071 (type TokenStream) => 2071 (type TokenStream) =>
2072 (type TokenStream: 'static + Clone;); 2072 (type TokenStream: 'static;);
2073 (type Group) => 2073 (type Group) =>
2074 (type Group: 'static + Clone;); 2074 (type Group: 'static;);
2075 ($($item:tt)*) => ($($item)*;) 2075 ($($item:tt)*) => ($($item)*;)
2076} 2076}
2077macro_rules! declare_server_traits { 2077macro_rules! declare_server_traits {
@@ -2083,39 +2083,41 @@ macro_rules! declare_server_traits {
2083 } 2083 }
2084 2084
2085 $(pub trait $name: Types { 2085 $(pub trait $name: Types {
2086 $(associated_item!(fn $method(&mut self, $($arg: $arg_ty),*) $(-> $ret_ty)?);)* 2086 $(associated_item!(fn $method($($arg: $arg_ty),*) $(-> $ret_ty)?);)*
2087 })* 2087 })*
2088 2088
2089 pub trait Server: Types $(+ $name)* {} 2089 pub trait Server: Types $(+ $name)* {}
2090 impl<S: Types $(+ $name)*> Server for S {} 2090 impl<S: Types $(+ $name)*> Server for S {}
2091 } 2091 }
2092} 2092}
2093
2093with_api!(Self, self_, declare_server_traits); 2094with_api!(Self, self_, declare_server_traits);
2094struct Group {} 2095struct G {}
2095struct TokenStream {} 2096struct T {}
2096struct Rustc; 2097struct Rustc;
2097impl Types for Rustc { 2098impl Types for Rustc {
2098 type TokenStream = TokenStream; 2099 type TokenStream = T;
2099 type Group = Group; 2100 type Group = G;
2100} 2101}
2102
2101fn make<T>() -> T { loop {} } 2103fn make<T>() -> T { loop {} }
2102impl TokenStream for Rustc { 2104impl TokenStream for Rustc {
2103 fn new() -> Self::TokenStream { 2105 fn new() -> Self::TokenStream {
2104 let group: Self::Group = make(); 2106 let group: Self::Group = make();
2105 make() 2107 make()
2106 } 2108 }
2107} 2109}
2108"#, true), 2110"#),
2109 @r###" 2111 @r###"
2110 1115..1126 '{ loop {} }': T 2112 1062..1073 '{ loop {} }': T
2111 1117..1124 'loop {}': ! 2113 1064..1071 'loop {}': !
2112 1122..1124 '{}': () 2114 1069..1071 '{}': ()
2113 1190..1253 '{ ... }': {unknown} 2115 1137..1200 '{ ... }': T
2114 1204..1209 'group': {unknown} 2116 1151..1156 'group': G
2115 1225..1229 'make': fn make<{unknown}>() -> {unknown} 2117 1172..1176 'make': fn make<G>() -> G
2116 1225..1231 'make()': {unknown} 2118 1172..1178 'make()': G
2117 1241..1245 'make': fn make<{unknown}>() -> {unknown} 2119 1188..1192 'make': fn make<T>() -> T
2118 1241..1247 'make()': {unknown} 2120 1188..1194 'make()': T
2119 "### 2121 "###
2120 ); 2122 );
2121} 2123}