Skip to content

regression: Compiler error with dyn + for<'a> #132000

Open
@ABorgna

Description

Code

pub trait Tr {
    type Assoc<'c>;
}

pub trait Mapping<'c, T: Tr>: Fn(T::Assoc<'c>) -> T::Assoc<'c> {}

pub trait ForallMap<T: Tr>: for<'c> Mapping<'c, T> {}

pub struct S<T: Tr>(pub dyn ForallMap<T>);

On stable, cargo build compiles without errors.

On beta (and nightly 2024-10-20), it fails with the following error:

error[E0582]: binding for associated type `Output` references lifetime `'c`, which does not appear in the trait input types
 --> src/lib.rs:9:29
  |
5 | pub trait Mapping<'c, T: Tr>: Fn(T::Assoc<'c>) -> T::Assoc<'c> {}
  |                                                   ------------ due to this supertrait
...
9 | pub struct S<T: Tr>(pub dyn ForallMap<T>);
  |                             ^^^^^^^^^^^^

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

playground

EDIT: Cleaned the example a bit

Version it worked on

rustc --version --verbose:

rustc 1.82.0 (f6e511eec 2024-10-15)
binary: rustc
commit-hash: f6e511eec7342f59a25f7c0534f1dbea00d01b14
commit-date: 2024-10-15
host: aarch64-apple-darwin
release: 1.82.0
LLVM version: 19.1.1

Version with regression

rustc +beta --version --verbose:

rustc 1.83.0-beta.2 (88c1c3c11 2024-10-18)
binary: rustc
commit-hash: 88c1c3c1102bbf3860891bfa52b7ddd9f26aec2f
commit-date: 2024-10-18
host: aarch64-apple-darwin
release: 1.83.0-beta.2
LLVM version: 19.1.1

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-trait-objectsArea: trait objects, vtable layoutC-bugCategory: This is a bug.T-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

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions