Skip to content

Commit 60dc66f

Browse files
committed
resolve: Do not call resolve_macro_path from late resolution
`maybe_resolve_path` is less precise in corner cases, but it's only used for diagnostics and error recovery, so it's good enough.
1 parent f5b8a11 commit 60dc66f

File tree

4 files changed

+14
-29
lines changed

4 files changed

+14
-29
lines changed

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
10471047
let parent_scope = &ParentScope { derives: &[], ..*parent_scope };
10481048
let Ok((Some(ext), _)) = this.reborrow().resolve_macro_path(
10491049
derive,
1050-
Some(MacroKind::Derive),
1050+
MacroKind::Derive,
10511051
parent_scope,
10521052
false,
10531053
false,

compiler/rustc_resolve/src/ident.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
458458
let parent_scope = &ParentScope { derives: &[], ..*parent_scope };
459459
match this.reborrow().resolve_macro_path(
460460
derive,
461-
Some(MacroKind::Derive),
461+
MacroKind::Derive,
462462
parent_scope,
463463
true,
464464
force,

compiler/rustc_resolve/src/late.rs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4315,7 +4315,6 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
43154315
qself,
43164316
path,
43174317
ns,
4318-
path_span,
43194318
source.defer_to_typeck(),
43204319
finalize,
43214320
source,
@@ -4438,7 +4437,6 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
44384437
qself: &Option<Box<QSelf>>,
44394438
path: &[Segment],
44404439
primary_ns: Namespace,
4441-
span: Span,
44424440
defer_to_typeck: bool,
44434441
finalize: Finalize,
44444442
source: PathSource<'_, 'ast, 'ra>,
@@ -4463,21 +4461,11 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
44634461
}
44644462

44654463
assert!(primary_ns != MacroNS);
4466-
4467-
if qself.is_none() {
4468-
let path_seg = |seg: &Segment| PathSegment::from_ident(seg.ident);
4469-
let path = Path { segments: path.iter().map(path_seg).collect(), span, tokens: None };
4470-
if let Ok((_, res)) = self.r.cm().resolve_macro_path(
4471-
&path,
4472-
None,
4473-
&self.parent_scope,
4474-
false,
4475-
false,
4476-
None,
4477-
None,
4478-
) {
4479-
return Ok(Some(PartialRes::new(res)));
4480-
}
4464+
if qself.is_none()
4465+
&& let PathResult::NonModule(res) =
4466+
self.r.cm().maybe_resolve_path(path, Some(MacroNS), &self.parent_scope, None)
4467+
{
4468+
return Ok(Some(res));
44814469
}
44824470

44834471
Ok(fin_res)

compiler/rustc_resolve/src/macros.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ impl<'ra, 'tcx> ResolverExpand for Resolver<'ra, 'tcx> {
405405
resolution.exts = Some(
406406
match self.cm().resolve_macro_path(
407407
&resolution.path,
408-
Some(MacroKind::Derive),
408+
MacroKind::Derive,
409409
&parent_scope,
410410
true,
411411
force,
@@ -570,7 +570,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
570570
) -> Result<(Arc<SyntaxExtension>, Res), Indeterminate> {
571571
let (ext, res) = match self.cm().resolve_macro_or_delegation_path(
572572
path,
573-
Some(kind),
573+
kind,
574574
parent_scope,
575575
true,
576576
force,
@@ -716,7 +716,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
716716
pub(crate) fn resolve_macro_path<'r>(
717717
self: CmResolver<'r, 'ra, 'tcx>,
718718
path: &ast::Path,
719-
kind: Option<MacroKind>,
719+
kind: MacroKind,
720720
parent_scope: &ParentScope<'ra>,
721721
trace: bool,
722722
force: bool,
@@ -739,7 +739,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
739739
fn resolve_macro_or_delegation_path<'r>(
740740
mut self: CmResolver<'r, 'ra, 'tcx>,
741741
ast_path: &ast::Path,
742-
kind: Option<MacroKind>,
742+
kind: MacroKind,
743743
parent_scope: &ParentScope<'ra>,
744744
trace: bool,
745745
force: bool,
@@ -753,7 +753,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
753753

754754
// Possibly apply the macro helper hack
755755
if deleg_impl.is_none()
756-
&& kind == Some(MacroKind::Bang)
756+
&& kind == MacroKind::Bang
757757
&& let [segment] = path.as_slice()
758758
&& segment.ident.span.ctxt().outer_expn_data().local_inner_macros
759759
{
@@ -781,7 +781,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
781781
};
782782

783783
if trace {
784-
let kind = kind.expect("macro kind must be specified if tracing is enabled");
785784
// FIXME: Should be an output of Speculative Resolution.
786785
self.multi_segment_macro_resolutions.borrow_mut().push((
787786
path,
@@ -796,10 +795,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
796795
self.prohibit_imported_non_macro_attrs(None, res.ok(), path_span);
797796
res
798797
} else {
799-
let scope_set = kind.map_or(ScopeSet::All(MacroNS), ScopeSet::Macro);
800798
let binding = self.reborrow().early_resolve_ident_in_lexical_scope(
801799
path[0].ident,
802-
scope_set,
800+
ScopeSet::Macro(kind),
803801
parent_scope,
804802
None,
805803
force,
@@ -811,7 +809,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
811809
}
812810

813811
if trace {
814-
let kind = kind.expect("macro kind must be specified if tracing is enabled");
815812
// FIXME: Should be an output of Speculative Resolution.
816813
self.single_segment_macro_resolutions.borrow_mut().push((
817814
path[0].ident,
@@ -843,7 +840,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
843840
_ => None,
844841
},
845842
None => self.get_macro(res).map(|macro_data| match kind {
846-
Some(MacroKind::Attr) if let Some(ref ext) = macro_data.attr_ext => Arc::clone(ext),
843+
MacroKind::Attr if let Some(ref ext) = macro_data.attr_ext => Arc::clone(ext),
847844
_ => Arc::clone(&macro_data.ext),
848845
}),
849846
};

0 commit comments

Comments
 (0)