Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Fix stage 1 compiler tests
  • Loading branch information
Kobzol committed Aug 30, 2025
commit 9de09ac101f5e46b7eda48261a6757dc78b25bd8
11 changes: 7 additions & 4 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2309,10 +2309,10 @@ declare_lint! {
/// ### Example
///
/// ```rust
/// #![feature(sanitize)]
/// #![cfg_attr(not(bootstrap), feature(sanitize))]
///
/// #[inline(always)]
/// #[sanitize(address = "off")]
/// #[cfg_attr(not(bootstrap), sanitize(address = "off"))]
/// fn x() {}
///
/// fn main() {
Expand Down Expand Up @@ -4832,13 +4832,16 @@ declare_lint! {
///
/// ### Example
///
/// ```rust,compile_fail
#[cfg_attr(not(bootstrap), doc = "```rust,compile_fail")]
#[cfg_attr(bootstrap, doc = "```rust")]
/// #![doc = in_root!()]
///
/// macro_rules! in_root { () => { "" } }
///
/// fn main() {}
/// ```
#[cfg_attr(not(bootstrap), doc = "```")]
#[cfg_attr(bootstrap, doc = "```")]
// ^ Needed to avoid tidy warning about odd number of backticks
///
/// {{produces}}
///
Expand Down
2 changes: 2 additions & 0 deletions src/bootstrap/src/core/build_steps/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1293,6 +1293,8 @@ impl Step for RustcBook {
// functional sysroot.
builder.std(self.build_compiler, self.target);
let mut cmd = builder.tool_cmd(Tool::LintDocs);
cmd.arg("--build-rustc-stage");
cmd.arg(self.build_compiler.stage.to_string());
cmd.arg("--src");
cmd.arg(builder.src.join("compiler"));
cmd.arg("--out");
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2730,7 +2730,7 @@ impl Step for CrateLibrustc {
}

fn metadata(&self) -> Option<StepMetadata> {
Some(StepMetadata::test("CrateLibrustc", self.target))
Some(StepMetadata::test("CrateLibrustc", self.target).built_by(self.build_compiler))
}
}

Expand Down
42 changes: 39 additions & 3 deletions src/bootstrap/src/core/builder/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2078,7 +2078,7 @@ mod snapshot {
[test] Pretty <host>
[build] rustc 1 <host> -> std 1 <host>
[build] rustc 0 <host> -> std 0 <host>
[test] CrateLibrustc <host>
[test] rustc 0 <host> -> CrateLibrustc 1 <host>
[build] rustc 1 <host> -> rustc 2 <host>
[test] crate-bootstrap <host> src/tools/coverage-dump
[test] crate-bootstrap <host> src/tools/jsondoclint
Expand Down Expand Up @@ -2211,6 +2211,40 @@ mod snapshot {
");
}

#[test]
fn test_compiler_stage_1() {
let ctx = TestCtx::new();
insta::assert_snapshot!(
ctx.config("test")
.path("compiler")
.stage(1)
.render_steps(), @r"
[build] llvm <host>
[build] rustc 0 <host> -> rustc 1 <host>
[build] rustc 0 <host> -> std 0 <host>
[build] rustdoc 0 <host>
[test] rustc 0 <host> -> CrateLibrustc 1 <host>
");
}

#[test]
fn test_compiler_stage_2() {
let ctx = TestCtx::new();
insta::assert_snapshot!(
ctx.config("test")
.path("compiler")
.stage(2)
.render_steps(), @r"
[build] llvm <host>
[build] rustc 0 <host> -> rustc 1 <host>
[build] rustc 1 <host> -> std 1 <host>
[build] rustc 1 <host> -> rustc 2 <host>
[build] rustc 1 <host> -> std 1 <host>
[build] rustdoc 1 <host>
[test] rustc 1 <host> -> CrateLibrustc 2 <host>
");
}

#[test]
fn test_exclude() {
let ctx = TestCtx::new();
Expand All @@ -2228,13 +2262,15 @@ mod snapshot {

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

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

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

// Ensure tests for rustc are not skipped.
steps.assert_contains(StepMetadata::test("CrateLibrustc", host));
steps.assert_contains(rustc_metadata());
steps.assert_contains_fuzzy(StepMetadata::build("rustc", host));
}

Expand Down
4 changes: 1 addition & 3 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1012,9 +1012,7 @@ impl Config {
}

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

Expand Down
42 changes: 34 additions & 8 deletions src/tools/lint-docs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ pub struct LintExtractor<'a> {
pub rustc_target: &'a str,
/// The target linker overriding `rustc`'s default
pub rustc_linker: Option<&'a str>,
/// Stage of the compiler that builds the docs (the stage of `rustc_path`).
pub build_rustc_stage: u32,
/// Verbose output.
pub verbose: bool,
/// Validate the style and the code example.
Expand Down Expand Up @@ -216,14 +218,7 @@ impl<'a> LintExtractor<'a> {
if let Some(text) = line.strip_prefix("/// ") {
doc_lines.push(text.to_string());
} else if let Some(text) = line.strip_prefix("#[doc = \"") {
let escaped = text.strip_suffix("\"]").unwrap();
let mut buf = String::new();
unescape_str(escaped, |_, res| match res {
Ok(c) => buf.push(c),
Err(err) => {
assert!(!err.is_fatal(), "failed to unescape string literal")
}
});
let buf = parse_doc_string(text);
doc_lines.push(buf);
} else if line == "///" {
doc_lines.push("".to_string());
Expand All @@ -234,6 +229,20 @@ impl<'a> LintExtractor<'a> {
// Ignore allow of lints (useful for
// invalid_rust_codeblocks).
continue;
} else if let Some(text) =
line.strip_prefix("#[cfg_attr(not(bootstrap), doc = \"")
{
if self.build_rustc_stage >= 1 {
let buf = parse_doc_string(text);
doc_lines.push(buf);
}
} else if let Some(text) =
line.strip_prefix("#[cfg_attr(bootstrap, doc = \"")
{
if self.build_rustc_stage == 0 {
let buf = parse_doc_string(text);
doc_lines.push(buf);
}
} else {
let name = lint_name(line).map_err(|e| {
format!(
Expand Down Expand Up @@ -580,6 +589,23 @@ impl<'a> LintExtractor<'a> {
}
}

/// Parses a doc string that follows `#[doc = "`.
fn parse_doc_string(text: &str) -> String {
let escaped = text.strip_suffix("]").unwrap_or(text);
let escaped = escaped.strip_suffix(")").unwrap_or(escaped).strip_suffix("\"");
let Some(escaped) = escaped else {
panic!("Cannot extract docstring content from {text}");
};
let mut buf = String::new();
unescape_str(escaped, |_, res| match res {
Ok(c) => buf.push(c),
Err(err) => {
assert!(!err.is_fatal(), "failed to unescape string literal")
}
});
buf
}

/// Adds `Lint`s that have been renamed.
fn add_renamed_lints(lints: &mut Vec<Lint>) {
for (level, names) in RENAMES {
Expand Down
13 changes: 13 additions & 0 deletions src/tools/lint-docs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,22 @@ fn doit() -> Result<(), Box<dyn Error>> {
let mut args = std::env::args().skip(1);
let mut src_path = None;
let mut out_path = None;
let mut build_rustc_stage = None;
let mut rustc_path = None;
let mut rustc_target = None;
let mut rustc_linker = None;
let mut verbose = false;
let mut validate = false;
while let Some(arg) = args.next() {
match arg.as_str() {
"--build-rustc-stage" => {
build_rustc_stage = match args.next() {
Some(s) => {
Some(s.parse::<u32>().expect("build rustc stage has to be an integer"))
}
None => return Err("--build-rustc-stage requires a value".into()),
};
}
"--src" => {
src_path = match args.next() {
Some(s) => Some(PathBuf::from(s)),
Expand Down Expand Up @@ -67,6 +76,9 @@ fn doit() -> Result<(), Box<dyn Error>> {
s => return Err(format!("unexpected argument `{}`", s).into()),
}
}
if build_rustc_stage.is_none() {
return Err("--build-rustc-stage must be specified to the stage of the compiler that generates the docs".into());
}
if src_path.is_none() {
return Err("--src must be specified to the directory with the compiler source".into());
}
Expand All @@ -85,6 +97,7 @@ fn doit() -> Result<(), Box<dyn Error>> {
rustc_path: &rustc_path.unwrap(),
rustc_target: &rustc_target.unwrap(),
rustc_linker: rustc_linker.as_deref(),
build_rustc_stage: build_rustc_stage.unwrap(),
verbose,
validate,
};
Expand Down