Skip to content

Commit 4c5de71

Browse files
committed
Bless tests
1 parent 9b7f17f commit 4c5de71

19 files changed

+294
-6
lines changed

src/test/ui/moves/issue-46099-move-in-macro.stderr

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ LL | let b = Box::new(true);
55
| - move occurs because `b` has type `Box<bool>`, which does not implement the `Copy` trait
66
LL | test!({b});
77
| ^ value used here after move
8+
|
9+
help: consider cloning `b`
10+
|
11+
LL | test!({b.clone()});
12+
| ++++++++
813

914
error: aborting due to previous error
1015

src/test/ui/moves/move-fn-self-receiver.stderr

+17
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ note: this function takes ownership of the receiver `self`, which moves `val.0`
1212
LL | fn into_iter(self) -> Self::IntoIter;
1313
| ^^^^
1414
= note: move occurs because `val.0` has type `Vec<bool>`, which does not implement the `Copy` trait
15+
help: consider cloning `val.0`
16+
|
17+
LL | val.0.clone().into_iter().next();
18+
| ++++++++
1519

1620
error[E0382]: use of moved value: `foo`
1721
--> $DIR/move-fn-self-receiver.rs:34:5
@@ -96,6 +100,10 @@ note: this function takes ownership of the receiver `self`, which moves `rc_foo`
96100
|
97101
LL | fn use_rc_self(self: Rc<Self>) {}
98102
| ^^^^
103+
help: consider cloning `rc_foo`
104+
|
105+
LL | rc_foo.clone().use_rc_self();
106+
| ++++++++
99107

100108
error[E0382]: use of moved value: `foo_add`
101109
--> $DIR/move-fn-self-receiver.rs:59:5
@@ -127,6 +135,10 @@ help: consider iterating over a slice of the `Vec<bool>`'s content to avoid movi
127135
|
128136
LL | for _val in &implicit_into_iter {}
129137
| +
138+
help: consider cloning `implicit_into_iter`
139+
|
140+
LL | for _val in implicit_into_iter.clone() {}
141+
| ++++++++
130142

131143
error[E0382]: use of moved value: `explicit_into_iter`
132144
--> $DIR/move-fn-self-receiver.rs:67:5
@@ -137,6 +149,11 @@ LL | for _val in explicit_into_iter.into_iter() {}
137149
| ----------- `explicit_into_iter` moved due to this method call
138150
LL | explicit_into_iter;
139151
| ^^^^^^^^^^^^^^^^^^ value used here after move
152+
|
153+
help: consider cloning `explicit_into_iter`
154+
|
155+
LL | for _val in explicit_into_iter.clone().into_iter() {}
156+
| ++++++++
140157

141158
error[E0382]: use of moved value: `container`
142159
--> $DIR/move-fn-self-receiver.rs:71:5

src/test/ui/moves/move-guard-same-consts.stderr

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ LL | (1, 2) if take(x) => (),
88
| - value moved here
99
LL | (1, 2) if take(x) => (),
1010
| ^ value used here after move
11+
|
12+
help: consider cloning `x`
13+
|
14+
LL | (1, 2) if take(x.clone()) => (),
15+
| ++++++++
1116

1217
error: aborting due to previous error
1318

src/test/ui/moves/move-in-guard-1.stderr

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ LL | (1, _) if take(x) => (),
88
| - value moved here
99
LL | (_, 2) if take(x) => (),
1010
| ^ value used here after move
11+
|
12+
help: consider cloning `x`
13+
|
14+
LL | (1, _) if take(x.clone()) => (),
15+
| ++++++++
1116

1217
error: aborting due to previous error
1318

src/test/ui/moves/move-in-guard-2.stderr

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ LL | let x: Box<_> = Box::new(1);
66
...
77
LL | (_, 2) if take(x) => (),
88
| ^ value used here after move
9+
|
10+
help: consider cloning `x`
11+
|
12+
LL | (_, 2) if take(x.clone()) => (),
13+
| ++++++++
914

1015
error: aborting due to previous error
1116

src/test/ui/moves/move-out-of-tuple-field.stderr

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ LL | let z = x.0;
77
| ^^^ value used here after move
88
|
99
= note: move occurs because `x.0` has type `Box<i32>`, which does not implement the `Copy` trait
10+
help: consider cloning `x.0`
11+
|
12+
LL | let y = x.0.clone();
13+
| ++++++++
1014

1115
error[E0382]: use of moved value: `x.0`
1216
--> $DIR/move-out-of-tuple-field.rs:12:13
@@ -17,6 +21,10 @@ LL | let z = x.0;
1721
| ^^^ value used here after move
1822
|
1923
= note: move occurs because `x.0` has type `Box<isize>`, which does not implement the `Copy` trait
24+
help: consider cloning `x.0`
25+
|
26+
LL | let y = x.0.clone();
27+
| ++++++++
2028

