Skip to content

Commit c65ddb8

Browse files
committed
Add regression test for issue 13110
1 parent 0ee9f44 commit c65ddb8

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

tests/ui/zero_repeat_side_effects.fixed

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,13 @@ fn main() {
5858
// as function param
5959
drop(vec![f(); 1]);
6060
}
61+
62+
macro_rules! LEN {
63+
() => {0};
64+
}
65+
66+
fn issue_13110() {
67+
f(); let _data: [i32; 0] = [];
68+
const LENGTH: usize = LEN!();
69+
f(); let _data: [i32; 0] = [];
70+
}

tests/ui/zero_repeat_side_effects.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,13 @@ fn main() {
5858
// as function param
5959
drop(vec![f(); 1]);
6060
}
61+
62+
macro_rules! LEN {
63+
() => {0};
64+
}
65+
66+
fn issue_13110() {
67+
let _data = [f(); LEN!()];
68+
const LENGTH: usize = LEN!();
69+
let _data = [f(); LENGTH];
70+
}

tests/ui/zero_repeat_side_effects.stderr

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,17 @@ error: function or method calls as the initial value in zero-sized array initial
7373
LL | [f(); N];
7474
| ^^^^^^^^ help: consider using: `{ f(); [] as [i32; 0] }`
7575

76-
error: aborting due to 12 previous errors
76+
error: function or method calls as the initial value in zero-sized array initializers may cause side effects
77+
--> tests/ui/zero_repeat_side_effects.rs:67:5
78+
|
79+
LL | let _data = [f(); LEN!()];
80+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f(); let _data: [i32; 0] = [];`
81+
82+
error: function or method calls as the initial value in zero-sized array initializers may cause side effects
83+
--> tests/ui/zero_repeat_side_effects.rs:69:5
84+
|
85+
LL | let _data = [f(); LENGTH];
86+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f(); let _data: [i32; 0] = [];`
87+
88+
error: aborting due to 14 previous errors
7789

0 commit comments

Comments
 (0)