diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 426fc4e7be228..b4a1e41c95bf0 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -29,7 +29,6 @@ use rustc_data_structures::stable_hash::{StableHash, StableHashCtxt, StableHashe use rustc_data_structures::tagged_ptr::Tag; use rustc_macros::{Decodable, Encodable, StableHash, Walkable}; pub use rustc_span::AttrId; -use rustc_span::def_id::LocalDefId; use rustc_span::{ ByteSymbol, DUMMY_SP, ErrorGuaranteed, Ident, LocalExpnId, Span, Spanned, Symbol, kw, respan, sym, @@ -4445,24 +4444,6 @@ impl TryFrom for ForeignItemKind { } pub type ForeignItem = Item; - -/// Fragment of the AST according to "HIR owner" semantics. -/// -/// This is used to map each `LocalDefId` to its content's AST. -#[derive(Debug)] -pub enum AstOwner { - /// This definition does not correspond to a HIR owner. - NonOwner, - /// This definition corresponds to a nested `use` tree. - /// The `LocalDefId` points to its HIR owner. - NestedUseTree(LocalDefId), - Crate(Box), - Item(Box), - TraitItem(Box), - ImplItem(Box), - ForeignItem(Box), -} - // Some nodes are used a lot. Make sure they don't unintentionally get bigger. #[cfg(target_pointer_width = "64")] mod size_asserts { diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index fc3fa99fa0644..e97c5c52b8823 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -8,9 +8,10 @@ use rustc_hir::{ self as hir, CRATE_OWNER_ID, HirId, ImplItemImplKind, LifetimeSource, PredicateOrigin, Target, find_attr, }; +use rustc_middle::middle::resolve::ResolverAstLowering; use rustc_middle::span_bug; +use rustc_middle::ty::TyCtxt; use rustc_middle::ty::data_structures::IndexMap; -use rustc_middle::ty::{ResolverAstLowering, TyCtxt}; use rustc_span::def_id::{DefId, LocalDefId}; use rustc_span::edit_distance::find_best_match_for_name; use rustc_span::{DUMMY_SP, DesugaringKind, Ident, Span, Symbol, kw, sym}; diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 5b76606d101bc..87d118e245001 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -55,7 +55,7 @@ use rustc_data_structures::unord::ExtendUnord; use rustc_errors::codes::*; use rustc_errors::{DiagArgFromDisplay, DiagCtxtHandle, ErrorGuaranteed}; use rustc_hir::attrs::lang_items::LangItem; -use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res}; +use rustc_hir::def::{DefKind, Namespace, PerNS, Res}; use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId, LocalDefIdMap}; use rustc_hir::definitions::PerParentDisambiguatorState; use rustc_hir::lints::DelayedLint; @@ -65,9 +65,12 @@ use rustc_hir::{ }; use rustc_index::{Idx, IndexVec}; use rustc_macros::extension; +use rustc_middle::middle::resolve::{ + AstOwner, LifetimeRes, PartialRes, PerOwnerResolverData, ResolverAstLowering, +}; use rustc_middle::queries::Providers; use rustc_middle::span_bug; -use rustc_middle::ty::{PerOwnerResolverData, ResolverAstLowering, TyCtxt}; +use rustc_middle::ty::TyCtxt; use rustc_session::diagnostics::add_feature_diagnostics; use rustc_span::symbol::{Ident, Symbol, kw, sym}; use rustc_span::{DUMMY_SP, DesugaringKind, Span}; diff --git a/compiler/rustc_ast_lowering/src/path.rs b/compiler/rustc_ast_lowering/src/path.rs index 261fcd18d96ba..387aa7566b42a 100644 --- a/compiler/rustc_ast_lowering/src/path.rs +++ b/compiler/rustc_ast_lowering/src/path.rs @@ -2,9 +2,10 @@ use std::sync::Arc; use rustc_ast::{self as ast, *}; use rustc_errors::StashKey; -use rustc_hir::def::{DefKind, PartialRes, PerNS, Res}; +use rustc_hir::def::{DefKind, PerNS, Res}; use rustc_hir::def_id::DefId; use rustc_hir::{self as hir, GenericArg}; +use rustc_middle::middle::resolve::PartialRes; use rustc_middle::{span_bug, ty}; use rustc_session::diagnostics::add_feature_diagnostics; use rustc_span::{BytePos, DUMMY_SP, DesugaringKind, Ident, Span, Symbol, sym}; diff --git a/compiler/rustc_hir/src/def.rs b/compiler/rustc_hir/src/def.rs index 010ecb1cd3d98..f1047e6c0bab4 100644 --- a/compiler/rustc_hir/src/def.rs +++ b/compiler/rustc_hir/src/def.rs @@ -4,12 +4,11 @@ use std::fmt::Debug; use rustc_ast as ast; use rustc_ast::NodeId; -use rustc_data_structures::fx::FxIndexMap; use rustc_error_messages::{DiagArgValue, IntoDiagArg}; use rustc_hir_id::HirId; use rustc_macros::{Decodable, Encodable, StableHash}; use rustc_span::Symbol; -use rustc_span::def_id::{DefId, LocalDefId}; +use rustc_span::def_id::DefId; use rustc_span::hygiene::MacroKind; use crate as hir; @@ -587,63 +586,6 @@ impl IntoDiagArg for Res { } } -/// The result of resolving a path before lowering to HIR, -/// with "module" segments resolved and associated item -/// segments deferred to type checking. -/// `base_res` is the resolution of the resolved part of the -/// path, `unresolved_segments` is the number of unresolved -/// segments. -/// -/// ```text -/// module::Type::AssocX::AssocY::MethodOrAssocType -/// ^~~~~~~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// base_res unresolved_segments = 3 -/// -/// ::AssocX::AssocY::MethodOrAssocType -/// ^~~~~~~~~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~~ -/// base_res unresolved_segments = 2 -/// ``` -#[derive(Copy, Clone, Debug)] -pub struct PartialRes { - base_res: Res, - unresolved_segments: usize, -} - -impl PartialRes { - #[inline] - pub fn new(base_res: Res) -> Self { - PartialRes { base_res, unresolved_segments: 0 } - } - - #[inline] - pub fn with_unresolved_segments(base_res: Res, mut unresolved_segments: usize) -> Self { - if base_res == Res::Err { - unresolved_segments = 0 - } - PartialRes { base_res, unresolved_segments } - } - - #[inline] - pub fn base_res(&self) -> Res { - self.base_res - } - - #[inline] - pub fn unresolved_segments(&self) -> usize { - self.unresolved_segments - } - - #[inline] - pub fn full_res(&self) -> Option> { - (self.unresolved_segments == 0).then_some(self.base_res) - } - - #[inline] - pub fn expect_full_res(&self) -> Res { - self.full_res().expect("unexpected unresolved segments") - } -} - /// Different kinds of symbols can coexist even if they share the same textual name. /// Therefore, they each have a separate universe (known as a "namespace"). #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Encodable, Decodable)] @@ -933,43 +875,3 @@ impl Res { matches!(self, Res::Def(DefKind::Ctor(_, CtorKind::Const), _) | Res::SelfCtor(..)) } } - -/// Resolution for a lifetime appearing in a type. -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] -pub enum LifetimeRes { - /// Successfully linked the lifetime to a generic parameter. - Param { - /// Id of the generic parameter that introduced it. - param: LocalDefId, - /// Id of the introducing place. That can be: - /// - an item's id, for the item's generic parameters; - /// - a TraitRef's ref_id, identifying the `for<...>` binder; - /// - a FnPtr type's id. - /// - /// This information is used for impl-trait lifetime captures, to know when to or not to - /// capture any given lifetime. - binder: NodeId, - }, - /// Created a generic parameter for an anonymous lifetime. - Fresh { - /// Id of the generic parameter that introduced it. - /// - /// Creating the associated `LocalDefId` is the responsibility of lowering. - param: NodeId, - /// Kind of elided lifetime - kind: hir::MissingLifetimeKind, - }, - /// This variant is used for anonymous lifetimes that we did not resolve during - /// late resolution. Those lifetimes will be inferred by typechecking. - Infer, - /// `'static` lifetime. - Static, - /// Resolution failure. - Error(rustc_span::ErrorGuaranteed), - /// HACK: This is used to recover the NodeId of an elided lifetime. - ElidedAnchor { start: NodeId, end: NodeId }, -} - -// FxIndexMap is necessary because its data ends up in .rmeta files, -// so its iteration order must be consistent. See #159677 for context. -pub type DocLinkResMap = FxIndexMap<(Symbol, Namespace), Option>>; diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index c829864b02288..ebdb82e2b4fe6 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -30,6 +30,7 @@ use rustc_lint::{BufferedEarlyLint, EarlyCheckNode, LintStore, unerased_lint_sto use rustc_metadata::EncodedMetadata; use rustc_metadata::creader::CStore; use rustc_middle::arena::Arena; +use rustc_middle::middle::resolve::{ResolverAstLowering, ResolverGlobalCtxt}; use rustc_middle::ty::{self, RegisteredTools, TyCtxt}; use rustc_middle::util::Providers; use rustc_parse::lexer::StripTokens; @@ -792,11 +793,7 @@ fn write_out_deps(tcx: TyCtxt<'_>, outputs: &OutputFilenames, out_filenames: &[P fn resolver_for_lowering_raw<'tcx>( tcx: TyCtxt<'tcx>, (): (), -) -> ( - &'tcx Steal>, - &'tcx Steal, - &'tcx ty::ResolverGlobalCtxt, -) { +) -> (&'tcx Steal>, &'tcx Steal, &'tcx ResolverGlobalCtxt) { let arenas = WorkerLocal::new(|_| Resolver::arenas()); let _ = tcx.registered_attr_tools(()); // Uses `crate_for_resolver`. let _ = tcx.registered_lint_tools(()); // Uses `crate_for_resolver`. diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index 8fe1d6561d135..08053bb2c6a60 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -10,8 +10,8 @@ use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LOCAL_CRATE}; use rustc_hir::definitions::{DefKey, DefPath, DefPathHash}; use rustc_middle::arena::ArenaAllocatable; use rustc_middle::bug; -use rustc_middle::metadata::{AmbigModChild, ModChild}; use rustc_middle::middle::exported_symbols::ExportedSymbol; +use rustc_middle::middle::resolve::{AmbigModChild, ModChild}; use rustc_middle::middle::stability::DeprecationEntry; use rustc_middle::queries::ExternProviders; use rustc_middle::query::LocalCrate; diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index 064d906293ae8..0d6122d6748cb 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -15,7 +15,7 @@ use rustc_data_structures::svh::Svh; use rustc_hir as hir; use rustc_hir::attrs::StrippedCfgItem; use rustc_hir::attrs::lang_items::LangItem; -use rustc_hir::def::{CtorKind, DefKind, DocLinkResMap, MacroKinds}; +use rustc_hir::def::{CtorKind, DefKind, MacroKinds}; use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, DefIndex, DefPathHash, StableCrateId}; use rustc_hir::definitions::DefKey; use rustc_hir::{PreciseCapturingArgKind, attrs}; @@ -24,12 +24,12 @@ use rustc_index::bit_set::DenseBitSet; use rustc_macros::{ BlobDecodable, Decodable, Encodable, LazyDecodable, MetadataEncodable, TyDecodable, TyEncodable, }; -use rustc_middle::metadata::{AmbigModChild, ModChild}; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs; use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerFile; use rustc_middle::middle::deduced_param_attrs::DeducedParamAttrs; use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo}; use rustc_middle::middle::lib_features::FeatureStability; +use rustc_middle::middle::resolve::{AmbigModChild, DocLinkResMap, ModChild}; use rustc_middle::middle::resolve_bound_vars::ObjectLifetimeDefault; use rustc_middle::mir; use rustc_middle::mir::ConstValue; diff --git a/compiler/rustc_metadata/src/rmeta/parameterized.rs b/compiler/rustc_metadata/src/rmeta/parameterized.rs index f19737bb936be..4eb922446b71b 100644 --- a/compiler/rustc_metadata/src/rmeta/parameterized.rs +++ b/compiler/rustc_metadata/src/rmeta/parameterized.rs @@ -104,18 +104,18 @@ trivially_parameterized_over_tcx! { rustc_hir::attrs::StrippedCfgItem, rustc_hir::attrs::lang_items::LangItem, rustc_hir::def::DefKind, - rustc_hir::def::DocLinkResMap, rustc_hir::def_id::DefId, rustc_hir::def_id::DefIndex, rustc_hir::definitions::DefKey, rustc_index::bit_set::DenseBitSet, - rustc_middle::metadata::AmbigModChild, - rustc_middle::metadata::ModChild, rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs, rustc_middle::middle::debugger_visualizer::DebuggerVisualizerFile, rustc_middle::middle::deduced_param_attrs::DeducedParamAttrs, rustc_middle::middle::exported_symbols::SymbolExportInfo, rustc_middle::middle::lib_features::FeatureStability, + rustc_middle::middle::resolve::AmbigModChild, + rustc_middle::middle::resolve::DocLinkResMap, + rustc_middle::middle::resolve::ModChild, rustc_middle::middle::resolve_bound_vars::ObjectLifetimeDefault, rustc_middle::mir::ConstQualifs, rustc_middle::mir::ConstValue, diff --git a/compiler/rustc_middle/src/arena.rs b/compiler/rustc_middle/src/arena.rs index 5995c048d8b92..3c973d7d3a5a2 100644 --- a/compiler/rustc_middle/src/arena.rs +++ b/compiler/rustc_middle/src/arena.rs @@ -36,18 +36,21 @@ rustc_arena::declare_arena! { rustc_hir::def_id::LocalDefId, rustc_middle::ty::DefinitionSiteHiddenType<'tcx>, >, - resolver: rustc_data_structures::steal::Steal>, + resolver: + rustc_data_structures::steal::Steal< + rustc_middle::middle::resolve::ResolverAstLowering<'tcx> + >, index_ast: rustc_index::IndexVec< rustc_span::def_id::LocalDefId, rustc_data_structures::steal::Steal<( - std::sync::Arc>, - rustc_ast::AstOwner + std::sync::Arc>, + rustc_middle::middle::resolve::AstOwner )> >, crate_alone: rustc_data_structures::steal::Steal, crate_for_resolver: rustc_data_structures::steal::Steal<(rustc_ast::Crate, rustc_ast::AttrVec)>, - resolutions: rustc_middle::ty::ResolverGlobalCtxt, + resolutions: rustc_middle::middle::resolve::ResolverGlobalCtxt, const_allocs: rustc_middle::mir::interpret::Allocation, region_scope_tree: rustc_middle::middle::region::ScopeTree, // Required for the incremental on-disk cache @@ -128,9 +131,9 @@ rustc_arena::declare_arena! { rustc_middle::ty::EarlyBinder<'tcx, Ty<'tcx>> >, external_constraints: rustc_middle::traits::solve::ExternalConstraintsData>, - doc_link_resolutions: rustc_hir::def::DocLinkResMap, + doc_link_resolutions: rustc_middle::middle::resolve::DocLinkResMap, stripped_cfg_items: rustc_hir::attrs::StrippedCfgItem, - mod_child: rustc_middle::metadata::ModChild, + mod_child: rustc_middle::middle::resolve::ModChild, features: rustc_feature::Features, specialization_graph: rustc_middle::traits::specialization_graph::Graph, crate_inherent_impls: rustc_middle::ty::CrateInherentImpls, diff --git a/compiler/rustc_middle/src/lib.rs b/compiler/rustc_middle/src/lib.rs index 993cb6e7769dd..48d90f9c704fc 100644 --- a/compiler/rustc_middle/src/lib.rs +++ b/compiler/rustc_middle/src/lib.rs @@ -77,7 +77,6 @@ pub mod hooks; pub mod ich; pub mod infer; pub mod lint; -pub mod metadata; pub mod middle; pub mod mir; pub mod mono; diff --git a/compiler/rustc_middle/src/metadata.rs b/compiler/rustc_middle/src/metadata.rs deleted file mode 100644 index 0c9b44a93a20e..0000000000000 --- a/compiler/rustc_middle/src/metadata.rs +++ /dev/null @@ -1,53 +0,0 @@ -use rustc_hir::def::Res; -use rustc_macros::{StableHash, TyDecodable, TyEncodable}; -use rustc_span::Ident; -use rustc_span::def_id::{DefId, ModId}; -use smallvec::SmallVec; - -use crate::ty; - -/// A simplified version of `ImportKind` from resolve. -/// `DefId`s here correspond to `use` and `extern crate` items themselves, not their targets. -#[derive(Clone, Copy, Debug, TyEncodable, TyDecodable, StableHash)] -pub enum Reexport { - Single(DefId), - Glob(DefId), - ExternCrate(DefId), - MacroUse, - MacroExport, -} - -impl Reexport { - pub fn id(self) -> Option { - match self { - Reexport::Single(id) | Reexport::Glob(id) | Reexport::ExternCrate(id) => Some(id), - Reexport::MacroUse | Reexport::MacroExport => None, - } - } -} - -/// This structure is supposed to keep enough data to re-create `Decl`s for other crates -/// during name resolution. Right now the bindings are not recreated entirely precisely so we may -/// need to add more data in the future to correctly support macros 2.0, for example. -/// Module child can be either a proper item or a reexport (including private imports). -/// In case of reexport all the fields describe the reexport item itself, not what it refers to. -#[derive(Debug, TyEncodable, TyDecodable, StableHash)] -pub struct ModChild { - /// Name of the item. - pub ident: Ident, - /// Resolution result corresponding to the item. - /// Local variables cannot be exported, so this `Res` doesn't need the ID parameter. - pub res: Res, - /// Visibility of the item. - pub vis: ty::Visibility, - /// Reexport chain linking this module child to its original reexported item. - /// Empty if the module child is a proper item. - pub reexport_chain: SmallVec<[Reexport; 2]>, -} - -/// Same as `ModChild`, however, it includes ambiguity error. -#[derive(Debug, TyEncodable, TyDecodable, StableHash)] -pub struct AmbigModChild { - pub main: ModChild, - pub second: ModChild, -} diff --git a/compiler/rustc_middle/src/middle/mod.rs b/compiler/rustc_middle/src/middle/mod.rs index 7967a6222c3be..924dcceb9cef8 100644 --- a/compiler/rustc_middle/src/middle/mod.rs +++ b/compiler/rustc_middle/src/middle/mod.rs @@ -34,5 +34,6 @@ pub mod lib_features { } pub mod privacy; pub mod region; +pub mod resolve; pub mod resolve_bound_vars; pub mod stability; diff --git a/compiler/rustc_middle/src/middle/resolve.rs b/compiler/rustc_middle/src/middle/resolve.rs new file mode 100644 index 0000000000000..2958048103320 --- /dev/null +++ b/compiler/rustc_middle/src/middle/resolve.rs @@ -0,0 +1,309 @@ +//! This module contains types that carry name resolution results from `rustc_resolve` to a +//! consumer in another crate (e.g. AST lowering, metadata, or a query). + +use rustc_ast::node_id::NodeMap; +use rustc_ast::{self as ast, NodeId}; +use rustc_attr_ir::StrippedCfgItem; +use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; +use rustc_data_structures::steal::Steal; +use rustc_data_structures::unord::{UnordMap, UnordSet}; +use rustc_errors::{ErrorGuaranteed, LintBuffer}; +use rustc_hir::def::{DefKind, Namespace, PerNS, Res}; +use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LocalDefIdMap, LocalModId, ModId}; +use rustc_hir::definitions::PerParentDisambiguatorState; +use rustc_hir::{MissingLifetimeKind, TraitCandidate}; +use rustc_macros::{StableHash, TyDecodable, TyEncodable}; +use rustc_span::{ExpnId, Ident, Span, Symbol}; +use smallvec::SmallVec; + +use crate::middle::privacy::EffectiveVisibilities; +use crate::ty::Visibility; + +/// The result of resolving a path before lowering to HIR, +/// with "module" segments resolved and associated item +/// segments deferred to type checking. +/// `base_res` is the resolution of the resolved part of the +/// path, `unresolved_segments` is the number of unresolved +/// segments. +/// +/// ```text +/// module::Type::AssocX::AssocY::MethodOrAssocType +/// ^~~~~~~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// base_res unresolved_segments = 3 +/// +/// ::AssocX::AssocY::MethodOrAssocType +/// ^~~~~~~~~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~~ +/// base_res unresolved_segments = 2 +/// ``` +#[derive(Copy, Clone, Debug)] +pub struct PartialRes { + base_res: Res, + unresolved_segments: usize, +} + +impl PartialRes { + #[inline] + pub fn new(base_res: Res) -> Self { + PartialRes { base_res, unresolved_segments: 0 } + } + + #[inline] + pub fn with_unresolved_segments(base_res: Res, mut unresolved_segments: usize) -> Self { + if base_res == Res::Err { + unresolved_segments = 0 + } + PartialRes { base_res, unresolved_segments } + } + + #[inline] + pub fn base_res(&self) -> Res { + self.base_res + } + + #[inline] + pub fn unresolved_segments(&self) -> usize { + self.unresolved_segments + } + + #[inline] + pub fn full_res(&self) -> Option> { + (self.unresolved_segments == 0).then_some(self.base_res) + } + + #[inline] + pub fn expect_full_res(&self) -> Res { + self.full_res().expect("unexpected unresolved segments") + } +} + +/// Resolution for a lifetime appearing in a type. +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] +pub enum LifetimeRes { + /// Successfully linked the lifetime to a generic parameter. + Param { + /// Id of the generic parameter that introduced it. + param: LocalDefId, + /// Id of the introducing place. That can be: + /// - an item's id, for the item's generic parameters; + /// - a TraitRef's ref_id, identifying the `for<...>` binder; + /// - a FnPtr type's id. + /// + /// This information is used for impl-trait lifetime captures, to know when to or not to + /// capture any given lifetime. + binder: NodeId, + }, + /// Created a generic parameter for an anonymous lifetime. + Fresh { + /// Id of the generic parameter that introduced it. + /// + /// Creating the associated `LocalDefId` is the responsibility of lowering. + param: NodeId, + /// Kind of elided lifetime + kind: MissingLifetimeKind, + }, + /// This variant is used for anonymous lifetimes that we did not resolve during + /// late resolution. Those lifetimes will be inferred by typechecking. + Infer, + /// `'static` lifetime. + Static, + /// Resolution failure. + Error(ErrorGuaranteed), + /// HACK: This is used to recover the NodeId of an elided lifetime. + ElidedAnchor { start: NodeId, end: NodeId }, +} + +/// A simplified version of `ImportKind` from resolve. +/// `DefId`s here correspond to `use` and `extern crate` items themselves, not their targets. +#[derive(Clone, Copy, Debug, TyEncodable, TyDecodable, StableHash)] +pub enum Reexport { + Single(DefId), + Glob(DefId), + ExternCrate(DefId), + MacroUse, + MacroExport, +} + +impl Reexport { + pub fn id(self) -> Option { + match self { + Reexport::Single(id) | Reexport::Glob(id) | Reexport::ExternCrate(id) => Some(id), + Reexport::MacroUse | Reexport::MacroExport => None, + } + } +} + +/// This structure is supposed to keep enough data to re-create `Decl`s for other crates +/// during name resolution. Right now the bindings are not recreated entirely precisely so we may +/// need to add more data in the future to correctly support macros 2.0, for example. +/// Module child can be either a proper item or a reexport (including private imports). +/// In case of reexport all the fields describe the reexport item itself, not what it refers to. +#[derive(Debug, TyEncodable, TyDecodable, StableHash)] +pub struct ModChild { + /// Name of the item. + pub ident: Ident, + /// Resolution result corresponding to the item. + /// Local variables cannot be exported, so this `Res` doesn't need the ID parameter. + pub res: Res, + /// Visibility of the item. + pub vis: Visibility, + /// Reexport chain linking this module child to its original reexported item. + /// Empty if the module child is a proper item. + pub reexport_chain: SmallVec<[Reexport; 2]>, +} + +/// Same as `ModChild`, however, it includes ambiguity error. +#[derive(Debug, TyEncodable, TyDecodable, StableHash)] +pub struct AmbigModChild { + pub main: ModChild, + pub second: ModChild, +} + +#[derive(Debug, StableHash)] +pub struct ResolverGlobalCtxt { + pub visibilities_for_hashing: Vec<(LocalDefId, Visibility)>, + /// Item with a given `LocalDefId` was defined during macro expansion with ID `ExpnId`. + pub expn_that_defined: UnordMap, + pub effective_visibilities: EffectiveVisibilities, + // FIXME: This table contains ADTs reachable from macro 2.0. + // Currently, reachability of a definition from a macro is determined by nominal visibility + // (see `compute_effective_visibilities`). This is incorrect and leads to the necessity + // of traversing ADT fields in `rustc_privacy`. Remove this workaround once the + // correct reachability logic is implemented for macros. + pub macro_reachable_adts: FxIndexMap>, + pub extern_crate_map: UnordMap, + pub maybe_unused_trait_imports: FxIndexSet, + pub module_children: LocalDefIdMap>, + pub ambig_module_children: LocalDefIdMap>, + pub glob_map: FxIndexMap>, + pub main_def: Option, + pub trait_impls: FxIndexMap>, + /// A list of proc macro LocalDefIds, written out in the order in which + /// they are declared in the static array generated by proc_macro_harness. + pub proc_macros: Vec, + /// Mapping from ident span to path span for paths that don't exist as written, but that + /// exist under `std`. For example, wrote `str::from_utf8` instead of `std::str::from_utf8`. + pub confused_type_with_std_module: FxIndexMap, + pub doc_link_resolutions: FxIndexMap, + pub doc_link_traits_in_scope: FxIndexMap>, + pub all_macro_rules: UnordSet, + pub stripped_cfg_items: Vec, + // Information about delegations which is used when handling recursive delegations + // and ensures easy access to delegation-only `LocalDefId`s. + pub delegation_infos: FxIndexMap, +} + +#[derive(Debug)] +pub struct PerOwnerResolverData<'tcx> { + pub node_id_to_def_id: NodeMap = Default::default(), + /// Whether lifetime elision was successful. + pub lifetime_elision_allowed: bool = false, + /// Resolutions for labels. Maps from NodeId of the break/continue expression to the NodeId of + /// their corresponding blocks or loops. + pub label_res_map: NodeMap = Default::default(), + /// Resolutions for lifetimes. + pub lifetimes_res_map: NodeMap = Default::default(), + + pub trait_map: NodeMap<&'tcx [TraitCandidate<'tcx>]> = Default::default(), + + /// Resolution for import nodes, which have multiple resolutions in different namespaces. + pub import_res: PerNS>> = Default::default(), + /// Lifetime parameters that lowering will have to introduce. + pub extra_lifetime_params_map: NodeMap> = + Default::default(), + + /// The id of the owner + pub id: NodeId, + /// The `DefId` of the owner, can't be found in `node_id_to_def_id`. + pub def_id: LocalDefId, +} + +impl<'tcx> PerOwnerResolverData<'tcx> { + pub fn new(id: NodeId, def_id: LocalDefId) -> PerOwnerResolverData<'tcx> { + PerOwnerResolverData { id, def_id, .. } + } + + /// Obtains resolution for a label with the given `NodeId`. + pub fn get_label_res(&self, id: NodeId) -> Option { + self.label_res_map.get(&id).copied() + } + + /// Obtains resolution for a lifetime with the given `NodeId`. + pub fn get_lifetime_res(&self, id: NodeId) -> Option { + self.lifetimes_res_map.get(&id).copied() + } + + /// Obtain the list of lifetimes parameters to add to an item. + /// + /// Extra lifetime parameters should only be added in places that can appear + /// as a `binder` in `LifetimeRes`. + /// + /// The extra lifetimes that appear from the parenthesized `Fn`-trait desugaring + /// should appear at the enclosing `PolyTraitRef`. + pub fn extra_lifetime_params(&self, id: NodeId) -> &[(Ident, NodeId, MissingLifetimeKind)] { + self.extra_lifetime_params_map.get(&id).map_or(&[], |v| &v[..]) + } +} + +/// Resolutions that should only be used for lowering. +/// This struct is meant to be consumed by lowering. +#[derive(Debug)] +pub struct ResolverAstLowering<'tcx> { + /// Resolutions for nodes that have a single resolution. + pub partial_res_map: NodeMap, + + pub next_node_id: NodeId, + + pub owners: NodeMap>, + + /// Lints that were emitted by the resolver and early lints. + pub lint_buffer: Steal, + + pub disambiguators: LocalDefIdMap>, +} + +#[derive(Debug, StableHash)] +pub struct DelegationInfo { + // `DefId` (either the resolution at delegation.id or item_id in case of a trait impl) for + // signature resolution, for details see + // https://github.com/rust-lang/rust/issues/118212#issuecomment-2160686914. + /// Refers to the next element in a delegation resolution chain. Usually points to the final + /// resolution, as most "chains" are just one step to a trait or an impl. + pub resolution_id: Result, +} + +#[derive(Clone, Copy, Debug, StableHash)] +pub struct MainDefinition { + pub res: Res, + pub is_import: bool, + pub span: Span, +} + +impl MainDefinition { + pub fn opt_fn_def_id(self) -> Option { + if let Res::Def(DefKind::Fn, def_id) = self.res { Some(def_id) } else { None } + } +} + +// FxIndexMap is necessary because its data ends up in .rmeta files, +// so its iteration order must be consistent. See #159677 for context. +pub type DocLinkResMap = FxIndexMap<(Symbol, Namespace), Option>>; + +/// Fragment of the AST according to "HIR owner" semantics. +/// +/// This is used to map each `LocalDefId` to its content's AST. +/// +/// This type isn't produced by name resolution but it is paired with `ResolverAstLowering` so this +/// is as good a place as any for it. +#[derive(Debug)] +pub enum AstOwner { + /// This definition does not correspond to a HIR owner. + NonOwner, + /// This definition corresponds to a nested `use` tree. + /// The `LocalDefId` points to its HIR owner. + NestedUseTree(LocalDefId), + Crate(Box), + Item(Box), + TraitItem(Box), + ImplItem(Box), + ForeignItem(Box), +} diff --git a/compiler/rustc_middle/src/middle/resolve_bound_vars.rs b/compiler/rustc_middle/src/middle/resolve_bound_vars.rs index a977fe1ddc07c..beb88e981480d 100644 --- a/compiler/rustc_middle/src/middle/resolve_bound_vars.rs +++ b/compiler/rustc_middle/src/middle/resolve_bound_vars.rs @@ -1,4 +1,5 @@ -//! Name resolution for lifetimes and late-bound type and const variables: type declarations. +//! Name resolution for lifetimes and late-bound type and const variables (done by +//! `rustc_hir_analysis`): type declarations. use rustc_data_structures::sorted_map::SortedMap; use rustc_errors::ErrorGuaranteed; diff --git a/compiler/rustc_middle/src/queries.rs b/compiler/rustc_middle/src/queries.rs index 5794a6533bd1d..47cf0473763b4 100644 --- a/compiler/rustc_middle/src/queries.rs +++ b/compiler/rustc_middle/src/queries.rs @@ -65,7 +65,7 @@ use rustc_data_structures::svh::Svh; use rustc_data_structures::unord::{UnordMap, UnordSet}; use rustc_errors::{ErrorGuaranteed, catch_fatal_errors}; use rustc_hir as hir; -use rustc_hir::def::{DefKind, DocLinkResMap}; +use rustc_hir::def::DefKind; use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LocalDefIdSet, LocalModId}; use rustc_hir::{ItemLocalId, PreciseCapturingArgKind}; use rustc_index::IndexVec; @@ -79,7 +79,6 @@ use rustc_target::spec::PanicStrategy; use crate::infer::canonical::{self, Canonical}; use crate::lint::LintExpectation; -use crate::metadata::ModChild; use crate::middle::codegen_fn_attrs::{CodegenFnAttrs, SanitizerFnAttrs}; use crate::middle::dead_code::DeadCodeLivenessSummary; use crate::middle::debugger_visualizer::DebuggerVisualizerFile; @@ -87,6 +86,9 @@ use crate::middle::deduced_param_attrs::DeducedParamAttrs; use crate::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo}; use crate::middle::lib_features::LibFeatures; use crate::middle::privacy::EffectiveVisibilities; +use crate::middle::resolve::{ + AstOwner, DocLinkResMap, ModChild, ResolverAstLowering, ResolverGlobalCtxt, +}; use crate::middle::resolve_bound_vars::{ObjectLifetimeDefault, ResolveBoundVars, ResolvedArg}; use crate::middle::stability::DeprecationEntry; use crate::mir::interpret::{ @@ -186,16 +188,16 @@ rustc_queries! { desc { "get the value of an environment variable" } } - query resolutions(_: ()) -> &'tcx ty::ResolverGlobalCtxt { + query resolutions(_: ()) -> &'tcx ResolverGlobalCtxt { desc { "getting the resolver outputs" } } query resolver_for_lowering_raw(_: ()) -> ( // Those two fields are consumed by `index_ast`. // We want them to be eventually dropped after lowering. - &'tcx Steal>, + &'tcx Steal>, &'tcx Steal, - &'tcx ty::ResolverGlobalCtxt, + &'tcx ResolverGlobalCtxt, ) { eval_always no_hash @@ -206,8 +208,8 @@ rustc_queries! { // There is only a single `ResolverAstLowering` for all owners. // We want to drop it once the whole HIR has been lowered. // We rely on reference counting to know when all definitions have been stolen. - Arc>, - ast::AstOwner, + Arc>, + AstOwner, )>> { arena_cache eval_always diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 5b5656c05f10d..b2e7e619a83ee 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -55,8 +55,8 @@ use crate::hir::{ProjectedMaybeOwner, ProjectedOwnerInfo}; use crate::ich::StableHashState; use crate::infer::canonical::{CanonicalParamEnvCache, CanonicalVarKind}; use crate::lint::emit_lint_base; -use crate::metadata::ModChild; use crate::middle::codegen_fn_attrs::{CodegenFnAttrs, TargetFeature}; +use crate::middle::resolve::{ModChild, ResolverAstLowering}; use crate::middle::resolve_bound_vars; use crate::mir::interpret::{self, Allocation, ConstAllocation}; use crate::mir::{Body, Local, Place, PlaceElem, ProjectionKind, Promoted}; @@ -2878,7 +2878,7 @@ impl<'tcx> TyCtxt<'tcx> { pub fn resolver_for_lowering( self, - ) -> (&'tcx Steal>, &'tcx Steal) { + ) -> (&'tcx Steal>, &'tcx Steal) { let (resolver, krate, _) = self.resolver_for_lowering_raw(()); (resolver, krate) } diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 3db521dfb5dee..88785d9d7f140 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -28,21 +28,17 @@ pub use intrinsic::IntrinsicDef; use rustc_abi::{ Align, FieldIdx, Integer, IntegerType, ReprFlags, ReprOptions, ScalableElt, VariantIdx, }; -use rustc_ast::node_id::NodeMap; -use rustc_ast::{self as ast, NodeId}; +use rustc_ast::{self as ast}; pub use rustc_ast_ir::{Movability, Mutability, try_visit}; use rustc_attr_ir::lang_items::LangItem; -use rustc_attr_ir::{self as attr, StrippedCfgItem, find_attr}; -use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet}; +use rustc_attr_ir::{self as attr, find_attr}; +use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; use rustc_data_structures::intern::Interned; use rustc_data_structures::stable_hash::{StableHash, StableHashCtxt, StableHasher}; -use rustc_data_structures::steal::Steal; -use rustc_data_structures::unord::{UnordMap, UnordSet}; -use rustc_errors::{Diag, ErrorGuaranteed, LintBuffer}; +use rustc_errors::{Diag, ErrorGuaranteed}; use rustc_hir as hir; -use rustc_hir::def::{CtorKind, CtorOf, DefKind, DocLinkResMap, LifetimeRes, Res}; -use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LocalDefIdMap}; -use rustc_hir::definitions::PerParentDisambiguatorState; +use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res}; +use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId}; use rustc_index::bit_set::BitMatrix; use rustc_index::{IndexVec, static_assert_size}; pub use rustc_lint_defs::RegisteredTools; @@ -54,7 +50,7 @@ use rustc_serialize::{Decodable, Encodable}; use rustc_session::config::OptLevel; use rustc_span::def_id::{LocalModId, ModId}; use rustc_span::hygiene::MacroKind; -use rustc_span::{DUMMY_SP, ExpnId, ExpnKind, Ident, Span, Symbol}; +use rustc_span::{DUMMY_SP, ExpnKind, Ident, Span, Symbol}; use rustc_target::callconv::FnAbi; pub use rustc_type_ir::data_structures::{DelayedMap, DelayedSet}; pub use rustc_type_ir::fast_reject::DeepRejectCtxt; @@ -114,8 +110,6 @@ pub use self::typeck_results::{ UserTypeKind, }; use crate::diagnostics::{OpaqueHiddenTypeMismatch, TypeMismatchReason}; -use crate::metadata::{AmbigModChild, ModChild}; -use crate::middle::privacy::EffectiveVisibilities; use crate::mir::{Body, CoroutineLayout, CoroutineSavedLocal, MirPhase, SourceInfo}; use crate::query::{IntoQueryKey, Providers}; use crate::ty; @@ -171,135 +165,6 @@ mod visit; // Data types -#[derive(Debug, StableHash)] -pub struct ResolverGlobalCtxt { - pub visibilities_for_hashing: Vec<(LocalDefId, Visibility)>, - /// Item with a given `LocalDefId` was defined during macro expansion with ID `ExpnId`. - pub expn_that_defined: UnordMap, - pub effective_visibilities: EffectiveVisibilities, - // FIXME: This table contains ADTs reachable from macro 2.0. - // Currently, reachability of a definition from a macro is determined by nominal visibility - // (see `compute_effective_visibilities`). This is incorrect and leads to the necessity - // of traversing ADT fields in `rustc_privacy`. Remove this workaround once the - // correct reachability logic is implemented for macros. - pub macro_reachable_adts: FxIndexMap>, - pub extern_crate_map: UnordMap, - pub maybe_unused_trait_imports: FxIndexSet, - pub module_children: LocalDefIdMap>, - pub ambig_module_children: LocalDefIdMap>, - pub glob_map: FxIndexMap>, - pub main_def: Option, - pub trait_impls: FxIndexMap>, - /// A list of proc macro LocalDefIds, written out in the order in which - /// they are declared in the static array generated by proc_macro_harness. - pub proc_macros: Vec, - /// Mapping from ident span to path span for paths that don't exist as written, but that - /// exist under `std`. For example, wrote `str::from_utf8` instead of `std::str::from_utf8`. - pub confused_type_with_std_module: FxIndexMap, - pub doc_link_resolutions: FxIndexMap, - pub doc_link_traits_in_scope: FxIndexMap>, - pub all_macro_rules: UnordSet, - pub stripped_cfg_items: Vec, - // Information about delegations which is used when handling recursive delegations - // and ensures easy access to delegation-only `LocalDefId`s. - pub delegation_infos: FxIndexMap, -} - -#[derive(Debug)] -pub struct PerOwnerResolverData<'tcx> { - pub node_id_to_def_id: NodeMap = Default::default(), - /// Whether lifetime elision was successful. - pub lifetime_elision_allowed: bool = false, - /// Resolutions for labels. Maps from NodeId of the break/continue expression to the NodeId of - /// their corresponding blocks or loops. - pub label_res_map: NodeMap = Default::default(), - /// Resolutions for lifetimes. - pub lifetimes_res_map: NodeMap = Default::default(), - - pub trait_map: NodeMap<&'tcx [hir::TraitCandidate<'tcx>]> = Default::default(), - - /// Resolution for import nodes, which have multiple resolutions in different namespaces. - pub import_res: hir::def::PerNS>> = Default::default(), - /// Lifetime parameters that lowering will have to introduce. - pub extra_lifetime_params_map: NodeMap> = - Default::default(), - - /// The id of the owner - pub id: ast::NodeId, - /// The `DefId` of the owner, can't be found in `node_id_to_def_id`. - pub def_id: LocalDefId, -} - -impl<'tcx> PerOwnerResolverData<'tcx> { - pub fn new(id: ast::NodeId, def_id: LocalDefId) -> PerOwnerResolverData<'tcx> { - PerOwnerResolverData { id, def_id, .. } - } - - /// Obtains resolution for a label with the given `NodeId`. - pub fn get_label_res(&self, id: ast::NodeId) -> Option { - self.label_res_map.get(&id).copied() - } - - /// Obtains resolution for a lifetime with the given `NodeId`. - pub fn get_lifetime_res(&self, id: ast::NodeId) -> Option { - self.lifetimes_res_map.get(&id).copied() - } - - /// Obtain the list of lifetimes parameters to add to an item. - /// - /// Extra lifetime parameters should only be added in places that can appear - /// as a `binder` in `LifetimeRes`. - /// - /// The extra lifetimes that appear from the parenthesized `Fn`-trait desugaring - /// should appear at the enclosing `PolyTraitRef`. - pub fn extra_lifetime_params( - &self, - id: NodeId, - ) -> &[(Ident, NodeId, hir::MissingLifetimeKind)] { - self.extra_lifetime_params_map.get(&id).map_or(&[], |v| &v[..]) - } -} - -/// Resolutions that should only be used for lowering. -/// This struct is meant to be consumed by lowering. -#[derive(Debug)] -pub struct ResolverAstLowering<'tcx> { - /// Resolutions for nodes that have a single resolution. - pub partial_res_map: NodeMap, - - pub next_node_id: ast::NodeId, - - pub owners: NodeMap>, - - /// Lints that were emitted by the resolver and early lints. - pub lint_buffer: Steal, - - pub disambiguators: LocalDefIdMap>, -} - -#[derive(Debug, StableHash)] -pub struct DelegationInfo { - // `DefId` (either the resolution at delegation.id or item_id in case of a trait impl) for signature resolution, - // for details see https://github.com/rust-lang/rust/issues/118212#issuecomment-2160686914 - /// Refers to the next element in a delegation resolution chain. - /// Usually points to the final resolution, as most "chains" are just - /// one step to a trait or an impl. - pub resolution_id: Result, -} - -#[derive(Clone, Copy, Debug, StableHash)] -pub struct MainDefinition { - pub res: Res, - pub is_import: bool, - pub span: Span, -} - -impl MainDefinition { - pub fn opt_fn_def_id(self) -> Option { - if let Res::Def(DefKind::Fn, def_id) = self.res { Some(def_id) } else { None } - } -} - #[derive(Copy, Clone, Debug, TyEncodable, TyDecodable, StableHash)] pub struct ImplTraitHeader<'tcx> { pub trait_ref: ty::EarlyBinder<'tcx, ty::TraitRef<'tcx>>, diff --git a/compiler/rustc_passes/src/diagnostics.rs b/compiler/rustc_passes/src/diagnostics.rs index c343d9c7078e7..ddd56b384a6a7 100644 --- a/compiler/rustc_passes/src/diagnostics.rs +++ b/compiler/rustc_passes/src/diagnostics.rs @@ -6,7 +6,8 @@ use rustc_errors::{ Diag, DiagCtxtHandle, DiagSymbolList, Diagnostic, EmissionGuarantee, Level, MultiSpan, msg, }; use rustc_macros::{Diagnostic, Subdiagnostic}; -use rustc_middle::ty::{MainDefinition, Ty}; +use rustc_middle::middle::resolve::MainDefinition; +use rustc_middle::ty::Ty; use rustc_span::{DUMMY_SP, Ident, Span, Symbol}; use crate::check_attr::ProcMacroKind; diff --git a/compiler/rustc_passes/src/lang_items.rs b/compiler/rustc_passes/src/lang_items.rs index ddf8bbf764e6e..68be74886a2e4 100644 --- a/compiler/rustc_passes/src/lang_items.rs +++ b/compiler/rustc_passes/src/lang_items.rs @@ -13,8 +13,9 @@ use rustc_crate_store::ExternCrate; use rustc_hir::Target; use rustc_hir::attrs::lang_items::{GenericRequirement, LangItem, LanguageItems}; use rustc_hir::def_id::{DefId, LocalDefId}; +use rustc_middle::middle::resolve::ResolverAstLowering; use rustc_middle::query::Providers; -use rustc_middle::ty::{ResolverAstLowering, TyCtxt}; +use rustc_middle::ty::TyCtxt; use rustc_span::{Span, Symbol, sym}; use crate::diagnostics::{DuplicateLangItem, IncorrectCrateType, IncorrectTarget}; diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index 5fa4db74cb279..88f057c3a6d6d 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -23,7 +23,7 @@ use rustc_hir::def::{self, *}; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_index::bit_set::DenseBitSet; use rustc_metadata::creader::LoadedMacro; -use rustc_middle::metadata::{ModChild, Reexport}; +use rustc_middle::middle::resolve::{ModChild, PartialRes, Reexport}; use rustc_middle::ty::{TyCtxtFeed, Visibility}; use rustc_middle::{bug, span_bug}; use rustc_span::def_id::{CRATE_MOD_ID, ModId}; diff --git a/compiler/rustc_resolve/src/def_collector.rs b/compiler/rustc_resolve/src/def_collector.rs index 29b1773ddc5ca..4c8000c28f065 100644 --- a/compiler/rustc_resolve/src/def_collector.rs +++ b/compiler/rustc_resolve/src/def_collector.rs @@ -10,8 +10,9 @@ use rustc_hir::Target; use rustc_hir::def::DefKind; use rustc_hir::def::Namespace::{TypeNS, ValueNS}; use rustc_hir::def_id::LocalDefId; +use rustc_middle::middle::resolve::PerOwnerResolverData; use rustc_middle::span_bug; -use rustc_middle::ty::{PerOwnerResolverData, TyCtxtFeed}; +use rustc_middle::ty::TyCtxtFeed; use rustc_span::{Span, Symbol, sym}; use tracing::{debug, instrument}; diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs index ebcdb8603eccd..520d0849a17d1 100644 --- a/compiler/rustc_resolve/src/ident.rs +++ b/compiler/rustc_resolve/src/ident.rs @@ -4,8 +4,9 @@ use Determinacy::*; use Namespace::*; use rustc_ast::{self as ast, NodeId}; use rustc_errors::ErrorGuaranteed; -use rustc_hir::def::{DefKind, MacroKinds, Namespace, NonMacroAttrKind, PartialRes, PerNS}; +use rustc_hir::def::{DefKind, MacroKinds, Namespace, NonMacroAttrKind, PerNS}; use rustc_lint_defs::builtin::PROC_MACRO_DERIVE_RESOLUTION_FALLBACK; +use rustc_middle::middle::resolve::PartialRes; use rustc_middle::{bug, span_bug}; use rustc_session::diagnostics::feature_err; use rustc_span::edition::Edition; diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index 388073971171b..1cda9b9139028 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -8,14 +8,14 @@ use rustc_data_structures::fx::{FxHashSet, FxIndexSet}; use rustc_data_structures::intern::Interned; use rustc_errors::{Applicability, BufferedEarlyLint, Diagnostic}; use rustc_expand::base::SyntaxExtensionKind; -use rustc_hir::def::{self, DefKind, PartialRes}; +use rustc_hir::def::{self, DefKind}; use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdMap}; use rustc_lint_defs::LintId; use rustc_lint_defs::builtin::{ AMBIGUOUS_GLOB_REEXPORTS, EXPORTED_PRIVATE_DEPENDENCIES, HIDDEN_GLOB_REEXPORTS, PUB_USE_OF_PRIVATE_EXTERN_CRATE, REDUNDANT_IMPORTS, UNUSED_IMPORTS, }; -use rustc_middle::metadata::{AmbigModChild, ModChild, Reexport}; +use rustc_middle::middle::resolve::{AmbigModChild, ModChild, PartialRes, Reexport}; use rustc_middle::span_bug; use rustc_middle::ty::Visibility; use rustc_session::diagnostics::feature_err; diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 396db754f7c96..b1e871339a607 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -25,12 +25,13 @@ use rustc_errors::{ StashKey, Suggestions, elided_lifetime_in_path_suggestion, pluralize, }; use rustc_hir::def::Namespace::{self, *}; -use rustc_hir::def::{CtorKind, DefKind, LifetimeRes, NonMacroAttrKind, PartialRes, PerNS}; +use rustc_hir::def::{CtorKind, DefKind, NonMacroAttrKind, PerNS}; use rustc_hir::def_id::{CRATE_DEF_ID, DefId, LOCAL_CRATE, LocalDefId}; use rustc_hir::{MissingLifetimeKind, PrimTy}; use rustc_lint_defs::builtin::{ELIDED_LIFETIMES_IN_PATHS, UNUSED_LABELS}; +use rustc_middle::middle::resolve::{DelegationInfo, LifetimeRes, PartialRes}; use rustc_middle::middle::resolve_bound_vars::Set1; -use rustc_middle::ty::{AssocTag, DelegationInfo, Visibility}; +use rustc_middle::ty::{AssocTag, Visibility}; use rustc_middle::{bug, span_bug}; use rustc_session::config::ResolveDocLinks; use rustc_session::diagnostics::feature_err; diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index f5e684cb81631..16febb373e805 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -53,22 +53,20 @@ use rustc_expand::base::{DeriveResolution, SyntaxExtension, SyntaxExtensionKind} use rustc_feature::{BUILTIN_ATTRIBUTES, Features}; use rustc_hir::attrs::StrippedCfgItem; use rustc_hir::def::Namespace::{self, *}; -use rustc_hir::def::{ - self, CtorOf, DefKind, DocLinkResMap, MacroKinds, NonMacroAttrKind, PartialRes, PerNS, -}; +use rustc_hir::def::{self, CtorOf, DefKind, MacroKinds, NonMacroAttrKind, PerNS}; use rustc_hir::def_id::{CRATE_DEF_ID, CrateNum, DefId, LOCAL_CRATE, LocalDefId, LocalDefIdMap}; use rustc_hir::definitions::{PerParentDisambiguatorState, PerParentDisambiguatorsMap}; use rustc_hir::{PrimTy, TraitCandidate, find_attr}; use rustc_index::bit_set::DenseBitSet; use rustc_lint_defs::builtin::PRIVATE_MACRO_USE; use rustc_metadata::creader::CStore; -use rustc_middle::metadata::{AmbigModChild, ModChild, Reexport}; use rustc_middle::middle::privacy::EffectiveVisibilities; -use rustc_middle::query::Providers; -use rustc_middle::ty::{ - self, DelegationInfo, MainDefinition, PerOwnerResolverData, RegisteredTools, - ResolverAstLowering, ResolverGlobalCtxt, TyCtxt, TyCtxtFeed, Visibility, +use rustc_middle::middle::resolve::{ + AmbigModChild, DelegationInfo, DocLinkResMap, MainDefinition, ModChild, PartialRes, + PerOwnerResolverData, Reexport, ResolverAstLowering, ResolverGlobalCtxt, }; +use rustc_middle::query::Providers; +use rustc_middle::ty::{self, RegisteredTools, TyCtxt, TyCtxtFeed, Visibility}; use rustc_middle::{bug, span_bug}; use rustc_span::def_id::{LocalModId, ModId}; use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind, SyntaxContext, Transparency}; @@ -1993,7 +1991,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { stripped_cfg_items, delegation_infos: self.delegation_infos, }; - let ast_lowering = ty::ResolverAstLowering { + let ast_lowering = ResolverAstLowering { partial_res_map: self.partial_res_map, next_node_id: self.next_node_id, owners: self.owners, diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 784a80ef02cd2..b6cd31a16eaaf 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -45,7 +45,7 @@ use rustc_hir::def::{CtorKind, DefKind, MacroKinds, Res}; use rustc_hir::def_id::{DefId, DefIdMap, DefIdSet, LOCAL_CRATE, LocalDefId}; use rustc_hir::{PredicateOrigin, find_attr}; use rustc_hir_analysis::{lower_const_arg_for_rustdoc, lower_ty}; -use rustc_middle::metadata::Reexport; +use rustc_middle::middle::resolve::Reexport; use rustc_middle::middle::resolve_bound_vars as rbv; use rustc_middle::ty::{ self, AdtKind, GenericArgsRef, RegionExt, Ty, TyCtxt, TypeVisitableExt, TypingMode, diff --git a/src/librustdoc/passes/lint/redundant_explicit_links.rs b/src/librustdoc/passes/lint/redundant_explicit_links.rs index 35e254c754d68..c04438d69007b 100644 --- a/src/librustdoc/passes/lint/redundant_explicit_links.rs +++ b/src/librustdoc/passes/lint/redundant_explicit_links.rs @@ -3,8 +3,9 @@ use std::ops::Range; use rustc_ast::NodeId; use rustc_errors::{Diag, DiagCtxtHandle, Diagnostic, Level, SuggestionStyle}; use rustc_hir::HirId; -use rustc_hir::def::{DefKind, DocLinkResMap, Namespace, Res}; +use rustc_hir::def::{DefKind, Namespace, Res}; use rustc_lint::Applicability; +use rustc_middle::middle::resolve::DocLinkResMap; use rustc_resolve::rustdoc::pulldown_cmark::{ BrokenLink, BrokenLinkCallback, CowStr, Event, LinkType, OffsetIter, Parser, Tag, };