diff --git a/src/libsyntax/ext/deriving/clone.rs b/src/libsyntax/ext/deriving/clone.rs index 6eb18e290238e..847af6427ef35 100644 --- a/src/libsyntax/ext/deriving/clone.rs +++ b/src/libsyntax/ext/deriving/clone.rs @@ -29,7 +29,7 @@ pub fn expand_deriving_clone(cx: &mut ExtCtxt, let trait_def = TraitDef { span: span, attributes: Vec::new(), - path: Path::new(vec!("std", "clone", "Clone")), + path: path!(std::clone::Clone), additional_bounds: Vec::new(), generics: LifetimeBounds::empty(), methods: vec!( diff --git a/src/libsyntax/ext/deriving/cmp/eq.rs b/src/libsyntax/ext/deriving/cmp/eq.rs index 00971b96e9288..65c164fc9a159 100644 --- a/src/libsyntax/ext/deriving/cmp/eq.rs +++ b/src/libsyntax/ext/deriving/cmp/eq.rs @@ -70,7 +70,7 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt, generics: LifetimeBounds::empty(), explicit_self: borrowed_explicit_self(), args: vec!(borrowed_self()), - ret_ty: Literal(Path::new(vec!("bool"))), + ret_ty: Literal(path!(bool)), attributes: attrs, combine_substructure: combine_substructure(box |a, b, c| { $f(a, b, c) @@ -82,7 +82,7 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt, let trait_def = TraitDef { span: span, attributes: Vec::new(), - path: Path::new(vec!("std", "cmp", "PartialEq")), + path: path!(std::cmp::PartialEq), additional_bounds: Vec::new(), generics: LifetimeBounds::empty(), methods: vec!( diff --git a/src/libsyntax/ext/deriving/cmp/ord.rs b/src/libsyntax/ext/deriving/cmp/ord.rs index 1f92f8d7b372a..8a706e5c46d64 100644 --- a/src/libsyntax/ext/deriving/cmp/ord.rs +++ b/src/libsyntax/ext/deriving/cmp/ord.rs @@ -36,7 +36,7 @@ pub fn expand_deriving_ord(cx: &mut ExtCtxt, generics: LifetimeBounds::empty(), explicit_self: borrowed_explicit_self(), args: vec!(borrowed_self()), - ret_ty: Literal(Path::new(vec!("bool"))), + ret_ty: Literal(path!(bool)), attributes: attrs, combine_substructure: combine_substructure(box |cx, span, substr| { cs_op($op, $equal, cx, span, substr) @@ -45,8 +45,8 @@ pub fn expand_deriving_ord(cx: &mut ExtCtxt, } } } - let ordering_ty = Literal(Path::new(vec!["std", "cmp", "Ordering"])); - let ret_ty = Literal(Path::new_(vec!["std", "option", "Option"], + let ordering_ty = Literal(path!(std::cmp::Ordering)); + let ret_ty = Literal(Path::new_(pathvec!(std::option::Option), None, vec![box ordering_ty], true)); @@ -69,7 +69,7 @@ pub fn expand_deriving_ord(cx: &mut ExtCtxt, let trait_def = TraitDef { span: span, attributes: vec![], - path: Path::new(vec!["std", "cmp", "PartialOrd"]), + path: path!(std::cmp::PartialOrd), additional_bounds: vec![], generics: LifetimeBounds::empty(), methods: vec![ diff --git a/src/libsyntax/ext/deriving/cmp/totaleq.rs b/src/libsyntax/ext/deriving/cmp/totaleq.rs index 0429db3643bb1..9efae379e1f0f 100644 --- a/src/libsyntax/ext/deriving/cmp/totaleq.rs +++ b/src/libsyntax/ext/deriving/cmp/totaleq.rs @@ -46,7 +46,7 @@ pub fn expand_deriving_totaleq(cx: &mut ExtCtxt, let trait_def = TraitDef { span: span, attributes: Vec::new(), - path: Path::new(vec!("std", "cmp", "Eq")), + path: path!(std::cmp::Eq), additional_bounds: Vec::new(), generics: LifetimeBounds::empty(), methods: vec!( diff --git a/src/libsyntax/ext/deriving/cmp/totalord.rs b/src/libsyntax/ext/deriving/cmp/totalord.rs index e90c1aa6fcee8..7a4b717e817fc 100644 --- a/src/libsyntax/ext/deriving/cmp/totalord.rs +++ b/src/libsyntax/ext/deriving/cmp/totalord.rs @@ -30,7 +30,7 @@ pub fn expand_deriving_totalord(cx: &mut ExtCtxt, let trait_def = TraitDef { span: span, attributes: Vec::new(), - path: Path::new(vec!("std", "cmp", "Ord")), + path: path!(std::cmp::Ord), additional_bounds: Vec::new(), generics: LifetimeBounds::empty(), methods: vec!( @@ -39,7 +39,7 @@ pub fn expand_deriving_totalord(cx: &mut ExtCtxt, generics: LifetimeBounds::empty(), explicit_self: borrowed_explicit_self(), args: vec!(borrowed_self()), - ret_ty: Literal(Path::new(vec!("std", "cmp", "Ordering"))), + ret_ty: Literal(path!(std::cmp::Ordering)), attributes: attrs, combine_substructure: combine_substructure(box |a, b, c| { cs_cmp(a, b, c) diff --git a/src/libsyntax/ext/deriving/decodable.rs b/src/libsyntax/ext/deriving/decodable.rs index 9552dff941d27..e7ef2ff060641 100644 --- a/src/libsyntax/ext/deriving/decodable.rs +++ b/src/libsyntax/ext/deriving/decodable.rs @@ -68,7 +68,7 @@ fn expand_deriving_decodable_imp(cx: &mut ExtCtxt, args: vec!(Ptr(box Literal(Path::new_local("__D")), Borrowed(None, MutMutable))), ret_ty: Literal(Path::new_( - vec!("std", "result", "Result"), + pathvec!(std::result::Result), None, vec!(box Self, box Literal(Path::new_( vec!["__D", "Error"], None, vec![], false diff --git a/src/libsyntax/ext/deriving/default.rs b/src/libsyntax/ext/deriving/default.rs index df5e1863d551d..8f210779d3d13 100644 --- a/src/libsyntax/ext/deriving/default.rs +++ b/src/libsyntax/ext/deriving/default.rs @@ -29,7 +29,7 @@ pub fn expand_deriving_default(cx: &mut ExtCtxt, let trait_def = TraitDef { span: span, attributes: Vec::new(), - path: Path::new(vec!("std", "default", "Default")), + path: path!(std::default::Default), additional_bounds: Vec::new(), generics: LifetimeBounds::empty(), methods: vec!( diff --git a/src/libsyntax/ext/deriving/encodable.rs b/src/libsyntax/ext/deriving/encodable.rs index d0b2c2faf3719..c3d42b6a4f7a7 100644 --- a/src/libsyntax/ext/deriving/encodable.rs +++ b/src/libsyntax/ext/deriving/encodable.rs @@ -144,7 +144,7 @@ fn expand_deriving_encodable_imp(cx: &mut ExtCtxt, args: vec!(Ptr(box Literal(Path::new_local("__S")), Borrowed(None, MutMutable))), ret_ty: Literal(Path::new_( - vec!("std", "result", "Result"), + pathvec!(std::result::Result), None, vec!(box Tuple(Vec::new()), box Literal(Path::new_( vec!["__S", "Error"], None, vec![], false diff --git a/src/libsyntax/ext/deriving/hash.rs b/src/libsyntax/ext/deriving/hash.rs index f8a7af3aa9170..2482ea4b7d40d 100644 --- a/src/libsyntax/ext/deriving/hash.rs +++ b/src/libsyntax/ext/deriving/hash.rs @@ -25,13 +25,13 @@ pub fn expand_deriving_hash(cx: &mut ExtCtxt, F: FnOnce(P), { - let path = Path::new_(vec!("std", "hash", "Hash"), None, + let path = Path::new_(pathvec!(std::hash::Hash), None, vec!(box Literal(Path::new_local("__S"))), true); let generics = LifetimeBounds { lifetimes: Vec::new(), bounds: vec!(("__S", - vec!(Path::new(vec!("std", "hash", "Writer")), - Path::new(vec!("std", "hash", "Hasher"))))), + vec!(path!(std::hash::Writer), + path!(std::hash::Hasher)))), }; let args = Path::new_local("__S"); let inline = cx.meta_word(span, InternedString::new("inline")); diff --git a/src/libsyntax/ext/deriving/mod.rs b/src/libsyntax/ext/deriving/mod.rs index 318b748ad7ff2..657ecc63a38dd 100644 --- a/src/libsyntax/ext/deriving/mod.rs +++ b/src/libsyntax/ext/deriving/mod.rs @@ -18,6 +18,18 @@ use ext::base::ExtCtxt; use codemap::Span; use ptr::P; +macro_rules! pathvec { + ($($x:ident)::+) => ( + vec![ $( stringify!($x) ),+ ] + ) +} + +macro_rules! path { + ($($x:tt)*) => ( + ::ext::deriving::generic::ty::Path::new( pathvec!( $($x)* ) ) + ) +} + pub mod bounds; pub mod clone; pub mod encodable; diff --git a/src/libsyntax/ext/deriving/primitive.rs b/src/libsyntax/ext/deriving/primitive.rs index ae7b20f7853fb..3b5d483017f94 100644 --- a/src/libsyntax/ext/deriving/primitive.rs +++ b/src/libsyntax/ext/deriving/primitive.rs @@ -30,7 +30,7 @@ pub fn expand_deriving_from_primitive(cx: &mut ExtCtxt, let trait_def = TraitDef { span: span, attributes: Vec::new(), - path: Path::new(vec!("std", "num", "FromPrimitive")), + path: path!(std::num::FromPrimitive), additional_bounds: Vec::new(), generics: LifetimeBounds::empty(), methods: vec!( @@ -38,9 +38,8 @@ pub fn expand_deriving_from_primitive(cx: &mut ExtCtxt, name: "from_i64", generics: LifetimeBounds::empty(), explicit_self: None, - args: vec!( - Literal(Path::new(vec!("i64")))), - ret_ty: Literal(Path::new_(vec!("std", "option", "Option"), + args: vec!(Literal(path!(i64))), + ret_ty: Literal(Path::new_(pathvec!(std::option::Option), None, vec!(box Self), true)), @@ -54,9 +53,8 @@ pub fn expand_deriving_from_primitive(cx: &mut ExtCtxt, name: "from_u64", generics: LifetimeBounds::empty(), explicit_self: None, - args: vec!( - Literal(Path::new(vec!("u64")))), - ret_ty: Literal(Path::new_(vec!("std", "option", "Option"), + args: vec!(Literal(path!(u64))), + ret_ty: Literal(Path::new_(pathvec!(std::option::Option), None, vec!(box Self), true)), diff --git a/src/libsyntax/ext/deriving/rand.rs b/src/libsyntax/ext/deriving/rand.rs index c708a09b53c9b..84486f770fa17 100644 --- a/src/libsyntax/ext/deriving/rand.rs +++ b/src/libsyntax/ext/deriving/rand.rs @@ -31,7 +31,7 @@ pub fn expand_deriving_rand(cx: &mut ExtCtxt, let trait_def = TraitDef { span: span, attributes: Vec::new(), - path: Path::new(vec!("std", "rand", "Rand")), + path: path!(std::rand::Rand), additional_bounds: Vec::new(), generics: LifetimeBounds::empty(), methods: vec!( @@ -40,7 +40,7 @@ pub fn expand_deriving_rand(cx: &mut ExtCtxt, generics: LifetimeBounds { lifetimes: Vec::new(), bounds: vec!(("R", - vec!( Path::new(vec!("std", "rand", "Rng")) ))) + vec!( path!(std::rand::Rng) ))), }, explicit_self: None, args: vec!( diff --git a/src/libsyntax/ext/deriving/show.rs b/src/libsyntax/ext/deriving/show.rs index 821fdeaa86a1f..d12035193f839 100644 --- a/src/libsyntax/ext/deriving/show.rs +++ b/src/libsyntax/ext/deriving/show.rs @@ -29,13 +29,13 @@ pub fn expand_deriving_show(cx: &mut ExtCtxt, F: FnOnce(P), { // &mut ::std::fmt::Formatter - let fmtr = Ptr(box Literal(Path::new(vec!("std", "fmt", "Formatter"))), + let fmtr = Ptr(box Literal(path!(std::fmt::Formatter)), Borrowed(None, ast::MutMutable)); let trait_def = TraitDef { span: span, attributes: Vec::new(), - path: Path::new(vec!["std", "fmt", "Debug"]), + path: path!(std::fmt::Debug), additional_bounds: Vec::new(), generics: LifetimeBounds::empty(), methods: vec![ @@ -44,7 +44,7 @@ pub fn expand_deriving_show(cx: &mut ExtCtxt, generics: LifetimeBounds::empty(), explicit_self: borrowed_explicit_self(), args: vec!(fmtr), - ret_ty: Literal(Path::new(vec!("std", "fmt", "Result"))), + ret_ty: Literal(path!(std::fmt::Result)), attributes: Vec::new(), combine_substructure: combine_substructure(box |a, b, c| { show_substructure(a, b, c)