Skip to content

Commit 1ecf818

Browse files
committed
fix clippy lints
1 parent 67bc835 commit 1ecf818

File tree

3 files changed

+55
-63
lines changed

3 files changed

+55
-63
lines changed

src/github.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ impl<'a> CommitsQuery<'a> {
7777
}
7878

7979
const PER_PAGE: usize = 100;
80-
const OWNER: &'static str = "rust-lang";
81-
const REPO: &'static str = "rust";
80+
const OWNER: &str = "rust-lang";
81+
const REPO: &str = "rust";
8282

8383
trait ToUrl {
8484
fn url(&self) -> String;
@@ -202,8 +202,8 @@ fn parse_paged_elems<Elem: for<'a> serde::Deserialize<'a>>(
202202
// parse the JSON into an array of the expected Elem type
203203
let elems: Vec<Elem> = response.json()?;
204204

205-
// if `elems` is empty, then we've run out of useful pages to lookup.
206-
if elems.len() == 0 {
205+
if elems.is_empty() {
206+
// we've run out of useful pages to lookup
207207
return Ok(Loop::Break);
208208
}
209209

src/main.rs

Lines changed: 49 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,9 @@ impl FromStr for Bound {
188188
}
189189

190190
impl Bound {
191-
fn sha(self) -> Result<String, Error> {
191+
fn sha(&self) -> Result<String, Error> {
192192
match self {
193-
Bound::Commit(commit) => Ok(commit),
193+
Bound::Commit(commit) => Ok(commit.clone()),
194194
Bound::Date(date) => {
195195
let date_str = date.format(YYYY_MM_DD);
196196
let url = format!(
@@ -213,7 +213,7 @@ impl Bound {
213213
}
214214
}
215215

216-
fn as_commit(self) -> Result<Self, Error> {
216+
fn as_commit(&self) -> Result<Self, Error> {
217217
self.sha().map(Bound::Commit)
218218
}
219219
}
@@ -246,31 +246,29 @@ impl Config {
246246

247247
let saw_ice = || -> bool { stderr_utf8.contains("error: internal compiler error") };
248248

249-
let input = (self.output_processing_mode(), status.success());
249+
let input = (self.regress_on(), status.success());
250250
let result = match input {
251-
(OutputProcessingMode::RegressOnErrorStatus, true) => TestOutcome::Baseline,
252-
(OutputProcessingMode::RegressOnErrorStatus, false) => TestOutcome::Regressed,
253-
254-
(OutputProcessingMode::RegressOnSuccessStatus, true) => TestOutcome::Regressed,
255-
(OutputProcessingMode::RegressOnSuccessStatus, false) => TestOutcome::Baseline,
256-
257-
(OutputProcessingMode::RegressOnIceAlone, _) => {
251+
(RegressOn::ErrorStatus, true) => TestOutcome::Baseline,
252+
(RegressOn::ErrorStatus, false) => TestOutcome::Regressed,
253+
(RegressOn::SuccessStatus, true) => TestOutcome::Regressed,
254+
(RegressOn::SuccessStatus, false) => TestOutcome::Baseline,
255+
(RegressOn::IceAlone, _) => {
258256
if saw_ice() {
259257
TestOutcome::Regressed
260258
} else {
261259
TestOutcome::Baseline
262260
}
263261
}
264-
(OutputProcessingMode::RegressOnNotIce, _) => {
262+
(RegressOn::NotIce, _) => {
265263
if saw_ice() {
266264
TestOutcome::Baseline
267265
} else {
268266
TestOutcome::Regressed
269267
}
270268
}
271269

272-
(OutputProcessingMode::RegressOnNonCleanError, true) => TestOutcome::Regressed,
273-
(OutputProcessingMode::RegressOnNonCleanError, false) => {
270+
(RegressOn::NonCleanError, true) => TestOutcome::Regressed,
271+
(RegressOn::NonCleanError, false) => {
274272
if saw_ice() {
275273
TestOutcome::Regressed
276274
} else {
@@ -285,22 +283,22 @@ impl Config {
285283
result
286284
}
287285

288-
fn output_processing_mode(&self) -> OutputProcessingMode {
286+
fn regress_on(&self) -> RegressOn {
289287
match self.args.regress.as_str() {
290-
"error" => OutputProcessingMode::RegressOnErrorStatus,
291-
"non-error" => OutputProcessingMode::RegressOnNonCleanError,
292-
"ice" => OutputProcessingMode::RegressOnIceAlone,
293-
"non-ice" => OutputProcessingMode::RegressOnNotIce,
294-
"success" => OutputProcessingMode::RegressOnSuccessStatus,
288+
"error" => RegressOn::ErrorStatus,
289+
"non-error" => RegressOn::NonCleanError,
290+
"ice" => RegressOn::IceAlone,
291+
"non-ice" => RegressOn::NotIce,
292+
"success" => RegressOn::SuccessStatus,
295293
setting => panic!("Unknown --regress setting: {:?}", setting),
296294
}
297295
}
298296
}
299297

300298
#[derive(Copy, Clone, PartialEq, Eq, Debug, StructOpt)]
301299
/// Customize what is treated as regression.
302-
enum OutputProcessingMode {
303-
/// `RegressOnErrorStatus`: Marks test outcome as `Regressed` if and only if
300+
enum RegressOn {
301+
/// `ErrorStatus`: Marks test outcome as `Regressed` if and only if
304302
/// the `rustc` process reports a non-success status. This corresponds to
305303
/// when `rustc` has an internal compiler error (ICE) or when it detects an
306304
/// error in the input program.
@@ -309,58 +307,54 @@ enum OutputProcessingMode {
309307
/// thus the default setting.
310308
///
311309
/// You explicitly opt into this seting via `--regress=error`.
312-
RegressOnErrorStatus,
310+
ErrorStatus,
313311

314-
/// `RegressOnSuccessStatus`: Marks test outcome as `Regressed` if and only
312+
/// `SuccessStatus`: Marks test outcome as `Regressed` if and only
315313
/// if the `rustc` process reports a success status. This corresponds to
316314
/// when `rustc` believes it has successfully compiled the program. This
317315
/// covers the use case for when you want to bisect to see when a bug was
318316
/// fixed.
319317
///
320318
/// You explicitly opt into this seting via `--regress=success`.
321-
RegressOnSuccessStatus,
319+
SuccessStatus,
322320

323-
/// `RegressOnIceAlone`: Marks test outcome as `Regressed` if and only if
321+
/// `IceAlone`: Marks test outcome as `Regressed` if and only if
324322
/// the `rustc` process issues a diagnostic indicating that an internal
325323
/// compiler error (ICE) occurred. This covers the use case for when you
326324
/// want to bisect to see when an ICE was introduced pon a codebase that is
327325
/// meant to produce a clean error.
328326
///
329327
/// You explicitly opt into this seting via `--regress=ice`.
330-
RegressOnIceAlone,
328+
IceAlone,
331329

332-
/// `RegressOnNotIce`: Marks test outcome as `Regressed` if and only if
330+
/// `NotIce`: Marks test outcome as `Regressed` if and only if
333331
/// the `rustc` process does not issue a diagnostic indicating that an
334332
/// internal compiler error (ICE) occurred. This covers the use case for
335333
/// when you want to bisect to see when an ICE was fixed.
336334
///
337335
/// You explicitly opt into this setting via `--regress=non-ice`
338-
RegressOnNotIce,
336+
NotIce,
339337

340-
/// `RegressOnNonCleanError`: Marks test outcome as `Baseline` if and only
338+
/// `NonCleanError`: Marks test outcome as `Baseline` if and only
341339
/// if the `rustc` process reports error status and does not issue any
342340
/// diagnostic indicating that an internal compiler error (ICE) occurred.
343341
/// This is the use case if the regression is a case where an ill-formed
344342
/// program has stopped being properly rejected by the compiler.
345343
///
346-
/// (The main difference between this case and `RegressOnSuccessStatus` is
347-
/// the handling of ICE: `RegressOnSuccessStatus` assumes that ICE should be
348-
/// considered baseline; `RegressOnNonCleanError` assumes ICE should be
344+
/// (The main difference between this case and `SuccessStatus` is
345+
/// the handling of ICE: `SuccessStatus` assumes that ICE should be
346+
/// considered baseline; `NonCleanError` assumes ICE should be
349347
/// considered a sign of a regression.)
350348
///
351349
/// You explicitly opt into this seting via `--regress=non-error`.
352-
RegressOnNonCleanError,
350+
NonCleanError,
353351
}
354352

355-
impl OutputProcessingMode {
353+
impl RegressOn {
356354
fn must_process_stderr(&self) -> bool {
357355
match self {
358-
OutputProcessingMode::RegressOnErrorStatus
359-
| OutputProcessingMode::RegressOnSuccessStatus => false,
360-
361-
OutputProcessingMode::RegressOnNonCleanError
362-
| OutputProcessingMode::RegressOnIceAlone
363-
| OutputProcessingMode::RegressOnNotIce => true,
356+
RegressOn::ErrorStatus | RegressOn::SuccessStatus => false,
357+
RegressOn::NonCleanError | RegressOn::IceAlone | RegressOn::NotIce => true,
364358
}
365359
}
366360
}
@@ -386,7 +380,7 @@ impl CommandTemplate {
386380
assert!(!self.0.is_empty());
387381
let mut s = self.0[0].to_string();
388382
for arg in &self.0[1..] {
389-
s.push_str(" ");
383+
s.push(' ');
390384
s.push_str(arg);
391385
}
392386
s
@@ -490,7 +484,7 @@ impl Config {
490484
}
491485

492486
let repo_access: Box<dyn RustRepositoryAccessor>;
493-
repo_access = match args.access.as_ref().map(|x| x.as_str()) {
487+
repo_access = match args.access.as_deref() {
494488
None | Some("checkout") => Box::new(AccessViaLocalGit),
495489
Some("github") => Box::new(AccessViaGithub),
496490
Some(other) => bail!("unknown access argument: {}", other),
@@ -625,7 +619,7 @@ fn bisect(cfg: &Config, client: &Client) -> Result<(), Error> {
625619

626620
fn searched_range(
627621
cfg: &Config,
628-
searched_toolchains: &Vec<Toolchain>,
622+
searched_toolchains: &[Toolchain],
629623
) -> (ToolchainSpec, ToolchainSpec) {
630624
let first_toolchain = searched_toolchains.first().unwrap().spec.clone();
631625
let last_toolchain = searched_toolchains.last().unwrap().spec.clone();
@@ -912,14 +906,13 @@ fn bisect_to_regression(
912906
cfg: &Config,
913907
client: &Client,
914908
dl_spec: &DownloadParams,
915-
) -> Result<usize, InstallError> {
916-
let found = least_satisfying(&toolchains, |t| {
909+
) -> usize {
910+
least_satisfying(&toolchains, |t| {
917911
match install_and_test(&t, &cfg, &client, &dl_spec) {
918912
Ok(r) => r,
919913
Err(_) => Satisfies::Unknown,
920914
}
921-
});
922-
Ok(found)
915+
})
923916
}
924917

925918
fn get_start_date(cfg: &Config) -> chrono::Date<Utc> {
@@ -933,12 +926,10 @@ fn get_start_date(cfg: &Config) -> chrono::Date<Utc> {
933926
fn get_end_date(cfg: &Config) -> chrono::Date<Utc> {
934927
if let Some(Bound::Date(date)) = cfg.args.end {
935928
date
929+
} else if let Some(date) = Toolchain::default_nightly() {
930+
date
936931
} else {
937-
if let Some(date) = Toolchain::default_nightly() {
938-
date
939-
} else {
940-
chrono::Utc::now().date()
941-
}
932+
chrono::Utc::now().date()
942933
}
943934
}
944935

@@ -1043,7 +1034,8 @@ fn bisect_nightlies(cfg: &Config, client: &Client) -> Result<BisectionResult, Er
10431034
}
10441035
}
10451036

1046-
let first_success = first_success.ok_or(format_err!("could not find a nightly that built"))?;
1037+
let first_success =
1038+
first_success.ok_or_else(|| format_err!("could not find a nightly that built"))?;
10471039

10481040
// confirm that the end of the date range has the regression
10491041
let mut t_end = Toolchain {
@@ -1076,7 +1068,7 @@ fn bisect_nightlies(cfg: &Config, client: &Client) -> Result<BisectionResult, Er
10761068
ToolchainSpec::Nightly { date: last_failure },
10771069
);
10781070

1079-
let found = bisect_to_regression(&toolchains, &cfg, client, &dl_spec)?;
1071+
let found = bisect_to_regression(&toolchains, &cfg, client, &dl_spec);
10801072

10811073
Ok(BisectionResult {
10821074
dl_spec,
@@ -1158,7 +1150,7 @@ fn bisect_ci_via(
11581150
" commit[{}] {}: {}",
11591151
j,
11601152
commit.date.date(),
1161-
commit.summary.split("\n").next().unwrap()
1153+
commit.summary.split('\n').next().unwrap()
11621154
)
11631155
}
11641156

@@ -1242,7 +1234,7 @@ fn bisect_ci_in_commits(
12421234
}
12431235
}
12441236

1245-
let found = bisect_to_regression(&toolchains, &cfg, client, &dl_spec)?;
1237+
let found = bisect_to_regression(&toolchains, &cfg, client, &dl_spec);
12461238

12471239
Ok(BisectionResult {
12481240
searched: toolchains,

src/toolchains.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl Toolchain {
112112
}
113113

114114
static DATE: OnceCell<Option<GitDate>> = OnceCell::new();
115-
*(DATE.get_or_init(|| inner()))
115+
*(DATE.get_or_init(inner))
116116
}
117117

118118
pub(crate) fn is_current_nightly(&self) -> bool {
@@ -339,7 +339,7 @@ impl Toolchain {
339339
cmd.env("CARGO_TARGET_DIR", format!("target-{}", self.rustup_name()));
340340

341341
// let `cmd` capture stderr for us to process afterward.
342-
let must_capture_output = cfg.output_processing_mode().must_process_stderr();
342+
let must_capture_output = cfg.regress_on().must_process_stderr();
343343
let emit_output = cfg.args.emit_cargo_output() || cfg.args.prompt;
344344

345345
let default_stdio = || {

0 commit comments

Comments
 (0)