Skip to content

Commit 8e9eba8

Browse files
committed
syntax/ext: remove the ~str dependence of the deriving code.
1 parent dc7b83d commit 8e9eba8

File tree

10 files changed

+81
-79
lines changed

10 files changed

+81
-79
lines changed

src/libsyntax/ext/deriving/clone.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ pub fn expand_deriving_clone(cx: @ext_ctxt,
2121
in_items: ~[@item])
2222
-> ~[@item] {
2323
let trait_def = TraitDef {
24-
path: Path::new(~[~"core", ~"clone", ~"Clone"]),
24+
path: Path::new(~["core", "clone", "Clone"]),
2525
additional_bounds: ~[],
2626
generics: LifetimeBounds::empty(),
2727
methods: ~[
2828
MethodDef {
29-
name: ~"clone",
29+
name: "clone",
3030
generics: LifetimeBounds::empty(),
3131
explicit_self: borrowed_explicit_self(),
3232
args: ~[],
@@ -48,12 +48,12 @@ pub fn expand_deriving_deep_clone(cx: @ext_ctxt,
4848
in_items: ~[@item])
4949
-> ~[@item] {
5050
let trait_def = TraitDef {
51-
path: Path::new(~[~"core", ~"clone", ~"DeepClone"]),
51+
path: Path::new(~["core", "clone", "DeepClone"]),
5252
additional_bounds: ~[],
5353
generics: LifetimeBounds::empty(),
5454
methods: ~[
5555
MethodDef {
56-
name: ~"deep_clone",
56+
name: "deep_clone",
5757
generics: LifetimeBounds::empty(),
5858
explicit_self: borrowed_explicit_self(),
5959
args: ~[],

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,20 @@ pub fn expand_deriving_eq(cx: @ext_ctxt,
3636
generics: LifetimeBounds::empty(),
3737
explicit_self: borrowed_explicit_self(),
3838
args: ~[borrowed_self()],
39-
ret_ty: Literal(Path::new(~[~"bool"])),
39+
ret_ty: Literal(Path::new(~["bool"])),
4040
const_nonmatching: true,
4141
combine_substructure: $f
4242
},
4343
}
4444
);
4545

4646
let trait_def = TraitDef {
47-
path: Path::new(~[~"core", ~"cmp", ~"Eq"]),
47+
path: Path::new(~["core", "cmp", "Eq"]),
4848
additional_bounds: ~[],
4949
generics: LifetimeBounds::empty(),
5050
methods: ~[
51-
md!(~"eq", cs_eq),
52-
md!(~"ne", cs_ne)
51+
md!("eq", cs_eq),
52+
md!("ne", cs_ne)
5353
]
5454
};
5555

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub fn expand_deriving_ord(cx: @ext_ctxt,
2626
generics: LifetimeBounds::empty(),
2727
explicit_self: borrowed_explicit_self(),
2828
args: ~[borrowed_self()],
29-
ret_ty: Literal(Path::new(~[~"bool"])),
29+
ret_ty: Literal(Path::new(~["bool"])),
3030
const_nonmatching: false,
3131
combine_substructure: |cx, span, substr|
3232
cs_ord($less, $equal, cx, span, substr)
@@ -37,15 +37,15 @@ pub fn expand_deriving_ord(cx: @ext_ctxt,
3737

3838

3939
let trait_def = TraitDef {
40-
path: Path::new(~[~"core", ~"cmp", ~"Ord"]),
40+
path: Path::new(~["core", "cmp", "Ord"]),
4141
// XXX: Ord doesn't imply Eq yet
42-
additional_bounds: ~[Literal(Path::new(~[~"core", ~"cmp", ~"Eq"]))],
42+
additional_bounds: ~[Literal(Path::new(~["core", "cmp", "Eq"]))],
4343
generics: LifetimeBounds::empty(),
4444
methods: ~[
45-
md!(~"lt", true, false),
46-
md!(~"le", true, true),
47-
md!(~"gt", false, false),
48-
md!(~"ge", false, true)
45+
md!("lt", true, false),
46+
md!("le", true, true),
47+
md!("gt", false, false),
48+
md!("ge", false, true)
4949
]
5050
};
5151

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ pub fn expand_deriving_totaleq(cx: @ext_ctxt,
2626
}
2727

2828
let trait_def = TraitDef {
29-
path: Path::new(~[~"core", ~"cmp", ~"TotalEq"]),
29+
path: Path::new(~["core", "cmp", "TotalEq"]),
3030
additional_bounds: ~[],
3131
generics: LifetimeBounds::empty(),
3232
methods: ~[
3333
MethodDef {
34-
name: ~"equals",
34+
name: "equals",
3535
generics: LifetimeBounds::empty(),
3636
explicit_self: borrowed_explicit_self(),
3737
args: ~[borrowed_self()],
38-
ret_ty: Literal(Path::new(~[~"bool"])),
38+
ret_ty: Literal(Path::new(~["bool"])),
3939
const_nonmatching: true,
4040
combine_substructure: cs_equals
4141
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ pub fn expand_deriving_totalord(cx: @ext_ctxt,
2020
mitem: @meta_item,
2121
in_items: ~[@item]) -> ~[@item] {
2222
let trait_def = TraitDef {
23-
path: Path::new(~[~"core", ~"cmp", ~"TotalOrd"]),
23+
path: Path::new(~["core", "cmp", "TotalOrd"]),
2424
additional_bounds: ~[],
2525
generics: LifetimeBounds::empty(),
2626
methods: ~[
2727
MethodDef {
28-
name: ~"cmp",
28+
name: "cmp",
2929
generics: LifetimeBounds::empty(),
3030
explicit_self: borrowed_explicit_self(),
3131
args: ~[borrowed_self()],
32-
ret_ty: Literal(Path::new(~[~"core", ~"cmp", ~"Ordering"])),
32+
ret_ty: Literal(Path::new(~["core", "cmp", "Ordering"])),
3333
const_nonmatching: false,
3434
combine_substructure: cs_cmp
3535
}

src/libsyntax/ext/deriving/generic.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,34 +195,34 @@ pub fn expand_deriving_generic(cx: @ext_ctxt,
195195

196196
pub struct TraitDef<'self> {
197197
/// Path of the trait, including any type parameters
198-
path: Path,
198+
path: Path<'self>,
199199
/// Additional bounds required of any type parameters of the type,
200200
/// other than the current trait
201-
additional_bounds: ~[Ty],
201+
additional_bounds: ~[Ty<'self>],
202202

203203
/// Any extra lifetimes and/or bounds, e.g. `D: std::serialize::Decoder`
204-
generics: LifetimeBounds,
204+
generics: LifetimeBounds<'self>,
205205

206206
methods: ~[MethodDef<'self>]
207207
}
208208

209209

210210
pub struct MethodDef<'self> {
211211
/// name of the method
212-
name: ~str,
212+
name: &'self str,
213213
/// List of generics, e.g. `R: core::rand::Rng`
214-
generics: LifetimeBounds,
214+
generics: LifetimeBounds<'self>,
215215

216216
/// Whether there is a self argument (outer Option) i.e. whether
217217
/// this is a static function, and whether it is a pointer (inner
218218
/// Option)
219-
explicit_self: Option<Option<PtrTy>>,
219+
explicit_self: Option<Option<PtrTy<'self>>>,
220220

221221
/// Arguments other than the self argument
222-
args: ~[Ty],
222+
args: ~[Ty<'self>],
223223

224224
/// Return type
225-
ret_ty: Ty,
225+
ret_ty: Ty<'self>,
226226

227227
/// if the value of the nonmatching enums is independent of the
228228
/// actual enum variants, i.e. can use _ => .. match.

src/libsyntax/ext/deriving/iter_bytes.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ pub fn expand_deriving_iter_bytes(cx: @ext_ctxt,
1919
mitem: @meta_item,
2020
in_items: ~[@item]) -> ~[@item] {
2121
let trait_def = TraitDef {
22-
path: Path::new(~[~"core", ~"to_bytes", ~"IterBytes"]),
22+
path: Path::new(~["core", "to_bytes", "IterBytes"]),
2323
additional_bounds: ~[],
2424
generics: LifetimeBounds::empty(),
2525
methods: ~[
2626
MethodDef {
27-
name: ~"iter_bytes",
27+
name: "iter_bytes",
2828
generics: LifetimeBounds::empty(),
2929
explicit_self: borrowed_explicit_self(),
3030
args: ~[
31-
Literal(Path::new(~[~"bool"])),
32-
Literal(Path::new(~[~"core", ~"to_bytes", ~"Cb"]))
31+
Literal(Path::new(~["bool"])),
32+
Literal(Path::new(~["core", "to_bytes", "Cb"]))
3333
],
34-
ret_ty: Literal(Path::new(~[~"bool"])),
34+
ret_ty: Literal(Path::new(~["bool"])),
3535
const_nonmatching: false,
3636
combine_substructure: iter_bytes_substructure
3737
}

src/libsyntax/ext/deriving/rand.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@ pub fn expand_deriving_rand(cx: @ext_ctxt,
2121
in_items: ~[@item])
2222
-> ~[@item] {
2323
let trait_def = TraitDef {
24-
path: Path::new(~[~"core", ~"rand", ~"Rand"]),
24+
path: Path::new(~["core", "rand", "Rand"]),
2525
additional_bounds: ~[],
2626
generics: LifetimeBounds::empty(),
2727
methods: ~[
2828
MethodDef {
29-
name: ~"rand",
29+
name: "rand",
3030
generics: LifetimeBounds {
3131
lifetimes: ~[],
32-
bounds: ~[(~"R",
33-
~[ Path::new(~[~"core", ~"rand", ~"Rng"]) ])]
32+
bounds: ~[("R",
33+
~[ Path::new(~["core", "rand", "Rng"]) ])]
3434
},
3535
explicit_self: None,
3636
args: ~[
37-
Ptr(~Literal(Path::new_local(~"R")),
37+
Ptr(~Literal(Path::new_local("R")),
3838
Borrowed(None, ast::m_mutbl))
3939
],
4040
ret_ty: Self,

src/libsyntax/ext/deriving/to_str.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ pub fn expand_deriving_to_str(cx: @ext_ctxt,
2020
in_items: ~[@item])
2121
-> ~[@item] {
2222
let trait_def = TraitDef {
23-
path: Path::new(~[~"core", ~"to_str", ~"ToStr"]),
23+
path: Path::new(~["core", "to_str", "ToStr"]),
2424
additional_bounds: ~[],
2525
generics: LifetimeBounds::empty(),
2626
methods: ~[
2727
MethodDef {
28-
name: ~"to_str",
28+
name: "to_str",
2929
generics: LifetimeBounds::empty(),
3030
explicit_self: borrowed_explicit_self(),
3131
args: ~[],
32-
ret_ty: Ptr(~Literal(Path::new_local(~"str")), Owned),
32+
ret_ty: Ptr(~Literal(Path::new_local("str")), Owned),
3333
const_nonmatching: false,
3434
combine_substructure: to_str_substructure
3535
}

src/libsyntax/ext/deriving/ty.rs

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,30 @@ use codemap::{span,respan};
2121
use opt_vec;
2222

2323
/// The types of pointers
24-
#[deriving(Eq)]
25-
pub enum PtrTy {
24+
pub enum PtrTy<'self> {
2625
Owned, // ~
2726
Managed(ast::mutability), // @[mut]
28-
Borrowed(Option<~str>, ast::mutability), // &['lifetime] [mut]
27+
Borrowed(Option<&'self str>, ast::mutability), // &['lifetime] [mut]
2928
}
3029

3130
/// A path, e.g. `::core::option::Option::<int>` (global). Has support
3231
/// for type parameters and a lifetime.
33-
#[deriving(Eq)]
34-
pub struct Path {
35-
path: ~[~str],
36-
lifetime: Option<~str>,
37-
params: ~[~Ty],
32+
pub struct Path<'self> {
33+
path: ~[&'self str],
34+
lifetime: Option<&'self str>,
35+
params: ~[~Ty<'self>],
3836
global: bool
3937
}
4038

41-
pub impl Path {
42-
fn new(path: ~[~str]) -> Path {
39+
pub impl<'self> Path<'self> {
40+
fn new<'r>(path: ~[&'r str]) -> Path<'r> {
4341
Path::new_(path, None, ~[], true)
4442
}
45-
fn new_local(path: ~str) -> Path {
43+
fn new_local<'r>(path: &'r str) -> Path<'r> {
4644
Path::new_(~[ path ], None, ~[], false)
4745
}
48-
fn new_(path: ~[~str], lifetime: Option<~str>, params: ~[~Ty], global: bool) -> Path {
46+
fn new_<'r>(path: ~[&'r str], lifetime: Option<&'r str>, params: ~[~Ty<'r>], global: bool)
47+
-> Path<'r> {
4948
Path {
5049
path: path,
5150
lifetime: lifetime,
@@ -56,9 +55,9 @@ pub impl Path {
5655

5756
fn to_ty(&self, cx: @ext_ctxt, span: span,
5857
self_ty: ident, self_generics: &Generics) -> @ast::Ty {
59-
build::mk_ty_path_path(cx, span,
60-
self.to_path(cx, span,
61-
self_ty, self_generics))
58+
build::mk_ty_path_path(cx, span,
59+
self.to_path(cx, span,
60+
self_ty, self_generics))
6261
}
6362
fn to_path(&self, cx: @ext_ctxt, span: span,
6463
self_ty: ident, self_generics: &Generics) -> @ast::Path {
@@ -75,45 +74,44 @@ pub impl Path {
7574
}
7675

7776
/// A type. Supports pointers (except for *), Self, and literals
78-
#[deriving(Eq)]
79-
pub enum Ty {
77+
pub enum Ty<'self> {
8078
Self,
8179
// &/~/@ Ty
82-
Ptr(~Ty, PtrTy),
80+
Ptr(~Ty<'self>, PtrTy<'self>),
8381
// mod::mod::Type<[lifetime], [Params...]>, including a plain type
8482
// parameter, and things like `int`
85-
Literal(Path),
83+
Literal(Path<'self>),
8684
// includes nil
87-
Tuple(~[Ty])
85+
Tuple(~[Ty<'self>])
8886
}
8987

90-
pub fn borrowed_ptrty() -> PtrTy {
88+
pub fn borrowed_ptrty<'r>() -> PtrTy<'r> {
9189
Borrowed(None, ast::m_imm)
9290
}
93-
pub fn borrowed(ty: ~Ty) -> Ty {
91+
pub fn borrowed<'r>(ty: ~Ty<'r>) -> Ty<'r> {
9492
Ptr(ty, borrowed_ptrty())
9593
}
9694

97-
pub fn borrowed_explicit_self() -> Option<Option<PtrTy>> {
95+
pub fn borrowed_explicit_self<'r>() -> Option<Option<PtrTy<'r>>> {
9896
Some(Some(borrowed_ptrty()))
9997
}
10098

101-
pub fn borrowed_self() -> Ty {
99+
pub fn borrowed_self<'r>() -> Ty<'r> {
102100
borrowed(~Self)
103101
}
104102

105-
pub fn nil_ty() -> Ty {
103+
pub fn nil_ty() -> Ty<'static> {
106104
Tuple(~[])
107105
}
108106

109-
fn mk_lifetime(cx: @ext_ctxt, span: span, lt: &Option<~str>) -> Option<@ast::Lifetime> {
107+
fn mk_lifetime(cx: @ext_ctxt, span: span, lt: &Option<&str>) -> Option<@ast::Lifetime> {
110108
match *lt {
111109
Some(ref s) => Some(@build::mk_lifetime(cx, span, cx.ident_of(*s))),
112110
None => None
113111
}
114112
}
115113

116-
pub impl Ty {
114+
pub impl<'self> Ty<'self> {
117115
fn to_ty(&self, cx: @ext_ctxt, span: span,
118116
self_ty: ident, self_generics: &Generics) -> @ast::Ty {
119117
match *self {
@@ -174,7 +172,7 @@ pub impl Ty {
174172
}
175173

176174

177-
fn mk_ty_param(cx: @ext_ctxt, span: span, name: ~str, bounds: ~[Path],
175+
fn mk_ty_param(cx: @ext_ctxt, span: span, name: &str, bounds: &[Path],
178176
self_ident: ident, self_generics: &Generics) -> ast::TyParam {
179177
let bounds = opt_vec::from(
180178
do bounds.map |b| {
@@ -192,24 +190,28 @@ fn mk_generics(lifetimes: ~[ast::Lifetime], ty_params: ~[ast::TyParam]) -> Gene
192190
}
193191

194192
/// Lifetimes and bounds on type parameters
195-
pub struct LifetimeBounds {
196-
lifetimes: ~[~str],
197-
bounds: ~[(~str, ~[Path])]
193+
pub struct LifetimeBounds<'self> {
194+
lifetimes: ~[&'self str],
195+
bounds: ~[(&'self str, ~[Path<'self>])]
198196
}
199197

200-
pub impl LifetimeBounds {
201-
fn empty() -> LifetimeBounds {
198+
pub impl<'self> LifetimeBounds<'self> {
199+
fn empty() -> LifetimeBounds<'static> {
202200
LifetimeBounds {
203201
lifetimes: ~[], bounds: ~[]
204202
}
205203
}
206204
fn to_generics(&self, cx: @ext_ctxt, span: span,
207205
self_ty: ident, self_generics: &Generics) -> Generics {
208-
let lifetimes = do self.lifetimes.map |&lt| {
209-
build::mk_lifetime(cx, span, cx.ident_of(lt))
206+
let lifetimes = do self.lifetimes.map |lt| {
207+
build::mk_lifetime(cx, span, cx.ident_of(*lt))
210208
};
211-
let ty_params = do self.bounds.map |&(name, bounds)| {
212-
mk_ty_param(cx, span, name, bounds, self_ty, self_generics)
209+
let ty_params = do self.bounds.map |t| {
210+
match t {
211+
&(ref name, ref bounds) => {
212+
mk_ty_param(cx, span, *name, *bounds, self_ty, self_generics)
213+
}
214+
}
213215
};
214216
mk_generics(lifetimes, ty_params)
215217
}

0 commit comments

Comments
 (0)