diff --git a/compiler/rustc_const_eval/src/check_consts/ops.rs b/compiler/rustc_const_eval/src/check_consts/ops.rs index b2e0577cc8248..af4f94afeaf60 100644 --- a/compiler/rustc_const_eval/src/check_consts/ops.rs +++ b/compiler/rustc_const_eval/src/check_consts/ops.rs @@ -1,9 +1,10 @@ //! Concrete error types for all operations which may be invalid in a certain const context. use hir::{ConstContext, LangItem}; -use rustc_errors::Diag; use rustc_errors::codes::*; +use rustc_errors::{Applicability, Diag, MultiSpan}; use rustc_hir as hir; +use rustc_hir::def::DefKind; use rustc_hir::def_id::DefId; use rustc_infer::infer::TyCtxtInferExt; use rustc_infer::traits::{ImplSource, Obligation, ObligationCause}; @@ -211,6 +212,7 @@ fn build_error_for_const_call<'tcx>( debug!(?call_kind); + let mut note = true; let mut err = match call_kind { CallKind::Normal { desugaring: Some((kind, self_ty)), .. } => { macro_rules! error { @@ -355,20 +357,82 @@ fn build_error_for_const_call<'tcx>( non_or_conditionally, }) } - _ => ccx.dcx().create_err(errors::NonConstFnCall { - span, - def_descr: ccx.tcx.def_descr(callee), - def_path_str: ccx.tcx.def_path_str_with_args(callee, args), - kind: ccx.const_kind(), - non_or_conditionally, - }), + _ => { + let def_descr = ccx.tcx.def_descr(callee); + let mut err = ccx.dcx().create_err(errors::NonConstFnCall { + span, + def_descr, + def_path_str: ccx.tcx.def_path_str_with_args(callee, args), + kind: ccx.const_kind(), + non_or_conditionally, + }); + let context_span = ccx.tcx.def_span(ccx.def_id()); + err.span_label(context_span, format!( + "calls in {}s are limited to constant functions, tuple structs and tuple variants", + ccx.const_kind(), + )); + note = false; + let def_kind = ccx.tcx.def_kind(callee); + if let DefKind::AssocTy | DefKind::AssocConst | DefKind::AssocFn = def_kind { + let parent = ccx.tcx.parent(callee); + if let DefKind::Trait = ccx.tcx.def_kind(parent) + && !ccx.tcx.is_const_trait(parent) + { + let assoc_span = ccx.tcx.def_span(callee); + let assoc_name = ccx.tcx.item_name(callee); + let mut span: MultiSpan = ccx.tcx.def_span(parent).into(); + span.push_span_label(assoc_span, format!("this {def_descr} is not const")); + let trait_descr = ccx.tcx.def_descr(parent); + let trait_span = ccx.tcx.def_span(parent); + let trait_name = ccx.tcx.item_name(parent); + span.push_span_label(trait_span, format!("this {trait_descr} is not const")); + err.span_note( + span, + format!( + "{def_descr} `{assoc_name}` is not const because {trait_descr} \ + `{trait_name}` is not const", + ), + ); + if parent.is_local() && ccx.tcx.sess.is_nightly_build() { + if !ccx.tcx.features().const_trait_impl() { + err.help( + "add `#![feature(const_trait_impl)]` to the crate attributes to \ + enable `#[const_trait]`", + ); + } + let indentation = ccx + .tcx + .sess + .source_map() + .indentation_before(trait_span) + .unwrap_or_default(); + err.span_suggestion_verbose( + trait_span.shrink_to_lo(), + format!("consider making trait `{trait_name}` const"), + format!("#[const_trait]\n{indentation}"), + Applicability::MachineApplicable, + ); + } else if !ccx.tcx.sess.is_nightly_build() { + err.help("const traits are not yet supported on stable Rust"); + } + } + } else if ccx.tcx.constness(callee) != hir::Constness::Const { + let name = ccx.tcx.item_name(callee); + err.span_note( + ccx.tcx.def_span(callee), + format!("{def_descr} `{name}` is not const"), + ); + } + err + } }; - err.note(format!( - "calls in {}s are limited to constant functions, \ - tuple structs and tuple variants", - ccx.const_kind(), - )); + if note { + err.note(format!( + "calls in {}s are limited to constant functions, tuple structs and tuple variants", + ccx.const_kind(), + )); + } err } diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs index 1ac309da101f1..1d2a803418ce7 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs @@ -806,6 +806,34 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { )) { diag.downgrade_to_delayed_bug(); } + for candidate in self.find_similar_impl_candidates(trait_ref) { + let CandidateSimilarity::Exact { .. } = candidate.similarity else { continue }; + let impl_did = candidate.impl_def_id; + let trait_did = candidate.trait_ref.def_id; + let impl_span = self.tcx.def_span(impl_did); + let trait_name = self.tcx.item_name(trait_did); + + if self.tcx.is_const_trait(trait_did) && !self.tcx.is_const_trait_impl(impl_did) { + if let Some(impl_did) = impl_did.as_local() + && let item = self.tcx.hir_expect_item(impl_did) + && let hir::ItemKind::Impl(item) = item.kind + && let Some(of_trait) = item.of_trait + { + // trait is const, impl is local and not const + diag.span_suggestion_verbose( + of_trait.path.span.shrink_to_lo(), + format!("make the `impl` of trait `{trait_name}` `const`"), + "const ".to_string(), + Applicability::MachineApplicable, + ); + } else { + diag.span_note( + impl_span, + format!("trait `{trait_name}` is implemented but not `const`"), + ); + } + } + } diag } diff --git a/tests/run-make/const-trait-stable-toolchain/const-super-trait-nightly-disabled.stderr b/tests/run-make/const-trait-stable-toolchain/const-super-trait-nightly-disabled.stderr index 464208f989e35..cd39ce0a1d48c 100644 --- a/tests/run-make/const-trait-stable-toolchain/const-super-trait-nightly-disabled.stderr +++ b/tests/run-make/const-trait-stable-toolchain/const-super-trait-nightly-disabled.stderr @@ -55,10 +55,24 @@ LL | #[const_trait] trait Bar: ~const Foo {} error[E0015]: cannot call non-const method `::a` in constant functions --> const-super-trait.rs:10:7 | +LL | const fn foo(x: &T) { + | ---------------------------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants LL | x.a(); | ^^^ | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants +note: method `a` is not const because trait `Foo` is not const + --> const-super-trait.rs:3:1 + | +LL | trait Foo { + | ^^^^^^^^^ this trait is not const +LL | fn a(&self); + | ------------ this method is not const + = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable `#[const_trait]` +help: consider making trait `Foo` const + | +LL + #[const_trait] +LL | trait Foo { + | error: aborting due to 6 previous errors diff --git a/tests/run-make/const-trait-stable-toolchain/const-super-trait-nightly-enabled.stderr b/tests/run-make/const-trait-stable-toolchain/const-super-trait-nightly-enabled.stderr index 569e559186f76..bdfe040bb83bb 100644 --- a/tests/run-make/const-trait-stable-toolchain/const-super-trait-nightly-enabled.stderr +++ b/tests/run-make/const-trait-stable-toolchain/const-super-trait-nightly-enabled.stderr @@ -35,10 +35,23 @@ LL | #[const_trait] trait Bar: ~const Foo {} error[E0015]: cannot call non-const method `::a` in constant functions --> const-super-trait.rs:10:7 | +LL | const fn foo(x: &T) { + | ---------------------------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants LL | x.a(); | ^^^ | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants +note: method `a` is not const because trait `Foo` is not const + --> const-super-trait.rs:3:1 + | +LL | trait Foo { + | ^^^^^^^^^ this trait is not const +LL | fn a(&self); + | ------------ this method is not const +help: consider making trait `Foo` const + | +LL + #[const_trait] +LL | trait Foo { + | error: aborting due to 4 previous errors diff --git a/tests/run-make/const-trait-stable-toolchain/const-super-trait-stable-disabled.stderr b/tests/run-make/const-trait-stable-toolchain/const-super-trait-stable-disabled.stderr index 694e06fb6ea2b..d35656c060d06 100644 --- a/tests/run-make/const-trait-stable-toolchain/const-super-trait-stable-disabled.stderr +++ b/tests/run-make/const-trait-stable-toolchain/const-super-trait-stable-disabled.stderr @@ -53,10 +53,19 @@ note: `Bar` can't be used with `[const]` because it isn't `const` error[E0015]: cannot call non-const method `::a` in constant functions --> const-super-trait.rs:10:7 | +9 | const fn foo(x: &T) { + | ---------------------------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants 10 | x.a(); | ^^^ | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants +note: method `a` is not const because trait `Foo` is not const + --> const-super-trait.rs:3:1 + | +3 | trait Foo { + | ^^^^^^^^^ this trait is not const +4 | fn a(&self); + | ------------ this method is not const + = help: const traits are not yet supported on stable Rust error: aborting due to 6 previous errors diff --git a/tests/run-make/const-trait-stable-toolchain/const-super-trait-stable-enabled.stderr b/tests/run-make/const-trait-stable-toolchain/const-super-trait-stable-enabled.stderr index 2109f0deb7291..c279c7a413cae 100644 --- a/tests/run-make/const-trait-stable-toolchain/const-super-trait-stable-enabled.stderr +++ b/tests/run-make/const-trait-stable-toolchain/const-super-trait-stable-enabled.stderr @@ -43,10 +43,19 @@ note: `Bar` can't be used with `[const]` because it isn't `const` error[E0015]: cannot call non-const method `::a` in constant functions --> const-super-trait.rs:10:7 | +9 | const fn foo(x: &T) { + | ---------------------------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants 10 | x.a(); | ^^^ | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants +note: method `a` is not const because trait `Foo` is not const + --> const-super-trait.rs:3:1 + | +3 | trait Foo { + | ^^^^^^^^^ this trait is not const +4 | fn a(&self); + | ------------ this method is not const + = help: const traits are not yet supported on stable Rust error: aborting due to 5 previous errors diff --git a/tests/ui/asm/non-const.stderr b/tests/ui/asm/non-const.stderr index eac4fe841bffd..da881a12f120f 100644 --- a/tests/ui/asm/non-const.stderr +++ b/tests/ui/asm/non-const.stderr @@ -2,9 +2,13 @@ error[E0015]: cannot call non-const function `non_const_fn` in constants --> $DIR/non-const.rs:10:31 | LL | global_asm!("/* {} */", const non_const_fn(0)); - | ^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^ calls in constants are limited to constant functions, tuple structs and tuple variants | - = note: calls in constants are limited to constant functions, tuple structs and tuple variants +note: function `non_const_fn` is not const + --> $DIR/non-const.rs:8:1 + | +LL | fn non_const_fn(x: i32) -> i32 { x } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/borrowck/issue-64453.stderr b/tests/ui/borrowck/issue-64453.stderr index 8ec9a10f09f4d..47d9082765555 100644 --- a/tests/ui/borrowck/issue-64453.stderr +++ b/tests/ui/borrowck/issue-64453.stderr @@ -2,9 +2,12 @@ error[E0015]: cannot call non-const function `format` in statics --> $DIR/issue-64453.rs:4:31 | LL | static settings_dir: String = format!(""); - | ^^^^^^^^^^^ + | --------------------------- ^^^^^^^^^^^ + | | + | calls in statics are limited to constant functions, tuple structs and tuple variants | - = note: calls in statics are limited to constant functions, tuple structs and tuple variants +note: function `format` is not const + --> $SRC_DIR/alloc/src/fmt.rs:LL:COL = note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)` = note: this error originates in the macro `format` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/const-generics/nested-type.full.stderr b/tests/ui/const-generics/nested-type.full.stderr index e5a1f230380d3..587de095452d1 100644 --- a/tests/ui/const-generics/nested-type.full.stderr +++ b/tests/ui/const-generics/nested-type.full.stderr @@ -1,10 +1,17 @@ error[E0015]: cannot call non-const associated function `Foo::{constant#0}::Foo::<17>::value` in constants --> $DIR/nested-type.rs:15:5 | -LL | Foo::<17>::value() - | ^^^^^^^^^^^^^^^^^^ - | - = note: calls in constants are limited to constant functions, tuple structs and tuple variants +LL | struct Foo; +LL | | +LL | | impl Foo { +... | +LL | | Foo::<17>::value() + | | ^^^^^^^^^^^^^^^^^^ +LL | | +LL | | }]>; + | |_- calls in constants are limited to constant functions, tuple structs and tuple variants error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/nested-type.min.stderr b/tests/ui/const-generics/nested-type.min.stderr index 8282acd4ea7b1..e7d21f8a98949 100644 --- a/tests/ui/const-generics/nested-type.min.stderr +++ b/tests/ui/const-generics/nested-type.min.stderr @@ -1,10 +1,17 @@ error[E0015]: cannot call non-const associated function `Foo::{constant#0}::Foo::<17>::value` in constants --> $DIR/nested-type.rs:15:5 | -LL | Foo::<17>::value() - | ^^^^^^^^^^^^^^^^^^ - | - = note: calls in constants are limited to constant functions, tuple structs and tuple variants +LL | struct Foo; +LL | | +LL | | impl Foo { +... | +LL | | Foo::<17>::value() + | | ^^^^^^^^^^^^^^^^^^ +LL | | +LL | | }]>; + | |_- calls in constants are limited to constant functions, tuple structs and tuple variants error: `[u8; { struct Foo; diff --git a/tests/ui/consts/const-call.stderr b/tests/ui/consts/const-call.stderr index b9dcf5addb519..db375f80b6c67 100644 --- a/tests/ui/consts/const-call.stderr +++ b/tests/ui/consts/const-call.stderr @@ -2,9 +2,13 @@ error[E0015]: cannot call non-const function `f` in constants --> $DIR/const-call.rs:6:17 | LL | let _ = [0; f(2)]; - | ^^^^ + | ^^^^ calls in constants are limited to constant functions, tuple structs and tuple variants | - = note: calls in constants are limited to constant functions, tuple structs and tuple variants +note: function `f` is not const + --> $DIR/const-call.rs:1:1 + | +LL | fn f(x: usize) -> usize { + | ^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/consts/const-eval/format.stderr b/tests/ui/consts/const-eval/format.stderr index bd50ac0bf4116..97b4436a058ee 100644 --- a/tests/ui/consts/const-eval/format.stderr +++ b/tests/ui/consts/const-eval/format.stderr @@ -18,10 +18,13 @@ LL | println!("{:?}", 0); error[E0015]: cannot call non-const function `_print` in constant functions --> $DIR/format.rs:7:5 | +LL | const fn print() { + | ---------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants LL | println!("{:?}", 0); | ^^^^^^^^^^^^^^^^^^^ | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants +note: function `_print` is not const + --> $SRC_DIR/std/src/io/stdio.rs:LL:COL = note: this error originates in the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0015]: cannot call non-const formatting macro in constant functions diff --git a/tests/ui/consts/const-extern-fn/const-extern-fn-call-extern-fn.stderr b/tests/ui/consts/const-extern-fn/const-extern-fn-call-extern-fn.stderr index 1fa881cf42b6a..8f07e038e1994 100644 --- a/tests/ui/consts/const-extern-fn/const-extern-fn-call-extern-fn.stderr +++ b/tests/ui/consts/const-extern-fn/const-extern-fn-call-extern-fn.stderr @@ -1,18 +1,32 @@ error[E0015]: cannot call non-const function `regular_in_block` in constant functions --> $DIR/const-extern-fn-call-extern-fn.rs:7:9 | +LL | const extern "C" fn bar() { + | ------------------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants +LL | unsafe { LL | regular_in_block(); | ^^^^^^^^^^^^^^^^^^ | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants +note: function `regular_in_block` is not const + --> $DIR/const-extern-fn-call-extern-fn.rs:2:5 + | +LL | fn regular_in_block(); + | ^^^^^^^^^^^^^^^^^^^^^^ error[E0015]: cannot call non-const function `regular` in constant functions --> $DIR/const-extern-fn-call-extern-fn.rs:16:9 | +LL | const extern "C" fn foo() { + | ------------------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants +LL | unsafe { LL | regular(); | ^^^^^^^^^ | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants +note: function `regular` is not const + --> $DIR/const-extern-fn-call-extern-fn.rs:12:1 + | +LL | extern "C" fn regular() {} + | ^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/tests/ui/consts/const-fn-not-safe-for-const.stderr b/tests/ui/consts/const-fn-not-safe-for-const.stderr index e8f0566e73dd8..068c06601c8b6 100644 --- a/tests/ui/consts/const-fn-not-safe-for-const.stderr +++ b/tests/ui/consts/const-fn-not-safe-for-const.stderr @@ -1,10 +1,16 @@ error[E0015]: cannot call non-const function `random` in constant functions --> $DIR/const-fn-not-safe-for-const.rs:14:5 | +LL | const fn sub1() -> u32 { + | ---------------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants LL | random() | ^^^^^^^^ | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants +note: function `random` is not const + --> $DIR/const-fn-not-safe-for-const.rs:5:1 + | +LL | fn random() -> u32 { + | ^^^^^^^^^^^^^^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/consts/control-flow/issue-46843.stderr b/tests/ui/consts/control-flow/issue-46843.stderr index 42eb035647c0e..310c860f59b45 100644 --- a/tests/ui/consts/control-flow/issue-46843.stderr +++ b/tests/ui/consts/control-flow/issue-46843.stderr @@ -2,9 +2,15 @@ error[E0015]: cannot call non-const function `non_const` in constants --> $DIR/issue-46843.rs:10:26 | LL | pub const Q: i32 = match non_const() { - | ^^^^^^^^^^^ + | ---------------- ^^^^^^^^^^^ + | | + | calls in constants are limited to constant functions, tuple structs and tuple variants | - = note: calls in constants are limited to constant functions, tuple structs and tuple variants +note: function `non_const` is not const + --> $DIR/issue-46843.rs:6:1 + | +LL | fn non_const() -> Thing { + | ^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/consts/issue-16538.stderr b/tests/ui/consts/issue-16538.stderr index 8bd11541a7dff..e78d95dcd186f 100644 --- a/tests/ui/consts/issue-16538.stderr +++ b/tests/ui/consts/issue-16538.stderr @@ -2,9 +2,15 @@ error[E0015]: cannot call non-const function `Y::foo` in statics --> $DIR/issue-16538.rs:11:23 | LL | static foo: &Y::X = &*Y::foo(Y::x as *const Y::X); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ----------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | calls in statics are limited to constant functions, tuple structs and tuple variants | - = note: calls in statics are limited to constant functions, tuple structs and tuple variants +note: function `foo` is not const + --> $DIR/issue-16538.rs:6:5 + | +LL | pub fn foo(value: *const X) -> *const X { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)` error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block diff --git a/tests/ui/consts/issue-32829-2.stderr b/tests/ui/consts/issue-32829-2.stderr index eedd9d34e550e..52398af41eeef 100644 --- a/tests/ui/consts/issue-32829-2.stderr +++ b/tests/ui/consts/issue-32829-2.stderr @@ -1,27 +1,48 @@ error[E0015]: cannot call non-const function `invalid` in constants --> $DIR/issue-32829-2.rs:10:9 | +LL | const bad_two : u32 = { + | ------------------- calls in constants are limited to constant functions, tuple structs and tuple variants +LL | { LL | invalid(); | ^^^^^^^^^ | - = note: calls in constants are limited to constant functions, tuple structs and tuple variants +note: function `invalid` is not const + --> $DIR/issue-32829-2.rs:68:1 + | +LL | fn invalid() {} + | ^^^^^^^^^^^^ error[E0015]: cannot call non-const function `invalid` in statics --> $DIR/issue-32829-2.rs:32:9 | +LL | static bad_five : u32 = { + | --------------------- calls in statics are limited to constant functions, tuple structs and tuple variants +LL | { LL | invalid(); | ^^^^^^^^^ | - = note: calls in statics are limited to constant functions, tuple structs and tuple variants +note: function `invalid` is not const + --> $DIR/issue-32829-2.rs:68:1 + | +LL | fn invalid() {} + | ^^^^^^^^^^^^ = note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)` error[E0015]: cannot call non-const function `invalid` in statics --> $DIR/issue-32829-2.rs:54:9 | +LL | static mut bad_eight : u32 = { + | -------------------------- calls in statics are limited to constant functions, tuple structs and tuple variants +LL | { LL | invalid(); | ^^^^^^^^^ | - = note: calls in statics are limited to constant functions, tuple structs and tuple variants +note: function `invalid` is not const + --> $DIR/issue-32829-2.rs:68:1 + | +LL | fn invalid() {} + | ^^^^^^^^^^^^ = note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)` error: aborting due to 3 previous errors diff --git a/tests/ui/consts/issue-43105.stderr b/tests/ui/consts/issue-43105.stderr index c030c0f5fcdec..442fbdd107fab 100644 --- a/tests/ui/consts/issue-43105.stderr +++ b/tests/ui/consts/issue-43105.stderr @@ -2,9 +2,15 @@ error[E0015]: cannot call non-const function `xyz` in constants --> $DIR/issue-43105.rs:3:17 | LL | const NUM: u8 = xyz(); - | ^^^^^ + | ------------- ^^^^^ + | | + | calls in constants are limited to constant functions, tuple structs and tuple variants | - = note: calls in constants are limited to constant functions, tuple structs and tuple variants +note: function `xyz` is not const + --> $DIR/issue-43105.rs:1:1 + | +LL | fn xyz() -> u8 { 42 } + | ^^^^^^^^^^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/consts/min_const_fn/bad_const_fn_body_ice.stderr b/tests/ui/consts/min_const_fn/bad_const_fn_body_ice.stderr index 8e52a7aa35e1e..c65abc530bc2b 100644 --- a/tests/ui/consts/min_const_fn/bad_const_fn_body_ice.stderr +++ b/tests/ui/consts/min_const_fn/bad_const_fn_body_ice.stderr @@ -9,10 +9,11 @@ LL | vec![1, 2, 3] error[E0015]: cannot call non-const method `slice::::into_vec::` in constant functions --> $DIR/bad_const_fn_body_ice.rs:2:5 | +LL | const fn foo(a: i32) -> Vec { + | -------------------------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants LL | vec![1, 2, 3] | ^^^^^^^^^^^^^ | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants = note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 2 previous errors diff --git a/tests/ui/consts/mir_check_nonconst.stderr b/tests/ui/consts/mir_check_nonconst.stderr index e930fa2103d5d..ad2056a737078 100644 --- a/tests/ui/consts/mir_check_nonconst.stderr +++ b/tests/ui/consts/mir_check_nonconst.stderr @@ -2,9 +2,15 @@ error[E0015]: cannot call non-const function `bar` in statics --> $DIR/mir_check_nonconst.rs:8:19 | LL | static foo: Foo = bar(); - | ^^^^^ + | --------------- ^^^^^ + | | + | calls in statics are limited to constant functions, tuple structs and tuple variants | - = note: calls in statics are limited to constant functions, tuple structs and tuple variants +note: function `bar` is not const + --> $DIR/mir_check_nonconst.rs:4:1 + | +LL | fn bar() -> Foo { + | ^^^^^^^^^^^^^^^ = note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)` error: aborting due to 1 previous error diff --git a/tests/ui/error-codes/E0010-teach.stderr b/tests/ui/error-codes/E0010-teach.stderr index 82bbe01aef792..237efbefcf6ef 100644 --- a/tests/ui/error-codes/E0010-teach.stderr +++ b/tests/ui/error-codes/E0010-teach.stderr @@ -11,9 +11,10 @@ error[E0015]: cannot call non-const method `slice::::into_vec:: $DIR/E0010-teach.rs:5:23 | LL | const CON: Vec = vec![1, 2, 3]; - | ^^^^^^^^^^^^^ + | ------------------- ^^^^^^^^^^^^^ + | | + | calls in constants are limited to constant functions, tuple structs and tuple variants | - = note: calls in constants are limited to constant functions, tuple structs and tuple variants = note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 2 previous errors diff --git a/tests/ui/error-codes/E0010.stderr b/tests/ui/error-codes/E0010.stderr index 87b722b5f6566..2bb87118d242d 100644 --- a/tests/ui/error-codes/E0010.stderr +++ b/tests/ui/error-codes/E0010.stderr @@ -10,9 +10,10 @@ error[E0015]: cannot call non-const method `slice::::into_vec:: $DIR/E0010.rs:3:23 | LL | const CON: Vec = vec![1, 2, 3]; - | ^^^^^^^^^^^^^ + | ------------------- ^^^^^^^^^^^^^ + | | + | calls in constants are limited to constant functions, tuple structs and tuple variants | - = note: calls in constants are limited to constant functions, tuple structs and tuple variants = note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 2 previous errors diff --git a/tests/ui/error-codes/E0015.stderr b/tests/ui/error-codes/E0015.stderr index 0c983d2843492..4331d7c34b3ca 100644 --- a/tests/ui/error-codes/E0015.stderr +++ b/tests/ui/error-codes/E0015.stderr @@ -2,9 +2,15 @@ error[E0015]: cannot call non-const function `create_some` in constants --> $DIR/E0015.rs:5:25 | LL | const FOO: Option = create_some(); - | ^^^^^^^^^^^^^ + | --------------------- ^^^^^^^^^^^^^ + | | + | calls in constants are limited to constant functions, tuple structs and tuple variants | - = note: calls in constants are limited to constant functions, tuple structs and tuple variants +note: function `create_some` is not const + --> $DIR/E0015.rs:1:1 + | +LL | fn create_some() -> Option { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/explicit-tail-calls/constck.stderr b/tests/ui/explicit-tail-calls/constck.stderr index c223d273b383f..84d7bc3a1bf13 100644 --- a/tests/ui/explicit-tail-calls/constck.stderr +++ b/tests/ui/explicit-tail-calls/constck.stderr @@ -1,18 +1,32 @@ error[E0015]: cannot call non-const function `not_const` in constant functions --> $DIR/constck.rs:6:16 | +LL | const fn f() { + | ------------ calls in constant functions are limited to constant functions, tuple structs and tuple variants +LL | if false { LL | become not_const(); | ^^^^^^^^^^^ | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants +note: function `not_const` is not const + --> $DIR/constck.rs:18:1 + | +LL | fn not_const() {} + | ^^^^^^^^^^^^^^ error[E0015]: cannot call non-const function `not_const` in constant functions --> $DIR/constck.rs:13:26 | +LL | const fn g((): ()) { + | ------------------ calls in constant functions are limited to constant functions, tuple structs and tuple variants +LL | if false { LL | become yes_const(not_const()); | ^^^^^^^^^^^ | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants +note: function `not_const` is not const + --> $DIR/constck.rs:18:1 + | +LL | fn not_const() {} + | ^^^^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/tests/ui/issues/issue-7364.stderr b/tests/ui/issues/issue-7364.stderr index a47a90c90ce16..fc442a62501fe 100644 --- a/tests/ui/issues/issue-7364.stderr +++ b/tests/ui/issues/issue-7364.stderr @@ -15,9 +15,10 @@ error[E0015]: cannot call non-const associated function `Box::>:: --> $DIR/issue-7364.rs:4:37 | LL | static boxed: Box> = Box::new(RefCell::new(0)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | --------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | calls in statics are limited to constant functions, tuple structs and tuple variants | - = note: calls in statics are limited to constant functions, tuple structs and tuple variants = note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)` error: aborting due to 2 previous errors diff --git a/tests/ui/resolve/issue-39559-2.stderr b/tests/ui/resolve/issue-39559-2.stderr index f6e6917d01e6d..fbbcaa663ae0d 100644 --- a/tests/ui/resolve/issue-39559-2.stderr +++ b/tests/ui/resolve/issue-39559-2.stderr @@ -2,17 +2,41 @@ error[E0015]: cannot call non-const associated function `::dim` in --> $DIR/issue-39559-2.rs:14:24 | LL | let array: [usize; Dim3::dim()] - | ^^^^^^^^^^^ + | ^^^^^^^^^^^ calls in constants are limited to constant functions, tuple structs and tuple variants + | +note: associated function `dim` is not const because trait `Dim` is not const + --> $DIR/issue-39559-2.rs:1:1 + | +LL | trait Dim { + | ^^^^^^^^^ this trait is not const +LL | fn dim() -> usize; + | ------------------ this associated function is not const + = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable `#[const_trait]` +help: consider making trait `Dim` const + | +LL + #[const_trait] +LL | trait Dim { | - = note: calls in constants are limited to constant functions, tuple structs and tuple variants error[E0015]: cannot call non-const associated function `::dim` in constants --> $DIR/issue-39559-2.rs:16:15 | LL | = [0; Dim3::dim()]; - | ^^^^^^^^^^^ + | ^^^^^^^^^^^ calls in constants are limited to constant functions, tuple structs and tuple variants + | +note: associated function `dim` is not const because trait `Dim` is not const + --> $DIR/issue-39559-2.rs:1:1 + | +LL | trait Dim { + | ^^^^^^^^^ this trait is not const +LL | fn dim() -> usize; + | ------------------ this associated function is not const + = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable `#[const_trait]` +help: consider making trait `Dim` const + | +LL + #[const_trait] +LL | trait Dim { | - = note: calls in constants are limited to constant functions, tuple structs and tuple variants error: aborting due to 2 previous errors diff --git a/tests/ui/static/static-mut-not-constant.stderr b/tests/ui/static/static-mut-not-constant.stderr index f28ea0b1689ab..7e64d36b26d17 100644 --- a/tests/ui/static/static-mut-not-constant.stderr +++ b/tests/ui/static/static-mut-not-constant.stderr @@ -2,9 +2,10 @@ error[E0015]: cannot call non-const associated function `Box::::new` in s --> $DIR/static-mut-not-constant.rs:1:28 | LL | static mut a: Box = Box::new(3); - | ^^^^^^^^^^^ + | ------------------------ ^^^^^^^^^^^ + | | + | calls in statics are limited to constant functions, tuple structs and tuple variants | - = note: calls in statics are limited to constant functions, tuple structs and tuple variants = note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)` error: aborting due to 1 previous error diff --git a/tests/ui/static/static-vec-repeat-not-constant.stderr b/tests/ui/static/static-vec-repeat-not-constant.stderr index e6ff199ae0198..24f0986ccc494 100644 --- a/tests/ui/static/static-vec-repeat-not-constant.stderr +++ b/tests/ui/static/static-vec-repeat-not-constant.stderr @@ -2,9 +2,15 @@ error[E0015]: cannot call non-const function `foo` in statics --> $DIR/static-vec-repeat-not-constant.rs:3:25 | LL | static a: [isize; 2] = [foo(); 2]; - | ^^^^^ + | -------------------- ^^^^^ + | | + | calls in statics are limited to constant functions, tuple structs and tuple variants | - = note: calls in statics are limited to constant functions, tuple structs and tuple variants +note: function `foo` is not const + --> $DIR/static-vec-repeat-not-constant.rs:1:1 + | +LL | fn foo() -> isize { 23 } + | ^^^^^^^^^^^^^^^^^ = note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)` error: aborting due to 1 previous error diff --git a/tests/ui/statics/check-values-constraints.stderr b/tests/ui/statics/check-values-constraints.stderr index eb2d37d297e9f..dfbb1f6e985c3 100644 --- a/tests/ui/statics/check-values-constraints.stderr +++ b/tests/ui/statics/check-values-constraints.stderr @@ -23,19 +23,29 @@ error[E0015]: cannot call non-const method `slice::::into_vec::< --> $DIR/check-values-constraints.rs:81:33 | LL | static STATIC11: Vec = vec![MyOwned]; - | ^^^^^^^^^^^^^ + | ----------------------------- ^^^^^^^^^^^^^ + | | + | calls in statics are limited to constant functions, tuple structs and tuple variants | - = note: calls in statics are limited to constant functions, tuple structs and tuple variants = note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)` = note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0015]: cannot call non-const method `::to_string` in statics --> $DIR/check-values-constraints.rs:92:38 | +LL | static mut STATIC14: SafeStruct = SafeStruct { + | ------------------------------- calls in statics are limited to constant functions, tuple structs and tuple variants +LL | field1: SafeEnum::Variant1, LL | field2: SafeEnum::Variant4("str".to_string()), | ^^^^^^^^^^^ | - = note: calls in statics are limited to constant functions, tuple structs and tuple variants +note: method `to_string` is not const because trait `ToString` is not const + --> $SRC_DIR/alloc/src/string.rs:LL:COL + | + = note: this trait is not const + ::: $SRC_DIR/alloc/src/string.rs:LL:COL + | + = note: this method is not const = note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)` error[E0010]: allocations are not allowed in statics @@ -49,10 +59,11 @@ LL | vec![MyOwned], error[E0015]: cannot call non-const method `slice::::into_vec::` in statics --> $DIR/check-values-constraints.rs:96:5 | +LL | static STATIC15: &'static [Vec] = &[ + | ---------------------------------------- calls in statics are limited to constant functions, tuple structs and tuple variants LL | vec![MyOwned], | ^^^^^^^^^^^^^ | - = note: calls in statics are limited to constant functions, tuple structs and tuple variants = note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)` = note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -67,10 +78,12 @@ LL | vec![MyOwned], error[E0015]: cannot call non-const method `slice::::into_vec::` in statics --> $DIR/check-values-constraints.rs:98:5 | +LL | static STATIC15: &'static [Vec] = &[ + | ---------------------------------------- calls in statics are limited to constant functions, tuple structs and tuple variants +... LL | vec![MyOwned], | ^^^^^^^^^^^^^ | - = note: calls in statics are limited to constant functions, tuple structs and tuple variants = note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)` = note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -85,10 +98,11 @@ LL | &vec![MyOwned], error[E0015]: cannot call non-const method `slice::::into_vec::` in statics --> $DIR/check-values-constraints.rs:103:6 | +LL | static STATIC16: (&'static Vec, &'static Vec) = ( + | --------------------------------------------------------------- calls in statics are limited to constant functions, tuple structs and tuple variants LL | &vec![MyOwned], | ^^^^^^^^^^^^^ | - = note: calls in statics are limited to constant functions, tuple structs and tuple variants = note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)` = note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -103,10 +117,12 @@ LL | &vec![MyOwned], error[E0015]: cannot call non-const method `slice::::into_vec::` in statics --> $DIR/check-values-constraints.rs:105:6 | +LL | static STATIC16: (&'static Vec, &'static Vec) = ( + | --------------------------------------------------------------- calls in statics are limited to constant functions, tuple structs and tuple variants +... LL | &vec![MyOwned], | ^^^^^^^^^^^^^ | - = note: calls in statics are limited to constant functions, tuple structs and tuple variants = note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)` = note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -122,9 +138,10 @@ error[E0015]: cannot call non-const method `slice::::into_vec:: $DIR/check-values-constraints.rs:111:31 | LL | static STATIC19: Vec = vec![3]; - | ^^^^^^^ + | --------------------------- ^^^^^^^ + | | + | calls in statics are limited to constant functions, tuple structs and tuple variants | - = note: calls in statics are limited to constant functions, tuple structs and tuple variants = note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)` = note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -140,9 +157,10 @@ error[E0015]: cannot call non-const method `slice::::into_vec:: $DIR/check-values-constraints.rs:117:32 | LL | static x: Vec = vec![3]; - | ^^^^^^^ + | -------------------- ^^^^^^^ + | | + | calls in statics are limited to constant functions, tuple structs and tuple variants | - = note: calls in statics are limited to constant functions, tuple structs and tuple variants = note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)` = note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/traits/const-traits/assoc-type.current.stderr b/tests/ui/traits/const-traits/assoc-type.current.stderr index 1e58efeedeea1..7fe086550f1c2 100644 --- a/tests/ui/traits/const-traits/assoc-type.current.stderr +++ b/tests/ui/traits/const-traits/assoc-type.current.stderr @@ -9,6 +9,10 @@ note: required by a bound in `Foo::Bar` | LL | type Bar: [const] Add; | ^^^^^^^^^^^ required by this bound in `Foo::Bar` +help: make the `impl` of trait `Add` `const` + | +LL | impl const Add for NonConstAdd { + | +++++ error: aborting due to 1 previous error diff --git a/tests/ui/traits/const-traits/assoc-type.next.stderr b/tests/ui/traits/const-traits/assoc-type.next.stderr index 1e58efeedeea1..7fe086550f1c2 100644 --- a/tests/ui/traits/const-traits/assoc-type.next.stderr +++ b/tests/ui/traits/const-traits/assoc-type.next.stderr @@ -9,6 +9,10 @@ note: required by a bound in `Foo::Bar` | LL | type Bar: [const] Add; | ^^^^^^^^^^^ required by this bound in `Foo::Bar` +help: make the `impl` of trait `Add` `const` + | +LL | impl const Add for NonConstAdd { + | +++++ error: aborting due to 1 previous error diff --git a/tests/ui/traits/const-traits/call-const-closure.stderr b/tests/ui/traits/const-traits/call-const-closure.stderr index 4bb8b2e9777e6..9de22759c2003 100644 --- a/tests/ui/traits/const-traits/call-const-closure.stderr +++ b/tests/ui/traits/const-traits/call-const-closure.stderr @@ -3,6 +3,11 @@ error[E0277]: the trait bound `(): [const] Bar` is not satisfied | LL | (const || ().foo())(); | ^^^ + | +help: make the `impl` of trait `Bar` `const` + | +LL | impl const Bar for () { + | +++++ error: aborting due to 1 previous error diff --git a/tests/ui/traits/const-traits/call-const-trait-method-fail.stderr b/tests/ui/traits/const-traits/call-const-trait-method-fail.stderr index 4aaf53344c90a..c6f93629379ac 100644 --- a/tests/ui/traits/const-traits/call-const-trait-method-fail.stderr +++ b/tests/ui/traits/const-traits/call-const-trait-method-fail.stderr @@ -3,6 +3,11 @@ error[E0277]: the trait bound `u32: [const] Plus` is not satisfied | LL | a.plus(b) | ^ + | +help: make the `impl` of trait `Plus` `const` + | +LL | impl const Plus for u32 { + | +++++ error: aborting due to 1 previous error diff --git a/tests/ui/traits/const-traits/call-generic-method-fail.stderr b/tests/ui/traits/const-traits/call-generic-method-fail.stderr index a2fba141f7b89..6e75730b9b513 100644 --- a/tests/ui/traits/const-traits/call-generic-method-fail.stderr +++ b/tests/ui/traits/const-traits/call-generic-method-fail.stderr @@ -3,6 +3,11 @@ error[E0277]: the trait bound `T: [const] PartialEq` is not satisfied | LL | *t == *t | ^^^^^^^^ + | +note: trait `PartialEq` is implemented but not `const` + --> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL +note: trait `PartialEq` is implemented but not `const` + --> $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL error: aborting due to 1 previous error diff --git a/tests/ui/traits/const-traits/call-generic-method-nonconst.stderr b/tests/ui/traits/const-traits/call-generic-method-nonconst.stderr index 9c1e0fee9e711..b2ec41182a83b 100644 --- a/tests/ui/traits/const-traits/call-generic-method-nonconst.stderr +++ b/tests/ui/traits/const-traits/call-generic-method-nonconst.stderr @@ -11,6 +11,10 @@ note: required by a bound in `equals_self` | LL | const fn equals_self(t: &T) -> bool { | ^^^^^^^^^^^ required by this bound in `equals_self` +help: make the `impl` of trait `Foo` `const` + | +LL | impl const Foo for S { + | +++++ error: aborting due to 1 previous error diff --git a/tests/ui/traits/const-traits/const-check-fns-in-const-impl.stderr b/tests/ui/traits/const-traits/const-check-fns-in-const-impl.stderr index 599a5503b0f33..70704780ddce7 100644 --- a/tests/ui/traits/const-traits/const-check-fns-in-const-impl.stderr +++ b/tests/ui/traits/const-traits/const-check-fns-in-const-impl.stderr @@ -2,9 +2,15 @@ error[E0015]: cannot call non-const function `non_const` in constant functions --> $DIR/const-check-fns-in-const-impl.rs:14:16 | LL | fn foo() { non_const() } - | ^^^^^^^^^^^ + | -------- ^^^^^^^^^^^ + | | + | calls in constant functions are limited to constant functions, tuple structs and tuple variants | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants +note: function `non_const` is not const + --> $DIR/const-check-fns-in-const-impl.rs:11:1 + | +LL | fn non_const() {} + | ^^^^^^^^^^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/traits/const-traits/const-closure-trait-method-fail.stderr b/tests/ui/traits/const-traits/const-closure-trait-method-fail.stderr index fddd8d10bccc4..faacc86512441 100644 --- a/tests/ui/traits/const-traits/const-closure-trait-method-fail.stderr +++ b/tests/ui/traits/const-traits/const-closure-trait-method-fail.stderr @@ -3,6 +3,11 @@ error[E0277]: the trait bound `(): const Tr` is not satisfied | LL | const _: () = assert!(need_const_closure(Tr::a) == 42); | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: make the `impl` of trait `Tr` `const` + | +LL | impl const Tr for () { + | +++++ error: aborting due to 1 previous error diff --git a/tests/ui/traits/const-traits/const-default-method-bodies.stderr b/tests/ui/traits/const-traits/const-default-method-bodies.stderr index 03ca6f1d51155..22b6a9b5613a8 100644 --- a/tests/ui/traits/const-traits/const-default-method-bodies.stderr +++ b/tests/ui/traits/const-traits/const-default-method-bodies.stderr @@ -3,6 +3,11 @@ error[E0277]: the trait bound `NonConstImpl: [const] ConstDefaultFn` is not sati | LL | NonConstImpl.a(); | ^ + | +help: make the `impl` of trait `ConstDefaultFn` `const` + | +LL | impl const ConstDefaultFn for NonConstImpl { + | +++++ error: aborting due to 1 previous error diff --git a/tests/ui/traits/const-traits/const-drop-fail-2.precise.stderr b/tests/ui/traits/const-traits/const-drop-fail-2.precise.stderr index c2309ea6e122e..48c8852a7b8d4 100644 --- a/tests/ui/traits/const-traits/const-drop-fail-2.precise.stderr +++ b/tests/ui/traits/const-traits/const-drop-fail-2.precise.stderr @@ -16,6 +16,10 @@ note: required by a bound in `check` | LL | const fn check(_: T) {} | ^^^^^^^^^^^^^^^^ required by this bound in `check` +help: make the `impl` of trait `A` `const` + | +LL | impl const A for NonTrivialDrop {} + | +++++ error: aborting due to 1 previous error diff --git a/tests/ui/traits/const-traits/const-drop-fail-2.stock.stderr b/tests/ui/traits/const-traits/const-drop-fail-2.stock.stderr index c2309ea6e122e..48c8852a7b8d4 100644 --- a/tests/ui/traits/const-traits/const-drop-fail-2.stock.stderr +++ b/tests/ui/traits/const-traits/const-drop-fail-2.stock.stderr @@ -16,6 +16,10 @@ note: required by a bound in `check` | LL | const fn check(_: T) {} | ^^^^^^^^^^^^^^^^ required by this bound in `check` +help: make the `impl` of trait `A` `const` + | +LL | impl const A for NonTrivialDrop {} + | +++++ error: aborting due to 1 previous error diff --git a/tests/ui/traits/const-traits/const-impl-trait.stderr b/tests/ui/traits/const-traits/const-impl-trait.stderr index cbb68d8c9839e..12f5aa478aced 100644 --- a/tests/ui/traits/const-traits/const-impl-trait.stderr +++ b/tests/ui/traits/const-traits/const-impl-trait.stderr @@ -6,6 +6,8 @@ LL | assert!(cmp(&())); | | | required by a bound introduced by this call | +note: trait `PartialEq` is implemented but not `const` + --> $SRC_DIR/core/src/cmp.rs:LL:COL note: required by a bound in `cmp` --> $DIR/const-impl-trait.rs:11:23 | diff --git a/tests/ui/traits/const-traits/const-opaque.no.stderr b/tests/ui/traits/const-traits/const-opaque.no.stderr index acf19ba96ab39..591b81f976745 100644 --- a/tests/ui/traits/const-traits/const-opaque.no.stderr +++ b/tests/ui/traits/const-traits/const-opaque.no.stderr @@ -11,12 +11,21 @@ note: required by a bound in `bar` | LL | const fn bar(t: T) -> impl [const] Foo { | ^^^^^^^^^^^ required by this bound in `bar` +help: make the `impl` of trait `Foo` `const` + | +LL | impl const Foo for () { + | +++++ error[E0277]: the trait bound `(): const Foo` is not satisfied --> $DIR/const-opaque.rs:33:12 | LL | opaque.method(); | ^^^^^^ + | +help: make the `impl` of trait `Foo` `const` + | +LL | impl const Foo for () { + | +++++ error: aborting due to 2 previous errors diff --git a/tests/ui/traits/const-traits/const_derives/derive-const-gate.stderr b/tests/ui/traits/const-traits/const_derives/derive-const-gate.stderr index cbc62d602a473..ac393825ec720 100644 --- a/tests/ui/traits/const-traits/const_derives/derive-const-gate.stderr +++ b/tests/ui/traits/const-traits/const_derives/derive-const-gate.stderr @@ -21,9 +21,7 @@ error[E0015]: cannot call non-const method `Formatter::<'_>::write_str` in const --> $DIR/derive-const-gate.rs:1:16 | LL | #[derive_const(Debug)] - | ^^^^^ - | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants + | ^^^^^ calls in constant functions are limited to constant functions, tuple structs and tuple variants error: aborting due to 3 previous errors diff --git a/tests/ui/traits/const-traits/const_derives/derive-const-non-const-type.stderr b/tests/ui/traits/const-traits/const_derives/derive-const-non-const-type.stderr index 93638801895da..9f620fcf81b7c 100644 --- a/tests/ui/traits/const-traits/const_derives/derive-const-non-const-type.stderr +++ b/tests/ui/traits/const-traits/const_derives/derive-const-non-const-type.stderr @@ -11,9 +11,7 @@ error[E0015]: cannot call non-const method `Formatter::<'_>::debug_tuple_field1_ --> $DIR/derive-const-non-const-type.rs:12:16 | LL | #[derive_const(Debug)] - | ^^^^^ - | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants + | ^^^^^ calls in constant functions are limited to constant functions, tuple structs and tuple variants error: aborting due to 2 previous errors diff --git a/tests/ui/traits/const-traits/const_derives/derive-const-use.stderr b/tests/ui/traits/const-traits/const_derives/derive-const-use.stderr index 4ea11a0c7ed91..caf72aae82add 100644 --- a/tests/ui/traits/const-traits/const_derives/derive-const-use.stderr +++ b/tests/ui/traits/const-traits/const_derives/derive-const-use.stderr @@ -5,6 +5,9 @@ LL | #[derive_const(Default, PartialEq)] | --------- in this derive macro expansion LL | pub struct S((), A); | ^^ + | +note: trait `PartialEq` is implemented but not `const` + --> $SRC_DIR/core/src/cmp.rs:LL:COL error: aborting due to 1 previous error diff --git a/tests/ui/traits/const-traits/cross-crate.gatednc.stderr b/tests/ui/traits/const-traits/cross-crate.gatednc.stderr index 1da519151182a..fe45ff188efb4 100644 --- a/tests/ui/traits/const-traits/cross-crate.gatednc.stderr +++ b/tests/ui/traits/const-traits/cross-crate.gatednc.stderr @@ -3,6 +3,12 @@ error[E0277]: the trait bound `cross_crate::NonConst: [const] cross_crate::MyTra | LL | NonConst.func(); | ^^^^ + | +note: trait `MyTrait` is implemented but not `const` + --> $DIR/auxiliary/cross-crate.rs:12:1 + | +LL | impl MyTrait for NonConst { + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/traits/const-traits/cross-crate.stock.stderr b/tests/ui/traits/const-traits/cross-crate.stock.stderr index 44a60c99ae9ea..89278ff56ad0c 100644 --- a/tests/ui/traits/const-traits/cross-crate.stock.stderr +++ b/tests/ui/traits/const-traits/cross-crate.stock.stderr @@ -1,10 +1,12 @@ error[E0658]: cannot call conditionally-const method `::func` in constant functions --> $DIR/cross-crate.rs:22:11 | +LL | const fn const_context() { + | ------------------------ calls in constant functions are limited to constant functions, tuple structs and tuple variants +... LL | Const.func(); | ^^^^^^ | - = 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 diff --git a/tests/ui/traits/const-traits/cross-crate.stocknc.stderr b/tests/ui/traits/const-traits/cross-crate.stocknc.stderr index 766c20aa8211f..6269e74fd1d2b 100644 --- a/tests/ui/traits/const-traits/cross-crate.stocknc.stderr +++ b/tests/ui/traits/const-traits/cross-crate.stocknc.stderr @@ -1,18 +1,21 @@ error[E0015]: cannot call non-const method `::func` in constant functions --> $DIR/cross-crate.rs:19:14 | +LL | const fn const_context() { + | ------------------------ calls in constant functions are limited to constant functions, tuple structs and tuple variants +LL | #[cfg(any(stocknc, gatednc))] 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 fn const_context() { + | ------------------------ calls in constant functions are limited to constant functions, tuple structs and tuple variants +... LL | Const.func(); | ^^^^^^ | - = 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 diff --git a/tests/ui/traits/const-traits/default-method-body-is-const-body-checking.stderr b/tests/ui/traits/const-traits/default-method-body-is-const-body-checking.stderr index 2e236cecfb475..3ce646ec5027f 100644 --- a/tests/ui/traits/const-traits/default-method-body-is-const-body-checking.stderr +++ b/tests/ui/traits/const-traits/default-method-body-is-const-body-checking.stderr @@ -9,6 +9,10 @@ note: required by a bound in `foo` | LL | const fn foo() where T: [const] Tr {} | ^^^^^^^^^^ required by this bound in `foo` +help: make the `impl` of trait `Tr` `const` + | +LL | impl const Tr for () {} + | +++++ error: aborting due to 1 previous error diff --git a/tests/ui/traits/const-traits/default-method-body-is-const-same-trait-ck.stderr b/tests/ui/traits/const-traits/default-method-body-is-const-same-trait-ck.stderr index 2dc2d48461749..f473a687efcb0 100644 --- a/tests/ui/traits/const-traits/default-method-body-is-const-same-trait-ck.stderr +++ b/tests/ui/traits/const-traits/default-method-body-is-const-same-trait-ck.stderr @@ -3,6 +3,11 @@ error[E0277]: the trait bound `(): [const] Tr` is not satisfied | LL | ().a() | ^ + | +help: make the `impl` of trait `Tr` `const` + | +LL | impl const Tr for () {} + | +++++ error: aborting due to 1 previous error diff --git a/tests/ui/traits/const-traits/inline-incorrect-early-bound-in-ctfe.stderr b/tests/ui/traits/const-traits/inline-incorrect-early-bound-in-ctfe.stderr index ad0829ff05fb0..092a5ac05b823 100644 --- a/tests/ui/traits/const-traits/inline-incorrect-early-bound-in-ctfe.stderr +++ b/tests/ui/traits/const-traits/inline-incorrect-early-bound-in-ctfe.stderr @@ -10,10 +10,23 @@ LL | fn foo(self) { error[E0015]: cannot call non-const method `<() as Trait>::foo` in constant functions --> $DIR/inline-incorrect-early-bound-in-ctfe.rs:26:8 | +LL | const fn foo() { + | -------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants LL | ().foo(); | ^^^^^ | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants +note: method `foo` is not const because trait `Trait` is not const + --> $DIR/inline-incorrect-early-bound-in-ctfe.rs:13:1 + | +LL | trait Trait { + | ^^^^^^^^^^^ this trait is not const +LL | fn foo(self); + | ------------- this method is not const +help: consider making trait `Trait` const + | +LL + #[const_trait] +LL | trait Trait { + | error: aborting due to 2 previous errors diff --git a/tests/ui/traits/const-traits/issue-79450.stderr b/tests/ui/traits/const-traits/issue-79450.stderr index 5bdebbbfb032b..dd78b464e7825 100644 --- a/tests/ui/traits/const-traits/issue-79450.stderr +++ b/tests/ui/traits/const-traits/issue-79450.stderr @@ -1,10 +1,13 @@ error[E0015]: cannot call non-const function `_print` in constant functions --> $DIR/issue-79450.rs:9:9 | +LL | fn prov(&self) { + | -------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants LL | println!("lul"); | ^^^^^^^^^^^^^^^ | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants +note: function `_print` is not const + --> $SRC_DIR/std/src/io/stdio.rs:LL:COL = note: this error originates in the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 1 previous error diff --git a/tests/ui/traits/const-traits/issue-88155.stderr b/tests/ui/traits/const-traits/issue-88155.stderr index 96a3c4187f5c2..2df4a0004b6a6 100644 --- a/tests/ui/traits/const-traits/issue-88155.stderr +++ b/tests/ui/traits/const-traits/issue-88155.stderr @@ -1,10 +1,23 @@ error[E0015]: cannot call non-const associated function `::assoc` in constant functions --> $DIR/issue-88155.rs:8:5 | +LL | pub const fn foo() -> bool { + | -------------------------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants LL | T::assoc() | ^^^^^^^^^^ | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants +note: associated function `assoc` is not const because trait `A` is not const + --> $DIR/issue-88155.rs:3:1 + | +LL | pub trait A { + | ^^^^^^^^^^^ this trait is not const +LL | fn assoc() -> bool; + | ------------------- this associated function is not const +help: consider making trait `A` const + | +LL + #[const_trait] +LL | pub trait A { + | error: aborting due to 1 previous error diff --git a/tests/ui/traits/const-traits/item-bound-entailment-fails.stderr b/tests/ui/traits/const-traits/item-bound-entailment-fails.stderr index 8e5894a32966f..3c150c77a6916 100644 --- a/tests/ui/traits/const-traits/item-bound-entailment-fails.stderr +++ b/tests/ui/traits/const-traits/item-bound-entailment-fails.stderr @@ -9,6 +9,10 @@ note: required by a bound in `Foo::Assoc` | LL | type Assoc: [const] Bar | ^^^^^^^^^^^ required by this bound in `Foo::Assoc` +help: make the `impl` of trait `Bar` `const` + | +LL | impl const Bar for N where T: Bar {} + | +++++ error[E0277]: the trait bound `T: [const] Bar` is not satisfied --> $DIR/item-bound-entailment-fails.rs:24:21 diff --git a/tests/ui/traits/const-traits/minicore-deref-fail.stderr b/tests/ui/traits/const-traits/minicore-deref-fail.stderr index 4329b235756be..e6c087cb9d822 100644 --- a/tests/ui/traits/const-traits/minicore-deref-fail.stderr +++ b/tests/ui/traits/const-traits/minicore-deref-fail.stderr @@ -3,6 +3,11 @@ error[E0277]: the trait bound `Ty: [const] minicore::Deref` is not satisfied | LL | *Ty; | ^^^ + | +help: make the `impl` of trait `Deref` `const` + | +LL | impl const Deref for Ty { + | +++++ error: aborting due to 1 previous error diff --git a/tests/ui/traits/const-traits/minicore-fn-fail.stderr b/tests/ui/traits/const-traits/minicore-fn-fail.stderr index c02a067774b56..eb840d421f488 100644 --- a/tests/ui/traits/const-traits/minicore-fn-fail.stderr +++ b/tests/ui/traits/const-traits/minicore-fn-fail.stderr @@ -11,6 +11,10 @@ note: required by a bound in `call_indirect` | LL | const fn call_indirect(t: &T) { t() } | ^^^^^^^^^^^^ required by this bound in `call_indirect` +help: make the `impl` of trait `Foo` `const` + | +LL | impl const Foo for () {} + | +++++ error: aborting due to 1 previous error diff --git a/tests/ui/traits/const-traits/no-explicit-const-params.stderr b/tests/ui/traits/const-traits/no-explicit-const-params.stderr index 6955e9ab2985d..47fa65b2479be 100644 --- a/tests/ui/traits/const-traits/no-explicit-const-params.stderr +++ b/tests/ui/traits/const-traits/no-explicit-const-params.stderr @@ -59,6 +59,11 @@ error[E0277]: the trait bound `(): const Bar` is not satisfied | LL | <() as Bar>::bar(); | ^^ + | +help: make the `impl` of trait `Bar` `const` + | +LL | impl const Bar for () { + | +++++ error: aborting due to 5 previous errors diff --git a/tests/ui/traits/const-traits/specializing-constness-2.stderr b/tests/ui/traits/const-traits/specializing-constness-2.stderr index 850e6939daebc..2a34cd1c4f82d 100644 --- a/tests/ui/traits/const-traits/specializing-constness-2.stderr +++ b/tests/ui/traits/const-traits/specializing-constness-2.stderr @@ -3,6 +3,11 @@ error[E0277]: the trait bound `T: [const] A` is not satisfied | LL | ::a(); | ^ + | +help: make the `impl` of trait `A` `const` + | +LL | impl const A for T { + | +++++ error: aborting due to 1 previous error diff --git a/tests/ui/traits/const-traits/staged-api-user-crate.stderr b/tests/ui/traits/const-traits/staged-api-user-crate.stderr index 81611da9e748c..1baa8b308284e 100644 --- a/tests/ui/traits/const-traits/staged-api-user-crate.stderr +++ b/tests/ui/traits/const-traits/staged-api-user-crate.stderr @@ -1,10 +1,11 @@ error[E0658]: cannot call conditionally-const associated function `::func` in constant functions --> $DIR/staged-api-user-crate.rs:12:5 | +LL | const fn stable_const_context() { + | ------------------------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants LL | Unstable::func(); | ^^^^^^^^^^^^^^^^ | - = 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 diff --git a/tests/ui/traits/const-traits/std-impl-gate.stock.stderr b/tests/ui/traits/const-traits/std-impl-gate.stock.stderr index 261f68bebdb25..3f40f602eefe2 100644 --- a/tests/ui/traits/const-traits/std-impl-gate.stock.stderr +++ b/tests/ui/traits/const-traits/std-impl-gate.stock.stderr @@ -1,10 +1,11 @@ error[E0658]: cannot call conditionally-const associated function ` as Default>::default` in constant functions --> $DIR/std-impl-gate.rs:13:5 | +LL | const fn const_context() -> Vec { + | -------------------------------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants LL | Default::default() | ^^^^^^^^^^^^^^^^^^ | - = 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 diff --git a/tests/ui/traits/const-traits/super-traits-fail-2.nn.stderr b/tests/ui/traits/const-traits/super-traits-fail-2.nn.stderr index 0ecbad64bc853..84fc743e4a2b7 100644 --- a/tests/ui/traits/const-traits/super-traits-fail-2.nn.stderr +++ b/tests/ui/traits/const-traits/super-traits-fail-2.nn.stderr @@ -48,10 +48,23 @@ LL | #[const_trait] trait Foo { error[E0015]: cannot call non-const method `::a` in constant functions --> $DIR/super-traits-fail-2.rs:20:7 | +LL | const fn foo(x: &T) { + | --------------------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants LL | x.a(); | ^^^ | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants +note: method `a` is not const because trait `Foo` is not const + --> $DIR/super-traits-fail-2.rs:6:1 + | +LL | trait Foo { + | ^^^^^^^^^ this trait is not const +LL | fn a(&self); + | ------------ this method is not const +help: consider making trait `Foo` const + | +LL + #[const_trait] +LL | trait Foo { + | error: aborting due to 5 previous errors diff --git a/tests/ui/traits/const-traits/super-traits-fail-2.ny.stderr b/tests/ui/traits/const-traits/super-traits-fail-2.ny.stderr index 0e5b697d1ddef..9d72e149aab28 100644 --- a/tests/ui/traits/const-traits/super-traits-fail-2.ny.stderr +++ b/tests/ui/traits/const-traits/super-traits-fail-2.ny.stderr @@ -60,10 +60,23 @@ LL | #[const_trait] trait Foo { error[E0015]: cannot call non-const method `::a` in constant functions --> $DIR/super-traits-fail-2.rs:20:7 | +LL | const fn foo(x: &T) { + | --------------------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants LL | x.a(); | ^^^ | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants +note: method `a` is not const because trait `Foo` is not const + --> $DIR/super-traits-fail-2.rs:6:1 + | +LL | trait Foo { + | ^^^^^^^^^ this trait is not const +LL | fn a(&self); + | ------------ this method is not const +help: consider making trait `Foo` const + | +LL + #[const_trait] +LL | trait Foo { + | error: aborting due to 6 previous errors diff --git a/tests/ui/traits/const-traits/super-traits-fail-3.nnn.stderr b/tests/ui/traits/const-traits/super-traits-fail-3.nnn.stderr index a0ae60526ef3f..2625f94460616 100644 --- a/tests/ui/traits/const-traits/super-traits-fail-3.nnn.stderr +++ b/tests/ui/traits/const-traits/super-traits-fail-3.nnn.stderr @@ -91,10 +91,25 @@ LL | #[const_trait] trait Bar: [const] Foo {} error[E0015]: cannot call non-const method `::a` in constant functions --> $DIR/super-traits-fail-3.rs:36:7 | +LL | const fn foo(x: &T) { + | ----------------------------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants +... LL | x.a(); | ^^^ | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants +note: method `a` is not const because trait `Foo` is not const + --> $DIR/super-traits-fail-3.rs:17:1 + | +LL | trait Foo { + | ^^^^^^^^^ this trait is not const +LL | fn a(&self); + | ------------ this method is not const + = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable `#[const_trait]` +help: consider making trait `Foo` const + | +LL + #[const_trait] +LL | trait Foo { + | error: aborting due to 9 previous errors diff --git a/tests/ui/traits/const-traits/super-traits-fail-3.nny.stderr b/tests/ui/traits/const-traits/super-traits-fail-3.nny.stderr index a0ae60526ef3f..2625f94460616 100644 --- a/tests/ui/traits/const-traits/super-traits-fail-3.nny.stderr +++ b/tests/ui/traits/const-traits/super-traits-fail-3.nny.stderr @@ -91,10 +91,25 @@ LL | #[const_trait] trait Bar: [const] Foo {} error[E0015]: cannot call non-const method `::a` in constant functions --> $DIR/super-traits-fail-3.rs:36:7 | +LL | const fn foo(x: &T) { + | ----------------------------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants +... LL | x.a(); | ^^^ | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants +note: method `a` is not const because trait `Foo` is not const + --> $DIR/super-traits-fail-3.rs:17:1 + | +LL | trait Foo { + | ^^^^^^^^^ this trait is not const +LL | fn a(&self); + | ------------ this method is not const + = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable `#[const_trait]` +help: consider making trait `Foo` const + | +LL + #[const_trait] +LL | trait Foo { + | error: aborting due to 9 previous errors 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 b00ad706a5fa1..155263656e368 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 @@ -41,10 +41,12 @@ LL | #[cfg_attr(any(yyy, yny, nyy, nyn), const_trait)] error[E0658]: cannot call conditionally-const method `::a` in constant functions --> $DIR/super-traits-fail-3.rs:36:7 | +LL | const fn foo(x: &T) { + | ----------------------------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants +... LL | x.a(); | ^^^ | - = 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 diff --git a/tests/ui/traits/const-traits/super-traits-fail-3.nyy.stderr b/tests/ui/traits/const-traits/super-traits-fail-3.nyy.stderr index b00ad706a5fa1..155263656e368 100644 --- a/tests/ui/traits/const-traits/super-traits-fail-3.nyy.stderr +++ b/tests/ui/traits/const-traits/super-traits-fail-3.nyy.stderr @@ -41,10 +41,12 @@ LL | #[cfg_attr(any(yyy, yny, nyy, nyn), const_trait)] error[E0658]: cannot call conditionally-const method `::a` in constant functions --> $DIR/super-traits-fail-3.rs:36:7 | +LL | const fn foo(x: &T) { + | ----------------------------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants +... LL | x.a(); | ^^^ | - = 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 diff --git a/tests/ui/traits/const-traits/super-traits-fail-3.ynn.stderr b/tests/ui/traits/const-traits/super-traits-fail-3.ynn.stderr index c8ec77c2f0930..4895b5b0cd08b 100644 --- a/tests/ui/traits/const-traits/super-traits-fail-3.ynn.stderr +++ b/tests/ui/traits/const-traits/super-traits-fail-3.ynn.stderr @@ -71,10 +71,24 @@ LL | #[const_trait] trait Bar: [const] Foo {} error[E0015]: cannot call non-const method `::a` in constant functions --> $DIR/super-traits-fail-3.rs:36:7 | +LL | const fn foo(x: &T) { + | ----------------------------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants +... LL | x.a(); | ^^^ | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants +note: method `a` is not const because trait `Foo` is not const + --> $DIR/super-traits-fail-3.rs:17:1 + | +LL | trait Foo { + | ^^^^^^^^^ this trait is not const +LL | fn a(&self); + | ------------ this method is not const +help: consider making trait `Foo` const + | +LL + #[const_trait] +LL | trait Foo { + | error: aborting due to 7 previous errors diff --git a/tests/ui/traits/const-traits/super-traits-fail-3.yny.stderr b/tests/ui/traits/const-traits/super-traits-fail-3.yny.stderr index a820239cde012..29bce84326cab 100644 --- a/tests/ui/traits/const-traits/super-traits-fail-3.yny.stderr +++ b/tests/ui/traits/const-traits/super-traits-fail-3.yny.stderr @@ -60,10 +60,24 @@ LL | #[const_trait] trait Foo { error[E0015]: cannot call non-const method `::a` in constant functions --> $DIR/super-traits-fail-3.rs:36:7 | +LL | const fn foo(x: &T) { + | ----------------------------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants +... LL | x.a(); | ^^^ | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants +note: method `a` is not const because trait `Foo` is not const + --> $DIR/super-traits-fail-3.rs:17:1 + | +LL | trait Foo { + | ^^^^^^^^^ this trait is not const +LL | fn a(&self); + | ------------ this method is not const +help: consider making trait `Foo` const + | +LL + #[const_trait] +LL | trait Foo { + | error: aborting due to 6 previous errors diff --git a/tests/ui/traits/const-traits/super-traits-fail.stderr b/tests/ui/traits/const-traits/super-traits-fail.stderr index e19aa30cf95c3..3010a5df0c31f 100644 --- a/tests/ui/traits/const-traits/super-traits-fail.stderr +++ b/tests/ui/traits/const-traits/super-traits-fail.stderr @@ -3,6 +3,11 @@ error[E0277]: the trait bound `S: [const] Foo` is not satisfied | LL | impl const Bar for S {} | ^ + | +help: make the `impl` of trait `Foo` `const` + | +LL | impl const Foo for S { + | +++++ error: aborting due to 1 previous error diff --git a/tests/ui/typeck/typeck_type_placeholder_item.stderr b/tests/ui/typeck/typeck_type_placeholder_item.stderr index 87750ee6dc140..a58ee60a11471 100644 --- a/tests/ui/typeck/typeck_type_placeholder_item.stderr +++ b/tests/ui/typeck/typeck_type_placeholder_item.stderr @@ -630,25 +630,47 @@ error[E0015]: cannot call non-const function `map::` in constants --> $DIR/typeck_type_placeholder_item.rs:231:22 | LL | const _: Option<_> = map(value); - | ^^^^^^^^^^ + | ------------------ ^^^^^^^^^^ + | | + | calls in constants are limited to constant functions, tuple structs and tuple variants | - = note: calls in constants are limited to constant functions, tuple structs and tuple variants +note: function `map` is not const + --> $DIR/typeck_type_placeholder_item.rs:222:1 + | +LL | fn map(_: fn() -> Option<&'static T>) -> Option { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0015]: cannot call non-const method ` as Iterator>::filter::<{closure@$DIR/typeck_type_placeholder_item.rs:240:29: 240:32}>` in constants --> $DIR/typeck_type_placeholder_item.rs:240:22 | LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x); - | ^^^^^^^^^^^^^^^^^^^^^^ + | ---------- ^^^^^^^^^^^^^^^^^^^^^^ + | | + | calls in constants are limited to constant functions, tuple structs and tuple variants + | +note: method `filter` is not const because trait `Iterator` is not const + --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL + | + = note: this trait is not const + ::: $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL | - = note: calls in constants are limited to constant functions, tuple structs and tuple variants + = note: this method is not const error[E0015]: cannot call non-const method `, {closure@$DIR/typeck_type_placeholder_item.rs:240:29: 240:32}> as Iterator>::map::` in constants --> $DIR/typeck_type_placeholder_item.rs:240:45 | LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x); - | ^^^^^^^^^^^^^^ + | ---------- ^^^^^^^^^^^^^^ + | | + | calls in constants are limited to constant functions, tuple structs and tuple variants + | +note: method `map` is not const because trait `Iterator` is not const + --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL + | + = note: this trait is not const + ::: $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL | - = note: calls in constants are limited to constant functions, tuple structs and tuple variants + = note: this method is not const error: aborting due to 83 previous errors