Skip to content

Commit 48dab5c

Browse files
Test for issue-86035
1 parent 99b0799 commit 48dab5c

File tree

6 files changed

+97
-0
lines changed

6 files changed

+97
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* This crate declares an item as both `prelude::*` and `m::Tr`.
2+
* The compiler should always suggest `m::Tr`. */
3+
4+
pub struct S;
5+
6+
pub mod prelude {
7+
pub use crate::m::Tr as _;
8+
}
9+
10+
pub mod m {
11+
pub trait Tr { fn method(&self); }
12+
impl Tr for crate::S { fn method(&self) {} }
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* This crate declares an item that is unnamed.
2+
* Its only public path is through `prelude::*`. */
3+
4+
pub struct S;
5+
6+
mod m {
7+
pub trait Tr { fn method(&self); }
8+
impl Tr for crate::S { fn method(&self) {} }
9+
}
10+
11+
pub mod prelude {
12+
pub use crate::m::Tr as _;
13+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// aux-build:overlapping_pub_trait_source.rs
2+
3+
/*
4+
* This crate declares two public paths, `m::Tr` and `prelude::_`. Make sure we prefer the former.
5+
*/
6+
extern crate overlapping_pub_trait_source;
7+
8+
fn main() {
9+
//~^ HELP the following trait is implemented but not in scope; perhaps add a `use` for it:
10+
//~| SUGGESTION overlapping_pub_trait_source::prelude::_
11+
use overlapping_pub_trait_source::S;
12+
S.method();
13+
//~^ ERROR no method named `method` found for struct `S` in the current scope [E0599]
14+
//~| HELP items from traits can only be used if the trait is in scope
15+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0599]: no method named `method` found for struct `S` in the current scope
2+
--> $DIR/overlapping_pub_trait.rs:12:7
3+
|
4+
LL | S.method();
5+
| ^^^^^^ method not found in `S`
6+
|
7+
::: $DIR/auxiliary/overlapping_pub_trait_source.rs:11:23
8+
|
9+
LL | pub trait Tr { fn method(&self); }
10+
| ------ the method is available for `S` here
11+
|
12+
= help: items from traits can only be used if the trait is in scope
13+
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
14+
|
15+
LL | use overlapping_pub_trait_source::prelude::_;
16+
|
17+
18+
error: aborting due to previous error
19+
20+
For more information about this error, try `rustc --explain E0599`.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// aux-build:unnamed_pub_trait_source.rs
2+
3+
/*
4+
* This crate declares an unnameable public path for our item. Make sure we don't suggest
5+
* importing it by name, and instead we suggest importing it by glob.
6+
*/
7+
extern crate unnamed_pub_trait_source;
8+
9+
fn main() {
10+
//~^ HELP the following trait is implemented but not in scope; perhaps add a `use` for it:
11+
//~| SUGGESTION unnamed_pub_trait_source::prelude::_
12+
use unnamed_pub_trait_source::S;
13+
S.method();
14+
//~^ ERROR no method named `method` found for struct `S` in the current scope [E0599]
15+
//~| HELP items from traits can only be used if the trait is in scope
16+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0599]: no method named `method` found for struct `S` in the current scope
2+
--> $DIR/unnamed_pub_trait.rs:13:7
3+
|
4+
LL | S.method();
5+
| ^^^^^^ method not found in `S`
6+
|
7+
::: $DIR/auxiliary/unnamed_pub_trait_source.rs:7:23
8+
|
9+
LL | pub trait Tr { fn method(&self); }
10+
| ------ the method is available for `S` here
11+
|
12+
= help: items from traits can only be used if the trait is in scope
13+
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
14+
|
15+
LL | use unnamed_pub_trait_source::prelude::_;
16+
|
17+
18+
error: aborting due to previous error
19+
20+
For more information about this error, try `rustc --explain E0599`.

0 commit comments

Comments
 (0)