Skip to content

Commit b1bf434

Browse files
bors[bot]kjeremy
andcommitted
Merge #1482
1482: Some clippy fixes for 1.36 r=kjeremy a=kjeremy Some clippy fixes now that 1.36 is released. ~~Plus the requisite format run (I can rebase after #1481 is merged to make this cleaner) .~~ The change from `map(|it| *it)` to `copied()` changes the minimum rust stable to 1.36. Co-authored-by: Jeremy Kolb <kjeremy@gmail.com>
2 parents c6a6e43 + e7fb6c8 commit b1bf434

File tree

31 files changed

+61
-67
lines changed

31 files changed

+61
-67
lines changed

crates/gen_lsp_server/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ fn initialize(
130130
Ok(RawMessage::Notification(n)) => {
131131
n.cast::<Initialized>().map_err(|_| "expected initialized notification")?;
132132
}
133-
_ => Err(format!("expected initialized notification"))?,
133+
_ => Err("expected initialized notification".to_string())?,
134134
}
135135
Ok(params)
136136
}

crates/ra_assists/src/auto_import.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ fn collect_path_segments_raw<'a>(
3939
// We need to reverse only the new added segments
4040
let only_new_segments = segments.split_at_mut(oldlen).1;
4141
only_new_segments.reverse();
42-
return Some(segments.len() - oldlen);
42+
Some(segments.len() - oldlen)
4343
}
4444

4545
fn fmt_segments(segments: &[SmolStr]) -> String {
4646
let mut buf = String::new();
4747
fmt_segments_raw(segments, &mut buf);
48-
return buf;
48+
buf
4949
}
5050

5151
fn fmt_segments_raw(segments: &[SmolStr], buf: &mut String) {
@@ -61,7 +61,7 @@ fn fmt_segments_raw(segments: &[SmolStr], buf: &mut String) {
6161

6262
// Returns the numeber of common segments.
6363
fn compare_path_segments(left: &[SmolStr], right: &[&ast::PathSegment]) -> usize {
64-
return left.iter().zip(right).filter(|(l, r)| compare_path_segment(l, r)).count();
64+
left.iter().zip(right).filter(|(l, r)| compare_path_segment(l, r)).count()
6565
}
6666

6767
fn compare_path_segment(a: &SmolStr, b: &ast::PathSegment) -> bool {
@@ -320,7 +320,7 @@ fn walk_use_tree_for_best_action<'a>(
320320

321321
// We remove the segments added
322322
current_path_segments.truncate(prev_len);
323-
return action;
323+
action
324324
}
325325

326326
fn best_action_for_target<'b, 'a: 'b>(
@@ -339,7 +339,7 @@ fn best_action_for_target<'b, 'a: 'b>(
339339
});
340340

341341
match best_action {
342-
Some(action) => return action,
342+
Some(action) => action,
343343
None => {
344344
// We have no action and no UseItem was found in container so we find
345345
// another item and we use it as anchor.
@@ -350,7 +350,7 @@ fn best_action_for_target<'b, 'a: 'b>(
350350
.find(|n| n.range().start() < anchor.range().start())
351351
.or_else(|| Some(anchor));
352352

353-
return ImportAction::add_new_use(anchor, false);
353+
ImportAction::add_new_use(anchor, false)
354354
}
355355
}
356356
}

crates/ra_cli/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,6 @@ fn read_stdin() -> Result<String> {
112112
}
113113

114114
fn rsplit_at_char(s: &str, c: char) -> Result<(&str, &str)> {
115-
let idx = s.rfind(":").ok_or_else(|| format!("no `{}` in {}", c, s))?;
115+
let idx = s.rfind(':').ok_or_else(|| format!("no `{}` in {}", c, s))?;
116116
Ok((&s[..idx], &s[idx + 1..]))
117117
}

crates/ra_db/src/input.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl CrateGraph {
139139
}
140140

141141
pub fn iter<'a>(&'a self) -> impl Iterator<Item = CrateId> + 'a {
142-
self.arena.keys().map(|it| *it)
142+
self.arena.keys().copied()
143143
}
144144

145145
pub fn crate_root(&self, crate_id: CrateId) -> FileId {
@@ -191,7 +191,7 @@ impl CrateGraph {
191191
return true;
192192
}
193193
}
194-
return false;
194+
false
195195
}
196196
}
197197

crates/ra_hir/src/code_model/docs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub(crate) fn documentation_query(
7474
DocDef::Module(it) => docs_from_ast(&*it.declaration_source(db)?.ast),
7575
DocDef::StructField(it) => match it.source(db).ast {
7676
FieldSource::Named(named) => docs_from_ast(&*named),
77-
FieldSource::Pos(..) => return None,
77+
FieldSource::Pos(..) => None,
7878
},
7979
DocDef::Struct(it) => docs_from_ast(&*it.source(db).ast),
8080
DocDef::Enum(it) => docs_from_ast(&*it.source(db).ast),

crates/ra_hir/src/expr.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl BodySourceMap {
150150
}
151151

152152
pub(crate) fn field_syntax(&self, expr: ExprId, field: usize) -> AstPtr<ast::NamedField> {
153-
self.field_map[&(expr, field)].clone()
153+
self.field_map[&(expr, field)]
154154
}
155155
}
156156

@@ -471,15 +471,15 @@ impl Pat {
471471
match self {
472472
Pat::Range { .. } | Pat::Lit(..) | Pat::Path(..) | Pat::Wild | Pat::Missing => {}
473473
Pat::Bind { subpat, .. } => {
474-
subpat.iter().map(|pat| *pat).for_each(f);
474+
subpat.iter().copied().for_each(f);
475475
}
476476
Pat::Tuple(args) | Pat::TupleStruct { args, .. } => {
477-
args.iter().map(|pat| *pat).for_each(f);
477+
args.iter().copied().for_each(f);
478478
}
479479
Pat::Ref { pat, .. } => f(*pat),
480480
Pat::Slice { prefix, rest, suffix } => {
481481
let total_iter = prefix.iter().chain(rest.iter()).chain(suffix.iter());
482-
total_iter.map(|pat| *pat).for_each(f);
482+
total_iter.copied().for_each(f);
483483
}
484484
Pat::Struct { args, .. } => {
485485
args.iter().map(|f| f.pat).for_each(f);

crates/ra_hir/src/expr/scope.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl ExprScopes {
7272
}
7373

7474
pub(crate) fn scope_for(&self, expr: ExprId) -> Option<ScopeId> {
75-
self.scope_by_expr.get(&expr).map(|&scope| scope)
75+
self.scope_by_expr.get(&expr).copied()
7676
}
7777

7878
pub(crate) fn scope_by_expr(&self) -> &FxHashMap<ExprId, ScopeId> {

crates/ra_hir/src/lang_item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl LangItems {
122122
module: Module,
123123
) {
124124
if let Some(module_lang_items) = db.module_lang_items(module) {
125-
self.items.extend(module_lang_items.items.iter().map(|(k, v)| (k.clone(), v.clone())))
125+
self.items.extend(module_lang_items.items.iter().map(|(k, v)| (k.clone(), *v)))
126126
}
127127

128128
// Look for lang items in the children
@@ -142,7 +142,7 @@ impl LangItems {
142142
{
143143
let node = item.source(db).ast;
144144
if let Some(lang_item_name) = lang_item_name(&*node) {
145-
self.items.entry(lang_item_name).or_insert(constructor(item));
145+
self.items.entry(lang_item_name).or_insert_with(|| constructor(item));
146146
}
147147
}
148148
}

crates/ra_hir/src/mock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl MockDatabase {
7676

7777
pub fn diagnostics(&self) -> String {
7878
let mut buf = String::from("\n");
79-
let mut files: Vec<FileId> = self.files.values().map(|&it| it).collect();
79+
let mut files: Vec<FileId> = self.files.values().copied().collect();
8080
files.sort();
8181
for file in files {
8282
let module = crate::source_binder::module_from_file_id(self, file).unwrap();

crates/ra_hir/src/nameres/collector.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,8 @@ where
227227
.items
228228
.iter()
229229
.map(|(name, res)| (name.clone(), Either::A(res.clone())));
230-
let macros = scope
231-
.macros
232-
.iter()
233-
.map(|(name, res)| (name.clone(), Either::B(res.clone())));
230+
let macros =
231+
scope.macros.iter().map(|(name, res)| (name.clone(), Either::B(*res)));
234232

235233
let all = items.chain(macros).collect::<Vec<_>>();
236234
self.update(module_id, Some(import_id), &all);
@@ -243,10 +241,8 @@ where
243241
.items
244242
.iter()
245243
.map(|(name, res)| (name.clone(), Either::A(res.clone())));
246-
let macros = scope
247-
.macros
248-
.iter()
249-
.map(|(name, res)| (name.clone(), Either::B(res.clone())));
244+
let macros =
245+
scope.macros.iter().map(|(name, res)| (name.clone(), Either::B(*res)));
250246

251247
let all = items.chain(macros).collect::<Vec<_>>();
252248

@@ -651,7 +647,7 @@ fn resolve_submodule(
651647
candidates.push(file_dir_mod.clone());
652648
};
653649
let sr = db.source_root(source_root_id);
654-
let mut points_to = candidates.into_iter().filter_map(|path| sr.files.get(&path)).map(|&it| it);
650+
let mut points_to = candidates.into_iter().filter_map(|path| sr.files.get(&path)).copied();
655651
// FIXME: handle ambiguity
656652
match points_to.next() {
657653
Some(file_id) => Ok(file_id),

0 commit comments

Comments
 (0)