diff options
| author | Josh Stone <jistone@redhat.com> | 2024-08-16 12:42:02 -0700 |
|---|---|---|
| committer | Josh Stone <jistone@redhat.com> | 2024-08-16 12:42:02 -0700 |
| commit | 29017e45a1c85afe457765a5d4c77e4fcdebb4f6 (patch) | |
| tree | 4df02e71af17c70ba458f9405c9a2bb6e7abfc4c | |
| parent | a73bc4a131d94eba633c4c572a28e0bf94a67530 (diff) | |
| download | rust-29017e45a1c85afe457765a5d4c77e4fcdebb4f6.tar.gz rust-29017e45a1c85afe457765a5d4c77e4fcdebb4f6.zip | |
mir/pretty: use `Option` instead of `Either<Once, Empty>`
`Either` is wasteful for a one-or-none iterator, especially since `Once` is already an `option::IntoIter` internally. We don't really need any of the iterator mechanisms in this case, just a single conditional insert.
| -rw-r--r-- | compiler/rustc_middle/src/mir/pretty.rs | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/compiler/rustc_middle/src/mir/pretty.rs b/compiler/rustc_middle/src/mir/pretty.rs index f2d87814130..5dd0e69cf1f 100644 --- a/compiler/rustc_middle/src/mir/pretty.rs +++ b/compiler/rustc_middle/src/mir/pretty.rs @@ -1418,21 +1418,19 @@ pub fn write_allocations<'tcx>( alloc.inner().provenance().ptrs().values().map(|p| p.alloc_id()) } - fn alloc_ids_from_const_val(val: ConstValue<'_>) -> impl Iterator<Item = AllocId> + '_ { + fn alloc_id_from_const_val(val: ConstValue<'_>) -> Option<AllocId> { match val { - ConstValue::Scalar(interpret::Scalar::Ptr(ptr, _)) => { - Either::Left(std::iter::once(ptr.provenance.alloc_id())) - } - ConstValue::Scalar(interpret::Scalar::Int { .. }) => Either::Right(std::iter::empty()), - ConstValue::ZeroSized => Either::Right(std::iter::empty()), + ConstValue::Scalar(interpret::Scalar::Ptr(ptr, _)) => Some(ptr.provenance.alloc_id()), + ConstValue::Scalar(interpret::Scalar::Int { .. }) => None, + ConstValue::ZeroSized => None, ConstValue::Slice { .. } => { // `u8`/`str` slices, shouldn't contain pointers that we want to print. - Either::Right(std::iter::empty()) + None } ConstValue::Indirect { alloc_id, .. } => { // FIXME: we don't actually want to print all of these, since some are printed nicely directly as values inline in MIR. // Really we'd want `pretty_print_const_value` to decide which allocations to print, instead of having a separate visitor. - Either::Left(std::iter::once(alloc_id)) + Some(alloc_id) } } } @@ -1443,7 +1441,9 @@ pub fn write_allocations<'tcx>( match c.const_ { Const::Ty(_, _) | Const::Unevaluated(..) => {} Const::Val(val, _) => { - self.0.extend(alloc_ids_from_const_val(val)); + if let Some(id) = alloc_id_from_const_val(val) { + self.0.insert(id); + } } } } |
