about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-07-13 15:16:00 +0200
committerGitHub <noreply@github.com>2025-07-13 15:16:00 +0200
commitccd6d6c04f7a06d8860301222020ab8ffd045637 (patch)
tree160178ab8845b77d62a5c21b608a4627759075dc /tests
parentdcdb35a7308a1b9a8bc72658aa402ee2472b1910 (diff)
parente681d1a9731897951ea4c2d68c7d8f4a322b9904 (diff)
downloadrust-ccd6d6c04f7a06d8860301222020ab8ffd045637.tar.gz
rust-ccd6d6c04f7a06d8860301222020ab8ffd045637.zip
Rollup merge of #143774 - oli-obk:const_from, r=fee1-dead
constify `From` and `Into`

tracking issue rust-lang/rust#143773

r? ``````@fee1-dead``````

I did not mark any impls elsewhere as `const`, those can happen on their own timeframe and don't need to be part of this MVP. But if there are some core ones you think should be in there I'll happily add them, just couldn't think of any
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/specialization/issue-111232.rs9
-rw-r--r--tests/ui/specialization/issue-111232.stderr9
-rw-r--r--tests/ui/traits/const-traits/non-const-op-in-closure-in-const.rs4
-rw-r--r--tests/ui/traits/const-traits/non-const-op-in-closure-in-const.stderr30
4 files changed, 17 insertions, 35 deletions
diff --git a/tests/ui/specialization/issue-111232.rs b/tests/ui/specialization/issue-111232.rs
index 3ed3c580e6d..fa00f01886f 100644
--- a/tests/ui/specialization/issue-111232.rs
+++ b/tests/ui/specialization/issue-111232.rs
@@ -1,4 +1,13 @@
 #![feature(min_specialization)]
+#![feature(const_trait_impl)]
+
+trait From<T> {
+    fn from(t: T) -> Self;
+}
+
+impl<T> From<T> for T {
+    fn from(t: T) -> T { t }
+}
 
 struct S;
 
diff --git a/tests/ui/specialization/issue-111232.stderr b/tests/ui/specialization/issue-111232.stderr
index ed392e4f915..5f169f0bb36 100644
--- a/tests/ui/specialization/issue-111232.stderr
+++ b/tests/ui/specialization/issue-111232.stderr
@@ -1,10 +1,13 @@
 error[E0520]: `from` specializes an item from a parent `impl`, but that item is not marked `default`
-  --> $DIR/issue-111232.rs:6:5
+  --> $DIR/issue-111232.rs:15:5
    |
+LL | impl<T> From<T> for T {
+   | --------------------- parent `impl` is here
+...
 LL |     fn from(s: S) -> S {
-   |     ^^^^^^^^^^^^^^^^^^
+   |     ^^^^^^^^^^^^^^^^^^ cannot specialize default item `from`
    |
-   = note: parent implementation is in crate `core`
+   = note: to specialize, `from` in the parent `impl` must be marked `default`
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/traits/const-traits/non-const-op-in-closure-in-const.rs b/tests/ui/traits/const-traits/non-const-op-in-closure-in-const.rs
index 86e3e5f769f..d5f80acc15b 100644
--- a/tests/ui/traits/const-traits/non-const-op-in-closure-in-const.rs
+++ b/tests/ui/traits/const-traits/non-const-op-in-closure-in-const.rs
@@ -1,6 +1,6 @@
-//@ known-bug: #110395
+#![feature(const_trait_impl, const_from)]
 
-#![feature(const_trait_impl)]
+//@ check-pass
 
 #[const_trait]
 trait Convert<T> {
diff --git a/tests/ui/traits/const-traits/non-const-op-in-closure-in-const.stderr b/tests/ui/traits/const-traits/non-const-op-in-closure-in-const.stderr
deleted file mode 100644
index e7f10e73c69..00000000000
--- a/tests/ui/traits/const-traits/non-const-op-in-closure-in-const.stderr
+++ /dev/null
@@ -1,30 +0,0 @@
-error: `[const]` can only be applied to `#[const_trait]` traits
-  --> $DIR/non-const-op-in-closure-in-const.rs:10:44
-   |
-LL | impl<A, B> const Convert<B> for A where B: [const] From<A> {
-   |                                            ^^^^^^^ can't be applied to `From`
-   |
-note: `From` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
-  --> $SRC_DIR/core/src/convert/mod.rs:LL:COL
-
-error: `[const]` can only be applied to `#[const_trait]` traits
-  --> $DIR/non-const-op-in-closure-in-const.rs:10:44
-   |
-LL | impl<A, B> const Convert<B> for A where B: [const] From<A> {
-   |                                            ^^^^^^^ can't be applied to `From`
-   |
-note: `From` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
-  --> $SRC_DIR/core/src/convert/mod.rs:LL:COL
-   = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
-
-error[E0015]: cannot call non-const associated function `<B as From<A>>::from` in constant functions
-  --> $DIR/non-const-op-in-closure-in-const.rs:12:9
-   |
-LL |         B::from(self)
-   |         ^^^^^^^^^^^^^
-   |
-   = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
-
-error: aborting due to 3 previous errors
-
-For more information about this error, try `rustc --explain E0015`.