Skip to content

Diagnostic improvement request: Enums that contain non-Send aliased types produce confusing error messages #146016

Closed

Description

@mutexlox-signal

Consider this code (also in this playground):

use std::sync::mpsc;
use std::thread;

mod other {
    use std::ffi::c_void;

    pub type Bar = *const c_void;
}

use other::Bar;

enum Foo {
    Case(i32),
    Case2(Bar),
}
fn main() {
    let (tx, rx) = mpsc::channel();
    let h = thread::spawn(move || match rx.recv().unwrap() {
        Foo::Case(x) => println!("{:?}", x),
        Foo::Case2(b) => println!("{:?}", b),
    });
    tx.send(Foo::Case2(std::ptr::null()));
    h.join();
}

When I compile this with the latest nightly (1.91.0-nightly (2025-08-28 f2824da98d44c4a4e17b), from rust playground), I see this error, which mentions neither Case2 nor Bar. In this case, it's easy enough to see what the problem is, but in a more complex example -- e.g. if Bar comes from a crate whose implementation the user is unfamiliar with -- it becomes difficult to understand what the cause of the problem is.

   Compiling playground v0.0.1 (/playground)
error[E0277]: `*const c_void` cannot be sent between threads safely
   --> src/main.rs:18:27
    |
 18 |       let h = thread::spawn(move ||
    |  _____________-------------_^
    | |             |
    | |             required by a bound introduced by this call
 19 | |     match rx.recv().unwrap() {
 20 | |         Foo::Case(x) => println!("{:?}", x),
 21 | |         Foo::Case2(b) => println!("{:?}", b),
 22 | |     });
    | |_____^ `*const c_void` cannot be sent between threads safely
    |
    = help: within `Foo`, the trait `Send` is not implemented for `*const c_void`
note: required because it appears within the type `Foo`
   --> src/main.rs:12:6
    |
 12 | enum Foo {
    |      ^^^
    = note: required for `std::sync::mpsc::Receiver<Foo>` to implement `Send`
note: required because it's used within this closure
   --> src/main.rs:18:27
    |
 18 |     let h = thread::spawn(move ||
    |                           ^^^^^^^
note: required by a bound in `spawn`
   --> /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/mod.rs:726:8
    |
723 | pub fn spawn<F, T>(f: F) -> JoinHandle<T>
    |        ----- required by a bound in this function
...
726 |     F: Send + 'static,
    |        ^^^^ required by this bound in `spawn`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` (bin "playground") due to 1 previous error

It would be better if the error mentioned either Case2, Bar, or both. (Likely mentioning Case2 would suffice, if the type alias presents issues with providing more helpful diagnostics).

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    A-diagnosticsArea: Messages for errors, warnings, and lints
    A-enumArea: Enums (discriminated unions, or more generally ADTs (algebraic data types))
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    C-bugCategory: This is a bug.
    on Aug 29, 2025
  2. self-assigned this
    on Sep 13, 2026
  3. added 2 commits that reference this issue on Sep 20, 2026
    920c6e8
    a423ddc
  4. added a commit that references this issue on Sep 21, 2026
    87ee6f0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-enumArea: Enums (discriminated unions, or more generally ADTs (algebraic data types))A-threadArea: `std::thread`T-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