64644bc4ea
Apply a patch that removes "let ... else" constructs, replacing them with "if let ... else" or "let ... = match ...". "let ... else" was stabilized in Rust 1.65.0. Reviewed-by: Junjie Mao <junjie.mao@hotmail.com> Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
46 lines
1.9 KiB
Diff
46 lines
1.9 KiB
Diff
--- a/src/shared/discriminant_assigner.rs
|
|
+++ b/src/shared/discriminant_assigner.rs
|
|
@@ -26,20 +26,20 @@
|
|
let discriminant_expr = &discriminant.1;
|
|
let variant_name = &variant.ident;
|
|
|
|
- let Expr::Lit(ExprLit { lit: Lit::Int(int), .. }) = discriminant_expr else {
|
|
+ if let Expr::Lit(ExprLit { lit: Lit::Int(int), .. }) = discriminant_expr {
|
|
+ let discriminant_value: u128 = int.base10_parse().unwrap_or_else(unreachable);
|
|
+ if discriminant_value > self.max_value() {
|
|
+ abort!(variant, "Value of variant exceeds the given number of bits")
|
|
+ }
|
|
+
|
|
+ Some(discriminant_value)
|
|
+ } else {
|
|
abort!(
|
|
discriminant_expr,
|
|
"variant `{}` is not a number", variant_name;
|
|
help = "only literal integers currently supported"
|
|
)
|
|
- };
|
|
-
|
|
- let discriminant_value: u128 = int.base10_parse().unwrap_or_else(unreachable);
|
|
- if discriminant_value > self.max_value() {
|
|
- abort!(variant, "Value of variant exceeds the given number of bits")
|
|
}
|
|
-
|
|
- Some(discriminant_value)
|
|
}
|
|
|
|
fn assign(&mut self, variant: &Variant) -> u128 {
|
|
--- a/src/shared/fallback.rs
|
|
+++ b/src/shared/fallback.rs
|
|
@@ -22,8 +22,9 @@
|
|
}
|
|
Unnamed(fields) => {
|
|
let variant_fields = fields.unnamed.iter();
|
|
- let Ok(fallback_value) = variant_fields.exactly_one() else {
|
|
- abort!(variant, "fallback variant must have exactly one field"; help = "use only one field or change to a unit variant")
|
|
+ let fallback_value = match variant_fields.exactly_one() {
|
|
+ Ok(ok) => ok,
|
|
+ _ => abort!(variant, "fallback variant must have exactly one field"; help = "use only one field or change to a unit variant")
|
|
};
|
|
|
|
if !is_last_variant {
|