Skip to content

Commit fe1e292

Browse files
committed
Revert performing basic const checks in typeck on stable
1 parent bcded33 commit fe1e292

35 files changed

+158
-276
lines changed

compiler/rustc_hir_typeck/src/callee.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
921921
callee_did: DefId,
922922
callee_args: GenericArgsRef<'tcx>,
923923
) {
924+
// FIXME(const_trait_impl): We should be enforcing these effects unconditionally.
925+
// This can be done as soon as we convert the standard library back to
926+
// using const traits, since if we were to enforce these conditions now,
927+
// we'd fail on basically every builtin trait call (i.e. `1 + 2`).
928+
if !self.tcx.features().const_trait_impl() {
929+
return;
930+
}
931+
924932
// If we have `rustc_do_not_const_check`, do not check `[const]` bounds.
925933
if self.has_rustc_attrs && find_attr!(self.tcx, self.body_id, RustcDoNotConstCheck) {
926934
return;

tests/crashes/137187.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
//@ known-bug: #137187
2-
#![feature(const_trait_impl, const_ops)]
3-
42
use std::ops::Add;
3+
54
const trait A where
6-
*const Self: const Add,
5+
*const Self: Add,
76
{
87
fn b(c: *const Self) -> <*const Self as Add>::Output {
98
c + c
109
}
1110
}
12-
13-
fn main() {}

tests/ui/coercion/coerce-loop-issue-122561.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ fn for_single_line() -> bool { for i in 0.. { return false; } }
4242
// that it's readable
4343
fn for_in_arg(a: &[(); for x in 0..2 {}]) -> bool {
4444
//~^ ERROR mismatched types
45-
//~| ERROR `std::ops::Range<{integer}>: const Iterator` is not satisfied
46-
//~| ERROR `std::ops::Range<{integer}>: const Iterator` is not satisfied
4745
true
4846
}
4947

@@ -88,17 +86,13 @@ fn loop_() -> bool {
8886
const C: i32 = {
8987
for i in 0.. {
9088
//~^ ERROR mismatched types
91-
//~| ERROR `std::ops::RangeFrom<{integer}>: const Iterator` is not satisfied
92-
//~| ERROR `std::ops::RangeFrom<{integer}>: const Iterator` is not satisfied
9389
}
9490
};
9591

9692
fn main() {
9793
let _ = [10; {
9894
for i in 0..5 {
9995
//~^ ERROR mismatched types
100-
//~| ERROR `std::ops::Range<{integer}>: const Iterator` is not satisfied
101-
//~| ERROR `std::ops::Range<{integer}>: const Iterator` is not satisfied
10296
}
10397
}];
10498

@@ -111,6 +105,4 @@ fn main() {
111105

112106
let _ = |a: &[(); for x in 0..2 {}]| {};
113107
//~^ ERROR mismatched types
114-
//~| ERROR `std::ops::Range<{integer}>: const Iterator` is not satisfied
115-
//~| ERROR `std::ops::Range<{integer}>: const Iterator` is not satisfied
116108
}

tests/ui/coercion/coerce-loop-issue-122561.stderr

Lines changed: 14 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,17 @@
11
warning: denote infinite loops with `loop { ... }`
2-
--> $DIR/coerce-loop-issue-122561.rs:51:5
2+
--> $DIR/coerce-loop-issue-122561.rs:49:5
33
|
44
LL | while true {
55
| ^^^^^^^^^^ help: use `loop`
66
|
77
= note: `#[warn(while_true)]` on by default
88

99
warning: denote infinite loops with `loop { ... }`
10-
--> $DIR/coerce-loop-issue-122561.rs:75:5
10+
--> $DIR/coerce-loop-issue-122561.rs:73:5
1111
|
1212
LL | while true {
1313
| ^^^^^^^^^^ help: use `loop`
1414

15-
error[E0277]: the trait bound `std::ops::Range<{integer}>: const Iterator` is not satisfied
16-
--> $DIR/coerce-loop-issue-122561.rs:43:33
17-
|
18-
LL | fn for_in_arg(a: &[(); for x in 0..2 {}]) -> bool {
19-
| ^^^^ required by a bound introduced by this call
20-
|
21-
note: trait `Iterator` is implemented but not `const`
22-
--> $SRC_DIR/core/src/iter/range.rs:LL:COL
23-
= note: required for `std::ops::Range<{integer}>` to implement `const IntoIterator`
24-
25-
error[E0277]: the trait bound `std::ops::Range<{integer}>: const Iterator` is not satisfied
26-
--> $DIR/coerce-loop-issue-122561.rs:43:33
27-
|
28-
LL | fn for_in_arg(a: &[(); for x in 0..2 {}]) -> bool {
29-
| ^^^^
30-
|
31-
note: trait `Iterator` is implemented but not `const`
32-
--> $SRC_DIR/core/src/iter/range.rs:LL:COL
33-
3415
error[E0308]: mismatched types
3516
--> $DIR/coerce-loop-issue-122561.rs:43:24
3617
|
@@ -131,7 +112,7 @@ LL | fn for_single_line() -> bool { for i in 0.. { return false; } /* `bool` val
131112
| ++++++++++++++++++
132113

133114
error[E0308]: mismatched types
134-
--> $DIR/coerce-loop-issue-122561.rs:51:5
115+
--> $DIR/coerce-loop-issue-122561.rs:49:5
135116
|
136117
LL | fn while_inifinite() -> bool {
137118
| ---- expected `bool` because of return type
@@ -150,7 +131,7 @@ LL + /* `bool` value */
150131
|
151132

152133
error[E0308]: mismatched types
153-
--> $DIR/coerce-loop-issue-122561.rs:60:5
134+
--> $DIR/coerce-loop-issue-122561.rs:58:5
154135
|
155136
LL | fn while_finite() -> bool {
156137
| ---- expected `bool` because of return type
@@ -170,7 +151,7 @@ LL + /* `bool` value */
170151
|
171152

172153
error[E0308]: mismatched types
173-
--> $DIR/coerce-loop-issue-122561.rs:68:5
154+
--> $DIR/coerce-loop-issue-122561.rs:66:5
174155
|
175156
LL | fn while_zero_times() -> bool {
176157
| ---- expected `bool` because of return type
@@ -188,7 +169,7 @@ LL + /* `bool` value */
188169
|
189170

190171
error[E0308]: mismatched types
191-
--> $DIR/coerce-loop-issue-122561.rs:75:5
172+
--> $DIR/coerce-loop-issue-122561.rs:73:5
192173
|
193174
LL | fn while_never_type() -> ! {
194175
| - expected `!` because of return type
@@ -206,30 +187,11 @@ LL ~ }
206187
LL + /* `loop {}` or `panic!("...")` */
207188
|
208189

209-
error[E0277]: the trait bound `std::ops::RangeFrom<{integer}>: const Iterator` is not satisfied
210-
--> $DIR/coerce-loop-issue-122561.rs:89:14
211-
|
212-
LL | for i in 0.. {
213-
| ^^^ required by a bound introduced by this call
214-
|
215-
note: trait `Iterator` is implemented but not `const`
216-
--> $SRC_DIR/core/src/iter/range.rs:LL:COL
217-
= note: required for `std::ops::RangeFrom<{integer}>` to implement `const IntoIterator`
218-
219-
error[E0277]: the trait bound `std::ops::RangeFrom<{integer}>: const Iterator` is not satisfied
220-
--> $DIR/coerce-loop-issue-122561.rs:89:14
221-
|
222-
LL | for i in 0.. {
223-
| ^^^
224-
|
225-
note: trait `Iterator` is implemented but not `const`
226-
--> $SRC_DIR/core/src/iter/range.rs:LL:COL
227-
228190
error[E0308]: mismatched types
229-
--> $DIR/coerce-loop-issue-122561.rs:89:5
191+
--> $DIR/coerce-loop-issue-122561.rs:87:5
230192
|
231193
LL | / for i in 0.. {
232-
... |
194+
LL | |
233195
LL | | }
234196
| |_____^ expected `i32`, found `()`
235197
|
@@ -240,30 +202,11 @@ LL ~ }
240202
LL + /* `i32` value */
241203
|
242204

243-
error[E0277]: the trait bound `std::ops::Range<{integer}>: const Iterator` is not satisfied
244-
--> $DIR/coerce-loop-issue-122561.rs:98:18
245-
|
246-
LL | for i in 0..5 {
247-
| ^^^^ required by a bound introduced by this call
248-
|
249-
note: trait `Iterator` is implemented but not `const`
250-
--> $SRC_DIR/core/src/iter/range.rs:LL:COL
251-
= note: required for `std::ops::Range<{integer}>` to implement `const IntoIterator`
252-
253-
error[E0277]: the trait bound `std::ops::Range<{integer}>: const Iterator` is not satisfied
254-
--> $DIR/coerce-loop-issue-122561.rs:98:18
255-
|
256-
LL | for i in 0..5 {
257-
| ^^^^
258-
|
259-
note: trait `Iterator` is implemented but not `const`
260-
--> $SRC_DIR/core/src/iter/range.rs:LL:COL
261-
262205
error[E0308]: mismatched types
263-
--> $DIR/coerce-loop-issue-122561.rs:98:9
206+
--> $DIR/coerce-loop-issue-122561.rs:94:9
264207
|
265208
LL | / for i in 0..5 {
266-
... |
209+
LL | |
267210
LL | | }
268211
| |_________^ expected `usize`, found `()`
269212
|
@@ -275,7 +218,7 @@ LL + /* `usize` value */
275218
|
276219

277220
error[E0308]: mismatched types
278-
--> $DIR/coerce-loop-issue-122561.rs:106:9
221+
--> $DIR/coerce-loop-issue-122561.rs:100:9
279222
|
280223
LL | / while false {
281224
LL | |
@@ -289,27 +232,8 @@ LL ~ }
289232
LL + /* `usize` value */
290233
|
291234

292-
error[E0277]: the trait bound `std::ops::Range<{integer}>: const Iterator` is not satisfied
293-
--> $DIR/coerce-loop-issue-122561.rs:112:32
294-
|
295-
LL | let _ = |a: &[(); for x in 0..2 {}]| {};
296-
| ^^^^ required by a bound introduced by this call
297-
|
298-
note: trait `Iterator` is implemented but not `const`
299-
--> $SRC_DIR/core/src/iter/range.rs:LL:COL
300-
= note: required for `std::ops::Range<{integer}>` to implement `const IntoIterator`
301-
302-
error[E0277]: the trait bound `std::ops::Range<{integer}>: const Iterator` is not satisfied
303-
--> $DIR/coerce-loop-issue-122561.rs:112:32
304-
|
305-
LL | let _ = |a: &[(); for x in 0..2 {}]| {};
306-
| ^^^^
307-
|
308-
note: trait `Iterator` is implemented but not `const`
309-
--> $SRC_DIR/core/src/iter/range.rs:LL:COL
310-
311235
error[E0308]: mismatched types
312-
--> $DIR/coerce-loop-issue-122561.rs:112:23
236+
--> $DIR/coerce-loop-issue-122561.rs:106:23
313237
|
314238
LL | let _ = |a: &[(); for x in 0..2 {}]| {};
315239
| ^^^^^^^^^^^^^^^^ expected `usize`, found `()`
@@ -320,7 +244,6 @@ help: consider returning a value here
320244
LL | let _ = |a: &[(); for x in 0..2 {} /* `usize` value */]| {};
321245
| +++++++++++++++++++
322246

323-
error: aborting due to 22 previous errors; 2 warnings emitted
247+
error: aborting due to 14 previous errors; 2 warnings emitted
324248

325-
Some errors have detailed explanations: E0277, E0308.
326-
For more information about an error, try `rustc --explain E0277`.
249+
For more information about this error, try `rustc --explain E0308`.
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
1-
error[E0277]: pointers cannot be reliably compared during const eval
1+
error: pointers cannot be reliably compared during const eval
22
--> $DIR/const_raw_ptr_ops.rs:7:26
33
|
44
LL | const X: bool = unsafe { &1 as *const i32 == &2 as *const i32 };
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
note: trait `PartialEq` is implemented but not `const`
8-
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
97
= note: see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information
108

11-
error[E0277]: pointers cannot be reliably compared during const eval
9+
error: pointers cannot be reliably compared during const eval
1210
--> $DIR/const_raw_ptr_ops.rs:9:27
1311
|
1412
LL | const X2: bool = unsafe { 42 as *const i32 == 43 as *const i32 };
1513
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1614
|
17-
note: trait `PartialEq` is implemented but not `const`
18-
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
1915
= note: see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information
2016

2117
error: aborting due to 2 previous errors
2218

23-
For more information about this error, try `rustc --explain E0277`.

tests/ui/consts/const-fn-error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ const X : usize = 2;
33
const fn f(x: usize) -> usize {
44
let mut sum = 0;
55
for i in 0..x {
6-
//~^ ERROR `std::ops::Range<usize>: [const] Iterator` is not satisfied
7-
//~| ERROR `std::ops::Range<usize>: [const] Iterator` is not satisfied
6+
//~^ ERROR cannot use `for`
7+
//~| ERROR cannot use `for`
88
sum += i;
99
}
1010
sum
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
error[E0277]: the trait bound `std::ops::Range<usize>: [const] Iterator` is not satisfied
1+
error[E0015]: cannot use `for` loop on `std::ops::Range<usize>` in constant functions
22
--> $DIR/const-fn-error.rs:5:14
33
|
44
LL | for i in 0..x {
5-
| ^^^^ required by a bound introduced by this call
5+
| ^^^^
66
|
7-
note: trait `Iterator` is implemented but not `const`
8-
--> $SRC_DIR/core/src/iter/range.rs:LL:COL
9-
= note: required for `std::ops::Range<usize>` to implement `[const] IntoIterator`
7+
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
108

11-
error[E0277]: the trait bound `std::ops::Range<usize>: [const] Iterator` is not satisfied
9+
error[E0015]: cannot use `for` loop on `std::ops::Range<usize>` in constant functions
1210
--> $DIR/const-fn-error.rs:5:14
1311
|
1412
LL | for i in 0..x {
1513
| ^^^^
1614
|
17-
note: trait `Iterator` is implemented but not `const`
18-
--> $SRC_DIR/core/src/iter/range.rs:LL:COL
15+
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
16+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
1917

2018
error: aborting due to 2 previous errors
2119

22-
For more information about this error, try `rustc --explain E0277`.
20+
For more information about this error, try `rustc --explain E0015`.

tests/ui/consts/const-for-feature-gate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
const _: () = {
44
for _ in 0..5 {}
5-
//~^ ERROR `std::ops::Range<{integer}>: const Iterator` is not satisfied
6-
//~| ERROR `std::ops::Range<{integer}>: const Iterator` is not satisfied
5+
//~^ ERROR cannot use `for`
6+
//~| ERROR cannot use `for`
77
};
88

99
fn main() {}
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
error[E0277]: the trait bound `std::ops::Range<{integer}>: const Iterator` is not satisfied
1+
error[E0015]: cannot use `for` loop on `std::ops::Range<i32>` in constants
22
--> $DIR/const-for-feature-gate.rs:4:14
33
|
44
LL | for _ in 0..5 {}
5-
| ^^^^ required by a bound introduced by this call
5+
| ^^^^
66
|
7-
note: trait `Iterator` is implemented but not `const`
8-
--> $SRC_DIR/core/src/iter/range.rs:LL:COL
9-
= note: required for `std::ops::Range<{integer}>` to implement `const IntoIterator`
7+
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
108

11-
error[E0277]: the trait bound `std::ops::Range<{integer}>: const Iterator` is not satisfied
9+
error[E0015]: cannot use `for` loop on `std::ops::Range<i32>` in constants
1210
--> $DIR/const-for-feature-gate.rs:4:14
1311
|
1412
LL | for _ in 0..5 {}
1513
| ^^^^
1614
|
17-
note: trait `Iterator` is implemented but not `const`
18-
--> $SRC_DIR/core/src/iter/range.rs:LL:COL
15+
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
16+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
1917

2018
error: aborting due to 2 previous errors
2119

22-
For more information about this error, try `rustc --explain E0277`.
20+
For more information about this error, try `rustc --explain E0015`.

tests/ui/consts/const-for.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
const _: () = {
44
for _ in 0..5 {}
5-
//~^ ERROR `std::ops::Range<{integer}>: const Iterator` is not satisfied
6-
//~| ERROR `std::ops::Range<{integer}>: const Iterator` is not satisfied
5+
//~^ ERROR cannot use `for`
6+
//~| ERROR cannot use `for`
77
};
88

99
fn main() {}

0 commit comments

Comments
 (0)