Skip to content

Commit 0d0caca

Browse files
committed
Use default_field_values in Resolver
1 parent 4c6f79d commit 0d0caca

File tree

1 file changed

+22
-39
lines changed
  • compiler/rustc_resolve/src

1 file changed

+22
-39
lines changed

compiler/rustc_resolve/src/lib.rs

Lines changed: 22 additions & 39 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)]
@@ -1054,7 +1055,7 @@ pub struct Resolver<'ra, 'tcx> {
10541055

10551056
graph_root: Module<'ra>,
10561057

1057-
prelude: Option<Module<'ra>>,
1058+
prelude: Option<Module<'ra>> = None,
10581059
extern_prelude: FxIndexMap<Macros20NormalizedIdent, ExternPreludeEntry<'ra>>,
10591060

10601061
/// N.B., this is used only for better diagnostics, not name resolution itself.
@@ -1065,10 +1066,10 @@ pub struct Resolver<'ra, 'tcx> {
10651066
field_visibility_spans: FxHashMap<DefId, Vec<Span>>,
10661067

10671068
/// All imports known to succeed or fail.
1068-
determined_imports: Vec<Import<'ra>>,
1069+
determined_imports: Vec<Import<'ra>> = Vec::new(),
10691070

10701071
/// All non-determined imports.
1071-
indeterminate_imports: Vec<Import<'ra>>,
1072+
indeterminate_imports: Vec<Import<'ra>> = Vec::new(),
10721073

10731074
// Spans for local variables found during pattern resolution.
10741075
// Used for suggestions during error reporting.
@@ -1119,19 +1120,19 @@ pub struct Resolver<'ra, 'tcx> {
11191120

11201121
/// Maps glob imports to the names of items actually imported.
11211122
glob_map: FxIndexMap<LocalDefId, FxIndexSet<Symbol>>,
1122-
glob_error: Option<ErrorGuaranteed>,
1123-
visibilities_for_hashing: Vec<(LocalDefId, Visibility)>,
1123+
glob_error: Option<ErrorGuaranteed> = None,
1124+
visibilities_for_hashing: Vec<(LocalDefId, Visibility)> = Vec::new(),
11241125
used_imports: FxHashSet<NodeId>,
11251126
maybe_unused_trait_imports: FxIndexSet<LocalDefId>,
11261127

11271128
/// Privacy errors are delayed until the end in order to deduplicate them.
1128-
privacy_errors: Vec<PrivacyError<'ra>>,
1129+
privacy_errors: Vec<PrivacyError<'ra>> = Vec::new(),
11291130
/// Ambiguity errors are delayed for deduplication.
1130-
ambiguity_errors: Vec<AmbiguityError<'ra>>,
1131+
ambiguity_errors: Vec<AmbiguityError<'ra>> = Vec::new(),
11311132
/// `use` injections are delayed for better placement and deduplication.
1132-
use_injections: Vec<UseError<'tcx>>,
1133+
use_injections: Vec<UseError<'tcx>> = Vec::new(),
11331134
/// Crate-local macro expanded `macro_export` referred to by a module-relative path.
1134-
macro_expanded_macro_export_errors: BTreeSet<(Span, Span)>,
1135+
macro_expanded_macro_export_errors: BTreeSet<(Span, Span)> = BTreeSet::new(),
11351136

11361137
arenas: &'ra ResolverArenas<'ra>,
11371138
dummy_binding: NameBinding<'ra>,
@@ -1157,10 +1158,11 @@ pub struct Resolver<'ra, 'tcx> {
11571158
proc_macro_stubs: FxHashSet<LocalDefId>,
11581159
/// Traces collected during macro resolution and validated when it's complete.
11591160
single_segment_macro_resolutions:
1160-
Vec<(Ident, MacroKind, ParentScope<'ra>, Option<NameBinding<'ra>>, Option<Span>)>,
1161+
Vec<(Ident, MacroKind, ParentScope<'ra>, Option<NameBinding<'ra>>, Option<Span>)>
1162+
= Vec::new(),
11611163
multi_segment_macro_resolutions:
1162-
Vec<(Vec<Segment>, Span, MacroKind, ParentScope<'ra>, Option<Res>, Namespace)>,
1163-
builtin_attrs: Vec<(Ident, ParentScope<'ra>)>,
1164+
Vec<(Vec<Segment>, Span, MacroKind, ParentScope<'ra>, Option<Res>, Namespace)> = Vec::new(),
1165+
builtin_attrs: Vec<(Ident, ParentScope<'ra>)> = Vec::new(),
11641166
/// `derive(Copy)` marks items they are applied to so they are treated specially later.
11651167
/// Derive macros cannot modify the item themselves and have to store the markers in the global
11661168
/// context, so they attach the markers to derive container IDs using this resolver table.
@@ -1182,9 +1184,9 @@ pub struct Resolver<'ra, 'tcx> {
11821184
/// Avoid duplicated errors for "name already defined".
11831185
name_already_seen: FxHashMap<Symbol, Span>,
11841186

1185-
potentially_unused_imports: Vec<Import<'ra>>,
1187+
potentially_unused_imports: Vec<Import<'ra>> = Vec::new(),
11861188

1187-
potentially_unnecessary_qualifications: Vec<UnnecessaryQualification<'ra>>,
1189+
potentially_unnecessary_qualifications: Vec<UnnecessaryQualification<'ra>> = Vec::new(),
11881190

11891191
/// Table for mapping struct IDs into struct constructor IDs,
11901192
/// it's not used during normal resolution, only for better error reporting.
@@ -1193,7 +1195,7 @@ pub struct Resolver<'ra, 'tcx> {
11931195

11941196
lint_buffer: LintBuffer,
11951197

1196-
next_node_id: NodeId,
1198+
next_node_id: NodeId = CRATE_NODE_ID,
11971199

11981200
node_id_to_def_id: NodeMap<Feed<'tcx, LocalDefId>>,
11991201

@@ -1211,17 +1213,17 @@ pub struct Resolver<'ra, 'tcx> {
12111213
item_generics_num_lifetimes: FxHashMap<LocalDefId, usize>,
12121214
delegation_fn_sigs: LocalDefIdMap<DelegationFnSig>,
12131215

1214-
main_def: Option<MainDefinition>,
1216+
main_def: Option<MainDefinition> = None,
12151217
trait_impls: FxIndexMap<DefId, Vec<LocalDefId>>,
12161218
/// A list of proc macro LocalDefIds, written out in the order in which
12171219
/// they are declared in the static array generated by proc_macro_harness.
1218-
proc_macros: Vec<LocalDefId>,
1220+
proc_macros: Vec<LocalDefId> = Vec::new(),
12191221
confused_type_with_std_module: FxIndexMap<Span, Span>,
12201222
/// Whether lifetime elision was successful.
12211223
lifetime_elision_allowed: FxHashSet<NodeId>,
12221224

12231225
/// Names of items that were stripped out via cfg with their corresponding cfg meta item.
1224-
stripped_cfg_items: Vec<StrippedCfgItem<NodeId>>,
1226+
stripped_cfg_items: Vec<StrippedCfgItem<NodeId>> = Vec::new(),
12251227

12261228
effective_visibilities: EffectiveVisibilities,
12271229
doc_link_resolutions: FxIndexMap<LocalDefId, DocLinkResMap>,
@@ -1245,7 +1247,7 @@ pub struct Resolver<'ra, 'tcx> {
12451247

12461248
/// Whether `Resolver::register_macros_for_all_crates` has been called once already, as we
12471249
/// don't need to run it more than once.
1248-
all_crate_macros_already_registered: bool,
1250+
all_crate_macros_already_registered: bool = false,
12491251

12501252
// Stores pre-expansion and pre-placeholder-fragment-insertion names for `impl Trait` types
12511253
// that were encountered during resolution. These names are used to generate item names
@@ -1531,15 +1533,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15311533
// The outermost module has def ID 0; this is not reflected in the
15321534
// AST.
15331535
graph_root,
1534-
prelude: None,
15351536
extern_prelude,
15361537

15371538
field_names: Default::default(),
15381539
field_visibility_spans: FxHashMap::default(),
15391540

1540-
determined_imports: Vec::new(),
1541-
indeterminate_imports: Vec::new(),
1542-
15431541
pat_span_map: Default::default(),
15441542
partial_res_map: Default::default(),
15451543
import_res_map: Default::default(),
@@ -1558,16 +1556,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15581556
ast_transform_scopes: FxHashMap::default(),
15591557

15601558
glob_map: Default::default(),
1561-
glob_error: None,
1562-
visibilities_for_hashing: Default::default(),
15631559
used_imports: FxHashSet::default(),
15641560
maybe_unused_trait_imports: Default::default(),
15651561

1566-
privacy_errors: Vec::new(),
1567-
ambiguity_errors: Vec::new(),
1568-
use_injections: Vec::new(),
1569-
macro_expanded_macro_export_errors: BTreeSet::new(),
1570-
15711562
arenas,
15721563
dummy_binding: arenas.new_pub_res_binding(Res::Err, DUMMY_SP, LocalExpnId::ROOT),
15731564
builtin_types_bindings: PrimTy::ALL
@@ -1611,27 +1602,19 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
16111602
derive_data: Default::default(),
16121603
local_macro_def_scopes: FxHashMap::default(),
16131604
name_already_seen: FxHashMap::default(),
1614-
potentially_unused_imports: Vec::new(),
1615-
potentially_unnecessary_qualifications: Default::default(),
16161605
struct_constructors: Default::default(),
16171606
unused_macros: Default::default(),
16181607
unused_macro_rules: Default::default(),
16191608
proc_macro_stubs: Default::default(),
1620-
single_segment_macro_resolutions: Default::default(),
1621-
multi_segment_macro_resolutions: Default::default(),
1622-
builtin_attrs: Default::default(),
16231609
containers_deriving_copy: Default::default(),
16241610
lint_buffer: LintBuffer::default(),
1625-
next_node_id: CRATE_NODE_ID,
16261611
node_id_to_def_id,
16271612
disambiguator: DisambiguatorState::new(),
16281613
placeholder_field_indices: Default::default(),
16291614
invocation_parents,
16301615
legacy_const_generic_args: Default::default(),
16311616
item_generics_num_lifetimes: Default::default(),
1632-
main_def: Default::default(),
16331617
trait_impls: Default::default(),
1634-
proc_macros: Default::default(),
16351618
confused_type_with_std_module: Default::default(),
16361619
lifetime_elision_allowed: Default::default(),
16371620
stripped_cfg_items: Default::default(),
@@ -1641,12 +1624,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
16411624
all_macro_rules: Default::default(),
16421625
delegation_fn_sigs: Default::default(),
16431626
glob_delegation_invoc_ids: Default::default(),
1644-
all_crate_macros_already_registered: false,
16451627
impl_unexpanded_invocations: Default::default(),
16461628
impl_binding_keys: Default::default(),
16471629
current_crate_outer_attr_insert_span,
16481630
mods_with_parse_errors: Default::default(),
16491631
impl_trait_names: Default::default(),
1632+
..
16501633
};
16511634

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

0 commit comments

Comments
 (0)