Skip to content

Commit c006f60

Browse files
committed
stuff
1 parent d056e25 commit c006f60

File tree

5 files changed

+191
-104
lines changed

5 files changed

+191
-104
lines changed

source/rustc_mir_build/src/expr_use_visitor.rs

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
//! normal visitor, which just walks the entire body in one shot, the
33
//! `ExprUseVisitor` determines how expressions are being used.
44
5+
#![allow(unused_imports)]
6+
57
use std::cell::{Ref, RefCell};
68
use std::ops::Deref;
79
use std::slice::from_ref;
@@ -29,8 +31,6 @@ use rustc_trait_selection::infer::InferCtxtExt;
2931
use tracing::{debug, trace};
3032
use ty::BorrowKind::ImmBorrow;
3133

32-
use crate::fn_ctxt::FnCtxt;
33-
3434
/// This trait defines the callbacks you can expect to receive when
3535
/// employing the ExprUseVisitor.
3636
pub trait Delegate<'tcx> {
@@ -150,6 +150,7 @@ pub trait TypeInformationCtxt<'tcx> {
150150
fn tcx(&self) -> TyCtxt<'tcx>;
151151
}
152152

153+
/*
153154
impl<'tcx> TypeInformationCtxt<'tcx> for &FnCtxt<'_, 'tcx> {
154155
type TypeckResults<'a> = Ref<'a, ty::TypeckResults<'tcx>>
155156
where
@@ -238,6 +239,51 @@ impl<'tcx> TypeInformationCtxt<'tcx> for (&LateContext<'tcx>, LocalDefId) {
238239
self.0.tcx
239240
}
240241
}
242+
*/
243+
244+
impl<'tcx> TypeInformationCtxt<'tcx> for &crate::upvar::FnCtxt<'_, 'tcx> {
245+
type TypeckResults<'a> = &'tcx ty::TypeckResults<'tcx>
246+
where
247+
Self: 'a;
248+
249+
type Error = !;
250+
251+
fn typeck_results(&self) -> Self::TypeckResults<'_> {
252+
self.typeck_results
253+
}
254+
255+
fn try_structurally_resolve_type(&self, _span: Span, ty: Ty<'tcx>) -> Ty<'tcx> {
256+
ty
257+
}
258+
259+
fn resolve_vars_if_possible<T: TypeFoldable<TyCtxt<'tcx>>>(&self, t: T) -> T {
260+
t
261+
}
262+
263+
fn report_error(&self, span: Span, msg: impl ToString) -> ! {
264+
span_bug!(span, "{}", msg.to_string())
265+
}
266+
267+
fn error_reported_in_ty(&self, _ty: Ty<'tcx>) -> Result<(), !> {
268+
Ok(())
269+
}
270+
271+
fn tainted_by_errors(&self) -> Result<(), !> {
272+
Ok(())
273+
}
274+
275+
fn type_is_copy_modulo_regions(&self, ty: Ty<'tcx>) -> bool {
276+
ty.is_copy_modulo_regions(self.tcx, self.param_env)
277+
}
278+
279+
fn body_owner_def_id(&self) -> LocalDefId {
280+
self.closure_def_id
281+
}
282+
283+
fn tcx(&self) -> TyCtxt<'tcx> {
284+
self.tcx
285+
}
286+
}
241287

242288
/// The ExprUseVisitor type
243289
///
@@ -250,11 +296,13 @@ pub struct ExprUseVisitor<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>
250296
upvars: Option<&'tcx FxIndexMap<HirId, hir::Upvar>>,
251297
}
252298

299+
/*
253300
impl<'a, 'tcx, D: Delegate<'tcx>> ExprUseVisitor<'tcx, (&'a LateContext<'tcx>, LocalDefId), D> {
254301
pub fn for_clippy(cx: &'a LateContext<'tcx>, body_def_id: LocalDefId, delegate: D) -> Self {
255302
Self::new((cx, body_def_id), delegate)
256303
}
257304
}
305+
*/
258306

259307
impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx, Cx, D> {
260308
/// Creates the ExprUseVisitor, configuring it with the various options provided:

source/rustc_mir_build/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
// tidy-alphabetical-start
44
#![allow(rustc::diagnostic_outside_of_impl)]
55
#![allow(rustc::untranslatable_diagnostic)]
6+
#![allow(dead_code)]
7+
#![allow(noop_method_call)]
68
#![feature(assert_matches)]
79
#![feature(box_patterns)]
810
#![feature(if_let_guard)]
911
#![feature(let_chains)]
1012
#![feature(try_blocks)]
1113
#![feature(rustc_private)]
14+
#![feature(never_type)]
1215
#![warn(unreachable_pub)]
1316
// tidy-alphabetical-end
1417

source/rustc_mir_build/src/thir/cx/expr.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -559,9 +559,12 @@ impl<'tcx> Cx<'tcx> {
559559
};
560560
let def_id = def_id.expect_local();
561561

562-
let upvars = self
562+
let (closure_captures, fake_reads) = crate::verus::get_upvars(self, expr, def_id);
563+
564+
let upvars = /*self
563565
.tcx
564-
.closure_captures(def_id)
566+
.closure_captures(def_id)*/
567+
closure_captures
565568
.iter()
566569
.zip_eq(args.upvar_tys())
567570
.filter(|(captured_place, ty)| {
@@ -575,16 +578,13 @@ impl<'tcx> Cx<'tcx> {
575578
.collect();
576579

577580
// Convert the closure fake reads, if any, from hir `Place` to ExprRef
578-
let fake_reads = match self.typeck_results.closure_fake_reads.get(&def_id) {
579-
Some(fake_reads) => fake_reads
581+
let fake_reads = fake_reads
580582
.iter()
581583
.map(|(place, cause, hir_id)| {
582584
let expr = self.convert_captured_hir_place(expr, place.clone());
583585
(self.thir.exprs.push(expr), *cause, *hir_id)
584586
})
585-
.collect(),
586-
None => Vec::new(),
587-
};
587+
.collect();
588588

589589
ExprKind::Closure(Box::new(crate::verus::fix_closure(self, ClosureExpr {
590590
closure_id: def_id,

0 commit comments

Comments
 (0)