-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Suggest using clone when we have &T and T implemented Clone #106497
Conversation
(rustbot has picked a reviewer for you, use r? to override) |
00a4067
to
401bb13
Compare
compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
Show resolved
Hide resolved
r? @estebank (petrochenkov is taking a pause from reviewing) |
There was a problem hiding this 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_trait_selection/src/traits/error_reporting/suggestions.rs
Outdated
Show resolved
Hide resolved
compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
Outdated
Show resolved
Hide resolved
compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
Outdated
Show resolved
Hide resolved
let clone_bound = generics.bounds_for_param(generic_param.def_id) | ||
.flat_map(|bp| bp.bounds) | ||
.any(|bound| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatting here is funny..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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 :-/
compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
Outdated
Show resolved
Hide resolved
&& self | ||
.infcx | ||
.type_implements_trait( | ||
clone_trait_def, | ||
[self.tcx.erase_regions(expected_ty)], | ||
self.param_env | ||
) | ||
.must_apply_modulo_regions() | ||
{ |
There was a problem hiding this comment.
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.
compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
Outdated
Show resolved
Hide resolved
Co-authored-by: Esteban Kuber <estebank@users.noreply.github.com>
☔ The latest upstream changes (presumably #106519) made this pull request unmergeable. Please resolve the merge conflicts. |
67bb77a
to
00ed01d
Compare
This comment has been minimized.
This comment has been minimized.
586089d
to
6082729
Compare
This comment has been minimized.
This comment has been minimized.
The only thing missing is a check for @bors r+ |
@@ -0,0 +1,20 @@ | |||
#[derive(Clone)] |
There was a problem hiding this comment.
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 :)
…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
Fixes #106443