Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 9 pull requests #135317

Closed
wants to merge 23 commits into from
Closed
Changes from 3 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5065a91
Improve prose around `as_slice` example of IterMut
hkBst Dec 21, 2024
5966ba0
Fix ptr::from_ref documentation example comment
madsmtm Dec 29, 2024
326fedf
Add Pin::as_deref_mut to relnotes
coolreader18 Jan 9, 2025
00448ab
Make bare-fn test less dependent on path width
ChrisDenton Jan 9, 2025
5e50518
Add tests cases from review of #132289
steffahn Jan 9, 2025
ad0e8dd
Cleanup `opaque_type_cycle_error`
yotamofek Jan 9, 2025
13e8876
Add `default_field_values` entry to unstable book
estebank Dec 28, 2024
9d2e1ed
Make sure to walk into nested const blocks in RegionResolutionVisitor
compiler-errors Jan 9, 2025
9585f36
Rename RegionResolutionVisitor to ScopeResolutionVisitor
compiler-errors Jan 9, 2025
a75617c
Foo<T> != Foo<U> under layout randomization
the8472 Nov 16, 2024
d7fb729
adjust UI tests
the8472 Dec 23, 2024
56889dd
exclude unsizable tail from randomization seed calculation
the8472 Nov 16, 2024
8b1de16
also initialize Layout field in rust-analyzer
the8472 Nov 16, 2024
d89b6d5
test that coercions still work under randomization
the8472 Jan 8, 2025
85ff229
Rollup merge of #133088 - the8472:randomize-me-harder, r=workingjubilee
workingjubilee Jan 10, 2025
0461d58
Rollup merge of #134619 - hkBst:patch-7, r=jhpratt
workingjubilee Jan 10, 2025
3fc4e94
Rollup merge of #134855 - estebank:default-field-values-unstable-docs…
workingjubilee Jan 10, 2025
b4d81df
Rollup merge of #134908 - madsmtm:ptr-from_ref-docs, r=ibraheemdev
workingjubilee Jan 10, 2025
c1ba22b
Rollup merge of #135275 - coolreader18:pin-as_deref_mut-relnotes, r=B…
workingjubilee Jan 10, 2025
f85b79a
Rollup merge of #135294 - ChrisDenton:bare-fn-width, r=jieyouxu
workingjubilee Jan 10, 2025
4ac1908
Rollup merge of #135304 - steffahn:tests_from_132289, r=compiler-errors
workingjubilee Jan 10, 2025
2b0cb21
Rollup merge of #135307 - yotamofek:cleanup-opaque-type-cycle-error, …
workingjubilee Jan 10, 2025
5e7dc15
Rollup merge of #135308 - compiler-errors:scope-visit, r=oli-obk
workingjubilee Jan 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions compiler/rustc_hir_analysis/src/check/region.rs
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ struct Context {
parent: Option<(Scope, ScopeDepth)>,
}

struct RegionResolutionVisitor<'tcx> {
struct ScopeResolutionVisitor<'tcx> {
tcx: TyCtxt<'tcx>,

// The number of expressions and patterns visited in the current body.
@@ -71,7 +71,7 @@ struct RegionResolutionVisitor<'tcx> {
}

