@@ -84,15 +84,19 @@ impl<'tcx> LateLintPass<'tcx> for TypeCosplay {
84
84
_ => check_structs_have_discriminant ( cx, v) , // NOTE: also catches unions
85
85
}
86
86
} else {
87
- // Retrieve spans: iter through map, grab first elem of two different key pairs, then get span
88
- // span_lint_and_help(
89
- // cx,
90
- // TYPE_COSPLAY,
91
- // span,
92
- // "Deserializing from multiple ADT types. "
93
- // None,
94
- // "help: deserialize from only structs with a discriminant, or an enum encapsulating all structs."
95
- // )
87
+ // Retrieve spans: iter through map, grab first elem of each key-pair, then get span
88
+ let mut spans = vec ! [ ] ;
89
+ self . deser_types . iter ( ) . for_each ( |( _, v) | {
90
+ spans. push ( v[ 0 ] . 1 ) ;
91
+ } ) ;
92
+ span_lint_and_help (
93
+ cx,
94
+ TYPE_COSPLAY ,
95
+ spans[ 0 ] ,
96
+ "Deserializing from multiple ADT types." ,
97
+ Some ( spans[ 1 ] ) ,
98
+ "help: deserialize from only structs with a discriminant, or an enum encapsulating all structs."
99
+ )
96
100
}
97
101
}
98
102
}
@@ -148,7 +152,7 @@ fn check_structs_have_discriminant(cx: &LateContext<'_>, types: &Vec<(DefId, Spa
148
152
/// Checks if `adt` has a proper discriminant. We define a proper discriminant as being an enum with
149
153
/// the number of variants at least the number of deserialized structs. Further the discriminant should
150
154
/// be the first field in the adt.
151
- fn has_discriminant ( cx : & LateContext , adt : & AdtDef , num_struct_types : usize , span : Span ) {
155
+ fn has_discriminant ( cx : & LateContext , adt : AdtDef , num_struct_types : usize , span : Span ) {
152
156
let variant = adt. variants ( ) . get ( Idx :: new ( 0 ) ) . unwrap ( ) ;
153
157
let first_field_def = & variant. fields [ 0 ] ;
154
158
let ty = cx. tcx . type_of ( first_field_def. did ) ;
0 commit comments