Skip to content

Commit 1eb8764

Browse files
matthiaskrgrcalebcartwright
authored andcommitted
fix more clippy warnings:
clippy::options_as_ref_deref clippy::or_fun_call clippy::clone_on_copy clippy::redundant_clone clippy::redundant_closure clippy::needless_return
1 parent 55fe4db commit 1eb8764

File tree

10 files changed

+14
-15
lines changed

10 files changed

+14
-15
lines changed

src/config/file_lines.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ impl str::FromStr for FileLines {
332332
let mut m = HashMap::new();
333333
for js in v {
334334
let (s, r) = JsonSpan::into_tuple(js)?;
335-
m.entry(s).or_insert_with(|| vec![]).push(r);
335+
m.entry(s).or_insert_with(Vec::new).push(r);
336336
}
337337
Ok(FileLines::from_ranges(m))
338338
}

src/format_report_formatter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl<'a> Display for FormatReportFormatter<'a> {
6868
let slice = Slice {
6969
source: error.line_str().unwrap_or(""),
7070
line_start: error.line_num().unwrap_or(0),
71-
origin: origin.as_ref().map(|s| s.as_str()),
71+
origin: origin.as_deref(),
7272
fold: false,
7373
annotations: slice_annotation(error).into_iter().collect(),
7474
};

src/formatting.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ fn format_file(
215215
// source map instead of hitting the file system.
216216
let original_text = match original_snippet {
217217
Some(snippet) => snippet,
218-
None => std::fs::read_to_string(path.as_path().ok_or(OperationError::IoError(
219-
std::io::Error::from(std::io::ErrorKind::InvalidInput),
220-
))?)?,
218+
None => std::fs::read_to_string(path.as_path().ok_or_else(|| {
219+
OperationError::IoError(std::io::Error::from(std::io::ErrorKind::InvalidInput))
220+
})?)?,
221221
};
222222
apply_newline_style(config.newline_style(), &mut visitor.buffer, &original_text);
223223

src/formatting/comment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ fn is_table_item(mut s: &str) -> bool {
885885
// This function may return false positive, but should get its job done in most cases (i.e.
886886
// markdown tables with two column delimiters).
887887
s = s.trim_start();
888-
return s.starts_with('|') && !matches!(s.rfind('|'), Some(0) | None);
888+
s.starts_with('|') && !matches!(s.rfind('|'), Some(0) | None)
889889
}
890890

891891
/// Given the span, rewrite the missing comment inside it if available.

src/formatting/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ pub(crate) fn rewrite_block_with_visitor(
527527

528528
let inner_attrs = attrs.map(inner_attributes);
529529
let label_str = rewrite_label(label);
530-
visitor.visit_block(block, inner_attrs.as_ref().map(|a| &**a), has_braces);
530+
visitor.visit_block(block, inner_attrs.as_deref(), has_braces);
531531
let visitor_context = visitor.get_context();
532532
context
533533
.skipped_range

src/formatting/generated.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ pub(super) fn is_generated_file(file_name: &FileName, original_snippet: Option<&
1212
FileName::Stdin => original_snippet
1313
.and_then(|s| s.lines().next())
1414
.map(str::to_owned)
15-
.unwrap_or("".to_owned()),
15+
.unwrap_or_default(),
1616
FileName::Real(ref path) => fs::File::open(path)
1717
.ok()
1818
.and_then(|f| io::BufReader::new(f).lines().next()?.ok())
19-
.unwrap_or("".to_owned()),
19+
.unwrap_or_default(),
2020
};
2121

2222
is_comment_with_generated_notation(&first_line)

src/formatting/imports.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ impl UseTree {
540540
}
541541

542542
fn flatten(self) -> Vec<UseTree> {
543-
match self.path.clone().last() {
543+
match self.path.last() {
544544
Some(UseSegment::List(list)) => {
545545
if list.len() == 1 && list[0].path.len() == 1 {
546546
if let UseSegment::Slf(..) = list[0].path[0] {

src/formatting/report.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl FormatResult {
6565

6666
/// Return the newline style used to format the result.
6767
pub fn newline_style(&self) -> NewlineStyle {
68-
self.newline_style.clone()
68+
self.newline_style
6969
}
7070

7171
pub fn original_text(&self) -> &str {

src/formatting/syntux/parser.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl<'a> Parser<'a> {
116116
if sess.can_reset_errors() {
117117
sess.reset_errors();
118118
}
119-
return None;
119+
None
120120
}
121121
}
122122
}));
@@ -194,8 +194,7 @@ impl<'a> Parser<'a> {
194194
mac: &'a ast::MacCall,
195195
) -> Result<Vec<ast::Item>, &'static str> {
196196
let token_stream = mac.args.inner_tokens();
197-
let mut parser =
198-
rustc_parse::stream_to_parser(sess.inner(), token_stream.clone(), Some(""));
197+
let mut parser = rustc_parse::stream_to_parser(sess.inner(), token_stream, Some(""));
199198
let mut items = vec![];
200199
let mut process_if_cfg = true;
201200

src/result.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl FormatError {
5454

5555
/// Return the content of the line on which this error arose.
5656
pub fn line_str(&self) -> Option<&str> {
57-
self.line_str.as_ref().map(|s| s.as_str())
57+
self.line_str.as_deref()
5858
}
5959

6060
pub(crate) fn new(kind: ErrorKind, line_num: usize, line_str: String) -> Self {

0 commit comments

Comments
 (0)