diff options
| author | mejrs <59372212+mejrs@users.noreply.github.com> | 2025-04-01 02:47:12 +0200 |
|---|---|---|
| committer | mejrs <59372212+mejrs@users.noreply.github.com> | 2025-04-14 00:12:37 +0200 |
| commit | 40e76c157548442fce755ec9cc2274aef11454ba (patch) | |
| tree | ea194f6aab250bdba10d802a3fe7cd8e97fb5c97 | |
| parent | 10ec5cbe96b8b1ba96fbacc207d6a2f0d19ca9e2 (diff) | |
| download | rust-40e76c157548442fce755ec9cc2274aef11454ba.tar.gz rust-40e76c157548442fce755ec9cc2274aef11454ba.zip | |
Test that `Self` properly works in filters
| -rw-r--r-- | tests/ui/on-unimplemented/use_self_no_underscore.rs | 14 | ||||
| -rw-r--r-- | tests/ui/on-unimplemented/use_self_no_underscore.stderr | 15 |
2 files changed, 29 insertions, 0 deletions
diff --git a/tests/ui/on-unimplemented/use_self_no_underscore.rs b/tests/ui/on-unimplemented/use_self_no_underscore.rs new file mode 100644 index 00000000000..045ef1a5d3f --- /dev/null +++ b/tests/ui/on-unimplemented/use_self_no_underscore.rs @@ -0,0 +1,14 @@ +#![feature(rustc_attrs)] + +#[rustc_on_unimplemented(on( + all(A = "{integer}", any(Self = "[{integral}; _]",)), + message = "an array of type `{Self}` cannot be built directly from an iterator", +))] +pub trait FromIterator<A>: Sized { + fn from_iter<T: IntoIterator<Item = A>>(iter: T) -> Self; +} +fn main() { + let iter = 0..42_8; + let x: [u8; 8] = FromIterator::from_iter(iter); + //~^ ERROR an array of type `[u8; 8]` cannot be built directly from an iterator +} diff --git a/tests/ui/on-unimplemented/use_self_no_underscore.stderr b/tests/ui/on-unimplemented/use_self_no_underscore.stderr new file mode 100644 index 00000000000..d01aee3485f --- /dev/null +++ b/tests/ui/on-unimplemented/use_self_no_underscore.stderr @@ -0,0 +1,15 @@ +error[E0277]: an array of type `[u8; 8]` cannot be built directly from an iterator + --> $DIR/use_self_no_underscore.rs:12:22 + | +LL | let x: [u8; 8] = FromIterator::from_iter(iter); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromIterator<{integer}>` is not implemented for `[u8; 8]` + | +help: this trait has no implementations, consider adding one + --> $DIR/use_self_no_underscore.rs:7:1 + | +LL | pub trait FromIterator<A>: Sized { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0277`. |
