From 3ff10242fee5356cb4be91db6df2eee6b9a34089 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 18 Jan 2024 21:14:16 +0100 Subject: [PATCH] Test async fn --- .../120240-async-fn-never-arg.rs | 16 ++++++++++++++++ .../120240-async-fn-never-arg.stderr | 12 ++++++++++++ .../ui/rfcs/rfc-0000-never_patterns/diverges.rs | 6 ++++++ 3 files changed, 34 insertions(+) create mode 100644 tests/ui/rfcs/rfc-0000-never_patterns/120240-async-fn-never-arg.rs create mode 100644 tests/ui/rfcs/rfc-0000-never_patterns/120240-async-fn-never-arg.stderr diff --git a/tests/ui/rfcs/rfc-0000-never_patterns/120240-async-fn-never-arg.rs b/tests/ui/rfcs/rfc-0000-never_patterns/120240-async-fn-never-arg.rs new file mode 100644 index 0000000000000..9150c831c8960 --- /dev/null +++ b/tests/ui/rfcs/rfc-0000-never_patterns/120240-async-fn-never-arg.rs @@ -0,0 +1,16 @@ +// edition: 2018 +// known-bug: #120240 +#![feature(never_patterns)] +#![allow(incomplete_features)] + +fn main() {} + +enum Void {} + +// Divergence is not detected. +async fn async_never(!: Void) -> ! {} // gives an error + +// Divergence is detected +async fn async_let(x: Void) -> ! { + let ! = x; +} diff --git a/tests/ui/rfcs/rfc-0000-never_patterns/120240-async-fn-never-arg.stderr b/tests/ui/rfcs/rfc-0000-never_patterns/120240-async-fn-never-arg.stderr new file mode 100644 index 0000000000000..fa71feee5f5aa --- /dev/null +++ b/tests/ui/rfcs/rfc-0000-never_patterns/120240-async-fn-never-arg.stderr @@ -0,0 +1,12 @@ +error[E0308]: mismatched types + --> $DIR/120240-async-fn-never-arg.rs:11:36 + | +LL | async fn async_never(!: Void) -> ! {} // gives an error + | ^^ expected `!`, found `()` + | + = note: expected type `!` + found unit type `()` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/rfcs/rfc-0000-never_patterns/diverges.rs b/tests/ui/rfcs/rfc-0000-never_patterns/diverges.rs index 57151e246ff56..3783100b50282 100644 --- a/tests/ui/rfcs/rfc-0000-never_patterns/diverges.rs +++ b/tests/ui/rfcs/rfc-0000-never_patterns/diverges.rs @@ -1,4 +1,5 @@ // check-pass +// edition: 2018 #![feature(never_patterns)] #![allow(incomplete_features)] #![deny(unreachable_patterns)] @@ -30,3 +31,8 @@ fn never_match() -> ! { // Ensures this typechecks because of divergence and not the type of the match expression. println!(); } + +// Note: divergence is not detected for async fns when the `!` is in the argument (#120240). +async fn async_let(x: Void) -> ! { + let ! = x; +}