Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
clubby789 opened this issue Oct 14, 2022 · 1 comment · Fixed by #103142
Closed

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

clubby789 opened this issue Oct 14, 2022 · 1 comment · Fixed by #103142
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@clubby789
Copy link
Contributor

clubby789 commented Oct 14, 2022

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 {

@clubby789 clubby789 added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 14, 2022
@fmease
Copy link
Member

fmease commented Oct 17, 2022

@rustbot claim

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Oct 18, 2022
Make diagnostic for unsatisfied `Termination` bounds more precise

Don't blindly emit a diagnostic claiming that “*`main` has an invalid return type*” if we encounter a type that should but doesn't implement `std::process::Termination` and isn't actually the return type of the program entry `main`.

Fixes rust-lang#103052.

`@rustbot` label A-diagnostics T-compiler T-libs
r? diagnostics
@bors bors closed this as completed in 472a874 Oct 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants