Skip to content

Commit 52bf473

Browse files
committed
Fix some clippy lints
1 parent f321593 commit 52bf473

File tree

8 files changed

+39
-46
lines changed

8 files changed

+39
-46
lines changed

src/fn_call.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx> for EvalContext<'a, 'mir, '
268268
)?;
269269
let mut args = self.frame().mir.args_iter();
270270

271-
let arg_local = args.next().ok_or(
271+
let arg_local = args.next().ok_or_else(||
272272
EvalErrorKind::AbiViolation(
273273
"Argument to __rust_maybe_catch_panic does not take enough arguments."
274274
.to_owned(),
@@ -504,7 +504,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx> for EvalContext<'a, 'mir, '
504504

505505
// Figure out how large a pthread TLS key actually is. This is libc::pthread_key_t.
506506
let key_type = args[0].ty.builtin_deref(true)
507-
.ok_or(EvalErrorKind::AbiViolation("Wrong signature used for pthread_key_create: First argument must be a raw pointer.".to_owned()))?.ty;
507+
.ok_or_else(|| EvalErrorKind::AbiViolation("Wrong signature used for pthread_key_create: First argument must be a raw pointer.".to_owned()))?.ty;
508508
let key_size = self.layout_of(key_type)?.size;
509509

510510
// Create key and write it into the memory where key_ptr wants it
@@ -747,7 +747,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx> for EvalContext<'a, 'mir, '
747747
// current frame.
748748
self.dump_local(dest);
749749
self.goto_block(dest_block);
750-
return Ok(());
750+
Ok(())
751751
}
752752

753753
fn write_null(&mut self, dest: Place, dest_ty: Ty<'tcx>) -> EvalResult<'tcx> {

src/helpers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'mir, 'tcx, super:
7575
}
7676
// FIXME: assuming here that type size is < i64::max_value()
7777
let pointee_size = self.layout_of(pointee_ty)?.size.bytes() as i64;
78-
return if let Some(offset) = offset.checked_mul(pointee_size) {
78+
if let Some(offset) = offset.checked_mul(pointee_size) {
7979
let ptr = ptr.ptr_signed_offset(offset, self)?;
8080
// Do not do bounds-checking for integers; they can never alias a normal pointer anyway.
8181
if let Scalar::Ptr(ptr) = ptr {
@@ -87,7 +87,7 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'mir, 'tcx, super:
8787
Ok(ptr)
8888
} else {
8989
err!(Overflow(mir::BinOp::Mul))
90-
};
90+
}
9191
}
9292

9393
fn value_to_isize(

src/lib.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
inclusive_range_methods,
66
)]
77

8+
#![cfg_attr(feature = "cargo-clippy", allow(cast_lossless))]
9+
810
#[macro_use]
911
extern crate log;
1012

@@ -427,14 +429,11 @@ impl<'mir, 'tcx: 'mir> Machine<'mir, 'tcx> for Evaluator<'tcx> {
427429
let frame = ecx.frame_mut();
428430
let bb = &frame.mir.basic_blocks()[frame.block];
429431
if bb.statements.len() == frame.stmt && !bb.is_cleanup {
430-
match bb.terminator().kind {
431-
::rustc::mir::TerminatorKind::Return => {
432-
for (local, _local_decl) in mir.local_decls.iter_enumerated().skip(1) {
433-
// Don't deallocate locals, because the return value might reference them
434-
frame.storage_dead(local);
435-
}
432+
if let ::rustc::mir::TerminatorKind::Return = bb.terminator().kind {
433+
for (local, _local_decl) in mir.local_decls.iter_enumerated().skip(1) {
434+
// Don't deallocate locals, because the return value might reference them
435+
frame.storage_dead(local);
436436
}
437-
_ => {}
438437
}
439438
}
440439
}
@@ -478,7 +477,7 @@ impl<'mir, 'tcx: 'mir> Machine<'mir, 'tcx> for Evaluator<'tcx> {
478477
value: Value::Scalar(Scalar::from_u128(match layout.size.bytes() {
479478
0 => 1 as u128,
480479
size => size as u128,
481-
}.into())),
480+
})),
482481
ty: usize,
483482
},
484483
dest,

src/locks.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,9 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> MemoryExt<'tcx> for Memory<'a, 'mir, 'tcx, Evalu
241241
// All is well
242242
continue 'locks;
243243
}
244-
} else {
245-
if !is_our_lock {
246-
// All is well.
247-
continue 'locks;
248-
}
244+
} else if !is_our_lock {
245+
// All is well.
246+
continue 'locks;
249247
}
250248
// If we get here, releasing this is an error except for NoLock.
251249
if lock.active != NoLock {
@@ -377,7 +375,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> MemoryExt<'tcx> for Memory<'a, 'mir, 'tcx, Evalu
377375
}
378376
// Clean up the map
379377
alloc_locks.retain(|lock| match lock.active {
380-
NoLock => lock.suspended.len() > 0,
378+
NoLock => !lock.suspended.is_empty(),
381379
_ => true,
382380
});
383381
}

src/operator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'mir, 'tcx, super:
6969
.expect("Offset called on non-ptr type")
7070
.ty;
7171
let ptr = self.pointer_offset(
72-
left.into(),
72+
left,
7373
pointee_ty,
7474
right.to_bits(self.memory.pointer_size())? as i64,
7575
)?;

