Closed as duplicate of#50730
Description
I tried this code:
trait Bar { type Qux; }
#[derive(Clone)]
struct Foo<T>(T::Qux) where T: Bar;
#[derive(Clone)]
struct Zoo<T>(<T as Bar>::Qux) where T: Bar;
I expected to see this happen: No error.
Instead, this happened:
Error on Long
only:
error[E0277]: the trait bound `<T as Bar>::Qux: Clone` is not satisfied
--> src/lib.rs:8:16
|
7 | #[derive(Clone)]
| ----- in this derive macro expansion
8 | struct Long<T>(<T as Bar>::Qux) where T: Bar;
| ^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `<T as Bar>::Qux`
|
= note: this error originates in the derive macro `Clone` (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 `playground` (lib) due to 1 previous error
Macro output:
#![feature(prelude_import)]
#[prelude_import]
use std::prelude::rust_2024::*;
#[macro_use]
extern crate std;
trait Bar {
type Qux;
}
struct Short<T>(T::Qux) where T: Bar;
#[automatically_derived]
impl<T: ::core::clone::Clone> ::core::clone::Clone for Short<T> where T: Bar,
T::Qux: ::core::clone::Clone {
#[inline]
fn clone(&self) -> Short<T> {
Short(::core::clone::Clone::clone(&self.0))
}
}
struct Long<T>(<T as Bar>::Qux) where T: Bar;
#[automatically_derived]
impl<T: ::core::clone::Clone> ::core::clone::Clone for Long<T> where T: Bar {
#[inline]
fn clone(&self) -> Long<T> { Long(::core::clone::Clone::clone(&self.0)) }
}
Meta
Tested on both stable 1.85.1 and nightly 1.88.0-nightly (2025-03-31 0b45675).
Metadata
Metadata
Assignees
Labels
Area: Associated items (types, constants & functions)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Category: This is a bug.Status: A Minimal Complete and Verifiable Example has been found for this issueRelevant to the compiler team, which will review and decide on the PR/issue.