Skip to content

Commit 51eb5ed

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 8e77954 commit 51eb5ed

File tree

4 files changed

+13
-28
lines changed

4 files changed

+13
-28
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
@@ -469,7 +469,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
469469
let parent_scope = &ParentScope { derives: &[], ..*parent_scope };
470470
match this.reborrow().resolve_macro_path(
471471
derive,
472-
Some(MacroKind::Derive),
472+
MacroKind::Derive,
473473
parent_scope,
474474
true,
475475
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: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ impl<'ra, 'tcx> ResolverExpand for Resolver<'ra, 'tcx> {
398398
resolution.exts = Some(
399399
match self.cm().resolve_macro_path(
400400
&resolution.path,
401-
Some(MacroKind::Derive),
401+
MacroKind::Derive,
402402
&parent_scope,
403403
true,
404404
force,
@@ -563,7 +563,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
563563
) -> Result<(Arc<SyntaxExtension>, Res), Indeterminate> {
564564
let (ext, res) = match self.cm().resolve_macro_or_delegation_path(
565565
path,
566-
Some(kind),
566+
kind,
567567
parent_scope,
568568
true,
569569
force,
@@ -710,7 +710,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
710710
pub(crate) fn resolve_macro_path<'r>(
711711
self: CmResolver<'r, 'ra, 'tcx>,
712712
path: &ast::Path,
713-
kind: Option<MacroKind>,
713+
kind: MacroKind,
714714
parent_scope: &ParentScope<'ra>,
715715
trace: bool,
716716
force: bool,
@@ -733,7 +733,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
733733
fn resolve_macro_or_delegation_path<'r>(
734734
mut self: CmResolver<'r, 'ra, 'tcx>,
735735
ast_path: &ast::Path,
736-
kind: Option<MacroKind>,
736+
kind: MacroKind,
737737
parent_scope: &ParentScope<'ra>,
738738
trace: bool,
739739
force: bool,
@@ -747,7 +747,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
747747

748748
// Possibly apply the macro helper hack
749749
if deleg_impl.is_none()
750-
&& kind == Some(MacroKind::Bang)
750+
&& kind == MacroKind::Bang
751751
&& let [segment] = path.as_slice()
752752
&& segment.ident.span.ctxt().outer_expn_data().local_inner_macros
753753
{
@@ -775,7 +775,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
775775
};
776776

777777
if trace {
778-
let kind = kind.expect("macro kind must be specified if tracing is enabled");
779778
// FIXME: Should be an output of Speculative Resolution.
780779
self.multi_segment_macro_resolutions.borrow_mut().push((
781780
path,
@@ -790,10 +789,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
790789
self.prohibit_imported_non_macro_attrs(None, res.ok(), path_span);
791790
res
792791
} else {
793-
let scope_set = kind.map_or(ScopeSet::All(MacroNS), ScopeSet::Macro);
794792
let binding = self.reborrow().early_resolve_ident_in_lexical_scope(
795793
path[0].ident,
796-
scope_set,
794+
ScopeSet::Macro(kind),
797795
parent_scope,
798796
None,
799797
force,
@@ -805,7 +803,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
805803
}
806804

807805
if trace {
808-
let kind = kind.expect("macro kind must be specified if tracing is enabled");
809806
// FIXME: Should be an output of Speculative Resolution.
810807
self.single_segment_macro_resolutions.borrow_mut().push((
811808
path[0].ident,

0 commit comments

Comments
 (0)