Auto merge of #109500 - petrochenkov:modchainld, r=oli-obk
resolve: Preserve reexport chains in `ModChild`ren This may be potentially useful for - avoiding uses of `hir::ItemKind::Use` (which usually lead to correctness issues) - preserving documentation comments on all reexports, including those from other crates - preserving and checking stability/deprecation info on reexports - all kinds of diagnostics The second commit then migrates some hacky logic from rustdoc to `module_reexports` to make it simpler and more correct. Ideally rustdoc should use `module_reexports` immediately at the top level, so `hir::ItemKind::Use`s are never used. The second commit also fixes issues with https://github.com/rust-lang/rust/pull/109330 and therefore Fixes https://github.com/rust-lang/rust/issues/109631 Fixes https://github.com/rust-lang/rust/issues/109614 Fixes https://github.com/rust-lang/rust/issues/109424
This commit is contained in:
commit
7201301df6
14 changed files with 97 additions and 168 deletions
|
@ -119,6 +119,7 @@ macro_rules! arena_types {
|
|||
[] external_constraints: rustc_middle::traits::solve::ExternalConstraintsData<'tcx>,
|
||||
[decode] doc_link_resolutions: rustc_hir::def::DocLinkResMap,
|
||||
[] closure_kind_origin: (rustc_span::Span, rustc_middle::hir::place::Place<'tcx>),
|
||||
[] mod_child: rustc_middle::metadata::ModChild,
|
||||
]);
|
||||
)
|
||||
}
|
||||
|
|
|
@ -5,13 +5,34 @@ use rustc_macros::HashStable;
|
|||
use rustc_span::def_id::DefId;
|
||||
use rustc_span::symbol::Ident;
|
||||
use rustc_span::Span;
|
||||
use smallvec::SmallVec;
|
||||
|
||||
/// 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, HashStable)]
|
||||
pub enum Reexport {
|
||||
Single(DefId),
|
||||
Glob(DefId),
|
||||
ExternCrate(DefId),
|
||||
MacroUse,
|
||||
MacroExport,
|
||||
}
|
||||
|
||||
impl Reexport {
|
||||
pub fn id(self) -> Option<DefId> {
|
||||
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 `NameBinding`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(Copy, Clone, Debug, TyEncodable, TyDecodable, HashStable)]
|
||||
#[derive(Debug, TyEncodable, TyDecodable, HashStable)]
|
||||
pub struct ModChild {
|
||||
/// Name of the item.
|
||||
pub ident: Ident,
|
||||
|
@ -24,4 +45,7 @@ pub struct ModChild {
|
|||
pub span: Span,
|
||||
/// A proper `macro_rules` item (not a reexport).
|
||||
pub macro_rules: bool,
|
||||
/// 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]>,
|
||||
}
|
||||
|
|
|
@ -235,7 +235,6 @@ trivial! {
|
|||
rustc_hir::OwnerId,
|
||||
rustc_hir::Upvar,
|
||||
rustc_index::bit_set::FiniteBitSet<u32>,
|
||||
rustc_middle::metadata::ModChild,
|
||||
rustc_middle::middle::dependency_format::Linkage,
|
||||
rustc_middle::middle::exported_symbols::SymbolExportInfo,
|
||||
rustc_middle::middle::resolve_bound_vars::ObjectLifetimeDefault,
|
||||
|
|
|
@ -1510,7 +1510,7 @@ rustc_queries! {
|
|||
desc { "getting traits in scope at a block" }
|
||||
}
|
||||
|
||||
query module_reexports(def_id: LocalDefId) -> Option<&'tcx [ModChild]> {
|
||||
query module_reexports(def_id: LocalDefId) -> &'tcx [ModChild] {
|
||||
desc { |tcx| "looking up reexports of module `{}`", tcx.def_path_str(def_id.to_def_id()) }
|
||||
}
|
||||
|
||||
|
|
|
@ -2502,7 +2502,7 @@ pub struct DeducedParamAttrs {
|
|||
|
||||
pub fn provide(providers: &mut ty::query::Providers) {
|
||||
providers.module_reexports =
|
||||
|tcx, id| tcx.resolutions(()).reexport_map.get(&id).map(|v| &v[..]);
|
||||
|tcx, id| tcx.resolutions(()).reexport_map.get(&id).map_or(&[], |v| &v[..]);
|
||||
providers.maybe_unused_trait_imports =
|
||||
|tcx, ()| &tcx.resolutions(()).maybe_unused_trait_imports;
|
||||
providers.names_imported_by_glob_use = |tcx, id| {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue