about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/test/mir-opt/end_region_cyclic.rs56
-rw-r--r--src/test/mir-opt/validate_3.rs34
-rw-r--r--src/test/ui/hygiene/fields-definition.rs32
-rw-r--r--src/test/ui/hygiene/fields-definition.stderr14
-rw-r--r--src/test/ui/hygiene/fields-move.rs40
-rw-r--r--src/test/ui/hygiene/fields-move.stderr39
-rw-r--r--src/test/ui/hygiene/fields-numeric-borrowck.rs18
-rw-r--r--src/test/ui/hygiene/fields-numeric-borrowck.stderr14
8 files changed, 208 insertions, 39 deletions
diff --git a/src/test/mir-opt/end_region_cyclic.rs b/src/test/mir-opt/end_region_cyclic.rs
index 83425a72f45..9c939d0d2fb 100644
--- a/src/test/mir-opt/end_region_cyclic.rs
+++ b/src/test/mir-opt/end_region_cyclic.rs
@@ -40,29 +40,29 @@ fn query() -> bool { true }
 
 // END RUST SOURCE
 // START rustc.main.SimplifyCfg-qualify-consts.after.mir
-// fn main() -> () {
+// fn main() -> (){
 //     let mut _0: ();
 //     scope 1 {
-//         let _2: S<'35_0rs>;
+//         let _2: S<'36_0rs>;
+//     }
+//     scope 2 {
 //     }
-//     ...
 //     let mut _1: ();
-//     let mut _3: std::cell::Cell<std::option::Option<&'35_0rs S<'35_0rs>>>;
-//     let mut _4: std::option::Option<&'35_0rs S<'35_0rs>>;
+//     let mut _3: std::cell::Cell<std::option::Option<&'36_0rs S<'36_0rs>>>;
+//     let mut _4: std::option::Option<&'36_0rs S<'36_0rs>>;
 //     let mut _5: ();
-//     let mut _6: &'16s std::cell::Cell<std::option::Option<&'35_0rs S<'35_0rs>>>;
-//     let mut _7: std::option::Option<&'35_0rs S<'35_0rs>>;
-//     let mut _8: &'35_0rs S<'35_0rs>;
-//     let mut _9: &'35_0rs S<'35_0rs>;
+//     let mut _6: &'17s std::cell::Cell<std::option::Option<&'36_0rs S<'36_0rs>>>;
+//     let mut _7: std::option::Option<&'36_0rs S<'36_0rs>>;
+//     let mut _8: &'36_0rs S<'36_0rs>;
+//     let mut _9: &'36_0rs S<'36_0rs>;
 //     let mut _10: ();
 //     let mut _11: bool;
 //     let mut _12: !;
 //     let mut _13: ();
-//     let mut _14: &'33s std::cell::Cell<std::option::Option<&'35_0rs S<'35_0rs>>>;
-//     let mut _15: std::option::Option<&'35_0rs S<'35_0rs>>;
-//     let mut _16: &'35_0rs S<'35_0rs>;
-//     let mut _17: &'35_0rs S<'35_0rs>;
-//
+//     let mut _14: &'34s std::cell::Cell<std::option::Option<&'36_0rs S<'36_0rs>>>;
+//     let mut _15: std::option::Option<&'36_0rs S<'36_0rs>>;
+//     let mut _16: &'36_0rs S<'36_0rs>;
+//     let mut _17: &'36_0rs S<'36_0rs>;
 //     bb0: {
 //         goto -> bb1;
 //     }
@@ -73,7 +73,7 @@ fn query() -> bool { true }
 //         StorageLive(_2);
 //         StorageLive(_3);
 //         StorageLive(_4);
-//         _4 = std::option::Option<&'35_0rs S<'35_0rs>>::None;
+//         _4 = std::option::Option<&'36_0rs S<'36_0rs>>::None;
 //         _3 = const <std::cell::Cell<T>>::new(move _4) -> [return: bb4, unwind: bb3];
 //     }
 //     bb3: {
@@ -81,21 +81,21 @@ fn query() -> bool { true }
 //     }
 //     bb4: {
 //         StorageDead(_4);
-//         _2 = S<'35_0rs> { r: move _3 };
+//         _2 = S<'36_0rs> { r: move _3 };
 //         StorageDead(_3);
 //         StorageLive(_6);
