Skip to content

Commit 81acd32

Browse files
committed
resolve: Do not finalize shadowed bindings
I.e. do not mark them as used, or non-speculative loaded, or similar. Previously they were sometimes finalized during early resolution, causing issues like rust-lang#144793 (comment).
1 parent 7cfd7d3 commit 81acd32

File tree

11 files changed

+39
-14
lines changed

11 files changed

+39
-14
lines changed

compiler/rustc_macros/src/query.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use syn::punctuated::Punctuated;
55
use syn::spanned::Spanned;
66
use syn::{
77
AttrStyle, Attribute, Block, Error, Expr, Ident, Pat, ReturnType, Token, Type, braced,
8-
parenthesized, parse_macro_input, parse_quote, token,
8+
parenthesized, parse_macro_input, token,
99
};
1010

1111
mod kw {

compiler/rustc_resolve/src/ident.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -492,14 +492,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
492492
_ => Err(Determinacy::Determined),
493493
},
494494
Scope::Module(module, derive_fallback_lint_id) => {
495-
// FIXME: use `finalize_scope` here.
496495
let (adjusted_parent_scope, adjusted_finalize) =
497496
if matches!(scope_set, ScopeSet::ModuleAndExternPrelude(..)) {
498-
(parent_scope, finalize)
497+
(parent_scope, finalize_scope!())
499498
} else {
500499
(
501500
&ParentScope { module, ..*parent_scope },
502-
finalize.map(|f| Finalize { used: Used::Scope, ..f }),
501+
finalize_scope!().map(|f| Finalize { used: Used::Scope, ..f }),
503502
)
504503
};
505504
let binding = this.reborrow().resolve_ident_in_module_unadjusted(
@@ -557,8 +556,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
557556
None => Err(Determinacy::Determined),
558557
},
559558
Scope::ExternPreludeItems => {
560-
// FIXME: use `finalize_scope` here.
561-
match this.reborrow().extern_prelude_get_item(ident, finalize.is_some()) {
559+
match this
560+
.reborrow()
561+
.extern_prelude_get_item(ident, finalize_scope!().is_some())
562+
{
562563
Some(binding) => {
563564
extern_prelude_item_binding = Some(binding);
564565
Ok((binding, Flags::empty()))

library/std/src/sys/pal/unix/stack_overflow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ mod imp {
7272
use crate::sync::OnceLock;
7373
use crate::sync::atomic::{Atomic, AtomicBool, AtomicPtr, AtomicUsize, Ordering};
7474
use crate::sys::pal::unix::os;
75-
use crate::{io, mem, panic, ptr};
75+
use crate::{io, mem, ptr};
7676

7777
// Signal handler for the SIGSEGV and SIGBUS handlers. We've got guard pages
7878
// (unmapped pages) at the end of every thread's stack, so if a thread ends

src/tools/clippy/tests/ui/useless_attribute.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ pub mod redundant_imports_issue {
153153
() => {};
154154
}
155155

156-
#[expect(redundant_imports)]
156+
#[expect(unused_imports)]
157157
pub(crate) use empty;
158158

159159
empty!();

src/tools/clippy/tests/ui/useless_attribute.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ pub mod redundant_imports_issue {
153153
() => {};
154154
}
155155

156-
#[expect(redundant_imports)]
156+
#[expect(unused_imports)]
157157
pub(crate) use empty;
158158

159159
empty!();

src/tools/rust-analyzer/crates/hir-expand/src/builtin/derive_macro.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use tracing::debug;
1212

1313
use crate::{
1414
ExpandError, ExpandResult, MacroCallId,
15-
builtin::quote::{dollar_crate, quote},
15+
builtin::quote::dollar_crate,
1616
db::ExpandDatabase,
1717
hygiene::span_with_def_site_ctxt,
1818
name::{self, AsName, Name},

src/tools/rust-analyzer/crates/hir-expand/src/builtin/fn_macro.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use syntax_bridge::syntax_node_to_token_tree;
1919

2020
use crate::{
2121
EditionedFileId, ExpandError, ExpandResult, Lookup as _, MacroCallId,
22-
builtin::quote::{WithDelimiter, dollar_crate, quote},
22+
builtin::quote::{WithDelimiter, dollar_crate},
2323
db::ExpandDatabase,
2424
hygiene::{span_with_call_site_ctxt, span_with_def_site_ctxt},
2525
name,

src/tools/rust-analyzer/crates/hir-expand/src/builtin/quote.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,6 @@ mod tests {
229229
use span::{Edition, ROOT_ERASED_FILE_AST_ID, SpanAnchor, SyntaxContext};
230230
use syntax::{TextRange, TextSize};
231231

232-
use super::quote;
233-
234232
const DUMMY: tt::Span = tt::Span {
235233
range: TextRange::empty(TextSize::new(0)),
236234
anchor: SpanAnchor {

src/tools/rustfmt/src/config/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,6 @@ mod test {
516516
#[allow(dead_code)]
517517
mod mock {
518518
use super::super::*;
519-
use crate::config_option_with_style_edition_default;
520519
use rustfmt_config_proc_macro::config_type;
521520

522521
#[config_type]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@ check-pass
2+
3+
#![warn(unused_imports)]
4+
5+
#[macro_export]
6+
macro_rules! mac { () => {} }
7+
8+
fn main() {
9+
// Unused, `mac` as `macro_rules!` is already in scope and has higher priority.
10+
use crate::mac; //~ WARN unused import: `crate::mac`
11+
12+
mac!();
13+
}

0 commit comments

Comments
 (0)