Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions library/alloc/src/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,12 @@ fn rc_inner_layout_for_value_layout(layout: Layout) -> Layout {
#[rustc_diagnostic_item = "Rc"]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_insignificant_dtor]
#[diagnostic::on_move(
message = "the type `{Self}` does not implement `Copy`",
label = "this move could be avoided by cloning the original `{Self}`, which is inexpensive",
note = "consider using `Rc::clone`"
)]

pub struct Rc<
T: ?Sized,
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/moves/move-fn-self-receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn move_out(val: Container) {

let rc_foo = Rc::new(Foo);
rc_foo.use_rc_self();
rc_foo; //~ ERROR use of moved
rc_foo; //~ ERROR the type `Rc` does not implement `Copy`

let foo_add = Foo;
foo_add + Foo;
Expand Down
5 changes: 3 additions & 2 deletions tests/ui/moves/move-fn-self-receiver.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,17 @@ LL | mut_foo;
LL | ret;
| --- borrow later used here

error[E0382]: use of moved value: `rc_foo`
error[E0382]: the type `Rc` does not implement `Copy`
--> $DIR/move-fn-self-receiver.rs:55:5
|
LL | let rc_foo = Rc::new(Foo);
| ------ move occurs because `rc_foo` has type `Rc<Foo>`, which does not implement the `Copy` trait
| ------ this move could be avoided by cloning the original `Rc`, which is inexpensive
LL | rc_foo.use_rc_self();
| ------------- `rc_foo` moved due to this method call
LL | rc_foo;
| ^^^^^^ value used here after move
|
= note: consider using `Rc::clone`
note: `Foo::use_rc_self` takes ownership of the receiver `self`, which moves `rc_foo`
--> $DIR/move-fn-self-receiver.rs:16:20
|
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/moves/use_of_moved_value_clone_suggestions.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// `Rc` is not ever `Copy`, we should not suggest adding `T: Copy` constraint
fn duplicate_rc<T>(t: std::rc::Rc<T>) -> (std::rc::Rc<T>, std::rc::Rc<T>) {
(t, t) //~ ERROR use of moved value: `t`
(t, t) //~ ERROR the type `Rc` does not implement `Copy`
}

fn main() {}
5 changes: 3 additions & 2 deletions tests/ui/moves/use_of_moved_value_clone_suggestions.stderr
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
error[E0382]: use of moved value: `t`
error[E0382]: the type `Rc` does not implement `Copy`
--> $DIR/use_of_moved_value_clone_suggestions.rs:3:9
|
LL | fn duplicate_rc<T>(t: std::rc::Rc<T>) -> (std::rc::Rc<T>, std::rc::Rc<T>) {
| - move occurs because `t` has type `Rc<T>`, which does not implement the `Copy` trait
| - this move could be avoided by cloning the original `Rc`, which is inexpensive
LL | (t, t)
| - ^ value used here after move
| |
| value moved here
|
= note: consider using `Rc::clone`
help: clone the value to increment its reference count
|
LL | (t.clone(), t)
Expand Down
Loading