Skip to content

Commit 61c2d76

Browse files
committed
Add test verifying that changing comments recompiles dependents
1 parent 3bc767e commit 61c2d76

File tree

7 files changed

+56
-4
lines changed

7 files changed

+56
-4
lines changed

compiler/rustc_metadata/src/creader.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use rustc_session::search_paths::PathKind;
3535
use rustc_span::edition::Edition;
3636
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, sym};
3737
use rustc_target::spec::{PanicStrategy, Target, TargetTuple};
38-
use tracing::{debug, info, trace};
38+
use tracing::{debug, info, instrument, trace};
3939

4040
use crate::errors;
4141
use crate::locator::{CrateError, CrateLocator, CratePaths};
@@ -168,7 +168,7 @@ impl<'a> std::fmt::Debug for CrateDump<'a> {
168168
}
169169

170170
/// Reason that a crate is being sourced as a dependency.
171-
#[derive(Clone, Copy)]
171+
#[derive(Clone, Copy, Debug)]
172172
enum CrateOrigin<'a> {
173173
/// This crate was a dependency of another crate.
174174
IndirectDependency {
@@ -779,6 +779,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
779779
}
780780
}
781781

782+
#[instrument(level = "debug", skip(self))]
782783
fn maybe_resolve_crate<'b>(
783784
&'b mut self,
784785
name: Symbol,

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
585585
adapted.set_some(on_disk_index, self.lazy(adapted_source_file));
586586
}
587587

588-
adapted.encode(&mut self.opaque)
588+
let ret = adapted.encode(&mut self.opaque);
589+
ret
589590
}
590591

591592
fn encode_crate_root(&mut self) -> LazyValue<CrateRoot> {

compiler/rustc_metadata/src/rmeta/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ impl RawDefId {
332332
}
333333
}
334334

335-
#[derive(Encodable, Decodable)]
335+
#[derive(Encodable, Decodable, Debug)]
336336
pub(crate) struct CrateDep {
337337
pub name: Symbol,
338338
pub hash: Svh,
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![crate_name = "foo"]
2+
#![crate_type = "lib"]
3+
// bbb
4+
pub struct Foo;
5+
6+
impl Foo {
7+
pub fn bar(self: Foo) {}
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![crate_name = "foo"]
2+
#![crate_type = "lib"]
3+
// aaa
4+
pub struct Foo;
5+
6+
impl Foo {
7+
pub fn bar(self: Foo) {}
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#! /bin/bash
2+
x test tests/run-make/rdr-ignores-comments
3+
cp before.rs foo.rs
4+
rustc +stage1 --emit=metadata ./foo.rs && mv libfoo.rmeta before.rmeta
5+
cp after.rs foo.rs
6+
rustc +stage1 --emit=metadata ./foo.rs && mv libfoo.rmeta after.rmeta
7+
rm foo.rs
8+
vbindiff before.rmeta after.rmeta
9+
rm before.rmeta after.rmeta
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// tests that we can reuse an existing rlib instead of rebuilding
2+
// when changin a non-doc comments in a file
3+
use run_make_support::{rfs, rustc};
4+
use std::path::Path;
5+
use std::hash::{Hash, Hasher};
6+
7+
fn main() {
8+
let before = check_and_hash("before.rs");
9+
let after = check_and_hash("after.rs");
10+
dbg!(before, after);
11+
assert_eq!(before, after);
12+
}
13+
14+
fn check_and_hash<P>(filename: P) -> u64
15+
where
16+
P: AsRef<Path>,
17+
{
18+
rfs::rename(filename, "foo.rs");
19+
rustc().input("foo.rs").emit("metadata").run();
20+
// hash the output
21+
let bytes = rfs::read("libfoo.rmeta");
22+
let mut hasher = std::hash::DefaultHasher::new();
23+
bytes.hash(&mut hasher);
24+
hasher.finish()
25+
}

0 commit comments

Comments
 (0)