@@ -14,6 +14,7 @@ use rustc_hir::def::DefKind;
14
14
use rustc_middle:: mir;
15
15
use rustc_middle:: mir:: interpret:: { alloc_range, AllocId } ;
16
16
use rustc_middle:: mir:: mono:: MonoItem ;
17
+ use rustc_middle:: ty:: print:: { with_forced_trimmed_paths, with_no_trimmed_paths} ;
17
18
use rustc_middle:: ty:: { self , Instance , ParamEnv , ScalarInt , Ty , TyCtxt , Variance } ;
18
19
use rustc_span:: def_id:: { CrateNum , DefId , LOCAL_CRATE } ;
19
20
use rustc_target:: abi:: FieldIdx ;
@@ -28,7 +29,7 @@ use stable_mir::ty::{
28
29
EarlyParamRegion , FloatTy , FnDef , GenericArgs , GenericParamDef , IntTy , LineInfo , Movability ,
29
30
RigidTy , Span , TyKind , UintTy ,
30
31
} ;
31
- use stable_mir:: { self , opaque, Context , CrateItem , Error , Filename , ItemKind } ;
32
+ use stable_mir:: { self , opaque, Context , Crate , CrateItem , Error , Filename , ItemKind , Symbol } ;
32
33
use std:: cell:: RefCell ;
33
34
use tracing:: debug;
34
35
@@ -61,9 +62,18 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
61
62
crates
62
63
}
63
64
64
- fn name_of_def_id ( & self , def_id : stable_mir:: DefId ) -> String {
65
+ fn def_name ( & self , def_id : stable_mir:: DefId , trimmed : bool ) -> Symbol {
65
66
let tables = self . 0 . borrow ( ) ;
66
- tables. tcx . def_path_str ( tables[ def_id] )
67
+ if trimmed {
68
+ with_forced_trimmed_paths ! ( tables. tcx. def_path_str( tables[ def_id] ) )
69
+ } else {
70
+ with_no_trimmed_paths ! ( tables. tcx. def_path_str( tables[ def_id] ) )
71
+ }
72
+ }
73
+
74
+ fn krate ( & self , def_id : stable_mir:: DefId ) -> Crate {
75
+ let tables = self . 0 . borrow ( ) ;
76
+ smir_crate ( tables. tcx , tables[ def_id] . krate )
67
77
}
68
78
69
79
fn span_to_string ( & self , span : stable_mir:: ty:: Span ) -> String {
@@ -240,12 +250,29 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
240
250
tables. create_def_id ( def_id)
241
251
}
242
252
243
- fn instance_mangled_name ( & self , def : InstanceDef ) -> String {
253
+ fn instance_mangled_name ( & self , instance : InstanceDef ) -> Symbol {
244
254
let tables = self . 0 . borrow_mut ( ) ;
245
- let instance = tables. instances [ def ] ;
255
+ let instance = tables. instances [ instance ] ;
246
256
tables. tcx . symbol_name ( instance) . name . to_string ( )
247
257
}
248
258
259
+ /// Retrieve the instance name for diagnostic messages.
260
+ ///
261
+ /// This will return the specialized name, e.g., `Vec<char>::new`.
262
+ fn instance_name ( & self , def : InstanceDef , trimmed : bool ) -> Symbol {
263
+ let tables = self . 0 . borrow_mut ( ) ;
264
+ let instance = tables. instances [ def] ;
265
+ if trimmed {
266
+ with_forced_trimmed_paths ! (
267
+ tables. tcx. def_path_str_with_args( instance. def_id( ) , instance. args)
268
+ )
269
+ } else {
270
+ with_no_trimmed_paths ! (
271
+ tables. tcx. def_path_str_with_args( instance. def_id( ) , instance. args)
272
+ )
273
+ }
274
+ }
275
+
249
276
fn mono_instance ( & self , item : stable_mir:: CrateItem ) -> stable_mir:: mir:: mono:: Instance {
250
277
let mut tables = self . 0 . borrow_mut ( ) ;
251
278
let def_id = tables[ item. 0 ] ;
0 commit comments