Skip to content

Commit 2475522

Browse files
committed
Streamline some PerNS uses.
1 parent 3d67935 commit 2475522

File tree

3 files changed

+9
-19
lines changed

3 files changed

+9
-19
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -706,18 +706,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
706706
}
707707

708708
fn lower_import_res(&mut self, id: NodeId, span: Span) -> PerNS<Option<Res>> {
709-
let PerNS { type_ns, value_ns, macro_ns } = self.resolver.get_import_res(id);
710-
let mut l = |ns: Option<_>| ns.map(|res| self.lower_res(res));
711-
let mut res = PerNS { type_ns: l(type_ns), value_ns: l(value_ns), macro_ns: l(macro_ns) };
712-
713-
if res.type_ns.is_none() && res.value_ns.is_none() && res.macro_ns.is_none() {
709+
let per_ns = self.resolver.get_import_res(id);
710+
let mut per_ns = per_ns.map(|res| res.map(|res| self.lower_res(res)));
711+
if per_ns.is_empty() {
714712
// Mark all namespaces with error, just to be sure.
715713
// Propagate the error to all namespaces, just to be sure.
716714
let err = Some(Res::Err);
717-
res = PerNS { type_ns: err, value_ns: err, macro_ns: err };
715+
per_ns = PerNS { type_ns: err, value_ns: err, macro_ns: err };
718716
self.dcx().span_delayed_bug(span, "no resolution for an import");
719717
}
720-
res
718+
per_ns
721719
}
722720

723721
fn make_lang_item_qpath(

compiler/rustc_hir/src/intravisit.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ use rustc_ast::visit::{VisitorResult, try_visit, visit_opt, walk_list};
6969
use rustc_span::def_id::LocalDefId;
7070
use rustc_span::{Ident, Span, Symbol};
7171

72-
use crate::def::PerNS;
7372
use crate::hir::*;
7473

7574
pub trait IntoVisitor<'hir> {
@@ -1148,15 +1147,9 @@ pub fn walk_use<'v, V: Visitor<'v>>(
11481147
path: &'v UsePath<'v>,
11491148
hir_id: HirId,
11501149
) -> V::Result {
1151-
let UsePath { segments, res: PerNS { value_ns, type_ns, macro_ns }, span } = *path;
1152-
if let Some(value_ns) = value_ns {
1153-
try_visit!(visitor.visit_path(&Path { segments, res: value_ns, span }, hir_id));
1154-
}
1155-
if let Some(type_ns) = type_ns {
1156-
try_visit!(visitor.visit_path(&Path { segments, res: type_ns, span }, hir_id));
1157-
}
1158-
if let Some(macro_ns) = macro_ns {
1159-
try_visit!(visitor.visit_path(&Path { segments, res: macro_ns, span }, hir_id));
1150+
let UsePath { segments, ref res, span } = *path;
1151+
for res in res.present_items() {
1152+
try_visit!(visitor.visit_path(&Path { segments, res, span }, hir_id));
11601153
}
11611154
V::Result::output()
11621155
}

compiler/rustc_lint/src/unqualified_local_imports.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ impl<'tcx> LateLintPass<'tcx> for UnqualifiedLocalImports {
5050
let is_local_import = matches!(
5151
path.res.type_ns,
5252
Some(hir::def::Res::Def(_, def_id)) if def_id.is_local()
53-
)
54-
|| matches!(
53+
) || matches!(
5554
path.res.value_ns,
5655
Some(hir::def::Res::Def(_, def_id)) if def_id.is_local()
5756
);

0 commit comments

Comments
 (0)