1use std::ops;
4
5use tracing::{debug, instrument};
6
7use super::interpret::GlobalAlloc;
8use super::*;
9use crate::ty::{CoroutineArgsExt, Unnormalized};
10
11#[derive(#[automatically_derived]
impl<'tcx> ::core::clone::Clone for Statement<'tcx> {
#[inline]
fn clone(&self) -> Statement<'tcx> {
Statement {
source_info: ::core::clone::Clone::clone(&self.source_info),
kind: ::core::clone::Clone::clone(&self.kind),
debuginfos: ::core::clone::Clone::clone(&self.debuginfos),
}
}
}Clone, const _: () =
{
impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
::rustc_serialize::Encodable<__E> for Statement<'tcx> {
fn encode(&self, __encoder: &mut __E) {
match *self {
Statement {
source_info: ref __binding_0,
kind: ref __binding_1,
debuginfos: ref __binding_2 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_2,
__encoder);
}
}
}
}
};TyEncodable, const _: () =
{
impl<'tcx, __D: ::rustc_middle::ty::codec::TyDecoder<'tcx>>
::rustc_serialize::Decodable<__D> for Statement<'tcx> {
fn decode(__decoder: &mut __D) -> Self {
Statement {
source_info: ::rustc_serialize::Decodable::decode(__decoder),
kind: ::rustc_serialize::Decodable::decode(__decoder),
debuginfos: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};TyDecodable, const _: () =
{
impl<'tcx> ::rustc_data_structures::stable_hash::StableHash for
Statement<'tcx> {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
Statement {
source_info: ref __binding_0,
kind: ref __binding_1,
debuginfos: ref __binding_2 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
{ __binding_2.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash, const _: () =
{
impl<'tcx>
::rustc_middle::ty::TypeFoldable<::rustc_middle::ty::TyCtxt<'tcx>>
for Statement<'tcx> {
fn try_fold_with<__F: ::rustc_middle::ty::FallibleTypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
__folder: &mut __F) -> Result<Self, __F::Error> {
Ok(match self {
Statement {
source_info: __binding_0,
kind: __binding_1,
debuginfos: __binding_2 } => {
Statement {
source_info: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
kind: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
__folder)?,
debuginfos: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_2,
__folder)?,
}
}
})
}
fn fold_with<__F: ::rustc_middle::ty::TypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
__folder: &mut __F) -> Self {
match self {
Statement {
source_info: __binding_0,
kind: __binding_1,
debuginfos: __binding_2 } => {
Statement {
source_info: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder),
kind: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
__folder),
debuginfos: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_2,
__folder),
}
}
}
}
}
};TypeFoldable, const _: () =
{
impl<'tcx>
::rustc_middle::ty::TypeVisitable<::rustc_middle::ty::TyCtxt<'tcx>>
for Statement<'tcx> {
fn visit_with<__V: ::rustc_middle::ty::TypeVisitor<::rustc_middle::ty::TyCtxt<'tcx>>>(&self,
__visitor: &mut __V) -> __V::Result {
match *self {
Statement {
source_info: ref __binding_0,
kind: ref __binding_1,
debuginfos: ref __binding_2 } => {
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_1,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_2,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
}
}
<__V::Result as ::rustc_middle::ty::VisitorResult>::output()
}
}
};TypeVisitable)]
16#[non_exhaustive]
17pub struct Statement<'tcx> {
18 pub source_info: SourceInfo,
19 pub kind: StatementKind<'tcx>,
20 pub debuginfos: StmtDebugInfos<'tcx>,
22}
23
24impl<'tcx> Statement<'tcx> {
25 pub fn make_nop(&mut self, drop_debuginfo: bool) {
28 if self.kind == StatementKind::Nop {
29 return;
30 }
31 let replaced_stmt = std::mem::replace(&mut self.kind, StatementKind::Nop);
32 if !drop_debuginfo {
33 let Some(debuginfo) = replaced_stmt.as_debuginfo() else {
34 crate::util::bug::bug_fmt(format_args!("debuginfo is not yet supported."))bug!("debuginfo is not yet supported.")
35 };
36 self.debuginfos.push(debuginfo);
37 }
38 }
39
40 pub fn new(source_info: SourceInfo, kind: StatementKind<'tcx>) -> Self {
41 Statement { source_info, kind, debuginfos: StmtDebugInfos::default() }
42 }
43}
44
45impl<'tcx> StatementKind<'tcx> {
46 pub const fn name(&self) -> &'static str {
49 match self {
50 StatementKind::Assign(..) => "Assign",
51 StatementKind::FakeRead(..) => "FakeRead",
52 StatementKind::SetDiscriminant { .. } => "SetDiscriminant",
53 StatementKind::StorageLive(..) => "StorageLive",
54 StatementKind::StorageDead(..) => "StorageDead",
55 StatementKind::PlaceMention(..) => "PlaceMention",
56 StatementKind::AscribeUserType(..) => "AscribeUserType",
57 StatementKind::Coverage(..) => "Coverage",
58 StatementKind::Intrinsic(..) => "Intrinsic",
59 StatementKind::ConstEvalCounter => "ConstEvalCounter",
60 StatementKind::Nop => "Nop",
61 StatementKind::BackwardIncompatibleDropHint { .. } => "BackwardIncompatibleDropHint",
62 }
63 }
64 pub fn as_assign_mut(&mut self) -> Option<&mut (Place<'tcx>, Rvalue<'tcx>)> {
65 match self {
66 StatementKind::Assign(x) => Some(x),
67 _ => None,
68 }
69 }
70
71 pub fn as_assign(&self) -> Option<&(Place<'tcx>, Rvalue<'tcx>)> {
72 match self {
73 StatementKind::Assign(x) => Some(x),
74 _ => None,
75 }
76 }
77
78 pub fn as_debuginfo(&self) -> Option<StmtDebugInfo<'tcx>> {
79 match self {
80 StatementKind::Assign((place, Rvalue::Ref(_, _, ref_place)))
81 if let Some(local) = place.as_local() =>
82 {
83 Some(StmtDebugInfo::AssignRef(local, *ref_place))
84 }
85 _ => None,
86 }
87 }
88}
89
90#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for PlaceTy<'tcx> { }Copy, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for PlaceTy<'tcx> {
#[inline]
fn clone(&self) -> PlaceTy<'tcx> {
let _: ::core::clone::AssertParamIsClone<Ty<'tcx>>;
let _: ::core::clone::AssertParamIsClone<Option<VariantIdx>>;
*self
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for PlaceTy<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f, "PlaceTy", "ty",
&self.ty, "variant_index", &&self.variant_index)
}
}Debug, const _: () =
{
impl<'tcx>
::rustc_middle::ty::TypeFoldable<::rustc_middle::ty::TyCtxt<'tcx>>
for PlaceTy<'tcx> {
fn try_fold_with<__F: ::rustc_middle::ty::FallibleTypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
__folder: &mut __F) -> Result<Self, __F::Error> {
Ok(match self {
PlaceTy { ty: __binding_0, variant_index: __binding_1 } => {
PlaceTy {
ty: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
variant_index: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
__folder)?,
}
}
})
}
fn fold_with<__F: ::rustc_middle::ty::TypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
__folder: &mut __F) -> Self {
match self {
PlaceTy { ty: __binding_0, variant_index: __binding_1 } => {
PlaceTy {
ty: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder),
variant_index: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
__folder),
}
}
}
}
}
};TypeFoldable, const _: () =
{
impl<'tcx>
::rustc_middle::ty::TypeVisitable<::rustc_middle::ty::TyCtxt<'tcx>>
for PlaceTy<'tcx> {
fn visit_with<__V: ::rustc_middle::ty::TypeVisitor<::rustc_middle::ty::TyCtxt<'tcx>>>(&self,
__visitor: &mut __V) -> __V::Result {
match *self {
PlaceTy {
ty: ref __binding_0, variant_index: ref __binding_1 } => {
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_1,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
}
}
<__V::Result as ::rustc_middle::ty::VisitorResult>::output()
}
}
};TypeVisitable)]
94pub struct PlaceTy<'tcx> {
95 pub ty: Ty<'tcx>,
96 pub variant_index: Option<VariantIdx>,
98}
99
100#[cfg(target_pointer_width = "64")]
102const _: [(); 16] = [(); ::std::mem::size_of::<PlaceTy<'_>>()];rustc_data_structures::static_assert_size!(PlaceTy<'_>, 16);
103
104impl<'tcx> PlaceTy<'tcx> {
105 #[inline]
106 pub fn from_ty(ty: Ty<'tcx>) -> PlaceTy<'tcx> {
107 PlaceTy { ty, variant_index: None }
108 }
109
110 x;#[instrument(level = "debug", skip(tcx), ret)]
118 pub fn field_ty(
119 tcx: TyCtxt<'tcx>,
120 self_ty: Ty<'tcx>,
121 variant_idx: Option<VariantIdx>,
122 f: FieldIdx,
123 ) -> Unnormalized<'tcx, Ty<'tcx>> {
124 if let Some(variant_index) = variant_idx {
125 match *self_ty.kind() {
126 ty::Adt(adt_def, args) if adt_def.is_enum() => {
127 adt_def.variant(variant_index).fields[f].ty(tcx, args)
128 }
129 ty::Coroutine(def_id, args) => {
130 let mut variants = args.as_coroutine().state_tys(def_id, tcx);
131 let Some(mut variant) = variants.nth(variant_index.into()) else {
132 bug!("variant {variant_index:?} of coroutine out of range: {self_ty:?}");
133 };
134
135 Unnormalized::new_wip(variant.nth(f.index()).unwrap_or_else(|| {
136 bug!("field {f:?} out of range of variant: {self_ty:?} {variant_idx:?}")
137 }))
138 }
139 _ => bug!("can't downcast non-adt non-coroutine type: {self_ty:?}"),
140 }
141 } else {
142 match self_ty.kind() {
143 ty::Adt(adt_def, args) if !adt_def.is_enum() => {
144 adt_def.non_enum_variant().fields[f].ty(tcx, args)
145 }
146 ty::Closure(_, args) => Unnormalized::dummy(
147 args.as_closure()
148 .upvar_tys()
149 .get(f.index())
150 .copied()
151 .unwrap_or_else(|| bug!("field {f:?} out of range: {self_ty:?}")),
152 ),
153 ty::CoroutineClosure(_, args) => Unnormalized::dummy(
154 args.as_coroutine_closure()
155 .upvar_tys()
156 .get(f.index())
157 .copied()
158 .unwrap_or_else(|| bug!("field {f:?} out of range: {self_ty:?}")),
159 ),
160 ty::Coroutine(_, args) => Unnormalized::dummy(
163 args.as_coroutine().prefix_tys().get(f.index()).copied().unwrap_or_else(|| {
164 bug!("field {f:?} out of range of prefixes for {self_ty}")
165 }),
166 ),
167 ty::Tuple(tys) => Unnormalized::dummy(
168 tys.get(f.index())
169 .copied()
170 .unwrap_or_else(|| bug!("field {f:?} out of range: {self_ty:?}")),
171 ),
172 _ => bug!("can't project out of {self_ty:?}"),
173 }
174 }
175 }
176
177 pub fn multi_projection_ty(
178 self,
179 tcx: TyCtxt<'tcx>,
180 elems: &[PlaceElem<'tcx>],
181 ) -> PlaceTy<'tcx> {
182 elems.iter().fold(self, |place_ty, &elem| place_ty.projection_ty(tcx, elem))
183 }
184
185 pub fn projection_ty<V: ::std::fmt::Debug>(
189 self,
190 tcx: TyCtxt<'tcx>,
191 elem: ProjectionElem<V, Ty<'tcx>>,
192 ) -> PlaceTy<'tcx> {
193 self.projection_ty_core(tcx, &elem, |ty| ty, |_, _, _, ty| ty, |ty| ty)
194 }
195
196 pub fn projection_ty_core<V, T>(
202 self,
203 tcx: TyCtxt<'tcx>,
204 elem: &ProjectionElem<V, T>,
205 mut structurally_normalize: impl FnMut(Ty<'tcx>) -> Ty<'tcx>,
208 mut handle_field: impl FnMut(Ty<'tcx>, Option<VariantIdx>, FieldIdx, T) -> Ty<'tcx>,
209 mut handle_opaque_cast_and_subtype: impl FnMut(T) -> Ty<'tcx>,
210 ) -> PlaceTy<'tcx>
211 where
212 V: ::std::fmt::Debug,
213 T: ::std::fmt::Debug + Copy,
214 {
215 if self.variant_index.is_some() && !#[allow(non_exhaustive_omitted_patterns)] match elem {
ProjectionElem::Field(..) => true,
_ => false,
}matches!(elem, ProjectionElem::Field(..)) {
216 crate::util::bug::bug_fmt(format_args!("cannot use non field projection on downcasted place"))bug!("cannot use non field projection on downcasted place")
217 }
218 let answer = match *elem {
219 ProjectionElem::Deref => {
220 let ty = structurally_normalize(self.ty).builtin_deref(true).unwrap_or_else(|| {
221 crate::util::bug::bug_fmt(format_args!("deref projection of non-dereferenceable ty {0:?}",
self))bug!("deref projection of non-dereferenceable ty {:?}", self)
222 });
223 PlaceTy::from_ty(ty)
224 }
225 ProjectionElem::Index(_) | ProjectionElem::ConstantIndex { .. } => {
226 PlaceTy::from_ty(structurally_normalize(self.ty).builtin_index().unwrap())
227 }
228 ProjectionElem::Subslice { from, to, from_end } => {
229 PlaceTy::from_ty(match structurally_normalize(self.ty).kind() {
230 ty::Slice(..) => self.ty,
231 ty::Array(inner, _) if !from_end => Ty::new_array(tcx, *inner, to - from),
232 ty::Array(inner, size) if from_end => {
233 let size = size
234 .try_to_target_usize(tcx)
235 .expect("expected subslice projection on fixed-size array");
236 let len = size - from - to;
237 Ty::new_array(tcx, *inner, len)
238 }
239 _ => crate::util::bug::bug_fmt(format_args!("cannot subslice non-array type: `{0:?}`",
self))bug!("cannot subslice non-array type: `{:?}`", self),
240 })
241 }
242 ProjectionElem::Downcast(_name, index) => {
243 PlaceTy { ty: self.ty, variant_index: Some(index) }
244 }
245 ProjectionElem::Field(f, fty) => PlaceTy::from_ty(handle_field(
246 structurally_normalize(self.ty),
247 self.variant_index,
248 f,
249 fty,
250 )),
251 ProjectionElem::OpaqueCast(ty) => PlaceTy::from_ty(handle_opaque_cast_and_subtype(ty)),
252
253 ProjectionElem::UnwrapUnsafeBinder(ty) => {
255 PlaceTy::from_ty(handle_opaque_cast_and_subtype(ty))
256 }
257 };
258 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_middle/src/mir/statement.rs:258",
"rustc_middle::mir::statement", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/mir/statement.rs"),
::tracing_core::__macro_support::Option::Some(258u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::mir::statement"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("projection_ty self: {0:?} elem: {1:?} yields: {2:?}",
self, elem, answer) as &dyn Value))])
});
} else { ; }
};debug!("projection_ty self: {:?} elem: {:?} yields: {:?}", self, elem, answer);
259 answer
260 }
261}
262
263impl<V, T> ProjectionElem<V, T> {
264 pub fn is_indirect(&self) -> bool {
267 match self {
268 Self::Deref => true,
269
270 Self::Field(_, _)
271 | Self::Index(_)
272 | Self::OpaqueCast(_)
273 | Self::ConstantIndex { .. }
274 | Self::Subslice { .. }
275 | Self::Downcast(_, _)
276 | Self::UnwrapUnsafeBinder(..) => false,
277 }
278 }
279
280 pub fn is_stable_offset(&self) -> bool {
283 match self {
284 Self::Deref | Self::Index(_) => false,
285 Self::Field(_, _)
286 | Self::OpaqueCast(_)
287 | Self::ConstantIndex { .. }
288 | Self::Subslice { .. }
289 | Self::Downcast(_, _)
290 | Self::UnwrapUnsafeBinder(..) => true,
291 }
292 }
293
294 pub fn is_downcast_to(&self, v: VariantIdx) -> bool {
296 #[allow(non_exhaustive_omitted_patterns)] match *self {
Self::Downcast(_, x) if x == v => true,
_ => false,
}matches!(*self, Self::Downcast(_, x) if x == v)
297 }
298
299 pub fn is_field_to(&self, f: FieldIdx) -> bool {
301 #[allow(non_exhaustive_omitted_patterns)] match *self {
Self::Field(x, _) if x == f => true,
_ => false,
}matches!(*self, Self::Field(x, _) if x == f)
302 }
303
304 pub fn can_use_in_debuginfo(&self) -> bool {
306 match self {
307 Self::ConstantIndex { from_end: false, .. }
308 | Self::Deref
309 | Self::Downcast(_, _)
310 | Self::Field(_, _) => true,
311 Self::ConstantIndex { from_end: true, .. }
312 | Self::Index(_)
313 | Self::OpaqueCast(_)
314 | Self::Subslice { .. } => false,
315
316 Self::UnwrapUnsafeBinder(..) => false,
318 }
319 }
320
321 pub fn kind(self) -> ProjectionKind {
323 self.try_map(|_| Some(()), |_| ()).unwrap()
324 }
325
326 pub fn try_map<V2, T2>(
328 self,
329 v: impl FnOnce(V) -> Option<V2>,
330 t: impl FnOnce(T) -> T2,
331 ) -> Option<ProjectionElem<V2, T2>> {
332 Some(match self {
333 ProjectionElem::Deref => ProjectionElem::Deref,
334 ProjectionElem::Downcast(name, read_variant) => {
335 ProjectionElem::Downcast(name, read_variant)
336 }
337 ProjectionElem::Field(f, ty) => ProjectionElem::Field(f, t(ty)),
338 ProjectionElem::ConstantIndex { offset, min_length, from_end } => {
339 ProjectionElem::ConstantIndex { offset, min_length, from_end }
340 }
341 ProjectionElem::Subslice { from, to, from_end } => {
342 ProjectionElem::Subslice { from, to, from_end }
343 }
344 ProjectionElem::OpaqueCast(ty) => ProjectionElem::OpaqueCast(t(ty)),
345 ProjectionElem::UnwrapUnsafeBinder(ty) => ProjectionElem::UnwrapUnsafeBinder(t(ty)),
346 ProjectionElem::Index(val) => ProjectionElem::Index(v(val)?),
347 })
348 }
349}
350
351pub type ProjectionKind = ProjectionElem<(), ()>;
354
355#[derive(#[automatically_derived]
impl<'tcx> ::core::clone::Clone for PlaceRef<'tcx> {
#[inline]
fn clone(&self) -> PlaceRef<'tcx> {
let _: ::core::clone::AssertParamIsClone<Local>;
let _: ::core::clone::AssertParamIsClone<&'tcx [PlaceElem<'tcx>]>;
*self
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::marker::Copy for PlaceRef<'tcx> { }Copy, #[automatically_derived]
impl<'tcx> ::core::cmp::PartialEq for PlaceRef<'tcx> {
#[inline]
fn eq(&self, other: &PlaceRef<'tcx>) -> bool {
self.local == other.local && self.projection == other.projection
}
}PartialEq, #[automatically_derived]
impl<'tcx> ::core::cmp::Eq for PlaceRef<'tcx> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Local>;
let _: ::core::cmp::AssertParamIsEq<&'tcx [PlaceElem<'tcx>]>;
}
}Eq, #[automatically_derived]
impl<'tcx> ::core::hash::Hash for PlaceRef<'tcx> {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.local, state);
::core::hash::Hash::hash(&self.projection, state)
}
}Hash)]
356pub struct PlaceRef<'tcx> {
357 pub local: Local,
358 pub projection: &'tcx [PlaceElem<'tcx>],
359}
360
361impl<'tcx> !PartialOrd for PlaceRef<'tcx> {}
366
367impl<'tcx> Place<'tcx> {
368 pub fn return_place() -> Place<'tcx> {
370 Place { local: RETURN_PLACE, projection: List::empty() }
371 }
372
373 pub fn is_indirect(&self) -> bool {
378 self.projection.iter().any(|elem| elem.is_indirect())
379 }
380
381 pub fn is_stable_offset(&self) -> bool {
384 self.projection.iter().all(|elem| elem.is_stable_offset())
385 }
386
387 pub fn is_indirect_first_projection(&self) -> bool {
393 self.as_ref().is_indirect_first_projection()
394 }
395
396 #[inline(always)]
399 pub fn local_or_deref_local(&self) -> Option<Local> {
400 self.as_ref().local_or_deref_local()
401 }
402
403 #[inline(always)]
406 pub fn as_local(&self) -> Option<Local> {
407 self.as_ref().as_local()
408 }
409
410 #[inline]
411 pub fn as_ref(&self) -> PlaceRef<'tcx> {
412 PlaceRef { local: self.local, projection: self.projection }
413 }
414
415 #[inline]
423 pub fn iter_projections(
424 self,
425 ) -> impl Iterator<Item = (PlaceRef<'tcx>, PlaceElem<'tcx>)> + DoubleEndedIterator {
426 self.as_ref().iter_projections()
427 }
428
429 pub fn project_deeper(self, more_projections: &[PlaceElem<'tcx>], tcx: TyCtxt<'tcx>) -> Self {
432 if more_projections.is_empty() {
433 return self;
434 }
435
436 self.as_ref().project_deeper(more_projections, tcx)
437 }
438
439 pub fn project_to_field(
443 self,
444 idx: FieldIdx,
445 local_decls: &impl HasLocalDecls<'tcx>,
446 tcx: TyCtxt<'tcx>,
447 ) -> Self {
448 let ty = self.ty(local_decls, tcx).ty;
449 let ty::Adt(adt, args) = ty.kind() else { {
::core::panicking::panic_fmt(format_args!("projecting to field of non-ADT {0}",
ty));
}panic!("projecting to field of non-ADT {ty}") };
450 let field = &adt.non_enum_variant().fields[idx];
451 let field_ty = field.ty(tcx, args).skip_norm_wip();
452 self.project_deeper(&[ProjectionElem::Field(idx, field_ty)], tcx)
453 }
454
455 pub fn ty_from<D>(
456 local: Local,
457 projection: &[PlaceElem<'tcx>],
458 local_decls: &D,
459 tcx: TyCtxt<'tcx>,
460 ) -> PlaceTy<'tcx>
461 where
462 D: ?Sized + HasLocalDecls<'tcx>,
463 {
464 PlaceTy::from_ty(local_decls.local_decls()[local].ty).multi_projection_ty(tcx, projection)
467 }
468
469 pub fn ty<D: ?Sized>(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> PlaceTy<'tcx>
470 where
471 D: HasLocalDecls<'tcx>,
472 {
473 Place::ty_from(self.local, self.projection, local_decls, tcx)
474 }
475}
476
477impl From<Local> for Place<'_> {
478 #[inline]
479 fn from(local: Local) -> Self {
480 Place { local, projection: List::empty() }
481 }
482}
483
484impl<'tcx> PlaceRef<'tcx> {
485 pub fn is_prefix_of(&self, other: PlaceRef<'tcx>) -> bool {
486 self.local == other.local
487 && self.projection.len() <= other.projection.len()
488 && self.projection == &other.projection[..self.projection.len()]
489 }
490
491 pub fn local_or_deref_local(&self) -> Option<Local> {
494 match *self {
495 PlaceRef { local, projection: [] }
496 | PlaceRef { local, projection: [ProjectionElem::Deref] } => Some(local),
497 _ => None,
498 }
499 }
500
501 pub fn is_indirect(&self) -> bool {
506 self.projection.iter().any(|elem| elem.is_indirect())
507 }
508
509 pub fn is_indirect_first_projection(&self) -> bool {
515 if true {
if !(self.projection.is_empty() ||
!self.projection[1..].contains(&PlaceElem::Deref)) {
::core::panicking::panic("assertion failed: self.projection.is_empty() ||\n !self.projection[1..].contains(&PlaceElem::Deref)")
};
};debug_assert!(
517 self.projection.is_empty() || !self.projection[1..].contains(&PlaceElem::Deref)
518 );
519 self.projection.first() == Some(&PlaceElem::Deref)
520 }
521
522 #[inline]
525 pub fn as_local(&self) -> Option<Local> {
526 match *self {
527 PlaceRef { local, projection: [] } => Some(local),
528 _ => None,
529 }
530 }
531
532 #[inline]
533 pub fn to_place(&self, tcx: TyCtxt<'tcx>) -> Place<'tcx> {
534 Place { local: self.local, projection: tcx.mk_place_elems(self.projection) }
535 }
536
537 #[inline]
538 pub fn last_projection(&self) -> Option<(PlaceRef<'tcx>, PlaceElem<'tcx>)> {
539 if let &[ref proj_base @ .., elem] = self.projection {
540 Some((PlaceRef { local: self.local, projection: proj_base }, elem))
541 } else {
542 None
543 }
544 }
545
546 #[inline]
554 pub fn iter_projections(
555 self,
556 ) -> impl Iterator<Item = (PlaceRef<'tcx>, PlaceElem<'tcx>)> + DoubleEndedIterator {
557 self.projection.iter().enumerate().map(move |(i, proj)| {
558 let base = PlaceRef { local: self.local, projection: &self.projection[..i] };
559 (base, *proj)
560 })
561 }
562
563 pub fn accessed_locals(self) -> impl Iterator<Item = Local> {
565 std::iter::once(self.local).chain(self.projection.iter().filter_map(|proj| match proj {
566 ProjectionElem::Index(local) => Some(*local),
567 ProjectionElem::Deref
568 | ProjectionElem::Field(_, _)
569 | ProjectionElem::ConstantIndex { .. }
570 | ProjectionElem::Subslice { .. }
571 | ProjectionElem::Downcast(_, _)
572 | ProjectionElem::OpaqueCast(_)
573 | ProjectionElem::UnwrapUnsafeBinder(_) => None,
574 }))
575 }
576
577 pub fn project_deeper(
580 self,
581 more_projections: &[PlaceElem<'tcx>],
582 tcx: TyCtxt<'tcx>,
583 ) -> Place<'tcx> {
584 let mut v: Vec<PlaceElem<'tcx>>;
585
586 let new_projections = if self.projection.is_empty() {
587 more_projections
588 } else {
589 v = Vec::with_capacity(self.projection.len() + more_projections.len());
590 v.extend(self.projection);
591 v.extend(more_projections);
592 &v
593 };
594
595 Place { local: self.local, projection: tcx.mk_place_elems(new_projections) }
596 }
597
598 pub fn ty<D>(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> PlaceTy<'tcx>
599 where
600 D: ?Sized + HasLocalDecls<'tcx>,
601 {
602 Place::ty_from(self.local, self.projection, local_decls, tcx)
603 }
604}
605
606impl From<Local> for PlaceRef<'_> {
607 #[inline]
608 fn from(local: Local) -> Self {
609 PlaceRef { local, projection: &[] }
610 }
611}
612
613impl<'tcx> Operand<'tcx> {
617 pub fn function_handle(
621 tcx: TyCtxt<'tcx>,
622 def_id: DefId,
623 args: impl IntoIterator<Item = GenericArg<'tcx>>,
624 span: Span,
625 ) -> Self {
626 let ty = Ty::new_fn_def(tcx, def_id, args);
627 Operand::zero_sized_constant(ty, span)
628 }
629
630 pub fn unevaluated_constant(
633 tcx: TyCtxt<'tcx>,
634 def_id: DefId,
635 args: &[GenericArg<'tcx>],
636 span: Span,
637 ) -> Self {
638 let const_ = Const::from_unevaluated(tcx, def_id).instantiate(tcx, args).skip_norm_wip();
639 Operand::Constant(Box::new(ConstOperand { span, user_ty: None, const_ }))
640 }
641
642 pub fn zero_sized_constant(ty: Ty<'tcx>, span: Span) -> Self {
644 let const_ = Const::Val(ConstValue::ZeroSized, ty);
645 Operand::Constant(Box::new(ConstOperand { span, user_ty: None, const_ }))
646 }
647
648 pub fn is_move(&self) -> bool {
649 #[allow(non_exhaustive_omitted_patterns)] match self {
Operand::Move(..) => true,
_ => false,
}matches!(self, Operand::Move(..))
650 }
651
652 pub fn const_from_scalar(
655 tcx: TyCtxt<'tcx>,
656 ty: Ty<'tcx>,
657 val: Scalar,
658 span: Span,
659 ) -> Operand<'tcx> {
660 if true {
if !{
let typing_env = ty::TypingEnv::fully_monomorphized();
let type_size =
tcx.layout_of(typing_env.as_query_input(ty)).unwrap_or_else(|e|
{
::core::panicking::panic_fmt(format_args!("could not compute layout for {0:?}: {1:?}",
ty, e));
}).size;
let scalar_size =
match val {
Scalar::Int(int) => int.size(),
_ => {
::core::panicking::panic_fmt(format_args!("Invalid scalar type {0:?}",
val));
}
};
scalar_size == type_size
} {
::core::panicking::panic("assertion failed: {\n let typing_env = ty::TypingEnv::fully_monomorphized();\n let type_size =\n tcx.layout_of(typing_env.as_query_input(ty)).unwrap_or_else(|e|\n panic!(\"could not compute layout for {ty:?}: {e:?}\")).size;\n let scalar_size =\n match val {\n Scalar::Int(int) => int.size(),\n _ => panic!(\"Invalid scalar type {val:?}\"),\n };\n scalar_size == type_size\n}")
};
};debug_assert!({
661 let typing_env = ty::TypingEnv::fully_monomorphized();
662 let type_size = tcx
663 .layout_of(typing_env.as_query_input(ty))
664 .unwrap_or_else(|e| panic!("could not compute layout for {ty:?}: {e:?}"))
665 .size;
666 let scalar_size = match val {
667 Scalar::Int(int) => int.size(),
668 _ => panic!("Invalid scalar type {val:?}"),
669 };
670 scalar_size == type_size
671 });
672 Operand::Constant(Box::new(ConstOperand {
673 span,
674 user_ty: None,
675 const_: Const::Val(ConstValue::Scalar(val), ty),
676 }))
677 }
678
679 pub fn to_copy(&self) -> Self {
680 match *self {
681 Operand::Copy(_) | Operand::Constant(_) | Operand::RuntimeChecks(_) => self.clone(),
682 Operand::Move(place) => Operand::Copy(place),
683 }
684 }
685
686 pub fn place(&self) -> Option<Place<'tcx>> {
689 match self {
690 Operand::Copy(place) | Operand::Move(place) => Some(*place),
691 Operand::Constant(_) | Operand::RuntimeChecks(_) => None,
692 }
693 }
694
695 pub fn constant(&self) -> Option<&ConstOperand<'tcx>> {
698 match self {
699 Operand::Constant(x) => Some(&**x),
700 Operand::Copy(_) | Operand::Move(_) | Operand::RuntimeChecks(_) => None,
701 }
702 }
703
704 pub fn const_fn_def(&self) -> Option<(DefId, GenericArgsRef<'tcx>)> {
709 let const_ty = self.constant()?.const_.ty();
710 if let ty::FnDef(def_id, args) = *const_ty.kind() { Some((def_id, args)) } else { None }
711 }
712
713 pub fn ty<D>(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> Ty<'tcx>
714 where
715 D: ?Sized + HasLocalDecls<'tcx>,
716 {
717 match self {
718 &Operand::Copy(ref l) | &Operand::Move(ref l) => l.ty(local_decls, tcx).ty,
719 Operand::Constant(c) => c.const_.ty(),
720 Operand::RuntimeChecks(_) => tcx.types.bool,
721 }
722 }
723
724 pub fn span<D>(&self, local_decls: &D) -> Span
725 where
726 D: ?Sized + HasLocalDecls<'tcx>,
727 {
728 match self {
729 &Operand::Copy(ref l) | &Operand::Move(ref l) => {
730 local_decls.local_decls()[l.local].source_info.span
731 }
732 Operand::Constant(c) => c.span,
733 Operand::RuntimeChecks(_) => DUMMY_SP,
735 }
736 }
737}
738
739impl<'tcx> ConstOperand<'tcx> {
740 pub fn check_static_ptr(&self, tcx: TyCtxt<'_>) -> Option<DefId> {
741 match self.const_.try_to_scalar() {
742 Some(Scalar::Ptr(ptr, _size)) => match tcx.global_alloc(ptr.provenance.alloc_id()) {
743 GlobalAlloc::Static(def_id) => {
744 if !!tcx.is_thread_local_static(def_id) {
::core::panicking::panic("assertion failed: !tcx.is_thread_local_static(def_id)")
};assert!(!tcx.is_thread_local_static(def_id));
745 Some(def_id)
746 }
747 _ => None,
748 },
749 _ => None,
750 }
751 }
752
753 #[inline]
754 pub fn ty(&self) -> Ty<'tcx> {
755 self.const_.ty()
756 }
757}
758
759impl<'tcx> Rvalue<'tcx> {
763 #[inline]
765 pub fn is_safe_to_remove(&self) -> bool {
766 match self {
767 Rvalue::Cast(CastKind::PointerExposeProvenance, _, _) => false,
771
772 Rvalue::Use(_, _)
773 | Rvalue::CopyForDeref(_)
774 | Rvalue::Repeat(_, _)
775 | Rvalue::Ref(_, _, _)
776 | Rvalue::Reborrow(_, _, _)
777 | Rvalue::ThreadLocalRef(_)
778 | Rvalue::RawPtr(_, _)
779 | Rvalue::Cast(
780 CastKind::IntToInt
781 | CastKind::FloatToInt
782 | CastKind::FloatToFloat
783 | CastKind::IntToFloat
784 | CastKind::FnPtrToPtr
785 | CastKind::PtrToPtr
786 | CastKind::PointerCoercion(_, _)
787 | CastKind::PointerWithExposedProvenance
788 | CastKind::Transmute
789 | CastKind::Subtype,
790 _,
791 _,
792 )
793 | Rvalue::BinaryOp(_, _)
794 | Rvalue::UnaryOp(_, _)
795 | Rvalue::Discriminant(_)
796 | Rvalue::Aggregate(_, _)
797 | Rvalue::WrapUnsafeBinder(_, _) => true,
798 }
799 }
800
801 pub fn is_generic_reborrow(&self) -> bool {
804 #[allow(non_exhaustive_omitted_patterns)] match self {
Self::Reborrow(..) => true,
_ => false,
}matches!(self, Self::Reborrow(..))
805 }
806
807 pub fn ty<D>(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> Ty<'tcx>
808 where
809 D: ?Sized + HasLocalDecls<'tcx>,
810 {
811 match *self {
812 Rvalue::Use(ref operand, _) => operand.ty(local_decls, tcx),
813 Rvalue::Repeat(ref operand, count) => {
814 Ty::new_array_with_const_len(tcx, operand.ty(local_decls, tcx), count)
815 }
816 Rvalue::ThreadLocalRef(did) => tcx.thread_local_ptr_ty(did),
817 Rvalue::Ref(reg, bk, ref place) => {
818 let place_ty = place.ty(local_decls, tcx).ty;
819 Ty::new_ref(tcx, reg, place_ty, bk.to_mutbl_lossy())
820 }
821 Rvalue::Reborrow(target, _, _) => target,
822 Rvalue::RawPtr(kind, ref place) => {
823 let place_ty = place.ty(local_decls, tcx).ty;
824 Ty::new_ptr(tcx, place_ty, kind.to_mutbl_lossy())
825 }
826 Rvalue::Cast(.., ty) => ty,
827 Rvalue::BinaryOp(op, (ref lhs, ref rhs)) => {
828 let lhs_ty = lhs.ty(local_decls, tcx);
829 let rhs_ty = rhs.ty(local_decls, tcx);
830 op.ty(tcx, lhs_ty, rhs_ty)
831 }
832 Rvalue::UnaryOp(op, ref operand) => {
833 let arg_ty = operand.ty(local_decls, tcx);
834 op.ty(tcx, arg_ty)
835 }
836 Rvalue::Discriminant(ref place) => place.ty(local_decls, tcx).ty.discriminant_ty(tcx),
837 Rvalue::Aggregate(ref ak, ref ops) => match **ak {
838 AggregateKind::Array(ty) => Ty::new_array(tcx, ty, ops.len() as u64),
839 AggregateKind::Tuple => {
840 Ty::new_tup_from_iter(tcx, ops.iter().map(|op| op.ty(local_decls, tcx)))
841 }
842 AggregateKind::Adt(did, _, args, _, _) => {
843 tcx.type_of(did).instantiate(tcx, args).skip_norm_wip()
844 }
845 AggregateKind::Closure(did, args) => Ty::new_closure(tcx, did, args),
846 AggregateKind::Coroutine(did, args) => Ty::new_coroutine(tcx, did, args),
847 AggregateKind::CoroutineClosure(did, args) => {
848 Ty::new_coroutine_closure(tcx, did, args)
849 }
850 AggregateKind::RawPtr(ty, mutability) => Ty::new_ptr(tcx, ty, mutability),
851 },
852 Rvalue::CopyForDeref(ref place) => place.ty(local_decls, tcx).ty,
853 Rvalue::WrapUnsafeBinder(_, ty) => ty,
854 }
855 }
856}
857
858impl BorrowKind {
859 pub fn mutability(&self) -> Mutability {
860 match *self {
861 BorrowKind::Shared | BorrowKind::Fake(_) => Mutability::Not,
862 BorrowKind::Mut { .. } => Mutability::Mut,
863 }
864 }
865
866 pub fn is_two_phase_borrow(&self) -> bool {
869 match *self {
870 BorrowKind::Shared
871 | BorrowKind::Fake(_)
872 | BorrowKind::Mut { kind: MutBorrowKind::Default | MutBorrowKind::ClosureCapture } => {
873 false
874 }
875 BorrowKind::Mut { kind: MutBorrowKind::TwoPhaseBorrow } => true,
876 }
877 }
878
879 pub fn to_mutbl_lossy(self) -> hir::Mutability {
880 match self {
881 BorrowKind::Mut { .. } => hir::Mutability::Mut,
882 BorrowKind::Shared => hir::Mutability::Not,
883
884 BorrowKind::Fake(_) => hir::Mutability::Not,
887 }
888 }
889}
890
891impl<'tcx> UnOp {
892 pub fn ty(&self, tcx: TyCtxt<'tcx>, arg_ty: Ty<'tcx>) -> Ty<'tcx> {
893 match self {
894 UnOp::Not | UnOp::Neg => arg_ty,
895 UnOp::PtrMetadata => arg_ty.pointee_metadata_ty_or_projection(tcx),
896 }
897 }
898}
899
900impl<'tcx> BinOp {
901 pub fn ty(&self, tcx: TyCtxt<'tcx>, lhs_ty: Ty<'tcx>, rhs_ty: Ty<'tcx>) -> Ty<'tcx> {
902 match self {
904 &BinOp::Add
905 | &BinOp::AddUnchecked
906 | &BinOp::Sub
907 | &BinOp::SubUnchecked
908 | &BinOp::Mul
909 | &BinOp::MulUnchecked
910 | &BinOp::Div
911 | &BinOp::Rem
912 | &BinOp::BitXor
913 | &BinOp::BitAnd
914 | &BinOp::BitOr => {
915 match (&lhs_ty, &rhs_ty) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val, &*right_val,
::core::option::Option::None);
}
}
};assert_eq!(lhs_ty, rhs_ty);
917 lhs_ty
918 }
919 &BinOp::AddWithOverflow | &BinOp::SubWithOverflow | &BinOp::MulWithOverflow => {
920 match (&lhs_ty, &rhs_ty) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val, &*right_val,
::core::option::Option::None);
}
}
};assert_eq!(lhs_ty, rhs_ty);
922 Ty::new_tup(tcx, &[lhs_ty, tcx.types.bool])
923 }
924 &BinOp::Shl
925 | &BinOp::ShlUnchecked
926 | &BinOp::Shr
927 | &BinOp::ShrUnchecked
928 | &BinOp::Offset => {
929 lhs_ty }
931 &BinOp::Eq | &BinOp::Lt | &BinOp::Le | &BinOp::Ne | &BinOp::Ge | &BinOp::Gt => {
932 tcx.types.bool
933 }
934 &BinOp::Cmp => {
935 match (&lhs_ty, &rhs_ty) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val, &*right_val,
::core::option::Option::None);
}
}
};assert_eq!(lhs_ty, rhs_ty);
937 tcx.ty_ordering_enum(DUMMY_SP)
938 }
939 }
940 }
941 pub(crate) fn to_hir_binop(self) -> hir::BinOpKind {
942 match self {
943 BinOp::Add | BinOp::AddWithOverflow => hir::BinOpKind::Add,
946 BinOp::Sub | BinOp::SubWithOverflow => hir::BinOpKind::Sub,
947 BinOp::Mul | BinOp::MulWithOverflow => hir::BinOpKind::Mul,
948 BinOp::Div => hir::BinOpKind::Div,
949 BinOp::Rem => hir::BinOpKind::Rem,
950 BinOp::BitXor => hir::BinOpKind::BitXor,
951 BinOp::BitAnd => hir::BinOpKind::BitAnd,
952 BinOp::BitOr => hir::BinOpKind::BitOr,
953 BinOp::Shl => hir::BinOpKind::Shl,
954 BinOp::Shr => hir::BinOpKind::Shr,
955 BinOp::Eq => hir::BinOpKind::Eq,
956 BinOp::Ne => hir::BinOpKind::Ne,
957 BinOp::Lt => hir::BinOpKind::Lt,
958 BinOp::Gt => hir::BinOpKind::Gt,
959 BinOp::Le => hir::BinOpKind::Le,
960 BinOp::Ge => hir::BinOpKind::Ge,
961 BinOp::Cmp
963 | BinOp::AddUnchecked
964 | BinOp::SubUnchecked
965 | BinOp::MulUnchecked
966 | BinOp::ShlUnchecked
967 | BinOp::ShrUnchecked
968 | BinOp::Offset => {
969 ::core::panicking::panic("internal error: entered unreachable code")unreachable!()
970 }
971 }
972 }
973
974 pub fn overflowing_to_wrapping(self) -> Option<BinOp> {
976 Some(match self {
977 BinOp::AddWithOverflow => BinOp::Add,
978 BinOp::SubWithOverflow => BinOp::Sub,
979 BinOp::MulWithOverflow => BinOp::Mul,
980 _ => return None,
981 })
982 }
983
984 pub fn is_overflowing(self) -> bool {
986 self.overflowing_to_wrapping().is_some()
987 }
988
989 pub fn wrapping_to_overflowing(self) -> Option<BinOp> {
991 Some(match self {
992 BinOp::Add => BinOp::AddWithOverflow,
993 BinOp::Sub => BinOp::SubWithOverflow,
994 BinOp::Mul => BinOp::MulWithOverflow,
995 _ => return None,
996 })
997 }
998}
999
1000impl From<Mutability> for RawPtrKind {
1001 fn from(other: Mutability) -> Self {
1002 match other {
1003 Mutability::Mut => RawPtrKind::Mut,
1004 Mutability::Not => RawPtrKind::Const,
1005 }
1006 }
1007}
1008
1009impl RawPtrKind {
1010 pub fn is_fake(self) -> bool {
1011 match self {
1012 RawPtrKind::Mut | RawPtrKind::Const => false,
1013 RawPtrKind::FakeForPtrMetadata => true,
1014 }
1015 }
1016
1017 pub fn to_mutbl_lossy(self) -> Mutability {
1018 match self {
1019 RawPtrKind::Mut => Mutability::Mut,
1020 RawPtrKind::Const => Mutability::Not,
1021
1022 RawPtrKind::FakeForPtrMetadata => Mutability::Not,
1025 }
1026 }
1027
1028 pub fn ptr_str(self) -> &'static str {
1029 match self {
1030 RawPtrKind::Mut => "mut",
1031 RawPtrKind::Const => "const",
1032 RawPtrKind::FakeForPtrMetadata => "const (fake)",
1033 }
1034 }
1035}
1036
1037#[derive(#[automatically_derived]
impl<'tcx> ::core::default::Default for StmtDebugInfos<'tcx> {
#[inline]
fn default() -> StmtDebugInfos<'tcx> {
StmtDebugInfos(::core::default::Default::default())
}
}Default, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for StmtDebugInfos<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f, "StmtDebugInfos",
&&self.0)
}
}Debug, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for StmtDebugInfos<'tcx> {
#[inline]
fn clone(&self) -> StmtDebugInfos<'tcx> {
StmtDebugInfos(::core::clone::Clone::clone(&self.0))
}
}Clone, const _: () =
{
impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
::rustc_serialize::Encodable<__E> for StmtDebugInfos<'tcx> {
fn encode(&self, __encoder: &mut __E) {
match *self {
StmtDebugInfos(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
}
}
}
};TyEncodable, const _: () =
{
impl<'tcx, __D: ::rustc_middle::ty::codec::TyDecoder<'tcx>>
::rustc_serialize::Decodable<__D> for StmtDebugInfos<'tcx> {
fn decode(__decoder: &mut __D) -> Self {
StmtDebugInfos(::rustc_serialize::Decodable::decode(__decoder))
}
}
};TyDecodable, const _: () =
{
impl<'tcx> ::rustc_data_structures::stable_hash::StableHash for
StmtDebugInfos<'tcx> {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
StmtDebugInfos(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash, const _: () =
{
impl<'tcx>
::rustc_middle::ty::TypeFoldable<::rustc_middle::ty::TyCtxt<'tcx>>
for StmtDebugInfos<'tcx> {
fn try_fold_with<__F: ::rustc_middle::ty::FallibleTypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
__folder: &mut __F) -> Result<Self, __F::Error> {
Ok(match self {
StmtDebugInfos(__binding_0) => {
StmtDebugInfos(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?)
}
})
}
fn fold_with<__F: ::rustc_middle::ty::TypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
__folder: &mut __F) -> Self {
match self {
StmtDebugInfos(__binding_0) => {
StmtDebugInfos(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder))
}
}
}
}
};TypeFoldable, const _: () =
{
impl<'tcx>
::rustc_middle::ty::TypeVisitable<::rustc_middle::ty::TyCtxt<'tcx>>
for StmtDebugInfos<'tcx> {
fn visit_with<__V: ::rustc_middle::ty::TypeVisitor<::rustc_middle::ty::TyCtxt<'tcx>>>(&self,
__visitor: &mut __V) -> __V::Result {
match *self {
StmtDebugInfos(ref __binding_0) => {
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
}
}
<__V::Result as ::rustc_middle::ty::VisitorResult>::output()
}
}
};TypeVisitable)]
1038pub struct StmtDebugInfos<'tcx>(Vec<StmtDebugInfo<'tcx>>);
1039
1040impl<'tcx> StmtDebugInfos<'tcx> {
1041 pub fn push(&mut self, debuginfo: StmtDebugInfo<'tcx>) {
1042 self.0.push(debuginfo);
1043 }
1044
1045 pub fn drop_debuginfo(&mut self) {
1046 self.0.clear();
1047 }
1048
1049 pub fn is_empty(&self) -> bool {
1050 self.0.is_empty()
1051 }
1052
1053 pub fn prepend(&mut self, debuginfos: &mut Self) {
1054 if debuginfos.is_empty() {
1055 return;
1056 };
1057 debuginfos.0.append(self);
1058 std::mem::swap(debuginfos, self);
1059 }
1060
1061 pub fn append(&mut self, debuginfos: &mut Self) {
1062 if debuginfos.is_empty() {
1063 return;
1064 };
1065 self.0.append(debuginfos);
1066 }
1067
1068 pub fn extend(&mut self, debuginfos: &Self) {
1069 if debuginfos.is_empty() {
1070 return;
1071 };
1072 self.0.extend_from_slice(debuginfos);
1073 }
1074
1075 pub fn retain_locals(&mut self, locals: &DenseBitSet<Local>) {
1076 self.retain(|debuginfo| match debuginfo {
1077 StmtDebugInfo::AssignRef(local, _) | StmtDebugInfo::InvalidAssign(local) => {
1078 locals.contains(*local)
1079 }
1080 });
1081 }
1082}
1083
1084impl<'tcx> ops::Deref for StmtDebugInfos<'tcx> {
1085 type Target = Vec<StmtDebugInfo<'tcx>>;
1086
1087 #[inline]
1088 fn deref(&self) -> &Vec<StmtDebugInfo<'tcx>> {
1089 &self.0
1090 }
1091}
1092
1093impl<'tcx> ops::DerefMut for StmtDebugInfos<'tcx> {
1094 #[inline]
1095 fn deref_mut(&mut self) -> &mut Vec<StmtDebugInfo<'tcx>> {
1096 &mut self.0
1097 }
1098}
1099
1100#[derive(#[automatically_derived]
impl<'tcx> ::core::clone::Clone for StmtDebugInfo<'tcx> {
#[inline]
fn clone(&self) -> StmtDebugInfo<'tcx> {
match self {
StmtDebugInfo::AssignRef(__self_0, __self_1) =>
StmtDebugInfo::AssignRef(::core::clone::Clone::clone(__self_0),
::core::clone::Clone::clone(__self_1)),
StmtDebugInfo::InvalidAssign(__self_0) =>
StmtDebugInfo::InvalidAssign(::core::clone::Clone::clone(__self_0)),
}
}
}Clone, const _: () =
{
impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
::rustc_serialize::Encodable<__E> for StmtDebugInfo<'tcx> {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
StmtDebugInfo::AssignRef(ref __binding_0, ref __binding_1)
=> {
0usize
}
StmtDebugInfo::InvalidAssign(ref __binding_0) => { 1usize }
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
match *self {
StmtDebugInfo::AssignRef(ref __binding_0, ref __binding_1)
=> {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
StmtDebugInfo::InvalidAssign(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
}
}
}
};TyEncodable, const _: () =
{
impl<'tcx, __D: ::rustc_middle::ty::codec::TyDecoder<'tcx>>
::rustc_serialize::Decodable<__D> for StmtDebugInfo<'tcx> {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => {
StmtDebugInfo::AssignRef(::rustc_serialize::Decodable::decode(__decoder),
::rustc_serialize::Decodable::decode(__decoder))
}
1usize => {
StmtDebugInfo::InvalidAssign(::rustc_serialize::Decodable::decode(__decoder))
}
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `StmtDebugInfo`, expected 0..2, actual {0}",
n));
}
}
}
}
};TyDecodable, const _: () =
{
impl<'tcx> ::rustc_data_structures::stable_hash::StableHash for
StmtDebugInfo<'tcx> {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
::std::mem::discriminant(self).stable_hash(__hcx, __hasher);
match *self {
StmtDebugInfo::AssignRef(ref __binding_0, ref __binding_1)
=> {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
StmtDebugInfo::InvalidAssign(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash, const _: () =
{
impl<'tcx>
::rustc_middle::ty::TypeFoldable<::rustc_middle::ty::TyCtxt<'tcx>>
for StmtDebugInfo<'tcx> {
fn try_fold_with<__F: ::rustc_middle::ty::FallibleTypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
__folder: &mut __F) -> Result<Self, __F::Error> {
Ok(match self {
StmtDebugInfo::AssignRef(__binding_0, __binding_1) => {
StmtDebugInfo::AssignRef(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
__folder)?)
}
StmtDebugInfo::InvalidAssign(__binding_0) => {
StmtDebugInfo::InvalidAssign(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?)
}
})
}
fn fold_with<__F: ::rustc_middle::ty::TypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
__folder: &mut __F) -> Self {
match self {
StmtDebugInfo::AssignRef(__binding_0, __binding_1) => {
StmtDebugInfo::AssignRef(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder),
::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
__folder))
}
StmtDebugInfo::InvalidAssign(__binding_0) => {
StmtDebugInfo::InvalidAssign(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder))
}
}
}
}
};TypeFoldable, const _: () =
{
impl<'tcx>
::rustc_middle::ty::TypeVisitable<::rustc_middle::ty::TyCtxt<'tcx>>
for StmtDebugInfo<'tcx> {
fn visit_with<__V: ::rustc_middle::ty::TypeVisitor<::rustc_middle::ty::TyCtxt<'tcx>>>(&self,
__visitor: &mut __V) -> __V::Result {
match *self {
StmtDebugInfo::AssignRef(ref __binding_0, ref __binding_1)
=> {
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_1,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
}
StmtDebugInfo::InvalidAssign(ref __binding_0) => {
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
}
}
<__V::Result as ::rustc_middle::ty::VisitorResult>::output()
}
}
};TypeVisitable)]
1101pub enum StmtDebugInfo<'tcx> {
1102 AssignRef(Local, Place<'tcx>),
1103 InvalidAssign(Local),
1104}