Skip to content

Regression in nightly-2022-05-01 relating to trait objects #96664

Closed
@Edgeworth

Description

@Edgeworth

Code

When updating from nightly nightly-2022-04-30-x86_64-unknown-linux-gnu to nightly nightly-2022-05-01-x86_64-unknown-linux-gnu, some code that previously compiled stopped compiling. Here's the basic idea of it:

pub trait State = Clone + Send + Sync + PartialOrd + PartialEq + fmt::Display;
pub trait RandState<S: State> = FnMut() -> S + Send;

pub struct Evolver<E: Evaluator> {
    rand_state: Box<dyn RandState<E::State>>
}

I expected to see this happen: compiles

Instead, this happened:

error[E0225]: only auto traits can be used as additional traits in a trait object
   --> src/gen/evaluated.rs:172:26
    |
172 |         genfn: &mut (dyn RandState<S> + '_),
    |                          ^^^^^^^^^^^^
    |                          |
    |                          trait alias used in trait object type (additional use)
    |                          trait alias used in trait object type (first use)
    |
   ::: src/evolve/evolver.rs:14:24
    |
14  | pub trait RandState<S: State> = FnMut() -> S + Send;
    |                        -----    ------------ first non-auto trait
    |                        |
    |                        referenced here (additional use)
    |
   ::: src/eval.rs:8:19
    |
8   | pub trait State = Clone + Send + Sync + PartialOrd + PartialEq + fmt::Display;
    |                   ----- additional non-auto trait
    |
    = help: consider creating a new trait with all of these as supertraits and using that trait here instead: `trait NewTrait: FnMut<()> + Clone + PartialOrd + PartialEq + std::fmt::Display {}`

This code previously compiled, and the code already does what the advice of the error message suggests, so it seems like a regression to me.

If needed, you can get the full repro by looking at https://github.com/Edgeworth/memega

Version it worked on

nightly-2022-04-30-x86_64-unknown-linux-gnu

Version with regression

nightly-2022-05-01-x86_64-unknown-linux-gnu

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions