Skip to content

Commit 5f1aeb5

Browse files
committed
Auto merge of rust-lang#84440 - Dylan-DPC:rollup-0xjb8oi, r=Dylan-DPC
Rollup of 7 pull requests Successful merges: - rust-lang#84343 (Remove `ScopeTree::closure_tree`) - rust-lang#84376 (Uses flex to fix formatting of h1 at any width) - rust-lang#84377 (Followup to rust-lang#83944) - rust-lang#84396 (Update LLVM submodule) - rust-lang#84402 (Move `sys_common::rwlock::StaticRWLock` etc. to `sys::unix::rwlock`) - rust-lang#84404 (Check for intrinsics before coercing to a function pointer) - rust-lang#84413 (Remove `sys::args::Args::inner_debug` and use `Debug` instead) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents ccf1712 + d1f5fc6 commit 5f1aeb5

File tree

21 files changed

+372
-567
lines changed

21 files changed

+372
-567
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

+35-10
Original file line numberDiff line numberDiff line change
@@ -1213,8 +1213,41 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12131213
deny_equality_constraints(self, predicate, generics);
12141214
}
12151215
}
1216-
1217-
visit::walk_generics(self, generics)
1216+
walk_list!(self, visit_generic_param, &generics.params);
1217+
for predicate in &generics.where_clause.predicates {
1218+
match predicate {
1219+
WherePredicate::BoundPredicate(bound_pred) => {
1220+
// A type binding, eg `for<'c> Foo: Send+Clone+'c`
1221+
self.check_late_bound_lifetime_defs(&bound_pred.bound_generic_params);
1222+
1223+
// This is slightly complicated. Our representation for poly-trait-refs contains a single
1224+
// binder and thus we only allow a single level of quantification. However,
1225+
// the syntax of Rust permits quantification in two places in where clauses,
1226+
// e.g., `T: for <'a> Foo<'a>` and `for <'a, 'b> &'b T: Foo<'a>`. If both are
1227+
// defined, then error.
1228+
if !bound_pred.bound_generic_params.is_empty() {
1229+
for bound in &bound_pred.bounds {
1230+
match bound {
1231+
GenericBound::Trait(t, _) => {
1232+
if !t.bound_generic_params.is_empty() {
1233+
struct_span_err!(
1234+
self.err_handler(),
1235+
t.span,
1236+
E0316,
1237+
"nested quantification of lifetimes"
1238+
)
1239+
.emit();
1240+
}
1241+
}
1242+
GenericBound::Outlives(_) => {}
1243+
}
1244+
}
1245+
}
1246+
}
1247+
_ => {}
1248+
}
1249+
self.visit_where_predicate(predicate);
1250+
}
12181251
}
12191252

12201253
fn visit_generic_param(&mut self, param: &'a GenericParam) {
@@ -1263,14 +1296,6 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12631296
visit::walk_pat(self, pat)
12641297
}
12651298

