about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-07-06 00:00:38 +0000
committerbors <bors@rust-lang.org>2023-07-06 00:00:38 +0000
commit8aca068215d6b7d5e54364b1e6ec953c7ecdaf64 (patch)
treed2de257a7dbe5d262e32e2d9dbe9905ae6714fa4
parent406241832efef6efbf553a8ba332a6da37e19365 (diff)
parenta4f99149fce5ce1ea03a85f73d06d29ee7bd6d5e (diff)
downloadrust-8aca068215d6b7d5e54364b1e6ec953c7ecdaf64.tar.gz
rust-8aca068215d6b7d5e54364b1e6ec953c7ecdaf64.zip
Auto merge of #113291 - oli-obk:pretty_print_mir_const, r=RalfJung
Specialize `try_destructure_mir_constant` for its sole user (pretty printing)

We can't remove the query, as we need to invoke it from rustc_middle, but can only implement it in mir interpretation/const eval.

r? `@RalfJung` for a first round.

While we could move all the logic into pretty printing, that would end up duplicating a bit of code with const eval, which doesn't seem great either.
-rw-r--r--clippy_utils/src/consts.rs7
1 files changed, 4 insertions, 3 deletions
diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs
index 1e1bb2a1d96..d1cfdc49658 100644
--- a/clippy_utils/src/consts.rs
+++ b/clippy_utils/src/consts.rs
@@ -725,13 +725,14 @@ fn field_of_struct<'tcx>(
     result: mir::ConstantKind<'tcx>,
     field: &Ident,
 ) -> Option<mir::ConstantKind<'tcx>> {
-    if let Some(dc) = lcx.tcx.try_destructure_mir_constant(lcx.param_env.and(result))
+    if let mir::ConstantKind::Val(result, ty) = result
+        && let Some(dc) = lcx.tcx.try_destructure_mir_constant_for_diagnostics((result, ty))
         && let Some(dc_variant) = dc.variant
         && let Some(variant) = adt_def.variants().get(dc_variant)
         && let Some(field_idx) = variant.fields.iter().position(|el| el.name == field.name)
-        && let Some(dc_field) = dc.fields.get(field_idx)
+        && let Some(&(val, ty)) = dc.fields.get(field_idx)
     {
-        Some(*dc_field)
+        Some(mir::ConstantKind::Val(val, ty))
     }
     else {
         None