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::ptr::NonNull;
20use std::{assert_matches, fmt, iter, str};
21
22pub use adt::*;
23pub use assoc::*;
24pub use generic_args::{GenericArgKind, TermKind, *};
25pub use generics::*;
26pub use intrinsic::IntrinsicDef;
27use rustc_abi::{
28 Align, FieldIdx, Integer, IntegerType, ReprFlags, ReprOptions, ScalableElt, VariantIdx,
29};
30use rustc_ast as ast;
31use rustc_ast::expand::typetree::{FncTree, Kind, Type, TypeTree};
32use rustc_ast::node_id::NodeMap;
33pub use rustc_ast_ir::{Movability, Mutability, try_visit};
34use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
35use rustc_data_structures::intern::Interned;
36use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
37use rustc_data_structures::steal::Steal;
38use rustc_data_structures::unord::{UnordMap, UnordSet};
39use rustc_errors::{Diag, ErrorGuaranteed, LintBuffer};
40use rustc_hir as hir;
41use rustc_hir::attrs::StrippedCfgItem;
42use rustc_hir::def::{CtorKind, CtorOf, DefKind, DocLinkResMap, LifetimeRes, Res};
43use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LocalDefIdMap};
44use rustc_hir::definitions::PerParentDisambiguatorState;
45use rustc_hir::{LangItem, attrs as attr, find_attr};
46use rustc_index::IndexVec;
47use rustc_index::bit_set::BitMatrix;
48use rustc_macros::{
49 BlobDecodable, Decodable, Encodable, HashStable, TyDecodable, TyEncodable, TypeFoldable,
50 TypeVisitable, extension,
51};
52use rustc_serialize::{Decodable, Encodable};
53use rustc_session::config::OptLevel;
54pub use rustc_session::lint::RegisteredTools;
55use rustc_span::hygiene::MacroKind;
56use rustc_span::{DUMMY_SP, ExpnId, ExpnKind, Ident, Span, Symbol};
57use rustc_target::callconv::FnAbi;
58pub use rustc_type_ir::data_structures::{DelayedMap, DelayedSet};
59pub use rustc_type_ir::fast_reject::DeepRejectCtxt;
60#[allow(
61 hidden_glob_reexports,
62 rustc::usage_of_type_ir_inherent,
63 rustc::non_glob_import_of_type_ir_inherent
64)]
65use rustc_type_ir::inherent;
66pub use rustc_type_ir::relate::VarianceDiagInfo;
67pub use rustc_type_ir::solve::{CandidatePreferenceMode, SizedTraitKind};
68pub use rustc_type_ir::*;
69#[allow(hidden_glob_reexports, unused_imports)]
70use rustc_type_ir::{InferCtxtLike, Interner};
71use tracing::{debug, instrument, trace};
72pub use vtable::*;
73
74pub use self::closure::{
75 BorrowKind, CAPTURE_STRUCT_LOCAL, CaptureInfo, CapturedPlace, ClosureTypeInfo,
76 MinCaptureInformationMap, MinCaptureList, RootVariableMinCaptureList, UpvarCapture, UpvarId,
77 UpvarPath, analyze_coroutine_closure_captures, is_ancestor_or_same_capture,
78 place_to_string_for_capture,
79};
80pub use self::consts::{
81 AtomicOrdering, Const, ConstInt, ConstKind, ConstToValTreeResult, Expr, ExprKind,
82 LitToConstInput, ScalarInt, SimdAlign, UnevaluatedConst, ValTree, ValTreeKindExt, Value,
83 const_lit_matches_ty,
84};
85pub use self::context::{
86 CtxtInterners, CurrentGcx, Feed, FreeRegionInfo, GlobalCtxt, Lift, TyCtxt, TyCtxtFeed, tls,
87};
88pub use self::fold::*;
89pub use self::instance::{Instance, InstanceKind, ReifyReason};
90pub(crate) use self::list::RawList;
91pub use self::list::{List, ListWithCachedTypeInfo};
92pub use self::opaque_types::OpaqueTypeKey;
93pub use self::pattern::{Pattern, PatternKind};
94pub use self::predicate::{
95 AliasTerm, AliasTermKind, ArgOutlivesPredicate, Clause, ClauseKind, CoercePredicate,
96 ExistentialPredicate, ExistentialPredicateStableCmpExt, ExistentialProjection,
97 ExistentialTraitRef, HostEffectPredicate, NormalizesTo, OutlivesPredicate, PolyCoercePredicate,
98 PolyExistentialPredicate, PolyExistentialProjection, PolyExistentialTraitRef,
99 PolyProjectionPredicate, PolyRegionOutlivesPredicate, PolySubtypePredicate, PolyTraitPredicate,
100 PolyTraitRef, PolyTypeOutlivesPredicate, Predicate, PredicateKind, ProjectionPredicate,
101 RegionConstraint, RegionEqPredicate, RegionOutlivesPredicate, SubtypePredicate, TraitPredicate,
102 TraitRef, TypeOutlivesPredicate,
103};
104pub use self::region::{
105 EarlyParamRegion, LateParamRegion, LateParamRegionKind, Region, RegionKind, RegionVid,
106};
107pub use self::sty::{
108 AliasTy, AliasTyKind, Article, Binder, BoundConst, BoundRegion, BoundRegionKind, BoundTy,
109 BoundTyKind, BoundVariableKind, CanonicalPolyFnSig, CoroutineArgsExt, EarlyBinder, FnSig,
110 FnSigKind, InlineConstArgs, InlineConstArgsParts, ParamConst, ParamTy, PlaceholderConst,
111 PlaceholderRegion, PlaceholderType, PolyFnSig, TyKind, TypeAndMut, TypingMode,
112 TypingModeEqWrapper, Unnormalized, UpvarArgs,
113};
114pub use self::trait_def::TraitDef;
115pub use self::typeck_results::{
116 CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, IsIdentity,
117 Rust2024IncompatiblePatInfo, TypeckResults, UserType, UserTypeAnnotationIndex, UserTypeKind,
118};
119use crate::error::{OpaqueHiddenTypeMismatch, TypeMismatchReason};
120use crate::ich::StableHashingContext;
121use crate::metadata::{AmbigModChild, ModChild};
122use crate::middle::privacy::EffectiveVisibilities;
123use crate::mir::{Body, CoroutineLayout, CoroutineSavedLocal, SourceInfo};
124use crate::query::{IntoQueryKey, Providers};
125use crate::ty;
126use crate::ty::codec::{TyDecoder, TyEncoder};
127pub use crate::ty::diagnostics::*;
128use crate::ty::fast_reject::SimplifiedType;
129use crate::ty::layout::{FnAbiError, LayoutError};
130use crate::ty::util::Discr;
131use crate::ty::walk::TypeWalker;
132
133pub mod abstract_const;
134pub mod adjustment;
135pub mod cast;
136pub mod codec;
137pub mod error;
138pub mod fast_reject;
139pub mod inhabitedness;
140pub mod layout;
141pub mod normalize_erasing_regions;
142pub mod offload_meta;
143pub mod pattern;
144pub mod print;
145pub mod relate;
146pub mod significant_drop_order;
147pub mod trait_def;
148pub mod util;
149pub mod vtable;
150
151mod adt;
152mod assoc;
153mod closure;
154mod consts;
155mod context;
156mod diagnostics;
157mod elaborate_impl;
158mod erase_regions;
159mod fold;
160mod generic_args;
161mod generics;
162mod impls_ty;
163mod instance;
164mod intrinsic;
165mod list;
166mod opaque_types;
167mod predicate;
168mod region;
169mod structural_impls;
170#[allow(hidden_glob_reexports)]
171mod sty;
172mod typeck_results;
173mod visit;
174
175#[derive(#[automatically_derived]
impl ::core::fmt::Debug for ResolverGlobalCtxt {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
let names: &'static _ =
&["visibilities_for_hashing", "expn_that_defined",
"effective_visibilities", "extern_crate_map",
"maybe_unused_trait_imports", "module_children",
"ambig_module_children", "glob_map", "main_def",
"trait_impls", "proc_macros",
"confused_type_with_std_module", "doc_link_resolutions",
"doc_link_traits_in_scope", "all_macro_rules",
"stripped_cfg_items"];
let values: &[&dyn ::core::fmt::Debug] =
&[&self.visibilities_for_hashing, &self.expn_that_defined,
&self.effective_visibilities, &self.extern_crate_map,
&self.maybe_unused_trait_imports, &self.module_children,
&self.ambig_module_children, &self.glob_map, &self.main_def,
&self.trait_impls, &self.proc_macros,
&self.confused_type_with_std_module,
&self.doc_link_resolutions, &self.doc_link_traits_in_scope,
&self.all_macro_rules, &&self.stripped_cfg_items];
::core::fmt::Formatter::debug_struct_fields_finish(f,
"ResolverGlobalCtxt", names, values)
}
}Debug, const _: () =
{
impl<'__ctx>
::rustc_data_structures::stable_hasher::HashStable<::rustc_middle::ich::StableHashingContext<'__ctx>>
for ResolverGlobalCtxt {
#[inline]
fn hash_stable(&self,
__hcx: &mut ::rustc_middle::ich::StableHashingContext<'__ctx>,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
match *self {
ResolverGlobalCtxt {
visibilities_for_hashing: ref __binding_0,
expn_that_defined: ref __binding_1,
effective_visibilities: ref __binding_2,
extern_crate_map: ref __binding_3,
maybe_unused_trait_imports: ref __binding_4,
module_children: ref __binding_5,
ambig_module_children: ref __binding_6,
glob_map: ref __binding_7,
main_def: ref __binding_8,
trait_impls: ref __binding_9,
proc_macros: ref __binding_10,
confused_type_with_std_module: ref __binding_11,
doc_link_resolutions: ref __binding_12,
doc_link_traits_in_scope: ref __binding_13,
all_macro_rules: ref __binding_14,
stripped_cfg_items: ref __binding_15 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
{ __binding_2.hash_stable(__hcx, __hasher); }
{ __binding_3.hash_stable(__hcx, __hasher); }
{ __binding_4.hash_stable(__hcx, __hasher); }
{ __binding_5.hash_stable(__hcx, __hasher); }
{ __binding_6.hash_stable(__hcx, __hasher); }
{ __binding_7.hash_stable(__hcx, __hasher); }
{ __binding_8.hash_stable(__hcx, __hasher); }
{ __binding_9.hash_stable(__hcx, __hasher); }
{ __binding_10.hash_stable(__hcx, __hasher); }
{ __binding_11.hash_stable(__hcx, __hasher); }
{ __binding_12.hash_stable(__hcx, __hasher); }
{ __binding_13.hash_stable(__hcx, __hasher); }
{ __binding_14.hash_stable(__hcx, __hasher); }
{ __binding_15.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable)]
178pub struct ResolverGlobalCtxt {
179 pub visibilities_for_hashing: Vec<(LocalDefId, Visibility)>,
180 pub expn_that_defined: UnordMap<LocalDefId, ExpnId>,
182 pub effective_visibilities: EffectiveVisibilities,
183 pub extern_crate_map: UnordMap<LocalDefId, CrateNum>,
184 pub maybe_unused_trait_imports: FxIndexSet<LocalDefId>,
185 pub module_children: LocalDefIdMap<Vec<ModChild>>,
186 pub ambig_module_children: LocalDefIdMap<Vec<AmbigModChild>>,
187 pub glob_map: FxIndexMap<LocalDefId, FxIndexSet<Symbol>>,
188 pub main_def: Option<MainDefinition>,
189 pub trait_impls: FxIndexMap<DefId, Vec<LocalDefId>>,
190 pub proc_macros: Vec<LocalDefId>,
193 pub confused_type_with_std_module: FxIndexMap<Span, Span>,
196 pub doc_link_resolutions: FxIndexMap<LocalDefId, DocLinkResMap>,
197 pub doc_link_traits_in_scope: FxIndexMap<LocalDefId, Vec<DefId>>,
198 pub all_macro_rules: UnordSet<Symbol>,
199 pub stripped_cfg_items: Vec<StrippedCfgItem>,
200}
201
202#[derive(#[automatically_derived]
impl<'tcx> ::core::fmt::Debug for ResolverAstLowering<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
let names: &'static _ =
&["partial_res_map", "import_res_map", "label_res_map",
"lifetimes_res_map", "extra_lifetime_params_map",
"next_node_id", "node_id_to_def_id", "trait_map",
"lifetime_elision_allowed", "lint_buffer",
"delegation_infos", "disambiguators"];
let values: &[&dyn ::core::fmt::Debug] =
&[&self.partial_res_map, &self.import_res_map,
&self.label_res_map, &self.lifetimes_res_map,
&self.extra_lifetime_params_map, &self.next_node_id,
&self.node_id_to_def_id, &self.trait_map,
&self.lifetime_elision_allowed, &self.lint_buffer,
&self.delegation_infos, &&self.disambiguators];
::core::fmt::Formatter::debug_struct_fields_finish(f,
"ResolverAstLowering", names, values)
}
}Debug)]
205pub struct ResolverAstLowering<'tcx> {
206 pub partial_res_map: NodeMap<hir::def::PartialRes>,
208 pub import_res_map: NodeMap<hir::def::PerNS<Option<Res<ast::NodeId>>>>,
210 pub label_res_map: NodeMap<ast::NodeId>,
212 pub lifetimes_res_map: NodeMap<LifetimeRes>,
214 pub extra_lifetime_params_map: NodeMap<Vec<(Ident, ast::NodeId, LifetimeRes)>>,
216
217 pub next_node_id: ast::NodeId,
218
219 pub node_id_to_def_id: NodeMap<LocalDefId>,
220
221 pub trait_map: NodeMap<&'tcx [hir::TraitCandidate<'tcx>]>,
222 pub lifetime_elision_allowed: FxHashSet<ast::NodeId>,
224
225 pub lint_buffer: Steal<LintBuffer>,
227
228 pub delegation_infos: LocalDefIdMap<DelegationInfo>,
230
231 pub disambiguators: LocalDefIdMap<Steal<PerParentDisambiguatorState>>,
232}
233
234#[derive(#[automatically_derived]
impl ::core::fmt::Debug for DelegationInfo {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field1_finish(f,
"DelegationInfo", "resolution_node", &&self.resolution_node)
}
}Debug)]
235pub struct DelegationInfo {
236 pub resolution_node: ast::NodeId,
239}
240
241#[derive(#[automatically_derived]
impl ::core::clone::Clone for MainDefinition {
#[inline]
fn clone(&self) -> MainDefinition {
let _: ::core::clone::AssertParamIsClone<Res<ast::NodeId>>;
let _: ::core::clone::AssertParamIsClone<bool>;
let _: ::core::clone::AssertParamIsClone<Span>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for MainDefinition { }Copy, #[automatically_derived]
impl ::core::fmt::Debug for MainDefinition {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field3_finish(f,
"MainDefinition", "res", &self.res, "is_import", &self.is_import,
"span", &&self.span)
}
}Debug, const _: () =
{
impl<'__ctx>
::rustc_data_structures::stable_hasher::HashStable<::rustc_middle::ich::StableHashingContext<'__ctx>>
for MainDefinition {
#[inline]
fn hash_stable(&self,
__hcx: &mut ::rustc_middle::ich::StableHashingContext<'__ctx>,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
match *self {
MainDefinition {
res: ref __binding_0,
is_import: ref __binding_1,
span: ref __binding_2 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
{ __binding_2.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable)]
242pub struct MainDefinition {
243 pub res: Res<ast::NodeId>,
244 pub is_import: bool,
245 pub span: Span,
246}
247
248impl MainDefinition {
249 pub fn opt_fn_def_id(self) -> Option<DefId> {
250 if let Res::Def(DefKind::Fn, def_id) = self.res { Some(def_id) } else { None }
251 }
252}
253
254#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for ImplTraitHeader<'tcx> { }Copy, #[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) {
match *self {
ImplTraitHeader {
trait_ref: ref __binding_0,
polarity: ref __binding_1,
safety: ref __binding_2,
constness: ref __binding_3 } => {
::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, '__ctx>
::rustc_data_structures::stable_hasher::HashStable<::rustc_middle::ich::StableHashingContext<'__ctx>>
for ImplTraitHeader<'tcx> {
#[inline]
fn hash_stable(&self,
__hcx: &mut ::rustc_middle::ich::StableHashingContext<'__ctx>,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
match *self {
ImplTraitHeader {
trait_ref: ref __binding_0,
polarity: ref __binding_1,
safety: ref __binding_2,
constness: ref __binding_3 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
{ __binding_2.hash_stable(__hcx, __hasher); }
{ __binding_3.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable)]
255pub struct ImplTraitHeader<'tcx> {
256 pub trait_ref: ty::EarlyBinder<'tcx, ty::TraitRef<'tcx>>,
257 pub polarity: ImplPolarity,
258 pub safety: hir::Safety,
259 pub constness: hir::Constness,
260}
261
262#[derive(#[automatically_derived]
impl ::core::marker::Copy for Asyncness { }Copy, #[automatically_derived]
impl ::core::clone::Clone for Asyncness {
#[inline]
fn clone(&self) -> Asyncness { *self }
}Clone, #[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);
match *self { Asyncness::Yes => {} Asyncness::No => {} }
}
}
};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<'__ctx>
::rustc_data_structures::stable_hasher::HashStable<::rustc_middle::ich::StableHashingContext<'__ctx>>
for Asyncness {
#[inline]
fn hash_stable(&self,
__hcx: &mut ::rustc_middle::ich::StableHashingContext<'__ctx>,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
match *self { Asyncness::Yes => {} Asyncness::No => {} }
}
}
};HashStable, #[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)]
263#[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)]
264pub enum Asyncness {
265 Yes,
266 #[default]
267 No,
268}
269
270impl Asyncness {
271 pub fn is_async(self) -> bool {
272 #[allow(non_exhaustive_omitted_patterns)] match self {
Asyncness::Yes => true,
_ => false,
}matches!(self, Asyncness::Yes)
273 }
274}
275
276#[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::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<'__ctx, Id>
::rustc_data_structures::stable_hasher::HashStable<::rustc_middle::ich::StableHashingContext<'__ctx>>
for Visibility<Id> where
Id: ::rustc_data_structures::stable_hasher::HashStable<::rustc_middle::ich::StableHashingContext<'__ctx>>
{
#[inline]
fn hash_stable(&self,
__hcx: &mut ::rustc_middle::ich::StableHashingContext<'__ctx>,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
match *self {
Visibility::Public => {}
Visibility::Restricted(ref __binding_0) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable)]
277pub enum Visibility<Id = LocalDefId> {
278 Public,
280 Restricted(Id),
282}
283
284impl Visibility {
285 pub fn to_string(self, def_id: LocalDefId, tcx: TyCtxt<'_>) -> String {
286 match self {
287 ty::Visibility::Restricted(restricted_id) => {
288 if restricted_id.is_top_level_module() {
289 "pub(crate)".to_string()
290 } else if restricted_id == tcx.parent_module_from_def_id(def_id).to_local_def_id() {
291 "pub(self)".to_string()
292 } else {
293 ::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!(
294 "pub(in crate{})",
295 tcx.def_path(restricted_id.to_def_id()).to_string_no_crate_verbose()
296 )
297 }
298 }
299 ty::Visibility::Public => "pub".to_string(),
300 }
301 }
302}
303
304#[derive(#[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::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) {
match *self {
ClosureSizeProfileData {
before_feature_tys: ref __binding_0,
after_feature_tys: ref __binding_1 } => {
::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, '__ctx>
::rustc_data_structures::stable_hasher::HashStable<::rustc_middle::ich::StableHashingContext<'__ctx>>
for ClosureSizeProfileData<'tcx> {
#[inline]
fn hash_stable(&self,
__hcx: &mut ::rustc_middle::ich::StableHashingContext<'__ctx>,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
match *self {
ClosureSizeProfileData {
before_feature_tys: ref __binding_0,
after_feature_tys: ref __binding_1 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable)]
305#[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)]
306pub struct ClosureSizeProfileData<'tcx> {
307 pub before_feature_tys: Ty<'tcx>,
309 pub after_feature_tys: Ty<'tcx>,
311}
312
313impl TyCtxt<'_> {
314 #[inline]
315 pub fn opt_parent(self, id: DefId) -> Option<DefId> {
316 self.def_key(id).parent.map(|index| DefId { index, ..id })
317 }
318
319 #[inline]
320 #[track_caller]
321 pub fn parent(self, id: DefId) -> DefId {
322 match self.opt_parent(id) {
323 Some(id) => id,
324 None => crate::util::bug::bug_fmt(format_args!("{0:?} doesn\'t have a parent", id))bug!("{id:?} doesn't have a parent"),
326 }
327 }
328
329 #[inline]
330 #[track_caller]
331 pub fn opt_local_parent(self, id: LocalDefId) -> Option<LocalDefId> {
332 self.opt_parent(id.to_def_id()).map(DefId::expect_local)
333 }
334
335 #[inline]
336 #[track_caller]
337 pub fn local_parent(self, id: impl Into<LocalDefId>) -> LocalDefId {
338 self.parent(id.into().to_def_id()).expect_local()
339 }
340
341 pub fn is_descendant_of(self, mut descendant: DefId, ancestor: DefId) -> bool {
342 if descendant.krate != ancestor.krate {
343 return false;
344 }
345
346 while descendant != ancestor {
347 match self.opt_parent(descendant) {
348 Some(parent) => descendant = parent,
349 None => return false,
350 }
351 }
352 true
353 }
354}
355
356impl<Id> Visibility<Id> {
357 pub fn is_public(self) -> bool {
358 #[allow(non_exhaustive_omitted_patterns)] match self {
Visibility::Public => true,
_ => false,
}matches!(self, Visibility::Public)
359 }
360
361 pub fn map_id<OutId>(self, f: impl FnOnce(Id) -> OutId) -> Visibility<OutId> {
362 match self {
363 Visibility::Public => Visibility::Public,
364 Visibility::Restricted(id) => Visibility::Restricted(f(id)),
365 }
366 }
367}
368
369impl<Id: Into<DefId>> Visibility<Id> {
370 pub fn to_def_id(self) -> Visibility<DefId> {
371 self.map_id(Into::into)
372 }
373
374 pub fn is_accessible_from(self, module: impl Into<DefId>, tcx: TyCtxt<'_>) -> bool {
376 match self {
377 Visibility::Public => true,
379 Visibility::Restricted(id) => tcx.is_descendant_of(module.into(), id.into()),
380 }
381 }
382
383 pub fn partial_cmp(
384 self,
385 vis: Visibility<impl Into<DefId>>,
386 tcx: TyCtxt<'_>,
387 ) -> Option<Ordering> {
388 match (self, vis) {
389 (Visibility::Public, Visibility::Public) => Some(Ordering::Equal),
390 (Visibility::Public, Visibility::Restricted(_)) => Some(Ordering::Greater),
391 (Visibility::Restricted(_), Visibility::Public) => Some(Ordering::Less),
392 (Visibility::Restricted(lhs_id), Visibility::Restricted(rhs_id)) => {
393 let (lhs_id, rhs_id) = (lhs_id.into(), rhs_id.into());
394 if lhs_id == rhs_id {
395 Some(Ordering::Equal)
396 } else if tcx.is_descendant_of(rhs_id, lhs_id) {
397 Some(Ordering::Greater)
398 } else if tcx.is_descendant_of(lhs_id, rhs_id) {
399 Some(Ordering::Less)
400 } else {
401 None
402 }
403 }
404 }
405 }
406}
407
408impl<Id: Into<DefId> + Debug + Copy> Visibility<Id> {
409 #[track_caller]
411 pub fn greater_than(
412 self,
413 vis: Visibility<impl Into<DefId> + Debug + Copy>,
414 tcx: TyCtxt<'_>,
415 ) -> bool {
416 match self.partial_cmp(vis, tcx) {
417 Some(ord) => ord.is_gt(),
418 None => {
419 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:?}"));
420 false
421 }
422 }
423 }
424}
425
426impl Visibility<DefId> {
427 pub fn expect_local(self) -> Visibility {
428 self.map_id(|id| id.expect_local())
429 }
430
431 pub fn is_visible_locally(self) -> bool {
433 match self {
434 Visibility::Public => true,
435 Visibility::Restricted(def_id) => def_id.is_local(),
436 }
437 }
438}
439
440#[derive(const _: () =
{
impl<'tcx, '__ctx>
::rustc_data_structures::stable_hasher::HashStable<::rustc_middle::ich::StableHashingContext<'__ctx>>
for CrateVariancesMap<'tcx> {
#[inline]
fn hash_stable(&self,
__hcx: &mut ::rustc_middle::ich::StableHashingContext<'__ctx>,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
match *self {
CrateVariancesMap { variances: ref __binding_0 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable, #[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)]
447pub struct CrateVariancesMap<'tcx> {
448 pub variances: DefIdMap<&'tcx [ty::Variance]>,
452}
453
454#[derive(#[automatically_derived]
impl ::core::marker::Copy for CReaderCacheKey { }Copy, #[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::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)]
457pub struct CReaderCacheKey {
458 pub cnum: Option<CrateNum>,
459 pub pos: usize,
460}
461
462#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for Ty<'tcx> { }Copy, #[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::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, '__ctx>
::rustc_data_structures::stable_hasher::HashStable<::rustc_middle::ich::StableHashingContext<'__ctx>>
for Ty<'tcx> {
#[inline]
fn hash_stable(&self,
__hcx: &mut ::rustc_middle::ich::StableHashingContext<'__ctx>,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
match *self {
Ty(ref __binding_0) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable)]
464#[rustc_diagnostic_item = "Ty"]
465#[rustc_pass_by_value]
466pub struct Ty<'tcx>(Interned<'tcx, WithCachedTypeInfo<TyKind<'tcx>>>);
467
468impl<'tcx> rustc_type_ir::inherent::IntoKind for Ty<'tcx> {
469 type Kind = TyKind<'tcx>;
470
471 fn kind(self) -> TyKind<'tcx> {
472 *self.kind()
473 }
474}
475
476impl<'tcx> rustc_type_ir::Flags for Ty<'tcx> {
477 fn flags(&self) -> TypeFlags {
478 self.0.flags
479 }
480
481 fn outer_exclusive_binder(&self) -> DebruijnIndex {
482 self.0.outer_exclusive_binder
483 }
484}
485
486#[derive(const _: () =
{
impl<'tcx, '__ctx>
::rustc_data_structures::stable_hasher::HashStable<::rustc_middle::ich::StableHashingContext<'__ctx>>
for CratePredicatesMap<'tcx> {
#[inline]
fn hash_stable(&self,
__hcx: &mut ::rustc_middle::ich::StableHashingContext<'__ctx>,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
match *self {
CratePredicatesMap { predicates: ref __binding_0 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for CratePredicatesMap<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field1_finish(f,
"CratePredicatesMap", "predicates", &&self.predicates)
}
}Debug)]
493pub struct CratePredicatesMap<'tcx> {
494 pub predicates: DefIdMap<&'tcx [(Clause<'tcx>, Span)]>,
498}
499
500#[derive(#[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::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> {
match ::core::cmp::PartialOrd::partial_cmp(&self.ptr, &other.ptr) {
::core::option::Option::Some(::core::cmp::Ordering::Equal) =>
::core::cmp::PartialOrd::partial_cmp(&self.marker,
&other.marker),
cmp => cmp,
}
}
}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)]
501pub struct Term<'tcx> {
502 ptr: NonNull<()>,
503 marker: PhantomData<(Ty<'tcx>, Const<'tcx>)>,
504}
505
506impl<'tcx> rustc_type_ir::inherent::Term<TyCtxt<'tcx>> for Term<'tcx> {}
507
508impl<'tcx> rustc_type_ir::inherent::IntoKind for Term<'tcx> {
509 type Kind = TermKind<'tcx>;
510
511 fn kind(self) -> Self::Kind {
512 self.kind()
513 }
514}
515
516unsafe impl<'tcx> rustc_data_structures::sync::DynSend for Term<'tcx> where
517 &'tcx (Ty<'tcx>, Const<'tcx>): rustc_data_structures::sync::DynSend
518{
519}
520unsafe impl<'tcx> rustc_data_structures::sync::DynSync for Term<'tcx> where
521 &'tcx (Ty<'tcx>, Const<'tcx>): rustc_data_structures::sync::DynSync
522{
523}
524unsafe impl<'tcx> Send for Term<'tcx> where &'tcx (Ty<'tcx>, Const<'tcx>): Send {}
525unsafe impl<'tcx> Sync for Term<'tcx> where &'tcx (Ty<'tcx>, Const<'tcx>): Sync {}
526
527impl Debug for Term<'_> {
528 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
529 match self.kind() {
530 TermKind::Ty(ty) => f.write_fmt(format_args!("Term::Ty({0:?})", ty))write!(f, "Term::Ty({ty:?})"),
531 TermKind::Const(ct) => f.write_fmt(format_args!("Term::Const({0:?})", ct))write!(f, "Term::Const({ct:?})"),
532 }
533 }
534}
535
536impl<'tcx> From<Ty<'tcx>> for Term<'tcx> {
537 fn from(ty: Ty<'tcx>) -> Self {
538 TermKind::Ty(ty).pack()
539 }
540}
541
542impl<'tcx> From<Const<'tcx>> for Term<'tcx> {
543 fn from(c: Const<'tcx>) -> Self {
544 TermKind::Const(c).pack()
545 }
546}
547
548impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Term<'tcx> {
549 fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
550 self.kind().hash_stable(hcx, hasher);
551 }
552}
553
554impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for Term<'tcx> {
555 fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>(
556 self,
557 folder: &mut F,
558 ) -> Result<Self, F::Error> {
559 match self.kind() {
560 ty::TermKind::Ty(ty) => ty.try_fold_with(folder).map(Into::into),
561 ty::TermKind::Const(ct) => ct.try_fold_with(folder).map(Into::into),
562 }
563 }
564
565 fn fold_with<F: TypeFolder<TyCtxt<'tcx>>>(self, folder: &mut F) -> Self {
566 match self.kind() {
567 ty::TermKind::Ty(ty) => ty.fold_with(folder).into(),
568 ty::TermKind::Const(ct) => ct.fold_with(folder).into(),
569 }
570 }
571}
572
573impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for Term<'tcx> {
574 fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result {
575 match self.kind() {
576 ty::TermKind::Ty(ty) => ty.visit_with(visitor),
577 ty::TermKind::Const(ct) => ct.visit_with(visitor),
578 }
579 }
580}
581
582impl<'tcx, E: TyEncoder<'tcx>> Encodable<E> for Term<'tcx> {
583 fn encode(&self, e: &mut E) {
584 self.kind().encode(e)
585 }
586}
587
588impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for Term<'tcx> {
589 fn decode(d: &mut D) -> Self {
590 let res: TermKind<'tcx> = Decodable::decode(d);
591 res.pack()
592 }
593}
594
595impl<'tcx> Term<'tcx> {
596 #[inline]
597 pub fn kind(self) -> TermKind<'tcx> {
598 let ptr =
599 unsafe { self.ptr.map_addr(|addr| NonZero::new_unchecked(addr.get() & !TAG_MASK)) };
600 unsafe {
604 match self.ptr.addr().get() & TAG_MASK {
605 TYPE_TAG => TermKind::Ty(Ty(Interned::new_unchecked(
606 ptr.cast::<WithCachedTypeInfo<ty::TyKind<'tcx>>>().as_ref(),
607 ))),
608 CONST_TAG => TermKind::Const(ty::Const(Interned::new_unchecked(
609 ptr.cast::<WithCachedTypeInfo<ty::ConstKind<'tcx>>>().as_ref(),
610 ))),
611 _ => core::intrinsics::unreachable(),
612 }
613 }
614 }
615
616 pub fn as_type(&self) -> Option<Ty<'tcx>> {
617 if let TermKind::Ty(ty) = self.kind() { Some(ty) } else { None }
618 }
619
620 pub fn expect_type(&self) -> Ty<'tcx> {
621 self.as_type().expect("expected a type, but found a const")
622 }
623
624 pub fn as_const(&self) -> Option<Const<'tcx>> {
625 if let TermKind::Const(c) = self.kind() { Some(c) } else { None }
626 }
627
628 pub fn expect_const(&self) -> Const<'tcx> {
629 self.as_const().expect("expected a const, but found a type")
630 }
631
632 pub fn into_arg(self) -> GenericArg<'tcx> {
633 match self.kind() {
634 TermKind::Ty(ty) => ty.into(),
635 TermKind::Const(c) => c.into(),
636 }
637 }
638
639 pub fn to_alias_term(self, tcx: TyCtxt<'tcx>) -> Option<AliasTerm<'tcx>> {
640 match self.kind() {
641 TermKind::Ty(ty) => match *ty.kind() {
642 ty::Alias(alias_ty) => Some(alias_ty.into()),
643 _ => None,
644 },
645 TermKind::Const(ct) => match ct.kind() {
646 ConstKind::Unevaluated(uv) => Some(AliasTerm::from_unevaluated_const(tcx, uv)),
647 _ => None,
648 },
649 }
650 }
651
652 pub fn is_infer(&self) -> bool {
653 match self.kind() {
654 TermKind::Ty(ty) => ty.is_ty_var(),
655 TermKind::Const(ct) => ct.is_ct_infer(),
656 }
657 }
658
659 pub fn is_trivially_wf(&self, tcx: TyCtxt<'tcx>) -> bool {
660 match self.kind() {
661 TermKind::Ty(ty) => ty.is_trivially_wf(tcx),
662 TermKind::Const(ct) => ct.is_trivially_wf(),
663 }
664 }
665
666 pub fn walk(self) -> TypeWalker<TyCtxt<'tcx>> {
677 TypeWalker::new(self.into())
678 }
679}
680
681const TAG_MASK: usize = 0b11;
682const TYPE_TAG: usize = 0b00;
683const CONST_TAG: usize = 0b01;
684
685impl<'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>)]
686impl<'tcx> TermKind<'tcx> {
687 #[inline]
688 fn pack(self) -> Term<'tcx> {
689 let (tag, ptr) = match self {
690 TermKind::Ty(ty) => {
691 assert_eq!(align_of_val(&*ty.0.0) & TAG_MASK, 0);
693 (TYPE_TAG, NonNull::from(ty.0.0).cast())
694 }
695 TermKind::Const(ct) => {
696 assert_eq!(align_of_val(&*ct.0.0) & TAG_MASK, 0);
698 (CONST_TAG, NonNull::from(ct.0.0).cast())
699 }
700 };
701
702 Term { ptr: ptr.map_addr(|addr| addr | tag), marker: PhantomData }
703 }
704}
705
706#[derive(#[automatically_derived]
impl<'tcx> ::core::clone::Clone for InstantiatedPredicates<'tcx> {
#[inline]
fn clone(&self) -> InstantiatedPredicates<'tcx> {
InstantiatedPredicates {
predicates: ::core::clone::Clone::clone(&self.predicates),
spans: ::core::clone::Clone::clone(&self.spans),
}
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for InstantiatedPredicates<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f,
"InstantiatedPredicates", "predicates", &self.predicates, "spans",
&&self.spans)
}
}Debug)]
726pub struct InstantiatedPredicates<'tcx> {
727 pub predicates: Vec<Unnormalized<'tcx, Clause<'tcx>>>,
728 pub spans: Vec<Span>,
729}
730
731impl<'tcx> InstantiatedPredicates<'tcx> {
732 pub fn empty() -> InstantiatedPredicates<'tcx> {
733 InstantiatedPredicates { predicates: ::alloc::vec::Vec::new()vec![], spans: ::alloc::vec::Vec::new()vec![] }
734 }
735
736 pub fn is_empty(&self) -> bool {
737 self.predicates.is_empty()
738 }
739
740 pub fn iter(&self) -> <&Self as IntoIterator>::IntoIter {
741 self.into_iter()
742 }
743}
744
745impl<'tcx> IntoIterator for InstantiatedPredicates<'tcx> {
746 type Item = (Unnormalized<'tcx, Clause<'tcx>>, Span);
747
748 type IntoIter = std::iter::Zip<
749 std::vec::IntoIter<Unnormalized<'tcx, Clause<'tcx>>>,
750 std::vec::IntoIter<Span>,
751 >;
752
753 fn into_iter(self) -> Self::IntoIter {
754 if true {
match (&self.predicates.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.predicates.len(), self.spans.len());
755 std::iter::zip(self.predicates, self.spans)
756 }
757}
758
759impl<'a, 'tcx> IntoIterator for &'a InstantiatedPredicates<'tcx> {
760 type Item = (Unnormalized<'tcx, Clause<'tcx>>, Span);
761
762 type IntoIter = std::iter::Zip<
763 std::iter::Copied<std::slice::Iter<'a, Unnormalized<'tcx, Clause<'tcx>>>>,
764 std::iter::Copied<std::slice::Iter<'a, Span>>,
765 >;
766
767 fn into_iter(self) -> Self::IntoIter {
768 if true {
match (&self.predicates.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.predicates.len(), self.spans.len());
769 std::iter::zip(self.predicates.iter().copied(), self.spans.iter().copied())
770 }
771}
772
773#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for ProvisionalHiddenType<'tcx> { }Copy, #[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, '__ctx>
::rustc_data_structures::stable_hasher::HashStable<::rustc_middle::ich::StableHashingContext<'__ctx>>
for ProvisionalHiddenType<'tcx> {
#[inline]
fn hash_stable(&self,
__hcx: &mut ::rustc_middle::ich::StableHashingContext<'__ctx>,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
match *self {
ProvisionalHiddenType {
span: ref __binding_0, ty: ref __binding_1 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable, const _: () =
{
impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
::rustc_serialize::Encodable<__E> for ProvisionalHiddenType<'tcx>
{
fn encode(&self, __encoder: &mut __E) {
match *self {
ProvisionalHiddenType {
span: ref __binding_0, ty: ref __binding_1 } => {
::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)]
774pub struct ProvisionalHiddenType<'tcx> {
775 pub span: Span,
789
790 pub ty: Ty<'tcx>,
803}
804
805#[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]
impl ::core::clone::Clone for DefiningScopeKind {
#[inline]
fn clone(&self) -> DefiningScopeKind { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for DefiningScopeKind { }Copy)]
807pub enum DefiningScopeKind {
808 HirTypeck,
813 MirBorrowck,
814}
815
816impl<'tcx> ProvisionalHiddenType<'tcx> {
817 pub fn new_error(tcx: TyCtxt<'tcx>, guar: ErrorGuaranteed) -> ProvisionalHiddenType<'tcx> {
818 ProvisionalHiddenType { span: DUMMY_SP, ty: Ty::new_error(tcx, guar) }
819 }
820
821 pub fn build_mismatch_error(
822 &self,
823 other: &Self,
824 tcx: TyCtxt<'tcx>,
825 ) -> Result<Diag<'tcx>, ErrorGuaranteed> {
826 (self.ty, other.ty).error_reported()?;
827 let sub_diag = if self.span == other.span {
829 TypeMismatchReason::ConflictType { span: self.span }
830 } else {
831 TypeMismatchReason::PreviousUse { span: self.span }
832 };
833 Ok(tcx.dcx().create_err(OpaqueHiddenTypeMismatch {
834 self_ty: self.ty,
835 other_ty: other.ty,
836 other_span: other.span,
837 sub: sub_diag,
838 }))
839 }
840
841 x;#[instrument(level = "debug", skip(tcx), ret)]
842 pub fn remap_generic_params_to_declaration_params(
843 self,
844 opaque_type_key: OpaqueTypeKey<'tcx>,
845 tcx: TyCtxt<'tcx>,
846 defining_scope_kind: DefiningScopeKind,
847 ) -> DefinitionSiteHiddenType<'tcx> {
848 let OpaqueTypeKey { def_id, args } = opaque_type_key;
849
850 let id_args = GenericArgs::identity_for_item(tcx, def_id);
857 debug!(?id_args);
858
859 let map = args.iter().zip(id_args).collect();
863 debug!("map = {:#?}", map);
864
865 let ty = match defining_scope_kind {
871 DefiningScopeKind::HirTypeck => {
872 fold_regions(tcx, self.ty, |_, _| tcx.lifetimes.re_erased)
873 }
874 DefiningScopeKind::MirBorrowck => self.ty,
875 };
876 let result_ty = ty.fold_with(&mut opaque_types::ReverseMapper::new(tcx, map, self.span));
877 if cfg!(debug_assertions) && matches!(defining_scope_kind, DefiningScopeKind::HirTypeck) {
878 assert_eq!(result_ty, fold_regions(tcx, result_ty, |_, _| tcx.lifetimes.re_erased));
879 }
880 DefinitionSiteHiddenType { span: self.span, ty: ty::EarlyBinder::bind(result_ty) }
881 }
882}
883
884#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for DefinitionSiteHiddenType<'tcx> { }Copy, #[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, '__ctx>
::rustc_data_structures::stable_hasher::HashStable<::rustc_middle::ich::StableHashingContext<'__ctx>>
for DefinitionSiteHiddenType<'tcx> {
#[inline]
fn hash_stable(&self,
__hcx: &mut ::rustc_middle::ich::StableHashingContext<'__ctx>,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
match *self {
DefinitionSiteHiddenType {
span: ref __binding_0, ty: ref __binding_1 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable, const _: () =
{
impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
::rustc_serialize::Encodable<__E> for
DefinitionSiteHiddenType<'tcx> {
fn encode(&self, __encoder: &mut __E) {
match *self {
DefinitionSiteHiddenType {
span: ref __binding_0, ty: ref __binding_1 } => {
::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)]
885pub struct DefinitionSiteHiddenType<'tcx> {
886 pub span: Span,
899
900 pub ty: ty::EarlyBinder<'tcx, Ty<'tcx>>,
902}
903
904impl<'tcx> DefinitionSiteHiddenType<'tcx> {
905 pub fn new_error(tcx: TyCtxt<'tcx>, guar: ErrorGuaranteed) -> DefinitionSiteHiddenType<'tcx> {
906 DefinitionSiteHiddenType {
907 span: DUMMY_SP,
908 ty: ty::EarlyBinder::bind(Ty::new_error(tcx, guar)),
909 }
910 }
911
912 pub fn build_mismatch_error(
913 &self,
914 other: &Self,
915 tcx: TyCtxt<'tcx>,
916 ) -> Result<Diag<'tcx>, ErrorGuaranteed> {
917 let self_ty = self.ty.instantiate_identity().skip_norm_wip();
918 let other_ty = other.ty.instantiate_identity().skip_norm_wip();
919 (self_ty, other_ty).error_reported()?;
920 let sub_diag = if self.span == other.span {
922 TypeMismatchReason::ConflictType { span: self.span }
923 } else {
924 TypeMismatchReason::PreviousUse { span: self.span }
925 };
926 Ok(tcx.dcx().create_err(OpaqueHiddenTypeMismatch {
927 self_ty,
928 other_ty,
929 other_span: other.span,
930 sub: sub_diag,
931 }))
932 }
933}
934
935pub type Clauses<'tcx> = &'tcx ListWithCachedTypeInfo<Clause<'tcx>>;
936
937impl<'tcx> rustc_type_ir::Flags for Clauses<'tcx> {
938 fn flags(&self) -> TypeFlags {
939 (**self).flags()
940 }
941
942 fn outer_exclusive_binder(&self) -> DebruijnIndex {
943 (**self).outer_exclusive_binder()
944 }
945}
946
947#[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]
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::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)]
953#[derive(const _: () =
{
impl<'tcx, '__ctx>
::rustc_data_structures::stable_hasher::HashStable<::rustc_middle::ich::StableHashingContext<'__ctx>>
for ParamEnv<'tcx> {
#[inline]
fn hash_stable(&self,
__hcx: &mut ::rustc_middle::ich::StableHashingContext<'__ctx>,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
match *self {
ParamEnv { caller_bounds: ref __binding_0 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable, 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)]
954pub struct ParamEnv<'tcx> {
955 caller_bounds: Clauses<'tcx>,
961}
962
963impl<'tcx> rustc_type_ir::inherent::ParamEnv<TyCtxt<'tcx>> for ParamEnv<'tcx> {
964 fn caller_bounds(self) -> impl inherent::SliceLike<Item = ty::Clause<'tcx>> {
965 self.caller_bounds()
966 }
967}
968
969impl<'tcx> ParamEnv<'tcx> {
970 #[inline]
977 pub fn empty() -> Self {
978 Self::new(ListWithCachedTypeInfo::empty())
979 }
980
981 #[inline]
982 pub fn caller_bounds(self) -> Clauses<'tcx> {
983 self.caller_bounds
984 }
985
986 #[inline]
988 pub fn new(caller_bounds: Clauses<'tcx>) -> Self {
989 ParamEnv { caller_bounds }
990 }
991
992 pub fn and<T: TypeVisitable<TyCtxt<'tcx>>>(self, value: T) -> ParamEnvAnd<'tcx, T> {
994 ParamEnvAnd { param_env: self, value }
995 }
996}
997
998#[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::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)]
999#[derive(const _: () =
{
impl<'tcx, '__ctx, T>
::rustc_data_structures::stable_hasher::HashStable<::rustc_middle::ich::StableHashingContext<'__ctx>>
for ParamEnvAnd<'tcx, T> where
T: ::rustc_data_structures::stable_hasher::HashStable<::rustc_middle::ich::StableHashingContext<'__ctx>>
{
#[inline]
fn hash_stable(&self,
__hcx: &mut ::rustc_middle::ich::StableHashingContext<'__ctx>,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
match *self {
ParamEnvAnd {
param_env: ref __binding_0, value: ref __binding_1 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable)]
1000pub struct ParamEnvAnd<'tcx, T> {
1001 pub param_env: ParamEnv<'tcx>,
1002 pub value: T,
1003}
1004
1005#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for TypingEnv<'tcx> { }Copy, #[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::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, '__ctx>
::rustc_data_structures::stable_hasher::HashStable<::rustc_middle::ich::StableHashingContext<'__ctx>>
for TypingEnv<'tcx> {
#[inline]
fn hash_stable(&self,
__hcx: &mut ::rustc_middle::ich::StableHashingContext<'__ctx>,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
match *self {
TypingEnv {
typing_mode: ref __binding_0, param_env: ref __binding_1 }
=> {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable)]
1016#[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)]
1017pub struct TypingEnv<'tcx> {
1018 #[type_foldable(identity)]
1019 #[type_visitable(ignore)]
1020 typing_mode: TypingModeEqWrapper<'tcx>,
1021 pub param_env: ParamEnv<'tcx>,
1022}
1023
1024impl<'tcx> TypingEnv<'tcx> {
1025 pub fn new(param_env: ParamEnv<'tcx>, typing_mode: TypingMode<'tcx>) -> Self {
1026 Self { typing_mode: TypingModeEqWrapper(typing_mode), param_env }
1027 }
1028
1029 pub fn typing_mode(&self) -> TypingMode<'tcx> {
1030 self.typing_mode.0
1031 }
1032
1033 pub fn fully_monomorphized() -> TypingEnv<'tcx> {
1041 Self::new(ParamEnv::empty(), TypingMode::PostAnalysis)
1042 }
1043
1044 pub fn non_body_analysis(
1050 tcx: TyCtxt<'tcx>,
1051 def_id: impl IntoQueryKey<DefId>,
1052 ) -> TypingEnv<'tcx> {
1053 let def_id = def_id.into_query_key();
1054 Self::new(tcx.param_env(def_id), TypingMode::non_body_analysis())
1055 }
1056
1057 pub fn post_analysis(tcx: TyCtxt<'tcx>, def_id: impl IntoQueryKey<DefId>) -> TypingEnv<'tcx> {
1058 let def_id = def_id.into_query_key();
1059 tcx.typing_env_normalized_for_post_analysis(def_id)
1060 }
1061
1062 pub fn with_post_analysis_normalized(self, tcx: TyCtxt<'tcx>) -> TypingEnv<'tcx> {
1065 let TypingEnv { typing_mode, param_env } = self;
1066 match typing_mode.0 {
1067 TypingMode::Coherence
1068 | TypingMode::Analysis { .. }
1069 | TypingMode::Borrowck { .. }
1070 | TypingMode::PostBorrowckAnalysis { .. } => {}
1071 TypingMode::PostAnalysis => return self,
1072 }
1073
1074 let param_env = if tcx.next_trait_solver_globally() {
1077 param_env
1078 } else {
1079 ParamEnv::new(tcx.reveal_opaque_types_in_bounds(param_env.caller_bounds()))
1080 };
1081 TypingEnv { typing_mode: TypingModeEqWrapper(TypingMode::PostAnalysis), param_env }
1082 }
1083
1084 pub fn as_query_input<T>(self, value: T) -> PseudoCanonicalInput<'tcx, T>
1089 where
1090 T: TypeVisitable<TyCtxt<'tcx>>,
1091 {
1092 PseudoCanonicalInput { typing_env: self, value }
1105 }
1106}
1107
1108#[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::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)]
1118#[derive(const _: () =
{
impl<'tcx, '__ctx, T>
::rustc_data_structures::stable_hasher::HashStable<::rustc_middle::ich::StableHashingContext<'__ctx>>
for PseudoCanonicalInput<'tcx, T> where
T: ::rustc_data_structures::stable_hasher::HashStable<::rustc_middle::ich::StableHashingContext<'__ctx>>
{
#[inline]
fn hash_stable(&self,
__hcx: &mut ::rustc_middle::ich::StableHashingContext<'__ctx>,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
match *self {
PseudoCanonicalInput {
typing_env: ref __binding_0, value: ref __binding_1 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable, 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)]
1119pub struct PseudoCanonicalInput<'tcx, T> {
1120 pub typing_env: TypingEnv<'tcx>,
1121 pub value: T,
1122}
1123
1124#[derive(#[automatically_derived]
impl ::core::marker::Copy for Destructor { }Copy, #[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<'__ctx>
::rustc_data_structures::stable_hasher::HashStable<::rustc_middle::ich::StableHashingContext<'__ctx>>
for Destructor {
#[inline]
fn hash_stable(&self,
__hcx: &mut ::rustc_middle::ich::StableHashingContext<'__ctx>,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
match *self {
Destructor { did: ref __binding_0 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for Destructor {
fn encode(&self, __encoder: &mut __E) {
match *self {
Destructor { did: ref __binding_0 } => {
::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)]
1125pub struct Destructor {
1126 pub did: DefId,
1128}
1129
1130#[derive(#[automatically_derived]
impl ::core::marker::Copy for AsyncDestructor { }Copy, #[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<'__ctx>
::rustc_data_structures::stable_hasher::HashStable<::rustc_middle::ich::StableHashingContext<'__ctx>>
for AsyncDestructor {
#[inline]
fn hash_stable(&self,
__hcx: &mut ::rustc_middle::ich::StableHashingContext<'__ctx>,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
match *self {
AsyncDestructor { impl_did: ref __binding_0 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for AsyncDestructor {
fn encode(&self, __encoder: &mut __E) {
match *self {
AsyncDestructor { impl_did: ref __binding_0 } => {
::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)]
1132pub struct AsyncDestructor {
1133 pub impl_did: DefId,
1135}
1136
1137#[derive(#[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::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<'__ctx>
::rustc_data_structures::stable_hasher::HashStable<::rustc_middle::ich::StableHashingContext<'__ctx>>
for VariantFlags {
#[inline]
fn hash_stable(&self,
__hcx: &mut ::rustc_middle::ich::StableHashingContext<'__ctx>,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
match *self {
VariantFlags(ref __binding_0) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable, const _: () =
{
impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
::rustc_serialize::Encodable<__E> for VariantFlags {
fn encode(&self, __encoder: &mut __E) {
match *self {
VariantFlags(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 VariantFlags {
fn decode(__decoder: &mut __D) -> Self {
VariantFlags(::rustc_serialize::Decodable::decode(__decoder))
}
}
};TyDecodable)]
1138pub struct VariantFlags(u8);
1139impl 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! {
1140 impl VariantFlags: u8 {
1141 const NO_VARIANT_FLAGS = 0;
1142 const IS_FIELD_LIST_NON_EXHAUSTIVE = 1 << 0;
1144 }
1145}
1146impl ::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 }
1147
1148#[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<'__ctx>
::rustc_data_structures::stable_hasher::HashStable<::rustc_middle::ich::StableHashingContext<'__ctx>>
for VariantDef {
#[inline]
fn hash_stable(&self,
__hcx: &mut ::rustc_middle::ich::StableHashingContext<'__ctx>,
__hasher:
&mut ::rustc_data_structures::stable_hasher::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.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
{ __binding_2.hash_stable(__hcx, __hasher); }
{ __binding_3.hash_stable(__hcx, __hasher); }
{ __binding_4.hash_stable(__hcx, __hasher); }
{ __binding_5.hash_stable(__hcx, __hasher); }
{ __binding_6.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable, const _: () =
{
impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
::rustc_serialize::Encodable<__E> for VariantDef {
fn encode(&self, __encoder: &mut __E) {
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 } => {
::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)]
1150pub struct VariantDef {
1151 pub def_id: DefId,
1154 pub ctor: Option<(CtorKind, DefId)>,
1157 pub name: Symbol,
1159 pub discr: VariantDiscr,
1161 pub fields: IndexVec<FieldIdx, FieldDef>,
1163 tainted: Option<ErrorGuaranteed>,
1165 flags: VariantFlags,
1167}
1168
1169impl VariantDef {
1170 #[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("compiler/rustc_middle/src/ty/mod.rs"),
::tracing_core::__macro_support::Option::Some(1186u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::ty"),
::tracing_core::field::FieldSet::new(&["name",
"variant_did", "ctor", "discr", "fields", "parent_did",
"recover_tainted", "is_field_list_non_exhaustive"],
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&name)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&variant_did)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ctor)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&discr)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fields)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&parent_did)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&recover_tainted)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&is_field_list_non_exhaustive
as &dyn 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")]
1187 pub fn new(
1188 name: Symbol,
1189 variant_did: Option<DefId>,
1190 ctor: Option<(CtorKind, DefId)>,
1191 discr: VariantDiscr,
1192 fields: IndexVec<FieldIdx, FieldDef>,
1193 parent_did: DefId,
1194 recover_tainted: Option<ErrorGuaranteed>,
1195 is_field_list_non_exhaustive: bool,
1196 ) -> Self {
1197 let mut flags = VariantFlags::NO_VARIANT_FLAGS;
1198 if is_field_list_non_exhaustive {
1199 flags |= VariantFlags::IS_FIELD_LIST_NON_EXHAUSTIVE;
1200 }
1201
1202 VariantDef {
1203 def_id: variant_did.unwrap_or(parent_did),
1204 ctor,
1205 name,
1206 discr,
1207 fields,
1208 flags,
1209 tainted: recover_tainted,
1210 }
1211 }
1212
1213 #[inline]
1219 pub fn is_field_list_non_exhaustive(&self) -> bool {
1220 self.flags.intersects(VariantFlags::IS_FIELD_LIST_NON_EXHAUSTIVE)
1221 }
1222
1223 #[inline]
1226 pub fn field_list_has_applicable_non_exhaustive(&self) -> bool {
1227 self.is_field_list_non_exhaustive() && !self.def_id.is_local()
1228 }
1229
1230 pub fn ident(&self, tcx: TyCtxt<'_>) -> Ident {
1232 Ident::new(self.name, tcx.def_ident_span(self.def_id).unwrap())
1233 }
1234
1235 #[inline]
1237 pub fn has_errors(&self) -> Result<(), ErrorGuaranteed> {
1238 self.tainted.map_or(Ok(()), Err)
1239 }
1240
1241 #[inline]
1242 pub fn ctor_kind(&self) -> Option<CtorKind> {
1243 self.ctor.map(|(kind, _)| kind)
1244 }
1245
1246 #[inline]
1247 pub fn ctor_def_id(&self) -> Option<DefId> {
1248 self.ctor.map(|(_, def_id)| def_id)
1249 }
1250
1251 #[inline]
1255 pub fn single_field(&self) -> &FieldDef {
1256 if !(self.fields.len() == 1) {
::core::panicking::panic("assertion failed: self.fields.len() == 1")
};assert!(self.fields.len() == 1);
1257
1258 &self.fields[FieldIdx::ZERO]
1259 }
1260
1261 #[inline]
1263 pub fn tail_opt(&self) -> Option<&FieldDef> {
1264 self.fields.raw.last()
1265 }
1266
1267 #[inline]
1273 pub fn tail(&self) -> &FieldDef {
1274 self.tail_opt().expect("expected unsized ADT to have a tail field")
1275 }
1276
1277 pub fn has_unsafe_fields(&self) -> bool {
1279 self.fields.iter().any(|x| x.safety.is_unsafe())
1280 }
1281}
1282
1283impl PartialEq for VariantDef {
1284 #[inline]
1285 fn eq(&self, other: &Self) -> bool {
1286 let Self {
1294 def_id: lhs_def_id,
1295 ctor: _,
1296 name: _,
1297 discr: _,
1298 fields: _,
1299 flags: _,
1300 tainted: _,
1301 } = &self;
1302 let Self {
1303 def_id: rhs_def_id,
1304 ctor: _,
1305 name: _,
1306 discr: _,
1307 fields: _,
1308 flags: _,
1309 tainted: _,
1310 } = other;
1311
1312 let res = lhs_def_id == rhs_def_id;
1313
1314 if truecfg!(debug_assertions) && res {
1316 let deep = self.ctor == other.ctor
1317 && self.name == other.name
1318 && self.discr == other.discr
1319 && self.fields == other.fields
1320 && self.flags == other.flags;
1321 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");
1322 }
1323
1324 res
1325 }
1326}
1327
1328impl Eq for VariantDef {}
1329
1330impl Hash for VariantDef {
1331 #[inline]
1332 fn hash<H: Hasher>(&self, s: &mut H) {
1333 let Self { def_id, ctor: _, name: _, discr: _, fields: _, flags: _, tainted: _ } = &self;
1341 def_id.hash(s)
1342 }
1343}
1344
1345#[derive(#[automatically_derived]
impl ::core::marker::Copy for VariantDiscr { }Copy, #[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::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<'__ctx>
::rustc_data_structures::stable_hasher::HashStable<::rustc_middle::ich::StableHashingContext<'__ctx>>
for VariantDiscr {
#[inline]
fn hash_stable(&self,
__hcx: &mut ::rustc_middle::ich::StableHashingContext<'__ctx>,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
match *self {
VariantDiscr::Explicit(ref __binding_0) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
VariantDiscr::Relative(ref __binding_0) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable)]
1346pub enum VariantDiscr {
1347 Explicit(DefId),
1350
1351 Relative(u32),
1356}
1357
1358#[derive(#[automatically_derived]
impl ::core::fmt::Debug for FieldDef {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field5_finish(f, "FieldDef",
"did", &self.did, "name", &self.name, "vis", &self.vis, "safety",
&self.safety, "value", &&self.value)
}
}Debug, const _: () =
{
impl<'__ctx>
::rustc_data_structures::stable_hasher::HashStable<::rustc_middle::ich::StableHashingContext<'__ctx>>
for FieldDef {
#[inline]
fn hash_stable(&self,
__hcx: &mut ::rustc_middle::ich::StableHashingContext<'__ctx>,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
match *self {
FieldDef {
did: ref __binding_0,
name: ref __binding_1,
vis: ref __binding_2,
safety: ref __binding_3,
value: ref __binding_4 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
{ __binding_2.hash_stable(__hcx, __hasher); }
{ __binding_3.hash_stable(__hcx, __hasher); }
{ __binding_4.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable, const _: () =
{
impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
::rustc_serialize::Encodable<__E> for FieldDef {
fn encode(&self, __encoder: &mut __E) {
match *self {
FieldDef {
did: ref __binding_0,
name: ref __binding_1,
vis: ref __binding_2,
safety: ref __binding_3,
value: ref __binding_4 } => {
::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);
}
}
}
}
};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),
safety: ::rustc_serialize::Decodable::decode(__decoder),
value: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};TyDecodable)]
1359pub struct FieldDef {
1360 pub did: DefId,
1361 pub name: Symbol,
1362 pub vis: Visibility<DefId>,
1363 pub safety: hir::Safety,
1364 pub value: Option<DefId>,
1365}
1366
1367impl PartialEq for FieldDef {
1368 #[inline]
1369 fn eq(&self, other: &Self) -> bool {
1370 let Self { did: lhs_did, name: _, vis: _, safety: _, value: _ } = &self;
1378
1379 let Self { did: rhs_did, name: _, vis: _, safety: _, value: _ } = other;
1380
1381 let res = lhs_did == rhs_did;
1382
1383 if truecfg!(debug_assertions) && res {
1385 let deep =
1386 self.name == other.name && self.vis == other.vis && self.safety == other.safety;
1387 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");
1388 }
1389
1390 res
1391 }
1392}
1393
1394impl Eq for FieldDef {}
1395
1396impl Hash for FieldDef {
1397 #[inline]
1398 fn hash<H: Hasher>(&self, s: &mut H) {
1399 let Self { did, name: _, vis: _, safety: _, value: _ } = &self;
1407
1408 did.hash(s)
1409 }
1410}
1411
1412impl<'tcx> FieldDef {
1413 pub fn ty(&self, tcx: TyCtxt<'tcx>, args: GenericArgsRef<'tcx>) -> Ty<'tcx> {
1416 tcx.type_of(self.did).instantiate(tcx, args).skip_norm_wip()
1417 }
1418
1419 pub fn ident(&self, tcx: TyCtxt<'_>) -> Ident {
1421 Ident::new(self.name, tcx.def_ident_span(self.did).unwrap())
1422 }
1423}
1424
1425#[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::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)]
1426pub enum ImplOverlapKind {
1427 Permitted {
1429 marker: bool,
1431 },
1432}
1433
1434#[derive(#[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::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<'__ctx>
::rustc_data_structures::stable_hasher::HashStable<::rustc_middle::ich::StableHashingContext<'__ctx>>
for ImplTraitInTraitData {
#[inline]
fn hash_stable(&self,
__hcx: &mut ::rustc_middle::ich::StableHashingContext<'__ctx>,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
match *self {
ImplTraitInTraitData::Trait {
fn_def_id: ref __binding_0, opaque_def_id: ref __binding_1 }
=> {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
}
ImplTraitInTraitData::Impl { fn_def_id: ref __binding_0 } =>
{
{ __binding_0.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable)]
1437pub enum ImplTraitInTraitData {
1438 Trait { fn_def_id: DefId, opaque_def_id: DefId },
1439 Impl { fn_def_id: DefId },
1440}
1441
1442impl<'tcx> TyCtxt<'tcx> {
1443 pub fn typeck_body(self, body: hir::BodyId) -> &'tcx TypeckResults<'tcx> {
1444 self.typeck(self.hir_body_owner_def_id(body))
1445 }
1446
1447 pub fn provided_trait_methods(self, id: DefId) -> impl 'tcx + Iterator<Item = &'tcx AssocItem> {
1448 self.associated_items(id)
1449 .in_definition_order()
1450 .filter(move |item| item.is_fn() && item.defaultness(self).has_value())
1451 }
1452
1453 pub fn repr_options_of_def(self, did: LocalDefId) -> ReprOptions {
1454 let mut flags = ReprFlags::empty();
1455 let mut size = None;
1456 let mut max_align: Option<Align> = None;
1457 let mut min_pack: Option<Align> = None;
1458
1459 let mut field_shuffle_seed = self.def_path_hash(did.to_def_id()).0.to_smaller_hash();
1462
1463 if let Some(user_seed) = self.sess.opts.unstable_opts.layout_seed {
1467 field_shuffle_seed ^= user_seed;
1468 }
1469
1470 let elt = {
{
'done:
{
for i in ::rustc_hir::attrs::HasAttrs::get_attrs(did, &self) {
#[allow(unused_imports)]
use rustc_hir::attrs::AttributeKind::*;
let i: &rustc_hir::Attribute = i;
match i {
rustc_hir::Attribute::Parsed(RustcScalableVector {
element_count, .. }) => {
break 'done Some(element_count);
}
rustc_hir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}
}find_attr!(self, did, RustcScalableVector { element_count, .. } => element_count
1471 )
1472 .map(|elt| match elt {
1473 Some(n) => ScalableElt::ElementCount(*n),
1474 None => ScalableElt::Container,
1475 });
1476 if elt.is_some() {
1477 flags.insert(ReprFlags::IS_SCALABLE);
1478 }
1479 if let Some(reprs) = {
{
'done:
{
for i in ::rustc_hir::attrs::HasAttrs::get_attrs(did, &self) {
#[allow(unused_imports)]
use rustc_hir::attrs::AttributeKind::*;
let i: &rustc_hir::Attribute = i;
match i {
rustc_hir::Attribute::Parsed(Repr { reprs, .. }) => {
break 'done Some(reprs);
}
rustc_hir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}
}find_attr!(self, did, Repr { reprs, .. } => reprs) {
1480 for (r, _) in reprs {
1481 flags.insert(match *r {
1482 attr::ReprRust => ReprFlags::empty(),
1483 attr::ReprC => ReprFlags::IS_C,
1484 attr::ReprPacked(pack) => {
1485 min_pack = Some(if let Some(min_pack) = min_pack {
1486 min_pack.min(pack)
1487 } else {
1488 pack
1489 });
1490 ReprFlags::empty()
1491 }
1492 attr::ReprTransparent => ReprFlags::IS_TRANSPARENT,
1493 attr::ReprSimd => ReprFlags::IS_SIMD,
1494 attr::ReprInt(i) => {
1495 size = Some(match i {
1496 attr::IntType::SignedInt(x) => match x {
1497 ast::IntTy::Isize => IntegerType::Pointer(true),
1498 ast::IntTy::I8 => IntegerType::Fixed(Integer::I8, true),
1499 ast::IntTy::I16 => IntegerType::Fixed(Integer::I16, true),
1500 ast::IntTy::I32 => IntegerType::Fixed(Integer::I32, true),
1501 ast::IntTy::I64 => IntegerType::Fixed(Integer::I64, true),
1502 ast::IntTy::I128 => IntegerType::Fixed(Integer::I128, true),
1503 },
1504 attr::IntType::UnsignedInt(x) => match x {
1505 ast::UintTy::Usize => IntegerType::Pointer(false),
1506 ast::UintTy::U8 => IntegerType::Fixed(Integer::I8, false),
1507 ast::UintTy::U16 => IntegerType::Fixed(Integer::I16, false),
1508 ast::UintTy::U32 => IntegerType::Fixed(Integer::I32, false),
1509 ast::UintTy::U64 => IntegerType::Fixed(Integer::I64, false),
1510 ast::UintTy::U128 => IntegerType::Fixed(Integer::I128, false),
1511 },
1512 });
1513 ReprFlags::empty()
1514 }
1515 attr::ReprAlign(align) => {
1516 max_align = max_align.max(Some(align));
1517 ReprFlags::empty()
1518 }
1519 });
1520 }
1521 }
1522
1523 if self.sess.opts.unstable_opts.randomize_layout {
1526 flags.insert(ReprFlags::RANDOMIZE_LAYOUT);
1527 }
1528
1529 let is_box = self.is_lang_item(did.to_def_id(), LangItem::OwnedBox);
1532
1533 if is_box {
1535 flags.insert(ReprFlags::IS_LINEAR);
1536 }
1537
1538 if {
{
'done:
{
for i in ::rustc_hir::attrs::HasAttrs::get_attrs(did, &self) {
#[allow(unused_imports)]
use rustc_hir::attrs::AttributeKind::*;
let i: &rustc_hir::Attribute = i;
match i {
rustc_hir::Attribute::Parsed(RustcPassIndirectlyInNonRusticAbis(..))
=> {
break 'done Some(());
}
rustc_hir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}
}.is_some()find_attr!(self, did, RustcPassIndirectlyInNonRusticAbis(..)) {
1540 flags.insert(ReprFlags::PASS_INDIRECTLY_IN_NON_RUSTIC_ABIS);
1541 }
1542
1543 ReprOptions {
1544 int: size,
1545 align: max_align,
1546 pack: min_pack,
1547 flags,
1548 field_shuffle_seed,
1549 scalable: elt,
1550 }
1551 }
1552
1553 pub fn opt_item_name(self, def_id: impl IntoQueryKey<DefId>) -> Option<Symbol> {
1555 let def_id = def_id.into_query_key();
1556 if let Some(cnum) = def_id.as_crate_root() {
1557 Some(self.crate_name(cnum))
1558 } else {
1559 let def_key = self.def_key(def_id);
1560 match def_key.disambiguated_data.data {
1561 rustc_hir::definitions::DefPathData::Ctor => self
1563 .opt_item_name(DefId { krate: def_id.krate, index: def_key.parent.unwrap() }),
1564 _ => def_key.get_opt_name(),
1565 }
1566 }
1567 }
1568
1569 pub fn item_name(self, id: impl IntoQueryKey<DefId>) -> Symbol {
1576 let id = id.into_query_key();
1577 self.opt_item_name(id).unwrap_or_else(|| {
1578 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));
1579 })
1580 }
1581
1582 pub fn opt_item_ident(self, def_id: impl IntoQueryKey<DefId>) -> Option<Ident> {
1586 let def_id = def_id.into_query_key();
1587 let def = self.opt_item_name(def_id)?;
1588 let span = self
1589 .def_ident_span(def_id)
1590 .unwrap_or_else(|| crate::util::bug::bug_fmt(format_args!("missing ident span for {0:?}",
def_id))bug!("missing ident span for {def_id:?}"));
1591 Some(Ident::new(def, span))
1592 }
1593
1594 pub fn item_ident(self, def_id: impl IntoQueryKey<DefId>) -> Ident {
1598 let def_id = def_id.into_query_key();
1599 self.opt_item_ident(def_id).unwrap_or_else(|| {
1600 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));
1601 })
1602 }
1603
1604 pub fn opt_associated_item(self, def_id: DefId) -> Option<AssocItem> {
1605 if let DefKind::AssocConst { .. } | DefKind::AssocFn | DefKind::AssocTy =
1606 self.def_kind(def_id)
1607 {
1608 Some(self.associated_item(def_id))
1609 } else {
1610 None
1611 }
1612 }
1613
1614 pub fn opt_rpitit_info(self, def_id: DefId) -> Option<ImplTraitInTraitData> {
1618 if let DefKind::AssocTy = self.def_kind(def_id)
1619 && let AssocKind::Type { data: AssocTypeData::Rpitit(rpitit_info) } =
1620 self.associated_item(def_id).kind
1621 {
1622 Some(rpitit_info)
1623 } else {
1624 None
1625 }
1626 }
1627
1628 pub fn find_field_index(self, ident: Ident, variant: &VariantDef) -> Option<FieldIdx> {
1629 variant.fields.iter_enumerated().find_map(|(i, field)| {
1630 self.hygienic_eq(ident, field.ident(self), variant.def_id).then_some(i)
1631 })
1632 }
1633
1634 x;#[instrument(level = "debug", skip(self), ret)]
1637 pub fn impls_are_allowed_to_overlap(
1638 self,
1639 def_id1: DefId,
1640 def_id2: DefId,
1641 ) -> Option<ImplOverlapKind> {
1642 let impl1 = self.impl_trait_header(def_id1);
1643 let impl2 = self.impl_trait_header(def_id2);
1644
1645 let trait_ref1 = impl1.trait_ref.skip_binder();
1646 let trait_ref2 = impl2.trait_ref.skip_binder();
1647
1648 if trait_ref1.references_error() || trait_ref2.references_error() {
1651 return Some(ImplOverlapKind::Permitted { marker: false });
1652 }
1653
1654 match (impl1.polarity, impl2.polarity) {
1655 (ImplPolarity::Reservation, _) | (_, ImplPolarity::Reservation) => {
1656 return Some(ImplOverlapKind::Permitted { marker: false });
1658 }
1659 (ImplPolarity::Positive, ImplPolarity::Negative)
1660 | (ImplPolarity::Negative, ImplPolarity::Positive) => {
1661 return None;
1663 }
1664 (ImplPolarity::Positive, ImplPolarity::Positive)
1665 | (ImplPolarity::Negative, ImplPolarity::Negative) => {}
1666 };
1667
1668 let is_marker_impl = |trait_ref: TraitRef<'_>| self.trait_def(trait_ref.def_id).is_marker;
1669 let is_marker_overlap = is_marker_impl(trait_ref1) && is_marker_impl(trait_ref2);
1670
1671 if is_marker_overlap {
1672 return Some(ImplOverlapKind::Permitted { marker: true });
1673 }
1674
1675 None
1676 }
1677
1678 pub fn expect_variant_res(self, res: Res) -> &'tcx VariantDef {
1681 match res {
1682 Res::Def(DefKind::Variant, did) => {
1683 let enum_did = self.parent(did);
1684 self.adt_def(enum_did).variant_with_id(did)
1685 }
1686 Res::Def(DefKind::Struct | DefKind::Union, did) => self.adt_def(did).non_enum_variant(),
1687 Res::Def(DefKind::Ctor(CtorOf::Variant, ..), variant_ctor_did) => {
1688 let variant_did = self.parent(variant_ctor_did);
1689 let enum_did = self.parent(variant_did);
1690 self.adt_def(enum_did).variant_with_ctor_id(variant_ctor_did)
1691 }
1692 Res::Def(DefKind::Ctor(CtorOf::Struct, ..), ctor_did) => {
1693 let struct_did = self.parent(ctor_did);
1694 self.adt_def(struct_did).non_enum_variant()
1695 }
1696 _ => 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),
1697 }
1698 }
1699
1700 #[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("compiler/rustc_middle/src/ty/mod.rs"),
::tracing_core::__macro_support::Option::Some(1701u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::ty"),
::tracing_core::field::FieldSet::new(&["instance"],
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&instance)
as &dyn 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;
}
{
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 compiler/rustc_middle/src/ty/mod.rs:1705",
"rustc_middle::ty", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/ty/mod.rs"),
::tracing_core::__macro_support::Option::Some(1705u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("calling def_kind on def: {0:?}",
def) as &dyn 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 compiler/rustc_middle/src/ty/mod.rs:1707",
"rustc_middle::ty", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/ty/mod.rs"),
::tracing_core::__macro_support::Option::Some(1707u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("returned from def_kind: {0:?}",
def_kind) as &dyn Value))])
});
} else { ; }
};
match def_kind {
DefKind::Const { .. } | DefKind::Static { .. } |
DefKind::AssocConst { .. } | DefKind::Ctor(..) |
DefKind::AnonConst | DefKind::InlineConst =>
self.mir_for_ctfe(def),
_ => self.optimized_mir(def),
}
}
ty::InstanceKind::VTableShim(..) |
ty::InstanceKind::ReifyShim(..) |
ty::InstanceKind::Intrinsic(..) |
ty::InstanceKind::FnPtrShim(..) |
ty::InstanceKind::Virtual(..) |
ty::InstanceKind::ClosureOnceShim { .. } |
ty::InstanceKind::ConstructCoroutineInClosureShim { .. } |
ty::InstanceKind::FutureDropPollShim(..) |
ty::InstanceKind::DropGlue(..) |
ty::InstanceKind::CloneShim(..) |
ty::InstanceKind::ThreadLocalShim(..) |
ty::InstanceKind::FnPtrAddrShim(..) |
ty::InstanceKind::AsyncDropGlueCtorShim(..) |
ty::InstanceKind::AsyncDropGlue(..) =>
self.mir_shims(instance),
}
}
}
}#[instrument(skip(self), level = "debug")]
1702 pub fn instance_mir(self, instance: ty::InstanceKind<'tcx>) -> &'tcx Body<'tcx> {
1703 match instance {
1704 ty::InstanceKind::Item(def) => {
1705 debug!("calling def_kind on def: {:?}", def);
1706 let def_kind = self.def_kind(def);
1707 debug!("returned from def_kind: {:?}", def_kind);
1708 match def_kind {
1709 DefKind::Const { .. }
1710 | DefKind::Static { .. }
1711 | DefKind::AssocConst { .. }
1712 | DefKind::Ctor(..)
1713 | DefKind::AnonConst
1714 | DefKind::InlineConst => self.mir_for_ctfe(def),
1715 _ => self.optimized_mir(def),
1718 }
1719 }
1720 ty::InstanceKind::VTableShim(..)
1721 | ty::InstanceKind::ReifyShim(..)
1722 | ty::InstanceKind::Intrinsic(..)
1723 | ty::InstanceKind::FnPtrShim(..)
1724 | ty::InstanceKind::Virtual(..)
1725 | ty::InstanceKind::ClosureOnceShim { .. }
1726 | ty::InstanceKind::ConstructCoroutineInClosureShim { .. }
1727 | ty::InstanceKind::FutureDropPollShim(..)
1728 | ty::InstanceKind::DropGlue(..)
1729 | ty::InstanceKind::CloneShim(..)
1730 | ty::InstanceKind::ThreadLocalShim(..)
1731 | ty::InstanceKind::FnPtrAddrShim(..)
1732 | ty::InstanceKind::AsyncDropGlueCtorShim(..)
1733 | ty::InstanceKind::AsyncDropGlue(..) => self.mir_shims(instance),
1734 }
1735 }
1736
1737 #[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."]
1739 pub fn get_attrs(
1740 self,
1741 did: impl Into<DefId>,
1742 attr: Symbol,
1743 ) -> impl Iterator<Item = &'tcx hir::Attribute> {
1744 #[allow(deprecated)]
1745 self.get_all_attrs(did).iter().filter(move |a: &&hir::Attribute| a.has_name(attr))
1746 }
1747
1748 #[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."]
1753 pub fn get_all_attrs(self, did: impl Into<DefId>) -> &'tcx [hir::Attribute] {
1754 let did: DefId = did.into();
1755 if let Some(did) = did.as_local() {
1756 self.hir_attrs(self.local_def_id_to_hir_id(did))
1757 } else {
1758 self.attrs_for_def(did)
1759 }
1760 }
1761
1762 pub fn get_attrs_by_path(
1763 self,
1764 did: DefId,
1765 attr: &[Symbol],
1766 ) -> impl Iterator<Item = &'tcx hir::Attribute> {
1767 let filter_fn = move |a: &&hir::Attribute| a.path_matches(attr);
1768 if let Some(did) = did.as_local() {
1769 self.hir_attrs(self.local_def_id_to_hir_id(did)).iter().filter(filter_fn)
1770 } else {
1771 self.attrs_for_def(did).iter().filter(filter_fn)
1772 }
1773 }
1774
1775 pub fn trait_is_auto(self, trait_def_id: DefId) -> bool {
1777 self.trait_def(trait_def_id).has_auto_impl
1778 }
1779
1780 pub fn trait_is_coinductive(self, trait_def_id: DefId) -> bool {
1783 self.trait_def(trait_def_id).is_coinductive
1784 }
1785
1786 pub fn trait_is_alias(self, trait_def_id: DefId) -> bool {
1788 self.def_kind(trait_def_id) == DefKind::TraitAlias
1789 }
1790
1791 fn layout_error(self, err: LayoutError<'tcx>) -> &'tcx LayoutError<'tcx> {
1793 self.arena.alloc(err)
1794 }
1795
1796 fn ordinary_coroutine_layout(
1802 self,
1803 def_id: DefId,
1804 args: GenericArgsRef<'tcx>,
1805 ) -> Result<&'tcx CoroutineLayout<'tcx>, &'tcx LayoutError<'tcx>> {
1806 let coroutine_kind_ty = args.as_coroutine().kind_ty();
1807 let mir = self.optimized_mir(def_id);
1808 let ty = || Ty::new_coroutine(self, def_id, args);
1809 if coroutine_kind_ty.is_unit() {
1811 mir.coroutine_layout_raw().ok_or_else(|| self.layout_error(LayoutError::Unknown(ty())))
1812 } else {
1813 let ty::Coroutine(_, identity_args) =
1816 *self.type_of(def_id).instantiate_identity().skip_norm_wip().kind()
1817 else {
1818 ::core::panicking::panic("internal error: entered unreachable code");unreachable!();
1819 };
1820 let identity_kind_ty = identity_args.as_coroutine().kind_ty();
1821 if identity_kind_ty == coroutine_kind_ty {
1824 mir.coroutine_layout_raw()
1825 .ok_or_else(|| self.layout_error(LayoutError::Unknown(ty())))
1826 } else {
1827 {
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));
1828 {
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!(
1829 identity_kind_ty.to_opt_closure_kind(),
1830 Some(ClosureKind::Fn | ClosureKind::FnMut)
1831 );
1832 self.optimized_mir(self.coroutine_by_move_body_def_id(def_id))
1833 .coroutine_layout_raw()
1834 .ok_or_else(|| self.layout_error(LayoutError::Unknown(ty())))
1835 }
1836 }
1837 }
1838
1839 fn async_drop_coroutine_layout(
1843 self,
1844 def_id: DefId,
1845 args: GenericArgsRef<'tcx>,
1846 ) -> Result<&'tcx CoroutineLayout<'tcx>, &'tcx LayoutError<'tcx>> {
1847 let ty = || Ty::new_coroutine(self, def_id, args);
1848 if args[0].has_placeholders() || args[0].has_non_region_param() {
1849 return Err(self.layout_error(LayoutError::TooGeneric(ty())));
1850 }
1851 let instance = InstanceKind::AsyncDropGlue(def_id, Ty::new_coroutine(self, def_id, args));
1852 self.mir_shims(instance)
1853 .coroutine_layout_raw()
1854 .ok_or_else(|| self.layout_error(LayoutError::Unknown(ty())))
1855 }
1856
1857 pub fn coroutine_layout(
1860 self,
1861 def_id: DefId,
1862 args: GenericArgsRef<'tcx>,
1863 ) -> Result<&'tcx CoroutineLayout<'tcx>, &'tcx LayoutError<'tcx>> {
1864 if self.is_async_drop_in_place_coroutine(def_id) {
1865 let arg_cor_ty = args.first().unwrap().expect_ty();
1869 if arg_cor_ty.is_coroutine() {
1870 let span = self.def_span(def_id);
1871 let source_info = SourceInfo::outermost(span);
1872 let variant_fields: IndexVec<VariantIdx, IndexVec<FieldIdx, CoroutineSavedLocal>> =
1875 iter::repeat(IndexVec::new()).take(CoroutineArgs::RESERVED_VARIANTS).collect();
1876 let variant_source_info: IndexVec<VariantIdx, SourceInfo> =
1877 iter::repeat(source_info).take(CoroutineArgs::RESERVED_VARIANTS).collect();
1878 let proxy_layout = CoroutineLayout {
1879 field_tys: [].into(),
1880 field_names: [].into(),
1881 variant_fields,
1882 variant_source_info,
1883 storage_conflicts: BitMatrix::new(0, 0),
1884 };
1885 return Ok(self.arena.alloc(proxy_layout));
1886 } else {
1887 self.async_drop_coroutine_layout(def_id, args)
1888 }
1889 } else {
1890 self.ordinary_coroutine_layout(def_id, args)
1891 }
1892 }
1893
1894 pub fn assoc_parent(self, def_id: DefId) -> Option<(DefId, DefKind)> {
1896 if !self.def_kind(def_id).is_assoc() {
1897 return None;
1898 }
1899 let parent = self.parent(def_id);
1900 let def_kind = self.def_kind(parent);
1901 Some((parent, def_kind))
1902 }
1903
1904 pub fn trait_item_of(self, def_id: impl IntoQueryKey<DefId>) -> Option<DefId> {
1906 let def_id = def_id.into_query_key();
1907 self.opt_associated_item(def_id)?.trait_item_def_id()
1908 }
1909
1910 pub fn trait_of_assoc(self, def_id: DefId) -> Option<DefId> {
1913 match self.assoc_parent(def_id) {
1914 Some((id, DefKind::Trait)) => Some(id),
1915 _ => None,
1916 }
1917 }
1918
1919 pub fn impl_is_of_trait(self, def_id: impl IntoQueryKey<DefId>) -> bool {
1920 let def_id = def_id.into_query_key();
1921 let DefKind::Impl { of_trait } = self.def_kind(def_id) else {
1922 {
::core::panicking::panic_fmt(format_args!("expected Impl for {0:?}",
def_id));
};panic!("expected Impl for {def_id:?}");
1923 };
1924 of_trait
1925 }
1926
1927 pub fn impl_of_assoc(self, def_id: DefId) -> Option<DefId> {
1930 match self.assoc_parent(def_id) {
1931 Some((id, DefKind::Impl { .. })) => Some(id),
1932 _ => None,
1933 }
1934 }
1935
1936 pub fn inherent_impl_of_assoc(self, def_id: DefId) -> Option<DefId> {
1939 match self.assoc_parent(def_id) {
1940 Some((id, DefKind::Impl { of_trait: false })) => Some(id),
1941 _ => None,
1942 }
1943 }
1944
1945 pub fn trait_impl_of_assoc(self, def_id: DefId) -> Option<DefId> {
1948 match self.assoc_parent(def_id) {
1949 Some((id, DefKind::Impl { of_trait: true })) => Some(id),
1950 _ => None,
1951 }
1952 }
1953
1954 pub fn impl_polarity(self, def_id: impl IntoQueryKey<DefId>) -> ty::ImplPolarity {
1955 let def_id = def_id.into_query_key();
1956 self.impl_trait_header(def_id).polarity
1957 }
1958
1959 pub fn impl_trait_ref(
1961 self,
1962 def_id: impl IntoQueryKey<DefId>,
1963 ) -> ty::EarlyBinder<'tcx, ty::TraitRef<'tcx>> {
1964 let def_id = def_id.into_query_key();
1965 self.impl_trait_header(def_id).trait_ref
1966 }
1967
1968 pub fn impl_opt_trait_ref(
1971 self,
1972 def_id: impl IntoQueryKey<DefId>,
1973 ) -> Option<ty::EarlyBinder<'tcx, ty::TraitRef<'tcx>>> {
1974 let def_id = def_id.into_query_key();
1975 self.impl_is_of_trait(def_id).then(|| self.impl_trait_ref(def_id))
1976 }
1977
1978 pub fn impl_trait_id(self, def_id: impl IntoQueryKey<DefId>) -> DefId {
1980 let def_id = def_id.into_query_key();
1981 self.impl_trait_ref(def_id).skip_binder().def_id
1982 }
1983
1984 pub fn impl_opt_trait_id(self, def_id: impl IntoQueryKey<DefId>) -> Option<DefId> {
1987 let def_id = def_id.into_query_key();
1988 self.impl_is_of_trait(def_id).then(|| self.impl_trait_id(def_id))
1989 }
1990
1991 pub fn is_exportable(self, def_id: DefId) -> bool {
1992 self.exportable_items(def_id.krate).contains(&def_id)
1993 }
1994
1995 pub fn is_builtin_derived(self, def_id: DefId) -> bool {
1998 if self.is_automatically_derived(def_id)
1999 && let Some(def_id) = def_id.as_local()
2000 && let outer = self.def_span(def_id).ctxt().outer_expn_data()
2001 && #[allow(non_exhaustive_omitted_patterns)] match outer.kind {
ExpnKind::Macro(MacroKind::Derive, _) => true,
_ => false,
}matches!(outer.kind, ExpnKind::Macro(MacroKind::Derive, _))
2002 && {
{
'done:
{
for i in
::rustc_hir::attrs::HasAttrs::get_attrs(outer.macro_def_id.unwrap(),
&self) {
#[allow(unused_imports)]
use rustc_hir::attrs::AttributeKind::*;
let i: &rustc_hir::Attribute = i;
match i {
rustc_hir::Attribute::Parsed(RustcBuiltinMacro { .. }) => {
break 'done Some(());
}
rustc_hir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}
}.is_some()find_attr!(self, outer.macro_def_id.unwrap(), RustcBuiltinMacro { .. })
2003 {
2004 true
2005 } else {
2006 false
2007 }
2008 }
2009
2010 pub fn is_automatically_derived(self, def_id: DefId) -> bool {
2012 {
{
'done:
{
for i in
::rustc_hir::attrs::HasAttrs::get_attrs(def_id, &self) {
#[allow(unused_imports)]
use rustc_hir::attrs::AttributeKind::*;
let i: &rustc_hir::Attribute = i;
match i {
rustc_hir::Attribute::Parsed(AutomaticallyDerived(..)) => {
break 'done Some(());
}
rustc_hir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}
}.is_some()find_attr!(self, def_id, AutomaticallyDerived(..))
2013 }
2014
2015 pub fn span_of_impl(self, impl_def_id: DefId) -> Result<Span, Symbol> {
2018 if let Some(impl_def_id) = impl_def_id.as_local() {
2019 Ok(self.def_span(impl_def_id))
2020 } else {
2021 Err(self.crate_name(impl_def_id.krate))
2022 }
2023 }
2024
2025 pub fn hygienic_eq(self, use_ident: Ident, def_ident: Ident, def_parent_def_id: DefId) -> bool {
2029 use_ident.name == def_ident.name
2033 && use_ident
2034 .span
2035 .ctxt()
2036 .hygienic_eq(def_ident.span.ctxt(), self.expn_that_defined(def_parent_def_id))
2037 }
2038
2039 pub fn adjust_ident(self, mut ident: Ident, scope: DefId) -> Ident {
2040 ident.span.normalize_to_macros_2_0_and_adjust(self.expn_that_defined(scope));
2041 ident
2042 }
2043
2044 pub fn adjust_ident_and_get_scope(
2046 self,
2047 mut ident: Ident,
2048 scope: DefId,
2049 block: hir::HirId,
2050 ) -> (Ident, DefId) {
2051 let scope = ident
2052 .span
2053 .normalize_to_macros_2_0_and_adjust(self.expn_that_defined(scope))
2054 .and_then(|actual_expansion| actual_expansion.expn_data().parent_module)
2055 .unwrap_or_else(|| self.parent_module(block).to_def_id());
2056 (ident, scope)
2057 }
2058
2059 #[inline]
2063 pub fn is_const_fn(self, def_id: DefId) -> bool {
2064 #[allow(non_exhaustive_omitted_patterns)] match self.def_kind(def_id) {
DefKind::Fn | DefKind::AssocFn | DefKind::Ctor(_, CtorKind::Fn) |
DefKind::Closure => true,
_ => false,
}matches!(
2065 self.def_kind(def_id),
2066 DefKind::Fn | DefKind::AssocFn | DefKind::Ctor(_, CtorKind::Fn) | DefKind::Closure
2067 ) && self.constness(def_id) == hir::Constness::Const
2068 }
2069
2070 pub fn is_conditionally_const(self, def_id: impl Into<DefId>) -> bool {
2077 let def_id: DefId = def_id.into();
2078 match self.def_kind(def_id) {
2079 DefKind::Impl { of_trait: true } => {
2080 let header = self.impl_trait_header(def_id);
2081 header.constness == hir::Constness::Const
2082 && self.is_const_trait(header.trait_ref.skip_binder().def_id)
2083 }
2084 DefKind::Impl { of_trait: false } => self.constness(def_id) == hir::Constness::Const,
2085 DefKind::Fn | DefKind::Ctor(_, CtorKind::Fn) => {
2086 self.constness(def_id) == hir::Constness::Const
2087 }
2088 DefKind::TraitAlias | DefKind::Trait => self.is_const_trait(def_id),
2089 DefKind::AssocTy => {
2090 let parent_def_id = self.parent(def_id);
2091 match self.def_kind(parent_def_id) {
2092 DefKind::Impl { of_trait: false } => false,
2093 DefKind::Impl { of_trait: true } | DefKind::Trait => {
2094 self.is_conditionally_const(parent_def_id)
2095 }
2096 _ => 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:?}"),
2097 }
2098 }
2099 DefKind::AssocFn => {
2100 let parent_def_id = self.parent(def_id);
2101 match self.def_kind(parent_def_id) {
2102 DefKind::Impl { of_trait: false } => {
2103 self.constness(def_id) == hir::Constness::Const
2104 }
2105 DefKind::Impl { of_trait: true } => {
2106 let Some(trait_method_did) = self.trait_item_of(def_id) else {
2107 return false;
2108 };
2109 self.constness(trait_method_did) == hir::Constness::Const
2110 && self.is_conditionally_const(parent_def_id)
2111 }
2112 DefKind::Trait => {
2113 self.constness(def_id) == hir::Constness::Const
2114 && self.is_conditionally_const(parent_def_id)
2115 }
2116 _ => 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:?}"),
2117 }
2118 }
2119 DefKind::OpaqueTy => match self.opaque_ty_origin(def_id) {
2120 hir::OpaqueTyOrigin::FnReturn { parent, .. } => self.is_conditionally_const(parent),
2121 hir::OpaqueTyOrigin::AsyncFn { .. } => false,
2122 hir::OpaqueTyOrigin::TyAlias { .. } => false,
2124 },
2125 DefKind::Closure => self.constness(def_id) == hir::Constness::Const,
2126 DefKind::Ctor(_, CtorKind::Const)
2127 | DefKind::Mod
2128 | DefKind::Struct
2129 | DefKind::Union
2130 | DefKind::Enum
2131 | DefKind::Variant
2132 | DefKind::TyAlias
2133 | DefKind::ForeignTy
2134 | DefKind::TyParam
2135 | DefKind::Const { .. }
2136 | DefKind::ConstParam
2137 | DefKind::Static { .. }
2138 | DefKind::AssocConst { .. }
2139 | DefKind::Macro(_)
2140 | DefKind::ExternCrate
2141 | DefKind::Use
2142 | DefKind::ForeignMod
2143 | DefKind::AnonConst
2144 | DefKind::InlineConst
2145 | DefKind::Field
2146 | DefKind::LifetimeParam
2147 | DefKind::GlobalAsm
2148 | DefKind::SyntheticCoroutineBody => false,
2149 }
2150 }
2151
2152 #[inline]
2153 pub fn is_const_trait(self, def_id: DefId) -> bool {
2154 self.trait_def(def_id).constness == hir::Constness::Const
2155 }
2156
2157 pub fn impl_method_has_trait_impl_trait_tys(self, def_id: DefId) -> bool {
2158 if self.def_kind(def_id) != DefKind::AssocFn {
2159 return false;
2160 }
2161
2162 let Some(item) = self.opt_associated_item(def_id) else {
2163 return false;
2164 };
2165
2166 let AssocContainer::TraitImpl(Ok(trait_item_def_id)) = item.container else {
2167 return false;
2168 };
2169
2170 !self.associated_types_for_impl_traits_in_associated_fn(trait_item_def_id).is_empty()
2171 }
2172
2173 #[inline]
2188 pub fn fn_abi_of_instance(
2189 self,
2190 query: ty::PseudoCanonicalInput<'tcx, (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>)>,
2191 ) -> Result<&'tcx FnAbi<'tcx, Ty<'tcx>>, &'tcx FnAbiError<'tcx>> {
2192 if self.sess.opts.optimize != OptLevel::No && self.sess.opts.incremental.is_none() {
2195 self.fn_abi_of_instance_raw(query)
2196 } else {
2197 self.fn_abi_of_instance_no_deduced_attrs(query)
2198 }
2199 }
2200}
2201
2202impl<'tcx> hir::attrs::HasAttrs<'tcx, TyCtxt<'tcx>> for DefId {
2205 fn get_attrs(self, tcx: &TyCtxt<'tcx>) -> &'tcx [hir::Attribute] {
2206 if let Some(did) = self.as_local() {
2207 tcx.hir_attrs(tcx.local_def_id_to_hir_id(did))
2208 } else {
2209 tcx.attrs_for_def(self)
2210 }
2211 }
2212}
2213
2214impl<'tcx> hir::attrs::HasAttrs<'tcx, TyCtxt<'tcx>> for LocalDefId {
2215 fn get_attrs(self, tcx: &TyCtxt<'tcx>) -> &'tcx [hir::Attribute] {
2216 tcx.hir_attrs(tcx.local_def_id_to_hir_id(self))
2217 }
2218}
2219
2220impl<'tcx> hir::attrs::HasAttrs<'tcx, TyCtxt<'tcx>> for hir::OwnerId {
2221 fn get_attrs(self, tcx: &TyCtxt<'tcx>) -> &'tcx [hir::Attribute] {
2222 hir::attrs::HasAttrs::get_attrs(self.def_id, tcx)
2223 }
2224}
2225
2226impl<'tcx> hir::attrs::HasAttrs<'tcx, TyCtxt<'tcx>> for hir::HirId {
2227 fn get_attrs(self, tcx: &TyCtxt<'tcx>) -> &'tcx [hir::Attribute] {
2228 tcx.hir_attrs(self)
2229 }
2230}
2231
2232pub fn provide(providers: &mut Providers) {
2233 closure::provide(providers);
2234 context::provide(providers);
2235 erase_regions::provide(providers);
2236 inhabitedness::provide(providers);
2237 util::provide(providers);
2238 print::provide(providers);
2239 super::util::bug::provide(providers);
2240 *providers = Providers {
2241 trait_impls_of: trait_def::trait_impls_of_provider,
2242 incoherent_impls: trait_def::incoherent_impls_provider,
2243 trait_impls_in_crate: trait_def::trait_impls_in_crate_provider,
2244 traits: trait_def::traits_provider,
2245 vtable_allocation: vtable::vtable_allocation_provider,
2246 ..*providers
2247 };
2248}
2249
2250#[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<'__ctx>
::rustc_data_structures::stable_hasher::HashStable<::rustc_middle::ich::StableHashingContext<'__ctx>>
for CrateInherentImpls {
#[inline]
fn hash_stable(&self,
__hcx: &mut ::rustc_middle::ich::StableHashingContext<'__ctx>,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
match *self {
CrateInherentImpls {
inherent_impls: ref __binding_0,
incoherent_impls: ref __binding_1 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable)]
2256pub struct CrateInherentImpls {
2257 pub inherent_impls: FxIndexMap<LocalDefId, Vec<DefId>>,
2258 pub incoherent_impls: FxIndexMap<SimplifiedType, Vec<LocalDefId>>,
2259}
2260
2261#[derive(#[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::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::cmp::PartialOrd::partial_cmp(&self.name, &other.name)
}
}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) {
match *self {
SymbolName { name: __binding_0 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
}
}
}
};TyEncodable, const _: () =
{
impl<'tcx, '__ctx>
::rustc_data_structures::stable_hasher::HashStable<::rustc_middle::ich::StableHashingContext<'__ctx>>
for SymbolName<'tcx> {
#[inline]
fn hash_stable(&self,
__hcx: &mut ::rustc_middle::ich::StableHashingContext<'__ctx>,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
match *self {
SymbolName { name: ref __binding_0 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable)]
2262pub struct SymbolName<'tcx> {
2263 pub name: &'tcx str,
2265}
2266
2267impl<'tcx> SymbolName<'tcx> {
2268 pub fn new(tcx: TyCtxt<'tcx>, name: &str) -> SymbolName<'tcx> {
2269 SymbolName { name: tcx.arena.alloc_str(name) }
2270 }
2271}
2272
2273impl<'tcx> fmt::Display for SymbolName<'tcx> {
2274 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
2275 fmt::Display::fmt(&self.name, fmt)
2276 }
2277}
2278
2279impl<'tcx> fmt::Debug for SymbolName<'tcx> {
2280 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
2281 fmt::Display::fmt(&self.name, fmt)
2282 }
2283}
2284
2285#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for DestructuredAdtConst<'tcx> { }Copy, #[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, '__ctx>
::rustc_data_structures::stable_hasher::HashStable<::rustc_middle::ich::StableHashingContext<'__ctx>>
for DestructuredAdtConst<'tcx> {
#[inline]
fn hash_stable(&self,
__hcx: &mut ::rustc_middle::ich::StableHashingContext<'__ctx>,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
match *self {
DestructuredAdtConst {
variant: ref __binding_0, fields: ref __binding_1 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable)]
2287pub struct DestructuredAdtConst<'tcx> {
2288 pub variant: VariantIdx,
2289 pub fields: &'tcx [ty::Const<'tcx>],
2290}
2291
2292pub fn fnc_typetrees<'tcx>(tcx: TyCtxt<'tcx>, fn_ty: Ty<'tcx>) -> FncTree {
2296 if tcx.sess.opts.unstable_opts.autodiff.contains(&rustc_session::config::AutoDiff::NoTT) {
2298 return FncTree { args: ::alloc::vec::Vec::new()vec![], ret: TypeTree::new() };
2299 }
2300
2301 if !fn_ty.is_fn() {
2303 return FncTree { args: ::alloc::vec::Vec::new()vec![], ret: TypeTree::new() };
2304 }
2305
2306 let fn_sig = fn_ty.fn_sig(tcx);
2308 let sig = tcx.instantiate_bound_regions_with_erased(fn_sig);
2309
2310 let mut args = ::alloc::vec::Vec::new()vec![];
2312 for ty in sig.inputs().iter() {
2313 let type_tree = typetree_from_ty(tcx, *ty);
2314 args.push(type_tree);
2315 }
2316
2317 let ret = typetree_from_ty(tcx, sig.output());
2319
2320 FncTree { args, ret }
2321}
2322
2323pub fn typetree_from_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> TypeTree {
2326 let mut visited = Vec::new();
2327 typetree_from_ty_inner(tcx, ty, 0, &mut visited)
2328}
2329
2330const MAX_TYPETREE_DEPTH: usize = 6;
2333
2334fn typetree_from_ty_inner<'tcx>(
2336 tcx: TyCtxt<'tcx>,
2337 ty: Ty<'tcx>,
2338 depth: usize,
2339 visited: &mut Vec<Ty<'tcx>>,
2340) -> TypeTree {
2341 if depth >= MAX_TYPETREE_DEPTH {
2342 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_middle/src/ty/mod.rs:2342",
"rustc_middle::ty", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/ty/mod.rs"),
::tracing_core::__macro_support::Option::Some(2342u32),
::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::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("typetree depth limit {0} reached for type: {1}",
MAX_TYPETREE_DEPTH, ty) as &dyn Value))])
});
} else { ; }
};trace!("typetree depth limit {} reached for type: {}", MAX_TYPETREE_DEPTH, ty);
2343 return TypeTree::new();
2344 }
2345
2346 if visited.contains(&ty) {
2347 return TypeTree::new();
2348 }
2349
2350 visited.push(ty);
2351 let result = typetree_from_ty_impl(tcx, ty, depth, visited);
2352 visited.pop();
2353 result
2354}
2355
2356fn typetree_from_ty_impl<'tcx>(
2358 tcx: TyCtxt<'tcx>,
2359 ty: Ty<'tcx>,
2360 depth: usize,
2361 visited: &mut Vec<Ty<'tcx>>,
2362) -> TypeTree {
2363 typetree_from_ty_impl_inner(tcx, ty, depth, visited, false)
2364}
2365
2366fn typetree_from_ty_impl_inner<'tcx>(
2368 tcx: TyCtxt<'tcx>,
2369 ty: Ty<'tcx>,
2370 depth: usize,
2371 visited: &mut Vec<Ty<'tcx>>,
2372 is_reference_target: bool,
2373) -> TypeTree {
2374 if ty.is_scalar() {
2375 let (kind, size) = if ty.is_integral() || ty.is_char() || ty.is_bool() {
2376 (Kind::Integer, ty.primitive_size(tcx).bytes_usize())
2377 } else if ty.is_floating_point() {
2378 match ty {
2379 x if x == tcx.types.f16 => (Kind::Half, 2),
2380 x if x == tcx.types.f32 => (Kind::Float, 4),
2381 x if x == tcx.types.f64 => (Kind::Double, 8),
2382 x if x == tcx.types.f128 => (Kind::F128, 16),
2383 _ => (Kind::Integer, 0),
2384 }
2385 } else {
2386 (Kind::Integer, 0)
2387 };
2388
2389 let offset = if is_reference_target && !ty.is_array() { 0 } else { -1 };
2392 return TypeTree(::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[Type { offset, size, kind, child: TypeTree::new() }]))vec![Type { offset, size, kind, child: TypeTree::new() }]);
2393 }
2394
2395 if ty.is_ref() || ty.is_raw_ptr() || ty.is_box() {
2396 let Some(inner_ty) = ty.builtin_deref(true) else {
2397 return TypeTree::new();
2398 };
2399
2400 let child = typetree_from_ty_impl_inner(tcx, inner_ty, depth + 1, visited, true);
2401 return TypeTree(::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[Type {
offset: -1,
size: tcx.data_layout.pointer_size().bytes_usize(),
kind: Kind::Pointer,
child,
}]))vec![Type {
2402 offset: -1,
2403 size: tcx.data_layout.pointer_size().bytes_usize(),
2404 kind: Kind::Pointer,
2405 child,
2406 }]);
2407 }
2408
2409 if ty.is_array() {
2410 if let ty::Array(element_ty, len_const) = ty.kind() {
2411 let len = len_const.try_to_target_usize(tcx).unwrap_or(0);
2412 if len == 0 {
2413 return TypeTree::new();
2414 }
2415 let element_tree =
2416 typetree_from_ty_impl_inner(tcx, *element_ty, depth + 1, visited, false);
2417 let mut types = Vec::new();
2418 for elem_type in &element_tree.0 {
2419 types.push(Type {
2420 offset: -1,
2421 size: elem_type.size,
2422 kind: elem_type.kind,
2423 child: elem_type.child.clone(),
2424 });
2425 }
2426
2427 return TypeTree(types);
2428 }
2429 }
2430
2431 if ty.is_slice() {
2432 if let ty::Slice(element_ty) = ty.kind() {
2433 let element_tree =
2434 typetree_from_ty_impl_inner(tcx, *element_ty, depth + 1, visited, false);
2435 return element_tree;
2436 }
2437 }
2438
2439 if let ty::Tuple(tuple_types) = ty.kind() {
2440 if tuple_types.is_empty() {
2441 return TypeTree::new();
2442 }
2443
2444 let mut types = Vec::new();
2445 let mut current_offset = 0;
2446
2447 for tuple_ty in tuple_types.iter() {
2448 let element_tree =
2449 typetree_from_ty_impl_inner(tcx, tuple_ty, depth + 1, visited, false);
2450
2451 let element_layout = tcx
2452 .layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(tuple_ty))
2453 .ok()
2454 .map(|layout| layout.size.bytes_usize())
2455 .unwrap_or(0);
2456
2457 for elem_type in &element_tree.0 {
2458 types.push(Type {
2459 offset: if elem_type.offset == -1 {
2460 current_offset as isize
2461 } else {
2462 current_offset as isize + elem_type.offset
2463 },
2464 size: elem_type.size,
2465 kind: elem_type.kind,
2466 child: elem_type.child.clone(),
2467 });
2468 }
2469
2470 current_offset += element_layout;
2471 }
2472
2473 return TypeTree(types);
2474 }
2475
2476 if let ty::Adt(adt_def, args) = ty.kind() {
2477 if adt_def.is_struct() {
2478 let struct_layout =
2479 tcx.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(ty));
2480 if let Ok(layout) = struct_layout {
2481 let mut types = Vec::new();
2482
2483 for (field_idx, field_def) in adt_def.all_fields().enumerate() {
2484 let field_ty = field_def.ty(tcx, args);
2485 let field_tree =
2486 typetree_from_ty_impl_inner(tcx, field_ty, depth + 1, visited, false);
2487
2488 let field_offset = layout.fields.offset(field_idx).bytes_usize();
2489
2490 for elem_type in &field_tree.0 {
2491 types.push(Type {
2492 offset: if elem_type.offset == -1 {
2493 field_offset as isize
2494 } else {
2495 field_offset as isize + elem_type.offset
2496 },
2497 size: elem_type.size,
2498 kind: elem_type.kind,
2499 child: elem_type.child.clone(),
2500 });
2501 }
2502 }
2503
2504 return TypeTree(types);
2505 }
2506 }
2507 }
2508
2509 TypeTree::new()
2510}