#![feature(nll)]
#![recursion_limit = "256"]
#![allow(rustdoc::private_intra_doc_links)]
+#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
#[macro_use]
extern crate tracing;
use rustc_ast_lowering::ResolverAstLowering;
use rustc_ast_pretty::pprust;
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
-use rustc_data_structures::ptr_key::PtrKey;
+use rustc_data_structures::intern::Interned;
use rustc_data_structures::sync::Lrc;
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
use rustc_expand::base::{DeriveResolutions, SyntaxExtension, SyntaxExtensionKind};
use rustc_hir::TraitCandidate;
use rustc_index::vec::IndexVec;
use rustc_metadata::creader::{CStore, CrateLoader};
-use rustc_middle::hir::exports::ExportMap;
+use rustc_middle::metadata::ModChild;
+use rustc_middle::middle::privacy::AccessLevels;
use rustc_middle::span_bug;
use rustc_middle::ty::query::Providers;
-use rustc_middle::ty::{self, DefIdTree, MainDefinition, ResolverOutputs};
+use rustc_middle::ty::{self, DefIdTree, MainDefinition, RegisteredTools, ResolverOutputs};
use rustc_query_system::ich::StableHashingContext;
use rustc_session::cstore::{CrateStore, MetadataLoaderDyn};
use rustc_session::lint;
use smallvec::{smallvec, SmallVec};
use std::cell::{Cell, RefCell};
-use std::collections::{BTreeMap, BTreeSet};
+use std::collections::BTreeSet;
use std::ops::ControlFlow;
use std::{cmp, fmt, iter, mem, ptr};
use tracing::debug;
use late::{ConstantItemKind, HasGenericParams, PathSource, Rib, RibKind::*};
use macros::{MacroRulesBinding, MacroRulesScope, MacroRulesScopeRef};
+use crate::access_levels::AccessLevelsVisitor;
+
type Res = def::Res<NodeId>;
+mod access_levels;
mod build_reduced_graph;
mod check_unused;
mod def_collector;
SelfInGenericParamDefault,
/// Error E0767: use of unreachable label
UnreachableLabel { name: Symbol, definition_span: Span, suggestion: Option<LabelSuggestion> },
+ /// Error E0323, E0324, E0325: mismatch between trait item and impl item.
+ TraitImplMismatch {
+ name: Symbol,
+ kind: &'static str,
+ trait_path: String,
+ trait_item_span: Span,
+ code: rustc_errors::DiagnosticId,
+ },
}
enum VisResolutionError<'a> {
}
}
- fn def_id(&self) -> DefId {
+ // Public for rustdoc.
+ pub fn def_id(&self) -> DefId {
self.opt_def_id().expect("`ModuleData::def_id` is called on a block module")
}
/// `CrateNum` resolutions of `extern crate` items.
extern_crate_map: FxHashMap<LocalDefId, CrateNum>,
- export_map: ExportMap,
+ reexport_map: FxHashMap<LocalDefId, Vec<ModChild>>,
trait_map: NodeMap<Vec<TraitCandidate>>,
/// A map from nodes to anonymous modules.
/// language items.
empty_module: Module<'a>,
module_map: FxHashMap<DefId, Module<'a>>,
- binding_parent_modules: FxHashMap<PtrKey<'a, NameBinding<'a>>, Module<'a>>,
+ binding_parent_modules: FxHashMap<Interned<'a, NameBinding<'a>>, Module<'a>>,
underscore_disambiguator: u32,
/// Maps glob imports to the names of items actually imported.
macro_names: FxHashSet<Ident>,
builtin_macros: FxHashMap<Symbol, BuiltinMacroState>,
registered_attrs: FxHashSet<Ident>,
- registered_tools: FxHashSet<Ident>,
+ registered_tools: RegisteredTools,
macro_use_prelude: FxHashMap<Symbol, &'a NameBinding<'a>>,
all_macros: FxHashMap<Symbol, Res>,
macro_map: FxHashMap<DefId, Lrc<SyntaxExtension>>,
item_generics_num_lifetimes: FxHashMap<LocalDefId, usize>,
main_def: Option<MainDefinition>,
- trait_impls: BTreeMap<DefId, Vec<LocalDefId>>,
+ trait_impls: FxIndexMap<DefId, Vec<LocalDefId>>,
/// A list of proc macro LocalDefIds, written out in the order in which
/// they are declared in the static array generated by proc_macro_harness.
proc_macros: Vec<NodeId>,
confused_type_with_std_module: FxHashMap<Span, Span>,
+
+ access_levels: AccessLevels,
}
/// Nothing really interesting here; it just provides memory for the rest of the crate.
self.name_resolutions.alloc(Default::default())
}
fn alloc_macro_rules_scope(&'a self, scope: MacroRulesScope<'a>) -> MacroRulesScopeRef<'a> {
- PtrKey(self.dropless.alloc(Cell::new(scope)))
+ Interned::new_unchecked(self.dropless.alloc(Cell::new(scope)))
}
fn alloc_macro_rules_binding(
&'a self,
import_res_map: Default::default(),
label_res_map: Default::default(),
extern_crate_map: Default::default(),
- export_map: FxHashMap::default(),
+ reexport_map: FxHashMap::default(),
trait_map: NodeMap::default(),
underscore_disambiguator: 0,
empty_module,
trait_impls: Default::default(),
proc_macros: Default::default(),
confused_type_with_std_module: Default::default(),
+ access_levels: Default::default(),
};
let root_parent_scope = ParentScope::module(graph_root, &resolver);
let definitions = self.definitions;
let visibilities = self.visibilities;
let extern_crate_map = self.extern_crate_map;
- let export_map = self.export_map;
+ let reexport_map = self.reexport_map;
let maybe_unused_trait_imports = self.maybe_unused_trait_imports;
let maybe_unused_extern_crates = self.maybe_unused_extern_crates;
let glob_map = self.glob_map;
let main_def = self.main_def;
let confused_type_with_std_module = self.confused_type_with_std_module;
+ let access_levels = self.access_levels;
ResolverOutputs {
definitions,
cstore: Box::new(self.crate_loader.into_cstore()),
visibilities,
+ access_levels,
extern_crate_map,
- export_map,
+ reexport_map,
glob_map,
maybe_unused_trait_imports,
maybe_unused_extern_crates,
trait_impls: self.trait_impls,
proc_macros,
confused_type_with_std_module,
+ registered_tools: self.registered_tools,
}
}
let proc_macros = self.proc_macros.iter().map(|id| self.local_def_id(*id)).collect();
ResolverOutputs {
definitions: self.definitions.clone(),
+ access_levels: self.access_levels.clone(),
cstore: Box::new(self.cstore().clone()),
visibilities: self.visibilities.clone(),
extern_crate_map: self.extern_crate_map.clone(),
- export_map: self.export_map.clone(),
+ reexport_map: self.reexport_map.clone(),
glob_map: self.glob_map.clone(),
maybe_unused_trait_imports: self.maybe_unused_trait_imports.clone(),
maybe_unused_extern_crates: self.maybe_unused_extern_crates.clone(),
trait_impls: self.trait_impls.clone(),
proc_macros,
confused_type_with_std_module: self.confused_type_with_std_module.clone(),
+ registered_tools: self.registered_tools.clone(),
}
}
pub fn resolve_crate(&mut self, krate: &Crate) {
self.session.time("resolve_crate", || {
self.session.time("finalize_imports", || ImportResolver { r: self }.finalize_imports());
+ self.session.time("resolve_access_levels", || {
+ AccessLevelsVisitor::compute_access_levels(self, krate)
+ });
self.session.time("finalize_macro_resolutions", || self.finalize_macro_resolutions());
self.session.time("late_resolve_crate", || self.late_resolve_crate(krate));
self.session.time("resolve_main", || self.resolve_main());
return Res::Err;
}
}
- Res::Def(DefKind::TyParam, _) | Res::SelfTy(..) => {
+ Res::Def(DefKind::TyParam, _) | Res::SelfTy { .. } => {
for rib in ribs {
let has_generic_params: HasGenericParams = match rib.kind {
NormalRibKind
// HACK(min_const_generics): If we encounter `Self` in an anonymous constant
// we can't easily tell if it's generic at this stage, so we instead remember
// this and then enforce the self type to be concrete later on.
- if let Res::SelfTy(trait_def, Some((impl_def, _))) = res {
- res = Res::SelfTy(trait_def, Some((impl_def, true)));
+ if let Res::SelfTy { trait_, alias_to: Some((def, _)) } = res {
+ res = Res::SelfTy { trait_, alias_to: Some((def, true)) }
} else {
if record_used {
self.report_error(
}
fn set_binding_parent_module(&mut self, binding: &'a NameBinding<'a>, module: Module<'a>) {
- if let Some(old_module) = self.binding_parent_modules.insert(PtrKey(binding), module) {
+ if let Some(old_module) =
+ self.binding_parent_modules.insert(Interned::new_unchecked(binding), module)
+ {
if !ptr::eq(module, old_module) {
span_bug!(binding.span, "parent module is reset for binding");
}
// is disambiguated to mitigate regressions from macro modularization.
// Scoping for `macro_rules` behaves like scoping for `let` at module level, in general.
match (
- self.binding_parent_modules.get(&PtrKey(macro_rules)),
- self.binding_parent_modules.get(&PtrKey(modularized)),
+ self.binding_parent_modules.get(&Interned::new_unchecked(macro_rules)),
+ self.binding_parent_modules.get(&Interned::new_unchecked(modularized)),
) {
(Some(macro_rules), Some(modularized)) => {
macro_rules.nearest_parent_mod() == modularized.nearest_parent_mod()
&self.all_macros
}
+ /// For rustdoc.
+ /// For local modules returns only reexports, for external modules returns all children.
+ pub fn module_children_or_reexports(&self, def_id: DefId) -> Vec<ModChild> {
+ if let Some(def_id) = def_id.as_local() {
+ self.reexport_map.get(&def_id).cloned().unwrap_or_default()
+ } else {
+ self.cstore().module_children_untracked(def_id, self.session)
+ }
+ }
+
/// Retrieves the span of the given `DefId` if `DefId` is in the local crate.
#[inline]
pub fn opt_span(&self, def_id: DefId) -> Option<Span> {
let attr = self
.cstore()
.item_attrs_untracked(def_id, self.session)
- .into_iter()
.find(|a| a.has_name(sym::rustc_legacy_const_generics))?;
let mut ret = Vec::new();
for meta in attr.meta_item_list()? {