Skip to content

Nightly 65e297d1e 2023-11-03 fails to infer auto traits #117602

Description

@adamreichold

The type aho_corasick::AhoCorack is not inferred to be Send + Sync by the above mentioned nightly release, c.f. https://github.com/quickwit-oss/tantivy/actions/runs/6759263517/job/18371750242?pr=2239 Using the stable, the code compiles with out issue.

EDIT: It seems to be related to GAT, i.e. a more minimal reproducer is:

trait SomethingSomething: Send {}

struct Wrapper<T> {
    something: Box<dyn SomethingSomething>,
    other: T,
}

trait HasSend {
    type IsSend<T: Send>: Send;
}

impl<T> HasSend for Wrapper<T> {
    type IsSend<S: Send> = Wrapper<S>;
}

which similarly fails on nightly and builds on stable.

More details
> rustc --crate-type=lib nightly-auto-trait.rs 
error[E0277]: `(dyn SomethingSomething + 'static)` cannot be sent between threads safely
   --> nightly-auto-trait.rs:13:28
    |
13  |     type IsSend<S: Send> = Wrapper<S>;
    |                            ^^^^^^^^^^ `(dyn SomethingSomething + 'static)` cannot be sent between threads safely
    |
    = help: the trait `Send` is not implemented for `(dyn SomethingSomething + 'static)`
    = note: required for `Unique<(dyn SomethingSomething + 'static)>` to implement `Send`
note: required because it appears within the type `Box<dyn SomethingSomething>`
   --> /home/adam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/boxed.rs:195:12
    |
195 | pub struct Box<
    |            ^^^
note: required because it appears within the type `Wrapper<S>`
   --> nightly-auto-trait.rs:3:8
    |
3   | struct Wrapper<T> {
    |        ^^^^^^^
note: required by a bound in `HasSend::IsSend`
   --> nightly-auto-trait.rs:9:27
    |
9   |     type IsSend<T: Send>: Send;
    |                           ^^^^ required by this bound in `HasSend::IsSend`

error: aborting due to previous error

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

on the above-mentioned nightly version whereas stable is happy

> rustc +stable --crate-type=lib nightly-auto-trait.rs 
warning: fields `something` and `other` are never read
 --> nightly-auto-trait.rs:4:5
  |
3 | struct Wrapper<T> {
  |        ------- fields in this struct
4 |     something: Box<dyn SomethingSomething>,
  |     ^^^^^^^^^
5 |     other: T,
  |     ^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: 1 warning emitted

Simply asserting that Wrapper is Send + Sync via e.g. fn is_send_sync<T: Send + Sync>(_: T) {} works on stable and nightly.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-GATsArea: Generic associated types (GATs)A-inferenceArea: Type inferenceC-bugCategory: This is a bug.F-generic_associated_types`#![feature(generic_associated_types)]` a.k.a. GATsT-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