Enforce Sized return types on Fn* bounds#83915
Enforce Sized return types on Fn* bounds#83915estebank wants to merge 3 commits intorust-lang:masterfrom
Sized return types on Fn* bounds#83915Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
I'm puzzled, I haven't been able to reproduce the problem locally. |
There was a problem hiding this comment.
For reviewer context, the filtering out of projections and opaque types is a hack and shouldn't be necessary long term if we find a better place to inject the Sized obligation.
If I don't keep this in, then we start failing stage 1 builds. This tells me there's a better place to inject this obligation, but I haven't been able to find it.
There was a problem hiding this comment.
You can look at the diff between the two commits to see what this check changes.
In a `fn() -> Out` bound, enforce `Out: Sized` to avoid unsoundness. Fix rust-lang#82633.
093d25b to
670d20d
Compare
| { | ||
| // Do not allow `foo::<fn() -> A>();` for `A: !Sized` (#82633) | ||
| let fn_sig = obligation.predicate.self_ty().skip_binder().fn_sig(self.tcx()); | ||
| let ty = self.infcx.replace_bound_vars_with_placeholders(fn_sig.output()); |
There was a problem hiding this comment.
Using replace_bound_vars_with_placeholders pacified CI, but I still don't understand why it wasn't triggering on my machine. Maybe the assert! wasn't being run locally?
|
Some discussion on Zulip: https://zulip-archive.rust-lang.org/144729wgtraits/32496PR83915.html |
|
Alternate branch: https://github.com/nikomatsakis/rust/tree/issue-82633-sized-return-types This fix is not perfect, but may be a better stepping stone. |
|
☔ The latest upstream changes (presumably #94108) made this pull request unmergeable. Please resolve the merge conflicts. |
…zed, r=jackh726 a fn pointer doesn't implement `Fn`/`FnMut`/`FnOnce` if its return type isn't sized I stumbled upon rust-lang#83915 which hasn't received much attention recently, and I wanted to revive it since this is one existing soundness hole that seems pretty easy to fix. I'm not actually sure that the [alternative approach described here](rust-lang#83915 (comment)) is sufficient, given the `src/test/ui/function-pointer/unsized-ret.rs` example I provided below. Rebasing the branch mentioned in that comment and testing that UI test, it seems that we actually end up only observing that `str: !Sized` during monomorphization, whereupon we ICE. Even if we were to fix that ICE, ideally we'd be raising an error that a fn pointer is being used badly during _typecheck_ instead of monomorphization, hence adapting the original approach in rust-lang#83915. I am happy to close this if people would prefer we rebase the original PR and land that -- I am partly opening to be annoying and get people thinking about this unsoundness again ❤️ 😸 cc: `@estebank` and `@nikomatsakis` r? types Here's a link to the thread: https://rust-lang.zulipchat.com/#narrow/stream/144729-t-types/topic/PR.20.2383915/near/235421351 for more context.
|
I think this PR can now be closed in favor of #100096? 🤔 feel free to reopen if that isn't the case |
|
@lcnr I'm just happy it's finally handled |
…ckh726 a fn pointer doesn't implement `Fn`/`FnMut`/`FnOnce` if its return type isn't sized I stumbled upon #83915 which hasn't received much attention recently, and I wanted to revive it since this is one existing soundness hole that seems pretty easy to fix. I'm not actually sure that the [alternative approach described here](rust-lang/rust#83915 (comment)) is sufficient, given the `src/test/ui/function-pointer/unsized-ret.rs` example I provided below. Rebasing the branch mentioned in that comment and testing that UI test, it seems that we actually end up only observing that `str: !Sized` during monomorphization, whereupon we ICE. Even if we were to fix that ICE, ideally we'd be raising an error that a fn pointer is being used badly during _typecheck_ instead of monomorphization, hence adapting the original approach in #83915. I am happy to close this if people would prefer we rebase the original PR and land that -- I am partly opening to be annoying and get people thinking about this unsoundness again ❤️ 😸 cc: `@estebank` and `@nikomatsakis` r? types Here's a link to the thread: https://rust-lang.zulipchat.com/#narrow/stream/144729-t-types/topic/PR.20.2383915/near/235421351 for more context.
…ckh726 a fn pointer doesn't implement `Fn`/`FnMut`/`FnOnce` if its return type isn't sized I stumbled upon #83915 which hasn't received much attention recently, and I wanted to revive it since this is one existing soundness hole that seems pretty easy to fix. I'm not actually sure that the [alternative approach described here](rust-lang/rust#83915 (comment)) is sufficient, given the `src/test/ui/function-pointer/unsized-ret.rs` example I provided below. Rebasing the branch mentioned in that comment and testing that UI test, it seems that we actually end up only observing that `str: !Sized` during monomorphization, whereupon we ICE. Even if we were to fix that ICE, ideally we'd be raising an error that a fn pointer is being used badly during _typecheck_ instead of monomorphization, hence adapting the original approach in #83915. I am happy to close this if people would prefer we rebase the original PR and land that -- I am partly opening to be annoying and get people thinking about this unsoundness again ❤️ 😸 cc: `@estebank` and `@nikomatsakis` r? types Here's a link to the thread: https://rust-lang.zulipchat.com/#narrow/stream/144729-t-types/topic/PR.20.2383915/near/235421351 for more context.
In a
fn() -> Outbound, enforceOut: Sizedto avoid unsoundness.Fix #82633.
r? @pnkfelix cc @nikomatsakis