Uh oh!
There was an error while loading. Please reload this page.
Require that a <_ as Try>::Residual implement the Residual trait - #154451
Conversation
| /// "foo-ness" of the residual so other types need to opt-in to interconversion. | ||
| #[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")] | ||
| type Residual; | ||
| type Residual: Residual<Self::Output>; |
There was a problem hiding this comment.
There's a more nuanced conversation about whether this should go further and also require
| typeResidual:Residual<Self::Output>; | |
| typeResidual:Residual<Self::Output,TryType = Self>; |
but that has a variety of implications, so I'd rather leave it for another time rather than this PR.
There was a problem hiding this comment.
@scottmcm Where is that further step being discussed? And what are those implications?
There was a problem hiding this comment.
IIUC, this would force Residuals to be truly colored. It's not enforced now, so, e.g., Poll currently shares a Residual with Result (Result<Infallible, E>). Someone can ? a Poll in a function returning Result without a specific FromResidual<R> impl:
fnfoo() -> Result<u8,bool>{
core::task::Poll::<Result<u16,bool>>::Ready(Ok(0))?;Ok(1)}I guess that's not desirable because it's unexpected. If Poll had its own Residual, it would take a deliberate impl FromResidual<Poll<Result<Infallible, E>>> for Result<T, E> for the above to work.
I'm also curious to see the discussions.
There was a problem hiding this comment.
I made #155368 as a place to have the discussion.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
rustbot
commented
Mar 28, 2026
Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
rustbot
commented
Mar 28, 2026
rustbot has assigned @petrochenkov. Use Why was this reviewer chosen?The reviewer was selected based on:
|
petrochenkov
commented
Apr 7, 2026
r? library |
rustbot
commented
Apr 7, 2026
Failed to set assignee to
|
petrochenkov
commented
Apr 7, 2026
r? libs |
jhpratt
commented
Apr 9, 2026
cc @rust-lang/libs-api
|
| /// "foo-ness" of the residual so other types need to opt-in to interconversion. | ||
| #[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")] | ||
| type Residual; | ||
| type Residual: Residual<Self::Output>; |
There was a problem hiding this comment.
| typeResidual:Residual<Self::Output>; | |
| typeResidual:[const]Residual<Self::Output>; |
There was a problem hiding this comment.
This needs more changes than just this so I'll leave it for a follow-up.
nia-e
commented
Apr 15, 2026
Per the discussion in the last @rust-lang/libs-api meeting, we're happy to defer to @scottmcm on the details here and the idea seems sound. Thanks ^^ |
This comment has been minimized.
This comment has been minimized.
The `Residual` trait was even more experimental than `Try`, but now that RFC3721 is merged, I think it would make sense to require this.
rustbot
commented
Apr 16, 2026
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
scottmcm
commented
Apr 16, 2026
@bors r=jhpratt |
Rollup of 18 pull requests Successful merges: - #154451 (Require that a `<_ as Try>::Residual` implement the `Residual` trait) - #154595 (Emit fatal on invalid const args with nested defs) - #154599 (report the `varargs_without_pattern` lint in deps) - #154699 (`core::unicode`: Replace `Cased` table with `Lt`) - #155353 (resolve: Remove `inaccessible_ctor_reexport` resolver field) - #155357 (Add `--remap-path-scope` as unstable in rustdoc) - #150649 (clippy fix: non_canonical_clone_impl) - #154604 (abort in core) - #154616 (Add `--quiet` flag to x.py and bootstrap to suppress output) - #155215 (Clean up `AttributeLintKind` and refactor diagnostic attribute linting) - #155228 (Check diagnostic output in incremental `cpass` and `rpass` revisions) - #155266 (Adjust release notes for post-merge feedback) - #155326 (Disallow ZST allocations with `TypedArena`.) - #155334 (docs: Use `0b1` instead of `NonZero::MIN` in `NonZero::bit_width` doctests) - #155340 (Handle nonnull pattern types in size skeleton) - #155347 (Add push_mut and new Layout methods to release notes) - #155356 (remove calls to AliasTyKind::def_id) - #155364 (Reduce diagnostic type visibilities.)
Uh oh!
There was an error while loading. Please reload this page.
Rollup merge of #154451 - scottmcm:require-residual, r=jhpratt Require that a `<_ as Try>::Residual` implement the `Residual` trait The `Residual` trait was even more experimental than `Try`, but now that rust-lang/rfcs#3721 is merged, I think it would make sense to require this. Technically it's not strictly required, but without it something working on `<T: Try>` might need an extra bound even to use a homogeneous try block with the same output type as `T::Output`. (Another `where` will of course be needed to return a *different* `impl Try` type still.) cc #154391
Rollup of 18 pull requests Successful merges: - rust-lang/rust#154451 (Require that a `<_ as Try>::Residual` implement the `Residual` trait) - rust-lang/rust#154595 (Emit fatal on invalid const args with nested defs) - rust-lang/rust#154599 (report the `varargs_without_pattern` lint in deps) - rust-lang/rust#154699 (`core::unicode`: Replace `Cased` table with `Lt`) - rust-lang/rust#155353 (resolve: Remove `inaccessible_ctor_reexport` resolver field) - rust-lang/rust#155357 (Add `--remap-path-scope` as unstable in rustdoc) - rust-lang/rust#150649 (clippy fix: non_canonical_clone_impl) - rust-lang/rust#154604 (abort in core) - rust-lang/rust#154616 (Add `--quiet` flag to x.py and bootstrap to suppress output) - rust-lang/rust#155215 (Clean up `AttributeLintKind` and refactor diagnostic attribute linting) - rust-lang/rust#155228 (Check diagnostic output in incremental `cpass` and `rpass` revisions) - rust-lang/rust#155266 (Adjust release notes for post-merge feedback) - rust-lang/rust#155326 (Disallow ZST allocations with `TypedArena`.) - rust-lang/rust#155334 (docs: Use `0b1` instead of `NonZero::MIN` in `NonZero::bit_width` doctests) - rust-lang/rust#155340 (Handle nonnull pattern types in size skeleton) - rust-lang/rust#155347 (Add push_mut and new Layout methods to release notes) - rust-lang/rust#155356 (remove calls to AliasTyKind::def_id) - rust-lang/rust#155364 (Reduce diagnostic type visibilities.)
Rollup of 18 pull requests Successful merges: - rust-lang/rust#154451 (Require that a `<_ as Try>::Residual` implement the `Residual` trait) - rust-lang/rust#154595 (Emit fatal on invalid const args with nested defs) - rust-lang/rust#154599 (report the `varargs_without_pattern` lint in deps) - rust-lang/rust#154699 (`core::unicode`: Replace `Cased` table with `Lt`) - rust-lang/rust#155353 (resolve: Remove `inaccessible_ctor_reexport` resolver field) - rust-lang/rust#155357 (Add `--remap-path-scope` as unstable in rustdoc) - rust-lang/rust#150649 (clippy fix: non_canonical_clone_impl) - rust-lang/rust#154604 (abort in core) - rust-lang/rust#154616 (Add `--quiet` flag to x.py and bootstrap to suppress output) - rust-lang/rust#155215 (Clean up `AttributeLintKind` and refactor diagnostic attribute linting) - rust-lang/rust#155228 (Check diagnostic output in incremental `cpass` and `rpass` revisions) - rust-lang/rust#155266 (Adjust release notes for post-merge feedback) - rust-lang/rust#155326 (Disallow ZST allocations with `TypedArena`.) - rust-lang/rust#155334 (docs: Use `0b1` instead of `NonZero::MIN` in `NonZero::bit_width` doctests) - rust-lang/rust#155340 (Handle nonnull pattern types in size skeleton) - rust-lang/rust#155347 (Add push_mut and new Layout methods to release notes) - rust-lang/rust#155356 (remove calls to AliasTyKind::def_id) - rust-lang/rust#155364 (Reduce diagnostic type visibilities.)
The
Residualtrait was even more experimental thanTry, but now that rust-lang/rfcs#3721 is merged, I think it would make sense to require this. Technically it's not strictly required, but without it something working on<T: Try>might need an extra bound even to use a homogeneous try block with the same output type asT::Output. (Anotherwherewill of course be needed to return a differentimpl Trytype still.)cc #154391