Skip to main content

rustc_public/
lib.rs

1//! The WIP public interface to rustc internals.
2//!
3//! For more information see <https://github.com/rust-lang/project-stable-mir>
4//!
5//! # Note
6//!
7//! This API is still completely unstable and subject to change.
8
9#![allow(rustc::usage_of_ty_tykind)]
10#![doc(test(attr(allow(unused_variables), deny(warnings), allow(internal_features))))]
11#![feature(sized_hierarchy)]
12//!
13//! This crate shall contain all type definitions and APIs that we expect third-party tools to invoke to
14//! interact with the compiler.
15//!
16//! The goal is to eventually be published on
17//! [crates.io](https://crates.io).
18
19use std::fmt::Debug;
20use std::marker::PhantomData;
21use std::{fmt, io};
22
23pub(crate) use rustc_public_bridge::IndexedVal;
24use rustc_public_bridge::Tables;
25use rustc_public_bridge::context::CompilerCtxt;
26/// Export the rustc_internal APIs. Note that this module has no stability
27/// guarantees and it is not taken into account for semver.
28#[cfg(feature = "rustc_internal")]
29pub mod rustc_internal;
30use serde::Serialize;
31
32use crate::compiler_interface::with;
33pub use crate::crate_def::{CrateDef, CrateDefItems, CrateDefType, DefId};
34pub use crate::error::*;
35use crate::mir::mono::StaticDef;
36use crate::mir::{Body, Mutability};
37use crate::ty::{
38    AssocItem, FnDef, ForeignModuleDef, ImplDef, ProvenanceMap, Span, TraitDef, Ty,
39    serialize_index_impl,
40};
41use crate::unstable::Stable;
42
43pub mod abi;
44mod alloc;
45pub(crate) mod unstable;
46#[macro_use]
47pub mod crate_def;
48pub mod compiler_interface;
49#[macro_use]
50pub mod error;
51pub mod mir;
52pub mod target;
53#[cfg(test)]
54mod tests;
55pub mod ty;
56pub mod visitor;
57
58/// Use String for now but we should replace it.
59pub type Symbol = String;
60
61/// The number that identifies a crate.
62#[derive(#[automatically_derived]
impl ::core::clone::Clone for CrateNum {
    #[inline]
    fn clone(&self) -> CrateNum {
        let _: ::core::clone::AssertParamIsClone<usize>;
        let _: ::core::clone::AssertParamIsClone<ThreadLocalIndex>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for CrateNum { }Copy, #[automatically_derived]
impl ::core::cmp::PartialEq for CrateNum {
    #[inline]
    fn eq(&self, other: &CrateNum) -> bool {
        self.0 == other.0 && self.1 == other.1
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for CrateNum {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_receiver_is_total_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<usize>;
        let _: ::core::cmp::AssertParamIsEq<ThreadLocalIndex>;
    }
}Eq, #[automatically_derived]
impl ::core::fmt::Debug for CrateNum {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_tuple_field2_finish(f, "CrateNum",
            &self.0, &&self.1)
    }
}Debug)]
63pub struct CrateNum(pub(crate) usize, ThreadLocalIndex);
64impl ::serde::Serialize for CrateNum {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where
        S: ::serde::Serializer {
        let n: usize = self.0;
        ::serde::Serialize::serialize(&n, serializer)
    }
}serialize_index_impl!(CrateNum);
65
66impl Debug for DefId {
67    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
68        f.debug_struct("DefId").field("id", &self.0).field("name", &self.name()).finish()
69    }
70}
71
72/// A list of crate items.
73pub type CrateItems = Vec<CrateItem>;
74
75/// A list of trait decls.
76pub type TraitDecls = Vec<TraitDef>;
77
78/// A list of impl trait decls.
79pub type ImplTraitDecls = Vec<ImplDef>;
80
81/// A list of associated items.
82pub type AssocItems = Vec<AssocItem>;
83
84/// Holds information about a crate.
85#[derive(#[automatically_derived]
impl ::core::clone::Clone for Crate {
    #[inline]
    fn clone(&self) -> Crate {
        Crate {
            id: ::core::clone::Clone::clone(&self.id),
            name: ::core::clone::Clone::clone(&self.name),
            is_local: ::core::clone::Clone::clone(&self.is_local),
        }
    }
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for Crate {
    #[inline]
    fn eq(&self, other: &Crate) -> bool {
        self.is_local == other.is_local && self.id == other.id &&
            self.name == other.name
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for Crate {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_receiver_is_total_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<CrateNum>;
        let _: ::core::cmp::AssertParamIsEq<Symbol>;
        let _: ::core::cmp::AssertParamIsEq<bool>;
    }
}Eq, #[automatically_derived]
impl ::core::fmt::Debug for Crate {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field3_finish(f, "Crate", "id",
            &self.id, "name", &self.name, "is_local", &&self.is_local)
    }
}Debug, #[doc(hidden)]
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications,
clippy :: absolute_paths,)]
const _: () =
    {
        #[allow(unused_extern_crates, clippy :: useless_attribute)]
        extern crate serde as _serde;
        ;
        #[automatically_derived]
        impl _serde::Serialize for Crate {
            fn serialize<__S>(&self, __serializer: __S)
                -> _serde::__private228::Result<__S::Ok, __S::Error> where
                __S: _serde::Serializer {
                let mut __serde_state =
                    _serde::Serializer::serialize_struct(__serializer, "Crate",
                            false as usize + 1 + 1 + 1)?;
                _serde::ser::SerializeStruct::serialize_field(&mut __serde_state,
                        "id", &self.id)?;
                _serde::ser::SerializeStruct::serialize_field(&mut __serde_state,
                        "name", &self.name)?;
                _serde::ser::SerializeStruct::serialize_field(&mut __serde_state,
                        "is_local", &self.is_local)?;
                _serde::ser::SerializeStruct::end(__serde_state)
            }
        }
    };Serialize)]
