1- //! Module that implements the public interface to the Stable MIR .
1+ //! The WIP stable interface to rustc internals .
22//!
3- //! This module shall contain all type definitions and APIs that we expect third-party tools to invoke to
4- //! interact with the compiler.
3+ //! For more information see <https://github.com/rust-lang/project-stable-mir>
54//!
6- //! The goal is to eventually move this module to its own crate which shall be published on
7- //! [crates.io](https://crates.io).
5+ //! # Note
6+ //!
7+ //! This API is still completely unstable and subject to change.
8+
9+ #![ doc(
10+ html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/" ,
11+ test( attr( allow( unused_variables) , deny( warnings) ) )
12+ ) ]
813//!
9- //! ## Note:
14+ //! This crate shall contain all type definitions and APIs that we expect third-party tools to invoke to
15+ //! interact with the compiler.
1016//!
11- //! There shouldn't be any direct references to internal compiler constructs in this module.
12- //! If you need an internal construct, consider using `rustc_internal` or `rustc_smir` .
17+ //! The goal is to eventually be published on
18+ //! [crates.io](https://crates.io) .
1319
1420use std:: cell:: Cell ;
1521use std:: fmt;
@@ -19,6 +25,9 @@ use self::ty::{
1925 GenericPredicates , Generics , ImplDef , ImplTrait , Span , TraitDecl , TraitDef , Ty , TyKind ,
2026} ;
2127
28+ #[ macro_use]
29+ extern crate scoped_tls;
30+
2231pub mod fold;
2332pub mod mir;
2433pub mod ty;
@@ -32,11 +41,11 @@ pub type CrateNum = usize;
3241
3342/// A unique identification number for each item accessible for the current compilation unit.
3443#[ derive( Clone , Copy , PartialEq , Eq ) ]
35- pub struct DefId ( pub ( crate ) usize ) ;
44+ pub struct DefId ( pub usize ) ;
3645
3746impl Debug for DefId {
3847 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
39- f. debug_struct ( "DefId: " )
48+ f. debug_struct ( "DefId" )
4049 . field ( "id" , & self . 0 )
4150 . field ( "name" , & with ( |cx| cx. name_of_def_id ( * self ) ) )
4251 . finish ( )
@@ -45,7 +54,7 @@ impl Debug for DefId {
4554
4655/// A unique identification number for each provenance
4756#[ derive( Clone , Copy , PartialEq , Eq , Debug ) ]
48- pub struct AllocId ( pub ( crate ) usize ) ;
57+ pub struct AllocId ( pub usize ) ;
4958
5059/// A list of crate items.
5160pub type CrateItems = Vec < CrateItem > ;
@@ -73,7 +82,7 @@ pub enum CompilerError<T> {
7382/// Holds information about a crate.
7483#[ derive( Clone , PartialEq , Eq , Debug ) ]
7584pub struct Crate {
76- pub ( crate ) id : CrateNum ,
85+ pub id : CrateNum ,
7786 pub name : Symbol ,
7887 pub is_local : bool ,
7988}
@@ -84,7 +93,7 @@ pub type DefKind = Opaque;
8493/// For now, it only stores the item DefId. Use functions inside `rustc_internal` module to
8594/// use this item.
8695#[ derive( Clone , PartialEq , Eq , Debug ) ]
87- pub struct CrateItem ( pub ( crate ) DefId ) ;
96+ pub struct CrateItem ( pub DefId ) ;
8897
8998impl CrateItem {
9099 pub fn body ( & self ) -> mir:: Body {
@@ -170,9 +179,12 @@ pub trait Context {
170179 /// Prints the name of given `DefId`
171180 fn name_of_def_id ( & self , def_id : DefId ) -> String ;
172181
182+ /// Prints a human readable form of `Span`
173183 fn print_span ( & self , span : Span ) -> String ;
174184
185+ /// Prints the kind of given `DefId`
175186 fn def_kind ( & mut self , def_id : DefId ) -> DefKind ;
187+
176188 /// `Span` of an item
177189 fn span_of_an_item ( & mut self , def_id : DefId ) -> Span ;
178190
@@ -200,7 +212,7 @@ pub fn run(mut context: impl Context, f: impl FnOnce()) {
200212
201213/// Loads the current context and calls a function with it.
202214/// Do not nest these, as that will ICE.
203- pub ( crate ) fn with < R > ( f : impl FnOnce ( & mut dyn Context ) -> R ) -> R {
215+ pub fn with < R > ( f : impl FnOnce ( & mut dyn Context ) -> R ) -> R {
204216 assert ! ( TLV . is_set( ) ) ;
205217 TLV . with ( |tlv| {
206218 let ptr = tlv. get ( ) ;
@@ -225,6 +237,6 @@ impl std::fmt::Debug for Opaque {
225237 }
226238}
227239
228- pub ( crate ) fn opaque < T : Debug > ( value : & T ) -> Opaque {
240+ pub fn opaque < T : Debug > ( value : & T ) -> Opaque {
229241 Opaque ( format ! ( "{value:?}" ) )
230242}
0 commit comments