Skip to content

Commit 9e6e7c5

Browse files
committed
Fix issue w/ get_body_with_borrowck_facts. Release v0.14.2
1 parent 2186233 commit 9e6e7c5

File tree

19 files changed

+59
-47
lines changed

19 files changed

+59
-47
lines changed

crates/rustc_plugin/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rustc_plugin"
3-
version = "0.14.1-nightly-2025-08-20"
3+
version = "0.14.2-nightly-2025-08-20"
44
edition = "2024"
55
authors = ["Will Crichton <crichton.will@gmail.com>"]
66
description = "A framework for writing plugins that integrate with the Rust compiler"

crates/rustc_plugin/src/driver.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ use std::{
22
env,
33
ops::Deref,
44
path::{Path, PathBuf},
5-
process::{exit, Command},
5+
process::{Command, exit},
66
};
77

8-
use rustc_session::{config::ErrorOutputType, EarlyDiagCtxt};
8+
use rustc_session::{EarlyDiagCtxt, config::ErrorOutputType};
99
use rustc_tools_util::VersionInfo;
1010

11-
use super::plugin::{RustcPlugin, PLUGIN_ARGS};
11+
use super::plugin::{PLUGIN_ARGS, RustcPlugin};
1212
use crate::cli::{RUN_ON_ALL_CRATES, SPECIFIC_CRATE, SPECIFIC_TARGET};
1313

1414
/// If a command-line option matches `find_arg`, then apply the predicate `pred` on its value. If

crates/rustc_plugin/src/plugin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{borrow::Cow, path::PathBuf, process::Command};
22

33
use cargo_metadata::camino::Utf8Path;
4-
use serde::{de::DeserializeOwned, Serialize};
4+
use serde::{Serialize, de::DeserializeOwned};
55

66
/// Specification of a set of crates.
77
pub enum CrateFilter {

crates/rustc_plugin/tests/test_example.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{env, fs, path::Path, process::Command, sync::Once};
22

3-
use anyhow::{ensure, Context, Result};
3+
use anyhow::{Context, Result, ensure};
44

55
static SETUP: Once = Once::new();
66

crates/rustc_utils/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rustc_utils"
3-
version = "0.14.1-nightly-2025-08-20"
3+
version = "0.14.2-nightly-2025-08-20"
44
edition = "2024"
55
authors = ["Will Crichton <crichton.will@gmail.com>"]
66
description = "Utilities for working with the Rust compiler"
@@ -27,7 +27,7 @@ serde = { version = "1", features = ["derive"], optional = true }
2727
textwrap = { version = "0.16", optional = true }
2828
regex = { version = "1", optional = true }
2929
ts-rs = { version = "7", optional = true }
30-
indexical = { version = "0.9.0", default-features = false, features = ["rustc"], optional = true }
30+
indexical = { version = "0.9.3", default-features = false, features = ["rustc"], optional = true }
3131

3232
[dev-dependencies]
3333
rustc_utils = { path = ".", features = ["test"] }

crates/rustc_utils/src/cache.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ where
7373
pub fn len(&self) -> usize {
7474
self.0.borrow().len()
7575
}
76+
77+
/// Returns true if the cache contains the key.
78+
pub fn contains_key(&self, key: &In) -> bool {
79+
self.0.borrow().contains_key(key)
80+
}
81+
7682
/// Returns the cached value for the given key, or runs `compute` if
7783
/// the value is not in cache.
7884
///
@@ -84,6 +90,7 @@ where
8490
.get_maybe_recursive(key, compute)
8591
.unwrap_or_else(recursion_panic)
8692
}
93+
8794
/// Returns the cached value for the given key, or runs `compute` if
8895
/// the value is not in cache.
8996
///
@@ -112,7 +119,9 @@ where
112119
}
113120

114121
fn recursion_panic<A>() -> A {
115-
panic!("Recursion detected! The computation of a value tried to retrieve the same from the cache. Using `get_maybe_recursive` to handle this case gracefully.")
122+
panic!(
123+
"Recursion detected! The computation of a value tried to retrieve the same from the cache. Using `get_maybe_recursive` to handle this case gracefully."
124+
)
116125
}
117126

