Skip to content

Commit b6f76b9

Browse files
author
Keegan McAllister
committed
Use a quote_path! helper macro in deriving
1 parent f1096c3 commit b6f76b9

File tree

14 files changed

+45
-35
lines changed

14 files changed

+45
-35
lines changed

src/libsyntax/ext/deriving/clone.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub fn expand_deriving_clone(cx: &mut ExtCtxt,
2727
let trait_def = TraitDef {
2828
span: span,
2929
attributes: Vec::new(),
30-
path: Path::new(vec!("std", "clone", "Clone")),
30+
path: quote_path!(std::clone::Clone),
3131
additional_bounds: Vec::new(),
3232
generics: LifetimeBounds::empty(),
3333
methods: vec!(

src/libsyntax/ext/deriving/cmp/eq.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt,
4242
generics: LifetimeBounds::empty(),
4343
explicit_self: borrowed_explicit_self(),
4444
args: vec!(borrowed_self()),
45-
ret_ty: Literal(Path::new(vec!("bool"))),
45+
ret_ty: Literal(quote_path!(bool)),
4646
attributes: attrs,
4747
combine_substructure: combine_substructure(|a, b, c| {
4848
$f(a, b, c)
@@ -54,7 +54,7 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt,
5454
let trait_def = TraitDef {
5555
span: span,
5656
attributes: Vec::new(),
57-
path: Path::new(vec!("std", "cmp", "PartialEq")),
57+
path: quote_path!(std::cmp::PartialEq),
5858
additional_bounds: Vec::new(),
5959
generics: LifetimeBounds::empty(),
6060
methods: vec!(

src/libsyntax/ext/deriving/cmp/ord.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub fn expand_deriving_ord(cx: &mut ExtCtxt,
3232
generics: LifetimeBounds::empty(),
3333
explicit_self: borrowed_explicit_self(),
3434
args: vec!(borrowed_self()),
35-
ret_ty: Literal(Path::new(vec!("bool"))),
35+
ret_ty: Literal(quote_path!(bool)),
3636
attributes: attrs,
3737
combine_substructure: combine_substructure(|cx, span, substr| {
3838
cs_op($op, $equal, cx, span, substr)
@@ -41,8 +41,8 @@ pub fn expand_deriving_ord(cx: &mut ExtCtxt,
4141
} }
4242
);
4343

44-
let ordering_ty = Literal(Path::new(vec!["std", "cmp", "Ordering"]));
45-
let ret_ty = Literal(Path::new_(vec!["std", "option", "Option"],
44+
let ordering_ty = Literal(quote_path!(std::cmp::Ordering));
45+
let ret_ty = Literal(Path::new_(quote_path_vec!(std::option::Option),
4646
None,
4747
vec![box ordering_ty],
4848
true));
@@ -65,7 +65,7 @@ pub fn expand_deriving_ord(cx: &mut ExtCtxt,
6565
let trait_def = TraitDef {
6666
span: span,
6767
attributes: vec![],
68-
path: Path::new(vec!["std", "cmp", "PartialOrd"]),
68+
path: quote_path!(std::cmp::PartialOrd),
6969
additional_bounds: vec![],
7070
generics: LifetimeBounds::empty(),
7171
methods: vec![

src/libsyntax/ext/deriving/cmp/totaleq.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub fn expand_deriving_totaleq(cx: &mut ExtCtxt,
4444
let trait_def = TraitDef {
4545
span: span,
4646
attributes: Vec::new(),
47-
path: Path::new(vec!("std", "cmp", "Eq")),
47+
path: quote_path!(std::cmp::Eq),
4848
additional_bounds: Vec::new(),
4949
generics: LifetimeBounds::empty(),
5050
methods: vec!(

src/libsyntax/ext/deriving/cmp/totalord.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub fn expand_deriving_totalord(cx: &mut ExtCtxt,
2828
let trait_def = TraitDef {
2929
span: span,
3030
attributes: Vec::new(),
31-
path: Path::new(vec!("std", "cmp", "Ord")),
31+
path: quote_path!(std::cmp::Ord),
3232
additional_bounds: Vec::new(),
3333
generics: LifetimeBounds::empty(),
3434
methods: vec!(
@@ -37,7 +37,7 @@ pub fn expand_deriving_totalord(cx: &mut ExtCtxt,
3737
generics: LifetimeBounds::empty(),
3838
explicit_self: borrowed_explicit_self(),
3939
args: vec!(borrowed_self()),
40-
ret_ty: Literal(Path::new(vec!("std", "cmp", "Ordering"))),
40+
ret_ty: Literal(quote_path!(std::cmp::Ordering)),
4141
attributes: attrs,
4242
combine_substructure: combine_substructure(|a, b, c| {
4343
cs_cmp(a, b, c)

src/libsyntax/ext/deriving/decodable.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ pub fn expand_deriving_decodable(cx: &mut ExtCtxt,
3131
let trait_def = TraitDef {
3232
span: span,
3333
attributes: Vec::new(),
34-
path: Path::new_(vec!("serialize", "Decodable"), None,
34+
path: Path::new_(quote_path_vec!(serialize::Decodable), None,
3535
vec!(box Literal(Path::new_local("__D")),
3636
box Literal(Path::new_local("__E"))), true),
3737
additional_bounds: Vec::new(),
3838
generics: LifetimeBounds {
3939
lifetimes: Vec::new(),
4040
bounds: vec!(("__D", None, vec!(Path::new_(
41-
vec!("serialize", "Decoder"), None,
41+
quote_path_vec!(serialize::Decoder), None,
4242
vec!(box Literal(Path::new_local("__E"))), true))),
4343
("__E", None, vec!()))
4444
},
@@ -49,7 +49,7 @@ pub fn expand_deriving_decodable(cx: &mut ExtCtxt,
4949
explicit_self: None,
5050
args: vec!(Ptr(box Literal(Path::new_local("__D")),
5151
Borrowed(None, MutMutable))),
52-
ret_ty: Literal(Path::new_(vec!("std", "result", "Result"), None,
52+
ret_ty: Literal(Path::new_(quote_path_vec!(std::result::Result), None,
5353
vec!(box Self,
5454
box Literal(Path::new_local("__E"))), true)),
5555
attributes: Vec::new(),

src/libsyntax/ext/deriving/default.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub fn expand_deriving_default(cx: &mut ExtCtxt,
2727
let trait_def = TraitDef {
2828
span: span,
2929
attributes: Vec::new(),
30-
path: Path::new(vec!("std", "default", "Default")),
30+
path: quote_path!(std::default::Default),
3131
additional_bounds: Vec::new(),
3232
generics: LifetimeBounds::empty(),
3333
methods: vec!(

src/libsyntax/ext/deriving/encodable.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ pub fn expand_deriving_encodable(cx: &mut ExtCtxt,
9696
let trait_def = TraitDef {
9797
span: span,
9898
attributes: Vec::new(),
99-
path: Path::new_(vec!("serialize", "Encodable"), None,
99+
path: Path::new_(quote_path_vec!(serialize::Encodable), None,
100100
vec!(box Literal(Path::new_local("__S")),
101101
box Literal(Path::new_local("__E"))), true),
102102
additional_bounds: Vec::new(),
103103
generics: LifetimeBounds {
104104
lifetimes: Vec::new(),
105105
bounds: vec!(("__S", None, vec!(Path::new_(
106-
vec!("serialize", "Encoder"), None,
106+
quote_path_vec!(serialize::Encoder), None,
107107
vec!(box Literal(Path::new_local("__E"))), true))),
108108
("__E", None, vec!()))
109109
},
@@ -114,7 +114,7 @@ pub fn expand_deriving_encodable(cx: &mut ExtCtxt,
114114
explicit_self: borrowed_explicit_self(),
115115
args: vec!(Ptr(box Literal(Path::new_local("__S")),
116116
Borrowed(None, MutMutable))),
117-
ret_ty: Literal(Path::new_(vec!("std", "result", "Result"),
117+
ret_ty: Literal(Path::new_(quote_path_vec!(std::result::Result),
118118
None,
119119
vec!(box Tuple(Vec::new()),
120120
box Literal(Path::new_local("__E"))),

src/libsyntax/ext/deriving/hash.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ pub fn expand_deriving_hash(cx: &mut ExtCtxt,
2424
push: |P<Item>|) {
2525

2626
let (path, generics, args) = if cx.ecfg.deriving_hash_type_parameter {
27-
(Path::new_(vec!("std", "hash", "Hash"), None,
27+
(Path::new_(quote_path_vec!(std::hash::Hash), None,
2828
vec!(box Literal(Path::new_local("__S"))), true),
2929
LifetimeBounds {
3030
lifetimes: Vec::new(),
3131
bounds: vec!(("__S", None,
32-
vec!(Path::new(vec!("std", "hash", "Writer"))))),
32+
vec!(quote_path!(std::hash::Writer)))),
3333
},
3434
Path::new_local("__S"))
3535
} else {
36-
(Path::new(vec!("std", "hash", "Hash")),
36+
(quote_path!(std::hash::Hash),
3737
LifetimeBounds::empty(),
38-
Path::new(vec!("std", "hash", "sip", "SipState")))
38+
quote_path!(std::hash::sip::SipState))
3939
};
4040
let inline = cx.meta_word(span, InternedString::new("inline"));
4141
let attrs = vec!(cx.attribute(span, inline));

src/libsyntax/ext/deriving/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ use ext::base::ExtCtxt;
2323
use codemap::Span;
2424
use ptr::P;
2525

26+
macro_rules! quote_path_vec (
27+
($($x:ident)::+) => (
28+
vec![ $( stringify!($x) ),+ ]
29+
)
30+
)
31+
32+
macro_rules! quote_path (
33+
($($x:tt)*) => (
34+
::ext::deriving::generic::ty::Path::new( quote_path_vec!( $($x)* ) )
35+
)
36+
)
37+
2638
pub mod bounds;
2739
pub mod clone;
2840
pub mod encodable;

src/libsyntax/ext/deriving/primitive.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,16 @@ pub fn expand_deriving_from_primitive(cx: &mut ExtCtxt,
2828
let trait_def = TraitDef {
2929
span: span,
3030
attributes: Vec::new(),
31-
path: Path::new(vec!("std", "num", "FromPrimitive")),
31+
path: quote_path!(std::num::FromPrimitive),
3232
additional_bounds: Vec::new(),
3333
generics: LifetimeBounds::empty(),
3434
methods: vec!(
3535
MethodDef {
3636
name: "from_i64",
3737
generics: LifetimeBounds::empty(),
3838
explicit_self: None,
39-
args: vec!(
40-
Literal(Path::new(vec!("i64")))),
41-
ret_ty: Literal(Path::new_(vec!("std", "option", "Option"),
39+
args: vec!(Literal(quote_path!(i64))),
40+
ret_ty: Literal(Path::new_(quote_path_vec!(std::option::Option),
4241
None,
4342
vec!(box Self),
4443
true)),
@@ -52,9 +51,8 @@ pub fn expand_deriving_from_primitive(cx: &mut ExtCtxt,
5251
name: "from_u64",
5352
generics: LifetimeBounds::empty(),
5453
explicit_self: None,
55-
args: vec!(
56-
Literal(Path::new(vec!("u64")))),
57-
ret_ty: Literal(Path::new_(vec!("std", "option", "Option"),
54+
args: vec!(Literal(quote_path!(u64))),
55+
ret_ty: Literal(Path::new_(quote_path_vec!(std::option::Option),
5856
None,
5957
vec!(box Self),
6058
true)),

src/libsyntax/ext/deriving/rand.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub fn expand_deriving_rand(cx: &mut ExtCtxt,
2525
let trait_def = TraitDef {
2626
span: span,
2727
attributes: Vec::new(),
28-
path: Path::new(vec!("std", "rand", "Rand")),
28+
path: quote_path!(std::rand::Rand),
2929
additional_bounds: Vec::new(),
3030
generics: LifetimeBounds::empty(),
3131
methods: vec!(
@@ -35,7 +35,7 @@ pub fn expand_deriving_rand(cx: &mut ExtCtxt,
3535
lifetimes: Vec::new(),
3636
bounds: vec!(("R",
3737
None,
38-
vec!( Path::new(vec!("std", "rand", "Rng")) )))
38+
vec!( quote_path!(std::rand::Rng) ))),
3939
},
4040
explicit_self: None,
4141
args: vec!(

src/libsyntax/ext/deriving/show.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ pub fn expand_deriving_show(cx: &mut ExtCtxt,
2727
item: &Item,
2828
push: |P<Item>|) {
2929
// &mut ::std::fmt::Formatter
30-
let fmtr = Ptr(box Literal(Path::new(vec!("std", "fmt", "Formatter"))),
30+
let fmtr = Ptr(box Literal(quote_path!(std::fmt::Formatter)),
3131
Borrowed(None, ast::MutMutable));
3232

3333
let trait_def = TraitDef {
3434
span: span,
3535
attributes: Vec::new(),
36-
path: Path::new(vec!("std", "fmt", "Show")),
36+
path: quote_path!(std::fmt::Show),
3737
additional_bounds: Vec::new(),
3838
generics: LifetimeBounds::empty(),
3939
methods: vec!(
@@ -42,7 +42,7 @@ pub fn expand_deriving_show(cx: &mut ExtCtxt,
4242
generics: LifetimeBounds::empty(),
4343
explicit_self: borrowed_explicit_self(),
4444
args: vec!(fmtr),
45-
ret_ty: Literal(Path::new(vec!("std", "fmt", "Result"))),
45+
ret_ty: Literal(quote_path!(std::fmt::Result)),
4646
attributes: Vec::new(),
4747
combine_substructure: combine_substructure(|a, b, c| {
4848
show_substructure(a, b, c)

src/libsyntax/ext/deriving/zero.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub fn expand_deriving_zero(cx: &mut ExtCtxt,
2727
let trait_def = TraitDef {
2828
span: span,
2929
attributes: Vec::new(),
30-
path: Path::new(vec!("std", "num", "Zero")),
30+
path: quote_path!(std::num::Zero),
3131
additional_bounds: Vec::new(),
3232
generics: LifetimeBounds::empty(),
3333
methods: vec!(
@@ -47,7 +47,7 @@ pub fn expand_deriving_zero(cx: &mut ExtCtxt,
4747
generics: LifetimeBounds::empty(),
4848
explicit_self: borrowed_explicit_self(),
4949
args: Vec::new(),
50-
ret_ty: Literal(Path::new(vec!("bool"))),
50+
ret_ty: Literal(quote_path!(bool)),
5151
attributes: attrs,
5252
combine_substructure: combine_substructure(|cx, span, substr| {
5353
cs_and(|cx, span, _, _| cx.span_bug(span,

0 commit comments

Comments
 (0)