#![feature(rustc_private, plugin, box_syntax)] #![plugin(cg)] extern crate rustc; #[macro_use] extern crate syntax; use syntax::ext::deriving::generic::ty; macro_rules! pathvec { ($($x:ident)::+) => ( vec![ $( stringify!($x) ),+ ] ) } macro_rules! path { ($($x:tt)*) => { ::syntax::ext::deriving::generic::ty::Path::new( pathvec!( $($x)* ) ) } } macro_rules! path_local { ($x:ident) => ( ::syntax::ext::deriving::generic::ty::Path::new_local(stringify!($x)) ) } macro_rules! path_std { ($($x:tt)*) => ( ::syntax::ext::deriving::generic::ty::Path::new( pathvec_std!( $($x)* ) ) ) } macro_rules! pathvec_std { ($cx:expr, $first:ident :: $($rest:ident)::+) => ( if $cx.use_std { pathvec!(std :: $($rest)::+) } else { pathvec!($first :: $($rest)::+) } ) } #[allow(dead_code)] struct TestStruct<'a, 'b> { a: &'a str, b: &'b str, } #[allow(dead_code)] struct TT<'a> { a: &'a str } #[allow(dead_code)] trait TTT<'a> { } impl<'a> TTT<'a> for TT<'a>{ } #[allow(dead_code)] struct Test2<'a, 'b, T: 'a + TTT<'a>> { a: &'a str, b: &'b str, t: &'a T } #[test] fn path() { let tt_path = ty::Path::new_(vec!["TestStruct"],Some("'c,'d"), vec![],false); assert!(ext_path!(TestStruct<'c, 'd>) == tt_path); let tt_ty = ty::Ty::Literal(tt_path); assert!(ext_ty!(TestStruct<'c, 'd>) == tt_ty); let expected = ty::Path::new_(vec!["std", "core", "option", "Option"], None, vec![box tt_ty], false ); let p: ty::Path = ext_path!(std::core::option::Option>); assert!(p == expected); } #[test] fn path2() { let ttt_ty = ty::Ty::Literal(ty::Path::new_(vec!["TTT"], Some("'a"), vec![],false)); assert!(ext_ty!(TTT<'a>) == ttt_ty); let test2_ty = ty::Ty::Literal(ty::Path::new_(vec!["Test2"],Some("'c,'d"), vec![box ttt_ty],false)); assert!(ext_ty!(Test2<'c, 'd, TTT<'a>>) == test2_ty); let expected = ty::Path::new_(vec!["std", "core", "option", "Option"], None, vec![box test2_ty], false); let p: ty::Path = ext_path!(std::core::option::Option>>); assert!(p == expected); }