118127
impl<In, Out> Default for Cache<In, Out> {

crates/rustc_utils/src/hir/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ mod test {
6060
use rustc_middle::ty::TypingEnv;
6161

6262
use super::TyExt;
63-
use crate::{test_utils, BodyExt};
63+
use crate::{BodyExt, test_utils};
6464

6565
#[test]
6666
fn test_ty_ext() {

crates/rustc_utils/src/mir/body.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ use std::{
66
process::{Command, Stdio},
77
};
88

9-
use anyhow::{ensure, Result};
9+
use anyhow::{Result, ensure};
1010
use pretty::PrettyPrintMirOptions;
1111
use rustc_data_structures::fx::FxHashMap as HashMap;
12-
use rustc_hir::{def_id::DefId, CoroutineDesugaring, CoroutineKind, HirId};
12+
use rustc_hir::{CoroutineDesugaring, CoroutineKind, HirId, def_id::DefId};
1313
use rustc_middle::{
1414
mir::{
15-
pretty, pretty::write_mir_fn, BasicBlock, Body, Local, Location, Place, SourceInfo,
16-
TerminatorKind, VarDebugInfoContents,
15+
BasicBlock, Body, Local, Location, Place, SourceInfo, TerminatorKind,
16+
VarDebugInfoContents, pretty, pretty::write_mir_fn,
1717
},
1818
ty::{Region, Ty, TyCtxt},
1919
};

crates/rustc_utils/src/mir/borrowck_facts.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,23 @@ fn mir_borrowck(
112112
///
113113
/// Note that as of May 2022, Polonius can be *very* slow for large functions.
114114
/// It may take up to 30 seconds to analyze a single body with a large CFG.
115-
#[allow(clippy::needless_lifetimes)]
116-
pub fn get_body_with_borrowck_facts(
117-
tcx: TyCtxt<'_>,
115+
pub fn get_body_with_borrowck_facts<'tcx>(
116+
tcx: TyCtxt<'tcx>,
118117
def_id: LocalDefId,
119-
) -> &BodyWithBorrowckFacts<'_> {
120-
let _ = tcx.mir_borrowck(def_id);
118+
) -> &'tcx BodyWithBorrowckFacts<'tcx> {
121119
MIR_BODIES.with(|cache| {
120+
// Note: as of nightly-2025-08-20, get_bodies_with_borrowck_facts also returns the bodies for children
121+
// of a checked body. We have to handle the case where the parent of the current `def_id` was checked,
122+
// or else rustc panics about a stolen body. Hence, we check for whether the cache contains the key already.
123+
if !cache.contains_key(&def_id) {
124+
let _ = tcx.mir_borrowck(def_id);
125+
}
126+
122127
let body = cache.get(&def_id, |_| panic!("mir_borrowck override should have stored body for item: {def_id:?}. Are you sure you registered borrowck_facts::override_queries?"));
123128
unsafe {
124129
std::mem::transmute::<
125-
&BodyWithBorrowckFacts<'static>,
126-
&BodyWithBorrowckFacts<'_>,
130+
&'_ BodyWithBorrowckFacts<'static>,
131+
&'tcx BodyWithBorrowckFacts<'tcx>,
127132
>(body)
128133
}
129134
})

crates/rustc_utils/src/mir/control_dependencies.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
use std::fmt;
1010

1111
use rustc_data_structures::graph::{
12-
dominators, dominators::Dominators, iterate, vec_graph::VecGraph, ControlFlowGraph,
13-
DirectedGraph, Predecessors, StartNode, Successors,
12+
ControlFlowGraph, DirectedGraph, Predecessors, StartNode, Successors, dominators,
13+
dominators::Dominators, iterate, vec_graph::VecGraph,
1414
};
1515
use rustc_index::{
16-
bit_set::{DenseBitSet, MixedBitSet, SparseBitMatrix},
1716
Idx,
17+
bit_set::{DenseBitSet, MixedBitSet, SparseBitMatrix},
1818
};
1919
use smallvec::SmallVec;
2020

@@ -206,7 +206,7 @@ mod test {
206206
use rustc_middle::mir::Location;
207207
use test_log::test;
208208

209-
use crate::{test_utils, BodyExt};
209+
use crate::{BodyExt, test_utils};
210210

211211
#[test]
212212
fn test_control_dependencies() {

0 commit comments

Comments
 (0)