Skip to content

Commit

Permalink
simplify tracking and opt for build-pass testing
Browse files Browse the repository at this point in the history
  • Loading branch information
dingxiangfei2009 committed Feb 12, 2022
1 parent 4097274 commit 906cdbf
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
6 changes: 5 additions & 1 deletion compiler/rustc_middle/src/middle/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,10 @@ impl ScopeTree {
}

pub fn record_local_access_scope(&mut self, var: hir::ItemLocalId, proposed_lifetime: Scope) {
debug!("record_local_access_scope(sub={:?}, sup={:?})", var, proposed_lifetime);
debug!(
"record_local_access_scope(var={:?}, proposed_lifetime={:?})",
var, proposed_lifetime
);
let mut id = Scope { id: var, data: ScopeData::Node };

while let Some(&(p, _)) = self.parent_map.get(&id) {
Expand All @@ -385,6 +388,7 @@ impl ScopeTree {
}

pub fn record_eager_scope(&mut self, var: hir::ItemLocalId, proposed_lifetime: Scope) {
debug!("record_eager_scope(var={:?}, proposed_lifetime={:?})", var, proposed_lifetime);
if let Some(destruction) = self.temporary_scope(var) {
if self.is_subscope_of(destruction, proposed_lifetime) {
// If the current temporary scope is already a subset of the proposed region,
Expand Down
11 changes: 3 additions & 8 deletions compiler/rustc_passes/src/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ fn mark_local_terminating_scopes<'tcx>(expr: &'tcx hir::Expr<'tcx>) -> FxHashSet
Ref,
Deref,
Project,
Local,
}
// Here we are looking for a chain of access to extract a place reference for
// a local variable.
Expand All @@ -233,7 +232,8 @@ fn mark_local_terminating_scopes<'tcx>(expr: &'tcx hir::Expr<'tcx>) -> FxHashSet
_,
hir::Path { res: hir::def::Res::Local(_), .. },
)) => {
ops.push((nested_expr, OpTy::Local));
// We have reached the end of the access path
// because a local variable access is encountered
break;
}
hir::ExprKind::AddrOf(_, _, subexpr) => {
Expand Down Expand Up @@ -261,9 +261,7 @@ fn mark_local_terminating_scopes<'tcx>(expr: &'tcx hir::Expr<'tcx>) -> FxHashSet
}
}
let mut ref_level = SmallVec::<[_; 4]>::new();
let mut ops_iter = ops.into_iter().rev();
ops_iter.next().unwrap();
for (expr, op) in ops_iter {
for (expr, op) in ops.into_iter().rev() {
match op {
OpTy::Ref => {
ref_level.push(expr);
Expand All @@ -279,9 +277,6 @@ fn mark_local_terminating_scopes<'tcx>(expr: &'tcx hir::Expr<'tcx>) -> FxHashSet
// These temporaries must stay alive even after the field access.
ref_level.clear();
}
OpTy::Local => {
panic!("unexpected encounter of Local")
}
}
}
self.locals.insert(expr.hir_id.local_id);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// edition:2018
// run-pass
// build-pass

use std::ops::Index;

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/generator/refined-region-for-local-accesses.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// edition:2018
// run-pass
// build-pass
#![feature(generators, generator_trait, negative_impls)]

fn assert_send<T: Send>(_: T) {}
Expand Down

0 comments on commit 906cdbf

Please sign in to comment.