Skip to content

Function type with opaque return type can be coerced to dyn Fn with arbitrary return type #98608

Closed

Description

@Noratrieb

I tried this code:

fn hi() -> impl Sized { std::ptr::null::<u8>() }

fn main() {
    let b: Box<dyn Fn() -> Box<u8>> = Box::new(hi);
    let boxed = b();
    let null = *boxed;
    println!("{null:?}");
}

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=a78a1c65a7788a1fc16bbb49823e31b1

I expected to see this happen: Compiler error, since impl Sized cannot be coerced to Box<u8>.

Instead, this happened: Code compiles, segfault

Meta

rustc --version --verbose:

rustc 1.64.0-nightly (2f3ddd9f5 2022-06-27)
binary: rustc
commit-hash: 2f3ddd9f594adf9773547aa7cedb43c4ac8ffd2f
commit-date: 2022-06-27
host: x86_64-unknown-linux-gnu
release: 1.64.0-nightly
LLVM version: 14.0.6

Activity

  1. JakobDegen commented on Jun 28, 2022

    @JakobDegen
    Contributor

    This regressed in 1.61, unfortunately my wifi is not currently up for running a proper bisect.

    @rustbot label +regression-from-stable-to-stable

  2. added
    regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Jun 28, 2022
  3. added
    I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
    on Jun 28, 2022
  4. oli-obk commented on Jun 28, 2022

    @oli-obk
    Contributor

    likely cause is one of the uses of take_opaque_type without actually registering the hidden types

  5. self-assigned this
    on Jun 28, 2022
  6. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Jun 28, 2022
  7. Dylan-DPC commented on Jun 30, 2022

    @Dylan-DPC
    Member

    marking it as critical based on the prioritisation group discussion

  8. added and removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Jun 30, 2022
  9. apiraino commented on Jun 30, 2022

    @apiraino
    Contributor

    Correct link for WG-prioritization Zulip discussion

  10. added a commit that references this issue on Jul 20, 2022
  11. added
    T-typesRelevant to the types team, which will review and decide on the PR/issue.
    on Oct 11, 2024
  12. added a commit that references this issue on May 11, 2026
  13. added a commit that references this issue on May 14, 2026
  14. added a commit that references this issue on Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-criticalCritical priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions