From d7cfdf528e5a99d975c18ea4b098c6cf705fc3fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sun, 22 Dec 2024 01:53:06 +0000 Subject: [PATCH] Update tests --- tests/ui/consts/rustc-impl-const-stability.rs | 6 +- .../consts/rustc-impl-const-stability.stderr | 6 +- tests/ui/specialization/const_trait_impl.rs | 8 ++- .../ui/specialization/const_trait_impl.stderr | 60 +++++++++---------- .../const-traits/const-traits-alloc.rs} | 0 .../const-traits/const-traits-core.rs} | 0 .../const_derives/derive-const-gate.rs | 5 +- .../const_derives/derive-const-gate.stderr | 24 +++++--- .../derive-const-non-const-type.rs | 2 +- .../derive-const-non-const-type.stderr | 28 +++++---- .../const_derives/derive-const-use.stderr | 51 +--------------- .../const-traits/std-impl-gate.gated.stderr | 13 +--- tests/ui/traits/const-traits/std-impl-gate.rs | 2 +- .../const-traits/std-impl-gate.stock.stderr | 8 ++- 14 files changed, 88 insertions(+), 125 deletions(-) rename tests/ui/{const-generics/std/const-generics-alloc.rs => traits/const-traits/const-traits-alloc.rs} (100%) rename tests/ui/{const-generics/std/const-generics-core.rs => traits/const-traits/const-traits-core.rs} (100%) diff --git a/tests/ui/consts/rustc-impl-const-stability.rs b/tests/ui/consts/rustc-impl-const-stability.rs index 0df8482bec121..045a7b500a91d 100644 --- a/tests/ui/consts/rustc-impl-const-stability.rs +++ b/tests/ui/consts/rustc-impl-const-stability.rs @@ -12,8 +12,8 @@ pub struct Data { #[stable(feature = "potato", since = "1.27.0")] #[rustc_const_unstable(feature = "data_foo", issue = "none")] -impl const Default for Data { - fn default() -> Data { - Data { _data: 42 } +impl const std::fmt::Debug for Data { + fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { + panic!() } } diff --git a/tests/ui/consts/rustc-impl-const-stability.stderr b/tests/ui/consts/rustc-impl-const-stability.stderr index 19c6bb5907f82..a3ef4031a13e6 100644 --- a/tests/ui/consts/rustc-impl-const-stability.stderr +++ b/tests/ui/consts/rustc-impl-const-stability.stderr @@ -1,8 +1,8 @@ -error: const `impl` for trait `Default` which is not marked with `#[const_trait]` +error: const `impl` for trait `Debug` which is not marked with `#[const_trait]` --> $DIR/rustc-impl-const-stability.rs:15:12 | -LL | impl const Default for Data { - | ^^^^^^^ this trait is not `const` +LL | impl const std::fmt::Debug for Data { + | ^^^^^^^^^^^^^^^ 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/specialization/const_trait_impl.rs b/tests/ui/specialization/const_trait_impl.rs index d842601a6b7b9..83e46fd13d8cb 100644 --- a/tests/ui/specialization/const_trait_impl.rs +++ b/tests/ui/specialization/const_trait_impl.rs @@ -2,6 +2,8 @@ #![feature(const_trait_impl, min_specialization, rustc_attrs)] +use std::fmt::Debug; + #[rustc_specialization_trait] #[const_trait] pub unsafe trait Sup { @@ -31,19 +33,19 @@ pub trait A { fn a() -> u32; } -impl const A for T { +impl const A for T { default fn a() -> u32 { 2 } } -impl const A for T { +impl const A for T { default fn a() -> u32 { 3 } } -impl const A for T { +impl const A for T { fn a() -> u32 { T::foo() } diff --git a/tests/ui/specialization/const_trait_impl.stderr b/tests/ui/specialization/const_trait_impl.stderr index 3e1260ff09c92..b0d9f149968ca 100644 --- a/tests/ui/specialization/const_trait_impl.stderr +++ b/tests/ui/specialization/const_trait_impl.stderr @@ -1,58 +1,58 @@ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const_trait_impl.rs:34:9 + --> $DIR/const_trait_impl.rs:36:9 | -LL | impl const A for T { - | ^^^^^^ can't be applied to `Default` +LL | impl const A for T { + | ^^^^^^ can't be applied to `Debug` | -note: `Default` can't be used with `~const` because it isn't annotated with `#[const_trait]` - --> $SRC_DIR/core/src/default.rs:LL:COL +note: `Debug` can't be used with `~const` because it isn't annotated with `#[const_trait]` + --> $SRC_DIR/core/src/fmt/mod.rs:LL:COL error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const_trait_impl.rs:40:9 + --> $DIR/const_trait_impl.rs:42:9 | -LL | impl const A for T { - | ^^^^^^ can't be applied to `Default` +LL | impl const A for T { + | ^^^^^^ can't be applied to `Debug` | -note: `Default` can't be used with `~const` because it isn't annotated with `#[const_trait]` - --> $SRC_DIR/core/src/default.rs:LL:COL +note: `Debug` can't be used with `~const` because it isn't annotated with `#[const_trait]` + --> $SRC_DIR/core/src/fmt/mod.rs:LL:COL error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const_trait_impl.rs:46:9 + --> $DIR/const_trait_impl.rs:48:9 | -LL | impl const A for T { - | ^^^^^^ can't be applied to `Default` +LL | impl const A for T { + | ^^^^^^ can't be applied to `Debug` | -note: `Default` can't be used with `~const` because it isn't annotated with `#[const_trait]` - --> $SRC_DIR/core/src/default.rs:LL:COL +note: `Debug` can't be used with `~const` because it isn't annotated with `#[const_trait]` + --> $SRC_DIR/core/src/fmt/mod.rs:LL:COL error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const_trait_impl.rs:40:9 + --> $DIR/const_trait_impl.rs:42:9 | -LL | impl const A for T { - | ^^^^^^ can't be applied to `Default` +LL | impl const A for T { + | ^^^^^^ can't be applied to `Debug` | -note: `Default` can't be used with `~const` because it isn't annotated with `#[const_trait]` - --> $SRC_DIR/core/src/default.rs:LL:COL +note: `Debug` can't be used with `~const` because it isn't annotated with `#[const_trait]` + --> $SRC_DIR/core/src/fmt/mod.rs:LL:COL = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const_trait_impl.rs:34:9 + --> $DIR/const_trait_impl.rs:36:9 | -LL | impl const A for T { - | ^^^^^^ can't be applied to `Default` +LL | impl const A for T { + | ^^^^^^ can't be applied to `Debug` | -note: `Default` can't be used with `~const` because it isn't annotated with `#[const_trait]` - --> $SRC_DIR/core/src/default.rs:LL:COL +note: `Debug` can't be used with `~const` because it isn't annotated with `#[const_trait]` + --> $SRC_DIR/core/src/fmt/mod.rs:LL:COL = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const_trait_impl.rs:46:9 + --> $DIR/const_trait_impl.rs:48:9 | -LL | impl const A for T { - | ^^^^^^ can't be applied to `Default` +LL | impl const A for T { + | ^^^^^^ can't be applied to `Debug` | -note: `Default` can't be used with `~const` because it isn't annotated with `#[const_trait]` - --> $SRC_DIR/core/src/default.rs:LL:COL +note: `Debug` can't be used with `~const` because it isn't annotated with `#[const_trait]` + --> $SRC_DIR/core/src/fmt/mod.rs:LL:COL = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: aborting due to 6 previous errors diff --git a/tests/ui/const-generics/std/const-generics-alloc.rs b/tests/ui/traits/const-traits/const-traits-alloc.rs similarity index 100% rename from tests/ui/const-generics/std/const-generics-alloc.rs rename to tests/ui/traits/const-traits/const-traits-alloc.rs diff --git a/tests/ui/const-generics/std/const-generics-core.rs b/tests/ui/traits/const-traits/const-traits-core.rs similarity index 100% rename from tests/ui/const-generics/std/const-generics-core.rs rename to tests/ui/traits/const-traits/const-traits-core.rs diff --git a/tests/ui/traits/const-traits/const_derives/derive-const-gate.rs b/tests/ui/traits/const-traits/const_derives/derive-const-gate.rs index a772d69c9e2e2..ed4a5fdd57dab 100644 --- a/tests/ui/traits/const-traits/const_derives/derive-const-gate.rs +++ b/tests/ui/traits/const-traits/const_derives/derive-const-gate.rs @@ -1,5 +1,6 @@ -#[derive_const(Default)] //~ ERROR use of unstable library feature -//~^ ERROR const `impl` for trait `Default` which is not marked with `#[const_trait]` +#[derive_const(Debug)] //~ ERROR use of unstable library feature +//~^ ERROR const `impl` for trait `Debug` which is not marked with `#[const_trait]` +//~| ERROR cannot call non-const fn pub struct S; fn main() {} 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 fae871a4c85ac..3aeadd280ef59 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 @@ -1,22 +1,32 @@ error[E0658]: use of unstable library feature `derive_const` --> $DIR/derive-const-gate.rs:1:3 | -LL | #[derive_const(Default)] +LL | #[derive_const(Debug)] | ^^^^^^^^^^^^ | = help: add `#![feature(derive_const)]` 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 `impl` for trait `Default` which is not marked with `#[const_trait]` +error: const `impl` for trait `Debug` which is not marked with `#[const_trait]` --> $DIR/derive-const-gate.rs:1:16 | -LL | #[derive_const(Default)] - | ^^^^^^^ this trait is not `const` +LL | #[derive_const(Debug)] + | ^^^^^ 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 - = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to 2 previous errors +error[E0015]: cannot call non-const fn `Formatter::<'_>::write_str` in constant functions + --> $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 + = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 3 previous errors -For more information about this error, try `rustc --explain E0658`. +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/const_derives/derive-const-non-const-type.rs b/tests/ui/traits/const-traits/const_derives/derive-const-non-const-type.rs index 7bda7117a47e6..df421cbf8dbac 100644 --- a/tests/ui/traits/const-traits/const_derives/derive-const-non-const-type.rs +++ b/tests/ui/traits/const-traits/const_derives/derive-const-non-const-type.rs @@ -7,7 +7,7 @@ impl Default for A { fn default() -> A { A } } -#[derive_const(Default)] +#[derive_const(Debug)] pub struct S(A); fn main() {} 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 8a6401afcf19f..c5bbbfa538cb8 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 @@ -1,24 +1,30 @@ -error: const `impl` for trait `Default` which is not marked with `#[const_trait]` +error: const `impl` for trait `Debug` which is not marked with `#[const_trait]` --> $DIR/derive-const-non-const-type.rs:10:16 | -LL | #[derive_const(Default)] - | ^^^^^^^ this trait is not `const` +LL | #[derive_const(Debug)] + | ^^^^^ 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 - = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0015]: cannot call non-const fn `::default` in constant functions +error[E0277]: `A` doesn't implement `Debug` --> $DIR/derive-const-non-const-type.rs:11:14 | -LL | #[derive_const(Default)] - | ------- in this derive macro expansion +LL | #[derive_const(Debug)] + | ----- in this derive macro expansion LL | pub struct S(A); - | ^ + | ^ `A` cannot be formatted using `{:?}` + | + = help: the trait `Debug` is not implemented for `A` + = note: add `#[derive(Debug)]` to `A` or manually `impl Debug for A` + = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `A` with `#[derive(Debug)]` + | +LL + #[derive(Debug)] +LL | pub struct A; | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0015`. +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/const-traits/const_derives/derive-const-use.stderr b/tests/ui/traits/const-traits/const_derives/derive-const-use.stderr index 3b06f4d801a41..ebd68b0822872 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 @@ -10,25 +10,6 @@ error[E0635]: unknown feature `const_default_impls` LL | #![feature(const_trait_impl, const_cmp, const_default_impls, derive_const)] | ^^^^^^^^^^^^^^^^^^^ -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 { - | ^^^^^^^ 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 - -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)] - | ^^^^^^^ 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 - = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info) - error: const `impl` for trait `PartialEq` which is not marked with `#[const_trait]` --> $DIR/derive-const-use.rs:11:12 | @@ -48,14 +29,6 @@ LL | #[derive_const(Default, PartialEq)] = note: adding a non-const method body in the future would be a breaking change = note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0015]: cannot call non-const fn `::default` in constants - --> $DIR/derive-const-use.rs:18:35 - | -LL | const _: () = assert!(S((), A) == S::default()); - | ^^^^^^^^^^^^ - | - = note: calls in constants are limited to constant functions, tuple structs and tuple variants - error[E0015]: cannot call non-const operator in constants --> $DIR/derive-const-use.rs:18:23 | @@ -64,28 +37,6 @@ LL | const _: () = assert!(S((), A) == S::default()); | = note: calls in constants are limited to constant functions, tuple structs and tuple variants -error[E0015]: cannot call non-const fn `<() as Default>::default` in constant functions - --> $DIR/derive-const-use.rs:16:14 - | -LL | #[derive_const(Default, PartialEq)] - | ------- in this derive macro expansion -LL | pub struct S((), A); - | ^^ - | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0015]: cannot call non-const fn `::default` in constant functions - --> $DIR/derive-const-use.rs:16:18 - | -LL | #[derive_const(Default, PartialEq)] - | ------- in this derive macro expansion -LL | pub struct S((), A); - | ^ - | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info) - error[E0015]: cannot call non-const operator in constant functions --> $DIR/derive-const-use.rs:16:14 | @@ -108,7 +59,7 @@ LL | pub struct S((), A); = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants = note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to 12 previous errors +error: aborting due to 7 previous errors Some errors have detailed explanations: E0015, E0635. For more information about an error, try `rustc --explain E0015`. diff --git a/tests/ui/traits/const-traits/std-impl-gate.gated.stderr b/tests/ui/traits/const-traits/std-impl-gate.gated.stderr index f3b171307618d..bf53b995bb673 100644 --- a/tests/ui/traits/const-traits/std-impl-gate.gated.stderr +++ b/tests/ui/traits/const-traits/std-impl-gate.gated.stderr @@ -4,15 +4,6 @@ error[E0635]: unknown feature `const_default_impls` LL | #![cfg_attr(gated, feature(const_trait_impl, const_default_impls))] | ^^^^^^^^^^^^^^^^^^^ -error[E0015]: cannot call non-const fn ` as Default>::default` in constant functions - --> $DIR/std-impl-gate.rs:13:5 - | -LL | Default::default() - | ^^^^^^^^^^^^^^^^^^ - | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - -error: aborting due to 2 previous errors +error: aborting due to 1 previous error -Some errors have detailed explanations: E0015, E0635. -For more information about an error, try `rustc --explain E0015`. +For more information about this error, try `rustc --explain E0635`. diff --git a/tests/ui/traits/const-traits/std-impl-gate.rs b/tests/ui/traits/const-traits/std-impl-gate.rs index a9e2ff06290a8..72ea633da1b4d 100644 --- a/tests/ui/traits/const-traits/std-impl-gate.rs +++ b/tests/ui/traits/const-traits/std-impl-gate.rs @@ -11,7 +11,7 @@ fn non_const_context() -> Vec { const fn const_context() -> Vec { Default::default() - //[stock]~^ ERROR cannot call non-const fn + //[stock]~^ ERROR cannot call conditionally-const associated function } fn main() { 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 7240b5f4a94c2..17815a41b498d 100644 --- a/tests/ui/traits/const-traits/std-impl-gate.stock.stderr +++ b/tests/ui/traits/const-traits/std-impl-gate.stock.stderr @@ -1,11 +1,13 @@ -error[E0015]: cannot call non-const fn ` as Default>::default` in constant functions +error[E0658]: cannot call conditionally-const associated function ` as Default>::default` in constant functions --> $DIR/std-impl-gate.rs:13:5 | LL | Default::default() | ^^^^^^^^^^^^^^^^^^ | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants + = 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 1 previous error -For more information about this error, try `rustc --explain E0015`. +For more information about this error, try `rustc --explain E0658`.