mirror of
https://github.com/serde-rs/serde.git
synced 2025-10-02 15:25:38 +00:00
Auto merge of #459 - serde-rs:phantom, r=oli-obk
PhantomData<T> does not require bounds on T
This commit is contained in:
commit
c6acec29e5
@ -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) {
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user