src/range_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl<T> RangeMap<T> {
189189
F: FnMut(&T) -> bool,
190190
{
191191
let mut remove = Vec::new();
192-
for (range, data) in self.map.iter() {
192+
for (range, data) in &self.map {
193193
if !f(data) {
194194
remove.push(*range);
195195
}

src/tls.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,38 +30,38 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> MemoryExt<'tcx> for Memory<'a, 'mir, 'tcx, Evalu
3030
},
3131
);
3232
trace!("New TLS key allocated: {} with dtor {:?}", new_key, dtor);
33-
return new_key;
33+
new_key
3434
}
3535

3636
fn delete_tls_key(&mut self, key: TlsKey) -> EvalResult<'tcx> {
37-
return match self.data.thread_local.remove(&key) {
37+
match self.data.thread_local.remove(&key) {
3838
Some(_) => {
3939
trace!("TLS key {} removed", key);
4040
Ok(())
4141
}
4242
None => err!(TlsOutOfBounds),
43-
};
43+
}
4444
}
4545

4646
fn load_tls(&mut self, key: TlsKey) -> EvalResult<'tcx, Scalar> {
47-
return match self.data.thread_local.get(&key) {
47+
match self.data.thread_local.get(&key) {
4848
Some(&TlsEntry { data, .. }) => {
4949
trace!("TLS key {} loaded: {:?}", key, data);
5050
Ok(data)
5151
}
5252
None => err!(TlsOutOfBounds),
53-
};
53+
}
5454
}
5555

5656
fn store_tls(&mut self, key: TlsKey, new_data: Scalar) -> EvalResult<'tcx> {
57-
return match self.data.thread_local.get_mut(&key) {
57+
match self.data.thread_local.get_mut(&key) {
5858
Some(&mut TlsEntry { ref mut data, .. }) => {
5959
trace!("TLS key {} stored: {:?}", key, new_data);
6060
*data = new_data;
6161
Ok(())
6262
}
6363
None => err!(TlsOutOfBounds),
64-
};
64+
}
6565
}
6666

6767
/// Returns a dtor, its argument and its index, if one is supposed to run
@@ -104,7 +104,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> MemoryExt<'tcx> for Memory<'a, 'mir, 'tcx, Evalu
104104
}
105105
}
106106
}
107-
return Ok(None);
107+
Ok(None)
108108
}
109109
}
110110

@@ -124,8 +124,8 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx> for EvalContext<'a, 'mir, '
124124
Place::undef(),
125125
StackPopCleanup::None,
126126
)?;
127-
let arg_local = self.frame().mir.args_iter().next().ok_or(
128-
EvalErrorKind::AbiViolation("TLS dtor does not take enough arguments.".to_owned()),
127+
let arg_local = self.frame().mir.args_iter().next().ok_or_else(
128+
|| EvalErrorKind::AbiViolation("TLS dtor does not take enough arguments.".to_owned()),
129129
)?;
130130
let dest = self.eval_place(&mir::Place::Local(arg_local))?;
131131
let ty = self.tcx.mk_mut_ptr(self.tcx.types.u8);

src/validation.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx> for EvalContext<'a, 'mir, '
135135
}
136136

137137
fn abstract_place(&self, place: &mir::Place<'tcx>) -> EvalResult<'tcx, AbsPlace<'tcx>> {
138-
Ok(match place {
139-
&mir::Place::Local(l) => AbsPlace::Local(l),
140-
&mir::Place::Static(ref s) => AbsPlace::Static(s.def_id),
141-
&mir::Place::Projection(ref p) =>
138+
Ok(match *place {
139+
mir::Place::Local(l) => AbsPlace::Local(l),
140+
mir::Place::Static(ref s) => AbsPlace::Static(s.def_id),
141+
mir::Place::Projection(ref p) =>
142142
AbsPlace::Projection(Box::new(self.abstract_place_projection(&*p)?)),
143143
})
144144
}
@@ -378,11 +378,8 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx> for EvalContext<'a, 'mir, '
378378
mut layout: ty::layout::TyLayout<'tcx>,
379379
i: usize,
380380
) -> EvalResult<'tcx, Ty<'tcx>> {
381-
match base {
382-
Place::Ptr { extra: PlaceExtra::DowncastVariant(variant_index), .. } => {
383-
layout = layout.for_variant(&self, variant_index);
384-
}
385-
_ => {}
381+
if let Place::Ptr { extra: PlaceExtra::DowncastVariant(variant_index), .. } = base {
382+
layout = layout.for_variant(&self, variant_index);
386383
}
387384
let tcx = self.tcx.tcx;
388385
Ok(match layout.ty.sty {
@@ -667,12 +664,11 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx> for EvalContext<'a, 'mir, '
667664
// Inner lifetimes *outlive* outer ones, so only if we have no lifetime restriction yet,
668665
// we record the region of this borrow to the context.
669666
if query.re == None {
670-
match *region {
671-
ReScope(scope) => query.re = Some(scope),
672-
// It is possible for us to encounter erased lifetimes here because the lifetimes in
673-
// this functions' Subst will be erased.
674-
_ => {}
667+
if let ReScope(scope) = *region {
668+
query.re = Some(scope);
675669
}
670+
// It is possible for us to encounter erased lifetimes here because the lifetimes in
671+
// this functions' Subst will be erased.
676672
}
677673
self.validate_ptr(val, query.place.0, pointee_ty, query.re, query.mutbl, mode)?;
678674
}
@@ -772,7 +768,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx> for EvalContext<'a, 'mir, '
772768
let variant_idx = self.read_discriminant_as_variant_index(query.place.1, query.ty)?;
773769
let variant = &adt.variants[variant_idx];
774770

775-
if variant.fields.len() > 0 {
771+
if !variant.fields.is_empty() {
776772
// Downcast to this variant, if needed
777773
let place = if adt.is_enum() {
778774
(

0 commit comments

Comments
 (0)