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

Suggest using clone when we have &T and T implemented Clone #106497

Merged
merged 5 commits into from
Jan 9, 2023

Conversation

chenyukang
Copy link
Member

Fixes #106443

@rustbot
Copy link
Collaborator

rustbot commented Jan 5, 2023

r? @petrochenkov

(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 Jan 5, 2023
@estebank
Copy link
Contributor

estebank commented Jan 5, 2023

r? @estebank (petrochenkov is taking a pause from reviewing)

@rustbot rustbot assigned estebank and unassigned petrochenkov Jan 5, 2023
Copy link
Contributor

@estebank estebank left a comment

Choose a reason for hiding this comment

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

I need to fully review, publishing to avoid forgetting about these

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs Outdated Show resolved Hide resolved
compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs Outdated Show resolved Hide resolved
Comment on lines 1076 to 1078
let clone_bound = generics.bounds_for_param(generic_param.def_id)
.flat_map(|bp| bp.bounds)
.any(|bound| {
Copy link
Member

Choose a reason for hiding this comment

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

formatting here is funny..

Copy link
Member Author

Choose a reason for hiding this comment

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

it's werid, this is how it's look in my VsCode:

image

And I run x fmt . before push, won't formatter get style right for this?

Copy link
Contributor

Choose a reason for hiding this comment

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

the formatter is skipping expressions inside of let chains :-/

Comment on lines +1027 to +1035
&& self
.infcx
.type_implements_trait(
clone_trait_def,
[self.tcx.erase_regions(expected_ty)],
self.param_env
)
.must_apply_modulo_regions()
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at this I'm thinking we should also check if the type implements Drop, and if so tweak the wording to be less confident, but this can be addressed in a later PR.

@bors
Copy link
Contributor

bors commented Jan 7, 2023

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

@chenyukang chenyukang force-pushed the yukang/fix-106443-sugg-clone branch 2 times, most recently from 67bb77a to 00ed01d Compare January 8, 2023 08:23
@rust-log-analyzer

This comment has been minimized.

@chenyukang chenyukang force-pushed the yukang/fix-106443-sugg-clone branch 2 times, most recently from 586089d to 6082729 Compare January 8, 2023 12:29
@rust-log-analyzer

This comment has been minimized.

@estebank
Copy link
Contributor

estebank commented Jan 8, 2023

The only thing missing is a check for T: Drop to tweak the wording, but we can do that in a follow up PR.

@bors r+

@bors
Copy link
Contributor

bors commented Jan 8, 2023

📌 Commit 0e570e5 has been approved by estebank

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 Jan 8, 2023
@@ -0,0 +1,20 @@
#[derive(Clone)]
Copy link
Contributor

Choose a reason for hiding this comment

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

This test can be marked as // run-rustfix, because after applying the suggestions the code will compile :)

bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 9, 2023
…mpiler-errors

Rollup of 8 pull requests

Successful merges:

 - rust-lang#104163 (Don't derive Debug for `OnceWith` & `RepeatWith`)
 - rust-lang#106131 (Mention "signature" rather than "fn pointer" when impl/trait methods are incompatible)
 - rust-lang#106363 (Structured suggestion for `&mut dyn Iterator` when possible)
 - rust-lang#106497 (Suggest using clone when we have &T and T implemented Clone)
 - rust-lang#106584 (Document that `Vec::from_raw_parts[_in]` must be given a pointer from the correct allocator.)
 - rust-lang#106600 (Suppress type errors that come from private fields)
 - rust-lang#106602 (Add goml scripts to tidy checks)
 - rust-lang#106606 (Do not emit structured suggestion for turbofish with wrong span)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit eefc44b into rust-lang:master Jan 9, 2023
@rustbot rustbot added this to the 1.68.0 milestone Jan 9, 2023
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.

Suggest .clone() when we have &T, T was expected and T: Clone
7 participants