Skip to content

Commit 2c2ae11

Browse files
committed
Fix stage 1 compiler tests
1 parent 51e4acb commit 2c2ae11

File tree

7 files changed

+97
-19
lines changed

7 files changed

+97
-19
lines changed

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2309,10 +2309,10 @@ declare_lint! {
23092309
/// ### Example
23102310
///
23112311
/// ```rust
2312-
/// #![feature(sanitize)]
2312+
/// #![cfg_attr(not(bootstrap), feature(sanitize))]
23132313
///
23142314
/// #[inline(always)]
2315-
/// #[sanitize(address = "off")]
2315+
/// #[cfg_attr(not(bootstrap), sanitize(address = "off"))]
23162316
/// fn x() {}
23172317
///
23182318
/// fn main() {
@@ -4832,13 +4832,16 @@ declare_lint! {
48324832
///
48334833
/// ### Example
48344834
///
4835-
/// ```rust,compile_fail
4835+
#[cfg_attr(not(bootstrap), doc = "```rust,compile_fail")]
4836+
#[cfg_attr(bootstrap, doc = "```rust")]
48364837
/// #![doc = in_root!()]
48374838
///
48384839
/// macro_rules! in_root { () => { "" } }
48394840
///
48404841
/// fn main() {}
4841-
/// ```
4842+
#[cfg_attr(not(bootstrap), doc = "```")]
4843+
#[cfg_attr(bootstrap, doc = "```")]
4844+
// ^ Needed to avoid tidy warning about odd number of backticks
48424845
///
48434846
/// {{produces}}
48444847
///

src/bootstrap/src/core/build_steps/doc.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,6 +1293,8 @@ impl Step for RustcBook {
12931293
// functional sysroot.
12941294
builder.std(self.build_compiler, self.target);
12951295
let mut cmd = builder.tool_cmd(Tool::LintDocs);
1296+
cmd.arg("--build-rustc-stage");
1297+
cmd.arg(self.build_compiler.stage.to_string());
12961298
cmd.arg("--src");
12971299
cmd.arg(builder.src.join("compiler"));
12981300
cmd.arg("--out");

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2728,7 +2728,7 @@ impl Step for CrateLibrustc {
27282728
}
27292729

27302730
fn metadata(&self) -> Option<StepMetadata> {
2731-
Some(StepMetadata::test("CrateLibrustc", self.target))
2731+
Some(StepMetadata::test("CrateLibrustc", self.target).built_by(self.build_compiler))
27322732
}
27332733
}
27342734

src/bootstrap/src/core/builder/tests.rs

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,7 +1943,7 @@ mod snapshot {
19431943
[test] Pretty <host>
19441944
[build] rustc 1 <host> -> std 1 <host>
19451945
[build] rustc 0 <host> -> std 0 <host>
1946-
[test] CrateLibrustc <host>
1946+
[test] rustc 0 <host> -> CrateLibrustc 1 <host>
19471947
[build] rustc 1 <host> -> rustc 2 <host>
19481948
[test] crate-bootstrap <host> src/tools/coverage-dump
19491949
[test] crate-bootstrap <host> src/tools/jsondoclint
@@ -1993,6 +1993,40 @@ mod snapshot {
19931993
");
19941994
}
19951995

1996+
#[test]
1997+
fn test_compiler_stage_1() {
1998+
let ctx = TestCtx::new();
1999+
insta::assert_snapshot!(
2000+
ctx.config("test")
2001+
.path("compiler")
2002+
.stage(1)
2003+
.render_steps(), @r"
2004+
[build] llvm <host>
2005+
[build] rustc 0 <host> -> rustc 1 <host>
2006+
[build] rustc 0 <host> -> std 0 <host>
2007+
[build] rustdoc 0 <host>
2008+
[test] rustc 0 <host> -> CrateLibrustc 1 <host>
2009+
");
2010+
}
2011+
2012+
#[test]
2013+
fn test_compiler_stage_2() {
2014+
let ctx = TestCtx::new();
2015+
insta::assert_snapshot!(
2016+
ctx.config("test")
2017+
.path("compiler")
2018+
.stage(2)
2019+
.render_steps(), @r"
2020+
[build] llvm <host>
2021+
[build] rustc 0 <host> -> rustc 1 <host>
2022+
[build] rustc 1 <host> -> std 1 <host>
2023+
[build] rustc 1 <host> -> rustc 2 <host>
2024+
[build] rustc 1 <host> -> std 1 <host>
2025+
[build] rustdoc 1 <host>
2026+
[test] rustc 1 <host> -> CrateLibrustc 2 <host>
2027+
");
2028+
}
2029+
19962030
#[test]
19972031
fn test_exclude() {
19982032
let ctx = TestCtx::new();
@@ -2010,13 +2044,15 @@ mod snapshot {
20102044

20112045
let get_steps = |args: &[&str]| ctx.config("test").args(args).get_steps();
20122046

2047+
let rustc_metadata =
2048+
|| StepMetadata::test("CrateLibrustc", host).built_by(Compiler::new(0, host));
20132049
// Ensure our test is valid, and `test::Rustc` would be run without the exclude.
2014-
get_steps(&[]).assert_contains(StepMetadata::test("CrateLibrustc", host));
2050+
get_steps(&[]).assert_contains(rustc_metadata());
20152051

20162052
let steps = get_steps(&["--skip", "compiler/rustc_data_structures"]);
20172053

20182054
// Ensure tests for rustc are not skipped.
2019-
steps.assert_contains(StepMetadata::test("CrateLibrustc", host));
2055+
steps.assert_contains(rustc_metadata());
20202056
steps.assert_contains_fuzzy(StepMetadata::build("rustc", host));
20212057
}
20222058

src/bootstrap/src/core/config/config.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,9 +1006,7 @@ impl Config {
10061006
}
10071007

10081008
if flags_compile_time_deps && !matches!(flags_cmd, Subcommand::Check { .. }) {
1009-
eprintln!(
1010-
"ERROR: Can't use --compile-time-deps with any subcommand other than check."
1011-
);
1009+
eprintln!("ERROR: Can't use --compile-time-deps with any subcommand other than check.");
10121010
exit!(1);
10131011
}
10141012

src/tools/lint-docs/src/lib.rs

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ pub struct LintExtractor<'a> {
5959
pub rustc_target: &'a str,
6060
/// The target linker overriding `rustc`'s default
6161
pub rustc_linker: Option<&'a str>,
62+
/// Stage of the compiler that builds the docs (the stage of `rustc_path`).
63+
pub build_rustc_stage: u32,
6264
/// Verbose output.
6365
pub verbose: bool,
6466
/// Validate the style and the code example.
@@ -216,14 +218,7 @@ impl<'a> LintExtractor<'a> {
216218
if let Some(text) = line.strip_prefix("/// ") {
217219
doc_lines.push(text.to_string());
218220
} else if let Some(text) = line.strip_prefix("#[doc = \"") {
219-
let escaped = text.strip_suffix("\"]").unwrap();
220-
let mut buf = String::new();
221-
unescape_str(escaped, |_, res| match res {
222-
Ok(c) => buf.push(c),
223-
Err(err) => {
224-
assert!(!err.is_fatal(), "failed to unescape string literal")
225-
}
226-
});
221+
let buf = parse_doc_string(text);
227222
doc_lines.push(buf);
228223
} else if line == "///" {
229224
doc_lines.push("".to_string());
@@ -234,6 +229,20 @@ impl<'a> LintExtractor<'a> {
234229
// Ignore allow of lints (useful for
235230
// invalid_rust_codeblocks).
236231
continue;
232+
} else if let Some(text) =
233+
line.strip_prefix("#[cfg_attr(not(bootstrap), doc = \"")
234+
{
235+
if self.build_rustc_stage >= 1 {
236+
let buf = parse_doc_string(text);
237+
doc_lines.push(buf);
238+
}
239+
} else if let Some(text) =
240+
line.strip_prefix("#[cfg_attr(bootstrap, doc = \"")
241+
{
242+
if self.build_rustc_stage == 0 {
243+
let buf = parse_doc_string(text);
244+
doc_lines.push(buf);
245+
}
237246
} else {
238247
let name = lint_name(line).map_err(|e| {
239248
format!(
@@ -580,6 +589,23 @@ impl<'a> LintExtractor<'a> {
580589
}
581590
}
582591

592+
/// Parses a doc string that follows `#[doc = "`.
593+
fn parse_doc_string(text: &str) -> String {
594+
let escaped = text.strip_suffix("]").unwrap_or(text);
595+
let escaped = escaped.strip_suffix(")").unwrap_or(escaped).strip_suffix("\"");
596+
let Some(escaped) = escaped else {
597+
panic!("Cannot extract docstring content from {text}");
598+
};
599+
let mut buf = String::new();
600+
unescape_str(escaped, |_, res| match res {
601+
Ok(c) => buf.push(c),
602+
Err(err) => {
603+
assert!(!err.is_fatal(), "failed to unescape string literal")
604+
}
605+
});
606+
buf
607+
}
608+
583609
/// Adds `Lint`s that have been renamed.
584610
fn add_renamed_lints(lints: &mut Vec<Lint>) {
585611
for (level, names) in RENAMES {

src/tools/lint-docs/src/main.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,22 @@ fn doit() -> Result<(), Box<dyn Error>> {
2525
let mut args = std::env::args().skip(1);
2626
let mut src_path = None;
2727
let mut out_path = None;
28+
let mut build_rustc_stage = None;
2829
let mut rustc_path = None;
2930
let mut rustc_target = None;
3031
let mut rustc_linker = None;
3132
let mut verbose = false;
3233
let mut validate = false;
3334
while let Some(arg) = args.next() {
3435
match arg.as_str() {
36+
"--build-rustc-stage" => {
37+
build_rustc_stage = match args.next() {
38+
Some(s) => {
39+
Some(s.parse::<u32>().expect("build rustc stage has to be an integer"))
40+
}
41+
None => return Err("--build-rustc-stage requires a value".into()),
42+
};
43+
}
3544
"--src" => {
3645
src_path = match args.next() {
3746
Some(s) => Some(PathBuf::from(s)),
@@ -67,6 +76,9 @@ fn doit() -> Result<(), Box<dyn Error>> {
6776
s => return Err(format!("unexpected argument `{}`", s).into()),
6877
}
6978
}
79+
if build_rustc_stage.is_none() {
80+
return Err("--build-rustc-stage must be specified to the stage of the compiler that generates the docs".into());
81+
}
7082
if src_path.is_none() {
7183
return Err("--src must be specified to the directory with the compiler source".into());
7284
}
@@ -85,6 +97,7 @@ fn doit() -> Result<(), Box<dyn Error>> {
8597
rustc_path: &rustc_path.unwrap(),
8698
rustc_target: &rustc_target.unwrap(),
8799
rustc_linker: rustc_linker.as_deref(),
100+
build_rustc_stage: build_rustc_stage.unwrap(),
88101
verbose,
89102
validate,
90103
};

0 commit comments

Comments
 (0)