diff --git a/compiler/rustc_hir_typeck/src/callee.rs b/compiler/rustc_hir_typeck/src/callee.rs index f59fcab46661f..4bb1936602c82 100644 --- a/compiler/rustc_hir_typeck/src/callee.rs +++ b/compiler/rustc_hir_typeck/src/callee.rs @@ -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; diff --git a/tests/crashes/137187.rs b/tests/crashes/137187.rs index 05cfb2b10e109..554275441ff0e 100644 --- a/tests/crashes/137187.rs +++ b/tests/crashes/137187.rs @@ -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() {} diff --git a/tests/ui/consts/const-eval/const_raw_ptr_ops.stable.stderr b/tests/ui/consts/const-eval/const_raw_ptr_ops.stable.stderr index 2c7e6e8671351..c39048c8f283c 100644 --- a/tests/ui/consts/const-eval/const_raw_ptr_ops.stable.stderr +++ b/tests/ui/consts/const-eval/const_raw_ptr_ops.stable.stderr @@ -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 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 for more information error: aborting due to 2 previous errors +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/consts/different-fn-ptr-binders-during-ctfe.stable.stderr b/tests/ui/consts/different-fn-ptr-binders-during-ctfe.stable.stderr index 92b09e7db0d45..f13e0c6661814 100644 --- a/tests/ui/consts/different-fn-ptr-binders-during-ctfe.stable.stderr +++ b/tests/ui/consts/different-fn-ptr-binders-during-ctfe.stable.stderr @@ -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 for more information error: aborting due to 1 previous error +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/consts/issue-25826.rs b/tests/ui/consts/issue-25826.rs index f5ed5aeedc39c..355d0ca30334e 100644 --- a/tests/ui/consts/issue-25826.rs +++ b/tests/ui/consts/issue-25826.rs @@ -2,5 +2,6 @@ fn id(t: T) -> T { t } fn main() { const A: bool = unsafe { id:: as *const () < id:: as *const () }; //~^ ERROR pointers cannot + //~| ERROR pointers cannot println!("{}", A); } diff --git a/tests/ui/consts/issue-25826.stderr b/tests/ui/consts/issue-25826.stderr index 7d21020da6477..2974c4853ef7c 100644 --- a/tests/ui/consts/issue-25826.stderr +++ b/tests/ui/consts/issue-25826.stderr @@ -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:: as *const () < id:: as *const () }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | +note: trait `PartialOrd` is implemented but not `const` + --> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL = note: see issue #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:: as *const () < id:: as *const () }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: trait `PartialEq` is implemented but not `const` + --> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL + = note: see issue #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`. diff --git a/tests/ui/consts/min_const_fn/cmp_fn_pointers.stderr b/tests/ui/consts/min_const_fn/cmp_fn_pointers.stderr index bfaccf1db1ca4..47887a6c68b92 100644 --- a/tests/ui/consts/min_const_fn/cmp_fn_pointers.stderr +++ b/tests/ui/consts/min_const_fn/cmp_fn_pointers.stderr @@ -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 for more information error: aborting due to 1 previous error +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/feature-gates/feature-gate-diagnostic-on-const.rs b/tests/ui/feature-gates/feature-gate-diagnostic-on-const.rs index 398fa30e74047..890e4aa5a601d 100644 --- a/tests/ui/feature-gates/feature-gate-diagnostic-on-const.rs +++ b/tests/ui/feature-gates/feature-gate-diagnostic-on-const.rs @@ -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() {} diff --git a/tests/ui/feature-gates/feature-gate-diagnostic-on-const.stderr b/tests/ui/feature-gates/feature-gate-diagnostic-on-const.stderr index 04c901f4f938b..4e2a573f72d78 100644 --- a/tests/ui/feature-gates/feature-gate-diagnostic-on-const.stderr +++ b/tests/ui/feature-gates/feature-gate-diagnostic-on-const.stderr @@ -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`. diff --git a/tests/ui/issues/issue-25901.rs b/tests/ui/issues/issue-25901.rs index 0ca34da95f55d..d40b869cd0cd8 100644 --- a/tests/ui/issues/issue-25901.rs +++ b/tests/ui/issues/issue-25901.rs @@ -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; diff --git a/tests/ui/issues/issue-25901.stderr b/tests/ui/issues/issue-25901.stderr index 233b5bfee5075..9b65366b969a5 100644 --- a/tests/ui/issues/issue-25901.stderr +++ b/tests/ui/issues/issue-25901.stderr @@ -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`. diff --git a/tests/ui/self/arbitrary-self-from-method-substs-ice.rs b/tests/ui/self/arbitrary-self-from-method-substs-ice.rs index 46e4afd8532e1..da3f385a3bcbc 100644 --- a/tests/ui/self/arbitrary-self-from-method-substs-ice.rs +++ b/tests/ui/self/arbitrary-self-from-method-substs-ice.rs @@ -9,9 +9,8 @@ struct Foo(u32); impl Foo { const fn get>(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 } } diff --git a/tests/ui/self/arbitrary-self-from-method-substs-ice.stderr b/tests/ui/self/arbitrary-self-from-method-substs-ice.stderr index f217370b024b5..0ea6b68d232ca 100644 --- a/tests/ui/self/arbitrary-self-from-method-substs-ice.stderr +++ b/tests/ui/self/arbitrary-self-from-method-substs-ice.stderr @@ -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>(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 @@ -25,7 +13,7 @@ LL | const fn get>(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: Rc`, `self: Arc`, or `self: Pin

` (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`. diff --git a/tests/ui/traits/const-traits/cross-crate.rs b/tests/ui/traits/const-traits/cross-crate.rs index b07aa8944c05d..a91201e3566b4 100644 --- a/tests/ui/traits/const-traits/cross-crate.rs +++ b/tests/ui/traits/const-traits/cross-crate.rs @@ -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() {} diff --git a/tests/ui/traits/const-traits/cross-crate.stock.stderr b/tests/ui/traits/const-traits/cross-crate.stock.stderr index 44a60c99ae9ea..606793cd3149d 100644 --- a/tests/ui/traits/const-traits/cross-crate.stock.stderr +++ b/tests/ui/traits/const-traits/cross-crate.stock.stderr @@ -1,5 +1,5 @@ error[E0658]: cannot call conditionally-const method `::func` in constant functions - --> $DIR/cross-crate.rs:22:11 + --> $DIR/cross-crate.rs:21:11 | LL | Const.func(); | ^^^^^^ diff --git a/tests/ui/traits/const-traits/cross-crate.stocknc.stderr b/tests/ui/traits/const-traits/cross-crate.stocknc.stderr index 766c20aa8211f..45e06c78cfb25 100644 --- a/tests/ui/traits/const-traits/cross-crate.stocknc.stderr +++ b/tests/ui/traits/const-traits/cross-crate.stocknc.stderr @@ -1,23 +1,15 @@ -error[E0015]: cannot call non-const method `::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 `::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 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`. diff --git a/tests/ui/traits/const-traits/gate.rs b/tests/ui/traits/const-traits/gate.rs index d1c93ab9f95af..3f348c8413930 100644 --- a/tests/ui/traits/const-traits/gate.rs +++ b/tests/ui/traits/const-traits/gate.rs @@ -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 { diff --git a/tests/ui/traits/const-traits/gate.stderr b/tests/ui/traits/const-traits/gate.stderr index 19fd54ff36983..6bef2c511ce7d 100644 --- a/tests/ui/traits/const-traits/gate.stderr +++ b/tests/ui/traits/const-traits/gate.stderr @@ -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 || {})); | ^^^^^ @@ -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`. diff --git a/tests/ui/traits/const-traits/super-traits-fail-3.nyn.stderr b/tests/ui/traits/const-traits/super-traits-fail-3.nyn.stderr index 1c56aa1297944..42b051cd8df82 100644 --- a/tests/ui/traits/const-traits/super-traits-fail-3.nyn.stderr +++ b/tests/ui/traits/const-traits/super-traits-fail-3.nyn.stderr @@ -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 `::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`. diff --git a/tests/ui/traits/const-traits/super-traits-fail-3.rs b/tests/ui/traits/const-traits/super-traits-fail-3.rs index 7dd434c528d09..55e8d3ca6e6ad 100644 --- a/tests/ui/traits/const-traits/super-traits-fail-3.rs +++ b/tests/ui/traits/const-traits/super-traits-fail-3.rs @@ -36,8 +36,8 @@ const fn foo(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 `::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 `::a` in constant functions //[nyy]~^^^ ERROR: cannot call conditionally-const method `::a` in constant functions }