Skip to content

Commit 2661a4e

Browse files
committed
Avoid BorrowMutError with RUSTC_LOG=debug
$ 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.
1 parent a53fb30 commit 2661a4e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,6 +2042,10 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>) -> EncodedMetadata {
20422042
encoder.emit_raw_bytes(&[0, 0, 0, 0]);
20432043

20442044
let source_map_files = tcx.sess.source_map().files();
2045+
let source_file_cache = (source_map_files[0].clone(), 0);
2046+
let required_source_files = Some(GrowableBitSet::with_capacity(source_map_files.len()));
2047+
drop(source_map_files);
2048+
20452049
let hygiene_ctxt = HygieneEncodeContext::default();
20462050

20472051
let mut ecx = EncodeContext {
@@ -2052,13 +2056,12 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>) -> EncodedMetadata {
20522056
lazy_state: LazyState::NoNode,
20532057
type_shorthands: Default::default(),
20542058
predicate_shorthands: Default::default(),
2055-
source_file_cache: (source_map_files[0].clone(), 0),
2059+
source_file_cache,
20562060
interpret_allocs: Default::default(),
2057-
required_source_files: Some(GrowableBitSet::with_capacity(source_map_files.len())),
2061+
required_source_files,
20582062
is_proc_macro: tcx.sess.crate_types().contains(&CrateType::ProcMacro),
20592063
hygiene_ctxt: &hygiene_ctxt,
20602064
};
2061-
drop(source_map_files);
20622065

20632066
// Encode the rustc version string in a predictable location.
20642067
rustc_version().encode(&mut ecx).unwrap();

0 commit comments

Comments
 (0)