-//         _6 = &'16s (_2.0: std::cell::Cell<std::option::Option<&'35_0rs S<'35_0rs>>>);
+//         _6 = &'17s (_2.0: std::cell::Cell<std::option::Option<&'36_0rs S<'36_0rs>>>);
 //         StorageLive(_7);
 //         StorageLive(_8);
 //         StorageLive(_9);
-//         _9 = &'35_0rs _2;
-//         _8 = &'35_0rs (*_9);
-//         _7 = std::option::Option<&'35_0rs S<'35_0rs>>::Some(move _8,);
+//         _9 = &'36_0rs _2;
+//         _8 = &'36_0rs (*_9);
+//         _7 = std::option::Option<&'36_0rs S<'36_0rs>>::Some(move _8,);
 //         StorageDead(_8);
 //         _5 = const <std::cell::Cell<T>>::set(move _6, move _7) -> [return: bb5, unwind: bb3];
 //     }
 //     bb5: {
-//         EndRegion('16s);
+//         EndRegion('17s);
 //         StorageDead(_7);
 //         StorageDead(_6);
 //         StorageDead(_9);
@@ -108,7 +108,7 @@ fn query() -> bool { true }
 //     bb7: {
 //         _0 = ();
 //         StorageDead(_11);
-//         EndRegion('35_0rs);
+//         EndRegion('36_0rs);
 //         StorageDead(_2);
 //         return;
 //     }
@@ -116,23 +116,23 @@ fn query() -> bool { true }
 //         _10 = ();
 //         StorageDead(_11);
 //         StorageLive(_14);
-//         _14 = &'33s (_2.0: std::cell::Cell<std::option::Option<&'35_0rs S<'35_0rs>>>);
+//         _14 = &'34s (_2.0: std::cell::Cell<std::option::Option<&'36_0rs S<'36_0rs>>>);
 //         StorageLive(_15);
 //         StorageLive(_16);
 //         StorageLive(_17);
-//         _17 = &'35_0rs _2;
-//         _16 = &'35_0rs (*_17);
-//         _15 = std::option::Option<&'35_0rs S<'35_0rs>>::Some(move _16,);
+//         _17 = &'36_0rs _2;
+//         _16 = &'36_0rs (*_17);
+//         _15 = std::option::Option<&'36_0rs S<'36_0rs>>::Some(move _16,);
 //         StorageDead(_16);
 //         _13 = const <std::cell::Cell<T>>::set(move _14, move _15) -> [return: bb9, unwind: bb3];
 //     }
 //     bb9: {
-//         EndRegion('33s);
+//         EndRegion('34s);
 //         StorageDead(_15);
 //         StorageDead(_14);
 //         StorageDead(_17);
 //         _1 = ();
-//         EndRegion('35_0rs);
+//         EndRegion('36_0rs);
 //         StorageDead(_2);
 //         goto -> bb1;
 //     }
