1
- //! Module that implements the public interface to the Stable MIR .
1
+ //! The WIP stable interface to rustc internals .
2
2
//!
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>
5
4
//!
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
+ ) ]
8
13
//!
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.
10
16
//!
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) .
13
19
14
20
use std:: cell:: Cell ;
15
21
use std:: fmt;
@@ -19,6 +25,9 @@ use self::ty::{
19
25
GenericPredicates , Generics , ImplDef , ImplTrait , Span , TraitDecl , TraitDef , Ty , TyKind ,
20
26
} ;
21
27
28
+ #[ macro_use]
29
+ extern crate scoped_tls;
30
+
22
31
pub mod fold;
23
32
pub mod mir;
24
33
pub mod ty;
@@ -32,11 +41,11 @@ pub type CrateNum = usize;
32
41
33
42
/// A unique identification number for each item accessible for the current compilation unit.
34
43
#[ derive( Clone , Copy , PartialEq , Eq ) ]
35
- pub struct DefId ( pub ( crate ) usize ) ;
44
+ pub struct DefId ( pub usize ) ;
36
45
37
46
impl Debug for DefId {
38
47
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
39
- f. debug_struct ( "DefId: " )
48
+ f. debug_struct ( "DefId" )
40
49
. field ( "id" , & self . 0 )
41
50
. field ( "name" , & with ( |cx| cx. name_of_def_id ( * self ) ) )
42
51
. finish ( )
@@ -45,7 +54,7 @@ impl Debug for DefId {
45
54
46
55
/// A unique identification number for each provenance
47
56
#[ derive( Clone , Copy , PartialEq , Eq , Debug ) ]
48
- pub struct AllocId ( pub ( crate ) usize ) ;
57
+ pub struct AllocId ( pub usize ) ;
49
58
50
59
/// A list of crate items.
51
60
pub type CrateItems = Vec < CrateItem > ;
@@ -73,7 +82,7 @@ pub enum CompilerError<T> {
73
82
/// Holds information about a crate.
74
83
#[ derive( Clone , PartialEq , Eq , Debug ) ]
75
84
pub struct Crate {
76
- pub ( crate ) id : CrateNum ,
85
+ pub id : CrateNum ,
77
86
pub name : Symbol ,
78
87
pub is_local : bool ,
79
88
}
@@ -84,7 +93,7 @@ pub type DefKind = Opaque;
84
93
/// For now, it only stores the item DefId. Use functions inside `rustc_internal` module to
85
94
/// use this item.
86
95
#[ derive( Clone , PartialEq , Eq , Debug ) ]
87
- pub struct CrateItem ( pub ( crate ) DefId ) ;
96
+ pub struct CrateItem ( pub DefId ) ;
88
97
89
98
impl CrateItem {
90
99
pub fn body ( & self ) -> mir:: Body {
@@ -170,9 +179,12 @@ pub trait Context {
170
179
/// Prints the name of given `DefId`
171
180
fn name_of_def_id ( & self , def_id : DefId ) -> String ;
172
181
182
+ /// Prints a human readable form of `Span`
173
183
fn print_span ( & self , span : Span ) -> String ;
174
184
185
+ /// Prints the kind of given `DefId`
175
186
fn def_kind ( & mut self , def_id : DefId ) -> DefKind ;
187
+
176
188
/// `Span` of an item
177
189
fn span_of_an_item ( & mut self , def_id : DefId ) -> Span ;
178
190
@@ -200,7 +212,7 @@ pub fn run(mut context: impl Context, f: impl FnOnce()) {
200
212
201
213
/// Loads the current context and calls a function with it.
202
214
/// 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 {
204
216
assert ! ( TLV . is_set( ) ) ;
205
217
TLV . with ( |tlv| {
206
218
let ptr = tlv. get ( ) ;
@@ -225,6 +237,6 @@ impl std::fmt::Debug for Opaque {
225
237
}
226
238
}
227
239
228
- pub ( crate ) fn opaque < T : Debug > ( value : & T ) -> Opaque {
240
+ pub fn opaque < T : Debug > ( value : & T ) -> Opaque {
229
241
Opaque ( format ! ( "{value:?}" ) )
230
242
}
0 commit comments