Repository navigation
Suggest cloning Arc/Rc #104232
Description
Activity
- addedA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
on Nov 10, 2022 @rustbot claim
@chenyukang make sure to account for
Rcas well! :)Reacted by YukangThis is covered by #103908, could be closed now.
@chenyukang oh! Great to hear, sorry for making you waste your time :-/
There are a couple of improvements I would like to make on top of that merged PR though, which you might be interested in doing: I would like to customize the message depending on the type size (if smaller than lets say a KB do not talk about perf cost), whether the type implements
Drop(to mention that the drop guard might change what is being done) and special caseArcandRcand tell people to clone without any equivocation. We might want to use this ticket to track that work?Reacted by Ibraheem AhmedTriage: The first case is now handled, but the second case isn't.
- addedD-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.
on Jan 13, 2023 - added a commit that references this issue
on May 1, 2024 Current output:
error[E0382]: use of moved value: `x` --> src/main.rs:5:9 | 3 | let x = Arc::new(1); | - move occurs because `x` has type `Arc<usize>`, which does not implement the `Copy` trait 4 | foo(x); | - value moved here 5 | bar(x); | ^ value used here after move | note: consider changing this parameter type in function `foo` to borrow instead if owning the value isn't necessary --> src/main.rs:8:11 | 8 | fn foo(_: Arc<usize>) {} | --- ^^^^^^^^^^ this parameter takes ownership of the value | | | in this function help: clone the value to increment its reference count | 4 | foo(x.clone()); | ++++++++error[E0382]: use of moved value: `x` --> src/main.rs:5:28 | 3 | let x = Arc::new(1); | - move occurs because `x` has type `Arc<i32>`, which does not implement the `Copy` trait 4 | for _ in 0..4 { | ------------- inside of this loop 5 | std::thread::spawn(move || { | ^^^^^^^ value moved into closure here, in previous iteration of loop 6 | println!("{}", x); | - use occurs due to use in closureAfter #124595, the output will be
error[E0382]: use of moved value: `qwer` --> f203.rs:5:28 | 3 | let qwer = Arc::new(1); | ---- move occurs because `qwer` has type `Arc<i32>`, which does not implement the `Copy` trait 4 | for _ in 0..4 { | ------------- inside of this loop 5 | std::thread::spawn(move || { | ^^^^^^^ value moved into closure here, in previous iteration of loop 6 | println!("{}", qwer); | ---- use occurs due to use in closure | help: clone the value before moving it into the closure | 5 ~ let value = qwer.clone(); 6 ~ std::thread::spawn(move || { 7 ~ println!("{}", value); |- added 2 commits that reference this issue
on May 1, 2024 - added a commit that references this issue
on Jun 24, 2025 - added a commit that references this issue
on Jun 26, 2025 - added 2 commits that reference this issue
on Jun 26, 2025 - added a commit that references this issue
on Jun 26, 2025 - added a commit that references this issue
on Jun 27, 2025
The help message could mention that
ArcimplementsClone. We don't usually suggest cloning values in diagnostics, but forArc/Rcwe probably should.Another common case (this one is probably harder to suggest a fix for):