1
1
//! Miscellaneous type-system utilities that are too small to deserve their own modules.
2
2
3
3
use crate :: middle:: codegen_fn_attrs:: CodegenFnAttrFlags ;
4
- use crate :: mir;
5
4
use crate :: query:: Providers ;
6
5
use crate :: ty:: layout:: IntegerExt ;
7
6
use crate :: ty:: {
@@ -17,7 +16,6 @@ use rustc_hir as hir;
17
16
use rustc_hir:: def:: { CtorOf , DefKind , Res } ;
18
17
use rustc_hir:: def_id:: { CrateNum , DefId , LocalDefId } ;
19
18
use rustc_index:: bit_set:: GrowableBitSet ;
20
- use rustc_index:: { Idx , IndexVec } ;
21
19
use rustc_macros:: HashStable ;
22
20
use rustc_session:: Limit ;
23
21
use rustc_span:: sym;
@@ -738,80 +736,6 @@ impl<'tcx> TyCtxt<'tcx> {
738
736
if visitor. found_recursion { Err ( expanded_type) } else { Ok ( expanded_type) }
739
737
}
740
738
741
- /// Returns names of captured upvars for closures and generators.
742
- ///
743
- /// Here are some examples:
744
- /// - `name__field1__field2` when the upvar is captured by value.
745
- /// - `_ref__name__field` when the upvar is captured by reference.
746
- ///
747
- /// For generators this only contains upvars that are shared by all states.
748
- pub fn closure_saved_names_of_captured_variables (
749
- self ,
750
- def_id : DefId ,
751
- ) -> SmallVec < [ String ; 16 ] > {
752
- let body = self . optimized_mir ( def_id) ;
753
-
754
- body. var_debug_info
755
- . iter ( )
756
- . filter_map ( |var| {
757
- let is_ref = match var. value {
758
- mir:: VarDebugInfoContents :: Place ( place)
759
- if place. local == mir:: Local :: new ( 1 ) =>
760
- {
761
- // The projection is either `[.., Field, Deref]` or `[.., Field]`. It
762
- // implies whether the variable is captured by value or by reference.
763
- matches ! ( place. projection. last( ) . unwrap( ) , mir:: ProjectionElem :: Deref )
764
- }
765
- _ => return None ,
766
- } ;
767
- let prefix = if is_ref { "_ref__" } else { "" } ;
768
- Some ( prefix. to_owned ( ) + var. name . as_str ( ) )
769
- } )
770
- . collect ( )
771
- }
772
-
773
- // FIXME(eddyb) maybe precompute this? Right now it's computed once
774
- // per generator monomorphization, but it doesn't depend on substs.
775
- pub fn generator_layout_and_saved_local_names (
776
- self ,
777
- def_id : DefId ,
778
- ) -> (
779
- & ' tcx ty:: GeneratorLayout < ' tcx > ,
780
- IndexVec < mir:: GeneratorSavedLocal , Option < rustc_span:: Symbol > > ,
781
- ) {
782
- let tcx = self ;
783
- let body = tcx. optimized_mir ( def_id) ;
784
- let generator_layout = body. generator_layout ( ) . unwrap ( ) ;
785
- let mut generator_saved_local_names =
786
- IndexVec :: from_elem ( None , & generator_layout. field_tys ) ;
787
-
788
- let state_arg = mir:: Local :: new ( 1 ) ;
789
- for var in & body. var_debug_info {
790
- let mir:: VarDebugInfoContents :: Place ( place) = & var. value else { continue } ;
791
- if place. local != state_arg {
792
- continue ;
793
- }
794
- match place. projection [ ..] {
795
- [
796
- // Deref of the `Pin<&mut Self>` state argument.
797
- mir:: ProjectionElem :: Field ( ..) ,
798
- mir:: ProjectionElem :: Deref ,
799
- // Field of a variant of the state.
800
- mir:: ProjectionElem :: Downcast ( _, variant) ,
801
- mir:: ProjectionElem :: Field ( field, _) ,
802
- ] => {
803
- let name = & mut generator_saved_local_names
804
- [ generator_layout. variant_fields [ variant] [ field] ] ;
805
- if name. is_none ( ) {
806
- name. replace ( var. name ) ;
807
- }
808
- }
809
- _ => { }
810
- }
811
- }
812
- ( generator_layout, generator_saved_local_names)
813
- }
814
-
815
739
/// Query and get an English description for the item's kind.
816
740
pub fn def_descr ( self , def_id : DefId ) -> & ' static str {
817
741
self . def_kind_descr ( self . def_kind ( def_id) , def_id)
0 commit comments