about summary refs log tree commit diff
path: root/tests/ui/consts
diff options
context:
space:
mode:
authorEvgenii Zheltonozhskii <zheltonozhskiy@gmail.com>2025-07-21 12:49:45 +0300
committerEvgenii Zheltonozhskii <zheltonozhskiy@gmail.com>2025-07-21 12:49:45 +0300
commit3c76e3d0026ea9904358b1614bbd9c4f8b7cedf5 (patch)
tree5d3aeecf65661c610495cc977f2af80cbd9317c7 /tests/ui/consts
parent12865ffd0dfb4ea969e2f16eb0140238bb9dd382 (diff)
downloadrust-3c76e3d0026ea9904358b1614bbd9c4f8b7cedf5.tar.gz
rust-3c76e3d0026ea9904358b1614bbd9c4f8b7cedf5.zip
Constify Try, From, TryFrom
Diffstat (limited to 'tests/ui/consts')
-rw-r--r--tests/ui/consts/const-try-feature-gate.rs2
-rw-r--r--tests/ui/consts/const-try-feature-gate.stderr36
-rw-r--r--tests/ui/consts/const-try.rs8
-rw-r--r--tests/ui/consts/const-try.stderr37
-rw-r--r--tests/ui/consts/control-flow/try.rs9
-rw-r--r--tests/ui/consts/control-flow/try.stderr19
-rw-r--r--tests/ui/consts/try-operator.rs3
-rw-r--r--tests/ui/consts/try-operator.stderr42
8 files changed, 43 insertions, 113 deletions
diff --git a/tests/ui/consts/const-try-feature-gate.rs b/tests/ui/consts/const-try-feature-gate.rs
index 09985079e8e..4a98185a18a 100644
--- a/tests/ui/consts/const-try-feature-gate.rs
+++ b/tests/ui/consts/const-try-feature-gate.rs
@@ -4,6 +4,8 @@ const fn t() -> Option<()> {
     Some(())?;
     //~^ ERROR `?` is not allowed
     //~| ERROR `?` is not allowed
+    //~| ERROR `Try` is not yet stable as a const trait
+    //~| ERROR `FromResidual` is not yet stable as a const trait
     None
 }
 
diff --git a/tests/ui/consts/const-try-feature-gate.stderr b/tests/ui/consts/const-try-feature-gate.stderr
index 0ad19d05b38..62a4a5fba4f 100644
--- a/tests/ui/consts/const-try-feature-gate.stderr
+++ b/tests/ui/consts/const-try-feature-gate.stderr
@@ -1,19 +1,47 @@
-error[E0015]: `?` is not allowed on `Option<()>` in constant functions
+error[E0658]: `?` is not allowed on `Option<()>` in constant functions
   --> $DIR/const-try-feature-gate.rs:4:5
    |
 LL |     Some(())?;
    |     ^^^^^^^^^
    |
    = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
+   = note: see issue #143874 <https://github.com/rust-lang/rust/issues/143874> for more information
+   = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
+   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
 
-error[E0015]: `?` is not allowed on `Option<()>` in constant functions
+error: `Try` is not yet stable as a const trait
+  --> $DIR/const-try-feature-gate.rs:4:5
+   |
+LL |     Some(())?;
+   |     ^^^^^^^^^
+   |
+help: add `#![feature(const_try)]` to the crate attributes to enable
+   |
+LL + #![feature(const_try)]
+   |
+
+error[E0658]: `?` is not allowed on `Option<()>` in constant functions
   --> $DIR/const-try-feature-gate.rs:4:5
    |
 LL |     Some(())?;
    |     ^^^^^^^^^
    |
    = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
+   = note: see issue #143874 <https://github.com/rust-lang/rust/issues/143874> for more information
+   = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
+   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
+
+error: `FromResidual` is not yet stable as a const trait
+  --> $DIR/const-try-feature-gate.rs:4:5
+   |
+LL |     Some(())?;
+   |     ^^^^^^^^^
+   |
+help: add `#![feature(const_try)]` to the crate attributes to enable
+   |
+LL + #![feature(const_try)]
+   |
 
-error: aborting due to 2 previous errors
+error: aborting due to 4 previous errors
 
-For more information about this error, try `rustc --explain E0015`.
+For more information about this error, try `rustc --explain E0658`.
diff --git a/tests/ui/consts/const-try.rs b/tests/ui/consts/const-try.rs
index e13fad78441..152400d702e 100644
--- a/tests/ui/consts/const-try.rs
+++ b/tests/ui/consts/const-try.rs
@@ -1,4 +1,6 @@
-//@ compile-flags: -Znext-solver
+//@ check-pass
+//@ revisions: current next
+//@[next] compile-flags: -Znext-solver
 
 // Demonstrates what's needed to make use of `?` in const contexts.
 
