Skip to content

Stabilize const TypeId::of #144133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions library/core/src/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ unsafe impl Send for TypeId {}
unsafe impl Sync for TypeId {}

#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_type_id", issue = "77125")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
impl const PartialEq for TypeId {
#[inline]
fn eq(&self, other: &Self) -> bool {
Expand Down Expand Up @@ -773,7 +773,7 @@ impl TypeId {
/// ```
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_type_id", issue = "77125")]
#[rustc_const_stable(feature = "const_type_id", since = "CURRENT_RUSTC_VERSION")]
pub const fn of<T: ?Sized + 'static>() -> TypeId {
const { intrinsics::type_id::<T>() }
}
Expand Down
2 changes: 0 additions & 2 deletions tests/mir-opt/gvn_const_eval_polymorphic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
//! evaluated to the string "crate_name::generic::<T>", and
//! `no_optimize` was incorrectly optimized to `false`.
#![feature(const_type_name)]

fn generic<T>() {}

const fn type_name_contains_i32<T>(_: &T) -> bool {
Expand Down
1 change: 0 additions & 1 deletion tests/ui/const-generics/issues/issue-90318.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(const_type_id)]
#![feature(generic_const_exprs)]
#![feature(const_trait_impl, const_cmp)]
#![feature(core_intrinsics)]
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/const-generics/issues/issue-90318.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: overly complex generic constant
--> $DIR/issue-90318.rs:15:8
--> $DIR/issue-90318.rs:14:8
|
LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
| ^^-----------------^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -10,7 +10,7 @@ LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
= note: this operation may be supported in the future

error: overly complex generic constant
--> $DIR/issue-90318.rs:22:8
--> $DIR/issue-90318.rs:21:8
|
LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
| ^^-----------------^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
12 changes: 2 additions & 10 deletions tests/ui/consts/const-fn-type-name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,12 @@ struct Struct<TA, TB, TC> {

type StructInstantiation = Struct<i8, f64, bool>;

const CONST_STRUCT: StructInstantiation = StructInstantiation {
a: 12,
b: 13.7,
c: false,
};
const CONST_STRUCT: StructInstantiation = StructInstantiation { a: 12, b: 13.7, c: false };

const CONST_STRUCT_NAME: &'static str = type_name_wrapper(&CONST_STRUCT);

fn main() {
let non_const_struct = StructInstantiation {
a: 87,
b: 65.99,
c: true,
};
let non_const_struct = StructInstantiation { a: 87, b: 65.99, c: true };

let non_const_struct_name = type_name_wrapper(&non_const_struct);

Expand Down
2 changes: 0 additions & 2 deletions tests/ui/consts/const-typeid-of-rpass.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
//@ run-pass
#![feature(const_type_id)]
#![feature(core_intrinsics)]

use std::any::TypeId;

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/consts/const_cmp_type_id.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ compile-flags: -Znext-solver
#![feature(const_type_id, const_trait_impl, const_cmp)]
#![feature(const_trait_impl, const_cmp)]

use std::any::TypeId;

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/consts/const_transmute_type_id.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(const_type_id, const_trait_impl, const_cmp)]
#![feature(const_trait_impl, const_cmp)]

use std::any::TypeId;

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/consts/const_transmute_type_id2.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ normalize-stderr: "0x(ff)+" -> "<u128::MAX>"

#![feature(const_type_id, const_trait_impl, const_cmp)]
#![feature( const_trait_impl, const_cmp)]

use std::any::TypeId;

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/consts/const_transmute_type_id3.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Test that all bytes of a TypeId must have the
//! TypeId marker provenance.
#![feature(const_type_id, const_trait_impl, const_cmp)]
#![feature( const_trait_impl, const_cmp)]

use std::any::TypeId;

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/consts/const_transmute_type_id4.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(const_type_id, const_trait_impl, const_cmp)]
#![feature(const_trait_impl, const_cmp)]

use std::any::TypeId;

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/consts/const_transmute_type_id5.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Test that we require an equal TypeId to have an integer part that properly
//! reflects the type id hash.
#![feature(const_type_id, const_trait_impl, const_cmp)]
#![feature(const_trait_impl, const_cmp)]

use std::any::TypeId;

Expand Down
2 changes: 0 additions & 2 deletions tests/ui/consts/issue-102117.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(const_type_id)]

use std::alloc::Layout;
use std::any::TypeId;
use std::mem::transmute;
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/consts/issue-102117.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0310]: the parameter type `T` may not live long enough
--> $DIR/issue-102117.rs:19:26
--> $DIR/issue-102117.rs:17:26
|
LL | type_id: TypeId::of::<T>(),
| ^^^^^^^^^^^^^^^^^
Expand All @@ -13,7 +13,7 @@ LL | pub fn new<T: 'static>() -> &'static Self {
| +++++++++

error[E0310]: the parameter type `T` may not live long enough
--> $DIR/issue-102117.rs:19:26
--> $DIR/issue-102117.rs:17:26
|
LL | type_id: TypeId::of::<T>(),
| ^^^^^^^^^^^^^^^^^
Expand Down
1 change: 0 additions & 1 deletion tests/ui/consts/issue-73976-monomorphic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// will be properly rejected. This test will ensure that monomorphic use of these
// would not be wrongly rejected in patterns.

#![feature(const_type_id)]
#![feature(const_type_name)]
#![feature(const_trait_impl)]
#![feature(const_cmp)]
Expand Down
1 change: 0 additions & 1 deletion tests/ui/consts/issue-73976-polymorphic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// This test case should either run-pass or be rejected at compile time.
// Currently we just disallow this usage and require pattern is monomorphic.

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

use std::any::{self, TypeId};
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/consts/issue-73976-polymorphic.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0158]: constant pattern cannot depend on generic parameters
--> $DIR/issue-73976-polymorphic.rs:20:37
--> $DIR/issue-73976-polymorphic.rs:19:37
|
LL | impl<T: 'static> GetTypeId<T> {
| -----------------------------
Expand All @@ -12,7 +12,7 @@ LL | matches!(GetTypeId::<T>::VALUE, GetTypeId::<T>::VALUE)
| ^^^^^^^^^^^^^^^^^^^^^ `const` depends on a generic parameter

error[E0158]: constant pattern cannot depend on generic parameters
--> $DIR/issue-73976-polymorphic.rs:31:42
--> $DIR/issue-73976-polymorphic.rs:30:42
|
LL | impl<T: 'static> GetTypeNameLen<T> {
| ----------------------------------
Expand Down
Loading