diff options
| author | bors <bors@rust-lang.org> | 2023-07-18 09:07:32 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-07-18 09:07:32 +0000 |
| commit | c44324a4fe8e96f9d6473255df6c3a481caca76f (patch) | |
| tree | 349f78508e61de1ac25315cfefa3f8af318d5738 /compiler/rustc_middle/src | |
| parent | 0f16bd341eaf3ad47134c6d855a764e0099fbc93 (diff) | |
| parent | ef50e204f35ba2952f7ffd0e7560b136f1ace0aa (diff) | |
| download | rust-c44324a4fe8e96f9d6473255df6c3a481caca76f.tar.gz rust-c44324a4fe8e96f9d6473255df6c3a481caca76f.zip | |
Auto merge of #113677 - bryangarza:unevaluated-const-ice_issue-110892, r=davidtwco
Safe Transmute: Fix ICE (due to UnevaluatedConst) This patch updates the code that looks at the `Assume` type when evaluating if transmutation is possible. An ICE was being triggered in the case that the `Assume` parameter contained an unevaluated const (in this test case, due to a function with missing parameter names). Fixes #110892
Diffstat (limited to 'compiler/rustc_middle/src')
| -rw-r--r-- | compiler/rustc_middle/src/ty/consts.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/compiler/rustc_middle/src/ty/consts.rs b/compiler/rustc_middle/src/ty/consts.rs index bf9f5846ed9..4ef70107f19 100644 --- a/compiler/rustc_middle/src/ty/consts.rs +++ b/compiler/rustc_middle/src/ty/consts.rs @@ -294,6 +294,14 @@ impl<'tcx> Const<'tcx> { Self::from_bits(tcx, n as u128, ParamEnv::empty().and(tcx.types.usize)) } + /// Attempts to convert to a `ValTree` + pub fn try_to_valtree(self) -> Option<ty::ValTree<'tcx>> { + match self.kind() { + ty::ConstKind::Value(valtree) => Some(valtree), + _ => None, + } + } + #[inline] /// Attempts to evaluate the given constant to bits. Can fail to evaluate in the presence of /// generics (or erroneous code) or if the value can't be represented as bits (e.g. because it |
