Skip to content

Conversation

@A4-Tacks
Copy link
Member

@A4-Tacks A4-Tacks commented Feb 4, 2026

Fixes #19878

Example

#[derive(Clo$0ne)]
struct Foo<T: core::ops::Deref>(T::Target);

Before this PR

struct Foo<T: core::ops::Deref>(T::Target);

impl<T: core::ops::Deref + Clone> Clone for Foo<T> {
    $0fn clone(&self) -> Self {
        Self(self.0.clone())
    }
}

After this PR

struct Foo<T: core::ops::Deref>(T::Target);

impl<T: core::ops::Deref + Clone> Clone for Foo<T>
where T::Target: Clone
{
    $0fn clone(&self) -> Self {
        Self(self.0.clone())
    }
}

Example
---
```rust
#[derive(Clo$0ne)]
struct Foo<T: core::ops::Deref>(T::Target);
```

**Before this PR**

```rust
struct Foo<T: core::ops::Deref>(T::Target);

impl<T: core::ops::Deref + Clone> Clone for Foo<T> {
    $0fn clone(&self) -> Self {
        Self(self.0.clone())
    }
}
```

**After this PR**

```rust
struct Foo<T: core::ops::Deref>(T::Target);

impl<T: core::ops::Deref + Clone> Clone for Foo<T>
where T::Target: Clone
{
    $0fn clone(&self) -> Self {
        Self(self.0.clone())
    }
}
```
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 4, 2026
trait_,
ty,
None,
trait_where_clause,
Copy link
Member

@ShoyuVanilla ShoyuVanilla Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This behaves correctly, but the variable name and passing it as the param with the same name might be misleading. We’re collecting clauses from the ADT here, not from the trait.

Copy link
Member

@ShoyuVanilla ShoyuVanilla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pub fn impl_trait(
attrs: impl IntoIterator<Item = ast::Attr>,
is_unsafe: bool,
trait_gen_params: Option<ast::GenericParamList>,
trait_gen_args: Option<ast::GenericArgList>,
type_gen_params: Option<ast::GenericParamList>,
type_gen_args: Option<ast::GenericArgList>,
is_negative: bool,
path_type: ast::Type,
ty: ast::Type,
trait_where_clause: Option<ast::WhereClause>,
ty_where_clause: Option<ast::WhereClause>,
body: Option<ast::AssocItemList>,
) -> ast::Impl {

We might need to improve the above API as well to accept iterator or sth for where clauses but I think this PR is good as is for now

@ShoyuVanilla ShoyuVanilla added this pull request to the merge queue Feb 10, 2026
Merged via the queue into rust-lang:master with commit 07a5948 Feb 10, 2026
15 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Convert to manual impl ... loses bounds

3 participants