rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.15k stars 12.56k forks source link

wrapping an erroring type in a tuple causes E0277 to be shown where it otherwise wouldn't be #130525

Open lolbinarycat opened 1 week ago

lolbinarycat commented 1 week ago

Code

use bevy::prelude::*;

#[derive(Component)]
struct Comp1(NonZeroU8);

fn main() {}

fn setup(mut commands: Commands) {
    commands.spawn((Comp1(1.try_into().unwrap()),));
}

Current output

   Compiling game v0.1.0 (/playground)
error[E0412]: cannot find type `NonZeroU8` in this scope
 --> src/main.rs:4:14
  |
4 | struct Comp1(NonZeroU8);
  |              ^^^^^^^^^ not found in this scope
  |
help: consider importing this type alias
  |
1 + use std::num::NonZeroU8;
  |

error[E0277]: `(Comp1,)` is not a `Bundle`
   --> src/main.rs:9:20
    |
9   |     commands.spawn((Comp1(1.try_into().unwrap()),));
    |              ----- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid `Bundle`
    |              |
    |              required by a bound introduced by this call
    |
    = help: the trait `Bundle` is not implemented for `(Comp1,)`
    = note: consider annotating `(Comp1,)` with `#[derive(Component)]` or `#[derive(Bundle)]`
    = help: the following other types implement trait `Bundle`:
              ()
              (B0, B1)
              (B0, B1, B2)
              (B0, B1, B2, B3)
              (B0, B1, B2, B3, B4)
              (B0, B1, B2, B3, B4, B5)
              (B0, B1, B2, B3, B4, B5, B6)
              (B0, B1, B2, B3, B4, B5, B6, B7)
            and 8 others
note: required by a bound in `bevy::prelude::Commands::<'w, 's>::spawn`
   --> /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_ecs-0.14.2/src/system/commands/mod.rs:362:21
    |
362 |     pub fn spawn<T: Bundle>(&mut self, bundle: T) -> EntityCommands {
    |                     ^^^^^^ required by this bound in `Commands::<'w, 's>::spawn`

Some errors have detailed explanations: E0277, E0412.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `game` (bin "game") due to 2 previous errors

Desired output

   Compiling game v0.1.0 (/playground)
error[E0412]: cannot find type `NonZeroU8` in this scope
 --> src/main.rs:4:14
  |
4 | struct Comp1(NonZeroU8);
  |              ^^^^^^^^^ not found in this scope
  |
help: consider importing this type alias
  |
1 + use std::num::NonZeroU8;
  |

Some errors have detailed explanations: E0277, E0412.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `game` (bin "game") due to 2 previous errors

Rationale and extra context

this is a bug, because E0277 is not shown when trying to directly use a trait on a type that contains an error, or when the trait is Default. only when using a user-defined trait within a tuple is this shown.

Other cases

No response

Rust Version

rustc 1.83.0-nightly (04a318787 2024-09-15) binary: rustc commit-hash: 04a318787b39732e306faf5ef6dc584990f4f417 commit-date: 2024-09-15 host: x86_64-unknown-linux-gnu release: 1.83.0-nightly LLVM version: 19.1.0

Anything else?

No response

compiler-errors commented 1 week ago

This issue is unreadable at the moment. Could you wrap the relevant code sections in triple backticks. Also, did you provide any actual repro for this issue? All I see is error output.

lolbinarycat commented 1 week ago

@compiler-errors i just used the issue form, as always. maybe it's a problem with the new beta features?