Skip to content

Avoid BorrowMutError with RUSTC_LOG=debug #78524

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

Merged
merged 4 commits into from
Oct 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
9 changes: 6 additions & 3 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_span/src/source_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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`.
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/auxiliary/rustc-rust-log-aux.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// rustc-env:RUSTC_LOG=debug
2 changes: 1 addition & 1 deletion src/test/ui/rustc-rust-log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
5 changes: 5 additions & 0 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down