Skip to content

Commit 9da9373

Browse files
committed
rustc_middle: Remove Option from module_reexports query
1 parent 612ddd2 commit 9da9373

File tree

7 files changed

+12
-17
lines changed

7 files changed

+12
-17
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1327,8 +1327,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
13271327
}
13281328
}));
13291329

1330-
if let Some(reexports) = tcx.module_reexports(local_def_id) {
1331-
assert!(!reexports.is_empty());
1330+
let reexports = tcx.module_reexports(local_def_id);
1331+
if !reexports.is_empty() {
13321332
record_array!(self.tables.module_reexports[def_id] <- reexports);
13331333
}
13341334
}

compiler/rustc_middle/src/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1510,7 +1510,7 @@ rustc_queries! {
15101510
desc { "getting traits in scope at a block" }
15111511
}
15121512

1513-
query module_reexports(def_id: LocalDefId) -> Option<&'tcx [ModChild]> {
1513+
query module_reexports(def_id: LocalDefId) -> &'tcx [ModChild] {
15141514
desc { |tcx| "looking up reexports of module `{}`", tcx.def_path_str(def_id.to_def_id()) }
15151515
}
15161516

compiler/rustc_middle/src/ty/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2502,7 +2502,7 @@ pub struct DeducedParamAttrs {
25022502

25032503
pub fn provide(providers: &mut ty::query::Providers) {
25042504
providers.module_reexports =
2505-
|tcx, id| tcx.resolutions(()).reexport_map.get(&id).map(|v| &v[..]);
2505+
|tcx, id| tcx.resolutions(()).reexport_map.get(&id).map_or(&[], |v| &v[..]);
25062506
providers.maybe_unused_trait_imports =
25072507
|tcx, ()| &tcx.resolutions(()).maybe_unused_trait_imports;
25082508
providers.names_imported_by_glob_use = |tcx, id| {

compiler/rustc_privacy/src/lib.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -515,16 +515,12 @@ impl<'tcx> EmbargoVisitor<'tcx> {
515515
let vis = self.tcx.local_visibility(item_id.owner_id.def_id);
516516
self.update_macro_reachable_def(item_id.owner_id.def_id, def_kind, vis, defining_mod);
517517
}
518-
if let Some(exports) = self.tcx.module_reexports(module_def_id) {
519-
for export in exports {
520-
if export.vis.is_accessible_from(defining_mod, self.tcx) {
521-
if let Res::Def(def_kind, def_id) = export.res {
522-
if let Some(def_id) = def_id.as_local() {
523-
let vis = self.tcx.local_visibility(def_id);
524-
self.update_macro_reachable_def(def_id, def_kind, vis, defining_mod);
525-
}
526-
}
527-
}
518+
for export in self.tcx.module_reexports(module_def_id) {
519+
if export.vis.is_accessible_from(defining_mod, self.tcx)
520+
&& let Res::Def(def_kind, def_id) = export.res
521+
&& let Some(def_id) = def_id.as_local() {
522+
let vis = self.tcx.local_visibility(def_id);
523+
self.update_macro_reachable_def(def_id, def_kind, vis, defining_mod);
528524
}
529525
}
530526
}

src/librustdoc/clean/inline.rs

-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ pub(crate) fn try_inline_glob(
153153
let reexports = cx
154154
.tcx
155155
.module_reexports(current_mod)
156-
.unwrap_or_default()
157156
.iter()
158157
.filter_map(|child| child.res.opt_def_id())
159158
.collect();

src/librustdoc/clean/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2062,7 +2062,7 @@ pub(crate) fn reexport_chain<'tcx>(
20622062
import_def_id: LocalDefId,
20632063
target_def_id: LocalDefId,
20642064
) -> &'tcx [Reexport] {
2065-
for child in tcx.module_reexports(tcx.local_parent(import_def_id)).unwrap_or_default() {
2065+
for child in tcx.module_reexports(tcx.local_parent(import_def_id)) {
20662066
if child.res.opt_def_id() == Some(target_def_id.to_def_id())
20672067
&& child.reexport_chain[0].id() == Some(import_def_id.to_def_id())
20682068
{

src/librustdoc/visit_ast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
133133
// is declared but also a reexport of itself producing two exports of the same
134134
// macro in the same module.
135135
let mut inserted = FxHashSet::default();
136-
for export in self.cx.tcx.module_reexports(CRATE_DEF_ID).unwrap_or(&[]) {
136+
for export in self.cx.tcx.module_reexports(CRATE_DEF_ID) {
137137
if let Res::Def(DefKind::Macro(_), def_id) = export.res &&
138138
let Some(local_def_id) = def_id.as_local() &&
139139
self.cx.tcx.has_attr(def_id, sym::macro_export) &&

0 commit comments

Comments
 (0)