@@ -13,14 +15,12 @@ struct TryMe;
 struct Error;
 
 impl const FromResidual<Error> for TryMe {
-    //~^ ERROR const `impl` for trait `FromResidual` which is not `const`
     fn from_residual(residual: Error) -> Self {
         TryMe
     }
 }
 
 impl const Try for TryMe {
-    //~^ ERROR const `impl` for trait `Try` which is not `const`
     type Output = ();
     type Residual = Error;
     fn from_output(output: Self::Output) -> Self {
@@ -33,8 +33,6 @@ impl const Try for TryMe {
 
 const fn t() -> TryMe {
     TryMe?;
-    //~^ ERROR `?` is not allowed on
-    //~| ERROR `?` is not allowed on
     TryMe
 }
 
diff --git a/tests/ui/consts/const-try.stderr b/tests/ui/consts/const-try.stderr
deleted file mode 100644
index 7004ea3e6db..00000000000
--- a/tests/ui/consts/const-try.stderr
+++ /dev/null
@@ -1,37 +0,0 @@
-error: const `impl` for trait `FromResidual` which is not `const`
-  --> $DIR/const-try.rs:15:12
-   |
-LL | impl const FromResidual<Error> for TryMe {
-   |            ^^^^^^^^^^^^^^^^^^^ this trait is not `const`
-   |
-   = note: marking a trait with `const` 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 `Try` which is not `const`
-  --> $DIR/const-try.rs:22:12
-   |
-LL | impl const Try for TryMe {
-   |            ^^^ this trait is not `const`
-   |
-   = note: marking a trait with `const` ensures all default method bodies are `const`
-   = note: adding a non-const method body in the future would be a breaking change
-
-error[E0015]: `?` is not allowed on `TryMe` in constant functions
-  --> $DIR/const-try.rs:35:5
-   |
-LL |     TryMe?;
-   |     ^^^^^^
-   |
-   = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
-
-error[E0015]: `?` is not allowed on `TryMe` in constant functions
-  --> $DIR/const-try.rs:35:5
-   |
-LL |     TryMe?;
-   |     ^^^^^^
-   |
-   = 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/ui/consts/control-flow/try.rs b/tests/ui/consts/control-flow/try.rs
index 67083e1a39b..6d762f9194e 100644
--- a/tests/ui/consts/control-flow/try.rs
+++ b/tests/ui/consts/control-flow/try.rs
@@ -1,11 +1,12 @@
-// The `?` operator is still not const-evaluatable because it calls `From::from` on the error
-// variant.
+//@ check-pass
+
+#![allow(dead_code)]
+#![feature(const_trait_impl)]
+#![feature(const_try)]
 
 const fn opt() -> Option<i32> {
     let x = Some(2);
     x?;
-    //~^ ERROR: `?` is not allowed
-    //~| ERROR: `?` is not allowed
     None
 }
 
diff --git a/tests/ui/consts/control-flow/try.stderr b/tests/ui/consts/control-flow/try.stderr
deleted file mode 100644
index 62a3e3ce6bc..00000000000
--- a/tests/ui/consts/control-flow/try.stderr
+++ /dev/null
@@ -1,19 +0,0 @@
-error[E0015]: `?` is not allowed on `Option<i32>` in constant functions
-  --> $DIR/try.rs:6:5
-   |
-LL |     x?;
-   |     ^^
-   |
-   = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
-
-error[E0015]: `?` is not allowed on `Option<i32>` in constant functions
-  --> $DIR/try.rs:6:5
-   |
-LL |     x?;
-   |     ^^
-   |
-   = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
-
-error: aborting due to 2 previous errors
-
-For more information about this error, try `rustc --explain E0015`.
diff --git a/tests/ui/consts/try-operator.rs b/tests/ui/consts/try-operator.rs
index 352dbeefa8a..59d9fcb1cbd 100644
--- a/tests/ui/consts/try-operator.rs
+++ b/tests/ui/consts/try-operator.rs
@@ -1,9 +1,8 @@
-//@ known-bug: #110395
+//@ run-pass
 
 #![feature(try_trait_v2)]
 #![feature(const_trait_impl)]
 #![feature(const_try)]
-#![feature(const_convert)]
 
 fn main() {
     const fn result() -> Result<bool, ()> {
diff --git a/tests/ui/consts/try-operator.stderr b/tests/ui/consts/try-operator.stderr
deleted file mode 100644
index fc37039d260..00000000000
--- a/tests/ui/consts/try-operator.stderr
+++ /dev/null
@@ -1,42 +0,0 @@
-error[E0635]: unknown feature `const_convert`
-  --> $DIR/try-operator.rs:6:12
-   |
-LL | #![feature(const_convert)]
-   |            ^^^^^^^^^^^^^
-
-error[E0015]: `?` is not allowed on `Result<(), ()>` in constant functions
-  --> $DIR/try-operator.rs:10:9
-   |
-LL |         Err(())?;
-   |         ^^^^^^^^
-   |
-   = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
-
-error[E0015]: `?` is not allowed on `Result<bool, ()>` in constant functions
-  --> $DIR/try-operator.rs:10:9
-   |
-LL |         Err(())?;
-   |         ^^^^^^^^
-   |
-   = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
-
-error[E0015]: `?` is not allowed on `Option<()>` in constant functions
-  --> $DIR/try-operator.rs:18:9
-   |
-LL |         None?;
-   |         ^^^^^
-   |
-   = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
-
-error[E0015]: `?` is not allowed on `Option<()>` in constant functions
-  --> $DIR/try-operator.rs:18:9
-   |
-LL |         None?;
-   |         ^^^^^
-   |
-   = 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, E0635.
-For more information about an error, try `rustc --explain E0015`.