Skip to content

Commit 32fe946

Browse files
committed
Move ty::{ResolverAstLowering, ResolverGlobalCtxt, ResolverOutputs} to their own little module (cute)
1 parent 0810f88 commit 32fe946

File tree

2 files changed

+84
-72
lines changed

2 files changed

+84
-72
lines changed

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 5 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ pub use self::BorrowKind::*;
1818
pub use self::IntVarValue::*;
1919
pub use self::Variance::*;
2020
use crate::error::TypeMismatchReason;
21-
use crate::metadata::ModChild;
22-
use crate::middle::privacy::EffectiveVisibilities;
2321
use crate::mir::{Body, GeneratorLayout};
2422
use crate::ty;
2523
use crate::ty::fast_reject::SimplifiedType;
@@ -28,24 +26,20 @@ pub use adt::*;
2826
pub use assoc::*;
2927
pub use generics::*;
3028
use rustc_ast as ast;
31-
use rustc_ast::node_id::NodeMap;
3229
use rustc_attr as attr;
33-
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
30+
use rustc_data_structures::fx::FxHashMap;
3431
use rustc_data_structures::intern::Interned;
3532
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
36-
use rustc_data_structures::steal::Steal;
3733
use rustc_hir as hir;
38-
use rustc_hir::def::{CtorKind, CtorOf, DefKind, DocLinkResMap, LifetimeRes, Res};
34+
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
3935
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LocalDefIdMap};
4036
use rustc_hir::Node;
41-
use rustc_index::IndexVec;
4237
use rustc_macros::HashStable;
4338
use rustc_serialize::{Decodable, Encodable};
44-
use rustc_session::lint::LintBuffer;
4539
pub use rustc_session::lint::RegisteredTools;
4640
use rustc_span::hygiene::MacroKind;
4741
use rustc_span::symbol::{sym, Ident, Symbol};
48-
use rustc_span::{ExpnId, ExpnKind, Span};
42+
use rustc_span::{ExpnKind, Span};
4943
use rustc_target::abi::{Align, FieldIdx, Integer, IntegerType, VariantIdx};
5044
pub use rustc_target::abi::{ReprFlags, ReprOptions};
5145
use rustc_type_ir::WithCachedTypeInfo;
@@ -147,6 +141,7 @@ mod opaque_hidden_type;
147141
mod param_env;
148142
mod placeholder;
149143
mod predicate;
144+
mod resolver_outputs;
150145
mod symbol_name;
151146
mod term;
152147
mod ty_; // FIXME: rename to `ty` once we don't import `crate::ty` here
@@ -166,75 +161,13 @@ pub use predicate::{
166161
PolyTypeOutlivesPredicate, Predicate, PredicateKind, ProjectionPredicate,
167162
RegionOutlivesPredicate, SubtypePredicate, ToPredicate, TraitPredicate, TypeOutlivesPredicate,
168163
};
164+
pub use resolver_outputs::{ResolverAstLowering, ResolverGlobalCtxt, ResolverOutputs};
169165
pub use symbol_name::SymbolName;
170166
pub use term::{Term, TermKind};
171167
pub use ty_::Ty;
172168
pub use variant_def::VariantDef;
173169
pub use visibility::Visibility;
174170

