1#![allow(rustc::usage_of_ty_tykind)]
13
14use std::cmp::Ordering;
15use std::fmt::Debug;
16use std::hash::{Hash, Hasher};
17use std::marker::PhantomData;
18use std::num::NonZero;
19use std::ops::ControlFlow;
20use std::ptr::NonNull;
21use std::{assert_matches, fmt, iter, str};
22
23pub use adt::*;
24pub use assoc::*;
25pub use generic_args::{GenericArgKind, TermKind, *};
26pub use generics::*;
27pub use intrinsic::IntrinsicDef;
28use rustc_abi::{
29 Align, FieldIdx, Integer, IntegerType, ReprFlags, ReprOptions, ScalableElt, VariantIdx,
30};
31use rustc_ast::{self as ast};
32pub use rustc_ast_ir::{Movability, Mutability, try_visit};
33use rustc_attr_ir::lang_items::LangItem;
34use rustc_attr_ir::{self as attr, find_attr};
35use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
36use rustc_data_structures::intern::Interned;
37use rustc_data_structures::stable_hash::{StableHash, StableHashCtxt, StableHasher};
38use rustc_errors::{Diag, ErrorGuaranteed};
39use rustc_hir as hir;
40use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
41use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId};
42use rustc_index::bit_set::BitMatrix;
43use rustc_index::{IndexVec, static_assert_size};
44pub use rustc_lint_defs::RegisteredTools;
45use rustc_macros::{
46 BlobDecodable, Decodable, Encodable, StableHash, TyDecodable, TyEncodable, TypeFoldable,
47 TypeVisitable, extension,
48};
49use rustc_serialize::{Decodable, Encodable};
50use rustc_session::config::OptLevel;
51use rustc_span::def_id::{LocalModId, ModId};
52use rustc_span::hygiene::MacroKind;
53use rustc_span::{DUMMY_SP, ExpnKind, Ident, Span, Symbol};
54use rustc_target::callconv::FnAbi;
55pub use rustc_type_ir::data_structures::{DelayedMap, DelayedSet};
56pub use rustc_type_ir::fast_reject::DeepRejectCtxt;
57pub use rustc_type_ir::relate::VarianceDiagInfo;
58pub use rustc_type_ir::search_graph::RequiredDepth;
59pub use rustc_type_ir::solve::{CandidatePreferenceMode, SizedTraitKind, VisibleForLeakCheck};
60pub use rustc_type_ir::*;
61use tracing::{debug, instrument};
62pub use vtable::*;
63
64pub use self::closure::{
65 BorrowKind, CAPTURE_STRUCT_LOCAL, CaptureInfo, CapturedPlace, ClosureTypeInfo,
66 MinCaptureInformationMap, MinCaptureList, RootVariableMinCaptureList, UpvarCapture, UpvarId,
67 UpvarPath, analyze_coroutine_closure_captures, is_ancestor_or_same_capture,
68 place_to_string_for_capture,
69};
70pub use self::consts::{
71 AliasConst, AliasConstKind, AtomicOrdering, Const, ConstInt, ConstKind, ConstToValTreeResult,
72 Expr, ExprKind, LitToConstInput, ScalarInt, SimdAlign, ValTree, ValTreeKindExt, Value,
73 const_lit_matches_ty,
74};
75pub use self::context::{
76 CtxtInterners, CurrentGcx, FreeRegionInfo, GlobalCtxt, Lift, TyCtxt, TyCtxtFeed, tls,
77};
78pub use self::fold::*;
79pub use self::instance::{Instance, InstanceKind, ReifyReason, ShimKind};
80pub(crate) use self::list::RawList;
81pub use self::list::{List, ListWithCachedTypeInfo};
82pub use self::opaque_types::OpaqueTypeKey;
83pub use self::pattern::{Pattern, PatternKind};
84pub use self::predicate::{
85 AliasTerm, AliasTermKind, ArgOutlivesClause, Clause, ClauseKind, CoercePredicate,
86 ExistentialPredicate, ExistentialPredicateStableCmpExt, ExistentialProjection,
87 ExistentialTraitRef, HostEffectClause, NormalizesTo, OutlivesClause, PolyCoercePredicate,
88 PolyExistentialPredicate, PolyExistentialProjection, PolyExistentialTraitRef,
89 PolyProjectionClause, PolyRegionOutlivesClause, PolySubtypePredicate, PolyTraitClause,
90 PolyTraitRef, PolyTypeOutlivesClause, Predicate, PredicateKind, ProjectionClause,
91 RegionConstraint, RegionEqPredicate, RegionOutlivesClause, SubtypePredicate, TraitClause,
92 TraitRef, TypeOutlivesClause,
93};
94pub use self::region::{
95 EarlyParamRegion, LateParamRegion, LateParamRegionKind, Region, RegionKind, RegionVid,
96};
97pub use self::sty::{
98 Alias, AliasTy, AliasTyKind, Article, Binder, BoundConst, BoundRegion, BoundRegionKind,
99 BoundTy, BoundTyKind, BoundVariableKind, CanonicalPolyFnSig, CoroutineArgsExt, EarlyBinder,
100 FnSig, FnSigKind, FreeAliasTy, InherentAliasTy, InlineConstArgs, InlineConstArgsParts,
101 OpaqueAliasTy, ParamConst, ParamTy, PlaceholderConst, PlaceholderRegion, PlaceholderType,
102 PolyFnSig, ProjectionAliasTy, TyKind, TypeAndMut, TypingMode, TypingModeEqWrapper,
103 Unnormalized, UpvarArgs,
104};
105pub use self::trait_def::TraitDef;
106pub use self::typeck_results::{
107 CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, IsIdentity,
108 Rust2024IncompatiblePatInfo, SplattedDef, TypeckResults, UserType, UserTypeAnnotationIndex,
109 UserTypeKind,
110};
111use crate::diagnostics::{OpaqueHiddenTypeMismatch, TypeMismatchReason};
112use crate::mir::{Body, CoroutineLayout, CoroutineSavedLocal, MirPhase, SourceInfo};
113use crate::query::{IntoQueryKey, Providers};
114use crate::ty;
115use crate::ty::codec::{TyDecoder, TyEncoder};
116pub use crate::ty::diagnostics::*;
117use crate::ty::fast_reject::SimplifiedType;
118use crate::ty::layout::{FnAbiError, LayoutError};
119use crate::ty::print::{with_crate_prefix, with_no_trimmed_paths};
120use crate::ty::util::Discr;
121use crate::ty::walk::TypeWalker;
122
123pub mod abstract_const;
124pub mod adjustment;
125pub mod cast;
126pub mod codec;
127pub mod error;
128pub mod fast_reject;
129pub mod inhabitedness;
130pub mod layout;
131pub mod normalize_erasing_regions;
132pub mod offload_meta;
133pub mod pattern;
134pub mod print;
135pub mod relate;
136pub mod significant_drop_order;
137pub mod sty;
138pub mod trait_def;
139pub mod typetree;
140pub mod util;
141pub mod vtable;
142
143mod adt;
144mod assoc;
145mod closure;
146mod consts;
147mod context;
148mod diagnostics;
149mod elaborate_impl;
150mod erase_regions;
151mod fold;
152mod generic_args;
153mod generics;
154mod impls_ty;
155mod instance;
156mod intrinsic;
157mod list;
158mod opaque_types;
159mod predicate;
160mod region;
161mod structural_impls;
162mod typeck_results;
163mod visit;
164
165#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for ImplTraitHeader<'tcx> { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl<'tcx> ::core::clone::TrivialClone for ImplTraitHeader<'tcx> { }
#[automatically_derived]
impl<'tcx> ::core::clone::Clone for ImplTraitHeader<'tcx> {
#[inline]
fn clone(&self) -> ImplTraitHeader<'tcx> {
let _:
::core::clone::AssertParamIsClone<ty::EarlyBinder<'tcx,
ty::TraitRef<'tcx>>>;
let _: ::core::clone::AssertParamIsClone<ImplPolarity>;
let _: ::core::clone::AssertParamIsClone<hir::Safety>;
let _: ::core::clone::AssertParamIsClone<hir::Constness>;
*self
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for ImplTraitHeader<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field4_finish(f,
"ImplTraitHeader", "trait_ref", &self.trait_ref, "polarity",
&self.polarity, "safety", &self.safety, "constness",
&&self.constness)
}
}Debug, const _: () =
{
impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
::rustc_serialize::Encodable<__E> for ImplTraitHeader<'tcx> {
fn encode(&self, __encoder: &mut __E) {
let ImplTraitHeader {
trait_ref: ref __binding_0,
polarity: ref __binding_1,
safety: ref __binding_2,
constness: ref __binding_3 } = *self;
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_2,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_3,
__encoder);
}
}
};TyEncodable, const _: () =
{
impl<'tcx, __D: ::rustc_middle::ty::codec::TyDecoder<'tcx>>
::rustc_serialize::Decodable<__D> for ImplTraitHeader<'tcx> {
fn decode(__decoder: &mut __D) -> Self {
ImplTraitHeader {
trait_ref: ::rustc_serialize::Decodable::decode(__decoder),
polarity: ::rustc_serialize::Decodable::decode(__decoder),
safety: ::rustc_serialize::Decodable::decode(__decoder),
constness: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};TyDecodable, const _: () =
{
impl<'tcx> ::rustc_data_structures::stable_hash::StableHash for
ImplTraitHeader<'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 {
ImplTraitHeader {
trait_ref: ref __binding_0,
polarity: ref __binding_1,
safety: ref __binding_2,
constness: ref __binding_3 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
{ __binding_2.stable_hash(__hcx, __hasher); }
{ __binding_3.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash)]
168pub struct ImplTraitHeader<'tcx> {
169 pub trait_ref: ty::EarlyBinder<'tcx, ty::TraitRef<'tcx>>,
170 pub polarity: ImplPolarity,
171 pub safety: hir::Safety,
172 pub constness: hir::Constness,
173}
174
175impl<'tcx> ImplTraitHeader<'tcx> {
176 pub fn is_fully_generic_for_reflection(self) -> bool {
186 #[derive(#[automatically_derived]
impl ::core::default::Default for ParamFinder {
#[inline]
fn default() -> ParamFinder {
ParamFinder { seen: ::core::default::Default::default() }
}
}Default)]
187 struct ParamFinder {
188 seen: FxHashSet<u32>,
189 }
190
191 impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ParamFinder {
192 type Result = ControlFlow<()>;
193 fn visit_region(&mut self, r: Region<'tcx>) -> Self::Result {
194 match r.kind() {
195 RegionKind::ReEarlyParam(param) => {
196 if self.seen.insert(param.index) {
197 ControlFlow::Continue(())
198 } else {
199 ControlFlow::Break(())
200 }
201 }
202 RegionKind::ReBound(..) => ControlFlow::Continue(()),
203 RegionKind::ReStatic | RegionKind::ReError(_) => ControlFlow::Break(()),
204 RegionKind::ReVar(_)
205 | RegionKind::RePlaceholder(_)
206 | RegionKind::ReErased
207 | RegionKind::ReLateParam(_) => crate::util::bug::bug_fmt(format_args!("unexpected lifetime in impl: {0:?}",
r))bug!("unexpected lifetime in impl: {r:?}"),
208 }
209 }
210
211 fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result {
212 match t.kind() {
213 TyKind::Param(p) => {
214 if !self.seen.insert(p.index) {
216 return ControlFlow::Break(());
217 }
218 }
219 TyKind::Alias(..) => return ControlFlow::Break(()),
220 _ => (),
221 }
222 t.super_visit_with(self)
223 }
224 }
225 self.trait_ref
226 .instantiate_identity()
227 .skip_norm_wip()
228 .visit_with(&mut ParamFinder::default())
229 .is_continue()
230 }
231}
232
233#[derive(#[automatically_derived]
impl ::core::marker::Copy for Asyncness { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for Asyncness { }
#[automatically_derived]
impl ::core::clone::Clone for Asyncness {
#[inline]
fn clone(&self) -> Asyncness { *self }
}Clone, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for Asyncness { }
#[automatically_derived]
impl ::core::cmp::PartialEq for Asyncness {
#[inline]
fn eq(&self, other: &Asyncness) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for Asyncness {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::hash::Hash for Asyncness {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
let __self_discr = ::core::intrinsics::discriminant_value(self);
::core::hash::Hash::hash(&__self_discr, state)
}
}Hash, const _: () =
{
impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
::rustc_serialize::Encodable<__E> for Asyncness {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
Asyncness::Yes => { 0usize }
Asyncness::No => { 1usize }
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
}
}
};TyEncodable, const _: () =
{
impl<'tcx, __D: ::rustc_middle::ty::codec::TyDecoder<'tcx>>
::rustc_serialize::Decodable<__D> for Asyncness {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => { Asyncness::Yes }
1usize => { Asyncness::No }
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `Asyncness`, expected 0..2, actual {0}",
n));
}
}
}
}
};TyDecodable, const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for Asyncness {
#[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 { Asyncness::Yes => {} Asyncness::No => {} }
}
}
};StableHash, #[automatically_derived]
impl ::core::fmt::Debug for Asyncness {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self { Asyncness::Yes => "Yes", Asyncness::No => "No", })
}
}Debug)]
234#[derive(const _: () =
{
impl<'tcx>
::rustc_middle::ty::TypeFoldable<::rustc_middle::ty::TyCtxt<'tcx>>
for Asyncness {
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 {
Asyncness::Yes => { Asyncness::Yes }
Asyncness::No => { Asyncness::No }
})
}
fn fold_with<__F: ::rustc_middle::ty::TypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
__folder: &mut __F) -> Self {
match self {
Asyncness::Yes => { Asyncness::Yes }
Asyncness::No => { Asyncness::No }
}
}
}
};TypeFoldable, const _: () =
{
impl<'tcx>
::rustc_middle::ty::TypeVisitable<::rustc_middle::ty::TyCtxt<'tcx>>
for Asyncness {
fn visit_with<__V: ::rustc_middle::ty::TypeVisitor<::rustc_middle::ty::TyCtxt<'tcx>>>(&self,
__visitor: &mut __V) -> __V::Result {
match *self { Asyncness::Yes => {} Asyncness::No => {} }
<__V::Result as ::rustc_middle::ty::VisitorResult>::output()
}
}
};TypeVisitable, #[automatically_derived]
impl ::core::default::Default for Asyncness {
#[inline]
fn default() -> Asyncness { Self::No }
}Default)]
235pub enum Asyncness {
236 Yes,
237 #[default]
238 No,
239}
240
241impl Asyncness {
242 pub fn is_async(self) -> bool {
243 #[allow(non_exhaustive_omitted_patterns)] match self {
Asyncness::Yes => true,
_ => false,
}matches!(self, Asyncness::Yes)
244 }
245}
246
247#[derive(#[automatically_derived]
impl<Id: ::core::clone::Clone> ::core::clone::Clone for Visibility<Id> {
#[inline]
fn clone(&self) -> Visibility<Id> {
match self {
Visibility::Public => Visibility::Public,
Visibility::Restricted(__self_0) =>
Visibility::Restricted(::core::clone::Clone::clone(__self_0)),
}
}
}Clone, #[automatically_derived]
impl<Id: ::core::fmt::Debug> ::core::fmt::Debug for Visibility<Id> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Visibility::Public =>
::core::fmt::Formatter::write_str(f, "Public"),
Visibility::Restricted(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"Restricted", &__self_0),
}
}
}Debug, #[automatically_derived]
impl<Id: ::core::cmp::PartialEq> ::core::marker::StructuralPartialEq for
Visibility<Id> {
}
#[automatically_derived]
impl<Id: ::core::cmp::PartialEq> ::core::cmp::PartialEq for Visibility<Id> {
#[inline]
fn eq(&self, other: &Visibility<Id>) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(Visibility::Restricted(__self_0),
Visibility::Restricted(__arg1_0)) => __self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]
impl<Id: ::core::cmp::Eq> ::core::cmp::Eq for Visibility<Id> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Id>;
}
}Eq, #[automatically_derived]
impl<Id: ::core::marker::Copy> ::core::marker::Copy for Visibility<Id> { }Copy, #[automatically_derived]
impl<Id: ::core::hash::Hash> ::core::hash::Hash for Visibility<Id> {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
let __self_discr = ::core::intrinsics::discriminant_value(self);
::core::hash::Hash::hash(&__self_discr, state);
match self {
Visibility::Restricted(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
_ => {}
}
}
}Hash, const _: () =
{
impl<Id, __E: ::rustc_span::SpanEncoder>
::rustc_serialize::Encodable<__E> for Visibility<Id> where
Id: ::rustc_serialize::Encodable<__E> {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
Visibility::Public => { 0usize }
Visibility::Restricted(ref __binding_0) => { 1usize }
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
match *self {
Visibility::Public => {}
Visibility::Restricted(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
}
}
}
};Encodable, const _: () =
{
impl<Id, __D: ::rustc_span::BlobDecoder>
::rustc_serialize::Decodable<__D> for Visibility<Id> where
Id: ::rustc_serialize::Decodable<__D> {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => { Visibility::Public }
1usize => {
Visibility::Restricted(::rustc_serialize::Decodable::decode(__decoder))
}
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `Visibility`, expected 0..2, actual {0}",
n));
}
}
}
}
};BlobDecodable, const _: () =
{
impl<Id> ::rustc_data_structures::stable_hash::StableHash for
Visibility<Id> where
Id: ::rustc_data_structures::stable_hash::StableHash {
#[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 {
Visibility::Public => {}
Visibility::Restricted(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash)]
248pub enum Visibility<Id = LocalModId> {
249 Public,
251 Restricted(Id),
253}
254
255impl Visibility {
256 pub fn to_string(self, def_id: LocalDefId, tcx: TyCtxt<'_>) -> String {
257 match self {
258 ty::Visibility::Restricted(restricted_id) => {
259 if restricted_id.is_top_level_module() {
260 "pub(crate)".to_string()
261 } else if restricted_id == tcx.parent_module_from_def_id(def_id) {
262 "pub(self)".to_string()
263 } else {
264 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("pub(in crate{0})",
tcx.def_path(restricted_id.to_def_id()).to_string_no_crate_verbose()))
})format!(
265 "pub(in crate{})",
266 tcx.def_path(restricted_id.to_def_id()).to_string_no_crate_verbose()
267 )
268 }
269 }
270 ty::Visibility::Public => "pub".to_string(),
271 }
272 }
273}
274
275#[derive(#[automatically_derived]
impl ::core::fmt::Debug for RestrictionKind {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
RestrictionKind::Unrestricted =>
::core::fmt::Formatter::write_str(f, "Unrestricted"),
RestrictionKind::Restricted(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"Restricted", __self_0, &__self_1),
}
}
}Debug, const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for
RestrictionKind {
#[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 {
RestrictionKind::Unrestricted => {}
RestrictionKind::Restricted(ref __binding_0,
ref __binding_1) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for RestrictionKind { }
#[automatically_derived]
impl ::core::cmp::PartialEq for RestrictionKind {
#[inline]
fn eq(&self, other: &RestrictionKind) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(RestrictionKind::Restricted(__self_0, __self_1),
RestrictionKind::Restricted(__arg1_0, __arg1_1)) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
_ => true,
}
}
}PartialEq, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for RestrictionKind { }
#[automatically_derived]
impl ::core::clone::Clone for RestrictionKind {
#[inline]
fn clone(&self) -> RestrictionKind {
let _: ::core::clone::AssertParamIsClone<DefId>;
let _: ::core::clone::AssertParamIsClone<Span>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for RestrictionKind { }Copy, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for RestrictionKind {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
RestrictionKind::Unrestricted => { 0usize }
RestrictionKind::Restricted(ref __binding_0,
ref __binding_1) => {
1usize
}
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
match *self {
RestrictionKind::Unrestricted => {}
RestrictionKind::Restricted(ref __binding_0,
ref __binding_1) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
}
}
}
};Encodable, const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for RestrictionKind {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => { RestrictionKind::Unrestricted }
1usize => {
RestrictionKind::Restricted(::rustc_serialize::Decodable::decode(__decoder),
::rustc_serialize::Decodable::decode(__decoder))
}
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `RestrictionKind`, expected 0..2, actual {0}",
n));
}
}
}
}
};Decodable)]
276pub enum RestrictionKind {
277 Unrestricted,
278 Restricted(DefId, Span),
279}
280
281impl RestrictionKind {
282 pub fn is_allowed_in(self, module: DefId, tcx: TyCtxt<'_>) -> bool {
285 match self {
286 RestrictionKind::Unrestricted => true,
287 RestrictionKind::Restricted(restricted_to, _) => {
288 tcx.is_descendant_of(module, restricted_to)
289 }
290 }
291 }
292
293 pub fn expect_span(self) -> Span {
295 match self {
296 RestrictionKind::Unrestricted => {
297 crate::util::bug::bug_fmt(format_args!("called `expect_span` on an unrestricted item"))bug!("called `expect_span` on an unrestricted item")
298 }
299 RestrictionKind::Restricted(_, span) => span,
300 }
301 }
302
303 pub fn restriction_path(self, tcx: TyCtxt<'_>) -> String {
305 match self {
306 RestrictionKind::Unrestricted => String::new(),
307 RestrictionKind::Restricted(restricted_to, _) => {
308 if restricted_to.krate == rustc_hir::def_id::LOCAL_CRATE {
309 {
let _guard = CratePrefixGuard::new();
{ let _guard = NoTrimmedGuard::new(); tcx.def_path_str(restricted_to) }
}with_crate_prefix!(with_no_trimmed_paths!(tcx.def_path_str(restricted_to)))
310 } else {
311 tcx.def_path_str(restricted_to.krate.as_mod_id())
312 }
313 }
314 }
315 }
316
317 pub fn stricter_of(self, rhs: Self, tcx: TyCtxt<'_>) -> Self {
320 match (self, rhs) {
321 (RestrictionKind::Unrestricted, r) | (r, RestrictionKind::Unrestricted) => r,
322 (
323 RestrictionKind::Restricted(left_did, _),
324 RestrictionKind::Restricted(right_did, _),
325 ) => {
326 if left_did.krate != right_did.krate {
327 crate::util::bug::bug_fmt(format_args!("stricter_of: left and right restriction do not reference the same crate"));bug!("stricter_of: left and right restriction do not reference the same crate");
328 }
329 if tcx.is_descendant_of(left_did, right_did) { self } else { rhs }
330 }
331 }
332 }
333}
334
335#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl<'tcx> ::core::clone::TrivialClone for ClosureSizeProfileData<'tcx>
{
}
#[automatically_derived]
impl<'tcx> ::core::clone::Clone for ClosureSizeProfileData<'tcx> {
#[inline]
fn clone(&self) -> ClosureSizeProfileData<'tcx> {
let _: ::core::clone::AssertParamIsClone<Ty<'tcx>>;
let _: ::core::clone::AssertParamIsClone<Ty<'tcx>>;
*self
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for ClosureSizeProfileData<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f,
"ClosureSizeProfileData", "before_feature_tys",
&self.before_feature_tys, "after_feature_tys",
&&self.after_feature_tys)
}
}Debug, #[automatically_derived]
impl<'tcx> ::core::marker::StructuralPartialEq for
ClosureSizeProfileData<'tcx> {
}
#[automatically_derived]
impl<'tcx> ::core::cmp::PartialEq for ClosureSizeProfileData<'tcx> {
#[inline]
fn eq(&self, other: &ClosureSizeProfileData<'tcx>) -> bool {
self.before_feature_tys == other.before_feature_tys &&
self.after_feature_tys == other.after_feature_tys
}
}PartialEq, #[automatically_derived]
impl<'tcx> ::core::cmp::Eq for ClosureSizeProfileData<'tcx> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Ty<'tcx>>;
let _: ::core::cmp::AssertParamIsEq<Ty<'tcx>>;
}
}Eq, #[automatically_derived]
impl<'tcx> ::core::marker::Copy for ClosureSizeProfileData<'tcx> { }Copy, #[automatically_derived]
impl<'tcx> ::core::hash::Hash for ClosureSizeProfileData<'tcx> {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.before_feature_tys, state);
::core::hash::Hash::hash(&self.after_feature_tys, state)
}
}Hash, const _: () =
{
impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
::rustc_serialize::Encodable<__E> for ClosureSizeProfileData<'tcx>
{
fn encode(&self, __encoder: &mut __E) {
let ClosureSizeProfileData {
before_feature_tys: ref __binding_0,
after_feature_tys: ref __binding_1 } = *self;
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
}
};TyEncodable, const _: () =
{
impl<'tcx, __D: ::rustc_middle::ty::codec::TyDecoder<'tcx>>
::rustc_serialize::Decodable<__D> for ClosureSizeProfileData<'tcx>
{
fn decode(__decoder: &mut __D) -> Self {
ClosureSizeProfileData {
before_feature_tys: ::rustc_serialize::Decodable::decode(__decoder),
after_feature_tys: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};TyDecodable, const _: () =
{
impl<'tcx> ::rustc_data_structures::stable_hash::StableHash for
ClosureSizeProfileData<'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 {
ClosureSizeProfileData {
before_feature_tys: ref __binding_0,
after_feature_tys: ref __binding_1 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash)]
336#[derive(const _: () =
{
impl<'tcx>
::rustc_middle::ty::TypeFoldable<::rustc_middle::ty::TyCtxt<'tcx>>
for ClosureSizeProfileData<'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 {
ClosureSizeProfileData {
before_feature_tys: __binding_0,
after_feature_tys: __binding_1 } => {
ClosureSizeProfileData {
before_feature_tys: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
after_feature_tys: ::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 {
ClosureSizeProfileData {
before_feature_tys: __binding_0,
after_feature_tys: __binding_1 } => {
ClosureSizeProfileData {
before_feature_tys: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder),
after_feature_tys: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
__folder),
}
}
}
}
}
};TypeFoldable, const _: () =
{
impl<'tcx>
::rustc_middle::ty::TypeVisitable<::rustc_middle::ty::TyCtxt<'tcx>>
for ClosureSizeProfileData<'tcx> {
fn visit_with<__V: ::rustc_middle::ty::TypeVisitor<::rustc_middle::ty::TyCtxt<'tcx>>>(&self,
__visitor: &mut __V) -> __V::Result {
match *self {
ClosureSizeProfileData {
before_feature_tys: ref __binding_0,
after_feature_tys: 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)]
337pub struct ClosureSizeProfileData<'tcx> {
338 pub before_feature_tys: Ty<'tcx>,
340 pub after_feature_tys: Ty<'tcx>,
342}
343
344impl TyCtxt<'_> {
345 #[inline]
346 pub fn opt_parent(self, id: DefId) -> Option<DefId> {
347 self.def_key(id).parent.map(|index| DefId { index, ..id })
348 }
349
350 #[inline]
351 #[track_caller]
352 pub fn parent(self, id: DefId) -> DefId {
353 match self.opt_parent(id) {
354 Some(id) => id,
355 None => crate::util::bug::bug_fmt(format_args!("{0:?} doesn\'t have a parent", id))bug!("{id:?} doesn't have a parent"),
357 }
358 }
359
360 #[inline]
361 #[track_caller]
362 pub fn opt_local_parent(self, id: LocalDefId) -> Option<LocalDefId> {
363 self.opt_parent(id.to_def_id()).map(DefId::expect_local)
364 }
365
366 #[inline]
367 #[track_caller]
368 pub fn local_parent(self, id: impl Into<LocalDefId>) -> LocalDefId {
369 self.parent(id.into().to_def_id()).expect_local()
370 }
371
372 pub fn def_id_partial_cmp(self, lhs: DefId, rhs: DefId) -> Option<Ordering> {
376 if lhs.krate != rhs.krate {
378 return None;
379 }
380
381 let search = |mut start: DefId, finish: DefId, ord| {
385 while start.index != finish.index {
386 match self.opt_parent(start) {
387 Some(parent) => start.index = parent.index,
388 None => return None,
389 }
390 }
391 Some(ord)
392 };
393 match lhs.index.cmp(&rhs.index) {
394 Ordering::Equal => Some(Ordering::Equal),
395 Ordering::Less => search(rhs, lhs, Ordering::Greater),
396 Ordering::Greater => search(lhs, rhs, Ordering::Less),
397 }
398 }
399
400 pub fn is_descendant_of(
401 self,
402 descendant: impl Into<DefId>,
403 ancestor: impl Into<DefId>,
404 ) -> bool {
405 #[allow(non_exhaustive_omitted_patterns)] match self.def_id_partial_cmp(descendant.into(),
ancestor.into()) {
Some(Ordering::Less | Ordering::Equal) => true,
_ => false,
}matches!(
406 self.def_id_partial_cmp(descendant.into(), ancestor.into()),
407 Some(Ordering::Less | Ordering::Equal)
408 )
409 }
410}
411
412impl<Id> Visibility<Id> {
413 pub fn is_public(self) -> bool {
414 #[allow(non_exhaustive_omitted_patterns)] match self {
Visibility::Public => true,
_ => false,
}matches!(self, Visibility::Public)
415 }
416
417 pub fn map_id<OutId>(self, f: impl FnOnce(Id) -> OutId) -> Visibility<OutId> {
418 match self {
419 Visibility::Public => Visibility::Public,
420 Visibility::Restricted(id) => Visibility::Restricted(f(id)),
421 }
422 }
423}
424
425impl Visibility<LocalModId> {
426 pub fn to_mod_id(self) -> Visibility<ModId> {
427 self.map_id(LocalModId::to_mod_id)
428 }
429}
430
431impl<Id: Into<DefId>> Visibility<Id> {
432 pub fn is_accessible_from(self, module: impl Into<DefId>, tcx: TyCtxt<'_>) -> bool {
434 match self {
435 Visibility::Public => true,
437 Visibility::Restricted(id) => tcx.is_descendant_of(module, id),
438 }
439 }
440
441 pub fn partial_cmp(
442 self,
443 vis: Visibility<impl Into<DefId>>,
444 tcx: TyCtxt<'_>,
445 ) -> Option<Ordering> {
446 match (self, vis) {
447 (Visibility::Public, Visibility::Public) => Some(Ordering::Equal),
448 (Visibility::Public, Visibility::Restricted(_)) => Some(Ordering::Greater),
449 (Visibility::Restricted(_), Visibility::Public) => Some(Ordering::Less),
450 (Visibility::Restricted(lhs_id), Visibility::Restricted(rhs_id)) => {
451 let (lhs_id, rhs_id) = (lhs_id.into(), rhs_id.into());
452 tcx.def_id_partial_cmp(lhs_id, rhs_id)
453 }
454 }
455 }
456}
457
458impl<Id: Into<DefId> + Debug + Copy> Visibility<Id> {
459 #[track_caller]
461 pub fn greater_than(
462 self,
463 vis: Visibility<impl Into<DefId> + Debug + Copy>,
464 tcx: TyCtxt<'_>,
465 ) -> bool {
466 match self.partial_cmp(vis, tcx) {
467 Some(ord) => ord.is_gt(),
468 None => {
469 tcx.dcx().delayed_bug(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("unordered visibilities: {0:?} and {1:?}",
self, vis))
})format!("unordered visibilities: {self:?} and {vis:?}"));
470 false
471 }
472 }
473 }
474}
475
476impl Visibility<ModId> {
477 pub fn expect_local(self) -> Visibility {
478 self.map_id(|id| id.expect_local())
479 }
480
481 pub fn is_visible_locally(self) -> bool {
483 match self {
484 Visibility::Public => true,
485 Visibility::Restricted(mod_id) => mod_id.is_local(),
486 }
487 }
488}
489
490#[derive(const _: () =
{
impl<'tcx> ::rustc_data_structures::stable_hash::StableHash for
CrateVariancesMap<'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 {
CrateVariancesMap { variances: ref __binding_0 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for CrateVariancesMap<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field1_finish(f,
"CrateVariancesMap", "variances", &&self.variances)
}
}Debug)]
497pub struct CrateVariancesMap<'tcx> {
498 pub variances: DefIdMap<&'tcx [ty::Variance]>,
502}
503
504#[derive(#[automatically_derived]
impl ::core::marker::Copy for CReaderCacheKey { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for CReaderCacheKey { }
#[automatically_derived]
impl ::core::clone::Clone for CReaderCacheKey {
#[inline]
fn clone(&self) -> CReaderCacheKey {
let _: ::core::clone::AssertParamIsClone<Option<CrateNum>>;
let _: ::core::clone::AssertParamIsClone<usize>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for CReaderCacheKey { }
#[automatically_derived]
impl ::core::cmp::PartialEq for CReaderCacheKey {
#[inline]
fn eq(&self, other: &CReaderCacheKey) -> bool {
self.cnum == other.cnum && self.pos == other.pos
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for CReaderCacheKey {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Option<CrateNum>>;
let _: ::core::cmp::AssertParamIsEq<usize>;
}
}Eq, #[automatically_derived]
impl ::core::hash::Hash for CReaderCacheKey {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.cnum, state);
::core::hash::Hash::hash(&self.pos, state)
}
}Hash)]
507pub struct CReaderCacheKey {
508 pub cnum: Option<CrateNum>,
509 pub pos: usize,
510}
511
512#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for Ty<'tcx> { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl<'tcx> ::core::clone::TrivialClone for Ty<'tcx> { }
#[automatically_derived]
impl<'tcx> ::core::clone::Clone for Ty<'tcx> {
#[inline]
fn clone(&self) -> Ty<'tcx> {
let _:
::core::clone::AssertParamIsClone<Interned<'tcx,
WithCachedTypeInfo<TyKind<'tcx>>>>;
*self
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::marker::StructuralPartialEq for Ty<'tcx> { }
#[automatically_derived]
impl<'tcx> ::core::cmp::PartialEq for Ty<'tcx> {
#[inline]
fn eq(&self, other: &Ty<'tcx>) -> bool { self.0 == other.0 }
}PartialEq, #[automatically_derived]
impl<'tcx> ::core::cmp::Eq for Ty<'tcx> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _:
::core::cmp::AssertParamIsEq<Interned<'tcx,
WithCachedTypeInfo<TyKind<'tcx>>>>;
}
}Eq, #[automatically_derived]
impl<'tcx> ::core::hash::Hash for Ty<'tcx> {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.0, state)
}
}Hash, const _: () =
{
impl<'tcx> ::rustc_data_structures::stable_hash::StableHash for
Ty<'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 {
Ty(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash)]
514#[rustc_diagnostic_item = "Ty"]
515#[rustc_pass_by_value]
516pub struct Ty<'tcx>(Interned<'tcx, WithCachedTypeInfo<TyKind<'tcx>>>);
517
518impl<'tcx> rustc_type_ir::inherent::IntoKind for Ty<'tcx> {
519 type Kind = TyKind<'tcx>;
520
521 fn kind(self) -> TyKind<'tcx> {
522 *self.kind()
523 }
524}
525
526impl<'tcx> rustc_type_ir::Flags for Ty<'tcx> {
527 fn flags(&self) -> TypeFlags {
528 self.0.flags
529 }
530
531 fn outer_exclusive_binder(&self) -> DebruijnIndex {
532 self.0.outer_exclusive_binder
533 }
534}
535
536#[derive(const _: () =
{
impl<'tcx> ::rustc_data_structures::stable_hash::StableHash for
CrateClausesMap<'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 {
CrateClausesMap { clauses: ref __binding_0 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for CrateClausesMap<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field1_finish(f,
"CrateClausesMap", "clauses", &&self.clauses)
}
}Debug)]
543pub struct CrateClausesMap<'tcx> {
544 pub clauses: DefIdMap<&'tcx [(Clause<'tcx>, Span)]>,
548}
549
550#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl<'tcx> ::core::clone::TrivialClone for Term<'tcx> { }
#[automatically_derived]
impl<'tcx> ::core::clone::Clone for Term<'tcx> {
#[inline]
fn clone(&self) -> Term<'tcx> {
let _: ::core::clone::AssertParamIsClone<NonNull<()>>;
let _:
::core::clone::AssertParamIsClone<PhantomData<(Ty<'tcx>,
Const<'tcx>)>>;
*self
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::marker::Copy for Term<'tcx> { }Copy, #[automatically_derived]
impl<'tcx> ::core::marker::StructuralPartialEq for Term<'tcx> { }
#[automatically_derived]
impl<'tcx> ::core::cmp::PartialEq for Term<'tcx> {
#[inline]
fn eq(&self, other: &Term<'tcx>) -> bool {
self.ptr == other.ptr && self.marker == other.marker
}
}PartialEq, #[automatically_derived]
impl<'tcx> ::core::cmp::Eq for Term<'tcx> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<NonNull<()>>;
let _:
::core::cmp::AssertParamIsEq<PhantomData<(Ty<'tcx>,
Const<'tcx>)>>;
}
}Eq, #[automatically_derived]
impl<'tcx> ::core::cmp::PartialOrd for Term<'tcx> {
#[inline]
fn partial_cmp(&self, other: &Term<'tcx>)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::option::Option::Some(::core::cmp::Ord::cmp(self, other))
}
}PartialOrd, #[automatically_derived]
impl<'tcx> ::core::cmp::Ord for Term<'tcx> {
#[inline]
fn cmp(&self, other: &Term<'tcx>) -> ::core::cmp::Ordering {
match ::core::cmp::Ord::cmp(&self.ptr, &other.ptr) {
::core::cmp::Ordering::Equal =>
::core::cmp::Ord::cmp(&self.marker, &other.marker),
cmp => cmp,
}
}
}Ord, #[automatically_derived]
impl<'tcx> ::core::hash::Hash for Term<'tcx> {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.ptr, state);
::core::hash::Hash::hash(&self.marker, state)
}
}Hash)]
551pub struct Term<'tcx> {
552 ptr: NonNull<()>,
553 marker: PhantomData<(Ty<'tcx>, Const<'tcx>)>,
554}
555
556impl<'tcx> rustc_type_ir::inherent::Term<TyCtxt<'tcx>> for Term<'tcx> {}
557
558impl<'tcx> rustc_type_ir::inherent::IntoKind for Term<'tcx> {
559 type Kind = TermKind<'tcx>;
560
561 fn kind(self) -> Self::Kind {
562 self.kind()
563 }
564}
565
566unsafe impl<'tcx> rustc_data_structures::sync::DynSend for Term<'tcx> where
567 &'tcx (Ty<'tcx>, Const<'tcx>): rustc_data_structures::sync::DynSend
568{
569}
570unsafe impl<'tcx> rustc_data_structures::sync::DynSync for Term<'tcx> where
571 &'tcx (Ty<'tcx>, Const<'tcx>): rustc_data_structures::sync::DynSync
572{
573}
574unsafe impl<'tcx> Send for Term<'tcx> where &'tcx (Ty<'tcx>, Const<'tcx>): Send {}
575unsafe impl<'tcx> Sync for Term<'tcx> where &'tcx (Ty<'tcx>, Const<'tcx>): Sync {}
576
577impl Debug for Term<'_> {
578 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
579 match self.kind() {
580 TermKind::Ty(ty) => f.write_fmt(format_args!("Term::Ty({0:?})", ty))write!(f, "Term::Ty({ty:?})"),
581 TermKind::Const(ct) => f.write_fmt(format_args!("Term::Const({0:?})", ct))write!(f, "Term::Const({ct:?})"),
582 }
583 }
584}
585
586impl<'tcx> From<Ty<'tcx>> for Term<'tcx> {
587 fn from(ty: Ty<'tcx>) -> Self {
588 TermKind::Ty(ty).pack()
589 }
590}
591
592impl<'tcx> From<Const<'tcx>> for Term<'tcx> {
593 fn from(c: Const<'tcx>) -> Self {
594 TermKind::Const(c).pack()
595 }
596}
597
598impl<'tcx> StableHash for Term<'tcx> {
599 fn stable_hash<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
600 self.kind().stable_hash(hcx, hasher);
601 }
602}
603
604impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for Term<'tcx> {
605 fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>(
606 self,
607 folder: &mut F,
608 ) -> Result<Self, F::Error> {
609 match self.kind() {
610 ty::TermKind::Ty(ty) => ty.try_fold_with(folder).map(Into::into),
611 ty::TermKind::Const(ct) => ct.try_fold_with(folder).map(Into::into),
612 }
613 }
614
615 fn fold_with<F: TypeFolder<TyCtxt<'tcx>>>(self, folder: &mut F) -> Self {
616 match self.kind() {
617 ty::TermKind::Ty(ty) => ty.fold_with(folder).into(),
618 ty::TermKind::Const(ct) => ct.fold_with(folder).into(),
619 }
620 }
621}
622
623impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for Term<'tcx> {
624 fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result {
625 match self.kind() {
626 ty::TermKind::Ty(ty) => ty.visit_with(visitor),
627 ty::TermKind::Const(ct) => ct.visit_with(visitor),
628 }
629 }
630}
631
632impl<'tcx, E: TyEncoder<'tcx>> Encodable<E> for Term<'tcx> {
633 fn encode(&self, e: &mut E) {
634 self.kind().encode(e)
635 }
636}
637
638impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for Term<'tcx> {
639 fn decode(d: &mut D) -> Self {
640 let res: TermKind<'tcx> = Decodable::decode(d);
641 res.pack()
642 }
643}
644
645impl<'tcx> Term<'tcx> {
646 #[inline]
647 pub fn kind(self) -> TermKind<'tcx> {
648 let ptr =
649 unsafe { self.ptr.map_addr(|addr| NonZero::new_unchecked(addr.get() & !TAG_MASK)) };
650 unsafe {
654 match self.ptr.addr().get() & TAG_MASK {
655 TYPE_TAG => TermKind::Ty(Ty(Interned::new_unchecked(
656 ptr.cast::<WithCachedTypeInfo<ty::TyKind<'tcx>>>().as_ref(),
657 ))),
658 CONST_TAG => TermKind::Const(ty::Const(Interned::new_unchecked(
659 ptr.cast::<WithCachedTypeInfo<ty::ConstKind<'tcx>>>().as_ref(),
660 ))),
661 _ => core::intrinsics::unreachable(),
662 }
663 }
664 }
665
666 pub fn as_type(&self) -> Option<Ty<'tcx>> {
667 if let TermKind::Ty(ty) = self.kind() { Some(ty) } else { None }
668 }
669
670 pub fn expect_type(&self) -> Ty<'tcx> {
671 self.as_type().expect("expected a type, but found a const")
672 }
673
674 pub fn as_const(&self) -> Option<Const<'tcx>> {
675 if let TermKind::Const(c) = self.kind() { Some(c) } else { None }
676 }
677
678 pub fn expect_const(&self) -> Const<'tcx> {
679 self.as_const().expect("expected a const, but found a type")
680 }
681
682 pub fn into_arg(self) -> GenericArg<'tcx> {
683 match self.kind() {
684 TermKind::Ty(ty) => ty.into(),
685 TermKind::Const(c) => c.into(),
686 }
687 }
688
689 pub fn to_alias_term(self) -> Option<AliasTerm<'tcx>> {
690 match self.kind() {
691 TermKind::Ty(ty) => match *ty.kind() {
692 ty::Alias(_, alias_ty) => Some(alias_ty.into()),
693 _ => None,
694 },
695 TermKind::Const(ct) => match ct.kind() {
696 ConstKind::Alias(_, alias_const) => Some(alias_const.into()),
697 _ => None,
698 },
699 }
700 }
701
702 pub fn is_non_rigid_alias(self) -> bool {
703 match self.kind() {
704 ty::TermKind::Ty(ty) => match ty.kind() {
705 ty::Alias(ty::IsRigid::No, _) => true,
706 _ => false,
707 },
708 ty::TermKind::Const(ct) => match ct.kind() {
709 ty::ConstKind::Alias(ty::IsRigid::No, _) => true,
710 _ => false,
711 },
712 }
713 }
714
715 pub fn is_infer(&self) -> bool {
716 match self.kind() {
717 TermKind::Ty(ty) => ty.is_ty_var(),
718 TermKind::Const(ct) => ct.is_ct_infer(),
719 }
720 }
721
722 pub fn is_trivially_wf(&self, tcx: TyCtxt<'tcx>) -> bool {
723 match self.kind() {
724 TermKind::Ty(ty) => ty.is_trivially_wf(tcx),
725 TermKind::Const(ct) => ct.is_trivially_wf(),
726 }
727 }
728
729 pub fn walk(self) -> TypeWalker<TyCtxt<'tcx>> {
740 TypeWalker::new(self.into())
741 }
742}
743
744const TAG_MASK: usize = 0b11;
745const TYPE_TAG: usize = 0b00;
746const CONST_TAG: usize = 0b01;
747
748pub trait TermKindPackExt<'tcx> {
fn pack(self)
-> Term<'tcx>;
}
impl<'tcx> TermKindPackExt<'tcx> for TermKind<'tcx> {
#[inline]
fn pack(self) -> Term<'tcx> {
let (tag, ptr) =
match self {
TermKind::Ty(ty) => {
{
match (&(align_of_val(&*ty.0.0) & TAG_MASK), &0) {
(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);
}
}
}
};
(TYPE_TAG, NonNull::from(ty.0.0).cast())
}
TermKind::Const(ct) => {
{
match (&(align_of_val(&*ct.0.0) & TAG_MASK), &0) {
(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);
}
}
}
};
(CONST_TAG, NonNull::from(ct.0.0).cast())
}
};
Term { ptr: ptr.map_addr(|addr| addr | tag), marker: PhantomData }
}
}#[extension(pub trait TermKindPackExt<'tcx>)]
749impl<'tcx> TermKind<'tcx> {
750 #[inline]
751 fn pack(self) -> Term<'tcx> {
752 let (tag, ptr) = match self {
753 TermKind::Ty(ty) => {
754 assert_eq!(align_of_val(&*ty.0.0) & TAG_MASK, 0);
756 (TYPE_TAG, NonNull::from(ty.0.0).cast())
757 }
758 TermKind::Const(ct) => {
759 assert_eq!(align_of_val(&*ct.0.0) & TAG_MASK, 0);
761 (CONST_TAG, NonNull::from(ct.0.0).cast())
762 }
763 };
764
765 Term { ptr: ptr.map_addr(|addr| addr | tag), marker: PhantomData }
766 }
767}
768
769#[derive(#[automatically_derived]
impl<'tcx> ::core::clone::Clone for InstantiatedClauses<'tcx> {
#[inline]
fn clone(&self) -> InstantiatedClauses<'tcx> {
InstantiatedClauses {
clauses: ::core::clone::Clone::clone(&self.clauses),
spans: ::core::clone::Clone::clone(&self.spans),
}
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for InstantiatedClauses<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f,
"InstantiatedClauses", "clauses", &self.clauses, "spans",
&&self.spans)
}
}Debug)]
789pub struct InstantiatedClauses<'tcx> {
790 pub clauses: Vec<Unnormalized<'tcx, Clause<'tcx>>>,
791 pub spans: Vec<Span>,
792}
793
794impl<'tcx> InstantiatedClauses<'tcx> {
795 pub fn empty() -> InstantiatedClauses<'tcx> {
796 InstantiatedClauses { clauses: ::alloc::vec::Vec::new()vec![], spans: ::alloc::vec::Vec::new()vec![] }
797 }
798
799 pub fn is_empty(&self) -> bool {
800 self.clauses.is_empty()
801 }
802
803 pub fn iter(&self) -> <&Self as IntoIterator>::IntoIter {
804 self.into_iter()
805 }
806}
807
808impl<'tcx> IntoIterator for InstantiatedClauses<'tcx> {
809 type Item = (Unnormalized<'tcx, Clause<'tcx>>, Span);
810
811 type IntoIter = std::iter::Zip<
812 std::vec::IntoIter<Unnormalized<'tcx, Clause<'tcx>>>,
813 std::vec::IntoIter<Span>,
814 >;
815
816 fn into_iter(self) -> Self::IntoIter {
817 if true {
{
match (&self.clauses.len(), &self.spans.len()) {
(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);
}
}
}
};
};debug_assert_eq!(self.clauses.len(), self.spans.len());
818 std::iter::zip(self.clauses, self.spans)
819 }
820}
821
822impl<'a, 'tcx> IntoIterator for &'a InstantiatedClauses<'tcx> {
823 type Item = (Unnormalized<'tcx, Clause<'tcx>>, Span);
824
825 type IntoIter = std::iter::Zip<
826 std::iter::Copied<std::slice::Iter<'a, Unnormalized<'tcx, Clause<'tcx>>>>,
827 std::iter::Copied<std::slice::Iter<'a, Span>>,
828 >;
829
830 fn into_iter(self) -> Self::IntoIter {
831 if true {
{
match (&self.clauses.len(), &self.spans.len()) {
(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);
}
}
}
};
};debug_assert_eq!(self.clauses.len(), self.spans.len());
832 std::iter::zip(self.clauses.iter().copied(), self.spans.iter().copied())
833 }
834}
835
836#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for ProvisionalHiddenType<'tcx> { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl<'tcx> ::core::clone::TrivialClone for ProvisionalHiddenType<'tcx>
{
}
#[automatically_derived]
impl<'tcx> ::core::clone::Clone for ProvisionalHiddenType<'tcx> {
#[inline]
fn clone(&self) -> ProvisionalHiddenType<'tcx> {
let _: ::core::clone::AssertParamIsClone<Span>;
let _: ::core::clone::AssertParamIsClone<Ty<'tcx>>;
*self
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for ProvisionalHiddenType<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f,
"ProvisionalHiddenType", "span", &self.span, "ty", &&self.ty)
}
}Debug, const _: () =
{
impl<'tcx>
::rustc_middle::ty::TypeFoldable<::rustc_middle::ty::TyCtxt<'tcx>>
for ProvisionalHiddenType<'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 {
ProvisionalHiddenType { span: __binding_0, ty: __binding_1 }
=> {
ProvisionalHiddenType {
span: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
ty: ::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 {
ProvisionalHiddenType { span: __binding_0, ty: __binding_1 }
=> {
ProvisionalHiddenType {
span: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder),
ty: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
__folder),
}
}
}
}
}
};TypeFoldable, const _: () =
{
impl<'tcx>
::rustc_middle::ty::TypeVisitable<::rustc_middle::ty::TyCtxt<'tcx>>
for ProvisionalHiddenType<'tcx> {
fn visit_with<__V: ::rustc_middle::ty::TypeVisitor<::rustc_middle::ty::TyCtxt<'tcx>>>(&self,
__visitor: &mut __V) -> __V::Result {
match *self {
ProvisionalHiddenType {
span: ref __binding_0, ty: 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, const _: () =
{
impl<'tcx> ::rustc_data_structures::stable_hash::StableHash for
ProvisionalHiddenType<'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 {
ProvisionalHiddenType {
span: ref __binding_0, ty: ref __binding_1 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash, const _: () =
{
impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
::rustc_serialize::Encodable<__E> for ProvisionalHiddenType<'tcx>
{
fn encode(&self, __encoder: &mut __E) {
let ProvisionalHiddenType {
span: ref __binding_0, ty: ref __binding_1 } = *self;
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
}
};TyEncodable, const _: () =
{
impl<'tcx, __D: ::rustc_middle::ty::codec::TyDecoder<'tcx>>
::rustc_serialize::Decodable<__D> for ProvisionalHiddenType<'tcx>
{
fn decode(__decoder: &mut __D) -> Self {
ProvisionalHiddenType {
span: ::rustc_serialize::Decodable::decode(__decoder),
ty: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};TyDecodable)]
837pub struct ProvisionalHiddenType<'tcx> {
838 pub span: Span,
852
853 pub ty: Ty<'tcx>,
866}
867
868#[derive(#[automatically_derived]
impl ::core::fmt::Debug for DefiningScopeKind {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
DefiningScopeKind::HirTypeck => "HirTypeck",
DefiningScopeKind::MirBorrowck => "MirBorrowck",
})
}
}Debug, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for DefiningScopeKind { }
#[automatically_derived]
impl ::core::clone::Clone for DefiningScopeKind {
#[inline]
fn clone(&self) -> DefiningScopeKind { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for DefiningScopeKind { }Copy)]
870pub enum DefiningScopeKind {
871 HirTypeck,
876 MirBorrowck,
877}
878
879impl<'tcx> ProvisionalHiddenType<'tcx> {
880 pub fn new_error(tcx: TyCtxt<'tcx>, guar: ErrorGuaranteed) -> ProvisionalHiddenType<'tcx> {
881 ProvisionalHiddenType { span: DUMMY_SP, ty: Ty::new_error(tcx, guar) }
882 }
883
884 pub fn build_mismatch_error(
885 &self,
886 other: &Self,
887 tcx: TyCtxt<'tcx>,
888 ) -> Result<Diag<'tcx>, ErrorGuaranteed> {
889 (self.ty, other.ty).error_reported()?;
890 let sub_diag = if self.span == other.span {
892 TypeMismatchReason::ConflictType { span: self.span }
893 } else {
894 TypeMismatchReason::PreviousUse { span: self.span }
895 };
896 Ok(tcx.dcx().create_err(OpaqueHiddenTypeMismatch {
897 self_ty: self.ty,
898 other_ty: other.ty,
899 other_span: other.span,
900 sub: sub_diag,
901 }))
902 }
903
904 {}
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() || { false }
{
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("remap_generic_params_to_declaration_params",
"rustc_middle::ty", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_middle/src/ty/mod.rs"),
::tracing_core::__macro_support::Option::Some(904u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::ty"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("self")
}> =
::tracing::__macro_support::FieldName::new("self");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("opaque_type_key")
}> =
::tracing::__macro_support::FieldName::new("opaque_type_key");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("defining_scope_kind")
}> =
::tracing::__macro_support::FieldName::new("defining_scope_kind");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&opaque_type_key)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&defining_scope_kind)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
(move ||
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy
:: needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return:
DefinitionSiteHiddenType<'tcx> = loop {};
return __tracing_attr_fake_return;
}
{
let OpaqueTypeKey { def_id, args } = opaque_type_key;
let id_args = GenericArgs::identity_for_item(tcx, def_id);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_middle/src/ty/mod.rs:920",
"rustc_middle::ty", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_middle/src/ty/mod.rs"),
::tracing_core::__macro_support::Option::Some(920u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::ty"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("id_args")
}> =
::tracing::__macro_support::FieldName::new("id_args");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&id_args)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let map = args.iter().zip(id_args).collect();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_middle/src/ty/mod.rs:926",
"rustc_middle::ty", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_middle/src/ty/mod.rs"),
::tracing_core::__macro_support::Option::Some(926u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::ty"),
::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("map = {0:#?}",
map) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let ty =
match defining_scope_kind {
DefiningScopeKind::HirTypeck => {
fold_regions(tcx, self.ty, |_, _| tcx.lifetimes.re_erased)
}
DefiningScopeKind::MirBorrowck => self.ty,
};
let result_ty =
ty.fold_with(&mut opaque_types::ReverseMapper::new(tcx, map,
self.span));
if true &&
#[allow(non_exhaustive_omitted_patterns)] match defining_scope_kind
{
DefiningScopeKind::HirTypeck => true,
_ => false,
} {
{
match (&result_ty,
&fold_regions(tcx, result_ty,
|_, _| tcx.lifetimes.re_erased)) {
(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);
}
}
}
};
}
DefinitionSiteHiddenType {
span: self.span,
ty: ty::EarlyBinder::bind(tcx, result_ty),
}
}
})();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_middle/src/ty/mod.rs:904",
"rustc_middle::ty", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_middle/src/ty/mod.rs"),
::tracing_core::__macro_support::Option::Some(904u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::ty"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return")
}> =
::tracing::__macro_support::FieldName::new("return");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
x;#[instrument(level = "debug", skip(tcx), ret)]
905 pub fn remap_generic_params_to_declaration_params(
906 self,
907 opaque_type_key: OpaqueTypeKey<'tcx>,
908 tcx: TyCtxt<'tcx>,
909 defining_scope_kind: DefiningScopeKind,
910 ) -> DefinitionSiteHiddenType<'tcx> {
911 let OpaqueTypeKey { def_id, args } = opaque_type_key;
912
913 let id_args = GenericArgs::identity_for_item(tcx, def_id);
920 debug!(?id_args);
921
922 let map = args.iter().zip(id_args).collect();
926 debug!("map = {:#?}", map);
927
928 let ty = match defining_scope_kind {
934 DefiningScopeKind::HirTypeck => {
935 fold_regions(tcx, self.ty, |_, _| tcx.lifetimes.re_erased)
936 }
937 DefiningScopeKind::MirBorrowck => self.ty,
938 };
939 let result_ty = ty.fold_with(&mut opaque_types::ReverseMapper::new(tcx, map, self.span));
940 if cfg!(debug_assertions) && matches!(defining_scope_kind, DefiningScopeKind::HirTypeck) {
941 assert_eq!(result_ty, fold_regions(tcx, result_ty, |_, _| tcx.lifetimes.re_erased));
942 }
943 DefinitionSiteHiddenType { span: self.span, ty: ty::EarlyBinder::bind(tcx, result_ty) }
944 }
945}
946
947#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for DefinitionSiteHiddenType<'tcx> { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl<'tcx> ::core::clone::TrivialClone for
DefinitionSiteHiddenType<'tcx> {
}
#[automatically_derived]
impl<'tcx> ::core::clone::Clone for DefinitionSiteHiddenType<'tcx> {
#[inline]
fn clone(&self) -> DefinitionSiteHiddenType<'tcx> {
let _: ::core::clone::AssertParamIsClone<Span>;
let _:
::core::clone::AssertParamIsClone<ty::EarlyBinder<'tcx,
Ty<'tcx>>>;
*self
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for DefinitionSiteHiddenType<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f,
"DefinitionSiteHiddenType", "span", &self.span, "ty", &&self.ty)
}
}Debug, const _: () =
{
impl<'tcx> ::rustc_data_structures::stable_hash::StableHash for
DefinitionSiteHiddenType<'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 {
DefinitionSiteHiddenType {
span: ref __binding_0, ty: ref __binding_1 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash, const _: () =
{
impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
::rustc_serialize::Encodable<__E> for
DefinitionSiteHiddenType<'tcx> {
fn encode(&self, __encoder: &mut __E) {
let DefinitionSiteHiddenType {
span: ref __binding_0, ty: ref __binding_1 } = *self;
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
}
};TyEncodable, const _: () =
{
impl<'tcx, __D: ::rustc_middle::ty::codec::TyDecoder<'tcx>>
::rustc_serialize::Decodable<__D> for
DefinitionSiteHiddenType<'tcx> {
fn decode(__decoder: &mut __D) -> Self {
DefinitionSiteHiddenType {
span: ::rustc_serialize::Decodable::decode(__decoder),
ty: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};TyDecodable)]
948pub struct DefinitionSiteHiddenType<'tcx> {
949 pub span: Span,
962
963 pub ty: ty::EarlyBinder<'tcx, Ty<'tcx>>,
965}
966
967impl<'tcx> DefinitionSiteHiddenType<'tcx> {
968 pub fn new_error(tcx: TyCtxt<'tcx>, guar: ErrorGuaranteed) -> DefinitionSiteHiddenType<'tcx> {
969 DefinitionSiteHiddenType {
970 span: DUMMY_SP,
971 ty: ty::EarlyBinder::bind(tcx, Ty::new_error(tcx, guar)),
972 }
973 }
974
975 pub fn build_mismatch_error(
976 &self,
977 other: &Self,
978 tcx: TyCtxt<'tcx>,
979 ) -> Result<Diag<'tcx>, ErrorGuaranteed> {
980 let self_ty = self.ty.instantiate_identity().skip_norm_wip();
981 let other_ty = other.ty.instantiate_identity().skip_norm_wip();
982 (self_ty, other_ty).error_reported()?;
983 let sub_diag = if self.span == other.span {
985 TypeMismatchReason::ConflictType { span: self.span }
986 } else {
987 TypeMismatchReason::PreviousUse { span: self.span }
988 };
989 Ok(tcx.dcx().create_err(OpaqueHiddenTypeMismatch {
990 self_ty,
991 other_ty,
992 other_span: other.span,
993 sub: sub_diag,
994 }))
995 }
996}
997
998pub type Clauses<'tcx> = &'tcx ListWithCachedTypeInfo<Clause<'tcx>>;
999
1000impl<'tcx> rustc_type_ir::Flags for Clauses<'tcx> {
1001 fn flags(&self) -> TypeFlags {
1002 (**self).flags()
1003 }
1004
1005 fn outer_exclusive_binder(&self) -> DebruijnIndex {
1006 (**self).outer_exclusive_binder()
1007 }
1008}
1009
1010#[derive(#[automatically_derived]
impl<'tcx> ::core::fmt::Debug for ParamEnv<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field1_finish(f, "ParamEnv",
"caller_bounds", &&self.caller_bounds)
}
}Debug, #[automatically_derived]
impl<'tcx> ::core::marker::Copy for ParamEnv<'tcx> { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl<'tcx> ::core::clone::TrivialClone for ParamEnv<'tcx> { }
#[automatically_derived]
impl<'tcx> ::core::clone::Clone for ParamEnv<'tcx> {
#[inline]
fn clone(&self) -> ParamEnv<'tcx> {
let _: ::core::clone::AssertParamIsClone<Clauses<'tcx>>;
*self
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::hash::Hash for ParamEnv<'tcx> {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.caller_bounds, state)
}
}Hash, #[automatically_derived]
impl<'tcx> ::core::marker::StructuralPartialEq for ParamEnv<'tcx> { }
#[automatically_derived]
impl<'tcx> ::core::cmp::PartialEq for ParamEnv<'tcx> {
#[inline]
fn eq(&self, other: &ParamEnv<'tcx>) -> bool {
self.caller_bounds == other.caller_bounds
}
}PartialEq, #[automatically_derived]
impl<'tcx> ::core::cmp::Eq for ParamEnv<'tcx> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Clauses<'tcx>>;
}
}Eq)]
1016#[derive(const _: () =
{
impl<'tcx> ::rustc_data_structures::stable_hash::StableHash for
ParamEnv<'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 {
ParamEnv { caller_bounds: ref __binding_0 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash, const _: () =
{
impl<'tcx>
::rustc_middle::ty::TypeVisitable<::rustc_middle::ty::TyCtxt<'tcx>>
for ParamEnv<'tcx> {
fn visit_with<__V: ::rustc_middle::ty::TypeVisitor<::rustc_middle::ty::TyCtxt<'tcx>>>(&self,
__visitor: &mut __V) -> __V::Result {
match *self {
ParamEnv { caller_bounds: 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, const _: () =
{
impl<'tcx>
::rustc_middle::ty::TypeFoldable<::rustc_middle::ty::TyCtxt<'tcx>>
for ParamEnv<'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 {
ParamEnv { caller_bounds: __binding_0 } => {
ParamEnv {
caller_bounds: ::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 {
ParamEnv { caller_bounds: __binding_0 } => {
ParamEnv {
caller_bounds: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder),
}
}
}
}
}
};TypeFoldable)]
1017pub struct ParamEnv<'tcx> {
1018 caller_bounds: Clauses<'tcx>,
1024}
1025
1026const _: [(); std::mem::size_of::<usize>()] =
[(); ::std::mem::size_of::<ParamEnv<'_>>()];static_assert_size!(ParamEnv<'_>, std::mem::size_of::<usize>());
1030
1031impl<'tcx> rustc_type_ir::inherent::ParamEnv<TyCtxt<'tcx>> for ParamEnv<'tcx> {
1032 fn caller_bounds(self) -> impl Iterator<Item = ty::Clause<'tcx>> {
1033 self.caller_bounds()
1034 }
1035}
1036
1037impl<'tcx> ParamEnv<'tcx> {
1038 #[inline]
1045 pub fn empty() -> Self {
1046 Self { caller_bounds: ListWithCachedTypeInfo::empty() }
1047 }
1048
1049 #[inline]
1050 pub fn caller_bounds(self) -> impl Iterator<Item = ty::Clause<'tcx>> + Clone {
1051 self.caller_bounds.iter()
1052 }
1053
1054 #[inline]
1055 pub fn is_empty(self) -> bool {
1056 self.caller_bounds.as_slice().is_empty()
1057 }
1058
1059 #[inline]
1061 pub fn new(
1062 tcx: TyCtxt<'tcx>,
1063 caller_bounds: impl IntoIterator<Item = ty::Clause<'tcx>>,
1064 ) -> Self {
1065 ParamEnv { caller_bounds: tcx.mk_clauses_from_iter(caller_bounds.into_iter()) }
1066 }
1067
1068 pub fn and<T: TypeVisitable<TyCtxt<'tcx>>>(self, value: T) -> ParamEnvAnd<'tcx, T> {
1070 ParamEnvAnd { param_env: self, value }
1071 }
1072
1073 pub fn with_normalized(self, tcx: TyCtxt<'tcx>) -> ParamEnv<'tcx> {
1075 if tcx.next_trait_solver_globally() {
1078 self
1079 } else {
1080 ParamEnv::new(tcx, tcx.reveal_opaque_types_in_bounds(self.caller_bounds).iter())
1081 }
1082 }
1083}
1084
1085#[derive(#[automatically_derived]
impl<'tcx, T: ::core::marker::Copy> ::core::marker::Copy for
ParamEnvAnd<'tcx, T> {
}Copy, #[automatically_derived]
impl<'tcx, T: ::core::clone::Clone> ::core::clone::Clone for
ParamEnvAnd<'tcx, T> {
#[inline]
fn clone(&self) -> ParamEnvAnd<'tcx, T> {
ParamEnvAnd {
param_env: ::core::clone::Clone::clone(&self.param_env),
value: ::core::clone::Clone::clone(&self.value),
}
}
}Clone, #[automatically_derived]
impl<'tcx, T: ::core::fmt::Debug> ::core::fmt::Debug for ParamEnvAnd<'tcx, T>
{
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f, "ParamEnvAnd",
"param_env", &self.param_env, "value", &&self.value)
}
}Debug, #[automatically_derived]
impl<'tcx, T: ::core::cmp::PartialEq> ::core::marker::StructuralPartialEq for
ParamEnvAnd<'tcx, T> {
}
#[automatically_derived]
impl<'tcx, T: ::core::cmp::PartialEq> ::core::cmp::PartialEq for
ParamEnvAnd<'tcx, T> {
#[inline]
fn eq(&self, other: &ParamEnvAnd<'tcx, T>) -> bool {
self.param_env == other.param_env && self.value == other.value
}
}PartialEq, #[automatically_derived]
impl<'tcx, T: ::core::cmp::Eq> ::core::cmp::Eq for ParamEnvAnd<'tcx, T> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<ParamEnv<'tcx>>;
let _: ::core::cmp::AssertParamIsEq<T>;
}
}Eq, #[automatically_derived]
impl<'tcx, T: ::core::hash::Hash> ::core::hash::Hash for ParamEnvAnd<'tcx, T>
{
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.param_env, state);
::core::hash::Hash::hash(&self.value, state)
}
}Hash, const _: () =
{
impl<'tcx, T>
::rustc_middle::ty::TypeFoldable<::rustc_middle::ty::TyCtxt<'tcx>>
for ParamEnvAnd<'tcx, T> where
T: ::rustc_middle::ty::TypeFoldable<::rustc_middle::ty::TyCtxt<'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 {
ParamEnvAnd { param_env: __binding_0, value: __binding_1 }
=> {
ParamEnvAnd {
param_env: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
value: ::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 {
ParamEnvAnd { param_env: __binding_0, value: __binding_1 }
=> {
ParamEnvAnd {
param_env: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder),
value: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
__folder),
}
}
}
}
}
};TypeFoldable, const _: () =
{
impl<'tcx, T>
::rustc_middle::ty::TypeVisitable<::rustc_middle::ty::TyCtxt<'tcx>>
for ParamEnvAnd<'tcx, T> where
T: ::rustc_middle::ty::TypeVisitable<::rustc_middle::ty::TyCtxt<'tcx>>
{
fn visit_with<__V: ::rustc_middle::ty::TypeVisitor<::rustc_middle::ty::TyCtxt<'tcx>>>(&self,
__visitor: &mut __V) -> __V::Result {
match *self {
ParamEnvAnd {
param_env: ref __binding_0, value: 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)]
1086#[derive(const _: () =
{
impl<'tcx, T> ::rustc_data_structures::stable_hash::StableHash for
ParamEnvAnd<'tcx, T> where
T: ::rustc_data_structures::stable_hash::StableHash {
#[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 {
ParamEnvAnd {
param_env: ref __binding_0, value: ref __binding_1 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash)]
1087pub struct ParamEnvAnd<'tcx, T> {
1088 pub param_env: ParamEnv<'tcx>,
1089 pub value: T,
1090}
1091
1092#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for TypingEnv<'tcx> { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl<'tcx> ::core::clone::TrivialClone for TypingEnv<'tcx> { }
#[automatically_derived]
impl<'tcx> ::core::clone::Clone for TypingEnv<'tcx> {
#[inline]
fn clone(&self) -> TypingEnv<'tcx> {
let _: ::core::clone::AssertParamIsClone<TypingModeEqWrapper<'tcx>>;
let _: ::core::clone::AssertParamIsClone<ParamEnv<'tcx>>;
*self
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for TypingEnv<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f, "TypingEnv",
"typing_mode", &self.typing_mode, "param_env", &&self.param_env)
}
}Debug, #[automatically_derived]
impl<'tcx> ::core::marker::StructuralPartialEq for TypingEnv<'tcx> { }
#[automatically_derived]
impl<'tcx> ::core::cmp::PartialEq for TypingEnv<'tcx> {
#[inline]
fn eq(&self, other: &TypingEnv<'tcx>) -> bool {
self.typing_mode == other.typing_mode &&
self.param_env == other.param_env
}
}PartialEq, #[automatically_derived]
impl<'tcx> ::core::cmp::Eq for TypingEnv<'tcx> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<TypingModeEqWrapper<'tcx>>;
let _: ::core::cmp::AssertParamIsEq<ParamEnv<'tcx>>;
}
}Eq, #[automatically_derived]
impl<'tcx> ::core::hash::Hash for TypingEnv<'tcx> {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.typing_mode, state);
::core::hash::Hash::hash(&self.param_env, state)
}
}Hash, const _: () =
{
impl<'tcx> ::rustc_data_structures::stable_hash::StableHash for
TypingEnv<'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 {
TypingEnv {
typing_mode: ref __binding_0, param_env: ref __binding_1 }
=> {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash)]
1103#[derive(const _: () =
{
impl<'tcx>
::rustc_middle::ty::TypeVisitable<::rustc_middle::ty::TyCtxt<'tcx>>
for TypingEnv<'tcx> {
fn visit_with<__V: ::rustc_middle::ty::TypeVisitor<::rustc_middle::ty::TyCtxt<'tcx>>>(&self,
__visitor: &mut __V) -> __V::Result {
match *self {
TypingEnv { param_env: ref __binding_1, .. } => {
{
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, const _: () =
{
impl<'tcx>
::rustc_middle::ty::TypeFoldable<::rustc_middle::ty::TyCtxt<'tcx>>
for TypingEnv<'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 {
TypingEnv { typing_mode: __binding_0, param_env: __binding_1
} => {
TypingEnv {
typing_mode: __binding_0,
param_env: ::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 {
TypingEnv { typing_mode: __binding_0, param_env: __binding_1
} => {
TypingEnv {
typing_mode: __binding_0,
param_env: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
__folder),
}
}
}
}
}
};TypeFoldable)]
1104pub struct TypingEnv<'tcx> {
1105 #[type_foldable(identity)]
1106 #[type_visitable(ignore)]
1107 typing_mode: TypingModeEqWrapper<'tcx>,
1108 pub param_env: ParamEnv<'tcx>,
1109}
1110
1111impl<'tcx> TypingEnv<'tcx> {
1112 pub fn new(param_env: ParamEnv<'tcx>, typing_mode: TypingMode<'tcx>) -> Self {
1113 Self { typing_mode: TypingModeEqWrapper(typing_mode), param_env }
1114 }
1115
1116 pub fn typing_mode(&self) -> TypingMode<'tcx> {
1117 self.typing_mode.0
1118 }
1119
1120 pub fn fully_monomorphized() -> TypingEnv<'tcx> {
1128 Self::new(ParamEnv::empty(), TypingMode::Codegen)
1129 }
1130
1131 pub fn non_body_analysis(
1137 tcx: TyCtxt<'tcx>,
1138 def_id: impl IntoQueryKey<DefId>,
1139 ) -> TypingEnv<'tcx> {
1140 let def_id = def_id.into_query_key();
1141 Self::new(tcx.param_env(def_id), TypingMode::non_body_analysis())
1142 }
1143
1144 pub fn post_typeck_until_borrowck(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> TypingEnv<'tcx> {
1147 let param_env = tcx.param_env(def_id.to_def_id());
1148 TypingEnv::new(param_env, ty::TypingMode::borrowck(tcx, def_id))
1149 }
1150
1151 pub fn post_typeck_until_borrowck_for_mir_build(
1156 tcx: TyCtxt<'tcx>,
1157 def_id: LocalDefId,
1158 ) -> TypingEnv<'tcx> {
1159 if tcx.use_typing_mode_post_typeck_until_borrowck() {
1160 TypingEnv::new(tcx.param_env(def_id.to_def_id()), ty::TypingMode::borrowck(tcx, def_id))
1161 } else {
1162 TypingEnv::non_body_analysis(tcx, def_id)
1165 }
1166 }
1167
1168 pub fn post_analysis(tcx: TyCtxt<'tcx>, def_id: impl IntoQueryKey<DefId>) -> TypingEnv<'tcx> {
1169 TypingEnv::new(tcx.param_env_normalized_for_post_analysis(def_id), TypingMode::PostAnalysis)
1170 }
1171
1172 pub fn codegen(tcx: TyCtxt<'tcx>, def_id: impl IntoQueryKey<DefId>) -> TypingEnv<'tcx> {
1173 TypingEnv::new(tcx.param_env_normalized_for_post_analysis(def_id), TypingMode::Codegen)
1174 }
1175
1176 pub fn with_post_analysis_normalized(self, tcx: TyCtxt<'tcx>) -> TypingEnv<'tcx> {
1179 let TypingEnv { typing_mode, param_env } = self;
1180 match typing_mode.0.assert_not_erased() {
1181 TypingMode::Coherence
1182 | TypingMode::Reflection
1183 | TypingMode::Typeck { .. }
1184 | TypingMode::PostTypeckUntilBorrowck { .. }
1185 | TypingMode::PostBorrowck { .. } => {}
1186 TypingMode::PostAnalysis | TypingMode::Codegen => return self,
1187 }
1188
1189 let param_env = param_env.with_normalized(tcx);
1190 TypingEnv::new(param_env, TypingMode::PostAnalysis)
1191 }
1192
1193 pub fn with_codegen_normalized(self, tcx: TyCtxt<'tcx>) -> TypingEnv<'tcx> {
1196 let TypingEnv { typing_mode, param_env } = self;
1197 match typing_mode.0.assert_not_erased() {
1198 TypingMode::Coherence
1199 | TypingMode::Reflection
1200 | TypingMode::Typeck { .. }
1201 | TypingMode::PostTypeckUntilBorrowck { .. }
1202 | TypingMode::PostBorrowck { .. }
1203 | TypingMode::PostAnalysis => {}
1204 TypingMode::Codegen => return self,
1205 }
1206
1207 let param_env = param_env.with_normalized(tcx);
1208 TypingEnv::new(param_env, TypingMode::Codegen)
1209 }
1210
1211 pub fn as_query_input<T>(self, value: T) -> PseudoCanonicalInput<'tcx, T>
1216 where
1217 T: TypeVisitable<TyCtxt<'tcx>>,
1218 {
1219 PseudoCanonicalInput { typing_env: self, value }
1232 }
1233}
1234
1235#[derive(#[automatically_derived]
impl<'tcx, T: ::core::marker::Copy> ::core::marker::Copy for
PseudoCanonicalInput<'tcx, T> {
}Copy, #[automatically_derived]
impl<'tcx, T: ::core::clone::Clone> ::core::clone::Clone for
PseudoCanonicalInput<'tcx, T> {
#[inline]
fn clone(&self) -> PseudoCanonicalInput<'tcx, T> {
PseudoCanonicalInput {
typing_env: ::core::clone::Clone::clone(&self.typing_env),
value: ::core::clone::Clone::clone(&self.value),
}
}
}Clone, #[automatically_derived]
impl<'tcx, T: ::core::fmt::Debug> ::core::fmt::Debug for
PseudoCanonicalInput<'tcx, T> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f,
"PseudoCanonicalInput", "typing_env", &self.typing_env, "value",
&&self.value)
}
}Debug, #[automatically_derived]
impl<'tcx, T: ::core::cmp::PartialEq> ::core::marker::StructuralPartialEq for
PseudoCanonicalInput<'tcx, T> {
}
#[automatically_derived]
impl<'tcx, T: ::core::cmp::PartialEq> ::core::cmp::PartialEq for
PseudoCanonicalInput<'tcx, T> {
#[inline]
fn eq(&self, other: &PseudoCanonicalInput<'tcx, T>) -> bool {
self.typing_env == other.typing_env && self.value == other.value
}
}PartialEq, #[automatically_derived]
impl<'tcx, T: ::core::cmp::Eq> ::core::cmp::Eq for
PseudoCanonicalInput<'tcx, T> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<TypingEnv<'tcx>>;
let _: ::core::cmp::AssertParamIsEq<T>;
}
}Eq, #[automatically_derived]
impl<'tcx, T: ::core::hash::Hash> ::core::hash::Hash for
PseudoCanonicalInput<'tcx, T> {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.typing_env, state);
::core::hash::Hash::hash(&self.value, state)
}
}Hash)]
1245#[derive(const _: () =
{
impl<'tcx, T> ::rustc_data_structures::stable_hash::StableHash for
PseudoCanonicalInput<'tcx, T> where
T: ::rustc_data_structures::stable_hash::StableHash {
#[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 {
PseudoCanonicalInput {
typing_env: ref __binding_0, value: ref __binding_1 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash, const _: () =
{
impl<'tcx, T>
::rustc_middle::ty::TypeVisitable<::rustc_middle::ty::TyCtxt<'tcx>>
for PseudoCanonicalInput<'tcx, T> where
T: ::rustc_middle::ty::TypeVisitable<::rustc_middle::ty::TyCtxt<'tcx>>
{
fn visit_with<__V: ::rustc_middle::ty::TypeVisitor<::rustc_middle::ty::TyCtxt<'tcx>>>(&self,
__visitor: &mut __V) -> __V::Result {
match *self {
PseudoCanonicalInput {
typing_env: ref __binding_0, value: 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, const _: () =
{
impl<'tcx, T>
::rustc_middle::ty::TypeFoldable<::rustc_middle::ty::TyCtxt<'tcx>>
for PseudoCanonicalInput<'tcx, T> where
T: ::rustc_middle::ty::TypeFoldable<::rustc_middle::ty::TyCtxt<'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 {
PseudoCanonicalInput {
typing_env: __binding_0, value: __binding_1 } => {
PseudoCanonicalInput {
typing_env: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
value: ::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 {
PseudoCanonicalInput {
typing_env: __binding_0, value: __binding_1 } => {
PseudoCanonicalInput {
typing_env: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder),
value: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
__folder),
}
}
}
}
}
};TypeFoldable)]
1246pub struct PseudoCanonicalInput<'tcx, T> {
1247 pub typing_env: TypingEnv<'tcx>,
1248 pub value: T,
1249}
1250
1251#[derive(#[automatically_derived]
impl ::core::marker::Copy for Destructor { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for Destructor { }
#[automatically_derived]
impl ::core::clone::Clone for Destructor {
#[inline]
fn clone(&self) -> Destructor {
let _: ::core::clone::AssertParamIsClone<DefId>;
*self
}
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for Destructor {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field1_finish(f, "Destructor",
"did", &&self.did)
}
}Debug, const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for Destructor {
#[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 {
Destructor { did: ref __binding_0 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for Destructor {
fn encode(&self, __encoder: &mut __E) {
let Destructor { did: ref __binding_0 } = *self;
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
}
};Encodable, const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for Destructor {
fn decode(__decoder: &mut __D) -> Self {
Destructor {
did: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};Decodable)]
1252pub struct Destructor {
1253 pub did: DefId,
1255}
1256
1257#[derive(#[automatically_derived]
impl ::core::marker::Copy for AsyncDestructor { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for AsyncDestructor { }
#[automatically_derived]
impl ::core::clone::Clone for AsyncDestructor {
#[inline]
fn clone(&self) -> AsyncDestructor {
let _: ::core::clone::AssertParamIsClone<DefId>;
*self
}
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for AsyncDestructor {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field1_finish(f,
"AsyncDestructor", "impl_did", &&self.impl_did)
}
}Debug, const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for
AsyncDestructor {
#[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 {
AsyncDestructor { impl_did: ref __binding_0 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for AsyncDestructor {
fn encode(&self, __encoder: &mut __E) {
let AsyncDestructor { impl_did: ref __binding_0 } = *self;
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
}
};Encodable, const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for AsyncDestructor {
fn decode(__decoder: &mut __D) -> Self {
AsyncDestructor {
impl_did: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};Decodable)]
1259pub struct AsyncDestructor {
1260 pub impl_did: DefId,
1262}
1263
1264#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for VariantFlags { }
#[automatically_derived]
impl ::core::clone::Clone for VariantFlags {
#[inline]
fn clone(&self) -> VariantFlags {
let _: ::core::clone::AssertParamIsClone<u8>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for VariantFlags { }Copy, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for VariantFlags { }
#[automatically_derived]
impl ::core::cmp::PartialEq for VariantFlags {
#[inline]
fn eq(&self, other: &VariantFlags) -> bool { self.0 == other.0 }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for VariantFlags {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<u8>;
}
}Eq, const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for VariantFlags
{
#[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 {
VariantFlags(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash, const _: () =
{
impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
::rustc_serialize::Encodable<__E> for VariantFlags {
fn encode(&self, __encoder: &mut __E) {
let VariantFlags(ref __binding_0) = *self;
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
}
};TyEncodable, const _: () =
{
impl<'tcx, __D: ::rustc_middle::ty::codec::TyDecoder<'tcx>>
::rustc_serialize::Decodable<__D> for VariantFlags {
fn decode(__decoder: &mut __D) -> Self {
VariantFlags(::rustc_serialize::Decodable::decode(__decoder))
}
}
};TyDecodable)]
1265pub struct VariantFlags(u8);
1266impl VariantFlags {
#[allow(deprecated, non_upper_case_globals,)]
pub const NO_VARIANT_FLAGS: Self = Self::from_bits_retain(0);
#[doc =
r" Indicates whether the field list of this variant is `#[non_exhaustive]`."]
#[allow(deprecated, non_upper_case_globals,)]
pub const IS_FIELD_LIST_NON_EXHAUSTIVE: Self =
Self::from_bits_retain(1 << 0);
}
impl ::bitflags::Flags for VariantFlags {
const FLAGS: &'static [::bitflags::Flag<VariantFlags>] =
&[{
#[allow(deprecated, non_upper_case_globals,)]
::bitflags::Flag::new("NO_VARIANT_FLAGS",
VariantFlags::NO_VARIANT_FLAGS)
},
{
#[allow(deprecated, non_upper_case_globals,)]
::bitflags::Flag::new("IS_FIELD_LIST_NON_EXHAUSTIVE",
VariantFlags::IS_FIELD_LIST_NON_EXHAUSTIVE)
}];
type Bits = u8;
fn bits(&self) -> u8 { VariantFlags::bits(self) }
fn from_bits_retain(bits: u8) -> VariantFlags {
VariantFlags::from_bits_retain(bits)
}
}
#[allow(dead_code, deprecated, unused_doc_comments, unused_attributes,
unused_mut, unused_imports, non_upper_case_globals, clippy ::
assign_op_pattern, clippy :: iter_without_into_iter,)]
const _: () =
{
#[allow(dead_code, deprecated, unused_attributes)]
impl VariantFlags {
#[inline]
pub const fn empty() -> Self {
Self(<u8 as ::bitflags::Bits>::EMPTY)
}
#[inline]
pub const fn all() -> Self {
let mut truncated = <u8 as ::bitflags::Bits>::EMPTY;
let mut i = 0;
{
{
let flag =
<VariantFlags as
::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
{
{
let flag =
<VariantFlags as
::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
let _ = i;
Self(truncated)
}
#[inline]
pub const fn bits(&self) -> u8 { self.0 }
#[inline]
pub const fn from_bits(bits: u8)
-> ::bitflags::__private::core::option::Option<Self> {
let truncated = Self::from_bits_truncate(bits).0;
if truncated == bits {
::bitflags::__private::core::option::Option::Some(Self(bits))
} else { ::bitflags::__private::core::option::Option::None }
}
#[inline]
pub const fn from_bits_truncate(bits: u8) -> Self {
Self(bits & Self::all().0)
}
#[inline]
pub const fn from_bits_retain(bits: u8) -> Self { Self(bits) }
#[inline]
pub fn from_name(name: &str)
-> ::bitflags::__private::core::option::Option<Self> {
{
if name == "NO_VARIANT_FLAGS" {
return ::bitflags::__private::core::option::Option::Some(Self(VariantFlags::NO_VARIANT_FLAGS.bits()));
}
};
;
{
if name == "IS_FIELD_LIST_NON_EXHAUSTIVE" {
return ::bitflags::__private::core::option::Option::Some(Self(VariantFlags::IS_FIELD_LIST_NON_EXHAUSTIVE.bits()));
}
};
;
let _ = name;
::bitflags::__private::core::option::Option::None
}
#[inline]
pub const fn is_empty(&self) -> bool {
self.0 == <u8 as ::bitflags::Bits>::EMPTY
}
#[inline]
pub const fn is_all(&self) -> bool {
Self::all().0 | self.0 == self.0
}
#[inline]
pub const fn intersects(&self, other: Self) -> bool {
self.0 & other.0 != <u8 as ::bitflags::Bits>::EMPTY
}
#[inline]
pub const fn contains(&self, other: Self) -> bool {
self.0 & other.0 == other.0
}
#[inline]
pub fn insert(&mut self, other: Self) {
*self = Self(self.0).union(other);
}
#[inline]
pub fn remove(&mut self, other: Self) {
*self = Self(self.0).difference(other);
}
#[inline]
pub fn toggle(&mut self, other: Self) {
*self = Self(self.0).symmetric_difference(other);
}
#[inline]
pub fn set(&mut self, other: Self, value: bool) {
if value { self.insert(other); } else { self.remove(other); }
}
#[inline]
#[must_use]
pub const fn intersection(self, other: Self) -> Self {
Self(self.0 & other.0)
}
#[inline]
#[must_use]
pub const fn union(self, other: Self) -> Self {
Self(self.0 | other.0)
}
#[inline]
#[must_use]
pub const fn difference(self, other: Self) -> Self {
Self(self.0 & !other.0)
}
#[inline]
#[must_use]
pub const fn symmetric_difference(self, other: Self) -> Self {
Self(self.0 ^ other.0)
}
#[inline]
#[must_use]
pub const fn complement(self) -> Self {
Self::from_bits_truncate(!self.0)
}
}
impl ::bitflags::__private::core::fmt::Binary for VariantFlags {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::Binary::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::fmt::Octal for VariantFlags {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::Octal::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::fmt::LowerHex for VariantFlags {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::LowerHex::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::fmt::UpperHex for VariantFlags {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::UpperHex::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::ops::BitOr for VariantFlags {
type Output = Self;
#[inline]
fn bitor(self, other: VariantFlags) -> Self { self.union(other) }
}
impl ::bitflags::__private::core::ops::BitOrAssign for VariantFlags {
#[inline]
fn bitor_assign(&mut self, other: Self) { self.insert(other); }
}
impl ::bitflags::__private::core::ops::BitXor for VariantFlags {
type Output = Self;
#[inline]
fn bitxor(self, other: Self) -> Self {
self.symmetric_difference(other)
}
}
impl ::bitflags::__private::core::ops::BitXorAssign for VariantFlags {
#[inline]
fn bitxor_assign(&mut self, other: Self) { self.toggle(other); }
}
impl ::bitflags::__private::core::ops::BitAnd for VariantFlags {
type Output = Self;
#[inline]
fn bitand(self, other: Self) -> Self { self.intersection(other) }
}
impl ::bitflags::__private::core::ops::BitAndAssign for VariantFlags {
#[inline]
fn bitand_assign(&mut self, other: Self) {
*self =
Self::from_bits_retain(self.bits()).intersection(other);
}
}
impl ::bitflags::__private::core::ops::Sub for VariantFlags {
type Output = Self;
#[inline]
fn sub(self, other: Self) -> Self { self.difference(other) }
}
impl ::bitflags::__private::core::ops::SubAssign for VariantFlags {
#[inline]
fn sub_assign(&mut self, other: Self) { self.remove(other); }
}
impl ::bitflags::__private::core::ops::Not for VariantFlags {
type Output = Self;
#[inline]
fn not(self) -> Self { self.complement() }
}
impl ::bitflags::__private::core::iter::Extend<VariantFlags> for
VariantFlags {
fn extend<T: ::bitflags::__private::core::iter::IntoIterator<Item
= Self>>(&mut self, iterator: T) {
for item in iterator { self.insert(item) }
}
}
impl ::bitflags::__private::core::iter::FromIterator<VariantFlags> for
VariantFlags {
fn from_iter<T: ::bitflags::__private::core::iter::IntoIterator<Item
= Self>>(iterator: T) -> Self {
use ::bitflags::__private::core::iter::Extend;
let mut result = Self::empty();
result.extend(iterator);
result
}
}
impl VariantFlags {
#[inline]
pub const fn iter(&self) -> ::bitflags::iter::Iter<VariantFlags> {
::bitflags::iter::Iter::__private_const_new(<VariantFlags as
::bitflags::Flags>::FLAGS,
VariantFlags::from_bits_retain(self.bits()),
VariantFlags::from_bits_retain(self.bits()))
}
#[inline]
pub const fn iter_names(&self)
-> ::bitflags::iter::IterNames<VariantFlags> {
::bitflags::iter::IterNames::__private_const_new(<VariantFlags
as ::bitflags::Flags>::FLAGS,
VariantFlags::from_bits_retain(self.bits()),
VariantFlags::from_bits_retain(self.bits()))
}
}
impl ::bitflags::__private::core::iter::IntoIterator for VariantFlags
{
type Item = VariantFlags;
type IntoIter = ::bitflags::iter::Iter<VariantFlags>;
fn into_iter(self) -> Self::IntoIter { self.iter() }
}
};bitflags::bitflags! {
1267 impl VariantFlags: u8 {
1268 const NO_VARIANT_FLAGS = 0;
1269 const IS_FIELD_LIST_NON_EXHAUSTIVE = 1 << 0;
1271 }
1272}
1273impl ::std::fmt::Debug for VariantFlags {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
::bitflags::parser::to_writer(self, f)
}
}rustc_data_structures::external_bitflags_debug! { VariantFlags }
1274
1275#[derive(#[automatically_derived]
impl ::core::fmt::Debug for VariantDef {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
let names: &'static _ =
&["def_id", "ctor", "name", "discr", "fields", "tainted",
"flags"];
let values: &[&dyn ::core::fmt::Debug] =
&[&self.def_id, &self.ctor, &self.name, &self.discr, &self.fields,
&self.tainted, &&self.flags];
::core::fmt::Formatter::debug_struct_fields_finish(f, "VariantDef",
names, values)
}
}Debug, const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for VariantDef {
#[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 {
VariantDef {
def_id: ref __binding_0,
ctor: ref __binding_1,
name: ref __binding_2,
discr: ref __binding_3,
fields: ref __binding_4,
tainted: ref __binding_5,
flags: ref __binding_6 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
{ __binding_2.stable_hash(__hcx, __hasher); }
{ __binding_3.stable_hash(__hcx, __hasher); }
{ __binding_4.stable_hash(__hcx, __hasher); }
{ __binding_5.stable_hash(__hcx, __hasher); }
{ __binding_6.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash, const _: () =
{
impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
::rustc_serialize::Encodable<__E> for VariantDef {
fn encode(&self, __encoder: &mut __E) {
let VariantDef {
def_id: ref __binding_0,
ctor: ref __binding_1,
name: ref __binding_2,
discr: ref __binding_3,
fields: ref __binding_4,
tainted: ref __binding_5,
flags: ref __binding_6 } = *self;
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_2,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_3,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_4,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_5,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_6,
__encoder);
}
}
};TyEncodable, const _: () =
{
impl<'tcx, __D: ::rustc_middle::ty::codec::TyDecoder<'tcx>>
::rustc_serialize::Decodable<__D> for VariantDef {
fn decode(__decoder: &mut __D) -> Self {
VariantDef {
def_id: ::rustc_serialize::Decodable::decode(__decoder),
ctor: ::rustc_serialize::Decodable::decode(__decoder),
name: ::rustc_serialize::Decodable::decode(__decoder),
discr: ::rustc_serialize::Decodable::decode(__decoder),
fields: ::rustc_serialize::Decodable::decode(__decoder),
tainted: ::rustc_serialize::Decodable::decode(__decoder),
flags: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};TyDecodable)]
1277pub struct VariantDef {
1278 pub def_id: DefId,
1281 pub ctor: Option<(CtorKind, DefId)>,
1284 pub name: Symbol,
1286 pub discr: VariantDiscr,
1288 pub fields: IndexVec<FieldIdx, FieldDef>,
1290 tainted: Option<ErrorGuaranteed>,
1292 flags: VariantFlags,
1294}
1295
1296impl VariantDef {
1297 {}
#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("new",
"rustc_middle::ty", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_middle/src/ty/mod.rs"),
::tracing_core::__macro_support::Option::Some(1313u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::ty"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("name")
}> =
::tracing::__macro_support::FieldName::new("name");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("variant_did")
}> =
::tracing::__macro_support::FieldName::new("variant_did");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("ctor")
}> =
::tracing::__macro_support::FieldName::new("ctor");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("discr")
}> =
::tracing::__macro_support::FieldName::new("discr");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("fields")
}> =
::tracing::__macro_support::FieldName::new("fields");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("parent_did")
}> =
::tracing::__macro_support::FieldName::new("parent_did");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("recover_tainted")
}> =
::tracing::__macro_support::FieldName::new("recover_tainted");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("is_field_list_non_exhaustive")
}> =
::tracing::__macro_support::FieldName::new("is_field_list_non_exhaustive");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&name)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&variant_did)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ctor)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&discr)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fields)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&parent_did)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&recover_tainted)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&is_field_list_non_exhaustive
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: Self = loop {};
return __tracing_attr_fake_return;
}
{
let mut flags = VariantFlags::NO_VARIANT_FLAGS;
if is_field_list_non_exhaustive {
flags |= VariantFlags::IS_FIELD_LIST_NON_EXHAUSTIVE;
}
VariantDef {
def_id: variant_did.unwrap_or(parent_did),
ctor,
name,
discr,
fields,
flags,
tainted: recover_tainted,
}
}
}
}#[instrument(level = "debug")]
1314 pub fn new(
1315 name: Symbol,
1316 variant_did: Option<DefId>,
1317 ctor: Option<(CtorKind, DefId)>,
1318 discr: VariantDiscr,
1319 fields: IndexVec<FieldIdx, FieldDef>,
1320 parent_did: DefId,
1321 recover_tainted: Option<ErrorGuaranteed>,
1322 is_field_list_non_exhaustive: bool,
1323 ) -> Self {
1324 let mut flags = VariantFlags::NO_VARIANT_FLAGS;
1325 if is_field_list_non_exhaustive {
1326 flags |= VariantFlags::IS_FIELD_LIST_NON_EXHAUSTIVE;
1327 }
1328
1329 VariantDef {
1330 def_id: variant_did.unwrap_or(parent_did),
1331 ctor,
1332 name,
1333 discr,
1334 fields,
1335 flags,
1336 tainted: recover_tainted,
1337 }
1338 }
1339
1340 #[inline]
1346 pub fn is_field_list_non_exhaustive(&self) -> bool {
1347 self.flags.intersects(VariantFlags::IS_FIELD_LIST_NON_EXHAUSTIVE)
1348 }
1349
1350 #[inline]
1353 pub fn field_list_has_applicable_non_exhaustive(&self) -> bool {
1354 self.is_field_list_non_exhaustive() && !self.def_id.is_local()
1355 }
1356
1357 pub fn ident(&self, tcx: TyCtxt<'_>) -> Ident {
1359 Ident::new(self.name, tcx.def_ident_span(self.def_id).unwrap())
1360 }
1361
1362 #[inline]
1364 pub fn has_errors(&self) -> Result<(), ErrorGuaranteed> {
1365 self.tainted.map_or(Ok(()), Err)
1366 }
1367
1368 #[inline]
1369 pub fn ctor_kind(&self) -> Option<CtorKind> {
1370 self.ctor.map(|(kind, _)| kind)
1371 }
1372
1373 #[inline]
1374 pub fn ctor_def_id(&self) -> Option<DefId> {
1375 self.ctor.map(|(_, def_id)| def_id)
1376 }
1377
1378 #[inline]
1382 pub fn single_field(&self) -> &FieldDef {
1383 if !(self.fields.len() == 1) {
::core::panicking::panic("assertion failed: self.fields.len() == 1")
};assert!(self.fields.len() == 1);
1384
1385 &self.fields[FieldIdx::ZERO]
1386 }
1387
1388 #[inline]
1390 pub fn tail_opt(&self) -> Option<&FieldDef> {
1391 self.fields.raw.last()
1392 }
1393
1394 #[inline]
1400 pub fn tail(&self) -> &FieldDef {
1401 self.tail_opt().expect("expected unsized ADT to have a tail field")
1402 }
1403
1404 pub fn has_unsafe_fields(&self) -> bool {
1406 self.fields.iter().any(|x| x.safety.is_unsafe())
1407 }
1408}
1409
1410impl PartialEq for VariantDef {
1411 #[inline]
1412 fn eq(&self, other: &Self) -> bool {
1413 let Self {
1421 def_id: lhs_def_id,
1422 ctor: _,
1423 name: _,
1424 discr: _,
1425 fields: _,
1426 flags: _,
1427 tainted: _,
1428 } = &self;
1429 let Self {
1430 def_id: rhs_def_id,
1431 ctor: _,
1432 name: _,
1433 discr: _,
1434 fields: _,
1435 flags: _,
1436 tainted: _,
1437 } = other;
1438
1439 let res = lhs_def_id == rhs_def_id;
1440
1441 if truecfg!(debug_assertions) && res {
1443 let deep = self.ctor == other.ctor
1444 && self.name == other.name
1445 && self.discr == other.discr
1446 && self.fields == other.fields
1447 && self.flags == other.flags;
1448 if !deep {
{
::core::panicking::panic_fmt(format_args!("VariantDef for the same def-id has differing data"));
}
};assert!(deep, "VariantDef for the same def-id has differing data");
1449 }
1450
1451 res
1452 }
1453}
1454
1455impl Eq for VariantDef {}
1456
1457impl Hash for VariantDef {
1458 #[inline]
1459 fn hash<H: Hasher>(&self, s: &mut H) {
1460 let Self { def_id, ctor: _, name: _, discr: _, fields: _, flags: _, tainted: _ } = &self;
1468 def_id.hash(s)
1469 }
1470}
1471
1472#[derive(#[automatically_derived]
impl ::core::marker::Copy for VariantDiscr { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for VariantDiscr { }
#[automatically_derived]
impl ::core::clone::Clone for VariantDiscr {
#[inline]
fn clone(&self) -> VariantDiscr {
let _: ::core::clone::AssertParamIsClone<DefId>;
let _: ::core::clone::AssertParamIsClone<u32>;
*self
}
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for VariantDiscr {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
VariantDiscr::Explicit(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"Explicit", &__self_0),
VariantDiscr::Relative(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"Relative", &__self_0),
}
}
}Debug, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for VariantDiscr { }
#[automatically_derived]
impl ::core::cmp::PartialEq for VariantDiscr {
#[inline]
fn eq(&self, other: &VariantDiscr) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(VariantDiscr::Explicit(__self_0),
VariantDiscr::Explicit(__arg1_0)) => __self_0 == __arg1_0,
(VariantDiscr::Relative(__self_0),
VariantDiscr::Relative(__arg1_0)) => __self_0 == __arg1_0,
_ => unsafe { ::core::intrinsics::unreachable() }
}
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for VariantDiscr {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<DefId>;
let _: ::core::cmp::AssertParamIsEq<u32>;
}
}Eq, const _: () =
{
impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
::rustc_serialize::Encodable<__E> for VariantDiscr {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
VariantDiscr::Explicit(ref __binding_0) => { 0usize }
VariantDiscr::Relative(ref __binding_0) => { 1usize }
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
match *self {
VariantDiscr::Explicit(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
VariantDiscr::Relative(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 VariantDiscr {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => {
VariantDiscr::Explicit(::rustc_serialize::Decodable::decode(__decoder))
}
1usize => {
VariantDiscr::Relative(::rustc_serialize::Decodable::decode(__decoder))
}
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `VariantDiscr`, expected 0..2, actual {0}",
n));
}
}
}
}
};TyDecodable, const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for VariantDiscr
{
#[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 {
VariantDiscr::Explicit(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
VariantDiscr::Relative(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash)]
1473pub enum VariantDiscr {
1474 Explicit(DefId),
1477
1478 Relative(u32),
1483}
1484
1485#[derive(#[automatically_derived]
impl ::core::fmt::Debug for FieldDef {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
let names: &'static _ =
&["did", "name", "vis", "mut_restriction", "safety", "value"];
let values: &[&dyn ::core::fmt::Debug] =
&[&self.did, &self.name, &self.vis, &self.mut_restriction,
&self.safety, &&self.value];
::core::fmt::Formatter::debug_struct_fields_finish(f, "FieldDef",
names, values)
}
}Debug, const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for FieldDef {
#[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 {
FieldDef {
did: ref __binding_0,
name: ref __binding_1,
vis: ref __binding_2,
mut_restriction: ref __binding_3,
safety: ref __binding_4,
value: ref __binding_5 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
{ __binding_2.stable_hash(__hcx, __hasher); }
{ __binding_3.stable_hash(__hcx, __hasher); }
{ __binding_4.stable_hash(__hcx, __hasher); }
{ __binding_5.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash, const _: () =
{
impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
::rustc_serialize::Encodable<__E> for FieldDef {
fn encode(&self, __encoder: &mut __E) {
let FieldDef {
did: ref __binding_0,
name: ref __binding_1,
vis: ref __binding_2,
mut_restriction: ref __binding_3,
safety: ref __binding_4,
value: ref __binding_5 } = *self;
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_2,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_3,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_4,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_5,
__encoder);
}
}
};TyEncodable, const _: () =
{
impl<'tcx, __D: ::rustc_middle::ty::codec::TyDecoder<'tcx>>
::rustc_serialize::Decodable<__D> for FieldDef {
fn decode(__decoder: &mut __D) -> Self {
FieldDef {
did: ::rustc_serialize::Decodable::decode(__decoder),
name: ::rustc_serialize::Decodable::decode(__decoder),
vis: ::rustc_serialize::Decodable::decode(__decoder),
mut_restriction: ::rustc_serialize::Decodable::decode(__decoder),
safety: ::rustc_serialize::Decodable::decode(__decoder),
value: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};TyDecodable)]
1486pub struct FieldDef {
1487 pub did: DefId,
1488 pub name: Symbol,
1489 pub vis: Visibility<ModId>,
1490 pub mut_restriction: RestrictionKind,
1491 pub safety: hir::Safety,
1492 pub value: Option<DefId>,
1493}
1494
1495impl PartialEq for FieldDef {
1496 #[inline]
1497 fn eq(&self, other: &Self) -> bool {
1498 let Self { did: lhs_did, name: _, vis: _, mut_restriction: _, safety: _, value: _ } = &self;
1506
1507 let Self { did: rhs_did, name: _, vis: _, mut_restriction: _, safety: _, value: _ } = other;
1508
1509 let res = lhs_did == rhs_did;
1510
1511 if truecfg!(debug_assertions) && res {
1513 let deep = self.name == other.name
1514 && self.vis == other.vis
1515 && self.mut_restriction == other.mut_restriction
1516 && self.safety == other.safety;
1517 if !deep {
{
::core::panicking::panic_fmt(format_args!("FieldDef for the same def-id has differing data"));
}
};assert!(deep, "FieldDef for the same def-id has differing data");
1518 }
1519
1520 res
1521 }
1522}
1523
1524impl Eq for FieldDef {}
1525
1526impl Hash for FieldDef {
1527 #[inline]
1528 fn hash<H: Hasher>(&self, s: &mut H) {
1529 let Self { did, name: _, vis: _, mut_restriction: _, safety: _, value: _ } = &self;
1537
1538 did.hash(s)
1539 }
1540}
1541
1542impl<'tcx> FieldDef {
1543 pub fn ty(
1546 &self,
1547 tcx: TyCtxt<'tcx>,
1548 args: GenericArgsRef<'tcx>,
1549 ) -> Unnormalized<'tcx, Ty<'tcx>> {
1550 tcx.type_of(self.did).instantiate(tcx, args)
1551 }
1552
1553 pub fn ident(&self, tcx: TyCtxt<'_>) -> Ident {
1555 Ident::new(self.name, tcx.def_ident_span(self.did).unwrap())
1556 }
1557}
1558
1559#[derive(#[automatically_derived]
impl ::core::fmt::Debug for ImplOverlapKind {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
ImplOverlapKind::Permitted { marker: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"Permitted", "marker", &__self_0),
}
}
}Debug, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for ImplOverlapKind { }
#[automatically_derived]
impl ::core::cmp::PartialEq for ImplOverlapKind {
#[inline]
fn eq(&self, other: &ImplOverlapKind) -> bool {
match (self, other) {
(ImplOverlapKind::Permitted { marker: __self_0 },
ImplOverlapKind::Permitted { marker: __arg1_0 }) =>
__self_0 == __arg1_0,
}
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for ImplOverlapKind {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<bool>;
}
}Eq)]
1560pub enum ImplOverlapKind {
1561 Permitted {
1563 marker: bool,
1565 },
1566}
1567
1568#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for ImplTraitInTraitData { }
#[automatically_derived]
impl ::core::clone::Clone for ImplTraitInTraitData {
#[inline]
fn clone(&self) -> ImplTraitInTraitData {
let _: ::core::clone::AssertParamIsClone<DefId>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for ImplTraitInTraitData { }Copy, #[automatically_derived]
impl ::core::fmt::Debug for ImplTraitInTraitData {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
ImplTraitInTraitData::Trait {
fn_def_id: __self_0, opaque_def_id: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f, "Trait",
"fn_def_id", __self_0, "opaque_def_id", &__self_1),
ImplTraitInTraitData::Impl { fn_def_id: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f, "Impl",
"fn_def_id", &__self_0),
}
}
}Debug, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for ImplTraitInTraitData { }
#[automatically_derived]
impl ::core::cmp::PartialEq for ImplTraitInTraitData {
#[inline]
fn eq(&self, other: &ImplTraitInTraitData) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(ImplTraitInTraitData::Trait {
fn_def_id: __self_0, opaque_def_id: __self_1 },
ImplTraitInTraitData::Trait {
fn_def_id: __arg1_0, opaque_def_id: __arg1_1 }) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
(ImplTraitInTraitData::Impl { fn_def_id: __self_0 },
ImplTraitInTraitData::Impl { fn_def_id: __arg1_0 }) =>
__self_0 == __arg1_0,
_ => unsafe { ::core::intrinsics::unreachable() }
}
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for ImplTraitInTraitData {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<DefId>;
}
}Eq, #[automatically_derived]
impl ::core::hash::Hash for ImplTraitInTraitData {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
let __self_discr = ::core::intrinsics::discriminant_value(self);
::core::hash::Hash::hash(&__self_discr, state);
match self {
ImplTraitInTraitData::Trait {
fn_def_id: __self_0, opaque_def_id: __self_1 } => {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state)
}
ImplTraitInTraitData::Impl { fn_def_id: __self_0 } =>
::core::hash::Hash::hash(__self_0, state),
}
}
}Hash, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for ImplTraitInTraitData {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
ImplTraitInTraitData::Trait {
fn_def_id: ref __binding_0, opaque_def_id: ref __binding_1 }
=> {
0usize
}
ImplTraitInTraitData::Impl { fn_def_id: ref __binding_0 } =>
{
1usize
}
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
match *self {
ImplTraitInTraitData::Trait {
fn_def_id: ref __binding_0, opaque_def_id: ref __binding_1 }
=> {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
ImplTraitInTraitData::Impl { fn_def_id: ref __binding_0 } =>
{
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
}
}
}
};Encodable, const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for ImplTraitInTraitData {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => {
ImplTraitInTraitData::Trait {
fn_def_id: ::rustc_serialize::Decodable::decode(__decoder),
opaque_def_id: ::rustc_serialize::Decodable::decode(__decoder),
}
}
1usize => {
ImplTraitInTraitData::Impl {
fn_def_id: ::rustc_serialize::Decodable::decode(__decoder),
}
}
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `ImplTraitInTraitData`, expected 0..2, actual {0}",
n));
}
}
}
}
};Decodable, const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for
ImplTraitInTraitData {
#[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 {
ImplTraitInTraitData::Trait {
fn_def_id: ref __binding_0, opaque_def_id: ref __binding_1 }
=> {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
ImplTraitInTraitData::Impl { fn_def_id: ref __binding_0 } =>
{
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash)]
1571pub enum ImplTraitInTraitData {
1572 Trait { fn_def_id: DefId, opaque_def_id: DefId },
1573 Impl { fn_def_id: DefId },
1574}
1575
1576impl<'tcx> TyCtxt<'tcx> {
1577 pub fn typeck_body(self, body: hir::BodyId) -> &'tcx TypeckResults<'tcx> {
1578 self.typeck(self.hir_body_owner_def_id(body))
1579 }
1580
1581 pub fn provided_trait_methods(self, id: DefId) -> impl 'tcx + Iterator<Item = &'tcx AssocItem> {
1582 self.associated_items(id)
1583 .in_definition_order()
1584 .filter(move |item| item.is_fn() && item.defaultness(self).has_value())
1585 }
1586
1587 pub fn repr_options_of_def(self, did: LocalDefId) -> ReprOptions {
1588 let mut flags = ReprFlags::empty();
1589 let mut size = None;
1590 let mut max_align: Option<Align> = None;
1591 let mut min_pack: Option<Align> = None;
1592
1593 let mut field_shuffle_seed = self.def_path_hash(did.to_def_id()).0.to_smaller_hash();
1596
1597 if let Some(user_seed) = self.sess.opts.unstable_opts.layout_seed {
1601 field_shuffle_seed ^= user_seed;
1602 }
1603
1604 let elt = {
{
'done:
{
for i in ::rustc_attr_ir::HasAttrs::get_attrs(did, &self) {
#[allow(unused_imports)]
use ::rustc_attr_ir::AttributeKind::*;
let i: &::rustc_attr_ir::Attribute = i;
match i {
::rustc_attr_ir::Attribute::Parsed(RustcScalableVector {
element_count }) => {
break 'done Some(element_count);
}
::rustc_attr_ir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}
}find_attr!(self, did, RustcScalableVector { element_count } => element_count
1605 )
1606 .map(|elt| match elt {
1607 Some(n) => ScalableElt::ElementCount(*n),
1608 None => ScalableElt::Container,
1609 });
1610 if elt.is_some() {
1611 flags.insert(ReprFlags::IS_SCALABLE);
1612 }
1613 if let Some(reprs) = {
{
'done:
{
for i in ::rustc_attr_ir::HasAttrs::get_attrs(did, &self) {
#[allow(unused_imports)]
use ::rustc_attr_ir::AttributeKind::*;
let i: &::rustc_attr_ir::Attribute = i;
match i {
::rustc_attr_ir::Attribute::Parsed(Repr { reprs, .. }) => {
break 'done Some(reprs);
}
::rustc_attr_ir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}
}find_attr!(self, did, Repr { reprs, .. } => reprs) {
1614 for (r, _) in reprs {
1615 flags.insert(match *r {
1616 attr::ReprRust => ReprFlags::empty(),
1617 attr::ReprC => ReprFlags::IS_C,
1618 attr::ReprPacked(pack) => {
1619 min_pack = Some(if let Some(min_pack) = min_pack {
1620 min_pack.min(pack)
1621 } else {
1622 pack
1623 });
1624 ReprFlags::empty()
1625 }
1626 attr::ReprTransparent => ReprFlags::IS_TRANSPARENT,
1627 attr::ReprSimd => ReprFlags::IS_SIMD,
1628 attr::ReprInt(i) => {
1629 size = Some(match i {
1630 attr::IntType::SignedInt(x) => match x {
1631 ast::IntTy::Isize => IntegerType::Pointer(true),
1632 ast::IntTy::I8 => IntegerType::Fixed(Integer::I8, true),
1633 ast::IntTy::I16 => IntegerType::Fixed(Integer::I16, true),
1634 ast::IntTy::I32 => IntegerType::Fixed(Integer::I32, true),
1635 ast::IntTy::I64 => IntegerType::Fixed(Integer::I64, true),
1636 ast::IntTy::I128 => IntegerType::Fixed(Integer::I128, true),
1637 },
1638 attr::IntType::UnsignedInt(x) => match x {
1639 ast::UintTy::Usize => IntegerType::Pointer(false),
1640 ast::UintTy::U8 => IntegerType::Fixed(Integer::I8, false),
1641 ast::UintTy::U16 => IntegerType::Fixed(Integer::I16, false),
1642 ast::UintTy::U32 => IntegerType::Fixed(Integer::I32, false),
1643 ast::UintTy::U64 => IntegerType::Fixed(Integer::I64, false),
1644 ast::UintTy::U128 => IntegerType::Fixed(Integer::I128, false),
1645 },
1646 });
1647 ReprFlags::empty()
1648 }
1649 attr::ReprAlign(align) => {
1650 max_align = max_align.max(Some(align));
1651 ReprFlags::empty()
1652 }
1653 });
1654 }
1655 }
1656
1657 if self.sess.opts.unstable_opts.randomize_layout {
1660 flags.insert(ReprFlags::RANDOMIZE_LAYOUT);
1661 }
1662
1663 let is_box = self.is_lang_item(did.to_def_id(), LangItem::OwnedBox);
1666
1667 if is_box {
1669 flags.insert(ReprFlags::IS_LINEAR);
1670 }
1671
1672 if {
{
'done:
{
for i in ::rustc_attr_ir::HasAttrs::get_attrs(did, &self) {
#[allow(unused_imports)]
use ::rustc_attr_ir::AttributeKind::*;
let i: &::rustc_attr_ir::Attribute = i;
match i {
::rustc_attr_ir::Attribute::Parsed(RustcPassIndirectlyInNonRusticAbis(..))
=> {
break 'done Some(());
}
::rustc_attr_ir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}
}.is_some()find_attr!(self, did, RustcPassIndirectlyInNonRusticAbis(..)) {
1674 flags.insert(ReprFlags::PASS_INDIRECTLY_IN_NON_RUSTIC_ABIS);
1675 }
1676
1677 ReprOptions {
1678 int: size,
1679 align: max_align,
1680 pack: min_pack,
1681 flags,
1682 field_shuffle_seed,
1683 scalable: elt,
1684 }
1685 }
1686
1687 pub fn opt_item_name(self, def_id: impl IntoQueryKey<DefId>) -> Option<Symbol> {
1689 let def_id = def_id.into_query_key();
1690 if let Some(cnum) = def_id.as_crate_root() {
1691 Some(self.crate_name(cnum))
1692 } else {
1693 let def_key = self.def_key(def_id);
1694 match def_key.disambiguated_data.data {
1695 rustc_hir::definitions::DefPathData::Ctor => self
1697 .opt_item_name(DefId { krate: def_id.krate, index: def_key.parent.unwrap() }),
1698 _ => def_key.get_opt_name(),
1699 }
1700 }
1701 }
1702
1703 pub fn item_name(self, id: impl IntoQueryKey<DefId>) -> Symbol {
1710 let id = id.into_query_key();
1711 self.opt_item_name(id).unwrap_or_else(|| {
1712 crate::util::bug::bug_fmt(format_args!("item_name: no name for {0:?}",
self.def_path(id)));bug!("item_name: no name for {:?}", self.def_path(id));
1713 })
1714 }
1715
1716 pub fn opt_item_ident(self, def_id: impl IntoQueryKey<DefId>) -> Option<Ident> {
1720 let def_id = def_id.into_query_key();
1721 let def = self.opt_item_name(def_id)?;
1722 let span = self
1723 .def_ident_span(def_id)
1724 .unwrap_or_else(|| crate::util::bug::bug_fmt(format_args!("missing ident span for {0:?}",
def_id))bug!("missing ident span for {def_id:?}"));
1725 Some(Ident::new(def, span))
1726 }
1727
1728 pub fn item_ident(self, def_id: impl IntoQueryKey<DefId>) -> Ident {
1732 let def_id = def_id.into_query_key();
1733 self.opt_item_ident(def_id).unwrap_or_else(|| {
1734 crate::util::bug::bug_fmt(format_args!("item_ident: no name for {0:?}",
self.def_path(def_id)));bug!("item_ident: no name for {:?}", self.def_path(def_id));
1735 })
1736 }
1737
1738 pub fn opt_associated_item(self, def_id: DefId) -> Option<AssocItem> {
1739 if let DefKind::AssocConst { .. } | DefKind::AssocFn | DefKind::AssocTy =
1740 self.def_kind(def_id)
1741 {
1742 Some(self.associated_item(def_id))
1743 } else {
1744 None
1745 }
1746 }
1747
1748 pub fn opt_rpitit_info(self, def_id: DefId) -> Option<ImplTraitInTraitData> {
1752 if let DefKind::AssocTy = self.def_kind(def_id)
1753 && let AssocKind::Type { data: AssocTypeData::Rpitit(rpitit_info) } =
1754 self.associated_item(def_id).kind
1755 {
1756 Some(rpitit_info)
1757 } else {
1758 None
1759 }
1760 }
1761
1762 pub fn find_field_index(self, ident: Ident, variant: &VariantDef) -> Option<FieldIdx> {
1763 variant.fields.iter_enumerated().find_map(|(i, field)| {
1764 self.hygienic_eq(ident, field.ident(self), variant.def_id).then_some(i)
1765 })
1766 }
1767
1768 {}
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() || { false }
{
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("impls_are_allowed_to_overlap",
"rustc_middle::ty", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_middle/src/ty/mod.rs"),
::tracing_core::__macro_support::Option::Some(1770u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::ty"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("def_id1")
}> =
::tracing::__macro_support::FieldName::new("def_id1");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("def_id2")
}> =
::tracing::__macro_support::FieldName::new("def_id2");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&def_id1)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&def_id2)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
(move ||
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy
:: needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: Option<ImplOverlapKind> =
loop {};
return __tracing_attr_fake_return;
}
{
let impl1 = self.impl_trait_header(def_id1);
let impl2 = self.impl_trait_header(def_id2);
let trait_ref1 = impl1.trait_ref.skip_binder();
let trait_ref2 = impl2.trait_ref.skip_binder();
if trait_ref1.references_error() ||
trait_ref2.references_error() {
return Some(ImplOverlapKind::Permitted { marker: false });
}
match (impl1.polarity, impl2.polarity) {
(ImplPolarity::Positive, ImplPolarity::Negative) |
(ImplPolarity::Negative, ImplPolarity::Positive) => {
return None;
}
(ImplPolarity::Positive, ImplPolarity::Positive) |
(ImplPolarity::Negative, ImplPolarity::Negative) => {}
};
let is_marker_impl =
|trait_ref: TraitRef<'_>|
self.trait_def(trait_ref.def_id).is_marker;
let is_marker_overlap =
is_marker_impl(trait_ref1) && is_marker_impl(trait_ref2);
if is_marker_overlap {
return Some(ImplOverlapKind::Permitted { marker: true });
}
None
}
})();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_middle/src/ty/mod.rs:1770",
"rustc_middle::ty", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_middle/src/ty/mod.rs"),
::tracing_core::__macro_support::Option::Some(1770u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::ty"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return")
}> =
::tracing::__macro_support::FieldName::new("return");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
x;#[instrument(level = "debug", skip(self), ret)]
1771 pub fn impls_are_allowed_to_overlap(
1772 self,
1773 def_id1: DefId,
1774 def_id2: DefId,
1775 ) -> Option<ImplOverlapKind> {
1776 let impl1 = self.impl_trait_header(def_id1);
1777 let impl2 = self.impl_trait_header(def_id2);
1778
1779 let trait_ref1 = impl1.trait_ref.skip_binder();
1780 let trait_ref2 = impl2.trait_ref.skip_binder();
1781
1782 if trait_ref1.references_error() || trait_ref2.references_error() {
1785 return Some(ImplOverlapKind::Permitted { marker: false });
1786 }
1787
1788 match (impl1.polarity, impl2.polarity) {
1789 (ImplPolarity::Positive, ImplPolarity::Negative)
1790 | (ImplPolarity::Negative, ImplPolarity::Positive) => {
1791 return None;
1793 }
1794 (ImplPolarity::Positive, ImplPolarity::Positive)
1795 | (ImplPolarity::Negative, ImplPolarity::Negative) => {}
1796 };
1797
1798 let is_marker_impl = |trait_ref: TraitRef<'_>| self.trait_def(trait_ref.def_id).is_marker;
1799 let is_marker_overlap = is_marker_impl(trait_ref1) && is_marker_impl(trait_ref2);
1800
1801 if is_marker_overlap {
1802 return Some(ImplOverlapKind::Permitted { marker: true });
1803 }
1804
1805 None
1806 }
1807
1808 pub fn expect_variant_res(self, res: Res) -> &'tcx VariantDef {
1811 match res {
1812 Res::Def(DefKind::Variant, did) => {
1813 let enum_did = self.parent(did);
1814 self.adt_def(enum_did).variant_with_id(did)
1815 }
1816 Res::Def(DefKind::Struct | DefKind::Union, did) => self.adt_def(did).non_enum_variant(),
1817 Res::Def(DefKind::Ctor(CtorOf::Variant, ..), variant_ctor_did) => {
1818 let variant_did = self.parent(variant_ctor_did);
1819 let enum_did = self.parent(variant_did);
1820 self.adt_def(enum_did).variant_with_ctor_id(variant_ctor_did)
1821 }
1822 Res::Def(DefKind::Ctor(CtorOf::Struct, ..), ctor_did) => {
1823 let struct_did = self.parent(ctor_did);
1824 self.adt_def(struct_did).non_enum_variant()
1825 }
1826 _ => crate::util::bug::bug_fmt(format_args!("expect_variant_res used with unexpected res {0:?}",
res))bug!("expect_variant_res used with unexpected res {:?}", res),
1827 }
1828 }
1829
1830 {}
#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("instance_mir",
"rustc_middle::ty", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_middle/src/ty/mod.rs"),
::tracing_core::__macro_support::Option::Some(1831u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::ty"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("instance")
}> =
::tracing::__macro_support::FieldName::new("instance");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&instance)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: &'tcx Body<'tcx> = loop {};
return __tracing_attr_fake_return;
}
{
let body =
match instance {
ty::InstanceKind::Item(def) => {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_middle/src/ty/mod.rs:1835",
"rustc_middle::ty", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_middle/src/ty/mod.rs"),
::tracing_core::__macro_support::Option::Some(1835u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::ty"),
::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("calling def_kind on def: {0:?}",
def) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let def_kind = self.def_kind(def);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_middle/src/ty/mod.rs:1837",
"rustc_middle::ty", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_middle/src/ty/mod.rs"),
::tracing_core::__macro_support::Option::Some(1837u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::ty"),
::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("returned from def_kind: {0:?}",
def_kind) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
match def_kind {
DefKind::Const { .. } | DefKind::Static { .. } |
DefKind::AssocConst { .. } | DefKind::Ctor(..) |
DefKind::AnonConst => self.mir_for_ctfe(def),
DefKind::Fn | DefKind::AssocFn if
#[allow(non_exhaustive_omitted_patterns)] match self.constness(def)
{
hir::Constness::Const { always: true } => true,
_ => false,
} => {
self.mir_for_ctfe(def)
}
_ => self.optimized_mir(def),
}
}
ty::InstanceKind::Intrinsic(..) |
ty::InstanceKind::LlvmIntrinsic(..) => {
crate::util::bug::bug_fmt(format_args!("intrinsics have no instance MIR"))
}
ty::InstanceKind::Virtual(..) =>
crate::util::bug::bug_fmt(format_args!("virtual dispatches have no instance MIR")),
ty::InstanceKind::Shim(shim) => self.mir_shims(shim),
};
if !#[allow(non_exhaustive_omitted_patterns)] match body.phase {
MirPhase::Runtime(_) => true,
_ => false,
} {
{
::core::panicking::panic_fmt(format_args!("body: {1:?} instance: {2:?} {0:?}",
if let ty::InstanceKind::Item(d) = instance {
Some(self.def_kind(d))
} else { None }, body, instance));
}
};
body
}
}
}#[instrument(skip(self), level = "debug")]
1832 pub fn instance_mir(self, instance: ty::InstanceKind<'tcx>) -> &'tcx Body<'tcx> {
1833 let body = match instance {
1834 ty::InstanceKind::Item(def) => {
1835 debug!("calling def_kind on def: {:?}", def);
1836 let def_kind = self.def_kind(def);
1837 debug!("returned from def_kind: {:?}", def_kind);
1838 match def_kind {
1839 DefKind::Const { .. }
1840 | DefKind::Static { .. }
1841 | DefKind::AssocConst { .. }
1842 | DefKind::Ctor(..)
1843 | DefKind::AnonConst => self.mir_for_ctfe(def),
1844 DefKind::Fn | DefKind::AssocFn
1845 if matches!(
1846 self.constness(def),
1847 hir::Constness::Const { always: true }
1848 ) =>
1849 {
1850 self.mir_for_ctfe(def)
1851 }
1852 _ => self.optimized_mir(def),
1855 }
1856 }
1857 ty::InstanceKind::Intrinsic(..) | ty::InstanceKind::LlvmIntrinsic(..) => {
1858 bug!("intrinsics have no instance MIR")
1859 }
1860 ty::InstanceKind::Virtual(..) => bug!("virtual dispatches have no instance MIR"),
1861 ty::InstanceKind::Shim(shim) => self.mir_shims(shim),
1862 };
1863
1864 assert!(
1865 matches!(body.phase, MirPhase::Runtime(_)),
1866 "body: {body:?} instance: {instance:?} {:?}",
1867 if let ty::InstanceKind::Item(d) = instance { Some(self.def_kind(d)) } else { None },
1868 );
1869
1870 body
1871 }
1872
1873 #[deprecated = "Though there are valid usecases for this method, especially when your attribute is not a parsed attribute, usually you want to call rustc_hir::find_attr! instead."]
1875 pub fn get_attrs(
1876 self,
1877 did: impl Into<DefId>,
1878 attr: Symbol,
1879 ) -> impl Iterator<Item = &'tcx rustc_attr_ir::Attribute> {
1880 #[expect(deprecated)]
1881 self.get_all_attrs(did).iter().filter(move |a: &&rustc_attr_ir::Attribute| a.has_name(attr))
1882 }
1883
1884 #[deprecated = "Though there are valid usecases for this method, especially when your attribute is not a parsed attribute, usually you want to call rustc_hir::find_attr! instead."]
1894 pub fn get_all_attrs(self, did: impl Into<DefId>) -> &'tcx [rustc_attr_ir::Attribute] {
1895 let did: DefId = did.into();
1896 if let Some(did) = did.as_local() {
1897 self.hir_attrs(self.local_def_id_to_hir_id(did))
1898 } else {
1899 self.attrs_for_def(did)
1900 }
1901 }
1902
1903 pub fn get_attrs_by_path(
1904 self,
1905 did: DefId,
1906 attr: &[Symbol],
1907 ) -> impl Iterator<Item = &'tcx rustc_attr_ir::Attribute> {
1908 let filter_fn = move |a: &&rustc_attr_ir::Attribute| a.path_matches(attr);
1909 if let Some(did) = did.as_local() {
1910 self.hir_attrs(self.local_def_id_to_hir_id(did)).iter().filter(filter_fn)
1911 } else {
1912 self.attrs_for_def(did).iter().filter(filter_fn)
1913 }
1914 }
1915
1916 pub fn trait_is_auto(self, trait_def_id: DefId) -> bool {
1918 self.trait_def(trait_def_id).has_auto_impl
1919 }
1920
1921 pub fn trait_is_coinductive(self, trait_def_id: DefId) -> bool {
1924 self.trait_def(trait_def_id).is_coinductive
1925 }
1926
1927 pub fn trait_is_alias(self, trait_def_id: DefId) -> bool {
1929 self.def_kind(trait_def_id) == DefKind::TraitAlias
1930 }
1931
1932 fn layout_error(self, err: LayoutError<'tcx>) -> &'tcx LayoutError<'tcx> {
1934 self.arena.alloc(err)
1935 }
1936
1937 fn ordinary_coroutine_layout(
1943 self,
1944 def_id: DefId,
1945 args: GenericArgsRef<'tcx>,
1946 ) -> Result<&'tcx CoroutineLayout<'tcx>, &'tcx LayoutError<'tcx>> {
1947 let coroutine_kind_ty = args.as_coroutine().kind_ty();
1948 let mir = self.optimized_mir(def_id);
1949 let ty = || Ty::new_coroutine(self, def_id, args);
1950 if coroutine_kind_ty.is_unit() {
1952 mir.coroutine_layout_raw().ok_or_else(|| self.layout_error(LayoutError::Unknown(ty())))
1953 } else {
1954 let ty::Coroutine(_, identity_args) =
1957 *self.type_of(def_id).instantiate_identity().skip_norm_wip().kind()
1958 else {
1959 ::core::panicking::panic("internal error: entered unreachable code");unreachable!();
1960 };
1961 let identity_kind_ty = identity_args.as_coroutine().kind_ty();
1962 if identity_kind_ty == coroutine_kind_ty {
1965 mir.coroutine_layout_raw()
1966 .ok_or_else(|| self.layout_error(LayoutError::Unknown(ty())))
1967 } else {
1968 {
match coroutine_kind_ty.to_opt_closure_kind() {
Some(ClosureKind::FnOnce) => {}
ref left_val => {
::core::panicking::assert_matches_failed(left_val,
"Some(ClosureKind::FnOnce)", ::core::option::Option::None);
}
}
};assert_matches!(coroutine_kind_ty.to_opt_closure_kind(), Some(ClosureKind::FnOnce));
1969 {
match identity_kind_ty.to_opt_closure_kind() {
Some(ClosureKind::Fn | ClosureKind::FnMut) => {}
ref left_val => {
::core::panicking::assert_matches_failed(left_val,
"Some(ClosureKind::Fn | ClosureKind::FnMut)",
::core::option::Option::None);
}
}
};assert_matches!(
1970 identity_kind_ty.to_opt_closure_kind(),
1971 Some(ClosureKind::Fn | ClosureKind::FnMut)
1972 );
1973 self.optimized_mir(self.coroutine_by_move_body_def_id(def_id))
1974 .coroutine_layout_raw()
1975 .ok_or_else(|| self.layout_error(LayoutError::Unknown(ty())))
1976 }
1977 }
1978 }
1979
1980 fn async_drop_coroutine_layout(
1984 self,
1985 def_id: DefId,
1986 args: GenericArgsRef<'tcx>,
1987 ) -> Result<&'tcx CoroutineLayout<'tcx>, &'tcx LayoutError<'tcx>> {
1988 let ty = || Ty::new_coroutine(self, def_id, args);
1989 if args[0].has_placeholders() || args[0].has_non_region_param() {
1990 return Err(self.layout_error(LayoutError::TooGeneric(ty())));
1991 }
1992 let instance = ShimKind::AsyncDropGlue(def_id, Ty::new_coroutine(self, def_id, args));
1993 self.mir_shims(instance)
1994 .coroutine_layout_raw()
1995 .ok_or_else(|| self.layout_error(LayoutError::Unknown(ty())))
1996 }
1997
1998 pub fn coroutine_layout(
2001 self,
2002 def_id: DefId,
2003 args: GenericArgsRef<'tcx>,
2004 ) -> Result<&'tcx CoroutineLayout<'tcx>, &'tcx LayoutError<'tcx>> {
2005 if self.is_async_drop_in_place_coroutine(def_id) {
2006 let arg_cor_ty = args.first().unwrap().expect_ty();
2010 if arg_cor_ty.is_coroutine() {
2011 let span = self.def_span(def_id);
2012 let source_info = SourceInfo::outermost(span);
2013 let variant_fields: IndexVec<VariantIdx, IndexVec<FieldIdx, CoroutineSavedLocal>> =
2016 iter::repeat(IndexVec::new()).take(CoroutineArgs::RESERVED_VARIANTS).collect();
2017 let variant_source_info: IndexVec<VariantIdx, SourceInfo> =
2018 iter::repeat(source_info).take(CoroutineArgs::RESERVED_VARIANTS).collect();
2019 let proxy_layout = CoroutineLayout {
2020 field_tys: [].into(),
2021 variant_fields,
2022 variant_source_info,
2023 storage_conflicts: BitMatrix::new(0, 0),
2024 };
2025 return Ok(self.arena.alloc(proxy_layout));
2026 } else {
2027 self.async_drop_coroutine_layout(def_id, args)
2028 }
2029 } else {
2030 self.ordinary_coroutine_layout(def_id, args)
2031 }
2032 }
2033
2034 pub fn assoc_parent(self, def_id: DefId) -> Option<(DefId, DefKind)> {
2036 if !self.def_kind(def_id).is_assoc() {
2037 return None;
2038 }
2039 let parent = self.parent(def_id);
2040 let def_kind = self.def_kind(parent);
2041 Some((parent, def_kind))
2042 }
2043
2044 pub fn trait_item_of(self, def_id: impl IntoQueryKey<DefId>) -> Option<DefId> {
2046 let def_id = def_id.into_query_key();
2047 self.opt_associated_item(def_id)?.trait_item_def_id()
2048 }
2049
2050 pub fn trait_of_assoc(self, def_id: DefId) -> Option<DefId> {
2053 match self.assoc_parent(def_id) {
2054 Some((id, DefKind::Trait)) => Some(id),
2055 _ => None,
2056 }
2057 }
2058
2059 pub fn impl_is_of_trait(self, def_id: impl IntoQueryKey<DefId>) -> bool {
2060 let def_id = def_id.into_query_key();
2061 let DefKind::Impl { of_trait } = self.def_kind(def_id) else {
2062 {
::core::panicking::panic_fmt(format_args!("expected Impl for {0:?}",
def_id));
};panic!("expected Impl for {def_id:?}");
2063 };
2064 of_trait
2065 }
2066
2067 pub fn impl_of_assoc(self, def_id: DefId) -> Option<DefId> {
2070 match self.assoc_parent(def_id) {
2071 Some((id, DefKind::Impl { .. })) => Some(id),
2072 _ => None,
2073 }
2074 }
2075
2076 pub fn inherent_impl_of_assoc(self, def_id: DefId) -> Option<DefId> {
2079 match self.assoc_parent(def_id) {
2080 Some((id, DefKind::Impl { of_trait: false })) => Some(id),
2081 _ => None,
2082 }
2083 }
2084
2085 pub fn trait_impl_of_assoc(self, def_id: DefId) -> Option<DefId> {
2088 match self.assoc_parent(def_id) {
2089 Some((id, DefKind::Impl { of_trait: true })) => Some(id),
2090 _ => None,
2091 }
2092 }
2093
2094 pub fn impl_polarity(self, def_id: impl IntoQueryKey<DefId>) -> ty::ImplPolarity {
2095 let def_id = def_id.into_query_key();
2096 self.impl_trait_header(def_id).polarity
2097 }
2098
2099 pub fn impl_trait_ref(
2101 self,
2102 def_id: impl IntoQueryKey<DefId>,
2103 ) -> ty::EarlyBinder<'tcx, ty::TraitRef<'tcx>> {
2104 let def_id = def_id.into_query_key();
2105 self.impl_trait_header(def_id).trait_ref
2106 }
2107
2108 pub fn impl_opt_trait_ref(
2111 self,
2112 def_id: impl IntoQueryKey<DefId>,
2113 ) -> Option<ty::EarlyBinder<'tcx, ty::TraitRef<'tcx>>> {
2114 let def_id = def_id.into_query_key();
2115 self.impl_is_of_trait(def_id).then(|| self.impl_trait_ref(def_id))
2116 }
2117
2118 pub fn impl_trait_id(self, def_id: impl IntoQueryKey<DefId>) -> DefId {
2120 let def_id = def_id.into_query_key();
2121 self.impl_trait_ref(def_id).skip_binder().def_id
2122 }
2123
2124 pub fn impl_opt_trait_id(self, def_id: impl IntoQueryKey<DefId>) -> Option<DefId> {
2127 let def_id = def_id.into_query_key();
2128 self.impl_is_of_trait(def_id).then(|| self.impl_trait_id(def_id))
2129 }
2130
2131 pub fn is_exportable(self, def_id: DefId) -> bool {
2132 self.exportable_items(def_id.krate).contains(&def_id)
2133 }
2134
2135 pub fn is_builtin_derived(self, def_id: DefId) -> bool {
2138 if self.is_automatically_derived(def_id)
2139 && let Some(def_id) = def_id.as_local()
2140 && let outer = self.def_span(def_id).ctxt().outer_expn_data()
2141 && #[allow(non_exhaustive_omitted_patterns)] match outer.kind {
ExpnKind::Macro(MacroKind::Derive, _) => true,
_ => false,
}matches!(outer.kind, ExpnKind::Macro(MacroKind::Derive, _))
2142 && {
{
'done:
{
for i in
::rustc_attr_ir::HasAttrs::get_attrs(outer.macro_def_id.unwrap(),
&self) {
#[allow(unused_imports)]
use ::rustc_attr_ir::AttributeKind::*;
let i: &::rustc_attr_ir::Attribute = i;
match i {
::rustc_attr_ir::Attribute::Parsed(RustcBuiltinMacro { .. })
=> {
break 'done Some(());
}
::rustc_attr_ir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}
}.is_some()find_attr!(self, outer.macro_def_id.unwrap(), RustcBuiltinMacro { .. })
2143 {
2144 true
2145 } else {
2146 false
2147 }
2148 }
2149
2150 pub fn is_automatically_derived(self, def_id: DefId) -> bool {
2152 {
{
'done:
{
for i in ::rustc_attr_ir::HasAttrs::get_attrs(def_id, &self) {
#[allow(unused_imports)]
use ::rustc_attr_ir::AttributeKind::*;
let i: &::rustc_attr_ir::Attribute = i;
match i {
::rustc_attr_ir::Attribute::Parsed(AutomaticallyDerived) =>
{
break 'done Some(());
}
::rustc_attr_ir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}
}.is_some()find_attr!(self, def_id, AutomaticallyDerived)
2153 }
2154
2155 pub fn span_of_impl(self, impl_def_id: DefId) -> Result<Span, Symbol> {
2158 if let Some(impl_def_id) = impl_def_id.as_local() {
2159 Ok(self.def_span(impl_def_id))
2160 } else {
2161 Err(self.crate_name(impl_def_id.krate))
2162 }
2163 }
2164
2165 pub fn hygienic_eq(self, use_ident: Ident, def_ident: Ident, def_parent_def_id: DefId) -> bool {
2169 use_ident.name == def_ident.name
2173 && use_ident
2174 .span
2175 .ctxt()
2176 .hygienic_eq(def_ident.span.ctxt(), self.expn_that_defined(def_parent_def_id))
2177 }
2178
2179 pub fn adjust_ident(self, mut ident: Ident, scope: DefId) -> Ident {
2180 ident.span.normalize_to_macros_2_0_and_adjust(self.expn_that_defined(scope));
2181 ident
2182 }
2183
2184 pub fn adjust_ident_and_get_scope(
2185 self,
2186 mut ident: Ident,
2187 scope: DefId,
2188 item_id: LocalDefId,
2189 ) -> (Ident, ModId) {
2190 let scope = ident
2191 .span
2192 .normalize_to_macros_2_0_and_adjust(self.expn_that_defined(scope))
2193 .and_then(|actual_expansion| actual_expansion.expn_data().parent_module)
2194 .unwrap_or_else(|| self.parent_module_from_def_id(item_id).to_mod_id());
2195 (ident, scope)
2196 }
2197
2198 #[inline]
2202 pub fn is_const_fn(self, def_id: impl IntoQueryKey<DefId>) -> bool {
2203 let def_id = def_id.into_query_key();
2204 #[allow(non_exhaustive_omitted_patterns)] match self.def_kind(def_id) {
DefKind::Fn | DefKind::AssocFn | DefKind::Ctor(_, CtorKind::Fn) |
DefKind::Closure => true,
_ => false,
}matches!(
2205 self.def_kind(def_id),
2206 DefKind::Fn | DefKind::AssocFn | DefKind::Ctor(_, CtorKind::Fn) | DefKind::Closure
2207 ) && #[allow(non_exhaustive_omitted_patterns)] match self.constness(def_id) {
hir::Constness::Const { .. } => true,
_ => false,
}matches!(self.constness(def_id), hir::Constness::Const { .. })
2208 }
2209
2210 pub fn is_conditionally_const(self, def_id: impl Into<DefId>) -> bool {
2217 let def_id: DefId = def_id.into();
2218 match self.def_kind(def_id) {
2219 DefKind::Impl { of_trait: true } => {
2220 let header = self.impl_trait_header(def_id);
2221 #[allow(non_exhaustive_omitted_patterns)] match header.constness {
hir::Constness::Const { always: false } => true,
_ => false,
}matches!(header.constness, hir::Constness::Const { always: false })
2222 && self.is_const_trait(header.trait_ref.skip_binder().def_id)
2223 }
2224 DefKind::Impl { of_trait: false } => {
2225 #[allow(non_exhaustive_omitted_patterns)] match self.constness(def_id) {
hir::Constness::Const { always: false } => true,
_ => false,
}matches!(self.constness(def_id), hir::Constness::Const { always: false })
2226 }
2227 DefKind::Fn | DefKind::Ctor(_, CtorKind::Fn) => {
2228 #[allow(non_exhaustive_omitted_patterns)] match self.constness(def_id) {
hir::Constness::Const { always: false } => true,
_ => false,
}matches!(self.constness(def_id), hir::Constness::Const { always: false })
2229 }
2230 DefKind::TraitAlias | DefKind::Trait => self.is_const_trait(def_id),
2231 DefKind::AssocTy => {
2232 let parent_def_id = self.parent(def_id);
2233 match self.def_kind(parent_def_id) {
2234 DefKind::Impl { of_trait: false } => false,
2235 DefKind::Impl { of_trait: true } | DefKind::Trait => {
2236 self.is_conditionally_const(parent_def_id)
2237 }
2238 _ => crate::util::bug::bug_fmt(format_args!("unexpected parent item of associated type: {0:?}",
parent_def_id))bug!("unexpected parent item of associated type: {parent_def_id:?}"),
2239 }
2240 }
2241 DefKind::AssocFn => {
2242 let parent_def_id = self.parent(def_id);
2243 match self.def_kind(parent_def_id) {
2244 DefKind::Impl { of_trait: false } => {
2245 #[allow(non_exhaustive_omitted_patterns)] match self.constness(def_id) {
hir::Constness::Const { always: false } => true,
_ => false,
}matches!(self.constness(def_id), hir::Constness::Const { always: false })
2246 }
2247 DefKind::Impl { of_trait: true } => {
2248 let Some(trait_method_did) = self.trait_item_of(def_id) else {
2249 return false;
2250 };
2251 #[allow(non_exhaustive_omitted_patterns)] match self.constness(trait_method_did)
{
hir::Constness::Const { always: false } => true,
_ => false,
}matches!(
2252 self.constness(trait_method_did),
2253 hir::Constness::Const { always: false }
2254 ) && self.is_conditionally_const(parent_def_id)
2255 }
2256 DefKind::Trait => {
2257 #[allow(non_exhaustive_omitted_patterns)] match self.constness(def_id) {
hir::Constness::Const { always: false } => true,
_ => false,
}matches!(self.constness(def_id), hir::Constness::Const { always: false })
2258 && self.is_conditionally_const(parent_def_id)
2259 }
2260 _ => crate::util::bug::bug_fmt(format_args!("unexpected parent item of associated fn: {0:?}",
parent_def_id))bug!("unexpected parent item of associated fn: {parent_def_id:?}"),
2261 }
2262 }
2263 DefKind::OpaqueTy => match self.opaque_ty_origin(def_id) {
2264 hir::OpaqueTyOrigin::FnReturn { parent, .. } => self.is_conditionally_const(parent),
2265 hir::OpaqueTyOrigin::AsyncFn { .. } => false,
2266 hir::OpaqueTyOrigin::TyAlias { .. } => false,
2268 },
2269 DefKind::Closure => {
2270 #[allow(non_exhaustive_omitted_patterns)] match self.constness(def_id) {
hir::Constness::Const { always: false } => true,
_ => false,
}matches!(self.constness(def_id), hir::Constness::Const { always: false })
2271 }
2272 DefKind::Ctor(_, CtorKind::Const)
2273 | DefKind::Mod
2274 | DefKind::Struct
2275 | DefKind::Union
2276 | DefKind::Enum
2277 | DefKind::Variant
2278 | DefKind::TyAlias
2279 | DefKind::ForeignTy
2280 | DefKind::TyParam
2281 | DefKind::Const { .. }
2282 | DefKind::ConstParam
2283 | DefKind::Static { .. }
2284 | DefKind::AssocConst { .. }
2285 | DefKind::Macro(_)
2286 | DefKind::ExternCrate
2287 | DefKind::Use
2288 | DefKind::ForeignMod
2289 | DefKind::AnonConst
2290 | DefKind::Field
2291 | DefKind::LifetimeParam
2292 | DefKind::GlobalAsm
2293 | DefKind::SyntheticCoroutineBody
2294 | DefKind::TestBinderConstraints => false,
2295 }
2296 }
2297
2298 #[inline]
2299 pub fn is_const_trait(self, def_id: DefId) -> bool {
2300 #[allow(non_exhaustive_omitted_patterns)] match self.trait_def(def_id).constness
{
hir::Constness::Const { .. } => true,
_ => false,
}matches!(self.trait_def(def_id).constness, hir::Constness::Const { .. })
2301 }
2302
2303 pub fn impl_method_has_trait_impl_trait_tys(self, def_id: DefId) -> bool {
2304 if self.def_kind(def_id) != DefKind::AssocFn {
2305 return false;
2306 }
2307
2308 let Some(item) = self.opt_associated_item(def_id) else {
2309 return false;
2310 };
2311
2312 let AssocContainer::TraitImpl(Ok(trait_item_def_id)) = item.container else {
2313 return false;
2314 };
2315
2316 !self.associated_types_for_impl_traits_in_associated_fn(trait_item_def_id).is_empty()
2317 }
2318
2319 #[inline]
2334 pub fn fn_abi_of_instance(
2335 self,
2336 query: ty::PseudoCanonicalInput<'tcx, (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>)>,
2337 ) -> Result<&'tcx FnAbi<'tcx, Ty<'tcx>>, &'tcx FnAbiError<'tcx>> {
2338 if self.sess.opts.optimize != OptLevel::No && self.sess.opts.incremental.is_none() {
2341 self.fn_abi_of_instance_raw(query)
2342 } else {
2343 self.fn_abi_of_instance_no_deduced_attrs(query)
2344 }
2345 }
2346}
2347
2348impl<'tcx> rustc_attr_ir::HasAttrs<'tcx, TyCtxt<'tcx>> for DefId {
2351 fn get_attrs(self, tcx: &TyCtxt<'tcx>) -> &'tcx [rustc_attr_ir::Attribute] {
2352 if let Some(did) = self.as_local() {
2353 tcx.hir_attrs(tcx.local_def_id_to_hir_id(did))
2354 } else {
2355 tcx.attrs_for_def(self)
2356 }
2357 }
2358}
2359
2360impl<'tcx> rustc_attr_ir::HasAttrs<'tcx, TyCtxt<'tcx>> for LocalDefId {
2361 fn get_attrs(self, tcx: &TyCtxt<'tcx>) -> &'tcx [rustc_attr_ir::Attribute] {
2362 tcx.hir_attrs(tcx.local_def_id_to_hir_id(self))
2363 }
2364}
2365
2366impl<'tcx> rustc_attr_ir::HasAttrs<'tcx, TyCtxt<'tcx>> for hir::OwnerId {
2367 fn get_attrs(self, tcx: &TyCtxt<'tcx>) -> &'tcx [rustc_attr_ir::Attribute] {
2368 rustc_attr_ir::HasAttrs::get_attrs(self.def_id, tcx)
2369 }
2370}
2371
2372impl<'tcx> rustc_attr_ir::HasAttrs<'tcx, TyCtxt<'tcx>> for hir::HirId {
2373 fn get_attrs(self, tcx: &TyCtxt<'tcx>) -> &'tcx [rustc_attr_ir::Attribute] {
2374 tcx.hir_attrs(self)
2375 }
2376}
2377
2378pub fn provide(providers: &mut Providers) {
2379 closure::provide(providers);
2380 context::provide(providers);
2381 erase_regions::provide(providers);
2382 inhabitedness::provide(providers);
2383 util::provide(providers);
2384 print::provide(providers);
2385 super::util::bug::provide(providers);
2386 *providers = Providers {
2387 trait_impls_of: trait_def::trait_impls_of_provider,
2388 incoherent_impls: trait_def::incoherent_impls_provider,
2389 trait_impls_in_crate: trait_def::trait_impls_in_crate_provider,
2390 traits: trait_def::traits_provider,
2391 vtable_allocation: vtable::vtable_allocation_provider,
2392 ..*providers
2393 };
2394}
2395
2396#[derive(#[automatically_derived]
impl ::core::clone::Clone for CrateInherentImpls {
#[inline]
fn clone(&self) -> CrateInherentImpls {
CrateInherentImpls {
inherent_impls: ::core::clone::Clone::clone(&self.inherent_impls),
incoherent_impls: ::core::clone::Clone::clone(&self.incoherent_impls),
}
}
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for CrateInherentImpls {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f,
"CrateInherentImpls", "inherent_impls", &self.inherent_impls,
"incoherent_impls", &&self.incoherent_impls)
}
}Debug, #[automatically_derived]
impl ::core::default::Default for CrateInherentImpls {
#[inline]
fn default() -> CrateInherentImpls {
CrateInherentImpls {
inherent_impls: ::core::default::Default::default(),
incoherent_impls: ::core::default::Default::default(),
}
}
}Default, const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for
CrateInherentImpls {
#[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 {
CrateInherentImpls {
inherent_impls: ref __binding_0,
incoherent_impls: ref __binding_1 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash)]
2402pub struct CrateInherentImpls {
2403 pub inherent_impls: FxIndexMap<LocalDefId, Vec<DefId>>,
2404 pub incoherent_impls: FxIndexMap<SimplifiedType, Vec<LocalDefId>>,
2405}
2406
2407#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl<'tcx> ::core::clone::TrivialClone for SymbolName<'tcx> { }
#[automatically_derived]
impl<'tcx> ::core::clone::Clone for SymbolName<'tcx> {
#[inline]
fn clone(&self) -> SymbolName<'tcx> {
let _: ::core::clone::AssertParamIsClone<&'tcx str>;
*self
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::marker::Copy for SymbolName<'tcx> { }Copy, #[automatically_derived]
impl<'tcx> ::core::marker::StructuralPartialEq for SymbolName<'tcx> { }
#[automatically_derived]
impl<'tcx> ::core::cmp::PartialEq for SymbolName<'tcx> {
#[inline]
fn eq(&self, other: &SymbolName<'tcx>) -> bool { self.name == other.name }
}PartialEq, #[automatically_derived]
impl<'tcx> ::core::cmp::Eq for SymbolName<'tcx> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<&'tcx str>;
}
}Eq, #[automatically_derived]
impl<'tcx> ::core::cmp::PartialOrd for SymbolName<'tcx> {
#[inline]
fn partial_cmp(&self, other: &SymbolName<'tcx>)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::option::Option::Some(::core::cmp::Ord::cmp(self, other))
}
}PartialOrd, #[automatically_derived]
impl<'tcx> ::core::cmp::Ord for SymbolName<'tcx> {
#[inline]
fn cmp(&self, other: &SymbolName<'tcx>) -> ::core::cmp::Ordering {
::core::cmp::Ord::cmp(&self.name, &other.name)
}
}Ord, #[automatically_derived]
impl<'tcx> ::core::hash::Hash for SymbolName<'tcx> {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.name, state)
}
}Hash, const _: () =
{
impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
::rustc_serialize::Encodable<__E> for SymbolName<'tcx> {
fn encode(&self, __encoder: &mut __E) {
let SymbolName { name: __binding_0 } = *self;
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
}
};TyEncodable, const _: () =
{
impl<'tcx> ::rustc_data_structures::stable_hash::StableHash for
SymbolName<'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 {
SymbolName { name: ref __binding_0 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash)]
2408pub struct SymbolName<'tcx> {
2409 pub name: &'tcx str,
2411}
2412
2413impl<'tcx> SymbolName<'tcx> {
2414 pub fn new(tcx: TyCtxt<'tcx>, name: &str) -> SymbolName<'tcx> {
2415 SymbolName { name: tcx.arena.alloc_str(name) }
2416 }
2417}
2418
2419impl<'tcx> fmt::Display for SymbolName<'tcx> {
2420 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
2421 fmt::Display::fmt(&self.name, fmt)
2422 }
2423}
2424
2425impl<'tcx> fmt::Debug for SymbolName<'tcx> {
2426 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
2427 fmt::Display::fmt(&self.name, fmt)
2428 }
2429}
2430
2431#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for DestructuredAdtConst<'tcx> { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl<'tcx> ::core::clone::TrivialClone for DestructuredAdtConst<'tcx> {
}
#[automatically_derived]
impl<'tcx> ::core::clone::Clone for DestructuredAdtConst<'tcx> {
#[inline]
fn clone(&self) -> DestructuredAdtConst<'tcx> {
let _: ::core::clone::AssertParamIsClone<VariantIdx>;
let _: ::core::clone::AssertParamIsClone<&'tcx [ty::Const<'tcx>]>;
*self
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for DestructuredAdtConst<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f,
"DestructuredAdtConst", "variant", &self.variant, "fields",
&&self.fields)
}
}Debug, const _: () =
{
impl<'tcx> ::rustc_data_structures::stable_hash::StableHash for
DestructuredAdtConst<'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 {
DestructuredAdtConst {
variant: ref __binding_0, fields: ref __binding_1 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash)]
2433pub struct DestructuredAdtConst<'tcx> {
2434 pub variant: VariantIdx,
2435 pub fields: &'tcx [ty::Const<'tcx>],
2436}