Skip to content

Commit fcf4852

Browse files
committed
Add some new tests + Fix failing tests
1 parent d3f8b8b commit fcf4852

8 files changed

+208
-39
lines changed

src/test/mir-opt/end_region_cyclic.rs

+28-28
Original file line numberDiff line numberDiff line change
@@ -40,29 +40,29 @@ fn query() -> bool { true }
4040

4141
// END RUST SOURCE
4242
// START rustc.main.SimplifyCfg-qualify-consts.after.mir
43-
// fn main() -> () {
43+
// fn main() -> (){
4444
// let mut _0: ();
4545
// scope 1 {
46-
// let _2: S<'35_0rs>;
46+
// let _2: S<'36_0rs>;
47+
// }
48+
// scope 2 {
4749
// }
48-
// ...
4950
// let mut _1: ();
50-
// let mut _3: std::cell::Cell<std::option::Option<&'35_0rs S<'35_0rs>>>;
51-
// let mut _4: std::option::Option<&'35_0rs S<'35_0rs>>;
51+
// let mut _3: std::cell::Cell<std::option::Option<&'36_0rs S<'36_0rs>>>;
52+
// let mut _4: std::option::Option<&'36_0rs S<'36_0rs>>;
5253
// let mut _5: ();
53-
// let mut _6: &'16s std::cell::Cell<std::option::Option<&'35_0rs S<'35_0rs>>>;
54-
// let mut _7: std::option::Option<&'35_0rs S<'35_0rs>>;
55-
// let mut _8: &'35_0rs S<'35_0rs>;
56-
// let mut _9: &'35_0rs S<'35_0rs>;
54+
// let mut _6: &'17s std::cell::Cell<std::option::Option<&'36_0rs S<'36_0rs>>>;
55+
// let mut _7: std::option::Option<&'36_0rs S<'36_0rs>>;
56+
// let mut _8: &'36_0rs S<'36_0rs>;
57+
// let mut _9: &'36_0rs S<'36_0rs>;
5758
// let mut _10: ();
5859
// let mut _11: bool;
5960
// let mut _12: !;
6061
// let mut _13: ();
61-
// let mut _14: &'33s std::cell::Cell<std::option::Option<&'35_0rs S<'35_0rs>>>;
62-
// let mut _15: std::option::Option<&'35_0rs S<'35_0rs>>;
63-
// let mut _16: &'35_0rs S<'35_0rs>;
64-
// let mut _17: &'35_0rs S<'35_0rs>;
65-
//
62+
// let mut _14: &'34s std::cell::Cell<std::option::Option<&'36_0rs S<'36_0rs>>>;
63+
// let mut _15: std::option::Option<&'36_0rs S<'36_0rs>>;
64+
// let mut _16: &'36_0rs S<'36_0rs>;
65+
// let mut _17: &'36_0rs S<'36_0rs>;
6666
// bb0: {
6767
// goto -> bb1;
6868
// }
@@ -73,29 +73,29 @@ fn query() -> bool { true }
7373
// StorageLive(_2);
7474
// StorageLive(_3);
7575
// StorageLive(_4);
76-
// _4 = std::option::Option<&'35_0rs S<'35_0rs>>::None;
76+
// _4 = std::option::Option<&'36_0rs S<'36_0rs>>::None;
7777
// _3 = const <std::cell::Cell<T>>::new(move _4) -> [return: bb4, unwind: bb3];
7878
// }
7979
// bb3: {
8080
// resume;
8181
// }
8282
// bb4: {
8383
// StorageDead(_4);
84-
// _2 = S<'35_0rs> { r: move _3 };
84+
// _2 = S<'36_0rs> { r: move _3 };
8585
// StorageDead(_3);
8686
// StorageLive(_6);
87-
// _6 = &'16s (_2.0: std::cell::Cell<std::option::Option<&'35_0rs S<'35_0rs>>>);
87+
// _6 = &'17s (_2.0: std::cell::Cell<std::option::Option<&'36_0rs S<'36_0rs>>>);
8888
// StorageLive(_7);
8989
// StorageLive(_8);
9090
// StorageLive(_9);
91-
// _9 = &'35_0rs _2;
92-
// _8 = &'35_0rs (*_9);
93-
// _7 = std::option::Option<&'35_0rs S<'35_0rs>>::Some(move _8,);
91+
// _9 = &'36_0rs _2;
92+
// _8 = &'36_0rs (*_9);
93+
// _7 = std::option::Option<&'36_0rs S<'36_0rs>>::Some(move _8,);
9494
// StorageDead(_8);
9595
// _5 = const <std::cell::Cell<T>>::set(move _6, move _7) -> [return: bb5, unwind: bb3];
9696
// }
9797
// bb5: {
98-
// EndRegion('16s);
98+
// EndRegion('17s);
9999
// StorageDead(_7);
100100
// StorageDead(_6);
101101
// StorageDead(_9);
@@ -108,31 +108,31 @@ fn query() -> bool { true }
108108
// bb7: {
109109
// _0 = ();
110110
// StorageDead(_11);
111-
// EndRegion('35_0rs);
111+
// EndRegion('36_0rs);
112112
// StorageDead(_2);
113113
// return;
114114
// }
115115
// bb8: {
116116
// _10 = ();
117117
// StorageDead(_11);
118118
// StorageLive(_14);
119-
// _14 = &'33s (_2.0: std::cell::Cell<std::option::Option<&'35_0rs S<'35_0rs>>>);
119+
// _14 = &'34s (_2.0: std::cell::Cell<std::option::Option<&'36_0rs S<'36_0rs>>>);
120120
// StorageLive(_15);
121121
// StorageLive(_16);
122122
// StorageLive(_17);
123-
// _17 = &'35_0rs _2;
124-
// _16 = &'35_0rs (*_17);
125-
// _15 = std::option::Option<&'35_0rs S<'35_0rs>>::Some(move _16,);
123+
// _17 = &'36_0rs _2;
124+
// _16 = &'36_0rs (*_17);
125+
// _15 = std::option::Option<&'36_0rs S<'36_0rs>>::Some(move _16,);
126126
// StorageDead(_16);
127127
// _13 = const <std::cell::Cell<T>>::set(move _14, move _15) -> [return: bb9, unwind: bb3];
128128
// }
129129
// bb9: {
130-
// EndRegion('33s);
130+
// EndRegion('34s);
131131
// StorageDead(_15);
132132
// StorageDead(_14);
133133
// StorageDead(_17);
134134
// _1 = ();
135-
// EndRegion('35_0rs);
135+
// EndRegion('36_0rs);
136136
// StorageDead(_2);
137137
// goto -> bb1;
138138
// }

