-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Avoid InferOk<'tcx, ()>
#131134
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
Avoid InferOk<'tcx, ()>
#131134
Conversation
Some changes occurred to the core trait solver cc @rust-lang/initiative-trait-system-refactor Some changes occurred in engine.rs, potentially modifying the public API of |
I do think this makes some of the code nicer, but doesn't this make it more annoying to refactor the locations in question? Since now they're a different type to begin with. |
It's unused.
`InferOk<'tcx, T>` wraps a `T` and a `Vec<PredicateObligation<'tcx>>`. A lot of the instances are `InferOk<'tcx, ()>`, which is just a clumsy wrapper for a `Vec<PredicateObligation<'tcx>>`. This commit removes the `InferOk` in those cases, avoiding a lot of boilerplate wrapping/unwrapping code. To help with this, the unused `UnitResult` type is replaced with `UnitInferResult`, which is like `InferResult<'tcx, ()>` but without the useless `InferOk<'tcx, ()>` wrapper.
12a6992
to
4f42b28
Compare
The |
Hm, okay! |
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.
I think the main reason to use InferOk
over Vec<...>
is that InferOk
is #[must_use]
and we want to make sure that people don't don't do the following, which implicitly drops the nested obligations
whatever_typesystem_operation()?;
I think we currently lint on that but will stop to do so with this change.
Hmm, interesting. This has made me think about
So this
Is it because they have side-effects as well as returning obligations? The following snippet is interesting, it's a case where rust/compiler/rustc_hir_typeck/src/method/probe.rs Lines 1407 to 1413 in 18b1161
Interesting that the When dealing with I'm not wedded to this PR, I'm just trying to understand some of the subtleties. |
yeah, a lot of compiler contributors tend to not be aware that relating types can result in nested obligations, so iirc we accidentally dropped them in quite a few places in the past. This is part of the reason the |
Prompted by rust-lang#131134, which tried to remove `InferOk<'tcx, ()>` occurrences.
Prompted by rust-lang#131134, which tried to remove `InferOk<'tcx, ()>` occurrences.
Prompted by rust-lang#131134, which tried to remove `InferOk<'tcx, ()>` occurrences.
InferOk<'tcx, ()>
is a silly type. This PR converts uses of it to something simpler.r? @lcnr