summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>2023-01-17 20:33:03 +0530
committerGitHub <noreply@github.com>2023-01-17 20:33:03 +0530
commit09faa266dac3a7e85f57a7b02e9ee181076207b7 (patch)
tree3eb4f20b30e59ad50fec3915bb375455dfeb415f /tests
parentf34cc658eb477958e2b73e05586e7af66faefad9 (diff)
parent7355ab3fe33518bbcaeb04ef0629674b6902293a (diff)
downloadrust-09faa266dac3a7e85f57a7b02e9ee181076207b7.tar.gz
Rollup merge of #101698 - raldone01:feat/const_cmp_typeid, r=scottmcm
Constify `TypeId` ordering impls Tracking issue: #101871 Adding const ordering to `TypeId` allows rtti crates to optimize some casting scenarios (without transmuting to `u64`). This would also prevent these crates from breaking if the underlying type is changed from `u64` to something different. Feature gate: `#![feature(const_cmp_type_id)]`
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/const-generics/issues/issue-90318.rs4
-rw-r--r--tests/ui/const-generics/issues/issue-90318.stderr33
-rw-r--r--tests/ui/consts/const_cmp_type_id.rs12
-rw-r--r--tests/ui/consts/issue-73976-monomorphic.rs3
4 files changed, 30 insertions, 22 deletions
diff --git a/tests/ui/const-generics/issues/issue-90318.rs b/tests/ui/const-generics/issues/issue-90318.rs
index d6c48e63bb3..909997340f3 100644
--- a/tests/ui/const-generics/issues/issue-90318.rs
+++ b/tests/ui/const-generics/issues/issue-90318.rs
@@ -12,14 +12,14 @@ impl True for If<true> {}
fn consume<T: 'static>(_val: T)
where
If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
- //~^ ERROR: can't compare
+ //~^ overly complex generic constant
{
}
fn test<T: 'static>()
where
If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
- //~^ ERROR: can't compare
+ //~^ overly complex generic constant
{
}
diff --git a/tests/ui/const-generics/issues/issue-90318.stderr b/tests/ui/const-generics/issues/issue-90318.stderr
index aba4b5c1a8d..f13fd795d7a 100644
--- a/tests/ui/const-generics/issues/issue-90318.stderr
+++ b/tests/ui/const-generics/issues/issue-90318.stderr
@@ -1,29 +1,24 @@
-error[E0277]: can't compare `TypeId` with `_` in const contexts
- --> $DIR/issue-90318.rs:14:28
+error: overly complex generic constant
+ --> $DIR/issue-90318.rs:14:8
|
LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
- | ^^ no implementation for `TypeId == _`
+ | ^^-----------------^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | borrowing is not supported in generic constants
|
- = help: the trait `~const PartialEq<_>` is not implemented for `TypeId`
-note: the trait `PartialEq<_>` is implemented for `TypeId`, but that implementation is not `const`
- --> $DIR/issue-90318.rs:14:28
- |
-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[E0277]: can't compare `TypeId` with `_` in const contexts
- --> $DIR/issue-90318.rs:21:28
+error: overly complex generic constant
+ --> $DIR/issue-90318.rs:21:8
|
LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
- | ^^ no implementation for `TypeId == _`
+ | ^^-----------------^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | borrowing is not supported in generic constants
|
- = help: the trait `~const PartialEq<_>` is not implemented for `TypeId`
-note: the trait `PartialEq<_>` is implemented for `TypeId`, but that implementation is not `const`
- --> $DIR/issue-90318.rs:21:28
- |
-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: aborting due to 2 previous errors
-For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/consts/const_cmp_type_id.rs b/tests/ui/consts/const_cmp_type_id.rs
new file mode 100644
index 00000000000..f10d1c24f7d
--- /dev/null
+++ b/tests/ui/consts/const_cmp_type_id.rs
@@ -0,0 +1,12 @@
+// run-pass
+#![feature(const_type_id)]
+#![feature(const_trait_impl)]
+
+use std::any::TypeId;
+
+const fn main() {
+ assert!(TypeId::of::<u8>() == TypeId::of::<u8>());
+ assert!(TypeId::of::<()>() != TypeId::of::<u8>());
+ const _A: bool = TypeId::of::<u8>() < TypeId::of::<u16>();
+ // can't assert `_A` because it is not deterministic
+}
diff --git a/tests/ui/consts/issue-73976-monomorphic.rs b/tests/ui/consts/issue-73976-monomorphic.rs
index 7706a97f23b..addcc1eaab6 100644
--- a/tests/ui/consts/issue-73976-monomorphic.rs
+++ b/tests/ui/consts/issue-73976-monomorphic.rs
@@ -7,6 +7,7 @@
#![feature(const_type_id)]
#![feature(const_type_name)]
+#![feature(const_trait_impl)]
use std::any::{self, TypeId};
@@ -17,7 +18,7 @@ impl<T: 'static> GetTypeId<T> {
}
const fn check_type_id<T: 'static>() -> bool {
- matches!(GetTypeId::<T>::VALUE, GetTypeId::<usize>::VALUE)
+ GetTypeId::<T>::VALUE == GetTypeId::<usize>::VALUE
}
pub struct GetTypeNameLen<T>(T);