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 https://github.com/rust-lang/rust/pull/144793#issuecomment-3168108005.
This commit is contained in:
parent
6f34f4ee07
commit
f89660e4aa
12 changed files with 39 additions and 15 deletions
|
|
@ -5,7 +5,7 @@ use syn::punctuated::Punctuated;
|
|||
use syn::spanned::Spanned;
|
||||
use syn::{
|
||||
AttrStyle, Attribute, Block, Error, Expr, Ident, Pat, ReturnType, Token, Type, braced,
|
||||
parenthesized, parse_macro_input, parse_quote, token,
|
||||
parenthesized, parse_macro_input, token,
|
||||
};
|
||||
|
||||
mod kw {
|
||||
|
|
|
|||
|
|
@ -492,14 +492,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
_ => Err(Determinacy::Determined),
|
||||
},
|
||||
Scope::Module(module, derive_fallback_lint_id) => {
|
||||
// FIXME: use `finalize_scope` here.
|
||||
let (adjusted_parent_scope, adjusted_finalize) =
|
||||
if matches!(scope_set, ScopeSet::ModuleAndExternPrelude(..)) {
|
||||
(parent_scope, finalize)
|
||||
(parent_scope, finalize_scope!())
|
||||
} else {
|
||||
(
|
||||
&ParentScope { module, ..*parent_scope },
|
||||
finalize.map(|f| Finalize { used: Used::Scope, ..f }),
|
||||
finalize_scope!().map(|f| Finalize { used: Used::Scope, ..f }),
|
||||
)
|
||||
};
|
||||
let binding = this.reborrow().resolve_ident_in_module_unadjusted(
|
||||
|
|
@ -557,8 +556,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
None => Err(Determinacy::Determined),
|
||||
},
|
||||
Scope::ExternPreludeItems => {
|
||||
// FIXME: use `finalize_scope` here.
|
||||
match this.reborrow().extern_prelude_get_item(ident, finalize.is_some()) {
|
||||
match this
|
||||
.reborrow()
|
||||
.extern_prelude_get_item(ident, finalize_scope!().is_some())
|
||||
{
|
||||
Some(binding) => {
|
||||
extern_prelude_item_binding = Some(binding);
|
||||
Ok((binding, Flags::empty()))
|
||||
|
|
|
|||
|
|
@ -46,7 +46,6 @@
|
|||
#![deny(unsafe_op_in_unsafe_fn)]
|
||||
|
||||
extern crate alloc;
|
||||
extern crate test;
|
||||
|
||||
use std::hash::{DefaultHasher, Hash, Hasher};
|
||||
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ mod imp {
|
|||
use crate::sync::OnceLock;
|
||||
use crate::sync::atomic::{Atomic, AtomicBool, AtomicPtr, AtomicUsize, Ordering};
|
||||
use crate::sys::pal::unix::os;
|
||||
use crate::{io, mem, panic, ptr};
|
||||
use crate::{io, mem, ptr};
|
||||
|
||||
// Signal handler for the SIGSEGV and SIGBUS handlers. We've got guard pages
|
||||
// (unmapped pages) at the end of every thread's stack, so if a thread ends
|
||||
|
|
|
|||
|
|
@ -153,7 +153,7 @@ pub mod redundant_imports_issue {
|
|||
() => {};
|
||||
}
|
||||
|
||||
#[expect(redundant_imports)]
|
||||
#[expect(unused_imports)]
|
||||
pub(crate) use empty;
|
||||
|
||||
empty!();
|
||||
|
|
|
|||
|
|
@ -153,7 +153,7 @@ pub mod redundant_imports_issue {
|
|||
() => {};
|
||||
}
|
||||
|
||||
#[expect(redundant_imports)]
|
||||
#[expect(unused_imports)]
|
||||
pub(crate) use empty;
|
||||
|
||||
empty!();
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use tracing::debug;
|
|||
|
||||
use crate::{
|
||||
ExpandError, ExpandResult, MacroCallId,
|
||||
builtin::quote::{dollar_crate, quote},
|
||||
builtin::quote::dollar_crate,
|
||||
db::ExpandDatabase,
|
||||
hygiene::span_with_def_site_ctxt,
|
||||
name::{self, AsName, Name},
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ use syntax_bridge::syntax_node_to_token_tree;
|
|||
|
||||
use crate::{
|
||||
EditionedFileId, ExpandError, ExpandResult, Lookup as _, MacroCallId,
|
||||
builtin::quote::{WithDelimiter, dollar_crate, quote},
|
||||
builtin::quote::{WithDelimiter, dollar_crate},
|
||||
db::ExpandDatabase,
|
||||
hygiene::{span_with_call_site_ctxt, span_with_def_site_ctxt},
|
||||
name,
|
||||
|
|
|
|||
|
|
@ -229,8 +229,6 @@ mod tests {
|
|||
use span::{Edition, ROOT_ERASED_FILE_AST_ID, SpanAnchor, SyntaxContext};
|
||||
use syntax::{TextRange, TextSize};
|
||||
|
||||
use super::quote;
|
||||
|
||||
const DUMMY: tt::Span = tt::Span {
|
||||
range: TextRange::empty(TextSize::new(0)),
|
||||
anchor: SpanAnchor {
|
||||
|
|
|
|||
|
|
@ -516,7 +516,6 @@ mod test {
|
|||
#[allow(dead_code)]
|
||||
mod mock {
|
||||
use super::super::*;
|
||||
use crate::config_option_with_style_edition_default;
|
||||
use rustfmt_config_proc_macro::config_type;
|
||||
|
||||
#[config_type]
|
||||
|
|
|
|||
13
tests/ui/resolve/unused-macro-import.rs
Normal file
13
tests/ui/resolve/unused-macro-import.rs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
//@ check-pass
|
||||
|
||||
#![warn(unused_imports)]
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! mac { () => {} }
|
||||
|
||||
fn main() {
|
||||
// Unused, `mac` as `macro_rules!` is already in scope and has higher priority.
|
||||
use crate::mac; //~ WARN unused import: `crate::mac`
|
||||
|
||||
mac!();
|
||||
}
|
||||
14
tests/ui/resolve/unused-macro-import.stderr
Normal file
14
tests/ui/resolve/unused-macro-import.stderr
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
warning: unused import: `crate::mac`
|
||||
--> $DIR/unused-macro-import.rs:10:9
|
||||
|
|
||||
LL | use crate::mac;
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/unused-macro-import.rs:3:9
|
||||
|
|
||||
LL | #![warn(unused_imports)]
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue