Skip to content

Segfault due to impossible_predicates treating ambiguous obligation as impossible #141119

Closed
@compiler-errors

Description

@compiler-errors

I tried this code:

trait Mirror {
    type Assoc: ?Sized;
}
impl<T: ?Sized> Mirror for T {
    type Assoc = T;
}

trait Q: 'static {
    fn q(&self);
}

impl Q for i32 {
    fn q(&self) { println!("i32"); }
}

impl Q for <dyn Q as Mirror>::Assoc where Self: 'static {
    fn q(&self) { println!("dyn Q"); }
}

fn foo<T: Q + ?Sized>(t: &T) {
    t.q();
}

fn main() {
    foo(&1 as &dyn Q);
}

I expected it to work. But instead:

Exited with signal 11 (SIGSEGV): segmentation violation

This is a manifestation of two bugs:

  • Overlap between built-in and user-written impls for dyn Trait: Trait
  • Ambiguity was being treated as a hard error in the impossible_predicates method

Since the new trait solver treats some dyn Trait: Trait overlap as ambiguity (specifically when the responses from the two candidates differ), and we strike methods from the vtable if impossible_predicates returns true, a false positive will lead to a segfault.

Meta

rustc --version --verbose:

rustc 1.89.0-nightly (16d2276fa 2025-05-16)
binary: rustc
commit-hash: 16d2276fa6fccb0cc239a542d4c3f0eb46f660ec
commit-date: 2025-05-16
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.4

Metadata

Metadata

Labels

A-codegenArea: Code generationC-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.WG-trait-system-refactorThe Rustc Trait System Refactor Initiative (-Znext-solver)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions