From 94a0819fe3a0d679c3042a77bfe6a2afc505daea Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:11:28 +0200 Subject: Adding upstream version 1.66.0+dfsg1. Signed-off-by: Daniel Baumann --- src/test/ui/dyn-star/auxiliary/dyn-star-foreign.rs | 10 +++++++ src/test/ui/dyn-star/box.rs | 17 +++++++++++ src/test/ui/dyn-star/const.rs | 14 +++++++++ src/test/ui/dyn-star/drop.rs | 23 +++++++++++++++ src/test/ui/dyn-star/drop.run.stdout | 1 + src/test/ui/dyn-star/error.rs | 13 +++++++++ src/test/ui/dyn-star/error.stderr | 9 ++++++ src/test/ui/dyn-star/feature-gate-dyn_star.rs | 9 ++++++ src/test/ui/dyn-star/feature-gate-dyn_star.stderr | 12 ++++++++ src/test/ui/dyn-star/make-dyn-star.rs | 18 ++++++++++++ src/test/ui/dyn-star/method.rs | 27 ++++++++++++++++++ src/test/ui/dyn-star/no-explicit-dyn-star-cast.rs | 13 +++++++++ .../ui/dyn-star/no-explicit-dyn-star-cast.stderr | 28 ++++++++++++++++++ src/test/ui/dyn-star/no-explicit-dyn-star.rs | 8 ++++++ src/test/ui/dyn-star/no-explicit-dyn-star.stderr | 9 ++++++ src/test/ui/dyn-star/no-implicit-dyn-star.rs | 8 ++++++ src/test/ui/dyn-star/no-implicit-dyn-star.stderr | 19 +++++++++++++ src/test/ui/dyn-star/syntax.rs | 11 ++++++++ src/test/ui/dyn-star/upcast.rs | 33 ++++++++++++++++++++++ 19 files changed, 282 insertions(+) create mode 100644 src/test/ui/dyn-star/auxiliary/dyn-star-foreign.rs create mode 100644 src/test/ui/dyn-star/box.rs create mode 100644 src/test/ui/dyn-star/const.rs create mode 100644 src/test/ui/dyn-star/drop.rs create mode 100644 src/test/ui/dyn-star/drop.run.stdout create mode 100644 src/test/ui/dyn-star/error.rs create mode 100644 src/test/ui/dyn-star/error.stderr create mode 100644 src/test/ui/dyn-star/feature-gate-dyn_star.rs create mode 100644 src/test/ui/dyn-star/feature-gate-dyn_star.stderr create mode 100644 src/test/ui/dyn-star/make-dyn-star.rs create mode 100644 src/test/ui/dyn-star/method.rs create mode 100644 src/test/ui/dyn-star/no-explicit-dyn-star-cast.rs create mode 100644 src/test/ui/dyn-star/no-explicit-dyn-star-cast.stderr create mode 100644 src/test/ui/dyn-star/no-explicit-dyn-star.rs create mode 100644 src/test/ui/dyn-star/no-explicit-dyn-star.stderr create mode 100644 src/test/ui/dyn-star/no-implicit-dyn-star.rs create mode 100644 src/test/ui/dyn-star/no-implicit-dyn-star.stderr create mode 100644 src/test/ui/dyn-star/syntax.rs create mode 100644 src/test/ui/dyn-star/upcast.rs (limited to 'src/test/ui/dyn-star') diff --git a/src/test/ui/dyn-star/auxiliary/dyn-star-foreign.rs b/src/test/ui/dyn-star/auxiliary/dyn-star-foreign.rs new file mode 100644 index 000000000..7673c7936 --- /dev/null +++ b/src/test/ui/dyn-star/auxiliary/dyn-star-foreign.rs @@ -0,0 +1,10 @@ +#![feature(dyn_star)] +#![allow(incomplete_features)] + +use std::fmt::Display; + +pub fn require_dyn_star_display(_: dyn* Display) {} + +fn works_locally() { + require_dyn_star_display(1usize); +} diff --git a/src/test/ui/dyn-star/box.rs b/src/test/ui/dyn-star/box.rs new file mode 100644 index 000000000..d1f1819d9 --- /dev/null +++ b/src/test/ui/dyn-star/box.rs @@ -0,0 +1,17 @@ +// run-pass +// compile-flags: -C opt-level=0 + +#![feature(dyn_star)] +#![allow(incomplete_features)] + +use std::fmt::Display; + +fn make_dyn_star() -> dyn* Display { + Box::new(42) as dyn* Display +} + +fn main() { + let x = make_dyn_star(); + + println!("{x}"); +} diff --git a/src/test/ui/dyn-star/const.rs b/src/test/ui/dyn-star/const.rs new file mode 100644 index 000000000..67e3ab7ab --- /dev/null +++ b/src/test/ui/dyn-star/const.rs @@ -0,0 +1,14 @@ +// run-pass +#![feature(dyn_star)] +#![allow(unused, incomplete_features)] + +use std::fmt::Debug; + +fn make_dyn_star() { + let i = 42usize; + let dyn_i: dyn* Debug = i; +} + +fn main() { + make_dyn_star(); +} diff --git a/src/test/ui/dyn-star/drop.rs b/src/test/ui/dyn-star/drop.rs new file mode 100644 index 000000000..1478498c0 --- /dev/null +++ b/src/test/ui/dyn-star/drop.rs @@ -0,0 +1,23 @@ +// run-pass +// check-run-results +#![feature(dyn_star)] +#![allow(incomplete_features)] + +use std::fmt::Debug; + +#[derive(Debug)] +struct Foo(usize); + +impl Drop for Foo { + fn drop(&mut self) { + println!("destructor called"); + } +} + +fn make_dyn_star(i: Foo) { + let _dyn_i: dyn* Debug = i; +} + +fn main() { + make_dyn_star(Foo(42)); +} diff --git a/src/test/ui/dyn-star/drop.run.stdout b/src/test/ui/dyn-star/drop.run.stdout new file mode 100644 index 000000000..dadb33ccf --- /dev/null +++ b/src/test/ui/dyn-star/drop.run.stdout @@ -0,0 +1 @@ +destructor called diff --git a/src/test/ui/dyn-star/error.rs b/src/test/ui/dyn-star/error.rs new file mode 100644 index 000000000..d8261387e --- /dev/null +++ b/src/test/ui/dyn-star/error.rs @@ -0,0 +1,13 @@ +#![feature(dyn_star)] +#![allow(incomplete_features)] + +use std::fmt::Debug; + +trait Foo {} + +fn make_dyn_star() { + let i = 42; + let dyn_i: dyn* Foo = i; //~ ERROR trait bound `{integer}: Foo` is not satisfied +} + +fn main() {} diff --git a/src/test/ui/dyn-star/error.stderr b/src/test/ui/dyn-star/error.stderr new file mode 100644 index 000000000..ae54b9ca7 --- /dev/null +++ b/src/test/ui/dyn-star/error.stderr @@ -0,0 +1,9 @@ +error[E0277]: the trait bound `{integer}: Foo` is not satisfied + --> $DIR/error.rs:10:27 + | +LL | let dyn_i: dyn* Foo = i; + | ^ the trait `Foo` is not implemented for `{integer}` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/dyn-star/feature-gate-dyn_star.rs b/src/test/ui/dyn-star/feature-gate-dyn_star.rs new file mode 100644 index 000000000..4756661cf --- /dev/null +++ b/src/test/ui/dyn-star/feature-gate-dyn_star.rs @@ -0,0 +1,9 @@ +// Feature gate test for dyn_star + +/// dyn* is not necessarily the final surface syntax (if we have one at all), +/// but for now we will support it to aid in writing tests independently. +pub fn dyn_star_parameter(_: &dyn* Send) { + //~^ dyn* trait objects are unstable +} + +fn main() {} diff --git a/src/test/ui/dyn-star/feature-gate-dyn_star.stderr b/src/test/ui/dyn-star/feature-gate-dyn_star.stderr new file mode 100644 index 000000000..2767e9478 --- /dev/null +++ b/src/test/ui/dyn-star/feature-gate-dyn_star.stderr @@ -0,0 +1,12 @@ +error[E0658]: dyn* trait objects are unstable + --> $DIR/feature-gate-dyn_star.rs:5:31 + | +LL | pub fn dyn_star_parameter(_: &dyn* Send) { + | ^^^^^^^^^ + | + = note: see issue #91611 for more information + = help: add `#![feature(dyn_star)]` to the crate attributes to enable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/dyn-star/make-dyn-star.rs b/src/test/ui/dyn-star/make-dyn-star.rs new file mode 100644 index 000000000..e5255a64b --- /dev/null +++ b/src/test/ui/dyn-star/make-dyn-star.rs @@ -0,0 +1,18 @@ +// run-pass +#![feature(dyn_star)] +#![allow(incomplete_features)] + +use std::fmt::Debug; + +fn make_dyn_star(i: usize) { + let _dyn_i: dyn* Debug = i; +} + +fn make_dyn_star_explicit(i: usize) { + let _dyn_i: dyn* Debug = i as dyn* Debug; +} + +fn main() { + make_dyn_star(42); + make_dyn_star_explicit(42); +} diff --git a/src/test/ui/dyn-star/method.rs b/src/test/ui/dyn-star/method.rs new file mode 100644 index 000000000..5a77640f0 --- /dev/null +++ b/src/test/ui/dyn-star/method.rs @@ -0,0 +1,27 @@ +// run-pass + +#![feature(dyn_star)] +#![allow(incomplete_features)] + +trait Foo { + fn get(&self) -> usize; +} + +impl Foo for usize { + fn get(&self) -> usize { + *self + } +} + +fn invoke_dyn_star(i: dyn* Foo) -> usize { + i.get() +} + +fn make_and_invoke_dyn_star(i: usize) -> usize { + let dyn_i: dyn* Foo = i; + invoke_dyn_star(dyn_i) +} + +fn main() { + println!("{}", make_and_invoke_dyn_star(42)); +} diff --git a/src/test/ui/dyn-star/no-explicit-dyn-star-cast.rs b/src/test/ui/dyn-star/no-explicit-dyn-star-cast.rs new file mode 100644 index 000000000..67240c8e8 --- /dev/null +++ b/src/test/ui/dyn-star/no-explicit-dyn-star-cast.rs @@ -0,0 +1,13 @@ +use std::fmt::Debug; + +fn make_dyn_star() { + let i = 42usize; + let dyn_i: dyn* Debug = i as dyn* Debug; + //~^ ERROR casting `usize` as `dyn* Debug` is invalid + //~| ERROR dyn* trait objects are unstable + //~| ERROR dyn* trait objects are unstable +} + +fn main() { + make_dyn_star(); +} diff --git a/src/test/ui/dyn-star/no-explicit-dyn-star-cast.stderr b/src/test/ui/dyn-star/no-explicit-dyn-star-cast.stderr new file mode 100644 index 000000000..687d7db04 --- /dev/null +++ b/src/test/ui/dyn-star/no-explicit-dyn-star-cast.stderr @@ -0,0 +1,28 @@ +error[E0658]: dyn* trait objects are unstable + --> $DIR/no-explicit-dyn-star-cast.rs:5:16 + | +LL | let dyn_i: dyn* Debug = i as dyn* Debug; + | ^^^^^^^^^^ + | + = note: see issue #91611 for more information + = help: add `#![feature(dyn_star)]` to the crate attributes to enable + +error[E0658]: dyn* trait objects are unstable + --> $DIR/no-explicit-dyn-star-cast.rs:5:34 + | +LL | let dyn_i: dyn* Debug = i as dyn* Debug; + | ^^^^^^^^^^ + | + = note: see issue #91611 for more information + = help: add `#![feature(dyn_star)]` to the crate attributes to enable + +error[E0606]: casting `usize` as `dyn* Debug` is invalid + --> $DIR/no-explicit-dyn-star-cast.rs:5:29 + | +LL | let dyn_i: dyn* Debug = i as dyn* Debug; + | ^^^^^^^^^^^^^^^ + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0606, E0658. +For more information about an error, try `rustc --explain E0606`. diff --git a/src/test/ui/dyn-star/no-explicit-dyn-star.rs b/src/test/ui/dyn-star/no-explicit-dyn-star.rs new file mode 100644 index 000000000..4f726b7c6 --- /dev/null +++ b/src/test/ui/dyn-star/no-explicit-dyn-star.rs @@ -0,0 +1,8 @@ +// aux-build:dyn-star-foreign.rs + +extern crate dyn_star_foreign; + +fn main() { + dyn_star_foreign::require_dyn_star_display(1usize as _); + //~^ ERROR casting `usize` as `dyn* std::fmt::Display` is invalid +} diff --git a/src/test/ui/dyn-star/no-explicit-dyn-star.stderr b/src/test/ui/dyn-star/no-explicit-dyn-star.stderr new file mode 100644 index 000000000..49706fae1 --- /dev/null +++ b/src/test/ui/dyn-star/no-explicit-dyn-star.stderr @@ -0,0 +1,9 @@ +error[E0606]: casting `usize` as `dyn* std::fmt::Display` is invalid + --> $DIR/no-explicit-dyn-star.rs:6:48 + | +LL | dyn_star_foreign::require_dyn_star_display(1usize as _); + | ^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0606`. diff --git a/src/test/ui/dyn-star/no-implicit-dyn-star.rs b/src/test/ui/dyn-star/no-implicit-dyn-star.rs new file mode 100644 index 000000000..d9470e284 --- /dev/null +++ b/src/test/ui/dyn-star/no-implicit-dyn-star.rs @@ -0,0 +1,8 @@ +// aux-build:dyn-star-foreign.rs + +extern crate dyn_star_foreign; + +fn main() { + dyn_star_foreign::require_dyn_star_display(1usize); + //~^ ERROR mismatched types +} diff --git a/src/test/ui/dyn-star/no-implicit-dyn-star.stderr b/src/test/ui/dyn-star/no-implicit-dyn-star.stderr new file mode 100644 index 000000000..e7c591862 --- /dev/null +++ b/src/test/ui/dyn-star/no-implicit-dyn-star.stderr @@ -0,0 +1,19 @@ +error[E0308]: mismatched types + --> $DIR/no-implicit-dyn-star.rs:6:48 + | +LL | dyn_star_foreign::require_dyn_star_display(1usize); + | ------------------------------------------ ^^^^^^ expected trait object `dyn std::fmt::Display`, found `usize` + | | + | arguments to this function are incorrect + | + = note: expected trait object `(dyn* std::fmt::Display + 'static)` + found type `usize` +note: function defined here + --> $DIR/auxiliary/dyn-star-foreign.rs:6:8 + | +LL | pub fn require_dyn_star_display(_: dyn* Display) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/dyn-star/syntax.rs b/src/test/ui/dyn-star/syntax.rs new file mode 100644 index 000000000..618c72562 --- /dev/null +++ b/src/test/ui/dyn-star/syntax.rs @@ -0,0 +1,11 @@ +// Make sure we can parse the `dyn* Trait` syntax +// +// check-pass + +#![feature(dyn_star)] +#![allow(incomplete_features)] + +pub fn dyn_star_parameter(_: dyn* Send) { +} + +fn main() {} diff --git a/src/test/ui/dyn-star/upcast.rs b/src/test/ui/dyn-star/upcast.rs new file mode 100644 index 000000000..cee76ada7 --- /dev/null +++ b/src/test/ui/dyn-star/upcast.rs @@ -0,0 +1,33 @@ +// run-pass + +#![feature(dyn_star, trait_upcasting)] +#![allow(incomplete_features)] + +trait Foo: Bar { + fn hello(&self); +} + +trait Bar { + fn world(&self); +} + +struct W(usize); + +impl Foo for W { + fn hello(&self) { + println!("hello!"); + } +} + +impl Bar for W { + fn world(&self) { + println!("world!"); + } +} + +fn main() { + let w: dyn* Foo = W(0); + w.hello(); + let w: dyn* Bar = w; + w.world(); +} -- cgit v1.2.3