175-
pub struct ResolverOutputs {
176-
pub global_ctxt: ResolverGlobalCtxt,
177-
pub ast_lowering: ResolverAstLowering,
178-
}
179-
180-
#[derive(Debug)]
181-
pub struct ResolverGlobalCtxt {
182-
pub visibilities: FxHashMap<LocalDefId, Visibility>,
183-
/// This field is used to decide whether we should make `PRIVATE_IN_PUBLIC` a hard error.
184-
pub has_pub_restricted: bool,
185-
/// Item with a given `LocalDefId` was defined during macro expansion with ID `ExpnId`.
186-
pub expn_that_defined: FxHashMap<LocalDefId, ExpnId>,
187-
pub effective_visibilities: EffectiveVisibilities,
188-
pub extern_crate_map: FxHashMap<LocalDefId, CrateNum>,
189-
pub maybe_unused_trait_imports: FxIndexSet<LocalDefId>,
190-
pub module_children: LocalDefIdMap<Vec<ModChild>>,
191-
pub glob_map: FxHashMap<LocalDefId, FxHashSet<Symbol>>,
192-
pub main_def: Option<MainDefinition>,
193-
pub trait_impls: FxIndexMap<DefId, Vec<LocalDefId>>,
194-
/// A list of proc macro LocalDefIds, written out in the order in which
195-
/// they are declared in the static array generated by proc_macro_harness.
196-
pub proc_macros: Vec<LocalDefId>,
197-
/// Mapping from ident span to path span for paths that don't exist as written, but that
198-
/// exist under `std`. For example, wrote `str::from_utf8` instead of `std::str::from_utf8`.
199-
pub confused_type_with_std_module: FxHashMap<Span, Span>,
200-
pub doc_link_resolutions: FxHashMap<LocalDefId, DocLinkResMap>,
201-
pub doc_link_traits_in_scope: FxHashMap<LocalDefId, Vec<DefId>>,
202-
pub all_macro_rules: FxHashMap<Symbol, Res<ast::NodeId>>,
203-
}
204-
205-
/// Resolutions that should only be used for lowering.
206-
/// This struct is meant to be consumed by lowering.
207-
#[derive(Debug)]
208-
pub struct ResolverAstLowering {
209-
pub legacy_const_generic_args: FxHashMap<DefId, Option<Vec<usize>>>,
210-
211-
/// Resolutions for nodes that have a single resolution.
212-
pub partial_res_map: NodeMap<hir::def::PartialRes>,
213-
/// Resolutions for import nodes, which have multiple resolutions in different namespaces.
214-
pub import_res_map: NodeMap<hir::def::PerNS<Option<Res<ast::NodeId>>>>,
215-
/// Resolutions for labels (node IDs of their corresponding blocks or loops).
216-
pub label_res_map: NodeMap<ast::NodeId>,
217-
/// Resolutions for lifetimes.
218-
pub lifetimes_res_map: NodeMap<LifetimeRes>,
219-
/// Lifetime parameters that lowering will have to introduce.
220-
pub extra_lifetime_params_map: NodeMap<Vec<(Ident, ast::NodeId, LifetimeRes)>>,
221-
222-
pub next_node_id: ast::NodeId,
223-
224-
pub node_id_to_def_id: FxHashMap<ast::NodeId, LocalDefId>,
225-
pub def_id_to_node_id: IndexVec<LocalDefId, ast::NodeId>,
226-
227-
pub trait_map: NodeMap<Vec<hir::TraitCandidate>>,
228-
/// A small map keeping true kinds of built-in macros that appear to be fn-like on
229-
/// the surface (`macro` items in libcore), but are actually attributes or derives.
230-
pub builtin_macro_kinds: FxHashMap<LocalDefId, MacroKind>,
231-
/// List functions and methods for which lifetime elision was successful.
232-
pub lifetime_elision_allowed: FxHashSet<ast::NodeId>,
233-
234-
/// Lints that were emitted by the resolver and early lints.
235-
pub lint_buffer: Steal<LintBuffer>,
236-
}
237-
238171
#[derive(Clone, Copy, Debug)]
239172
pub struct MainDefinition {
240173
pub res: Res<ast::NodeId>,
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
use rustc_ast as ast;
2+
use rustc_ast::node_id::NodeMap;
3+
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
4+
use rustc_data_structures::steal::Steal;
5+
use rustc_hir as hir;
6+
use rustc_hir::def::{DocLinkResMap, LifetimeRes, Res};
7+
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LocalDefIdMap};
8+
use rustc_index::IndexVec;
9+
use rustc_session::lint::LintBuffer;
10+
use rustc_span::hygiene::MacroKind;
11+
use rustc_span::symbol::{Ident, Symbol};
12+
use rustc_span::{ExpnId, Span};
13+
14+
use crate::metadata::ModChild;
15+
use crate::middle::privacy::EffectiveVisibilities;
16+
use crate::ty::{MainDefinition, Visibility};
17+
18+
pub struct ResolverOutputs {
19+
pub global_ctxt: ResolverGlobalCtxt,
20+
pub ast_lowering: ResolverAstLowering,
21+
}
22+
23+
#[derive(Debug)]
24+
pub struct ResolverGlobalCtxt {
25+
pub visibilities: FxHashMap<LocalDefId, Visibility>,
26+
/// This field is used to decide whether we should make `PRIVATE_IN_PUBLIC` a hard error.
27+
pub has_pub_restricted: bool,
28+
/// Item with a given `LocalDefId` was defined during macro expansion with ID `ExpnId`.
29+
pub expn_that_defined: FxHashMap<LocalDefId, ExpnId>,
30+
pub effective_visibilities: EffectiveVisibilities,
31+
pub extern_crate_map: FxHashMap<LocalDefId, CrateNum>,
32+
pub maybe_unused_trait_imports: FxIndexSet<LocalDefId>,
33+
pub module_children: LocalDefIdMap<Vec<ModChild>>,
34+
pub glob_map: FxHashMap<LocalDefId, FxHashSet<Symbol>>,
35+
pub main_def: Option<MainDefinition>,
36+
pub trait_impls: FxIndexMap<DefId, Vec<LocalDefId>>,
37+
/// A list of proc macro LocalDefIds, written out in the order in which
38+
/// they are declared in the static array generated by proc_macro_harness.
39+
pub proc_macros: Vec<LocalDefId>,
40+
/// Mapping from ident span to path span for paths that don't exist as written, but that
41+
/// exist under `std`. For example, wrote `str::from_utf8` instead of `std::str::from_utf8`.
42+
pub confused_type_with_std_module: FxHashMap<Span, Span>,
43+
pub doc_link_resolutions: FxHashMap<LocalDefId, DocLinkResMap>,
44+
pub doc_link_traits_in_scope: FxHashMap<LocalDefId, Vec<DefId>>,
45+
pub all_macro_rules: FxHashMap<Symbol, Res<ast::NodeId>>,
46+
}
47+
48+
/// Resolutions that should only be used for lowering.
49+
/// This struct is meant to be consumed by lowering.
50+
#[derive(Debug)]
51+
pub struct ResolverAstLowering {
52+
pub legacy_const_generic_args: FxHashMap<DefId, Option<Vec<usize>>>,
53+
54+
/// Resolutions for nodes that have a single resolution.
55+
pub partial_res_map: NodeMap<hir::def::PartialRes>,
56+
/// Resolutions for import nodes, which have multiple resolutions in different namespaces.
57+
pub import_res_map: NodeMap<hir::def::PerNS<Option<Res<ast::NodeId>>>>,
58+
/// Resolutions for labels (node IDs of their corresponding blocks or loops).
59+
pub label_res_map: NodeMap<ast::NodeId>,
60+
/// Resolutions for lifetimes.
61+
pub lifetimes_res_map: NodeMap<LifetimeRes>,
62+
/// Lifetime parameters that lowering will have to introduce.
63+
pub extra_lifetime_params_map: NodeMap<Vec<(Ident, ast::NodeId, LifetimeRes)>>,
64+
65+
pub next_node_id: ast::NodeId,
66+
67+
pub node_id_to_def_id: FxHashMap<ast::NodeId, LocalDefId>,
68+
pub def_id_to_node_id: IndexVec<LocalDefId, ast::NodeId>,
69+
70+
pub trait_map: NodeMap<Vec<hir::TraitCandidate>>,
71+
/// A small map keeping true kinds of built-in macros that appear to be fn-like on
72+
/// the surface (`macro` items in libcore), but are actually attributes or derives.
73+
pub builtin_macro_kinds: FxHashMap<LocalDefId, MacroKind>,
74+
/// List functions and methods for which lifetime elision was successful.
75+
pub lifetime_elision_allowed: FxHashSet<ast::NodeId>,
76+
77+
/// Lints that were emitted by the resolver and early lints.
78+
pub lint_buffer: Steal<LintBuffer>,
79+
}

0 commit comments

Comments
 (0)