Skip to content

Commit 39fe3a6

Browse files
committed
Test for non-working proc macro server assoc types
1 parent 14570df commit 39fe3a6

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

crates/ra_hir_ty/src/tests/traits.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,6 +1986,74 @@ fn test<I: Iterator<Item: Iterator<Item = u32>>>() {
19861986
assert_eq!(t, "u32");
19871987
}
19881988

1989+
#[test]
1990+
fn proc_macro_server_types() {
1991+
assert_snapshot!(
1992+
infer_with_mismatches(r#"
1993+
macro_rules! with_api {
1994+
($S:ident, $self:ident, $m:ident) => {
1995+
$m! {
1996+
TokenStream {
1997+
fn new() -> $S::TokenStream;
1998+
},
1999+
Group {
2000+
},
2001+
}
2002+
};
2003+
}
2004+
macro_rules! associated_item {
2005+
(type TokenStream) =>
2006+
(type TokenStream: 'static + Clone;);
2007+
(type Group) =>
2008+
(type Group: 'static + Clone;);
2009+
($($item:tt)*) => ($($item)*;)
2010+
}
2011+
macro_rules! declare_server_traits {
2012+
($($name:ident {
2013+
$(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)?;)*
2014+
}),* $(,)?) => {
2015+
pub trait Types {
2016+
$(associated_item!(type $name);)*
2017+
}
2018+
2019+
$(pub trait $name: Types {
2020+
$(associated_item!(fn $method(&mut self, $($arg: $arg_ty),*) $(-> $ret_ty)?);)*
2021+
})*
2022+
2023+
pub trait Server: Types $(+ $name)* {}
2024+
impl<S: Types $(+ $name)*> Server for S {}
2025+
}
2026+
}
2027+
with_api!(Self, self_, declare_server_traits);
2028+
struct Group {}
2029+
struct TokenStream {}
2030+
struct Rustc;
2031+
impl Types for Rustc {
2032+
type TokenStream = TokenStream;
2033+
type Group = Group;
2034+
}
2035+
fn make<T>() -> T { loop {} }
2036+
impl TokenStream for Rustc {
2037+
fn new() -> Self::TokenStream {
2038+
let group: Self::Group = make();
2039+
make()
2040+
}
2041+
}
2042+
"#, true),
2043+
@r###"
2044+
[1115; 1126) '{ loop {} }': T
2045+
[1117; 1124) 'loop {}': !
2046+
[1122; 1124) '{}': ()
2047+
[1190; 1253) '{ ... }': {unknown}
2048+
[1204; 1209) 'group': {unknown}
2049+
[1225; 1229) 'make': fn make<{unknown}>() -> {unknown}
2050+
[1225; 1231) 'make()': {unknown}
2051+
[1241; 1245) 'make': fn make<{unknown}>() -> {unknown}
2052+
[1241; 1247) 'make()': {unknown}
2053+
"###
2054+
);
2055+
}
2056+
19892057
#[test]
19902058
fn unify_impl_trait() {
19912059
assert_snapshot!(

0 commit comments

Comments
 (0)