1use annotate_snippets::Level;
3use clap::ValueEnum;
4use indoc::indoc;
5use itertools::Itertools;
6use macros::EnumAsGetters;
7use serde::{Deserialize, Serialize};
8use std::path::PathBuf;
9
10use crate::{
11 ast::*,
12 errors::{ErrorCtx, display_unspanned_error},
13 name_matcher::NamePattern,
14 raise_error, register_error,
15};
16
17pub const CHARON_ARGS: &str = "CHARON_ARGS";
20
21#[derive(Debug, Default, Clone, PartialEq, Eq)]
30#[derive(clap::Args)]
31#[derive(Serialize, Deserialize)]
32#[clap(name = "Charon")]
33#[cfg_attr(feature = "charon_on_charon", charon::rename("cli_options"))]
34pub struct CliOpts {
35 #[clap(long)]
37 #[serde(default)]
38 pub ullbc: bool,
39 #[clap(long)]
45 #[serde(default)]
46 pub precise_drops: bool,
47 #[arg(long)]
50 pub mir: Option<MirLevel>,
51 #[clap(long = "rustc-arg")]
53 #[serde(default)]
54 pub rustc_args: Vec<String>,
55 #[clap(long, value_delimiter = ',')]
60 #[serde(default)]
61 pub targets: Vec<String>,
62 #[clap(long)]
67 #[serde(default)]
68 pub sysroot: Option<String>,
69
70 #[clap(long, visible_alias = "mono")]
74 #[serde(default)]
75 pub monomorphize: bool,
76 #[clap(
80 long,
81 value_name("INCLUDE_TYPES"),
82 num_args(0..=1),
83 require_equals(true),
84 default_missing_value("all"),
85 )]
86 #[serde(default)]
87 pub monomorphize_mut: Option<MonomorphizeMut>,
88
89 #[clap(long, value_delimiter = ',')]
93 #[serde(default)]
94 pub start_from: Vec<String>,
95 #[clap(long, value_delimiter = ',')]
98 #[serde(default)]
99 pub start_from_if_exists: Vec<String>,
100 #[clap(
104 long,
105 value_name("ATTRIBUTE"),
106 num_args(0..),
107 require_equals(true),
108 value_delimiter = ',',
109 default_missing_value("verify::start_from"),
110 )]
111 #[serde(default)]
112 pub start_from_attribute: Vec<String>,
113 #[clap(long)]
115 #[serde(default)]
116 pub start_from_pub: bool,
117
118 #[clap(
120 long,
121 help = indoc!("
122 Whitelist of items to translate. These use the name-matcher syntax (note: this differs
123 a bit from the ocaml NameMatcher).
124
125 Note: This is very rough at the moment. E.g. this parses `u64` as a path instead of the
126 built-in type. It is also not possible to filter a trait impl (this will only filter
127 its methods). Please report bugs or missing features.
128
129 Examples:
130 - `crate::module1::module2::item`: refers to this item and all its subitems (e.g.
131 submodules or trait methods);
132 - `crate::module1::module2::item::_`: refers only to the subitems of this item;
133 - `core::convert::{impl core::convert::Into<_> for _}`: retrieve the body of this
134 very useful impl;
135
136 When multiple patterns in the `--include` and `--opaque` options match the same item,
137 the most precise pattern wins. E.g.: `charon --opaque crate::module --include
138 crate::module::_` makes the `module` opaque (we won't explore its contents), but the
139 items in it transparent (we will translate them if we encounter them.)
140 "))]
141 #[serde(default)]
142 #[cfg_attr(feature = "charon_on_charon", charon::rename("included"))]
143 pub include: Vec<String>,
144 #[clap(long)]
146 #[serde(default)]
147 pub opaque: Vec<String>,
148 #[clap(long)]
150 #[serde(default)]
151 pub exclude: Vec<String>,
152 #[clap(long)]
155 #[serde(default)]
156 pub extract_opaque_bodies: bool,
157 #[clap(long)]
160 #[serde(default)]
161 pub translate_all_methods: bool,
162 #[clap(long)]
166 #[serde(default)]
167 pub eager_vtables: bool,
168 #[clap(long)]
172 #[serde(default)]
173 pub duplicate_defaulted_methods: bool,
174
175 #[clap(long, alias = "remove-associated-types")]
178 #[serde(default)]
179 pub lift_associated_types: Vec<String>,
180 #[clap(long)]
183 #[serde(default)]
184 pub hide_marker_traits: bool,
185 #[clap(long)]
187 #[serde(default)]
188 pub hide_allocator: bool,
189 #[clap(long)]
191 #[serde(default)]
192 pub no_doc_comments: bool,
193
194 #[clap(long)]
198 #[serde(default)]
199 pub remove_unused_clauses: bool,
200 #[clap(long)]
205 #[serde(default)]
206 pub remove_unused_self_clauses: bool,
207 #[clap(long)]
210 #[serde(default)]
211 pub remove_adt_clauses: bool,
212
213 #[clap(long)]
215 #[serde(default)]
216 pub desugar_drops: bool,
217 #[clap(long)]
221 #[serde(default)]
222 pub resugar_drops: bool,
223 #[clap(long)]
225 #[serde(default)]
226 pub detect_drop_flags: bool,
227 #[clap(long)]
230 #[serde(default)]
231 pub ops_to_function_calls: bool,
232 #[clap(long)]
236 #[serde(default)]
237 pub index_to_function_calls: bool,
238 #[clap(long)]
240 #[serde(default)]
241 pub treat_box_as_builtin: bool,
242 #[clap(long)]
248 #[serde(default)]
249 pub no_gen_tuple_structs: bool,
250 #[clap(long)]
252 #[serde(default)]
253 pub raw_consts: bool,
254 #[clap(long)]
259 #[serde(default)]
260 pub consts: Option<ConstHandling>,
261 #[clap(long)]
264 #[serde(default)]
265 pub unsized_strings: bool,
266 #[clap(long)]
269 #[serde(default)]
270 pub reconstruct_fallible_operations: bool,
271 #[clap(long)]
273 #[serde(default)]
274 pub reconstruct_asserts: bool,
275 #[clap(long)]
278 #[serde(default)]
279 pub reconstruct_matches: bool,
280 #[clap(long)]
284 #[serde(default)]
285 pub deallocate_all_locals: bool,
286 #[clap(long)]
290 #[serde(default)]
291 pub unbind_item_vars: bool,
292
293 #[clap(long)]
295 #[serde(default)]
296 pub print_original_ullbc: bool,
297 #[clap(long)]
299 #[serde(default)]
300 pub print_ullbc: bool,
301 #[clap(long)]
303 #[serde(default)]
304 pub print_built_llbc: bool,
305 #[clap(long)]
307 #[serde(default)]
308 pub print_llbc: bool,
309 #[clap(long = "dest", value_parser)]
313 #[serde(default)]
314 pub dest_dir: Option<PathBuf>,
315 #[clap(long, value_parser)]
319 #[serde(default)]
320 pub dest_file: Option<PathBuf>,
321 #[clap(long)]
323 #[serde(default)]
324 pub no_dedup_serialized_ast: bool,
325 #[clap(long, value_enum)]
327 #[serde(default)]
328 pub format: Option<SerializationFormatArg>,
329 #[clap(long)]
331 #[serde(default)]
332 pub no_serialize: bool,
333 #[clap(
335 long = "skip-borrow-check",
336 alias = "skip-borrowck",
337 visible_alias = "no-borrow-check",
338 alias = "no-borrowck"
339 )]
340 #[serde(default)]
341 pub skip_borrowck: bool,
342 #[clap(long)]
344 #[serde(default)]
345 pub erase_body_lifetimes: bool,
346 #[clap(long)]
348 #[serde(default)]
349 pub no_typecheck: bool,
350 #[clap(long)]
352 #[serde(default)]
353 pub no_normalize: bool,
354 #[clap(long)]
356 #[serde(default)]
357 pub no_reorder_decls: bool,
358 #[clap(long)]
360 #[serde(default)]
361 pub no_compute_layout_guarantees: bool,
362 #[clap(long)]
364 #[serde(default)]
365 pub abort_on_error: bool,
366 #[clap(long)]
368 #[serde(default)]
369 pub error_on_warnings: bool,
370
371 #[clap(long)]
373 #[arg(value_enum)]
374 pub preset: Option<Preset>,
375}
376
377#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
380#[derive(ValueEnum)]
381#[derive(Serialize, Deserialize)]
382pub enum MirLevel {
383 Built,
385 Promoted,
387 Elaborated,
390 Optimized,
393}
394
395#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
398#[derive(ValueEnum)]
399#[derive(Serialize, Deserialize)]
400#[non_exhaustive]
401pub enum Preset {
402 OldDefaults,
405 RawMir,
408 Fast,
410 Aeneas,
411 Eurydice,
412 Soteria,
413 Tests,
414}
415
416#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
418#[derive(ValueEnum)]
419#[derive(Serialize, Deserialize)]
420pub enum ConstHandling {
421 #[default]
424 Initializers,
425 Values,
428}
429
430#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
431#[derive(ValueEnum)]
432#[derive(Serialize, Deserialize)]
433pub enum MonomorphizeMut {
434 #[default]
436 All,
437 ExceptTypes,
439}
440
441#[derive(Debug, Copy, Clone, PartialEq, Eq)]
442#[derive(ValueEnum)]
443#[derive(Serialize, Deserialize)]
444pub enum SerializationFormatArg {
445 Json,
446 Postcard,
447 #[cfg_attr(feature = "charon_on_charon", charon::rename("AllFormats"))]
448 All,
449}
450
451#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
452#[derive(ValueEnum)]
453#[derive(Serialize, Deserialize)]
454pub enum SerializationFormat {
455 #[default]
456 Json,
457 Postcard,
458}
459
460impl SerializationFormatArg {
461 pub fn as_format(self) -> Option<SerializationFormat> {
462 match self {
463 SerializationFormatArg::Json => Some(SerializationFormat::Json),
464 SerializationFormatArg::Postcard => Some(SerializationFormat::Postcard),
465 SerializationFormatArg::All => None,
466 }
467 }
468}
469
470impl From<SerializationFormat> for SerializationFormatArg {
471 fn from(format: SerializationFormat) -> SerializationFormatArg {
472 match format {
473 SerializationFormat::Json => SerializationFormatArg::Json,
474 SerializationFormat::Postcard => SerializationFormatArg::Postcard,
475 }
476 }
477}
478
479impl SerializationFormat {
480 pub fn output_extension(self, ullbc: bool) -> &'static str {
481 match (ullbc, self) {
482 (true, SerializationFormat::Json) => "ullbc",
483 (false, SerializationFormat::Json) => "llbc",
484 (true, SerializationFormat::Postcard) => "ullbc.postcard",
485 (false, SerializationFormat::Postcard) => "llbc.postcard",
486 }
487 }
488}
489
490impl CliOpts {
491 pub fn apply_preset(&mut self) {
492 if let Some(preset) = self.preset {
493 match preset {
494 Preset::OldDefaults => {
495 self.treat_box_as_builtin = true;
496 self.hide_allocator = true;
497 self.ops_to_function_calls = true;
498 self.index_to_function_calls = true;
499 self.reconstruct_fallible_operations = true;
500 self.reconstruct_asserts = true;
501 self.reconstruct_matches = true;
502 self.unbind_item_vars = true;
503 self.duplicate_defaulted_methods = true;
504 }
505 Preset::RawMir => {
506 self.extract_opaque_bodies = true;
507 self.raw_consts = true;
508 self.ullbc = true;
509 }
510 Preset::Fast => {
511 self.ullbc = true;
512 self.no_typecheck = true;
513 self.no_normalize = true;
514 self.no_reorder_decls = true;
515 self.no_compute_layout_guarantees = true;
516 self.hide_marker_traits = true;
517 self.raw_consts = true;
518 }
519 Preset::Aeneas => {
520 self.lift_associated_types.push("*".to_owned());
521 self.treat_box_as_builtin = true;
522 self.ops_to_function_calls = true;
523 self.index_to_function_calls = true;
524 self.reconstruct_fallible_operations = true;
525 self.reconstruct_asserts = true;
526 self.reconstruct_matches = true;
527 self.hide_marker_traits = true;
528 self.hide_allocator = true;
529 self.remove_unused_self_clauses = true;
530 self.remove_adt_clauses = true;
531 self.unbind_item_vars = true;
532 self.deallocate_all_locals = true;
533 self.no_gen_tuple_structs = true;
534 }
535 Preset::Eurydice => {
536 self.hide_allocator = true;
537 self.treat_box_as_builtin = true;
538 self.reconstruct_fallible_operations = true;
539 self.reconstruct_asserts = true;
540 self.reconstruct_matches = true;
541 self.lift_associated_types.push("*".to_owned());
542 self.unbind_item_vars = true;
543 self.duplicate_defaulted_methods = true;
544 self.include.push("core::marker::MetaSized".to_owned());
546 }
547 Preset::Soteria => {
548 self.desugar_drops = true;
549 self.extract_opaque_bodies = true;
550 self.mir = Some(MirLevel::Elaborated);
551 self.reconstruct_fallible_operations = true;
552 self.reconstruct_asserts = true;
553 self.monomorphize = true;
554 self.no_normalize = true;
555 self.no_typecheck = true;
556 self.no_reorder_decls = true;
557 self.no_compute_layout_guarantees = true;
558 self.erase_body_lifetimes = true;
559 self.no_doc_comments = true;
560 self.precise_drops = true;
561 self.consts = Some(ConstHandling::Values);
562 self.ullbc = true;
563 }
564 Preset::Tests => {
565 self.no_dedup_serialized_ast = true; self.treat_box_as_builtin = true;
567 self.hide_allocator = true;
568 self.reconstruct_fallible_operations = true;
569 self.reconstruct_asserts = true;
570 self.reconstruct_matches = true;
571 self.resugar_drops = true;
572 if !self.monomorphize {
573 self.ops_to_function_calls = true;
574 self.index_to_function_calls = true;
575 }
576 self.duplicate_defaulted_methods = true;
577 self.deallocate_all_locals = true;
578 self.rustc_args.push("--edition=2021".to_owned());
579 self.rustc_args
580 .push("-Zcrate-attr=feature(register_tool)".to_owned());
581 self.rustc_args
582 .push("-Zcrate-attr=register_tool(charon)".to_owned());
583 self.exclude.push("core::fmt".to_owned());
584 if self.extract_opaque_bodies {
585 self.exclude
586 .extend(["core::array".to_owned(), "core::slice::index".to_owned()]);
587 }
588 }
589 }
590 }
591 }
592
593 pub fn validate(&self) -> anyhow::Result<()> {
595 if self.dest_dir.is_some() {
596 display_unspanned_error(
597 Level::WARNING,
598 "`--dest` is deprecated, use `--dest-file` instead",
599 )
600 }
601
602 if self.remove_adt_clauses && self.lift_associated_types.is_empty() {
603 anyhow::bail!(
604 "`--remove-adt-clauses` should be used with `--lift-associated-types='*'` \
605 to avoid missing clause errors",
606 )
607 }
608 if matches!(self.monomorphize_mut, Some(MonomorphizeMut::ExceptTypes))
609 && !self.remove_adt_clauses
610 {
611 anyhow::bail!(
612 "`--monomorphize-mut=except-types` should be used with `--remove-adt-clauses` \
613 to avoid generics mismatches"
614 )
615 }
616 if self.no_gen_tuple_structs && self.monomorphize {
617 anyhow::bail!(
618 "`--no-gen-tuple-structs` is not compatible with `--monomorphize`, as \
619 monomorphization requires each tuple to have its own type declaration"
620 )
621 }
622 if self.monomorphize && (self.ops_to_function_calls || self.index_to_function_calls) {
623 anyhow::bail!(
624 "`--monomorphize` is not compatible with `--ops-to-function-calls` or \
625 `--index-to-function-calls`"
626 )
627 }
628 if self.no_serialize && self.format.is_some() {
629 anyhow::bail!(
630 "`--no-serialize` is not compatible with `--format`, the format is only relevant if we serialize"
631 );
632 }
633 if self.resugar_drops && self.desugar_drops {
634 anyhow::bail!("`--desugar-drops` and `--resugar-drops` are mutually incompatible")
635 }
636 Ok(())
637 }
638
639 fn target_filename(
640 &self,
641 path_base: PathBuf,
642 format: SerializationFormat,
643 ) -> (PathBuf, SerializationFormat) {
644 let extension = format.output_extension(self.ullbc);
645 let target_filename = path_base.with_added_extension(extension);
646 (target_filename, format)
647 }
648
649 pub fn targets(&self, crate_name: &str) -> Vec<(PathBuf, SerializationFormat)> {
650 if self.no_serialize {
651 return vec![];
652 }
653
654 let format = self.format.unwrap_or(SerializationFormatArg::Json);
655 let mut path_base = self.dest_dir.clone().unwrap_or_default();
656 path_base.push(crate_name);
657
658 match format.as_format() {
659 Some(format) => match self.dest_file.clone() {
660 Some(dest) => vec![(dest, format)],
661 None => vec![self.target_filename(path_base, format)],
662 },
663 None => {
664 let path_base = self.dest_file.clone().unwrap_or(path_base);
665 vec![
666 self.target_filename(path_base.clone(), SerializationFormat::Json),
667 self.target_filename(path_base, SerializationFormat::Postcard),
668 ]
669 }
670 }
671 }
672}
673
674#[derive(Debug, Clone, EnumAsGetters)]
676pub enum StartFrom {
677 Pattern { pattern: NamePattern, strict: bool },
680 Attribute(String),
682 Pub,
685}
686
687impl StartFrom {
688 pub fn matches(&self, ctx: &TranslatedCrate, item_meta: &ItemMeta) -> bool {
689 match self {
690 StartFrom::Pattern { pattern, .. } => pattern.matches(ctx, &item_meta.name),
691 StartFrom::Attribute(attr) => item_meta
692 .attr_info
693 .attributes
694 .iter()
695 .filter_map(|a| a.as_unknown())
696 .any(|raw_attr| raw_attr.path == *attr),
697 StartFrom::Pub => item_meta.attr_info.public && item_meta.is_local,
698 }
699 }
700}
701
702pub struct TranslateOptions {
704 pub start_from: Vec<StartFrom>,
706 pub mir_level: MirLevel,
708 pub translate_all_methods: bool,
711 pub eager_vtables: bool,
713 pub duplicate_defaulted_methods: bool,
715 pub monomorphize_mut: Option<MonomorphizeMut>,
718 pub hide_marker_traits: bool,
721 pub hide_allocator: bool,
723 pub no_doc_comments: bool,
725 pub hide_traits: Vec<NamePattern>,
728 pub remove_unused_clauses: bool,
732 pub remove_unused_self_clauses: bool,
734 pub remove_adt_clauses: bool,
736 pub monomorphize_with_hax: bool,
738 pub ullbc: bool,
740 pub ops_to_function_calls: bool,
743 pub index_to_function_calls: bool,
745 pub print_built_llbc: bool,
747 pub treat_box_as_builtin: bool,
749 pub no_gen_tuple_structs: bool,
752 pub raw_consts: bool,
754 pub consts: ConstHandling,
757 pub unsized_strings: bool,
760 pub reconstruct_fallible_operations: bool,
763 pub reconstruct_asserts: bool,
765 pub reconstruct_matches: bool,
767 pub deallocate_all_locals: bool,
769 pub unbind_item_vars: bool,
771 pub item_opacities: Vec<(NamePattern, ItemOpacity)>,
774 pub lift_associated_types: Vec<NamePattern>,
776 pub erase_body_lifetimes: bool,
778 pub no_typecheck: bool,
780 pub no_normalize: bool,
782 pub no_reorder_decls: bool,
784 pub no_compute_layout_guarantees: bool,
786 pub desugar_drops: bool,
788 pub resugar_drops: bool,
790 pub detect_drop_flags: bool,
792 pub add_destruct_bounds: bool,
794}
795
796impl TranslateOptions {
797 pub fn new(error_ctx: &mut ErrorCtx, options: &CliOpts) -> Self {
798 let mut parse_pattern = |s: &str| -> Result<_, Error> {
799 match NamePattern::parse(s) {
800 Ok(p) => Ok(p),
801 Err(e) => raise_error!(error_ctx, no_crate, "failed to parse pattern `{s}` ({e})"),
802 }
803 };
804
805 let mut mir_level = options.mir.unwrap_or(MirLevel::Promoted);
806 if options.precise_drops {
807 mir_level = std::cmp::max(mir_level, MirLevel::Elaborated);
808 }
809
810 let mut start_from = options
811 .start_from
812 .iter()
813 .filter_map(|path| parse_pattern(path).ok())
814 .map(|p| StartFrom::Pattern {
815 pattern: p,
816 strict: true,
817 })
818 .collect_vec();
819 start_from.extend(
820 options
821 .start_from_if_exists
822 .iter()
823 .filter_map(|path| parse_pattern(path).ok())
824 .map(|p| StartFrom::Pattern {
825 pattern: p,
826 strict: false,
827 }),
828 );
829 for attr in options.start_from_attribute.iter().cloned() {
830 start_from.push(StartFrom::Attribute(attr));
831 }
832 if options.start_from_pub {
833 start_from.push(StartFrom::Pub);
834 }
835 if start_from.is_empty() {
836 start_from.push(StartFrom::Pattern {
837 pattern: parse_pattern("crate").unwrap(),
838 strict: true,
839 });
840 }
841
842 let hide_traits = options
843 .hide_marker_traits
844 .then_some([
845 "core::marker::Sized",
846 "core::marker::MetaSized",
847 "core::marker::PointeeSized",
848 "core::marker::Tuple",
849 "core::clone::TrivialClone",
850 ])
851 .into_iter()
852 .flatten()
853 .chain(options.hide_allocator.then_some("core::alloc::Allocator"))
854 .filter_map(|s| parse_pattern(s).ok())
855 .collect_vec();
856
857 let item_opacities = {
858 use ItemOpacity::*;
859 let mut opacities = vec![];
860
861 if options.extract_opaque_bodies {
863 opacities.push(("_".to_string(), Transparent));
864 } else {
865 opacities.push(("_".to_string(), Foreign));
866 }
867
868 if options.treat_box_as_builtin {
869 opacities.push((
871 "alloc::boxed::box_assume_init_into_vec_unsafe".to_string(),
872 Transparent,
873 ));
874 }
875
876 opacities.push(("crate".to_owned(), Transparent));
878
879 for pat in options.include.iter() {
880 opacities.push((pat.to_string(), Transparent));
881 }
882 for pat in options.opaque.iter() {
883 opacities.push((pat.to_string(), Opaque));
884 }
885 for pat in options.exclude.iter() {
886 opacities.push((pat.to_string(), Invisible));
887 }
888
889 for trait_name in &hide_traits {
890 opacities.push((trait_name.to_string(), Invisible));
891 }
892
893 let hide_traits = hide_traits
895 .iter()
896 .cloned()
897 .flat_map(|pat| [pat.clone(), NamePattern::impl_for(pat)])
898 .map(|pat| (pat, Invisible));
899 opacities
900 .into_iter()
901 .filter_map(|(s, opacity)| parse_pattern(&s).ok().map(|pat| (pat, opacity)))
902 .chain(hide_traits)
903 .collect()
904 };
905
906 let lift_associated_types = options
907 .lift_associated_types
908 .iter()
909 .filter_map(|s| parse_pattern(s).ok())
910 .collect();
911
912 TranslateOptions {
913 start_from,
914 mir_level,
915 monomorphize_mut: options.monomorphize_mut,
916 hide_marker_traits: options.hide_marker_traits,
917 hide_allocator: options.hide_allocator,
918 no_doc_comments: options.no_doc_comments,
919 hide_traits,
920 remove_unused_clauses: options.remove_unused_clauses,
921 remove_unused_self_clauses: options.remove_unused_self_clauses,
922 remove_adt_clauses: options.remove_adt_clauses,
923 monomorphize_with_hax: options.monomorphize,
924 ullbc: options.ullbc,
925 ops_to_function_calls: options.ops_to_function_calls,
926 index_to_function_calls: options.index_to_function_calls,
927 print_built_llbc: options.print_built_llbc,
928 item_opacities,
929 treat_box_as_builtin: options.treat_box_as_builtin,
930 no_gen_tuple_structs: options.no_gen_tuple_structs,
931 raw_consts: options.raw_consts,
932 consts: options.consts.unwrap_or_default(),
933 unsized_strings: options.unsized_strings,
934 reconstruct_fallible_operations: options.reconstruct_fallible_operations,
935 reconstruct_asserts: options.reconstruct_asserts,
936 reconstruct_matches: options.reconstruct_matches,
937 deallocate_all_locals: options.deallocate_all_locals,
938 lift_associated_types,
939 unbind_item_vars: options.unbind_item_vars,
940 translate_all_methods: options.translate_all_methods,
941 eager_vtables: options.eager_vtables,
942 duplicate_defaulted_methods: options.duplicate_defaulted_methods,
943 erase_body_lifetimes: options.erase_body_lifetimes,
944 no_typecheck: options.no_typecheck,
945 no_normalize: options.no_normalize,
946 no_reorder_decls: options.no_reorder_decls,
947 no_compute_layout_guarantees: options.no_compute_layout_guarantees,
948 desugar_drops: options.desugar_drops,
949 resugar_drops: options.resugar_drops,
950 detect_drop_flags: options.detect_drop_flags,
951 add_destruct_bounds: options.precise_drops,
952 }
953 }
954
955 #[tracing::instrument(skip(self, krate), ret)]
958 pub fn opacity_for_name(&self, krate: &TranslatedCrate, name: &Name) -> ItemOpacity {
959 if name.is_builtin() {
961 return ItemOpacity::Transparent;
962 }
963 let (_, opacity) = self
967 .item_opacities
968 .iter()
969 .filter(|(pat, _)| pat.matches(krate, name))
970 .max()
971 .unwrap();
972 *opacity
973 }
974}