Skip to content

Unsatisfied implicit trait bound is not made explicit in E0277 #150576

@MDLC01

Description

@MDLC01

Code

trait Trait {
    fn foo(&self);
}

// Implicitly requires `T: Sized`.
// Adding a `?Sized` bound makes the error go away.
impl<T> Trait for T {
    fn foo(&self) {}
}

// `[u8]` does not implement `Sized`.
fn test(x: &[u8]) {
    Trait::foo(x)
}

Current output

error[E0277]: the trait bound `[u8]: Trait` is not satisfied
  --> src/lib.rs:13:16
   |
13 |     Trait::foo(x)
   |     ---------- ^ the trait `Trait` is not implemented for `[u8]`
   |     |
   |     required by a bound introduced by this call
   |
note: required for `[u8]` to implement `Trait`
  --> src/lib.rs:7:9
   |
 7 | impl<T> Trait for T {
   |      -  ^^^^^     ^
   |      |
   |      unsatisfied trait bound introduced here
help: consider borrowing here
   |
13 |     Trait::foo(&x)
   |                +
13 |     Trait::foo(&mut x)
   |                ++++

For more information about this error, try `rustc --explain E0277`.

Desired output

error[E0277]: the trait bound `[u8]: Trait` is not satisfied
  --> src/lib.rs:12:16
   |
13 |     Trait::foo(x)
   |     ---------- ^ the trait `Sized` is not implemented for `[u8]`
   |     |
   |     required by a bound introduced by this call
   |
note: required for `[u8]` to implement `Trait`
  --> src/lib.rs:6:9
   |
 7 | impl<T> Trait for T {
   |      -  ^^^^^     ^
   |      |
   |      unsatisfied trait bound introduced here
help: consider relaxing the implicit `Sized` bound
   |
 7 | impl<T: ?Sized> Trait for T {
   |       ++++++++

For more information about this error, try `rustc --explain E0277`.

Rationale and extra context

No response

Other cases

Rust Version

$ rustc --version --verbose
rustc 1.90.0 (1159e78c4 2025-09-14)
binary: rustc
commit-hash: 1159e78c4747b02ef996e55082b704c09b970588
commit-date: 2025-09-14
host: x86_64-pc-windows-gnu
release: 1.90.0
LLVM version: 20.1.8

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler 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