Skip to content

Commit

Permalink
Add test for rust-lang#34721
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Jan 24, 2019
1 parent 5e9c8d7 commit e0a606c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/test/ui/issues/issue-34721.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#![feature(nll)]

pub trait Foo {
fn zero(self) -> Self;
}

impl Foo for u32 {
fn zero(self) -> u32 { 0u32 }
}

pub mod bar {
pub use Foo;
pub fn bar<T: Foo>(x: T) -> T {
x.zero()
}
}

mod baz {
use bar;
use Foo;
pub fn baz<T: Foo>(x: T) -> T {
if 0 == 1 {
bar::bar(x.zero())
} else {
x.zero()
};
x.zero()
//~^ ERROR use of moved value
}
}

fn main() {
let _ = baz::baz(0u32);
}
18 changes: 18 additions & 0 deletions src/test/ui/issues/issue-34721.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error[E0382]: use of moved value: `x`
--> $DIR/issue-34721.rs:27:9
|
LL | pub fn baz<T: Foo>(x: T) -> T {
| - move occurs because `x` has type `T`, which does not implement the `Copy` trait
LL | if 0 == 1 {
LL | bar::bar(x.zero())
| - value moved here
LL | } else {
LL | x.zero()
| - value moved here
LL | };
LL | x.zero()
| ^ value used here after move

error: aborting due to previous error

For more information about this error, try `rustc --explain E0382`.

0 comments on commit e0a606c

Please sign in to comment.