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
5 changes: 4 additions & 1 deletion compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ use rustc_span::edit_distance::find_best_match_for_name;
use rustc_span::edition::Edition;
use rustc_span::hygiene::MacroKind;
use rustc_span::source_map::{SourceMap, Spanned};
use rustc_span::{BytePos, Ident, Macros20NormalizedIdent, Span, Symbol, SyntaxContext, kw, sym};
use rustc_span::{
BytePos, DUMMY_SP, Ident, Macros20NormalizedIdent, Span, Symbol, SyntaxContext, kw, sym,
};
use thin_vec::{ThinVec, thin_vec};
use tracing::{debug, instrument};

Expand Down Expand Up @@ -1179,6 +1181,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
ctxt: SyntaxContext,
filter_fn: &impl Fn(Res) -> bool,
) {
let ctxt = DUMMY_SP.with_ctxt(ctxt);
self.cm().visit_scopes(scope_set, ps, ctxt, None, |this, scope, use_prelude, _| {
match scope {
Scope::DeriveHelpers(expn_id) => {
Expand Down
19 changes: 11 additions & 8 deletions compiler/rustc_resolve/src/ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
mut self: CmResolver<'r, 'ra, 'tcx>,
scope_set: ScopeSet<'ra>,
parent_scope: &ParentScope<'ra>,
orig_ctxt: SyntaxContext,
// Location of the span is not significant, but pass a `Span` instead of `SyntaxContext`
// to avoid extracting and re-packaging the syntax context unnecessarily.
orig_ctxt: Span,
derive_fallback_lint_id: Option<NodeId>,
mut visitor: impl FnMut(
&mut CmResolver<'r, 'ra, 'tcx>,
Scope<'ra>,
UsePrelude,
SyntaxContext,
Span,
) -> ControlFlow<T>,
) -> Option<T> {
// General principles:
Expand Down Expand Up @@ -238,11 +240,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
fn hygienic_lexical_parent(
&self,
module: Module<'ra>,
ctxt: &mut SyntaxContext,
span: &mut Span,
derive_fallback_lint_id: Option<NodeId>,
) -> Option<(Module<'ra>, Option<NodeId>)> {
if !module.expansion.outer_expn_is_descendant_of(*ctxt) {
return Some((self.expn_def_scope(ctxt.remove_mark()), None));
let ctxt = span.ctxt();
if !module.expansion.outer_expn_is_descendant_of(ctxt) {
return Some((self.expn_def_scope(span.remove_mark()), None));
}

if let ModuleKind::Block = module.kind {
Expand Down Expand Up @@ -272,7 +275,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
let ext = &self.get_macro_by_def_id(def_id).ext;
if ext.builtin_name.is_none()
&& ext.macro_kinds() == MacroKinds::DERIVE
&& parent.expansion.outer_expn_is_descendant_of(*ctxt)
&& parent.expansion.outer_expn_is_descendant_of(ctxt)
{
return Some((parent, derive_fallback_lint_id));
}
Expand Down Expand Up @@ -433,10 +436,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
let break_result = self.visit_scopes(
scope_set,
parent_scope,
orig_ident.span.ctxt(),
orig_ident.span,
derive_fallback_lint_id,
|this, scope, use_prelude, ctxt| {
let ident = Ident::new(orig_ident.name, orig_ident.span.with_ctxt(ctxt));
let ident = Ident::new(orig_ident.name, ctxt);
// The passed `ctxt` is already normalized, so avoid expensive double normalization.
let ident = Macros20NormalizedIdent(ident);
let res = match this.reborrow().resolve_ident_in_scope(
Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ use rustc_session::config::{CrateType, ResolveDocLinks};
use rustc_session::lint;
use rustc_session::parse::feature_err;
use rustc_span::source_map::{Spanned, respan};
use rustc_span::{
BytePos, DUMMY_SP, Ident, Macros20NormalizedIdent, Span, Symbol, SyntaxContext, kw, sym,
};
use rustc_span::{BytePos, DUMMY_SP, Ident, Macros20NormalizedIdent, Span, Symbol, kw, sym};
use smallvec::{SmallVec, smallvec};
use thin_vec::ThinVec;
use tracing::{debug, instrument, trace};
Expand Down Expand Up @@ -5224,7 +5222,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
self.r.traits_in_scope(
self.current_trait_ref.as_ref().map(|(module, _)| *module),
&self.parent_scope,
ident.span.ctxt(),
ident.span,
Some((ident.name, ns)),
)
}
Expand Down Expand Up @@ -5323,7 +5321,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
.entry(self.parent_scope.module.nearest_parent_mod().expect_local())
.or_insert_with(|| {
self.r
.traits_in_scope(None, &self.parent_scope, SyntaxContext::root(), None)
.traits_in_scope(None, &self.parent_scope, DUMMY_SP, None)
.into_iter()
.filter_map(|tr| {
if self.is_invalid_proc_macro_item_for_doc(tr.def_id) {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1918,7 +1918,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
&mut self,
current_trait: Option<Module<'ra>>,
parent_scope: &ParentScope<'ra>,
ctxt: SyntaxContext,
ctxt: Span,
assoc_item: Option<(Symbol, Namespace)>,
) -> Vec<TraitCandidate> {
let mut found_traits = Vec::new();
Expand Down
Loading