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::clone_double_ref to rustc #109842

Closed

Conversation

fee1-dead
Copy link
Member

@fee1-dead fee1-dead commented Apr 1, 2023

This closes #109451, but is only part 1 for fixing #109429. The second part would be to run a selection of lints even after borrowck had errors.

// Avoid overwhelming user with errors if borrow checking failed.
// I'm not sure how helpful this is, to be honest, but it avoids a
// lot of annoying errors in the ui tests (basically,
// lint warnings and so on -- kindck used to do this abort, but
// kindck is gone now). -nmatsakis
if let Some(reported) = sess.has_errors() {
return Err(reported);
}

Note: both suggestions are pretty bad.. Why don't we just suggest dereferencing?


For Clippy:

changelog: Moves: Uplifted clippy::clone_double_ref into rustc

@rustbot
Copy link
Collaborator

rustbot commented Apr 1, 2023

r? @wesleywiser

(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. labels Apr 1, 2023
@rustbot
Copy link
Collaborator

rustbot commented Apr 1, 2023

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@fee1-dead
Copy link
Member Author

Turns out that noop_method_call is a thing already. This should probably be merged to that.

@fee1-dead fee1-dead 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 Apr 1, 2023
Copy link
Member

@flip1995 flip1995 left a comment

Choose a reason for hiding this comment

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

Clippy specific review.

src/tools/clippy/tests/ui/deprecated.rs Outdated Show resolved Hide resolved
src/tools/clippy/tests/ui/unnecessary_clone.stderr Outdated Show resolved Hide resolved
@rustbot
Copy link
Collaborator

rustbot commented Apr 7, 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

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Apr 8, 2023
@rust-log-analyzer

This comment has been minimized.

@fee1-dead fee1-dead force-pushed the uplift-clone-2x-ref branch 3 times, most recently from ebab009 to 655c9ea Compare April 8, 2023 08:22
@bors
Copy link
Contributor

bors commented Apr 10, 2023

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

@fee1-dead
Copy link
Member Author

@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 Apr 14, 2023
@@ -31,18 +31,48 @@ declare_lint! {
/// calling `clone` on a `&T` where `T` does not implement clone, actually doesn't do anything
/// as references are copy. This lint detects these calls and warns the user about them.
pub NOOP_METHOD_CALL,
Allow,
Warn,
Copy link
Member

@compiler-errors compiler-errors Apr 28, 2023

Choose a reason for hiding this comment

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

I feel like this change and the associated changes to lib/compiler should be done in a separate PR.

Or at least the PR title and description need to be updated to reflect that this is also bumping NOOP_METHOD_CALL to warn.

But I would prefer the first option. Just uplifting clone_double_ref seems to me very easy to r+, having to approve both is a bit harder to disentangle (esp in case we need to unland one in the future, e.g. due to lots of false positives in some yet undiscovered case -- which I have no reason to believe may happen, but stranger things have happened before).

/// reference, instead of cloning the inner type which should be what was intended.
pub SUSPICIOUS_DOUBLE_REF_OP,
Warn,
"using `clone` on `&&T`"
Copy link
Member

@compiler-errors compiler-errors Apr 28, 2023

Choose a reason for hiding this comment

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

This lint isn't Clone specific as implemented below? Wording, etc. should probably be adjusted?

@@ -1,6 +1,7 @@
// Check that cyclic glob imports are allowed with underscore imports

// check-pass
#![allow(noop_method_call)]
Copy link
Member

Choose a reason for hiding this comment

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

I would actually prefer if we added the WARNs to this UI test and others.

|
LL | let non_deref_type_deref: &PlainType<u32> = non_deref_type.deref();
| ^^^^^^^^ unnecessary method call
|
= note: the type `&PlainType<u32>` which `deref` is being called on is the same as the type returned from `deref`, so the method call does not do anything and can be removed

warning: using `.deref()` on a double reference, which copies `&PlainType<u32>` instead of dereferencing the inner type
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
warning: using `.deref()` on a double reference, which copies `&PlainType<u32>` instead of dereferencing the inner type
warning: using `.deref()` on a double reference, which returns `&PlainType<u32>` instead of dereferencing the inner type

@compiler-errors compiler-errors self-assigned this Apr 28, 2023
@fee1-dead fee1-dead marked this pull request as draft April 28, 2023 17:19
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Apr 30, 2023
…=compiler-errors

uplift `clippy::clone_double_ref` as `suspicious_double_ref_op`

Split from rust-lang#109842.

r? `@compiler-errors`
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request May 2, 2023
…=compiler-errors

uplift `clippy::clone_double_ref` as `suspicious_double_ref_op`

Split from rust-lang#109842.

r? ``@compiler-errors``
@bors
Copy link
Contributor

bors commented May 2, 2023

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

@compiler-errors compiler-errors 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 May 2, 2023
flip1995 pushed a commit to flip1995/rust that referenced this pull request May 5, 2023
…=compiler-errors

uplift `clippy::clone_double_ref` as `suspicious_double_ref_op`

Split from rust-lang#109842.

r? ``@compiler-errors``
@fee1-dead fee1-dead closed this May 24, 2023
@fee1-dead fee1-dead deleted the uplift-clone-2x-ref branch May 24, 2023 15:19
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 S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) 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.

Uplift clippy::clone_double_ref to rustc
7 participants