Skip to content

Commit ed1ece6

Browse files
committedMay 12, 2016
Auto merge of #33169 - swgillespie:issue32829, r=eddyb
const_fn: Check the terminating expression of a block for blocks in a const initializer In a const or static initializer, the `CheckBlock` check ensures that blocks in the initializer expression are only in tail positions or in items. In this case, it didn't check the terminating expression of a block, which resulted in an ICE later in the compiler pipeline if the trailing expression was itself a block. This change fixes the ICE and ensures that the proper error is emitted. This fixes the ICE in #32829 .
2 parents 22ac88f + 94a0552 commit ed1ece6

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed
 

Diff for: ‎src/test/compile-fail/issue32829.rs

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// Copyright 2016 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+
#![feature(const_fn)]
11+
12+
const bad : u32 = {
13+
{
14+
5; //~ ERROR: blocks in constants are limited to items and tail expressions
15+
0
16+
}
17+
};
18+
19+
const bad_two : u32 = {
20+
{
21+
invalid();
22+
//~^ ERROR: blocks in constants are limited to items and tail expressions
23+
//~^^ ERROR: calls in constants are limited to constant functions, struct and enum
24+
0
25+
}
26+
};
27+
28+
const bad_three : u32 = {
29+
{
30+
valid();
31+
//~^ ERROR: blocks in constants are limited to items and tail expressions
32+
0
33+
}
34+
};
35+
36+
static bad_four : u32 = {
37+
{
38+
5; //~ ERROR: blocks in statics are limited to items and tail expressions
39+
0
40+
}
41+
};
42+
43+
static bad_five : u32 = {
44+
{
45+
invalid();
46+
//~^ ERROR: blocks in statics are limited to items and tail expressions
47+
//~^^ ERROR: calls in statics are limited to constant functions, struct and enum
48+
0
49+
}
50+
};
51+
52+
static bad_six : u32 = {
53+
{
54+
valid();
55+
//~^ ERROR: blocks in statics are limited to items and tail expressions
56+
0
57+
}
58+
};
59+
60+
static mut bad_seven : u32 = {
61+
{
62+
5; //~ ERROR: blocks in statics are limited to items and tail expressions
63+
0
64+
}
65+
};
66+
67+
static mut bad_eight : u32 = {
68+
{
69+
invalid();
70+
//~^ ERROR: blocks in statics are limited to items and tail expressions
71+
//~^^ ERROR: calls in statics are limited to constant functions, struct and enum
72+
0
73+
}
74+
};
75+
76+
static mut bad_nine : u32 = {
77+
{
78+
valid();
79+
//~^ ERROR: blocks in statics are limited to items and tail expressions
80+
0
81+
}
82+
};
83+
84+
85+
fn invalid() {}
86+
const fn valid() {}
87+
88+
fn main() {}

0 commit comments

Comments
 (0)