86pub struct Crate {
87    pub id: CrateNum,
88    pub name: Symbol,
89    pub is_local: bool,
90}
91
92impl Crate {
93    /// The list of foreign modules in this crate.
94    pub fn foreign_modules(&self) -> Vec<ForeignModuleDef> {
95        with(|cx| cx.foreign_modules(self.id))
96    }
97
98    /// The list of traits declared in this crate.
99    pub fn trait_decls(&self) -> TraitDecls {
100        with(|cx| cx.trait_decls(self.id))
101    }
102
103    /// The list of trait implementations in this crate.
104    pub fn trait_impls(&self) -> ImplTraitDecls {
105        with(|cx| cx.trait_impls(self.id))
106    }
107
108    /// Return a list of function definitions from this crate independent on their visibility.
109    pub fn fn_defs(&self) -> Vec<FnDef> {
110        with(|cx| cx.crate_functions(self.id))
111    }
112
113    /// Return a list of static items defined in this crate independent on their visibility.
114    pub fn statics(&self) -> Vec<StaticDef> {
115        with(|cx| cx.crate_statics(self.id))
116    }
117}
118
119#[derive(#[automatically_derived]
impl ::core::marker::Copy for ItemKind { }Copy, #[automatically_derived]
impl ::core::clone::Clone for ItemKind {
    #[inline]
    fn clone(&self) -> ItemKind {
        let _: ::core::clone::AssertParamIsClone<CtorKind>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for ItemKind {
    #[inline]
    fn eq(&self, other: &ItemKind) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr &&
            match (self, other) {
                (ItemKind::Ctor(__self_0), ItemKind::Ctor(__arg1_0)) =>
                    __self_0 == __arg1_0,
                _ => true,
            }
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for ItemKind {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_receiver_is_total_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<CtorKind>;
    }
}Eq, #[automatically_derived]
impl ::core::fmt::Debug for ItemKind {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            ItemKind::Fn => ::core::fmt::Formatter::write_str(f, "Fn"),
            ItemKind::Static =>
                ::core::fmt::Formatter::write_str(f, "Static"),
            ItemKind::Const => ::core::fmt::Formatter::write_str(f, "Const"),
            ItemKind::Ctor(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Ctor",
                    &__self_0),
        }
    }
}Debug, #[automatically_derived]
impl ::core::hash::Hash for ItemKind {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        ::core::hash::Hash::hash(&__self_discr, state);
        match self {
            ItemKind::Ctor(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            _ => {}
        }
    }
}Hash, #[doc(hidden)]
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications,
clippy :: absolute_paths,)]
const _: () =
    {
        #[allow(unused_extern_crates, clippy :: useless_attribute)]
        extern crate serde as _serde;
        ;
        #[automatically_derived]
        impl _serde::Serialize for ItemKind {
            fn serialize<__S>(&self, __serializer: __S)
                -> _serde::__private228::Result<__S::Ok, __S::Error> where
                __S: _serde::Serializer {
                match *self {
                    ItemKind::Fn =>
                        _serde::Serializer::serialize_unit_variant(__serializer,
                            "ItemKind", 0u32, "Fn"),
                    ItemKind::Static =>
                        _serde::Serializer::serialize_unit_variant(__serializer,
                            "ItemKind", 1u32, "Static"),
                    ItemKind::Const =>
                        _serde::Serializer::serialize_unit_variant(__serializer,
                            "ItemKind", 2u32, "Const"),
                    ItemKind::Ctor(ref __field0) =>
                        _serde::Serializer::serialize_newtype_variant(__serializer,
                            "ItemKind", 3u32, "Ctor", __field0),
                }
            }
        }
    };Serialize)]
120pub enum ItemKind {
121    Fn,
122    Static,
123    Const,
124    Ctor(CtorKind),
125}
126
127#[derive(#[automatically_derived]
impl ::core::marker::Copy for CtorKind { }Copy, #[automatically_derived]
impl ::core::clone::Clone for CtorKind {
    #[inline]
    fn clone(&self) -> CtorKind { *self }
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for CtorKind {
    #[inline]
    fn eq(&self, other: &CtorKind) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for CtorKind {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_receiver_is_total_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::fmt::Debug for CtorKind {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f,
            match self { CtorKind::Const => "Const", CtorKind::Fn => "Fn", })
    }
}Debug, #[automatically_derived]
impl ::core::hash::Hash for CtorKind {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        ::core::hash::Hash::hash(&__self_discr, state)
    }
}Hash, #[doc(hidden)]
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications,
clippy :: absolute_paths,)]
const _: () =
    {
        #[allow(unused_extern_crates, clippy :: useless_attribute)]
        extern crate serde as _serde;
        ;
        #[automatically_derived]
        impl _serde::Serialize for CtorKind {
            fn serialize<__S>(&self, __serializer: __S)
                -> _serde::__private228::Result<__S::Ok, __S::Error> where
                __S: _serde::Serializer {
                match *self {
                    CtorKind::Const =>
                        _serde::Serializer::serialize_unit_variant(__serializer,
                            "CtorKind", 0u32, "Const"),
                    CtorKind::Fn =>
                        _serde::Serializer::serialize_unit_variant(__serializer,
                            "CtorKind", 1u32, "Fn"),
                }
            }
        }
    };Serialize)]
128pub enum CtorKind {
129    Const,
130    Fn,
131}
132
133pub type Filename = String;
134
135#[automatically_derived]
impl ::core::clone::Clone for CrateItem {
    #[inline]
    fn clone(&self) -> CrateItem {
        let _: ::core::clone::AssertParamIsClone<DefId>;
        *self
    }
}
#[automatically_derived]
impl ::core::marker::Copy for CrateItem { }
#[automatically_derived]
impl ::core::marker::StructuralPartialEq for CrateItem { }
#[automatically_derived]
impl ::core::cmp::PartialEq for CrateItem {
    #[inline]
    fn eq(&self, other: &CrateItem) -> bool { self.0 == other.0 }
}
#[automatically_derived]
impl ::core::cmp::Eq for CrateItem {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_receiver_is_total_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<DefId>;
    }
}
#[automatically_derived]
impl ::core::fmt::Debug for CrateItem {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_tuple_field1_finish(f, "CrateItem",
            &&self.0)
    }
}
#[automatically_derived]
impl ::core::hash::Hash for CrateItem {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        ::core::hash::Hash::hash(&self.0, state)
    }
}
#[doc(hidden)]
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications,
clippy :: absolute_paths,)]
const _: () =
    {
        #[allow(unused_extern_crates, clippy :: useless_attribute)]
        extern crate serde as _serde;
        ;
        #[automatically_derived]
        impl _serde::Serialize for CrateItem {
            fn serialize<__S>(&self, __serializer: __S)
                -> _serde::__private228::Result<__S::Ok, __S::Error> where
                __S: _serde::Serializer {
                _serde::Serializer::serialize_newtype_struct(__serializer,
                    "CrateItem", &self.0)
            }
        }
    };
impl CrateDef for CrateItem {
    fn def_id(&self) -> DefId { self.0 }
}
impl CrateDefType for CrateItem {}crate_def_with_ty! {
136    /// Holds information about an item in a crate.
137    #[derive(Serialize)]
138    pub CrateItem;
139}
140
141impl CrateItem {
142    /// This will return the body of an item or panic if it's not available.
143    pub fn expect_body(&self) -> mir::Body {
144        with(|cx| cx.mir_body(self.0))
145    }
146
147    /// Return the body of an item if available.
148    pub fn body(&self) -> Option<mir::Body> {
149        with(|cx| cx.has_body(self.0).then(|| cx.mir_body(self.0)))
150    }
151
152    /// Check if a body is available for this item.
153    pub fn has_body(&self) -> bool {
154        with(|cx| cx.has_body(self.0))
155    }
156
157    pub fn span(&self) -> Span {
158        with(|cx| cx.span_of_an_item(self.0))
159    }
160
161    pub fn kind(&self) -> ItemKind {
162        with(|cx| cx.item_kind(*self))
163    }
164
165    pub fn requires_monomorphization(&self) -> bool {
166        with(|cx| cx.requires_monomorphization(self.0))
167    }
168
169    pub fn ty(&self) -> Ty {
170        with(|cx| cx.def_ty(self.0))
171    }
172
173    pub fn is_foreign_item(&self) -> bool {
174        with(|cx| cx.is_foreign_item(self.0))
175    }
176
177    /// Emit MIR for this item body.
178    pub fn emit_mir<W: io::Write>(&self, w: &mut W) -> io::Result<()> {
179        self.body()
180            .ok_or_else(|| io::Error::other(::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("No body found for `{0}`",
                self.name()))
    })format!("No body found for `{}`", self.name())))?
181            .dump(w, &self.trimmed_name())
182    }
183}
184
185/// Return the function where execution starts if the current
186/// crate defines that. This is usually `main`, but could be
187/// `start` if the crate is a no-std crate.
188pub fn entry_fn() -> Option<CrateItem> {
189    with(|cx| cx.entry_fn())
190}
191
192/// Access to the local crate.
193pub fn local_crate() -> Crate {
194    with(|cx| cx.local_crate())
195}
196
197/// Try to find a crate or crates if multiple crates exist from given name.
198pub fn find_crates(name: &str) -> Vec<Crate> {
199    with(|cx| cx.find_crates(name))
200}
201
202/// Try to find a crate with the given name.
203pub fn external_crates() -> Vec<Crate> {
204    with(|cx| cx.external_crates())
205}
206
207/// Retrieve all items in the local crate that have a MIR associated with them.
208pub fn all_local_items() -> CrateItems {
209    with(|cx| cx.all_local_items())
210}
211
212pub fn all_trait_decls() -> TraitDecls {
213    with(|cx| cx.all_trait_decls())
214}
215
216pub fn all_trait_impls() -> ImplTraitDecls {
217    with(|cx| cx.all_trait_impls())
218}
219
220/// A type that provides internal information but that can still be used for debug purpose.
221#[derive(#[automatically_derived]
impl ::core::clone::Clone for Opaque {
    #[inline]
    fn clone(&self) -> Opaque { Opaque(::core::clone::Clone::clone(&self.0)) }
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for Opaque {
    #[inline]
    fn eq(&self, other: &Opaque) -> bool { self.0 == other.0 }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for Opaque {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_receiver_is_total_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<String>;
    }
}Eq, #[automatically_derived]
impl ::core::hash::Hash for Opaque {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        ::core::hash::Hash::hash(&self.0, state)
    }
}Hash, #[doc(hidden)]
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications,
clippy :: absolute_paths,)]
const _: () =
    {
        #[allow(unused_extern_crates, clippy :: useless_attribute)]
        extern crate serde as _serde;
        ;
        #[automatically_derived]
        impl _serde::Serialize for Opaque {
            fn serialize<__S>(&self, __serializer: __S)
                -> _serde::__private228::Result<__S::Ok, __S::Error> where
                __S: _serde::Serializer {
                _serde::Serializer::serialize_newtype_struct(__serializer,
                    "Opaque", &self.0)
            }
        }
    };Serialize)]
222pub struct Opaque(String);
223
224impl std::fmt::Display for Opaque {
225    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
226        f.write_fmt(format_args!("{0}", self.0))write!(f, "{}", self.0)
227    }
228}
229
230impl std::fmt::Debug for Opaque {
231    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
232        f.write_fmt(format_args!("{0}", self.0))write!(f, "{}", self.0)
233    }
234}
235
236pub fn opaque<T: Debug>(value: &T) -> Opaque {
237    Opaque(::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("{0:?}", value))
    })format!("{value:?}"))
238}
239
240macro_rules! bridge_impl {
241    ($name: ident, $ty: ty) => {
242        impl rustc_public_bridge::bridge::$name<compiler_interface::BridgeTys> for $ty {
243            fn new(def: crate::DefId) -> Self {
244                Self(def)
245            }
246        }
247    };
248}
249
250impl rustc_public_bridge::bridge::CrateItem<compiler_interface::BridgeTys> for
    crate::CrateItem {
    fn new(def: crate::DefId) -> Self { Self(def) }
}bridge_impl!(CrateItem, crate::CrateItem);
251impl rustc_public_bridge::bridge::AdtDef<compiler_interface::BridgeTys> for
    crate::ty::AdtDef {
    fn new(def: crate::DefId) -> Self { Self(def) }
}bridge_impl!(AdtDef, crate::ty::AdtDef);
252impl rustc_public_bridge::bridge::ForeignModuleDef<compiler_interface::BridgeTys>
    for crate::ty::ForeignModuleDef {
    fn new(def: crate::DefId) -> Self { Self(def) }
}bridge_impl!(ForeignModuleDef, crate::ty::ForeignModuleDef);
253impl rustc_public_bridge::bridge::ForeignDef<compiler_interface::BridgeTys>
    for crate::ty::ForeignDef {
    fn new(def: crate::DefId) -> Self { Self(def) }
}bridge_impl!(ForeignDef, crate::ty::ForeignDef);
254impl rustc_public_bridge::bridge::FnDef<compiler_interface::BridgeTys> for
    crate::ty::FnDef {
    fn new(def: crate::DefId) -> Self { Self(def) }
}bridge_impl!(FnDef, crate::ty::FnDef);
255impl rustc_public_bridge::bridge::ClosureDef<compiler_interface::BridgeTys>
    for crate::ty::ClosureDef {
    fn new(def: crate::DefId) -> Self { Self(def) }
}bridge_impl!(ClosureDef, crate::ty::ClosureDef);
256impl rustc_public_bridge::bridge::CoroutineDef<compiler_interface::BridgeTys>
    for crate::ty::CoroutineDef {
    fn new(def: crate::DefId) -> Self { Self(def) }
}bridge_impl!(CoroutineDef, crate::ty::CoroutineDef);
257impl rustc_public_bridge::bridge::CoroutineClosureDef<compiler_interface::BridgeTys>
    for crate::ty::CoroutineClosureDef {
    fn new(def: crate::DefId) -> Self { Self(def) }
}bridge_impl!(CoroutineClosureDef, crate::ty::CoroutineClosureDef);
258impl rustc_public_bridge::bridge::AliasDef<compiler_interface::BridgeTys> for
    crate::ty::AliasDef {
    fn new(def: crate::DefId) -> Self { Self(def) }
}bridge_impl!(AliasDef, crate::ty::AliasDef);
259impl rustc_public_bridge::bridge::ParamDef<compiler_interface::BridgeTys> for
    crate::ty::ParamDef {
    fn new(def: crate::DefId) -> Self { Self(def) }
}bridge_impl!(ParamDef, crate::ty::ParamDef);
260impl rustc_public_bridge::bridge::BrNamedDef<compiler_interface::BridgeTys>
    for crate::ty::BrNamedDef {
    fn new(def: crate::DefId) -> Self { Self(def) }
}bridge_impl!(BrNamedDef, crate::ty::BrNamedDef);
261impl rustc_public_bridge::bridge::TraitDef<compiler_interface::BridgeTys> for
    crate::ty::TraitDef {
    fn new(def: crate::DefId) -> Self { Self(def) }
}bridge_impl!(TraitDef, crate::ty::TraitDef);
262impl rustc_public_bridge::bridge::GenericDef<compiler_interface::BridgeTys>
    for crate::ty::GenericDef {
    fn new(def: crate::DefId) -> Self { Self(def) }
}bridge_impl!(GenericDef, crate::ty::GenericDef);
263impl rustc_public_bridge::bridge::ConstDef<compiler_interface::BridgeTys> for
    crate::ty::ConstDef {
    fn new(def: crate::DefId) -> Self { Self(def) }
}bridge_impl!(ConstDef, crate::ty::ConstDef);
264impl rustc_public_bridge::bridge::ImplDef<compiler_interface::BridgeTys> for
    crate::ty::ImplDef {
    fn new(def: crate::DefId) -> Self { Self(def) }
}bridge_impl!(ImplDef, crate::ty::ImplDef);
265impl rustc_public_bridge::bridge::RegionDef<compiler_interface::BridgeTys> for
    crate::ty::RegionDef {
    fn new(def: crate::DefId) -> Self { Self(def) }
}bridge_impl!(RegionDef, crate::ty::RegionDef);
266impl rustc_public_bridge::bridge::CoroutineWitnessDef<compiler_interface::BridgeTys>
    for crate::ty::CoroutineWitnessDef {
    fn new(def: crate::DefId) -> Self { Self(def) }
}bridge_impl!(CoroutineWitnessDef, crate::ty::CoroutineWitnessDef);
267impl rustc_public_bridge::bridge::AssocDef<compiler_interface::BridgeTys> for
    crate::ty::AssocDef {
    fn new(def: crate::DefId) -> Self { Self(def) }
}bridge_impl!(AssocDef, crate::ty::AssocDef);
268impl rustc_public_bridge::bridge::OpaqueDef<compiler_interface::BridgeTys> for
    crate::ty::OpaqueDef {
    fn new(def: crate::DefId) -> Self { Self(def) }
}bridge_impl!(OpaqueDef, crate::ty::OpaqueDef);
269impl rustc_public_bridge::bridge::StaticDef<compiler_interface::BridgeTys> for
    crate::mir::mono::StaticDef {
    fn new(def: crate::DefId) -> Self { Self(def) }
}bridge_impl!(StaticDef, crate::mir::mono::StaticDef);
270
271impl rustc_public_bridge::bridge::Prov<compiler_interface::BridgeTys> for crate::ty::Prov {
272    fn new(aid: crate::mir::alloc::AllocId) -> Self {
273        Self(aid)
274    }
275}
276
277impl rustc_public_bridge::bridge::Allocation<compiler_interface::BridgeTys>
278    for crate::ty::Allocation
279{
280    fn new<'tcx>(
281        bytes: Vec<Option<u8>>,
282        ptrs: Vec<(usize, rustc_middle::mir::interpret::AllocId)>,
283        align: u64,
284        mutability: rustc_middle::mir::Mutability,
285        tables: &mut Tables<'tcx, compiler_interface::BridgeTys>,
286        cx: &CompilerCtxt<'tcx, compiler_interface::BridgeTys>,
287    ) -> Self {
288        Self {
289            bytes,
290            provenance: ProvenanceMap {
291                ptrs: ptrs.iter().map(|(i, aid)| (*i, tables.prov(*aid))).collect(),
292            },
293            align,
294            mutability: mutability.stable(tables, cx),
295        }
296    }
297}
298
299#[derive(#[automatically_derived]
impl ::core::clone::Clone for ThreadLocalIndex {
    #[inline]
    fn clone(&self) -> ThreadLocalIndex {
        let _: ::core::clone::AssertParamIsClone<PhantomData<*const ()>>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for ThreadLocalIndex { }Copy, #[automatically_derived]
impl ::core::hash::Hash for ThreadLocalIndex {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        ::core::hash::Hash::hash(&self._phantom, state)
    }
}Hash, #[automatically_derived]
impl ::core::cmp::PartialEq for ThreadLocalIndex {
    #[inline]
    fn eq(&self, other: &ThreadLocalIndex) -> bool {
        self._phantom == other._phantom
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for ThreadLocalIndex {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_receiver_is_total_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<PhantomData<*const ()>>;
    }
}Eq, #[automatically_derived]
impl ::core::default::Default for ThreadLocalIndex {
    #[inline]
    fn default() -> ThreadLocalIndex {
        ThreadLocalIndex { _phantom: ::core::default::Default::default() }
    }
}Default)]
300/// Marker type for indexes into thread local structures.
301///
302/// Makes things `!Send`/`!Sync`, so users don't move `rustc_public` types to
303/// thread with no (or worse, different) `rustc_public` pointer.
304///
305/// Note. This doesn't make it impossible to confuse TLS. You could return a
306/// `DefId` from one `run!` invocation, and then use it inside a different
307/// `run!` invocation with different tables.
308pub(crate) struct ThreadLocalIndex {
309    _phantom: PhantomData<*const ()>,
310}
311#[expect(non_upper_case_globals)]
312/// Emulating unit struct `struct ThreadLocalIndex`;
313pub(crate) const ThreadLocalIndex: ThreadLocalIndex = ThreadLocalIndex { _phantom: PhantomData };
314
315impl fmt::Debug for ThreadLocalIndex {
316    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
317        f.debug_tuple("ThreadLocalIndex").finish()
318    }
319}