Skip to content

Commit d53b0ff

Browse files
committed
Auto merge of rust-lang#134724 - onur-ozkan:type-improvements, r=jieyouxu
improve type mutation for certain structures self-explanatory
2 parents 32c8a9f + 6b2fd4f commit d53b0ff

File tree

4 files changed

+34
-53
lines changed

4 files changed

+34
-53
lines changed

src/bootstrap/src/core/build_steps/check.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,13 @@ pub struct Std {
3131
}
3232

3333
impl Std {
34-
pub fn new_with_build_kind(target: TargetSelection, kind: Option<Kind>) -> Self {
35-
Self { target, crates: vec![], override_build_kind: kind }
34+
pub fn new(target: TargetSelection) -> Self {
35+
Self { target, crates: vec![], override_build_kind: None }
36+
}
37+
38+
pub fn build_kind(mut self, kind: Option<Kind>) -> Self {
39+
self.override_build_kind = kind;
40+
self
3641
}
3742
}
3843

@@ -167,20 +172,17 @@ pub struct Rustc {
167172

168173
impl Rustc {
169174
pub fn new(target: TargetSelection, builder: &Builder<'_>) -> Self {
170-
Self::new_with_build_kind(target, builder, None)
171-
}
172-
173-
pub fn new_with_build_kind(
174-
target: TargetSelection,
175-
builder: &Builder<'_>,
176-
kind: Option<Kind>,
177-
) -> Self {
178175
let crates = builder
179176
.in_tree_crates("rustc-main", Some(target))
180177
.into_iter()
181178
.map(|krate| krate.name.to_string())
182179
.collect();
183-
Self { target, crates, override_build_kind: kind }
180+
Self { target, crates, override_build_kind: None }
181+
}
182+
183+
pub fn build_kind(mut self, build_kind: Option<Kind>) -> Self {
184+
self.override_build_kind = build_kind;
185+
self
184186
}
185187
}
186188

@@ -216,7 +218,7 @@ impl Step for Rustc {
216218
builder.ensure(crate::core::build_steps::compile::Std::new(compiler, compiler.host));
217219
builder.ensure(crate::core::build_steps::compile::Std::new(compiler, target));
218220
} else {
219-
builder.ensure(Std::new_with_build_kind(target, self.override_build_kind));
221+
builder.ensure(Std::new(target).build_kind(self.override_build_kind));
220222
}
221223

222224
let mut cargo = builder::Cargo::new(

src/bootstrap/src/core/build_steps/clippy.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ impl Step for Rustc {
215215
builder.ensure(compile::Std::new(compiler, compiler.host));
216216
builder.ensure(compile::Std::new(compiler, target));
217217
} else {
218-
builder.ensure(check::Std::new_with_build_kind(target, Some(Kind::Check)));
218+
builder.ensure(check::Std::new(target).build_kind(Some(Kind::Check)));
219219
}
220220

221221
let mut cargo = builder::Cargo::new(
@@ -285,7 +285,7 @@ macro_rules! lint_any {
285285
let compiler = builder.compiler(builder.top_stage, builder.config.build);
286286
let target = self.target;
287287

288-
builder.ensure(check::Rustc::new_with_build_kind(target, builder, Some(Kind::Check)));
288+
builder.ensure(check::Rustc::new(target, builder).build_kind(Some(Kind::Check)));
289289

290290
let cargo = prepare_tool_cargo(
291291
builder,

src/bootstrap/src/core/build_steps/compile.rs

+10-31
Original file line numberDiff line numberDiff line change
@@ -57,41 +57,20 @@ impl Std {
5757
}
5858
}
5959

60-
pub fn force_recompile(compiler: Compiler, target: TargetSelection) -> Self {
61-
Self {
62-
target,
63-
compiler,
64-
crates: Default::default(),
65-
force_recompile: true,
66-
extra_rust_args: &[],
67-
is_for_mir_opt_tests: false,
68-
}
60+
pub fn force_recompile(mut self, force_recompile: bool) -> Self {
61+
self.force_recompile = force_recompile;
62+
self
6963
}
7064

71-
pub fn new_for_mir_opt_tests(compiler: Compiler, target: TargetSelection) -> Self {
72-
Self {
73-
target,
74-
compiler,
75-
crates: Default::default(),
76-
force_recompile: false,
77-
extra_rust_args: &[],
78-
is_for_mir_opt_tests: true,
79-
}
65+
#[allow(clippy::wrong_self_convention)]
66+
pub fn is_for_mir_opt_tests(mut self, is_for_mir_opt_tests: bool) -> Self {
67+
self.is_for_mir_opt_tests = is_for_mir_opt_tests;
68+
self
8069
}
8170

82-
pub fn new_with_extra_rust_args(
83-
compiler: Compiler,
84-
target: TargetSelection,
85-
extra_rust_args: &'static [&'static str],
86-
) -> Self {
87-
Self {
88-
target,
89-
compiler,
90-
crates: Default::default(),
91-
force_recompile: false,
92-
extra_rust_args,
93-
is_for_mir_opt_tests: false,
94-
}
71+
pub fn extra_rust_args(mut self, extra_rust_args: &'static [&'static str]) -> Self {
72+
self.extra_rust_args = extra_rust_args;
73+
self
9574
}
9675

9776
fn copy_extra_objects(

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -1718,7 +1718,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
17181718

17191719
// ensure that `libproc_macro` is available on the host.
17201720
if suite == "mir-opt" {
1721-
builder.ensure(compile::Std::new_for_mir_opt_tests(compiler, compiler.host));
1721+
builder.ensure(compile::Std::new(compiler, compiler.host).is_for_mir_opt_tests(true));
17221722
} else {
17231723
builder.ensure(compile::Std::new(compiler, compiler.host));
17241724
}
@@ -1731,7 +1731,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
17311731
let mut cmd = builder.tool_cmd(Tool::Compiletest);
17321732

17331733
if suite == "mir-opt" {
1734-
builder.ensure(compile::Std::new_for_mir_opt_tests(compiler, target));
1734+
builder.ensure(compile::Std::new(compiler, target).is_for_mir_opt_tests(true));
17351735
} else {
17361736
builder.ensure(compile::Std::new(compiler, target));
17371737
}
@@ -2737,7 +2737,7 @@ impl Step for Crate {
27372737

27382738
// Prepare sysroot
27392739
// See [field@compile::Std::force_recompile].
2740-
builder.ensure(compile::Std::force_recompile(compiler, compiler.host));
2740+
builder.ensure(compile::Std::new(compiler, compiler.host).force_recompile(true));
27412741

27422742
// If we're not doing a full bootstrap but we're testing a stage2
27432743
// version of libstd, then what we're actually testing is the libstd
@@ -2781,7 +2781,7 @@ impl Step for Crate {
27812781
} else {
27822782
// Also prepare a sysroot for the target.
27832783
if builder.config.build != target {
2784-
builder.ensure(compile::Std::force_recompile(compiler, target));
2784+
builder.ensure(compile::Std::new(compiler, target).force_recompile(true));
27852785
builder.ensure(RemoteCopyLibs { compiler, target });
27862786
}
27872787

@@ -3557,10 +3557,10 @@ impl Step for CodegenGCC {
35573557
let compiler = self.compiler;
35583558
let target = self.target;
35593559

3560-
builder.ensure(compile::Std::new_with_extra_rust_args(compiler, target, &[
3561-
"-Csymbol-mangling-version=v0",
3562-
"-Cpanic=abort",
3563-
]));
3560+
builder.ensure(
3561+
compile::Std::new(compiler, target)
3562+
.extra_rust_args(&["-Csymbol-mangling-version=v0", "-Cpanic=abort"]),
3563+
);
35643564

35653565
// If we're not doing a full bootstrap but we're testing a stage2
35663566
// version of libstd, then what we're actually testing is the libstd

0 commit comments

Comments
 (0)