Skip to content

Commit 5bc7a63

Browse files
committed
Auto merge of #161872 - petrochenkov:rechain, r=<try>
[WIP] resolve: Concatenate reexport chains from all crates
2 parents e457a7b + 20bc0ce commit 5bc7a63

2 files changed

Lines changed: 41 additions & 22 deletions

File tree

compiler/rustc_resolve/src/build_reduced_graph.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
412412
non_glob_decl: Some(decl),
413413
orig_ident_span,
414414
single_imports: Default::default(),
415+
extern_reexport_chain: reexport_chain.clone(),
415416
..
416417
});
417418

compiler/rustc_resolve/src/imports.rs

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use rustc_session::diagnostics::feature_err;
2222
use rustc_span::edit_distance::find_best_match_for_name;
2323
use rustc_span::hygiene::LocalExpnId;
2424
use rustc_span::{Ident, Span, Symbol, kw, sym};
25+
use smallvec::SmallVec;
2526
use tracing::debug;
2627

2728
use crate::Namespace::{self, *};
@@ -277,6 +278,7 @@ pub(crate) struct NameResolution<'ra> {
277278
/// The glob declaration for this name, if it is known to exist.
278279
pub glob_decl: Option<Decl<'ra>> = None,
279280
pub orig_ident_span: Span,
281+
pub extern_reexport_chain: SmallVec<[Reexport; 2]>,
280282
}
281283

282284
/// `Interned` is used because values of this type have "identity" and compare as unequal even if
@@ -285,7 +287,12 @@ pub(crate) type NameResolutionRef<'ra> = Interned<'ra, CmRefCell<NameResolution<
285287

286288
impl<'ra> NameResolution<'ra> {
287289
pub(crate) fn new(orig_ident_span: Span) -> Self {
288-
NameResolution { single_imports: FxIndexSet::default(), orig_ident_span, .. }
290+
NameResolution {
291+
single_imports: FxIndexSet::default(),
292+
orig_ident_span,
293+
extern_reexport_chain: Default::default(),
294+
..
295+
}
289296
}
290297

291298
/// Returns the best declaration if it is not going to change, and `None` if the best
@@ -1890,30 +1897,41 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
18901897
let mut children = Vec::new();
18911898
let mut ambig_children = Vec::new();
18921899

1893-
module.to_module().for_each_child(self, |this, ident, orig_ident_span, _, decl| {
1894-
let res = decl.res().expect_non_local();
1895-
if res != def::Res::Err {
1896-
let vis = if this.rust_embed_hack(module, decl) {
1897-
Visibility::Public
1898-
} else {
1899-
decl.vis()
1900-
};
1901-
let ident = ident.orig(orig_ident_span);
1902-
let child = |reexport_chain| ModChild { ident, res, vis, reexport_chain };
1903-
if let Some((ambig_binding1, ambig_binding2)) = decl.descent_to_ambiguity() {
1904-
let main = child(ambig_binding1.reexport_chain());
1905-
let second = ModChild {
1906-
ident,
1907-
res: ambig_binding2.res().expect_non_local(),
1908-
vis: ambig_binding2.vis(),
1909-
reexport_chain: ambig_binding2.reexport_chain(),
1900+
for (key, name_resolution) in self.resolutions(module.to_module()).iter() {
1901+
let name_resolution = name_resolution.borrow_checked(self);
1902+
if let Some(decl) = name_resolution.best_decl() {
1903+
let res = decl.res().expect_non_local();
1904+
if res != def::Res::Err {
1905+
let ident = key.ident;
1906+
let orig_ident_span = name_resolution.orig_ident_span;
1907+
let vis = if self.rust_embed_hack(module, decl) {
1908+
Visibility::Public
1909+
} else {
1910+
decl.vis()
19101911
};
1911-
ambig_children.push(AmbigModChild { main, second })
1912-
} else {
1913-
children.push(child(decl.reexport_chain()));
1912+
let ident = ident.orig(orig_ident_span);
1913+
let child = |reexport_chain| ModChild { ident, res, vis, reexport_chain };
1914+
if let Some((ambig_binding1, ambig_binding2)) = decl.descent_to_ambiguity() {
1915+
let mut reexport_chain = ambig_binding1.reexport_chain();
1916+
reexport_chain
1917+
.extend(name_resolution.extern_reexport_chain.iter().copied());
1918+
let main = child(reexport_chain);
1919+
let second = ModChild {
1920+
ident,
1921+
res: ambig_binding2.res().expect_non_local(),
1922+
vis: ambig_binding2.vis(),
1923+
reexport_chain: ambig_binding2.reexport_chain(),
1924+
};
1925+
ambig_children.push(AmbigModChild { main, second })
1926+
} else {
1927+
let mut reexport_chain = decl.reexport_chain();
1928+
reexport_chain
1929+
.extend(name_resolution.extern_reexport_chain.iter().copied());
1930+
children.push(child(reexport_chain));
1931+
}
19141932
}
19151933
}
1916-
});
1934+
}
19171935

19181936
if !children.is_empty() {
19191937
module_children.insert(def_id.expect_local(), children);

0 commit comments

Comments
 (0)