-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some new tests + Fix failing tests
- Loading branch information
1 parent
d3f8b8b
commit fcf4852
Showing
8 changed files
with
208 additions
and
39 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![feature(decl_macro)] | ||
|
||
macro modern($a: ident) { | ||
struct Modern { | ||
a: u8, | ||
$a: u8, // OK | ||
} | ||
} | ||
|
||
macro_rules! legacy { | ||
($a: ident) => { | ||
struct Legacy { | ||
a: u8, | ||
$a: u8, //~ ERROR field `a` is already declared | ||
} | ||
} | ||
} | ||
|
||
modern!(a); | ||
legacy!(a); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error[E0124]: field `a` is already declared | ||
--> $DIR/fields-definition.rs:24:17 | ||
| | ||
LL | a: u8, | ||
| ----- `a` first declared here | ||
LL | $a: u8, //~ ERROR field `a` is already declared | ||
| ^^ field already declared | ||
... | ||
LL | legacy!(a); | ||
| ----------- in this macro invocation | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0124`. |
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,40 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// issue #46314 | ||
|
||
#![feature(decl_macro)] | ||
|
||
#[derive(Debug)] | ||
struct NonCopy(String); | ||
|
||
struct Foo { | ||
x: NonCopy, | ||
} | ||
|
||
macro copy_modern($foo: ident) { | ||
$foo.x | ||
} | ||
|
||
macro_rules! copy_legacy { | ||
($foo: ident) => { | ||
$foo.x //~ ERROR use of moved value: `foo.x` | ||
} | ||
} | ||
|
||
fn assert_two_copies(a: NonCopy, b: NonCopy) { | ||
println!("Got two copies: {:?}, {:?}", a, b); | ||
} | ||
|
||
fn main() { | ||
let foo = Foo { x: NonCopy("foo".into()) }; | ||
assert_two_copies(copy_modern!(foo), foo.x); //~ ERROR use of moved value: `foo.x` | ||
assert_two_copies(copy_legacy!(foo), foo.x); //~ ERROR use of moved value: `foo.x` | ||
} |
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,39 @@ | ||
error[E0382]: use of moved value: `foo.x` | ||
--> $DIR/fields-move.rs:38:42 | ||
| | ||
LL | $foo.x | ||
| ------ value moved here | ||
... | ||
LL | assert_two_copies(copy_modern!(foo), foo.x); //~ ERROR use of moved value: `foo.x` | ||
| ^^^^^ value used here after move | ||
| | ||
= note: move occurs because `foo.x` has type `NonCopy`, which does not implement the `Copy` trait | ||
|
||
error[E0382]: use of moved value: `foo.x` | ||
--> $DIR/fields-move.rs:28:9 | ||
| | ||
LL | $foo.x | ||
| ------ value moved here | ||
... | ||
LL | $foo.x //~ ERROR use of moved value: `foo.x` | ||
| ^^^^^^ value used here after move | ||
... | ||
LL | assert_two_copies(copy_legacy!(foo), foo.x); //~ ERROR use of moved value: `foo.x` | ||
| ----------------- in this macro invocation | ||
| | ||
= note: move occurs because `foo.x` has type `NonCopy`, which does not implement the `Copy` trait | ||
|
||
error[E0382]: use of moved value: `foo.x` | ||
--> $DIR/fields-move.rs:39:42 | ||
| | ||
LL | $foo.x | ||
| ------ value moved here | ||
... | ||
LL | assert_two_copies(copy_legacy!(foo), foo.x); //~ ERROR use of moved value: `foo.x` | ||
| ^^^^^ value used here after move | ||
| | ||
= note: move occurs because `foo.x` has type `NonCopy`, which does not implement the `Copy` trait | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0382`. |
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,18 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
struct S(u8); | ||
|
||
fn main() { | ||
let mut s = S(0); | ||
let borrow1 = &mut s.0; | ||
let S { 0: ref mut borrow2 } = s; | ||
//~^ ERROR cannot borrow `s.0` as mutable more than once at a time | ||
} |
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,14 @@ | ||
error[E0499]: cannot borrow `s.0` as mutable more than once at a time | ||
--> $DIR/fields-numeric-borrowck.rs:16:16 | ||
| | ||
LL | let borrow1 = &mut s.0; | ||
| --- first mutable borrow occurs here | ||
LL | let S { 0: ref mut borrow2 } = s; | ||
| ^^^^^^^^^^^^^^^ second mutable borrow occurs here | ||
LL | //~^ ERROR cannot borrow `s.0` as mutable more than once at a time | ||
LL | } | ||
| - first borrow ends here | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0499`. |