Skip to content

Commit 32c0a85

Browse files
committed
resolve: Pass a normalized ident to resolve_ident_in_scope
In practice it was already normalized because `visit_scopes` normalized it
1 parent f1c45dd commit 32c0a85

2 files changed

Lines changed: 12 additions & 23 deletions

File tree

compiler/rustc_resolve/src/ident.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -434,12 +434,14 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
434434
orig_ident.span.ctxt(),
435435
derive_fallback_lint_id,
436436
|this, scope, use_prelude, ctxt| {
437+
let ident = Ident::new(orig_ident.name, orig_ident.span.with_ctxt(ctxt));
438+
// The passed `ctxt` is already normalized, so avoid expensive double normalization.
439+
let ident = Macros20NormalizedIdent(ident);
437440
let res = match this.reborrow().resolve_ident_in_scope(
438-
orig_ident,
441+
ident,
439442
ns,
440443
scope,
441444
use_prelude,
442-
ctxt,
443445
scope_set,
444446
parent_scope,
445447
// Shadowed bindings don't need to be marked as used or non-speculatively loaded.
@@ -508,20 +510,17 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
508510

509511
fn resolve_ident_in_scope<'r>(
510512
mut self: CmResolver<'r, 'ra, 'tcx>,
511-
orig_ident: Ident,
513+
ident: Macros20NormalizedIdent,
512514
ns: Namespace,
513515
scope: Scope<'ra>,
514516
use_prelude: UsePrelude,
515-
ctxt: SyntaxContext,
516517
scope_set: ScopeSet<'ra>,
517518
parent_scope: &ParentScope<'ra>,
518519
finalize: Option<Finalize>,
519520
force: bool,
520521
ignore_binding: Option<NameBinding<'ra>>,
521522
ignore_import: Option<Import<'ra>>,
522523
) -> Result<NameBinding<'ra>, ControlFlow<Determinacy, Determinacy>> {
523-
let unnorm_ident = Ident::new(orig_ident.name, orig_ident.span.with_ctxt(ctxt));
524-
let ident = Macros20NormalizedIdent::new(unnorm_ident);
525524
let ret = match scope {
526525
Scope::DeriveHelpers(expn_id) => {
527526
if let Some(binding) = self.helper_attrs.get(&expn_id).and_then(|attrs| {
@@ -600,11 +599,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
600599
self.get_mut().lint_buffer.buffer_lint(
601600
PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
602601
lint_id,
603-
orig_ident.span,
602+
ident.span,
604603
errors::ProcMacroDeriveResolutionFallback {
605-
span: orig_ident.span,
604+
span: ident.span,
606605
ns_descr: ns.descr(),
607-
ident: unnorm_ident,
606+
ident: ident.0,
608607
},
609608
);
610609
}
@@ -650,11 +649,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
650649
self.get_mut().lint_buffer.buffer_lint(
651650
PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
652651
lint_id,
653-
orig_ident.span,
652+
ident.span,
654653
errors::ProcMacroDeriveResolutionFallback {
655-
span: orig_ident.span,
654+
span: ident.span,
656655
ns_descr: ns.descr(),
657-
ident: unnorm_ident,
656+
ident: ident.0,
658657
},
659658
);
660659
}
@@ -700,7 +699,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
700699
let mut result = Err(Determinacy::Determined);
701700
if let Some(prelude) = self.prelude
702701
&& let Ok(binding) = self.reborrow().resolve_ident_in_scope_set(
703-
unnorm_ident,
702+
ident.0,
704703
ScopeSet::Module(ns, prelude),
705704
parent_scope,
706705
None,

tests/ui/proc-macro/generate-mod.stderr

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ LL | #[derive(generate_mod::CheckDerive)]
4747
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
4848
= note: for more information, see issue #83583 <https://github.com/rust-lang/rust/issues/83583>
4949
= note: `#[deny(proc_macro_derive_resolution_fallback)]` (part of `#[deny(future_incompatible)]`) on by default
50-
= note: this error originates in the derive macro `generate_mod::CheckDerive` (in Nightly builds, run with -Z macro-backtrace for more info)
5150

5251
error: cannot find type `OuterDerive` in this scope
5352
--> $DIR/generate-mod.rs:18:10
@@ -57,7 +56,6 @@ LL | #[derive(generate_mod::CheckDerive)]
5756
|
5857
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
5958
= note: for more information, see issue #83583 <https://github.com/rust-lang/rust/issues/83583>
60-
= note: this error originates in the derive macro `generate_mod::CheckDerive` (in Nightly builds, run with -Z macro-backtrace for more info)
6159

6260
error: cannot find type `FromOutside` in this scope
6361
--> $DIR/generate-mod.rs:25:14
@@ -67,7 +65,6 @@ LL | #[derive(generate_mod::CheckDerive)]
6765
|
6866
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
6967
= note: for more information, see issue #83583 <https://github.com/rust-lang/rust/issues/83583>
70-
= note: this error originates in the derive macro `generate_mod::CheckDerive` (in Nightly builds, run with -Z macro-backtrace for more info)
7168

7269
error: cannot find type `OuterDerive` in this scope
7370
--> $DIR/generate-mod.rs:25:14
@@ -77,7 +74,6 @@ LL | #[derive(generate_mod::CheckDerive)]
7774
|
7875
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
7976
= note: for more information, see issue #83583 <https://github.com/rust-lang/rust/issues/83583>
80-
= note: this error originates in the derive macro `generate_mod::CheckDerive` (in Nightly builds, run with -Z macro-backtrace for more info)
8177

8278
error: aborting due to 8 previous errors
8379

@@ -92,7 +88,6 @@ LL | #[derive(generate_mod::CheckDerive)]
9288
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
9389
= note: for more information, see issue #83583 <https://github.com/rust-lang/rust/issues/83583>
9490
= note: `#[deny(proc_macro_derive_resolution_fallback)]` (part of `#[deny(future_incompatible)]`) on by default
95-
= note: this error originates in the derive macro `generate_mod::CheckDerive` (in Nightly builds, run with -Z macro-backtrace for more info)
9691

9792
Future breakage diagnostic:
9893
error: cannot find type `OuterDerive` in this scope
@@ -104,7 +99,6 @@ LL | #[derive(generate_mod::CheckDerive)]
10499
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
105100
= note: for more information, see issue #83583 <https://github.com/rust-lang/rust/issues/83583>
106101
= note: `#[deny(proc_macro_derive_resolution_fallback)]` (part of `#[deny(future_incompatible)]`) on by default
107-
= note: this error originates in the derive macro `generate_mod::CheckDerive` (in Nightly builds, run with -Z macro-backtrace for more info)
108102

109103
Future breakage diagnostic:
110104
error: cannot find type `FromOutside` in this scope
@@ -116,7 +110,6 @@ LL | #[derive(generate_mod::CheckDerive)]
116110
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
117111
= note: for more information, see issue #83583 <https://github.com/rust-lang/rust/issues/83583>
118112
= note: `#[deny(proc_macro_derive_resolution_fallback)]` (part of `#[deny(future_incompatible)]`) on by default
119-
= note: this error originates in the derive macro `generate_mod::CheckDerive` (in Nightly builds, run with -Z macro-backtrace for more info)
120113

121114
Future breakage diagnostic:
122115
error: cannot find type `OuterDerive` in this scope
@@ -128,7 +121,6 @@ LL | #[derive(generate_mod::CheckDerive)]
128121
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
129122
= note: for more information, see issue #83583 <https://github.com/rust-lang/rust/issues/83583>
130123
= note: `#[deny(proc_macro_derive_resolution_fallback)]` (part of `#[deny(future_incompatible)]`) on by default
131-
= note: this error originates in the derive macro `generate_mod::CheckDerive` (in Nightly builds, run with -Z macro-backtrace for more info)
132124

133125
Future breakage diagnostic:
134126
warning: cannot find type `FromOutside` in this scope
@@ -139,7 +131,6 @@ LL | #[derive(generate_mod::CheckDeriveLint)] // OK, lint is suppressed
139131
|
140132
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
141133
= note: for more information, see issue #83583 <https://github.com/rust-lang/rust/issues/83583>
142-
= note: this warning originates in the derive macro `generate_mod::CheckDeriveLint` (in Nightly builds, run with -Z macro-backtrace for more info)
143134

144135
Future breakage diagnostic:
145136
warning: cannot find type `OuterDeriveLint` in this scope
@@ -150,5 +141,4 @@ LL | #[derive(generate_mod::CheckDeriveLint)] // OK, lint is suppressed
150141
|
151142
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
152143
= note: for more information, see issue #83583 <https://github.com/rust-lang/rust/issues/83583>
153-
= note: this warning originates in the derive macro `generate_mod::CheckDeriveLint` (in Nightly builds, run with -Z macro-backtrace for more info)
154144

0 commit comments

Comments
 (0)