Auto merge of #459 - serde-rs:phantom, r=oli-obk

PhantomData<T> does not require bounds on T
This commit is contained in:
Homu 2016-07-23 01:43:45 +09:00
commit c6acec29e5
2 changed files with 13 additions and 0 deletions

View File

@ -79,6 +79,13 @@ pub fn with_bound<F>(
}
impl visit::Visitor for FindTyParams {
fn visit_path(&mut self, path: &ast::Path, _id: ast::NodeId) {
if let Some(seg) = path.segments.last() {
if seg.identifier.name.as_str() == "PhantomData" {
// Hardcoded exception, because PhantomData<T> implements
// Serialize and Deserialize whether or not T implements it.
return;
}
}
if !path.global && path.segments.len() == 1 {
let id = path.segments[0].identifier.name;
if self.all_ty_params.contains(&id) {

View File

@ -35,6 +35,12 @@ fn test_gen() {
}
assert::<PhantomX>();
#[derive(Serialize, Deserialize)]
struct PhantomT<T> {
t: PhantomData<T>,
}
assert::<PhantomT<X>>();
#[derive(Serialize, Deserialize)]
struct Bounds<T: Serialize + Deserialize> {
t: T,