diff options
| author | Bryan Garza <1396101+bryangarza@users.noreply.github.com> | 2023-07-13 16:32:36 -0700 |
|---|---|---|
| committer | Bryan Garza <1396101+bryangarza@users.noreply.github.com> | 2023-07-17 09:43:35 -0700 |
| commit | ef50e204f35ba2952f7ffd0e7560b136f1ace0aa (patch) | |
| tree | 6824c95fb64273695c5c2fa1f8df985cfd6afcbf /compiler/rustc_middle/src | |
| parent | 8ca44ef9caa4049d584fbbce218c219cdca33a2f (diff) | |
| download | rust-ef50e204f35ba2952f7ffd0e7560b136f1ace0aa.tar.gz rust-ef50e204f35ba2952f7ffd0e7560b136f1ace0aa.zip | |
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 1cbfe99f87f..d92c7512fbf 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 |
