Skip to content

Commit bce645f

Browse files
committed
WIP
1 parent 6ac16d8 commit bce645f

19 files changed

+351
-226
lines changed

compiler/rustc_resolve/src/imports.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,10 +359,24 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
359359
(true, true) => {
360360
let (glob_binding, old_glob_binding) = (binding, old_binding);
361361
if res != old_glob_binding.res() {
362+
let (primary_binding, secondary_binding, warning) = if !binding
363+
.is_ambiguity_recursive()
364+
&& let NameBindingKind::Import { import: old_import, .. } =
365+
old_glob_binding.kind
366+
&& let NameBindingKind::Import { import, .. } = glob_binding.kind
367+
&& old_import == import
368+
{
369+
// When imported from the same import, we have to replace
370+
// `old_glob_binding` with `glob_binding` to avoid cascade errors.
371+
(glob_binding, old_glob_binding, true)
372+
} else {
373+
(old_glob_binding, glob_binding, false)
374+
};
362375
resolution.glob_binding = Some(this.new_ambiguity_binding(
363376
AmbiguityKind::GlobVsGlob,
364-
old_glob_binding,
365-
glob_binding,
377+
primary_binding,
378+
secondary_binding,
379+
warning,
366380
));
367381
} else if !old_glob_binding.vis.is_at_least(glob_binding.vis, this.tcx)
368382
|| glob_binding.is_ambiguity_recursive()
@@ -382,6 +396,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
382396
AmbiguityKind::GlobVsExpanded,
383397
non_glob_binding,
384398
glob_binding,
399+
false,
385400
));
386401
} else {
387402
resolution.non_glob_binding = Some(non_glob_binding);
@@ -394,6 +409,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
394409
AmbiguityKind::GlobVsGlob,
395410
old_glob_binding,
396411
glob_binding,
412+
false,
397413
));
398414
} else if !old_glob_binding.vis.is_at_least(glob_binding.vis, this.tcx)
399415
|| glob_binding.is_ambiguity_recursive()
@@ -426,8 +442,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
426442
ambiguity_kind: AmbiguityKind,
427443
primary_binding: NameBinding<'ra>,
428444
secondary_binding: NameBinding<'ra>,
445+
warning: bool,
429446
) -> NameBinding<'ra> {
430-
let ambiguity = Some((secondary_binding, ambiguity_kind, false));
447+
let ambiguity = Some((secondary_binding, ambiguity_kind, warning));
431448
let data = NameBindingData { ambiguity, ..*primary_binding };
432449
self.arenas.alloc_name_binding(data)
433450
}

tests/ui/imports/import-after-macro-expand-10.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ use crate::b::*;
1313
fn main() {
1414
let h: crate::b::HeaderMap = HeaderMap;
1515
//~^ ERROR `HeaderMap` is ambiguous
16-
//~| ERROR mismatched types
16+
//~| WARN this was previously accepted
1717
}

tests/ui/imports/import-after-macro-expand-10.stderr

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
error[E0659]: `HeaderMap` is ambiguous
1+
error: `HeaderMap` is ambiguous
22
--> $DIR/import-after-macro-expand-10.rs:14:34
33
|
44
LL | let h: crate::b::HeaderMap = HeaderMap;
55
| ^^^^^^^^^ ambiguous name
66
|
7+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8+
= note: for more information, see issue #114095 <https://github.com/rust-lang/rust/issues/114095>
79
= note: ambiguous because of multiple glob imports of a name in the same module
810
note: `HeaderMap` could refer to the unit struct imported here
911
--> $DIR/import-after-macro-expand-10.rs:11:5
@@ -17,28 +19,31 @@ note: `HeaderMap` could also refer to the unit struct imported here
1719
LL | use crate::b::*;
1820
| ^^^^^^^^^^^
1921
= help: consider adding an explicit import of `HeaderMap` to disambiguate
22+
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default
2023

21-
error[E0308]: mismatched types
24+
error: aborting due to 1 previous error
25+
26+
Future incompatibility report: Future breakage diagnostic:
27+
error: `HeaderMap` is ambiguous
2228
--> $DIR/import-after-macro-expand-10.rs:14:34
2329
|
2430
LL | let h: crate::b::HeaderMap = HeaderMap;
25-
| ------------------- ^^^^^^^^^ expected `b::HeaderMap`, found `http::HeaderMap`
26-
| |
27-
| expected due to this
31+
| ^^^^^^^^^ ambiguous name
2832
|
29-
= note: `http::HeaderMap` and `b::HeaderMap` have similar names, but are actually distinct types
30-
note: `http::HeaderMap` is defined in module `crate::b::http` of the current crate
31-
--> $DIR/import-after-macro-expand-10.rs:3:9
33+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
34+
= note: for more information, see issue #114095 <https://github.com/rust-lang/rust/issues/114095>
35+
= note: ambiguous because of multiple glob imports of a name in the same module
36+
note: `HeaderMap` could refer to the unit struct imported here
37+
--> $DIR/import-after-macro-expand-10.rs:11:5
3238
|
33-
LL | pub struct HeaderMap;
34-
| ^^^^^^^^^^^^^^^^^^^^
35-
note: `b::HeaderMap` is defined in module `crate::b` of the current crate
36-
--> $DIR/import-after-macro-expand-10.rs:8:5
39+
LL | use crate::b::*;
40+
| ^^^^^^^^^^^
41+
= help: consider adding an explicit import of `HeaderMap` to disambiguate
42+
note: `HeaderMap` could also refer to the unit struct imported here
43+
--> $DIR/import-after-macro-expand-10.rs:11:5
3744
|
38-
LL | pub struct HeaderMap;
39-
| ^^^^^^^^^^^^^^^^^^^^
40-
41-
error: aborting due to 2 previous errors
45+
LL | use crate::b::*;
46+
| ^^^^^^^^^^^
47+
= help: consider adding an explicit import of `HeaderMap` to disambiguate
48+
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default
4249

43-
Some errors have detailed explanations: E0308, E0659.
44-
For more information about an error, try `rustc --explain E0308`.

tests/ui/imports/import-after-macro-expand-11.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ mod p {
1313
fn f() {
1414
let h: crate::p::H = H;
1515
//~^ ERROR `H` is ambiguous
16-
//~| ERROR mismatched types
16+
//~| WARN this was previously accepted
1717
}
1818
}
1919
}

tests/ui/imports/import-after-macro-expand-11.stderr

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
error[E0659]: `H` is ambiguous
1+
error: `H` is ambiguous
22
--> $DIR/import-after-macro-expand-11.rs:14:33
33
|
44
LL | let h: crate::p::H = H;
55
| ^ ambiguous name
66
|
7+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8+
= note: for more information, see issue #114095 <https://github.com/rust-lang/rust/issues/114095>
79
= note: ambiguous because of multiple glob imports of a name in the same module
810
note: `H` could refer to the unit struct imported here
911
--> $DIR/import-after-macro-expand-11.rs:11:13
@@ -17,28 +19,31 @@ note: `H` could also refer to the unit struct imported here
1719
LL | use super::*;
1820
| ^^^^^^^^
1921
= help: consider adding an explicit import of `H` to disambiguate
22+
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default
2023

21-
error[E0308]: mismatched types
24+
error: aborting due to 1 previous error
25+
26+
Future incompatibility report: Future breakage diagnostic:
27+
error: `H` is ambiguous
2228
--> $DIR/import-after-macro-expand-11.rs:14:33
2329
|
2430
LL | let h: crate::p::H = H;
25-
| ----------- ^ expected `p::H`, found `H`
26-
| |
27-
| expected due to this
31+
| ^ ambiguous name
2832
|
29-
= note: `H` and `p::H` have similar names, but are actually distinct types
30-
note: `H` is defined in module `crate` of the current crate
31-
--> $DIR/import-after-macro-expand-11.rs:2:1
33+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
34+
= note: for more information, see issue #114095 <https://github.com/rust-lang/rust/issues/114095>
35+
= note: ambiguous because of multiple glob imports of a name in the same module
36+
note: `H` could refer to the unit struct imported here
37+
--> $DIR/import-after-macro-expand-11.rs:11:13
3238
|
33-
LL | struct H;
34-
| ^^^^^^^^
35-
note: `p::H` is defined in module `crate::p` of the current crate
36-
--> $DIR/import-after-macro-expand-11.rs:8:5
39+
LL | use super::*;
40+
| ^^^^^^^^
41+
= help: consider adding an explicit import of `H` to disambiguate
42+
note: `H` could also refer to the unit struct imported here
43+
--> $DIR/import-after-macro-expand-11.rs:11:13
3744
|
38-
LL | struct H;
39-
| ^^^^^^^^
40-
41-
error: aborting due to 2 previous errors
45+
LL | use super::*;
46+
| ^^^^^^^^
47+
= help: consider adding an explicit import of `H` to disambiguate
48+
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default
4249

43-
Some errors have detailed explanations: E0308, E0659.
44-
For more information about an error, try `rustc --explain E0308`.

