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

Make missing_copy_implementations more cautious #102406

Merged
merged 3 commits into from
Dec 10, 2022
Merged

Make missing_copy_implementations more cautious #102406

merged 3 commits into from
Dec 10, 2022

Conversation

mejrs
Copy link
Contributor

@mejrs mejrs commented Sep 28, 2022

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Sep 28, 2022
@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @wesleywiser (or someone else) soon.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 28, 2022
Comment on lines +754 to +762
// If the type contains a raw pointer, it may represent something like a handle,
// and recommending Copy might be a bad idea.
for field in def.all_fields() {
let did = field.did;
if cx.tcx.type_of(did).is_unsafe_ptr() {
return;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

While I think the rationale makes sense, it seems very inconsistent to me for pointers to actually be Copy but then we don't treat them as Copy in this lint. I would prefer that we don't make this change without a larger consensus that this is the right approach to take.

Copy link
Contributor

Choose a reason for hiding this comment

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

Pointers themselves are just locations in memory with no semantics attached. However, the moment a user puts a pointer into their own type, they can add additional semantics, e.g., that the type uniquely borrows the data behind the pointer. For that reason, the decision to make a type with a pointer Copy is probably best made on a case-by-case basis, IMHO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We shouldn't recommend implementing Copy if might have certain other semantics. I think it's a reasonable assumption that when raw pointers are involved that is the case.

Of course that can never be prevented, for example some kind of Token ZST not being Copy could be very intentional, but that is impossible to determine.

I'm happy to remove it if you disagree.

Comment on lines +778 to +785
// Default value of clippy::trivially_copy_pass_by_ref
const MAX_SIZE: u64 = 256;

if let Some(size) = cx.layout_of(ty).ok().map(|l| l.size.bytes()) {
if size > MAX_SIZE {
return;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

I'm not quite sure how I feel about this. It seems very similar to the points raised in the discussion of #83518 in that we may want to allow users to control this value, we may want different values on different targets, etc.

However, since this controls silencing the lint instead of triggering the lint, I don't have an objection to landing this change.

@wesleywiser
Copy link
Member

Thanks for the discussion @LegionMammal978 and @mejrs! On further reflection, I agree with your POV so I'm ok with landing this.

@bors r+

@bors
Copy link
Contributor

bors commented Nov 18, 2022

📌 Commit 1ccc2ab has been approved by wesleywiser

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 Nov 18, 2022
Manishearth added a commit to Manishearth/rust that referenced this pull request Nov 18, 2022
Make `missing_copy_implementations` more cautious

- Fixes rust-lang#98348
- Also makes the lint not fire on large types and types containing raw pointers. Thoughts?
@Manishearth
Copy link
Member

@bors r-

#104585 (comment)

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 18, 2022
@mejrs
Copy link
Contributor Author

mejrs commented Nov 19, 2022

@rustbot ready

@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 Nov 19, 2022
@bors
Copy link
Contributor

bors commented Nov 27, 2022

☔ The latest upstream changes (presumably #103917) made this pull request unmergeable. Please resolve the merge conflicts.

@wesleywiser
Copy link
Member

This just needs a rebase and then it's good to go!

@mejrs
Copy link
Contributor Author

mejrs commented Nov 29, 2022

@rustbot ready

@jyn514
Copy link
Member

jyn514 commented Dec 8, 2022

@bors r=wesleywiser

@bors
Copy link
Contributor

bors commented Dec 8, 2022

📌 Commit 34277fc has been approved by wesleywiser

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 Dec 8, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Dec 9, 2022
Make `missing_copy_implementations` more cautious

- Fixes rust-lang#98348
- Also makes the lint not fire on large types and types containing raw pointers. Thoughts?
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 10, 2022
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#102406 (Make `missing_copy_implementations` more cautious)
 - rust-lang#105265 (Add `rustc_on_unimplemented` to `Sum` and `Product` trait.)
 - rust-lang#105385 (Skip test on s390x as LLD does not support the platform)
 - rust-lang#105453 (Make `VecDeque::from_iter` O(1) from `vec(_deque)::IntoIter`)
 - rust-lang#105468 (Mangle "main" as "__main_void" on wasm32-wasi)
 - rust-lang#105480 (rustdoc: remove no-op mobile CSS `#sidebar-toggle { text-align }`)
 - rust-lang#105489 (Fix typo in apple_base.rs)
 - rust-lang#105504 (rustdoc: make stability badge CSS more consistent)
 - rust-lang#105506 (Tweak `rustc_must_implement_one_of` diagnostic output)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 4fae589 into rust-lang:master Dec 10, 2022
@rustbot rustbot added this to the 1.68.0 milestone Dec 10, 2022
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-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

missing_copy_implementations probably shouldn't fire if the type implements Iterator
8 participants