@@ -11,7 +11,6 @@ use rustc::hir::def_id::DefId;
11
11
use rustc:: hir:: intravisit:: { Visitor , NestedVisitorMap } ;
12
12
use rustc:: hir:: map:: Map ;
13
13
use rustc:: hir;
14
- use rustc:: session:: Session ;
15
14
use rustc:: ty:: TyCtxt ;
16
15
use rustc:: ty:: query:: Providers ;
17
16
use syntax:: ast:: Mutability ;
@@ -75,31 +74,29 @@ pub(crate) fn provide(providers: &mut Providers<'_>) {
75
74
76
75
#[ derive( Copy , Clone ) ]
77
76
struct CheckConstVisitor < ' tcx > {
78
- sess : & ' tcx Session ,
79
- hir_map : & ' tcx Map < ' tcx > ,
77
+ tcx : TyCtxt < ' tcx > ,
80
78
const_kind : Option < ConstKind > ,
81
79
}
82
80
83
81
impl < ' tcx > CheckConstVisitor < ' tcx > {
84
82
fn new ( tcx : TyCtxt < ' tcx > ) -> Self {
85
83
CheckConstVisitor {
86
- sess : & tcx. sess ,
87
- hir_map : tcx. hir ( ) ,
84
+ tcx,
88
85
const_kind : None ,
89
86
}
90
87
}
91
88
92
89
/// Emits an error when an unsupported expression is found in a const context.
93
90
fn const_check_violated ( & self , bad_op : & str , span : Span ) {
94
- if self . sess . opts . debugging_opts . unleash_the_miri_inside_of_you {
95
- self . sess . span_warn ( span, "skipping const checks" ) ;
91
+ if self . tcx . sess . opts . debugging_opts . unleash_the_miri_inside_of_you {
92
+ self . tcx . sess . span_warn ( span, "skipping const checks" ) ;
96
93
return ;
97
94
}
98
95
99
96
let const_kind = self . const_kind
100
97
. expect ( "`const_check_violated` may only be called inside a const context" ) ;
101
98
102
- span_err ! ( self . sess, span, E0744 , "`{}` is not allowed in a `{}`" , bad_op, const_kind) ;
99
+ span_err ! ( self . tcx . sess, span, E0744 , "`{}` is not allowed in a `{}`" , bad_op, const_kind) ;
103
100
}
104
101
105
102
/// Saves the parent `const_kind` before calling `f` and restores it afterwards.
@@ -113,7 +110,7 @@ impl<'tcx> CheckConstVisitor<'tcx> {
113
110
114
111
impl < ' tcx > Visitor < ' tcx > for CheckConstVisitor < ' tcx > {
115
112
fn nested_visit_map < ' this > ( & ' this mut self ) -> NestedVisitorMap < ' this , ' tcx > {
116
- NestedVisitorMap :: OnlyBodies ( & self . hir_map )
113
+ NestedVisitorMap :: OnlyBodies ( & self . tcx . hir ( ) )
117
114
}
118
115
119
116
fn visit_anon_const ( & mut self , anon : & ' tcx hir:: AnonConst ) {
@@ -122,7 +119,7 @@ impl<'tcx> Visitor<'tcx> for CheckConstVisitor<'tcx> {
122
119
}
123
120
124
121
fn visit_body ( & mut self , body : & ' tcx hir:: Body ) {
125
- let kind = ConstKind :: for_body ( body, self . hir_map ) ;
122
+ let kind = ConstKind :: for_body ( body, self . tcx . hir ( ) ) ;
126
123
self . recurse_into ( kind, |this| hir:: intravisit:: walk_body ( this, body) ) ;
127
124
}
128
125
0 commit comments