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

Make diagnostic for unsatisfied Termination bounds more precise #103142

Merged
merged 1 commit into from
Oct 18, 2022

Conversation

fmease
Copy link
Member

@fmease fmease commented Oct 17, 2022

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 #103052.

@rustbot label A-diagnostics T-compiler T-libs
r? diagnostics

@rustbot rustbot added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Oct 17, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 17, 2022
@rustbot
Copy link
Collaborator

rustbot commented Oct 17, 2022

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@rustbot rustbot added the A-diagnostics Area: Messages for errors, warnings, and lints label Oct 17, 2022
@@ -164,6 +164,10 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
flags.push((sym::from_desugaring, Some(format!("{:?}", k))));
}

if let ObligationCauseCode::MainFunctionType = obligation.cause.code() {
Copy link
Member Author

@fmease fmease Oct 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, this branch could be generalized to pass along any obligation cause as a flag by using the hypothetical Debug impl for ObligationCauseCode similar to the from_desugaring branch above. However, ObligationCauseCode is quite a big & complex type and it doesn't impl Debug (yet). I am not really convinced that it's a good idea to derive an impl for it (if that's even possible).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea I'd think we'd want to add a method that just gives us the enum variant name without the fields if we wanted to expose all causes to users

@oli-obk
Copy link
Contributor

oli-obk commented Oct 18, 2022

@bors r+

cc @estebank you're gonna love this I think

@bors
Copy link
Contributor

bors commented Oct 18, 2022

📌 Commit 684df4d has been approved by oli-obk

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 18, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request 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 added a commit to rust-lang-ci/rust that referenced this pull request Oct 18, 2022
Rollup of 6 pull requests

Successful merges:

 - rust-lang#103023 (Adding `fuchsia-ignore` and `needs-unwind` to compiler test cases)
 - rust-lang#103142 (Make diagnostic for unsatisfied `Termination` bounds more precise)
 - rust-lang#103154 (Fix typo in `ReverseSearcher` docs)
 - rust-lang#103159 (Remove the redundant `Some(try_opt!(..))` in `checked_pow`)
 - rust-lang#103163 (Remove all uses of array_assume_init)
 - rust-lang#103168 (Stabilize asm_sym)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 472a874 into rust-lang:master Oct 18, 2022
@rustbot rustbot added this to the 1.66.0 milestone Oct 18, 2022
@fmease fmease deleted the fix-103052 branch October 19, 2022 16:08
Manishearth added a commit to Manishearth/rust that referenced this pull request Nov 11, 2022
`#[test]`: Point at return type if `Termination` bound is unsatisfied

Together with rust-lang#103142 (already merged) this fully fixes rust-lang#50291.

I don't consider my current solution of changing a few spans “here and there” very clean since the
failed obligation is a `FunctionArgumentObligation` and we point at a type instead of a function argument.

If you agree with me on this point, I can offer to keep the spans of the existing nodes and instead inject
`let _: AssertRetTyIsTermination<$ret_ty>;` (type to be defined in `libtest`) similar to `AssertParamIsEq` etc.
used by some built-in derive-macros.

I haven't tried that approach yet though and cannot promise that it would actually work out or
be “cleaner” for that matter.

`@rustbot` label A-libtest A-diagnostics
r? `@estebank`
Manishearth added a commit to Manishearth/rust that referenced this pull request Nov 11, 2022
`#[test]`: Point at return type if `Termination` bound is unsatisfied

Together with rust-lang#103142 (already merged) this fully fixes rust-lang#50291.

I don't consider my current solution of changing a few spans “here and there” very clean since the
failed obligation is a `FunctionArgumentObligation` and we point at a type instead of a function argument.

If you agree with me on this point, I can offer to keep the spans of the existing nodes and instead inject
`let _: AssertRetTyIsTermination<$ret_ty>;` (type to be defined in `libtest`) similar to `AssertParamIsEq` etc.
used by some built-in derive-macros.

I haven't tried that approach yet though and cannot promise that it would actually work out or
be “cleaner” for that matter.

``@rustbot`` label A-libtest A-diagnostics
r? ``@estebank``
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Nov 11, 2022
`#[test]`: Point at return type if `Termination` bound is unsatisfied

Together with rust-lang#103142 (already merged) this fully fixes rust-lang#50291.

I don't consider my current solution of changing a few spans “here and there” very clean since the
failed obligation is a `FunctionArgumentObligation` and we point at a type instead of a function argument.

If you agree with me on this point, I can offer to keep the spans of the existing nodes and instead inject
`let _: AssertRetTyIsTermination<$ret_ty>;` (type to be defined in `libtest`) similar to `AssertParamIsEq` etc.
used by some built-in derive-macros.

I haven't tried that approach yet though and cannot promise that it would actually work out or
be “cleaner” for that matter.

```@rustbot``` label A-libtest A-diagnostics
r? ```@estebank```
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Nov 11, 2022
`#[test]`: Point at return type if `Termination` bound is unsatisfied

Together with rust-lang#103142 (already merged) this fully fixes rust-lang#50291.

I don't consider my current solution of changing a few spans “here and there” very clean since the
failed obligation is a `FunctionArgumentObligation` and we point at a type instead of a function argument.

If you agree with me on this point, I can offer to keep the spans of the existing nodes and instead inject
`let _: AssertRetTyIsTermination<$ret_ty>;` (type to be defined in `libtest`) similar to `AssertParamIsEq` etc.
used by some built-in derive-macros.

I haven't tried that approach yet though and cannot promise that it would actually work out or
be “cleaner” for that matter.

````@rustbot```` label A-libtest A-diagnostics
r? ````@estebank````
Aaron1011 pushed a commit to Aaron1011/rust that referenced this pull request Jan 6, 2023
Rollup of 6 pull requests

Successful merges:

 - rust-lang#103023 (Adding `fuchsia-ignore` and `needs-unwind` to compiler test cases)
 - rust-lang#103142 (Make diagnostic for unsatisfied `Termination` bounds more precise)
 - rust-lang#103154 (Fix typo in `ReverseSearcher` docs)
 - rust-lang#103159 (Remove the redundant `Some(try_opt!(..))` in `checked_pow`)
 - rust-lang#103163 (Remove all uses of array_assume_init)
 - rust-lang#103168 (Stabilize asm_sym)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
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 S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

#[rustc_on_unimplemented] warning for Termination can be misleading
5 participants