Auto merge of #21614 - kvark:typedef, r=huonw
Fixes #21497 I don't know if this can be tested with built-in tests.
This commit is contained in:
commit
16286f5cf9
@ -51,7 +51,8 @@ pub fn expand_deriving_bound<F>(cx: &mut ExtCtxt,
|
||||
path: Path::new(vec!("std", "marker", name)),
|
||||
additional_bounds: Vec::new(),
|
||||
generics: LifetimeBounds::empty(),
|
||||
methods: vec!()
|
||||
methods: Vec::new(),
|
||||
associated_types: Vec::new(),
|
||||
};
|
||||
|
||||
trait_def.expand(cx, mitem, item, push)
|
||||
|
@ -44,7 +44,8 @@ pub fn expand_deriving_clone<F>(cx: &mut ExtCtxt,
|
||||
cs_clone("Clone", c, s, sub)
|
||||
}),
|
||||
}
|
||||
)
|
||||
),
|
||||
associated_types: Vec::new(),
|
||||
};
|
||||
|
||||
trait_def.expand(cx, mitem, item, push)
|
||||
|
@ -88,7 +88,8 @@ pub fn expand_deriving_eq<F>(cx: &mut ExtCtxt,
|
||||
methods: vec!(
|
||||
md!("eq", cs_eq),
|
||||
md!("ne", cs_ne)
|
||||
)
|
||||
),
|
||||
associated_types: Vec::new(),
|
||||
};
|
||||
trait_def.expand(cx, mitem, item, push)
|
||||
}
|
||||
|
@ -78,7 +78,8 @@ pub fn expand_deriving_ord<F>(cx: &mut ExtCtxt,
|
||||
md!("le", true, true),
|
||||
md!("gt", false, false),
|
||||
md!("ge", false, true)
|
||||
]
|
||||
],
|
||||
associated_types: Vec::new(),
|
||||
};
|
||||
trait_def.expand(cx, mitem, item, push)
|
||||
}
|
||||
|
@ -61,7 +61,8 @@ pub fn expand_deriving_totaleq<F>(cx: &mut ExtCtxt,
|
||||
cs_total_eq_assert(a, b, c)
|
||||
})
|
||||
}
|
||||
)
|
||||
),
|
||||
associated_types: Vec::new(),
|
||||
};
|
||||
trait_def.expand(cx, mitem, item, push)
|
||||
}
|
||||
|
@ -45,7 +45,8 @@ pub fn expand_deriving_totalord<F>(cx: &mut ExtCtxt,
|
||||
cs_cmp(a, b, c)
|
||||
}),
|
||||
}
|
||||
)
|
||||
),
|
||||
associated_types: Vec::new(),
|
||||
};
|
||||
|
||||
trait_def.expand(cx, mitem, item, push)
|
||||
|
@ -79,7 +79,9 @@ fn expand_deriving_decodable_imp<F>(cx: &mut ExtCtxt,
|
||||
combine_substructure: combine_substructure(box |a, b, c| {
|
||||
decodable_substructure(a, b, c, krate)
|
||||
}),
|
||||
})
|
||||
}
|
||||
),
|
||||
associated_types: Vec::new(),
|
||||
};
|
||||
|
||||
trait_def.expand(cx, mitem, item, push)
|
||||
|
@ -43,7 +43,9 @@ pub fn expand_deriving_default<F>(cx: &mut ExtCtxt,
|
||||
combine_substructure: combine_substructure(box |a, b, c| {
|
||||
default_substructure(a, b, c)
|
||||
})
|
||||
})
|
||||
}
|
||||
),
|
||||
associated_types: Vec::new(),
|
||||
};
|
||||
trait_def.expand(cx, mitem, item, push)
|
||||
}
|
||||
|
@ -155,7 +155,9 @@ fn expand_deriving_encodable_imp<F>(cx: &mut ExtCtxt,
|
||||
combine_substructure: combine_substructure(box |a, b, c| {
|
||||
encodable_substructure(a, b, c)
|
||||
}),
|
||||
})
|
||||
}
|
||||
),
|
||||
associated_types: Vec::new(),
|
||||
};
|
||||
|
||||
trait_def.expand(cx, mitem, item, push)
|
||||
|
@ -228,6 +228,8 @@ pub struct TraitDef<'a> {
|
||||
pub generics: LifetimeBounds<'a>,
|
||||
|
||||
pub methods: Vec<MethodDef<'a>>,
|
||||
|
||||
pub associated_types: Vec<(ast::Ident, Ty<'a>)>,
|
||||
}
|
||||
|
||||
|
||||
@ -387,6 +389,22 @@ impl<'a> TraitDef<'a> {
|
||||
methods: Vec<P<ast::Method>>) -> P<ast::Item> {
|
||||
let trait_path = self.path.to_path(cx, self.span, type_ident, generics);
|
||||
|
||||
// Transform associated types from `deriving::ty::Ty` into `ast::Typedef`
|
||||
let associated_types = self.associated_types.iter().map(|&(ident, ref type_def)| {
|
||||
P(ast::Typedef {
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
span: self.span,
|
||||
ident: ident,
|
||||
vis: ast::Inherited,
|
||||
attrs: Vec::new(),
|
||||
typ: type_def.to_ty(cx,
|
||||
self.span,
|
||||
type_ident,
|
||||
generics
|
||||
),
|
||||
})
|
||||
});
|
||||
|
||||
let Generics { mut lifetimes, ty_params, mut where_clause } =
|
||||
self.generics.to_generics(cx, self.span, type_ident, generics);
|
||||
let mut ty_params = ty_params.into_vec();
|
||||
@ -494,7 +512,11 @@ impl<'a> TraitDef<'a> {
|
||||
methods.into_iter()
|
||||
.map(|method| {
|
||||
ast::MethodImplItem(method)
|
||||
}).collect()))
|
||||
}).chain(
|
||||
associated_types.map(|type_| {
|
||||
ast::TypeImplItem(type_)
|
||||
})
|
||||
).collect()))
|
||||
}
|
||||
|
||||
fn expand_struct_def(&self,
|
||||
|
@ -54,7 +54,8 @@ pub fn expand_deriving_hash<F>(cx: &mut ExtCtxt,
|
||||
hash_substructure(a, b, c)
|
||||
})
|
||||
}
|
||||
)
|
||||
),
|
||||
associated_types: Vec::new(),
|
||||
};
|
||||
|
||||
hash_trait_def.expand(cx, mitem, item, push);
|
||||
|
@ -65,7 +65,9 @@ pub fn expand_deriving_from_primitive<F>(cx: &mut ExtCtxt,
|
||||
combine_substructure: combine_substructure(box |c, s, sub| {
|
||||
cs_from("u64", c, s, sub)
|
||||
}),
|
||||
})
|
||||
}
|
||||
),
|
||||
associated_types: Vec::new(),
|
||||
};
|
||||
|
||||
trait_def.expand(cx, mitem, item, push)
|
||||
|
@ -49,7 +49,8 @@ pub fn expand_deriving_rand<F>(cx: &mut ExtCtxt,
|
||||
rand_substructure(a, b, c)
|
||||
})
|
||||
}
|
||||
)
|
||||
),
|
||||
associated_types: Vec::new(),
|
||||
};
|
||||
trait_def.expand(cx, mitem, item, push)
|
||||
}
|
||||
|
@ -35,10 +35,10 @@ pub fn expand_deriving_show<F>(cx: &mut ExtCtxt,
|
||||
let trait_def = TraitDef {
|
||||
span: span,
|
||||
attributes: Vec::new(),
|
||||
path: Path::new(vec!("std", "fmt", "Debug")),
|
||||
path: Path::new(vec!["std", "fmt", "Debug"]),
|
||||
additional_bounds: Vec::new(),
|
||||
generics: LifetimeBounds::empty(),
|
||||
methods: vec!(
|
||||
methods: vec![
|
||||
MethodDef {
|
||||
name: "fmt",
|
||||
generics: LifetimeBounds::empty(),
|
||||
@ -50,7 +50,8 @@ pub fn expand_deriving_show<F>(cx: &mut ExtCtxt,
|
||||
show_substructure(a, b, c)
|
||||
})
|
||||
}
|
||||
)
|
||||
],
|
||||
associated_types: Vec::new(),
|
||||
};
|
||||
trait_def.expand(cx, mitem, item, push)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user