-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
When derive
ing, account for HRTB on BareFn
fields
#125987
Conversation
r? @Nadrieril rustbot has assigned @Nadrieril. Use |
This comment has been minimized.
This comment has been minimized.
When given ```rust trait SomeTrait { type SomeType<'a>; } struct Foo<T: SomeTrait> { x: for<'a> fn(T::SomeType<'a>) } ``` expand to ```rust impl<T: ::core::clone::Clone + SomeTrait> ::core::clone::Clone for Foo<T> where for<'a> T::SomeType<'a>: ::core::clone::Clone { #[inline] fn clone(&self) -> Foo<T> { Foo { x: ::core::clone::Clone::clone(&self.x) } } } ``` instead of the previous invalid ``` impl<T: ::core::clone::Clone + SomeTrait> ::core::clone::Clone for Foo<T> where T::SomeType<'a>: ::core::clone::Clone { #[inline] fn clone(&self) -> Foo<T> { Foo { x: ::core::clone::Clone::clone(&self.x) } } } ``` Fix rust-lang#122622.
Looks sensible, ty! @bors r+ |
When `derive`ing, account for HRTB on `BareFn` fields When given ```rust trait SomeTrait { type SomeType<'a>; } #[derive(Clone)] struct Foo<T: SomeTrait> { x: for<'a> fn(T::SomeType<'a>) } ``` expand to ```rust impl<T: ::core::clone::Clone + SomeTrait> ::core::clone::Clone for Foo<T> where for<'a> T::SomeType<'a>: ::core::clone::Clone { #[inline] fn clone(&self) -> Foo<T> { Foo { x: ::core::clone::Clone::clone(&self.x) } } } ``` instead of the previous invalid ``` impl<T: ::core::clone::Clone + SomeTrait> ::core::clone::Clone for Foo<T> where T::SomeType<'a>: ::core::clone::Clone { #[inline] fn clone(&self) -> Foo<T> { Foo { x: ::core::clone::Clone::clone(&self.x) } } } ``` Fix rust-lang#122622. <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r? <reviewer name> -->
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#124731 (Add translation support by mdbook-i18n-helpers to bootstrap) - rust-lang#125168 (Match ergonomics 2024: align implementation with RFC) - rust-lang#125925 (Don't trigger `unsafe_op_in_unsafe_fn` for deprecated safe fns) - rust-lang#125966 (Implement `os_string_pathbuf_leak`) - rust-lang#125987 (When `derive`ing, account for HRTB on `BareFn` fields) - rust-lang#126045 (check_expr_struct_fields: taint context with errors if struct definit…) - rust-lang#126048 (Fix typos in cargo-specifics.md) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 6 pull requests Successful merges: - rust-lang#124731 (Add translation support by mdbook-i18n-helpers to bootstrap) - rust-lang#125168 (Match ergonomics 2024: align implementation with RFC) - rust-lang#125925 (Don't trigger `unsafe_op_in_unsafe_fn` for deprecated safe fns) - rust-lang#125987 (When `derive`ing, account for HRTB on `BareFn` fields) - rust-lang#126045 (check_expr_struct_fields: taint context with errors if struct definit…) - rust-lang#126048 (Fix typos in cargo-specifics.md) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#125987 - estebank:issue-122622, r=Nadrieril When `derive`ing, account for HRTB on `BareFn` fields When given ```rust trait SomeTrait { type SomeType<'a>; } #[derive(Clone)] struct Foo<T: SomeTrait> { x: for<'a> fn(T::SomeType<'a>) } ``` expand to ```rust impl<T: ::core::clone::Clone + SomeTrait> ::core::clone::Clone for Foo<T> where for<'a> T::SomeType<'a>: ::core::clone::Clone { #[inline] fn clone(&self) -> Foo<T> { Foo { x: ::core::clone::Clone::clone(&self.x) } } } ``` instead of the previous invalid ``` impl<T: ::core::clone::Clone + SomeTrait> ::core::clone::Clone for Foo<T> where T::SomeType<'a>: ::core::clone::Clone { #[inline] fn clone(&self) -> Foo<T> { Foo { x: ::core::clone::Clone::clone(&self.x) } } } ``` Fix rust-lang#122622. <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r? <reviewer name> -->
Why would any part of the field type result in extra bounds at all? I thought any sort of "perfect derive" was blocked on an opt-in syntax, so private implementation details like field types don't accidentally leak into public impl headers. |
We already to a little bit of looking into fields for cases like: trait Trait {
type Item;
}
#[derive(Clone)]
struct Struct<T: Trait>(T::Item); The generated |
Interesting. I don't really get why it would ever be needed for |
When given
expand to
instead of the previous invalid
Fix #122622.