Skip to content

Commit d15aa78

Browse files
mkjjubeormk1
authored andcommitted
sshwire-derive: Disallow enum values
Those are currently ignored, so fail if they are present. If needed they could be implemented in future. Discussion in mkj#29 (comment)
1 parent cec2a82 commit d15aa78

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

sshwire-derive/src/lib.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,11 @@ fn encode_enum(
283283
let atts = take_field_atts(&var.attributes)?;
284284

285285
let mut rhs = StreamBuilder::new();
286+
if let Some(val) = &var.value {
287+
// Avoid users expecting enum values to be encoded.
288+
// Could be implemented if needed.
289+
return Err(Error::Custom { error: "sunset_sshwire_derive::SSHEncode currently does not encode enum discriminants.".into(), span: Some(val.span())})
290+
}
286291
match var.fields {
287292
None => {
288293
// Unit enum
@@ -300,7 +305,7 @@ fn encode_enum(
300305
}
301306

302307
}
303-
_ => return Err(Error::Custom { error: "SSHEncode currently only implements Unit or single value enum variants.".into(), span: None})
308+
_ => return Err(Error::Custom { error: "sunset_sshwire_derive::SSHEncode currently only implements Unit or single value enum variants.".into(), span: None})
304309
}
305310

306311
match_arm.puncts("=>");
@@ -372,7 +377,7 @@ fn encode_enum_names(
372377
})?;
373378

374379
}
375-
_ => return Err(Error::Custom { error: "SSHEncode currently only implements Unit or single value enum variants.".into(), span: None})
380+
_ => return Err(Error::Custom { error: "sunset_sshwire_derive::SSHEncode currently only implements Unit or single value enum variants.".into(), span: None})
376381
}
377382

378383
match_arm.puncts("=>");

0 commit comments

Comments
 (0)