Skip to content

Commit 061edfe

Browse files
committed
Add #[must_use] attribute to several command-related methods
This should make it harder to accidentally forget to use results of methods on `BootstrapCommand` and `CommandStatus`.
1 parent f933d78 commit 061edfe

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Diff for: src/bootstrap/src/utils/exec.rs

+12
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,17 @@ impl BootstrapCommand {
109109
self
110110
}
111111

112+
#[must_use]
112113
pub fn delay_failure(self) -> Self {
113114
Self { failure_behavior: BehaviorOnFailure::DelayFail, ..self }
114115
}
115116

117+
#[must_use]
116118
pub fn fail_fast(self) -> Self {
117119
Self { failure_behavior: BehaviorOnFailure::Exit, ..self }
118120
}
119121

122+
#[must_use]
120123
pub fn allow_failure(self) -> Self {
121124
Self { failure_behavior: BehaviorOnFailure::Ignore, ..self }
122125
}
@@ -127,11 +130,13 @@ impl BootstrapCommand {
127130
}
128131

129132
/// Capture all output of the command, do not print it.
133+
#[must_use]
130134
pub fn capture(self) -> Self {
131135
Self { stdout: OutputMode::Capture, stderr: OutputMode::Capture, ..self }
132136
}
133137

134138
/// Capture stdout of the command, do not print it.
139+
#[must_use]
135140
pub fn capture_stdout(self) -> Self {
136141
Self { stdout: OutputMode::Capture, ..self }
137142
}
@@ -178,36 +183,43 @@ pub struct CommandOutput {
178183
}
179184

180185
impl CommandOutput {
186+
#[must_use]
181187
pub fn did_not_start() -> Self {
182188
Self { status: CommandStatus::DidNotStart, stdout: vec![], stderr: vec![] }
183189
}
184190

191+
#[must_use]
185192
pub fn is_success(&self) -> bool {
186193
match self.status {
187194
CommandStatus::Finished(status) => status.success(),
188195
CommandStatus::DidNotStart => false,
189196
}
190197
}
191198

199+
#[must_use]
192200
pub fn is_failure(&self) -> bool {
193201
!self.is_success()
194202
}
195203

204+
#[must_use]
196205
pub fn status(&self) -> Option<ExitStatus> {
197206
match self.status {
198207
CommandStatus::Finished(status) => Some(status),
199208
CommandStatus::DidNotStart => None,
200209
}
201210
}
202211

212+
#[must_use]
203213
pub fn stdout(&self) -> String {
204214
String::from_utf8(self.stdout.clone()).expect("Cannot parse process stdout as UTF-8")
205215
}
206216

217+
#[must_use]
207218
pub fn stdout_if_ok(&self) -> Option<String> {
208219
if self.is_success() { Some(self.stdout()) } else { None }
209220
}
210221

222+
#[must_use]
211223
pub fn stderr(&self) -> String {
212224
String::from_utf8(self.stderr.clone()).expect("Cannot parse process stderr as UTF-8")
213225
}

Diff for: src/bootstrap/src/utils/helpers.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ pub fn check_cfg_arg(name: &str, values: Option<&[&str]>) -> String {
499499
/// Whenever a git invocation is needed, this function should be preferred over
500500
/// manually building a git `BootstrapCommand`. This approach allows us to manage
501501
/// bootstrap-specific needs/hacks from a single source, rather than applying them on next to every
502-
/// `BootstrapCommand::new("git")`, which is painful to ensure that the required change is applied
502+
/// git command creation, which is painful to ensure that the required change is applied
503503
/// on each one of them correctly.
504504
pub fn git(source_dir: Option<&Path>) -> BootstrapCommand {
505505
let mut git = command("git");

0 commit comments

Comments
 (0)