diff options
Diffstat (limited to 'compiler/rustc_ast_lowering/src')
| -rw-r--r-- | compiler/rustc_ast_lowering/src/item.rs | 22 | ||||
| -rw-r--r-- | compiler/rustc_ast_lowering/src/lib.rs | 16 | ||||
| -rw-r--r-- | compiler/rustc_ast_lowering/src/path.rs | 8 |
3 files changed, 32 insertions, 14 deletions
diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index d3aacaa15a8..d1a2ddbdb34 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -3,10 +3,11 @@ use rustc_ast::ptr::P; use rustc_ast::visit::AssocCtxt; use rustc_ast::*; use rustc_errors::ErrorGuaranteed; -use rustc_hir::def::{DefKind, Res}; +use rustc_hir::def::{DefKind, PerNS, Res}; use rustc_hir::def_id::{CRATE_DEF_ID, LocalDefId}; use rustc_hir::{self as hir, HirId, LifetimeSource, PredicateOrigin}; use rustc_index::{IndexSlice, IndexVec}; +use rustc_middle::span_bug; use rustc_middle::ty::{ResolverAstLowering, TyCtxt}; use rustc_span::edit_distance::find_best_match_for_name; use rustc_span::{DUMMY_SP, DesugaringKind, Ident, Span, Symbol, kw, sym}; @@ -527,7 +528,22 @@ impl<'hir> LoweringContext<'_, 'hir> { } UseTreeKind::Glob => { let res = self.expect_full_res(id); - let res = smallvec![self.lower_res(res)]; + let res = self.lower_res(res); + // Put the result in the appropriate namespace. + let res = match res { + Res::Def(DefKind::Mod | DefKind::Trait, _) => { + PerNS { type_ns: Some(res), value_ns: None, macro_ns: None } + } + Res::Def(DefKind::Enum, _) => { + PerNS { type_ns: None, value_ns: Some(res), macro_ns: None } + } + Res::Err => { + // Propagate the error to all namespaces, just to be sure. + let err = Some(Res::Err); + PerNS { type_ns: err, value_ns: err, macro_ns: err } + } + _ => span_bug!(path.span, "bad glob res {:?}", res), + }; let path = Path { segments, span: path.span, tokens: None }; let path = self.lower_use_path(res, &path, ParamMode::Explicit); hir::ItemKind::Use(path, hir::UseKind::Glob) @@ -601,7 +617,7 @@ impl<'hir> LoweringContext<'_, 'hir> { } else { // For non-empty lists we can just drop all the data, the prefix is already // present in HIR as a part of nested imports. - self.arena.alloc(hir::UsePath { res: smallvec![], segments: &[], span }) + self.arena.alloc(hir::UsePath { res: PerNS::default(), segments: &[], span }) }; hir::ItemKind::Use(path, hir::UseKind::ListStem) } diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 422e79ca82f..f41627e479f 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -64,7 +64,7 @@ use rustc_middle::ty::{ResolverAstLowering, TyCtxt}; use rustc_session::parse::{add_feature_diagnostics, feature_err}; use rustc_span::symbol::{Ident, Symbol, kw, sym}; use rustc_span::{DUMMY_SP, DesugaringKind, Span}; -use smallvec::{SmallVec, smallvec}; +use smallvec::SmallVec; use thin_vec::ThinVec; use tracing::{debug, instrument, trace}; @@ -705,14 +705,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { self.resolver.get_partial_res(id).map_or(Res::Err, |pr| pr.expect_full_res()) } - fn lower_import_res(&mut self, id: NodeId, span: Span) -> SmallVec<[Res; 3]> { - let res = self.resolver.get_import_res(id).present_items(); - let res: SmallVec<_> = res.map(|res| self.lower_res(res)).collect(); - if res.is_empty() { + fn lower_import_res(&mut self, id: NodeId, span: Span) -> PerNS<Option<Res>> { + let per_ns = self.resolver.get_import_res(id); + let per_ns = per_ns.map(|res| res.map(|res| self.lower_res(res))); + if per_ns.is_empty() { + // Propagate the error to all namespaces, just to be sure. self.dcx().span_delayed_bug(span, "no resolution for an import"); - return smallvec![Res::Err]; + let err = Some(Res::Err); + return PerNS { type_ns: err, value_ns: err, macro_ns: err }; } - res + per_ns } fn make_lang_item_qpath( diff --git a/compiler/rustc_ast_lowering/src/path.rs b/compiler/rustc_ast_lowering/src/path.rs index 5cda64ce7b4..c80ef275c80 100644 --- a/compiler/rustc_ast_lowering/src/path.rs +++ b/compiler/rustc_ast_lowering/src/path.rs @@ -1,13 +1,13 @@ use std::sync::Arc; use rustc_ast::{self as ast, *}; -use rustc_hir::def::{DefKind, PartialRes, Res}; +use rustc_hir::def::{DefKind, PartialRes, PerNS, Res}; use rustc_hir::def_id::DefId; use rustc_hir::{self as hir, GenericArg}; use rustc_middle::{span_bug, ty}; use rustc_session::parse::add_feature_diagnostics; use rustc_span::{BytePos, DUMMY_SP, DesugaringKind, Ident, Span, Symbol, sym}; -use smallvec::{SmallVec, smallvec}; +use smallvec::smallvec; use tracing::{debug, instrument}; use super::errors::{ @@ -226,11 +226,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { pub(crate) fn lower_use_path( &mut self, - res: SmallVec<[Res; 3]>, + res: PerNS<Option<Res>>, p: &Path, param_mode: ParamMode, ) -> &'hir hir::UsePath<'hir> { - assert!((1..=3).contains(&res.len())); + assert!(!res.is_empty()); self.arena.alloc(hir::UsePath { res, segments: self.arena.alloc_from_iter(p.segments.iter().map(|segment| { |
