-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Conversation
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
@@ -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() { |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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
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
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
`#[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`
`#[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``
`#[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```
`#[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````
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
Don't blindly emit a diagnostic claiming that “
main
has an invalid return type” if we encounter a type that should but doesn't implementstd::process::Termination
and isn't actually the return type of the program entrymain
.Fixes #103052.
@rustbot label A-diagnostics T-compiler T-libs
r? diagnostics