Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,7 @@ fn visibility_di_flags<'ll, 'tcx>(
match visibility {
Visibility::Public => DIFlags::FlagPublic,
// Private fields have a restricted visibility of the module containing the type.
Visibility::Restricted(did) if did == parent_did => DIFlags::FlagPrivate,
Visibility::Restricted(did) if did.to_def_id() == parent_did => DIFlags::FlagPrivate,
// `pub(crate)`/`pub(super)` visibilities are any other restricted visibility.
Visibility::Restricted(..) => DIFlags::FlagProtected,
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use rustc_parse::MACRO_ARGUMENTS;
use rustc_parse::parser::Parser;
use rustc_session::Session;
use rustc_session::parse::ParseSess;
use rustc_span::def_id::{CrateNum, DefId, LocalDefId};
use rustc_span::def_id::{CrateNum, DefId, LocalDefId, ModId};
use rustc_span::edition::Edition;
use rustc_span::hygiene::{AstPass, ExpnData, ExpnKind, LocalExpnId, MacroKind};
use rustc_span::source_map::SourceMap;
Expand Down Expand Up @@ -1003,7 +1003,7 @@ impl SyntaxExtension {
descr: Symbol,
kind: MacroKind,
macro_def_id: Option<DefId>,
parent_module: Option<DefId>,
parent_module: Option<ModId>,
) -> ExpnData {
ExpnData::new(
ExpnKind::Macro(kind, descr),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use rustc_middle::ty::{
TypeVisitableExt, TypeVisitor, TypingMode, Unnormalized,
};
use rustc_span::Span;
use rustc_span::def_id::ModId;
use rustc_trait_selection::regions::InferCtxtRegionExt;
use rustc_trait_selection::traits::{ObligationCtxt, elaborate, normalize_param_env_or_error};

Expand Down Expand Up @@ -380,7 +381,7 @@ fn report_mismatched_rpitit_signature<'tcx>(
);
}

fn type_visibility<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<ty::Visibility<DefId>> {
fn type_visibility<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<ty::Visibility<ModId>> {
match *ty.kind() {
ty::Ref(_, ty, _) => type_visibility(tcx, ty),
ty::Adt(def, args) => {
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ use rustc_middle::ty::{
use rustc_middle::{bug, span_bug};
use rustc_session::diagnostics::feature_err;
use rustc_session::lint::builtin::AMBIGUOUS_ASSOCIATED_ITEMS;
use rustc_span::def_id::ModId;
use rustc_span::{DUMMY_SP, Ident, Span, kw, sym};
use rustc_trait_selection::infer::InferCtxtExt;
use rustc_trait_selection::traits::{self, FulfillmentError};
Expand Down Expand Up @@ -116,7 +117,7 @@ pub enum RegionInferReason<'a> {
pub struct InherentAssocCandidate {
pub impl_: DefId,
pub assoc_item: DefId,
pub scope: DefId,
pub scope: ModId,
}

pub struct ResolvedStructPath<'tcx> {
Expand Down Expand Up @@ -1806,7 +1807,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
ident: Ident,
assoc_tag: ty::AssocTag,
scope: DefId,
) -> Option<(ty::AssocItem, /*scope*/ DefId)> {
) -> Option<(ty::AssocItem, /*scope*/ ModId)> {
let tcx = self.tcx();

let (ident, def_scope) = tcx.adjust_ident_and_get_scope(ident, scope, self.item_def_id());
Expand All @@ -1826,7 +1827,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
&self,
item_def_id: DefId,
ident: Ident,
scope: DefId,
scope: ModId,
block: HirId,
span: Span,
) {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@ impl UnreachablePub {
&& let parent_parent = cx
.tcx
.parent_module_from_def_id(cx.tcx.parent_module_from_def_id(def_id).into())
&& *restricted_did == parent_parent.to_local_def_id()
&& *restricted_did == parent_parent
&& !restricted_did.to_def_id().is_crate_root()
{
"pub(super)"
Expand Down
14 changes: 7 additions & 7 deletions compiler/rustc_lint/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::cell::Cell;

use rustc_data_structures::stack::ensure_sufficient_stack;
use rustc_data_structures::sync::par_join;
use rustc_hir::def_id::{LocalDefId, LocalModDefId};
use rustc_hir::def_id::{LocalDefId, LocalModId};
use rustc_hir::{self as hir, AmbigArg, HirId, intravisit as hir_visit};
use rustc_middle::hir::nested_filter;
use rustc_middle::ty::{self, TyCtxt};
Expand Down Expand Up @@ -335,7 +335,7 @@ crate::late_lint_methods!(impl_late_lint_pass, []);

pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>(
tcx: TyCtxt<'tcx>,
module_def_id: LocalModDefId,
mod_id: LocalModId,
builtin_lints: T,
) {
let context = LateContext {
Expand All @@ -344,7 +344,7 @@ pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>(
cached_typeck_results: Cell::new(None),
param_env: ty::ParamEnv::empty(),
effective_visibilities: tcx.effective_visibilities(()),
last_node_with_lint_attrs: tcx.local_def_id_to_hir_id(module_def_id),
last_node_with_lint_attrs: tcx.local_def_id_to_hir_id(mod_id),
generics: None,
only_module: true,
};
Expand All @@ -363,26 +363,26 @@ pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>(
let builtin_lints_must_run = is_lint_pass_required(skippable_lints, &builtin_lints.get_lints());
if passes.is_empty() {
if builtin_lints_must_run {
late_lint_mod_inner(tcx, module_def_id, context, builtin_lints);
late_lint_mod_inner(tcx, mod_id, context, builtin_lints);
}
} else {
if builtin_lints_must_run {
passes.push(Box::new(builtin_lints) as Box<dyn LateLintPass<'tcx>>);
}
let pass = RuntimeCombinedLateLintPass { passes };
late_lint_mod_inner(tcx, module_def_id, context, pass);
late_lint_mod_inner(tcx, mod_id, context, pass);
}
}

fn late_lint_mod_inner<'tcx, T: LateLintPass<'tcx>>(
tcx: TyCtxt<'tcx>,
module_def_id: LocalModDefId,
mod_id: LocalModId,
context: LateContext<'tcx>,
pass: T,
) {
let mut cx = LateContextAndPass { context, pass };

let (module, _span, hir_id) = tcx.hir_get_module(module_def_id);
let (module, _span, hir_id) = tcx.hir_get_module(mod_id);

cx.with_lint_attrs(hir_id, |cx| {
// There is no module lint that will have the crate itself as an item, so check it here.
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_lint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ use redundant_semicolon::*;
use reference_casting::*;
use runtime_symbols::*;
use rustc_data_structures::unord::UnordSet;
use rustc_hir::def_id::LocalModDefId;
use rustc_hir::def_id::LocalModId;
use rustc_middle::query::Providers;
use rustc_middle::ty::TyCtxt;
use shadowed_into_iter::ShadowedIntoIter;
Expand Down Expand Up @@ -154,8 +154,8 @@ pub fn provide(providers: &mut Providers) {
*providers = Providers { lint_mod, ..*providers };
}

fn lint_mod(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) {
late_lint_mod(tcx, module_def_id, BuiltinCombinedLateLintModPass::new());
fn lint_mod(tcx: TyCtxt<'_>, mod_id: LocalModId) {
late_lint_mod(tcx, mod_id, BuiltinCombinedLateLintModPass::new());
}

early_lint_methods!(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/unused/must_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ pub fn is_ty_must_use<'tcx>(
return IsTyMustUse::Trivial;
}

let parent_mod_did = cx.tcx.parent_module(expr.hir_id).to_def_id();
let parent_mod_did = cx.tcx.parent_module(expr.hir_id);
let is_uninhabited =
|t: Ty<'tcx>| !t.is_inhabited_from(cx.tcx, parent_mod_did, cx.typing_env());

Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use rustc_serialize::{Decodable, Decoder};
use rustc_session::config::TargetModifier;
use rustc_session::config::mitigation_coverage::DeniedPartialMitigation;
use rustc_session::cstore::{CrateSource, ExternCrate};
use rustc_span::def_id::ModId;
use rustc_span::hygiene::HygieneDecodeContext;
use rustc_span::{
BlobDecoder, BytePos, ByteSymbol, DUMMY_SP, Pos, RemapPathScopeComponents, SpanData,
Expand Down Expand Up @@ -1173,14 +1174,14 @@ impl CrateMetadata {
)
}

fn get_visibility(&self, tcx: TyCtxt<'_>, id: DefIndex) -> Visibility<DefId> {
fn get_visibility(&self, tcx: TyCtxt<'_>, id: DefIndex) -> Visibility<ModId> {
self.root
.tables
.visibility
.get(self, id)
.unwrap_or_else(|| self.missing("visibility", id))
.decode((self, tcx))
.map_id(|index| self.local_def_id(index))
.map_id(|index| ModId::new_unchecked(self.local_def_id(index)))
}

fn get_safety(&self, id: DefIndex) -> Safety {
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use rustc_middle::util::Providers;
use rustc_serialize::Decoder;
use rustc_session::StableCrateId;
use rustc_session::cstore::{CrateStore, ExternCrate};
use rustc_span::def_id::ModId;
use rustc_span::hygiene::ExpnId;
use rustc_span::{Span, Symbol, kw};

Expand Down Expand Up @@ -191,6 +192,13 @@ impl IntoArgs for DefId {
}
}

impl IntoArgs for ModId {
type Other = ();
fn into_args(self) -> (DefId, ()) {
(self.to_def_id(), ())
}
}

impl IntoArgs for CrateNum {
type Other = ();
fn into_args(self) -> (DefId, ()) {
Expand Down
15 changes: 10 additions & 5 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use rustc_middle::{bug, span_bug};
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder, opaque};
use rustc_session::config::mitigation_coverage::DeniedPartialMitigation;
use rustc_session::config::{CrateType, OptLevel, TargetModifier};
use rustc_span::def_id::CRATE_MOD_ID;
use rustc_span::hygiene::HygieneEncodeContext;
use rustc_span::{
ByteSymbol, ExternalSource, FileName, SourceFile, SpanData, SpanEncoder, StableSourceFileId,
Expand Down Expand Up @@ -1455,8 +1456,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
record!(self.tables.codegen_fn_attrs[def_id] <- self.tcx.codegen_fn_attrs(def_id));
}
if should_encode_visibility(def_kind) {
let vis =
self.tcx.local_visibility(local_id).map_id(|def_id| def_id.local_def_index);
let vis = self
.tcx
.local_visibility(local_id)
.map_id(|mod_id| mod_id.to_local_def_id().local_def_index);
record!(self.tables.visibility[def_id] <- vis);
}
if should_encode_stability(def_kind) {
Expand Down Expand Up @@ -1979,16 +1982,18 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
self.tables.def_kind.set_some(LOCAL_CRATE.as_def_id().index, DefKind::Mod);
record!(self.tables.def_span[LOCAL_CRATE.as_def_id()] <- tcx.def_span(LOCAL_CRATE.as_def_id()));
self.encode_attrs(LOCAL_CRATE.as_def_id().expect_local());
let vis = tcx.local_visibility(CRATE_DEF_ID).map_id(|def_id| def_id.local_def_index);
let vis = tcx
.local_visibility(CRATE_DEF_ID)
.map_id(|mod_id| mod_id.to_local_def_id().local_def_index);
record!(self.tables.visibility[LOCAL_CRATE.as_def_id()] <- vis);
if let Some(stability) = stability {
record!(self.tables.lookup_stability[LOCAL_CRATE.as_def_id()] <- stability);
}
self.encode_deprecation(LOCAL_CRATE.as_def_id());
if let Some(res_map) = tcx.resolutions(()).doc_link_resolutions.get(&CRATE_DEF_ID) {
if let Some(res_map) = tcx.resolutions(()).doc_link_resolutions.get(&CRATE_MOD_ID) {
record!(self.tables.doc_link_resolutions[LOCAL_CRATE.as_def_id()] <- res_map);
}
if let Some(traits) = tcx.resolutions(()).doc_link_traits_in_scope.get(&CRATE_DEF_ID) {
if let Some(traits) = tcx.resolutions(()).doc_link_traits_in_scope.get(&CRATE_MOD_ID) {
record_array!(self.tables.doc_link_traits_in_scope[LOCAL_CRATE.as_def_id()] <- traits);
}

Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_middle/src/dep_graph/dep_node_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::fmt::Debug;

use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::stable_hash::{StableHash, StableHasher};
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId, LocalModDefId, ModDefId};
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId, LocalModId, ModId};
use rustc_hir::definitions::DefPathHash;
use rustc_hir::{HirId, ItemLocalId, OwnerId};

Expand Down Expand Up @@ -194,7 +194,7 @@ impl<'tcx> DepNodeKey<'tcx> for HirId {
}
}

impl<'tcx> DepNodeKey<'tcx> for ModDefId {
impl<'tcx> DepNodeKey<'tcx> for ModId {
#[inline(always)]
fn key_fingerprint_style() -> KeyFingerprintStyle {
KeyFingerprintStyle::DefPathHash
Expand All @@ -207,11 +207,11 @@ impl<'tcx> DepNodeKey<'tcx> for ModDefId {

#[inline(always)]
fn try_recover_key(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
DefId::try_recover_key(tcx, dep_node).map(ModDefId::new_unchecked)
DefId::try_recover_key(tcx, dep_node).map(ModId::new_unchecked)
}
}

impl<'tcx> DepNodeKey<'tcx> for LocalModDefId {
impl<'tcx> DepNodeKey<'tcx> for LocalModId {
#[inline(always)]
fn key_fingerprint_style() -> KeyFingerprintStyle {
KeyFingerprintStyle::DefPathHash
Expand All @@ -224,6 +224,6 @@ impl<'tcx> DepNodeKey<'tcx> for LocalModDefId {

#[inline(always)]
fn try_recover_key(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
LocalDefId::try_recover_key(tcx, dep_node).map(LocalModDefId::new_unchecked)
LocalDefId::try_recover_key(tcx, dep_node).map(LocalModId::new_unchecked)
}
}
Loading
Loading