Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion compiler/rustc_resolve/src/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
// Record primary definitions.
let mut define_extern = |ns| {
let orig_ident_span = orig_ident.span;
let reexport_chain: &[Reexport] = if !reexport_chain.is_empty() {
self.arenas.dropless.alloc_slice(reexport_chain)
} else {
&[]
};
let decl = self.arenas.alloc_decl(DeclData {
kind: DeclKind::Def(res),
kind: DeclKind::Def(res, reexport_chain),
ambiguity: CmCell::new(ambig),
initial_vis: vis,
ambiguity_vis_max: CmCell::new(None),
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_resolve/src/diagnostics/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
if let Some(ambiguity_warning) = ambiguity_error.warning {
let node_id = match ambiguity_error.b1.0.kind {
DeclKind::Import { import, .. } => import.root_id,
DeclKind::Def(_) => CRATE_NODE_ID,
DeclKind::Def(..) => CRATE_NODE_ID,
};

let lint = match ambiguity_warning {
Expand Down Expand Up @@ -2465,7 +2465,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
/// If the binding refers to a tuple struct constructor with fields,
/// returns the span of its fields.
fn ctor_fields_span(&self, decl: Decl<'_>) -> Option<Span> {
let DeclKind::Def(Res::Def(DefKind::Ctor(CtorOf::Struct, CtorKind::Fn), ctor_def_id)) =
let DeclKind::Def(Res::Def(DefKind::Ctor(CtorOf::Struct, CtorKind::Fn), ctor_def_id), _) =
decl.kind
else {
return None;
Expand Down Expand Up @@ -2735,7 +2735,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {

match binding.kind {
DeclKind::Import { source_decl, import, .. } => {
let through_reexport = !matches!(source_decl.kind, DeclKind::Def(_));
let through_reexport = !matches!(source_decl.kind, DeclKind::Def(..));
let uses_relative_path = import
.module_path
.first()
Expand Down Expand Up @@ -2810,7 +2810,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
sugg_paths.push((path, through_reexport));
}
}
DeclKind::Def(_) => {}
DeclKind::Def(..) => {}
}
let first = binding == first_binding;
let def_span = self.tcx.sess.source_map().guess_head_span(binding.span);
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_resolve/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
&& !binding.vis().is_public()
{
let binding_id = match binding.kind {
DeclKind::Def(res) => {
DeclKind::Def(res, ..) => {
Some(self.def_id_to_node_id(res.def_id().expect_local()))
}
DeclKind::Import { import, .. } => import.id(),
Expand Down Expand Up @@ -1513,7 +1513,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
match source_decl.kind {
// Never suggest names that previously could not
// be resolved.
DeclKind::Def(Res::Err) => None,
DeclKind::Def(Res::Err, ..) => None,
_ => Some(i.name),
}
}
Expand Down Expand Up @@ -1697,7 +1697,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {

match decl.kind {
// exclude decl_macro
DeclKind::Def(Res::Def(DefKind::Macro(_), def_id))
DeclKind::Def(Res::Def(DefKind::Macro(_), def_id), _)
if let SyntaxExtensionKind::MacroRules(mr) =
&self.get_macro_by_def_id(def_id).kind
&& mr.is_macro_rules() =>
Expand Down
35 changes: 23 additions & 12 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,9 @@ type Decl<'ra> = Interned<'ra, DeclData<'ra>>;
enum DeclKind<'ra> {
/// The name declaration is a definition (possibly without a `DefId`),
/// can be provided by source code or built into the language.
Comment thread
petrochenkov marked this conversation as resolved.
Resolved
Def(Res),
///
/// The reexports are only added for declarations in external modules.
Def(Res, &'ra [Reexport]),
/// The name declaration is a link to another name declaration.
Import { source_decl: Decl<'ra>, import: Import<'ra> },
}
Expand Down Expand Up @@ -1152,7 +1154,7 @@ impl<'ra> DeclData<'ra> {

fn res(&self) -> Res {
match self.kind {
DeclKind::Def(res) => res,
DeclKind::Def(res, ..) => res,
DeclKind::Import { source_decl, .. } => source_decl.res(),
}
}
Expand Down Expand Up @@ -1185,9 +1187,10 @@ impl<'ra> DeclData<'ra> {
fn is_possibly_imported_variant(&self) -> bool {
match self.kind {
DeclKind::Import { source_decl, .. } => source_decl.is_possibly_imported_variant(),
DeclKind::Def(Res::Def(DefKind::Variant | DefKind::Ctor(CtorOf::Variant, ..), _)) => {
true
}
DeclKind::Def(
Res::Def(DefKind::Variant | DefKind::Ctor(CtorOf::Variant, ..), _),
_,
) => true,
DeclKind::Def(..) => false,
}
}
Expand All @@ -1197,7 +1200,7 @@ impl<'ra> DeclData<'ra> {
DeclKind::Import { import, .. } => {
matches!(import.kind, ImportKind::ExternCrate { .. })
}
DeclKind::Def(Res::Def(_, def_id)) => def_id.is_crate_root(),
DeclKind::Def(Res::Def(_, def_id), _) => def_id.is_crate_root(),
_ => false,
}
}
Expand Down Expand Up @@ -1232,13 +1235,21 @@ impl<'ra> DeclData<'ra> {
}

fn reexport_chain(self: Decl<'ra>) -> SmallVec<[Reexport; 2]> {
let mut reexport_chain = SmallVec::new();
let mut full_reexport_chain: SmallVec<[Reexport; 2]> = SmallVec::new();
let mut next_binding = self;
while let DeclKind::Import { source_decl, import, .. } = next_binding.kind {
reexport_chain.push(import.simplify());
next_binding = source_decl;
loop {
match next_binding.kind {
DeclKind::Import { source_decl, import, .. } => {
full_reexport_chain.push(import.simplify());
next_binding = source_decl;
}
DeclKind::Def(_, reexport_chain) => {
full_reexport_chain.extend(reexport_chain.iter().copied());
break;
}
}
}
reexport_chain
full_reexport_chain
}

// Suppose that we resolved macro invocation with `invoc_parent_expansion` to binding `binding`
Expand Down Expand Up @@ -1585,7 +1596,7 @@ impl<'ra> ResolverArenas<'ra> {
parent_module: Option<Module<'ra>>,
) -> Decl<'ra> {
self.alloc_decl(DeclData {
kind: DeclKind::Def(res),
kind: DeclKind::Def(res, &[]),
ambiguity: CmCell::new(None),
initial_vis: vis,
ambiguity_vis_max: CmCell::new(None),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1143,7 +1143,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
if let Some((mod_def_id, node_id)) = invoc_in_mod_inert_attr
&& let Some(decl) = decl
// This is a `macro_rules` itself, not some import.
&& let DeclKind::Def(res) = decl.kind
&& let DeclKind::Def(res, _) = decl.kind
&& let Res::Def(DefKind::Macro(kinds), def_id) = res
&& kinds.contains(MacroKinds::BANG)
// And the `macro_rules` is defined inside the attribute's module,
Expand Down
5 changes: 5 additions & 0 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2772,6 +2772,11 @@ fn get_all_import_attributes<'hir>(
.iter()
.flat_map(|reexport| reexport.id())
{
if cx.tcx.def_kind(def_id) == DefKind::ExternCrate {
// There is no attribute to query from an `DefKind::ExternCrate` item, only
// from `DefKind::Use`.
continue;
}
let import_attrs = inline::load_attrs(cx.tcx, def_id);
if first {
// This is the "original" reexport so we get all its attributes without filtering them.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#![crate_name = "baz"]

/// baz
pub struct Type;
8 changes: 8 additions & 0 deletions tests/rustdoc-html/reexport/auxiliary/transient-reexports.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//@ aux-build: transient-reexports-dep.rs

#![crate_name = "bar"]

extern crate baz;

/// bar
pub use baz::Type;
21 changes: 21 additions & 0 deletions tests/rustdoc-html/reexport/transient-reexports.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// If there is more than one dependency level, the transient crates reexports used to be
// skipped. This test ensures it's not the case anymore.
// Regression test <https://github.com/rust-lang/rust/issues/81893>.

//@ aux-build: transient-reexports.rs

#![crate_name = "foo"]

extern crate bar;

//@ has 'foo/index.html'

// We ensure that there is only one item, so it's not possibly another item we're gonna check.
//@ count - '//dl/[@class="item-table"]/dt' 1
//@ count - '//dl/[@class="item-table"]/dd' 1
//@ has - '//dl/[@class="item-table"]/dt/a[@href="struct.Type.html"]' 'Type'
// We should have "foo", "bar" and "baz" (one fragment in each crate reexport).
//@ has - '//dl/[@class="item-table"]/dd' 'foo bar baz'

/// foo
pub use bar::Type;
Loading