1266-
fn visit_where_predicate(&mut self, p: &'a WherePredicate) {
1267-
if let &WherePredicate::BoundPredicate(ref bound_predicate) = p {
1268-
// A type binding, eg `for<'c> Foo: Send+Clone+'c`
1269-
self.check_late_bound_lifetime_defs(&bound_predicate.bound_generic_params);
1270-
}
1271-
visit::walk_where_predicate(self, p);
1272-
}
1273-
12741299
fn visit_poly_trait_ref(&mut self, t: &'a PolyTraitRef, m: &'a TraitBoundModifier) {
12751300
self.check_late_bound_lifetime_defs(&t.bound_generic_params);
12761301
visit::walk_poly_trait_ref(self, t, m);

compiler/rustc_middle/src/middle/region.rs

-31
Original file line numberDiff line numberDiff line change
@@ -235,18 +235,6 @@ pub struct ScopeTree {
235235
/// escape into 'static and should have no local cleanup scope.
236236
rvalue_scopes: FxHashMap<hir::ItemLocalId, Option<Scope>>,
237237

238-
/// Encodes the hierarchy of fn bodies. Every fn body (including
239-
/// closures) forms its own distinct region hierarchy, rooted in
240-
/// the block that is the fn body. This map points from the ID of
241-
/// that root block to the ID of the root block for the enclosing
242-
/// fn, if any. Thus the map structures the fn bodies into a
243-
/// hierarchy based on their lexical mapping. This is used to
244-
/// handle the relationships between regions in a fn and in a
245-
/// closure defined by that fn. See the "Modeling closures"
246-
/// section of the README in infer::region_constraints for
247-
/// more details.
248-
closure_tree: FxHashMap<hir::ItemLocalId, hir::ItemLocalId>,
249-
250238
/// If there are any `yield` nested within a scope, this map
251239
/// stores the `Span` of the last one and its index in the
252240
/// postorder of the Visitor traversal on the HIR.
@@ -356,23 +344,6 @@ impl ScopeTree {
356344
self.destruction_scopes.get(&n).cloned()
357345
}
358346

359-
/// Records that `sub_closure` is defined within `sup_closure`. These IDs
360-
/// should be the ID of the block that is the fn body, which is
361-
/// also the root of the region hierarchy for that fn.
362-
pub fn record_closure_parent(
363-
&mut self,
364-
sub_closure: hir::ItemLocalId,
365-
sup_closure: hir::ItemLocalId,
366-
) {
367-
debug!(
368-
"record_closure_parent(sub_closure={:?}, sup_closure={:?})",
369-
sub_closure, sup_closure
370-
);
371-
assert!(sub_closure != sup_closure);
372-
let previous = self.closure_tree.insert(sub_closure, sup_closure);
373-
assert!(previous.is_none());
374-
}
375-
376347
pub fn record_var_scope(&mut self, var: hir::ItemLocalId, lifetime: Scope) {
377348
debug!("record_var_scope(sub={:?}, sup={:?})", var, lifetime);
378349
assert!(var != lifetime.item_local_id());
@@ -474,7 +445,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for ScopeTree {
474445
ref var_map,
475446
ref destruction_scopes,
476447
ref rvalue_scopes,
477-
ref closure_tree,
478448
ref yield_in_scope,
479449
} = *self;
480450

@@ -488,7 +458,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for ScopeTree {
488458
var_map.hash_stable(hcx, hasher);
489459
destruction_scopes.hash_stable(hcx, hasher);
490460
rvalue_scopes.hash_stable(hcx, hasher);
491-
closure_tree.hash_stable(hcx, hasher);
492461
yield_in_scope.hash_stable(hcx, hasher);
493462
}
494463
}

compiler/rustc_passes/src/region.rs

+1-14
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,6 @@ use std::mem;
2323

2424
#[derive(Debug, Copy, Clone)]
2525
pub struct Context {
26-
/// The root of the current region tree. This is typically the id
27-
/// of the innermost fn body. Each fn forms its own disjoint tree
28-
/// in the region hierarchy. These fn bodies are themselves
29-
/// arranged into a tree. See the "Modeling closures" section of
30-
/// the README in `rustc_trait_selection::infer::region_constraints`
31-
/// for more details.
32-
root_id: Option<hir::ItemLocalId>,
33-
3426
/// The scope that contains any new variables declared, plus its depth in
3527
/// the scope tree.
3628
var_parent: Option<(Scope, ScopeDepth)>,
@@ -743,11 +735,6 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> {
743735
let outer_pessimistic_yield = mem::replace(&mut self.pessimistic_yield, false);
744736
self.terminating_scopes.insert(body.value.hir_id.local_id);
745737

746-
if let Some(root_id) = self.cx.root_id {
747-
self.scope_tree.record_closure_parent(body.value.hir_id.local_id, root_id);
748-
}
749-
self.cx.root_id = Some(body.value.hir_id.local_id);
750-
751738
self.enter_scope(Scope { id: body.value.hir_id.local_id, data: ScopeData::CallSite });
752739
self.enter_scope(Scope { id: body.value.hir_id.local_id, data: ScopeData::Arguments });
753740

@@ -824,7 +811,7 @@ fn region_scope_tree(tcx: TyCtxt<'_>, def_id: DefId) -> &ScopeTree {
824811
tcx,
825812
scope_tree: ScopeTree::default(),
826813
expr_and_pat_count: 0,
827-
cx: Context { root_id: None, parent: None, var_parent: None },
814+
cx: Context { parent: None, var_parent: None },
828815
terminating_scopes: Default::default(),
829816
pessimistic_yield: false,
830817
fixup_scopes: vec![],

0 commit comments

Comments
 (0)