From 853ca8cb8b30e13a10f475f99093a83e9dfaa65c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Mon, 9 Dec 2024 21:51:43 +0000 Subject: [PATCH] reword messages and add more test cases for stable/nightly and feature enabled/disabled --- compiler/rustc_hir_analysis/messages.ftl | 6 +- compiler/rustc_hir_analysis/src/collect.rs | 16 ++- compiler/rustc_hir_analysis/src/errors.rs | 2 + .../src/hir_ty_lowering/mod.rs | 19 +++- .../const-super-trait.nightly.disabled.stderr | 66 ++++++++++++ .../const-super-trait.nightly.enabled.stderr | 45 ++++++++ .../const-super-trait.rs | 13 +++ .../const-super-trait.stable.disabled.stderr | 64 +++++++++++ .../const-super-trait.stable.enabled.stderr | 54 ++++++++++ .../const-trait-stable-toolchain/rmake.rs | 51 +++++++++ tests/ui/consts/const-try.stderr | 4 +- .../consts/rustc-impl-const-stability.stderr | 2 +- .../call-const-trait-method-pass.stderr | 2 +- .../call-generic-method-chain.stderr | 2 +- .../call-generic-method-dup-bound.stderr | 2 +- .../call-generic-method-pass.stderr | 2 +- .../const-bounds-non-const-trait.stderr | 6 +- .../const-impl-requires-const-trait.stderr | 4 +- .../const_derives/derive-const-gate.stderr | 2 +- .../derive-const-non-const-type.stderr | 2 +- .../const_derives/derive-const-use.stderr | 8 +- .../derive-const-with-params.stderr | 2 +- .../effects/spec-effectvar-ice.stderr | 10 +- .../ice-119717-constant-lifetime.stderr | 2 +- .../ice-126148-failed-to-normalize.stderr | 4 +- .../super-traits-fail-2.nn.stderr | 6 +- .../super-traits-fail-2.ny.stderr | 10 +- .../super-traits-fail-3.nnn.stderr | 102 ++++++++++++++++++ .../super-traits-fail-3.nny.stderr | 102 ++++++++++++++++++ .../super-traits-fail-3.nyn.stderr | 53 +++++++++ .../super-traits-fail-3.nyy.stderr | 53 +++++++++ .../const-traits/super-traits-fail-3.rs | 43 +++++--- ....stderr => super-traits-fail-3.ynn.stderr} | 26 ++--- ....stderr => super-traits-fail-3.yny.stderr} | 22 ++-- ....stderr => super-traits-fail-3.yyn.stderr} | 14 +-- .../trait-default-body-stability.stderr | 4 +- 36 files changed, 732 insertions(+), 93 deletions(-) create mode 100644 tests/run-make/const-trait-stable-toolchain/const-super-trait.nightly.disabled.stderr create mode 100644 tests/run-make/const-trait-stable-toolchain/const-super-trait.nightly.enabled.stderr create mode 100644 tests/run-make/const-trait-stable-toolchain/const-super-trait.rs create mode 100644 tests/run-make/const-trait-stable-toolchain/const-super-trait.stable.disabled.stderr create mode 100644 tests/run-make/const-trait-stable-toolchain/const-super-trait.stable.enabled.stderr create mode 100644 tests/run-make/const-trait-stable-toolchain/rmake.rs create mode 100644 tests/ui/traits/const-traits/super-traits-fail-3.nnn.stderr create mode 100644 tests/ui/traits/const-traits/super-traits-fail-3.nny.stderr create mode 100644 tests/ui/traits/const-traits/super-traits-fail-3.nyn.stderr create mode 100644 tests/ui/traits/const-traits/super-traits-fail-3.nyy.stderr rename tests/ui/traits/const-traits/{super-traits-fail-3.nn.stderr => super-traits-fail-3.ynn.stderr} (72%) rename tests/ui/traits/const-traits/{super-traits-fail-3.ny.stderr => super-traits-fail-3.yny.stderr} (72%) rename tests/ui/traits/const-traits/{super-traits-fail-3.yn.stderr => super-traits-fail-3.yyn.stderr} (73%) diff --git a/compiler/rustc_hir_analysis/messages.ftl b/compiler/rustc_hir_analysis/messages.ftl index b93ef8b3c1e44..32498d9c5ab5b 100644 --- a/compiler/rustc_hir_analysis/messages.ftl +++ b/compiler/rustc_hir_analysis/messages.ftl @@ -99,11 +99,11 @@ hir_analysis_coercion_between_struct_single_note = expected a single field to be hir_analysis_const_bound_for_non_const_trait = `{$modifier}` can only be applied to `#[const_trait]` traits .label = can't be applied to `{$trait_name}` .note = `{$trait_name}` can't be used with `{$modifier}` because it isn't annotated with `#[const_trait]` - .suggestion = mark `{$trait_name}` as `const` + .suggestion = {$suggestion_pre}mark `{$trait_name}` as `#[const_trait]` to allow it to have `const` implementations hir_analysis_const_impl_for_non_const_trait = const `impl` for trait `{$trait_name}` which is not marked with `#[const_trait]` - .label = not marked with `#[const_trait]` - .suggestion = mark `{$trait_name}` as `const` + .label = this trait is not `const` + .suggestion = {$suggestion_pre}mark `{$trait_name}` as `#[const_trait]` to allow it to have `const` implementations .note = marking a trait with `#[const_trait]` ensures all default method bodies are `const` .adding = adding a non-const method body in the future would be a breaking change diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index a4636da3f6213..1bd0585e77134 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -1637,11 +1637,23 @@ fn check_impl_constness( } let trait_name = tcx.item_name(trait_def_id).to_string(); + let (local_trait_span, suggestion_pre) = + match (trait_def_id.is_local(), tcx.sess.is_nightly_build()) { + (true, true) => ( + Some(tcx.def_span(trait_def_id).shrink_to_lo()), + if tcx.features().const_trait_impl() { + "" + } else { + "enable `#![feature(const_trait_impl)]` in your crate and " + }, + ), + (false, _) | (_, false) => (None, ""), + }; Some(tcx.dcx().emit_err(errors::ConstImplForNonConstTrait { trait_ref_span: hir_trait_ref.path.span, trait_name, - local_trait_span: - trait_def_id.as_local().map(|_| tcx.def_span(trait_def_id).shrink_to_lo()), + local_trait_span, + suggestion_pre, marking: (), adding: (), })) diff --git a/compiler/rustc_hir_analysis/src/errors.rs b/compiler/rustc_hir_analysis/src/errors.rs index 0a8562c8f72e6..7f62ccc91f09a 100644 --- a/compiler/rustc_hir_analysis/src/errors.rs +++ b/compiler/rustc_hir_analysis/src/errors.rs @@ -539,6 +539,7 @@ pub(crate) struct ConstImplForNonConstTrait { style = "verbose" )] pub local_trait_span: Option, + pub suggestion_pre: &'static str, #[note] pub marking: (), #[note(hir_analysis_adding)] @@ -554,6 +555,7 @@ pub(crate) struct ConstBoundForNonConstTrait { pub modifier: &'static str, #[note] pub def_span: Option, + pub suggestion_pre: &'static str, #[suggestion( applicability = "machine-applicable", code = "#[const_trait] ", diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs index fd7f15c0c79c3..09e46517cea8b 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs @@ -737,16 +737,25 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { if let hir::BoundConstness::Always(span) | hir::BoundConstness::Maybe(span) = constness && !self.tcx().is_const_trait(trait_def_id) { - let (def_span, suggestion) = if trait_def_id.is_local() { - (None, Some(tcx.def_span(trait_def_id).shrink_to_lo())) - } else { - (Some(tcx.def_span(trait_def_id)), None) - }; + let (def_span, suggestion, suggestion_pre) = + match (trait_def_id.is_local(), self.tcx().sess.is_nightly_build()) { + (true, true) => ( + None, + Some(tcx.def_span(trait_def_id).shrink_to_lo()), + if self.tcx().features().const_trait_impl() { + "" + } else { + "enable `#![feature(const_trait_impl)]` in your crate and " + }, + ), + (false, _) | (_, false) => (Some(tcx.def_span(trait_def_id)), None, ""), + }; self.dcx().emit_err(crate::errors::ConstBoundForNonConstTrait { span, modifier: constness.as_str(), def_span, trait_name: self.tcx().def_path_str(trait_def_id), + suggestion_pre, suggestion, }); } 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 new file mode 100644 index 0000000000000..596f7c510be52 --- /dev/null +++ b/tests/run-make/const-trait-stable-toolchain/const-super-trait.nightly.disabled.stderr @@ -0,0 +1,66 @@ +error: `~const` is not allowed here + --> const-super-trait.rs:7:12 + | +LL | trait Bar: ~const Foo {} + | ^^^^^^ + | +note: this trait is not a `#[const_trait]`, so it cannot have `~const` trait bounds + --> const-super-trait.rs:7:1 + | +LL | trait Bar: ~const Foo {} + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0658]: const trait impls are experimental + --> const-super-trait.rs:7:12 + | +LL | trait Bar: ~const Foo {} + | ^^^^^^ + | + = note: see issue #67792 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 + +error[E0658]: const trait impls are experimental + --> const-super-trait.rs:9:17 + | +LL | const fn foo(x: &T) { + | ^^^^^^ + | + = note: see issue #67792 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 + +error: `~const` can only be applied to `#[const_trait]` traits + --> const-super-trait.rs:7:12 + | +LL | trait Bar: ~const Foo {} + | ^^^^^^ can't be applied to `Foo` + | +help: enable `#![feature(const_trait_impl)]` in your crate and mark `Foo` as `#[const_trait]` to allow it to have `const` implementations + | +LL | #[const_trait] trait Foo { + | ++++++++++++++ + +error: `~const` can only be applied to `#[const_trait]` traits + --> const-super-trait.rs:9:17 + | +LL | const fn foo(x: &T) { + | ^^^^^^ can't be applied to `Bar` + | +help: enable `#![feature(const_trait_impl)]` in your crate and mark `Bar` as `#[const_trait]` to allow it to have `const` implementations + | +LL | #[const_trait] trait Bar: ~const Foo {} + | ++++++++++++++ + +error[E0015]: cannot call non-const fn `::a` in constant functions + --> const-super-trait.rs:10:7 + | +LL | x.a(); + | ^^^ + | + = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants + +error: aborting due to 6 previous errors + +Some errors have detailed explanations: E0015, E0658. +For more information about an error, try `rustc --explain E0015`. 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 new file mode 100644 index 0000000000000..7235278d1bd78 --- /dev/null +++ b/tests/run-make/const-trait-stable-toolchain/const-super-trait.nightly.enabled.stderr @@ -0,0 +1,45 @@ +error: `~const` is not allowed here + --> const-super-trait.rs:7:12 + | +LL | trait Bar: ~const Foo {} + | ^^^^^^ + | +note: this trait is not a `#[const_trait]`, so it cannot have `~const` trait bounds + --> const-super-trait.rs:7:1 + | +LL | trait Bar: ~const Foo {} + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error: `~const` can only be applied to `#[const_trait]` traits + --> const-super-trait.rs:7:12 + | +LL | trait Bar: ~const Foo {} + | ^^^^^^ can't be applied to `Foo` + | +help: mark `Foo` as `#[const_trait]` to allow it to have `const` implementations + | +LL | #[const_trait] trait Foo { + | ++++++++++++++ + +error: `~const` can only be applied to `#[const_trait]` traits + --> const-super-trait.rs:9:17 + | +LL | const fn foo(x: &T) { + | ^^^^^^ can't be applied to `Bar` + | +help: mark `Bar` as `#[const_trait]` to allow it to have `const` implementations + | +LL | #[const_trait] trait Bar: ~const Foo {} + | ++++++++++++++ + +error[E0015]: cannot call non-const fn `::a` in constant functions + --> const-super-trait.rs:10:7 + | +LL | x.a(); + | ^^^ + | + = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0015`. diff --git a/tests/run-make/const-trait-stable-toolchain/const-super-trait.rs b/tests/run-make/const-trait-stable-toolchain/const-super-trait.rs new file mode 100644 index 0000000000000..bb5a21a3f1cf6 --- /dev/null +++ b/tests/run-make/const-trait-stable-toolchain/const-super-trait.rs @@ -0,0 +1,13 @@ +#![cfg_attr(feature_enabled, feature(const_trait_impl))] + +trait Foo { + fn a(&self); +} + +trait Bar: ~const Foo {} + +const fn foo(x: &T) { + x.a(); +} + +fn main() {} \ No newline at end of file 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 new file mode 100644 index 0000000000000..eacdaf5e36909 --- /dev/null +++ b/tests/run-make/const-trait-stable-toolchain/const-super-trait.stable.disabled.stderr @@ -0,0 +1,64 @@ +error: `~const` is not allowed here + --> const-super-trait.rs:7:12 + | +7 | trait Bar: ~const Foo {} + | ^^^^^^ + | +note: this trait is not a `#[const_trait]`, so it cannot have `~const` trait bounds + --> const-super-trait.rs:7:1 + | +7 | trait Bar: ~const Foo {} + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0658]: const trait impls are experimental + --> const-super-trait.rs:7:12 + | +7 | trait Bar: ~const Foo {} + | ^^^^^^ + | + = note: see issue #67792 for more information + +error[E0658]: const trait impls are experimental + --> const-super-trait.rs:9:17 + | +9 | const fn foo(x: &T) { + | ^^^^^^ + | + = note: see issue #67792 for more information + +error: `~const` can only be applied to `#[const_trait]` traits + --> const-super-trait.rs:7:12 + | +7 | trait Bar: ~const Foo {} + | ^^^^^^ can't be applied to `Foo` + | +note: `Foo` can't be used with `~const` because it isn't annotated with `#[const_trait]` + --> const-super-trait.rs:3:1 + | +3 | trait Foo { + | ^^^^^^^^^ + +error: `~const` can only be applied to `#[const_trait]` traits + --> const-super-trait.rs:9:17 + | +9 | const fn foo(x: &T) { + | ^^^^^^ can't be applied to `Bar` + | +note: `Bar` can't be used with `~const` because it isn't annotated with `#[const_trait]` + --> const-super-trait.rs:7:1 + | +7 | trait Bar: ~const Foo {} + | ^^^^^^^^^^^^^^^^^^^^^ + +error[E0015]: cannot call non-const fn `::a` in constant functions + --> const-super-trait.rs:10:7 + | +10 | x.a(); + | ^^^ + | + = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants + +error: aborting due to 6 previous errors + +Some errors have detailed explanations: E0015, E0658. +For more information about an error, try `rustc --explain E0015`. 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 new file mode 100644 index 0000000000000..e4943ec86a8c9 --- /dev/null +++ b/tests/run-make/const-trait-stable-toolchain/const-super-trait.stable.enabled.stderr @@ -0,0 +1,54 @@ +error: `~const` is not allowed here + --> const-super-trait.rs:7:12 + | +7 | trait Bar: ~const Foo {} + | ^^^^^^ + | +note: this trait is not a `#[const_trait]`, so it cannot have `~const` trait bounds + --> const-super-trait.rs:7:1 + | +7 | trait Bar: ~const Foo {} + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0554]: `#![feature]` may not be used on the dev release channel + --> const-super-trait.rs:1:30 + | +1 | #![cfg_attr(feature_enabled, feature(const_trait_impl))] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: `~const` can only be applied to `#[const_trait]` traits + --> const-super-trait.rs:7:12 + | +7 | trait Bar: ~const Foo {} + | ^^^^^^ can't be applied to `Foo` + | +note: `Foo` can't be used with `~const` because it isn't annotated with `#[const_trait]` + --> const-super-trait.rs:3:1 + | +3 | trait Foo { + | ^^^^^^^^^ + +error: `~const` can only be applied to `#[const_trait]` traits + --> const-super-trait.rs:9:17 + | +9 | const fn foo(x: &T) { + | ^^^^^^ can't be applied to `Bar` + | +note: `Bar` can't be used with `~const` because it isn't annotated with `#[const_trait]` + --> const-super-trait.rs:7:1 + | +7 | trait Bar: ~const Foo {} + | ^^^^^^^^^^^^^^^^^^^^^ + +error[E0015]: cannot call non-const fn `::a` in constant functions + --> const-super-trait.rs:10:7 + | +10 | x.a(); + | ^^^ + | + = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants + +error: aborting due to 5 previous errors + +Some errors have detailed explanations: E0015, E0554. +For more information about an error, try `rustc --explain E0015`. diff --git a/tests/run-make/const-trait-stable-toolchain/rmake.rs b/tests/run-make/const-trait-stable-toolchain/rmake.rs new file mode 100644 index 0000000000000..09ec399e232be --- /dev/null +++ b/tests/run-make/const-trait-stable-toolchain/rmake.rs @@ -0,0 +1,51 @@ +// Test output of const super trait errors in both stable and nightly. +// We don't want to provide suggestions on stable that only make sense in nightly. + +use run_make_support::{diff, rustc}; + +fn main() { + let out = rustc() + .input("const-super-trait.rs") + .env("RUSTC_BOOTSTRAP", "-1") + .cfg("feature_enabled") + .run_fail() + .assert_stderr_not_contains("as `#[const_trait]` to allow it to have `const` implementations") + .stderr_utf8(); + diff() + .expected_file("const-super-trait.stable.enabled.stderr") + .actual_text("(rustc)", &out) + .run(); + let out = rustc() + .input("const-super-trait.rs") + .cfg("feature_enabled") + .ui_testing() + .run_fail() + .assert_stderr_not_contains("enable `#![feature(const_trait_impl)]` in your crate and mark") + .assert_stderr_contains("as `#[const_trait]` to allow it to have `const` implementations") + .stderr_utf8(); + diff() + .expected_file("const-super-trait.nightly.enabled.stderr") + .actual_text("(rustc)", &out) + .run(); + let out = rustc() + .input("const-super-trait.rs") + .env("RUSTC_BOOTSTRAP", "-1") + .run_fail() + .assert_stderr_not_contains("enable `#![feature(const_trait_impl)]` in your crate and mark") + .assert_stderr_not_contains("as `#[const_trait]` to allow it to have `const` implementations") + .stderr_utf8(); + diff() + .expected_file("const-super-trait.stable.disabled.stderr") + .actual_text("(rustc)", &out) + .run(); + let out = rustc() + .input("const-super-trait.rs") + .ui_testing() + .run_fail() + .assert_stderr_contains("enable `#![feature(const_trait_impl)]` in your crate and mark") + .stderr_utf8(); + diff() + .expected_file("const-super-trait.nightly.disabled.stderr") + .actual_text("(rustc)", &out) + .run(); +} diff --git a/tests/ui/consts/const-try.stderr b/tests/ui/consts/const-try.stderr index a1913d03dcc70..4209ca1d52665 100644 --- a/tests/ui/consts/const-try.stderr +++ b/tests/ui/consts/const-try.stderr @@ -2,7 +2,7 @@ error: const `impl` for trait `FromResidual` which is not marked with `#[const_t --> $DIR/const-try.rs:15:12 | LL | impl const FromResidual for TryMe { - | ^^^^^^^^^^^^^^^^^^^ not marked with `#[const_trait]` + | ^^^^^^^^^^^^^^^^^^^ this trait is not `const` | = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` = note: adding a non-const method body in the future would be a breaking change @@ -11,7 +11,7 @@ error: const `impl` for trait `Try` which is not marked with `#[const_trait]` --> $DIR/const-try.rs:22:12 | LL | impl const Try for TryMe { - | ^^^ not marked with `#[const_trait]` + | ^^^ this trait is not `const` | = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` = note: adding a non-const method body in the future would be a breaking change diff --git a/tests/ui/consts/rustc-impl-const-stability.stderr b/tests/ui/consts/rustc-impl-const-stability.stderr index 3028e451d1e6d..19c6bb5907f82 100644 --- a/tests/ui/consts/rustc-impl-const-stability.stderr +++ b/tests/ui/consts/rustc-impl-const-stability.stderr @@ -2,7 +2,7 @@ error: const `impl` for trait `Default` which is not marked with `#[const_trait] --> $DIR/rustc-impl-const-stability.rs:15:12 | LL | impl const Default for Data { - | ^^^^^^^ not marked with `#[const_trait]` + | ^^^^^^^ this trait is not `const` | = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` = note: adding a non-const method body in the future would be a breaking change diff --git a/tests/ui/traits/const-traits/call-const-trait-method-pass.stderr b/tests/ui/traits/const-traits/call-const-trait-method-pass.stderr index c4a134481b3df..ef494bde98ce3 100644 --- a/tests/ui/traits/const-traits/call-const-trait-method-pass.stderr +++ b/tests/ui/traits/const-traits/call-const-trait-method-pass.stderr @@ -2,7 +2,7 @@ error: const `impl` for trait `PartialEq` which is not marked with `#[const_trai --> $DIR/call-const-trait-method-pass.rs:15:12 | LL | impl const PartialEq for Int { - | ^^^^^^^^^ not marked with `#[const_trait]` + | ^^^^^^^^^ this trait is not `const` | = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` = note: adding a non-const method body in the future would be a breaking change diff --git a/tests/ui/traits/const-traits/call-generic-method-chain.stderr b/tests/ui/traits/const-traits/call-generic-method-chain.stderr index 343a4132dde7e..d7a2a18649400 100644 --- a/tests/ui/traits/const-traits/call-generic-method-chain.stderr +++ b/tests/ui/traits/const-traits/call-generic-method-chain.stderr @@ -2,7 +2,7 @@ error: const `impl` for trait `PartialEq` which is not marked with `#[const_trai --> $DIR/call-generic-method-chain.rs:11:12 | LL | impl const PartialEq for S { - | ^^^^^^^^^ not marked with `#[const_trait]` + | ^^^^^^^^^ this trait is not `const` | = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` = note: adding a non-const method body in the future would be a breaking change diff --git a/tests/ui/traits/const-traits/call-generic-method-dup-bound.stderr b/tests/ui/traits/const-traits/call-generic-method-dup-bound.stderr index 6bce80321c35a..90465d0a5b2db 100644 --- a/tests/ui/traits/const-traits/call-generic-method-dup-bound.stderr +++ b/tests/ui/traits/const-traits/call-generic-method-dup-bound.stderr @@ -2,7 +2,7 @@ error: const `impl` for trait `PartialEq` which is not marked with `#[const_trai --> $DIR/call-generic-method-dup-bound.rs:9:12 | LL | impl const PartialEq for S { - | ^^^^^^^^^ not marked with `#[const_trait]` + | ^^^^^^^^^ this trait is not `const` | = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` = note: adding a non-const method body in the future would be a breaking change diff --git a/tests/ui/traits/const-traits/call-generic-method-pass.stderr b/tests/ui/traits/const-traits/call-generic-method-pass.stderr index f14dfec741a32..a7626a4e99d26 100644 --- a/tests/ui/traits/const-traits/call-generic-method-pass.stderr +++ b/tests/ui/traits/const-traits/call-generic-method-pass.stderr @@ -2,7 +2,7 @@ error: const `impl` for trait `PartialEq` which is not marked with `#[const_trai --> $DIR/call-generic-method-pass.rs:11:12 | LL | impl const PartialEq for S { - | ^^^^^^^^^ not marked with `#[const_trait]` + | ^^^^^^^^^ this trait is not `const` | = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` = note: adding a non-const method body in the future would be a breaking change diff --git a/tests/ui/traits/const-traits/const-bounds-non-const-trait.stderr b/tests/ui/traits/const-traits/const-bounds-non-const-trait.stderr index 34304967e0e75..f97d3a9181e06 100644 --- a/tests/ui/traits/const-traits/const-bounds-non-const-trait.stderr +++ b/tests/ui/traits/const-traits/const-bounds-non-const-trait.stderr @@ -4,7 +4,7 @@ error: `~const` can only be applied to `#[const_trait]` traits LL | const fn perform() {} | ^^^^^^ can't be applied to `NonConst` | -help: mark `NonConst` as `const` +help: mark `NonConst` as `#[const_trait]` to allow it to have `const` implementations | LL | #[const_trait] trait NonConst {} | ++++++++++++++ @@ -16,7 +16,7 @@ LL | const fn perform() {} | ^^^^^^ can't be applied to `NonConst` | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: mark `NonConst` as `const` +help: mark `NonConst` as `#[const_trait]` to allow it to have `const` implementations | LL | #[const_trait] trait NonConst {} | ++++++++++++++ @@ -27,7 +27,7 @@ error: `const` can only be applied to `#[const_trait]` traits LL | fn operate() {} | ^^^^^ can't be applied to `NonConst` | -help: mark `NonConst` as `const` +help: mark `NonConst` as `#[const_trait]` to allow it to have `const` implementations | LL | #[const_trait] trait NonConst {} | ++++++++++++++ diff --git a/tests/ui/traits/const-traits/const-impl-requires-const-trait.stderr b/tests/ui/traits/const-traits/const-impl-requires-const-trait.stderr index 97655b852a4a6..c728eda069ecb 100644 --- a/tests/ui/traits/const-traits/const-impl-requires-const-trait.stderr +++ b/tests/ui/traits/const-traits/const-impl-requires-const-trait.stderr @@ -2,11 +2,11 @@ error: const `impl` for trait `A` which is not marked with `#[const_trait]` --> $DIR/const-impl-requires-const-trait.rs:6:12 | LL | impl const A for () {} - | ^ not marked with `#[const_trait]` + | ^ this trait is not `const` | = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` = note: adding a non-const method body in the future would be a breaking change -help: mark `A` as `const` +help: mark `A` as `#[const_trait]` to allow it to have `const` implementations | LL | #[const_trait] pub trait A {} | ++++++++++++++ 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 95adbccfdc9a7..fae871a4c85ac 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 @@ -11,7 +11,7 @@ error: const `impl` for trait `Default` which is not marked with `#[const_trait] --> $DIR/derive-const-gate.rs:1:16 | LL | #[derive_const(Default)] - | ^^^^^^^ not marked with `#[const_trait]` + | ^^^^^^^ this trait is not `const` | = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` = note: adding a non-const method body in the future would be a breaking change 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 26e9c4e41ecec..8a6401afcf19f 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 @@ -2,7 +2,7 @@ error: const `impl` for trait `Default` which is not marked with `#[const_trait] --> $DIR/derive-const-non-const-type.rs:10:16 | LL | #[derive_const(Default)] - | ^^^^^^^ not marked with `#[const_trait]` + | ^^^^^^^ this trait is not `const` | = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` = note: adding a non-const method body in the future would be a breaking change 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 d8514d14654cf..3b06f4d801a41 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 @@ -14,7 +14,7 @@ error: const `impl` for trait `Default` which is not marked with `#[const_trait] --> $DIR/derive-const-use.rs:7:12 | LL | impl const Default for A { - | ^^^^^^^ not marked with `#[const_trait]` + | ^^^^^^^ this trait is not `const` | = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` = note: adding a non-const method body in the future would be a breaking change @@ -23,7 +23,7 @@ error: const `impl` for trait `Default` which is not marked with `#[const_trait] --> $DIR/derive-const-use.rs:15:16 | LL | #[derive_const(Default, PartialEq)] - | ^^^^^^^ not marked with `#[const_trait]` + | ^^^^^^^ this trait is not `const` | = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` = note: adding a non-const method body in the future would be a breaking change @@ -33,7 +33,7 @@ error: const `impl` for trait `PartialEq` which is not marked with `#[const_trai --> $DIR/derive-const-use.rs:11:12 | LL | impl const PartialEq for A { - | ^^^^^^^^^ not marked with `#[const_trait]` + | ^^^^^^^^^ this trait is not `const` | = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` = note: adding a non-const method body in the future would be a breaking change @@ -42,7 +42,7 @@ error: const `impl` for trait `PartialEq` which is not marked with `#[const_trai --> $DIR/derive-const-use.rs:15:25 | LL | #[derive_const(Default, PartialEq)] - | ^^^^^^^^^ not marked with `#[const_trait]` + | ^^^^^^^^^ this trait is not `const` | = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` = note: adding a non-const method body in the future would be a breaking change diff --git a/tests/ui/traits/const-traits/const_derives/derive-const-with-params.stderr b/tests/ui/traits/const-traits/const_derives/derive-const-with-params.stderr index 9eccefcabcdae..6b1405712ef7d 100644 --- a/tests/ui/traits/const-traits/const_derives/derive-const-with-params.stderr +++ b/tests/ui/traits/const-traits/const_derives/derive-const-with-params.stderr @@ -2,7 +2,7 @@ error: const `impl` for trait `PartialEq` which is not marked with `#[const_trai --> $DIR/derive-const-with-params.rs:7:16 | LL | #[derive_const(PartialEq)] - | ^^^^^^^^^ not marked with `#[const_trait]` + | ^^^^^^^^^ this trait is not `const` | = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` = note: adding a non-const method body in the future would be a breaking change diff --git a/tests/ui/traits/const-traits/effects/spec-effectvar-ice.stderr b/tests/ui/traits/const-traits/effects/spec-effectvar-ice.stderr index 2bf1ed81c6c05..474d96698d56b 100644 --- a/tests/ui/traits/const-traits/effects/spec-effectvar-ice.stderr +++ b/tests/ui/traits/const-traits/effects/spec-effectvar-ice.stderr @@ -2,11 +2,11 @@ error: const `impl` for trait `Foo` which is not marked with `#[const_trait]` --> $DIR/spec-effectvar-ice.rs:10:15 | LL | impl const Foo for T {} - | ^^^ not marked with `#[const_trait]` + | ^^^ this trait is not `const` | = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` = note: adding a non-const method body in the future would be a breaking change -help: mark `Foo` as `const` +help: mark `Foo` as `#[const_trait]` to allow it to have `const` implementations | LL | #[const_trait] trait Foo {} | ++++++++++++++ @@ -15,11 +15,11 @@ error: const `impl` for trait `Foo` which is not marked with `#[const_trait]` --> $DIR/spec-effectvar-ice.rs:13:15 | LL | impl const Foo for T where T: const Specialize {} - | ^^^ not marked with `#[const_trait]` + | ^^^ this trait is not `const` | = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` = note: adding a non-const method body in the future would be a breaking change -help: mark `Foo` as `const` +help: mark `Foo` as `#[const_trait]` to allow it to have `const` implementations | LL | #[const_trait] trait Foo {} | ++++++++++++++ @@ -30,7 +30,7 @@ error: `const` can only be applied to `#[const_trait]` traits LL | impl const Foo for T where T: const Specialize {} | ^^^^^ can't be applied to `Specialize` | -help: mark `Specialize` as `const` +help: mark `Specialize` as `#[const_trait]` to allow it to have `const` implementations | LL | #[const_trait] trait Specialize {} | ++++++++++++++ diff --git a/tests/ui/traits/const-traits/ice-119717-constant-lifetime.stderr b/tests/ui/traits/const-traits/ice-119717-constant-lifetime.stderr index a4f8d3e43daf9..5af263de28c48 100644 --- a/tests/ui/traits/const-traits/ice-119717-constant-lifetime.stderr +++ b/tests/ui/traits/const-traits/ice-119717-constant-lifetime.stderr @@ -2,7 +2,7 @@ error: const `impl` for trait `FromResidual` which is not marked with `#[const_t --> $DIR/ice-119717-constant-lifetime.rs:6:15 | LL | impl const FromResidual for T { - | ^^^^^^^^^^^^ not marked with `#[const_trait]` + | ^^^^^^^^^^^^ this trait is not `const` | = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` = note: adding a non-const method body in the future would be a breaking change diff --git a/tests/ui/traits/const-traits/ice-126148-failed-to-normalize.stderr b/tests/ui/traits/const-traits/ice-126148-failed-to-normalize.stderr index 0c3bf2adfefd4..41f99c2d375e6 100644 --- a/tests/ui/traits/const-traits/ice-126148-failed-to-normalize.stderr +++ b/tests/ui/traits/const-traits/ice-126148-failed-to-normalize.stderr @@ -2,7 +2,7 @@ error: const `impl` for trait `FromResidual` which is not marked with `#[const_t --> $DIR/ice-126148-failed-to-normalize.rs:8:12 | LL | impl const FromResidual for TryMe {} - | ^^^^^^^^^^^^^^^^^^^ not marked with `#[const_trait]` + | ^^^^^^^^^^^^^^^^^^^ this trait is not `const` | = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` = note: adding a non-const method body in the future would be a breaking change @@ -19,7 +19,7 @@ error: const `impl` for trait `Try` which is not marked with `#[const_trait]` --> $DIR/ice-126148-failed-to-normalize.rs:12:12 | LL | impl const Try for TryMe { - | ^^^ not marked with `#[const_trait]` + | ^^^ this trait is not `const` | = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` = note: adding a non-const method body in the future would be a breaking change 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 16bf2e0e2b3fe..51b88cf87022a 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 @@ -16,7 +16,7 @@ error: `~const` can only be applied to `#[const_trait]` traits LL | trait Bar: ~const Foo {} | ^^^^^^ can't be applied to `Foo` | -help: mark `Foo` as `const` +help: mark `Foo` as `#[const_trait]` to allow it to have `const` implementations | LL | #[const_trait] trait Foo { | ++++++++++++++ @@ -28,7 +28,7 @@ LL | trait Bar: ~const Foo {} | ^^^^^^ can't be applied to `Foo` | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: mark `Foo` as `const` +help: mark `Foo` as `#[const_trait]` to allow it to have `const` implementations | LL | #[const_trait] trait Foo { | ++++++++++++++ @@ -40,7 +40,7 @@ LL | trait Bar: ~const Foo {} | ^^^^^^ can't be applied to `Foo` | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: mark `Foo` as `const` +help: mark `Foo` as `#[const_trait]` to allow it to have `const` implementations | LL | #[const_trait] trait Foo { | ++++++++++++++ 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 91e0df38b8f09..38fb6f05412f4 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 @@ -4,7 +4,7 @@ error: `~const` can only be applied to `#[const_trait]` traits LL | trait Bar: ~const Foo {} | ^^^^^^ can't be applied to `Foo` | -help: mark `Foo` as `const` +help: mark `Foo` as `#[const_trait]` to allow it to have `const` implementations | LL | #[const_trait] trait Foo { | ++++++++++++++ @@ -16,7 +16,7 @@ LL | trait Bar: ~const Foo {} | ^^^^^^ can't be applied to `Foo` | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: mark `Foo` as `const` +help: mark `Foo` as `#[const_trait]` to allow it to have `const` implementations | LL | #[const_trait] trait Foo { | ++++++++++++++ @@ -28,7 +28,7 @@ LL | trait Bar: ~const Foo {} | ^^^^^^ can't be applied to `Foo` | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: mark `Foo` as `const` +help: mark `Foo` as `#[const_trait]` to allow it to have `const` implementations | LL | #[const_trait] trait Foo { | ++++++++++++++ @@ -40,7 +40,7 @@ LL | trait Bar: ~const Foo {} | ^^^^^^ can't be applied to `Foo` | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: mark `Foo` as `const` +help: mark `Foo` as `#[const_trait]` to allow it to have `const` implementations | LL | #[const_trait] trait Foo { | ++++++++++++++ @@ -52,7 +52,7 @@ LL | trait Bar: ~const Foo {} | ^^^^^^ can't be applied to `Foo` | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: mark `Foo` as `const` +help: mark `Foo` as `#[const_trait]` to allow it to have `const` implementations | LL | #[const_trait] trait Foo { | ++++++++++++++ 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 new file mode 100644 index 0000000000000..fd802fde5bd5a --- /dev/null +++ b/tests/ui/traits/const-traits/super-traits-fail-3.nnn.stderr @@ -0,0 +1,102 @@ +error: `~const` is not allowed here + --> $DIR/super-traits-fail-3.rs:23:12 + | +LL | trait Bar: ~const Foo {} + | ^^^^^^ + | +note: this trait is not a `#[const_trait]`, so it cannot have `~const` trait bounds + --> $DIR/super-traits-fail-3.rs:23:1 + | +LL | trait Bar: ~const Foo {} + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0658]: const trait impls are experimental + --> $DIR/super-traits-fail-3.rs:23:12 + | +LL | trait Bar: ~const Foo {} + | ^^^^^^ + | + = note: see issue #67792 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 + +error[E0658]: const trait impls are experimental + --> $DIR/super-traits-fail-3.rs:32:17 + | +LL | const fn foo(x: &T) { + | ^^^^^^ + | + = note: see issue #67792 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 + +error: `~const` can only be applied to `#[const_trait]` traits + --> $DIR/super-traits-fail-3.rs:23:12 + | +LL | trait Bar: ~const Foo {} + | ^^^^^^ can't be applied to `Foo` + | +help: enable `#![feature(const_trait_impl)]` in your crate and mark `Foo` as `#[const_trait]` to allow it to have `const` implementations + | +LL | #[const_trait] trait Foo { + | ++++++++++++++ + +error: `~const` can only be applied to `#[const_trait]` traits + --> $DIR/super-traits-fail-3.rs:23:12 + | +LL | trait Bar: ~const Foo {} + | ^^^^^^ can't be applied to `Foo` + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: enable `#![feature(const_trait_impl)]` in your crate and mark `Foo` as `#[const_trait]` to allow it to have `const` implementations + | +LL | #[const_trait] trait Foo { + | ++++++++++++++ + +error: `~const` can only be applied to `#[const_trait]` traits + --> $DIR/super-traits-fail-3.rs:23:12 + | +LL | trait Bar: ~const Foo {} + | ^^^^^^ can't be applied to `Foo` + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: enable `#![feature(const_trait_impl)]` in your crate and mark `Foo` as `#[const_trait]` to allow it to have `const` implementations + | +LL | #[const_trait] trait Foo { + | ++++++++++++++ + +error: `~const` can only be applied to `#[const_trait]` traits + --> $DIR/super-traits-fail-3.rs:32:17 + | +LL | const fn foo(x: &T) { + | ^^^^^^ can't be applied to `Bar` + | +help: enable `#![feature(const_trait_impl)]` in your crate and mark `Bar` as `#[const_trait]` to allow it to have `const` implementations + | +LL | #[const_trait] trait Bar: ~const Foo {} + | ++++++++++++++ + +error: `~const` can only be applied to `#[const_trait]` traits + --> $DIR/super-traits-fail-3.rs:32:17 + | +LL | const fn foo(x: &T) { + | ^^^^^^ can't be applied to `Bar` + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: enable `#![feature(const_trait_impl)]` in your crate and mark `Bar` as `#[const_trait]` to allow it to have `const` implementations + | +LL | #[const_trait] trait Bar: ~const Foo {} + | ++++++++++++++ + +error[E0015]: cannot call non-const fn `::a` in constant functions + --> $DIR/super-traits-fail-3.rs:36: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`. 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 new file mode 100644 index 0000000000000..fd802fde5bd5a --- /dev/null +++ b/tests/ui/traits/const-traits/super-traits-fail-3.nny.stderr @@ -0,0 +1,102 @@ +error: `~const` is not allowed here + --> $DIR/super-traits-fail-3.rs:23:12 + | +LL | trait Bar: ~const Foo {} + | ^^^^^^ + | +note: this trait is not a `#[const_trait]`, so it cannot have `~const` trait bounds + --> $DIR/super-traits-fail-3.rs:23:1 + | +LL | trait Bar: ~const Foo {} + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0658]: const trait impls are experimental + --> $DIR/super-traits-fail-3.rs:23:12 + | +LL | trait Bar: ~const Foo {} + | ^^^^^^ + | + = note: see issue #67792 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 + +error[E0658]: const trait impls are experimental + --> $DIR/super-traits-fail-3.rs:32:17 + | +LL | const fn foo(x: &T) { + | ^^^^^^ + | + = note: see issue #67792 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 + +error: `~const` can only be applied to `#[const_trait]` traits + --> $DIR/super-traits-fail-3.rs:23:12 + | +LL | trait Bar: ~const Foo {} + | ^^^^^^ can't be applied to `Foo` + | +help: enable `#![feature(const_trait_impl)]` in your crate and mark `Foo` as `#[const_trait]` to allow it to have `const` implementations + | +LL | #[const_trait] trait Foo { + | ++++++++++++++ + +error: `~const` can only be applied to `#[const_trait]` traits + --> $DIR/super-traits-fail-3.rs:23:12 + | +LL | trait Bar: ~const Foo {} + | ^^^^^^ can't be applied to `Foo` + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: enable `#![feature(const_trait_impl)]` in your crate and mark `Foo` as `#[const_trait]` to allow it to have `const` implementations + | +LL | #[const_trait] trait Foo { + | ++++++++++++++ + +error: `~const` can only be applied to `#[const_trait]` traits + --> $DIR/super-traits-fail-3.rs:23:12 + | +LL | trait Bar: ~const Foo {} + | ^^^^^^ can't be applied to `Foo` + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: enable `#![feature(const_trait_impl)]` in your crate and mark `Foo` as `#[const_trait]` to allow it to have `const` implementations + | +LL | #[const_trait] trait Foo { + | ++++++++++++++ + +error: `~const` can only be applied to `#[const_trait]` traits + --> $DIR/super-traits-fail-3.rs:32:17 + | +LL | const fn foo(x: &T) { + | ^^^^^^ can't be applied to `Bar` + | +help: enable `#![feature(const_trait_impl)]` in your crate and mark `Bar` as `#[const_trait]` to allow it to have `const` implementations + | +LL | #[const_trait] trait Bar: ~const Foo {} + | ++++++++++++++ + +error: `~const` can only be applied to `#[const_trait]` traits + --> $DIR/super-traits-fail-3.rs:32:17 + | +LL | const fn foo(x: &T) { + | ^^^^^^ can't be applied to `Bar` + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: enable `#![feature(const_trait_impl)]` in your crate and mark `Bar` as `#[const_trait]` to allow it to have `const` implementations + | +LL | #[const_trait] trait Bar: ~const Foo {} + | ++++++++++++++ + +error[E0015]: cannot call non-const fn `::a` in constant functions + --> $DIR/super-traits-fail-3.rs:36: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`. 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 new file mode 100644 index 0000000000000..8abda1c8f8afe --- /dev/null +++ b/tests/ui/traits/const-traits/super-traits-fail-3.nyn.stderr @@ -0,0 +1,53 @@ +error[E0658]: const trait impls are experimental + --> $DIR/super-traits-fail-3.rs:23:12 + | +LL | trait Bar: ~const Foo {} + | ^^^^^^ + | + = note: see issue #67792 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 + +error[E0658]: const trait impls are experimental + --> $DIR/super-traits-fail-3.rs:32:17 + | +LL | const fn foo(x: &T) { + | ^^^^^^ + | + = note: see issue #67792 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 + +error[E0658]: `const_trait` is a temporary placeholder for marking a trait that is suitable for `const` `impls` and all default bodies as `const`, which may be removed or renamed in the future. + --> $DIR/super-traits-fail-3.rs:15:37 + | +LL | #[cfg_attr(any(yyy, yyn, nyy, nyn), const_trait)] + | ^^^^^^^^^^^ + | + = note: see issue #67792 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 + +error[E0658]: `const_trait` is a temporary placeholder for marking a trait that is suitable for `const` `impls` and all default bodies as `const`, which may be removed or renamed in the future. + --> $DIR/super-traits-fail-3.rs:21:37 + | +LL | #[cfg_attr(any(yyy, yny, nyy, nyn), const_trait)] + | ^^^^^^^^^^^ + | + = note: see issue #67792 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 + +error[E0658]: cannot call conditionally-const method `::a` in constant functions + --> $DIR/super-traits-fail-3.rs:36:5 + | +LL | x.a(); + | ^^^^^ + | + = note: see issue #67792 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 + +error: aborting due to 5 previous errors + +For more information about this error, try `rustc --explain E0658`. 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 new file mode 100644 index 0000000000000..8abda1c8f8afe --- /dev/null +++ b/tests/ui/traits/const-traits/super-traits-fail-3.nyy.stderr @@ -0,0 +1,53 @@ +error[E0658]: const trait impls are experimental + --> $DIR/super-traits-fail-3.rs:23:12 + | +LL | trait Bar: ~const Foo {} + | ^^^^^^ + | + = note: see issue #67792 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 + +error[E0658]: const trait impls are experimental + --> $DIR/super-traits-fail-3.rs:32:17 + | +LL | const fn foo(x: &T) { + | ^^^^^^ + | + = note: see issue #67792 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 + +error[E0658]: `const_trait` is a temporary placeholder for marking a trait that is suitable for `const` `impls` and all default bodies as `const`, which may be removed or renamed in the future. + --> $DIR/super-traits-fail-3.rs:15:37 + | +LL | #[cfg_attr(any(yyy, yyn, nyy, nyn), const_trait)] + | ^^^^^^^^^^^ + | + = note: see issue #67792 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 + +error[E0658]: `const_trait` is a temporary placeholder for marking a trait that is suitable for `const` `impls` and all default bodies as `const`, which may be removed or renamed in the future. + --> $DIR/super-traits-fail-3.rs:21:37 + | +LL | #[cfg_attr(any(yyy, yny, nyy, nyn), const_trait)] + | ^^^^^^^^^^^ + | + = note: see issue #67792 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 + +error[E0658]: cannot call conditionally-const method `::a` in constant functions + --> $DIR/super-traits-fail-3.rs:36:5 + | +LL | x.a(); + | ^^^^^ + | + = note: see issue #67792 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 + +error: aborting due to 5 previous errors + +For more information about this error, try `rustc --explain E0658`. 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 bd95ae8d96a9d..aa27554e7f895 100644 --- a/tests/ui/traits/const-traits/super-traits-fail-3.rs +++ b/tests/ui/traits/const-traits/super-traits-fail-3.rs @@ -1,29 +1,42 @@ //@ compile-flags: -Znext-solver -#![feature(const_trait_impl)] +#![cfg_attr(any(yyy, yyn, yny, ynn), feature(const_trait_impl))] -//@ revisions: yy yn ny nn -//@[yy] check-pass +//@ revisions: yyy yyn yny ynn nyy nyn nny nnn +//@[yyy] check-pass +/// yyy: feature enabled, Foo is const, Bar is const +/// yyn: feature enabled, Foo is const, Bar is not const +/// yny: feature enabled, Foo is not const, Bar is const +/// ynn: feature enabled, Foo is not const, Bar is not const +/// nyy: feature not enabled, Foo is const, Bar is const +/// nyn: feature not enabled, Foo is const, Bar is not const +/// nny: feature not enabled, Foo is not const, Bar is const +/// nnn: feature not enabled, Foo is not const, Bar is not const -#[cfg_attr(any(yy, yn), const_trait)] +#[cfg_attr(any(yyy, yyn, nyy, nyn), const_trait)] +//[nyy,nyn]~^ ERROR: `const_trait` is a temporary placeholder for marking a trait that is suitable for `const` `impls` and all default bodies as `const`, which may be removed or renamed in the future trait Foo { fn a(&self); } -#[cfg_attr(any(yy, ny), const_trait)] +#[cfg_attr(any(yyy, yny, nyy, nyn), const_trait)] +//[nyy,nyn]~^ ERROR: `const_trait` is a temporary placeholder for marking a trait that is suitable for `const` `impls` and all default bodies as `const`, which may be removed or renamed in the future trait Bar: ~const Foo {} -//[ny,nn]~^ ERROR: `~const` can only be applied to `#[const_trait]` -//[ny,nn]~| ERROR: `~const` can only be applied to `#[const_trait]` -//[ny,nn]~| ERROR: `~const` can only be applied to `#[const_trait]` -//[ny]~| ERROR: `~const` can only be applied to `#[const_trait]` -//[ny]~| ERROR: `~const` can only be applied to `#[const_trait]` -//[yn,nn]~^^^^^^ ERROR: `~const` is not allowed here +//[yny,ynn,nny,nnn]~^ ERROR: `~const` can only be applied to `#[const_trait]` +//[yny,ynn,nny,nnn]~| ERROR: `~const` can only be applied to `#[const_trait]` +//[yny,ynn,nny,nnn]~| ERROR: `~const` can only be applied to `#[const_trait]` +//[yny]~^^^^ ERROR: `~const` can only be applied to `#[const_trait]` +//[yny]~| ERROR: `~const` can only be applied to `#[const_trait]` +//[yyn,ynn,nny,nnn]~^^^^^^ ERROR: `~const` is not allowed here +//[nyy,nyn,nny,nnn]~^^^^^^^ ERROR: const trait impls are experimental const fn foo(x: &T) { - //[yn,nn]~^ ERROR: `~const` can only be applied to `#[const_trait]` - //[yn,nn]~| ERROR: `~const` can only be applied to `#[const_trait]` + //[yyn,ynn,nny,nnn]~^ ERROR: `~const` can only be applied to `#[const_trait]` + //[yyn,ynn,nny,nnn]~| ERROR: `~const` can only be applied to `#[const_trait]` + //[nyy,nyn,nny,nnn]~^^^ ERROR: const trait impls are experimental x.a(); - //[yn]~^ ERROR: the trait bound `T: ~const Foo` is not satisfied - //[nn,ny]~^^ ERROR: cannot call non-const fn `::a` in constant functions + //[yyn]~^ ERROR: the trait bound `T: ~const Foo` is not satisfied + //[ynn,yny,nny,nnn]~^^ ERROR: cannot call non-const fn `::a` in constant functions + //[nyy,nyn]~^^^ ERROR: cannot call conditionally-const method `::a` in constant functions } fn main() {} diff --git a/tests/ui/traits/const-traits/super-traits-fail-3.nn.stderr b/tests/ui/traits/const-traits/super-traits-fail-3.ynn.stderr similarity index 72% rename from tests/ui/traits/const-traits/super-traits-fail-3.nn.stderr rename to tests/ui/traits/const-traits/super-traits-fail-3.ynn.stderr index 103f3c2b62abd..16424696eeb51 100644 --- a/tests/ui/traits/const-traits/super-traits-fail-3.nn.stderr +++ b/tests/ui/traits/const-traits/super-traits-fail-3.ynn.stderr @@ -1,75 +1,75 @@ error: `~const` is not allowed here - --> $DIR/super-traits-fail-3.rs:13:12 + --> $DIR/super-traits-fail-3.rs:23:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ | note: this trait is not a `#[const_trait]`, so it cannot have `~const` trait bounds - --> $DIR/super-traits-fail-3.rs:13:1 + --> $DIR/super-traits-fail-3.rs:23:1 | LL | trait Bar: ~const Foo {} | ^^^^^^^^^^^^^^^^^^^^^^^^ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-3.rs:13:12 + --> $DIR/super-traits-fail-3.rs:23:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ can't be applied to `Foo` | -help: mark `Foo` as `const` +help: mark `Foo` as `#[const_trait]` to allow it to have `const` implementations | LL | #[const_trait] trait Foo { | ++++++++++++++ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-3.rs:13:12 + --> $DIR/super-traits-fail-3.rs:23:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ can't be applied to `Foo` | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: mark `Foo` as `const` +help: mark `Foo` as `#[const_trait]` to allow it to have `const` implementations | LL | #[const_trait] trait Foo { | ++++++++++++++ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-3.rs:13:12 + --> $DIR/super-traits-fail-3.rs:23:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ can't be applied to `Foo` | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: mark `Foo` as `const` +help: mark `Foo` as `#[const_trait]` to allow it to have `const` implementations | LL | #[const_trait] trait Foo { | ++++++++++++++ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-3.rs:21:17 + --> $DIR/super-traits-fail-3.rs:32:17 | LL | const fn foo(x: &T) { | ^^^^^^ can't be applied to `Bar` | -help: mark `Bar` as `const` +help: mark `Bar` as `#[const_trait]` to allow it to have `const` implementations | LL | #[const_trait] trait Bar: ~const Foo {} | ++++++++++++++ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-3.rs:21:17 + --> $DIR/super-traits-fail-3.rs:32:17 | LL | const fn foo(x: &T) { | ^^^^^^ can't be applied to `Bar` | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: mark `Bar` as `const` +help: mark `Bar` as `#[const_trait]` to allow it to have `const` implementations | LL | #[const_trait] trait Bar: ~const Foo {} | ++++++++++++++ error[E0015]: cannot call non-const fn `::a` in constant functions - --> $DIR/super-traits-fail-3.rs:24:7 + --> $DIR/super-traits-fail-3.rs:36:7 | LL | x.a(); | ^^^ diff --git a/tests/ui/traits/const-traits/super-traits-fail-3.ny.stderr b/tests/ui/traits/const-traits/super-traits-fail-3.yny.stderr similarity index 72% rename from tests/ui/traits/const-traits/super-traits-fail-3.ny.stderr rename to tests/ui/traits/const-traits/super-traits-fail-3.yny.stderr index a963a043f1cc6..c81544c4bf5b7 100644 --- a/tests/ui/traits/const-traits/super-traits-fail-3.ny.stderr +++ b/tests/ui/traits/const-traits/super-traits-fail-3.yny.stderr @@ -1,64 +1,64 @@ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-3.rs:13:12 + --> $DIR/super-traits-fail-3.rs:23:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ can't be applied to `Foo` | -help: mark `Foo` as `const` +help: mark `Foo` as `#[const_trait]` to allow it to have `const` implementations | LL | #[const_trait] trait Foo { | ++++++++++++++ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-3.rs:13:12 + --> $DIR/super-traits-fail-3.rs:23:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ can't be applied to `Foo` | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: mark `Foo` as `const` +help: mark `Foo` as `#[const_trait]` to allow it to have `const` implementations | LL | #[const_trait] trait Foo { | ++++++++++++++ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-3.rs:13:12 + --> $DIR/super-traits-fail-3.rs:23:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ can't be applied to `Foo` | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: mark `Foo` as `const` +help: mark `Foo` as `#[const_trait]` to allow it to have `const` implementations | LL | #[const_trait] trait Foo { | ++++++++++++++ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-3.rs:13:12 + --> $DIR/super-traits-fail-3.rs:23:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ can't be applied to `Foo` | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: mark `Foo` as `const` +help: mark `Foo` as `#[const_trait]` to allow it to have `const` implementations | LL | #[const_trait] trait Foo { | ++++++++++++++ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-3.rs:13:12 + --> $DIR/super-traits-fail-3.rs:23:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ can't be applied to `Foo` | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: mark `Foo` as `const` +help: mark `Foo` as `#[const_trait]` to allow it to have `const` implementations | LL | #[const_trait] trait Foo { | ++++++++++++++ error[E0015]: cannot call non-const fn `::a` in constant functions - --> $DIR/super-traits-fail-3.rs:24:7 + --> $DIR/super-traits-fail-3.rs:36:7 | LL | x.a(); | ^^^ diff --git a/tests/ui/traits/const-traits/super-traits-fail-3.yn.stderr b/tests/ui/traits/const-traits/super-traits-fail-3.yyn.stderr similarity index 73% rename from tests/ui/traits/const-traits/super-traits-fail-3.yn.stderr rename to tests/ui/traits/const-traits/super-traits-fail-3.yyn.stderr index 6b2046f0595a7..3270611dace2e 100644 --- a/tests/ui/traits/const-traits/super-traits-fail-3.yn.stderr +++ b/tests/ui/traits/const-traits/super-traits-fail-3.yyn.stderr @@ -1,40 +1,40 @@ error: `~const` is not allowed here - --> $DIR/super-traits-fail-3.rs:13:12 + --> $DIR/super-traits-fail-3.rs:23:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ | note: this trait is not a `#[const_trait]`, so it cannot have `~const` trait bounds - --> $DIR/super-traits-fail-3.rs:13:1 + --> $DIR/super-traits-fail-3.rs:23:1 | LL | trait Bar: ~const Foo {} | ^^^^^^^^^^^^^^^^^^^^^^^^ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-3.rs:21:17 + --> $DIR/super-traits-fail-3.rs:32:17 | LL | const fn foo(x: &T) { | ^^^^^^ can't be applied to `Bar` | -help: mark `Bar` as `const` +help: mark `Bar` as `#[const_trait]` to allow it to have `const` implementations | LL | #[const_trait] trait Bar: ~const Foo {} | ++++++++++++++ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-3.rs:21:17 + --> $DIR/super-traits-fail-3.rs:32:17 | LL | const fn foo(x: &T) { | ^^^^^^ can't be applied to `Bar` | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: mark `Bar` as `const` +help: mark `Bar` as `#[const_trait]` to allow it to have `const` implementations | LL | #[const_trait] trait Bar: ~const Foo {} | ++++++++++++++ error[E0277]: the trait bound `T: ~const Foo` is not satisfied - --> $DIR/super-traits-fail-3.rs:24:7 + --> $DIR/super-traits-fail-3.rs:36:7 | LL | x.a(); | ^ diff --git a/tests/ui/traits/const-traits/trait-default-body-stability.stderr b/tests/ui/traits/const-traits/trait-default-body-stability.stderr index a6e7164c49bb0..77b81211e8152 100644 --- a/tests/ui/traits/const-traits/trait-default-body-stability.stderr +++ b/tests/ui/traits/const-traits/trait-default-body-stability.stderr @@ -2,7 +2,7 @@ error: const `impl` for trait `Try` which is not marked with `#[const_trait]` --> $DIR/trait-default-body-stability.rs:19:12 | LL | impl const Try for T { - | ^^^ not marked with `#[const_trait]` + | ^^^ this trait is not `const` | = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` = note: adding a non-const method body in the future would be a breaking change @@ -11,7 +11,7 @@ error: const `impl` for trait `FromResidual` which is not marked with `#[const_t --> $DIR/trait-default-body-stability.rs:34:12 | LL | impl const FromResidual for T { - | ^^^^^^^^^^^^ not marked with `#[const_trait]` + | ^^^^^^^^^^^^ this trait is not `const` | = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` = note: adding a non-const method body in the future would be a breaking change