Skip to content

Commit e33d313

Browse files
committed
Call FileEncoder::finish in rmeta encoding
1 parent cf226e9 commit e33d313

File tree

5 files changed

+10
-5
lines changed

5 files changed

+10
-5
lines changed

compiler/rustc_incremental/src/persist/save.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub fn save_dep_graph(tcx: TyCtxt<'_>) {
4949
join(
5050
move || {
5151
sess.time("incr_comp_persist_dep_graph", || {
52-
if let Err(err) = tcx.dep_graph.encode(&tcx.sess.prof) {
52+
if let Err(err) = tcx.dep_graph.finish_encoding(&tcx.sess.prof) {
5353
sess.emit_err(errors::WriteDepGraph { path: &staging_dep_graph_path, err });
5454
}
5555
if let Err(err) = fs::rename(&staging_dep_graph_path, &dep_graph_path) {

compiler/rustc_metadata/src/rmeta/encoder.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -2251,7 +2251,12 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>, path: &Path) {
22512251
// culminating in the `CrateRoot` which points to all of it.
22522252
let root = ecx.encode_crate_root();
22532253

2254-
ecx.opaque.flush();
2254+
// Make sure we report any errors from writing to the file.
2255+
// If we forget this, compilation can succeed with an incomplete rmeta file,
2256+
// causing an ICE when the rmeta file is read by another compilation.
2257+
if let Err(err) = ecx.opaque.finish() {
2258+
tcx.sess.emit_err(FailWriteFile { err });
2259+
}
22552260

22562261
let mut file = ecx.opaque.file();
22572262
// We will return to this position after writing the root position.

compiler/rustc_middle/src/query/on_disk_cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ impl<'a, 'tcx> CacheEncoder<'a, 'tcx> {
867867
}
868868

869869
#[inline]
870-
fn finish(self) -> Result<usize, io::Error> {
870+
fn finish(mut self) -> Result<usize, io::Error> {
871871
self.encoder.finish()
872872
}
873873
}

compiler/rustc_query_system/src/dep_graph/graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ impl<D: Deps> DepGraph<D> {
989989
}
990990
}
991991

992-
pub fn encode(&self, profiler: &SelfProfilerRef) -> FileEncodeResult {
992+
pub fn finish_encoding(&self, profiler: &SelfProfilerRef) -> FileEncodeResult {
993993
if let Some(data) = &self.data {
994994
data.current.encoder.steal().finish(profiler)
995995
} else {

compiler/rustc_serialize/src/opaque.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ impl FileEncoder {
152152
})
153153
}
154154

155-
pub fn finish(mut self) -> Result<usize, io::Error> {
155+
pub fn finish(&mut self) -> Result<usize, io::Error> {
156156
self.flush();
157157
match std::mem::replace(&mut self.res, Ok(())) {
158158
Ok(()) => Ok(self.position()),

0 commit comments

Comments
 (0)