mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-13 04:26:48 +00:00
Rollup merge of #78524 - tmiasko:source-files-borrow, r=Aaron1011
Avoid BorrowMutError with RUSTC_LOG=debug ```console $ touch empty.rs $ env RUSTC_LOG=debug rustc +stage1 --crate-type=lib empty.rs ``` Fails with a `BorrowMutError` because source map files are already borrowed while `features_query` attempts to format a log message containing a span. Release the borrow before the query to avoid the issue.
This commit is contained in:
commit
f8539221d0
@ -512,7 +512,7 @@ impl<T: Clone> Clone for Lock<T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Default)]
|
||||
pub struct RwLock<T>(InnerRwLock<T>);
|
||||
|
||||
impl<T> RwLock<T> {
|
||||
|
@ -2042,6 +2042,10 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>) -> EncodedMetadata {
|
||||
encoder.emit_raw_bytes(&[0, 0, 0, 0]);
|
||||
|
||||
let source_map_files = tcx.sess.source_map().files();
|
||||
let source_file_cache = (source_map_files[0].clone(), 0);
|
||||
let required_source_files = Some(GrowableBitSet::with_capacity(source_map_files.len()));
|
||||
drop(source_map_files);
|
||||
|
||||
let hygiene_ctxt = HygieneEncodeContext::default();
|
||||
|
||||
let mut ecx = EncodeContext {
|
||||
@ -2052,13 +2056,12 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>) -> EncodedMetadata {
|
||||
lazy_state: LazyState::NoNode,
|
||||
type_shorthands: Default::default(),
|
||||
predicate_shorthands: Default::default(),
|
||||
source_file_cache: (source_map_files[0].clone(), 0),
|
||||
source_file_cache,
|
||||
interpret_allocs: Default::default(),
|
||||
required_source_files: Some(GrowableBitSet::with_capacity(source_map_files.len())),
|
||||
required_source_files,
|
||||
is_proc_macro: tcx.sess.crate_types().contains(&CrateType::ProcMacro),
|
||||
hygiene_ctxt: &hygiene_ctxt,
|
||||
};
|
||||
drop(source_map_files);
|
||||
|
||||
// Encode the rustc version string in a predictable location.
|
||||
rustc_version().encode(&mut ecx).unwrap();
|
||||
|
@ -12,7 +12,7 @@ pub use crate::*;
|
||||
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::stable_hasher::StableHasher;
|
||||
use rustc_data_structures::sync::{AtomicU32, Lock, LockGuard, Lrc, MappedLockGuard};
|
||||
use rustc_data_structures::sync::{AtomicU32, Lrc, MappedReadGuard, ReadGuard, RwLock};
|
||||
use std::cmp;
|
||||
use std::convert::TryFrom;
|
||||
use std::hash::Hash;
|
||||
@ -168,7 +168,7 @@ pub struct SourceMap {
|
||||
/// The address space below this value is currently used by the files in the source map.
|
||||
used_address_space: AtomicU32,
|
||||
|
||||
files: Lock<SourceMapFiles>,
|
||||
files: RwLock<SourceMapFiles>,
|
||||
file_loader: Box<dyn FileLoader + Sync + Send>,
|
||||
// This is used to apply the file path remapping as specified via
|
||||
// `--remap-path-prefix` to all `SourceFile`s allocated within this `SourceMap`.
|
||||
@ -236,8 +236,8 @@ impl SourceMap {
|
||||
|
||||
// By returning a `MonotonicVec`, we ensure that consumers cannot invalidate
|
||||
// any existing indices pointing into `files`.
|
||||
pub fn files(&self) -> MappedLockGuard<'_, monotonic::MonotonicVec<Lrc<SourceFile>>> {
|
||||
LockGuard::map(self.files.borrow(), |files| &mut files.source_files)
|
||||
pub fn files(&self) -> MappedReadGuard<'_, monotonic::MonotonicVec<Lrc<SourceFile>>> {
|
||||
ReadGuard::map(self.files.borrow(), |files| &files.source_files)
|
||||
}
|
||||
|
||||
pub fn source_file_by_stable_id(
|
||||
|
1
src/test/ui/auxiliary/rustc-rust-log-aux.rs
Normal file
1
src/test/ui/auxiliary/rustc-rust-log-aux.rs
Normal file
@ -0,0 +1 @@
|
||||
// rustc-env:RUSTC_LOG=debug
|
@ -8,7 +8,7 @@
|
||||
// dont-check-compiler-stdout
|
||||
// dont-check-compiler-stderr
|
||||
// compile-flags: --error-format human
|
||||
|
||||
// aux-build: rustc-rust-log-aux.rs
|
||||
// rustc-env:RUSTC_LOG=debug
|
||||
|
||||
fn main() {}
|
||||
|
@ -1775,6 +1775,11 @@ impl<'test> TestCx<'test> {
|
||||
let mut aux_rustc =
|
||||
aux_cx.make_compile_args(input_file, aux_output, EmitMetadata::No, AllowUnused::No);
|
||||
|
||||
for key in &aux_props.unset_rustc_env {
|
||||
aux_rustc.env_remove(key);
|
||||
}
|
||||
aux_rustc.envs(aux_props.rustc_env.clone());
|
||||
|
||||
let (dylib, crate_type) = if aux_props.no_prefer_dynamic {
|
||||
(true, None)
|
||||
} else if self.config.target.contains("cloudabi")
|
||||
|
Loading…
Reference in New Issue
Block a user