Skip to content

"Unused" associated type bounds in dyn no longer parameterize the type #140645

Open
@QuineDot

Description

@QuineDot

Code

I tried this code:

#![allow(unused_associated_type_bounds)]

pub trait Other {}
pub trait Trait {
    type Assoc where Self: Sized;
}

impl Other for dyn Trait {}
impl Other for dyn Trait<Assoc = ()> {}
impl<T> dyn Trait<Assoc = T> {}

I expected to see this happen: successful compilation.

Instead, this happened:

error[E0119]: conflicting implementations of trait `Other` for type `(dyn Trait + 'static)`
 --> src/lib.rs:9:1
  |
8 | impl Other for dyn Trait {}
  | ------------------------ first implementation here
9 | impl Other for dyn Trait<Assoc = ()> {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(dyn Trait + 'static)`

error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
  --> src/lib.rs:10:6
   |
10 | impl<T> dyn Trait<Assoc = T> {}
   |      ^ unconstrained type parameter

Some errors have detailed explanations: E0119, E0207.
For more information about an error, try `rustc --explain E0119`.

Version it worked on

It most recently worked on: Rust 1.86.0

Version with regression

Playground: Beta version: 1.87.0-beta.8 (2025-05-03 973ec11)

More notes

CC #125560

Before Beta, dyn Trait and dyn Trait<Assoc = ()> were different types. Now they are the same type.

Here's a more complete example that makes practical (albeit contrived) use of distinct dyn Trait<Assoc = ...> types.

Considering the release notes, #136458 may be the cause (but there's no discussion about this change in particular). Assuming this is the case and the use case that broke is considered unimportant, this aspect of the change could at least be mentioned in the release notes.

Incidentally, this also means dyn Trait<Assoc = &'can_be_non_static str> meets a 'static bound now. Hopefully irrelevant, but it does seem like an exception to outlive bounds being syntactical.

@rustbot modify labels: +regression-from-stable-to-beta, -regression-untriaged

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-dyn-traitArea: trait objects, vtable layoutC-bugCategory: This is a bug.I-prioritizeIssue: Indicates that prioritization has been requested for this issue.L-unused_associated_type_boundsLint: unused_associated_type_boundsT-typesRelevant to the types team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions