Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2a8fb1e

Browse files
committed
Addnew_unchecked
1 parent742b709 commit2a8fb1e

File tree

2 files changed

+62
-25
lines changed

2 files changed

+62
-25
lines changed

‎compiler/core/src/opcodes.rs‎

Lines changed: 46 additions & 24 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎scripts/gen_opcodes.py‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,21 @@ def rust_code(self) -> str:
164164
{impls}
165165
""".strip()
166166

167+
@property
168+
deffn_new_unchecked(self)->str:
169+
returnf"""
170+
/// Creates a new `{self.enum_name}` without checking the value is a valid opcode ID.
171+
///
172+
/// # Safety
173+
///
174+
/// The caller must ensure that `id` satisfies `{self.enum_name}::is_valid(id)`.
175+
#[must_use]
176+
pub const unsafe fn new_unchecked(id:{self.typ}) -> Self {{
177+
// SAFETY: caller responsibility
178+
unsafe {{ std::mem::transmute::<{self.typ}, Self>(id) }}
179+
}}
180+
"""
181+
167182
@property
168183
deffn_is_valid(self)->str:
169184
valid_ranges=fmt_ranges(
@@ -253,7 +268,7 @@ def fn_prefix(typ: str):
253268
{fn_prefix(typ)}
254269
if Self::is_valid(id) {{
255270
// SAFETY: We just validated that we have a valid opcode id.
256-
Ok(unsafe {{std::mem::transmute::<{self.typ}, Self>(id) }})
271+
Ok(unsafe {{Self::new_unchecked(id) }})
257272
}} else {{
258273
Err(())
259274
}}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp