Skip to content

Commit 16286f5

Browse files
committed
Auto merge of #21614 - kvark:typedef, r=huonw
Fixes #21497 I don't know if this can be tested with built-in tests.
2 parents 977c44a + e563215 commit 16286f5

File tree

14 files changed

+55
-16
lines changed

14 files changed

+55
-16
lines changed

src/libsyntax/ext/deriving/bounds.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ pub fn expand_deriving_bound<F>(cx: &mut ExtCtxt,
5151
path: Path::new(vec!("std", "marker", name)),
5252
additional_bounds: Vec::new(),
5353
generics: LifetimeBounds::empty(),
54-
methods: vec!()
54+
methods: Vec::new(),
55+
associated_types: Vec::new(),
5556
};
5657

5758
trait_def.expand(cx, mitem, item, push)

src/libsyntax/ext/deriving/clone.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ pub fn expand_deriving_clone<F>(cx: &mut ExtCtxt,
4444
cs_clone("Clone", c, s, sub)
4545
}),
4646
}
47-
)
47+
),
48+
associated_types: Vec::new(),
4849
};
4950

5051
trait_def.expand(cx, mitem, item, push)

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ pub fn expand_deriving_eq<F>(cx: &mut ExtCtxt,
8888
methods: vec!(
8989
md!("eq", cs_eq),
9090
md!("ne", cs_ne)
91-
)
91+
),
92+
associated_types: Vec::new(),
9293
};
9394
trait_def.expand(cx, mitem, item, push)
9495
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ pub fn expand_deriving_ord<F>(cx: &mut ExtCtxt,
7878
md!("le", true, true),
7979
md!("gt", false, false),
8080
md!("ge", false, true)
81-
]
81+
],
82+
associated_types: Vec::new(),
8283
};
8384
trait_def.expand(cx, mitem, item, push)
8485
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ pub fn expand_deriving_totaleq<F>(cx: &mut ExtCtxt,
6161
cs_total_eq_assert(a, b, c)
6262
})
6363
}
64-
)
64+
),
65+
associated_types: Vec::new(),
6566
};
6667
trait_def.expand(cx, mitem, item, push)
6768
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ pub fn expand_deriving_totalord<F>(cx: &mut ExtCtxt,
4545
cs_cmp(a, b, c)
4646
}),
4747
}
48-
)
48+
),
49+
associated_types: Vec::new(),
4950
};
5051

5152
trait_def.expand(cx, mitem, item, push)

src/libsyntax/ext/deriving/decodable.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ fn expand_deriving_decodable_imp<F>(cx: &mut ExtCtxt,
7979
combine_substructure: combine_substructure(box |a, b, c| {
8080
decodable_substructure(a, b, c, krate)
8181
}),
82-
})
82+
}
83+
),
84+
associated_types: Vec::new(),
8385
};
8486

8587
trait_def.expand(cx, mitem, item, push)

src/libsyntax/ext/deriving/default.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ pub fn expand_deriving_default<F>(cx: &mut ExtCtxt,
4343
combine_substructure: combine_substructure(box |a, b, c| {
4444
default_substructure(a, b, c)
4545
})
46-
})
46+
}
47+
),
48+
associated_types: Vec::new(),
4749
};
4850
trait_def.expand(cx, mitem, item, push)
4951
}

src/libsyntax/ext/deriving/encodable.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ fn expand_deriving_encodable_imp<F>(cx: &mut ExtCtxt,
155155
combine_substructure: combine_substructure(box |a, b, c| {
156156
encodable_substructure(a, b, c)
157157
}),
158-
})
158+
}
159+
),
160+
associated_types: Vec::new(),
159161
};
160162

161163
trait_def.expand(cx, mitem, item, push)

src/libsyntax/ext/deriving/generic/mod.rs

+23-1
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ pub struct TraitDef<'a> {
228228
pub generics: LifetimeBounds<'a>,
229229

230230
pub methods: Vec<MethodDef<'a>>,
231+
232+
pub associated_types: Vec<(ast::Ident, Ty<'a>)>,
231233
}
232234

233235

@@ -387,6 +389,22 @@ impl<'a> TraitDef<'a> {
387389
methods: Vec<P<ast::Method>>) -> P<ast::Item> {
388390
let trait_path = self.path.to_path(cx, self.span, type_ident, generics);
389391

392+
// Transform associated types from `deriving::ty::Ty` into `ast::Typedef`
393+
let associated_types = self.associated_types.iter().map(|&(ident, ref type_def)| {
394+
P(ast::Typedef {
395+
id: ast::DUMMY_NODE_ID,
396+
span: self.span,
397+
ident: ident,
398+
vis: ast::Inherited,
399+
attrs: Vec::new(),
400+
typ: type_def.to_ty(cx,
401+
self.span,
402+
type_ident,
403+
generics
404+
),
405+
})
406+
});
407+
390408
let Generics { mut lifetimes, ty_params, mut where_clause } =
391409
self.generics.to_generics(cx, self.span, type_ident, generics);
392410
let mut ty_params = ty_params.into_vec();
@@ -494,7 +512,11 @@ impl<'a> TraitDef<'a> {
494512
methods.into_iter()
495513
.map(|method| {
496514
ast::MethodImplItem(method)
497-
}).collect()))
515+
}).chain(
516+
associated_types.map(|type_| {
517+
ast::TypeImplItem(type_)
518+
})
519+
).collect()))
498520
}
499521

500522
fn expand_struct_def(&self,

src/libsyntax/ext/deriving/hash.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ pub fn expand_deriving_hash<F>(cx: &mut ExtCtxt,
5454
hash_substructure(a, b, c)
5555
})
5656
}
57-
)
57+
),
58+
associated_types: Vec::new(),
5859
};
5960

6061
hash_trait_def.expand(cx, mitem, item, push);

src/libsyntax/ext/deriving/primitive.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ pub fn expand_deriving_from_primitive<F>(cx: &mut ExtCtxt,
6565
combine_substructure: combine_substructure(box |c, s, sub| {
6666
cs_from("u64", c, s, sub)
6767
}),
68-
})
68+
}
69+
),
70+
associated_types: Vec::new(),
6971
};
7072

7173
trait_def.expand(cx, mitem, item, push)

src/libsyntax/ext/deriving/rand.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ pub fn expand_deriving_rand<F>(cx: &mut ExtCtxt,
4949
rand_substructure(a, b, c)
5050
})
5151
}
52-
)
52+
),
53+
associated_types: Vec::new(),
5354
};
5455
trait_def.expand(cx, mitem, item, push)
5556
}

src/libsyntax/ext/deriving/show.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ pub fn expand_deriving_show<F>(cx: &mut ExtCtxt,
3535
let trait_def = TraitDef {
3636
span: span,
3737
attributes: Vec::new(),
38-
path: Path::new(vec!("std", "fmt", "Debug")),
38+
path: Path::new(vec!["std", "fmt", "Debug"]),
3939
additional_bounds: Vec::new(),
4040
generics: LifetimeBounds::empty(),
41-
methods: vec!(
41+
methods: vec![
4242
MethodDef {
4343
name: "fmt",
4444
generics: LifetimeBounds::empty(),
@@ -50,7 +50,8 @@ pub fn expand_deriving_show<F>(cx: &mut ExtCtxt,
5050
show_substructure(a, b, c)
5151
})
5252
}
53-
)
53+
],
54+
associated_types: Vec::new(),
5455
};
5556
trait_def.expand(cx, mitem, item, push)
5657
}

0 commit comments

Comments
 (0)