Skip to content

TypeId doesn't match itself in generic function. #73976

Closed

Description

I tried this code:
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=57bb53139f14a69326e005ea9d9f7cd7

#![feature(const_type_id)]

use std::any::TypeId;

pub struct GetTypeId<T>(T);

impl<T: 'static> GetTypeId<T> {
    pub const VALUE: TypeId = TypeId::of::<T>();
}

const fn check_type_id<T: 'static>() -> bool {
    matches!(GetTypeId::<T>::VALUE, GetTypeId::<T>::VALUE)
}

fn main() {
    assert!(check_type_id::<usize>());
}

I expected the code to run without errors

Instead, the assertion failed.

Meta

Compiler version: 1.46.0-nightly (2020-07-01 f781bab)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation (MIR interpretation)C-bugCategory: This is a bug.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions