summaryrefslogtreecommitdiffstats
path: root/src/test/ui/dyn-star
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/ui/dyn-star')
-rw-r--r--src/test/ui/dyn-star/align.normal.stderr11
-rw-r--r--src/test/ui/dyn-star/align.over_aligned.stderr20
-rw-r--r--src/test/ui/dyn-star/align.rs17
-rw-r--r--src/test/ui/dyn-star/check-size-at-cast-polymorphic-bad.rs15
-rw-r--r--src/test/ui/dyn-star/check-size-at-cast-polymorphic-bad.stderr15
-rw-r--r--src/test/ui/dyn-star/check-size-at-cast-polymorphic.rs16
-rw-r--r--src/test/ui/dyn-star/check-size-at-cast.rs10
-rw-r--r--src/test/ui/dyn-star/check-size-at-cast.stderr11
-rw-r--r--src/test/ui/dyn-star/dispatch-on-pin-mut.rs52
-rw-r--r--src/test/ui/dyn-star/dispatch-on-pin-mut.run.stdout1
-rw-r--r--src/test/ui/dyn-star/dispatch-on-pin-mut.stderr11
-rw-r--r--src/test/ui/dyn-star/dont-unsize-coerce-dyn-star.rs27
-rw-r--r--src/test/ui/dyn-star/dont-unsize-coerce-dyn-star.run.stdout2
-rw-r--r--src/test/ui/dyn-star/dont-unsize-coerce-dyn-star.stderr11
-rw-r--r--src/test/ui/dyn-star/dyn-async-trait.rs36
-rw-r--r--src/test/ui/dyn-star/issue-102430.rs32
-rw-r--r--src/test/ui/dyn-star/no-unsize-coerce-dyn-trait.rs13
-rw-r--r--src/test/ui/dyn-star/no-unsize-coerce-dyn-trait.stderr23
-rw-r--r--src/test/ui/dyn-star/return.rs10
-rw-r--r--src/test/ui/dyn-star/return.stderr11
-rw-r--r--src/test/ui/dyn-star/unsize-into-ref-dyn-star.rs9
-rw-r--r--src/test/ui/dyn-star/unsize-into-ref-dyn-star.stderr9
-rw-r--r--src/test/ui/dyn-star/upcast.rs3
-rw-r--r--src/test/ui/dyn-star/upcast.stderr20
24 files changed, 383 insertions, 2 deletions
diff --git a/src/test/ui/dyn-star/align.normal.stderr b/src/test/ui/dyn-star/align.normal.stderr
new file mode 100644
index 000000000..983d7bf6e
--- /dev/null
+++ b/src/test/ui/dyn-star/align.normal.stderr
@@ -0,0 +1,11 @@
+warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes
+ --> $DIR/align.rs:4:12
+ |
+LL | #![feature(dyn_star)]
+ | ^^^^^^^^
+ |
+ = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
+ = note: `#[warn(incomplete_features)]` on by default
+
+warning: 1 warning emitted
+
diff --git a/src/test/ui/dyn-star/align.over_aligned.stderr b/src/test/ui/dyn-star/align.over_aligned.stderr
new file mode 100644
index 000000000..6b6fc55d8
--- /dev/null
+++ b/src/test/ui/dyn-star/align.over_aligned.stderr
@@ -0,0 +1,20 @@
+warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes
+ --> $DIR/align.rs:4:12
+ |
+LL | #![feature(dyn_star)]
+ | ^^^^^^^^
+ |
+ = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
+ = note: `#[warn(incomplete_features)]` on by default
+
+error[E0277]: `AlignedUsize` needs to be a pointer-sized type
+ --> $DIR/align.rs:15:13
+ |
+LL | let x = AlignedUsize(12) as dyn* Debug;
+ | ^^^^^^^^^^^^^^^^ `AlignedUsize` needs to be a pointer-sized type
+ |
+ = help: the trait `PointerSized` is not implemented for `AlignedUsize`
+
+error: aborting due to previous error; 1 warning emitted
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/dyn-star/align.rs b/src/test/ui/dyn-star/align.rs
new file mode 100644
index 000000000..fb41a05a0
--- /dev/null
+++ b/src/test/ui/dyn-star/align.rs
@@ -0,0 +1,17 @@
+// revisions: normal over_aligned
+//[normal] check-pass
+
+#![feature(dyn_star)]
+//~^ WARN the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes
+
+use std::fmt::Debug;
+
+#[cfg_attr(over_aligned, repr(C, align(1024)))]
+#[cfg_attr(not(over_aligned), repr(C))]
+#[derive(Debug)]
+struct AlignedUsize(usize);
+
+fn main() {
+ let x = AlignedUsize(12) as dyn* Debug;
+ //[over_aligned]~^ ERROR `AlignedUsize` needs to be a pointer-sized type
+}
diff --git a/src/test/ui/dyn-star/check-size-at-cast-polymorphic-bad.rs b/src/test/ui/dyn-star/check-size-at-cast-polymorphic-bad.rs
new file mode 100644
index 000000000..e19e36cc7
--- /dev/null
+++ b/src/test/ui/dyn-star/check-size-at-cast-polymorphic-bad.rs
@@ -0,0 +1,15 @@
+#![feature(dyn_star)]
+#![allow(incomplete_features)]
+
+use std::fmt::Debug;
+
+fn dyn_debug(_: (dyn* Debug + '_)) {
+
+}
+
+fn polymorphic<T: Debug + ?Sized>(t: &T) {
+ dyn_debug(t);
+ //~^ ERROR `&T` needs to be a pointer-sized type
+}
+
+fn main() {}
diff --git a/src/test/ui/dyn-star/check-size-at-cast-polymorphic-bad.stderr b/src/test/ui/dyn-star/check-size-at-cast-polymorphic-bad.stderr
new file mode 100644
index 000000000..53ccbe43d
--- /dev/null
+++ b/src/test/ui/dyn-star/check-size-at-cast-polymorphic-bad.stderr
@@ -0,0 +1,15 @@
+error[E0277]: `&T` needs to be a pointer-sized type
+ --> $DIR/check-size-at-cast-polymorphic-bad.rs:11:15
+ |
+LL | dyn_debug(t);
+ | ^ `&T` needs to be a pointer-sized type
+ |
+ = help: the trait `PointerSized` is not implemented for `&T`
+help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
+ |
+LL | fn polymorphic<T: Debug + ?Sized>(t: &T) where &T: PointerSized {
+ | ++++++++++++++++++++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/dyn-star/check-size-at-cast-polymorphic.rs b/src/test/ui/dyn-star/check-size-at-cast-polymorphic.rs
new file mode 100644
index 000000000..5c0a3d256
--- /dev/null
+++ b/src/test/ui/dyn-star/check-size-at-cast-polymorphic.rs
@@ -0,0 +1,16 @@
+// check-pass
+
+#![feature(dyn_star)]
+#![allow(incomplete_features)]
+
+use std::fmt::Debug;
+
+fn dyn_debug(_: (dyn* Debug + '_)) {
+
+}
+
+fn polymorphic<T: Debug>(t: &T) {
+ dyn_debug(t);
+}
+
+fn main() {}
diff --git a/src/test/ui/dyn-star/check-size-at-cast.rs b/src/test/ui/dyn-star/check-size-at-cast.rs
new file mode 100644
index 000000000..1f22f7983
--- /dev/null
+++ b/src/test/ui/dyn-star/check-size-at-cast.rs
@@ -0,0 +1,10 @@
+#![feature(dyn_star)]
+#![allow(incomplete_features)]
+
+use std::fmt::Debug;
+
+fn main() {
+ let i = [1, 2, 3, 4] as dyn* Debug;
+ //~^ ERROR `[i32; 4]` needs to be a pointer-sized type
+ dbg!(i);
+}
diff --git a/src/test/ui/dyn-star/check-size-at-cast.stderr b/src/test/ui/dyn-star/check-size-at-cast.stderr
new file mode 100644
index 000000000..af2a1ccf7
--- /dev/null
+++ b/src/test/ui/dyn-star/check-size-at-cast.stderr
@@ -0,0 +1,11 @@
+error[E0277]: `[i32; 4]` needs to be a pointer-sized type
+ --> $DIR/check-size-at-cast.rs:7:13
+ |
+LL | let i = [1, 2, 3, 4] as dyn* Debug;
+ | ^^^^^^^^^^^^ `[i32; 4]` needs to be a pointer-sized type
+ |
+ = help: the trait `PointerSized` is not implemented for `[i32; 4]`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/dyn-star/dispatch-on-pin-mut.rs b/src/test/ui/dyn-star/dispatch-on-pin-mut.rs
new file mode 100644
index 000000000..5774c8b2a
--- /dev/null
+++ b/src/test/ui/dyn-star/dispatch-on-pin-mut.rs
@@ -0,0 +1,52 @@
+// run-pass
+// edition:2021
+// check-run-results
+
+#![feature(dyn_star)]
+//~^ WARN the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes
+
+use std::future::Future;
+
+async fn foo(f: dyn* Future<Output = i32>) {
+ println!("value: {}", f.await);
+}
+
+async fn async_main() {
+ foo(Box::pin(async { 1 })).await
+}
+
+// ------------------------------------------------------------------------- //
+// Implementation Details Below...
+
+use std::pin::Pin;
+use std::task::*;
+
+pub fn noop_waker() -> Waker {
+ let raw = RawWaker::new(std::ptr::null(), &NOOP_WAKER_VTABLE);
+
+ // SAFETY: the contracts for RawWaker and RawWakerVTable are upheld
+ unsafe { Waker::from_raw(raw) }
+}
+
+const NOOP_WAKER_VTABLE: RawWakerVTable = RawWakerVTable::new(noop_clone, noop, noop, noop);
+
+unsafe fn noop_clone(_p: *const ()) -> RawWaker {
+ RawWaker::new(std::ptr::null(), &NOOP_WAKER_VTABLE)
+}
+
+unsafe fn noop(_p: *const ()) {}
+
+fn main() {
+ let mut fut = async_main();
+
+ // Poll loop, just to test the future...
+ let waker = noop_waker();
+ let ctx = &mut Context::from_waker(&waker);
+
+ loop {
+ match unsafe { Pin::new_unchecked(&mut fut).poll(ctx) } {
+ Poll::Pending => {}
+ Poll::Ready(()) => break,
+ }
+ }
+}
diff --git a/src/test/ui/dyn-star/dispatch-on-pin-mut.run.stdout b/src/test/ui/dyn-star/dispatch-on-pin-mut.run.stdout
new file mode 100644
index 000000000..96c5ca698
--- /dev/null
+++ b/src/test/ui/dyn-star/dispatch-on-pin-mut.run.stdout
@@ -0,0 +1 @@
+value: 1
diff --git a/src/test/ui/dyn-star/dispatch-on-pin-mut.stderr b/src/test/ui/dyn-star/dispatch-on-pin-mut.stderr
new file mode 100644
index 000000000..fdf74aa7e
--- /dev/null
+++ b/src/test/ui/dyn-star/dispatch-on-pin-mut.stderr
@@ -0,0 +1,11 @@
+warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes
+ --> $DIR/dispatch-on-pin-mut.rs:5:12
+ |
+LL | #![feature(dyn_star)]
+ | ^^^^^^^^
+ |
+ = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
+ = note: `#[warn(incomplete_features)]` on by default
+
+warning: 1 warning emitted
+
diff --git a/src/test/ui/dyn-star/dont-unsize-coerce-dyn-star.rs b/src/test/ui/dyn-star/dont-unsize-coerce-dyn-star.rs
new file mode 100644
index 000000000..c12b16f16
--- /dev/null
+++ b/src/test/ui/dyn-star/dont-unsize-coerce-dyn-star.rs
@@ -0,0 +1,27 @@
+// run-pass
+// check-run-results
+
+#![feature(dyn_star)]
+//~^ WARN the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes
+
+trait AddOne {
+ fn add1(&mut self) -> usize;
+}
+
+impl AddOne for usize {
+ fn add1(&mut self) -> usize {
+ *self += 1;
+ *self
+ }
+}
+
+fn add_one(i: &mut (dyn* AddOne + '_)) -> usize {
+ i.add1()
+}
+
+fn main() {
+ let mut x = 42usize as dyn* AddOne;
+
+ println!("{}", add_one(&mut x));
+ println!("{}", add_one(&mut x));
+}
diff --git a/src/test/ui/dyn-star/dont-unsize-coerce-dyn-star.run.stdout b/src/test/ui/dyn-star/dont-unsize-coerce-dyn-star.run.stdout
new file mode 100644
index 000000000..b4db3ed70
--- /dev/null
+++ b/src/test/ui/dyn-star/dont-unsize-coerce-dyn-star.run.stdout
@@ -0,0 +1,2 @@
+43
+44
diff --git a/src/test/ui/dyn-star/dont-unsize-coerce-dyn-star.stderr b/src/test/ui/dyn-star/dont-unsize-coerce-dyn-star.stderr
new file mode 100644
index 000000000..933c13383
--- /dev/null
+++ b/src/test/ui/dyn-star/dont-unsize-coerce-dyn-star.stderr
@@ -0,0 +1,11 @@
+warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes
+ --> $DIR/dont-unsize-coerce-dyn-star.rs:4:12
+ |
+LL | #![feature(dyn_star)]
+ | ^^^^^^^^
+ |
+ = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
+ = note: `#[warn(incomplete_features)]` on by default
+
+warning: 1 warning emitted
+
diff --git a/src/test/ui/dyn-star/dyn-async-trait.rs b/src/test/ui/dyn-star/dyn-async-trait.rs
new file mode 100644
index 000000000..9b27133b4
--- /dev/null
+++ b/src/test/ui/dyn-star/dyn-async-trait.rs
@@ -0,0 +1,36 @@
+// check-pass
+// edition: 2021
+
+// This test case is meant to demonstrate how close we can get to async
+// functions in dyn traits with the current level of dyn* support.
+
+#![feature(dyn_star)]
+#![allow(incomplete_features)]
+
+use std::future::Future;
+
+trait DynAsyncCounter {
+ fn increment<'a>(&'a mut self) -> dyn* Future<Output = usize> + 'a;
+}
+
+struct MyCounter {
+ count: usize,
+}
+
+impl DynAsyncCounter for MyCounter {
+ fn increment<'a>(&'a mut self) -> dyn* Future<Output = usize> + 'a {
+ Box::pin(async {
+ self.count += 1;
+ self.count
+ })
+ }
+}
+
+async fn do_counter(counter: &mut dyn DynAsyncCounter) -> usize {
+ counter.increment().await
+}
+
+fn main() {
+ let mut counter = MyCounter { count: 0 };
+ let _ = do_counter(&mut counter);
+}
diff --git a/src/test/ui/dyn-star/issue-102430.rs b/src/test/ui/dyn-star/issue-102430.rs
new file mode 100644
index 000000000..244ecda66
--- /dev/null
+++ b/src/test/ui/dyn-star/issue-102430.rs
@@ -0,0 +1,32 @@
+// check-pass
+
+#![feature(dyn_star)]
+#![allow(incomplete_features)]
+
+trait AddOne {
+ fn add1(&mut self) -> usize;
+}
+
+impl AddOne for usize {
+ fn add1(&mut self) -> usize {
+ *self += 1;
+ *self
+ }
+}
+
+impl AddOne for &mut usize {
+ fn add1(&mut self) -> usize {
+ (*self).add1()
+ }
+}
+
+fn add_one(mut i: dyn* AddOne + '_) -> usize {
+ i.add1()
+}
+
+fn main() {
+ let mut x = 42usize;
+ let y = &mut x as (dyn* AddOne + '_);
+
+ println!("{}", add_one(y));
+}
diff --git a/src/test/ui/dyn-star/no-unsize-coerce-dyn-trait.rs b/src/test/ui/dyn-star/no-unsize-coerce-dyn-trait.rs
new file mode 100644
index 000000000..a4eb669e3
--- /dev/null
+++ b/src/test/ui/dyn-star/no-unsize-coerce-dyn-trait.rs
@@ -0,0 +1,13 @@
+#![feature(dyn_star, trait_upcasting)]
+//~^ WARN the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes
+
+trait A: B {}
+trait B {}
+impl A for usize {}
+impl B for usize {}
+
+fn main() {
+ let x: Box<dyn* A> = Box::new(1usize as dyn* A);
+ let y: Box<dyn* B> = x;
+ //~^ ERROR mismatched types
+}
diff --git a/src/test/ui/dyn-star/no-unsize-coerce-dyn-trait.stderr b/src/test/ui/dyn-star/no-unsize-coerce-dyn-trait.stderr
new file mode 100644
index 000000000..2fc751b3b
--- /dev/null
+++ b/src/test/ui/dyn-star/no-unsize-coerce-dyn-trait.stderr
@@ -0,0 +1,23 @@
+warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes
+ --> $DIR/no-unsize-coerce-dyn-trait.rs:1:12
+ |
+LL | #![feature(dyn_star, trait_upcasting)]
+ | ^^^^^^^^
+ |
+ = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
+ = note: `#[warn(incomplete_features)]` on by default
+
+error[E0308]: mismatched types
+ --> $DIR/no-unsize-coerce-dyn-trait.rs:11:26
+ |
+LL | let y: Box<dyn* B> = x;
+ | ----------- ^ expected trait `B`, found trait `A`
+ | |
+ | expected due to this
+ |
+ = note: expected struct `Box<dyn* B>`
+ found struct `Box<dyn* A>`
+
+error: aborting due to previous error; 1 warning emitted
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/dyn-star/return.rs b/src/test/ui/dyn-star/return.rs
new file mode 100644
index 000000000..fa3d8d7d5
--- /dev/null
+++ b/src/test/ui/dyn-star/return.rs
@@ -0,0 +1,10 @@
+// check-pass
+
+#![feature(dyn_star)]
+//~^ WARN the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes
+
+fn _foo() -> dyn* Unpin {
+ 4usize
+}
+
+fn main() {}
diff --git a/src/test/ui/dyn-star/return.stderr b/src/test/ui/dyn-star/return.stderr
new file mode 100644
index 000000000..e000351a6
--- /dev/null
+++ b/src/test/ui/dyn-star/return.stderr
@@ -0,0 +1,11 @@
+warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes
+ --> $DIR/return.rs:3:12
+ |
+LL | #![feature(dyn_star)]
+ | ^^^^^^^^
+ |
+ = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
+ = note: `#[warn(incomplete_features)]` on by default
+
+warning: 1 warning emitted
+
diff --git a/src/test/ui/dyn-star/unsize-into-ref-dyn-star.rs b/src/test/ui/dyn-star/unsize-into-ref-dyn-star.rs
new file mode 100644
index 000000000..1e8cafe15
--- /dev/null
+++ b/src/test/ui/dyn-star/unsize-into-ref-dyn-star.rs
@@ -0,0 +1,9 @@
+#![feature(dyn_star)]
+#![allow(incomplete_features)]
+
+use std::fmt::Debug;
+
+fn main() {
+ let i = 42 as &dyn* Debug;
+ //~^ ERROR non-primitive cast: `i32` as `&dyn* Debug`
+}
diff --git a/src/test/ui/dyn-star/unsize-into-ref-dyn-star.stderr b/src/test/ui/dyn-star/unsize-into-ref-dyn-star.stderr
new file mode 100644
index 000000000..f6444a60a
--- /dev/null
+++ b/src/test/ui/dyn-star/unsize-into-ref-dyn-star.stderr
@@ -0,0 +1,9 @@
+error[E0605]: non-primitive cast: `i32` as `&dyn* Debug`
+ --> $DIR/unsize-into-ref-dyn-star.rs:7:13
+ |
+LL | let i = 42 as &dyn* Debug;
+ | ^^^^^^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0605`.
diff --git a/src/test/ui/dyn-star/upcast.rs b/src/test/ui/dyn-star/upcast.rs
index cee76ada7..c667ac143 100644
--- a/src/test/ui/dyn-star/upcast.rs
+++ b/src/test/ui/dyn-star/upcast.rs
@@ -1,7 +1,6 @@
-// run-pass
+// known-bug: #104800
#![feature(dyn_star, trait_upcasting)]
-#![allow(incomplete_features)]
trait Foo: Bar {
fn hello(&self);
diff --git a/src/test/ui/dyn-star/upcast.stderr b/src/test/ui/dyn-star/upcast.stderr
new file mode 100644
index 000000000..6a95f7754
--- /dev/null
+++ b/src/test/ui/dyn-star/upcast.stderr
@@ -0,0 +1,20 @@
+warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes
+ --> $DIR/upcast.rs:3:12
+ |
+LL | #![feature(dyn_star, trait_upcasting)]
+ | ^^^^^^^^
+ |
+ = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
+ = note: `#[warn(incomplete_features)]` on by default
+
+error[E0277]: `dyn* Foo` needs to be a pointer-sized type
+ --> $DIR/upcast.rs:30:23
+ |
+LL | let w: dyn* Bar = w;
+ | ^ `dyn* Foo` needs to be a pointer-sized type
+ |
+ = help: the trait `PointerSized` is not implemented for `dyn* Foo`
+
+error: aborting due to previous error; 1 warning emitted
+
+For more information about this error, try `rustc --explain E0277`.