wrapping an erroring type in a tuple causes E0277 to be shown where it otherwise wouldn't be
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the diagnostic from the Rust code in src/main.rs, focusing on the tuple passed to Commands::spawn and the resulting E0277 and E0412 messages. Trace how rustc handles trait obligations when another type error is present. Done means the invalid NonZeroU8 example retains E0412 while no longer emitting the misleading tuple Bundle E0277.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100