Skip to content

Commit 4a7df22

Browse files
committed
Accommodate error message explosion from box-desugaring in some tests.
See discussion on Issue 22231.
1 parent 467345b commit 4a7df22

File tree

8 files changed

+194
-27
lines changed

8 files changed

+194
-27
lines changed

src/test/compile-fail/check-static-values-constraints.rs

Lines changed: 116 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,22 @@ static STATIC10: UnsafeStruct = UnsafeStruct;
9999
struct MyOwned;
100100

101101
static STATIC11: Box<MyOwned> = box MyOwned;
102-
//~^ ERROR allocations are not allowed in statics
102+
//~^ ERROR statics are not allowed to have destructors
103+
//~| ERROR statics are not allowed to have destructors
104+
//~| ERROR statics are not allowed to have destructors
105+
//~| ERROR blocks in statics are limited to items and tail expressions
106+
//~| ERROR blocks in statics are limited to items and tail expressions
107+
//~| ERROR blocks in statics are limited to items and tail expressions
108+
//~| ERROR blocks in statics are limited to items and tail expressions
109+
//~| ERROR function calls in statics are limited to struct and enum constructors
110+
//~| ERROR function calls in statics are limited to struct and enum constructors
111+
//~| ERROR function calls in statics are limited to struct and enum constructors
112+
//~| ERROR function calls in statics are limited to struct and enum constructors
113+
//~| ERROR paths in statics may only refer to constants or functions
114+
//~| ERROR paths in statics may only refer to constants or functions
115+
//~| ERROR paths in statics may only refer to constants or functions
116+
//~| ERROR paths in statics may only refer to constants or functions
117+
//~| ERROR references in statics may only refer to immutable values
103118

104119
// The following examples test that mutable structs are just forbidden
105120
// to have types with destructors
@@ -121,23 +136,117 @@ static mut STATIC14: SafeStruct = SafeStruct {
121136
};
122137

123138
static STATIC15: &'static [Box<MyOwned>] = &[
124-
box MyOwned, //~ ERROR allocations are not allowed in statics
125-
box MyOwned, //~ ERROR allocations are not allowed in statics
139+
box MyOwned,
140+
//~^ ERROR statics are not allowed to have destructors
141+
//~| ERROR statics are not allowed to have destructors
142+
//~| ERROR statics are not allowed to have destructors
143+
//~| ERROR blocks in statics are limited to items and tail expressions
144+
//~| ERROR blocks in statics are limited to items and tail expressions
145+
//~| ERROR blocks in statics are limited to items and tail expressions
146+
//~| ERROR blocks in statics are limited to items and tail expressions
147+
//~| ERROR function calls in statics are limited to struct and enum constructors
148+
//~| ERROR function calls in statics are limited to struct and enum constructors
149+
//~| ERROR function calls in statics are limited to struct and enum constructors
150+
//~| ERROR function calls in statics are limited to struct and enum constructors
151+
//~| ERROR paths in statics may only refer to constants or functions
152+
//~| ERROR paths in statics may only refer to constants or functions
153+
//~| ERROR paths in statics may only refer to constants or functions
154+
//~| ERROR paths in statics may only refer to constants or functions
155+
//~| ERROR references in statics may only refer to immutable values
156+
box MyOwned,
157+
//~^ ERROR statics are not allowed to have destructors
158+
//~| ERROR statics are not allowed to have destructors
159+
//~| ERROR statics are not allowed to have destructors
160+
//~| ERROR blocks in statics are limited to items and tail expressions
161+
//~| ERROR blocks in statics are limited to items and tail expressions
162+
//~| ERROR blocks in statics are limited to items and tail expressions
163+
//~| ERROR blocks in statics are limited to items and tail expressions
164+
//~| ERROR function calls in statics are limited to struct and enum constructors
165+
//~| ERROR function calls in statics are limited to struct and enum constructors
166+
//~| ERROR function calls in statics are limited to struct and enum constructors
167+
//~| ERROR function calls in statics are limited to struct and enum constructors
168+
//~| ERROR paths in statics may only refer to constants or functions
169+
//~| ERROR paths in statics may only refer to constants or functions
170+
//~| ERROR paths in statics may only refer to constants or functions
171+
//~| ERROR paths in statics may only refer to constants or functions
172+
//~| ERROR references in statics may only refer to immutable values
126173
];
127174

128175
static STATIC16: (&'static Box<MyOwned>, &'static Box<MyOwned>) = (
129-
&box MyOwned, //~ ERROR allocations are not allowed in statics
130-
&box MyOwned, //~ ERROR allocations are not allowed in statics
176+
&box MyOwned,
177+
//~^ ERROR statics are not allowed to have destructors
178+
//~| ERROR statics are not allowed to have destructors
179+
//~| ERROR statics are not allowed to have destructors
180+
//~| ERROR blocks in statics are limited to items and tail expressions
181+
//~| ERROR blocks in statics are limited to items and tail expressions
182+
//~| ERROR blocks in statics are limited to items and tail expressions
183+
//~| ERROR blocks in statics are limited to items and tail expressions
184+
//~| ERROR function calls in statics are limited to struct and enum constructors
185+
//~| ERROR function calls in statics are limited to struct and enum constructors
186+
//~| ERROR function calls in statics are limited to struct and enum constructors
187+
//~| ERROR function calls in statics are limited to struct and enum constructors
188+
//~| ERROR paths in statics may only refer to constants or functions
189+
//~| ERROR paths in statics may only refer to constants or functions
190+
//~| ERROR paths in statics may only refer to constants or functions
191+
//~| ERROR paths in statics may only refer to constants or functions
192+
//~| ERROR references in statics may only refer to immutable values
193+
&box MyOwned,
194+
//~^ ERROR statics are not allowed to have destructors
195+
//~| ERROR statics are not allowed to have destructors
196+
//~| ERROR statics are not allowed to have destructors
197+
//~| ERROR blocks in statics are limited to items and tail expressions
198+
//~| ERROR blocks in statics are limited to items and tail expressions
199+
//~| ERROR blocks in statics are limited to items and tail expressions
200+
//~| ERROR blocks in statics are limited to items and tail expressions
201+
//~| ERROR function calls in statics are limited to struct and enum constructors
202+
//~| ERROR function calls in statics are limited to struct and enum constructors
203+
//~| ERROR function calls in statics are limited to struct and enum constructors
204+
//~| ERROR function calls in statics are limited to struct and enum constructors
205+
//~| ERROR paths in statics may only refer to constants or functions
206+
//~| ERROR paths in statics may only refer to constants or functions
207+
//~| ERROR paths in statics may only refer to constants or functions
208+
//~| ERROR paths in statics may only refer to constants or functions
209+
//~| ERROR references in statics may only refer to immutable values
131210
);
132211

133212
static mut STATIC17: SafeEnum = SafeEnum::Variant1;
134213
//~^ ERROR mutable statics are not allowed to have destructors
135214

136215
static STATIC19: Box<isize> =
137216
box 3;
138-
//~^ ERROR allocations are not allowed in statics
217+
//~^ ERROR statics are not allowed to have destructors
218+
//~| ERROR statics are not allowed to have destructors
219+
//~| ERROR statics are not allowed to have destructors
220+
//~| ERROR blocks in statics are limited to items and tail expressions
221+
//~| ERROR blocks in statics are limited to items and tail expressions
222+
//~| ERROR blocks in statics are limited to items and tail expressions
223+
//~| ERROR blocks in statics are limited to items and tail expressions
224+
//~| ERROR function calls in statics are limited to struct and enum constructors
225+
//~| ERROR function calls in statics are limited to struct and enum constructors
226+
//~| ERROR function calls in statics are limited to struct and enum constructors
227+
//~| ERROR function calls in statics are limited to struct and enum constructors
228+
//~| ERROR paths in statics may only refer to constants or functions
229+
//~| ERROR paths in statics may only refer to constants or functions
230+
//~| ERROR paths in statics may only refer to constants or functions
231+
//~| ERROR paths in statics may only refer to constants or functions
232+
//~| ERROR references in statics may only refer to immutable values
139233

140234
pub fn main() {
141235
let y = { static x: Box<isize> = box 3; x };
142-
//~^ ERROR allocations are not allowed in statics
236+
//~^ ERROR statics are not allowed to have destructors
237+
//~| ERROR statics are not allowed to have destructors
238+
//~| ERROR statics are not allowed to have destructors
239+
//~| ERROR blocks in statics are limited to items and tail expressions
240+
//~| ERROR blocks in statics are limited to items and tail expressions
241+
//~| ERROR blocks in statics are limited to items and tail expressions
242+
//~| ERROR blocks in statics are limited to items and tail expressions
243+
//~| ERROR function calls in statics are limited to struct and enum constructors
244+
//~| ERROR function calls in statics are limited to struct and enum constructors
245+
//~| ERROR function calls in statics are limited to struct and enum constructors
246+
//~| ERROR function calls in statics are limited to struct and enum constructors
247+
//~| ERROR paths in statics may only refer to constants or functions
248+
//~| ERROR paths in statics may only refer to constants or functions
249+
//~| ERROR paths in statics may only refer to constants or functions
250+
//~| ERROR paths in statics may only refer to constants or functions
251+
//~| ERROR references in statics may only refer to immutable values
143252
}

src/test/compile-fail/dst-rvalue.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@
1414

1515
pub fn main() {
1616
let _x: Box<str> = box *"hello world";
17-
//~^ ERROR E0161
18-
//~^^ ERROR cannot move out of borrowed content
17+
//~^ ERROR E0277
18+
//~| ERROR the trait `core::marker::Sized` is not implemented for the type `str`
19+
//~| ERROR the trait `core::marker::Sized` is not implemented for the type `str`
20+
//~| ERROR the trait `core::marker::Sized` is not implemented for the type `str`
1921

2022
let array: &[isize] = &[1, 2, 3];
2123
let _x: Box<[isize]> = box *array;
22-
//~^ ERROR E0161
23-
//~^^ ERROR cannot move out of borrowed content
24+
//~^ ERROR E0277
25+
//~| ERROR the trait `core::marker::Sized` is not implemented for the type `[isize]`
26+
//~| ERROR the trait `core::marker::Sized` is not implemented for the type `[isize]`
27+
//~| ERROR the trait `core::marker::Sized` is not implemented for the type `[isize]`
2428
}

src/test/compile-fail/issue-14084.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(box_syntax)]
11+
#![feature(placement_in_syntax)]
1212

1313
fn main() {
14-
box ( () ) 0;
15-
//~^ ERROR: only the managed heap and exchange heap are currently supported
14+
let _bx: Box<_> = box ( () ) 0;
15+
//~^ ERROR: the trait `core::ops::Placer<_>` is not implemented for the type `()`
16+
//~| ERROR: the trait `core::ops::Placer<_>` is not implemented for the type `()`
1617
}

src/test/compile-fail/issue-7364.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,24 @@ use std::cell::RefCell;
1414

1515
// Regression test for issue 7364
1616
static boxed: Box<RefCell<isize>> = box RefCell::new(0);
17-
//~^ ERROR allocations are not allowed in statics
17+
//~^ ERROR statics are not allowed to have destructors
18+
//~| ERROR statics are not allowed to have destructors
19+
//~| ERROR statics are not allowed to have destructors
1820
//~| ERROR the trait `core::marker::Sync` is not implemented for the type
1921
//~| ERROR the trait `core::marker::Sync` is not implemented for the type
22+
//~| ERROR blocks in statics are limited to items and tail expressions
23+
//~| ERROR blocks in statics are limited to items and tail expressions
24+
//~| ERROR blocks in statics are limited to items and tail expressions
25+
//~| ERROR blocks in statics are limited to items and tail expressions
2026
//~| ERROR function calls in statics are limited to struct and enum constructors
27+
//~| ERROR function calls in statics are limited to struct and enum constructors
28+
//~| ERROR function calls in statics are limited to struct and enum constructors
29+
//~| ERROR function calls in statics are limited to struct and enum constructors
30+
//~| ERROR function calls in statics are limited to struct and enum constructors
31+
//~| ERROR paths in statics may only refer to constants or functions
32+
//~| ERROR paths in statics may only refer to constants or functions
33+
//~| ERROR paths in statics may only refer to constants or functions
34+
//~| ERROR paths in statics may only refer to constants or functions
35+
//~| ERROR references in statics may only refer to immutable values
2136

2237
fn main() { }

src/test/compile-fail/lint-owned-heap-memory.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#![allow(dead_code)]
1212
#![forbid(box_pointers)]
1313
#![feature(box_syntax)]
14+
#![feature(core)]
1415

1516
struct Foo {
1617
x: Box<isize> //~ ERROR type uses owned
@@ -19,4 +20,7 @@ struct Foo {
1920
fn main() {
2021
let _x : Foo = Foo {x : box 10};
2122
//~^ ERROR type uses owned
23+
//~| ERROR type uses owned
24+
//~| ERROR type uses owned
25+
//~| ERROR type uses owned
2226
}

src/test/compile-fail/occurs-check-2.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,21 @@
1111
#![feature(box_syntax)]
1212

1313
fn main() {
14-
let f;
14+
let f: Box<_>;
1515
let g;
1616
g = f;
1717
f = box g;
18-
//~^ ERROR mismatched types
19-
//~| expected `_`
20-
//~| found `Box<_>`
21-
//~| cyclic type of infinite size
18+
//~^ ERROR the trait `core::ops::Place<Box<_>>` is not implemented for the type
19+
20+
// (At one time, we produced a nicer error message like below.
21+
// but right now, the desugaring produces the above error instead
22+
// for the cyclic type here; its especially unfortunate because
23+
// printed error leaves out the information necessary for one to
24+
// deduce that the necessary type for the given impls *is*
25+
// cyclic.)
26+
//
27+
// ^ ERROR mismatched types
28+
// | expected `_`
29+
// | found `Box<_>`
30+
// | cyclic type of infinite size
2231
}

src/test/compile-fail/occurs-check.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,19 @@
1111
#![feature(box_syntax)]
1212

1313
fn main() {
14-
let f;
14+
let f: Box<_>;
1515
f = box f;
16-
//~^ ERROR mismatched types
17-
//~| expected `_`
18-
//~| found `Box<_>`
19-
//~| cyclic type of infinite size
16+
//~^ ERROR the trait `core::ops::Place<Box<_>>` is not implemented for the type
17+
18+
// (At one time, we produced a nicer error message like below.
19+
// but right now, the desugaring produces the above error instead
20+
// for the cyclic type here; its especially unfortunate because
21+
// printed error leaves out the information necessary for one to
22+
// deduce that the necessary type for the given impls *is*
23+
// cyclic.)
24+
//
25+
// ^ ERROR mismatched types
26+
// | expected `_`
27+
// | found `Box<_>`
28+
// | cyclic type of infinite size
2029
}

src/test/compile-fail/static-mut-not-constant.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,23 @@
1111
#![feature(box_syntax)]
1212

1313
static mut a: Box<isize> = box 3;
14-
//~^ ERROR allocations are not allowed in statics
15-
//~^^ ERROR mutable statics are not allowed to have owned pointers
14+
//~^ ERROR mutable statics are not allowed to have owned pointers
15+
//~| ERROR statics are not allowed to have destructors
16+
//^| ERROR statics are not allowed to have destructors
17+
//~| ERROR statics are not allowed to have destructors
18+
//~| ERROR statics are not allowed to have destructors
19+
//~| ERROR blocks in statics are limited to items and tail expressions
20+
//~| ERROR blocks in statics are limited to items and tail expressions
21+
//~| ERROR blocks in statics are limited to items and tail expressions
22+
//~| ERROR blocks in statics are limited to items and tail expressions
23+
//~| ERROR function calls in statics are limited to struct and enum constructors
24+
//~| ERROR function calls in statics are limited to struct and enum constructors
25+
//~| ERROR function calls in statics are limited to struct and enum constructors
26+
//~| ERROR function calls in statics are limited to struct and enum constructors
27+
//~| ERROR paths in statics may only refer to constants or functions
28+
//~| ERROR paths in statics may only refer to constants or functions
29+
//~| ERROR paths in statics may only refer to constants or functions
30+
//~| ERROR paths in statics may only refer to constants or functions
31+
//~| ERROR references in statics may only refer to immutable values
1632

1733
fn main() {}

0 commit comments

Comments
 (0)