Skip to content

Commit 689d696

Browse files
Fix clippy warnings
1 parent 373a6f8 commit 689d696

File tree

8 files changed

+43
-38
lines changed

8 files changed

+43
-38
lines changed

src/db/file.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,21 @@ pub fn add_path_into_database<P: AsRef<Path>>(
2929
) -> Result<(Value, CompressionAlgorithms)> {
3030
let (file_list, algorithms) = storage.store_all(prefix, path.as_ref())?;
3131
Ok((
32-
file_list_to_json(file_list.into_iter().collect())?,
32+
file_list_to_json(file_list.into_iter().collect()),
3333
algorithms,
3434
))
3535
}
3636

37-
fn file_list_to_json(file_list: Vec<(PathBuf, String)>) -> Result<Value> {
38-
let file_list: Vec<_> = file_list
39-
.into_iter()
40-
.map(|(path, name)| {
41-
Value::Array(vec![
42-
Value::String(name),
43-
Value::String(path.into_os_string().into_string().unwrap()),
44-
])
45-
})
46-
.collect();
47-
48-
Ok(Value::Array(file_list))
37+
fn file_list_to_json(file_list: Vec<(PathBuf, String)>) -> Value {
38+
Value::Array(
39+
file_list
40+
.into_iter()
41+
.map(|(path, name)| {
42+
Value::Array(vec![
43+
Value::String(name),
44+
Value::String(path.into_os_string().into_string().unwrap()),
45+
])
46+
})
47+
.collect(),
48+
)
4949
}

src/docbuilder/crates.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ use failure::err_msg;
33
use serde_json::Value;
44
use std::io::prelude::*;
55
use std::io::BufReader;
6-
use std::{fs, path::PathBuf, str::FromStr};
6+
use std::{fs, path::Path, str::FromStr};
77

8-
fn crates_from_file<F>(path: &PathBuf, func: &mut F) -> Result<()>
8+
fn crates_from_file<F>(path: &Path, func: &mut F) -> Result<()>
99
where
1010
F: FnMut(&str, &str),
1111
{
@@ -61,7 +61,7 @@ where
6161
Ok(())
6262
}
6363

64-
pub fn crates_from_path<F>(path: &PathBuf, func: &mut F) -> Result<()>
64+
pub fn crates_from_path<F>(path: &Path, func: &mut F) -> Result<()>
6565
where
6666
F: FnMut(&str, &str),
6767
{

src/docbuilder/rustwide_builder.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -584,11 +584,12 @@ impl RustwideBuilder {
584584
}
585585

586586
// Add docs.rs specific arguments
587-
let mut cargo_args = Vec::new();
588-
// We know that `metadata` unconditionally passes `-Z rustdoc-map`.
589-
// Don't copy paste this, since that fact is not stable and may change in the future.
590-
cargo_args.push("-Zunstable-options".into());
591-
cargo_args.push(r#"--config=doc.extern-map.registries.crates-io="https://docs.rs""#.into());
587+
let mut cargo_args = vec![
588+
// We know that `metadata` unconditionally passes `-Z rustdoc-map`.
589+
// Don't copy paste this, since that fact is not stable and may change in the future.
590+
"-Zunstable-options".into(),
591+
r#"--config=doc.extern-map.registries.crates-io="https://docs.rs""#.into(),
592+
];
592593
if let Some(cpu_limit) = self.config.build_cpu_limit {
593594
cargo_args.push(format!("-j{}", cpu_limit));
594595
}

src/storage/mod.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl Storage {
139139
conn = db.start_connection()?;
140140
Box::new(conn.start_storage_transaction()?)
141141
}
142-
StorageBackend::S3(s3) => Box::new(s3.start_storage_transaction()?),
142+
StorageBackend::S3(s3) => Box::new(s3.start_storage_transaction()),
143143
};
144144

145145
let res = f(trans.as_mut())?;
@@ -173,7 +173,7 @@ impl Storage {
173173
let content = compress(file, alg)?;
174174
let bucket_path = Path::new(prefix).join(&file_path).to_slash().unwrap();
175175

176-
let mime = detect_mime(&file_path)?;
176+
let mime = detect_mime(&file_path);
177177
file_paths_and_mimes.insert(file_path, mime.to_string());
178178
algs.insert(alg);
179179

@@ -207,7 +207,7 @@ impl Storage {
207207
let content = content.into();
208208
let alg = CompressionAlgorithm::default();
209209
let content = compress(&*content, alg)?;
210-
let mime = detect_mime(&path)?.to_owned();
210+
let mime = detect_mime(&path).to_owned();
211211

212212
self.store_inner(std::iter::once(Ok(Blob {
213213
path,
@@ -272,11 +272,11 @@ trait StorageTransaction {
272272
fn complete(self: Box<Self>) -> Result<(), Error>;
273273
}
274274

275-
fn detect_mime(file_path: impl AsRef<Path>) -> Result<&'static str, Error> {
275+
fn detect_mime(file_path: impl AsRef<Path>) -> &'static str {
276276
let mime = mime_guess::from_path(file_path.as_ref())
277277
.first_raw()
278278
.unwrap_or("text/plain");
279-
Ok(match mime {
279+
match mime {
280280
"text/plain" | "text/troff" | "text/x-markdown" | "text/x-rust" | "text/x-toml" => {
281281
match file_path.as_ref().extension().and_then(OsStr::to_str) {
282282
Some("md") => "text/markdown",
@@ -291,7 +291,7 @@ fn detect_mime(file_path: impl AsRef<Path>) -> Result<&'static str, Error> {
291291
}
292292
"image/svg" => "image/svg+xml",
293293
_ => mime,
294-
})
294+
}
295295
}
296296

297297
#[cfg(test)]
@@ -327,7 +327,6 @@ mod test {
327327

328328
fn check_mime(path: &str, expected_mime: &str) {
329329
let detected_mime = detect_mime(Path::new(&path));
330-
let detected_mime = detected_mime.expect("no mime was given");
331330
assert_eq!(detected_mime, expected_mime);
332331
}
333332
}

src/storage/s3.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ impl S3Backend {
132132
})
133133
}
134134

135-
pub(super) fn start_storage_transaction(&self) -> Result<S3StorageTransaction, Error> {
136-
Ok(S3StorageTransaction { s3: self })
135+
pub(super) fn start_storage_transaction(&self) -> S3StorageTransaction {
136+
S3StorageTransaction { s3: self }
137137
}
138138

139139
#[cfg(test)]
@@ -146,7 +146,7 @@ impl S3Backend {
146146
panic!("safeguard to prevent deleting the production bucket");
147147
}
148148

149-
let mut transaction = Box::new(self.start_storage_transaction()?);
149+
let mut transaction = Box::new(self.start_storage_transaction());
150150
transaction.delete_prefix("")?;
151151
transaction.complete()?;
152152

src/web/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,10 +614,12 @@ mod test {
614614
Some(version)
615615
}
616616

617+
#[allow(clippy::unnecessary_wraps)]
617618
fn semver(version: &'static str) -> Option<String> {
618619
Some(version.into())
619620
}
620621

622+
#[allow(clippy::unnecessary_wraps)]
621623
fn exact(version: &'static str) -> Option<String> {
622624
Some(version.into())
623625
}

src/web/page/templates.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ fn load_rustc_resource_suffix(conn: &mut Client) -> Result<String> {
8686

8787
if let Ok(vers) = res[0].try_get::<_, Value>("value") {
8888
if let Some(vers_str) = vers.as_str() {
89-
return Ok(crate::utils::parse_rustc_version(vers_str)?);
89+
return crate::utils::parse_rustc_version(vers_str);
9090
}
9191
}
9292

@@ -200,6 +200,7 @@ impl tera::Function for ReturnValue {
200200

201201
/// Prettily format a timestamp
202202
// TODO: This can be replaced by chrono
203+
#[allow(clippy::unnecessary_wraps)]
203204
fn timeformat(value: &Value, args: &HashMap<String, Value>) -> TeraResult<Value> {
204205
let fmt = if let Some(Value::Bool(true)) = args.get("relative") {
205206
let value = DateTime::parse_from_rfc3339(value.as_str().unwrap())
@@ -235,13 +236,15 @@ fn timeformat(value: &Value, args: &HashMap<String, Value>) -> TeraResult<Value>
235236
}
236237

237238
/// Print a tera value to stdout
239+
#[allow(clippy::unnecessary_wraps)]
238240
fn dbg(value: &Value, _args: &HashMap<String, Value>) -> TeraResult<Value> {
239241
println!("{:?}", value);
240242

241243
Ok(value.clone())
242244
}
243245

244246
/// Dedent a string by removing all leading whitespace
247+
#[allow(clippy::unnecessary_wraps)]
245248
fn dedent(value: &Value, args: &HashMap<String, Value>) -> TeraResult<Value> {
246249
let string = value.as_str().expect("dedent takes a string");
247250

src/web/statics.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ pub(crate) fn static_handler(req: &mut Request) -> IronResult<Response> {
2020
let file = file.join("/");
2121

2222
Ok(match file.as_str() {
23-
"vendored.css" => serve_resource(VENDORED_CSS, ContentType("text/css".parse().unwrap()))?,
24-
"style.css" => serve_resource(STYLE_CSS, ContentType("text/css".parse().unwrap()))?,
25-
"rustdoc.css" => serve_resource(RUSTDOC_CSS, ContentType("text/css".parse().unwrap()))?,
23+
"vendored.css" => serve_resource(VENDORED_CSS, ContentType("text/css".parse().unwrap())),
24+
"style.css" => serve_resource(STYLE_CSS, ContentType("text/css".parse().unwrap())),
25+
"rustdoc.css" => serve_resource(RUSTDOC_CSS, ContentType("text/css".parse().unwrap())),
2626
file => serve_file(file)?,
2727
})
2828
}
@@ -79,10 +79,10 @@ fn serve_file(file: &str) -> IronResult<Response> {
7979
));
8080
}
8181

82-
serve_resource(contents, content_type)
82+
Ok(serve_resource(contents, content_type))
8383
}
8484

85-
fn serve_resource<R, C>(resource: R, content_type: C) -> IronResult<Response>
85+
fn serve_resource<R, C>(resource: R, content_type: C) -> Response
8686
where
8787
R: AsRef<[u8]>,
8888
C: Into<Option<ContentType>>,
@@ -110,7 +110,7 @@ where
110110
response.headers.set(content_type);
111111
}
112112

113-
Ok(response)
113+
response
114114
}
115115

116116
pub(super) fn ico_handler(req: &mut Request) -> IronResult<Response> {

0 commit comments

Comments
 (0)