about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorOli Scherer <github333195615777966@oli-obk.de>2025-03-12 10:26:37 +0000
committerOli Scherer <github333195615777966@oli-obk.de>2025-07-09 16:37:11 +0000
commit486ffda9dcd0d4ef0a09d81e6ce5f241e77526a1 (patch)
tree6016dd4aa95f8637e464cda9688a84c5a1002bc4 /tests
parent6b3ae3f6e45a33c2d95fa0362c9b2593e567fd34 (diff)
downloadrust-486ffda9dcd0d4ef0a09d81e6ce5f241e77526a1.tar.gz
rust-486ffda9dcd0d4ef0a09d81e6ce5f241e77526a1.zip
Add opaque TypeId handles for CTFE
Diffstat (limited to 'tests')
-rw-r--r--tests/codegen/error-provide.rs6
-rw-r--r--tests/ui/const-generics/issues/issue-90318.rs3
-rw-r--r--tests/ui/const-generics/issues/issue-90318.stderr25
-rw-r--r--tests/ui/consts/const_cmp_type_id.rs3
-rw-r--r--tests/ui/consts/const_cmp_type_id.stderr20
-rw-r--r--tests/ui/consts/const_transmute_type_id.rs11
-rw-r--r--tests/ui/consts/const_transmute_type_id.stderr12
-rw-r--r--tests/ui/consts/const_transmute_type_id2.rs14
-rw-r--r--tests/ui/consts/const_transmute_type_id2.stderr15
-rw-r--r--tests/ui/consts/const_transmute_type_id3.rs16
-rw-r--r--tests/ui/consts/const_transmute_type_id3.stderr15
-rw-r--r--tests/ui/consts/const_transmute_type_id4.rs16
-rw-r--r--tests/ui/consts/const_transmute_type_id4.stderr15
-rw-r--r--tests/ui/consts/issue-73976-monomorphic.rs2
-rw-r--r--tests/ui/consts/issue-73976-monomorphic.stderr9
15 files changed, 131 insertions, 51 deletions
diff --git a/tests/codegen/error-provide.rs b/tests/codegen/error-provide.rs
index 25a66078fd4..7f091e34359 100644
--- a/tests/codegen/error-provide.rs
+++ b/tests/codegen/error-provide.rs
@@ -37,9 +37,9 @@ impl std::error::Error for MyError {
         // and eliminate redundant ones, rather than compare one-by-one.
 
         // CHECK-NEXT: start:
-        // CHECK-NEXT: %[[SCRUTINEE:[^ ]+]] = load i64, ptr
-        // CHECK-NEXT: switch i64 %[[SCRUTINEE]], label %{{.*}} [
-        // CHECK-COUNT-3: i64 {{.*}}, label %{{.*}}
+        // CHECK-NEXT: %[[SCRUTINEE:[^ ]+]] = load i128, ptr
+        // CHECK-NEXT: switch i128 %[[SCRUTINEE]], label %{{.*}} [
+        // CHECK-COUNT-3: i128 {{.*}}, label %{{.*}}
         // CHECK-NEXT: ]
         request
             .provide_ref::<MyBacktrace1>(&self.backtrace1)
diff --git a/tests/ui/const-generics/issues/issue-90318.rs b/tests/ui/const-generics/issues/issue-90318.rs
index 317ddad49cd..dfba90a5575 100644
--- a/tests/ui/const-generics/issues/issue-90318.rs
+++ b/tests/ui/const-generics/issues/issue-90318.rs
@@ -1,5 +1,6 @@
 #![feature(const_type_id)]
 #![feature(generic_const_exprs)]
+#![feature(const_trait_impl)]
 #![feature(core_intrinsics)]
 #![allow(incomplete_features)]
 
@@ -13,7 +14,6 @@ fn consume<T: 'static>(_val: T)
 where
     If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
     //~^ ERROR overly complex generic constant
-    //~| ERROR: cannot call
 {
 }
 
@@ -21,7 +21,6 @@ fn test<T: 'static>()
 where
     If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
     //~^ ERROR overly complex generic constant
-    //~| ERROR: cannot call
 {
 }
 
diff --git a/tests/ui/const-generics/issues/issue-90318.stderr b/tests/ui/const-generics/issues/issue-90318.stderr
index 9c7cb5ceb58..7031230db91 100644
--- a/tests/ui/const-generics/issues/issue-90318.stderr
+++ b/tests/ui/const-generics/issues/issue-90318.stderr
@@ -1,5 +1,5 @@
 error: overly complex generic constant
-  --> $DIR/issue-90318.rs:14:8
+  --> $DIR/issue-90318.rs:15:8
    |
 LL |     If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
    |        ^^-----------------^^^^^^^^^^^^^^^^^^^^^^^^
@@ -20,26 +20,5 @@ LL |     If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
    = help: consider moving this anonymous constant into a `const` function
    = note: this operation may be supported in the future
 
-error[E0015]: cannot call non-const operator in constants
-  --> $DIR/issue-90318.rs:14:10
-   |
-LL |     If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
-   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-   |
-note: impl defined here, but it is not `const`
-  --> $SRC_DIR/core/src/any.rs:LL:COL
-   = note: calls in constants are limited to constant functions, tuple structs and tuple variants
-
-error[E0015]: cannot call non-const operator in constants
-  --> $DIR/issue-90318.rs:22:10
-   |
-LL |     If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
-   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-   |
-note: impl defined here, but it is not `const`
-  --> $SRC_DIR/core/src/any.rs:LL:COL
-   = note: calls in constants are limited to constant functions, tuple structs and tuple variants
-
-error: aborting due to 4 previous errors
+error: aborting due to 2 previous errors
 
-For more information about this error, try `rustc --explain E0015`.
diff --git a/tests/ui/consts/const_cmp_type_id.rs b/tests/ui/consts/const_cmp_type_id.rs
index dca0615083a..def615bd92b 100644
--- a/tests/ui/consts/const_cmp_type_id.rs
+++ b/tests/ui/consts/const_cmp_type_id.rs
@@ -6,10 +6,9 @@ use std::any::TypeId;
 fn main() {
     const {
         assert!(TypeId::of::<u8>() == TypeId::of::<u8>());
-        //~^ ERROR the trait bound `TypeId: const PartialEq` is not satisfied
         assert!(TypeId::of::<()>() != TypeId::of::<u8>());
-        //~^ ERROR the trait bound `TypeId: const PartialEq` is not satisfied
         let _a = TypeId::of::<u8>() < TypeId::of::<u16>();
+        //~^ ERROR: cannot call non-const operator in constants
         // can't assert `_a` because it is not deterministic
         // FIXME(const_trait_impl) make it pass
     }
diff --git a/tests/ui/consts/const_cmp_type_id.stderr b/tests/ui/consts/const_cmp_type_id.stderr
index a8242a200ef..540eec5098b 100644
--- a/tests/ui/consts/const_cmp_type_id.stderr
+++ b/tests/ui/consts/const_cmp_type_id.stderr
@@ -1,15 +1,13 @@
-error[E0277]: the trait bound `TypeId: const PartialEq` is not satisfied
-  --> $DIR/const_cmp_type_id.rs:8:17
+error[E0015]: cannot call non-const operator in constants
+  --> $DIR/const_cmp_type_id.rs:10:18
    |
-LL |         assert!(TypeId::of::<u8>() == TypeId::of::<u8>());
-   |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-error[E0277]: the trait bound `TypeId: const PartialEq` is not satisfied
-  --> $DIR/const_cmp_type_id.rs:10:17
+LL |         let _a = TypeId::of::<u8>() < TypeId::of::<u16>();
+   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
-LL |         assert!(TypeId::of::<()>() != TypeId::of::<u8>());
-   |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+note: impl defined here, but it is not `const`
+  --> $SRC_DIR/core/src/any.rs:LL:COL
+   = note: calls in constants are limited to constant functions, tuple structs and tuple variants
 
-error: aborting due to 2 previous errors
+error: aborting due to 1 previous error
 
-For more information about this error, try `rustc --explain E0277`.
+For more information about this error, try `rustc --explain E0015`.
diff --git a/tests/ui/consts/const_transmute_type_id.rs b/tests/ui/consts/const_transmute_type_id.rs
new file mode 100644
index 00000000000..56ead6a622b
--- /dev/null
+++ b/tests/ui/consts/const_transmute_type_id.rs
@@ -0,0 +1,11 @@
+#![feature(const_type_id, const_trait_impl)]
+
+use std::any::TypeId;
+
+const _: () = {
+    let id = TypeId::of::<u8>();
+    let id: u8 = unsafe { (&raw const id).cast::<u8>().read() };
+    //~^ ERROR: unable to turn pointer into integer
+};
+
+fn main() {}
diff --git a/tests/ui/consts/const_transmute_type_id.stderr b/tests/ui/consts/const_transmute_type_id.stderr
new file mode 100644
index 00000000000..85bd4ea2736
--- /dev/null
+++ b/tests/ui/consts/const_transmute_type_id.stderr
@@ -0,0 +1,12 @@
+error[E0080]: unable to turn pointer into integer
+  --> $DIR/const_transmute_type_id.rs:7:27
+   |
+LL |     let id: u8 = unsafe { (&raw const id).cast::<u8>().read() };
+   |                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `_` failed here
+   |
+   = help: this code performed an operation that depends on the underlying bytes representing a pointer
+   = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0080`.
diff --git a/tests/ui/consts/const_transmute_type_id2.rs b/tests/ui/consts/const_transmute_type_id2.rs
new file mode 100644
index 00000000000..e29cf8171ac
--- /dev/null
+++ b/tests/ui/consts/const_transmute_type_id2.rs
@@ -0,0 +1,14 @@
+//@ normalize-stderr: "0x(ff)+" -> "<u128::MAX>"
+
+#![feature(const_type_id, const_trait_impl)]
+
+use std::any::TypeId;
+
+const _: () = {
+    let a: TypeId = unsafe { std::mem::transmute(u128::MAX) };
+    let b: TypeId = unsafe { std::mem::transmute(u128::MAX) };
+    assert!(a == b);
+    //~^ ERROR: pointer must point to some allocation
+};
+
+fn main() {}
diff --git a/tests/ui/consts/const_transmute_type_id2.stderr b/tests/ui/consts/const_transmute_type_id2.stderr
new file mode 100644
index 00000000000..5646eb1257d
--- /dev/null
+++ b/tests/ui/consts/const_transmute_type_id2.stderr
@@ -0,0 +1,15 @@
+error[E0080]: pointer not dereferenceable: pointer must point to some allocation, but got <u128::MAX>[noalloc] which is a dangling pointer (it has no provenance)
+  --> $DIR/const_transmute_type_id2.rs:10:13
+   |
+LL |     assert!(a == b);
+   |             ^^^^^^ evaluation of `_` failed inside this call
+   |
+note: inside `<TypeId as PartialEq>::eq`
+  --> $SRC_DIR/core/src/any.rs:LL:COL
+note: inside `<TypeId as PartialEq>::eq::compiletime`
+  --> $SRC_DIR/core/src/any.rs:LL:COL
+   = note: this error originates in the macro `$crate::intrinsics::const_eval_select` which comes from the expansion of the macro `crate::intrinsics::const_eval_select` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0080`.
diff --git a/tests/ui/consts/const_transmute_type_id3.rs b/tests/ui/consts/const_transmute_type_id3.rs
new file mode 100644
index 00000000000..a870d6e7e80
--- /dev/null
+++ b/tests/ui/consts/const_transmute_type_id3.rs
@@ -0,0 +1,16 @@
+#![feature(const_type_id, const_trait_impl)]
+
+use std::any::TypeId;
+
+const _: () = {
+    let a = TypeId::of::<()>();
+    let mut b = TypeId::of::<()>();
+    unsafe {
+        let ptr = &mut b as *mut TypeId as *mut usize;
+        std::ptr::write(ptr.offset(1), 999);
+    }
+    assert!(a == b);
+    //~^ ERROR: one of the TypeId arguments is invalid, the hash does not match the type it represents
+};
+
+fn main() {}
diff --git a/tests/ui/consts/const_transmute_type_id3.stderr b/tests/ui/consts/const_transmute_type_id3.stderr
new file mode 100644
index 00000000000..8cfdcfebaa4
--- /dev/null
+++ b/tests/ui/consts/const_transmute_type_id3.stderr
@@ -0,0 +1,15 @@
+error[E0080]: type_id_eq: one of the TypeId arguments is invalid, the hash does not match the type it represents
+  --> $DIR/const_transmute_type_id3.rs:12:13
+   |
+LL |     assert!(a == b);
+   |             ^^^^^^ evaluation of `_` failed inside this call
+   |
+note: inside `<TypeId as PartialEq>::eq`
+  --> $SRC_DIR/core/src/any.rs:LL:COL
+note: inside `<TypeId as PartialEq>::eq::compiletime`
+  --> $SRC_DIR/core/src/any.rs:LL:COL
+   = note: this error originates in the macro `$crate::intrinsics::const_eval_select` which comes from the expansion of the macro `crate::intrinsics::const_eval_select` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0080`.
diff --git a/tests/ui/consts/const_transmute_type_id4.rs b/tests/ui/consts/const_transmute_type_id4.rs
new file mode 100644
index 00000000000..bc71f961a51
--- /dev/null
+++ b/tests/ui/consts/const_transmute_type_id4.rs
@@ -0,0 +1,16 @@
+#![feature(const_type_id, const_trait_impl)]
+
+use std::any::TypeId;
+
+const _: () = {
+    let a = TypeId::of::<()>();
+    let mut b = TypeId::of::<()>();
+    unsafe {
+        let ptr = &mut b as *mut TypeId as *mut *const ();
+        std::ptr::write(ptr.offset(0), main as fn() as *const ());
+    }
+    assert!(a == b);
+    //~^ ERROR: type_id_eq: `TypeId` provenance is not a type id
+};
+
+fn main() {}
diff --git a/tests/ui/consts/const_transmute_type_id4.stderr b/tests/ui/consts/const_transmute_type_id4.stderr
new file mode 100644
index 00000000000..b418a79d7f0
--- /dev/null
+++ b/tests/ui/consts/const_transmute_type_id4.stderr
@@ -0,0 +1,15 @@
+error[E0080]: type_id_eq: `TypeId` provenance is not a type id
+  --> $DIR/const_transmute_type_id4.rs:12:13
+   |
+LL |     assert!(a == b);
+   |             ^^^^^^ evaluation of `_` failed inside this call
+   |
+note: inside `<TypeId as PartialEq>::eq`
+  --> $SRC_DIR/core/src/any.rs:LL:COL
+note: inside `<TypeId as PartialEq>::eq::compiletime`
+  --> $SRC_DIR/core/src/any.rs:LL:COL
+   = note: this error originates in the macro `$crate::intrinsics::const_eval_select` which comes from the expansion of the macro `crate::intrinsics::const_eval_select` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0080`.
diff --git a/tests/ui/consts/issue-73976-monomorphic.rs b/tests/ui/consts/issue-73976-monomorphic.rs
index 561c1976051..3bfdb397afb 100644
--- a/tests/ui/consts/issue-73976-monomorphic.rs
+++ b/tests/ui/consts/issue-73976-monomorphic.rs
@@ -1,4 +1,4 @@
-//@ known-bug: #110395
+//@ check-pass
 //
 // This test is complement to the test in issue-73976-polymorphic.rs.
 // In that test we ensure that polymorphic use of type_id and type_name in patterns
diff --git a/tests/ui/consts/issue-73976-monomorphic.stderr b/tests/ui/consts/issue-73976-monomorphic.stderr
deleted file mode 100644
index 367d5be09da..00000000000
--- a/tests/ui/consts/issue-73976-monomorphic.stderr
+++ /dev/null
@@ -1,9 +0,0 @@
-error[E0277]: the trait bound `TypeId: [const] PartialEq` is not satisfied
-  --> $DIR/issue-73976-monomorphic.rs:21:5
-   |
-LL |     GetTypeId::<T>::VALUE == GetTypeId::<usize>::VALUE
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-error: aborting due to 1 previous error
-
-For more information about this error, try `rustc --explain E0277`.