Skip to content

The mismatched types were not detected, and a segmentation fault occurred at runtime. #139792

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

Closed
rucsesec opened this issue Apr 14, 2025 · 2 comments
Labels
A-type-system Area: Type system C-bug Category: This is a bug. E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@rucsesec
Copy link

I tried this code:

use std::fmt::Display;

trait Trait{
    type Associated;
}

impl<T: ?Sized> Trait for T {
    type Associated = Box<dyn Display>;
}

fn foo<T: ?Sized>(_: <T as Trait>::Associated) {}

fn main() {
    let x = "Hello World".to_string();
    foo::<dyn Trait<Associated = &str>>( &x );
}

I expected to see this happen: mismatched types:expected “Box<dyn Display>”, found “&str”.
Instead, this happened: The code compiles successfully but encounters a segmentation fault at runtime.

Program returned: 139
Program stderr
Program terminated with signal: SIGSEGV

Demo: godbolt permalink
Demo: on current playground

Meta

rustc --version --verbose:

rustc 1.88.0-nightly (0fe8f3454 2025-04-10)
@rucsesec rucsesec added the C-bug Category: This is a bug. label Apr 14, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 14, 2025
@bjorn3 bjorn3 added A-type-system Area: Type system I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness labels Apr 14, 2025
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Apr 14, 2025
@jieyouxu jieyouxu added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue. labels Apr 14, 2025
@jieyouxu
Copy link
Member

This also segfaults on stable

@oli-obk oli-obk added the E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc label Apr 14, 2025
@lcnr
Copy link
Contributor

lcnr commented Apr 14, 2025

Thank you for finding this unsoundness and reporting it. This is already a known issue which is difficult to fix. We do intend to fix this in the medium term however. Closing in favor of #57893

@lcnr lcnr closed this as completed Apr 14, 2025
@jieyouxu jieyouxu removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Apr 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-type-system Area: Type system C-bug Category: This is a bug. E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants