-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Open
Labels
A-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)C-bugCategory: This is a bug.Category: This is a bug.F-type_info#![feature(type_info)]#![feature(type_info)]T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Description
In the following code, all the assertions pass. The out variable is set to the TypeId of the return type of for<'a> fn(&'a ()) -> &'a (). I don't know what the lifetime of this reference type is. The type seems to have the following properties:
- It implements
RefUnit - It does not implement
IsStatic - It has a different
TypeIdfrom&'static ().
This seems very strange.
#![feature(type_info)]
use std::any::TypeId;
use std::mem::type_info::{Type, TypeKind};
trait RefUnit {}
impl<'a> RefUnit for &'a () {}
trait IsStatic {}
impl<T: 'static> IsStatic for T {}
fn main() {
let out = const {
let x = Type::of::<for<'a> fn(&'a ()) -> &'a ()>();
let TypeKind::FnPtr(fn_ptr) = x.kind else {
panic!()
};
let out: TypeId = fn_ptr.output;
// out is the TypeId of &'????? ()
assert!(out.trait_info_of::<dyn RefUnit>().is_some());
assert!(out.trait_info_of::<dyn IsStatic>().is_none());
assert!(TypeId::of::<&'static ()>().trait_info_of::<dyn IsStatic>().is_some());
out
};
assert!(out != TypeId::of::<&'static ()>());
}Meta
Reproducible on the playground with version 1.95.0-nightly (2026-02-24 859951e3c7c9d0322c39)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)C-bugCategory: This is a bug.Category: This is a bug.F-type_info#![feature(type_info)]#![feature(type_info)]T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.