2129
error: aborting due to 2 previous errors
2230

src/test/ui/moves/moves-based-on-type-access-to-field.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ note: this function takes ownership of the receiver `self`, which moves `x`
1313
|
1414
LL | fn into_iter(self) -> Self::IntoIter;
1515
| ^^^^
16+
help: consider cloning `x`
17+
|
18+
LL | consume(x.clone().into_iter().next().unwrap());
19+
| ++++++++
1620

1721
error: aborting due to previous error
1822

src/test/ui/moves/moves-based-on-type-capture-clause-bad.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ LL | println!("{}", x);
1212
| ^ value borrowed here after move
1313
|
1414
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
15+
help: consider cloning `x`
16+
|
17+
LL | println!("{}", x.clone());
18+
| ++++++++
1519

1620
error: aborting due to previous error
1721

src/test/ui/moves/moves-based-on-type-distribute-copy-over-paren.stderr

+10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ LL | let _y = Foo { f:x };
99
LL |
1010
LL | touch(&x);
1111
| ^^ value borrowed here after move
12+
|
13+
help: consider cloning `x`
14+
|
15+
LL | let _y = Foo { f:x.clone() };
16+
| ++++++++
1217

1318
error[E0382]: borrow of moved value: `x`
1419
--> $DIR/moves-based-on-type-distribute-copy-over-paren.rs:21:11
@@ -21,6 +26,11 @@ LL | let _y = Foo { f:(((x))) };
2126
LL |
2227
LL | touch(&x);
2328
| ^^ value borrowed here after move
29+
|
30+
help: consider cloning `x`
31+
|
32+
LL | let _y = Foo { f:(((x))).clone() };
33+
| ++++++++
2434

2535
error: aborting due to 2 previous errors
2636

src/test/ui/moves/moves-based-on-type-exprs.stderr

+53
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ LL | let _y = Foo { f:x };
77
| - value moved here
88
LL | touch(&x);
99
| ^^ value borrowed here after move
10+
|
11+
help: consider cloning `x`
12+
|
13+
LL | let _y = Foo { f:x.clone() };
14+
| ++++++++
1015

1116
error[E0382]: borrow of moved value: `x`
1217
--> $DIR/moves-based-on-type-exprs.rs:18:11
@@ -17,6 +22,11 @@ LL | let _y = (x, 3);
1722
| - value moved here
1823
LL | touch(&x);
1924
| ^^ value borrowed here after move
25+
|
26+
help: consider cloning `x`
27+
|
28+
LL | let _y = (x.clone(), 3);
29+
| ++++++++
2030

2131
error[E0382]: borrow of moved value: `x`
2232
--> $DIR/moves-based-on-type-exprs.rs:35:11
@@ -29,6 +39,11 @@ LL | x
2939
...
3040
LL | touch(&x);
3141
| ^^ value borrowed here after move
42+
|
43+
help: consider cloning `x`
44+
|
45+
LL | x.clone()
46+
| ++++++++
3247

3348
error[E0382]: borrow of moved value: `y`
3449
--> $DIR/moves-based-on-type-exprs.rs:36:11
@@ -41,6 +56,11 @@ LL | y
4156
...
4257
LL | touch(&y);
4358
| ^^ value borrowed here after move
59+
|
60+
help: consider cloning `y`
61+
|
62+
LL | y.clone()
63+
| ++++++++
4464

4565
error[E0382]: borrow of moved value: `x`
4666
--> $DIR/moves-based-on-type-exprs.rs:46:11
@@ -53,6 +73,11 @@ LL | true => x,
5373
...
5474
LL | touch(&x);
5575
| ^^ value borrowed here after move
76+
|
77+
help: consider cloning `x`
78+
|
79+
LL | true => x.clone(),
80+
| ++++++++
5681

5782
error[E0382]: borrow of moved value: `y`
5883
--> $DIR/moves-based-on-type-exprs.rs:47:11
@@ -65,6 +90,11 @@ LL | false => y
6590
...
6691
LL | touch(&y);
6792
| ^^ value borrowed here after move
93+
|
94+
help: consider cloning `y`
95+
|
96+
LL | false => y.clone()
97+
| ++++++++
6898

6999
error[E0382]: borrow of moved value: `x`
70100
--> $DIR/moves-based-on-type-exprs.rs:58:11
@@ -77,6 +107,11 @@ LL | _ if guard(x) => 10,
77107
...
78108
LL | touch(&x);
79109
| ^^ value borrowed here after move
110+
|
111+
help: consider cloning `x`
112+
|
113+
LL | _ if guard(x.clone()) => 10,
114+
| ++++++++
80115

81116
error[E0382]: borrow of moved value: `x`
82117
--> $DIR/moves-based-on-type-exprs.rs:65:11
@@ -87,6 +122,11 @@ LL | let _y = [x];
87122
| - value moved here
88123
LL | touch(&x);
89124
| ^^ value borrowed here after move
125+
|
126+
help: consider cloning `x`
127+
|
128+
LL | let _y = [x.clone()];
129+
| ++++++++
90130

