Skip to content

Commit f0956a5

Browse files
committed
use if statement
1 parent f4dafd9 commit f0956a5

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

compiler/rustc_mir_transform/src/known_panics_lint.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,11 @@ impl<'tcx> Value<'tcx> {
103103
(PlaceElem::Index(idx), Value::Aggregate { fields, .. }) => {
104104
let idx = prop.get_const(idx.into())?.immediate()?;
105105
let idx = prop.ecx.read_target_usize(idx).ok()?.try_into().ok()?;
106-
let idx = (idx <= FieldIdx::MAX_AS_U32).then(|| FieldIdx::from_u32(idx))?;
107-
fields.get(idx).unwrap_or(&Value::Uninit)
106+
if idx <= FieldIdx::MAX_AS_U32 {
107+
fields.get(FieldIdx::from_u32(idx)).unwrap_or(&Value::Uninit)
108+
} else {
109+
return None;
110+
}
108111
}
109112
(
110113
PlaceElem::ConstantIndex { offset, min_length: _, from_end: false },

0 commit comments

Comments
 (0)