1use std::ops;
4
5use rustc_data_structures::outline;
6use tracing::{debug, instrument};
7
8use super::interpret::GlobalAlloc;
9use super::*;
10use crate::ty::{CoroutineArgsExt, Unnormalized};
11
12#[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)]
17#[non_exhaustive]
18pub struct Statement<'tcx> {
19 pub source_info: SourceInfo,
20 pub kind: StatementKind<'tcx>,
21 pub debuginfos: StmtDebugInfos<'tcx>,
23}
24
25impl<'tcx> Statement<'tcx> {
26 pub fn make_nop(&mut self, drop_debuginfo: bool) {
29 if self.kind == StatementKind::Nop {
30 return;
31 }
32 let replaced_stmt = std::mem::replace(&mut self.kind, StatementKind::Nop);
33 if !drop_debuginfo {
34 let Some(debuginfo) = replaced_stmt.as_debuginfo() else {
35 crate::util::bug::bug_fmt(format_args!("debuginfo is not yet supported."))bug!("debuginfo is not yet supported.")
36 };
37 self.debuginfos.push(debuginfo);
38 }
39 }
40
41 pub fn new(source_info: SourceInfo, kind: StatementKind<'tcx>) -> Self {
42 Statement { source_info, kind, debuginfos: StmtDebugInfos::default() }
43 }
44}
45
46impl<'tcx> StatementKind<'tcx> {
47 pub const fn name(&self) -> &'static str {
50 match self {
51 StatementKind::Assign(..) => "Assign",
52 StatementKind::FakeRead(..) => "FakeRead",
53 StatementKind::SetDiscriminant { .. } => "SetDiscriminant",
54 StatementKind::StorageLive(..) => "StorageLive",
55 StatementKind::StorageDead(..) => "StorageDead",
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((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 ) -> Unnormalized<'tcx, 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 Unnormalized::new_wip(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) => Unnormalized::dummy(
148 args.as_closure()
149 .upvar_tys()
150 .get(f.index())
151 .copied()
152 .unwrap_or_else(|| bug!("field {f:?} out of range: {self_ty:?}")),
153 ),
154 ty::CoroutineClosure(_, args) => Unnormalized::dummy(
155 args.as_coroutine_closure()
156 .upvar_tys()
157 .get(f.index())
158 .copied()
159 .unwrap_or_else(|| bug!("field {f:?} out of range: {self_ty:?}")),
160 ),
161 ty::Coroutine(_, args) => Unnormalized::dummy(
164 args.as_coroutine().prefix_tys().get(f.index()).copied().unwrap_or_else(|| {
165 bug!("field {f:?} out of range of prefixes for {self_ty}")
166 }),
167 ),
168 ty::Tuple(tys) => Unnormalized::dummy(
169 tys.get(f.index())
170 .copied()
171 .unwrap_or_else(|| bug!("field {f:?} out of range: {self_ty:?}")),
172 ),
173 _ => bug!("can't project out of {self_ty:?}"),
174 }
175 }
176 }
177
178 pub fn multi_projection_ty(
179 self,
180 tcx: TyCtxt<'tcx>,
181 elems: &[PlaceElem<'tcx>],
182 ) -> PlaceTy<'tcx> {
183 elems.iter().fold(self, |place_ty, &elem| place_ty.projection_ty(tcx, elem))
184 }
185
186 pub fn projection_ty<V: ::std::fmt::Debug>(
190 self,
191 tcx: TyCtxt<'tcx>,
192 elem: ProjectionElem<V, Ty<'tcx>>,
193 ) -> PlaceTy<'tcx> {
194 self.projection_ty_core(tcx, &elem, |ty| ty, |_, _, _, ty| ty, |ty| ty)
195 }
196
197 pub fn projection_ty_core<V, T>(
203 self,
204 tcx: TyCtxt<'tcx>,
205 elem: &ProjectionElem<V, T>,
206 mut structurally_normalize: impl FnMut(Ty<'tcx>) -> Ty<'tcx>,
209 mut handle_field: impl FnMut(Ty<'tcx>, Option<VariantIdx>, FieldIdx, T) -> Ty<'tcx>,
210 mut handle_opaque_cast_and_subtype: impl FnMut(T) -> Ty<'tcx>,
211 ) -> PlaceTy<'tcx>
212 where
213 V: ::std::fmt::Debug,
214 T: ::std::fmt::Debug + Copy,
215 {
216 if self.variant_index.is_some() && !#[allow(non_exhaustive_omitted_patterns)] match elem {
ProjectionElem::Field(..) => true,
_ => false,
}matches!(elem, ProjectionElem::Field(..)) {
217 crate::util::bug::bug_fmt(format_args!("cannot use non field projection on downcasted place"))bug!("cannot use non field projection on downcasted place")
218 }
219 let answer = match *elem {
220 ProjectionElem::Deref => {
221 let ty = structurally_normalize(self.ty).builtin_deref(true).unwrap_or_else(|| {
222 crate::util::bug::bug_fmt(format_args!("deref projection of non-dereferenceable ty {0:?}",
self))bug!("deref projection of non-dereferenceable ty {:?}", self)
223 });
224 PlaceTy::from_ty(ty)
225 }
226 ProjectionElem::Index(_) | ProjectionElem::ConstantIndex { .. } => {
227 PlaceTy::from_ty(structurally_normalize(self.ty).builtin_index().unwrap())
228 }
229 ProjectionElem::Subslice { from, to, from_end } => {
230 PlaceTy::from_ty(match structurally_normalize(self.ty).kind() {
231 ty::Slice(..) => self.ty,
232 ty::Array(inner, _) if !from_end => Ty::new_array(tcx, *inner, to - from),
233 ty::Array(inner, size) if from_end => {
234 let size = size
235 .try_to_target_usize(tcx)
236 .expect("expected subslice projection on fixed-size array");
237 let len = size - from - to;
238 Ty::new_array(tcx, *inner, len)
239 }
240 _ => crate::util::bug::bug_fmt(format_args!("cannot subslice non-array type: `{0:?}`",
self))bug!("cannot subslice non-array type: `{:?}`", self),
241 })
242 }
243 ProjectionElem::Downcast(_name, index) => {
244 PlaceTy { ty: self.ty, variant_index: Some(index) }
245 }
246 ProjectionElem::Field(f, fty) => PlaceTy::from_ty(handle_field(
247 structurally_normalize(self.ty),
248 self.variant_index,
249 f,
250 fty,
251 )),
252 ProjectionElem::OpaqueCast(ty) => PlaceTy::from_ty(handle_opaque_cast_and_subtype(ty)),
253
254 ProjectionElem::UnwrapUnsafeBinder(ty) => {
256 PlaceTy::from_ty(handle_opaque_cast_and_subtype(ty))
257 }
258 };
259 {
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:259",
"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(259u32),
::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);
260 answer
261 }
262}
263
264impl<V, T> ProjectionElem<V, T> {
265 pub fn is_indirect(&self) -> bool {
268 match self {
269 Self::Deref => true,
270
271 Self::Field(_, _)
272 | Self::Index(_)
273 | Self::OpaqueCast(_)
274 | Self::ConstantIndex { .. }
275 | Self::Subslice { .. }
276 | Self::Downcast(_, _)
277 | Self::UnwrapUnsafeBinder(..) => false,
278 }
279 }
280
281 pub fn is_stable_offset(&self) -> bool {
284 match self {
285 Self::Deref | Self::Index(_) => false,
286 Self::Field(_, _)
287 | Self::OpaqueCast(_)
288 | Self::ConstantIndex { .. }
289 | Self::Subslice { .. }
290 | Self::Downcast(_, _)
291 | Self::UnwrapUnsafeBinder(..) => true,
292 }
293 }
294
295 pub fn is_downcast_to(&self, v: VariantIdx) -> bool {
297 #[allow(non_exhaustive_omitted_patterns)] match *self {
Self::Downcast(_, x) if x == v => true,
_ => false,
}matches!(*self, Self::Downcast(_, x) if x == v)
298 }
299
300 pub fn is_field_to(&self, f: FieldIdx) -> bool {
302 #[allow(non_exhaustive_omitted_patterns)] match *self {
Self::Field(x, _) if x == f => true,
_ => false,
}matches!(*self, Self::Field(x, _) if x == f)
303 }
304
305 pub fn can_use_in_debuginfo(&self) -> bool {
307 match self {
308 Self::ConstantIndex { from_end: false, .. }
309 | Self::Deref
310 | Self::Downcast(_, _)
311 | Self::Field(_, _) => true,
312 Self::ConstantIndex { from_end: true, .. }
313 | Self::Index(_)
314 | Self::OpaqueCast(_)
315 | Self::Subslice { .. } => false,
316
317 Self::UnwrapUnsafeBinder(..) => false,
319 }
320 }
321
322 pub fn kind(self) -> ProjectionKind {
324 self.try_map(|_| Some(()), |_| ()).unwrap()
325 }
326
327 pub fn try_map<V2, T2>(
329 self,
330 v: impl FnOnce(V) -> Option<V2>,
331 t: impl FnOnce(T) -> T2,
332 ) -> Option<ProjectionElem<V2, T2>> {
333 Some(match self {
334 ProjectionElem::Deref => ProjectionElem::Deref,
335 ProjectionElem::Downcast(name, read_variant) => {
336 ProjectionElem::Downcast(name, read_variant)
337 }
338 ProjectionElem::Field(f, ty) => ProjectionElem::Field(f, t(ty)),
339 ProjectionElem::ConstantIndex { offset, min_length, from_end } => {
340 ProjectionElem::ConstantIndex { offset, min_length, from_end }
341 }
342 ProjectionElem::Subslice { from, to, from_end } => {
343 ProjectionElem::Subslice { from, to, from_end }
344 }
345 ProjectionElem::OpaqueCast(ty) => ProjectionElem::OpaqueCast(t(ty)),
346 ProjectionElem::UnwrapUnsafeBinder(ty) => ProjectionElem::UnwrapUnsafeBinder(t(ty)),
347 ProjectionElem::Index(val) => ProjectionElem::Index(v(val)?),
348 })
349 }
350}
351
352pub type ProjectionKind = ProjectionElem<(), ()>;
355
356#[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)]
357pub struct PlaceRef<'tcx> {
358 pub local: Local,
359 pub projection: &'tcx [PlaceElem<'tcx>],
360}
361
362impl<'tcx> !PartialOrd for PlaceRef<'tcx> {}
367
368impl<'tcx> Place<'tcx> {
369 pub fn return_place() -> Place<'tcx> {
371 Place { local: RETURN_PLACE, projection: List::empty() }
372 }
373
374 pub fn is_indirect(&self) -> bool {
379 self.projection.iter().any(|elem| elem.is_indirect())
380 }
381
382 pub fn is_stable_offset(&self) -> bool {
385 self.projection.iter().all(|elem| elem.is_stable_offset())
386 }
387
388 pub fn is_indirect_first_projection(&self) -> bool {
394 self.as_ref().is_indirect_first_projection()
395 }
396
397 #[inline(always)]
400 pub fn local_or_deref_local(&self) -> Option<Local> {
401 self.as_ref().local_or_deref_local()
402 }
403
404 #[inline(always)]
407 pub fn as_local(&self) -> Option<Local> {
408 self.as_ref().as_local()
409 }
410
411 #[inline]
412 pub fn as_ref(&self) -> PlaceRef<'tcx> {
413 PlaceRef { local: self.local, projection: self.projection }
414 }
415
416 #[inline]
424 pub fn iter_projections(
425 self,
426 ) -> impl Iterator<Item = (PlaceRef<'tcx>, PlaceElem<'tcx>)> + DoubleEndedIterator {
427 self.as_ref().iter_projections()
428 }
429
430 pub fn project_deeper(self, more_projections: &[PlaceElem<'tcx>], tcx: TyCtxt<'tcx>) -> Self {
433 if more_projections.is_empty() {
434 return self;
435 }
436
437 self.as_ref().project_deeper(more_projections, tcx)
438 }
439
440 pub fn project_to_field(
444 self,
445 idx: FieldIdx,
446 local_decls: &impl HasLocalDecls<'tcx>,
447 tcx: TyCtxt<'tcx>,
448 ) -> Self {
449 let ty = self.ty(local_decls, tcx).ty;
450 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}") };
451 let field = &adt.non_enum_variant().fields[idx];
452 let field_ty = field.ty(tcx, args).skip_norm_wip();
453 self.project_deeper(&[ProjectionElem::Field(idx, field_ty)], tcx)
454 }
455
456 pub fn ty_from<D>(
457 local: Local,
458 projection: &[PlaceElem<'tcx>],
459 local_decls: &D,
460 tcx: TyCtxt<'tcx>,
461 ) -> PlaceTy<'tcx>
462 where
463 D: ?Sized + HasLocalDecls<'tcx>,
464 {
465 PlaceTy::from_ty(local_decls.local_decls()[local].ty).multi_projection_ty(tcx, projection)
468 }
469
470 pub fn ty<D: ?Sized>(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> PlaceTy<'tcx>
471 where
472 D: HasLocalDecls<'tcx>,
473 {
474 Place::ty_from(self.local, self.projection, local_decls, tcx)
475 }
476}
477
478impl From<Local> for Place<'_> {
479 #[inline]
480 fn from(local: Local) -> Self {
481 Place { local, projection: List::empty() }
482 }
483}
484
485impl<'tcx> PlaceRef<'tcx> {
486 pub fn is_prefix_of(&self, other: PlaceRef<'tcx>) -> bool {
487 self.local == other.local
488 && self.projection.len() <= other.projection.len()
489 && self.projection == &other.projection[..self.projection.len()]
490 }
491
492 pub fn local_or_deref_local(&self) -> Option<Local> {
495 match *self {
496 PlaceRef { local, projection: [] }
497 | PlaceRef { local, projection: [ProjectionElem::Deref] } => Some(local),
498 _ => None,
499 }
500 }
501
502 pub fn is_indirect(&self) -> bool {
507 self.projection.iter().any(|elem| elem.is_indirect())
508 }
509
510 pub fn is_indirect_first_projection(&self) -> bool {
516 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!(
518 self.projection.is_empty() || !self.projection[1..].contains(&PlaceElem::Deref)
519 );
520 self.projection.first() == Some(&PlaceElem::Deref)
521 }
522
523 #[inline]
526 pub fn as_local(&self) -> Option<Local> {
527 match *self {
528 PlaceRef { local, projection: [] } => Some(local),
529 _ => None,
530 }
531 }
532
533 #[inline]
534 pub fn to_place(&self, tcx: TyCtxt<'tcx>) -> Place<'tcx> {
535 Place { local: self.local, projection: tcx.mk_place_elems(self.projection) }
536 }
537
538 #[inline]
539 pub fn last_projection(&self) -> Option<(PlaceRef<'tcx>, PlaceElem<'tcx>)> {
540 if let &[ref proj_base @ .., elem] = self.projection {
541 Some((PlaceRef { local: self.local, projection: proj_base }, elem))
542 } else {
543 None
544 }
545 }
546
547 #[inline]
555 pub fn iter_projections(
556 self,
557 ) -> impl Iterator<Item = (PlaceRef<'tcx>, PlaceElem<'tcx>)> + DoubleEndedIterator {
558 self.projection.iter().enumerate().map(move |(i, proj)| {
559 let base = PlaceRef { local: self.local, projection: &self.projection[..i] };
560 (base, *proj)
561 })
562 }
563
564 pub fn accessed_locals(self) -> impl Iterator<Item = Local> {
566 std::iter::once(self.local).chain(self.projection.iter().filter_map(|proj| match proj {
567 ProjectionElem::Index(local) => Some(*local),
568 ProjectionElem::Deref
569 | ProjectionElem::Field(_, _)
570 | ProjectionElem::ConstantIndex { .. }
571 | ProjectionElem::Subslice { .. }
572 | ProjectionElem::Downcast(_, _)
573 | ProjectionElem::OpaqueCast(_)
574 | ProjectionElem::UnwrapUnsafeBinder(_) => None,
575 }))
576 }
577
578 pub fn project_deeper(
581 self,
582 more_projections: &[PlaceElem<'tcx>],
583 tcx: TyCtxt<'tcx>,
584 ) -> Place<'tcx> {
585 let mut v: Vec<PlaceElem<'tcx>>;
586
587 let new_projections = if self.projection.is_empty() {
588 more_projections
589 } else {
590 v = Vec::with_capacity(self.projection.len() + more_projections.len());
591 v.extend(self.projection);
592 v.extend(more_projections);
593 &v
594 };
595
596 Place { local: self.local, projection: tcx.mk_place_elems(new_projections) }
597 }
598
599 pub fn ty<D>(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> PlaceTy<'tcx>
600 where
601 D: ?Sized + HasLocalDecls<'tcx>,
602 {
603 Place::ty_from(self.local, self.projection, local_decls, tcx)
604 }
605}
606
607impl From<Local> for PlaceRef<'_> {
608 #[inline]
609 fn from(local: Local) -> Self {
610 PlaceRef { local, projection: &[] }
611 }
612}
613
614impl<'tcx> Operand<'tcx> {
618 pub fn function_handle(
622 tcx: TyCtxt<'tcx>,
623 def_id: DefId,
624 args: ty::Binder<'tcx, impl IntoIterator<Item = GenericArg<'tcx>>>,
625 span: Span,
626 ) -> Self {
627 let ty = Ty::new_fn_def(tcx, def_id, args);
628 Operand::zero_sized_constant(ty, span)
629 }
630
631 pub fn unevaluated_constant(
634 tcx: TyCtxt<'tcx>,
635 def_id: DefId,
636 args: &[GenericArg<'tcx>],
637 span: Span,
638 ) -> Self {
639 let const_ = Const::from_unevaluated(tcx, def_id).instantiate(tcx, args).skip_norm_wip();
640 Operand::Constant(Box::new(ConstOperand { span, user_ty: None, const_ }))
641 }
642
643 pub fn zero_sized_constant(ty: Ty<'tcx>, span: Span) -> Self {
645 let const_ = Const::Val(ConstValue::ZeroSized, ty);
646 Operand::Constant(Box::new(ConstOperand { span, user_ty: None, const_ }))
647 }
648
649 pub fn is_move(&self) -> bool {
650 #[allow(non_exhaustive_omitted_patterns)] match self {
Operand::Move(..) => true,
_ => false,
}matches!(self, Operand::Move(..))
651 }
652
653 pub fn const_from_scalar(
656 tcx: TyCtxt<'tcx>,
657 ty: Ty<'tcx>,
658 val: Scalar,
659 span: Span,
660 ) -> Operand<'tcx> {
661 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!({
662 let typing_env = ty::TypingEnv::fully_monomorphized();
663 let type_size = tcx
664 .layout_of(typing_env.as_query_input(ty))
665 .unwrap_or_else(|e| panic!("could not compute layout for {ty:?}: {e:?}"))
666 .size;
667 let scalar_size = match val {
668 Scalar::Int(int) => int.size(),
669 _ => panic!("Invalid scalar type {val:?}"),
670 };
671 scalar_size == type_size
672 });
673 Operand::Constant(Box::new(ConstOperand {
674 span,
675 user_ty: None,
676 const_: Const::Val(ConstValue::Scalar(val), ty),
677 }))
678 }
679
680 pub fn to_copy(&self) -> Self {
681 match *self {
682 Operand::Copy(_) | Operand::Constant(_) | Operand::RuntimeChecks(_) => self.clone(),
683 Operand::Move(place) => Operand::Copy(place),
684 }
685 }
686
687 pub fn place(&self) -> Option<Place<'tcx>> {
690 match self {
691 Operand::Copy(place) | Operand::Move(place) => Some(*place),
692 Operand::Constant(_) | Operand::RuntimeChecks(_) => None,
693 }
694 }
695
696 pub fn constant(&self) -> Option<&ConstOperand<'tcx>> {
699 match self {
700 Operand::Constant(x) => Some(&**x),
701 Operand::Copy(_) | Operand::Move(_) | Operand::RuntimeChecks(_) => None,
702 }
703 }
704
705 pub fn const_fn_def(&self) -> Option<(DefId, GenericArgsRef<'tcx>)> {
710 let const_ty = self.constant()?.const_.ty();
711 if let ty::FnDef(def_id, args) = *const_ty.kind() {
712 Some((def_id, args.no_bound_vars().unwrap()))
713 } else {
714 None
715 }
716 }
717
718 pub fn ty<D>(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> Ty<'tcx>
719 where
720 D: ?Sized + HasLocalDecls<'tcx>,
721 {
722 match self {
723 &Operand::Copy(ref l) | &Operand::Move(ref l) => l.ty(local_decls, tcx).ty,
724 Operand::Constant(c) => c.const_.ty(),
725 Operand::RuntimeChecks(_) => tcx.types.bool,
726 }
727 }
728
729 pub fn span<D>(&self, local_decls: &D) -> Span
730 where
731 D: ?Sized + HasLocalDecls<'tcx>,
732 {
733 match self {
734 &Operand::Copy(ref l) | &Operand::Move(ref l) => {
735 local_decls.local_decls()[l.local].source_info.span
736 }
737 Operand::Constant(c) => c.span,
738 Operand::RuntimeChecks(_) => DUMMY_SP,
740 }
741 }
742}
743
744impl<'tcx> ConstOperand<'tcx> {
745 pub fn check_static_ptr(&self, tcx: TyCtxt<'_>) -> Option<DefId> {
746 match self.const_.try_to_scalar() {
747 Some(Scalar::Ptr(ptr, _size)) => match tcx.global_alloc(ptr.provenance.alloc_id()) {
748 GlobalAlloc::Static(def_id) => {
749 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));
750 Some(def_id)
751 }
752 _ => None,
753 },
754 _ => None,
755 }
756 }
757
758 #[inline]
759 pub fn ty(&self) -> Ty<'tcx> {
760 self.const_.ty()
761 }
762}
763
764impl<'tcx> Rvalue<'tcx> {
768 #[inline]
770 pub fn is_safe_to_remove(&self) -> bool {
771 match self {
772 Rvalue::Cast(CastKind::PointerExposeProvenance, _, _) => false,
776
777 Rvalue::Use(_, _)
778 | Rvalue::CopyForDeref(_)
779 | Rvalue::Repeat(_, _)
780 | Rvalue::Ref(_, _, _)
781 | Rvalue::Reborrow(_, _, _)
782 | Rvalue::ThreadLocalRef(_)
783 | Rvalue::RawPtr(_, _)
784 | Rvalue::Cast(
785 CastKind::IntToInt
786 | CastKind::FloatToInt
787 | CastKind::FloatToFloat
788 | CastKind::IntToFloat
789 | CastKind::FnPtrToPtr
790 | CastKind::PtrToPtr
791 | CastKind::PointerCoercion(_, _)
792 | CastKind::PointerWithExposedProvenance
793 | CastKind::Transmute
794 | CastKind::Subtype,
795 _,
796 _,
797 )
798 | Rvalue::BinaryOp(_, _)
799 | Rvalue::UnaryOp(_, _)
800 | Rvalue::Discriminant(_)
801 | Rvalue::Aggregate(_, _)
802 | Rvalue::WrapUnsafeBinder(_, _) => true,
803 }
804 }
805
806 pub fn is_generic_reborrow(&self) -> bool {
809 #[allow(non_exhaustive_omitted_patterns)] match self {
Self::Reborrow(..) => true,
_ => false,
}matches!(self, Self::Reborrow(..))
810 }
811
812 pub fn ty<D>(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> Ty<'tcx>
813 where
814 D: ?Sized + HasLocalDecls<'tcx>,
815 {
816 match *self {
817 Rvalue::Use(ref operand, _) => operand.ty(local_decls, tcx),
818 Rvalue::Repeat(ref operand, count) => {
819 Ty::new_array_with_const_len(tcx, operand.ty(local_decls, tcx), count)
820 }
821 Rvalue::ThreadLocalRef(did) => tcx.thread_local_ptr_ty(did),
822 Rvalue::Ref(reg, bk, ref place) => {
823 let place_ty = place.ty(local_decls, tcx).ty;
824 Ty::new_ref(tcx, reg, place_ty, bk.to_mutbl_lossy())
825 }
826 Rvalue::Reborrow(target, _, _) => target,
827 Rvalue::RawPtr(kind, ref place) => {
828 let place_ty = place.ty(local_decls, tcx).ty;
829 Ty::new_ptr(tcx, place_ty, kind.to_mutbl_lossy())
830 }
831 Rvalue::Cast(.., ty) => ty,
832 Rvalue::BinaryOp(op, (ref lhs, ref rhs)) => {
833 let lhs_ty = lhs.ty(local_decls, tcx);
834 let rhs_ty = rhs.ty(local_decls, tcx);
835 op.ty(tcx, lhs_ty, rhs_ty)
836 }
837 Rvalue::UnaryOp(op, ref operand) => {
838 let arg_ty = operand.ty(local_decls, tcx);
839 op.ty(tcx, arg_ty)
840 }
841 Rvalue::Discriminant(ref place) => place.ty(local_decls, tcx).ty.discriminant_ty(tcx),
842 Rvalue::Aggregate(ref ak, ref ops) => match **ak {
843 AggregateKind::Array(ty) => Ty::new_array(tcx, ty, ops.len() as u64),
844 AggregateKind::Tuple => {
845 Ty::new_tup_from_iter(tcx, ops.iter().map(|op| op.ty(local_decls, tcx)))
846 }
847 AggregateKind::Adt(did, _, args, _, _) => {
848 tcx.type_of(did).instantiate(tcx, args).skip_norm_wip()
849 }
850 AggregateKind::Closure(did, args) => Ty::new_closure(tcx, did, args),
851 AggregateKind::Coroutine(did, args) => Ty::new_coroutine(tcx, did, args),
852 AggregateKind::CoroutineClosure(did, args) => {
853 Ty::new_coroutine_closure(tcx, did, args)
854 }
855 AggregateKind::RawPtr(ty, mutability) => Ty::new_ptr(tcx, ty, mutability),
856 },
857 Rvalue::CopyForDeref(ref place) => place.ty(local_decls, tcx).ty,
858 Rvalue::WrapUnsafeBinder(_, ty) => ty,
859 }
860 }
861}
862
863impl BorrowKind {
864 pub fn mutability(&self) -> Mutability {
865 match *self {
866 BorrowKind::Shared | BorrowKind::Fake(_) => Mutability::Not,
867 BorrowKind::Mut { .. } => Mutability::Mut,
868 }
869 }
870
871 pub fn is_two_phase_borrow(&self) -> bool {
874 match *self {
875 BorrowKind::Shared
876 | BorrowKind::Fake(_)
877 | BorrowKind::Mut { kind: MutBorrowKind::Default | MutBorrowKind::ClosureCapture } => {
878 false
879 }
880 BorrowKind::Mut { kind: MutBorrowKind::TwoPhaseBorrow } => true,
881 }
882 }
883
884 pub fn to_mutbl_lossy(self) -> hir::Mutability {
885 match self {
886 BorrowKind::Mut { .. } => hir::Mutability::Mut,
887 BorrowKind::Shared => hir::Mutability::Not,
888
889 BorrowKind::Fake(_) => hir::Mutability::Not,
892 }
893 }
894}
895
896impl<'tcx> UnOp {
897 pub fn ty(&self, tcx: TyCtxt<'tcx>, arg_ty: Ty<'tcx>) -> Ty<'tcx> {
898 match self {
899 UnOp::Not | UnOp::Neg => arg_ty,
900 UnOp::PtrMetadata => arg_ty.pointee_metadata_ty_or_projection(tcx),
901 }
902 }
903}
904
905impl<'tcx> BinOp {
906 pub fn ty(&self, tcx: TyCtxt<'tcx>, lhs_ty: Ty<'tcx>, rhs_ty: Ty<'tcx>) -> Ty<'tcx> {
907 match self {
909 &BinOp::Add
910 | &BinOp::AddUnchecked
911 | &BinOp::Sub
912 | &BinOp::SubUnchecked
913 | &BinOp::Mul
914 | &BinOp::MulUnchecked
915 | &BinOp::Div
916 | &BinOp::Rem
917 | &BinOp::BitXor
918 | &BinOp::BitAnd
919 | &BinOp::BitOr => {
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 lhs_ty
923 }
924 &BinOp::AddWithOverflow | &BinOp::SubWithOverflow | &BinOp::MulWithOverflow => {
925 {
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);
927 Ty::new_tup(tcx, &[lhs_ty, tcx.types.bool])
928 }
929 &BinOp::Shl
930 | &BinOp::ShlUnchecked
931 | &BinOp::Shr
932 | &BinOp::ShrUnchecked
933 | &BinOp::Offset => {
934 lhs_ty }
936 &BinOp::Eq | &BinOp::Lt | &BinOp::Le | &BinOp::Ne | &BinOp::Ge | &BinOp::Gt => {
937 tcx.types.bool
938 }
939 &BinOp::Cmp => {
940 {
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);
942 tcx.ty_ordering_enum(DUMMY_SP)
943 }
944 }
945 }
946 pub(crate) fn to_hir_binop(self) -> hir::BinOpKind {
947 match self {
948 BinOp::Add | BinOp::AddWithOverflow => hir::BinOpKind::Add,
951 BinOp::Sub | BinOp::SubWithOverflow => hir::BinOpKind::Sub,
952 BinOp::Mul | BinOp::MulWithOverflow => hir::BinOpKind::Mul,
953 BinOp::Div => hir::BinOpKind::Div,
954 BinOp::Rem => hir::BinOpKind::Rem,
955 BinOp::BitXor => hir::BinOpKind::BitXor,
956 BinOp::BitAnd => hir::BinOpKind::BitAnd,
957 BinOp::BitOr => hir::BinOpKind::BitOr,
958 BinOp::Shl => hir::BinOpKind::Shl,
959 BinOp::Shr => hir::BinOpKind::Shr,
960 BinOp::Eq => hir::BinOpKind::Eq,
961 BinOp::Ne => hir::BinOpKind::Ne,
962 BinOp::Lt => hir::BinOpKind::Lt,
963 BinOp::Gt => hir::BinOpKind::Gt,
964 BinOp::Le => hir::BinOpKind::Le,
965 BinOp::Ge => hir::BinOpKind::Ge,
966 BinOp::Cmp
968 | BinOp::AddUnchecked
969 | BinOp::SubUnchecked
970 | BinOp::MulUnchecked
971 | BinOp::ShlUnchecked
972 | BinOp::ShrUnchecked
973 | BinOp::Offset => {
974 ::core::panicking::panic("internal error: entered unreachable code")unreachable!()
975 }
976 }
977 }
978
979 pub fn overflowing_to_wrapping(self) -> Option<BinOp> {
981 Some(match self {
982 BinOp::AddWithOverflow => BinOp::Add,
983 BinOp::SubWithOverflow => BinOp::Sub,
984 BinOp::MulWithOverflow => BinOp::Mul,
985 _ => return None,
986 })
987 }
988
989 pub fn is_overflowing(self) -> bool {
991 self.overflowing_to_wrapping().is_some()
992 }
993
994 pub fn wrapping_to_overflowing(self) -> Option<BinOp> {
996 Some(match self {
997 BinOp::Add => BinOp::AddWithOverflow,
998 BinOp::Sub => BinOp::SubWithOverflow,
999 BinOp::Mul => BinOp::MulWithOverflow,
1000 _ => return None,
1001 })
1002 }
1003}
1004
1005impl From<Mutability> for RawPtrKind {
1006 fn from(other: Mutability) -> Self {
1007 match other {
1008 Mutability::Mut => RawPtrKind::Mut,
1009 Mutability::Not => RawPtrKind::Const,
1010 }
1011 }
1012}
1013
1014impl RawPtrKind {
1015 pub fn is_fake(self) -> bool {
1016 match self {
1017 RawPtrKind::Mut | RawPtrKind::Const => false,
1018 RawPtrKind::FakeForPtrMetadata => true,
1019 }
1020 }
1021
1022 pub fn to_mutbl_lossy(self) -> Mutability {
1023 match self {
1024 RawPtrKind::Mut => Mutability::Mut,
1025 RawPtrKind::Const => Mutability::Not,
1026
1027 RawPtrKind::FakeForPtrMetadata => Mutability::Not,
1030 }
1031 }
1032
1033 pub fn ptr_str(self) -> &'static str {
1034 match self {
1035 RawPtrKind::Mut => "mut",
1036 RawPtrKind::Const => "const",
1037 RawPtrKind::FakeForPtrMetadata => "const (fake)",
1038 }
1039 }
1040}
1041
1042type ThinVec<T> = Option<Box<Vec<T>>>;
1046
1047#[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)]
1052pub struct StmtDebugInfos<'tcx>(ThinVec<StmtDebugInfo<'tcx>>);
1053
1054impl<'tcx> StmtDebugInfos<'tcx> {
1055 pub fn push(&mut self, debuginfo: StmtDebugInfo<'tcx>) {
1056 self.0.get_or_insert_default().push(debuginfo);
1057 }
1058 #[inline]
1059 pub fn drop_debuginfo(&mut self) {
1060 match &mut self.0 {
1061 None => (),
1062 Some(v) => outline(move || v.clear()),
1063 }
1064 }
1065
1066 #[inline]
1067 pub fn is_empty(&self) -> bool {
1068 match &self.0 {
1069 None => true,
1070 Some(v) => outline(move || v.is_empty()),
1071 }
1072 }
1073 #[inline]
1074 pub fn prepend(&mut self, debuginfos: &mut Self) {
1075 if debuginfos.is_empty() {
1076 return;
1077 };
1078 outline(move || {
1079 debuginfos.append(self);
1080 std::mem::swap(debuginfos, self);
1081 })
1082 }
1083 #[inline]
1084 pub fn append(&mut self, debuginfos: &mut Self) {
1085 if debuginfos.is_empty() {
1086 return;
1087 };
1088 outline(move || {
1089 self.0.get_or_insert_default().append(debuginfos.0.as_mut().unwrap().as_mut())
1090 });
1091 }
1092 #[inline]
1093 pub fn extend(&mut self, debuginfos: &Self) {
1094 if debuginfos.is_empty() {
1095 return;
1096 };
1097 outline(move || self.0.get_or_insert_default().extend_from_slice(debuginfos.as_slice()))
1098 }
1099
1100 #[inline]
1101 pub fn as_slice(&self) -> &[StmtDebugInfo<'tcx>] {
1102 match &self.0 {
1103 None => &[],
1104 Some(items) => outline(move || items.as_slice()),
1105 }
1106 }
1107
1108 #[inline]
1109 pub fn as_mut_slice(&mut self) -> &mut [StmtDebugInfo<'tcx>] {
1110 match &mut self.0 {
1111 None => &mut [],
1112 Some(items) => outline(move || items.as_mut_slice()),
1113 }
1114 }
1115 #[inline]
1116 pub fn retain_locals(&mut self, locals: &DenseBitSet<Local>) {
1117 match &mut self.0 {
1118 None => (),
1119 Some(items) => outline(move || {
1120 items.retain(|debuginfo| match debuginfo {
1121 StmtDebugInfo::AssignRef(local, _) | StmtDebugInfo::InvalidAssign(local) => {
1122 locals.contains(*local)
1123 }
1124 })
1125 }),
1126 }
1127 }
1128}
1129
1130impl<'tcx> ops::Deref for StmtDebugInfos<'tcx> {
1131 type Target = [StmtDebugInfo<'tcx>];
1132
1133 #[inline]
1134 fn deref(&self) -> &Self::Target {
1135 self.as_slice()
1136 }
1137}
1138
1139impl<'tcx> ops::DerefMut for StmtDebugInfos<'tcx> {
1140 #[inline]
1141 fn deref_mut(&mut self) -> &mut Self::Target {
1142 self.as_mut_slice()
1143 }
1144}
1145
1146#[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)]
1147pub enum StmtDebugInfo<'tcx> {
1148 AssignRef(Local, Place<'tcx>),
1149 InvalidAssign(Local),
1150}