Skip to content

Commit

Permalink
use if statement
Browse files Browse the repository at this point in the history
  • Loading branch information
Luv-Ray committed May 31, 2024
1 parent f4dafd9 commit f0956a5
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions compiler/rustc_mir_transform/src/known_panics_lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,11 @@ impl<'tcx> Value<'tcx> {
(PlaceElem::Index(idx), Value::Aggregate { fields, .. }) => {
let idx = prop.get_const(idx.into())?.immediate()?;
let idx = prop.ecx.read_target_usize(idx).ok()?.try_into().ok()?;
let idx = (idx <= FieldIdx::MAX_AS_U32).then(|| FieldIdx::from_u32(idx))?;
fields.get(idx).unwrap_or(&Value::Uninit)
if idx <= FieldIdx::MAX_AS_U32 {
fields.get(FieldIdx::from_u32(idx)).unwrap_or(&Value::Uninit)
} else {
return None;
}
}
(
PlaceElem::ConstantIndex { offset, min_length: _, from_end: false },
Expand Down

0 comments on commit f0956a5

Please sign in to comment.