From 48dab5c9601d856fdbdd9bda183732edd9545c29 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 30 Nov 2021 17:53:39 -0800 Subject: [PATCH] Test for issue-86035 --- .../auxiliary/overlapping_pub_trait_source.rs | 13 ++++++++++++ .../auxiliary/unnamed_pub_trait_source.rs | 13 ++++++++++++ src/test/ui/imports/overlapping_pub_trait.rs | 15 ++++++++++++++ .../ui/imports/overlapping_pub_trait.stderr | 20 +++++++++++++++++++ src/test/ui/imports/unnamed_pub_trait.rs | 16 +++++++++++++++ src/test/ui/imports/unnamed_pub_trait.stderr | 20 +++++++++++++++++++ 6 files changed, 97 insertions(+) create mode 100644 src/test/ui/imports/auxiliary/overlapping_pub_trait_source.rs create mode 100644 src/test/ui/imports/auxiliary/unnamed_pub_trait_source.rs create mode 100644 src/test/ui/imports/overlapping_pub_trait.rs create mode 100644 src/test/ui/imports/overlapping_pub_trait.stderr create mode 100644 src/test/ui/imports/unnamed_pub_trait.rs create mode 100644 src/test/ui/imports/unnamed_pub_trait.stderr diff --git a/src/test/ui/imports/auxiliary/overlapping_pub_trait_source.rs b/src/test/ui/imports/auxiliary/overlapping_pub_trait_source.rs new file mode 100644 index 00000000000..2a25d60acff --- /dev/null +++ b/src/test/ui/imports/auxiliary/overlapping_pub_trait_source.rs @@ -0,0 +1,13 @@ +/* This crate declares an item as both `prelude::*` and `m::Tr`. + * The compiler should always suggest `m::Tr`. */ + +pub struct S; + +pub mod prelude { + pub use crate::m::Tr as _; +} + +pub mod m { + pub trait Tr { fn method(&self); } + impl Tr for crate::S { fn method(&self) {} } +} diff --git a/src/test/ui/imports/auxiliary/unnamed_pub_trait_source.rs b/src/test/ui/imports/auxiliary/unnamed_pub_trait_source.rs new file mode 100644 index 00000000000..d73c9a795b6 --- /dev/null +++ b/src/test/ui/imports/auxiliary/unnamed_pub_trait_source.rs @@ -0,0 +1,13 @@ +/* This crate declares an item that is unnamed. + * Its only public path is through `prelude::*`. */ + +pub struct S; + +mod m { + pub trait Tr { fn method(&self); } + impl Tr for crate::S { fn method(&self) {} } +} + +pub mod prelude { + pub use crate::m::Tr as _; +} diff --git a/src/test/ui/imports/overlapping_pub_trait.rs b/src/test/ui/imports/overlapping_pub_trait.rs new file mode 100644 index 00000000000..a28c3b6cd46 --- /dev/null +++ b/src/test/ui/imports/overlapping_pub_trait.rs @@ -0,0 +1,15 @@ +// aux-build:overlapping_pub_trait_source.rs + +/* + * This crate declares two public paths, `m::Tr` and `prelude::_`. Make sure we prefer the former. + */ +extern crate overlapping_pub_trait_source; + +fn main() { + //~^ HELP the following trait is implemented but not in scope; perhaps add a `use` for it: + //~| SUGGESTION overlapping_pub_trait_source::prelude::_ + use overlapping_pub_trait_source::S; + S.method(); + //~^ ERROR no method named `method` found for struct `S` in the current scope [E0599] + //~| HELP items from traits can only be used if the trait is in scope +} diff --git a/src/test/ui/imports/overlapping_pub_trait.stderr b/src/test/ui/imports/overlapping_pub_trait.stderr new file mode 100644 index 00000000000..36ea9ae006e --- /dev/null +++ b/src/test/ui/imports/overlapping_pub_trait.stderr @@ -0,0 +1,20 @@ +error[E0599]: no method named `method` found for struct `S` in the current scope + --> $DIR/overlapping_pub_trait.rs:12:7 + | +LL | S.method(); + | ^^^^^^ method not found in `S` + | + ::: $DIR/auxiliary/overlapping_pub_trait_source.rs:11:23 + | +LL | pub trait Tr { fn method(&self); } + | ------ the method is available for `S` here + | + = help: items from traits can only be used if the trait is in scope +help: the following trait is implemented but not in scope; perhaps add a `use` for it: + | +LL | use overlapping_pub_trait_source::prelude::_; + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0599`. diff --git a/src/test/ui/imports/unnamed_pub_trait.rs b/src/test/ui/imports/unnamed_pub_trait.rs new file mode 100644 index 00000000000..79f7ebfbd4a --- /dev/null +++ b/src/test/ui/imports/unnamed_pub_trait.rs @@ -0,0 +1,16 @@ +// aux-build:unnamed_pub_trait_source.rs + +/* + * This crate declares an unnameable public path for our item. Make sure we don't suggest + * importing it by name, and instead we suggest importing it by glob. + */ +extern crate unnamed_pub_trait_source; + +fn main() { + //~^ HELP the following trait is implemented but not in scope; perhaps add a `use` for it: + //~| SUGGESTION unnamed_pub_trait_source::prelude::_ + use unnamed_pub_trait_source::S; + S.method(); + //~^ ERROR no method named `method` found for struct `S` in the current scope [E0599] + //~| HELP items from traits can only be used if the trait is in scope +} diff --git a/src/test/ui/imports/unnamed_pub_trait.stderr b/src/test/ui/imports/unnamed_pub_trait.stderr new file mode 100644 index 00000000000..75ccbcd384e --- /dev/null +++ b/src/test/ui/imports/unnamed_pub_trait.stderr @@ -0,0 +1,20 @@ +error[E0599]: no method named `method` found for struct `S` in the current scope + --> $DIR/unnamed_pub_trait.rs:13:7 + | +LL | S.method(); + | ^^^^^^ method not found in `S` + | + ::: $DIR/auxiliary/unnamed_pub_trait_source.rs:7:23 + | +LL | pub trait Tr { fn method(&self); } + | ------ the method is available for `S` here + | + = help: items from traits can only be used if the trait is in scope +help: the following trait is implemented but not in scope; perhaps add a `use` for it: + | +LL | use unnamed_pub_trait_source::prelude::_; + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0599`.