1use std::ops;
4
5use tracing::{debug, instrument};
6
7use super::interpret::GlobalAlloc;
8use super::*;
9use crate::ty::CoroutineArgsExt;
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, '__ctx>
::rustc_data_structures::stable_hasher::HashStable<::rustc_query_system::ich::StableHashingContext<'__ctx>>
for Statement<'tcx> {
#[inline]
fn hash_stable(&self,
__hcx:
&mut ::rustc_query_system::ich::StableHashingContext<'__ctx>,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
match *self {
Statement {
source_info: ref __binding_0,
kind: ref __binding_1,
debuginfos: ref __binding_2 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
{ __binding_2.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable, 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::Retag(..) => "Retag",
56 StatementKind::PlaceMention(..) => "PlaceMention",
57 StatementKind::AscribeUserType(..) => "AscribeUserType",
58 StatementKind::Coverage(..) => "Coverage",
59 StatementKind::Intrinsic(..) => "Intrinsic",
60 StatementKind::ConstEvalCounter => "ConstEvalCounter",
61 StatementKind::Nop => "Nop",
62 StatementKind::BackwardIncompatibleDropHint { .. } => "BackwardIncompatibleDropHint",
63 }
64 }
65 pub fn as_assign_mut(&mut self) -> Option<&mut (Place<'tcx>, Rvalue<'tcx>)> {
66 match self {
67 StatementKind::Assign(x) => Some(x),
68 _ => None,
69 }
70 }
71
72 pub fn as_assign(&self) -> Option<&(Place<'tcx>, Rvalue<'tcx>)> {
73 match self {
74 StatementKind::Assign(x) => Some(x),
75 _ => None,
76 }
77 }
78
79 pub fn as_debuginfo(&self) -> Option<StmtDebugInfo<'tcx>> {
80 match self {
81 StatementKind::Assign(box (place, Rvalue::Ref(_, _, ref_place)))
82 if let Some(local) = place.as_local() =>
83 {
84 Some(StmtDebugInfo::AssignRef(local, *ref_place))
85 }
86 _ => None,
87 }
88 }
89}
90
91#[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)]
95pub struct PlaceTy<'tcx> {
96 pub ty: Ty<'tcx>,
97 pub variant_index: Option<VariantIdx>,
99}
100
101#[cfg(target_pointer_width = "64")]
103const _: [(); 16] = [(); ::std::mem::size_of::<PlaceTy<'_>>()];rustc_data_structures::static_assert_size!(PlaceTy<'_>, 16);
104
105impl<'tcx> PlaceTy<'tcx> {
106 #[inline]
107 pub fn from_ty(ty: Ty<'tcx>) -> PlaceTy<'tcx> {
108 PlaceTy { ty, variant_index: None }
109 }
110
111 x;#[instrument(level = "debug", skip(tcx), ret)]
119 pub fn field_ty(
120 tcx: TyCtxt<'tcx>,
121 self_ty: Ty<'tcx>,
122 variant_idx: Option<VariantIdx>,
123 f: FieldIdx,
124 ) -> Ty<'tcx> {
125 if let Some(variant_index) = variant_idx {
126 match *self_ty.kind() {
127 ty::Adt(adt_def, args) if adt_def.is_enum() => {
128 adt_def.variant(variant_index).fields[f].ty(tcx, args)
129 }
130 ty::Coroutine(def_id, args) => {
131 let mut variants = args.as_coroutine().state_tys(def_id, tcx);
132 let Some(mut variant) = variants.nth(variant_index.into()) else {
133 bug!("variant {variant_index:?} of coroutine out of range: {self_ty:?}");
134 };
135
136 variant.nth(f.index()).unwrap_or_else(|| {
137 bug!("field {f:?} out of range of variant: {self_ty:?} {variant_idx:?}")
138 })
139 }
140 _ => bug!("can't downcast non-adt non-coroutine type: {self_ty:?}"),
141 }
142 } else {
143 match self_ty.kind() {
144 ty::Adt(adt_def, args) if !adt_def.is_enum() => {
145 adt_def.non_enum_variant().fields[f].ty(tcx, args)
146 }
147 ty::Closure(_, args) => args
148 .as_closure()
149 .upvar_tys()
150 .get(f.index())
151 .copied()
152 .unwrap_or_else(|| bug!("field {f:?} out of range: {self_ty:?}")),
153 ty::CoroutineClosure(_, args) => args
154 .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 ty::Coroutine(_, args) => {
162 args.as_coroutine().prefix_tys().get(f.index()).copied().unwrap_or_else(|| {
163 bug!("field {f:?} out of range of prefixes for {self_ty}")
164 })
165 }
166 ty::Tuple(tys) => tys
167 .get(f.index())
168 .copied()
169 .unwrap_or_else(|| bug!("field {f:?} out of range: {self_ty:?}")),
170 _ => bug!("can't project out of {self_ty:?}"),
171 }
172 }
173 }
174
175 pub fn multi_projection_ty(
176 self,
177 tcx: TyCtxt<'tcx>,
178 elems: &[PlaceElem<'tcx>],
179 ) -> PlaceTy<'tcx> {
180 elems.iter().fold(self, |place_ty, &elem| place_ty.projection_ty(tcx, elem))
181 }
182
183 pub fn projection_ty<V: ::std::fmt::Debug>(
187 self,
188 tcx: TyCtxt<'tcx>,
189 elem: ProjectionElem<V, Ty<'tcx>>,
190 ) -> PlaceTy<'tcx> {
191 self.projection_ty_core(tcx, &elem, |ty| ty, |_, _, _, ty| ty, |ty| ty)
192 }
193
194 pub fn projection_ty_core<V, T>(
200 self,
201 tcx: TyCtxt<'tcx>,
202 elem: &ProjectionElem<V, T>,
203 mut structurally_normalize: impl FnMut(Ty<'tcx>) -> Ty<'tcx>,
204 mut handle_field: impl FnMut(Ty<'tcx>, Option<VariantIdx>, FieldIdx, T) -> Ty<'tcx>,
205 mut handle_opaque_cast_and_subtype: impl FnMut(T) -> Ty<'tcx>,
206 ) -> PlaceTy<'tcx>
207 where
208 V: ::std::fmt::Debug,
209 T: ::std::fmt::Debug + Copy,
210 {
211 if self.variant_index.is_some() && !#[allow(non_exhaustive_omitted_patterns)] match elem {
ProjectionElem::Field(..) => true,
_ => false,
}matches!(elem, ProjectionElem::Field(..)) {
212 crate::util::bug::bug_fmt(format_args!("cannot use non field projection on downcasted place"))bug!("cannot use non field projection on downcasted place")
213 }
214 let answer = match *elem {
215 ProjectionElem::Deref => {
216 let ty = structurally_normalize(self.ty).builtin_deref(true).unwrap_or_else(|| {
217 crate::util::bug::bug_fmt(format_args!("deref projection of non-dereferenceable ty {0:?}",
self))bug!("deref projection of non-dereferenceable ty {:?}", self)
218 });
219 PlaceTy::from_ty(ty)
220 }
221 ProjectionElem::Index(_) | ProjectionElem::ConstantIndex { .. } => {
222 PlaceTy::from_ty(structurally_normalize(self.ty).builtin_index().unwrap())
223 }
224 ProjectionElem::Subslice { from, to, from_end } => {
225 PlaceTy::from_ty(match structurally_normalize(self.ty).kind() {
226 ty::Slice(..) => self.ty,
227 ty::Array(inner, _) if !from_end => Ty::new_array(tcx, *inner, to - from),
228 ty::Array(inner, size) if from_end => {
229 let size = size
230 .try_to_target_usize(tcx)
231 .expect("expected subslice projection on fixed-size array");
232 let len = size - from - to;
233 Ty::new_array(tcx, *inner, len)
234 }
235 _ => crate::util::bug::bug_fmt(format_args!("cannot subslice non-array type: `{0:?}`",
self))bug!("cannot subslice non-array type: `{:?}`", self),
236 })
237 }
238 ProjectionElem::Downcast(_name, index) => {
239 PlaceTy { ty: self.ty, variant_index: Some(index) }
240 }
241 ProjectionElem::Field(f, fty) => PlaceTy::from_ty(handle_field(
242 structurally_normalize(self.ty),
243 self.variant_index,
244 f,
245 fty,
246 )),
247 ProjectionElem::OpaqueCast(ty) => PlaceTy::from_ty(handle_opaque_cast_and_subtype(ty)),
248
249 ProjectionElem::UnwrapUnsafeBinder(ty) => {
251 PlaceTy::from_ty(handle_opaque_cast_and_subtype(ty))
252 }
253 };
254 {
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:254",
"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(254u32),
::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);
255 answer
256 }
257}
258
259impl<V, T> ProjectionElem<V, T> {
260 pub fn is_indirect(&self) -> bool {
263 match self {
264 Self::Deref => true,
265
266 Self::Field(_, _)
267 | Self::Index(_)
268 | Self::OpaqueCast(_)
269 | Self::ConstantIndex { .. }
270 | Self::Subslice { .. }
271 | Self::Downcast(_, _)
272 | Self::UnwrapUnsafeBinder(..) => false,
273 }
274 }
275
276 pub fn is_stable_offset(&self) -> bool {
279 match self {
280 Self::Deref | Self::Index(_) => false,
281 Self::Field(_, _)
282 | Self::OpaqueCast(_)
283 | Self::ConstantIndex { .. }
284 | Self::Subslice { .. }
285 | Self::Downcast(_, _)
286 | Self::UnwrapUnsafeBinder(..) => true,
287 }
288 }
289
290 pub fn is_downcast_to(&self, v: VariantIdx) -> bool {
292 #[allow(non_exhaustive_omitted_patterns)] match *self {
Self::Downcast(_, x) if x == v => true,
_ => false,
}matches!(*self, Self::Downcast(_, x) if x == v)
293 }
294
295 pub fn is_field_to(&self, f: FieldIdx) -> bool {
297 #[allow(non_exhaustive_omitted_patterns)] match *self {
Self::Field(x, _) if x == f => true,
_ => false,
}matches!(*self, Self::Field(x, _) if x == f)
298 }
299
300 pub fn can_use_in_debuginfo(&self) -> bool {
302 match self {
303 Self::ConstantIndex { from_end: false, .. }
304 | Self::Deref
305 | Self::Downcast(_, _)
306 | Self::Field(_, _) => true,
307 Self::ConstantIndex { from_end: true, .. }
308 | Self::Index(_)
309 | Self::OpaqueCast(_)
310 | Self::Subslice { .. } => false,
311
312 Self::UnwrapUnsafeBinder(..) => false,
314 }
315 }
316
317 pub fn kind(self) -> ProjectionKind {
319 self.try_map(|_| Some(()), |_| ()).unwrap()
320 }
321
322 pub fn try_map<V2, T2>(
324 self,
325 v: impl FnOnce(V) -> Option<V2>,
326 t: impl FnOnce(T) -> T2,
327 ) -> Option<ProjectionElem<V2, T2>> {
328 Some(match self {
329 ProjectionElem::Deref => ProjectionElem::Deref,
330 ProjectionElem::Downcast(name, read_variant) => {
331 ProjectionElem::Downcast(name, read_variant)
332 }
333 ProjectionElem::Field(f, ty) => ProjectionElem::Field(f, t(ty)),
334 ProjectionElem::ConstantIndex { offset, min_length, from_end } => {
335 ProjectionElem::ConstantIndex { offset, min_length, from_end }
336 }
337 ProjectionElem::Subslice { from, to, from_end } => {
338 ProjectionElem::Subslice { from, to, from_end }
339 }
340 ProjectionElem::OpaqueCast(ty) => ProjectionElem::OpaqueCast(t(ty)),
341 ProjectionElem::UnwrapUnsafeBinder(ty) => ProjectionElem::UnwrapUnsafeBinder(t(ty)),
342 ProjectionElem::Index(val) => ProjectionElem::Index(v(val)?),
343 })
344 }
345}
346
347pub type ProjectionKind = ProjectionElem<(), ()>;
350
351#[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_receiver_is_total_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)]
352pub struct PlaceRef<'tcx> {
353 pub local: Local,
354 pub projection: &'tcx [PlaceElem<'tcx>],
355}
356
357impl<'tcx> !PartialOrd for PlaceRef<'tcx> {}
362
363impl<'tcx> Place<'tcx> {
364 pub fn return_place() -> Place<'tcx> {
366 Place { local: RETURN_PLACE, projection: List::empty() }
367 }
368
369 pub fn is_indirect(&self) -> bool {
374 self.projection.iter().any(|elem| elem.is_indirect())
375 }
376
377 pub fn is_stable_offset(&self) -> bool {
380 self.projection.iter().all(|elem| elem.is_stable_offset())
381 }
382
383 pub fn is_indirect_first_projection(&self) -> bool {
389 self.as_ref().is_indirect_first_projection()
390 }
391
392 #[inline(always)]
395 pub fn local_or_deref_local(&self) -> Option<Local> {
396 self.as_ref().local_or_deref_local()
397 }
398
399 #[inline(always)]
402 pub fn as_local(&self) -> Option<Local> {
403 self.as_ref().as_local()
404 }
405
406 #[inline]
407 pub fn as_ref(&self) -> PlaceRef<'tcx> {
408 PlaceRef { local: self.local, projection: self.projection }
409 }
410
411 #[inline]
419 pub fn iter_projections(
420 self,
421 ) -> impl Iterator<Item = (PlaceRef<'tcx>, PlaceElem<'tcx>)> + DoubleEndedIterator {
422 self.as_ref().iter_projections()
423 }
424
425 pub fn project_deeper(self, more_projections: &[PlaceElem<'tcx>], tcx: TyCtxt<'tcx>) -> Self {
428 if more_projections.is_empty() {
429 return self;
430 }
431
432 self.as_ref().project_deeper(more_projections, tcx)
433 }
434
435 pub fn ty_from<D>(
436 local: Local,
437 projection: &[PlaceElem<'tcx>],
438 local_decls: &D,
439 tcx: TyCtxt<'tcx>,
440 ) -> PlaceTy<'tcx>
441 where
442 D: ?Sized + HasLocalDecls<'tcx>,
443 {
444 PlaceTy::from_ty(local_decls.local_decls()[local].ty).multi_projection_ty(tcx, projection)
447 }
448
449 pub fn ty<D: ?Sized>(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> PlaceTy<'tcx>
450 where
451 D: HasLocalDecls<'tcx>,
452 {
453 Place::ty_from(self.local, self.projection, local_decls, tcx)
454 }
455}
456
457impl From<Local> for Place<'_> {
458 #[inline]
459 fn from(local: Local) -> Self {
460 Place { local, projection: List::empty() }
461 }
462}
463
464impl<'tcx> PlaceRef<'tcx> {
465 pub fn local_or_deref_local(&self) -> Option<Local> {
468 match *self {
469 PlaceRef { local, projection: [] }
470 | PlaceRef { local, projection: [ProjectionElem::Deref] } => Some(local),
471 _ => None,
472 }
473 }
474
475 pub fn is_indirect(&self) -> bool {
480 self.projection.iter().any(|elem| elem.is_indirect())
481 }
482
483 pub fn is_indirect_first_projection(&self) -> bool {
489 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!(
491 self.projection.is_empty() || !self.projection[1..].contains(&PlaceElem::Deref)
492 );
493 self.projection.first() == Some(&PlaceElem::Deref)
494 }
495
496 #[inline]
499 pub fn as_local(&self) -> Option<Local> {
500 match *self {
501 PlaceRef { local, projection: [] } => Some(local),
502 _ => None,
503 }
504 }
505
506 #[inline]
507 pub fn to_place(&self, tcx: TyCtxt<'tcx>) -> Place<'tcx> {
508 Place { local: self.local, projection: tcx.mk_place_elems(self.projection) }
509 }
510
511 #[inline]
512 pub fn last_projection(&self) -> Option<(PlaceRef<'tcx>, PlaceElem<'tcx>)> {
513 if let &[ref proj_base @ .., elem] = self.projection {
514 Some((PlaceRef { local: self.local, projection: proj_base }, elem))
515 } else {
516 None
517 }
518 }
519
520 #[inline]
528 pub fn iter_projections(
529 self,
530 ) -> impl Iterator<Item = (PlaceRef<'tcx>, PlaceElem<'tcx>)> + DoubleEndedIterator {
531 self.projection.iter().enumerate().map(move |(i, proj)| {
532 let base = PlaceRef { local: self.local, projection: &self.projection[..i] };
533 (base, *proj)
534 })
535 }
536
537 pub fn accessed_locals(self) -> impl Iterator<Item = Local> {
539 std::iter::once(self.local).chain(self.projection.iter().filter_map(|proj| match proj {
540 ProjectionElem::Index(local) => Some(*local),
541 ProjectionElem::Deref
542 | ProjectionElem::Field(_, _)
543 | ProjectionElem::ConstantIndex { .. }
544 | ProjectionElem::Subslice { .. }
545 | ProjectionElem::Downcast(_, _)
546 | ProjectionElem::OpaqueCast(_)
547 | ProjectionElem::UnwrapUnsafeBinder(_) => None,
548 }))
549 }
550
551 pub fn project_deeper(
554 self,
555 more_projections: &[PlaceElem<'tcx>],
556 tcx: TyCtxt<'tcx>,
557 ) -> Place<'tcx> {
558 let mut v: Vec<PlaceElem<'tcx>>;
559
560 let new_projections = if self.projection.is_empty() {
561 more_projections
562 } else {
563 v = Vec::with_capacity(self.projection.len() + more_projections.len());
564 v.extend(self.projection);
565 v.extend(more_projections);
566 &v
567 };
568
569 Place { local: self.local, projection: tcx.mk_place_elems(new_projections) }
570 }
571
572 pub fn ty<D>(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> PlaceTy<'tcx>
573 where
574 D: ?Sized + HasLocalDecls<'tcx>,
575 {
576 Place::ty_from(self.local, self.projection, local_decls, tcx)
577 }
578}
579
580impl From<Local> for PlaceRef<'_> {
581 #[inline]
582 fn from(local: Local) -> Self {
583 PlaceRef { local, projection: &[] }
584 }
585}
586
587impl<'tcx> Operand<'tcx> {
591 pub fn function_handle(
595 tcx: TyCtxt<'tcx>,
596 def_id: DefId,
597 args: impl IntoIterator<Item = GenericArg<'tcx>>,
598 span: Span,
599 ) -> Self {
600 let ty = Ty::new_fn_def(tcx, def_id, args);
601 Operand::Constant(Box::new(ConstOperand {
602 span,
603 user_ty: None,
604 const_: Const::Val(ConstValue::ZeroSized, ty),
605 }))
606 }
607
608 pub fn unevaluated_constant(
611 tcx: TyCtxt<'tcx>,
612 def_id: DefId,
613 args: &[GenericArg<'tcx>],
614 span: Span,
615 ) -> Self {
616 let const_ = Const::from_unevaluated(tcx, def_id).instantiate(tcx, args);
617 Operand::Constant(Box::new(ConstOperand { span, user_ty: None, const_ }))
618 }
619
620 pub fn is_move(&self) -> bool {
621 #[allow(non_exhaustive_omitted_patterns)] match self {
Operand::Move(..) => true,
_ => false,
}matches!(self, Operand::Move(..))
622 }
623
624 pub fn const_from_scalar(
627 tcx: TyCtxt<'tcx>,
628 ty: Ty<'tcx>,
629 val: Scalar,
630 span: Span,
631 ) -> Operand<'tcx> {
632 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!({
633 let typing_env = ty::TypingEnv::fully_monomorphized();
634 let type_size = tcx
635 .layout_of(typing_env.as_query_input(ty))
636 .unwrap_or_else(|e| panic!("could not compute layout for {ty:?}: {e:?}"))
637 .size;
638 let scalar_size = match val {
639 Scalar::Int(int) => int.size(),
640 _ => panic!("Invalid scalar type {val:?}"),
641 };
642 scalar_size == type_size
643 });
644 Operand::Constant(Box::new(ConstOperand {
645 span,
646 user_ty: None,
647 const_: Const::Val(ConstValue::Scalar(val), ty),
648 }))
649 }
650
651 pub fn to_copy(&self) -> Self {
652 match *self {
653 Operand::Copy(_) | Operand::Constant(_) | Operand::RuntimeChecks(_) => self.clone(),
654 Operand::Move(place) => Operand::Copy(place),
655 }
656 }
657
658 pub fn place(&self) -> Option<Place<'tcx>> {
661 match self {
662 Operand::Copy(place) | Operand::Move(place) => Some(*place),
663 Operand::Constant(_) | Operand::RuntimeChecks(_) => None,
664 }
665 }
666
667 pub fn constant(&self) -> Option<&ConstOperand<'tcx>> {
670 match self {
671 Operand::Constant(x) => Some(&**x),
672 Operand::Copy(_) | Operand::Move(_) | Operand::RuntimeChecks(_) => None,
673 }
674 }
675
676 pub fn const_fn_def(&self) -> Option<(DefId, GenericArgsRef<'tcx>)> {
681 let const_ty = self.constant()?.const_.ty();
682 if let ty::FnDef(def_id, args) = *const_ty.kind() { Some((def_id, args)) } else { None }
683 }
684
685 pub fn ty<D>(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> Ty<'tcx>
686 where
687 D: ?Sized + HasLocalDecls<'tcx>,
688 {
689 match self {
690 &Operand::Copy(ref l) | &Operand::Move(ref l) => l.ty(local_decls, tcx).ty,
691 Operand::Constant(c) => c.const_.ty(),
692 Operand::RuntimeChecks(_) => tcx.types.bool,
693 }
694 }
695
696 pub fn span<D>(&self, local_decls: &D) -> Span
697 where
698 D: ?Sized + HasLocalDecls<'tcx>,
699 {
700 match self {
701 &Operand::Copy(ref l) | &Operand::Move(ref l) => {
702 local_decls.local_decls()[l.local].source_info.span
703 }
704 Operand::Constant(c) => c.span,
705 Operand::RuntimeChecks(_) => DUMMY_SP,
707 }
708 }
709}
710
711impl<'tcx> ConstOperand<'tcx> {
712 pub fn check_static_ptr(&self, tcx: TyCtxt<'_>) -> Option<DefId> {
713 match self.const_.try_to_scalar() {
714 Some(Scalar::Ptr(ptr, _size)) => match tcx.global_alloc(ptr.provenance.alloc_id()) {
715 GlobalAlloc::Static(def_id) => {
716 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));
717 Some(def_id)
718 }
719 _ => None,
720 },
721 _ => None,
722 }
723 }
724
725 #[inline]
726 pub fn ty(&self) -> Ty<'tcx> {
727 self.const_.ty()
728 }
729}
730
731pub enum RvalueInitializationState {
735 Shallow,
736 Deep,
737}
738
739impl<'tcx> Rvalue<'tcx> {
740 #[inline]
742 pub fn is_safe_to_remove(&self) -> bool {
743 match self {
744 Rvalue::Cast(CastKind::PointerExposeProvenance, _, _) => false,
748
749 Rvalue::Use(_)
750 | Rvalue::CopyForDeref(_)
751 | Rvalue::Repeat(_, _)
752 | Rvalue::Ref(_, _, _)
753 | Rvalue::ThreadLocalRef(_)
754 | Rvalue::RawPtr(_, _)
755 | Rvalue::Cast(
756 CastKind::IntToInt
757 | CastKind::FloatToInt
758 | CastKind::FloatToFloat
759 | CastKind::IntToFloat
760 | CastKind::FnPtrToPtr
761 | CastKind::PtrToPtr
762 | CastKind::PointerCoercion(_, _)
763 | CastKind::PointerWithExposedProvenance
764 | CastKind::Transmute
765 | CastKind::Subtype,
766 _,
767 _,
768 )
769 | Rvalue::BinaryOp(_, _)
770 | Rvalue::UnaryOp(_, _)
771 | Rvalue::Discriminant(_)
772 | Rvalue::Aggregate(_, _)
773 | Rvalue::ShallowInitBox(_, _)
774 | Rvalue::WrapUnsafeBinder(_, _) => true,
775 }
776 }
777
778 pub fn ty<D>(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> Ty<'tcx>
779 where
780 D: ?Sized + HasLocalDecls<'tcx>,
781 {
782 match *self {
783 Rvalue::Use(ref operand) => operand.ty(local_decls, tcx),
784 Rvalue::Repeat(ref operand, count) => {
785 Ty::new_array_with_const_len(tcx, operand.ty(local_decls, tcx), count)
786 }
787 Rvalue::ThreadLocalRef(did) => tcx.thread_local_ptr_ty(did),
788 Rvalue::Ref(reg, bk, ref place) => {
789 let place_ty = place.ty(local_decls, tcx).ty;
790 Ty::new_ref(tcx, reg, place_ty, bk.to_mutbl_lossy())
791 }
792 Rvalue::RawPtr(kind, ref place) => {
793 let place_ty = place.ty(local_decls, tcx).ty;
794 Ty::new_ptr(tcx, place_ty, kind.to_mutbl_lossy())
795 }
796 Rvalue::Cast(.., ty) => ty,
797 Rvalue::BinaryOp(op, box (ref lhs, ref rhs)) => {
798 let lhs_ty = lhs.ty(local_decls, tcx);
799 let rhs_ty = rhs.ty(local_decls, tcx);
800 op.ty(tcx, lhs_ty, rhs_ty)
801 }
802 Rvalue::UnaryOp(op, ref operand) => {
803 let arg_ty = operand.ty(local_decls, tcx);
804 op.ty(tcx, arg_ty)
805 }
806 Rvalue::Discriminant(ref place) => place.ty(local_decls, tcx).ty.discriminant_ty(tcx),
807 Rvalue::Aggregate(ref ak, ref ops) => match **ak {
808 AggregateKind::Array(ty) => Ty::new_array(tcx, ty, ops.len() as u64),
809 AggregateKind::Tuple => {
810 Ty::new_tup_from_iter(tcx, ops.iter().map(|op| op.ty(local_decls, tcx)))
811 }
812 AggregateKind::Adt(did, _, args, _, _) => tcx.type_of(did).instantiate(tcx, args),
813 AggregateKind::Closure(did, args) => Ty::new_closure(tcx, did, args),
814 AggregateKind::Coroutine(did, args) => Ty::new_coroutine(tcx, did, args),
815 AggregateKind::CoroutineClosure(did, args) => {
816 Ty::new_coroutine_closure(tcx, did, args)
817 }
818 AggregateKind::RawPtr(ty, mutability) => Ty::new_ptr(tcx, ty, mutability),
819 },
820 Rvalue::ShallowInitBox(_, ty) => Ty::new_box(tcx, ty),
821 Rvalue::CopyForDeref(ref place) => place.ty(local_decls, tcx).ty,
822 Rvalue::WrapUnsafeBinder(_, ty) => ty,
823 }
824 }
825
826 #[inline]
827 pub fn initialization_state(&self) -> RvalueInitializationState {
830 match *self {
831 Rvalue::ShallowInitBox(_, _) => RvalueInitializationState::Shallow,
832 _ => RvalueInitializationState::Deep,
833 }
834 }
835}
836
837impl BorrowKind {
838 pub fn mutability(&self) -> Mutability {
839 match *self {
840 BorrowKind::Shared | BorrowKind::Fake(_) => Mutability::Not,
841 BorrowKind::Mut { .. } => Mutability::Mut,
842 }
843 }
844
845 pub fn is_two_phase_borrow(&self) -> bool {
848 match *self {
849 BorrowKind::Shared
850 | BorrowKind::Fake(_)
851 | BorrowKind::Mut { kind: MutBorrowKind::Default | MutBorrowKind::ClosureCapture } => {
852 false
853 }
854 BorrowKind::Mut { kind: MutBorrowKind::TwoPhaseBorrow } => true,
855 }
856 }
857
858 pub fn to_mutbl_lossy(self) -> hir::Mutability {
859 match self {
860 BorrowKind::Mut { .. } => hir::Mutability::Mut,
861 BorrowKind::Shared => hir::Mutability::Not,
862
863 BorrowKind::Fake(_) => hir::Mutability::Not,
866 }
867 }
868}
869
870impl<'tcx> UnOp {
871 pub fn ty(&self, tcx: TyCtxt<'tcx>, arg_ty: Ty<'tcx>) -> Ty<'tcx> {
872 match self {
873 UnOp::Not | UnOp::Neg => arg_ty,
874 UnOp::PtrMetadata => arg_ty.pointee_metadata_ty_or_projection(tcx),
875 }
876 }
877}
878
879impl<'tcx> BinOp {
880 pub fn ty(&self, tcx: TyCtxt<'tcx>, lhs_ty: Ty<'tcx>, rhs_ty: Ty<'tcx>) -> Ty<'tcx> {
881 match self {
883 &BinOp::Add
884 | &BinOp::AddUnchecked
885 | &BinOp::Sub
886 | &BinOp::SubUnchecked
887 | &BinOp::Mul
888 | &BinOp::MulUnchecked
889 | &BinOp::Div
890 | &BinOp::Rem
891 | &BinOp::BitXor
892 | &BinOp::BitAnd
893 | &BinOp::BitOr => {
894 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);
896 lhs_ty
897 }
898 &BinOp::AddWithOverflow | &BinOp::SubWithOverflow | &BinOp::MulWithOverflow => {
899 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);
901 Ty::new_tup(tcx, &[lhs_ty, tcx.types.bool])
902 }
903 &BinOp::Shl
904 | &BinOp::ShlUnchecked
905 | &BinOp::Shr
906 | &BinOp::ShrUnchecked
907 | &BinOp::Offset => {
908 lhs_ty }
910 &BinOp::Eq | &BinOp::Lt | &BinOp::Le | &BinOp::Ne | &BinOp::Ge | &BinOp::Gt => {
911 tcx.types.bool
912 }
913 &BinOp::Cmp => {
914 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);
916 tcx.ty_ordering_enum(DUMMY_SP)
917 }
918 }
919 }
920 pub(crate) fn to_hir_binop(self) -> hir::BinOpKind {
921 match self {
922 BinOp::Add | BinOp::AddWithOverflow => hir::BinOpKind::Add,
925 BinOp::Sub | BinOp::SubWithOverflow => hir::BinOpKind::Sub,
926 BinOp::Mul | BinOp::MulWithOverflow => hir::BinOpKind::Mul,
927 BinOp::Div => hir::BinOpKind::Div,
928 BinOp::Rem => hir::BinOpKind::Rem,
929 BinOp::BitXor => hir::BinOpKind::BitXor,
930 BinOp::BitAnd => hir::BinOpKind::BitAnd,
931 BinOp::BitOr => hir::BinOpKind::BitOr,
932 BinOp::Shl => hir::BinOpKind::Shl,
933 BinOp::Shr => hir::BinOpKind::Shr,
934 BinOp::Eq => hir::BinOpKind::Eq,
935 BinOp::Ne => hir::BinOpKind::Ne,
936 BinOp::Lt => hir::BinOpKind::Lt,
937 BinOp::Gt => hir::BinOpKind::Gt,
938 BinOp::Le => hir::BinOpKind::Le,
939 BinOp::Ge => hir::BinOpKind::Ge,
940 BinOp::Cmp
942 | BinOp::AddUnchecked
943 | BinOp::SubUnchecked
944 | BinOp::MulUnchecked
945 | BinOp::ShlUnchecked
946 | BinOp::ShrUnchecked
947 | BinOp::Offset => {
948 ::core::panicking::panic("internal error: entered unreachable code")unreachable!()
949 }
950 }
951 }
952
953 pub fn overflowing_to_wrapping(self) -> Option<BinOp> {
955 Some(match self {
956 BinOp::AddWithOverflow => BinOp::Add,
957 BinOp::SubWithOverflow => BinOp::Sub,
958 BinOp::MulWithOverflow => BinOp::Mul,
959 _ => return None,
960 })
961 }
962
963 pub fn is_overflowing(self) -> bool {
965 self.overflowing_to_wrapping().is_some()
966 }
967
968 pub fn wrapping_to_overflowing(self) -> Option<BinOp> {
970 Some(match self {
971 BinOp::Add => BinOp::AddWithOverflow,
972 BinOp::Sub => BinOp::SubWithOverflow,
973 BinOp::Mul => BinOp::MulWithOverflow,
974 _ => return None,
975 })
976 }
977}
978
979impl From<Mutability> for RawPtrKind {
980 fn from(other: Mutability) -> Self {
981 match other {
982 Mutability::Mut => RawPtrKind::Mut,
983 Mutability::Not => RawPtrKind::Const,
984 }
985 }
986}
987
988impl RawPtrKind {
989 pub fn is_fake(self) -> bool {
990 match self {
991 RawPtrKind::Mut | RawPtrKind::Const => false,
992 RawPtrKind::FakeForPtrMetadata => true,
993 }
994 }
995
996 pub fn to_mutbl_lossy(self) -> Mutability {
997 match self {
998 RawPtrKind::Mut => Mutability::Mut,
999 RawPtrKind::Const => Mutability::Not,
1000
1001 RawPtrKind::FakeForPtrMetadata => Mutability::Not,
1004 }
1005 }
1006
1007 pub fn ptr_str(self) -> &'static str {
1008 match self {
1009 RawPtrKind::Mut => "mut",
1010 RawPtrKind::Const => "const",
1011 RawPtrKind::FakeForPtrMetadata => "const (fake)",
1012 }
1013 }
1014}
1015
1016#[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, '__ctx>
::rustc_data_structures::stable_hasher::HashStable<::rustc_query_system::ich::StableHashingContext<'__ctx>>
for StmtDebugInfos<'tcx> {
#[inline]
fn hash_stable(&self,
__hcx:
&mut ::rustc_query_system::ich::StableHashingContext<'__ctx>,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
match *self {
StmtDebugInfos(ref __binding_0) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable, 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)]
1017pub struct StmtDebugInfos<'tcx>(Vec<StmtDebugInfo<'tcx>>);
1018
1019impl<'tcx> StmtDebugInfos<'tcx> {
1020 pub fn push(&mut self, debuginfo: StmtDebugInfo<'tcx>) {
1021 self.0.push(debuginfo);
1022 }
1023
1024 pub fn drop_debuginfo(&mut self) {
1025 self.0.clear();
1026 }
1027
1028 pub fn is_empty(&self) -> bool {
1029 self.0.is_empty()
1030 }
1031
1032 pub fn prepend(&mut self, debuginfos: &mut Self) {
1033 if debuginfos.is_empty() {
1034 return;
1035 };
1036 debuginfos.0.append(self);
1037 std::mem::swap(debuginfos, self);
1038 }
1039
1040 pub fn append(&mut self, debuginfos: &mut Self) {
1041 if debuginfos.is_empty() {
1042 return;
1043 };
1044 self.0.append(debuginfos);
1045 }
1046
1047 pub fn extend(&mut self, debuginfos: &Self) {
1048 if debuginfos.is_empty() {
1049 return;
1050 };
1051 self.0.extend_from_slice(debuginfos);
1052 }
1053
1054 pub fn retain<F>(&mut self, f: F)
1055 where
1056 F: FnMut(&StmtDebugInfo<'tcx>) -> bool,
1057 {
1058 self.0.retain(f);
1059 }
1060}
1061
1062impl<'tcx> ops::Deref for StmtDebugInfos<'tcx> {
1063 type Target = Vec<StmtDebugInfo<'tcx>>;
1064
1065 #[inline]
1066 fn deref(&self) -> &Vec<StmtDebugInfo<'tcx>> {
1067 &self.0
1068 }
1069}
1070
1071impl<'tcx> ops::DerefMut for StmtDebugInfos<'tcx> {
1072 #[inline]
1073 fn deref_mut(&mut self) -> &mut Vec<StmtDebugInfo<'tcx>> {
1074 &mut self.0
1075 }
1076}
1077
1078#[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, '__ctx>
::rustc_data_structures::stable_hasher::HashStable<::rustc_query_system::ich::StableHashingContext<'__ctx>>
for StmtDebugInfo<'tcx> {
#[inline]
fn hash_stable(&self,
__hcx:
&mut ::rustc_query_system::ich::StableHashingContext<'__ctx>,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
match *self {
StmtDebugInfo::AssignRef(ref __binding_0, ref __binding_1)
=> {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
}
StmtDebugInfo::InvalidAssign(ref __binding_0) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable, 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)]
1079pub enum StmtDebugInfo<'tcx> {
1080 AssignRef(Local, Place<'tcx>),
1081 InvalidAssign(Local),
1082}