about summary refs log tree commit diff
path: root/tests/ui/traits
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2025-08-23 22:22:18 +0200
committerGitHub <noreply@github.com>2025-08-23 22:22:18 +0200
commit9847cb249964b175c627e812275f7a9601b9dca8 (patch)
treea9c6360cdef2fbbc181a8797e6e0fd97e644180c /tests/ui/traits
parente7dc14e59bd3f99fb0aa3f278fafe9ebc15c6738 (diff)
parente8ae1dab12bc1388cd5f6545ccc88297b779f511 (diff)
downloadrust-9847cb249964b175c627e812275f7a9601b9dca8.tar.gz
rust-9847cb249964b175c627e812275f7a9601b9dca8.zip
Rollup merge of #145713 - lcnr:const-trait-bootstrap, r=compiler-errors
next-solver: fix `feature(const_trait_impl)` bootstrap

rarw

r? ``@compiler-errors`` ``@fee1-dead``
Diffstat (limited to 'tests/ui/traits')
-rw-r--r--tests/ui/traits/const-traits/constructor-const-fn.rs15
-rw-r--r--tests/ui/traits/const-traits/reservation-impl-ice.rs13
-rw-r--r--tests/ui/traits/const-traits/reservation-impl-ice.stderr25
3 files changed, 53 insertions, 0 deletions
diff --git a/tests/ui/traits/const-traits/constructor-const-fn.rs b/tests/ui/traits/const-traits/constructor-const-fn.rs
new file mode 100644
index 00000000000..4a7bf531df2
--- /dev/null
+++ b/tests/ui/traits/const-traits/constructor-const-fn.rs
@@ -0,0 +1,15 @@
+//@ check-pass
+//@ compile-flags: -Znext-solver
+#![feature(const_trait_impl)]
+const fn impls_fn<F: ~const Fn(u32) -> Foo>(_: &F) {}
+
+struct Foo(u32);
+
+const fn foo() {
+    // This previously triggered an incorrect assert
+    // when checking whether the constructor of `Foo`
+    // is const.
+    impls_fn(&Foo)
+}
+
+fn main() {}
diff --git a/tests/ui/traits/const-traits/reservation-impl-ice.rs b/tests/ui/traits/const-traits/reservation-impl-ice.rs
new file mode 100644
index 00000000000..efaea1cc6b2
--- /dev/null
+++ b/tests/ui/traits/const-traits/reservation-impl-ice.rs
@@ -0,0 +1,13 @@
+//@ compile-flags: -Znext-solver
+#![feature(const_from, never_type, const_trait_impl)]
+
+const fn impls_from<T: ~const From<!>>() {}
+
+const fn foo() {
+    // This previously ICE'd when encountering the reservation impl
+    // from the standard library.
+    impls_from::<()>();
+    //~^ ERROR the trait bound `(): From<!>` is not satisfied
+}
+
+fn main() {}
diff --git a/tests/ui/traits/const-traits/reservation-impl-ice.stderr b/tests/ui/traits/const-traits/reservation-impl-ice.stderr
new file mode 100644
index 00000000000..a3fdcbac69e
--- /dev/null
+++ b/tests/ui/traits/const-traits/reservation-impl-ice.stderr
@@ -0,0 +1,25 @@
+error[E0277]: the trait bound `(): From<!>` is not satisfied
+  --> $DIR/reservation-impl-ice.rs:9:18
+   |
+LL |     impls_from::<()>();
+   |                  ^^ the trait `From<!>` is not implemented for `()`
+   |
+   = help: the following other types implement trait `From<T>`:
+             `(T, T)` implements `From<[T; 2]>`
+             `(T, T, T)` implements `From<[T; 3]>`
+             `(T, T, T, T)` implements `From<[T; 4]>`
+             `(T, T, T, T, T)` implements `From<[T; 5]>`
+             `(T, T, T, T, T, T)` implements `From<[T; 6]>`
+             `(T, T, T, T, T, T, T)` implements `From<[T; 7]>`
+             `(T, T, T, T, T, T, T, T)` implements `From<[T; 8]>`
+             `(T, T, T, T, T, T, T, T, T)` implements `From<[T; 9]>`
+           and 4 others
+note: required by a bound in `impls_from`
+  --> $DIR/reservation-impl-ice.rs:4:24
+   |
+LL | const fn impls_from<T: ~const From<!>>() {}
+   |                        ^^^^^^^^^^^^^^ required by this bound in `impls_from`
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0277`.