Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion library/core/src/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,8 @@ impl dyn Any + Send + Sync {
/// While `TypeId` implements `Hash`, `PartialOrd`, and `Ord`, it is worth
/// noting that the hashes and ordering will vary between Rust releases. Beware
/// of relying on them inside of your code!
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
#[derive(Clone, Copy, Debug, Hash, Eq)]
#[derive_const(PartialEq, PartialOrd, Ord)]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct TypeId {
t: u64,
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/const-generics/issues/issue-90318.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
}

Expand Down
33 changes: 14 additions & 19 deletions tests/ui/const-generics/issues/issue-90318.stderr
Original file line number Diff line number Diff line change
@@ -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`.
12 changes: 12 additions & 0 deletions tests/ui/consts/const_cmp_type_id.rs
Original file line number Diff line number Diff line change
@@ -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
}
3 changes: 2 additions & 1 deletion tests/ui/consts/issue-73976-monomorphic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#![feature(const_type_id)]
#![feature(const_type_name)]
#![feature(const_trait_impl)]

use std::any::{self, TypeId};

Expand All @@ -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);
Expand Down