Closed
Description
I tried this code:
#![feature(termination_trait_lib)]
trait Same {
type Output;
}
impl<T> Same for T {
type Output = T;
}
type Unit = <() as Same>::Output;
fn test() {
fn foo() -> Result<Unit, std::io::Error> { todo!() }
fn assert_impl_termination<T: std::process::Termination>(_: fn() -> T) {}
// Compiles
assert_impl_termination(foo);
}
// Doesn't compile
fn main() -> Result<Unit, std::io::Error> {
todo!()
}
I expected to see both test
and main
compile, instead only test
compiles, while trying to compile main
gives this error:
error[E0277]: `main` has invalid return type `Result<<() as Same>::Output, std::io::Error>`
--> src/main.rs:20:14
|
20 | fn main() -> Result<Unit, std::io::Error> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `main` can only return types that implement `Termination`
|
= help: consider using `()`, or a `Result`
help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement
|
20 | fn main() -> Result<Unit, std::io::Error> where Result<<() as Same>::Output, std::io::Error>: Termination {
| +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
For more information about this error, try `rustc --explain E0277`.
Note that the feature
attribute is only needed for the bound in assert_impl_termination
. The issue with main
happens both in stable and nightly, with or without the feature.
Meta
rustc --version --verbose
:
rustc 1.54.0 (a178d0322 2021-07-26)
binary: rustc
commit-hash: a178d0322ce20e33eac124758e837cbd80a6f633
commit-date: 2021-07-26
host: x86_64-pc-windows-msvc
release: 1.54.0
LLVM version: 12.0.1
rustc 1.56.0-nightly (29ef6cf16 2021-08-31)
binary: rustc
commit-hash: 29ef6cf1637aa8317f8911f93f14e18d404c1b0e
commit-date: 2021-08-31
host: x86_64-pc-windows-msvc
release: 1.56.0-nightly
LLVM version: 13.0.0