Merge pull request #19461 from Hmikihiro/shadow_by_module

fix: shadow type by module
This commit is contained in:
Lukas Wirth 2025-04-10 12:20:14 +00:00 committed by GitHub
commit f880acd18c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 180 additions and 7 deletions

View file

@ -3330,6 +3330,150 @@ pub fn foo() {}
fn main() {
let s = st$0r::f();
}
"#,
);
}
#[test]
fn struct_shadow_by_module() {
check(
r#"
mod foo {
pub mod bar {
// ^^^
pub type baz = usize;
}
}
struct bar;
fn main() {
use foo::bar;
let x: ba$0r::baz = 5;
}
"#,
);
}
#[test]
fn type_alias_shadow_by_module() {
check(
r#"
mod foo {
pub mod bar {
// ^^^
pub fn baz() {}
}
}
trait Qux {}
fn item<bar: Qux>() {
use foo::bar;
ba$0r::baz();
}
}
"#,
);
check(
r#"
mod foo {
pub mod bar {
// ^^^
pub fn baz() {}
}
}
fn item<bar>(x: bar) {
use foo::bar;
let x: bar$0 = x;
}
"#,
);
}
#[test]
fn trait_shadow_by_module() {
check(
r#"
pub mod foo {
pub mod Bar {}
// ^^^
}
trait Bar {}
fn main() {
use foo::Bar;
fn f<Qux: B$0ar>() {}
}
"#,
);
}
#[test]
fn const_shadow_by_module() {
check(
r#"
pub mod foo {
pub struct u8 {}
pub mod bar {
pub mod u8 {}
}
}
fn main() {
use foo::u8;
{
use foo::bar::u8;
fn f1<const N: u$08>() {}
}
fn f2<const N: u8>() {}
}
"#,
);
check(
r#"
pub mod foo {
pub struct u8 {}
// ^^
pub mod bar {
pub mod u8 {}
}
}
fn main() {
use foo::u8;
{
use foo::bar::u8;
fn f1<const N: u8>() {}
}
fn f2<const N: u$08>() {}
}
"#,
);
check(
r#"
pub mod foo {
pub struct buz {}
pub mod bar {
pub mod buz {}
// ^^^
}
}
fn main() {
use foo::buz;
{
use foo::bar::buz;
fn f1<const N: buz$0>() {}
}
}
"#,
);
}