Skip to content

Commit 03bf42d

Browse files
oslfmtsmoelius
authored andcommitted
fix recommended test case panic
1 parent 5387f4c commit 03bf42d

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

lints/type_cosplay/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,14 @@ impl<'tcx> LateLintPass<'tcx> for TypeCosplay {
7777
}
7878

7979
fn check_crate_post(&mut self, cx: &LateContext<'tcx>) {
80+
// NOTE: the case where len == 0 does nothing, since no types are deserialized
8081
if self.deser_types.len() == 1 {
8182
let (k, v) = self.deser_types.iter().next().unwrap();
8283
match k {
8384
AdtKind::Enum => check_enums(cx, v),
8485
_ => check_structs_have_discriminant(cx, v), // NOTE: also catches unions
8586
}
86-
} else {
87+
} else if self.deser_types.len() > 1 {
8788
// Retrieve spans: iter through map, grab first elem of each key-pair, then get span
8889
let mut spans = vec![];
8990
self.deser_types.iter().for_each(|(_, v)| {

lints/type_cosplay/ui/insecure-3/src/lib.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ LL | let user = User::try_from_slice(&ctx.accounts.user.data.borrow()).u
88
help: help: deserialize from only structs with a discriminant, or an enum encapsulating all structs.
99
--> $DIR/lib.rs:28:21
1010
|
11-
LL | let extra = AnotherDiscriminant::try_from_slice(&ctx.accounts.user.data.borrow()).unwrap();
12-
| ^^^^^^^^^^^^^^^^^^^
11+
LL | let extra = Instruction::try_from_slice(&ctx.accounts.user.data.borrow()).unwrap();
12+
| ^^^^^^^^^^^
1313

1414
error: aborting due to previous error
1515

0 commit comments

Comments
 (0)