1use std::borrow::Borrow;
2use std::collections::hash_map::Entry;
3use std::fs::File;
4use std::io::{Read, Seek, Write};
5use std::path::{Path, PathBuf};
6use std::sync::Arc;
7
8use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
9use rustc_data_structures::memmap::{Mmap, MmapMut};
10use rustc_data_structures::sync::{par_for_each_in, par_join};
11use rustc_data_structures::temp_dir::MaybeTempDir;
12use rustc_data_structures::thousands::usize_with_underscores;
13use rustc_feature::Features;
14use rustc_hir as hir;
15use rustc_hir::attrs::{AttributeKind, EncodeCrossCrate};
16use rustc_hir::def_id::{CRATE_DEF_ID, CRATE_DEF_INDEX, LOCAL_CRATE, LocalDefId, LocalDefIdSet};
17use rustc_hir::definitions::DefPathData;
18use rustc_hir::find_attr;
19use rustc_hir_pretty::id_to_string;
20use rustc_middle::dep_graph::WorkProductId;
21use rustc_middle::middle::dependency_format::Linkage;
22use rustc_middle::mir::interpret;
23use rustc_middle::query::Providers;
24use rustc_middle::traits::specialization_graph;
25use rustc_middle::ty::AssocContainer;
26use rustc_middle::ty::codec::TyEncoder;
27use rustc_middle::ty::fast_reject::{self, TreatParams};
28use rustc_middle::{bug, span_bug};
29use rustc_serialize::{Decodable, Decoder, Encodable, Encoder, opaque};
30use rustc_session::config::{CrateType, OptLevel, TargetModifier};
31use rustc_span::hygiene::HygieneEncodeContext;
32use rustc_span::{
33 ByteSymbol, ExternalSource, FileName, SourceFile, SpanData, SpanEncoder, StableSourceFileId,
34 Symbol, SyntaxContext, sym,
35};
36use tracing::{debug, instrument, trace};
37
38use crate::eii::EiiMapEncodedKeyValue;
39use crate::errors::{FailCreateFileEncoder, FailWriteFile};
40use crate::rmeta::*;
41
42pub(super) struct EncodeContext<'a, 'tcx> {
43 opaque: opaque::FileEncoder,
44 tcx: TyCtxt<'tcx>,
45 feat: &'tcx rustc_feature::Features,
46 tables: TableBuilders,
47
48 lazy_state: LazyState,
49 span_shorthands: FxHashMap<Span, usize>,
50 type_shorthands: FxHashMap<Ty<'tcx>, usize>,
51 predicate_shorthands: FxHashMap<ty::PredicateKind<'tcx>, usize>,
52
53 interpret_allocs: FxIndexSet<interpret::AllocId>,
54
55 source_file_cache: (Arc<SourceFile>, usize),
59 required_source_files: Option<FxIndexSet<usize>>,
66 is_proc_macro: bool,
67 hygiene_ctxt: &'a HygieneEncodeContext,
68 symbol_index_table: FxHashMap<u32, usize>,
70}
71
72macro_rules! empty_proc_macro {
76 ($self:ident) => {
77 if $self.is_proc_macro {
78 return LazyArray::default();
79 }
80 };
81}
82
83macro_rules! encoder_methods {
84 ($($name:ident($ty:ty);)*) => {
85 $(fn $name(&mut self, value: $ty) {
86 self.opaque.$name(value)
87 })*
88 }
89}
90
91impl<'a, 'tcx> Encoder for EncodeContext<'a, 'tcx> {
92 self
value
self.opaque.emit_raw_bytes(value);encoder_methods! {
93 emit_usize(usize);
94 emit_u128(u128);
95 emit_u64(u64);
96 emit_u32(u32);
97 emit_u16(u16);
98 emit_u8(u8);
99
100 emit_isize(isize);
101 emit_i128(i128);
102 emit_i64(i64);
103 emit_i32(i32);
104 emit_i16(i16);
105
106 emit_raw_bytes(&[u8]);
107 }
108}
109
110impl<'a, 'tcx, T> Encodable<EncodeContext<'a, 'tcx>> for LazyValue<T> {
111 fn encode(&self, e: &mut EncodeContext<'a, 'tcx>) {
112 e.emit_lazy_distance(self.position);
113 }
114}
115
116impl<'a, 'tcx, T> Encodable<EncodeContext<'a, 'tcx>> for LazyArray<T> {
117 fn encode(&self, e: &mut EncodeContext<'a, 'tcx>) {
118 e.emit_usize(self.num_elems);
119 if self.num_elems > 0 {
120 e.emit_lazy_distance(self.position)
121 }
122 }
123}
124
125impl<'a, 'tcx, I, T> Encodable<EncodeContext<'a, 'tcx>> for LazyTable<I, T> {
126 fn encode(&self, e: &mut EncodeContext<'a, 'tcx>) {
127 e.emit_usize(self.width);
128 e.emit_usize(self.len);
129 e.emit_lazy_distance(self.position);
130 }
131}
132
133impl<'a, 'tcx> Encodable<EncodeContext<'a, 'tcx>> for ExpnIndex {
134 fn encode(&self, s: &mut EncodeContext<'a, 'tcx>) {
135 s.emit_u32(self.as_u32());
136 }
137}
138
139impl<'a, 'tcx> SpanEncoder for EncodeContext<'a, 'tcx> {
140 fn encode_crate_num(&mut self, crate_num: CrateNum) {
141 if crate_num != LOCAL_CRATE && self.is_proc_macro {
142 {
::core::panicking::panic_fmt(format_args!("Attempted to encode non-local CrateNum {0:?} for proc-macro crate",
crate_num));
};panic!("Attempted to encode non-local CrateNum {crate_num:?} for proc-macro crate");
143 }
144 self.emit_u32(crate_num.as_u32());
145 }
146
147 fn encode_def_index(&mut self, def_index: DefIndex) {
148 self.emit_u32(def_index.as_u32());
149 }
150
151 fn encode_def_id(&mut self, def_id: DefId) {
152 def_id.krate.encode(self);
153 def_id.index.encode(self);
154 }
155
156 fn encode_syntax_context(&mut self, syntax_context: SyntaxContext) {
157 rustc_span::hygiene::raw_encode_syntax_context(syntax_context, self.hygiene_ctxt, self);
158 }
159
160 fn encode_expn_id(&mut self, expn_id: ExpnId) {
161 if expn_id.krate == LOCAL_CRATE {
162 self.hygiene_ctxt.schedule_expn_data_for_encoding(expn_id);
167 }
168 expn_id.krate.encode(self);
169 expn_id.local_id.encode(self);
170 }
171
172 fn encode_span(&mut self, span: Span) {
173 match self.span_shorthands.entry(span) {
174 Entry::Occupied(o) => {
175 let last_location = *o.get();
178 let offset = self.opaque.position() - last_location;
181 if offset < last_location {
182 let needed = bytes_needed(offset);
183 SpanTag::indirect(true, needed as u8).encode(self);
184 self.opaque.write_with(|dest| {
185 *dest = offset.to_le_bytes();
186 needed
187 });
188 } else {
189 let needed = bytes_needed(last_location);
190 SpanTag::indirect(false, needed as u8).encode(self);
191 self.opaque.write_with(|dest| {
192 *dest = last_location.to_le_bytes();
193 needed
194 });
195 }
196 }
197 Entry::Vacant(v) => {
198 let position = self.opaque.position();
199 v.insert(position);
200 span.data().encode(self);
202 }
203 }
204 }
205
206 fn encode_symbol(&mut self, sym: Symbol) {
207 self.encode_symbol_or_byte_symbol(sym.as_u32(), |this| this.emit_str(sym.as_str()));
208 }
209
210 fn encode_byte_symbol(&mut self, byte_sym: ByteSymbol) {
211 self.encode_symbol_or_byte_symbol(byte_sym.as_u32(), |this| {
212 this.emit_byte_str(byte_sym.as_byte_str())
213 });
214 }
215}
216
217fn bytes_needed(n: usize) -> usize {
218 (usize::BITS - n.leading_zeros()).div_ceil(u8::BITS) as usize
219}
220
221impl<'a, 'tcx> Encodable<EncodeContext<'a, 'tcx>> for SpanData {
222 fn encode(&self, s: &mut EncodeContext<'a, 'tcx>) {
223 let ctxt = if s.is_proc_macro { SyntaxContext::root() } else { self.ctxt };
255
256 if self.is_dummy() {
257 let tag = SpanTag::new(SpanKind::Partial, ctxt, 0);
258 tag.encode(s);
259 if tag.context().is_none() {
260 ctxt.encode(s);
261 }
262 return;
263 }
264
265 if true {
if !(self.lo <= self.hi) {
::core::panicking::panic("assertion failed: self.lo <= self.hi")
};
};debug_assert!(self.lo <= self.hi);
267
268 if !s.source_file_cache.0.contains(self.lo) {
269 let source_map = s.tcx.sess.source_map();
270 let source_file_index = source_map.lookup_source_file_idx(self.lo);
271 s.source_file_cache =
272 (Arc::clone(&source_map.files()[source_file_index]), source_file_index);
273 }
274 let (ref source_file, source_file_index) = s.source_file_cache;
275 if true {
if !source_file.contains(self.lo) {
::core::panicking::panic("assertion failed: source_file.contains(self.lo)")
};
};debug_assert!(source_file.contains(self.lo));
276
277 if !source_file.contains(self.hi) {
278 let tag = SpanTag::new(SpanKind::Partial, ctxt, 0);
281 tag.encode(s);
282 if tag.context().is_none() {
283 ctxt.encode(s);
284 }
285 return;
286 }
287
288 let (kind, metadata_index) = if source_file.is_imported() && !s.is_proc_macro {
305 let metadata_index = {
315 match &*source_file.external_src.read() {
317 ExternalSource::Foreign { metadata_index, .. } => *metadata_index,
318 src => {
::core::panicking::panic_fmt(format_args!("Unexpected external source {0:?}",
src));
}panic!("Unexpected external source {src:?}"),
319 }
320 };
321
322 (SpanKind::Foreign, metadata_index)
323 } else {
324 let source_files =
326 s.required_source_files.as_mut().expect("Already encoded SourceMap!");
327 let (metadata_index, _) = source_files.insert_full(source_file_index);
328 let metadata_index: u32 =
329 metadata_index.try_into().expect("cannot export more than U32_MAX files");
330
331 (SpanKind::Local, metadata_index)
332 };
333
334 let lo = self.lo - source_file.start_pos;
337
338 let len = self.hi - self.lo;
341
342 let tag = SpanTag::new(kind, ctxt, len.0 as usize);
343 tag.encode(s);
344 if tag.context().is_none() {
345 ctxt.encode(s);
346 }
347 lo.encode(s);
348 if tag.length().is_none() {
349 len.encode(s);
350 }
351
352 metadata_index.encode(s);
354
355 if kind == SpanKind::Foreign {
356 let cnum = s.source_file_cache.0.cnum;
359 cnum.encode(s);
360 }
361 }
362}
363
364impl<'a, 'tcx> Encodable<EncodeContext<'a, 'tcx>> for [u8] {
365 fn encode(&self, e: &mut EncodeContext<'a, 'tcx>) {
366 Encoder::emit_usize(e, self.len());
367 e.emit_raw_bytes(self);
368 }
369}
370
371impl<'a, 'tcx> TyEncoder<'tcx> for EncodeContext<'a, 'tcx> {
372 const CLEAR_CROSS_CRATE: bool = true;
373
374 fn position(&self) -> usize {
375 self.opaque.position()
376 }
377
378 fn type_shorthands(&mut self) -> &mut FxHashMap<Ty<'tcx>, usize> {
379 &mut self.type_shorthands
380 }
381
382 fn predicate_shorthands(&mut self) -> &mut FxHashMap<ty::PredicateKind<'tcx>, usize> {
383 &mut self.predicate_shorthands
384 }
385
386 fn encode_alloc_id(&mut self, alloc_id: &rustc_middle::mir::interpret::AllocId) {
387 let (index, _) = self.interpret_allocs.insert_full(*alloc_id);
388
389 index.encode(self);
390 }
391}
392
393macro_rules! record {
396 ($self:ident.$tables:ident.$table:ident[$def_id:expr] <- $value:expr) => {{
397 {
398 let value = $value;
399 let lazy = $self.lazy(value);
400 $self.$tables.$table.set_some($def_id.index, lazy);
401 }
402 }};
403}
404
405macro_rules! record_array {
408 ($self:ident.$tables:ident.$table:ident[$def_id:expr] <- $value:expr) => {{
409 {
410 let value = $value;
411 let lazy = $self.lazy_array(value);
412 $self.$tables.$table.set_some($def_id.index, lazy);
413 }
414 }};
415}
416
417macro_rules! record_defaulted_array {
418 ($self:ident.$tables:ident.$table:ident[$def_id:expr] <- $value:expr) => {{
419 {
420 let value = $value;
421 let lazy = $self.lazy_array(value);
422 $self.$tables.$table.set($def_id.index, lazy);
423 }
424 }};
425}
426
427impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
428 fn emit_lazy_distance(&mut self, position: NonZero<usize>) {
429 let pos = position.get();
430 let distance = match self.lazy_state {
431 LazyState::NoNode => ::rustc_middle::util::bug::bug_fmt(format_args!("emit_lazy_distance: outside of a metadata node"))bug!("emit_lazy_distance: outside of a metadata node"),
432 LazyState::NodeStart(start) => {
433 let start = start.get();
434 if !(pos <= start) {
::core::panicking::panic("assertion failed: pos <= start")
};assert!(pos <= start);
435 start - pos
436 }
437 LazyState::Previous(last_pos) => {
438 if !(last_pos <= position) {
{
::core::panicking::panic_fmt(format_args!("make sure that the calls to `lazy*` are in the same order as the metadata fields"));
}
};assert!(
439 last_pos <= position,
440 "make sure that the calls to `lazy*` \
441 are in the same order as the metadata fields",
442 );
443 position.get() - last_pos.get()
444 }
445 };
446 self.lazy_state = LazyState::Previous(NonZero::new(pos).unwrap());
447 self.emit_usize(distance);
448 }
449
450 fn lazy<T: ParameterizedOverTcx, B: Borrow<T::Value<'tcx>>>(&mut self, value: B) -> LazyValue<T>
451 where
452 T::Value<'tcx>: Encodable<EncodeContext<'a, 'tcx>>,
453 {
454 let pos = NonZero::new(self.position()).unwrap();
455
456 match (&self.lazy_state, &LazyState::NoNode) {
(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!(self.lazy_state, LazyState::NoNode);
457 self.lazy_state = LazyState::NodeStart(pos);
458 value.borrow().encode(self);
459 self.lazy_state = LazyState::NoNode;
460
461 if !(pos.get() <= self.position()) {
::core::panicking::panic("assertion failed: pos.get() <= self.position()")
};assert!(pos.get() <= self.position());
462
463 LazyValue::from_position(pos)
464 }
465
466 fn lazy_array<T: ParameterizedOverTcx, I: IntoIterator<Item = B>, B: Borrow<T::Value<'tcx>>>(
467 &mut self,
468 values: I,
469 ) -> LazyArray<T>
470 where
471 T::Value<'tcx>: Encodable<EncodeContext<'a, 'tcx>>,
472 {
473 let pos = NonZero::new(self.position()).unwrap();
474
475 match (&self.lazy_state, &LazyState::NoNode) {
(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!(self.lazy_state, LazyState::NoNode);
476 self.lazy_state = LazyState::NodeStart(pos);
477 let len = values.into_iter().map(|value| value.borrow().encode(self)).count();
478 self.lazy_state = LazyState::NoNode;
479
480 if !(pos.get() <= self.position()) {
::core::panicking::panic("assertion failed: pos.get() <= self.position()")
};assert!(pos.get() <= self.position());
481
482 LazyArray::from_position_and_num_elems(pos, len)
483 }
484
485 fn encode_symbol_or_byte_symbol(
486 &mut self,
487 index: u32,
488 emit_str_or_byte_str: impl Fn(&mut Self),
489 ) {
490 if Symbol::is_predefined(index) {
492 self.opaque.emit_u8(SYMBOL_PREDEFINED);
493 self.opaque.emit_u32(index);
494 } else {
495 match self.symbol_index_table.entry(index) {
497 Entry::Vacant(o) => {
498 self.opaque.emit_u8(SYMBOL_STR);
499 let pos = self.opaque.position();
500 o.insert(pos);
501 emit_str_or_byte_str(self);
502 }
503 Entry::Occupied(o) => {
504 let x = *o.get();
505 self.emit_u8(SYMBOL_OFFSET);
506 self.emit_usize(x);
507 }
508 }
509 }
510 }
511
512 fn encode_def_path_table(&mut self) {
513 let table = self.tcx.def_path_table();
514 if self.is_proc_macro {
515 for def_index in std::iter::once(CRATE_DEF_INDEX)
516 .chain(self.tcx.resolutions(()).proc_macros.iter().map(|p| p.local_def_index))
517 {
518 let def_key = self.lazy(table.def_key(def_index));
519 let def_path_hash = table.def_path_hash(def_index);
520 self.tables.def_keys.set_some(def_index, def_key);
521 self.tables.def_path_hashes.set(def_index, def_path_hash.local_hash().as_u64());
522 }
523 } else {
524 for (def_index, def_key, def_path_hash) in table.enumerated_keys_and_path_hashes() {
525 let def_key = self.lazy(def_key);
526 self.tables.def_keys.set_some(def_index, def_key);
527 self.tables.def_path_hashes.set(def_index, def_path_hash.local_hash().as_u64());
528 }
529 }
530 }
531
532 fn encode_def_path_hash_map(&mut self) -> LazyValue<DefPathHashMapRef<'static>> {
533 self.lazy(DefPathHashMapRef::BorrowedFromTcx(self.tcx.def_path_hash_to_def_index_map()))
534 }
535
536 fn encode_source_map(&mut self) -> LazyTable<u32, Option<LazyValue<rustc_span::SourceFile>>> {
537 let source_map = self.tcx.sess.source_map();
538 let all_source_files = source_map.files();
539
540 let required_source_files = self.required_source_files.take().unwrap();
544
545 let mut adapted = TableBuilder::default();
546
547 let local_crate_stable_id = self.tcx.stable_crate_id(LOCAL_CRATE);
548
549 for (on_disk_index, &source_file_index) in required_source_files.iter().enumerate() {
554 let source_file = &all_source_files[source_file_index];
555 if !(!source_file.is_imported() || self.is_proc_macro) {
::core::panicking::panic("assertion failed: !source_file.is_imported() || self.is_proc_macro")
};assert!(!source_file.is_imported() || self.is_proc_macro);
557
558 let mut adapted_source_file = (**source_file).clone();
566
567 match source_file.name {
568 FileName::Real(ref original_file_name) => {
569 let mut adapted_file_name = original_file_name.clone();
570 adapted_file_name.update_for_crate_metadata();
571 adapted_source_file.name = FileName::Real(adapted_file_name);
572 }
573 _ => {
574 }
576 };
577
578 if self.is_proc_macro {
585 adapted_source_file.cnum = LOCAL_CRATE;
586 }
587
588 adapted_source_file.stable_id = StableSourceFileId::from_filename_for_export(
592 &adapted_source_file.name,
593 local_crate_stable_id,
594 );
595
596 let on_disk_index: u32 =
597 on_disk_index.try_into().expect("cannot export more than U32_MAX files");
598 adapted.set_some(on_disk_index, self.lazy(adapted_source_file));
599 }
600
601 adapted.encode(&mut self.opaque)
602 }
603
604 fn encode_crate_root(&mut self) -> LazyValue<CrateRoot> {
605 let tcx = self.tcx;
606 let mut stats: Vec<(&'static str, usize)> = Vec::with_capacity(32);
607
608 macro_rules! stat {
609 ($label:literal, $f:expr) => {{
610 let orig_pos = self.position();
611 let res = $f();
612 stats.push(($label, self.position() - orig_pos));
613 res
614 }};
615 }
616
617 stats.push(("preamble", self.position()));
619
620 let externally_implementable_items = {
let orig_pos = self.position();
let res = (|| self.encode_externally_implementable_items())();
stats.push(("externally-implementable-items",
self.position() - orig_pos));
res
}stat!("externally-implementable-items", || self
621 .encode_externally_implementable_items());
622
623 let (crate_deps, dylib_dependency_formats) =
624 {
let orig_pos = self.position();
let res =
(||
(self.encode_crate_deps(),
self.encode_dylib_dependency_formats()))();
stats.push(("dep", self.position() - orig_pos));
res
}stat!("dep", || (self.encode_crate_deps(), self.encode_dylib_dependency_formats()));
625
626 let lib_features = {
let orig_pos = self.position();
let res = (|| self.encode_lib_features())();
stats.push(("lib-features", self.position() - orig_pos));
res
}stat!("lib-features", || self.encode_lib_features());
627
628 let stability_implications =
629 {
let orig_pos = self.position();
let res = (|| self.encode_stability_implications())();
stats.push(("stability-implications", self.position() - orig_pos));
res
}stat!("stability-implications", || self.encode_stability_implications());
630
631 let (lang_items, lang_items_missing) = {
let orig_pos = self.position();
let res =
(||
{
(self.encode_lang_items(), self.encode_lang_items_missing())
})();
stats.push(("lang-items", self.position() - orig_pos));
res
}stat!("lang-items", || {
632 (self.encode_lang_items(), self.encode_lang_items_missing())
633 });
634
635 let stripped_cfg_items = {
let orig_pos = self.position();
let res = (|| self.encode_stripped_cfg_items())();
stats.push(("stripped-cfg-items", self.position() - orig_pos));
res
}stat!("stripped-cfg-items", || self.encode_stripped_cfg_items());
636
637 let diagnostic_items = {
let orig_pos = self.position();
let res = (|| self.encode_diagnostic_items())();
stats.push(("diagnostic-items", self.position() - orig_pos));
res
}stat!("diagnostic-items", || self.encode_diagnostic_items());
638
639 let native_libraries = {
let orig_pos = self.position();
let res = (|| self.encode_native_libraries())();
stats.push(("native-libs", self.position() - orig_pos));
res
}stat!("native-libs", || self.encode_native_libraries());
640
641 let foreign_modules = {
let orig_pos = self.position();
let res = (|| self.encode_foreign_modules())();
stats.push(("foreign-modules", self.position() - orig_pos));
res
}stat!("foreign-modules", || self.encode_foreign_modules());
642
643 _ = {
let orig_pos = self.position();
let res = (|| self.encode_def_path_table())();
stats.push(("def-path-table", self.position() - orig_pos));
res
}stat!("def-path-table", || self.encode_def_path_table());
644
645 let traits = {
let orig_pos = self.position();
let res = (|| self.encode_traits())();
stats.push(("traits", self.position() - orig_pos));
res
}stat!("traits", || self.encode_traits());
647
648 let impls = {
let orig_pos = self.position();
let res = (|| self.encode_impls())();
stats.push(("impls", self.position() - orig_pos));
res
}stat!("impls", || self.encode_impls());
650
651 let incoherent_impls = {
let orig_pos = self.position();
let res = (|| self.encode_incoherent_impls())();
stats.push(("incoherent-impls", self.position() - orig_pos));
res
}stat!("incoherent-impls", || self.encode_incoherent_impls());
652
653 _ = {
let orig_pos = self.position();
let res = (|| self.encode_mir())();
stats.push(("mir", self.position() - orig_pos));
res
}stat!("mir", || self.encode_mir());
654
655 _ = {
let orig_pos = self.position();
let res = (|| self.encode_def_ids())();
stats.push(("def-ids", self.position() - orig_pos));
res
}stat!("def-ids", || self.encode_def_ids());
656
657 let interpret_alloc_index = {
let orig_pos = self.position();
let res =
(||
{
let mut interpret_alloc_index = Vec::new();
let mut n = 0;
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_metadata/src/rmeta/encoder.rs:660",
"rustc_metadata::rmeta::encoder", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(660u32),
::tracing_core::__macro_support::Option::Some("rustc_metadata::rmeta::encoder"),
::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!("beginning to encode alloc ids")
as &dyn Value))])
});
} else { ; }
};
loop {
let new_n = self.interpret_allocs.len();
if n == new_n { break; }
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_metadata/src/rmeta/encoder.rs:668",
"rustc_metadata::rmeta::encoder", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(668u32),
::tracing_core::__macro_support::Option::Some("rustc_metadata::rmeta::encoder"),
::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!("encoding {0} further alloc ids",
new_n - n) as &dyn Value))])
});
} else { ; }
};
for idx in n..new_n {
let id = self.interpret_allocs[idx];
let pos = self.position() as u64;
interpret_alloc_index.push(pos);
interpret::specialized_encode_alloc_id(self, tcx, id);
}
n = new_n;
}
self.lazy_array(interpret_alloc_index)
})();
stats.push(("interpret-alloc-index", self.position() - orig_pos));
res
}stat!("interpret-alloc-index", || {
658 let mut interpret_alloc_index = Vec::new();
659 let mut n = 0;
660 trace!("beginning to encode alloc ids");
661 loop {
662 let new_n = self.interpret_allocs.len();
663 if n == new_n {
665 break;
667 }
668 trace!("encoding {} further alloc ids", new_n - n);
669 for idx in n..new_n {
670 let id = self.interpret_allocs[idx];
671 let pos = self.position() as u64;
672 interpret_alloc_index.push(pos);
673 interpret::specialized_encode_alloc_id(self, tcx, id);
674 }
675 n = new_n;
676 }
677 self.lazy_array(interpret_alloc_index)
678 });
679
680 let proc_macro_data = {
let orig_pos = self.position();
let res = (|| self.encode_proc_macros())();
stats.push(("proc-macro-data", self.position() - orig_pos));
res
}stat!("proc-macro-data", || self.encode_proc_macros());
684
685 let tables = {
let orig_pos = self.position();
let res = (|| self.tables.encode(&mut self.opaque))();
stats.push(("tables", self.position() - orig_pos));
res
}stat!("tables", || self.tables.encode(&mut self.opaque));
686
687 let debugger_visualizers =
688 {
let orig_pos = self.position();
let res = (|| self.encode_debugger_visualizers())();
stats.push(("debugger-visualizers", self.position() - orig_pos));
res
}stat!("debugger-visualizers", || self.encode_debugger_visualizers());
689
690 let exportable_items = {
let orig_pos = self.position();
let res = (|| self.encode_exportable_items())();
stats.push(("exportable-items", self.position() - orig_pos));
res
}stat!("exportable-items", || self.encode_exportable_items());
691
692 let stable_order_of_exportable_impls =
693 {
let orig_pos = self.position();
let res = (|| self.encode_stable_order_of_exportable_impls())();
stats.push(("exportable-items", self.position() - orig_pos));
res
}stat!("exportable-items", || self.encode_stable_order_of_exportable_impls());
694
695 let (exported_non_generic_symbols, exported_generic_symbols) =
697 {
let orig_pos = self.position();
let res =
(||
{
(self.encode_exported_symbols(tcx.exported_non_generic_symbols(LOCAL_CRATE)),
self.encode_exported_symbols(tcx.exported_generic_symbols(LOCAL_CRATE)))
})();
stats.push(("exported-symbols", self.position() - orig_pos));
res
}stat!("exported-symbols", || {
698 (
699 self.encode_exported_symbols(tcx.exported_non_generic_symbols(LOCAL_CRATE)),
700 self.encode_exported_symbols(tcx.exported_generic_symbols(LOCAL_CRATE)),
701 )
702 });
703
704 let (syntax_contexts, expn_data, expn_hashes) = {
let orig_pos = self.position();
let res = (|| self.encode_hygiene())();
stats.push(("hygiene", self.position() - orig_pos));
res
}stat!("hygiene", || self.encode_hygiene());
711
712 let def_path_hash_map = {
let orig_pos = self.position();
let res = (|| self.encode_def_path_hash_map())();
stats.push(("def-path-hash-map", self.position() - orig_pos));
res
}stat!("def-path-hash-map", || self.encode_def_path_hash_map());
713
714 let source_map = {
let orig_pos = self.position();
let res = (|| self.encode_source_map())();
stats.push(("source-map", self.position() - orig_pos));
res
}stat!("source-map", || self.encode_source_map());
717 let target_modifiers = {
let orig_pos = self.position();
let res = (|| self.encode_target_modifiers())();
stats.push(("target-modifiers", self.position() - orig_pos));
res
}stat!("target-modifiers", || self.encode_target_modifiers());
718
719 let root = {
let orig_pos = self.position();
let res =
(||
{
let attrs = tcx.hir_krate_attrs();
self.lazy(CrateRoot {
header: CrateHeader {
name: tcx.crate_name(LOCAL_CRATE),
triple: tcx.sess.opts.target_triple.clone(),
hash: tcx.crate_hash(LOCAL_CRATE),
is_proc_macro_crate: proc_macro_data.is_some(),
is_stub: false,
},
extra_filename: tcx.sess.opts.cg.extra_filename.clone(),
stable_crate_id: tcx.stable_crate_id(LOCAL_CRATE),
required_panic_strategy: tcx.required_panic_strategy(LOCAL_CRATE),
panic_in_drop_strategy: tcx.sess.opts.unstable_opts.panic_in_drop,
edition: tcx.sess.edition(),
has_global_allocator: tcx.has_global_allocator(LOCAL_CRATE),
has_alloc_error_handler: tcx.has_alloc_error_handler(LOCAL_CRATE),
has_panic_handler: tcx.has_panic_handler(LOCAL_CRATE),
has_default_lib_allocator: {
{
'done:
{
for i in attrs {
#[allow(unused_imports)]
use rustc_hir::attrs::AttributeKind::*;
let i: &rustc_hir::Attribute = i;
match i {
rustc_hir::Attribute::Parsed(DefaultLibAllocator) => {
break 'done Some(());
}
rustc_hir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}.is_some()
},
externally_implementable_items,
proc_macro_data,
debugger_visualizers,
compiler_builtins: {
{
'done:
{
for i in attrs {
#[allow(unused_imports)]
use rustc_hir::attrs::AttributeKind::*;
let i: &rustc_hir::Attribute = i;
match i {
rustc_hir::Attribute::Parsed(CompilerBuiltins) => {
break 'done Some(());
}
rustc_hir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}.is_some()
},
needs_allocator: {
{
'done:
{
for i in attrs {
#[allow(unused_imports)]
use rustc_hir::attrs::AttributeKind::*;
let i: &rustc_hir::Attribute = i;
match i {
rustc_hir::Attribute::Parsed(NeedsAllocator) => {
break 'done Some(());
}
rustc_hir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}.is_some()
},
needs_panic_runtime: {
{
'done:
{
for i in attrs {
#[allow(unused_imports)]
use rustc_hir::attrs::AttributeKind::*;
let i: &rustc_hir::Attribute = i;
match i {
rustc_hir::Attribute::Parsed(NeedsPanicRuntime) => {
break 'done Some(());
}
rustc_hir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}.is_some()
},
no_builtins: {
{
'done:
{
for i in attrs {
#[allow(unused_imports)]
use rustc_hir::attrs::AttributeKind::*;
let i: &rustc_hir::Attribute = i;
match i {
rustc_hir::Attribute::Parsed(NoBuiltins) => {
break 'done Some(());
}
rustc_hir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}.is_some()
},
panic_runtime: {
{
'done:
{
for i in attrs {
#[allow(unused_imports)]
use rustc_hir::attrs::AttributeKind::*;
let i: &rustc_hir::Attribute = i;
match i {
rustc_hir::Attribute::Parsed(PanicRuntime) => {
break 'done Some(());
}
rustc_hir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}.is_some()
},
profiler_runtime: {
{
'done:
{
for i in attrs {
#[allow(unused_imports)]
use rustc_hir::attrs::AttributeKind::*;
let i: &rustc_hir::Attribute = i;
match i {
rustc_hir::Attribute::Parsed(ProfilerRuntime) => {
break 'done Some(());
}
rustc_hir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}.is_some()
},
symbol_mangling_version: tcx.sess.opts.get_symbol_mangling_version(),
crate_deps,
dylib_dependency_formats,
lib_features,
stability_implications,
lang_items,
diagnostic_items,
lang_items_missing,
stripped_cfg_items,
native_libraries,
foreign_modules,
source_map,
target_modifiers,
traits,
impls,
incoherent_impls,
exportable_items,
stable_order_of_exportable_impls,
exported_non_generic_symbols,
exported_generic_symbols,
interpret_alloc_index,
tables,
syntax_contexts,
expn_data,
expn_hashes,
def_path_hash_map,
specialization_enabled_in: tcx.specialization_enabled_in(LOCAL_CRATE),
})
})();
stats.push(("final", self.position() - orig_pos));
res
}stat!("final", || {
720 let attrs = tcx.hir_krate_attrs();
721 self.lazy(CrateRoot {
722 header: CrateHeader {
723 name: tcx.crate_name(LOCAL_CRATE),
724 triple: tcx.sess.opts.target_triple.clone(),
725 hash: tcx.crate_hash(LOCAL_CRATE),
726 is_proc_macro_crate: proc_macro_data.is_some(),
727 is_stub: false,
728 },
729 extra_filename: tcx.sess.opts.cg.extra_filename.clone(),
730 stable_crate_id: tcx.stable_crate_id(LOCAL_CRATE),
731 required_panic_strategy: tcx.required_panic_strategy(LOCAL_CRATE),
732 panic_in_drop_strategy: tcx.sess.opts.unstable_opts.panic_in_drop,
733 edition: tcx.sess.edition(),
734 has_global_allocator: tcx.has_global_allocator(LOCAL_CRATE),
735 has_alloc_error_handler: tcx.has_alloc_error_handler(LOCAL_CRATE),
736 has_panic_handler: tcx.has_panic_handler(LOCAL_CRATE),
737 has_default_lib_allocator: find_attr!(attrs, DefaultLibAllocator),
738 externally_implementable_items,
739 proc_macro_data,
740 debugger_visualizers,
741 compiler_builtins: find_attr!(attrs, CompilerBuiltins),
742 needs_allocator: find_attr!(attrs, NeedsAllocator),
743 needs_panic_runtime: find_attr!(attrs, NeedsPanicRuntime),
744 no_builtins: find_attr!(attrs, NoBuiltins),
745 panic_runtime: find_attr!(attrs, PanicRuntime),
746 profiler_runtime: find_attr!(attrs, ProfilerRuntime),
747 symbol_mangling_version: tcx.sess.opts.get_symbol_mangling_version(),
748
749 crate_deps,
750 dylib_dependency_formats,
751 lib_features,
752 stability_implications,
753 lang_items,
754 diagnostic_items,
755 lang_items_missing,
756 stripped_cfg_items,
757 native_libraries,
758 foreign_modules,
759 source_map,
760 target_modifiers,
761 traits,
762 impls,
763 incoherent_impls,
764 exportable_items,
765 stable_order_of_exportable_impls,
766 exported_non_generic_symbols,
767 exported_generic_symbols,
768 interpret_alloc_index,
769 tables,
770 syntax_contexts,
771 expn_data,
772 expn_hashes,
773 def_path_hash_map,
774 specialization_enabled_in: tcx.specialization_enabled_in(LOCAL_CRATE),
775 })
776 });
777
778 let total_bytes = self.position();
779
780 let computed_total_bytes: usize = stats.iter().map(|(_, size)| size).sum();
781 match (&total_bytes, &computed_total_bytes) {
(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!(total_bytes, computed_total_bytes);
782
783 if tcx.sess.opts.unstable_opts.meta_stats {
784 use std::fmt::Write;
785
786 self.opaque.flush();
787
788 let pos_before_rewind = self.opaque.file().stream_position().unwrap();
790 let mut zero_bytes = 0;
791 self.opaque.file().rewind().unwrap();
792 let file = std::io::BufReader::new(self.opaque.file());
793 for e in file.bytes() {
794 if e.unwrap() == 0 {
795 zero_bytes += 1;
796 }
797 }
798 match (&self.opaque.file().stream_position().unwrap(), &pos_before_rewind) {
(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!(self.opaque.file().stream_position().unwrap(), pos_before_rewind);
799
800 stats.sort_by_key(|&(_, usize)| usize);
801 stats.reverse(); let prefix = "meta-stats";
804 let perc = |bytes| (bytes * 100) as f64 / total_bytes as f64;
805
806 let section_w = 23;
807 let size_w = 10;
808 let banner_w = 64;
809
810 let mut s = String::new();
816 _ = s.write_fmt(format_args!("{1} {0}\n", "=".repeat(banner_w), prefix))writeln!(s, "{prefix} {}", "=".repeat(banner_w));
817 _ = s.write_fmt(format_args!("{1} METADATA STATS: {0}\n",
tcx.crate_name(LOCAL_CRATE), prefix))writeln!(s, "{prefix} METADATA STATS: {}", tcx.crate_name(LOCAL_CRATE));
818 _ = s.write_fmt(format_args!("{2} {0:<3$}{1:>4$}\n", "Section", "Size", prefix,
section_w, size_w))writeln!(s, "{prefix} {:<section_w$}{:>size_w$}", "Section", "Size");
819 _ = s.write_fmt(format_args!("{1} {0}\n", "-".repeat(banner_w), prefix))writeln!(s, "{prefix} {}", "-".repeat(banner_w));
820 for (label, size) in stats {
821 _ = s.write_fmt(format_args!("{3} {0:<4$}{1:>5$} ({2:4.1}%)\n", label,
usize_with_underscores(size), perc(size), prefix, section_w, size_w))writeln!(
822 s,
823 "{prefix} {:<section_w$}{:>size_w$} ({:4.1}%)",
824 label,
825 usize_with_underscores(size),
826 perc(size)
827 );
828 }
829 _ = s.write_fmt(format_args!("{1} {0}\n", "-".repeat(banner_w), prefix))writeln!(s, "{prefix} {}", "-".repeat(banner_w));
830 _ = s.write_fmt(format_args!("{3} {0:<4$}{1:>5$} (of which {2:.1}% are zero bytes)\n",
"Total", usize_with_underscores(total_bytes), perc(zero_bytes),
prefix, section_w, size_w))writeln!(
831 s,
832 "{prefix} {:<section_w$}{:>size_w$} (of which {:.1}% are zero bytes)",
833 "Total",
834 usize_with_underscores(total_bytes),
835 perc(zero_bytes)
836 );
837 _ = s.write_fmt(format_args!("{1} {0}\n", "=".repeat(banner_w), prefix))writeln!(s, "{prefix} {}", "=".repeat(banner_w));
838 { ::std::io::_eprint(format_args!("{0}", s)); };eprint!("{s}");
839 }
840
841 root
842 }
843}
844
845struct AnalyzeAttrState<'a> {
846 is_exported: bool,
847 is_doc_hidden: bool,
848 features: &'a Features,
849}
850
851#[inline]
861fn analyze_attr(attr: &hir::Attribute, state: &mut AnalyzeAttrState<'_>) -> bool {
862 let mut should_encode = false;
863 if let hir::Attribute::Parsed(p) = attr
864 && p.encode_cross_crate() == EncodeCrossCrate::No
865 {
866 } else if let hir::Attribute::Parsed(AttributeKind::DocComment { .. }) = attr {
868 if state.is_exported {
872 should_encode = true;
873 }
874 } else if let hir::Attribute::Parsed(AttributeKind::Doc(d)) = attr {
875 should_encode = true;
876 if d.hidden.is_some() {
877 state.is_doc_hidden = true;
878 }
879 } else if let &[sym::diagnostic, seg] = &*attr.path() {
880 should_encode = rustc_feature::is_stable_diagnostic_attribute(seg, state.features);
881 } else {
882 should_encode = true;
883 }
884 should_encode
885}
886
887fn should_encode_span(def_kind: DefKind) -> bool {
888 match def_kind {
889 DefKind::Mod
890 | DefKind::Struct
891 | DefKind::Union
892 | DefKind::Enum
893 | DefKind::Variant
894 | DefKind::Trait
895 | DefKind::TyAlias
896 | DefKind::ForeignTy
897 | DefKind::TraitAlias
898 | DefKind::AssocTy
899 | DefKind::TyParam
900 | DefKind::ConstParam
901 | DefKind::LifetimeParam
902 | DefKind::Fn
903 | DefKind::Const { .. }
904 | DefKind::Static { .. }
905 | DefKind::Ctor(..)
906 | DefKind::AssocFn
907 | DefKind::AssocConst { .. }
908 | DefKind::Macro(_)
909 | DefKind::ExternCrate
910 | DefKind::Use
911 | DefKind::AnonConst
912 | DefKind::InlineConst
913 | DefKind::OpaqueTy
914 | DefKind::Field
915 | DefKind::Impl { .. }
916 | DefKind::Closure
917 | DefKind::SyntheticCoroutineBody => true,
918 DefKind::ForeignMod | DefKind::GlobalAsm => false,
919 }
920}
921
922fn should_encode_attrs(def_kind: DefKind) -> bool {
923 match def_kind {
924 DefKind::Mod
925 | DefKind::Struct
926 | DefKind::Union
927 | DefKind::Enum
928 | DefKind::Variant
929 | DefKind::Trait
930 | DefKind::TyAlias
931 | DefKind::ForeignTy
932 | DefKind::TraitAlias
933 | DefKind::AssocTy
934 | DefKind::Fn
935 | DefKind::Const { .. }
936 | DefKind::Static { nested: false, .. }
937 | DefKind::AssocFn
938 | DefKind::AssocConst { .. }
939 | DefKind::Macro(_)
940 | DefKind::Field
941 | DefKind::Impl { .. } => true,
942 DefKind::Closure => true,
947 DefKind::SyntheticCoroutineBody => false,
948 DefKind::TyParam
949 | DefKind::ConstParam
950 | DefKind::Ctor(..)
951 | DefKind::ExternCrate
952 | DefKind::Use
953 | DefKind::ForeignMod
954 | DefKind::AnonConst
955 | DefKind::InlineConst
956 | DefKind::OpaqueTy
957 | DefKind::LifetimeParam
958 | DefKind::Static { nested: true, .. }
959 | DefKind::GlobalAsm => false,
960 }
961}
962
963fn should_encode_expn_that_defined(def_kind: DefKind) -> bool {
964 match def_kind {
965 DefKind::Mod
966 | DefKind::Struct
967 | DefKind::Union
968 | DefKind::Enum
969 | DefKind::Variant
970 | DefKind::Trait
971 | DefKind::Impl { .. } => true,
972 DefKind::TyAlias
973 | DefKind::ForeignTy
974 | DefKind::TraitAlias
975 | DefKind::AssocTy
976 | DefKind::TyParam
977 | DefKind::Fn
978 | DefKind::Const { .. }
979 | DefKind::ConstParam
980 | DefKind::Static { .. }
981 | DefKind::Ctor(..)
982 | DefKind::AssocFn
983 | DefKind::AssocConst { .. }
984 | DefKind::Macro(_)
985 | DefKind::ExternCrate
986 | DefKind::Use
987 | DefKind::ForeignMod
988 | DefKind::AnonConst
989 | DefKind::InlineConst
990 | DefKind::OpaqueTy
991 | DefKind::Field
992 | DefKind::LifetimeParam
993 | DefKind::GlobalAsm
994 | DefKind::Closure
995 | DefKind::SyntheticCoroutineBody => false,
996 }
997}
998
999fn should_encode_visibility(def_kind: DefKind) -> bool {
1000 match def_kind {
1001 DefKind::Mod
1002 | DefKind::Struct
1003 | DefKind::Union
1004 | DefKind::Enum
1005 | DefKind::Variant
1006 | DefKind::Trait
1007 | DefKind::TyAlias
1008 | DefKind::ForeignTy
1009 | DefKind::TraitAlias
1010 | DefKind::AssocTy
1011 | DefKind::Fn
1012 | DefKind::Const { .. }
1013 | DefKind::Static { nested: false, .. }
1014 | DefKind::Ctor(..)
1015 | DefKind::AssocFn
1016 | DefKind::AssocConst { .. }
1017 | DefKind::Macro(..)
1018 | DefKind::Field => true,
1019 DefKind::Use
1020 | DefKind::ForeignMod
1021 | DefKind::TyParam
1022 | DefKind::ConstParam
1023 | DefKind::LifetimeParam
1024 | DefKind::AnonConst
1025 | DefKind::InlineConst
1026 | DefKind::Static { nested: true, .. }
1027 | DefKind::OpaqueTy
1028 | DefKind::GlobalAsm
1029 | DefKind::Impl { .. }
1030 | DefKind::Closure
1031 | DefKind::ExternCrate
1032 | DefKind::SyntheticCoroutineBody => false,
1033 }
1034}
1035
1036fn should_encode_stability(def_kind: DefKind) -> bool {
1037 match def_kind {
1038 DefKind::Mod
1039 | DefKind::Ctor(..)
1040 | DefKind::Variant
1041 | DefKind::Field
1042 | DefKind::Struct
1043 | DefKind::AssocTy
1044 | DefKind::AssocFn
1045 | DefKind::AssocConst { .. }
1046 | DefKind::TyParam
1047 | DefKind::ConstParam
1048 | DefKind::Static { .. }
1049 | DefKind::Const { .. }
1050 | DefKind::Fn
1051 | DefKind::ForeignMod
1052 | DefKind::TyAlias
1053 | DefKind::OpaqueTy
1054 | DefKind::Enum
1055 | DefKind::Union
1056 | DefKind::Impl { .. }
1057 | DefKind::Trait
1058 | DefKind::TraitAlias
1059 | DefKind::Macro(..)
1060 | DefKind::ForeignTy => true,
1061 DefKind::Use
1062 | DefKind::LifetimeParam
1063 | DefKind::AnonConst
1064 | DefKind::InlineConst
1065 | DefKind::GlobalAsm
1066 | DefKind::Closure
1067 | DefKind::ExternCrate
1068 | DefKind::SyntheticCoroutineBody => false,
1069 }
1070}
1071
1072fn should_encode_mir(
1093 tcx: TyCtxt<'_>,
1094 reachable_set: &LocalDefIdSet,
1095 def_id: LocalDefId,
1096) -> (bool, bool) {
1097 match tcx.def_kind(def_id) {
1098 DefKind::Ctor(_, _) => (true, false),
1100 DefKind::AnonConst { .. }
1102 | DefKind::InlineConst
1103 | DefKind::AssocConst { .. }
1104 | DefKind::Const { .. } => (true, false),
1105 DefKind::Closure if tcx.is_coroutine(def_id.to_def_id()) => (false, true),
1107 DefKind::SyntheticCoroutineBody => (false, true),
1108 DefKind::AssocFn | DefKind::Fn | DefKind::Closure => {
1110 let opt = tcx.sess.opts.unstable_opts.always_encode_mir
1111 || (tcx.sess.opts.output_types.should_codegen()
1112 && reachable_set.contains(&def_id)
1113 && (tcx.generics_of(def_id).requires_monomorphization(tcx)
1114 || tcx.cross_crate_inlinable(def_id)));
1115 let is_const_fn = tcx.is_const_fn(def_id.to_def_id());
1117 (is_const_fn, opt)
1118 }
1119 _ => (false, false),
1121 }
1122}
1123
1124fn should_encode_variances<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, def_kind: DefKind) -> bool {
1125 match def_kind {
1126 DefKind::Struct
1127 | DefKind::Union
1128 | DefKind::Enum
1129 | DefKind::OpaqueTy
1130 | DefKind::Fn
1131 | DefKind::Ctor(..)
1132 | DefKind::AssocFn => true,
1133 DefKind::AssocTy => {
1134 #[allow(non_exhaustive_omitted_patterns)] match tcx.opt_rpitit_info(def_id) {
Some(ty::ImplTraitInTraitData::Trait { .. }) => true,
_ => false,
}matches!(tcx.opt_rpitit_info(def_id), Some(ty::ImplTraitInTraitData::Trait { .. }))
1136 }
1137 DefKind::Mod
1138 | DefKind::Variant
1139 | DefKind::Field
1140 | DefKind::AssocConst { .. }
1141 | DefKind::TyParam
1142 | DefKind::ConstParam
1143 | DefKind::Static { .. }
1144 | DefKind::Const { .. }
1145 | DefKind::ForeignMod
1146 | DefKind::Impl { .. }
1147 | DefKind::Trait
1148 | DefKind::TraitAlias
1149 | DefKind::Macro(..)
1150 | DefKind::ForeignTy
1151 | DefKind::Use
1152 | DefKind::LifetimeParam
1153 | DefKind::AnonConst
1154 | DefKind::InlineConst
1155 | DefKind::GlobalAsm
1156 | DefKind::Closure
1157 | DefKind::ExternCrate
1158 | DefKind::SyntheticCoroutineBody => false,
1159 DefKind::TyAlias => tcx.type_alias_is_lazy(def_id),
1160 }
1161}
1162
1163fn should_encode_generics(def_kind: DefKind) -> bool {
1164 match def_kind {
1165 DefKind::Struct
1166 | DefKind::Union
1167 | DefKind::Enum
1168 | DefKind::Variant
1169 | DefKind::Trait
1170 | DefKind::TyAlias
1171 | DefKind::ForeignTy
1172 | DefKind::TraitAlias
1173 | DefKind::AssocTy
1174 | DefKind::Fn
1175 | DefKind::Const { .. }
1176 | DefKind::Static { .. }
1177 | DefKind::Ctor(..)
1178 | DefKind::AssocFn
1179 | DefKind::AssocConst { .. }
1180 | DefKind::AnonConst
1181 | DefKind::InlineConst
1182 | DefKind::OpaqueTy
1183 | DefKind::Impl { .. }
1184 | DefKind::Field
1185 | DefKind::TyParam
1186 | DefKind::Closure
1187 | DefKind::SyntheticCoroutineBody => true,
1188 DefKind::Mod
1189 | DefKind::ForeignMod
1190 | DefKind::ConstParam
1191 | DefKind::Macro(..)
1192 | DefKind::Use
1193 | DefKind::LifetimeParam
1194 | DefKind::GlobalAsm
1195 | DefKind::ExternCrate => false,
1196 }
1197}
1198
1199fn should_encode_type(tcx: TyCtxt<'_>, def_id: LocalDefId, def_kind: DefKind) -> bool {
1200 match def_kind {
1201 DefKind::Struct
1202 | DefKind::Union
1203 | DefKind::Enum
1204 | DefKind::Variant
1205 | DefKind::Ctor(..)
1206 | DefKind::Field
1207 | DefKind::Fn
1208 | DefKind::Const { .. }
1209 | DefKind::Static { nested: false, .. }
1210 | DefKind::TyAlias
1211 | DefKind::ForeignTy
1212 | DefKind::Impl { .. }
1213 | DefKind::AssocFn
1214 | DefKind::AssocConst { .. }
1215 | DefKind::Closure
1216 | DefKind::ConstParam
1217 | DefKind::AnonConst
1218 | DefKind::InlineConst
1219 | DefKind::SyntheticCoroutineBody => true,
1220
1221 DefKind::OpaqueTy => {
1222 let origin = tcx.local_opaque_ty_origin(def_id);
1223 if let hir::OpaqueTyOrigin::FnReturn { parent, .. }
1224 | hir::OpaqueTyOrigin::AsyncFn { parent, .. } = origin
1225 && let hir::Node::TraitItem(trait_item) = tcx.hir_node_by_def_id(parent)
1226 && let (_, hir::TraitFn::Required(..)) = trait_item.expect_fn()
1227 {
1228 false
1229 } else {
1230 true
1231 }
1232 }
1233
1234 DefKind::AssocTy => {
1235 let assoc_item = tcx.associated_item(def_id);
1236 match assoc_item.container {
1237 ty::AssocContainer::InherentImpl | ty::AssocContainer::TraitImpl(_) => true,
1238 ty::AssocContainer::Trait => assoc_item.defaultness(tcx).has_value(),
1239 }
1240 }
1241 DefKind::TyParam => {
1242 let hir::Node::GenericParam(param) = tcx.hir_node_by_def_id(def_id) else { ::rustc_middle::util::bug::bug_fmt(format_args!("impossible case reached"))bug!() };
1243 let hir::GenericParamKind::Type { default, .. } = param.kind else { ::rustc_middle::util::bug::bug_fmt(format_args!("impossible case reached"))bug!() };
1244 default.is_some()
1245 }
1246
1247 DefKind::Trait
1248 | DefKind::TraitAlias
1249 | DefKind::Mod
1250 | DefKind::ForeignMod
1251 | DefKind::Macro(..)
1252 | DefKind::Static { nested: true, .. }
1253 | DefKind::Use
1254 | DefKind::LifetimeParam
1255 | DefKind::GlobalAsm
1256 | DefKind::ExternCrate => false,
1257 }
1258}
1259
1260fn should_encode_fn_sig(def_kind: DefKind) -> bool {
1261 match def_kind {
1262 DefKind::Fn | DefKind::AssocFn | DefKind::Ctor(_, CtorKind::Fn) => true,
1263
1264 DefKind::Struct
1265 | DefKind::Union
1266 | DefKind::Enum
1267 | DefKind::Variant
1268 | DefKind::Field
1269 | DefKind::Const { .. }
1270 | DefKind::Static { .. }
1271 | DefKind::Ctor(..)
1272 | DefKind::TyAlias
1273 | DefKind::OpaqueTy
1274 | DefKind::ForeignTy
1275 | DefKind::Impl { .. }
1276 | DefKind::AssocConst { .. }
1277 | DefKind::Closure
1278 | DefKind::ConstParam
1279 | DefKind::AnonConst
1280 | DefKind::InlineConst
1281 | DefKind::AssocTy
1282 | DefKind::TyParam
1283 | DefKind::Trait
1284 | DefKind::TraitAlias
1285 | DefKind::Mod
1286 | DefKind::ForeignMod
1287 | DefKind::Macro(..)
1288 | DefKind::Use
1289 | DefKind::LifetimeParam
1290 | DefKind::GlobalAsm
1291 | DefKind::ExternCrate
1292 | DefKind::SyntheticCoroutineBody => false,
1293 }
1294}
1295
1296fn should_encode_constness(def_kind: DefKind) -> bool {
1297 match def_kind {
1298 DefKind::Fn
1299 | DefKind::AssocFn
1300 | DefKind::Closure
1301 | DefKind::Ctor(_, CtorKind::Fn)
1302 | DefKind::Impl { of_trait: false } => true,
1303
1304 DefKind::Struct
1305 | DefKind::Union
1306 | DefKind::Enum
1307 | DefKind::Field
1308 | DefKind::Const { .. }
1309 | DefKind::AssocConst { .. }
1310 | DefKind::AnonConst
1311 | DefKind::Static { .. }
1312 | DefKind::TyAlias
1313 | DefKind::OpaqueTy
1314 | DefKind::Impl { .. }
1315 | DefKind::ForeignTy
1316 | DefKind::ConstParam
1317 | DefKind::InlineConst
1318 | DefKind::AssocTy
1319 | DefKind::TyParam
1320 | DefKind::Trait
1321 | DefKind::TraitAlias
1322 | DefKind::Mod
1323 | DefKind::ForeignMod
1324 | DefKind::Macro(..)
1325 | DefKind::Use
1326 | DefKind::LifetimeParam
1327 | DefKind::GlobalAsm
1328 | DefKind::ExternCrate
1329 | DefKind::Ctor(_, CtorKind::Const)
1330 | DefKind::Variant
1331 | DefKind::SyntheticCoroutineBody => false,
1332 }
1333}
1334
1335fn should_encode_const(def_kind: DefKind) -> bool {
1336 match def_kind {
1337 DefKind::Const { .. }
1339 | DefKind::AssocConst { .. }
1340 | DefKind::AnonConst
1341 | DefKind::InlineConst => true,
1342
1343 DefKind::Struct
1344 | DefKind::Union
1345 | DefKind::Enum
1346 | DefKind::Variant
1347 | DefKind::Ctor(..)
1348 | DefKind::Field
1349 | DefKind::Fn
1350 | DefKind::Static { .. }
1351 | DefKind::TyAlias
1352 | DefKind::OpaqueTy
1353 | DefKind::ForeignTy
1354 | DefKind::Impl { .. }
1355 | DefKind::AssocFn
1356 | DefKind::Closure
1357 | DefKind::ConstParam
1358 | DefKind::AssocTy
1359 | DefKind::TyParam
1360 | DefKind::Trait
1361 | DefKind::TraitAlias
1362 | DefKind::Mod
1363 | DefKind::ForeignMod
1364 | DefKind::Macro(..)
1365 | DefKind::Use
1366 | DefKind::LifetimeParam
1367 | DefKind::GlobalAsm
1368 | DefKind::ExternCrate
1369 | DefKind::SyntheticCoroutineBody => false,
1370 }
1371}
1372
1373fn should_encode_const_of_item<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, def_kind: DefKind) -> bool {
1374 tcx.is_type_const(def_id)
1376 && (!#[allow(non_exhaustive_omitted_patterns)] match def_kind {
DefKind::AssocConst { .. } => true,
_ => false,
}matches!(def_kind, DefKind::AssocConst { .. }) || assoc_item_has_value(tcx, def_id))
1377}
1378
1379fn assoc_item_has_value<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool {
1380 let assoc_item = tcx.associated_item(def_id);
1381 match assoc_item.container {
1382 ty::AssocContainer::InherentImpl | ty::AssocContainer::TraitImpl(_) => true,
1383 ty::AssocContainer::Trait => assoc_item.defaultness(tcx).has_value(),
1384 }
1385}
1386
1387impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1388 fn encode_attrs(&mut self, def_id: LocalDefId) {
1389 let tcx = self.tcx;
1390 let mut state = AnalyzeAttrState {
1391 is_exported: tcx.effective_visibilities(()).is_exported(def_id),
1392 is_doc_hidden: false,
1393 features: &tcx.features(),
1394 };
1395 let attr_iter = tcx
1396 .hir_attrs(tcx.local_def_id_to_hir_id(def_id))
1397 .iter()
1398 .filter(|attr| analyze_attr(*attr, &mut state));
1399
1400 {
{
let value = attr_iter;
let lazy = self.lazy_array(value);
self.tables.attributes.set_some(def_id.to_def_id().index, lazy);
}
};record_array!(self.tables.attributes[def_id.to_def_id()] <- attr_iter);
1401
1402 let mut attr_flags = AttrFlags::empty();
1403 if state.is_doc_hidden {
1404 attr_flags |= AttrFlags::IS_DOC_HIDDEN;
1405 }
1406 self.tables.attr_flags.set(def_id.local_def_index, attr_flags);
1407 }
1408
1409 fn encode_def_ids(&mut self) {
1410 self.encode_info_for_mod(CRATE_DEF_ID);
1411
1412 if self.is_proc_macro {
1415 return;
1416 }
1417
1418 let tcx = self.tcx;
1419
1420 for local_id in tcx.iter_local_def_id() {
1421 let def_id = local_id.to_def_id();
1422 let def_kind = tcx.def_kind(local_id);
1423 self.tables.def_kind.set_some(def_id.index, def_kind);
1424
1425 if def_kind == DefKind::AnonConst
1430 && match tcx.hir_node_by_def_id(local_id) {
1431 hir::Node::ConstArg(hir::ConstArg { kind, .. }) => match kind {
1432 hir::ConstArgKind::Error(..)
1434 | hir::ConstArgKind::Struct(..)
1435 | hir::ConstArgKind::Array(..)
1436 | hir::ConstArgKind::TupleCall(..)
1437 | hir::ConstArgKind::Tup(..)
1438 | hir::ConstArgKind::Path(..)
1439 | hir::ConstArgKind::Literal { .. }
1440 | hir::ConstArgKind::Infer(..) => true,
1441 hir::ConstArgKind::Anon(..) => false,
1442 },
1443 _ => false,
1444 }
1445 {
1446 if !tcx.features().min_generic_const_args() {
1448 continue;
1449 }
1450 }
1451
1452 if def_kind == DefKind::Field
1453 && let hir::Node::Field(field) = tcx.hir_node_by_def_id(local_id)
1454 && let Some(anon) = field.default
1455 {
1456 {
{
let value = anon.def_id.to_def_id();
let lazy = self.lazy(value);
self.tables.default_fields.set_some(def_id.index, lazy);
}
};record!(self.tables.default_fields[def_id] <- anon.def_id.to_def_id());
1457 }
1458
1459 if should_encode_span(def_kind) {
1460 let def_span = tcx.def_span(local_id);
1461 {
{
let value = def_span;
let lazy = self.lazy(value);
self.tables.def_span.set_some(def_id.index, lazy);
}
};record!(self.tables.def_span[def_id] <- def_span);
1462 }
1463 if should_encode_attrs(def_kind) {
1464 self.encode_attrs(local_id);
1465 }
1466 if should_encode_expn_that_defined(def_kind) {
1467 {
{
let value = self.tcx.expn_that_defined(def_id);
let lazy = self.lazy(value);
self.tables.expn_that_defined.set_some(def_id.index, lazy);
}
};record!(self.tables.expn_that_defined[def_id] <- self.tcx.expn_that_defined(def_id));
1468 }
1469 if should_encode_span(def_kind)
1470 && let Some(ident_span) = tcx.def_ident_span(def_id)
1471 {
1472 {
{
let value = ident_span;
let lazy = self.lazy(value);
self.tables.def_ident_span.set_some(def_id.index, lazy);
}
};record!(self.tables.def_ident_span[def_id] <- ident_span);
1473 }
1474 if def_kind.has_codegen_attrs() {
1475 {
{
let value = self.tcx.codegen_fn_attrs(def_id);
let lazy = self.lazy(value);
self.tables.codegen_fn_attrs.set_some(def_id.index, lazy);
}
};record!(self.tables.codegen_fn_attrs[def_id] <- self.tcx.codegen_fn_attrs(def_id));
1476 }
1477 if should_encode_visibility(def_kind) {
1478 let vis =
1479 self.tcx.local_visibility(local_id).map_id(|def_id| def_id.local_def_index);
1480 {
{
let value = vis;
let lazy = self.lazy(value);
self.tables.visibility.set_some(def_id.index, lazy);
}
};record!(self.tables.visibility[def_id] <- vis);
1481 }
1482 if should_encode_stability(def_kind) {
1483 self.encode_stability(def_id);
1484 self.encode_const_stability(def_id);
1485 self.encode_default_body_stability(def_id);
1486 self.encode_deprecation(def_id);
1487 }
1488 if should_encode_variances(tcx, def_id, def_kind) {
1489 let v = self.tcx.variances_of(def_id);
1490 {
{
let value = v;
let lazy = self.lazy_array(value);
self.tables.variances_of.set_some(def_id.index, lazy);
}
};record_array!(self.tables.variances_of[def_id] <- v);
1491 }
1492 if should_encode_fn_sig(def_kind) {
1493 {
{
let value = tcx.fn_sig(def_id);
let lazy = self.lazy(value);
self.tables.fn_sig.set_some(def_id.index, lazy);
}
};record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id));
1494 }
1495 if should_encode_generics(def_kind) {
1496 let g = tcx.generics_of(def_id);
1497 {
{
let value = g;
let lazy = self.lazy(value);
self.tables.generics_of.set_some(def_id.index, lazy);
}
};record!(self.tables.generics_of[def_id] <- g);
1498 {
{
let value = self.tcx.explicit_predicates_of(def_id);
let lazy = self.lazy(value);
self.tables.explicit_predicates_of.set_some(def_id.index, lazy);
}
};record!(self.tables.explicit_predicates_of[def_id] <- self.tcx.explicit_predicates_of(def_id));
1499 let inferred_outlives = self.tcx.inferred_outlives_of(def_id);
1500 {
{
let value = inferred_outlives;
let lazy = self.lazy_array(value);
self.tables.inferred_outlives_of.set(def_id.index, lazy);
}
};record_defaulted_array!(self.tables.inferred_outlives_of[def_id] <- inferred_outlives);
1501
1502 for param in &g.own_params {
1503 if let ty::GenericParamDefKind::Const { has_default: true, .. } = param.kind {
1504 let default = self.tcx.const_param_default(param.def_id);
1505 {
{
let value = default;
let lazy = self.lazy(value);
self.tables.const_param_default.set_some(param.def_id.index, lazy);
}
};record!(self.tables.const_param_default[param.def_id] <- default);
1506 }
1507 }
1508 }
1509 if tcx.is_conditionally_const(def_id) {
1510 {
{
let value = self.tcx.const_conditions(def_id);
let lazy = self.lazy(value);
self.tables.const_conditions.set_some(def_id.index, lazy);
}
};record!(self.tables.const_conditions[def_id] <- self.tcx.const_conditions(def_id));
1511 }
1512 if should_encode_type(tcx, local_id, def_kind) {
1513 {
{
let value = self.tcx.type_of(def_id);
let lazy = self.lazy(value);
self.tables.type_of.set_some(def_id.index, lazy);
}
};record!(self.tables.type_of[def_id] <- self.tcx.type_of(def_id));
1514 }
1515 if should_encode_constness(def_kind) {
1516 let constness = self.tcx.constness(def_id);
1517 self.tables.constness.set(def_id.index, constness);
1518 }
1519 if let DefKind::Fn | DefKind::AssocFn = def_kind {
1520 let asyncness = tcx.asyncness(def_id);
1521 self.tables.asyncness.set(def_id.index, asyncness);
1522 {
{
let value = tcx.fn_arg_idents(def_id);
let lazy = self.lazy_array(value);
self.tables.fn_arg_idents.set_some(def_id.index, lazy);
}
};record_array!(self.tables.fn_arg_idents[def_id] <- tcx.fn_arg_idents(def_id));
1523 }
1524 if let Some(name) = tcx.intrinsic(def_id) {
1525 {
{
let value = name;
let lazy = self.lazy(value);
self.tables.intrinsic.set_some(def_id.index, lazy);
}
};record!(self.tables.intrinsic[def_id] <- name);
1526 }
1527 if let DefKind::TyParam = def_kind {
1528 let default = self.tcx.object_lifetime_default(def_id);
1529 {
{
let value = default;
let lazy = self.lazy(value);
self.tables.object_lifetime_default.set_some(def_id.index, lazy);
}
};record!(self.tables.object_lifetime_default[def_id] <- default);
1530 }
1531 if let DefKind::Trait = def_kind {
1532 {
{
let value = self.tcx.trait_def(def_id);
let lazy = self.lazy(value);
self.tables.trait_def.set_some(def_id.index, lazy);
}
};record!(self.tables.trait_def[def_id] <- self.tcx.trait_def(def_id));
1533 {
{
let value =
self.tcx.explicit_super_predicates_of(def_id).skip_binder();
let lazy = self.lazy_array(value);
self.tables.explicit_super_predicates_of.set(def_id.index, lazy);
}
};record_defaulted_array!(self.tables.explicit_super_predicates_of[def_id] <-
1534 self.tcx.explicit_super_predicates_of(def_id).skip_binder());
1535 {
{
let value =
self.tcx.explicit_implied_predicates_of(def_id).skip_binder();
let lazy = self.lazy_array(value);
self.tables.explicit_implied_predicates_of.set(def_id.index, lazy);
}
};record_defaulted_array!(self.tables.explicit_implied_predicates_of[def_id] <-
1536 self.tcx.explicit_implied_predicates_of(def_id).skip_binder());
1537 let module_children = self.tcx.module_children_local(local_id);
1538 {
{
let value =
module_children.iter().map(|child| child.res.def_id().index);
let lazy = self.lazy_array(value);
self.tables.module_children_non_reexports.set_some(def_id.index,
lazy);
}
};record_array!(self.tables.module_children_non_reexports[def_id] <-
1539 module_children.iter().map(|child| child.res.def_id().index));
1540 if self.tcx.is_const_trait(def_id) {
1541 {
{
let value =
self.tcx.explicit_implied_const_bounds(def_id).skip_binder();
let lazy = self.lazy_array(value);
self.tables.explicit_implied_const_bounds.set(def_id.index, lazy);
}
};record_defaulted_array!(self.tables.explicit_implied_const_bounds[def_id]
1542 <- self.tcx.explicit_implied_const_bounds(def_id).skip_binder());
1543 }
1544 }
1545 if let DefKind::TraitAlias = def_kind {
1546 {
{
let value = self.tcx.trait_def(def_id);
let lazy = self.lazy(value);
self.tables.trait_def.set_some(def_id.index, lazy);
}
};record!(self.tables.trait_def[def_id] <- self.tcx.trait_def(def_id));
1547 {
{
let value =
self.tcx.explicit_super_predicates_of(def_id).skip_binder();
let lazy = self.lazy_array(value);
self.tables.explicit_super_predicates_of.set(def_id.index, lazy);
}
};record_defaulted_array!(self.tables.explicit_super_predicates_of[def_id] <-
1548 self.tcx.explicit_super_predicates_of(def_id).skip_binder());
1549 {
{
let value =
self.tcx.explicit_implied_predicates_of(def_id).skip_binder();
let lazy = self.lazy_array(value);
self.tables.explicit_implied_predicates_of.set(def_id.index, lazy);
}
};record_defaulted_array!(self.tables.explicit_implied_predicates_of[def_id] <-
1550 self.tcx.explicit_implied_predicates_of(def_id).skip_binder());
1551 }
1552 if let DefKind::Trait | DefKind::Impl { .. } = def_kind {
1553 let associated_item_def_ids = self.tcx.associated_item_def_ids(def_id);
1554 {
{
let value =
associated_item_def_ids.iter().map(|&def_id|
{
if !def_id.is_local() {
::core::panicking::panic("assertion failed: def_id.is_local()")
};
def_id.index
});
let lazy = self.lazy_array(value);
self.tables.associated_item_or_field_def_ids.set_some(def_id.index,
lazy);
}
};record_array!(self.tables.associated_item_or_field_def_ids[def_id] <-
1555 associated_item_def_ids.iter().map(|&def_id| {
1556 assert!(def_id.is_local());
1557 def_id.index
1558 })
1559 );
1560 for &def_id in associated_item_def_ids {
1561 self.encode_info_for_assoc_item(def_id);
1562 }
1563 }
1564 if let DefKind::Closure | DefKind::SyntheticCoroutineBody = def_kind
1565 && let Some(coroutine_kind) = self.tcx.coroutine_kind(def_id)
1566 {
1567 self.tables.coroutine_kind.set(def_id.index, Some(coroutine_kind))
1568 }
1569 if def_kind == DefKind::Closure
1570 && tcx.type_of(def_id).skip_binder().is_coroutine_closure()
1571 {
1572 let coroutine_for_closure = self.tcx.coroutine_for_closure(def_id);
1573 self.tables
1574 .coroutine_for_closure
1575 .set_some(def_id.index, coroutine_for_closure.into());
1576
1577 if tcx.needs_coroutine_by_move_body_def_id(coroutine_for_closure) {
1579 self.tables.coroutine_by_move_body_def_id.set_some(
1580 coroutine_for_closure.index,
1581 self.tcx.coroutine_by_move_body_def_id(coroutine_for_closure).into(),
1582 );
1583 }
1584 }
1585 if let DefKind::Static { .. } = def_kind {
1586 if !self.tcx.is_foreign_item(def_id) {
1587 let data = self.tcx.eval_static_initializer(def_id).unwrap();
1588 {
{
let value = data;
let lazy = self.lazy(value);
self.tables.eval_static_initializer.set_some(def_id.index, lazy);
}
};record!(self.tables.eval_static_initializer[def_id] <- data);
1589 }
1590 }
1591 if let DefKind::Enum | DefKind::Struct | DefKind::Union = def_kind {
1592 self.encode_info_for_adt(local_id);
1593 }
1594 if let DefKind::Mod = def_kind {
1595 self.encode_info_for_mod(local_id);
1596 }
1597 if let DefKind::Macro(_) = def_kind {
1598 self.encode_info_for_macro(local_id);
1599 }
1600 if let DefKind::TyAlias = def_kind {
1601 self.tables
1602 .type_alias_is_lazy
1603 .set(def_id.index, self.tcx.type_alias_is_lazy(def_id));
1604 }
1605 if let DefKind::OpaqueTy = def_kind {
1606 self.encode_explicit_item_bounds(def_id);
1607 self.encode_explicit_item_self_bounds(def_id);
1608 {
{
let value = self.tcx.opaque_ty_origin(def_id);
let lazy = self.lazy(value);
self.tables.opaque_ty_origin.set_some(def_id.index, lazy);
}
};record!(self.tables.opaque_ty_origin[def_id] <- self.tcx.opaque_ty_origin(def_id));
1609 self.encode_precise_capturing_args(def_id);
1610 if tcx.is_conditionally_const(def_id) {
1611 {
{
let value = tcx.explicit_implied_const_bounds(def_id).skip_binder();
let lazy = self.lazy_array(value);
self.tables.explicit_implied_const_bounds.set(def_id.index, lazy);
}
};record_defaulted_array!(self.tables.explicit_implied_const_bounds[def_id]
1612 <- tcx.explicit_implied_const_bounds(def_id).skip_binder());
1613 }
1614 }
1615 if let DefKind::AnonConst = def_kind {
1616 {
{
let value = self.tcx.anon_const_kind(def_id);
let lazy = self.lazy(value);
self.tables.anon_const_kind.set_some(def_id.index, lazy);
}
};record!(self.tables.anon_const_kind[def_id] <- self.tcx.anon_const_kind(def_id));
1617 }
1618 if should_encode_const_of_item(self.tcx, def_id, def_kind) {
1619 {
{
let value = self.tcx.const_of_item(def_id);
let lazy = self.lazy(value);
self.tables.const_of_item.set_some(def_id.index, lazy);
}
};record!(self.tables.const_of_item[def_id] <- self.tcx.const_of_item(def_id));
1620 }
1621 if tcx.impl_method_has_trait_impl_trait_tys(def_id)
1622 && let Ok(table) = self.tcx.collect_return_position_impl_trait_in_trait_tys(def_id)
1623 {
1624 {
{
let value = table;
let lazy = self.lazy(value);
self.tables.trait_impl_trait_tys.set_some(def_id.index, lazy);
}
};record!(self.tables.trait_impl_trait_tys[def_id] <- table);
1625 }
1626 if let DefKind::Impl { .. } | DefKind::Trait = def_kind {
1627 let table = tcx.associated_types_for_impl_traits_in_trait_or_impl(def_id);
1628 {
{
let value = table;
let lazy = self.lazy(value);
self.tables.associated_types_for_impl_traits_in_trait_or_impl.set_some(def_id.index,
lazy);
}
};record!(self.tables.associated_types_for_impl_traits_in_trait_or_impl[def_id] <- table);
1629 }
1630 }
1631
1632 for (def_id, impls) in &tcx.crate_inherent_impls(()).0.inherent_impls {
1633 {
{
let value =
impls.iter().map(|def_id|
{
if !def_id.is_local() {
::core::panicking::panic("assertion failed: def_id.is_local()")
};
def_id.index
});
let lazy = self.lazy_array(value);
self.tables.inherent_impls.set(def_id.to_def_id().index, lazy);
}
};record_defaulted_array!(self.tables.inherent_impls[def_id.to_def_id()] <- impls.iter().map(|def_id| {
1634 assert!(def_id.is_local());
1635 def_id.index
1636 }));
1637 }
1638
1639 for (def_id, res_map) in &tcx.resolutions(()).doc_link_resolutions {
1640 {
{
let value = res_map;
let lazy = self.lazy(value);
self.tables.doc_link_resolutions.set_some(def_id.to_def_id().index,
lazy);
}
};record!(self.tables.doc_link_resolutions[def_id.to_def_id()] <- res_map);
1641 }
1642
1643 for (def_id, traits) in &tcx.resolutions(()).doc_link_traits_in_scope {
1644 {
{
let value = traits;
let lazy = self.lazy_array(value);
self.tables.doc_link_traits_in_scope.set_some(def_id.to_def_id().index,
lazy);
}
};record_array!(self.tables.doc_link_traits_in_scope[def_id.to_def_id()] <- traits);
1645 }
1646 }
1647
1648 fn encode_externally_implementable_items(&mut self) -> LazyArray<EiiMapEncodedKeyValue> {
1649 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
1650 let externally_implementable_items = self.tcx.externally_implementable_items(LOCAL_CRATE);
1651
1652 self.lazy_array(externally_implementable_items.iter().map(
1653 |(foreign_item, (decl, impls))| {
1654 (
1655 *foreign_item,
1656 (decl.clone(), impls.iter().map(|(impl_did, i)| (*impl_did, *i)).collect()),
1657 )
1658 },
1659 ))
1660 }
1661
1662 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::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("encode_info_for_adt",
"rustc_metadata::rmeta::encoder", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(1662u32),
::tracing_core::__macro_support::Option::Some("rustc_metadata::rmeta::encoder"),
::tracing_core::field::FieldSet::new(&["local_def_id"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::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(&local_def_id)
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: () = loop {};
return __tracing_attr_fake_return;
}
{
let def_id = local_def_id.to_def_id();
let tcx = self.tcx;
let adt_def = tcx.adt_def(def_id);
{
{
let value = adt_def.repr();
let lazy = self.lazy(value);
self.tables.repr_options.set_some(def_id.index, lazy);
}
};
let params_in_repr = self.tcx.params_in_repr(def_id);
{
{
let value = params_in_repr;
let lazy = self.lazy(value);
self.tables.params_in_repr.set_some(def_id.index, lazy);
}
};
if adt_def.is_enum() {
let module_children = tcx.module_children_local(local_def_id);
{
{
let value =
module_children.iter().map(|child|
child.res.def_id().index);
let lazy = self.lazy_array(value);
self.tables.module_children_non_reexports.set_some(def_id.index,
lazy);
}
};
} else {
if true {
match (&adt_def.variants().len(), &1) {
(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);
}
}
};
};
if true {
match (&adt_def.non_enum_variant().def_id, &def_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);
}
}
};
};
}
for (idx, variant) in adt_def.variants().iter_enumerated() {
let data =
VariantData {
discr: variant.discr,
idx,
ctor: variant.ctor.map(|(kind, def_id)|
(kind, def_id.index)),
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
};
{
{
let value = data;
let lazy = self.lazy(value);
self.tables.variant_data.set_some(variant.def_id.index,
lazy);
}
};
{
{
let value =
variant.fields.iter().map(|f|
{
if !f.did.is_local() {
::core::panicking::panic("assertion failed: f.did.is_local()")
};
f.did.index
});
let lazy = self.lazy_array(value);
self.tables.associated_item_or_field_def_ids.set_some(variant.def_id.index,
lazy);
}
};
for field in &variant.fields {
self.tables.safety.set(field.did.index, field.safety);
}
if let Some((CtorKind::Fn, ctor_def_id)) = variant.ctor {
let fn_sig = tcx.fn_sig(ctor_def_id);
{
{
let value = fn_sig;
let lazy = self.lazy(value);
self.tables.fn_sig.set_some(variant.def_id.index, lazy);
}
};
}
}
if let Some(destructor) = tcx.adt_destructor(local_def_id) {
{
{
let value = destructor;
let lazy = self.lazy(value);
self.tables.adt_destructor.set_some(def_id.index, lazy);
}
};
}
if let Some(destructor) = tcx.adt_async_destructor(local_def_id) {
{
{
let value = destructor;
let lazy = self.lazy(value);
self.tables.adt_async_destructor.set_some(def_id.index,
lazy);
}
};
}
}
}
}#[instrument(level = "trace", skip(self))]
1663 fn encode_info_for_adt(&mut self, local_def_id: LocalDefId) {
1664 let def_id = local_def_id.to_def_id();
1665 let tcx = self.tcx;
1666 let adt_def = tcx.adt_def(def_id);
1667 record!(self.tables.repr_options[def_id] <- adt_def.repr());
1668
1669 let params_in_repr = self.tcx.params_in_repr(def_id);
1670 record!(self.tables.params_in_repr[def_id] <- params_in_repr);
1671
1672 if adt_def.is_enum() {
1673 let module_children = tcx.module_children_local(local_def_id);
1674 record_array!(self.tables.module_children_non_reexports[def_id] <-
1675 module_children.iter().map(|child| child.res.def_id().index));
1676 } else {
1677 debug_assert_eq!(adt_def.variants().len(), 1);
1679 debug_assert_eq!(adt_def.non_enum_variant().def_id, def_id);
1680 }
1682
1683 for (idx, variant) in adt_def.variants().iter_enumerated() {
1684 let data = VariantData {
1685 discr: variant.discr,
1686 idx,
1687 ctor: variant.ctor.map(|(kind, def_id)| (kind, def_id.index)),
1688 is_non_exhaustive: variant.is_field_list_non_exhaustive(),
1689 };
1690 record!(self.tables.variant_data[variant.def_id] <- data);
1691
1692 record_array!(self.tables.associated_item_or_field_def_ids[variant.def_id] <- variant.fields.iter().map(|f| {
1693 assert!(f.did.is_local());
1694 f.did.index
1695 }));
1696
1697 for field in &variant.fields {
1698 self.tables.safety.set(field.did.index, field.safety);
1699 }
1700
1701 if let Some((CtorKind::Fn, ctor_def_id)) = variant.ctor {
1702 let fn_sig = tcx.fn_sig(ctor_def_id);
1703 record!(self.tables.fn_sig[variant.def_id] <- fn_sig);
1705 }
1706 }
1707
1708 if let Some(destructor) = tcx.adt_destructor(local_def_id) {
1709 record!(self.tables.adt_destructor[def_id] <- destructor);
1710 }
1711
1712 if let Some(destructor) = tcx.adt_async_destructor(local_def_id) {
1713 record!(self.tables.adt_async_destructor[def_id] <- destructor);
1714 }
1715 }
1716
1717 #[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("encode_info_for_mod",
"rustc_metadata::rmeta::encoder", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(1717u32),
::tracing_core::__macro_support::Option::Some("rustc_metadata::rmeta::encoder"),
::tracing_core::field::FieldSet::new(&["local_def_id"],
::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(&local_def_id)
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: () = loop {};
return __tracing_attr_fake_return;
}
{
let tcx = self.tcx;
let def_id = local_def_id.to_def_id();
if self.is_proc_macro {
{
{
let value = tcx.expn_that_defined(local_def_id);
let lazy = self.lazy(value);
self.tables.expn_that_defined.set_some(def_id.index, lazy);
}
};
} else {
let module_children = tcx.module_children_local(local_def_id);
{
{
let value =
module_children.iter().filter(|child|
child.reexport_chain.is_empty()).map(|child|
child.res.def_id().index);
let lazy = self.lazy_array(value);
self.tables.module_children_non_reexports.set_some(def_id.index,
lazy);
}
};
{
{
let value =
module_children.iter().filter(|child|
!child.reexport_chain.is_empty());
let lazy = self.lazy_array(value);
self.tables.module_children_reexports.set(def_id.index,
lazy);
}
};
let ambig_module_children =
tcx.resolutions(()).ambig_module_children.get(&local_def_id).map_or_default(|v|
&v[..]);
{
{
let value = ambig_module_children;
let lazy = self.lazy_array(value);
self.tables.ambig_module_children.set(def_id.index, lazy);
}
};
}
}
}
}#[instrument(level = "debug", skip(self))]
1718 fn encode_info_for_mod(&mut self, local_def_id: LocalDefId) {
1719 let tcx = self.tcx;
1720 let def_id = local_def_id.to_def_id();
1721
1722 if self.is_proc_macro {
1728 record!(self.tables.expn_that_defined[def_id] <- tcx.expn_that_defined(local_def_id));
1730 } else {
1731 let module_children = tcx.module_children_local(local_def_id);
1732
1733 record_array!(self.tables.module_children_non_reexports[def_id] <-
1734 module_children.iter().filter(|child| child.reexport_chain.is_empty())
1735 .map(|child| child.res.def_id().index));
1736
1737 record_defaulted_array!(self.tables.module_children_reexports[def_id] <-
1738 module_children.iter().filter(|child| !child.reexport_chain.is_empty()));
1739
1740 let ambig_module_children = tcx
1741 .resolutions(())
1742 .ambig_module_children
1743 .get(&local_def_id)
1744 .map_or_default(|v| &v[..]);
1745 record_defaulted_array!(self.tables.ambig_module_children[def_id] <-
1746 ambig_module_children);
1747 }
1748 }
1749
1750 fn encode_explicit_item_bounds(&mut self, def_id: DefId) {
1751 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_metadata/src/rmeta/encoder.rs:1751",
"rustc_metadata::rmeta::encoder", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(1751u32),
::tracing_core::__macro_support::Option::Some("rustc_metadata::rmeta::encoder"),
::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!("EncodeContext::encode_explicit_item_bounds({0:?})",
def_id) as &dyn Value))])
});
} else { ; }
};debug!("EncodeContext::encode_explicit_item_bounds({:?})", def_id);
1752 let bounds = self.tcx.explicit_item_bounds(def_id).skip_binder();
1753 {
{
let value = bounds;
let lazy = self.lazy_array(value);
self.tables.explicit_item_bounds.set(def_id.index, lazy);
}
};record_defaulted_array!(self.tables.explicit_item_bounds[def_id] <- bounds);
1754 }
1755
1756 fn encode_explicit_item_self_bounds(&mut self, def_id: DefId) {
1757 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_metadata/src/rmeta/encoder.rs:1757",
"rustc_metadata::rmeta::encoder", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(1757u32),
::tracing_core::__macro_support::Option::Some("rustc_metadata::rmeta::encoder"),
::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!("EncodeContext::encode_explicit_item_self_bounds({0:?})",
def_id) as &dyn Value))])
});
} else { ; }
};debug!("EncodeContext::encode_explicit_item_self_bounds({:?})", def_id);
1758 let bounds = self.tcx.explicit_item_self_bounds(def_id).skip_binder();
1759 {
{
let value = bounds;
let lazy = self.lazy_array(value);
self.tables.explicit_item_self_bounds.set(def_id.index, lazy);
}
};record_defaulted_array!(self.tables.explicit_item_self_bounds[def_id] <- bounds);
1760 }
1761
1762 #[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("encode_info_for_assoc_item",
"rustc_metadata::rmeta::encoder", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(1762u32),
::tracing_core::__macro_support::Option::Some("rustc_metadata::rmeta::encoder"),
::tracing_core::field::FieldSet::new(&["def_id"],
::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(&def_id)
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: () = loop {};
return __tracing_attr_fake_return;
}
{
let tcx = self.tcx;
let item = tcx.associated_item(def_id);
if #[allow(non_exhaustive_omitted_patterns)] match item.container
{
AssocContainer::Trait | AssocContainer::TraitImpl(_) =>
true,
_ => false,
} {
self.tables.defaultness.set(def_id.index,
item.defaultness(tcx));
}
{
{
let value = item.container;
let lazy = self.lazy(value);
self.tables.assoc_container.set_some(def_id.index, lazy);
}
};
if let AssocContainer::Trait = item.container && item.is_type() {
self.encode_explicit_item_bounds(def_id);
self.encode_explicit_item_self_bounds(def_id);
if tcx.is_conditionally_const(def_id) {
{
{
let value =
self.tcx.explicit_implied_const_bounds(def_id).skip_binder();
let lazy = self.lazy_array(value);
self.tables.explicit_implied_const_bounds.set(def_id.index,
lazy);
}
};
}
}
if let ty::AssocKind::Type {
data: ty::AssocTypeData::Rpitit(rpitit_info) } = item.kind {
{
{
let value = rpitit_info;
let lazy = self.lazy(value);
self.tables.opt_rpitit_info.set_some(def_id.index, lazy);
}
};
if #[allow(non_exhaustive_omitted_patterns)] match rpitit_info
{
ty::ImplTraitInTraitData::Trait { .. } => true,
_ => false,
} {
{
{
let value = self.tcx.assumed_wf_types_for_rpitit(def_id);
let lazy = self.lazy_array(value);
self.tables.assumed_wf_types_for_rpitit.set_some(def_id.index,
lazy);
}
};
self.encode_precise_capturing_args(def_id);
}
}
}
}
}#[instrument(level = "debug", skip(self))]
1763 fn encode_info_for_assoc_item(&mut self, def_id: DefId) {
1764 let tcx = self.tcx;
1765 let item = tcx.associated_item(def_id);
1766
1767 if matches!(item.container, AssocContainer::Trait | AssocContainer::TraitImpl(_)) {
1768 self.tables.defaultness.set(def_id.index, item.defaultness(tcx));
1769 }
1770
1771 record!(self.tables.assoc_container[def_id] <- item.container);
1772
1773 if let AssocContainer::Trait = item.container
1774 && item.is_type()
1775 {
1776 self.encode_explicit_item_bounds(def_id);
1777 self.encode_explicit_item_self_bounds(def_id);
1778 if tcx.is_conditionally_const(def_id) {
1779 record_defaulted_array!(self.tables.explicit_implied_const_bounds[def_id]
1780 <- self.tcx.explicit_implied_const_bounds(def_id).skip_binder());
1781 }
1782 }
1783 if let ty::AssocKind::Type { data: ty::AssocTypeData::Rpitit(rpitit_info) } = item.kind {
1784 record!(self.tables.opt_rpitit_info[def_id] <- rpitit_info);
1785 if matches!(rpitit_info, ty::ImplTraitInTraitData::Trait { .. }) {
1786 record_array!(
1787 self.tables.assumed_wf_types_for_rpitit[def_id]
1788 <- self.tcx.assumed_wf_types_for_rpitit(def_id)
1789 );
1790 self.encode_precise_capturing_args(def_id);
1791 }
1792 }
1793 }
1794
1795 fn encode_precise_capturing_args(&mut self, def_id: DefId) {
1796 let Some(precise_capturing_args) = self.tcx.rendered_precise_capturing_args(def_id) else {
1797 return;
1798 };
1799
1800 {
{
let value = precise_capturing_args;
let lazy = self.lazy_array(value);
self.tables.rendered_precise_capturing_args.set_some(def_id.index,
lazy);
}
};record_array!(self.tables.rendered_precise_capturing_args[def_id] <- precise_capturing_args);
1801 }
1802
1803 fn encode_mir(&mut self) {
1804 if self.is_proc_macro {
1805 return;
1806 }
1807
1808 let tcx = self.tcx;
1809 let reachable_set = tcx.reachable_set(());
1810
1811 let keys_and_jobs = tcx.mir_keys(()).iter().filter_map(|&def_id| {
1812 let (encode_const, encode_opt) = should_encode_mir(tcx, reachable_set, def_id);
1813 if encode_const || encode_opt { Some((def_id, encode_const, encode_opt)) } else { None }
1814 });
1815 for (def_id, encode_const, encode_opt) in keys_and_jobs {
1816 if true {
if !(encode_const || encode_opt) {
::core::panicking::panic("assertion failed: encode_const || encode_opt")
};
};debug_assert!(encode_const || encode_opt);
1817
1818 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_metadata/src/rmeta/encoder.rs:1818",
"rustc_metadata::rmeta::encoder", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(1818u32),
::tracing_core::__macro_support::Option::Some("rustc_metadata::rmeta::encoder"),
::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!("EntryBuilder::encode_mir({0:?})",
def_id) as &dyn Value))])
});
} else { ; }
};debug!("EntryBuilder::encode_mir({:?})", def_id);
1819 if encode_opt {
1820 {
{
let value = tcx.optimized_mir(def_id);
let lazy = self.lazy(value);
self.tables.optimized_mir.set_some(def_id.to_def_id().index, lazy);
}
};record!(self.tables.optimized_mir[def_id.to_def_id()] <- tcx.optimized_mir(def_id));
1821 self.tables
1822 .cross_crate_inlinable
1823 .set(def_id.to_def_id().index, self.tcx.cross_crate_inlinable(def_id));
1824 {
{
let value = tcx.closure_saved_names_of_captured_variables(def_id);
let lazy = self.lazy(value);
self.tables.closure_saved_names_of_captured_variables.set_some(def_id.to_def_id().index,
lazy);
}
};record!(self.tables.closure_saved_names_of_captured_variables[def_id.to_def_id()]
1825 <- tcx.closure_saved_names_of_captured_variables(def_id));
1826
1827 if self.tcx.is_coroutine(def_id.to_def_id())
1828 && let Some(witnesses) = tcx.mir_coroutine_witnesses(def_id)
1829 {
1830 {
{
let value = witnesses;
let lazy = self.lazy(value);
self.tables.mir_coroutine_witnesses.set_some(def_id.to_def_id().index,
lazy);
}
};record!(self.tables.mir_coroutine_witnesses[def_id.to_def_id()] <- witnesses);
1831 }
1832 }
1833 let mut is_trivial = false;
1834 if encode_const {
1835 if let Some((val, ty)) = tcx.trivial_const(def_id) {
1836 is_trivial = true;
1837 {
{
let value = (val, ty);
let lazy = self.lazy(value);
self.tables.trivial_const.set_some(def_id.to_def_id().index, lazy);
}
};record!(self.tables.trivial_const[def_id.to_def_id()] <- (val, ty));
1838 } else {
1839 is_trivial = false;
1840 {
{
let value = tcx.mir_for_ctfe(def_id);
let lazy = self.lazy(value);
self.tables.mir_for_ctfe.set_some(def_id.to_def_id().index, lazy);
}
};record!(self.tables.mir_for_ctfe[def_id.to_def_id()] <- tcx.mir_for_ctfe(def_id));
1841 }
1842
1843 let abstract_const = tcx.thir_abstract_const(def_id);
1845 if let Ok(Some(abstract_const)) = abstract_const {
1846 {
{
let value = abstract_const;
let lazy = self.lazy(value);
self.tables.thir_abstract_const.set_some(def_id.to_def_id().index,
lazy);
}
};record!(self.tables.thir_abstract_const[def_id.to_def_id()] <- abstract_const);
1847 }
1848
1849 if should_encode_const(tcx.def_kind(def_id)) {
1850 let qualifs = tcx.mir_const_qualif(def_id);
1851 {
{
let value = qualifs;
let lazy = self.lazy(value);
self.tables.mir_const_qualif.set_some(def_id.to_def_id().index, lazy);
}
};record!(self.tables.mir_const_qualif[def_id.to_def_id()] <- qualifs);
1852 let body = tcx.hir_maybe_body_owned_by(def_id);
1853 if let Some(body) = body {
1854 let const_data = rendered_const(self.tcx, &body, def_id);
1855 {
{
let value = const_data;
let lazy = self.lazy(value);
self.tables.rendered_const.set_some(def_id.to_def_id().index, lazy);
}
};record!(self.tables.rendered_const[def_id.to_def_id()] <- const_data);
1856 }
1857 }
1858 }
1859 if !is_trivial {
1860 {
{
let value = tcx.promoted_mir(def_id);
let lazy = self.lazy(value);
self.tables.promoted_mir.set_some(def_id.to_def_id().index, lazy);
}
};record!(self.tables.promoted_mir[def_id.to_def_id()] <- tcx.promoted_mir(def_id));
1861 }
1862
1863 if self.tcx.is_coroutine(def_id.to_def_id())
1864 && let Some(witnesses) = tcx.mir_coroutine_witnesses(def_id)
1865 {
1866 {
{
let value = witnesses;
let lazy = self.lazy(value);
self.tables.mir_coroutine_witnesses.set_some(def_id.to_def_id().index,
lazy);
}
};record!(self.tables.mir_coroutine_witnesses[def_id.to_def_id()] <- witnesses);
1867 }
1868 }
1869
1870 if tcx.sess.opts.output_types.should_codegen()
1874 && tcx.sess.opts.optimize != OptLevel::No
1875 && tcx.sess.opts.incremental.is_none()
1876 {
1877 for &local_def_id in tcx.mir_keys(()) {
1878 if let DefKind::AssocFn | DefKind::Fn = tcx.def_kind(local_def_id) {
1879 {
{
let value = self.tcx.deduced_param_attrs(local_def_id.to_def_id());
let lazy = self.lazy_array(value);
self.tables.deduced_param_attrs.set_some(local_def_id.to_def_id().index,
lazy);
}
};record_array!(self.tables.deduced_param_attrs[local_def_id.to_def_id()] <-
1880 self.tcx.deduced_param_attrs(local_def_id.to_def_id()));
1881 }
1882 }
1883 }
1884 }
1885
1886 #[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("encode_stability",
"rustc_metadata::rmeta::encoder", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(1886u32),
::tracing_core::__macro_support::Option::Some("rustc_metadata::rmeta::encoder"),
::tracing_core::field::FieldSet::new(&["def_id"],
::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(&def_id)
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: () = loop {};
return __tracing_attr_fake_return;
}
{
if self.feat.staged_api() ||
self.tcx.sess.opts.unstable_opts.force_unstable_if_unmarked
{
if let Some(stab) = self.tcx.lookup_stability(def_id) {
{
{
let value = stab;
let lazy = self.lazy(value);
self.tables.lookup_stability.set_some(def_id.index, lazy);
}
}
}
}
}
}
}#[instrument(level = "debug", skip(self))]
1887 fn encode_stability(&mut self, def_id: DefId) {
1888 if self.feat.staged_api() || self.tcx.sess.opts.unstable_opts.force_unstable_if_unmarked {
1891 if let Some(stab) = self.tcx.lookup_stability(def_id) {
1892 record!(self.tables.lookup_stability[def_id] <- stab)
1893 }
1894 }
1895 }
1896
1897 #[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("encode_const_stability",
"rustc_metadata::rmeta::encoder", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(1897u32),
::tracing_core::__macro_support::Option::Some("rustc_metadata::rmeta::encoder"),
::tracing_core::field::FieldSet::new(&["def_id"],
::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(&def_id)
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: () = loop {};
return __tracing_attr_fake_return;
}
{
if self.feat.staged_api() ||
self.tcx.sess.opts.unstable_opts.force_unstable_if_unmarked
{
if let Some(stab) = self.tcx.lookup_const_stability(def_id) {
{
{
let value = stab;
let lazy = self.lazy(value);
self.tables.lookup_const_stability.set_some(def_id.index,
lazy);
}
}
}
}
}
}
}#[instrument(level = "debug", skip(self))]
1898 fn encode_const_stability(&mut self, def_id: DefId) {
1899 if self.feat.staged_api() || self.tcx.sess.opts.unstable_opts.force_unstable_if_unmarked {
1902 if let Some(stab) = self.tcx.lookup_const_stability(def_id) {
1903 record!(self.tables.lookup_const_stability[def_id] <- stab)
1904 }
1905 }
1906 }
1907
1908 #[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("encode_default_body_stability",
"rustc_metadata::rmeta::encoder", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(1908u32),
::tracing_core::__macro_support::Option::Some("rustc_metadata::rmeta::encoder"),
::tracing_core::field::FieldSet::new(&["def_id"],
::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(&def_id)
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: () = loop {};
return __tracing_attr_fake_return;
}
{
if self.feat.staged_api() ||
self.tcx.sess.opts.unstable_opts.force_unstable_if_unmarked
{
if let Some(stab) =
self.tcx.lookup_default_body_stability(def_id) {
{
{
let value = stab;
let lazy = self.lazy(value);
self.tables.lookup_default_body_stability.set_some(def_id.index,
lazy);
}
}
}
}
}
}
}#[instrument(level = "debug", skip(self))]
1909 fn encode_default_body_stability(&mut self, def_id: DefId) {
1910 if self.feat.staged_api() || self.tcx.sess.opts.unstable_opts.force_unstable_if_unmarked {
1913 if let Some(stab) = self.tcx.lookup_default_body_stability(def_id) {
1914 record!(self.tables.lookup_default_body_stability[def_id] <- stab)
1915 }
1916 }
1917 }
1918
1919 #[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("encode_deprecation",
"rustc_metadata::rmeta::encoder", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(1919u32),
::tracing_core::__macro_support::Option::Some("rustc_metadata::rmeta::encoder"),
::tracing_core::field::FieldSet::new(&["def_id"],
::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(&def_id)
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: () = loop {};
return __tracing_attr_fake_return;
}
{
if let Some(depr) = self.tcx.lookup_deprecation(def_id) {
{
{
let value = depr;
let lazy = self.lazy(value);
self.tables.lookup_deprecation_entry.set_some(def_id.index,
lazy);
}
};
}
}
}
}#[instrument(level = "debug", skip(self))]
1920 fn encode_deprecation(&mut self, def_id: DefId) {
1921 if let Some(depr) = self.tcx.lookup_deprecation(def_id) {
1922 record!(self.tables.lookup_deprecation_entry[def_id] <- depr);
1923 }
1924 }
1925
1926 #[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("encode_info_for_macro",
"rustc_metadata::rmeta::encoder", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(1926u32),
::tracing_core::__macro_support::Option::Some("rustc_metadata::rmeta::encoder"),
::tracing_core::field::FieldSet::new(&["def_id"],
::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(&def_id)
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: () = loop {};
return __tracing_attr_fake_return;
}
{
let tcx = self.tcx;
let (_, macro_def, _) =
tcx.hir_expect_item(def_id).expect_macro();
self.tables.is_macro_rules.set(def_id.local_def_index,
macro_def.macro_rules);
{
{
let value = &*macro_def.body;
let lazy = self.lazy(value);
self.tables.macro_definition.set_some(def_id.to_def_id().index,
lazy);
}
};
}
}
}#[instrument(level = "debug", skip(self))]
1927 fn encode_info_for_macro(&mut self, def_id: LocalDefId) {
1928 let tcx = self.tcx;
1929
1930 let (_, macro_def, _) = tcx.hir_expect_item(def_id).expect_macro();
1931 self.tables.is_macro_rules.set(def_id.local_def_index, macro_def.macro_rules);
1932 record!(self.tables.macro_definition[def_id.to_def_id()] <- &*macro_def.body);
1933 }
1934
1935 fn encode_native_libraries(&mut self) -> LazyArray<NativeLib> {
1936 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
1937 let used_libraries = self.tcx.native_libraries(LOCAL_CRATE);
1938 self.lazy_array(used_libraries.iter())
1939 }
1940
1941 fn encode_foreign_modules(&mut self) -> LazyArray<ForeignModule> {
1942 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
1943 let foreign_modules = self.tcx.foreign_modules(LOCAL_CRATE);
1944 self.lazy_array(foreign_modules.iter().map(|(_, m)| m).cloned())
1945 }
1946
1947 fn encode_hygiene(&mut self) -> (SyntaxContextTable, ExpnDataTable, ExpnHashTable) {
1948 let mut syntax_contexts: TableBuilder<_, _> = Default::default();
1949 let mut expn_data_table: TableBuilder<_, _> = Default::default();
1950 let mut expn_hash_table: TableBuilder<_, _> = Default::default();
1951
1952 self.hygiene_ctxt.encode(
1953 &mut (&mut *self, &mut syntax_contexts, &mut expn_data_table, &mut expn_hash_table),
1954 |(this, syntax_contexts, _, _), index, ctxt_data| {
1955 syntax_contexts.set_some(index, this.lazy(ctxt_data));
1956 },
1957 |(this, _, expn_data_table, expn_hash_table), index, expn_data, hash| {
1958 if let Some(index) = index.as_local() {
1959 expn_data_table.set_some(index.as_raw(), this.lazy(expn_data));
1960 expn_hash_table.set_some(index.as_raw(), this.lazy(hash));
1961 }
1962 },
1963 );
1964
1965 (
1966 syntax_contexts.encode(&mut self.opaque),
1967 expn_data_table.encode(&mut self.opaque),
1968 expn_hash_table.encode(&mut self.opaque),
1969 )
1970 }
1971
1972 fn encode_proc_macros(&mut self) -> Option<ProcMacroData> {
1973 let is_proc_macro = self.tcx.crate_types().contains(&CrateType::ProcMacro);
1974 if is_proc_macro {
1975 let tcx = self.tcx;
1976 let proc_macro_decls_static = tcx.proc_macro_decls_static(()).unwrap().local_def_index;
1977 let stability = tcx.lookup_stability(CRATE_DEF_ID);
1978 let macros =
1979 self.lazy_array(tcx.resolutions(()).proc_macros.iter().map(|p| p.local_def_index));
1980 for (i, span) in self.tcx.sess.psess.proc_macro_quoted_spans() {
1981 let span = self.lazy(span);
1982 self.tables.proc_macro_quoted_spans.set_some(i, span);
1983 }
1984
1985 self.tables.def_kind.set_some(LOCAL_CRATE.as_def_id().index, DefKind::Mod);
1986 {
{
let value = tcx.def_span(LOCAL_CRATE.as_def_id());
let lazy = self.lazy(value);
self.tables.def_span.set_some(LOCAL_CRATE.as_def_id().index, lazy);
}
};record!(self.tables.def_span[LOCAL_CRATE.as_def_id()] <- tcx.def_span(LOCAL_CRATE.as_def_id()));
1987 self.encode_attrs(LOCAL_CRATE.as_def_id().expect_local());
1988 let vis = tcx.local_visibility(CRATE_DEF_ID).map_id(|def_id| def_id.local_def_index);
1989 {
{
let value = vis;
let lazy = self.lazy(value);
self.tables.visibility.set_some(LOCAL_CRATE.as_def_id().index, lazy);
}
};record!(self.tables.visibility[LOCAL_CRATE.as_def_id()] <- vis);
1990 if let Some(stability) = stability {
1991 {
{
let value = stability;
let lazy = self.lazy(value);
self.tables.lookup_stability.set_some(LOCAL_CRATE.as_def_id().index,
lazy);
}
};record!(self.tables.lookup_stability[LOCAL_CRATE.as_def_id()] <- stability);
1992 }
1993 self.encode_deprecation(LOCAL_CRATE.as_def_id());
1994 if let Some(res_map) = tcx.resolutions(()).doc_link_resolutions.get(&CRATE_DEF_ID) {
1995 {
{
let value = res_map;
let lazy = self.lazy(value);
self.tables.doc_link_resolutions.set_some(LOCAL_CRATE.as_def_id().index,
lazy);
}
};record!(self.tables.doc_link_resolutions[LOCAL_CRATE.as_def_id()] <- res_map);
1996 }
1997 if let Some(traits) = tcx.resolutions(()).doc_link_traits_in_scope.get(&CRATE_DEF_ID) {
1998 {
{
let value = traits;
let lazy = self.lazy_array(value);
self.tables.doc_link_traits_in_scope.set_some(LOCAL_CRATE.as_def_id().index,
lazy);
}
};record_array!(self.tables.doc_link_traits_in_scope[LOCAL_CRATE.as_def_id()] <- traits);
1999 }
2000
2001 for &proc_macro in &tcx.resolutions(()).proc_macros {
2005 let id = proc_macro;
2006 let proc_macro = tcx.local_def_id_to_hir_id(proc_macro);
2007 let mut name = tcx.hir_name(proc_macro);
2008 let span = tcx.hir_span(proc_macro);
2009 let attrs = tcx.hir_attrs(proc_macro);
2012 let macro_kind = if {
{
'done:
{
for i in attrs {
#[allow(unused_imports)]
use rustc_hir::attrs::AttributeKind::*;
let i: &rustc_hir::Attribute = i;
match i {
rustc_hir::Attribute::Parsed(ProcMacro(..)) => {
break 'done Some(());
}
rustc_hir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}.is_some()
}find_attr!(attrs, ProcMacro(..)) {
2013 MacroKind::Bang
2014 } else if {
{
'done:
{
for i in attrs {
#[allow(unused_imports)]
use rustc_hir::attrs::AttributeKind::*;
let i: &rustc_hir::Attribute = i;
match i {
rustc_hir::Attribute::Parsed(ProcMacroAttribute(..)) => {
break 'done Some(());
}
rustc_hir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}.is_some()
}find_attr!(attrs, ProcMacroAttribute(..)) {
2015 MacroKind::Attr
2016 } else if let Some(trait_name) =
2017 {
'done:
{
for i in attrs {
#[allow(unused_imports)]
use rustc_hir::attrs::AttributeKind::*;
let i: &rustc_hir::Attribute = i;
match i {
rustc_hir::Attribute::Parsed(ProcMacroDerive { trait_name, ..
}) => {
break 'done Some(trait_name);
}
rustc_hir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}find_attr!(attrs, ProcMacroDerive { trait_name, ..} => trait_name)
2018 {
2019 name = *trait_name;
2020 MacroKind::Derive
2021 } else {
2022 ::rustc_middle::util::bug::bug_fmt(format_args!("Unknown proc-macro type for item {0:?}",
id));bug!("Unknown proc-macro type for item {:?}", id);
2023 };
2024
2025 let mut def_key = self.tcx.hir_def_key(id);
2026 def_key.disambiguated_data.data = DefPathData::MacroNs(name);
2027
2028 let def_id = id.to_def_id();
2029 self.tables.def_kind.set_some(def_id.index, DefKind::Macro(macro_kind.into()));
2030 self.tables.proc_macro.set_some(def_id.index, macro_kind);
2031 self.encode_attrs(id);
2032 {
{
let value = def_key;
let lazy = self.lazy(value);
self.tables.def_keys.set_some(def_id.index, lazy);
}
};record!(self.tables.def_keys[def_id] <- def_key);
2033 {
{
let value = span;
let lazy = self.lazy(value);
self.tables.def_ident_span.set_some(def_id.index, lazy);
}
};record!(self.tables.def_ident_span[def_id] <- span);
2034 {
{
let value = span;
let lazy = self.lazy(value);
self.tables.def_span.set_some(def_id.index, lazy);
}
};record!(self.tables.def_span[def_id] <- span);
2035 {
{
let value = ty::Visibility::Public;
let lazy = self.lazy(value);
self.tables.visibility.set_some(def_id.index, lazy);
}
};record!(self.tables.visibility[def_id] <- ty::Visibility::Public);
2036 if let Some(stability) = stability {
2037 {
{
let value = stability;
let lazy = self.lazy(value);
self.tables.lookup_stability.set_some(def_id.index, lazy);
}
};record!(self.tables.lookup_stability[def_id] <- stability);
2038 }
2039 }
2040
2041 Some(ProcMacroData { proc_macro_decls_static, stability, macros })
2042 } else {
2043 None
2044 }
2045 }
2046
2047 fn encode_debugger_visualizers(&mut self) -> LazyArray<DebuggerVisualizerFile> {
2048 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2049 self.lazy_array(
2050 self.tcx
2051 .debugger_visualizers(LOCAL_CRATE)
2052 .iter()
2053 .map(DebuggerVisualizerFile::path_erased),
2058 )
2059 }
2060
2061 fn encode_crate_deps(&mut self) -> LazyArray<CrateDep> {
2062 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2063
2064 let deps = self
2065 .tcx
2066 .crates(())
2067 .iter()
2068 .map(|&cnum| {
2069 let dep = CrateDep {
2070 name: self.tcx.crate_name(cnum),
2071 hash: self.tcx.crate_hash(cnum),
2072 host_hash: self.tcx.crate_host_hash(cnum),
2073 kind: self.tcx.crate_dep_kind(cnum),
2074 extra_filename: self.tcx.extra_filename(cnum).clone(),
2075 is_private: self.tcx.is_private_dep(cnum),
2076 };
2077 (cnum, dep)
2078 })
2079 .collect::<Vec<_>>();
2080
2081 {
2082 let mut expected_cnum = 1;
2084 for &(n, _) in &deps {
2085 match (&n, &CrateNum::new(expected_cnum)) {
(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!(n, CrateNum::new(expected_cnum));
2086 expected_cnum += 1;
2087 }
2088 }
2089
2090 self.lazy_array(deps.iter().map(|(_, dep)| dep))
2095 }
2096
2097 fn encode_target_modifiers(&mut self) -> LazyArray<TargetModifier> {
2098 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2099 let tcx = self.tcx;
2100 self.lazy_array(tcx.sess.opts.gather_target_modifiers())
2101 }
2102
2103 fn encode_lib_features(&mut self) -> LazyArray<(Symbol, FeatureStability)> {
2104 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2105 let tcx = self.tcx;
2106 let lib_features = tcx.lib_features(LOCAL_CRATE);
2107 self.lazy_array(lib_features.to_sorted_vec())
2108 }
2109
2110 fn encode_stability_implications(&mut self) -> LazyArray<(Symbol, Symbol)> {
2111 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2112 let tcx = self.tcx;
2113 let implications = tcx.stability_implications(LOCAL_CRATE);
2114 let sorted = implications.to_sorted_stable_ord();
2115 self.lazy_array(sorted.into_iter().map(|(k, v)| (*k, *v)))
2116 }
2117
2118 fn encode_diagnostic_items(&mut self) -> LazyArray<(Symbol, DefIndex)> {
2119 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2120 let tcx = self.tcx;
2121 let diagnostic_items = &tcx.diagnostic_items(LOCAL_CRATE).name_to_id;
2122 self.lazy_array(diagnostic_items.iter().map(|(&name, def_id)| (name, def_id.index)))
2123 }
2124
2125 fn encode_lang_items(&mut self) -> LazyArray<(DefIndex, LangItem)> {
2126 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2127 let lang_items = self.tcx.lang_items().iter();
2128 self.lazy_array(lang_items.filter_map(|(lang_item, def_id)| {
2129 def_id.as_local().map(|id| (id.local_def_index, lang_item))
2130 }))
2131 }
2132
2133 fn encode_lang_items_missing(&mut self) -> LazyArray<LangItem> {
2134 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2135 let tcx = self.tcx;
2136 self.lazy_array(&tcx.lang_items().missing)
2137 }
2138
2139 fn encode_stripped_cfg_items(&mut self) -> LazyArray<StrippedCfgItem<DefIndex>> {
2140 self.lazy_array(
2141 self.tcx
2142 .stripped_cfg_items(LOCAL_CRATE)
2143 .into_iter()
2144 .map(|item| item.clone().map_scope_id(|def_id| def_id.index)),
2145 )
2146 }
2147
2148 fn encode_traits(&mut self) -> LazyArray<DefIndex> {
2149 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2150 self.lazy_array(self.tcx.traits(LOCAL_CRATE).iter().map(|def_id| def_id.index))
2151 }
2152
2153 #[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("encode_impls",
"rustc_metadata::rmeta::encoder", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(2154u32),
::tracing_core::__macro_support::Option::Some("rustc_metadata::rmeta::encoder"),
::tracing_core::field::FieldSet::new(&[],
::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,
&{ meta.fields().value_set(&[]) })
} 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: LazyArray<TraitImpls> = loop {};
return __tracing_attr_fake_return;
}
{
if self.is_proc_macro { return LazyArray::default(); };
let tcx = self.tcx;
let mut trait_impls:
FxIndexMap<DefId, Vec<(DefIndex, Option<SimplifiedType>)>> =
FxIndexMap::default();
for id in tcx.hir_free_items() {
let DefKind::Impl { of_trait } =
tcx.def_kind(id.owner_id) else { continue; };
let def_id = id.owner_id.to_def_id();
if of_trait {
let header = tcx.impl_trait_header(def_id);
{
{
let value = header;
let lazy = self.lazy(value);
self.tables.impl_trait_header.set_some(def_id.index, lazy);
}
};
self.tables.defaultness.set(def_id.index,
tcx.defaultness(def_id));
let trait_ref = header.trait_ref.instantiate_identity();
let simplified_self_ty =
fast_reject::simplify_type(self.tcx, trait_ref.self_ty(),
TreatParams::InstantiateWithInfer);
trait_impls.entry(trait_ref.def_id).or_default().push((id.owner_id.def_id.local_def_index,
simplified_self_ty));
let trait_def = tcx.trait_def(trait_ref.def_id);
if let Ok(mut an) = trait_def.ancestors(tcx, def_id) &&
let Some(specialization_graph::Node::Impl(parent)) =
an.nth(1) {
self.tables.impl_parent.set_some(def_id.index,
parent.into());
}
if tcx.is_lang_item(trait_ref.def_id,
LangItem::CoerceUnsized) {
let coerce_unsized_info =
tcx.coerce_unsized_info(def_id).unwrap();
{
{
let value = coerce_unsized_info;
let lazy = self.lazy(value);
self.tables.coerce_unsized_info.set_some(def_id.index,
lazy);
}
};
}
}
}
let trait_impls: Vec<_> =
trait_impls.into_iter().map(|(trait_def_id, impls)|
TraitImpls {
trait_id: (trait_def_id.krate.as_u32(), trait_def_id.index),
impls: self.lazy_array(&impls),
}).collect();
self.lazy_array(&trait_impls)
}
}
}#[instrument(level = "debug", skip(self))]
2155 fn encode_impls(&mut self) -> LazyArray<TraitImpls> {
2156 empty_proc_macro!(self);
2157 let tcx = self.tcx;
2158 let mut trait_impls: FxIndexMap<DefId, Vec<(DefIndex, Option<SimplifiedType>)>> =
2159 FxIndexMap::default();
2160
2161 for id in tcx.hir_free_items() {
2162 let DefKind::Impl { of_trait } = tcx.def_kind(id.owner_id) else {
2163 continue;
2164 };
2165 let def_id = id.owner_id.to_def_id();
2166
2167 if of_trait {
2168 let header = tcx.impl_trait_header(def_id);
2169 record!(self.tables.impl_trait_header[def_id] <- header);
2170
2171 self.tables.defaultness.set(def_id.index, tcx.defaultness(def_id));
2172
2173 let trait_ref = header.trait_ref.instantiate_identity();
2174 let simplified_self_ty = fast_reject::simplify_type(
2175 self.tcx,
2176 trait_ref.self_ty(),
2177 TreatParams::InstantiateWithInfer,
2178 );
2179 trait_impls
2180 .entry(trait_ref.def_id)
2181 .or_default()
2182 .push((id.owner_id.def_id.local_def_index, simplified_self_ty));
2183
2184 let trait_def = tcx.trait_def(trait_ref.def_id);
2185 if let Ok(mut an) = trait_def.ancestors(tcx, def_id)
2186 && let Some(specialization_graph::Node::Impl(parent)) = an.nth(1)
2187 {
2188 self.tables.impl_parent.set_some(def_id.index, parent.into());
2189 }
2190
2191 if tcx.is_lang_item(trait_ref.def_id, LangItem::CoerceUnsized) {
2194 let coerce_unsized_info = tcx.coerce_unsized_info(def_id).unwrap();
2195 record!(self.tables.coerce_unsized_info[def_id] <- coerce_unsized_info);
2196 }
2197 }
2198 }
2199
2200 let trait_impls: Vec<_> = trait_impls
2201 .into_iter()
2202 .map(|(trait_def_id, impls)| TraitImpls {
2203 trait_id: (trait_def_id.krate.as_u32(), trait_def_id.index),
2204 impls: self.lazy_array(&impls),
2205 })
2206 .collect();
2207
2208 self.lazy_array(&trait_impls)
2209 }
2210
2211 #[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("encode_incoherent_impls",
"rustc_metadata::rmeta::encoder", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(2211u32),
::tracing_core::__macro_support::Option::Some("rustc_metadata::rmeta::encoder"),
::tracing_core::field::FieldSet::new(&[],
::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,
&{ meta.fields().value_set(&[]) })
} 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: LazyArray<IncoherentImpls> =
loop {};
return __tracing_attr_fake_return;
}
{
if self.is_proc_macro { return LazyArray::default(); };
let tcx = self.tcx;
let all_impls: Vec<_> =
tcx.crate_inherent_impls(()).0.incoherent_impls.iter().map(|(&simp,
impls)|
IncoherentImpls {
self_ty: self.lazy(simp),
impls: self.lazy_array(impls.iter().map(|def_id|
def_id.local_def_index)),
}).collect();
self.lazy_array(&all_impls)
}
}
}#[instrument(level = "debug", skip(self))]
2212 fn encode_incoherent_impls(&mut self) -> LazyArray<IncoherentImpls> {
2213 empty_proc_macro!(self);
2214 let tcx = self.tcx;
2215
2216 let all_impls: Vec<_> = tcx
2217 .crate_inherent_impls(())
2218 .0
2219 .incoherent_impls
2220 .iter()
2221 .map(|(&simp, impls)| IncoherentImpls {
2222 self_ty: self.lazy(simp),
2223 impls: self.lazy_array(impls.iter().map(|def_id| def_id.local_def_index)),
2224 })
2225 .collect();
2226
2227 self.lazy_array(&all_impls)
2228 }
2229
2230 fn encode_exportable_items(&mut self) -> LazyArray<DefIndex> {
2231 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2232 self.lazy_array(self.tcx.exportable_items(LOCAL_CRATE).iter().map(|def_id| def_id.index))
2233 }
2234
2235 fn encode_stable_order_of_exportable_impls(&mut self) -> LazyArray<(DefIndex, usize)> {
2236 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2237 let stable_order_of_exportable_impls =
2238 self.tcx.stable_order_of_exportable_impls(LOCAL_CRATE);
2239 self.lazy_array(
2240 stable_order_of_exportable_impls.iter().map(|(def_id, idx)| (def_id.index, *idx)),
2241 )
2242 }
2243
2244 fn encode_exported_symbols(
2251 &mut self,
2252 exported_symbols: &[(ExportedSymbol<'tcx>, SymbolExportInfo)],
2253 ) -> LazyArray<(ExportedSymbol<'static>, SymbolExportInfo)> {
2254 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2255
2256 self.lazy_array(exported_symbols.iter().cloned())
2257 }
2258
2259 fn encode_dylib_dependency_formats(&mut self) -> LazyArray<Option<LinkagePreference>> {
2260 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2261 let formats = self.tcx.dependency_formats(());
2262 if let Some(arr) = formats.get(&CrateType::Dylib) {
2263 return self.lazy_array(arr.iter().skip(1 ).map(
2264 |slot| match *slot {
2265 Linkage::NotLinked | Linkage::IncludedFromDylib => None,
2266
2267 Linkage::Dynamic => Some(LinkagePreference::RequireDynamic),
2268 Linkage::Static => Some(LinkagePreference::RequireStatic),
2269 },
2270 ));
2271 }
2272 LazyArray::default()
2273 }
2274}
2275
2276fn prefetch_mir(tcx: TyCtxt<'_>) {
2279 if !tcx.sess.opts.output_types.should_codegen() {
2280 return;
2282 }
2283
2284 let reachable_set = tcx.reachable_set(());
2285 par_for_each_in(tcx.mir_keys(()), |&&def_id| {
2286 if tcx.is_trivial_const(def_id) {
2287 return;
2288 }
2289 let (encode_const, encode_opt) = should_encode_mir(tcx, reachable_set, def_id);
2290
2291 if encode_const {
2292 tcx.ensure_done().mir_for_ctfe(def_id);
2293 }
2294 if encode_opt {
2295 tcx.ensure_done().optimized_mir(def_id);
2296 }
2297 if encode_opt || encode_const {
2298 tcx.ensure_done().promoted_mir(def_id);
2299 }
2300 })
2301}
2302
2303pub struct EncodedMetadata {
2327 full_metadata: Option<Mmap>,
2330 stub_metadata: Option<Vec<u8>>,
2333 path: Option<Box<Path>>,
2335 _temp_dir: Option<MaybeTempDir>,
2338}
2339
2340impl EncodedMetadata {
2341 #[inline]
2342 pub fn from_path(
2343 path: PathBuf,
2344 stub_path: Option<PathBuf>,
2345 temp_dir: Option<MaybeTempDir>,
2346 ) -> std::io::Result<Self> {
2347 let file = std::fs::File::open(&path)?;
2348 let file_metadata = file.metadata()?;
2349 if file_metadata.len() == 0 {
2350 return Ok(Self {
2351 full_metadata: None,
2352 stub_metadata: None,
2353 path: None,
2354 _temp_dir: None,
2355 });
2356 }
2357 let full_mmap = unsafe { Some(Mmap::map(file)?) };
2358
2359 let stub =
2360 if let Some(stub_path) = stub_path { Some(std::fs::read(stub_path)?) } else { None };
2361
2362 Ok(Self {
2363 full_metadata: full_mmap,
2364 stub_metadata: stub,
2365 path: Some(path.into()),
2366 _temp_dir: temp_dir,
2367 })
2368 }
2369
2370 #[inline]
2371 pub fn full(&self) -> &[u8] {
2372 &self.full_metadata.as_deref().unwrap_or_default()
2373 }
2374
2375 #[inline]
2376 pub fn stub_or_full(&self) -> &[u8] {
2377 self.stub_metadata.as_deref().unwrap_or(self.full())
2378 }
2379
2380 #[inline]
2381 pub fn path(&self) -> Option<&Path> {
2382 self.path.as_deref()
2383 }
2384}
2385
2386impl<S: Encoder> Encodable<S> for EncodedMetadata {
2387 fn encode(&self, s: &mut S) {
2388 self.stub_metadata.encode(s);
2389
2390 let slice = self.full();
2391 slice.encode(s)
2392 }
2393}
2394
2395impl<D: Decoder> Decodable<D> for EncodedMetadata {
2396 fn decode(d: &mut D) -> Self {
2397 let stub = <Option<Vec<u8>>>::decode(d);
2398
2399 let len = d.read_usize();
2400 let full_metadata = if len > 0 {
2401 let mut mmap = MmapMut::map_anon(len).unwrap();
2402 mmap.copy_from_slice(d.read_raw_bytes(len));
2403 Some(mmap.make_read_only().unwrap())
2404 } else {
2405 None
2406 };
2407
2408 Self { full_metadata, stub_metadata: stub, path: None, _temp_dir: None }
2409 }
2410}
2411
2412#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::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("encode_metadata",
"rustc_metadata::rmeta::encoder", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(2412u32),
::tracing_core::__macro_support::Option::Some("rustc_metadata::rmeta::encoder"),
::tracing_core::field::FieldSet::new(&["path", "ref_path"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::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(&path)
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(&ref_path)
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: () = loop {};
return __tracing_attr_fake_return;
}
{
tcx.dep_graph.assert_ignored();
if let Some(ref_path) = ref_path {
let _prof_timer =
tcx.prof.verbose_generic_activity("generate_crate_metadata_stub");
with_encode_metadata_header(tcx, ref_path,
|ecx|
{
let header: LazyValue<CrateHeader> =
ecx.lazy(CrateHeader {
name: tcx.crate_name(LOCAL_CRATE),
triple: tcx.sess.opts.target_triple.clone(),
hash: tcx.crate_hash(LOCAL_CRATE),
is_proc_macro_crate: false,
is_stub: true,
});
header.position.get()
})
}
let _prof_timer =
tcx.prof.verbose_generic_activity("generate_crate_metadata");
let dep_node = tcx.metadata_dep_node();
if tcx.dep_graph.is_fully_enabled() &&
let work_product_id =
WorkProductId::from_cgu_name("metadata") &&
let Some(work_product) =
tcx.dep_graph.previous_work_product(&work_product_id) &&
tcx.dep_graph.try_mark_green(tcx, &dep_node).is_some() {
let saved_path = &work_product.saved_files["rmeta"];
let incr_comp_session_dir =
tcx.sess.incr_comp_session_dir_opt().unwrap();
let source_file =
rustc_incremental::in_incr_comp_dir(&incr_comp_session_dir,
saved_path);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_metadata/src/rmeta/encoder.rs:2447",
"rustc_metadata::rmeta::encoder", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(2447u32),
::tracing_core::__macro_support::Option::Some("rustc_metadata::rmeta::encoder"),
::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!("copying preexisting metadata from {0:?} to {1:?}",
source_file, path) as &dyn Value))])
});
} else { ; }
};
match rustc_fs_util::link_or_copy(&source_file, path) {
Ok(_) => {}
Err(err) =>
tcx.dcx().emit_fatal(FailCreateFileEncoder { err }),
};
return;
};
if tcx.sess.threads() != 1 {
par_join(|| prefetch_mir(tcx),
||
{
let _ = tcx.exported_non_generic_symbols(LOCAL_CRATE);
let _ = tcx.exported_generic_symbols(LOCAL_CRATE);
});
}
tcx.dep_graph.with_task(dep_node, tcx, path,
|tcx, path|
{
with_encode_metadata_header(tcx, path,
|ecx|
{
let root = ecx.encode_crate_root();
ecx.opaque.flush();
tcx.prof.artifact_size("crate_metadata", "crate_metadata",
ecx.opaque.file().metadata().unwrap().len());
root.position.get()
})
}, None);
}
}
}#[instrument(level = "trace", skip(tcx))]
2413pub fn encode_metadata(tcx: TyCtxt<'_>, path: &Path, ref_path: Option<&Path>) {
2414 tcx.dep_graph.assert_ignored();
2417
2418 if let Some(ref_path) = ref_path {
2420 let _prof_timer = tcx.prof.verbose_generic_activity("generate_crate_metadata_stub");
2421
2422 with_encode_metadata_header(tcx, ref_path, |ecx| {
2423 let header: LazyValue<CrateHeader> = ecx.lazy(CrateHeader {
2424 name: tcx.crate_name(LOCAL_CRATE),
2425 triple: tcx.sess.opts.target_triple.clone(),
2426 hash: tcx.crate_hash(LOCAL_CRATE),
2427 is_proc_macro_crate: false,
2428 is_stub: true,
2429 });
2430 header.position.get()
2431 })
2432 }
2433
2434 let _prof_timer = tcx.prof.verbose_generic_activity("generate_crate_metadata");
2435
2436 let dep_node = tcx.metadata_dep_node();
2437
2438 if tcx.dep_graph.is_fully_enabled()
2440 && let work_product_id = WorkProductId::from_cgu_name("metadata")
2441 && let Some(work_product) = tcx.dep_graph.previous_work_product(&work_product_id)
2442 && tcx.dep_graph.try_mark_green(tcx, &dep_node).is_some()
2443 {
2444 let saved_path = &work_product.saved_files["rmeta"];
2445 let incr_comp_session_dir = tcx.sess.incr_comp_session_dir_opt().unwrap();
2446 let source_file = rustc_incremental::in_incr_comp_dir(&incr_comp_session_dir, saved_path);
2447 debug!("copying preexisting metadata from {source_file:?} to {path:?}");
2448 match rustc_fs_util::link_or_copy(&source_file, path) {
2449 Ok(_) => {}
2450 Err(err) => tcx.dcx().emit_fatal(FailCreateFileEncoder { err }),
2451 };
2452 return;
2453 };
2454
2455 if tcx.sess.threads() != 1 {
2456 par_join(
2460 || prefetch_mir(tcx),
2461 || {
2462 let _ = tcx.exported_non_generic_symbols(LOCAL_CRATE);
2463 let _ = tcx.exported_generic_symbols(LOCAL_CRATE);
2464 },
2465 );
2466 }
2467
2468 tcx.dep_graph.with_task(
2471 dep_node,
2472 tcx,
2473 path,
2474 |tcx, path| {
2475 with_encode_metadata_header(tcx, path, |ecx| {
2476 let root = ecx.encode_crate_root();
2479
2480 ecx.opaque.flush();
2482 tcx.prof.artifact_size(
2484 "crate_metadata",
2485 "crate_metadata",
2486 ecx.opaque.file().metadata().unwrap().len(),
2487 );
2488
2489 root.position.get()
2490 })
2491 },
2492 None,
2493 );
2494}
2495
2496fn with_encode_metadata_header(
2497 tcx: TyCtxt<'_>,
2498 path: &Path,
2499 f: impl FnOnce(&mut EncodeContext<'_, '_>) -> usize,
2500) {
2501 let mut encoder = opaque::FileEncoder::new(path)
2502 .unwrap_or_else(|err| tcx.dcx().emit_fatal(FailCreateFileEncoder { err }));
2503 encoder.emit_raw_bytes(METADATA_HEADER);
2504
2505 encoder.emit_raw_bytes(&0u64.to_le_bytes());
2507
2508 let source_map_files = tcx.sess.source_map().files();
2509 let source_file_cache = (Arc::clone(&source_map_files[0]), 0);
2510 let required_source_files = Some(FxIndexSet::default());
2511 drop(source_map_files);
2512
2513 let hygiene_ctxt = HygieneEncodeContext::default();
2514
2515 let mut ecx = EncodeContext {
2516 opaque: encoder,
2517 tcx,
2518 feat: tcx.features(),
2519 tables: Default::default(),
2520 lazy_state: LazyState::NoNode,
2521 span_shorthands: Default::default(),
2522 type_shorthands: Default::default(),
2523 predicate_shorthands: Default::default(),
2524 source_file_cache,
2525 interpret_allocs: Default::default(),
2526 required_source_files,
2527 is_proc_macro: tcx.crate_types().contains(&CrateType::ProcMacro),
2528 hygiene_ctxt: &hygiene_ctxt,
2529 symbol_index_table: Default::default(),
2530 };
2531
2532 rustc_version(tcx.sess.cfg_version).encode(&mut ecx);
2534
2535 let root_position = f(&mut ecx);
2536
2537 if let Err((path, err)) = ecx.opaque.finish() {
2541 tcx.dcx().emit_fatal(FailWriteFile { path: &path, err });
2542 }
2543
2544 let file = ecx.opaque.file();
2545 if let Err(err) = encode_root_position(file, root_position) {
2546 tcx.dcx().emit_fatal(FailWriteFile { path: ecx.opaque.path(), err });
2547 }
2548}
2549
2550fn encode_root_position(mut file: &File, pos: usize) -> Result<(), std::io::Error> {
2551 let pos_before_seek = file.stream_position().unwrap();
2553
2554 let header = METADATA_HEADER.len();
2556 file.seek(std::io::SeekFrom::Start(header as u64))?;
2557 file.write_all(&pos.to_le_bytes())?;
2558
2559 file.seek(std::io::SeekFrom::Start(pos_before_seek))?;
2561 Ok(())
2562}
2563
2564pub(crate) fn provide(providers: &mut Providers) {
2565 *providers = Providers {
2566 doc_link_resolutions: |tcx, def_id| {
2567 tcx.resolutions(())
2568 .doc_link_resolutions
2569 .get(&def_id)
2570 .unwrap_or_else(|| ::rustc_middle::util::bug::span_bug_fmt(tcx.def_span(def_id),
format_args!("no resolutions for a doc link"))span_bug!(tcx.def_span(def_id), "no resolutions for a doc link"))
2571 },
2572 doc_link_traits_in_scope: |tcx, def_id| {
2573 tcx.resolutions(()).doc_link_traits_in_scope.get(&def_id).unwrap_or_else(|| {
2574 ::rustc_middle::util::bug::span_bug_fmt(tcx.def_span(def_id),
format_args!("no traits in scope for a doc link"))span_bug!(tcx.def_span(def_id), "no traits in scope for a doc link")
2575 })
2576 },
2577
2578 ..*providers
2579 }
2580}
2581
2582pub fn rendered_const<'tcx>(tcx: TyCtxt<'tcx>, body: &hir::Body<'_>, def_id: LocalDefId) -> String {
2610 let value = body.value;
2611
2612 #[derive(#[automatically_derived]
impl ::core::cmp::PartialEq for Classification {
#[inline]
fn eq(&self, other: &Classification) -> 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 Classification {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {}
}Eq)]
2613 enum Classification {
2614 Literal,
2615 Simple,
2616 Complex,
2617 }
2618
2619 use Classification::*;
2620
2621 fn classify(expr: &hir::Expr<'_>) -> Classification {
2622 match &expr.kind {
2623 hir::ExprKind::Unary(hir::UnOp::Neg, expr) => {
2624 if #[allow(non_exhaustive_omitted_patterns)] match expr.kind {
hir::ExprKind::Lit(_) => true,
_ => false,
}matches!(expr.kind, hir::ExprKind::Lit(_)) { Literal } else { Complex }
2625 }
2626 hir::ExprKind::Lit(_) => Literal,
2627 hir::ExprKind::Tup([]) => Simple,
2628 hir::ExprKind::Block(hir::Block { stmts: [], expr: Some(expr), .. }, _) => {
2629 if classify(expr) == Complex { Complex } else { Simple }
2630 }
2631 hir::ExprKind::Path(hir::QPath::Resolved(_, hir::Path { segments, .. })) => {
2636 if segments.iter().all(|segment| segment.args.is_none()) { Simple } else { Complex }
2637 }
2638 hir::ExprKind::Path(hir::QPath::TypeRelative(..)) => Simple,
2641 _ => Complex,
2642 }
2643 }
2644
2645 match classify(value) {
2646 Literal
2656 if !value.span.from_expansion()
2657 && let Ok(snippet) = tcx.sess.source_map().span_to_snippet(value.span) =>
2658 {
2659 snippet
2660 }
2661
2662 Literal | Simple => id_to_string(&tcx, body.id().hir_id),
2665
2666 Complex => {
2670 if tcx.def_kind(def_id) == DefKind::AnonConst {
2671 "{ _ }".to_owned()
2672 } else {
2673 "_".to_owned()
2674 }
2675 }
2676 }
2677}