Skip to content

Commit ec6f715

Browse files
bors[bot]kjeremy
andcommitted
Merge #1491
1491: More clippy r=matklad a=kjeremy A few more clippy changes. I'm a little unsure of the second commit. It's the trivially_copy_pass_by_ref lint and there are a number of places in the code we could use it if it makes sense. Co-authored-by: Jeremy Kolb <kjeremy@gmail.com>
2 parents 3be2d1d + 98d769a commit ec6f715

File tree

5 files changed

+34
-36
lines changed

5 files changed

+34
-36
lines changed

crates/ra_assists/src/fill_match_arms.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,24 @@ pub(crate) fn fill_match_arms(mut ctx: AssistCtx<impl HirDatabase>) -> Option<As
2323
// We already have some match arms, so we don't provide any assists.
2424
// Unless if there is only one trivial match arm possibly created
2525
// by match postfix complete. Trivial match arm is the catch all arm.
26-
match match_expr.match_arm_list() {
27-
Some(arm_list) => {
28-
let mut arm_iter = arm_list.arms();
29-
let first = arm_iter.next();
30-
31-
match first {
32-
// If there arm list is empty or there is only one trivial arm, then proceed.
33-
Some(arm) if is_trivial_arm(arm) => {
34-
if arm_iter.next() != None {
35-
return None;
36-
}
37-
}
38-
None => {}
39-
40-
_ => {
26+
if let Some(arm_list) = match_expr.match_arm_list() {
27+
let mut arm_iter = arm_list.arms();
28+
let first = arm_iter.next();
29+
30+
match first {
31+
// If there arm list is empty or there is only one trivial arm, then proceed.
32+
Some(arm) if is_trivial_arm(arm) => {
33+
if arm_iter.next() != None {
4134
return None;
4235
}
4336
}
37+
None => {}
38+
39+
_ => {
40+
return None;
41+
}
4442
}
45-
_ => {}
46-
}
43+
};
4744

4845
let expr = match_expr.expr()?;
4946
let analyzer = hir::SourceAnalyzer::new(ctx.db, ctx.frange.file_id, expr.syntax(), None);

crates/ra_db/src/input.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ impl CrateGraph {
131131
if self.dfs_find(from, to, &mut FxHashSet::default()) {
132132
return Err(CyclicDependencies);
133133
}
134-
Ok(self.arena.get_mut(&from).unwrap().add_dep(name, to))
134+
self.arena.get_mut(&from).unwrap().add_dep(name, to);
135+
Ok(())
135136
}
136137

137138
pub fn is_empty(&self) -> bool {

crates/ra_hir/src/code_model.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,10 @@ impl Module {
240240
}
241241

242242
pub fn path_to_root(self, db: &impl HirDatabase) -> Vec<Module> {
243-
let mut res = vec![self.clone()];
244-
let mut curr = self.clone();
243+
let mut res = vec![self];
244+
let mut curr = self;
245245
while let Some(next) = curr.parent(db) {
246-
res.push(next.clone());
246+
res.push(next);
247247
curr = next
248248
}
249249
res
@@ -299,7 +299,7 @@ impl Module {
299299
.collect()
300300
}
301301

302-
fn with_module_id(&self, module_id: CrateModuleId) -> Module {
302+
fn with_module_id(self, module_id: CrateModuleId) -> Module {
303303
Module { module_id, krate: self.krate }
304304
}
305305
}
@@ -463,33 +463,33 @@ pub struct EnumVariant {
463463
}
464464

465465
impl EnumVariant {
466-
pub fn module(&self, db: &impl HirDatabase) -> Module {
466+
pub fn module(self, db: &impl HirDatabase) -> Module {
467467
self.parent.module(db)
468468
}
469-
pub fn parent_enum(&self, _db: &impl DefDatabase) -> Enum {
469+
pub fn parent_enum(self, _db: &impl DefDatabase) -> Enum {
470470
self.parent
471471
}
472472

473-
pub fn name(&self, db: &impl DefDatabase) -> Option<Name> {
473+
pub fn name(self, db: &impl DefDatabase) -> Option<Name> {
474474
db.enum_data(self.parent).variants[self.id].name.clone()
475475
}
476476

477-
pub fn fields(&self, db: &impl HirDatabase) -> Vec<StructField> {
477+
pub fn fields(self, db: &impl HirDatabase) -> Vec<StructField> {
478478
self.variant_data(db)
479479
.fields()
480480
.into_iter()
481481
.flat_map(|it| it.iter())
482-
.map(|(id, _)| StructField { parent: (*self).into(), id })
482+
.map(|(id, _)| StructField { parent: self.into(), id })
483483
.collect()
484484
}
485485

486-
pub fn field(&self, db: &impl HirDatabase, name: &Name) -> Option<StructField> {
486+
pub fn field(self, db: &impl HirDatabase, name: &Name) -> Option<StructField> {
487487
self.variant_data(db)
488488
.fields()
489489
.into_iter()
490490
.flat_map(|it| it.iter())
491491
.find(|(_id, data)| data.name == *name)
492-
.map(|(id, _)| StructField { parent: (*self).into(), id })
492+
.map(|(id, _)| StructField { parent: self.into(), id })
493493
}
494494
}
495495

@@ -517,11 +517,11 @@ impl DefWithBody {
517517
}
518518

519519
/// Builds a resolver for code inside this item.
520-
pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver {
521-
match *self {
522-
DefWithBody::Const(ref c) => c.resolver(db),
523-
DefWithBody::Function(ref f) => f.resolver(db),
524-
DefWithBody::Static(ref s) => s.resolver(db),
520+
pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver {
521+
match self {
522+
DefWithBody::Const(c) => c.resolver(db),
523+
DefWithBody::Function(f) => f.resolver(db),
524+
DefWithBody::Static(s) => s.resolver(db),
525525
}
526526
}
527527
}

crates/ra_hir/src/ty/infer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
529529
match matching_def {
530530
Some(_) => {
531531
self.write_assoc_resolution(id, item);
532-
return matching_def;
532+
matching_def
533533
}
534534
None => None,
535535
}

crates/ra_syntax/src/validation/unescape.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ where
262262

263263
fn byte_from_char(c: char) -> u8 {
264264
let res = c as u32;
265-
assert!(res <= u8::max_value() as u32, "guaranteed because of Mode::Byte");
265+
assert!(res <= u32::from(u8::max_value()), "guaranteed because of Mode::Byte");
266266
res as u8
267267
}
268268

0 commit comments

Comments
 (0)