summaryrefslogtreecommitdiffstats
path: root/tests/ui/rfc-1937-termination-trait
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
commit64d98f8ee037282c35007b64c2649055c56af1db (patch)
tree5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/ui/rfc-1937-termination-trait
parentAdding debian version 1.67.1+dfsg1-1. (diff)
downloadrustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz
rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/rfc-1937-termination-trait')
-rw-r--r--tests/ui/rfc-1937-termination-trait/issue-103052-1.rs11
-rw-r--r--tests/ui/rfc-1937-termination-trait/issue-103052-1.stderr17
-rw-r--r--tests/ui/rfc-1937-termination-trait/issue-103052-2.rs18
-rw-r--r--tests/ui/rfc-1937-termination-trait/issue-103052-2.stderr15
-rw-r--r--tests/ui/rfc-1937-termination-trait/termination-trait-for-box-dyn-error.rs11
-rw-r--r--tests/ui/rfc-1937-termination-trait/termination-trait-for-never.rs7
-rw-r--r--tests/ui/rfc-1937-termination-trait/termination-trait-for-result-box-error_err.rs10
-rw-r--r--tests/ui/rfc-1937-termination-trait/termination-trait-for-str.rs8
-rw-r--r--tests/ui/rfc-1937-termination-trait/termination-trait-impl-trait.rs3
-rw-r--r--tests/ui/rfc-1937-termination-trait/termination-trait-impl-trait.stderr11
-rw-r--r--tests/ui/rfc-1937-termination-trait/termination-trait-in-test-should-panic.rs15
-rw-r--r--tests/ui/rfc-1937-termination-trait/termination-trait-in-test-should-panic.stderr12
-rw-r--r--tests/ui/rfc-1937-termination-trait/termination-trait-in-test.rs28
-rw-r--r--tests/ui/rfc-1937-termination-trait/termination-trait-main-i32.rs6
-rw-r--r--tests/ui/rfc-1937-termination-trait/termination-trait-main-i32.stderr11
-rw-r--r--tests/ui/rfc-1937-termination-trait/termination-trait-main-wrong-type.rs3
-rw-r--r--tests/ui/rfc-1937-termination-trait/termination-trait-main-wrong-type.stderr11
-rw-r--r--tests/ui/rfc-1937-termination-trait/termination-trait-not-satisfied.rs5
-rw-r--r--tests/ui/rfc-1937-termination-trait/termination-trait-not-satisfied.stderr11
-rw-r--r--tests/ui/rfc-1937-termination-trait/termination-trait-test-wrong-type.rs8
-rw-r--r--tests/ui/rfc-1937-termination-trait/termination-trait-test-wrong-type.stderr16
21 files changed, 237 insertions, 0 deletions
diff --git a/tests/ui/rfc-1937-termination-trait/issue-103052-1.rs b/tests/ui/rfc-1937-termination-trait/issue-103052-1.rs
new file mode 100644
index 000000000..a75c91cc9
--- /dev/null
+++ b/tests/ui/rfc-1937-termination-trait/issue-103052-1.rs
@@ -0,0 +1,11 @@
+// Check that we don't blindly emit a diagnostic claiming that "`main` has an invalid return type"
+// if we encounter a type that doesn't implement `std::process::Termination` and is not actually
+// the return type of the program entry `main`.
+
+fn receive(_: impl std::process::Termination) {}
+
+struct Something;
+
+fn main() {
+ receive(Something); //~ ERROR the trait bound `Something: Termination` is not satisfied
+}
diff --git a/tests/ui/rfc-1937-termination-trait/issue-103052-1.stderr b/tests/ui/rfc-1937-termination-trait/issue-103052-1.stderr
new file mode 100644
index 000000000..409dede1a
--- /dev/null
+++ b/tests/ui/rfc-1937-termination-trait/issue-103052-1.stderr
@@ -0,0 +1,17 @@
+error[E0277]: the trait bound `Something: Termination` is not satisfied
+ --> $DIR/issue-103052-1.rs:10:13
+ |
+LL | receive(Something);
+ | ------- ^^^^^^^^^ the trait `Termination` is not implemented for `Something`
+ | |
+ | required by a bound introduced by this call
+ |
+note: required by a bound in `receive`
+ --> $DIR/issue-103052-1.rs:5:20
+ |
+LL | fn receive(_: impl std::process::Termination) {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `receive`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/rfc-1937-termination-trait/issue-103052-2.rs b/tests/ui/rfc-1937-termination-trait/issue-103052-2.rs
new file mode 100644
index 000000000..fa9182b6d
--- /dev/null
+++ b/tests/ui/rfc-1937-termination-trait/issue-103052-2.rs
@@ -0,0 +1,18 @@
+#![feature(return_position_impl_trait_in_trait)]
+#![allow(incomplete_features)]
+
+mod child {
+ trait Main {
+ fn main() -> impl std::process::Termination;
+ }
+
+ struct Something;
+
+ impl Main for () {
+ fn main() -> Something { //~ ERROR the trait bound `Something: Termination` is not satisfied
+ Something
+ }
+ }
+}
+
+fn main() {}
diff --git a/tests/ui/rfc-1937-termination-trait/issue-103052-2.stderr b/tests/ui/rfc-1937-termination-trait/issue-103052-2.stderr
new file mode 100644
index 000000000..a700c72ea
--- /dev/null
+++ b/tests/ui/rfc-1937-termination-trait/issue-103052-2.stderr
@@ -0,0 +1,15 @@
+error[E0277]: the trait bound `Something: Termination` is not satisfied
+ --> $DIR/issue-103052-2.rs:12:22
+ |
+LL | fn main() -> Something {
+ | ^^^^^^^^^ the trait `Termination` is not implemented for `Something`
+ |
+note: required by a bound in `Main::main::{opaque#0}`
+ --> $DIR/issue-103052-2.rs:6:27
+ |
+LL | fn main() -> impl std::process::Termination;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Main::main::{opaque#0}`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/rfc-1937-termination-trait/termination-trait-for-box-dyn-error.rs b/tests/ui/rfc-1937-termination-trait/termination-trait-for-box-dyn-error.rs
new file mode 100644
index 000000000..10dc6115d
--- /dev/null
+++ b/tests/ui/rfc-1937-termination-trait/termination-trait-for-box-dyn-error.rs
@@ -0,0 +1,11 @@
+// run-fail
+// error-pattern:returned Box<dyn Error> from main()
+// failure-status: 1
+// ignore-emscripten no processes
+
+use std::error::Error;
+use std::io;
+
+fn main() -> Result<(), Box<dyn Error>> {
+ Err(Box::new(io::Error::new(io::ErrorKind::Other, "returned Box<dyn Error> from main()")))
+}
diff --git a/tests/ui/rfc-1937-termination-trait/termination-trait-for-never.rs b/tests/ui/rfc-1937-termination-trait/termination-trait-for-never.rs
new file mode 100644
index 000000000..faf2526c8
--- /dev/null
+++ b/tests/ui/rfc-1937-termination-trait/termination-trait-for-never.rs
@@ -0,0 +1,7 @@
+// run-fail
+// error-pattern:oh, dear
+// ignore-emscripten no processes
+
+fn main() -> ! {
+ panic!("oh, dear");
+}
diff --git a/tests/ui/rfc-1937-termination-trait/termination-trait-for-result-box-error_err.rs b/tests/ui/rfc-1937-termination-trait/termination-trait-for-result-box-error_err.rs
new file mode 100644
index 000000000..6a625fb05
--- /dev/null
+++ b/tests/ui/rfc-1937-termination-trait/termination-trait-for-result-box-error_err.rs
@@ -0,0 +1,10 @@
+// run-fail
+// error-pattern:returned Box<Error> from main()
+// failure-status: 1
+// ignore-emscripten no processes
+
+use std::io::{Error, ErrorKind};
+
+fn main() -> Result<(), Box<Error>> {
+ Err(Box::new(Error::new(ErrorKind::Other, "returned Box<Error> from main()")))
+}
diff --git a/tests/ui/rfc-1937-termination-trait/termination-trait-for-str.rs b/tests/ui/rfc-1937-termination-trait/termination-trait-for-str.rs
new file mode 100644
index 000000000..94f16c6fd
--- /dev/null
+++ b/tests/ui/rfc-1937-termination-trait/termination-trait-for-str.rs
@@ -0,0 +1,8 @@
+// run-fail
+// error-pattern: An error message for you
+// failure-status: 1
+// ignore-emscripten no processes
+
+fn main() -> Result<(), &'static str> {
+ Err("An error message for you")
+}
diff --git a/tests/ui/rfc-1937-termination-trait/termination-trait-impl-trait.rs b/tests/ui/rfc-1937-termination-trait/termination-trait-impl-trait.rs
new file mode 100644
index 000000000..3b60cbc57
--- /dev/null
+++ b/tests/ui/rfc-1937-termination-trait/termination-trait-impl-trait.rs
@@ -0,0 +1,3 @@
+// Tests that an `impl Trait` that is not `impl Termination` will not work.
+fn main() -> impl Copy { }
+//~^ ERROR `main` has invalid return type `impl Copy`
diff --git a/tests/ui/rfc-1937-termination-trait/termination-trait-impl-trait.stderr b/tests/ui/rfc-1937-termination-trait/termination-trait-impl-trait.stderr
new file mode 100644
index 000000000..5ee6d127e
--- /dev/null
+++ b/tests/ui/rfc-1937-termination-trait/termination-trait-impl-trait.stderr
@@ -0,0 +1,11 @@
+error[E0277]: `main` has invalid return type `impl Copy`
+ --> $DIR/termination-trait-impl-trait.rs:2:14
+ |
+LL | fn main() -> impl Copy { }
+ | ^^^^^^^^^ `main` can only return types that implement `Termination`
+ |
+ = help: consider using `()`, or a `Result`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/rfc-1937-termination-trait/termination-trait-in-test-should-panic.rs b/tests/ui/rfc-1937-termination-trait/termination-trait-in-test-should-panic.rs
new file mode 100644
index 000000000..96808a3ed
--- /dev/null
+++ b/tests/ui/rfc-1937-termination-trait/termination-trait-in-test-should-panic.rs
@@ -0,0 +1,15 @@
+// compile-flags: --test
+
+#![feature(test)]
+
+extern crate test;
+use std::num::ParseIntError;
+use test::Bencher;
+
+#[test]
+#[should_panic]
+fn not_a_num() -> Result<(), ParseIntError> {
+ //~^ ERROR functions using `#[should_panic]` must return `()`
+ let _: u32 = "abc".parse()?;
+ Ok(())
+}
diff --git a/tests/ui/rfc-1937-termination-trait/termination-trait-in-test-should-panic.stderr b/tests/ui/rfc-1937-termination-trait/termination-trait-in-test-should-panic.stderr
new file mode 100644
index 000000000..7f6749fc9
--- /dev/null
+++ b/tests/ui/rfc-1937-termination-trait/termination-trait-in-test-should-panic.stderr
@@ -0,0 +1,12 @@
+error: functions using `#[should_panic]` must return `()`
+ --> $DIR/termination-trait-in-test-should-panic.rs:11:1
+ |
+LL | / fn not_a_num() -> Result<(), ParseIntError> {
+LL | |
+LL | | let _: u32 = "abc".parse()?;
+LL | | Ok(())
+LL | | }
+ | |_^
+
+error: aborting due to previous error
+
diff --git a/tests/ui/rfc-1937-termination-trait/termination-trait-in-test.rs b/tests/ui/rfc-1937-termination-trait/termination-trait-in-test.rs
new file mode 100644
index 000000000..43888cece
--- /dev/null
+++ b/tests/ui/rfc-1937-termination-trait/termination-trait-in-test.rs
@@ -0,0 +1,28 @@
+// compile-flags: --test
+// run-pass
+// needs-unwind
+
+
+#![feature(test)]
+
+extern crate test;
+use std::num::ParseIntError;
+use test::Bencher;
+
+#[test]
+fn is_a_num() -> Result<(), ParseIntError> {
+ let _: u32 = "22".parse()?;
+ Ok(())
+}
+
+#[bench]
+fn test_a_positive_bench(_: &mut Bencher) -> Result<(), ParseIntError> {
+ Ok(())
+}
+
+#[bench]
+#[should_panic]
+fn test_a_neg_bench(_: &mut Bencher) -> Result<(), ParseIntError> {
+ let _: u32 = "abc".parse()?;
+ Ok(())
+}
diff --git a/tests/ui/rfc-1937-termination-trait/termination-trait-main-i32.rs b/tests/ui/rfc-1937-termination-trait/termination-trait-main-i32.rs
new file mode 100644
index 000000000..10f7d2215
--- /dev/null
+++ b/tests/ui/rfc-1937-termination-trait/termination-trait-main-i32.rs
@@ -0,0 +1,6 @@
+fn main() -> i32 {
+//~^ ERROR `main` has invalid return type `i32`
+//~| NOTE `main` can only return types that implement `Termination`
+//~| HELP consider using `()`, or a `Result`
+ 0
+}
diff --git a/tests/ui/rfc-1937-termination-trait/termination-trait-main-i32.stderr b/tests/ui/rfc-1937-termination-trait/termination-trait-main-i32.stderr
new file mode 100644
index 000000000..53779d365
--- /dev/null
+++ b/tests/ui/rfc-1937-termination-trait/termination-trait-main-i32.stderr
@@ -0,0 +1,11 @@
+error[E0277]: `main` has invalid return type `i32`
+ --> $DIR/termination-trait-main-i32.rs:1:14
+ |
+LL | fn main() -> i32 {
+ | ^^^ `main` can only return types that implement `Termination`
+ |
+ = help: consider using `()`, or a `Result`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/rfc-1937-termination-trait/termination-trait-main-wrong-type.rs b/tests/ui/rfc-1937-termination-trait/termination-trait-main-wrong-type.rs
new file mode 100644
index 000000000..687d5f144
--- /dev/null
+++ b/tests/ui/rfc-1937-termination-trait/termination-trait-main-wrong-type.rs
@@ -0,0 +1,3 @@
+fn main() -> char { //~ ERROR
+ ' '
+}
diff --git a/tests/ui/rfc-1937-termination-trait/termination-trait-main-wrong-type.stderr b/tests/ui/rfc-1937-termination-trait/termination-trait-main-wrong-type.stderr
new file mode 100644
index 000000000..bc8fd92ce
--- /dev/null
+++ b/tests/ui/rfc-1937-termination-trait/termination-trait-main-wrong-type.stderr
@@ -0,0 +1,11 @@
+error[E0277]: `main` has invalid return type `char`
+ --> $DIR/termination-trait-main-wrong-type.rs:1:14
+ |
+LL | fn main() -> char {
+ | ^^^^ `main` can only return types that implement `Termination`
+ |
+ = help: consider using `()`, or a `Result`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/rfc-1937-termination-trait/termination-trait-not-satisfied.rs b/tests/ui/rfc-1937-termination-trait/termination-trait-not-satisfied.rs
new file mode 100644
index 000000000..4c6168abb
--- /dev/null
+++ b/tests/ui/rfc-1937-termination-trait/termination-trait-not-satisfied.rs
@@ -0,0 +1,5 @@
+struct ReturnType {}
+
+fn main() -> ReturnType { //~ ERROR `main` has invalid return type `ReturnType`
+ ReturnType {}
+}
diff --git a/tests/ui/rfc-1937-termination-trait/termination-trait-not-satisfied.stderr b/tests/ui/rfc-1937-termination-trait/termination-trait-not-satisfied.stderr
new file mode 100644
index 000000000..cb329548d
--- /dev/null
+++ b/tests/ui/rfc-1937-termination-trait/termination-trait-not-satisfied.stderr
@@ -0,0 +1,11 @@
+error[E0277]: `main` has invalid return type `ReturnType`
+ --> $DIR/termination-trait-not-satisfied.rs:3:14
+ |
+LL | fn main() -> ReturnType {
+ | ^^^^^^^^^^ `main` can only return types that implement `Termination`
+ |
+ = help: consider using `()`, or a `Result`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/rfc-1937-termination-trait/termination-trait-test-wrong-type.rs b/tests/ui/rfc-1937-termination-trait/termination-trait-test-wrong-type.rs
new file mode 100644
index 000000000..193a523ae
--- /dev/null
+++ b/tests/ui/rfc-1937-termination-trait/termination-trait-test-wrong-type.rs
@@ -0,0 +1,8 @@
+// compile-flags: --test
+
+use std::num::ParseFloatError;
+
+#[test]
+fn can_parse_zero_as_f32() -> Result<f32, ParseFloatError> { //~ ERROR
+ "0".parse()
+}
diff --git a/tests/ui/rfc-1937-termination-trait/termination-trait-test-wrong-type.stderr b/tests/ui/rfc-1937-termination-trait/termination-trait-test-wrong-type.stderr
new file mode 100644
index 000000000..a19750cc7
--- /dev/null
+++ b/tests/ui/rfc-1937-termination-trait/termination-trait-test-wrong-type.stderr
@@ -0,0 +1,16 @@
+error[E0277]: the trait bound `f32: Termination` is not satisfied
+ --> $DIR/termination-trait-test-wrong-type.rs:6:31
+ |
+LL | #[test]
+ | ------- in this procedural macro expansion
+LL | fn can_parse_zero_as_f32() -> Result<f32, ParseFloatError> {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Termination` is not implemented for `f32`
+ |
+ = note: required for `Result<f32, ParseFloatError>` to implement `Termination`
+note: required by a bound in `assert_test_result`
+ --> $SRC_DIR/test/src/lib.rs:LL:COL
+ = note: this error originates in the attribute macro `test` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.