Skip to content

Commit 581051e

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 8e77954 commit 581051e

File tree

10 files changed

+12
-15
lines changed

10 files changed

+12
-15
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
@@ -505,14 +505,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
505505
_ => Err(Determinacy::Determined),
506506
},
507507
Scope::Module(module, derive_fallback_lint_id) => {
508-
// FIXME: use `finalize_scope` here.
509508
let (adjusted_parent_scope, adjusted_finalize) =
510509
if matches!(scope_set, ScopeSet::ModuleAndExternPrelude(..)) {
511-
(parent_scope, finalize)
510+
(parent_scope, finalize_scope!())
512511
} else {
513512
(
514513
&ParentScope { module, ..*parent_scope },
515-
finalize.map(|f| Finalize { used: Used::Scope, ..f }),
514+
finalize_scope!().map(|f| Finalize { used: Used::Scope, ..f }),
516515
)
517516
};
518517
let binding = this.reborrow().resolve_ident_in_module_unadjusted(
@@ -574,8 +573,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
574573
None => Err(Determinacy::Determined),
575574
},
576575
Scope::ExternPreludeItems => {
577-
// FIXME: use `finalize_scope` here.
578-
match this.reborrow().extern_prelude_get_item(ident, finalize.is_some()) {
576+
match this
577+
.reborrow()
578+
.extern_prelude_get_item(ident, finalize_scope!().is_some())
579+
{
579580
Some(binding) => Ok((binding, Flags::empty())),
580581
None => Err(Determinacy::determined(
581582
this.graph_root.unexpanded_invocations.borrow().is_empty(),

library/alloctests/tests/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
#![deny(unsafe_op_in_unsafe_fn)]
4848

4949
extern crate alloc;
50-
extern crate test;
5150

5251
use std::hash::{DefaultHasher, Hash, Hasher};
5352

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]

0 commit comments

Comments
 (0)