diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/error-codes/e0119 | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/error-codes/e0119')
-rw-r--r-- | src/test/ui/error-codes/e0119/auxiliary/complex_impl_support.rs | 22 | ||||
-rw-r--r-- | src/test/ui/error-codes/e0119/auxiliary/issue-23563-a.rs | 25 | ||||
-rw-r--r-- | src/test/ui/error-codes/e0119/complex-impl.rs | 11 | ||||
-rw-r--r-- | src/test/ui/error-codes/e0119/complex-impl.stderr | 14 | ||||
-rw-r--r-- | src/test/ui/error-codes/e0119/conflict-with-std.rs | 26 | ||||
-rw-r--r-- | src/test/ui/error-codes/e0119/conflict-with-std.stderr | 32 | ||||
-rw-r--r-- | src/test/ui/error-codes/e0119/issue-23563.rs | 29 | ||||
-rw-r--r-- | src/test/ui/error-codes/e0119/issue-23563.stderr | 13 | ||||
-rw-r--r-- | src/test/ui/error-codes/e0119/issue-27403.rs | 11 | ||||
-rw-r--r-- | src/test/ui/error-codes/e0119/issue-27403.stderr | 13 | ||||
-rw-r--r-- | src/test/ui/error-codes/e0119/issue-28981.rs | 7 | ||||
-rw-r--r-- | src/test/ui/error-codes/e0119/issue-28981.stderr | 12 | ||||
-rw-r--r-- | src/test/ui/error-codes/e0119/so-37347311.rs | 17 | ||||
-rw-r--r-- | src/test/ui/error-codes/e0119/so-37347311.stderr | 12 |
14 files changed, 244 insertions, 0 deletions
diff --git a/src/test/ui/error-codes/e0119/auxiliary/complex_impl_support.rs b/src/test/ui/error-codes/e0119/auxiliary/complex_impl_support.rs new file mode 100644 index 000000000..ad5bb107f --- /dev/null +++ b/src/test/ui/error-codes/e0119/auxiliary/complex_impl_support.rs @@ -0,0 +1,22 @@ +use std::marker::PhantomData; + +pub trait External {} + +pub struct M<'a, 'b, 'c, T, U, V> { + a: PhantomData<&'a ()>, + b: PhantomData<&'b ()>, + c: PhantomData<&'c ()>, + d: PhantomData<T>, + e: PhantomData<U>, + f: PhantomData<V>, +} + +impl<'a, 'b, 'c, T, U, V, W> External for (T, M<'a, 'b, 'c, Box<U>, V, W>) +where + 'b: 'a, + T: 'a, + U: (FnOnce(T) -> V) + 'static, + V: Iterator<Item=T> + Clone, + W: std::ops::Add, + W::Output: Copy, +{} diff --git a/src/test/ui/error-codes/e0119/auxiliary/issue-23563-a.rs b/src/test/ui/error-codes/e0119/auxiliary/issue-23563-a.rs new file mode 100644 index 000000000..141f36369 --- /dev/null +++ b/src/test/ui/error-codes/e0119/auxiliary/issue-23563-a.rs @@ -0,0 +1,25 @@ +// Ref: https://github.com/rust-lang/rust/issues/23563#issuecomment-260751672 + +pub trait LolTo<T> { + fn convert_to(&self) -> T; +} + +pub trait LolInto<T>: Sized { + fn convert_into(self) -> T; +} + +pub trait LolFrom<T> { + fn from(_: T) -> Self; +} + +impl<'a, T: ?Sized, U> LolInto<U> for &'a T where T: LolTo<U> { + fn convert_into(self) -> U { + self.convert_to() + } +} + +impl<T, U> LolFrom<T> for U where T: LolInto<U> { + fn from(t: T) -> U { + t.convert_into() + } +} diff --git a/src/test/ui/error-codes/e0119/complex-impl.rs b/src/test/ui/error-codes/e0119/complex-impl.rs new file mode 100644 index 000000000..9149e4ce5 --- /dev/null +++ b/src/test/ui/error-codes/e0119/complex-impl.rs @@ -0,0 +1,11 @@ +// aux-build:complex_impl_support.rs + +extern crate complex_impl_support; + +use complex_impl_support::{External, M}; + +struct Q; + +impl<R> External for (Q, R) {} //~ ERROR only traits defined + +fn main() {} diff --git a/src/test/ui/error-codes/e0119/complex-impl.stderr b/src/test/ui/error-codes/e0119/complex-impl.stderr new file mode 100644 index 000000000..654073eec --- /dev/null +++ b/src/test/ui/error-codes/e0119/complex-impl.stderr @@ -0,0 +1,14 @@ +error[E0117]: only traits defined in the current crate can be implemented for arbitrary types + --> $DIR/complex-impl.rs:9:1 + | +LL | impl<R> External for (Q, R) {} + | ^^^^^^^^^^^^^^^^^^^^^------ + | | | + | | this is not defined in the current crate because tuples are always foreign + | impl doesn't use only types from inside the current crate + | + = note: define and implement a trait or new type instead + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0117`. diff --git a/src/test/ui/error-codes/e0119/conflict-with-std.rs b/src/test/ui/error-codes/e0119/conflict-with-std.rs new file mode 100644 index 000000000..c9db2bab1 --- /dev/null +++ b/src/test/ui/error-codes/e0119/conflict-with-std.rs @@ -0,0 +1,26 @@ +use std::marker::PhantomData; +use std::convert::{TryFrom, AsRef}; + +struct Q; +impl AsRef<Q> for Box<Q> { //~ ERROR conflicting implementations + fn as_ref(&self) -> &Q { + &**self + } +} + +struct S; +impl From<S> for S { //~ ERROR conflicting implementations + fn from(s: S) -> S { + s + } +} + +struct X; +impl TryFrom<X> for X { //~ ERROR conflicting implementations + type Error = (); + fn try_from(u: X) -> Result<X, ()> { + Ok(u) + } +} + +fn main() {} diff --git a/src/test/ui/error-codes/e0119/conflict-with-std.stderr b/src/test/ui/error-codes/e0119/conflict-with-std.stderr new file mode 100644 index 000000000..3ff96a6a4 --- /dev/null +++ b/src/test/ui/error-codes/e0119/conflict-with-std.stderr @@ -0,0 +1,32 @@ +error[E0119]: conflicting implementations of trait `std::convert::AsRef<Q>` for type `std::boxed::Box<Q>` + --> $DIR/conflict-with-std.rs:5:1 + | +LL | impl AsRef<Q> for Box<Q> { + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: conflicting implementation in crate `alloc`: + - impl<T, A> AsRef<T> for Box<T, A> + where A: Allocator, T: ?Sized; + +error[E0119]: conflicting implementations of trait `std::convert::From<S>` for type `S` + --> $DIR/conflict-with-std.rs:12:1 + | +LL | impl From<S> for S { + | ^^^^^^^^^^^^^^^^^^ + | + = note: conflicting implementation in crate `core`: + - impl<T> From<T> for T; + +error[E0119]: conflicting implementations of trait `std::convert::TryFrom<X>` for type `X` + --> $DIR/conflict-with-std.rs:19:1 + | +LL | impl TryFrom<X> for X { + | ^^^^^^^^^^^^^^^^^^^^^ + | + = note: conflicting implementation in crate `core`: + - impl<T, U> TryFrom<U> for T + where U: Into<T>; + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0119`. diff --git a/src/test/ui/error-codes/e0119/issue-23563.rs b/src/test/ui/error-codes/e0119/issue-23563.rs new file mode 100644 index 000000000..f578560c5 --- /dev/null +++ b/src/test/ui/error-codes/e0119/issue-23563.rs @@ -0,0 +1,29 @@ +// aux-build:issue-23563-a.rs + +// Ref: https://github.com/rust-lang/rust/issues/23563#issuecomment-260751672 + +extern crate issue_23563_a as a; + +use a::LolFrom; +use a::LolInto; +use a::LolTo; + +struct LocalType<T>(Option<T>); + +impl<'a, T> LolFrom<&'a [T]> for LocalType<T> { //~ ERROR conflicting implementations of trait + fn from(_: &'a [T]) -> LocalType<T> { LocalType(None) } +} + +impl<T> LolInto<LocalType<T>> for LocalType<T> { + fn convert_into(self) -> LocalType<T> { + self + } +} + +impl LolTo<LocalType<u8>> for [u8] { + fn convert_to(&self) -> LocalType<u8> { + LocalType(None) + } +} + +fn main() {} diff --git a/src/test/ui/error-codes/e0119/issue-23563.stderr b/src/test/ui/error-codes/e0119/issue-23563.stderr new file mode 100644 index 000000000..f149cef58 --- /dev/null +++ b/src/test/ui/error-codes/e0119/issue-23563.stderr @@ -0,0 +1,13 @@ +error[E0119]: conflicting implementations of trait `a::LolFrom<&[_]>` for type `LocalType<_>` + --> $DIR/issue-23563.rs:13:1 + | +LL | impl<'a, T> LolFrom<&'a [T]> for LocalType<T> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: conflicting implementation in crate `issue_23563_a`: + - impl<T, U> LolFrom<T> for U + where T: LolInto<U>; + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0119`. diff --git a/src/test/ui/error-codes/e0119/issue-27403.rs b/src/test/ui/error-codes/e0119/issue-27403.rs new file mode 100644 index 000000000..b03a564ff --- /dev/null +++ b/src/test/ui/error-codes/e0119/issue-27403.rs @@ -0,0 +1,11 @@ +pub struct GenX<S> { + inner: S, +} + +impl<S> Into<S> for GenX<S> { //~ ERROR conflicting implementations + fn into(self) -> S { + self.inner + } +} + +fn main() {} diff --git a/src/test/ui/error-codes/e0119/issue-27403.stderr b/src/test/ui/error-codes/e0119/issue-27403.stderr new file mode 100644 index 000000000..c11a50487 --- /dev/null +++ b/src/test/ui/error-codes/e0119/issue-27403.stderr @@ -0,0 +1,13 @@ +error[E0119]: conflicting implementations of trait `std::convert::Into<_>` for type `GenX<_>` + --> $DIR/issue-27403.rs:5:1 + | +LL | impl<S> Into<S> for GenX<S> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: conflicting implementation in crate `core`: + - impl<T, U> Into<U> for T + where U: From<T>; + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0119`. diff --git a/src/test/ui/error-codes/e0119/issue-28981.rs b/src/test/ui/error-codes/e0119/issue-28981.rs new file mode 100644 index 000000000..5fb7e9a99 --- /dev/null +++ b/src/test/ui/error-codes/e0119/issue-28981.rs @@ -0,0 +1,7 @@ +use std::ops::Deref; + +struct Foo; + +impl<Foo> Deref for Foo { } //~ ERROR must be used + +fn main() {} diff --git a/src/test/ui/error-codes/e0119/issue-28981.stderr b/src/test/ui/error-codes/e0119/issue-28981.stderr new file mode 100644 index 000000000..97b570bc7 --- /dev/null +++ b/src/test/ui/error-codes/e0119/issue-28981.stderr @@ -0,0 +1,12 @@ +error[E0210]: type parameter `Foo` must be used as the type parameter for some local type (e.g., `MyStruct<Foo>`) + --> $DIR/issue-28981.rs:5:6 + | +LL | impl<Foo> Deref for Foo { } + | ^^^ type parameter `Foo` must be used as the type parameter for some local type + | + = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local + = note: only traits defined in the current crate can be implemented for a type parameter + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0210`. diff --git a/src/test/ui/error-codes/e0119/so-37347311.rs b/src/test/ui/error-codes/e0119/so-37347311.rs new file mode 100644 index 000000000..d5f624bc4 --- /dev/null +++ b/src/test/ui/error-codes/e0119/so-37347311.rs @@ -0,0 +1,17 @@ +// Ref: https://stackoverflow.com/q/37347311 + +trait Storage { + type Error; +} + +enum MyError<S: Storage> { + StorageProblem(S::Error), +} + +impl<S: Storage> From<S::Error> for MyError<S> { //~ ERROR conflicting implementations + fn from(error: S::Error) -> MyError<S> { + MyError::StorageProblem(error) + } +} + +fn main() {} diff --git a/src/test/ui/error-codes/e0119/so-37347311.stderr b/src/test/ui/error-codes/e0119/so-37347311.stderr new file mode 100644 index 000000000..f1c2b0d29 --- /dev/null +++ b/src/test/ui/error-codes/e0119/so-37347311.stderr @@ -0,0 +1,12 @@ +error[E0119]: conflicting implementations of trait `std::convert::From<MyError<_>>` for type `MyError<_>` + --> $DIR/so-37347311.rs:11:1 + | +LL | impl<S: Storage> From<S::Error> for MyError<S> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: conflicting implementation in crate `core`: + - impl<T> From<T> for T; + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0119`. |