diff options
| -rw-r--r-- | tests/ui/typeck/auxiliary/private-dep.rs | 3 | ||||
| -rw-r--r-- | tests/ui/typeck/auxiliary/public-dep.rs | 11 | ||||
| -rw-r--r-- | tests/ui/typeck/dont-suggest-private-dependencies.rs | 30 | ||||
| -rw-r--r-- | tests/ui/typeck/dont-suggest-private-dependencies.stderr | 43 |
4 files changed, 87 insertions, 0 deletions
diff --git a/tests/ui/typeck/auxiliary/private-dep.rs b/tests/ui/typeck/auxiliary/private-dep.rs new file mode 100644 index 00000000000..472b40ef622 --- /dev/null +++ b/tests/ui/typeck/auxiliary/private-dep.rs @@ -0,0 +1,3 @@ +pub trait A { + fn foo() {} +} diff --git a/tests/ui/typeck/auxiliary/public-dep.rs b/tests/ui/typeck/auxiliary/public-dep.rs new file mode 100644 index 00000000000..438692a1caa --- /dev/null +++ b/tests/ui/typeck/auxiliary/public-dep.rs @@ -0,0 +1,11 @@ +//@ aux-crate:priv:private_dep=private-dep.rs +//@ compile-flags: -Zunstable-options + +extern crate private_dep; +use private_dep::A; + +pub struct B; + +impl A for B { + fn foo() {} +} diff --git a/tests/ui/typeck/dont-suggest-private-dependencies.rs b/tests/ui/typeck/dont-suggest-private-dependencies.rs new file mode 100644 index 00000000000..afac00c5213 --- /dev/null +++ b/tests/ui/typeck/dont-suggest-private-dependencies.rs @@ -0,0 +1,30 @@ +// Don't suggest importing a function from a private dependency. +// Issues: #138191, #142676 + +// Avoid suggesting traits from std-private deps +//@ forbid-output: compiler_builtins +//@ forbid-output: object + +// Check a custom trait to withstand changes in above crates +//@ aux-crate:public_dep=public-dep.rs +//@ compile-flags: -Zunstable-options +//@ forbid-output: private_dep + +struct VecReader(Vec<u8>); + +impl std::io::Read for VecReader { + fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> { + self.0.read(buf) + //~^ ERROR no method named `read` found for struct `Vec<u8>` + } +} + +extern crate public_dep; +use public_dep::B; + +fn main() { + let _ = u8::cast_from_lossy(9); + //~^ ERROR no function or associated item named `cast_from_lossy` found for type `u8` + let _ = B::foo(); + //~^ ERROR no function or associated item named `foo` found for struct `B` +} diff --git a/tests/ui/typeck/dont-suggest-private-dependencies.stderr b/tests/ui/typeck/dont-suggest-private-dependencies.stderr new file mode 100644 index 00000000000..18848a2c08d --- /dev/null +++ b/tests/ui/typeck/dont-suggest-private-dependencies.stderr @@ -0,0 +1,43 @@ +error[E0599]: no method named `read` found for struct `Vec<u8>` in the current scope + --> $DIR/dont-suggest-private-dependencies.rs:17:16 + | +LL | self.0.read(buf) + | ^^^^ + | + = help: items from traits can only be used if the trait is in scope +help: trait `ReadRef` which provides `read` is implemented but not in scope; perhaps you want to import it + | +LL + use object::read::read_ref::ReadRef; + | +help: there is a method `read_at` with a similar name + | +LL | self.0.read_at(buf) + | +++ + +error[E0599]: no function or associated item named `cast_from_lossy` found for type `u8` in the current scope + --> $DIR/dont-suggest-private-dependencies.rs:26:17 + | +LL | let _ = u8::cast_from_lossy(9); + | ^^^^^^^^^^^^^^^ function or associated item not found in `u8` + | + = help: items from traits can only be used if the trait is in scope +help: trait `CastFrom` which provides `cast_from_lossy` is implemented but not in scope; perhaps you want to import it + | +LL + use compiler_builtins::math::libm_math::support::int_traits::CastFrom; + | + +error[E0599]: no function or associated item named `foo` found for struct `B` in the current scope + --> $DIR/dont-suggest-private-dependencies.rs:28:16 + | +LL | let _ = B::foo(); + | ^^^ function or associated item not found in `B` + | + = help: items from traits can only be used if the trait is in scope +help: trait `A` which provides `foo` is implemented but not in scope; perhaps you want to import it + | +LL + use private_dep::A; + | + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0599`. |
