rust-lang / rust-lang/rust

Missing `where Self: Sized` in impl gives wrong error message for new solver

Open
#162,368 4 comments 0 reactions 1 assignee View on GitHub

@ozankenangungor is already working on this.

Since Sep 6, 2026.

A-associated-items A-diagnostics D-incorrect T-compiler WG-trait-system-refactor
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
trait Trait {
    type Assoc
    where
        Self: Sized;
}
impl<T: ?Sized> Trait for T {
    type Assoc = i32;
}
Current output

New solver:

error[E0271]: type mismatch resolving `<T as Trait>::Assoc == _`
  --> src/main.rs:XX:XX
   |
XX |     type Assoc = i32;
   |                  ^^^
   |                  |
   |                  types differ
   |                  type mismatch resolving `<T as Trait>::Assoc == _`
Desired output
error[E0277]: the size for values of type `T` cannot be known at compilation time
  --> src/main.rs:XX:XX
   |
XX | impl<T: ?Sized> Trait for T {
   |      - this type parameter needs to be `Sized`
   |
note: required by a bound in `Trait::Assoc`
  --> src/main.rs:X:XX
   |
XX |     type Assoc
   |          ----- required by a bound in this associated type
XX |     where
XX |         Self: Sized;
   |               ^^^^^ required by this bound in `Trait::Assoc`

The help should suggest adding where Self: Sized.

Rationale and extra context

Note that the output with the old solver is also incorrect, as it claims i32 is not Sized (but the base message is correct):

error[E0277]: the size for values of type `T` cannot be known at compilation time
  --> src/main.rs:XX:XX
   |
XX | impl<T: ?Sized> Trait for T {
   |      - this type parameter needs to be `Sized`
XX |     type Assoc = i32;
   |                  ^^^ doesn't have a size known at compile-time
   |
help: consider removing the `?Sized` bound to make the type parameter `Sized`
   |
XX - impl<T: ?Sized> Trait for T {
XX + impl<T> Trait for T {
   |
Rust Version
rustc 1.100.0-nightly (0ed41eb41 2026-09-04)
binary: rustc
commit-hash: 0ed41eb4142dda2df61eb1145a312c1a9d62eb56
commit-date: 2026-09-04
host: x86_64-unknown-linux-gnu
release: 1.100.0-nightly
LLVM version: 23.1.1

@rustbot label D-incorrect WG-trait-system-refactor A-associated-items

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.