tests/ui/imports/import-after-macro-expand-12.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn main() {
2626
use self::*;
2727
B::ASSOC
2828
//~^ ERROR `B` is ambiguous
29-
//~| ERROR mismatched types
29+
//~| WARN this was previously accepted
3030
};
3131
let b: u16 = m!({
3232
use self::*;

tests/ui/imports/import-after-macro-expand-12.stderr

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
error[E0659]: `B` is ambiguous
1+
error: `B` is ambiguous
22
--> $DIR/import-after-macro-expand-12.rs:27:9
33
|
44
LL | B::ASSOC
55
| ^ ambiguous name
66
|
7+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8+
= note: for more information, see issue #114095 <https://github.com/rust-lang/rust/issues/114095>
79
= note: ambiguous because of multiple glob imports of a name in the same module
810
note: `B` could refer to the enum imported here
911
--> $DIR/import-after-macro-expand-12.rs:26:13
@@ -17,19 +19,31 @@ note: `B` could also refer to the enum imported here
1719
LL | use self::*;
1820
| ^^^^^^^
1921
= help: consider adding an explicit import of `B` to disambiguate
22+
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default
2023

21-
error[E0308]: mismatched types
24+
error: aborting due to 1 previous error
25+
26+
Future incompatibility report: Future breakage diagnostic:
27+
error: `B` is ambiguous
2228
--> $DIR/import-after-macro-expand-12.rs:27:9
2329
|
2430
LL | B::ASSOC
25-
| ^^^^^^^^ expected `u16`, found `u8`
31+
| ^ ambiguous name
2632
|
27-
help: you can convert a `u8` to a `u16`
33+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
34+
= note: for more information, see issue #114095 <https://github.com/rust-lang/rust/issues/114095>
35+
= note: ambiguous because of multiple glob imports of a name in the same module
36+
note: `B` could refer to the enum imported here
37+
--> $DIR/import-after-macro-expand-12.rs:26:13
2838
|
29-
LL | B::ASSOC.into()
30-
| +++++++
31-
32-
error: aborting due to 2 previous errors
39+
LL | use self::*;
40+
| ^^^^^^^
41+
= help: consider adding an explicit import of `B` to disambiguate
42+
note: `B` could also refer to the enum imported here
43+
--> $DIR/import-after-macro-expand-12.rs:26:13
44+
|
45+
LL | use self::*;
46+
| ^^^^^^^
47+
= help: consider adding an explicit import of `B` to disambiguate
48+
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default
3349

34-
Some errors have detailed explanations: E0308, E0659.
35-
For more information about an error, try `rustc --explain E0308`.

tests/ui/imports/import-after-macro-expand-13.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use crate::a::HeaderMap;
44
//~^ ERROR `HeaderMap` is ambiguous
5+
//~| WARN this was previously accepted
56

67
mod b {
78
pub mod http {
@@ -20,5 +21,5 @@ mod a {
2021
fn main() {
2122
let h: crate::b::HeaderMap = HeaderMap;
2223
//~^ ERROR `HeaderMap` is ambiguous
23-
//~| ERROR mismatched types
24+
//~| WARN this was previously accepted
2425
}

tests/ui/imports/import-after-macro-expand-13.stderr

Lines changed: 56 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,95 @@
1-
error[E0659]: `HeaderMap` is ambiguous
1+
error: `HeaderMap` is ambiguous
22
--> $DIR/import-after-macro-expand-13.rs:3:15
33
|
44
LL | use crate::a::HeaderMap;
55
| ^^^^^^^^^ ambiguous name
66
|
7+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8+
= note: for more information, see issue #114095 <https://github.com/rust-lang/rust/issues/114095>
79
= note: ambiguous because of multiple glob imports of a name in the same module
810
note: `HeaderMap` could refer to the struct imported here
9-
--> $DIR/import-after-macro-expand-13.rs:17:13
11+
--> $DIR/import-after-macro-expand-13.rs:18:13
1012
|
1113
LL | pub use crate::b::*;
1214
| ^^^^^^^^^^^
1315
= help: consider adding an explicit import of `HeaderMap` to disambiguate
1416
note: `HeaderMap` could also refer to the struct imported here
15-
--> $DIR/import-after-macro-expand-13.rs:17:13
17+
--> $DIR/import-after-macro-expand-13.rs:18:13
1618
|
1719
LL | pub use crate::b::*;
1820
| ^^^^^^^^^^^
1921
= help: consider adding an explicit import of `HeaderMap` to disambiguate
22+
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default
2023

21-
error[E0659]: `HeaderMap` is ambiguous
22-
--> $DIR/import-after-macro-expand-13.rs:21:34
24+
error: `HeaderMap` is ambiguous
25+
--> $DIR/import-after-macro-expand-13.rs:22:34
2326
|
2427
LL | let h: crate::b::HeaderMap = HeaderMap;
2528
| ^^^^^^^^^ ambiguous name
2629
|
30+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
31+
= note: for more information, see issue #114095 <https://github.com/rust-lang/rust/issues/114095>
2732
= note: ambiguous because of multiple glob imports of a name in the same module
2833
note: `HeaderMap` could refer to the unit struct imported here
29-
--> $DIR/import-after-macro-expand-13.rs:17:13
34+
--> $DIR/import-after-macro-expand-13.rs:18:13
3035
|
3136
LL | pub use crate::b::*;
3237
| ^^^^^^^^^^^
3338
= help: consider adding an explicit import of `HeaderMap` to disambiguate
3439
note: `HeaderMap` could also refer to the unit struct imported here
35-
--> $DIR/import-after-macro-expand-13.rs:17:13
40+
--> $DIR/import-after-macro-expand-13.rs:18:13
3641
|
3742
LL | pub use crate::b::*;
3843
| ^^^^^^^^^^^
3944
= help: consider adding an explicit import of `HeaderMap` to disambiguate
4045

41-
error[E0308]: mismatched types
42-
--> $DIR/import-after-macro-expand-13.rs:21:34
46+
error: aborting due to 2 previous errors
47+
48+
Future incompatibility report: Future breakage diagnostic:
49+
error: `HeaderMap` is ambiguous
50+
--> $DIR/import-after-macro-expand-13.rs:3:15
4351
|
44-
LL | let h: crate::b::HeaderMap = HeaderMap;
45-
| ------------------- ^^^^^^^^^ expected `b::HeaderMap`, found `http::HeaderMap`
46-
| |
47-
| expected due to this
52+
LL | use crate::a::HeaderMap;
53+
| ^^^^^^^^^ ambiguous name
4854
|
49-
= note: `http::HeaderMap` and `b::HeaderMap` have similar names, but are actually distinct types
50-
note: `http::HeaderMap` is defined in module `crate::b::http` of the current crate
51-
--> $DIR/import-after-macro-expand-13.rs:8:9
55+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
56+
= note: for more information, see issue #114095 <https://github.com/rust-lang/rust/issues/114095>
57+
= note: ambiguous because of multiple glob imports of a name in the same module
58+
note: `HeaderMap` could refer to the struct imported here
59+
--> $DIR/import-after-macro-expand-13.rs:18:13
5260
|
53-
LL | pub struct HeaderMap;
54-
| ^^^^^^^^^^^^^^^^^^^^
55-
note: `b::HeaderMap` is defined in module `crate::b` of the current crate
56-
--> $DIR/import-after-macro-expand-13.rs:13:5
61+
LL | pub use crate::b::*;
62+
| ^^^^^^^^^^^
63+
= help: consider adding an explicit import of `HeaderMap` to disambiguate
64+
note: `HeaderMap` could also refer to the struct imported here
65+
--> $DIR/import-after-macro-expand-13.rs:18:13
5766
|
58-
LL | pub struct HeaderMap;
59-
| ^^^^^^^^^^^^^^^^^^^^
67+
LL | pub use crate::b::*;
68+
| ^^^^^^^^^^^
69+
= help: consider adding an explicit import of `HeaderMap` to disambiguate
70+
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default
6071

61-
error: aborting due to 3 previous errors
72+
Future breakage diagnostic:
73+
error: `HeaderMap` is ambiguous
74+
--> $DIR/import-after-macro-expand-13.rs:22:34
75+
|
76+
LL | let h: crate::b::HeaderMap = HeaderMap;
77+
| ^^^^^^^^^ ambiguous name
78+
|
79+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
80+
= note: for more information, see issue #114095 <https://github.com/rust-lang/rust/issues/114095>
81+
= note: ambiguous because of multiple glob imports of a name in the same module
82+
note: `HeaderMap` could refer to the unit struct imported here
83+
--> $DIR/import-after-macro-expand-13.rs:18:13
84+
|
85+
LL | pub use crate::b::*;
86+
| ^^^^^^^^^^^
87+
= help: consider adding an explicit import of `HeaderMap` to disambiguate
88+
note: `HeaderMap` could also refer to the unit struct imported here
89+
--> $DIR/import-after-macro-expand-13.rs:18:13
90+
|
91+
LL | pub use crate::b::*;
92+
| ^^^^^^^^^^^
93+
= help: consider adding an explicit import of `HeaderMap` to disambiguate
94+
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default
6295

63-
Some errors have detailed explanations: E0308, E0659.
64-
For more information about an error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)