@@ -14,6 +14,7 @@ use rustc_hir::def::DefKind;
1414use  rustc_middle:: mir; 
1515use  rustc_middle:: mir:: interpret:: { alloc_range,  AllocId } ; 
1616use  rustc_middle:: mir:: mono:: MonoItem ; 
17+ use  rustc_middle:: ty:: print:: { with_forced_trimmed_paths,  with_no_trimmed_paths} ; 
1718use  rustc_middle:: ty:: { self ,  Instance ,  ParamEnv ,  ScalarInt ,  Ty ,  TyCtxt ,  Variance } ; 
1819use  rustc_span:: def_id:: { CrateNum ,  DefId ,  LOCAL_CRATE } ; 
1920use  rustc_target:: abi:: FieldIdx ; 
@@ -28,7 +29,7 @@ use stable_mir::ty::{
2829    EarlyParamRegion ,  FloatTy ,  FnDef ,  GenericArgs ,  GenericParamDef ,  IntTy ,  LineInfo ,  Movability , 
2930    RigidTy ,  Span ,  TyKind ,  UintTy , 
3031} ; 
31- use  stable_mir:: { self ,  opaque,  Context ,  CrateItem ,  Error ,  Filename ,  ItemKind } ; 
32+ use  stable_mir:: { self ,  opaque,  Context ,  Crate ,   CrateItem ,  Error ,  Filename ,  ItemKind ,   Symbol } ; 
3233use  std:: cell:: RefCell ; 
3334use  tracing:: debug; 
3435
@@ -61,9 +62,18 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
6162        crates
6263    } 
6364
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  { 
6566        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 ) 
6777    } 
6878
6979    fn  span_to_string ( & self ,  span :  stable_mir:: ty:: Span )  -> String  { 
@@ -240,12 +250,29 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
240250        tables. create_def_id ( def_id) 
241251    } 
242252
243-     fn  instance_mangled_name ( & self ,  def :  InstanceDef )  -> String  { 
253+     fn  instance_mangled_name ( & self ,  instance :  InstanceDef )  -> Symbol  { 
244254        let  tables = self . 0 . borrow_mut ( ) ; 
245-         let  instance = tables. instances [ def ] ; 
255+         let  instance = tables. instances [ instance ] ; 
246256        tables. tcx . symbol_name ( instance) . name . to_string ( ) 
247257    } 
248258
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+ 
249276    fn  mono_instance ( & self ,  item :  stable_mir:: CrateItem )  -> stable_mir:: mir:: mono:: Instance  { 
250277        let  mut  tables = self . 0 . borrow_mut ( ) ; 
251278        let  def_id = tables[ item. 0 ] ; 
0 commit comments