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

Commit46f3e29

Browse files
committed
clippy
1 parent6c48b49 commit46f3e29

File tree

2 files changed

+31
-32
lines changed

2 files changed

+31
-32
lines changed

‎compiler/core/src/opcodes.rs‎

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

‎scripts/gen_opcodes.py‎

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,14 +218,39 @@ def build_has_attr_fn(self, fn_attr: str, prop_attr: str, doc_flag: str):
218218

219219
@property
220220
defimpl_try_from_nums(self)->str:
221+
deffn_prefix(typ:str):
222+
s_val=int(
223+
self.typ[1:]
224+
)# Will not work if `self.typ` is either isize or usize
225+
try:
226+
o_val=int(typ[1:])
227+
exceptValueError:
228+
o_val=float("inf")
229+
230+
ifself.typ[0]!=typ[0]:
231+
arg=f"raw:{typ}"
232+
id_def="let id = raw.try_into().map_err(|_| ())?;"
233+
elifo_val>s_val:
234+
arg=f"raw:{typ}"
235+
id_def="let id = raw.try_into().map_err(|_| ())?;"
236+
elifo_val==s_val:
237+
arg=f"id:{typ}"
238+
id_def=""
239+
else:
240+
arg=f"raw:{typ}"
241+
id_def="let id = raw.into();"
242+
243+
returnf"""
244+
fn try_from({arg}) -> Result<Self, Self::Error> {{
245+
{id_def}
246+
""".strip()
247+
221248
return"\n\n".join(
222249
f"""
223250
impl TryFrom<{typ}> for{self.enum_name} {{
224251
type Error = ();
225252
226-
fn try_from(raw:{typ}) -> Result<Self, Self::Error> {{
227-
#[allow(clippy::unnecessary_fallible_conversions)]
228-
let id = raw.try_into().map_err(|_| ())?;
253+
{fn_prefix(typ)}
229254
if Self::is_valid(id) {{
230255
// SAFETY: We just validated that we have a valid opcode id.
231256
Ok(unsafe {{ std::mem::transmute::<{self.typ}, Self>(id) }})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp