Skip to content

Commit 0637dc0

Browse files
committed
Edition-2018-fied code and fixed a lot of clippy lints
Signed-off-by: Daniel Egger <[email protected]>
1 parent babadce commit 0637dc0

File tree

4 files changed

+29
-36
lines changed

4 files changed

+29
-36
lines changed

ci/svd2rust-regress/Cargo.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
[package]
2+
edition = "2018"
23
name = "svd2rust-regress"
34
version = "0.1.0"
45
authors = ["James Munns <[email protected]>", "The svd2rust developers"]
56

67
[dependencies]
7-
reqwest = "0.8"
8-
rayon = "1.0"
8+
reqwest = "0.9"
9+
rayon = "1.1"
910
structopt = "0.2"
10-
error-chain = "0.11"
11-
inflections = "1.1.0"
11+
error-chain = "0.12"
12+
inflections = "1.1"

ci/svd2rust-regress/src/main.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
#[macro_use]
22
extern crate error_chain;
3-
extern crate inflections;
4-
extern crate rayon;
5-
extern crate reqwest;
6-
extern crate structopt;
73

84
mod errors;
95
mod svd_test;
@@ -176,8 +172,7 @@ fn main() {
176172
// FIXME: Use Option::filter instead when stable, rust-lang/rust#45860
177173
if default_rustfmt
178174
.iter()
179-
.filter(|p| p.is_file())
180-
.next()
175+
.find(|p| p.is_file())
181176
.is_none()
182177
{
183178
panic!("No rustfmt found");
@@ -264,8 +259,8 @@ fn main() {
264259
Err(e) => {
265260
any_fails.store(true, Ordering::Release);
266261
let additional_info = if opt.verbose > 0 {
267-
match e.kind() {
268-
&errors::ErrorKind::ProcessFailed(_, _, Some(ref stderr), ref previous_processes_stderr) => {
262+
match *e.kind() {
263+
errors::ErrorKind::ProcessFailed(_, _, Some(ref stderr), ref previous_processes_stderr) => {
269264
let mut buf = String::new();
270265
if opt.verbose > 1 {
271266
for stderr in previous_processes_stderr {

ci/svd2rust-regress/src/svd_test.rs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use errors::*;
1+
use crate::errors::*;
22
use reqwest;
33
use std::fs::{self, File, OpenOptions};
44
use std::io::prelude::*;
55
use std::path::PathBuf;
66
use std::process::{Command, Output};
7-
use tests::TestCase;
7+
use crate::tests::TestCase;
88

99
static CRATES_ALL: &[&str] = &["bare-metal = \"0.2.0\"", "vcell = \"0.1.0\""];
1010
static CRATES_MSP430: &[&str] = &["msp430 = \"0.1.0\""];
@@ -42,7 +42,7 @@ trait CommandHelper {
4242
name: &str,
4343
stdout: Option<&PathBuf>,
4444
stderr: Option<&PathBuf>,
45-
previous_processes_stderr: &Vec<PathBuf>,
45+
previous_processes_stderr: &[PathBuf],
4646
) -> Result<()>;
4747
}
4848

@@ -53,7 +53,7 @@ impl CommandHelper for Output {
5353
name: &str,
5454
stdout: Option<&PathBuf>,
5555
stderr: Option<&PathBuf>,
56-
previous_processes_stderr: &Vec<PathBuf>,
56+
previous_processes_stderr: &[PathBuf],
5757
) -> Result<()> {
5858
if let Some(out) = stdout {
5959
let out_payload = String::from_utf8_lossy(&self.stdout);
@@ -70,7 +70,7 @@ impl CommandHelper for Output {
7070
ErrorKind::ProcessFailed(name.into(),
7171
stdout.cloned(),
7272
stderr.cloned(),
73-
previous_processes_stderr.clone(),
73+
previous_processes_stderr.to_vec(),
7474
).into()
7575
);
7676
}
@@ -109,7 +109,7 @@ pub fn test(t: &TestCase, bin_path: &PathBuf, rustfmt_bin_path: Option<&PathBuf>
109109
.arg(&chip_dir)
110110
.output()
111111
.chain_err(|| "Failed to cargo init")?
112-
.capture_outputs(true, "cargo init", None, None, &vec![])?;
112+
.capture_outputs(true, "cargo init", None, None, &[])?;
113113

114114
// Add some crates to the Cargo.toml of our new project
115115
let svd_toml = path_helper_base(&chip_dir, &["Cargo.toml"]);
@@ -119,7 +119,7 @@ pub fn test(t: &TestCase, bin_path: &PathBuf, rustfmt_bin_path: Option<&PathBuf>
119119
.open(svd_toml)
120120
.chain_err(|| "Failed to open Cargo.toml for appending")?;
121121

122-
use tests::Architecture::*;
122+
use crate::tests::Architecture::*;
123123
let crates = CRATES_ALL
124124
.iter()
125125
.chain(match &t.arch {
@@ -154,10 +154,10 @@ pub fn test(t: &TestCase, bin_path: &PathBuf, rustfmt_bin_path: Option<&PathBuf>
154154
// If the architecture is cortex-m we move the generated lib.rs file to src/
155155
let lib_rs_file = path_helper_base(&chip_dir, &["src", "lib.rs"]);
156156
let svd2rust_err_file = path_helper_base(&chip_dir, &["svd2rust.err.log"]);
157-
let target = match &t.arch {
158-
&CortexM => "cortex-m",
159-
&Msp430 => "msp430",
160-
&RiscV => "riscv",
157+
let target = match t.arch {
158+
CortexM => "cortex-m",
159+
Msp430 => "msp430",
160+
RiscV => "riscv",
161161
};
162162
let mut svd2rust_bin = Command::new(bin_path);
163163
if nightly {
@@ -175,16 +175,13 @@ pub fn test(t: &TestCase, bin_path: &PathBuf, rustfmt_bin_path: Option<&PathBuf>
175175
"svd2rust",
176176
if t.arch != CortexM { Some(&lib_rs_file) } else { None }, // use Option.filter
177177
Some(&svd2rust_err_file),
178-
&vec![],
178+
&[],
179179
)?;
180180
process_stderr_paths.push(svd2rust_err_file);
181181

182-
match &t.arch {
183-
&CortexM => {
184-
// TODO: Give error the path to stderr
185-
fs::rename(path_helper_base(&chip_dir, &["lib.rs"]), &lib_rs_file).chain_err(|| "While moving lib.rs file")?
186-
}
187-
_ => (),
182+
if let CortexM = t.arch {
183+
// TODO: Give error the path to stderr
184+
fs::rename(path_helper_base(&chip_dir, &["lib.rs"]), &lib_rs_file).chain_err(|| "While moving lib.rs file")?
188185
}
189186

190187
let rustfmt_err_file = path_helper_base(&chip_dir, &["rustfmt.err.log"]);

ci/svd2rust-regress/src/tests.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ use self::RunWhen::*;
7474

7575
/// List of chars that some vendors use in their peripheral/field names but
7676
/// that are not valid in Rust ident
77-
const BLACKLIST_CHARS: &'static [char] = &['(', ')', '[', ']'];
77+
const BLACKLIST_CHARS: &[char] = &['(', ')', '[', ']'];
7878

7979
/// Lovingly stolen from `svd2rust`. Probably could be `Cow`
8080
pub trait ToSanitizedSnakeCase {
@@ -96,16 +96,16 @@ impl ToSanitizedSnakeCase for str {
9696

9797
match s.chars().next().unwrap_or('\0') {
9898
'0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' => {
99-
String::from(format!("_{}", s.to_snake_case()))
99+
format!("_{}", s.to_snake_case())
100100
}
101101
_ => {
102102
keywords! {
103103
s,
104104
abstract,
105105
alignof,
106106
as,
107-
async,
108-
await,
107+
r#async,
108+
r#await,
109109
become,
110110
box,
111111
break,
@@ -145,7 +145,7 @@ impl ToSanitizedSnakeCase for str {
145145
super,
146146
trait,
147147
true,
148-
try,
148+
r#try,
149149
type,
150150
typeof,
151151
unsafe,
@@ -166,7 +166,7 @@ impl ToSanitizedSnakeCase for str {
166166
}
167167

168168
// NOTE: All chip names must be unique!
169-
pub const TESTS: &'static [&'static TestCase] = &[
169+
pub const TESTS: &[&TestCase] = &[
170170
// BAD-SVD missing resetValue
171171
&TestCase {
172172
arch: CortexM,

0 commit comments

Comments
 (0)