Skip to content

Commit 8b52c73

Browse files
committed
resolve: Relax some asserts in glob overwriting and add tests
1 parent 8c52f73 commit 8b52c73

5 files changed

Lines changed: 83 additions & 3 deletions

File tree

compiler/rustc_resolve/src/imports.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,13 +300,13 @@ fn remove_same_import<'ra>(d1: Decl<'ra>, d2: Decl<'ra>) -> (Decl<'ra>, Decl<'ra
300300
if let DeclKind::Import { import: import1, source_decl: d1_next } = d1.kind
301301
&& let DeclKind::Import { import: import2, source_decl: d2_next } = d2.kind
302302
&& import1 == import2
303-
&& d1.warn_ambiguity.get() == d2.warn_ambiguity.get()
304303
{
305304
assert_eq!(d1.ambiguity.get(), d2.ambiguity.get());
306-
assert!(!d1.warn_ambiguity.get());
307305
assert_eq!(d1.expansion, d2.expansion);
308306
assert_eq!(d1.span, d2.span);
309-
assert_eq!(d1.vis(), d2.vis());
307+
// Visibility of the new import declaration may be different,
308+
// because it already incorporates the visibility of the source binding.
309+
// `warn_ambiguity` of a re-fetched glob can also change in both directions.
310310
remove_same_import(d1_next, d2_next)
311311
} else {
312312
(d1, d2)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//@ check-pass
2+
3+
mod openssl {
4+
pub use self::handwritten::*;
5+
6+
mod handwritten {
7+
mod m1 {
8+
pub struct S {}
9+
}
10+
mod m2 {
11+
#[derive(Default)]
12+
pub struct S {}
13+
}
14+
15+
pub use self::m1::*; //~ WARN ambiguous glob re-exports
16+
pub use self::m2::*;
17+
}
18+
}
19+
20+
pub use openssl::*;
21+
22+
fn main() {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
warning: ambiguous glob re-exports
2+
--> $DIR/overwrite-deep-glob.rs:15:17
3+
|
4+
LL | pub use self::m1::*;
5+
| ^^^^^^^^^^^ the name `S` in the type namespace is first re-exported here
6+
LL | pub use self::m2::*;
7+
| ----------- but the name `S` in the type namespace is also re-exported here
8+
|
9+
= note: `#[warn(ambiguous_glob_reexports)]` on by default
10+
11+
warning: 1 warning emitted
12+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//@ check-pass
2+
//@ edition:2024
3+
4+
mod a {
5+
mod b {
6+
mod c {
7+
pub struct E;
8+
}
9+
mod d {
10+
mod c {
11+
pub struct E;
12+
}
13+
mod d {
14+
#[derive(Debug)]
15+
pub struct E;
16+
}
17+
pub use c::*;
18+
use d::*;
19+
}
20+
use c::*;
21+
use d::*;
22+
}
23+
}
24+
25+
fn main() {}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//@ check-pass
2+
3+
mod b {
4+
pub mod http {
5+
pub struct HeaderMap;
6+
}
7+
8+
pub(crate) use self::http::*;
9+
#[derive(Debug)]
10+
pub struct HeaderMap;
11+
}
12+
13+
mod a {
14+
pub use crate::b::*;
15+
16+
fn check_type() {
17+
let _: HeaderMap = crate::b::HeaderMap;
18+
}
19+
}
20+
21+
fn main() {}

0 commit comments

Comments
 (0)