diff --git a/src/test/mir-opt/validate_3.rs b/src/test/mir-opt/validate_3.rs
index 80e75fcee8a..79645bd3600 100644
--- a/src/test/mir-opt/validate_3.rs
+++ b/src/test/mir-opt/validate_3.rs
@@ -29,34 +29,46 @@ fn main() {
 
 // END RUST SOURCE
 // START rustc.main.EraseRegions.after.mir
-// fn main() -> () {
-//     ...
+// fn main() -> (){
+//     let mut _0: ();
+//     scope 1 {
+//         let _1: Test;
+//         scope 3 {
+//             let _2: &ReErased Test;
+//         }
+//         scope 4 {
+//         }
+//     }
+//     scope 2 {
+//     }
+//     let mut _3: ();
+//     let mut _4: &ReErased i32;
 //     let mut _5: &ReErased i32;
 //     bb0: {
 //         StorageLive(_1);
 //         _1 = Test { x: const 0i32 };
 //         StorageLive(_2);
-//         Validate(Suspend(ReScope(Remainder(BlockRemainder { block: ItemLocalId(19), first_statement_index: 3 }))), [_1: Test]);
+//         Validate(Suspend(ReScope(Remainder(BlockRemainder { block: ItemLocalId(20), first_statement_index: 3 }))), [_1: Test]);
 //         _2 = &ReErased _1;
-//         Validate(Acquire, [(*_2): Test/ReScope(Remainder(BlockRemainder { block: ItemLocalId(19), first_statement_index: 3 })) (imm)]);
+//         Validate(Acquire, [(*_2): Test/ReScope(Remainder(BlockRemainder { block: ItemLocalId(20), first_statement_index: 3 })) (imm)]);
 //         StorageLive(_4);
 //         StorageLive(_5);
-//         Validate(Suspend(ReScope(Node(ItemLocalId(17)))), [((*_2).0: i32): i32/ReScope(Remainder(BlockRemainder { block: ItemLocalId(19), first_statement_index: 3 })) (imm)]);
+//         Validate(Suspend(ReScope(Node(ItemLocalId(18)))), [((*_2).0: i32): i32/ReScope(Remainder(BlockRemainder { block: ItemLocalId(20), first_statement_index: 3 })) (imm)]);
 //         _5 = &ReErased ((*_2).0: i32);
-//         Validate(Acquire, [(*_5): i32/ReScope(Node(ItemLocalId(17))) (imm)]);
-//         Validate(Suspend(ReScope(Node(ItemLocalId(17)))), [(*_5): i32/ReScope(Node(ItemLocalId(17))) (imm)]);
+//         Validate(Acquire, [(*_5): i32/ReScope(Node(ItemLocalId(18))) (imm)]);
+//         Validate(Suspend(ReScope(Node(ItemLocalId(18)))), [(*_5): i32/ReScope(Node(ItemLocalId(18))) (imm)]);
 //         _4 = &ReErased (*_5);
-//         Validate(Acquire, [(*_4): i32/ReScope(Node(ItemLocalId(17))) (imm)]);
-//         Validate(Release, [_3: (), _4: &ReScope(Node(ItemLocalId(17))) i32]);
+//         Validate(Acquire, [(*_4): i32/ReScope(Node(ItemLocalId(18))) (imm)]);
+//         Validate(Release, [_3: (), _4: &ReScope(Node(ItemLocalId(18))) i32]);
 //         _3 = const foo(move _4) -> bb1;
 //     }
 //     bb1: {
 //         Validate(Acquire, [_3: ()]);
-//         EndRegion(ReScope(Node(ItemLocalId(17))));
+//         EndRegion(ReScope(Node(ItemLocalId(18))));
 //         StorageDead(_4);
 //         StorageDead(_5);
 //         _0 = ();
-//         EndRegion(ReScope(Remainder(BlockRemainder { block: ItemLocalId(19), first_statement_index: 3 })));
+//         EndRegion(ReScope(Remainder(BlockRemainder { block: ItemLocalId(20), first_statement_index: 3 })));
 //         StorageDead(_2);
 //         StorageDead(_1);
 //         return;
diff --git a/src/test/ui/hygiene/fields-definition.rs b/src/test/ui/hygiene/fields-definition.rs
new file mode 100644
index 00000000000..c92bf55a723
--- /dev/null
+++ b/src/test/ui/hygiene/fields-definition.rs
@@ -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() {}
diff --git a/src/test/ui/hygiene/fields-definition.stderr b/src/test/ui/hygiene/fields-definition.stderr
new file mode 100644
index 00000000000..73f524b7d2a
--- /dev/null
+++ b/src/test/ui/hygiene/fields-definition.stderr
@@ -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`.
diff --git a/src/test/ui/hygiene/fields-move.rs b/src/test/ui/hygiene/fields-move.rs
new file mode 100644
index 00000000000..a6e3b2b2d8b
--- /dev/null
+++ b/src/test/ui/hygiene/fields-move.rs
@@ -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`
+}
diff --git a/src/test/ui/hygiene/fields-move.stderr b/src/test/ui/hygiene/fields-move.stderr
new file mode 100644
index 00000000000..ba9de09f9d2
--- /dev/null
+++ b/src/test/ui/hygiene/fields-move.stderr
@@ -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`.
diff --git a/src/test/ui/hygiene/fields-numeric-borrowck.rs b/src/test/ui/hygiene/fields-numeric-borrowck.rs
new file mode 100644
index 00000000000..50ace39e709
--- /dev/null
+++ b/src/test/ui/hygiene/fields-numeric-borrowck.rs
@@ -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
+}
diff --git a/src/test/ui/hygiene/fields-numeric-borrowck.stderr b/src/test/ui/hygiene/fields-numeric-borrowck.stderr
new file mode 100644
index 00000000000..ccd898fff27
--- /dev/null
+++ b/src/test/ui/hygiene/fields-numeric-borrowck.stderr
@@ -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`.