Skip to content

Inconsistent derivation for type which stores associated type #115181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rodrimati1992 opened this issue Aug 24, 2023 · 1 comment
Closed

Inconsistent derivation for type which stores associated type #115181

rodrimati1992 opened this issue Aug 24, 2023 · 1 comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-trait-system Area: Trait system C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@rodrimati1992
Copy link
Contributor

rodrimati1992 commented Aug 24, 2023

I tried this code:

#[derive(Debug)]
pub struct Foo<T: Iterator>(T::Item);

#[derive(Debug)]
pub struct Bar<T: Iterator>(<T as Iterator>::Item);

I expected to see this happen: either both structs cause a compilation error or neither do.

Instead, this happened: the first struct is accepted and the second causes a compilation error:

> cargo b
   Compiling foo v0.0.0 ([redacted])
error[E0277]: `<T as Iterator>::Item` doesn't implement `Debug`
 --> src/main.rs:5:29
  |
4 | #[derive(Debug)]
  |          ----- in this derive macro expansion
5 | pub struct Bar<T: Iterator>(<T as Iterator>::Item);
  |                             ^^^^^^^^^^^^^^^^^^^^^ `<T as Iterator>::Item` cannot be formatted using `{:?}` because it doesn't implement `Debug`
  |
  = help: the trait `Debug` is not implemented for `<T as Iterator>::Item`
  = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)

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

Meta

rustc --version --verbose:

rustc 1.71.1 (eb26296b5 2023-08-03)
binary: rustc
commit-hash: eb26296b556cef10fb713a38f3d16b9886080f26
commit-date: 2023-08-03
host: x86_64-unknown-linux-gnu
release: 1.71.1
LLVM version: 16.0.5
@rodrimati1992 rodrimati1992 added the C-bug Category: This is a bug. label Aug 24, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 24, 2023
@fmease fmease added A-trait-system Area: Trait system A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-associated-items Area: Associated items (types, constants & functions) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Sep 29, 2023
@fmease
Copy link
Member

fmease commented Nov 20, 2024

Duplicate of #50730

@fmease fmease marked this as a duplicate of #50730 Nov 20, 2024
@fmease fmease closed this as not planned Won't fix, can't repro, duplicate, stale Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-trait-system Area: Trait system C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants