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", "delayed_lint_items", "eiis"];
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.delayed_lint_items, &&self.eiis];
::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,
delayed_lint_items: ref __binding_9,
eiis: 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,
delayed_lint_items: ref __binding_9,
eiis: 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),
delayed_lint_items: ::rustc_serialize::Decodable::decode(__decoder),
eiis: ::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 delayed_lint_items: Box<[OwnerId]>,
41
42 eiis: Box<[LocalDefId]>,
44}
45
46impl ModuleItems {
47 pub fn free_items(&self) -> impl Iterator<Item = ItemId> {
54 self.free_items.iter().copied()
55 }
56
57 pub fn trait_items(&self) -> impl Iterator<Item = TraitItemId> {
58 self.trait_items.iter().copied()
59 }
60
61 pub fn delayed_lint_items(&self) -> impl Iterator<Item = OwnerId> {
62 self.delayed_lint_items.iter().copied()
63 }
64
65 pub fn eiis(&self) -> impl Iterator<Item = LocalDefId> {
66 self.eiis.iter().copied()
67 }
68
69 pub fn impl_items(&self) -> impl Iterator<Item = ImplItemId> {
72 self.impl_items.iter().copied()
73 }
74
75 pub fn foreign_items(&self) -> impl Iterator<Item = ForeignItemId> {
76 self.foreign_items.iter().copied()
77 }
78
79 pub fn owners(&self) -> impl Iterator<Item = OwnerId> {
80 self.add_root
81 .then_some(CRATE_OWNER_ID)
82 .into_iter()
83 .chain(self.free_items.iter().map(|id| id.owner_id))
84 .chain(self.trait_items.iter().map(|id| id.owner_id))
85 .chain(self.impl_items.iter().map(|id| id.owner_id))
86 .chain(self.foreign_items.iter().map(|id| id.owner_id))
87 }
88
89 pub fn opaques(&self) -> impl Iterator<Item = LocalDefId> {
90 self.opaques.iter().copied()
91 }
92
93 pub fn nested_bodies(&self) -> impl Iterator<Item = LocalDefId> {
95 self.nested_bodies.iter().copied()
96 }
97
98 pub fn definitions(&self) -> impl Iterator<Item = LocalDefId> {
99 self.owners().map(|id| id.def_id)
100 }
101
102 pub fn par_nested_bodies(
104 &self,
105 f: impl Fn(LocalDefId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,
106 ) -> Result<(), ErrorGuaranteed> {
107 try_par_for_each_in(&self.nested_bodies[..], |&&id| f(id))
108 }
109
110 pub fn par_items(
111 &self,
112 f: impl Fn(ItemId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,
113 ) -> Result<(), ErrorGuaranteed> {
114 try_par_for_each_in(&self.free_items[..], |&&id| f(id))
115 }
116
117 pub fn par_trait_items(
118 &self,
119 f: impl Fn(TraitItemId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,
120 ) -> Result<(), ErrorGuaranteed> {
121 try_par_for_each_in(&self.trait_items[..], |&&id| f(id))
122 }
123
124 pub fn par_impl_items(
125 &self,
126 f: impl Fn(ImplItemId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,
127 ) -> Result<(), ErrorGuaranteed> {
128 try_par_for_each_in(&self.impl_items[..], |&&id| f(id))
129 }
130
131 pub fn par_foreign_items(
132 &self,
133 f: impl Fn(ForeignItemId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,
134 ) -> Result<(), ErrorGuaranteed> {
135 try_par_for_each_in(&self.foreign_items[..], |&&id| f(id))
136 }
137
138 pub fn par_opaques(
139 &self,
140 f: impl Fn(LocalDefId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,
141 ) -> Result<(), ErrorGuaranteed> {
142 try_par_for_each_in(&self.opaques[..], |&&id| f(id))
143 }
144}
145
146impl<'tcx> TyCtxt<'tcx> {
147 pub fn parent_module(self, id: HirId) -> LocalModDefId {
148 if !id.is_owner() && self.def_kind(id.owner) == DefKind::Mod {
149 LocalModDefId::new_unchecked(id.owner.def_id)
150 } else {
151 self.parent_module_from_def_id(id.owner.def_id)
152 }
153 }
154
155 pub fn parent_module_from_def_id(self, mut id: LocalDefId) -> LocalModDefId {
156 while let Some(parent) = self.opt_local_parent(id) {
157 id = parent;
158 if self.def_kind(id) == DefKind::Mod {
159 break;
160 }
161 }
162 LocalModDefId::new_unchecked(id)
163 }
164
165 pub fn is_foreign_item(self, def_id: impl Into<DefId>) -> bool {
167 self.opt_parent(def_id.into())
168 .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))
169 }
170
171 pub fn hash_owner_nodes(
172 self,
173 node: OwnerNode<'_>,
174 bodies: &SortedMap<ItemLocalId, &Body<'_>>,
175 attrs: &SortedMap<ItemLocalId, &[Attribute]>,
176 define_opaque: Option<&[(Span, LocalDefId)]>,
177 ) -> Hashes {
178 if !self.needs_hir_hash() {
179 return Hashes { bodies_hash: None, attrs_hash: None };
180 }
181
182 self.with_stable_hashing_context(|mut hcx| {
183 let mut stable_hasher = StableHasher::new();
184 node.stable_hash(&mut hcx, &mut stable_hasher);
185 bodies.stable_hash(&mut hcx, &mut stable_hasher);
187 let h1 = stable_hasher.finish();
188
189 let mut stable_hasher = StableHasher::new();
190 attrs.stable_hash(&mut hcx, &mut stable_hasher);
191
192 define_opaque.stable_hash(&mut hcx, &mut stable_hasher);
194
195 let h2 = stable_hasher.finish();
196
197 Hashes { bodies_hash: Some(h1), attrs_hash: Some(h2) }
198 })
199 }
200
201 pub fn qpath_is_lang_item(self, qpath: QPath<'_>, lang_item: LangItem) -> bool {
202 self.qpath_lang_item(qpath) == Some(lang_item)
203 }
204
205 pub fn qpath_lang_item(self, qpath: QPath<'_>) -> Option<LangItem> {
207 if let QPath::Resolved(_, path) = qpath
208 && let Res::Def(_, def_id) = path.res
209 {
210 return self.lang_items().from_def_id(def_id);
211 }
212 None
213 }
214
215 pub fn expr_guaranteed_to_constitute_read_for_never(self, expr: &Expr<'_>) -> bool {
227 if !expr.is_syntactic_place_expr() {
233 return true;
234 }
235
236 let parent_node = self.parent_hir_node(expr.hir_id);
237 match parent_node {
238 Node::Expr(parent_expr) => {
239 match parent_expr.kind {
240 ExprKind::AddrOf(..) | ExprKind::Field(..) => false,
244
245 ExprKind::Type(..) | ExprKind::UnsafeBinderCast(..) => {
248 self.expr_guaranteed_to_constitute_read_for_never(parent_expr)
249 }
250
251 ExprKind::Assign(lhs, _, _) => {
252 expr.hir_id != lhs.hir_id
254 }
255
256 ExprKind::Match(scrutinee, arms, _) => {
259 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);
260 arms.iter().all(|arm| arm.pat.is_guaranteed_to_constitute_read_for_never())
261 }
262 ExprKind::Let(LetExpr { init, pat, .. }) => {
263 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);
264 pat.is_guaranteed_to_constitute_read_for_never()
265 }
266
267 ExprKind::Array(_)
269 | ExprKind::Call(_, _)
270 | ExprKind::Use(_, _)
271 | ExprKind::MethodCall(_, _, _, _)
272 | ExprKind::Tup(_)
273 | ExprKind::Binary(_, _, _)
274 | ExprKind::Unary(_, _)
275 | ExprKind::Cast(_, _)
276 | ExprKind::DropTemps(_)
277 | ExprKind::If(_, _, _)
278 | ExprKind::Closure(_)
279 | ExprKind::Block(_, _)
280 | ExprKind::AssignOp(_, _, _)
281 | ExprKind::Index(_, _, _)
282 | ExprKind::Break(_, _)
283 | ExprKind::Ret(_)
284 | ExprKind::Become(_)
285 | ExprKind::InlineAsm(_)
286 | ExprKind::Struct(_, _, _)
287 | ExprKind::Repeat(_, _)
288 | ExprKind::Yield(_, _) => true,
289
290 ExprKind::ConstBlock(_)
292 | ExprKind::Loop(_, _, _, _)
293 | ExprKind::Lit(_)
294 | ExprKind::Path(_)
295 | ExprKind::Continue(_)
296 | ExprKind::OffsetOf(_, _)
297 | 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),
298 }
299 }
300
301 Node::LetStmt(LetStmt { init: Some(target), pat, .. }) => {
304 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);
305 pat.is_guaranteed_to_constitute_read_for_never()
306 }
307
308 Node::Block(_)
310 | Node::Arm(_)
311 | Node::ExprField(_)
312 | Node::AnonConst(_)
313 | Node::ConstBlock(_)
314 | Node::ConstArg(_)
315 | Node::Stmt(_)
316 | Node::Item(Item { kind: ItemKind::Const(..) | ItemKind::Static(..), .. })
317 | Node::TraitItem(TraitItem { kind: TraitItemKind::Const(..), .. })
318 | Node::ImplItem(ImplItem { kind: ImplItemKind::Const(..), .. }) => true,
319
320 Node::TyPat(_) | Node::Pat(_) => {
321 self.dcx().span_delayed_bug(expr.span, "place expr not allowed in pattern");
322 true
323 }
324
325 Node::Param(_)
327 | Node::Item(_)
328 | Node::ForeignItem(_)
329 | Node::TraitItem(_)
330 | Node::ImplItem(_)
331 | Node::Variant(_)
332 | Node::Field(_)
333 | Node::PathSegment(_)
334 | Node::Ty(_)
335 | Node::AssocItemConstraint(_)
336 | Node::TraitRef(_)
337 | Node::PatField(_)
338 | Node::PatExpr(_)
339 | Node::LetStmt(_)
340 | Node::Synthetic
341 | Node::Err(_)
342 | Node::Ctor(_)
343 | Node::Lifetime(_)
344 | Node::GenericParam(_)
345 | Node::Crate(_)
346 | Node::Infer(_)
347 | Node::WherePredicate(_)
348 | Node::PreciseCapturingNonLifetimeArg(_)
349 | Node::ConstArgExprField(_)
350 | Node::OpaqueTy(_) => {
351 {
::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:?}")
352 }
353 }
354 }
355
356 #[inline]
357 fn hir_owner_parent_impl(self, owner_id: OwnerId) -> HirId {
358 self.opt_local_parent(owner_id.def_id).map_or(CRATE_HIR_ID, |parent_def_id| {
359 let parent_owner_id = self.local_def_id_to_hir_id(parent_def_id).owner;
360 HirId {
361 owner: parent_owner_id,
362 local_id: self
363 .hir_owner(parent_owner_id.def_id)
364 .unwrap()
365 .parenting
366 .get(&owner_id.def_id)
367 .copied()
368 .unwrap_or(ItemLocalId::ZERO),
369 }
370 })
371 }
372
373 #[inline]
376 pub fn hir_owner_parent(self, owner_id: OwnerId) -> HirId {
377 if self.dep_graph.is_fully_enabled() {
378 self.hir_owner_parent_q(owner_id)
379 } else {
380 self.hir_owner_parent_impl(owner_id)
381 }
382 }
383}
384
385#[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)]
387pub struct Hashes {
388 pub bodies_hash: Option<Fingerprint>,
389 pub attrs_hash: Option<Fingerprint>,
390}
391
392#[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)]
399pub struct ProjectedOwnerInfo<'tcx> {
400 nodes: &'tcx OwnerNodes<'tcx>,
401 parenting: &'tcx LocalDefIdMap<ItemLocalId>,
402 trait_map: &'tcx ItemLocalMap<&'tcx [TraitCandidate<'tcx>]>,
403
404 #[stable_hash(ignore)]
405 delayed_lints: &'tcx Steal<DelayedLints>,
406}
407
408impl<'tcx> ProjectedOwnerInfo<'tcx> {
409 pub fn new(
410 nodes: &'tcx OwnerNodes<'tcx>,
411 parenting: &'tcx LocalDefIdMap<ItemLocalId>,
412 trait_map: &'tcx ItemLocalMap<&'tcx [TraitCandidate<'tcx>]>,
413 delayed_lints: &'tcx Steal<DelayedLints>,
414 ) -> ProjectedOwnerInfo<'tcx> {
415 ProjectedOwnerInfo { nodes, parenting, trait_map, delayed_lints }
416 }
417}
418
419#[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)]
420pub enum ProjectedMaybeOwner<'tcx> {
421 Owner(ProjectedOwnerInfo<'tcx>),
422 NonOwner(HirId),
423}
424
425impl<'tcx> ProjectedMaybeOwner<'tcx> {
426 pub fn new(value: MaybeOwner<'tcx>) -> Self {
427 match value {
428 MaybeOwner::Owner(o) => ProjectedMaybeOwner::Owner(ProjectedOwnerInfo {
429 nodes: &o.nodes,
430 parenting: &o.parenting,
431 trait_map: &o.trait_map,
432 delayed_lints: &o.delayed_lints,
433 }),
434 MaybeOwner::NonOwner(hir_id) => ProjectedMaybeOwner::NonOwner(hir_id),
435 }
436 }
437
438 pub fn as_owner(&self) -> Option<&ProjectedOwnerInfo<'tcx>> {
439 match self {
440 ProjectedMaybeOwner::Owner(i) => Some(i),
441 ProjectedMaybeOwner::NonOwner(_) => None,
442 }
443 }
444
445 pub fn unwrap(&'tcx self) -> &'tcx ProjectedOwnerInfo<'tcx> {
446 self.as_owner().unwrap_or_else(|| { ::core::panicking::panic_fmt(format_args!("Not a HIR owner")); }panic!("Not a HIR owner"))
447 }
448}
449
450pub fn provide(providers: &mut Providers) {
451 providers.hir_crate_items = map::hir_crate_items;
452 providers.crate_hash = map::crate_hash;
453 providers.hir_module_items = map::hir_module_items;
454 providers.hir_attr_map =
455 |tcx, id| tcx.lower_to_hir(id).as_owner().map_or(AttributeMap::EMPTY, |o| &o.attrs);
456 providers.hir_owner = |tcx, def_id| ProjectedMaybeOwner::new(tcx.lower_to_hir(def_id));
457 providers.hir_owner_parent_q = |tcx, owner_id| tcx.hir_owner_parent_impl(owner_id);
458 providers.def_span = |tcx, def_id| tcx.hir_span(tcx.local_def_id_to_hir_id(def_id));
459 providers.def_ident_span = |tcx, def_id| {
460 let hir_id = tcx.local_def_id_to_hir_id(def_id);
461 tcx.hir_opt_ident_span(hir_id)
462 };
463 providers.ty_span = |tcx, def_id| {
464 let node = tcx.hir_node_by_def_id(def_id);
465 match node.ty() {
466 Some(ty) => ty.span,
467 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:#?}"),
468 }
469 };
470 providers.fn_arg_idents = |tcx, def_id| {
471 let node = tcx.hir_node_by_def_id(def_id);
472 if let Some(body_id) = node.body_id() {
473 tcx.arena.alloc_from_iter(tcx.hir_body_param_idents(body_id))
474 } else if let Node::TraitItem(&TraitItem {
475 kind: TraitItemKind::Fn(_, TraitFn::Required(idents)),
476 ..
477 })
478 | Node::ForeignItem(&ForeignItem {
479 kind: ForeignItemKind::Fn(_, idents, _),
480 ..
481 }) = node
482 {
483 idents
484 } else {
485 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!(
486 tcx.hir_span(tcx.local_def_id_to_hir_id(def_id)),
487 "fn_arg_idents: unexpected item {:?}",
488 def_id
489 );
490 }
491 };
492 providers.all_local_trait_impls = |tcx, ()| &tcx.resolutions(()).trait_impls;
493 providers.local_trait_impls =
494 |tcx, trait_id| tcx.resolutions(()).trait_impls.get(&trait_id).map_or(&[], |xs| &xs[..]);
495 providers.expn_that_defined =
496 |tcx, id| tcx.resolutions(()).expn_that_defined.get(&id).copied().unwrap_or(ExpnId::root());
497}