resolve: Relax some asserts in glob overwriting and add tests

This commit is contained in:
Vadim Petrochenkov
2026-01-10 19:21:38 +03:00
parent 8c52f735ab
commit 8b52c73b3e
5 changed files with 83 additions and 3 deletions
+3 -3
View File
@@ -300,13 +300,13 @@ fn remove_same_import<'ra>(d1: Decl<'ra>, d2: Decl<'ra>) -> (Decl<'ra>, Decl<'ra
if let DeclKind::Import { import: import1, source_decl: d1_next } = d1.kind
&& let DeclKind::Import { import: import2, source_decl: d2_next } = d2.kind
&& import1 == import2
&& d1.warn_ambiguity.get() == d2.warn_ambiguity.get()
{
assert_eq!(d1.ambiguity.get(), d2.ambiguity.get());
assert!(!d1.warn_ambiguity.get());
assert_eq!(d1.expansion, d2.expansion);
assert_eq!(d1.span, d2.span);
assert_eq!(d1.vis(), d2.vis());
// Visibility of the new import declaration may be different,
// because it already incorporates the visibility of the source binding.
// `warn_ambiguity` of a re-fetched glob can also change in both directions.
remove_same_import(d1_next, d2_next)
} else {
(d1, d2)
+22
View File
@@ -0,0 +1,22 @@
//@ check-pass
mod openssl {
pub use self::handwritten::*;
mod handwritten {
mod m1 {
pub struct S {}
}
mod m2 {
#[derive(Default)]
pub struct S {}
}
pub use self::m1::*; //~ WARN ambiguous glob re-exports
pub use self::m2::*;
}
}
pub use openssl::*;
fn main() {}
@@ -0,0 +1,12 @@
warning: ambiguous glob re-exports
--> $DIR/overwrite-deep-glob.rs:15:17
|
LL | pub use self::m1::*;
| ^^^^^^^^^^^ the name `S` in the type namespace is first re-exported here
LL | pub use self::m2::*;
| ----------- but the name `S` in the type namespace is also re-exported here
|
= note: `#[warn(ambiguous_glob_reexports)]` on by default
warning: 1 warning emitted
@@ -0,0 +1,25 @@
//@ check-pass
//@ edition:2024
mod a {
mod b {
mod c {
pub struct E;
}
mod d {
mod c {
pub struct E;
}
mod d {
#[derive(Debug)]
pub struct E;
}
pub use c::*;
use d::*;
}
use c::*;
use d::*;
}
}
fn main() {}
@@ -0,0 +1,21 @@
//@ check-pass
mod b {
pub mod http {
pub struct HeaderMap;
}
pub(crate) use self::http::*;
#[derive(Debug)]
pub struct HeaderMap;
}
mod a {
pub use crate::b::*;
fn check_type() {
let _: HeaderMap = crate::b::HeaderMap;
}
}
fn main() {}