Skip to content

Commit c68032f

Browse files
committedJun 3, 2025·
Auto merge of #141944 - matthiaskrgr:rollup-e7xhp6w, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #140715 (Clarify &mut-methods' docs on sync::OnceLock) - #141677 (Async drop - type instead of async drop fn, fixes #140484) - #141741 (Overhaul `UsePath`) - #141873 (Fixed a typo in `ManuallyDrop`'s doc) - #141876 (Don't declare variables in `ExprKind::Let` in invalid positions) - #141886 (Add missing 2015 edition directives) - #141889 (Add missing `dyn` keywords to tests that do not test for them) - #141891 (Fix borrowck mentioning a name from an external macro we (deliberately) don't save) r? `@ghost` `@rustbot` modify labels: rollup
2 parents b17dba4 + f3622ea commit c68032f

File tree

61 files changed

+380
-192
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+380
-192
lines changed
 

‎compiler/rustc_ast_lowering/src/item.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ use rustc_ast::ptr::P;
33
use rustc_ast::visit::AssocCtxt;
44
use rustc_ast::*;
55
use rustc_errors::ErrorGuaranteed;
6-
use rustc_hir::def::{DefKind, Res};
6+
use rustc_hir::def::{DefKind, PerNS, Res};
77
use rustc_hir::def_id::{CRATE_DEF_ID, LocalDefId};
88
use rustc_hir::{self as hir, HirId, LifetimeSource, PredicateOrigin};
99
use rustc_index::{IndexSlice, IndexVec};
10+
use rustc_middle::span_bug;
1011
use rustc_middle::ty::{ResolverAstLowering, TyCtxt};
1112
use rustc_span::edit_distance::find_best_match_for_name;
1213
use rustc_span::{DUMMY_SP, DesugaringKind, Ident, Span, Symbol, kw, sym};
@@ -527,7 +528,22 @@ impl<'hir> LoweringContext<'_, 'hir> {
527528
}
528529
UseTreeKind::Glob => {
529530
let res = self.expect_full_res(id);
530-
let res = smallvec![self.lower_res(res)];
531+
let res = self.lower_res(res);
532+
// Put the result in the appropriate namespace.
533+
let res = match res {
534+
Res::Def(DefKind::Mod | DefKind::Trait, _) => {
535+
PerNS { type_ns: Some(res), value_ns: None, macro_ns: None }
536+
}
537+
Res::Def(DefKind::Enum, _) => {
538+
PerNS { type_ns: None, value_ns: Some(res), macro_ns: None }
539+
}
540+
Res::Err => {
541+
// Propagate the error to all namespaces, just to be sure.
542+
let err = Some(Res::Err);
543+
PerNS { type_ns: err, value_ns: err, macro_ns: err }
544+
}
545+
_ => span_bug!(path.span, "bad glob res {:?}", res),
546+
};
531547
let path = Path { segments, span: path.span, tokens: None };
532548
let path = self.lower_use_path(res, &path, ParamMode::Explicit);
533549
hir::ItemKind::Use(path, hir::UseKind::Glob)
@@ -601,7 +617,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
601617
} else {
602618
// For non-empty lists we can just drop all the data, the prefix is already
603619
// present in HIR as a part of nested imports.
604-
self.arena.alloc(hir::UsePath { res: smallvec![], segments: &[], span })
620+
self.arena.alloc(hir::UsePath { res: PerNS::default(), segments: &[], span })
605621
};
606622
hir::ItemKind::Use(path, hir::UseKind::ListStem)
607623
}

‎compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ use rustc_middle::ty::{ResolverAstLowering, TyCtxt};
6464
use rustc_session::parse::{add_feature_diagnostics, feature_err};
6565
use rustc_span::symbol::{Ident, Symbol, kw, sym};
6666
use rustc_span::{DUMMY_SP, DesugaringKind, Span};
67-
use smallvec::{SmallVec, smallvec};
67+
use smallvec::SmallVec;
6868
use thin_vec::ThinVec;
6969
use tracing::{debug, instrument, trace};
7070

@@ -705,14 +705,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
705705
self.resolver.get_partial_res(id).map_or(Res::Err, |pr| pr.expect_full_res())
706706
}
707707

708-
fn lower_import_res(&mut self, id: NodeId, span: Span) -> SmallVec<[Res; 3]> {
709-
let res = self.resolver.get_import_res(id).present_items();
710-
let res: SmallVec<_> = res.map(|res| self.lower_res(res)).collect();
711-
if res.is_empty() {
708+
fn lower_import_res(&mut self, id: NodeId, span: Span) -> PerNS<Option<Res>> {
709+
let per_ns = self.resolver.get_import_res(id);
710+
let per_ns = per_ns.map(|res| res.map(|res| self.lower_res(res)));
711+
if per_ns.is_empty() {
712+
// Propagate the error to all namespaces, just to be sure.
712713
self.dcx().span_delayed_bug(span, "no resolution for an import");
713-
return smallvec![Res::Err];
714+
let err = Some(Res::Err);
715+
return PerNS { type_ns: err, value_ns: err, macro_ns: err };
714716
}
715-
res
717+
per_ns
716718
}
717719

718720
fn make_lang_item_qpath(

0 commit comments

Comments
 (0)
Please sign in to comment.