#![feature(drain_filter)]
#![feature(bool_to_option)]
#![feature(crate_visibility_modifier)]
-#![feature(format_args_capture)]
+#![cfg_attr(bootstrap, feature(format_args_capture))]
#![feature(iter_zip)]
+#![feature(let_else)]
#![feature(never_type)]
#![feature(nll)]
#![recursion_limit = "256"]
use rustc_middle::span_bug;
use rustc_middle::ty::query::Providers;
use rustc_middle::ty::{self, DefIdTree, MainDefinition, ResolverOutputs};
+use rustc_query_system::ich::StableHashingContext;
use rustc_session::cstore::{CrateStore, MetadataLoaderDyn};
use rustc_session::lint;
use rustc_session::lint::{BuiltinLintDiagnostics, LintBuffer};
use rustc_session::Session;
use rustc_span::edition::Edition;
use rustc_span::hygiene::{ExpnId, ExpnKind, LocalExpnId, MacroKind, SyntaxContext, Transparency};
-use rustc_span::source_map::{CachingSourceMapView, Spanned};
+use rustc_span::source_map::Spanned;
use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::{Span, DUMMY_SP};
impl AmbiguityKind {
fn descr(self) -> &'static str {
match self {
- AmbiguityKind::Import => "name vs any other name during import resolution",
- AmbiguityKind::BuiltinAttr => "built-in attribute vs any other name",
- AmbiguityKind::DeriveHelper => "derive helper attribute vs any other name",
+ AmbiguityKind::Import => "multiple potential import sources",
+ AmbiguityKind::BuiltinAttr => "a name conflict with a builtin attribute",
+ AmbiguityKind::DeriveHelper => "a name conflict with a derive helper attribute",
AmbiguityKind::MacroRulesVsModularized => {
- "`macro_rules` vs non-`macro_rules` from other module"
+ "a conflict between a `macro_rules` name and a non-`macro_rules` name from another module"
}
AmbiguityKind::GlobVsOuter => {
- "glob import vs any other name from outer scope during import/macro resolution"
+ "a conflict between a name from a glob import and an outer scope during import or macro resolution"
}
- AmbiguityKind::GlobVsGlob => "glob import vs glob import in the same module",
+ AmbiguityKind::GlobVsGlob => "multiple glob imports of a name in the same module",
AmbiguityKind::GlobVsExpanded => {
- "glob import vs macro-expanded name in the same \
- module during import/macro resolution"
+ "a conflict between a name from a glob import and a macro-expanded name in the same module during import or macro resolution"
}
AmbiguityKind::MoreExpandedVsOuter => {
- "macro-expanded name vs less macro-expanded name \
- from outer scope during import/macro resolution"
+ "a conflict between a macro-expanded name and a less macro-expanded name from outer scope during import or macro resolution"
}
}
}
/// `CrateNum` resolutions of `extern crate` items.
extern_crate_map: FxHashMap<LocalDefId, CrateNum>,
export_map: ExportMap,
- trait_map: Option<NodeMap<Vec<TraitCandidate>>>,
+ trait_map: NodeMap<Vec<TraitCandidate>>,
/// A map from nodes to anonymous modules.
/// Anonymous modules are pseudo-modules that are implicitly created around items
non_macro_attr: Lrc<SyntaxExtension>,
local_macro_def_scopes: FxHashMap<LocalDefId, Module<'a>>,
ast_transform_scopes: FxHashMap<LocalExpnId, Module<'a>>,
- unused_macros: FxHashMap<LocalDefId, (NodeId, Span)>,
+ unused_macros: FxHashMap<LocalDefId, (NodeId, Ident)>,
proc_macro_stubs: FxHashSet<LocalDefId>,
/// Traces collected during macro resolution and validated when it's complete.
single_segment_macro_resolutions:
&mut self.definitions
}
+ fn create_stable_hashing_context(&self) -> StableHashingContext<'_> {
+ StableHashingContext::new(self.session, &self.definitions, self.crate_loader.cstore())
+ }
+
fn lint_buffer(&mut self) -> &mut LintBuffer {
&mut self.lint_buffer
}
self.next_node_id()
}
- fn take_trait_map(&mut self) -> NodeMap<Vec<TraitCandidate>> {
- std::mem::replace(&mut self.trait_map, None).unwrap()
+ fn take_trait_map(&mut self, node: NodeId) -> Option<Vec<TraitCandidate>> {
+ self.trait_map.remove(&node)
}
fn opt_local_def_id(&self, node: NodeId) -> Option<LocalDefId> {
}
}
-struct ExpandHasher<'a, 'b> {
- source_map: CachingSourceMapView<'a>,
- resolver: &'a Resolver<'b>,
-}
-
-impl<'a, 'b> rustc_span::HashStableContext for ExpandHasher<'a, 'b> {
- #[inline]
- fn hash_spans(&self) -> bool {
- true
- }
-
- #[inline]
- fn def_span(&self, id: LocalDefId) -> Span {
- self.resolver.def_span(id)
- }
-
- #[inline]
- fn def_path_hash(&self, def_id: DefId) -> DefPathHash {
- self.resolver.def_path_hash(def_id)
- }
-
- #[inline]
- fn span_data_to_lines_and_cols(
- &mut self,
- span: &rustc_span::SpanData,
- ) -> Option<(Lrc<rustc_span::SourceFile>, usize, rustc_span::BytePos, usize, rustc_span::BytePos)>
- {
- self.source_map.span_data_to_lines_and_cols(span)
- }
-}
-
impl<'a> Resolver<'a> {
pub fn new(
session: &'a Session,
label_res_map: Default::default(),
extern_crate_map: Default::default(),
export_map: FxHashMap::default(),
- trait_map: Some(NodeMap::default()),
+ trait_map: NodeMap::default(),
underscore_disambiguator: 0,
empty_module,
module_map,
self.arenas.new_module(parent, kind, expn_id, span, no_implicit_prelude, module_map)
}
- fn create_stable_hashing_context(&self) -> ExpandHasher<'_, 'a> {
- ExpandHasher {
- source_map: CachingSourceMapView::new(self.session.source_map()),
- resolver: self,
- }
- }
-
pub fn next_node_id(&mut self) -> NodeId {
let next = self
.next_node_id
} else {
(
format!("use of undeclared crate or module `{}`", ident),
- self.find_similarly_named_module_or_crate(
- ident.name,
- &parent_scope.module,
- )
- .map(|sugg| {
- (
- vec![(ident.span, sugg.to_string())],
+ if ident.name == sym::alloc {
+ Some((
+ vec![],
String::from(
- "there is a crate or module with a similar name",
+ "add `extern crate alloc` to use the `alloc` crate",
),
Applicability::MaybeIncorrect,
+ ))
+ } else {
+ self.find_similarly_named_module_or_crate(
+ ident.name,
+ &parent_scope.module,
)
- }),
+ .map(|sugg| {
+ (
+ vec![(ident.span, sugg.to_string())],
+ String::from(
+ "there is a crate or module with a similar name",
+ ),
+ Applicability::MaybeIncorrect,
+ )
+ })
+ },
)
}
} else {