Skip to content

Commit f50d490

Browse files
committed
Use default_field_values in Resolver
1 parent ac878bc commit f50d490

File tree

1 file changed

+23
-41
lines changed
  • compiler/rustc_resolve/src

1 file changed

+23
-41
lines changed

compiler/rustc_resolve/src/lib.rs

Lines changed: 23 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#![doc(rust_logo)]
1515
#![feature(assert_matches)]
1616
#![feature(box_patterns)]
17+
#![feature(default_field_values)]
1718
#![feature(if_let_guard)]
1819
#![feature(iter_intersperse)]
1920
#![feature(rustc_attrs)]
@@ -1024,7 +1025,7 @@ pub struct Resolver<'ra, 'tcx> {
10241025

10251026
graph_root: Module<'ra>,
10261027

1027-
prelude: Option<Module<'ra>>,
1028+
prelude: Option<Module<'ra>> = None,
10281029
extern_prelude: FxIndexMap<Ident, ExternPreludeEntry<'ra>>,
10291030

10301031
/// N.B., this is used only for better diagnostics, not name resolution itself.
@@ -1035,10 +1036,10 @@ pub struct Resolver<'ra, 'tcx> {
10351036
field_visibility_spans: FxHashMap<DefId, Vec<Span>>,
10361037

10371038
/// All imports known to succeed or fail.
1038-
determined_imports: Vec<Import<'ra>>,
1039+
determined_imports: Vec<Import<'ra>> = Vec::new(),
10391040

10401041
/// All non-determined imports.
1041-
indeterminate_imports: Vec<Import<'ra>>,
1042+
indeterminate_imports: Vec<Import<'ra>> = Vec::new(),
10421043

10431044
// Spans for local variables found during pattern resolution.
10441045
// Used for suggestions during error reporting.
@@ -1087,23 +1088,23 @@ pub struct Resolver<'ra, 'tcx> {
10871088
extern_module_map: RefCell<FxIndexMap<DefId, Module<'ra>>>,
10881089
binding_parent_modules: FxHashMap<NameBinding<'ra>, Module<'ra>>,
10891090

1090-
underscore_disambiguator: u32,
1091+
underscore_disambiguator: u32 = 0,
10911092

10921093
/// Maps glob imports to the names of items actually imported.
10931094
glob_map: FxIndexMap<LocalDefId, FxIndexSet<Symbol>>,
1094-
glob_error: Option<ErrorGuaranteed>,
1095-
visibilities_for_hashing: Vec<(LocalDefId, Visibility)>,
1095+
glob_error: Option<ErrorGuaranteed> = None,
1096+
visibilities_for_hashing: Vec<(LocalDefId, Visibility)> = Vec::new(),
10961097
used_imports: FxHashSet<NodeId>,
10971098
maybe_unused_trait_imports: FxIndexSet<LocalDefId>,
10981099

10991100
/// Privacy errors are delayed until the end in order to deduplicate them.
1100-
privacy_errors: Vec<PrivacyError<'ra>>,
1101+
privacy_errors: Vec<PrivacyError<'ra>> = Vec::new(),
11011102
/// Ambiguity errors are delayed for deduplication.
1102-
ambiguity_errors: Vec<AmbiguityError<'ra>>,
1103+
ambiguity_errors: Vec<AmbiguityError<'ra>> = Vec::new(),
11031104
/// `use` injections are delayed for better placement and deduplication.
1104-
use_injections: Vec<UseError<'tcx>>,
1105+
use_injections: Vec<UseError<'tcx>> = Vec::new(),
11051106
/// Crate-local macro expanded `macro_export` referred to by a module-relative path.
1106-
macro_expanded_macro_export_errors: BTreeSet<(Span, Span)>,
1107+
macro_expanded_macro_export_errors: BTreeSet<(Span, Span)> = BTreeSet::new(),
11071108

11081109
arenas: &'ra ResolverArenas<'ra>,
11091110
dummy_binding: NameBinding<'ra>,
@@ -1130,10 +1131,11 @@ pub struct Resolver<'ra, 'tcx> {
11301131
proc_macro_stubs: FxHashSet<LocalDefId>,
11311132
/// Traces collected during macro resolution and validated when it's complete.
11321133
single_segment_macro_resolutions:
1133-
Vec<(Ident, MacroKind, ParentScope<'ra>, Option<NameBinding<'ra>>, Option<Span>)>,
1134+
Vec<(Ident, MacroKind, ParentScope<'ra>, Option<NameBinding<'ra>>, Option<Span>)>
1135+
= Vec::new(),
11341136
multi_segment_macro_resolutions:
1135-
Vec<(Vec<Segment>, Span, MacroKind, ParentScope<'ra>, Option<Res>, Namespace)>,
1136-
builtin_attrs: Vec<(Ident, ParentScope<'ra>)>,
1137+
Vec<(Vec<Segment>, Span, MacroKind, ParentScope<'ra>, Option<Res>, Namespace)> = Vec::new(),
1138+
builtin_attrs: Vec<(Ident, ParentScope<'ra>)> = Vec::new(),
11371139
/// `derive(Copy)` marks items they are applied to so they are treated specially later.
11381140
/// Derive macros cannot modify the item themselves and have to store the markers in the global
11391141
/// context, so they attach the markers to derive container IDs using this resolver table.
@@ -1155,9 +1157,9 @@ pub struct Resolver<'ra, 'tcx> {
11551157
/// Avoid duplicated errors for "name already defined".
11561158
name_already_seen: FxHashMap<Symbol, Span>,
11571159

1158-
potentially_unused_imports: Vec<Import<'ra>>,
1160+
potentially_unused_imports: Vec<Import<'ra>> = Vec::new(),
11591161

1160-
potentially_unnecessary_qualifications: Vec<UnnecessaryQualification<'ra>>,
1162+
potentially_unnecessary_qualifications: Vec<UnnecessaryQualification<'ra>> = Vec::new(),
11611163

11621164
/// Table for mapping struct IDs into struct constructor IDs,
11631165
/// it's not used during normal resolution, only for better error reporting.
@@ -1166,7 +1168,7 @@ pub struct Resolver<'ra, 'tcx> {
11661168

11671169
lint_buffer: LintBuffer,
11681170

1169-
next_node_id: NodeId,
1171+
next_node_id: NodeId = CRATE_NODE_ID,
11701172

11711173
node_id_to_def_id: NodeMap<Feed<'tcx, LocalDefId>>,
11721174

@@ -1184,17 +1186,17 @@ pub struct Resolver<'ra, 'tcx> {
11841186
item_generics_num_lifetimes: FxHashMap<LocalDefId, usize>,
11851187
delegation_fn_sigs: LocalDefIdMap<DelegationFnSig>,
11861188

1187-
main_def: Option<MainDefinition>,
1189+
main_def: Option<MainDefinition> = None,
11881190
trait_impls: FxIndexMap<DefId, Vec<LocalDefId>>,
11891191
/// A list of proc macro LocalDefIds, written out in the order in which
11901192
/// they are declared in the static array generated by proc_macro_harness.
1191-
proc_macros: Vec<LocalDefId>,
1193+
proc_macros: Vec<LocalDefId> = Vec::new(),
11921194
confused_type_with_std_module: FxIndexMap<Span, Span>,
11931195
/// Whether lifetime elision was successful.
11941196
lifetime_elision_allowed: FxHashSet<NodeId>,
11951197

11961198
/// Names of items that were stripped out via cfg with their corresponding cfg meta item.
1197-
stripped_cfg_items: Vec<StrippedCfgItem<NodeId>>,
1199+
stripped_cfg_items: Vec<StrippedCfgItem<NodeId>> = Vec::new(),
11981200

11991201
effective_visibilities: EffectiveVisibilities,
12001202
doc_link_resolutions: FxIndexMap<LocalDefId, DocLinkResMap>,
@@ -1218,7 +1220,7 @@ pub struct Resolver<'ra, 'tcx> {
12181220

12191221
/// Whether `Resolver::register_macros_for_all_crates` has been called once already, as we
12201222
/// don't need to run it more than once.
1221-
all_crate_macros_already_registered: bool,
1223+
all_crate_macros_already_registered: bool = false,
12221224

12231225
// Stores pre-expansion and pre-placeholder-fragment-insertion names for `impl Trait` types
12241226
// that were encountered during resolution. These names are used to generate item names
@@ -1486,15 +1488,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
14861488
// The outermost module has def ID 0; this is not reflected in the
14871489
// AST.
14881490
graph_root,
1489-
prelude: None,
14901491
extern_prelude,
14911492

14921493
field_names: Default::default(),
14931494
field_visibility_spans: FxHashMap::default(),
14941495

1495-
determined_imports: Vec::new(),
1496-
indeterminate_imports: Vec::new(),
1497-
14981496
pat_span_map: Default::default(),
14991497
partial_res_map: Default::default(),
15001498
import_res_map: Default::default(),
@@ -1505,7 +1503,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15051503
extern_crate_map: Default::default(),
15061504
module_children: Default::default(),
15071505
trait_map: NodeMap::default(),
1508-
underscore_disambiguator: 0,
15091506
empty_module,
15101507
local_module_map,
15111508
extern_module_map: Default::default(),
@@ -1514,16 +1511,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15141511
ast_transform_scopes: FxHashMap::default(),
15151512

15161513
glob_map: Default::default(),
1517-
glob_error: None,
1518-
visibilities_for_hashing: Default::default(),
15191514
used_imports: FxHashSet::default(),
15201515
maybe_unused_trait_imports: Default::default(),
15211516

1522-
privacy_errors: Vec::new(),
1523-
ambiguity_errors: Vec::new(),
1524-
use_injections: Vec::new(),
1525-
macro_expanded_macro_export_errors: BTreeSet::new(),
1526-
15271517
arenas,
15281518
dummy_binding: arenas.new_pub_res_binding(Res::Err, DUMMY_SP, LocalExpnId::ROOT),
15291519
builtin_types_bindings: PrimTy::ALL
@@ -1568,27 +1558,19 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15681558
derive_data: Default::default(),
15691559
local_macro_def_scopes: FxHashMap::default(),
15701560
name_already_seen: FxHashMap::default(),
1571-
potentially_unused_imports: Vec::new(),
1572-
potentially_unnecessary_qualifications: Default::default(),
15731561
struct_constructors: Default::default(),
15741562
unused_macros: Default::default(),
15751563
unused_macro_rules: Default::default(),
15761564
proc_macro_stubs: Default::default(),
1577-
single_segment_macro_resolutions: Default::default(),
1578-
multi_segment_macro_resolutions: Default::default(),
1579-
builtin_attrs: Default::default(),
15801565
containers_deriving_copy: Default::default(),
15811566
lint_buffer: LintBuffer::default(),
1582-
next_node_id: CRATE_NODE_ID,
15831567
node_id_to_def_id,
15841568
disambiguator: DisambiguatorState::new(),
15851569
placeholder_field_indices: Default::default(),
15861570
invocation_parents,
15871571
legacy_const_generic_args: Default::default(),
15881572
item_generics_num_lifetimes: Default::default(),
1589-
main_def: Default::default(),
15901573
trait_impls: Default::default(),
1591-
proc_macros: Default::default(),
15921574
confused_type_with_std_module: Default::default(),
15931575
lifetime_elision_allowed: Default::default(),
15941576
stripped_cfg_items: Default::default(),
@@ -1598,12 +1580,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15981580
all_macro_rules: Default::default(),
15991581
delegation_fn_sigs: Default::default(),
16001582
glob_delegation_invoc_ids: Default::default(),
1601-
all_crate_macros_already_registered: false,
16021583
impl_unexpanded_invocations: Default::default(),
16031584
impl_binding_keys: Default::default(),
16041585
current_crate_outer_attr_insert_span,
16051586
mods_with_parse_errors: Default::default(),
16061587
impl_trait_names: Default::default(),
1588+
..
16071589
};
16081590

16091591
let root_parent_scope = ParentScope::module(graph_root, &resolver);

0 commit comments

Comments
 (0)