diff options
| author | bors <bors@rust-lang.org> | 2023-09-21 12:04:33 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-09-21 12:04:33 +0000 |
| commit | 66ab7e6883c563ceacf8386a50e851e9855cd6b4 (patch) | |
| tree | c8206b6a97130fb396796c98f7bb9a1cd3df77df /compiler/rustc_middle/src/mir/statement.rs | |
| parent | e4a361a48a59ead52b302aaa2e1d9d345264935a (diff) | |
| parent | e9aee820b310e82c7c86ecd7fd931c6f3c51350f (diff) | |
| download | rust-66ab7e6883c563ceacf8386a50e851e9855cd6b4.tar.gz rust-66ab7e6883c563ceacf8386a50e851e9855cd6b4.zip | |
Auto merge of #116027 - GuillaumeGomez:rollup-3zdi9lf, r=GuillaumeGomez
Rollup of 5 pull requests Successful merges: - #115257 (Improve invalid UTF-8 lint by finding the expression initializer) - #115936 (Prevent promotion of const fn calls in inline consts) - #115972 (rename mir::Constant -> mir::ConstOperand, mir::ConstKind -> mir::Const) - #116007 (Call panic_display directly in const_panic_fmt.) - #116019 (Delete obsolete `--disable-per-crate-search` rustdoc flag) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_middle/src/mir/statement.rs')
| -rw-r--r-- | compiler/rustc_middle/src/mir/statement.rs | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/compiler/rustc_middle/src/mir/statement.rs b/compiler/rustc_middle/src/mir/statement.rs index 25534f46960..5ac108bc829 100644 --- a/compiler/rustc_middle/src/mir/statement.rs +++ b/compiler/rustc_middle/src/mir/statement.rs @@ -1,5 +1,5 @@ /// Functionality for statements, operands, places, and things that appear in them. -use super::*; +use super::{interpret::GlobalAlloc, *}; /////////////////////////////////////////////////////////////////////////// // Statements @@ -302,10 +302,10 @@ impl<'tcx> Operand<'tcx> { span: Span, ) -> Self { let ty = Ty::new_fn_def(tcx, def_id, args); - Operand::Constant(Box::new(Constant { + Operand::Constant(Box::new(ConstOperand { span, user_ty: None, - literal: ConstantKind::Val(ConstValue::ZeroSized, ty), + const_: Const::Val(ConstValue::ZeroSized, ty), })) } @@ -333,10 +333,10 @@ impl<'tcx> Operand<'tcx> { }; scalar_size == type_size }); - Operand::Constant(Box::new(Constant { + Operand::Constant(Box::new(ConstOperand { span, user_ty: None, - literal: ConstantKind::Val(ConstValue::Scalar(val), ty), + const_: Const::Val(ConstValue::Scalar(val), ty), })) } @@ -356,9 +356,9 @@ impl<'tcx> Operand<'tcx> { } } - /// Returns the `Constant` that is the target of this `Operand`, or `None` if this `Operand` is a + /// Returns the `ConstOperand` that is the target of this `Operand`, or `None` if this `Operand` is a /// place. - pub fn constant(&self) -> Option<&Constant<'tcx>> { + pub fn constant(&self) -> Option<&ConstOperand<'tcx>> { match self { Operand::Constant(x) => Some(&**x), Operand::Copy(_) | Operand::Move(_) => None, @@ -370,11 +370,31 @@ impl<'tcx> Operand<'tcx> { /// While this is unlikely in general, it's the normal case of what you'll /// find as the `func` in a [`TerminatorKind::Call`]. pub fn const_fn_def(&self) -> Option<(DefId, GenericArgsRef<'tcx>)> { - let const_ty = self.constant()?.literal.ty(); + let const_ty = self.constant()?.const_.ty(); if let ty::FnDef(def_id, args) = *const_ty.kind() { Some((def_id, args)) } else { None } } } +impl<'tcx> ConstOperand<'tcx> { + pub fn check_static_ptr(&self, tcx: TyCtxt<'_>) -> Option<DefId> { + match self.const_.try_to_scalar() { + Some(Scalar::Ptr(ptr, _size)) => match tcx.global_alloc(ptr.provenance) { + GlobalAlloc::Static(def_id) => { + assert!(!tcx.is_thread_local_static(def_id)); + Some(def_id) + } + _ => None, + }, + _ => None, + } + } + + #[inline] + pub fn ty(&self) -> Ty<'tcx> { + self.const_.ty() + } +} + /////////////////////////////////////////////////////////////////////////// /// Rvalues |
