Skip to content

Commit 6bada23

Browse files
copy test from 148946
1 parent 1df7adf commit 6bada23

File tree

3 files changed

+228
-31
lines changed

3 files changed

+228
-31
lines changed

tests/ui/imports/ambiguous-trait-in-scope.rs

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//@ edition:2018
2+
//@ aux-crate:external=ambiguous-trait-reexport.rs
3+
14
mod m1 {
25
pub trait Trait {
36
fn method1(&self) {}
@@ -10,13 +13,24 @@ mod m2 {
1013
}
1114
impl Trait for u8 {}
1215
}
16+
mod m1_reexport {
17+
pub use crate::m1::Trait;
18+
}
19+
mod m2_reexport {
20+
pub use crate::m2::Trait;
21+
}
1322

14-
pub fn test1() {
23+
mod ambig_reexport {
24+
pub use crate::m1::*;
25+
pub use crate::m2::*;
26+
}
27+
28+
fn test1() {
1529
// Create an ambiguous import for `Trait` in one order
1630
use m1::*;
1731
use m2::*;
18-
0u8.method1(); //~ WARNING Use of ambiguously glob imported trait `Trait` [ambiguous_trait_glob_imports]
19-
//~| WARNING: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
32+
0u8.method1(); //~ WARNING Use of ambiguously glob imported trait `Trait` [ambiguous_glob_imported_trait]
33+
//~| WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
2034
0u8.method2(); //~ ERROR: no method named `method2` found for type `u8` in the current scope
2135
}
2236

@@ -25,8 +39,45 @@ fn test2() {
2539
use m2::*;
2640
use m1::*;
2741
0u8.method1(); //~ ERROR: no method named `method1` found for type `u8` in the current scope
28-
0u8.method2(); //~ WARNING Use of ambiguously glob imported trait `Trait` [ambiguous_trait_glob_imports]
29-
//~| WARNING: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
42+
0u8.method2(); //~ WARNING Use of ambiguously glob imported trait `Trait` [ambiguous_glob_imported_trait]
43+
//~| WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
44+
}
45+
46+
fn test_indirect_reexport() {
47+
use m1_reexport::*;
48+
use m2_reexport::*;
49+
0u8.method1(); //~ WARNING Use of ambiguously glob imported trait `Trait` [ambiguous_glob_imported_trait]
50+
//~| WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
51+
0u8.method2(); //~ ERROR: no method named `method2` found for type `u8` in the current scope
52+
}
53+
54+
fn test_ambig_reexport() {
55+
use ambig_reexport::*;
56+
0u8.method1(); //~ WARNING Use of ambiguously glob imported trait `Trait` [ambiguous_glob_imported_trait]
57+
//~| WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
58+
0u8.method2(); //~ ERROR: no method named `method2` found for type `u8` in the current scope
59+
}
60+
61+
fn test_external() {
62+
use external::m1::*;
63+
use external::m2::*;
64+
0u8.method1(); //~ WARNING Use of ambiguously glob imported trait `Trait` [ambiguous_glob_imported_trait]
65+
//~| WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
66+
0u8.method2(); //~ ERROR: no method named `method2` found for type `u8` in the current scope
67+
}
68+
69+
fn test_external_indirect_reexport() {
70+
use external::m1_reexport::*;
71+
use external::m2_reexport::*;
72+
0u8.method1(); //~ WARNING Use of ambiguously glob imported trait `Trait` [ambiguous_glob_imported_trait]
73+
//~| WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
74+
0u8.method2(); //~ ERROR: no method named `method2` found for type `u8` in the current scope
75+
}
76+
77+
fn test_external_ambig_reexport() {
78+
use external::ambig_reexport::*;
79+
0u8.method1(); //~ ERROR: no method named `method1` found for type `u8` in the current scope
80+
0u8.method2(); //~ ERROR: no method named `method2` found for type `u8` in the current scope
3081
}
3182

3283
fn main() {}
Lines changed: 149 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: Use of ambiguously glob imported trait `Trait`
2-
--> $DIR/ambiguous-trait-in-scope.rs:18:9
2+
--> $DIR/ambiguous-trait-in-scope.rs:32:9
33
|
44
LL | use m1::*;
55
| -- `Trait`imported ambiguously here
@@ -10,50 +10,38 @@ LL | 0u8.method1();
1010
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
1111
= note: for more information, see issue #147992 <https://github.com/rust-lang/rust/issues/147992>
1212
= help: Import `Trait` explicitly
13-
= note: `#[warn(ambiguous_trait_glob_imports)]` (part of `#[warn(future_incompatible)]`) on by default
13+
= note: `#[warn(ambiguous_glob_imported_trait)]` (part of `#[warn(future_incompatible)]`) on by default
1414

1515
error[E0599]: no method named `method2` found for type `u8` in the current scope
16-
--> $DIR/ambiguous-trait-in-scope.rs:20:9
16+
--> $DIR/ambiguous-trait-in-scope.rs:34:9
1717
|
18-
LL | fn method2(&self) {}
19-
| ------- the method is available for `u8` here
20-
...
2118
LL | 0u8.method2();
22-
| ^^^^^^^
19+
| ^^^^^^^ method not found in `u8`
2320
|
2421
= help: items from traits can only be used if the trait is in scope
25-
help: trait `Trait` which provides `method2` is implemented but not in scope; perhaps you want to import it
26-
|
27-
LL + use m2::Trait;
22+
help: the following traits which provide `method2` are implemented but not in scope; perhaps you want to import one of them
2823
|
29-
help: there is a method `method1` with a similar name
24+
LL + use ambiguous_trait_reexport::m2::Trait;
3025
|
31-
LL - 0u8.method2();
32-
LL + 0u8.method1();
26+
LL + use crate::m2::Trait;
3327
|
3428

3529
error[E0599]: no method named `method1` found for type `u8` in the current scope
36-
--> $DIR/ambiguous-trait-in-scope.rs:27:9
30+
--> $DIR/ambiguous-trait-in-scope.rs:41:9
3731
|
38-
LL | fn method1(&self) {}
39-
| ------- the method is available for `u8` here
40-
...
4132
LL | 0u8.method1();
42-
| ^^^^^^^
33+
| ^^^^^^^ method not found in `u8`
4334
|
4435
= help: items from traits can only be used if the trait is in scope
45-
help: trait `Trait` which provides `method1` is implemented but not in scope; perhaps you want to import it
46-
|
47-
LL + use m1::Trait;
36+
help: the following traits which provide `method1` are implemented but not in scope; perhaps you want to import one of them
4837
|
49-
help: there is a method `method2` with a similar name
38+
LL + use ambiguous_trait_reexport::m1::Trait;
5039
|
51-
LL - 0u8.method1();
52-
LL + 0u8.method2();
40+
LL + use crate::m1::Trait;
5341
|
5442

5543
warning: Use of ambiguously glob imported trait `Trait`
56-
--> $DIR/ambiguous-trait-in-scope.rs:28:9
44+
--> $DIR/ambiguous-trait-in-scope.rs:42:9
5745
|
5846
LL | use m2::*;
5947
| -- `Trait`imported ambiguously here
@@ -65,6 +53,141 @@ LL | 0u8.method2();
6553
= note: for more information, see issue #147992 <https://github.com/rust-lang/rust/issues/147992>
6654
= help: Import `Trait` explicitly
6755

68-
error: aborting due to 2 previous errors; 2 warnings emitted
56+
warning: Use of ambiguously glob imported trait `Trait`
57+
--> $DIR/ambiguous-trait-in-scope.rs:49:9
58+
|
59+
LL | use m1_reexport::*;
60+
| ----------- `Trait`imported ambiguously here
61+
LL | use m2_reexport::*;
62+
LL | 0u8.method1();
63+
| ^^^^^^^
64+
|
65+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
66+
= note: for more information, see issue #147992 <https://github.com/rust-lang/rust/issues/147992>
67+
= help: Import `Trait` explicitly
68+
69+
error[E0599]: no method named `method2` found for type `u8` in the current scope
70+
--> $DIR/ambiguous-trait-in-scope.rs:51:9
71+
|
72+
LL | 0u8.method2();
73+
| ^^^^^^^ method not found in `u8`
74+
|
75+
= help: items from traits can only be used if the trait is in scope
76+
help: the following traits which provide `method2` are implemented but not in scope; perhaps you want to import one of them
77+
|
78+
LL + use ambiguous_trait_reexport::m2::Trait;
79+
|
80+
LL + use crate::m2::Trait;
81+
|
82+
83+
warning: Use of ambiguously glob imported trait `Trait`
84+
--> $DIR/ambiguous-trait-in-scope.rs:56:9
85+
|
86+
LL | use ambig_reexport::*;
87+
| -------------- `Trait`imported ambiguously here
88+
LL | 0u8.method1();
89+
| ^^^^^^^
90+
|
91+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
92+
= note: for more information, see issue #147992 <https://github.com/rust-lang/rust/issues/147992>
93+
= help: Import `Trait` explicitly
94+
95+
error[E0599]: no method named `method2` found for type `u8` in the current scope
96+
--> $DIR/ambiguous-trait-in-scope.rs:58:9
97+
|
98+
LL | 0u8.method2();
99+
| ^^^^^^^ method not found in `u8`
100+
|
101+
= help: items from traits can only be used if the trait is in scope
102+
help: the following traits which provide `method2` are implemented but not in scope; perhaps you want to import one of them
103+
|
104+
LL + use ambiguous_trait_reexport::m2::Trait;
105+
|
106+
LL + use crate::m2::Trait;
107+
|
108+
109+
warning: Use of ambiguously glob imported trait `Trait`
110+
--> $DIR/ambiguous-trait-in-scope.rs:64:9
111+
|
112+
LL | use external::m1::*;
113+
| ------------ `Trait`imported ambiguously here
114+
LL | use external::m2::*;
115+
LL | 0u8.method1();
116+
| ^^^^^^^
117+
|
118+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
119+
= note: for more information, see issue #147992 <https://github.com/rust-lang/rust/issues/147992>
120+
= help: Import `Trait` explicitly
121+
122+
error[E0599]: no method named `method2` found for type `u8` in the current scope
123+
--> $DIR/ambiguous-trait-in-scope.rs:66:9
124+
|
125+
LL | 0u8.method2();
126+
| ^^^^^^^ method not found in `u8`
127+
|
128+
= help: items from traits can only be used if the trait is in scope
129+
help: the following traits which provide `method2` are implemented but not in scope; perhaps you want to import one of them
130+
|
131+
LL + use ambiguous_trait_reexport::m2::Trait;
132+
|
133+
LL + use crate::m2::Trait;
134+
|
135+
136+
warning: Use of ambiguously glob imported trait `Trait`
137+
--> $DIR/ambiguous-trait-in-scope.rs:72:9
138+
|
139+
LL | use external::m1_reexport::*;
140+
| --------------------- `Trait`imported ambiguously here
141+
LL | use external::m2_reexport::*;
142+
LL | 0u8.method1();
143+
| ^^^^^^^
144+
|
145+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
146+
= note: for more information, see issue #147992 <https://github.com/rust-lang/rust/issues/147992>
147+
= help: Import `Trait` explicitly
148+
149+
error[E0599]: no method named `method2` found for type `u8` in the current scope
150+
--> $DIR/ambiguous-trait-in-scope.rs:74:9
151+
|
152+
LL | 0u8.method2();
153+
| ^^^^^^^ method not found in `u8`
154+
|
155+
= help: items from traits can only be used if the trait is in scope
156+
help: the following traits which provide `method2` are implemented but not in scope; perhaps you want to import one of them
157+
|
158+
LL + use ambiguous_trait_reexport::m2::Trait;
159+
|
160+
LL + use crate::m2::Trait;
161+
|
162+
163+
error[E0599]: no method named `method1` found for type `u8` in the current scope
164+
--> $DIR/ambiguous-trait-in-scope.rs:79:9
165+
|
166+
LL | 0u8.method1();
167+
| ^^^^^^^ method not found in `u8`
168+
|
169+
= help: items from traits can only be used if the trait is in scope
170+
help: the following traits which provide `method1` are implemented but not in scope; perhaps you want to import one of them
171+
|
172+
LL + use ambiguous_trait_reexport::m1::Trait;
173+
|
174+
LL + use crate::m1::Trait;
175+
|
176+
177+
error[E0599]: no method named `method2` found for type `u8` in the current scope
178+
--> $DIR/ambiguous-trait-in-scope.rs:80:9
179+
|
180+
LL | 0u8.method2();
181+
| ^^^^^^^ method not found in `u8`
182+
|
183+
= help: items from traits can only be used if the trait is in scope
184+
help: the following traits which provide `method2` are implemented but not in scope; perhaps you want to import one of them
185+
|
186+
LL + use ambiguous_trait_reexport::m2::Trait;
187+
|
188+
LL + use crate::m2::Trait;
189+
|
190+
191+
error: aborting due to 8 previous errors; 6 warnings emitted
69192

70193
For more information about this error, try `rustc --explain E0599`.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
pub mod m1 {
2+
pub trait Trait {
3+
fn method1(&self) {}
4+
}
5+
impl Trait for u8 {}
6+
}
7+
pub mod m2 {
8+
pub trait Trait {
9+
fn method2(&self) {}
10+
}
11+
impl Trait for u8 {}
12+
}
13+
pub mod m1_reexport {
14+
pub use crate::m1::Trait;
15+
}
16+
pub mod m2_reexport {
17+
pub use crate::m2::Trait;
18+
}
19+
20+
pub mod ambig_reexport {
21+
pub use crate::m1::*;
22+
pub use crate::m2::*;
23+
}

0 commit comments

Comments
 (0)