Skip to content

Commit 1a2d233

Browse files
Auto merge of #149375 - oli-obk:const_typeck, r=<try>
Perform many const checks in typeck
2 parents a417515 + 3af479a commit 1a2d233

20 files changed

+85
-88
lines changed

compiler/rustc_hir_typeck/src/callee.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -904,14 +904,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
904904
callee_did: DefId,
905905
callee_args: GenericArgsRef<'tcx>,
906906
) {
907-
// FIXME(const_trait_impl): We should be enforcing these effects unconditionally.
908-
// This can be done as soon as we convert the standard library back to
909-
// using const traits, since if we were to enforce these conditions now,
910-
// we'd fail on basically every builtin trait call (i.e. `1 + 2`).
911-
if !self.tcx.features().const_trait_impl() {
912-
return;
913-
}
914-
915907
// If we have `rustc_do_not_const_check`, do not check `[const]` bounds.
916908
if self.has_rustc_attrs && self.tcx.has_attr(self.body_id, sym::rustc_do_not_const_check) {
917909
return;

tests/crashes/137187.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
//@ known-bug: #137187
2+
#![feature(const_trait_impl, const_ops)]
3+
24
use std::ops::Add;
3-
trait A where
4-
*const Self: Add,
5+
const trait A where
6+
*const Self: const Add,
57
{
6-
const fn b(c: *const Self) -> <*const Self as Add>::Output {
8+
fn b(c: *const Self) -> <*const Self as Add>::Output {
79
c + c
810
}
911
}
12+
13+
fn main() {}
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
1-
error: pointers cannot be reliably compared during const eval
1+
error[E0277]: 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
79
= note: see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information
810

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

1721
error: aborting due to 2 previous errors
1822

23+
For more information about this error, try `rustc --explain E0277`.
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
error: pointers cannot be reliably compared during const eval
1+
error[E0277]: pointers cannot be reliably compared during const eval
22
--> $DIR/different-fn-ptr-binders-during-ctfe.rs:5:5
33
|
44
LL | x == y
55
| ^^^^^^
66
|
7+
note: trait `PartialEq` is implemented but not `const`
8+
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
79
= note: see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information
810

911
error: aborting due to 1 previous error
1012

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

tests/ui/consts/issue-25826.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ fn id<T>(t: T) -> T { t }
22
fn main() {
33
const A: bool = unsafe { id::<u8> as *const () < id::<u16> as *const () };
44
//~^ ERROR pointers cannot
5+
//~| ERROR pointers cannot
56
println!("{}", A);
67
}

tests/ui/consts/issue-25826.stderr

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
1-
error: pointers cannot be reliably compared during const eval
1+
error[E0277]: pointers cannot be reliably compared during const eval
22
--> $DIR/issue-25826.rs:3:30
33
|
44
LL | const A: bool = unsafe { id::<u8> as *const () < id::<u16> as *const () };
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7+
note: trait `PartialOrd` is implemented but not `const`
8+
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
79
= note: see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information
810

9-
error: aborting due to 1 previous error
11+
error[E0277]: pointers cannot be reliably compared during const eval
12+
--> $DIR/issue-25826.rs:3:30
13+
|
14+
LL | const A: bool = unsafe { id::<u8> as *const () < id::<u16> as *const () };
15+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16+
|
17+
note: trait `PartialEq` is implemented but not `const`
18+
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
19+
= note: see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information
20+
note: required by a bound in `std::cmp::PartialOrd::lt`
21+
--> $SRC_DIR/core/src/cmp.rs:LL:COL
22+
23+
error: aborting due to 2 previous errors
1024

25+
For more information about this error, try `rustc --explain E0277`.
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
error: pointers cannot be reliably compared during const eval
1+
error[E0277]: pointers cannot be reliably compared during const eval
22
--> $DIR/cmp_fn_pointers.rs:2:14
33
|
44
LL | unsafe { x == y }
55
| ^^^^^^
66
|
7+
note: trait `PartialEq` is implemented but not `const`
8+
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
79
= note: see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information
810

911
error: aborting due to 1 previous error
1012

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

tests/ui/feature-gates/feature-gate-diagnostic-on-const.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use diagnostic_on_const::Foo;
1010

1111
const fn foo() {
1212
Foo == Foo;
13-
//~^ ERROR: cannot call non-const operator in constant functions
13+
//~^ ERROR: the trait bound `Foo: [const] PartialEq` is not satisfied
1414
}
1515

1616
fn main() {}
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
error[E0015]: cannot call non-const operator in constant functions
1+
error[E0277]: the trait bound `Foo: [const] PartialEq` is not satisfied
22
--> $DIR/feature-gate-diagnostic-on-const.rs:12:5
33
|
44
LL | Foo == Foo;
55
| ^^^^^^^^^^
66
|
7-
note: impl defined here, but it is not `const`
7+
note: trait `PartialEq` is implemented but not `const`
88
--> $DIR/auxiliary/diagnostic-on-const.rs:4:1
99
|
1010
LL | impl PartialEq for Foo {
1111
| ^^^^^^^^^^^^^^^^^^^^^^
12-
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
1312

1413
error: aborting due to 1 previous error
1514

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

tests/ui/issues/issue-25901.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ struct A;
22
struct B;
33

44
static S: &'static B = &A;
5-
//~^ ERROR cannot perform non-const deref coercion
5+
//~^ ERROR the trait bound `A: const Deref` is not satisfied
66

77
use std::ops::Deref;
88

0 commit comments

Comments
 (0)