Skip to content

Commit

Permalink
Auto merge of rust-lang#113291 - oli-obk:pretty_print_mir_const, r=Ra…
Browse files Browse the repository at this point in the history
…lfJung

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.
  • Loading branch information
bors committed Jul 6, 2023
2 parents 4062418 + a4f9914 commit 8aca068
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions clippy_utils/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8aca068

Please sign in to comment.