Skip to content

Commit 2c2b622

Browse files
authored
Rollup merge of #151218 - crate-struct, r=clubby789
compiletest: Add `AuxCrate` struct with docs. To make the code clearer.
2 parents cfa8f97 + 4530e26 commit 2c2b622

3 files changed

Lines changed: 22 additions & 12 deletions

File tree

src/tools/compiletest/src/directives.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use tracing::*;
88

99
use crate::common::{CodegenBackend, Config, Debugger, FailMode, PassMode, RunFailMode, TestMode};
1010
use crate::debuggers::{extract_cdb_version, extract_gdb_version};
11-
pub(crate) use crate::directives::auxiliary::AuxProps;
1211
use crate::directives::auxiliary::parse_and_update_aux;
12+
pub(crate) use crate::directives::auxiliary::{AuxCrate, AuxProps};
1313
use crate::directives::directive_names::{
1414
KNOWN_DIRECTIVE_NAMES_SET, KNOWN_HTMLDOCCK_DIRECTIVE_NAMES, KNOWN_JSONDOCCK_DIRECTIVE_NAMES,
1515
};

src/tools/compiletest/src/directives/auxiliary.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ use super::directives::{AUX_BIN, AUX_BUILD, AUX_CODEGEN_BACKEND, AUX_CRATE, PROC
77
use crate::common::Config;
88
use crate::directives::DirectiveLine;
99

10+
/// The value of an `aux-crate` directive.
11+
#[derive(Clone, Debug, Default)]
12+
pub struct AuxCrate {
13+
/// With `aux-crate: foo=bar.rs` this will be `foo`.
14+
/// With `aux-crate: noprelude:foo=bar.rs` this will be `noprelude:foo`.
15+
pub name: String,
16+
/// With `aux-crate: foo=bar.rs` this will be `bar.rs`.
17+
pub path: String,
18+
}
19+
1020
/// Properties parsed from `aux-*` test directives.
1121
#[derive(Clone, Debug, Default)]
1222
pub(crate) struct AuxProps {
@@ -17,7 +27,7 @@ pub(crate) struct AuxProps {
1727
pub(crate) bins: Vec<String>,
1828
/// Similar to `builds`, but a list of NAME=somelib.rs of dependencies
1929
/// to build and pass with the `--extern` flag.
20-
pub(crate) crates: Vec<(String, String)>,
30+
pub(crate) crates: Vec<AuxCrate>,
2131
/// Same as `builds`, but for proc-macros.
2232
pub(crate) proc_macros: Vec<String>,
2333
/// Similar to `builds`, but also uses the resulting dylib as a
@@ -34,7 +44,7 @@ impl AuxProps {
3444
iter::empty()
3545
.chain(builds.iter().map(String::as_str))
3646
.chain(bins.iter().map(String::as_str))
37-
.chain(crates.iter().map(|(_, path)| path.as_str()))
47+
.chain(crates.iter().map(|c| c.path.as_str()))
3848
.chain(proc_macros.iter().map(String::as_str))
3949
.chain(codegen_backend.iter().map(String::as_str))
4050
}
@@ -63,10 +73,10 @@ pub(super) fn parse_and_update_aux(
6373
}
6474
}
6575

66-
fn parse_aux_crate(r: String) -> (String, String) {
76+
fn parse_aux_crate(r: String) -> AuxCrate {
6777
let mut parts = r.trim().splitn(2, '=');
68-
(
69-
parts.next().expect("missing aux-crate name (e.g. log=log.rs)").to_string(),
70-
parts.next().expect("missing aux-crate value (e.g. log=log.rs)").to_string(),
71-
)
78+
AuxCrate {
79+
name: parts.next().expect("missing aux-crate name (e.g. log=log.rs)").to_string(),
80+
path: parts.next().expect("missing aux-crate value (e.g. log=log.rs)").to_string(),
81+
}
7282
}

src/tools/compiletest/src/runtest.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::common::{
1818
TestSuite, UI_EXTENSIONS, UI_FIXED, UI_RUN_STDERR, UI_RUN_STDOUT, UI_STDERR, UI_STDOUT, UI_SVG,
1919
UI_WINDOWS_SVG, expected_output_path, incremental_dir, output_base_dir, output_base_name,
2020
};
21-
use crate::directives::TestProps;
21+
use crate::directives::{AuxCrate, TestProps};
2222
use crate::errors::{Error, ErrorKind, load_errors};
2323
use crate::output_capture::ConsoleOut;
2424
use crate::read2::{Truncated, read2_abbreviated};
@@ -1285,9 +1285,9 @@ impl<'test> TestCx<'test> {
12851285
}
12861286
};
12871287

1288-
for (aux_name, aux_path) in &self.props.aux.crates {
1289-
let aux_type = self.build_auxiliary(&aux_path, &aux_dir, None);
1290-
add_extern(rustc, aux_name, aux_path, aux_type);
1288+
for AuxCrate { name, path } in &self.props.aux.crates {
1289+
let aux_type = self.build_auxiliary(&path, &aux_dir, None);
1290+
add_extern(rustc, name, path, aux_type);
12911291
}
12921292

12931293
for proc_macro in &self.props.aux.proc_macros {

0 commit comments

Comments
 (0)