summaryrefslogtreecommitdiffstats
path: root/tests/ui/rfcs/rfc-1937-termination-trait
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/rfcs/rfc-1937-termination-trait')
-rw-r--r--tests/ui/rfcs/rfc-1937-termination-trait/issue-103052-1.rs11
-rw-r--r--tests/ui/rfcs/rfc-1937-termination-trait/issue-103052-1.stderr17
-rw-r--r--tests/ui/rfcs/rfc-1937-termination-trait/issue-103052-2.current.stderr15
-rw-r--r--tests/ui/rfcs/rfc-1937-termination-trait/issue-103052-2.next.stderr15
-rw-r--r--tests/ui/rfcs/rfc-1937-termination-trait/issue-103052-2.rs18
-rw-r--r--tests/ui/rfcs/rfc-1937-termination-trait/issue-103052-2.stderr15
-rw-r--r--tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-for-box-dyn-error-err.rs11
-rw-r--r--tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-for-box-dyn-error-ok.rs (renamed from tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-for-box-dyn-error.rs)0
-rw-r--r--tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-for-never.rs7
-rw-r--r--tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-for-result-box-error_err.rs10
-rw-r--r--tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-for-str-err.rs8
-rw-r--r--tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-for-str-ok.rs (renamed from tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-for-str.rs)0
-rw-r--r--tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-impl-trait.rs3
-rw-r--r--tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-impl-trait.stderr11
-rw-r--r--tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-in-test-should-panic.rs15
-rw-r--r--tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-in-test-should-panic.stderr12
-rw-r--r--tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-in-test.rs28
-rw-r--r--tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-main-i32.rs6
-rw-r--r--tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-main-i32.stderr11
-rw-r--r--tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-main-wrong-type.rs3
-rw-r--r--tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-main-wrong-type.stderr11
-rw-r--r--tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-not-satisfied.rs5
-rw-r--r--tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-not-satisfied.stderr11
-rw-r--r--tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-test-wrong-type.rs8
-rw-r--r--tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-test-wrong-type.stderr16
25 files changed, 267 insertions, 0 deletions
diff --git a/tests/ui/rfcs/rfc-1937-termination-trait/issue-103052-1.rs b/tests/ui/rfcs/rfc-1937-termination-trait/issue-103052-1.rs
new file mode 100644
index 000000000..a75c91cc9
--- /dev/null
+++ b/tests/ui/rfcs/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/rfcs/rfc-1937-termination-trait/issue-103052-1.stderr b/tests/ui/rfcs/rfc-1937-termination-trait/issue-103052-1.stderr
new file mode 100644
index 000000000..6c3d576cf
--- /dev/null
+++ b/tests/ui/rfcs/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 1 previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/rfcs/rfc-1937-termination-trait/issue-103052-2.current.stderr b/tests/ui/rfcs/rfc-1937-termination-trait/issue-103052-2.current.stderr
new file mode 100644
index 000000000..f2727336b
--- /dev/null
+++ b/tests/ui/rfcs/rfc-1937-termination-trait/issue-103052-2.current.stderr
@@ -0,0 +1,15 @@
+error[E0277]: the trait bound `Something: Termination` is not satisfied
+ --> $DIR/issue-103052-2.rs:15: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:9:27
+ |
+LL | fn main() -> impl std::process::Termination;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Main::main::{opaque#0}`
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/rfcs/rfc-1937-termination-trait/issue-103052-2.next.stderr b/tests/ui/rfcs/rfc-1937-termination-trait/issue-103052-2.next.stderr
new file mode 100644
index 000000000..4bb420664
--- /dev/null
+++ b/tests/ui/rfcs/rfc-1937-termination-trait/issue-103052-2.next.stderr
@@ -0,0 +1,15 @@
+error[E0277]: the trait bound `Something: Termination` is not satisfied
+ --> $DIR/issue-103052-2.rs:15:22
+ |
+LL | fn main() -> Something {
+ | ^^^^^^^^^ the trait `Termination` is not implemented for `Something`
+ |
+note: required by a bound in `Main::{opaque#0}`
+ --> $DIR/issue-103052-2.rs:9:27
+ |
+LL | fn main() -> impl std::process::Termination;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Main::{opaque#0}`
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/rfcs/rfc-1937-termination-trait/issue-103052-2.rs b/tests/ui/rfcs/rfc-1937-termination-trait/issue-103052-2.rs
new file mode 100644
index 000000000..1933a68c2
--- /dev/null
+++ b/tests/ui/rfcs/rfc-1937-termination-trait/issue-103052-2.rs
@@ -0,0 +1,18 @@
+#![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/rfcs/rfc-1937-termination-trait/issue-103052-2.stderr b/tests/ui/rfcs/rfc-1937-termination-trait/issue-103052-2.stderr
new file mode 100644
index 000000000..3fbbfd0fd
--- /dev/null
+++ b/tests/ui/rfcs/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:11:22
+ |
+LL | fn main() -> Something {
+ | ^^^^^^^^^ the trait `Termination` is not implemented for `Something`
+ |
+note: required by a bound in `Main::{opaque#0}`
+ --> $DIR/issue-103052-2.rs:5:27
+ |
+LL | fn main() -> impl std::process::Termination;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Main::{opaque#0}`
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-for-box-dyn-error-err.rs b/tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-for-box-dyn-error-err.rs
new file mode 100644
index 000000000..10dc6115d
--- /dev/null
+++ b/tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-for-box-dyn-error-err.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/rfcs/rfc-1937-termination-trait/termination-trait-for-box-dyn-error.rs b/tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-for-box-dyn-error-ok.rs
index e98582cbc..e98582cbc 100644
--- a/tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-for-box-dyn-error.rs
+++ b/tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-for-box-dyn-error-ok.rs
diff --git a/tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-for-never.rs b/tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-for-never.rs
new file mode 100644
index 000000000..faf2526c8
--- /dev/null
+++ b/tests/ui/rfcs/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/rfcs/rfc-1937-termination-trait/termination-trait-for-result-box-error_err.rs b/tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-for-result-box-error_err.rs
new file mode 100644
index 000000000..6a625fb05
--- /dev/null
+++ b/tests/ui/rfcs/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/rfcs/rfc-1937-termination-trait/termination-trait-for-str-err.rs b/tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-for-str-err.rs
new file mode 100644
index 000000000..94f16c6fd
--- /dev/null
+++ b/tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-for-str-err.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/rfcs/rfc-1937-termination-trait/termination-trait-for-str.rs b/tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-for-str-ok.rs
index f0591c38c..f0591c38c 100644
--- a/tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-for-str.rs
+++ b/tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-for-str-ok.rs
diff --git a/tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-impl-trait.rs b/tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-impl-trait.rs
new file mode 100644
index 000000000..3b60cbc57
--- /dev/null
+++ b/tests/ui/rfcs/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/rfcs/rfc-1937-termination-trait/termination-trait-impl-trait.stderr b/tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-impl-trait.stderr
new file mode 100644
index 000000000..f562b97c3
--- /dev/null
+++ b/tests/ui/rfcs/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 1 previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-in-test-should-panic.rs b/tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-in-test-should-panic.rs
new file mode 100644
index 000000000..96808a3ed
--- /dev/null
+++ b/tests/ui/rfcs/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/rfcs/rfc-1937-termination-trait/termination-trait-in-test-should-panic.stderr b/tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-in-test-should-panic.stderr
new file mode 100644
index 000000000..534599b74
--- /dev/null
+++ b/tests/ui/rfcs/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 1 previous error
+
diff --git a/tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-in-test.rs b/tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-in-test.rs
new file mode 100644
index 000000000..43888cece
--- /dev/null
+++ b/tests/ui/rfcs/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/rfcs/rfc-1937-termination-trait/termination-trait-main-i32.rs b/tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-main-i32.rs
new file mode 100644
index 000000000..10f7d2215
--- /dev/null
+++ b/tests/ui/rfcs/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/rfcs/rfc-1937-termination-trait/termination-trait-main-i32.stderr b/tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-main-i32.stderr
new file mode 100644
index 000000000..fdbb0e655
--- /dev/null
+++ b/tests/ui/rfcs/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 1 previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-main-wrong-type.rs b/tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-main-wrong-type.rs
new file mode 100644
index 000000000..687d5f144
--- /dev/null
+++ b/tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-main-wrong-type.rs
@@ -0,0 +1,3 @@
+fn main() -> char { //~ ERROR
+ ' '
+}
diff --git a/tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-main-wrong-type.stderr b/tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-main-wrong-type.stderr
new file mode 100644
index 000000000..7ed17dff1
--- /dev/null
+++ b/tests/ui/rfcs/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 1 previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-not-satisfied.rs b/tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-not-satisfied.rs
new file mode 100644
index 000000000..4c6168abb
--- /dev/null
+++ b/tests/ui/rfcs/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/rfcs/rfc-1937-termination-trait/termination-trait-not-satisfied.stderr b/tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-not-satisfied.stderr
new file mode 100644
index 000000000..1b842c206
--- /dev/null
+++ b/tests/ui/rfcs/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 1 previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-test-wrong-type.rs b/tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-test-wrong-type.rs
new file mode 100644
index 000000000..193a523ae
--- /dev/null
+++ b/tests/ui/rfcs/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/rfcs/rfc-1937-termination-trait/termination-trait-test-wrong-type.stderr b/tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-test-wrong-type.stderr
new file mode 100644
index 000000000..0a703367d
--- /dev/null
+++ b/tests/ui/rfcs/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 1 previous error
+
+For more information about this error, try `rustc --explain E0277`.