GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix `TryFrom<u8> · RustPython/RustPython@f4b8be8

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • crates/compiler-core/src
    • bytecode.rs
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎crates/compiler-core/src/bytecode.rs‎

Copy file name to clipboardExpand all lines: crates/compiler-core/src/bytecode.rs
+35-10Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -872,21 +872,46 @@ pub enum Instruction {
872872

873873
const _: () = assert!(mem::size_of::<Instruction>() == 1);
874874

875-
impl From<Instruction> for u8 {
876-
#[inline]
877-
fn from(ins: Instruction) -> Self {
878-
// SAFETY: there's no padding bits
879-
unsafe { core::mem::transmute::<Instruction, Self>(ins) }
880-
}
881-
}
882-
883875
impl TryFrom<u8> for Instruction {
884876
type Error = MarshalError;
885877

886878
#[inline]
887879
fn try_from(value: u8) -> Result<Self, MarshalError> {
888-
// TODO: Use `num_enum`
889-
Ok(unsafe { core::mem::transmute::<u8, Self>(value) })
880+
Ok(match value {
881+
1
882+
| 5..=7
883+
| 9
884+
| 10
885+
| 14..=16
886+
| 18..=20
887+
| 24
888+
| 26..=32
889+
| 36
890+
| 37
891+
| 39
892+
| 40
893+
| 45
894+
| 47..=52
895+
| 54..=56
896+
| 58..=61
897+
| 63..=67
898+
| 69
899+
| 71..=76
900+
| 80
901+
| 82..=85
902+
| 91
903+
| 95..=97
904+
| 100
905+
| 101
906+
| 103
907+
| 105
908+
| 106
909+
| 108..=110
910+
| 113..=118
911+
| 149
912+
| 222..=255 => unsafe { core::mem::transmute::<u8, Self>(value) },
913+
_ => return Err(MarshalError::InvalidBytecode),
914+
})
890915
}
891916
}
892917

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.