src/test/mir-opt/validate_3.rs

+23-11
Original file line numberDiff line numberDiff line change
@@ -29,34 +29,46 @@ fn main() {
2929

3030
// END RUST SOURCE
3131
// START rustc.main.EraseRegions.after.mir
32-
// fn main() -> () {
33-
// ...
32+
// fn main() -> (){
33+
// let mut _0: ();
34+
// scope 1 {
35+
// let _1: Test;
36+
// scope 3 {
37+
// let _2: &ReErased Test;
38+
// }
39+
// scope 4 {
40+
// }
41+
// }
42+
// scope 2 {
43+
// }
44+
// let mut _3: ();
45+
// let mut _4: &ReErased i32;
3446
// let mut _5: &ReErased i32;
3547
// bb0: {
3648
// StorageLive(_1);
3749
// _1 = Test { x: const 0i32 };
3850
// StorageLive(_2);
39-
// Validate(Suspend(ReScope(Remainder(BlockRemainder { block: ItemLocalId(19), first_statement_index: 3 }))), [_1: Test]);
51+
// Validate(Suspend(ReScope(Remainder(BlockRemainder { block: ItemLocalId(20), first_statement_index: 3 }))), [_1: Test]);
4052
// _2 = &ReErased _1;
41-
// Validate(Acquire, [(*_2): Test/ReScope(Remainder(BlockRemainder { block: ItemLocalId(19), first_statement_index: 3 })) (imm)]);
53+
// Validate(Acquire, [(*_2): Test/ReScope(Remainder(BlockRemainder { block: ItemLocalId(20), first_statement_index: 3 })) (imm)]);
4254
// StorageLive(_4);
4355
// StorageLive(_5);
44-
// Validate(Suspend(ReScope(Node(ItemLocalId(17)))), [((*_2).0: i32): i32/ReScope(Remainder(BlockRemainder { block: ItemLocalId(19), first_statement_index: 3 })) (imm)]);
56+
// Validate(Suspend(ReScope(Node(ItemLocalId(18)))), [((*_2).0: i32): i32/ReScope(Remainder(BlockRemainder { block: ItemLocalId(20), first_statement_index: 3 })) (imm)]);
4557
// _5 = &ReErased ((*_2).0: i32);
46-
// Validate(Acquire, [(*_5): i32/ReScope(Node(ItemLocalId(17))) (imm)]);
47-
// Validate(Suspend(ReScope(Node(ItemLocalId(17)))), [(*_5): i32/ReScope(Node(ItemLocalId(17))) (imm)]);
58+
// Validate(Acquire, [(*_5): i32/ReScope(Node(ItemLocalId(18))) (imm)]);
59+
// Validate(Suspend(ReScope(Node(ItemLocalId(18)))), [(*_5): i32/ReScope(Node(ItemLocalId(18))) (imm)]);
4860
// _4 = &ReErased (*_5);
49-
// Validate(Acquire, [(*_4): i32/ReScope(Node(ItemLocalId(17))) (imm)]);
50-
// Validate(Release, [_3: (), _4: &ReScope(Node(ItemLocalId(17))) i32]);
61+
// Validate(Acquire, [(*_4): i32/ReScope(Node(ItemLocalId(18))) (imm)]);
62+
// Validate(Release, [_3: (), _4: &ReScope(Node(ItemLocalId(18))) i32]);
5163
// _3 = const foo(move _4) -> bb1;
5264
// }
5365
// bb1: {
5466
// Validate(Acquire, [_3: ()]);
55-
// EndRegion(ReScope(Node(ItemLocalId(17))));
67+
// EndRegion(ReScope(Node(ItemLocalId(18))));
5668
// StorageDead(_4);
5769
// StorageDead(_5);
5870
// _0 = ();
59-
// EndRegion(ReScope(Remainder(BlockRemainder { block: ItemLocalId(19), first_statement_index: 3 })));
71+
// EndRegion(ReScope(Remainder(BlockRemainder { block: ItemLocalId(20), first_statement_index: 3 })));
6072
// StorageDead(_2);
6173
// StorageDead(_1);
6274
// return;
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(decl_macro)]
12+
13+
macro modern($a: ident) {
14+
struct Modern {
15+
a: u8,
16+
$a: u8, // OK
17+
}
18+
}
19+
20+
macro_rules! legacy {
21+
($a: ident) => {
22+
struct Legacy {
23+
a: u8,
24+
$a: u8, //~ ERROR field `a` is already declared
25+
}
26+
}
27+
}
28+
29+
modern!(a);
30+
legacy!(a);
31+
32+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0124]: field `a` is already declared
2+
--> $DIR/fields-definition.rs:24:17
3+
|
4+
LL | a: u8,
5+
| ----- `a` first declared here
6+
LL | $a: u8, //~ ERROR field `a` is already declared
7+
| ^^ field already declared
8+
...
9+
LL | legacy!(a);
10+
| ----------- in this macro invocation
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0124`.

src/test/ui/hygiene/fields-move.rs

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// issue #46314
12+
13+
#![feature(decl_macro)]
14+
15+
#[derive(Debug)]
16+
struct NonCopy(String);
17+
18+
struct Foo {
19+
x: NonCopy,
20+
}
21+
22+
macro copy_modern($foo: ident) {
23+
$foo.x
24+
}
25+
26+
macro_rules! copy_legacy {
27+
($foo: ident) => {
28+
$foo.x //~ ERROR use of moved value: `foo.x`
29+
}
30+
}
31+
32+
fn assert_two_copies(a: NonCopy, b: NonCopy) {
33+
println!("Got two copies: {:?}, {:?}", a, b);
34+
}
35+
36+
fn main() {
37+
let foo = Foo { x: NonCopy("foo".into()) };
38+
assert_two_copies(copy_modern!(foo), foo.x); //~ ERROR use of moved value: `foo.x`
39+
assert_two_copies(copy_legacy!(foo), foo.x); //~ ERROR use of moved value: `foo.x`
40+
}
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
error[E0382]: use of moved value: `foo.x`
2+
--> $DIR/fields-move.rs:38:42
3+
|
4+
LL | $foo.x
5+
| ------ value moved here
6+
...
7+
LL | assert_two_copies(copy_modern!(foo), foo.x); //~ ERROR use of moved value: `foo.x`
8+
| ^^^^^ value used here after move
9+
|
10+
= note: move occurs because `foo.x` has type `NonCopy`, which does not implement the `Copy` trait
11+
12+
error[E0382]: use of moved value: `foo.x`
13+
--> $DIR/fields-move.rs:28:9
14+
|
15+
LL | $foo.x
16+
| ------ value moved here
17+
...
18+
LL | $foo.x //~ ERROR use of moved value: `foo.x`
19+
| ^^^^^^ value used here after move
20+
...
21+
LL | assert_two_copies(copy_legacy!(foo), foo.x); //~ ERROR use of moved value: `foo.x`
22+
| ----------------- in this macro invocation
23+
|
24+
= note: move occurs because `foo.x` has type `NonCopy`, which does not implement the `Copy` trait
25+
26+
error[E0382]: use of moved value: `foo.x`
27+
--> $DIR/fields-move.rs:39:42
28+
|
29+
LL | $foo.x
30+
| ------ value moved here
31+
...
32+
LL | assert_two_copies(copy_legacy!(foo), foo.x); //~ ERROR use of moved value: `foo.x`
33+
| ^^^^^ value used here after move
34+
|
35+
= note: move occurs because `foo.x` has type `NonCopy`, which does not implement the `Copy` trait
36+
37+
error: aborting due to 3 previous errors
38+
39+
For more information about this error, try `rustc --explain E0382`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
struct S(u8);
12+
13+
fn main() {
14+
let mut s = S(0);
15+
let borrow1 = &mut s.0;
16+
let S { 0: ref mut borrow2 } = s;
17+
//~^ ERROR cannot borrow `s.0` as mutable more than once at a time
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0499]: cannot borrow `s.0` as mutable more than once at a time
2+
--> $DIR/fields-numeric-borrowck.rs:16:16
3+
|
4+
LL | let borrow1 = &mut s.0;
5+
| --- first mutable borrow occurs here
6+
LL | let S { 0: ref mut borrow2 } = s;
7+
| ^^^^^^^^^^^^^^^ second mutable borrow occurs here
8+
LL | //~^ ERROR cannot borrow `s.0` as mutable more than once at a time
9+
LL | }
10+
| - first borrow ends here
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0499`.

0 commit comments

Comments
 (0)