/// Records the lifetime of a local variable as `cx.var_parent`
fn record_var_lifetime(visitor: &mut RegionResolutionVisitor<'_>, var_id: hir::ItemLocalId) {
fn record_var_lifetime(visitor: &mut ScopeResolutionVisitor<'_>, var_id: hir::ItemLocalId) {
match visitor.cx.var_parent {
None => {
// this can happen in extern fn declarations like
@@ -82,7 +82,7 @@ fn record_var_lifetime(visitor: &mut RegionResolutionVisitor<'_>, var_id: hir::I
}
}

fn resolve_block<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, blk: &'tcx hir::Block<'tcx>) {
fn resolve_block<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, blk: &'tcx hir::Block<'tcx>) {
debug!("resolve_block(blk.hir_id={:?})", blk.hir_id);

let prev_cx = visitor.cx;
@@ -193,7 +193,7 @@ fn resolve_block<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, blk: &'tcx h
visitor.cx = prev_cx;
}

fn resolve_arm<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, arm: &'tcx hir::Arm<'tcx>) {
fn resolve_arm<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, arm: &'tcx hir::Arm<'tcx>) {
fn has_let_expr(expr: &Expr<'_>) -> bool {
match &expr.kind {
hir::ExprKind::Binary(_, lhs, rhs) => has_let_expr(lhs) || has_let_expr(rhs),
@@ -220,7 +220,7 @@ fn resolve_arm<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, arm: &'tcx hir
visitor.cx = prev_cx;
}

fn resolve_pat<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, pat: &'tcx hir::Pat<'tcx>) {
fn resolve_pat<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, pat: &'tcx hir::Pat<'tcx>) {
visitor.record_child_scope(Scope { local_id: pat.hir_id.local_id, data: ScopeData::Node });

// If this is a binding then record the lifetime of that binding.
@@ -237,7 +237,7 @@ fn resolve_pat<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, pat: &'tcx hir
debug!("resolve_pat - post-increment {} pat = {:?}", visitor.expr_and_pat_count, pat);
}

fn resolve_stmt<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, stmt: &'tcx hir::Stmt<'tcx>) {
fn resolve_stmt<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, stmt: &'tcx hir::Stmt<'tcx>) {
let stmt_id = stmt.hir_id.local_id;
debug!("resolve_stmt(stmt.id={:?})", stmt_id);

@@ -256,7 +256,7 @@ fn resolve_stmt<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, stmt: &'tcx h
visitor.cx.parent = prev_parent;
}

fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx hir::Expr<'tcx>) {
fn resolve_expr<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, expr: &'tcx hir::Expr<'tcx>) {
debug!("resolve_expr - pre-increment {} expr = {:?}", visitor.expr_and_pat_count, expr);

let prev_cx = visitor.cx;
@@ -420,10 +420,10 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h
// properly, we can't miss any types.

match expr.kind {
// Manually recurse over closures and inline consts, because they are the only
// case of nested bodies that share the parent environment.
hir::ExprKind::Closure(&hir::Closure { body, .. })
| hir::ExprKind::ConstBlock(hir::ConstBlock { body, .. }) => {
// Manually recurse over closures, because they are nested bodies
// that share the parent environment. We handle const blocks in
// `visit_inline_const`.
hir::ExprKind::Closure(&hir::Closure { body, .. }) => {
let body = visitor.tcx.hir().body(body);
visitor.visit_body(body);
}
@@ -554,7 +554,7 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h
}

fn resolve_local<'tcx>(
visitor: &mut RegionResolutionVisitor<'tcx>,
visitor: &mut ScopeResolutionVisitor<'tcx>,
pat: Option<&'tcx hir::Pat<'tcx>>,
init: Option<&'tcx hir::Expr<'tcx>>,
) {
@@ -725,7 +725,7 @@ fn resolve_local<'tcx>(
/// | ( E& )
/// ```
fn record_rvalue_scope_if_borrow_expr<'tcx>(
visitor: &mut RegionResolutionVisitor<'tcx>,
visitor: &mut ScopeResolutionVisitor<'tcx>,
expr: &hir::Expr<'_>,
blk_id: Option<Scope>,
) {
@@ -782,7 +782,7 @@ fn resolve_local<'tcx>(
}
}

impl<'tcx> RegionResolutionVisitor<'tcx> {
impl<'tcx> ScopeResolutionVisitor<'tcx> {
/// Records the current parent (if any) as the parent of `child_scope`.
/// Returns the depth of `child_scope`.
fn record_child_scope(&mut self, child_scope: Scope) -> ScopeDepth {
@@ -838,7 +838,7 @@ impl<'tcx> RegionResolutionVisitor<'tcx> {
}
}

impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> {
impl<'tcx> Visitor<'tcx> for ScopeResolutionVisitor<'tcx> {
fn visit_block(&mut self, b: &'tcx Block<'tcx>) {
resolve_block(self, b);
}
@@ -906,6 +906,10 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> {
fn visit_local(&mut self, l: &'tcx LetStmt<'tcx>) {
resolve_local(self, Some(l.pat), l.init)
}
fn visit_inline_const(&mut self, c: &'tcx hir::ConstBlock) {
let body = self.tcx.hir().body(c.body);
self.visit_body(body);
}
}

/// Per-body `region::ScopeTree`. The `DefId` should be the owner `DefId` for the body;
@@ -922,7 +926,7 @@ pub(crate) fn region_scope_tree(tcx: TyCtxt<'_>, def_id: DefId) -> &ScopeTree {
}

let scope_tree = if let Some(body) = tcx.hir().maybe_body_owned_by(def_id.expect_local()) {
let mut visitor = RegionResolutionVisitor {
let mut visitor = ScopeResolutionVisitor {
tcx,
scope_tree: ScopeTree::default(),
expr_and_pat_count: 0,
16 changes: 16 additions & 0 deletions tests/ui/inline-const/collect-scopes-in-pat.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @compile-flags: -Zlint-mir
//@ check-pass

#![feature(inline_const_pat)]

fn main() {
match 1 {
const {
|| match 0 {
x => 0,
};
0
} => (),
_ => (),
}
}