-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
879efa8
commit f0a16b8
Showing
5 changed files
with
119 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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) //~ use of moved value: `t` | ||
} | ||
|
||
fn main() {} |
13 changes: 13 additions & 0 deletions
13
src/test/ui/moves/use_of_moved_value_clone_suggestions.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
error[E0382]: use of moved value: `t` | ||
--> $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 | ||
LL | (t, t) | ||
| - ^ value used here after move | ||
| | | ||
| value moved here | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0382`. |
72 changes: 72 additions & 0 deletions
72
src/test/ui/moves/use_of_moved_value_copy_suggestions.fixed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// run-rustfix | ||
#![allow(dead_code)] | ||
|
||
fn duplicate_t<T: Copy>(t: T) -> (T, T) { | ||
//~^ HELP consider restricting type parameter `T` | ||
(t, t) //~ use of moved value: `t` | ||
} | ||
|
||
fn duplicate_opt<T: Copy>(t: Option<T>) -> (Option<T>, Option<T>) { | ||
//~^ HELP consider restricting type parameter `T` | ||
(t, t) //~ use of moved value: `t` | ||
} | ||
|
||
fn duplicate_tup1<T: Copy>(t: (T,)) -> ((T,), (T,)) { | ||
//~^ HELP consider restricting type parameter `T` | ||
(t, t) //~ use of moved value: `t` | ||
} | ||
|
||
fn duplicate_tup2<A: Copy, B: Copy>(t: (A, B)) -> ((A, B), (A, B)) { | ||
//~^ HELP consider restricting type parameters | ||
(t, t) //~ use of moved value: `t` | ||
} | ||
|
||
fn duplicate_custom<T: Trait + Copy>(t: S<T>) -> (S<T>, S<T>) { | ||
//~^ HELP consider restricting type parameter `T` | ||
(t, t) //~ use of moved value: `t` | ||
} | ||
|
||
struct S<T>(T); | ||
trait Trait {} | ||
impl<T: Trait + Clone> Clone for S<T> { | ||
fn clone(&self) -> Self { | ||
Self(self.0.clone()) | ||
} | ||
} | ||
impl<T: Trait + Copy> Copy for S<T> {} | ||
|
||
trait A {} | ||
trait B {} | ||
|
||
// Test where bounds are added with different bound placements | ||
fn duplicate_custom_1<T: Trait + Copy>(t: S<T>) -> (S<T>, S<T>) where { | ||
//~^ HELP consider restricting type parameter `T` | ||
(t, t) //~ use of moved value: `t` | ||
} | ||
|
||
fn duplicate_custom_2<T>(t: S<T>) -> (S<T>, S<T>) | ||
where | ||
T: A + Trait + Copy, | ||
//~^ HELP consider further restricting this bound | ||
{ | ||
(t, t) //~ use of moved value: `t` | ||
} | ||
|
||
fn duplicate_custom_3<T>(t: S<T>) -> (S<T>, S<T>) | ||
where | ||
T: A, | ||
T: B, T: Trait, T: Copy | ||
//~^ HELP consider further restricting type parameter `T` | ||
{ | ||
(t, t) //~ use of moved value: `t` | ||
} | ||
|
||
fn duplicate_custom_4<T: A>(t: S<T>) -> (S<T>, S<T>) | ||
where | ||
T: B + Trait + Copy, | ||
//~^ HELP consider further restricting this bound | ||
{ | ||
(t, t) //~ use of moved value: `t` | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters