1pub mod map;
6pub mod nested_filter;
7pub mod place;
8
9use rustc_data_structures::fingerprint::Fingerprint;
10use rustc_data_structures::sorted_map::SortedMap;
11use rustc_data_structures::stable_hash::{StableHash, StableHasher};
12use rustc_data_structures::steal::Steal;
13use rustc_data_structures::sync::{DynSend, DynSync, try_par_for_each_in};
14use rustc_hir::def::{DefKind, Res};
15use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdMap, LocalModDefId};
16use rustc_hir::lints::DelayedLints;
17use rustc_hir::*;
18use rustc_macros::{Decodable, Encodable, StableHash};
19use rustc_span::{ErrorGuaranteed, ExpnId, Span};
20
21use crate::query::Providers;
22use crate::ty::TyCtxt;
23
24#[derive(#[automatically_derived]
impl ::core::fmt::Debug for ModuleItems {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
let names: &'static _ =
&["add_root", "submodules", "free_items", "trait_items",
"impl_items", "foreign_items", "opaques", "body_owners",
"nested_bodies", "eiis", "proc_macro_decls"];
let values: &[&dyn ::core::fmt::Debug] =
&[&self.add_root, &self.submodules, &self.free_items,
&self.trait_items, &self.impl_items, &self.foreign_items,
&self.opaques, &self.body_owners, &self.nested_bodies,
&self.eiis, &&self.proc_macro_decls];
::core::fmt::Formatter::debug_struct_fields_finish(f, "ModuleItems",
names, values)
}
}Debug, const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for ModuleItems
{
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
ModuleItems {
add_root: ref __binding_0,
submodules: ref __binding_1,
free_items: ref __binding_2,
trait_items: ref __binding_3,
impl_items: ref __binding_4,
foreign_items: ref __binding_5,
opaques: ref __binding_6,
body_owners: ref __binding_7,
nested_bodies: ref __binding_8,
eiis: ref __binding_9,
proc_macro_decls: ref __binding_10 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
{ __binding_2.stable_hash(__hcx, __hasher); }
{ __binding_3.stable_hash(__hcx, __hasher); }
{ __binding_4.stable_hash(__hcx, __hasher); }
{ __binding_5.stable_hash(__hcx, __hasher); }
{ __binding_6.stable_hash(__hcx, __hasher); }
{ __binding_7.stable_hash(__hcx, __hasher); }
{ __binding_8.stable_hash(__hcx, __hasher); }
{ __binding_9.stable_hash(__hcx, __hasher); }
{ __binding_10.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for ModuleItems {
fn encode(&self, __encoder: &mut __E) {
match *self {
ModuleItems {
add_root: ref __binding_0,
submodules: ref __binding_1,
free_items: ref __binding_2,
trait_items: ref __binding_3,
impl_items: ref __binding_4,
foreign_items: ref __binding_5,
opaques: ref __binding_6,
body_owners: ref __binding_7,
nested_bodies: ref __binding_8,
eiis: ref __binding_9,
proc_macro_decls: ref __binding_10 } => {
::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);
::rustc_serialize::Encodable::<__E>::encode(__binding_7,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_8,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_9,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_10,
__encoder);
}
}
}
}
};Encodable, const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for ModuleItems {
fn decode(__decoder: &mut __D) -> Self {
ModuleItems {
add_root: ::rustc_serialize::Decodable::decode(__decoder),
submodules: ::rustc_serialize::Decodable::decode(__decoder),
free_items: ::rustc_serialize::Decodable::decode(__decoder),
trait_items: ::rustc_serialize::Decodable::decode(__decoder),
impl_items: ::rustc_serialize::Decodable::decode(__decoder),
foreign_items: ::rustc_serialize::Decodable::decode(__decoder),
opaques: ::rustc_serialize::Decodable::decode(__decoder),
body_owners: ::rustc_serialize::Decodable::decode(__decoder),
nested_bodies: ::rustc_serialize::Decodable::decode(__decoder),
eiis: ::rustc_serialize::Decodable::decode(__decoder),
proc_macro_decls: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};Decodable)]
27pub struct ModuleItems {
28 add_root: bool,
31 submodules: Box<[OwnerId]>,
32 free_items: Box<[ItemId]>,
33 trait_items: Box<[TraitItemId]>,
34 impl_items: Box<[ImplItemId]>,
35 foreign_items: Box<[ForeignItemId]>,
36 opaques: Box<[LocalDefId]>,
37 body_owners: Box<[LocalDefId]>,
38 nested_bodies: Box<[LocalDefId]>,
39
40 eiis: Box<[LocalDefId]>,
42
43 proc_macro_decls: Option<LocalDefId>,
45}
46
47impl ModuleItems {
48 pub fn free_items(&self) -> impl Iterator<Item = ItemId> {
55 self.free_items.iter().copied()
56 }
57
58 pub fn trait_items(&self) -> impl Iterator<Item = TraitItemId> {
59 self.trait_items.iter().copied()
60 }
61
62 #[inline]
63 pub fn proc_macro_decls(&self) -> Option<LocalDefId> {
64 self.proc_macro_decls
65 }
66
67 pub fn eiis(&self) -> impl Iterator<Item = LocalDefId> {
68 self.eiis.iter().copied()
69 }
70
71 pub fn impl_items(&self) -> impl Iterator<Item = ImplItemId> {
74 self.impl_items.iter().copied()
75 }
76
77 pub fn foreign_items(&self) -> impl Iterator<Item = ForeignItemId> {
78 self.foreign_items.iter().copied()
79 }
80
81 pub fn owners(&self) -> impl Iterator<Item = OwnerId> {
82 self.add_root
83 .then_some(CRATE_OWNER_ID)
84 .into_iter()
85 .chain(self.free_items.iter().map(|id| id.owner_id))
86 .chain(self.trait_items.iter().map(|id| id.owner_id))
87 .chain(self.impl_items.iter().map(|id| id.owner_id))
88 .chain(self.foreign_items.iter().map(|id| id.owner_id))
89 }
90
91 pub fn opaques(&self) -> impl Iterator<Item = LocalDefId> {
92 self.opaques.iter().copied()
93 }
94
95 pub fn nested_bodies(&self) -> impl Iterator<Item = LocalDefId> {
97 self.nested_bodies.iter().copied()
98 }
99
100 pub fn definitions(&self) -> impl Iterator<Item = LocalDefId> {
101 self.owners().map(|id| id.def_id)
102 }
103
104 pub fn par_nested_bodies(
106 &self,
107 f: impl Fn(LocalDefId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,
108 ) -> Result<(), ErrorGuaranteed> {
109 try_par_for_each_in(&self.nested_bodies[..], |&&id| f(id))
110 }
111
112 pub fn par_items(
113 &self,
114 f: impl Fn(ItemId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,
115 ) -> Result<(), ErrorGuaranteed> {
116 try_par_for_each_in(&self.free_items[..], |&&id| f(id))
117 }
118
119 pub fn par_trait_items(
120 &self,
121 f: impl Fn(TraitItemId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,
122 ) -> Result<(), ErrorGuaranteed> {
123 try_par_for_each_in(&self.trait_items[..], |&&id| f(id))
124 }
125
126 pub fn par_impl_items(
127 &self,
128 f: impl Fn(ImplItemId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,
129 ) -> Result<(), ErrorGuaranteed> {
130 try_par_for_each_in(&self.impl_items[..], |&&id| f(id))
131 }
132
133 pub fn par_foreign_items(
134 &self,
135 f: impl Fn(ForeignItemId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,
136 ) -> Result<(), ErrorGuaranteed> {
137 try_par_for_each_in(&self.foreign_items[..], |&&id| f(id))
138 }
139
140 pub fn par_opaques(
141 &self,
142 f: impl Fn(LocalDefId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,
143 ) -> Result<(), ErrorGuaranteed> {
144 try_par_for_each_in(&self.opaques[..], |&&id| f(id))
145 }
146}
147
148impl<'tcx> TyCtxt<'tcx> {
149 pub fn parent_module(self, id: HirId) -> LocalModDefId {
150 if !id.is_owner() && self.def_kind(id.owner) == DefKind::Mod {
151 LocalModDefId::new_unchecked(id.owner.def_id)
152 } else {
153 self.parent_module_from_def_id(id.owner.def_id)
154 }
155 }
156
157 pub fn parent_module_from_def_id(self, mut id: LocalDefId) -> LocalModDefId {
158 while let Some(parent) = self.opt_local_parent(id) {
159 id = parent;
160 if self.def_kind(id) == DefKind::Mod {
161 break;
162 }
163 }
164 LocalModDefId::new_unchecked(id)
165 }
166
167 pub fn is_foreign_item(self, def_id: impl Into<DefId>) -> bool {
169 self.opt_parent(def_id.into())
170 .is_some_and(|parent| #[allow(non_exhaustive_omitted_patterns)] match self.def_kind(parent) {
DefKind::ForeignMod => true,
_ => false,
}matches!(self.def_kind(parent), DefKind::ForeignMod))
171 }
172
173 pub fn hash_owner_nodes(
174 self,
175 node: OwnerNode<'_>,
176 bodies: &SortedMap<ItemLocalId, &Body<'_>>,
177 attrs: &SortedMap<ItemLocalId, &[Attribute]>,
178 define_opaque: Option<&[(Span, LocalDefId)]>,
179 ) -> Hashes {
180 if !self.needs_hir_hash() {
181 return Hashes { bodies_hash: None, attrs_hash: None };
182 }
183
184 self.with_stable_hashing_context(|mut hcx| {
185 let mut stable_hasher = StableHasher::new();
186 node.stable_hash(&mut hcx, &mut stable_hasher);
187 bodies.stable_hash(&mut hcx, &mut stable_hasher);
189 let h1 = stable_hasher.finish();
190
191 let mut stable_hasher = StableHasher::new();
192 attrs.stable_hash(&mut hcx, &mut stable_hasher);
193
194 define_opaque.stable_hash(&mut hcx, &mut stable_hasher);
196
197 let h2 = stable_hasher.finish();
198
199 Hashes { bodies_hash: Some(h1), attrs_hash: Some(h2) }
200 })
201 }
202
203 pub fn qpath_is_lang_item(self, qpath: QPath<'_>, lang_item: LangItem) -> bool {
204 self.qpath_lang_item(qpath) == Some(lang_item)
205 }
206
207 pub fn qpath_lang_item(self, qpath: QPath<'_>) -> Option<LangItem> {
209 if let QPath::Resolved(_, path) = qpath
210 && let Res::Def(_, def_id) = path.res
211 {
212 return self.lang_items().from_def_id(def_id);
213 }
214 None
215 }
216
217 pub fn expr_guaranteed_to_constitute_read_for_never(self, expr: &Expr<'_>) -> bool {
229 if !expr.is_syntactic_place_expr() {
235 return true;
236 }
237
238 let parent_node = self.parent_hir_node(expr.hir_id);
239 match parent_node {
240 Node::Expr(parent_expr) => {
241 match parent_expr.kind {
242 ExprKind::AddrOf(..) | ExprKind::Field(..) => false,
246
247 ExprKind::Type(..) | ExprKind::UnsafeBinderCast(..) => {
250 self.expr_guaranteed_to_constitute_read_for_never(parent_expr)
251 }
252
253 ExprKind::Assign(lhs, _, _) => {
254 expr.hir_id != lhs.hir_id
256 }
257
258 ExprKind::Match(scrutinee, arms, _) => {
261 {
match (&scrutinee.hir_id, &expr.hir_id) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(scrutinee.hir_id, expr.hir_id);
262 arms.iter().all(|arm| arm.pat.is_guaranteed_to_constitute_read_for_never())
263 }
264 ExprKind::Let(LetExpr { init, pat, .. }) => {
265 {
match (&init.hir_id, &expr.hir_id) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(init.hir_id, expr.hir_id);
266 pat.is_guaranteed_to_constitute_read_for_never()
267 }
268
269 ExprKind::Array(_)
271 | ExprKind::Call(_, _)
272 | ExprKind::Use(_, _)
273 | ExprKind::MethodCall(_, _, _, _)
274 | ExprKind::Tup(_)
275 | ExprKind::Binary(_, _, _)
276 | ExprKind::Unary(_, _)
277 | ExprKind::Cast(_, _)
278 | ExprKind::DropTemps(_)
279 | ExprKind::If(_, _, _)
280 | ExprKind::Closure(_)
281 | ExprKind::Block(_, _)
282 | ExprKind::AssignOp(_, _, _)
283 | ExprKind::Index(_, _, _)
284 | ExprKind::Break(_, _)
285 | ExprKind::Ret(_)
286 | ExprKind::Become(_)
287 | ExprKind::InlineAsm(_)
288 | ExprKind::Struct(_, _, _)
289 | ExprKind::Repeat(_, _)
290 | ExprKind::Yield(_, _) => true,
291
292 ExprKind::ConstBlock(_)
294 | ExprKind::Loop(_, _, _, _)
295 | ExprKind::Lit(_)
296 | ExprKind::Path(_)
297 | ExprKind::Continue(_)
298 | ExprKind::OffsetOf(_, _)
299 | ExprKind::Err(_) => {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("no sub-expr expected for {0:?}", expr.kind)));
}unreachable!("no sub-expr expected for {:?}", expr.kind),
300 }
301 }
302
303 Node::LetStmt(LetStmt { init: Some(target), pat, .. }) => {
306 {
match (&target.hir_id, &expr.hir_id) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(target.hir_id, expr.hir_id);
307 pat.is_guaranteed_to_constitute_read_for_never()
308 }
309
310 Node::Block(_)
312 | Node::Arm(_)
313 | Node::ExprField(_)
314 | Node::AnonConst(_)
315 | Node::ConstBlock(_)
316 | Node::ConstArg(_)
317 | Node::Stmt(_)
318 | Node::Item(Item { kind: ItemKind::Const(..) | ItemKind::Static(..), .. })
319 | Node::TraitItem(TraitItem { kind: TraitItemKind::Const(..), .. })
320 | Node::ImplItem(ImplItem { kind: ImplItemKind::Const(..), .. }) => true,
321
322 Node::TyPat(_) | Node::Pat(_) => {
323 self.dcx().span_delayed_bug(expr.span, "place expr not allowed in pattern");
324 true
325 }
326
327 Node::Param(_)
329 | Node::Item(_)
330 | Node::ForeignItem(_)
331 | Node::TraitItem(_)
332 | Node::ImplItem(_)
333 | Node::Variant(_)
334 | Node::Field(_)
335 | Node::PathSegment(_)
336 | Node::Ty(_)
337 | Node::AssocItemConstraint(_)
338 | Node::TraitRef(_)
339 | Node::PatField(_)
340 | Node::PatExpr(_)
341 | Node::LetStmt(_)
342 | Node::Synthetic
343 | Node::Err(_)
344 | Node::Ctor(_)
345 | Node::Lifetime(_)
346 | Node::GenericParam(_)
347 | Node::Crate(_)
348 | Node::Infer(_)
349 | Node::WherePredicate(_)
350 | Node::PreciseCapturingNonLifetimeArg(_)
351 | Node::ConstArgExprField(_)
352 | Node::OpaqueTy(_) => {
353 {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("no sub-expr expected for {0:?}", parent_node)));
}unreachable!("no sub-expr expected for {parent_node:?}")
354 }
355 }
356 }
357
358 #[inline]
359 fn hir_owner_parent_impl(self, owner_id: OwnerId) -> HirId {
360 self.opt_local_parent(owner_id.def_id).map_or(CRATE_HIR_ID, |parent_def_id| {
361 let parent_owner_id = self.local_def_id_to_hir_id(parent_def_id).owner;
362 HirId {
363 owner: parent_owner_id,
364 local_id: self
365 .hir_owner(parent_owner_id.def_id)
366 .unwrap()
367 .parenting
368 .get(&owner_id.def_id)
369 .copied()
370 .unwrap_or(ItemLocalId::ZERO),
371 }
372 })
373 }
374
375 #[inline]
378 pub fn hir_owner_parent(self, owner_id: OwnerId) -> HirId {
379 if self.dep_graph.is_fully_enabled() {
380 self.hir_owner_parent_q(owner_id)
381 } else {
382 self.hir_owner_parent_impl(owner_id)
383 }
384 }
385}
386
387#[derive(#[automatically_derived]
impl ::core::clone::Clone for Hashes {
#[inline]
fn clone(&self) -> Hashes {
let _: ::core::clone::AssertParamIsClone<Option<Fingerprint>>;
let _: ::core::clone::AssertParamIsClone<Option<Fingerprint>>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for Hashes { }Copy, #[automatically_derived]
impl ::core::fmt::Debug for Hashes {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f, "Hashes",
"bodies_hash", &self.bodies_hash, "attrs_hash", &&self.attrs_hash)
}
}Debug)]
389pub struct Hashes {
390 pub bodies_hash: Option<Fingerprint>,
391 pub attrs_hash: Option<Fingerprint>,
392}
393
394#[derive(#[automatically_derived]
impl<'tcx> ::core::clone::Clone for ProjectedOwnerInfo<'tcx> {
#[inline]
fn clone(&self) -> ProjectedOwnerInfo<'tcx> {
let _: ::core::clone::AssertParamIsClone<&'tcx OwnerNodes<'tcx>>;
let _:
::core::clone::AssertParamIsClone<&'tcx LocalDefIdMap<ItemLocalId>>;
let _:
::core::clone::AssertParamIsClone<&'tcx ItemLocalMap<&'tcx [TraitCandidate<'tcx>]>>;
let _: ::core::clone::AssertParamIsClone<&'tcx Steal<DelayedLints>>;
*self
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::marker::Copy for ProjectedOwnerInfo<'tcx> { }Copy, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for ProjectedOwnerInfo<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field4_finish(f,
"ProjectedOwnerInfo", "nodes", &self.nodes, "parenting",
&self.parenting, "trait_map", &self.trait_map, "delayed_lints",
&&self.delayed_lints)
}
}Debug, const _: () =
{
impl<'tcx> ::rustc_data_structures::stable_hash::StableHash for
ProjectedOwnerInfo<'tcx> {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
ProjectedOwnerInfo {
nodes: ref __binding_0,
parenting: ref __binding_1,
trait_map: ref __binding_2,
delayed_lints: ref __binding_3 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
{ __binding_2.stable_hash(__hcx, __hasher); }
{}
}
}
}
}
};StableHash)]
401pub struct ProjectedOwnerInfo<'tcx> {
402 nodes: &'tcx OwnerNodes<'tcx>,
403 parenting: &'tcx LocalDefIdMap<ItemLocalId>,
404 trait_map: &'tcx ItemLocalMap<&'tcx [TraitCandidate<'tcx>]>,
405
406 #[stable_hash(ignore)]
407 delayed_lints: &'tcx Steal<DelayedLints>,
408}
409
410impl<'tcx> ProjectedOwnerInfo<'tcx> {
411 pub fn new(
412 nodes: &'tcx OwnerNodes<'tcx>,
413 parenting: &'tcx LocalDefIdMap<ItemLocalId>,
414 trait_map: &'tcx ItemLocalMap<&'tcx [TraitCandidate<'tcx>]>,
415 delayed_lints: &'tcx Steal<DelayedLints>,
416 ) -> ProjectedOwnerInfo<'tcx> {
417 ProjectedOwnerInfo { nodes, parenting, trait_map, delayed_lints }
418 }
419}
420
421#[derive(#[automatically_derived]
impl<'tcx> ::core::clone::Clone for ProjectedMaybeOwner<'tcx> {
#[inline]
fn clone(&self) -> ProjectedMaybeOwner<'tcx> {
let _: ::core::clone::AssertParamIsClone<ProjectedOwnerInfo<'tcx>>;
let _: ::core::clone::AssertParamIsClone<HirId>;
*self
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::marker::Copy for ProjectedMaybeOwner<'tcx> { }Copy, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for ProjectedMaybeOwner<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
ProjectedMaybeOwner::Owner(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Owner",
&__self_0),
ProjectedMaybeOwner::NonOwner(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"NonOwner", &__self_0),
}
}
}Debug, const _: () =
{
impl<'tcx> ::rustc_data_structures::stable_hash::StableHash for
ProjectedMaybeOwner<'tcx> {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
::std::mem::discriminant(self).stable_hash(__hcx, __hasher);
match *self {
ProjectedMaybeOwner::Owner(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
ProjectedMaybeOwner::NonOwner(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash)]
422pub enum ProjectedMaybeOwner<'tcx> {
423 Owner(ProjectedOwnerInfo<'tcx>),
424 NonOwner(HirId),
425}
426
427impl<'tcx> ProjectedMaybeOwner<'tcx> {
428 pub fn new(value: MaybeOwner<'tcx>) -> Self {
429 match value {
430 MaybeOwner::Owner(o) => ProjectedMaybeOwner::Owner(ProjectedOwnerInfo {
431 nodes: &o.nodes,
432 parenting: &o.parenting,
433 trait_map: &o.trait_map,
434 delayed_lints: &o.delayed_lints,
435 }),
436 MaybeOwner::NonOwner(hir_id) => ProjectedMaybeOwner::NonOwner(hir_id),
437 }
438 }
439
440 pub fn as_owner(&self) -> Option<&ProjectedOwnerInfo<'tcx>> {
441 match self {
442 ProjectedMaybeOwner::Owner(i) => Some(i),
443 ProjectedMaybeOwner::NonOwner(_) => None,
444 }
445 }
446
447 pub fn unwrap(&'tcx self) -> &'tcx ProjectedOwnerInfo<'tcx> {
448 self.as_owner().unwrap_or_else(|| { ::core::panicking::panic_fmt(format_args!("Not a HIR owner")); }panic!("Not a HIR owner"))
449 }
450}
451
452pub fn provide(providers: &mut Providers) {
453 providers.hir_crate_items = map::hir_crate_items;
454 providers.crate_hash = map::crate_hash;
455 providers.hir_module_items = map::hir_module_items;
456 providers.hir_attr_map =
457 |tcx, id| tcx.lower_to_hir(id).as_owner().map_or(AttributeMap::EMPTY, |o| &o.attrs);
458 providers.hir_owner = |tcx, def_id| ProjectedMaybeOwner::new(tcx.lower_to_hir(def_id));
459 providers.hir_owner_parent_q = |tcx, owner_id| tcx.hir_owner_parent_impl(owner_id);
460 providers.def_span = |tcx, def_id| tcx.hir_span(tcx.local_def_id_to_hir_id(def_id));
461 providers.def_ident_span = |tcx, def_id| {
462 let hir_id = tcx.local_def_id_to_hir_id(def_id);
463 tcx.hir_opt_ident_span(hir_id)
464 };
465 providers.ty_span = |tcx, def_id| {
466 let node = tcx.hir_node_by_def_id(def_id);
467 match node.ty() {
468 Some(ty) => ty.span,
469 None => crate::util::bug::bug_fmt(format_args!("{0:?} doesn\'t have a type: {1:#?}",
def_id, node))bug!("{def_id:?} doesn't have a type: {node:#?}"),
470 }
471 };
472 providers.fn_arg_idents = |tcx, def_id| {
473 let node = tcx.hir_node_by_def_id(def_id);
474 if let Some(body_id) = node.body_id() {
475 tcx.arena.alloc_from_iter(tcx.hir_body_param_idents(body_id))
476 } else if let Node::TraitItem(&TraitItem {
477 kind: TraitItemKind::Fn(_, TraitFn::Required(idents)),
478 ..
479 })
480 | Node::ForeignItem(&ForeignItem {
481 kind: ForeignItemKind::Fn(_, idents, _),
482 ..
483 }) = node
484 {
485 idents
486 } else {
487 crate::util::bug::span_bug_fmt(tcx.hir_span(tcx.local_def_id_to_hir_id(def_id)),
format_args!("fn_arg_idents: unexpected item {0:?}", def_id));span_bug!(
488 tcx.hir_span(tcx.local_def_id_to_hir_id(def_id)),
489 "fn_arg_idents: unexpected item {:?}",
490 def_id
491 );
492 }
493 };
494 providers.all_local_trait_impls = |tcx, ()| &tcx.resolutions(()).trait_impls;
495 providers.local_trait_impls =
496 |tcx, trait_id| tcx.resolutions(()).trait_impls.get(&trait_id).map_or(&[], |xs| &xs[..]);
497 providers.expn_that_defined =
498 |tcx, id| tcx.resolutions(()).expn_that_defined.get(&id).copied().unwrap_or(ExpnId::root());
499}