Skip to content

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

Closed as duplicate of#57893
@rucsesec

Description

@rucsesec

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-type-systemArea: Type systemC-bugCategory: This is a bug.E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustcI-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessT-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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions