Skip to content

Commit 4cac90c

Browse files
Move const fn floating point test out of min_const_fn
1 parent b428f28 commit 4cac90c

5 files changed

+94
-62
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: fatal error triggered by #[rustc_error]
2+
--> $DIR/const_fn_floating_point_arithmetic.rs:20:1
3+
|
4+
LL | fn main() {}
5+
| ^^^^^^^^^
6+
7+
error: aborting due to previous error
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// gate-test-const_fn_floating_point_arithmetic
2+
3+
// revisions: stock gated
4+
5+
#![feature(rustc_attrs)]
6+
#![cfg_attr(gated, feature(const_fn_floating_point_arithmetic))]
7+
8+
const fn add(f: f32) -> f32 { f + 2.0 }
9+
//[stock]~^ floating point arithmetic
10+
const fn sub(f: f32) -> f32 { 2.0 - f }
11+
//[stock]~^ floating point arithmetic
12+
const fn mul(f: f32, g: f32) -> f32 { f * g }
13+
//[stock]~^ floating point arithmetic
14+
const fn div(f: f32, g: f32) -> f32 { f / g }
15+
//[stock]~^ floating point arithmetic
16+
const fn neg(f: f32) -> f32 { -f }
17+
//[stock]~^ floating point arithmetic
18+
19+
#[rustc_error]
20+
fn main() {} //[gated]~ fatal error triggered by #[rustc_error]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
error[E0658]: floating point arithmetic is not allowed in constant functions
2+
--> $DIR/const_fn_floating_point_arithmetic.rs:8:31
3+
|
4+
LL | const fn add(f: f32) -> f32 { f + 2.0 }
5+
| ^^^^^^^
6+
|
7+
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
8+
= help: add `#![feature(const_fn_floating_point_arithmetic)]` to the crate attributes to enable
9+
10+
error[E0658]: floating point arithmetic is not allowed in constant functions
11+
--> $DIR/const_fn_floating_point_arithmetic.rs:10:31
12+
|
13+
LL | const fn sub(f: f32) -> f32 { 2.0 - f }
14+
| ^^^^^^^
15+
|
16+
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
17+
= help: add `#![feature(const_fn_floating_point_arithmetic)]` to the crate attributes to enable
18+
19+
error[E0658]: floating point arithmetic is not allowed in constant functions
20+
--> $DIR/const_fn_floating_point_arithmetic.rs:12:39
21+
|
22+
LL | const fn mul(f: f32, g: f32) -> f32 { f * g }
23+
| ^^^^^
24+
|
25+
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
26+
= help: add `#![feature(const_fn_floating_point_arithmetic)]` to the crate attributes to enable
27+
28+
error[E0658]: floating point arithmetic is not allowed in constant functions
29+
--> $DIR/const_fn_floating_point_arithmetic.rs:14:39
30+
|
31+
LL | const fn div(f: f32, g: f32) -> f32 { f / g }
32+
| ^^^^^
33+
|
34+
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
35+
= help: add `#![feature(const_fn_floating_point_arithmetic)]` to the crate attributes to enable
36+
37+
error[E0658]: floating point arithmetic is not allowed in constant functions
38+
--> $DIR/const_fn_floating_point_arithmetic.rs:16:31
39+
|
40+
LL | const fn neg(f: f32) -> f32 { -f }
41+
| ^^
42+
|
43+
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
44+
= help: add `#![feature(const_fn_floating_point_arithmetic)]` to the crate attributes to enable
45+
46+
error: aborting due to 5 previous errors
47+
48+
For more information about this error, try `rustc --explain E0658`.

src/test/ui/consts/min_const_fn/min_const_fn.rs

-8
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,6 @@ const fn foo11<T: std::fmt::Display>(t: T) -> T { t }
7777
//~^ ERROR trait bounds other than `Sized` on const fn parameters are unstable
7878
const fn foo11_2<T: Send>(t: T) -> T { t }
7979
//~^ ERROR trait bounds other than `Sized` on const fn parameters are unstable
80-
const fn foo19(f: f32) -> f32 { f * 2.0 }
81-
//~^ ERROR floating point arithmetic
82-
const fn foo19_2(f: f32) -> f32 { 2.0 - f }
83-
//~^ ERROR floating point arithmetic
84-
const fn foo19_3(f: f32) -> f32 { -f }
85-
//~^ ERROR floating point arithmetic
86-
const fn foo19_4(f: f32, g: f32) -> f32 { f / g }
87-
//~^ ERROR floating point arithmetic
8880

8981
static BAR: u32 = 42;
9082
const fn foo25() -> u32 { BAR } //~ ERROR cannot refer to statics

src/test/ui/consts/min_const_fn/min_const_fn.stderr

+18-54
Original file line numberDiff line numberDiff line change
@@ -76,60 +76,24 @@ LL | const fn foo11_2<T: Send>(t: T) -> T { t }
7676
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
7777
= help: add `#![feature(const_fn)]` to the crate attributes to enable
7878

79-
error[E0658]: floating point arithmetic is not allowed in constant functions
80-
--> $DIR/min_const_fn.rs:80:33
81-
|
82-
LL | const fn foo19(f: f32) -> f32 { f * 2.0 }
83-
| ^^^^^^^
84-
|
85-
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
86-
= help: add `#![feature(const_fn_floating_point_arithmetic)]` to the crate attributes to enable
87-
88-
error[E0658]: floating point arithmetic is not allowed in constant functions
89-
--> $DIR/min_const_fn.rs:82:35
90-
|
91-
LL | const fn foo19_2(f: f32) -> f32 { 2.0 - f }
92-
| ^^^^^^^
93-
|
94-
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
95-
= help: add `#![feature(const_fn_floating_point_arithmetic)]` to the crate attributes to enable
96-
97-
error[E0658]: floating point arithmetic is not allowed in constant functions
98-
--> $DIR/min_const_fn.rs:84:35
99-
|
100-
LL | const fn foo19_3(f: f32) -> f32 { -f }
101-
| ^^
102-
|
103-
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
104-
= help: add `#![feature(const_fn_floating_point_arithmetic)]` to the crate attributes to enable
105-
106-
error[E0658]: floating point arithmetic is not allowed in constant functions
107-
--> $DIR/min_const_fn.rs:86:43
108-
|
109-
LL | const fn foo19_4(f: f32, g: f32) -> f32 { f / g }
110-
| ^^^^^
111-
|
112-
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
113-
= help: add `#![feature(const_fn_floating_point_arithmetic)]` to the crate attributes to enable
114-
11579
error[E0013]: constant functions cannot refer to statics
116-
--> $DIR/min_const_fn.rs:90:27
80+
--> $DIR/min_const_fn.rs:82:27
11781
|
11882
LL | const fn foo25() -> u32 { BAR }
11983
| ^^^
12084
|
12185
= help: consider extracting the value of the `static` to a `const`, and referring to that
12286

12387
error[E0013]: constant functions cannot refer to statics
124-
--> $DIR/min_const_fn.rs:91:37
88+
--> $DIR/min_const_fn.rs:83:37
12589
|
12690
LL | const fn foo26() -> &'static u32 { &BAR }
12791
| ^^^
12892
|
12993
= help: consider extracting the value of the `static` to a `const`, and referring to that
13094

13195
error[E0658]: casting pointers to integers in constant functions is unstable
132-
--> $DIR/min_const_fn.rs:92:42
96+
--> $DIR/min_const_fn.rs:84:42
13397
|
13498
LL | const fn foo30(x: *const u32) -> usize { x as usize }
13599
| ^^^^^^^^^^
@@ -138,7 +102,7 @@ LL | const fn foo30(x: *const u32) -> usize { x as usize }
138102
= help: add `#![feature(const_raw_ptr_to_usize_cast)]` to the crate attributes to enable
139103

140104
error[E0658]: casting pointers to integers in constant functions is unstable
141-
--> $DIR/min_const_fn.rs:94:63
105+
--> $DIR/min_const_fn.rs:86:63
142106
|
143107
LL | const fn foo30_with_unsafe(x: *const u32) -> usize { unsafe { x as usize } }
144108
| ^^^^^^^^^^
@@ -147,7 +111,7 @@ LL | const fn foo30_with_unsafe(x: *const u32) -> usize { unsafe { x as usize }
147111
= help: add `#![feature(const_raw_ptr_to_usize_cast)]` to the crate attributes to enable
148112

149113
error[E0658]: casting pointers to integers in constant functions is unstable
150-
--> $DIR/min_const_fn.rs:96:42
114+
--> $DIR/min_const_fn.rs:88:42
151115
|
152116
LL | const fn foo30_2(x: *mut u32) -> usize { x as usize }
153117
| ^^^^^^^^^^
@@ -156,7 +120,7 @@ LL | const fn foo30_2(x: *mut u32) -> usize { x as usize }
156120
= help: add `#![feature(const_raw_ptr_to_usize_cast)]` to the crate attributes to enable
157121

158122
error[E0658]: casting pointers to integers in constant functions is unstable
159-
--> $DIR/min_const_fn.rs:98:63
123+
--> $DIR/min_const_fn.rs:90:63
160124
|
161125
LL | const fn foo30_2_with_unsafe(x: *mut u32) -> usize { unsafe { x as usize } }
162126
| ^^^^^^^^^^
@@ -165,7 +129,7 @@ LL | const fn foo30_2_with_unsafe(x: *mut u32) -> usize { unsafe { x as usize }
165129
= help: add `#![feature(const_raw_ptr_to_usize_cast)]` to the crate attributes to enable
166130

167131
error[E0658]: mutable references are not allowed in constant functions
168-
--> $DIR/min_const_fn.rs:101:14
132+
--> $DIR/min_const_fn.rs:93:14
169133
|
170134
LL | const fn inc(x: &mut i32) { *x += 1 }
171135
| ^
@@ -174,7 +138,7 @@ LL | const fn inc(x: &mut i32) { *x += 1 }
174138
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
175139

176140
error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable
177-
--> $DIR/min_const_fn.rs:110:6
141+
--> $DIR/min_const_fn.rs:102:6
178142
|
179143
LL | impl<T: std::fmt::Debug> Foo<T> {
180144
| ^
@@ -183,7 +147,7 @@ LL | impl<T: std::fmt::Debug> Foo<T> {
183147
= help: add `#![feature(const_fn)]` to the crate attributes to enable
184148

185149
error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable
186-
--> $DIR/min_const_fn.rs:115:6
150+
--> $DIR/min_const_fn.rs:107:6
187151
|
188152
LL | impl<T: std::fmt::Debug + Sized> Foo<T> {
189153
| ^
@@ -192,7 +156,7 @@ LL | impl<T: std::fmt::Debug + Sized> Foo<T> {
192156
= help: add `#![feature(const_fn)]` to the crate attributes to enable
193157

194158
error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable
195-
--> $DIR/min_const_fn.rs:120:6
159+
--> $DIR/min_const_fn.rs:112:6
196160
|
197161
LL | impl<T: Sync + Sized> Foo<T> {
198162
| ^
@@ -201,7 +165,7 @@ LL | impl<T: Sync + Sized> Foo<T> {
201165
= help: add `#![feature(const_fn)]` to the crate attributes to enable
202166

203167
error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable
204-
--> $DIR/min_const_fn.rs:126:34
168+
--> $DIR/min_const_fn.rs:118:34
205169
|
206170
LL | const fn no_apit2(_x: AlanTuring<impl std::fmt::Debug>) {}
207171
| ^^^^^^^^^^^^^^^^^^^^
@@ -210,7 +174,7 @@ LL | const fn no_apit2(_x: AlanTuring<impl std::fmt::Debug>) {}
210174
= help: add `#![feature(const_fn)]` to the crate attributes to enable
211175

212176
error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable
213-
--> $DIR/min_const_fn.rs:128:22
177+
--> $DIR/min_const_fn.rs:120:22
214178
|
215179
LL | const fn no_apit(_x: impl std::fmt::Debug) {}
216180
| ^^^^^^^^^^^^^^^^^^^^
@@ -219,7 +183,7 @@ LL | const fn no_apit(_x: impl std::fmt::Debug) {}
219183
= help: add `#![feature(const_fn)]` to the crate attributes to enable
220184

221185
error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable
222-
--> $DIR/min_const_fn.rs:129:23
186+
--> $DIR/min_const_fn.rs:121:23
223187
|
224188
LL | const fn no_dyn_trait(_x: &dyn std::fmt::Debug) {}
225189
| ^^
@@ -228,7 +192,7 @@ LL | const fn no_dyn_trait(_x: &dyn std::fmt::Debug) {}
228192
= help: add `#![feature(const_fn)]` to the crate attributes to enable
229193

230194
error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable
231-
--> $DIR/min_const_fn.rs:130:32
195+
--> $DIR/min_const_fn.rs:122:32
232196
|
233197
LL | const fn no_dyn_trait_ret() -> &'static dyn std::fmt::Debug { &() }
234198
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -237,7 +201,7 @@ LL | const fn no_dyn_trait_ret() -> &'static dyn std::fmt::Debug { &() }
237201
= help: add `#![feature(const_fn)]` to the crate attributes to enable
238202

239203
error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable
240-
--> $DIR/min_const_fn.rs:135:41
204+
--> $DIR/min_const_fn.rs:127:41
241205
|
242206
LL | const fn really_no_traits_i_mean_it() { (&() as &dyn std::fmt::Debug, ()).1 }
243207
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -246,7 +210,7 @@ LL | const fn really_no_traits_i_mean_it() { (&() as &dyn std::fmt::Debug, ()).1
246210
= help: add `#![feature(const_fn)]` to the crate attributes to enable
247211

248212
error[E0723]: function pointers in const fn are unstable
249-
--> $DIR/min_const_fn.rs:138:21
213+
--> $DIR/min_const_fn.rs:130:21
250214
|
251215
LL | const fn no_fn_ptrs(_x: fn()) {}
252216
| ^^
@@ -255,15 +219,15 @@ LL | const fn no_fn_ptrs(_x: fn()) {}
255219
= help: add `#![feature(const_fn)]` to the crate attributes to enable
256220

257221
error[E0723]: function pointers in const fn are unstable
258-
--> $DIR/min_const_fn.rs:140:27
222+
--> $DIR/min_const_fn.rs:132:27
259223
|
260224
LL | const fn no_fn_ptrs2() -> fn() { fn foo() {} foo }
261225
| ^^^^
262226
|
263227
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
264228
= help: add `#![feature(const_fn)]` to the crate attributes to enable
265229

266-
error: aborting due to 30 previous errors
230+
error: aborting due to 26 previous errors
267231

268232
Some errors have detailed explanations: E0013, E0493, E0658, E0723.
269233
For more information about an error, try `rustc --explain E0013`.

0 commit comments

Comments
 (0)