1
- use ty:: { self , TypeFoldable } ;
1
+ use ty:: { self , TyCtxt , TypeFoldable } ;
2
2
3
3
use rustc_data_structures:: fx:: FxHashSet ;
4
4
use syntax:: symbol:: InternedString ;
@@ -21,8 +21,8 @@ impl<'tcx> ty::fold::TypeVisitor<'tcx> for LateBoundRegionNameCollector {
21
21
}
22
22
}
23
23
24
- # [ derive ( Debug ) ]
25
- pub struct PrintCx {
24
+ pub struct PrintCx < ' a , ' gcx , ' tcx > {
25
+ pub ( crate ) tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
26
26
pub ( crate ) is_debug : bool ,
27
27
pub ( crate ) is_verbose : bool ,
28
28
pub ( crate ) identify_regions : bool ,
@@ -31,22 +31,21 @@ pub struct PrintCx {
31
31
pub ( crate ) binder_depth : usize ,
32
32
}
33
33
34
- impl PrintCx {
35
- pub ( crate ) fn new ( ) -> Self {
34
+ impl PrintCx < ' a , ' gcx , ' tcx > {
35
+ pub ( crate ) fn with < R > ( f : impl FnOnce ( PrintCx < ' _ , ' _ , ' _ > ) -> R ) -> R {
36
36
ty:: tls:: with ( |tcx| {
37
- let ( is_verbose, identify_regions) =
38
- ( tcx. sess . verbose ( ) , tcx. sess . opts . debugging_opts . identify_regions ) ;
39
- PrintCx {
37
+ f ( PrintCx {
38
+ tcx,
40
39
is_debug : false ,
41
- is_verbose : is_verbose ,
42
- identify_regions : identify_regions,
40
+ is_verbose : tcx . sess . verbose ( ) ,
41
+ identify_regions : tcx . sess . opts . debugging_opts . identify_regions ,
43
42
used_region_names : None ,
44
43
region_index : 0 ,
45
44
binder_depth : 0 ,
46
- }
45
+ } )
47
46
} )
48
47
}
49
- pub ( crate ) fn prepare_late_bound_region_info < ' tcx , T > ( & mut self , value : & ty:: Binder < T > )
48
+ pub ( crate ) fn prepare_late_bound_region_info < T > ( & mut self , value : & ty:: Binder < T > )
50
49
where T : TypeFoldable < ' tcx >
51
50
{
52
51
let mut collector = LateBoundRegionNameCollector ( Default :: default ( ) ) ;
@@ -57,32 +56,32 @@ impl PrintCx {
57
56
}
58
57
59
58
pub trait Print < ' tcx > {
60
- fn print < F : fmt:: Write > ( & self , f : & mut F , cx : & mut PrintCx ) -> fmt:: Result ;
61
- fn print_to_string ( & self , cx : & mut PrintCx ) -> String {
59
+ fn print < F : fmt:: Write > ( & self , f : & mut F , cx : & mut PrintCx < ' _ , ' _ , ' _ > ) -> fmt:: Result ;
60
+ fn print_to_string ( & self , cx : & mut PrintCx < ' _ , ' _ , ' _ > ) -> String {
62
61
let mut result = String :: new ( ) ;
63
62
let _ = self . print ( & mut result, cx) ;
64
63
result
65
64
}
66
- fn print_display < F : fmt:: Write > ( & self , f : & mut F , cx : & mut PrintCx ) -> fmt:: Result {
65
+ fn print_display < F : fmt:: Write > ( & self , f : & mut F , cx : & mut PrintCx < ' _ , ' _ , ' _ > ) -> fmt:: Result {
67
66
let old_debug = cx. is_debug ;
68
67
cx. is_debug = false ;
69
68
let result = self . print ( f, cx) ;
70
69
cx. is_debug = old_debug;
71
70
result
72
71
}
73
- fn print_display_to_string ( & self , cx : & mut PrintCx ) -> String {
72
+ fn print_display_to_string ( & self , cx : & mut PrintCx < ' _ , ' _ , ' _ > ) -> String {
74
73
let mut result = String :: new ( ) ;
75
74
let _ = self . print_display ( & mut result, cx) ;
76
75
result
77
76
}
78
- fn print_debug < F : fmt:: Write > ( & self , f : & mut F , cx : & mut PrintCx ) -> fmt:: Result {
77
+ fn print_debug < F : fmt:: Write > ( & self , f : & mut F , cx : & mut PrintCx < ' _ , ' _ , ' _ > ) -> fmt:: Result {
79
78
let old_debug = cx. is_debug ;
80
79
cx. is_debug = true ;
81
80
let result = self . print ( f, cx) ;
82
81
cx. is_debug = old_debug;
83
82
result
84
83
}
85
- fn print_debug_to_string ( & self , cx : & mut PrintCx ) -> String {
84
+ fn print_debug_to_string ( & self , cx : & mut PrintCx < ' _ , ' _ , ' _ > ) -> String {
86
85
let mut result = String :: new ( ) ;
87
86
let _ = self . print_debug ( & mut result, cx) ;
88
87
result
0 commit comments