Because it's always empty.
impl Default for Generics {
/// Creates an instance of `Generics`.
fn default() -> Generics {
- Generics {
- params: Vec::new(),
- where_clause: WhereClause {
- has_where_token: false,
- predicates: Vec::new(),
- span: DUMMY_SP,
- },
- span: DUMMY_SP,
- }
+ Generics { params: Vec::new(), where_clause: Default::default(), span: DUMMY_SP }
}
}
pub span: Span,
}
+impl Default for WhereClause {
+ fn default() -> WhereClause {
+ WhereClause { has_where_token: false, predicates: Vec::new(), span: DUMMY_SP }
+ }
+}
+
/// A single predicate in a where-clause.
#[derive(Clone, Encodable, Decodable, Debug)]
pub enum WherePredicate {
-use crate::deriving::generic::ty::*;
use crate::deriving::generic::*;
use crate::deriving::path_std;
path: path_std!(marker::Copy),
skip_path_as_bound: false,
additional_bounds: Vec::new(),
- generics: Bounds::empty(),
supports_unions: true,
methods: Vec::new(),
associated_types: Vec::new(),
path: path_std!(clone::Clone),
skip_path_as_bound: false,
additional_bounds: bounds,
- generics: Bounds::empty(),
supports_unions: true,
methods: vec![MethodDef {
name: sym::clone,
path: path_std!(cmp::Eq),
skip_path_as_bound: false,
additional_bounds: Vec::new(),
- generics: Bounds::empty(),
supports_unions: true,
methods: vec![MethodDef {
name: sym::assert_receiver_is_total_eq,
path: path_std!(cmp::Ord),
skip_path_as_bound: false,
additional_bounds: Vec::new(),
- generics: Bounds::empty(),
supports_unions: false,
methods: vec![MethodDef {
name: sym::cmp,
path: path_std!(cmp::PartialEq),
skip_path_as_bound: false,
additional_bounds: Vec::new(),
- generics: Bounds::empty(),
supports_unions: false,
methods,
associated_types: Vec::new(),
path: path_std!(cmp::PartialOrd),
skip_path_as_bound: false,
additional_bounds: vec![],
- generics: Bounds::empty(),
supports_unions: false,
methods: vec![partial_cmp_def],
associated_types: Vec::new(),
path: path_std!(fmt::Debug),
skip_path_as_bound: false,
additional_bounds: Vec::new(),
- generics: Bounds::empty(),
supports_unions: false,
methods: vec![MethodDef {
name: sym::fmt,
path: Path::new_(vec![krate, sym::Decodable], vec![], PathKind::Global),
skip_path_as_bound: false,
additional_bounds: Vec::new(),
- generics: Bounds::empty(),
supports_unions: false,
methods: vec![MethodDef {
name: sym::decode,
path: Path::new(vec![kw::Default, sym::Default]),
skip_path_as_bound: has_a_default_variant(item),
additional_bounds: Vec::new(),
- generics: Bounds::empty(),
supports_unions: false,
methods: vec![MethodDef {
name: kw::Default,
path: Path::new_(vec![krate, sym::Encodable], vec![], PathKind::Global),
skip_path_as_bound: false,
additional_bounds: Vec::new(),
- generics: Bounds::empty(),
supports_unions: false,
methods: vec![MethodDef {
name: sym::encode,
/// other than the current trait
pub additional_bounds: Vec<Ty>,
- /// Any extra lifetimes and/or bounds, e.g., `D: serialize::Decoder`
- pub generics: Bounds,
-
/// Can this trait be derived for unions?
pub supports_unions: bool,
})
});
- let Generics { mut params, mut where_clause, .. } =
- self.generics.to_generics(cx, self.span, type_ident, generics);
+ let mut where_clause = ast::WhereClause::default();
where_clause.span = generics.where_clause.span;
let ctxt = self.span.ctxt();
let span = generics.span.with_ctxt(ctxt);
// Create the generic parameters
- params.extend(generics.params.iter().map(|param| match ¶m.kind {
- GenericParamKind::Lifetime { .. } => param.clone(),
- GenericParamKind::Type { .. } => {
- // I don't think this can be moved out of the loop, since
- // a GenericBound requires an ast id
- let bounds: Vec<_> =
+ let params: Vec<_> = generics
+ .params
+ .iter()
+ .map(|param| match ¶m.kind {
+ GenericParamKind::Lifetime { .. } => param.clone(),
+ GenericParamKind::Type { .. } => {
+ // I don't think this can be moved out of the loop, since
+ // a GenericBound requires an ast id
+ let bounds: Vec<_> =
// extra restrictions on the generics parameters to the
// type being derived upon
self.additional_bounds.iter().map(|p| {
param.bounds.iter().cloned()
).collect();
- cx.typaram(param.ident.span.with_ctxt(ctxt), param.ident, bounds, None)
- }
- GenericParamKind::Const { ty, kw_span, .. } => {
- let const_nodefault_kind = GenericParamKind::Const {
- ty: ty.clone(),
- kw_span: kw_span.with_ctxt(ctxt),
-
- // We can't have default values inside impl block
- default: None,
- };
- let mut param_clone = param.clone();
- param_clone.kind = const_nodefault_kind;
- param_clone
- }
- }));
+ cx.typaram(param.ident.span.with_ctxt(ctxt), param.ident, bounds, None)
+ }
+ GenericParamKind::Const { ty, kw_span, .. } => {
+ let const_nodefault_kind = GenericParamKind::Const {
+ ty: ty.clone(),
+ kw_span: kw_span.with_ctxt(ctxt),
+
+ // We can't have default values inside impl block
+ default: None,
+ };
+ let mut param_clone = param.clone();
+ param_clone.kind = const_nodefault_kind;
+ param_clone
+ }
+ })
+ .collect();
// and similarly for where clauses
where_clause.predicates.extend(generics.where_clause.predicates.iter().map(|clause| {
path,
skip_path_as_bound: false,
additional_bounds: Vec::new(),
- generics: Bounds::empty(),
supports_unions: false,
methods: vec![MethodDef {
name: sym::hash,