Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Dec 22, 2024
1 parent b910a27 commit 00b0c75
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 125 deletions.
6 changes: 3 additions & 3 deletions tests/ui/consts/rustc-impl-const-stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!()
}
}
6 changes: 3 additions & 3 deletions tests/ui/consts/rustc-impl-const-stability.stderr
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 5 additions & 3 deletions tests/ui/specialization/const_trait_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -31,19 +33,19 @@ pub trait A {
fn a() -> u32;
}

impl<T: ~const Default> const A for T {
impl<T: ~const Debug> const A for T {
default fn a() -> u32 {
2
}
}

impl<T: ~const Default + ~const Sup> const A for T {
impl<T: ~const Debug + ~const Sup> const A for T {
default fn a() -> u32 {
3
}
}

impl<T: ~const Default + ~const Sub> const A for T {
impl<T: ~const Debug + ~const Sub> const A for T {
fn a() -> u32 {
T::foo()
}
Expand Down
60 changes: 30 additions & 30 deletions tests/ui/specialization/const_trait_impl.stderr
Original file line number Diff line number Diff line change
@@ -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<T: ~const Default> const A for T {
| ^^^^^^ can't be applied to `Default`
LL | impl<T: ~const Debug> 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<T: ~const Default + ~const Sup> const A for T {
| ^^^^^^ can't be applied to `Default`
LL | impl<T: ~const Debug + ~const Sup> 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<T: ~const Default + ~const Sub> const A for T {
| ^^^^^^ can't be applied to `Default`
LL | impl<T: ~const Debug + ~const Sub> 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<T: ~const Default + ~const Sup> const A for T {
| ^^^^^^ can't be applied to `Default`
LL | impl<T: ~const Debug + ~const Sup> 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<T: ~const Default> const A for T {
| ^^^^^^ can't be applied to `Default`
LL | impl<T: ~const Debug> 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<T: ~const Default + ~const Sub> const A for T {
| ^^^^^^ can't be applied to `Default`
LL | impl<T: ~const Debug + ~const Sub> 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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() {}
Original file line number Diff line number Diff line change
@@ -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`.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ impl Default for A {
fn default() -> A { A }
}

#[derive_const(Default)]
#[derive_const(Debug)]
pub struct S(A);

fn main() {}
Original file line number Diff line number Diff line change
@@ -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 `<A as Default>::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`.
Original file line number Diff line number Diff line change
Expand Up @@ -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
|
Expand All @@ -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 `<S as Default>::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
|
Expand All @@ -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 `<A as Default>::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
|
Expand All @@ -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`.
13 changes: 2 additions & 11 deletions tests/ui/traits/const-traits/std-impl-gate.gated.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<Vec<usize> 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`.
2 changes: 1 addition & 1 deletion tests/ui/traits/const-traits/std-impl-gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn non_const_context() -> Vec<usize> {

const fn const_context() -> Vec<usize> {
Default::default()
//[stock]~^ ERROR cannot call non-const fn
//[stock]~^ ERROR cannot call conditionally-const associated function
}

fn main() {
Expand Down
8 changes: 5 additions & 3 deletions tests/ui/traits/const-traits/std-impl-gate.stock.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
error[E0015]: cannot call non-const fn `<Vec<usize> as Default>::default` in constant functions
error[E0658]: cannot call conditionally-const associated function `<Vec<usize> 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 <https://github.com/rust-lang/rust/issues/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`.

0 comments on commit 00b0c75

Please sign in to comment.