91131
error[E0382]: borrow of moved value: `x`
92132
--> $DIR/moves-based-on-type-exprs.rs:71:11
@@ -97,6 +137,11 @@ LL | let _y = vec![x];
97137
| - value moved here
98138
LL | touch(&x);
99139
| ^^ value borrowed here after move
140+
|
141+
help: consider cloning `x`
142+
|
143+
LL | let _y = vec![x.clone()];
144+
| ++++++++
100145

101146
error[E0382]: borrow of moved value: `x`
102147
--> $DIR/moves-based-on-type-exprs.rs:77:11
@@ -113,6 +158,10 @@ note: this function takes ownership of the receiver `self`, which moves `x`
113158
|
114159
LL | fn into_iter(self) -> Self::IntoIter;
115160
| ^^^^
161+
help: consider cloning `x`
162+
|
163+
LL | let _y = x.clone().into_iter().next().unwrap();
164+
| ++++++++
116165

117166
error[E0382]: borrow of moved value: `x`
118167
--> $DIR/moves-based-on-type-exprs.rs:83:11
@@ -129,6 +178,10 @@ note: this function takes ownership of the receiver `self`, which moves `x`
129178
|
130179
LL | fn into_iter(self) -> Self::IntoIter;
131180
| ^^^^
181+
help: consider cloning `x`
182+
|
183+
LL | let _y = [x.clone().into_iter().next().unwrap(); 1];
184+
| ++++++++
132185

133186
error: aborting due to 11 previous errors
134187

src/test/ui/moves/moves-based-on-type-match-bindings.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ LL | touch(&x);
88
| ^^ value borrowed here after partial move
99
|
1010
= note: partial move occurs because `x.f` has type `String`, which does not implement the `Copy` trait
11+
help: consider cloning `x.f`
12+
|
13+
LL | Foo {f.clone()} => {}
14+
| ++++++++
1115

1216
error: aborting due to previous error
1317

src/test/ui/moves/moves-based-on-type-tuple.stderr

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ LL | Box::new((x, x))
88
| - ^ value used here after move
99
| |
1010
| value moved here
11+
|
12+
help: consider cloning `x`
13+
|
14+
LL | Box::new((x.clone(), x))
15+
| ++++++++
1116

1217
error: aborting due to previous error
1318

src/test/ui/moves/moves-sru-moved-field.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ LL | let _c = Foo {noncopyable: h, ..f};
77
| ^^^^^^^^^^^^^^^^^^^^^^^^^ value used here after move
88
|
99
= note: move occurs because `f.moved` has type `Box<isize>`, which does not implement the `Copy` trait
10+
help: consider cloning `f.moved`
11+
|
12+
LL | let _b = Foo {noncopyable: g, ..f}.clone();
13+
| ++++++++
1014

1115
error: aborting due to previous error
1216

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// run-rustfix
2+
#![allow(dead_code)]
3+
4+
// `Rc` is not ever `Copy`, we should not suggest adding `T: Copy` constraint.
5+
// But should suggest adding `.clone()`.
6+
fn move_rc<T>(t: std::rc::Rc<T>) {
7+
[t.clone(), t]; //~ use of moved value: `t`
8+
}
9+
10+
// Even though `T` could be `Copy` it's already `Clone`
11+
// so don't suggest adding `T: Copy` constraint,
12+
// instead suggest adding `.clone()`.
13+
fn move_clone_already<T: Clone>(t: T) {
14+
[t.clone(), t]; //~ use of moved value: `t`
15+
}
16+
17+
// Same as `Rc`
18+
fn move_clone_only<T: Clone>(t: (T, String)) {
19+
[t.clone(), t]; //~ use of moved value: `t`
20+
}
21+
22+
// loop
23+
fn move_in_a_loop<T: Clone>(t: T) {
24+
loop {
25+
if true {
26+
drop(t.clone()); //~ use of moved value: `t`
27+
} else {
28+
drop(t.clone());
29+
}
30+
}
31+
}
32+
33+
fn main() {}

src/test/ui/moves/use_of_moved_value_clone_suggestions.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ fn move_rc<T>(t: std::rc::Rc<T>) {
77
[t, t]; //~ use of moved value: `t`
88
}
99

10-
// Even though `T` could be `Copy` it's already `Clone` so don't suggest adding `T: Copy` constraint,
10+
// Even though `T` could be `Copy` it's already `Clone`
11+
// so don't suggest adding `T: Copy` constraint,
1112
// instead suggest adding `.clone()`.
1213
fn move_clone_already<T: Clone>(t: T) {
1314
[t, t]; //~ use of moved value: `t`

0 commit comments

Comments
 (0)