Skip to content
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

Explain more clearly why fn() -> T can't be #[derive(Clone)] #114029

Merged
merged 1 commit into from
Aug 5, 2023

Conversation

Enselic
Copy link
Member

@Enselic Enselic commented Jul 24, 2023

Closes #73480

The derived impls were generated with rustc -Z unpretty=expanded main.rs and the raw output is:

struct Generate<T>(fn() -> T);
#[automatically_derived]
impl<T: ::core::marker::Copy> ::core::marker::Copy for Generate<T> { }
#[automatically_derived]
impl<T: ::core::clone::Clone> ::core::clone::Clone for Generate<T> {
    #[inline]
    fn clone(&self) -> Generate<T> {
        Generate(::core::clone::Clone::clone(&self.0))
    }
}

@rustbot
Copy link
Collaborator

rustbot commented Jul 24, 2023

r? @scottmcm

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jul 24, 2023
@rust-log-analyzer

This comment has been minimized.

/// struct Generate<T>(fn() -> T);
/// ```
///
/// the auto-derived implementation will be **invalid**, because it will become:
Copy link
Member

Choose a reason for hiding this comment

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

I don't think "invalid" is a good thing to say here, since that code compiles fine https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=63f01a475d60aa4896f193a3a887044b.

That might not be what you want, but it's not invalid, so I think this section should better elaborate what it's trying to say.

@rustbot author

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you for the feedback! I have now pushed a more fleshed out explanation. Looking forward to your new feedback. Here is how the new version looks when rendered:

Skärmbild 2023-07-30 195929

@rustbot ready

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 29, 2023
@scottmcm scottmcm added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jul 29, 2023
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 30, 2023
@scottmcm
Copy link
Member

scottmcm commented Aug 5, 2023

Thanks, it looks better now.

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Aug 5, 2023

📌 Commit c6566a8 has been approved by scottmcm

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 5, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 5, 2023
Explain more clearly why `fn() -> T` can't be `#[derive(Clone)]`

Closes rust-lang#73480

The derived impls were generated with `rustc -Z unpretty=expanded main.rs` and the raw output is:

```rust
struct Generate<T>(fn() -> T);
#[automatically_derived]
impl<T: ::core::marker::Copy> ::core::marker::Copy for Generate<T> { }
#[automatically_derived]
impl<T: ::core::clone::Clone> ::core::clone::Clone for Generate<T> {
    #[inline]
    fn clone(&self) -> Generate<T> {
        Generate(::core::clone::Clone::clone(&self.0))
    }
}
```
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 5, 2023
…iaskrgr

Rollup of 3 pull requests

Successful merges:

 - rust-lang#114029 (Explain more clearly why `fn() -> T` can't be `#[derive(Clone)]`)
 - rust-lang#114248 (Make lint missing-copy-implementations honor negative `Copy` impls)
 - rust-lang#114498 (Print tidy command with bless tidy check failure)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit bedadff into rust-lang:master Aug 5, 2023
11 checks passed
@rustbot rustbot added this to the 1.73.0 milestone Aug 5, 2023
@Enselic Enselic deleted the clone-doc branch August 17, 2023 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clone docs say it can't be derived for function pointers but it can
5 participants