Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions compiler/rustc_hir_typeck/src/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -904,14 +904,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
callee_did: DefId,
callee_args: GenericArgsRef<'tcx>,
) {
// FIXME(const_trait_impl): We should be enforcing these effects unconditionally.
// This can be done as soon as we convert the standard library back to
// using const traits, since if we were to enforce these conditions now,
// we'd fail on basically every builtin trait call (i.e. `1 + 2`).
if !self.tcx.features().const_trait_impl() {
return;
}

// If we have `rustc_do_not_const_check`, do not check `[const]` bounds.
if self.has_rustc_attrs && self.tcx.has_attr(self.body_id, sym::rustc_do_not_const_check) {
return;
Expand Down
10 changes: 7 additions & 3 deletions tests/crashes/137187.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
//@ known-bug: #137187
#![feature(const_trait_impl, const_ops)]

use std::ops::Add;
trait A where
*const Self: Add,
const trait A where
*const Self: const Add,
{
const fn b(c: *const Self) -> <*const Self as Add>::Output {
fn b(c: *const Self) -> <*const Self as Add>::Output {
c + c
}
}

fn main() {}
Comment on lines 1 to +13
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This produces the same ICE as before, but the changes were required to pass typeck so we'd actually get to mir const checks

9 changes: 7 additions & 2 deletions tests/ui/consts/const-eval/const_raw_ptr_ops.stable.stderr
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
error: pointers cannot be reliably compared during const eval
error[E0277]: pointers cannot be reliably compared during const eval
--> $DIR/const_raw_ptr_ops.rs:7:26
|
LL | const X: bool = unsafe { &1 as *const i32 == &2 as *const i32 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: trait `PartialEq` is implemented but not `const`
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
= note: see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information

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

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0277`.
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
error: pointers cannot be reliably compared during const eval
error[E0277]: pointers cannot be reliably compared during const eval
--> $DIR/different-fn-ptr-binders-during-ctfe.rs:5:5
|
LL | x == y
| ^^^^^^
|
note: trait `PartialEq` is implemented but not `const`
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
= note: see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0277`.
1 change: 1 addition & 0 deletions tests/ui/consts/issue-25826.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ fn id<T>(t: T) -> T { t }
fn main() {
const A: bool = unsafe { id::<u8> as *const () < id::<u16> as *const () };
//~^ ERROR pointers cannot
//~| ERROR pointers cannot
println!("{}", A);
}
19 changes: 17 additions & 2 deletions tests/ui/consts/issue-25826.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
error: pointers cannot be reliably compared during const eval
error[E0277]: pointers cannot be reliably compared during const eval
--> $DIR/issue-25826.rs:3:30
|
LL | const A: bool = unsafe { id::<u8> as *const () < id::<u16> as *const () };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: trait `PartialOrd` is implemented but not `const`
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
= note: see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information

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

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0277`.
5 changes: 4 additions & 1 deletion tests/ui/consts/min_const_fn/cmp_fn_pointers.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
error: pointers cannot be reliably compared during const eval
error[E0277]: pointers cannot be reliably compared during const eval
--> $DIR/cmp_fn_pointers.rs:2:14
|
LL | unsafe { x == y }
| ^^^^^^
|
note: trait `PartialEq` is implemented but not `const`
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
= note: see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0277`.
2 changes: 1 addition & 1 deletion tests/ui/feature-gates/feature-gate-diagnostic-on-const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use diagnostic_on_const::Foo;

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

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
error[E0015]: cannot call non-const operator in constant functions
error[E0277]: the trait bound `Foo: [const] PartialEq` is not satisfied
--> $DIR/feature-gate-diagnostic-on-const.rs:12:5
|
LL | Foo == Foo;
| ^^^^^^^^^^
|
note: impl defined here, but it is not `const`
note: trait `PartialEq` is implemented but not `const`
--> $DIR/auxiliary/diagnostic-on-const.rs:4:1
|
LL | impl PartialEq for Foo {
| ^^^^^^^^^^^^^^^^^^^^^^
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0015`.
For more information about this error, try `rustc --explain E0277`.
2 changes: 1 addition & 1 deletion tests/ui/issues/issue-25901.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ struct A;
struct B;

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

use std::ops::Deref;

Expand Down
19 changes: 5 additions & 14 deletions tests/ui/issues/issue-25901.stderr
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
error[E0015]: cannot perform non-const deref coercion on `A` in statics
error[E0277]: the trait bound `A: const Deref` is not satisfied
--> $DIR/issue-25901.rs:4:24
|
LL | static S: &'static B = &A;
| ^^
|
= note: attempting to deref into `B`
note: deref defined here
--> $DIR/issue-25901.rs:10:5
help: make the `impl` of trait `Deref` `const`
|
LL | type Target = B;
| ^^^^^^^^^^^
note: impl defined here, but it is not `const`
--> $DIR/issue-25901.rs:9:1
|
LL | impl Deref for A {
| ^^^^^^^^^^^^^^^^
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
LL | impl const Deref for A {
| +++++

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0015`.
For more information about this error, try `rustc --explain E0277`.
3 changes: 1 addition & 2 deletions tests/ui/self/arbitrary-self-from-method-substs-ice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ struct Foo(u32);
impl Foo {
const fn get<R: Deref<Target = Self>>(self: R) -> u32 {
//~^ ERROR invalid generic `self` parameter type
//~| ERROR destructor of `R` cannot be evaluated at compile-time
self.0
//~^ ERROR cannot perform non-const deref coercion on `R` in constant functions
//~^ ERROR the trait bound `R: [const] Deref` is not satisfied
}
}

Expand Down
24 changes: 6 additions & 18 deletions tests/ui/self/arbitrary-self-from-method-substs-ice.stderr
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
error[E0015]: cannot perform non-const deref coercion on `R` in constant functions
--> $DIR/arbitrary-self-from-method-substs-ice.rs:13:9
error[E0277]: the trait bound `R: [const] Deref` is not satisfied
--> $DIR/arbitrary-self-from-method-substs-ice.rs:12:9
|
LL | self.0
| ^^^^^^
|
= note: attempting to deref into `Foo`
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants

error[E0493]: destructor of `R` cannot be evaluated at compile-time
--> $DIR/arbitrary-self-from-method-substs-ice.rs:10:43
|
LL | const fn get<R: Deref<Target = Self>>(self: R) -> u32 {
| ^^^^ the destructor for this type cannot be evaluated in constant functions
...
LL | }
| - value is dropped here
| ^^^^

error[E0801]: invalid generic `self` parameter type: `R`
--> $DIR/arbitrary-self-from-method-substs-ice.rs:10:49
Expand All @@ -25,7 +13,7 @@ LL | const fn get<R: Deref<Target = Self>>(self: R) -> u32 {
= note: type of `self` must not be a method generic parameter type
= help: use a concrete type such as `self`, `&self`, `&mut self`, `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one of the previous types except `Self`)

error: aborting due to 3 previous errors
error: aborting due to 2 previous errors

Some errors have detailed explanations: E0015, E0493, E0801.
For more information about an error, try `rustc --explain E0015`.
Some errors have detailed explanations: E0277, E0801.
For more information about an error, try `rustc --explain E0277`.
5 changes: 2 additions & 3 deletions tests/ui/traits/const-traits/cross-crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ fn non_const_context() {
const fn const_context() {
#[cfg(any(stocknc, gatednc))]
NonConst.func();
//[stocknc]~^ ERROR: cannot call
//[gatednc]~^^ ERROR: the trait bound
//[stocknc,gatednc]~^ ERROR: the trait bound
Const.func();
//[stock,stocknc]~^ ERROR: cannot call
//[stock]~^ ERROR: cannot call
}

fn main() {}
2 changes: 1 addition & 1 deletion tests/ui/traits/const-traits/cross-crate.stock.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0658]: cannot call conditionally-const method `<cross_crate::Const as cross_crate::MyTrait>::func` in constant functions
--> $DIR/cross-crate.rs:22:11
--> $DIR/cross-crate.rs:21:11
|
LL | Const.func();
| ^^^^^^
Expand Down
24 changes: 8 additions & 16 deletions tests/ui/traits/const-traits/cross-crate.stocknc.stderr
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
error[E0015]: cannot call non-const method `<cross_crate::NonConst as cross_crate::MyTrait>::func` in constant functions
error[E0277]: the trait bound `cross_crate::NonConst: [const] cross_crate::MyTrait` is not satisfied
--> $DIR/cross-crate.rs:19:14
|
LL | NonConst.func();
| ^^^^^^
| ^^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants

error[E0658]: cannot call conditionally-const method `<cross_crate::Const as cross_crate::MyTrait>::func` in constant functions
--> $DIR/cross-crate.rs:22:11
|
LL | Const.func();
| ^^^^^^
note: trait `MyTrait` is implemented but not `const`
--> $DIR/auxiliary/cross-crate.rs:11:1
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= note: see issue #143874 <https://github.com/rust-lang/rust/issues/143874> for more information
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
LL | impl MyTrait for NonConst {
| ^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors
error: aborting due to 1 previous error

Some errors have detailed explanations: E0015, E0658.
For more information about an error, try `rustc --explain E0015`.
For more information about this error, try `rustc --explain E0277`.
1 change: 1 addition & 0 deletions tests/ui/traits/const-traits/gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
fn main() {
(const || {})();
//~^ ERROR: const closures are experimental
//~| ERROR: the trait bound `{closure@$DIR/gate.rs:4:6: 4:14}: [const] Fn()` is not satisfied
}

macro_rules! e {
Expand Down
13 changes: 10 additions & 3 deletions tests/ui/traits/const-traits/gate.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ LL | (const || {})();
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error[E0658]: const closures are experimental
--> $DIR/gate.rs:12:5
--> $DIR/gate.rs:13:5
|
LL | e!((const || {}));
| ^^^^^
Expand All @@ -18,6 +18,13 @@ LL | e!((const || {}));
= help: add `#![feature(const_closures)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error: aborting due to 2 previous errors
error[E0277]: the trait bound `{closure@$DIR/gate.rs:4:6: 4:14}: [const] Fn()` is not satisfied
--> $DIR/gate.rs:4:5
|
LL | (const || {})();
| ^^^^^^^^^^^^^^^

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0658`.
Some errors have detailed explanations: E0277, E0658.
For more information about an error, try `rustc --explain E0277`.
10 changes: 4 additions & 6 deletions tests/ui/traits/const-traits/super-traits-fail-3.nyn.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,13 @@ help: enable `#![feature(const_trait_impl)]` in your crate and mark `Bar` as `co
LL | #[cfg(any(yyn, ynn, nyn, nnn))] const trait Bar: [const] Foo {}
| +++++

error[E0015]: cannot call non-const method `<T as Foo>::a` in constant functions
error[E0277]: the trait bound `T: [const] Foo` is not satisfied
--> $DIR/super-traits-fail-3.rs:38:7
|
LL | x.a();
| ^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
| ^

error: aborting due to 9 previous errors

Some errors have detailed explanations: E0015, E0658.
For more information about an error, try `rustc --explain E0015`.
Some errors have detailed explanations: E0277, E0658.
For more information about an error, try `rustc --explain E0277`.
4 changes: 2 additions & 2 deletions tests/ui/traits/const-traits/super-traits-fail-3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ const fn foo<T: [const] Bar>(x: &T) {
//[yyn,ynn,nyn,nnn]~| ERROR: `[const]` can only be applied to `const` traits
//[nyy,nyn,nny,nnn]~^^^ ERROR: const trait impls are experimental
x.a();
//[yyn]~^ ERROR: the trait bound `T: [const] Foo` is not satisfied
//[ynn,yny,nny,nnn,nyn]~^^ ERROR: cannot call non-const method `<T as Foo>::a` in constant functions
//[yyn,nyn]~^ ERROR: the trait bound `T: [const] Foo` is not satisfied
//[ynn,yny,nny,nnn]~^^ ERROR: cannot call non-const method `<T as Foo>::a` in constant functions
//[nyy]~^^^ ERROR: cannot call conditionally-const method `<T as Foo>::a` in constant functions
}

Expand Down
Loading