Skip to content

Commit c4d5dde

Browse files
committed
Explain and simplify valtree -> mir-const fallback
1 parent 9cf7810 commit c4d5dde

File tree

1 file changed

+9
-7
lines changed
  • compiler/rustc_mir_build/src/thir/pattern

1 file changed

+9
-7
lines changed

compiler/rustc_mir_build/src/thir/pattern/mod.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -519,16 +519,18 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
519519
};
520520

521521
let cid = GlobalId { instance, promoted: None };
522-
// Prefer
522+
// Prefer valtrees over opaque constants.
523523
let const_value = self
524524
.tcx
525525
.const_eval_global_id_for_typeck(param_env_reveal_all, cid, Some(span))
526-
.and_then(|val| match val {
527-
Some(valtree) => Ok(mir::ConstantKind::Ty(self.tcx.mk_const(valtree, ty))),
528-
None => self
529-
.tcx
530-
.const_eval_global_id(param_env_reveal_all, cid, Some(span))
531-
.map(|lit| mir::ConstantKind::Val(lit, ty)),
526+
.map(|val| match val {
527+
Some(valtree) => mir::ConstantKind::Ty(self.tcx.mk_const(valtree, ty)),
528+
None => mir::ConstantKind::Val(
529+
self.tcx
530+
.const_eval_global_id(param_env_reveal_all, cid, Some(span))
531+
.expect("const_eval_global_id_for_typeck should have already failed"),
532+
ty,
533+
),
532534
});
533535

534536
match const_value {

0 commit comments

Comments
 (0)