11use rustc:: hir:: * ;
22use rustc:: hir:: intravisit as visit;
33use rustc:: hir:: map:: Node :: { NodeExpr , NodeStmt } ;
4- use rustc:: infer;
54use rustc:: lint:: * ;
65use rustc:: middle:: expr_use_visitor:: * ;
76use rustc:: middle:: mem_categorization:: { cmt, Categorization } ;
8- use rustc:: traits:: ProjectionMode ;
97use rustc:: ty:: adjustment:: AutoAdjustment ;
108use rustc:: ty;
119use rustc:: util:: nodemap:: NodeSet ;
@@ -42,7 +40,7 @@ fn is_non_trait_box(ty: ty::Ty) -> bool {
4240}
4341
4442struct EscapeDelegate < ' a , ' tcx : ' a > {
45- cx : & ' a LateContext < ' a , ' tcx > ,
43+ tcx : ty :: TyCtxt < ' a , ' tcx , ' tcx > ,
4644 set : NodeSet ,
4745}
4846
@@ -55,15 +53,18 @@ impl LintPass for EscapePass {
5553impl LateLintPass for EscapePass {
5654 fn check_fn ( & mut self , cx : & LateContext , _: visit:: FnKind , decl : & FnDecl , body : & Block , _: Span , id : NodeId ) {
5755 let param_env = ty:: ParameterEnvironment :: for_item ( cx. tcx , id) ;
58- let infcx = infer:: new_infer_ctxt ( cx. tcx , & cx. tcx . tables , Some ( param_env) , ProjectionMode :: Any ) ;
56+
57+ let infcx = cx. tcx . borrowck_fake_infer_ctxt ( param_env) ;
5958 let mut v = EscapeDelegate {
60- cx : cx,
59+ tcx : cx. tcx ,
6160 set : NodeSet ( ) ,
6261 } ;
62+
6363 {
6464 let mut vis = ExprUseVisitor :: new ( & mut v, & infcx) ;
6565 vis. walk_fn ( decl, body) ;
6666 }
67+
6768 for node in v. set {
6869 span_lint ( cx,
6970 BOXED_LOCAL ,
@@ -75,7 +76,6 @@ impl LateLintPass for EscapePass {
7576
7677impl < ' a , ' tcx : ' a > Delegate < ' tcx > for EscapeDelegate < ' a , ' tcx > {
7778 fn consume ( & mut self , _: NodeId , _: Span , cmt : cmt < ' tcx > , mode : ConsumeMode ) {
78-
7979 if let Categorization :: Local ( lid) = cmt. cat {
8080 if self . set . contains ( & lid) {
8181 if let Move ( DirectRefMove ) = mode {
@@ -87,7 +87,7 @@ impl<'a, 'tcx: 'a> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
8787 }
8888 fn matched_pat ( & mut self , _: & Pat , _: cmt < ' tcx > , _: MatchMode ) { }
8989 fn consume_pat ( & mut self , consume_pat : & Pat , cmt : cmt < ' tcx > , _: ConsumeMode ) {
90- let map = & self . cx . tcx . map ;
90+ let map = & self . tcx . map ;
9191 if map. is_argument ( consume_pat. id ) {
9292 // Skip closure arguments
9393 if let Some ( NodeExpr ( ..) ) = map. find ( map. get_parent_node ( consume_pat. id ) ) {
@@ -132,8 +132,7 @@ impl<'a, 'tcx: 'a> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
132132
133133 if let Categorization :: Local ( lid) = cmt. cat {
134134 if self . set . contains ( & lid) {
135- if let Some ( & AutoAdjustment :: AdjustDerefRef ( adj) ) = self . cx
136- . tcx
135+ if let Some ( & AutoAdjustment :: AdjustDerefRef ( adj) ) = self . tcx
137136 . tables
138137 . borrow ( )
139138 . adjustments
@@ -148,13 +147,11 @@ impl<'a, 'tcx: 'a> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
148147 }
149148 } else if LoanCause :: AddrOf == loan_cause {
150149 // &x
151- if let Some ( & AutoAdjustment :: AdjustDerefRef ( adj) ) = self . cx
152- . tcx
150+ if let Some ( & AutoAdjustment :: AdjustDerefRef ( adj) ) = self . tcx
153151 . tables
154152 . borrow ( )
155153 . adjustments
156- . get ( & self . cx
157- . tcx
154+ . get ( & self . tcx
158155 . map
159156 . get_parent_node ( borrow_id) ) {
160157 if adj. autoderefs <= 1 {
0 commit comments