1pub mod map;
6pub mod nested_filter;
7pub mod place;
8
9use std::sync::Arc;
10
11use rustc_ast::{self as ast};
12use rustc_data_structures::fingerprint::Fingerprint;
13use rustc_data_structures::fx::FxIndexSet;
14use rustc_data_structures::sorted_map::SortedMap;
15use rustc_data_structures::stable_hash::{StableHash, StableHashCtxt, StableHasher};
16use rustc_data_structures::steal::Steal;
17use rustc_data_structures::sync::{DynSend, DynSync, try_par_for_each_in};
18use rustc_hir::def::{DefKind, Res};
19use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdMap, LocalModDefId};
20use rustc_hir::lints::DelayedLints;
21use rustc_hir::*;
22use rustc_index::IndexVec;
23use rustc_macros::{Decodable, Encodable, StableHash};
24use rustc_span::{ErrorGuaranteed, ExpnId, Span};
25
26use crate::query::Providers;
27use crate::ty::{ResolverAstLowering, TyCtxt};
28
29#[derive(#[automatically_derived]
impl<'hir> ::core::fmt::Debug for Crate<'hir> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field4_finish(f, "Crate",
"owners", &self.owners, "delayed_ids", &self.delayed_ids,
"delayed_resolver", &self.delayed_resolver, "opt_hir_hash",
&&self.opt_hir_hash)
}
}Debug)]
36pub struct Crate<'hir> {
37 owners: IndexVec<LocalDefId, MaybeOwner<'hir>>,
39 pub delayed_ids: FxIndexSet<LocalDefId>,
41 pub delayed_resolver: Steal<(ResolverAstLowering<'hir>, Arc<ast::Crate>)>,
44 pub opt_hir_hash: Option<Fingerprint>,
46}
47
48impl<'hir> Crate<'hir> {
49 pub fn new(
50 owners: IndexVec<LocalDefId, MaybeOwner<'hir>>,
51 delayed_ids: FxIndexSet<LocalDefId>,
52 delayed_resolver: Steal<(ResolverAstLowering<'hir>, Arc<ast::Crate>)>,
53 opt_hir_hash: Option<Fingerprint>,
54 ) -> Crate<'hir> {
55 Crate { owners, delayed_ids, delayed_resolver, opt_hir_hash }
56 }
57
58 pub fn owner(&self, tcx: TyCtxt<'hir>, def_id: LocalDefId) -> MaybeOwner<'hir> {
63 if let Some(owner) = self.owners.get(def_id)
67 && (self.delayed_ids.is_empty() || !#[allow(non_exhaustive_omitted_patterns)] match owner {
MaybeOwner::Phantom => true,
_ => false,
}matches!(owner, MaybeOwner::Phantom))
68 {
69 return *owner;
70 }
71
72 if self.delayed_ids.contains(&def_id) {
73 tcx.ensure_done().lower_delayed_owner(def_id);
74 }
75
76 tcx.hir_delayed_owner(def_id)
77 }
78}
79
80impl StableHash for Crate<'_> {
81 fn stable_hash<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
82 let Crate { opt_hir_hash, .. } = self;
83 opt_hir_hash.unwrap().stable_hash(hcx, hasher)
84 }
85}
86
87#[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)]
90pub struct ModuleItems {
91 add_root: bool,
94 submodules: Box<[OwnerId]>,
95 free_items: Box<[ItemId]>,
96 trait_items: Box<[TraitItemId]>,
97 impl_items: Box<[ImplItemId]>,
98 foreign_items: Box<[ForeignItemId]>,
99 opaques: Box<[LocalDefId]>,
100 body_owners: Box<[LocalDefId]>,
101 nested_bodies: Box<[LocalDefId]>,
102 delayed_lint_items: Box<[OwnerId]>,
104
105 eiis: Box<[LocalDefId]>,
107}
108
109impl ModuleItems {
110 pub fn free_items(&self) -> impl Iterator<Item = ItemId> {
117 self.free_items.iter().copied()
118 }
119
120 pub fn trait_items(&self) -> impl Iterator<Item = TraitItemId> {
121 self.trait_items.iter().copied()
122 }
123
124 pub fn delayed_lint_items(&self) -> impl Iterator<Item = OwnerId> {
125 self.delayed_lint_items.iter().copied()
126 }
127
128 pub fn eiis(&self) -> impl Iterator<Item = LocalDefId> {
129 self.eiis.iter().copied()
130 }
131
132 pub fn impl_items(&self) -> impl Iterator<Item = ImplItemId> {
135 self.impl_items.iter().copied()
136 }
137
138 pub fn foreign_items(&self) -> impl Iterator<Item = ForeignItemId> {
139 self.foreign_items.iter().copied()
140 }
141
142 pub fn owners(&self) -> impl Iterator<Item = OwnerId> {
143 self.add_root
144 .then_some(CRATE_OWNER_ID)
145 .into_iter()
146 .chain(self.free_items.iter().map(|id| id.owner_id))
147 .chain(self.trait_items.iter().map(|id| id.owner_id))
148 .chain(self.impl_items.iter().map(|id| id.owner_id))
149 .chain(self.foreign_items.iter().map(|id| id.owner_id))
150 }
151
152 pub fn opaques(&self) -> impl Iterator<Item = LocalDefId> {
153 self.opaques.iter().copied()
154 }
155
156 pub fn nested_bodies(&self) -> impl Iterator<Item = LocalDefId> {
158 self.nested_bodies.iter().copied()
159 }
160
161 pub fn definitions(&self) -> impl Iterator<Item = LocalDefId> {
162 self.owners().map(|id| id.def_id)
163 }
164
165 pub fn par_nested_bodies(
167 &self,
168 f: impl Fn(LocalDefId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,
169 ) -> Result<(), ErrorGuaranteed> {
170 try_par_for_each_in(&self.nested_bodies[..], |&&id| f(id))
171 }
172
173 pub fn par_items(
174 &self,
175 f: impl Fn(ItemId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,
176 ) -> Result<(), ErrorGuaranteed> {
177 try_par_for_each_in(&self.free_items[..], |&&id| f(id))
178 }
179
180 pub fn par_trait_items(
181 &self,
182 f: impl Fn(TraitItemId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,
183 ) -> Result<(), ErrorGuaranteed> {
184 try_par_for_each_in(&self.trait_items[..], |&&id| f(id))
185 }
186
187 pub fn par_impl_items(
188 &self,
189 f: impl Fn(ImplItemId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,
190 ) -> Result<(), ErrorGuaranteed> {
191 try_par_for_each_in(&self.impl_items[..], |&&id| f(id))
192 }
193
194 pub fn par_foreign_items(
195 &self,
196 f: impl Fn(ForeignItemId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,
197 ) -> Result<(), ErrorGuaranteed> {
198 try_par_for_each_in(&self.foreign_items[..], |&&id| f(id))
199 }
200
201 pub fn par_opaques(
202 &self,
203 f: impl Fn(LocalDefId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,
204 ) -> Result<(), ErrorGuaranteed> {
205 try_par_for_each_in(&self.opaques[..], |&&id| f(id))
206 }
207}
208
209impl<'tcx> TyCtxt<'tcx> {
210 pub fn parent_module(self, id: HirId) -> LocalModDefId {
211 if !id.is_owner() && self.def_kind(id.owner) == DefKind::Mod {
212 LocalModDefId::new_unchecked(id.owner.def_id)
213 } else {
214 self.parent_module_from_def_id(id.owner.def_id)
215 }
216 }
217
218 pub fn parent_module_from_def_id(self, mut id: LocalDefId) -> LocalModDefId {
219 while let Some(parent) = self.opt_local_parent(id) {
220 id = parent;
221 if self.def_kind(id) == DefKind::Mod {
222 break;
223 }
224 }
225 LocalModDefId::new_unchecked(id)
226 }
227
228 pub fn is_foreign_item(self, def_id: impl Into<DefId>) -> bool {
230 self.opt_parent(def_id.into())
231 .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))
232 }
233
234 pub fn hash_owner_nodes(
235 self,
236 node: OwnerNode<'_>,
237 bodies: &SortedMap<ItemLocalId, &Body<'_>>,
238 attrs: &SortedMap<ItemLocalId, &[Attribute]>,
239 define_opaque: Option<&[(Span, LocalDefId)]>,
240 ) -> Hashes {
241 if !self.needs_hir_hash() {
242 return Hashes { opt_hash_including_bodies: None, attrs_hash: None };
243 }
244
245 self.with_stable_hashing_context(|mut hcx| {
246 let mut stable_hasher = StableHasher::new();
247 node.stable_hash(&mut hcx, &mut stable_hasher);
248 bodies.stable_hash(&mut hcx, &mut stable_hasher);
250 let h1 = stable_hasher.finish();
251
252 let mut stable_hasher = StableHasher::new();
253 attrs.stable_hash(&mut hcx, &mut stable_hasher);
254
255 define_opaque.stable_hash(&mut hcx, &mut stable_hasher);
257
258 let h2 = stable_hasher.finish();
259
260 Hashes { opt_hash_including_bodies: Some(h1), attrs_hash: Some(h2) }
261 })
262 }
263
264 pub fn qpath_is_lang_item(self, qpath: QPath<'_>, lang_item: LangItem) -> bool {
265 self.qpath_lang_item(qpath) == Some(lang_item)
266 }
267
268 pub fn qpath_lang_item(self, qpath: QPath<'_>) -> Option<LangItem> {
270 if let QPath::Resolved(_, path) = qpath
271 && let Res::Def(_, def_id) = path.res
272 {
273 return self.lang_items().from_def_id(def_id);
274 }
275 None
276 }
277
278 pub fn expr_guaranteed_to_constitute_read_for_never(self, expr: &Expr<'_>) -> bool {
290 if !expr.is_syntactic_place_expr() {
296 return true;
297 }
298
299 let parent_node = self.parent_hir_node(expr.hir_id);
300 match parent_node {
301 Node::Expr(parent_expr) => {
302 match parent_expr.kind {
303 ExprKind::AddrOf(..) | ExprKind::Field(..) => false,
307
308 ExprKind::Type(..) | ExprKind::UnsafeBinderCast(..) => {
311 self.expr_guaranteed_to_constitute_read_for_never(parent_expr)
312 }
313
314 ExprKind::Assign(lhs, _, _) => {
315 expr.hir_id != lhs.hir_id
317 }
318
319 ExprKind::Match(scrutinee, arms, _) => {
322 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);
323 arms.iter().all(|arm| arm.pat.is_guaranteed_to_constitute_read_for_never())
324 }
325 ExprKind::Let(LetExpr { init, pat, .. }) => {
326 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);
327 pat.is_guaranteed_to_constitute_read_for_never()
328 }
329
330 ExprKind::Array(_)
332 | ExprKind::Call(_, _)
333 | ExprKind::Use(_, _)
334 | ExprKind::MethodCall(_, _, _, _)
335 | ExprKind::Tup(_)
336 | ExprKind::Binary(_, _, _)
337 | ExprKind::Unary(_, _)
338 | ExprKind::Cast(_, _)
339 | ExprKind::DropTemps(_)
340 | ExprKind::If(_, _, _)
341 | ExprKind::Closure(_)
342 | ExprKind::Block(_, _)
343 | ExprKind::AssignOp(_, _, _)
344 | ExprKind::Index(_, _, _)
345 | ExprKind::Break(_, _)
346 | ExprKind::Ret(_)
347 | ExprKind::Become(_)
348 | ExprKind::InlineAsm(_)
349 | ExprKind::Struct(_, _, _)
350 | ExprKind::Repeat(_, _)
351 | ExprKind::Yield(_, _) => true,
352
353 ExprKind::ConstBlock(_)
355 | ExprKind::Loop(_, _, _, _)
356 | ExprKind::Lit(_)
357 | ExprKind::Path(_)
358 | ExprKind::Continue(_)
359 | ExprKind::OffsetOf(_, _)
360 | 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),
361 }
362 }
363
364 Node::LetStmt(LetStmt { init: Some(target), pat, .. }) => {
367 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);
368 pat.is_guaranteed_to_constitute_read_for_never()
369 }
370
371 Node::Block(_)
373 | Node::Arm(_)
374 | Node::ExprField(_)
375 | Node::AnonConst(_)
376 | Node::ConstBlock(_)
377 | Node::ConstArg(_)
378 | Node::Stmt(_)
379 | Node::Item(Item { kind: ItemKind::Const(..) | ItemKind::Static(..), .. })
380 | Node::TraitItem(TraitItem { kind: TraitItemKind::Const(..), .. })
381 | Node::ImplItem(ImplItem { kind: ImplItemKind::Const(..), .. }) => true,
382
383 Node::TyPat(_) | Node::Pat(_) => {
384 self.dcx().span_delayed_bug(expr.span, "place expr not allowed in pattern");
385 true
386 }
387
388 Node::Param(_)
390 | Node::Item(_)
391 | Node::ForeignItem(_)
392 | Node::TraitItem(_)
393 | Node::ImplItem(_)
394 | Node::Variant(_)
395 | Node::Field(_)
396 | Node::PathSegment(_)
397 | Node::Ty(_)
398 | Node::AssocItemConstraint(_)
399 | Node::TraitRef(_)
400 | Node::PatField(_)
401 | Node::PatExpr(_)
402 | Node::LetStmt(_)
403 | Node::Synthetic
404 | Node::Err(_)
405 | Node::Ctor(_)
406 | Node::Lifetime(_)
407 | Node::GenericParam(_)
408 | Node::Crate(_)
409 | Node::Infer(_)
410 | Node::WherePredicate(_)
411 | Node::PreciseCapturingNonLifetimeArg(_)
412 | Node::ConstArgExprField(_)
413 | Node::OpaqueTy(_) => {
414 {
::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:?}")
415 }
416 }
417 }
418
419 #[inline]
420 fn hir_owner_parent_impl(self, owner_id: OwnerId) -> HirId {
421 self.opt_local_parent(owner_id.def_id).map_or(CRATE_HIR_ID, |parent_def_id| {
422 let parent_owner_id = self.local_def_id_to_hir_id(parent_def_id).owner;
423 HirId {
424 owner: parent_owner_id,
425 local_id: self
426 .hir_owner(parent_owner_id.def_id)
427 .unwrap()
428 .parenting
429 .get(&owner_id.def_id)
430 .copied()
431 .unwrap_or(ItemLocalId::ZERO),
432 }
433 })
434 }
435
436 #[inline]
439 pub fn hir_owner_parent(self, owner_id: OwnerId) -> HirId {
440 if self.dep_graph.is_fully_enabled() {
441 self.hir_owner_parent_q(owner_id)
442 } else {
443 self.hir_owner_parent_impl(owner_id)
444 }
445 }
446}
447
448#[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",
"opt_hash_including_bodies", &self.opt_hash_including_bodies,
"attrs_hash", &&self.attrs_hash)
}
}Debug)]
450pub struct Hashes {
451 pub opt_hash_including_bodies: Option<Fingerprint>,
452 pub attrs_hash: Option<Fingerprint>,
453}
454
455#[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)]
462pub struct ProjectedOwnerInfo<'tcx> {
463 nodes: &'tcx OwnerNodes<'tcx>,
464 parenting: &'tcx LocalDefIdMap<ItemLocalId>,
465 trait_map: &'tcx ItemLocalMap<&'tcx [TraitCandidate<'tcx>]>,
466
467 #[stable_hash(ignore)]
468 delayed_lints: &'tcx Steal<DelayedLints>,
469}
470
471impl<'tcx> ProjectedOwnerInfo<'tcx> {
472 pub fn new(
473 nodes: &'tcx OwnerNodes<'tcx>,
474 parenting: &'tcx LocalDefIdMap<ItemLocalId>,
475 trait_map: &'tcx ItemLocalMap<&'tcx [TraitCandidate<'tcx>]>,
476 delayed_lints: &'tcx Steal<DelayedLints>,
477 ) -> ProjectedOwnerInfo<'tcx> {
478 ProjectedOwnerInfo { nodes, parenting, trait_map, delayed_lints }
479 }
480}
481
482#[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)]
483pub enum ProjectedMaybeOwner<'tcx> {
484 Owner(ProjectedOwnerInfo<'tcx>),
485 NonOwner(HirId),
486}
487
488impl<'tcx> ProjectedMaybeOwner<'tcx> {
489 pub fn new(value: MaybeOwner<'tcx>, def_id: LocalDefId) -> Self {
490 match value {
491 MaybeOwner::Owner(o) => ProjectedMaybeOwner::Owner(ProjectedOwnerInfo {
492 nodes: &o.nodes,
493 parenting: &o.parenting,
494 trait_map: &o.trait_map,
495 delayed_lints: &o.delayed_lints,
496 }),
497 MaybeOwner::NonOwner(hir_id) => ProjectedMaybeOwner::NonOwner(hir_id),
498 MaybeOwner::Phantom => crate::util::bug::bug_fmt(format_args!("No HirId for {0:?}",
def_id.local_def_index))bug!("No HirId for {:?}", def_id.local_def_index),
500 }
501 }
502
503 pub fn as_owner(&self) -> Option<&ProjectedOwnerInfo<'tcx>> {
504 match self {
505 ProjectedMaybeOwner::Owner(i) => Some(i),
506 ProjectedMaybeOwner::NonOwner(_) => None,
507 }
508 }
509
510 pub fn unwrap(&'tcx self) -> &'tcx ProjectedOwnerInfo<'tcx> {
511 self.as_owner().unwrap_or_else(|| { ::core::panicking::panic_fmt(format_args!("Not a HIR owner")); }panic!("Not a HIR owner"))
512 }
513}
514
515pub fn provide(providers: &mut Providers) {
516 providers.hir_crate_items = map::hir_crate_items;
517 providers.crate_hash = map::crate_hash;
518 providers.hir_module_items = map::hir_module_items;
519 providers.hir_attr_map = |tcx, id| {
520 tcx.hir_crate(()).owner(tcx, id.def_id).as_owner().map_or(AttributeMap::EMPTY, |o| &o.attrs)
521 };
522 providers.hir_owner =
523 |tcx, def_id| ProjectedMaybeOwner::new(tcx.hir_crate(()).owner(tcx, def_id), def_id);
524 providers.hir_owner_parent_q = |tcx, owner_id| tcx.hir_owner_parent_impl(owner_id);
525 providers.def_span = |tcx, def_id| tcx.hir_span(tcx.local_def_id_to_hir_id(def_id));
526 providers.def_ident_span = |tcx, def_id| {
527 let hir_id = tcx.local_def_id_to_hir_id(def_id);
528 tcx.hir_opt_ident_span(hir_id)
529 };
530 providers.ty_span = |tcx, def_id| {
531 let node = tcx.hir_node_by_def_id(def_id);
532 match node.ty() {
533 Some(ty) => ty.span,
534 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:#?}"),
535 }
536 };
537 providers.fn_arg_idents = |tcx, def_id| {
538 let node = tcx.hir_node_by_def_id(def_id);
539 if let Some(body_id) = node.body_id() {
540 tcx.arena.alloc_from_iter(tcx.hir_body_param_idents(body_id))
541 } else if let Node::TraitItem(&TraitItem {
542 kind: TraitItemKind::Fn(_, TraitFn::Required(idents)),
543 ..
544 })
545 | Node::ForeignItem(&ForeignItem {
546 kind: ForeignItemKind::Fn(_, idents, _),
547 ..
548 }) = node
549 {
550 idents
551 } else {
552 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!(
553 tcx.hir_span(tcx.local_def_id_to_hir_id(def_id)),
554 "fn_arg_idents: unexpected item {:?}",
555 def_id
556 );
557 }
558 };
559 providers.all_local_trait_impls = |tcx, ()| &tcx.resolutions(()).trait_impls;
560 providers.local_trait_impls =
561 |tcx, trait_id| tcx.resolutions(()).trait_impls.get(&trait_id).map_or(&[], |xs| &xs[..]);
562 providers.expn_that_defined =
563 |tcx, id| tcx.resolutions(()).expn_that_defined.get(&id).copied().unwrap_or(ExpnId::root());
564}