Skip to content

#[rustc_on_unimplemented] warning for Termination can be misleading #103052

Closed
@clubby789

Description

@clubby789

Given the following code: link

use std::process::Termination;
fn foo<T: Termination>(_: T) {}
fn bar() {foo(1_i32);}

The current output is:

error[[E0277]](https://doc.rust-lang.org/stable/error-index.html#E0277): `main` has invalid return type `i32`
 --> src/lib.rs:3:15
  |
3 | fn bar() {foo(1_i32);}
  |           --- ^^^^^ `main` can only return types that implement `Termination`
  |           |
  |           required by a bound introduced by this call
  |
  = help: the trait `Termination` is not implemented for `i32`
note: required by a bound in `foo`
 --> src/lib.rs:2:11
  |
2 | fn foo<T: Termination>(_: T) {}
  |           ^^^^^^^^^^^ required by this bound in `foo`

Ideally the output should look like:

error[[E0277]](https://doc.rust-lang.org/stable/error-index.html#E0277): the trait bound `i32: std::process::Termination` is not satisfied
 --> src/lib.rs:3:15
  |
3 | fn bar() {foo(1_i32);}
  |           --- ^^^^^ the trait `std::process::Termination` is not implemented for `i32`
  |           |
  |           required by a bound introduced by this call

#[cfg_attr(not(test), lang = "termination")]
#[stable(feature = "termination_trait_lib", since = "1.61.0")]
#[rustc_on_unimplemented(
message = "`main` has invalid return type `{Self}`",
label = "`main` can only return types that implement `{Termination}`"
)]
pub trait Termination {

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions