gccrs#4750: Fix ignored self in grouped glob imports
Link: Rust-GCC/gccrs#4750
Note
Bug fix (issue #4689)
Objective
Fixes a bug in the module resolution system where grouped imports combining self and a glob (e.g., use path::module::{self, *};) would successfully import the inner items via the glob, but silently drop the base module (or enum) itself.
Changes Made
Modified the early name resolution phase. Previously, the self keyword in grouped imports was being overwritten or ignored. This PR ensures that self imports within a group are assigned their own unique NodeId, preventing them from being dropped from the AST during resolution.
Why is this needed for alloc?
The standard library and the alloc crate heavily utilize this specific import syntax for module preludes and re-exports (e.g., importing all variants of an enum while also exposing the enum type itself). Failing to resolve these imports blocks the compilation of the alloc crate root.
Test Case
pub mod collections {
pub enum TryReserveError {
AllocError,
CapacityOverflow,
}
}
pub mod test_working {
// this explicit list was working correctly before the PR.
use super::collections::TryReserveError::{self, AllocError, CapacityOverflow};
fn _test_function() -> TryReserveError {
AllocError
}
}
pub mod test_failing {
use super::collections::TryReserveError::{self, *};
// ^^^^ this was silently ignored
fn _test_function() -> TryReserveError {
// ^^^^^^^^^^^^^^^
// compiler threw an "unknown symbol" error here.
CapacityOverflow
}
}
fn main() {
println!("valid");
}