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

Uplift clippy::{drop,forget}_{ref,copy} lints #109732

Merged
merged 16 commits into from
May 12, 2023

Conversation

Urgau
Copy link
Member

@Urgau Urgau commented Mar 29, 2023

This PR aims at uplifting the clippy::drop_ref, clippy::drop_copy, clippy::forget_ref and clippy::forget_copy lints.

Those lints are/were declared in the correctness category of clippy because they lint on useless and most probably is not what the developer wanted.

drop_ref and forget_ref

ℹ️ The lints have been renamed to dropping_copy_types and forgetting_copy_types in #111756

The drop_ref and forget_ref lint checks for calls to std::mem::drop or std::mem::forget with a reference instead of an owned value.

Example

let mut lock_guard = mutex.lock();
std::mem::drop(&lock_guard) // Should have been drop(lock_guard), mutex
// still locked
operation_that_requires_mutex_to_be_unlocked();

Explanation

Calling drop or forget on a reference will only drop the reference itself, which is a no-op. It will not call the drop or forget method on the underlying referenced value, which is likely what was intended.

drop_copy and forget_copy

ℹ️ The lints have been renamed to dropping_references and forgetting_references in #111756

The drop_copy and forget_copy lint checks for calls to std::mem::forget or std::mem::drop with a value that derives the Copy trait.

Example

let x: i32 = 42; // i32 implements Copy
std::mem::forget(x) // A copy of x is passed to the function, leaving the
                    // original unaffected

Explanation

Calling std::mem::forget does nothing for types that implement Copy since the value will be copied and moved into the function on invocation.


Followed the instructions for uplift a clippy describe here: #99696 (review)

cc @m-ou-se (as T-libs-api leader because the uplifting was discussed in a recent meeting)

@rustbot
Copy link
Collaborator

rustbot commented Mar 29, 2023

r? @TaKO8Ki

(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-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 29, 2023
@rustbot
Copy link
Collaborator

rustbot commented Mar 29, 2023

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@rust-log-analyzer

This comment has been minimized.

@Urgau Urgau force-pushed the uplift_drop_forget_ref_lints branch from 026278d to 5c6fed5 Compare March 29, 2023 17:38
@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@Noratrieb Noratrieb left a comment

Choose a reason for hiding this comment

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

some cases in rustc, fun (can't wait for clippy to finally work on rustc^^)

compiler/rustc_middle/src/mir/visit.rs Show resolved Hide resolved
@Urgau Urgau force-pushed the uplift_drop_forget_ref_lints branch from 5c6fed5 to e87ceee Compare March 29, 2023 20:54
@rust-log-analyzer

This comment has been minimized.

@Urgau Urgau force-pushed the uplift_drop_forget_ref_lints branch 4 times, most recently from d7ccffc to 88a9561 Compare March 30, 2023 08:33
@rust-log-analyzer

This comment has been minimized.

@Urgau Urgau force-pushed the uplift_drop_forget_ref_lints branch 2 times, most recently from 8183b99 to c3edde2 Compare March 30, 2023 09:55
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 2, 2023
@Urgau Urgau force-pushed the uplift_drop_forget_ref_lints branch from c3edde2 to fad236f Compare April 2, 2023 13:38
@Urgau
Copy link
Member Author

Urgau commented Apr 4, 2023

Nominating for T-lang approval, as it seems to be the norm.

@rustbot label: +I-lang-nominated

@rustbot rustbot added the I-lang-nominated Nominated for discussion during a lang team meeting. label Apr 4, 2023
@nikomatsakis
Copy link
Contributor

@rustbot labels -I-lang-nominated

@rfcbot fcp merge

We discussed this our @rust-lang/lang meeting and we agree that, when this occurs, it is very likely to be a bug or misunderstanding, which is our usual criteria for uplift.

@rustbot rustbot removed the I-lang-nominated Nominated for discussion during a lang team meeting. label Apr 4, 2023
@GuillaumeGomez
Copy link
Member

@bors r=davidtwco

@bors
Copy link
Contributor

bors commented May 11, 2023

📌 Commit f5aede9 has been approved by davidtwco

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented May 11, 2023

🌲 The tree is currently closed for pull requests below priority 100. This pull request will be tested once the tree is reopened.

@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 May 11, 2023
@bors
Copy link
Contributor

bors commented May 12, 2023

⌛ Testing commit f5aede9 with merge 077fc26...

@bors
Copy link
Contributor

bors commented May 12, 2023

☀️ Test successful - checks-actions
Approved by: davidtwco
Pushing 077fc26 to master...

1 similar comment
@bors
Copy link
Contributor

bors commented May 12, 2023

☀️ Test successful - checks-actions
Approved by: davidtwco
Pushing 077fc26 to master...

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (077fc26): comparison URL.

Overall result: ❌✅ regressions and improvements - ACTION NEEDED

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.5% [0.4%, 0.8%] 5
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.4% [-1.9%, -1.0%] 4
All ❌✅ (primary) 0.5% [0.4%, 0.8%] 5

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
1.2% [0.7%, 1.6%] 2
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.6% [-2.9%, -2.4%] 2
All ❌✅ (primary) 1.2% [0.7%, 1.6%] 2

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 659.774s -> 659.596s (-0.03%)

@rustbot rustbot added the perf-regression Performance regression. label May 12, 2023
@Urgau Urgau deleted the uplift_drop_forget_ref_lints branch May 13, 2023 09:26
bors added a commit to rust-lang/cargo that referenced this pull request May 13, 2023
Remove useless drop of copy type

### What does this PR try to resolve?

This PR aims to remove useless drop of copy type to clear warnings that reported after rust-lang/rust#109732

```
warning: calls to `std::mem::drop` with a value that implements `Copy` does nothing
    --> src/cargo/core/compiler/job_queue/mod.rs:1048:21
     |
1048 |                        drop(write!(
     |  ______________________^____-
     | | _____________________|
     | ||
1049 | ||                         message,
1050 | ||                         " (run `{command} --{args}` to apply {suggestions})"
1051 | ||                     ))
     | ||_____________________-^
     | |______________________|
     |                        argument has type `Result<(), std::fmt::Error>`
     |
     = note: use `let _ = ...` to ignore the expression or result
     = note: `#[warn(drop_copy)]` on by default
```

### How should we test and review this PR?

```bash
cargo build && cargo test # without any warnings
```

### Additional information

None
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request May 22, 2023
…lints, r=fee1-dead

Rename `{drop,forget}_{copy,ref}` lints to more consistent naming

This PR renames previous uplifted lints in rust-lang#109732 to more consistent naming.

I followed the renaming done [here](rust-lang#53224) and also advocated in this [clippy issue](rust-lang/rust-clippy#2845):
   - `drop_copy` to `dropping_copy_types`
   - `forget_copy` to `forgetting_copy_types`
   - `drop_ref` to `dropping_references`
   - `forget_ref` to `forgetting_references`
oli-obk pushed a commit to oli-obk/miri that referenced this pull request May 23, 2023
…fee1-dead

Rename `{drop,forget}_{copy,ref}` lints to more consistent naming

This PR renames previous uplifted lints in rust-lang/rust#109732 to more consistent naming.

I followed the renaming done [here](rust-lang/rust#53224) and also advocated in this [clippy issue](rust-lang/rust-clippy#2845):
   - `drop_copy` to `dropping_copy_types`
   - `forget_copy` to `forgetting_copy_types`
   - `drop_ref` to `dropping_references`
   - `forget_ref` to `forgetting_references`
thomcc pushed a commit to tcdi/postgrestd that referenced this pull request Jul 18, 2023
Followed up of d36e390d8176babedcf326581959958d447170cd
See rust-lang/rust#109732 (comment)
for more details.

Co-authored-by: Jethro Beekman <jethro@fortanix.com>
thomcc pushed a commit to tcdi/postgrestd that referenced this pull request Jul 18, 2023
…fee1-dead

Rename `{drop,forget}_{copy,ref}` lints to more consistent naming

This PR renames previous uplifted lints in rust-lang/rust#109732 to more consistent naming.

I followed the renaming done [here](rust-lang/rust#53224) and also advocated in this [clippy issue](rust-lang/rust-clippy#2845):
   - `drop_copy` to `dropping_copy_types`
   - `forget_copy` to `forgetting_copy_types`
   - `drop_ref` to `dropping_references`
   - `forget_ref` to `forgetting_references`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-testsuite Area: The testsuite used to check the correctness of rustc disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.