Skip to content

Commit 9ea3c19

Browse files
committed
fix(fmt/style): Further apply Clippy suggestions manually
1. Fix Pattern Type Mismatch by Adding deref's 2. Move commented `else if` to previous block in `intrinsic.rs`
1 parent 6f76488 commit 9ea3c19

File tree

5 files changed

+58
-49
lines changed

5 files changed

+58
-49
lines changed

src/debuginfo.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ fn compute_mir_scopes<'gcc, 'tcx>(
9191
/// FIXME(tempdragon/?): Add Scope Support Here.
9292
fn make_mir_scope<'gcc, 'tcx>(
9393
cx: &CodegenCx<'gcc, 'tcx>,
94-
instance: Instance<'tcx>,
94+
_instance: Instance<'tcx>,
9595
mir: &Body<'tcx>,
9696
variables: &Option<BitSet<SourceScope>>,
9797
debug_context: &mut FunctionDebugContext<'tcx, (), Location<'gcc>>,
@@ -104,7 +104,7 @@ fn make_mir_scope<'gcc, 'tcx>(
104104

105105
let scope_data = &mir.source_scopes[scope];
106106
let parent_scope = if let Some(parent) = scope_data.parent_scope {
107-
make_mir_scope(cx, instance, mir, variables, debug_context, instantiated, parent);
107+
make_mir_scope(cx, _instance, mir, variables, debug_context, instantiated, parent);
108108
debug_context.scopes[parent]
109109
} else {
110110
// The root is the function itself.
@@ -118,7 +118,7 @@ fn make_mir_scope<'gcc, 'tcx>(
118118
return;
119119
};
120120

121-
if let Some(vars) = variables {
121+
if let Some(ref vars) = *variables {
122122
if !vars.contains(scope) && scope_data.inlined.is_none() {
123123
// Do not create a DIScope if there are no variables defined in this
124124
// MIR `SourceScope`, and it's not `inlined`, to avoid debuginfo bloat.
@@ -136,8 +136,13 @@ fn make_mir_scope<'gcc, 'tcx>(
136136
let inlined_at = scope_data.inlined.map(|(_, callsite_span)| {
137137
// FIXME(eddyb) this doesn't account for the macro-related
138138
// `Span` fixups that `rustc_codegen_ssa::mir::debuginfo` does.
139-
let callsite_scope = parent_scope.adjust_dbg_scope_for_span(cx, callsite_span);
140-
cx.dbg_loc(callsite_scope, parent_scope.inlined_at, callsite_span)
139+
140+
// NOTE: These variables passed () here.
141+
// Changed to comply to clippy.
142+
143+
/* let callsite_scope = */
144+
parent_scope.adjust_dbg_scope_for_span(cx, callsite_span);
145+
cx.dbg_loc(/* callsite_scope */ (), parent_scope.inlined_at, callsite_span)
141146
});
142147
let p_inlined_at = parent_scope.inlined_at;
143148
// TODO(tempdragon): dbg_scope: Add support for scope extension here.
@@ -275,15 +280,15 @@ impl<'gcc, 'tcx> DebugInfoMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
275280
let pos = span.lo();
276281
let DebugLoc { file, line, col } = self.lookup_debug_loc(pos);
277282
let loc = match &file.name {
278-
rustc_span::FileName::Real(name) => match name {
279-
rustc_span::RealFileName::LocalPath(name) => {
283+
rustc_span::FileName::Real(ref name) => match &name {
284+
rustc_span::RealFileName::LocalPath(ref name) => {
280285
if let Some(name) = name.to_str() {
281286
self.context.new_location(name, line as i32, col as i32)
282287
} else {
283288
Location::null()
284289
}
285290
}
286-
rustc_span::RealFileName::Remapped { local_path, virtual_name: _ } => {
291+
rustc_span::RealFileName::Remapped { ref local_path, virtual_name: _unused } => {
287292
if let Some(name) = local_path.as_ref() {
288293
if let Some(name) = name.to_str() {
289294
self.context.new_location(name, line as i32, col as i32)

src/int.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,10 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
253253
) -> (<Self as BackendTypes>::Value, <Self as BackendTypes>::Value) {
254254
use rustc_middle::ty::{Int, IntTy::*, Uint, UintTy::*};
255255

256-
let new_kind = match typ.kind() {
256+
let new_kind = match *typ.kind() {
257257
Int(t @ Isize) => Int(t.normalize(self.tcx.sess.target.pointer_width)),
258258
Uint(t @ Usize) => Uint(t.normalize(self.tcx.sess.target.pointer_width)),
259-
t @ (Uint(_) | Int(_)) => *t,
259+
t @ (Uint(_) | Int(_)) => t,
260260
_ => panic!("tried to get overflow intrinsic for op applied to non-int type"),
261261
};
262262

src/intrinsic/mod.rs

+18-14
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
166166
sym::volatile_load | sym::unaligned_volatile_load => {
167167
let tp_ty = fn_args.type_at(0);
168168
let ptr = args[0].immediate();
169-
let load = if let PassMode::Cast { cast: ty, pad_i32: _ } = &fn_abi.ret.mode {
169+
// The reference was changed to clone to comply to clippy.
170+
let load = if let PassMode::Cast { cast: ty, pad_i32: _ } = fn_abi.ret.mode.clone()
171+
{
170172
let gcc_ty = ty.gcc_type(self);
171173
self.volatile_load(gcc_ty, ptr)
172174
} else {
@@ -308,17 +310,18 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
308310
let b = args[1].immediate();
309311
if layout.size().bytes() == 0 {
310312
self.const_bool(true)
311-
}
312-
/*else if use_integer_compare {
313-
let integer_ty = self.type_ix(layout.size.bits()); // FIXME(antoyo): LLVM creates an integer of 96 bits for [i32; 3], but gcc doesn't support this, so it creates an integer of 128 bits.
314-
let ptr_ty = self.type_ptr_to(integer_ty);
315-
let a_ptr = self.bitcast(a, ptr_ty);
316-
let a_val = self.load(integer_ty, a_ptr, layout.align.abi);
317-
let b_ptr = self.bitcast(b, ptr_ty);
318-
let b_val = self.load(integer_ty, b_ptr, layout.align.abi);
319-
self.icmp(IntPredicate::IntEQ, a_val, b_val)
320-
}*/
321-
else {
313+
// The else if an immediate neighbor of this block.
314+
// It is moved here to comply to Clippy.
315+
/*else if use_integer_compare {
316+
let integer_ty = self.type_ix(layout.size.bits()); // FIXME(antoyo): LLVM creates an integer of 96 bits for [i32; 3], but gcc doesn't support this, so it creates an integer of 128 bits.
317+
let ptr_ty = self.type_ptr_to(integer_ty);
318+
let a_ptr = self.bitcast(a, ptr_ty);
319+
let a_val = self.load(integer_ty, a_ptr, layout.align.abi);
320+
let b_ptr = self.bitcast(b, ptr_ty);
321+
let b_val = self.load(integer_ty, b_ptr, layout.align.abi);
322+
self.icmp(IntPredicate::IntEQ, a_val, b_val)
323+
}*/
324+
} else {
322325
let void_ptr_type = self.context.new_type::<*const ()>();
323326
let a_ptr = self.bitcast(a, void_ptr_type);
324327
let b_ptr = self.bitcast(b, void_ptr_type);
@@ -385,7 +388,8 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
385388
};
386389

387390
if !fn_abi.ret.is_ignore() {
388-
if let PassMode::Cast { cast: ty, .. } = &fn_abi.ret.mode {
391+
// The reference was changed to clone to comply to clippy.
392+
if let PassMode::Cast { cast: ty, .. } = fn_abi.ret.mode.clone() {
389393
let ptr_llty = self.type_ptr_to(ty.gcc_type(self));
390394
let ptr = self.pointercast(result.llval, ptr_llty);
391395
self.store(llval, ptr, result.align);
@@ -586,7 +590,7 @@ fn int_type_width_signed<'gcc, 'tcx>(
586590
ty: Ty<'tcx>,
587591
cx: &CodegenCx<'gcc, 'tcx>,
588592
) -> Option<(u64, bool)> {
589-
match ty.kind() {
593+
match *ty.kind() {
590594
ty::Int(t) => Some((
591595
match t {
592596
rustc_middle::ty::IntTy::Isize => u64::from(cx.tcx.sess.target.pointer_width),

src/intrinsic/simd.rs

+24-24
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
7171
let expected_bytes = len / 8 + ((len % 8 > 0) as u64);
7272

7373
let mask_ty = arg_tys[0];
74-
let mut mask = match mask_ty.kind() {
74+
let mut mask = match *mask_ty.kind() {
7575
ty::Int(i) if i.bit_width() == Some(expected_int_bits) => args[0].immediate(),
7676
ty::Uint(i) if i.bit_width() == Some(expected_int_bits) => args[0].immediate(),
7777
ty::Array(elem, len)
78-
if matches!(elem.kind(), ty::Uint(ty::UintTy::U8))
78+
if matches!(*elem.kind(), ty::Uint(ty::UintTy::U8))
7979
&& len.try_eval_target_usize(bx.tcx, ty::ParamEnv::reveal_all())
8080
== Some(expected_bytes) =>
8181
{
@@ -353,8 +353,8 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
353353
if name == sym::simd_shuffle {
354354
// Make sure this is actually an array, since typeck only checks the length-suffixed
355355
// version of this intrinsic.
356-
let n: u64 = match args[2].layout.ty.kind() {
357-
ty::Array(ty, len) if matches!(ty.kind(), ty::Uint(ty::UintTy::U32)) => {
356+
let n: u64 = match *args[2].layout.ty.kind() {
357+
ty::Array(ty, len) if matches!(*ty.kind(), ty::Uint(ty::UintTy::U32)) => {
358358
len.try_eval_target_usize(bx.cx.tcx, ty::ParamEnv::reveal_all()).unwrap_or_else(
359359
|| span_bug!(span, "could not evaluate shuffle index array length"),
360360
)
@@ -427,7 +427,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
427427
m_len == v_len,
428428
InvalidMonomorphization::MismatchedLengths { span, name, m_len, v_len }
429429
);
430-
match m_elem_ty.kind() {
430+
match *m_elem_ty.kind() {
431431
ty::Int(_) => {}
432432
_ => return_error!(InvalidMonomorphization::MaskType { span, name, ty: m_elem_ty }),
433433
}
@@ -460,13 +460,13 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
460460
Unsupported,
461461
}
462462

463-
let in_style = match in_elem.kind() {
463+
let in_style = match *in_elem.kind() {
464464
ty::Int(_) | ty::Uint(_) => Style::Int,
465465
ty::Float(_) => Style::Float,
466466
_ => Style::Unsupported,
467467
};
468468

469-
let out_style = match out_elem.kind() {
469+
let out_style = match *out_elem.kind() {
470470
ty::Int(_) | ty::Uint(_) => Style::Int,
471471
ty::Float(_) => Style::Float,
472472
_ => Style::Unsupported,
@@ -493,7 +493,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
493493
macro_rules! arith_binary {
494494
($($name: ident: $($($p: ident),* => $call: ident),*;)*) => {
495495
$(if name == sym::$name {
496-
match in_elem.kind() {
496+
match *in_elem.kind() {
497497
$($(ty::$p(_))|* => {
498498
return Ok(bx.$call(args[0].immediate(), args[1].immediate()))
499499
})*
@@ -543,13 +543,13 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
543543
shift += 1;
544544
}
545545

546-
match ret_ty.kind() {
546+
match *ret_ty.kind() {
547547
ty::Uint(i) if i.bit_width() == Some(expected_int_bits) => {
548548
// Zero-extend iN to the bitmask type:
549549
return Ok(result);
550550
}
551551
ty::Array(elem, len)
552-
if matches!(elem.kind(), ty::Uint(ty::UintTy::U8))
552+
if matches!(*elem.kind(), ty::Uint(ty::UintTy::U8))
553553
&& len.try_eval_target_usize(bx.tcx, ty::ParamEnv::reveal_all())
554554
== Some(expected_bytes) =>
555555
{
@@ -588,7 +588,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
588588
return Err(());
589589
}};
590590
}
591-
let (elem_ty_str, elem_ty) = if let ty::Float(f) = in_elem.kind() {
591+
let (elem_ty_str, elem_ty) = if let ty::Float(ref f) = *in_elem.kind() {
592592
let elem_ty = bx.cx.type_float_from_ty(*f);
593593
match f.bit_width() {
594594
32 => ("f", elem_ty),
@@ -795,15 +795,15 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
795795

796796
// This counts how many pointers
797797
fn ptr_count(t: Ty<'_>) -> usize {
798-
match t.kind() {
798+
match *t.kind() {
799799
ty::RawPtr(p) => 1 + ptr_count(p.ty),
800800
_ => 0,
801801
}
802802
}
803803

804804
// Non-ptr type
805805
fn non_ptr(t: Ty<'_>) -> Ty<'_> {
806-
match t.kind() {
806+
match *t.kind() {
807807
ty::RawPtr(p) => non_ptr(p.ty),
808808
_ => t,
809809
}
@@ -813,7 +813,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
813813
// to the element type of the first argument
814814
let (_, element_ty0) = arg_tys[0].simd_size_and_type(bx.tcx());
815815
let (_, element_ty1) = arg_tys[1].simd_size_and_type(bx.tcx());
816-
let (pointer_count, underlying_ty) = match element_ty1.kind() {
816+
let (pointer_count, underlying_ty) = match *element_ty1.kind() {
817817
ty::RawPtr(p) if p.ty == in_elem => (ptr_count(element_ty1), non_ptr(element_ty1)),
818818
_ => {
819819
require!(
@@ -837,7 +837,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
837837

838838
// The element type of the third argument must be a signed integer type of any width:
839839
let (_, element_ty2) = arg_tys[2].simd_size_and_type(bx.tcx());
840-
match element_ty2.kind() {
840+
match *element_ty2.kind() {
841841
ty::Int(_) => (),
842842
_ => {
843843
require!(
@@ -909,15 +909,15 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
909909

910910
// This counts how many pointers
911911
fn ptr_count(t: Ty<'_>) -> usize {
912-
match t.kind() {
912+
match *t.kind() {
913913
ty::RawPtr(p) => 1 + ptr_count(p.ty),
914914
_ => 0,
915915
}
916916
}
917917

918918
// Non-ptr type
919919
fn non_ptr(t: Ty<'_>) -> Ty<'_> {
920-
match t.kind() {
920+
match *t.kind() {
921921
ty::RawPtr(p) => non_ptr(p.ty),
922922
_ => t,
923923
}
@@ -928,7 +928,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
928928
let (_, element_ty0) = arg_tys[0].simd_size_and_type(bx.tcx());
929929
let (_, element_ty1) = arg_tys[1].simd_size_and_type(bx.tcx());
930930
let (_, element_ty2) = arg_tys[2].simd_size_and_type(bx.tcx());
931-
let (pointer_count, underlying_ty) = match element_ty1.kind() {
931+
let (pointer_count, underlying_ty) = match *element_ty1.kind() {
932932
ty::RawPtr(p) if p.ty == in_elem && p.mutbl == hir::Mutability::Mut => {
933933
(ptr_count(element_ty1), non_ptr(element_ty1))
934934
}
@@ -953,7 +953,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
953953
assert_eq!(underlying_ty, non_ptr(element_ty0));
954954

955955
// The element type of the third argument must be a signed integer type of any width:
956-
match element_ty2.kind() {
956+
match *element_ty2.kind() {
957957
ty::Int(_) => (),
958958
_ => {
959959
require!(
@@ -1011,7 +1011,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
10111011
macro_rules! arith_unary {
10121012
($($name: ident: $($($p: ident),* => $call: ident),*;)*) => {
10131013
$(if name == sym::$name {
1014-
match in_elem.kind() {
1014+
match *in_elem.kind() {
10151015
$($(ty::$p(_))|* => {
10161016
return Ok(bx.$call(args[0].immediate()))
10171017
})*
@@ -1135,7 +1135,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
11351135
ret_ty == in_elem,
11361136
InvalidMonomorphization::ReturnType { span, name, in_elem, in_ty, ret_ty }
11371137
);
1138-
return match in_elem.kind() {
1138+
return match *in_elem.kind() {
11391139
ty::Int(_) | ty::Uint(_) => {
11401140
let r = bx.vector_reduce_op(args[0].immediate(), $vec_op);
11411141
if $ordered {
@@ -1204,7 +1204,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
12041204
ret_ty == in_elem,
12051205
InvalidMonomorphization::ReturnType { span, name, in_elem, in_ty, ret_ty }
12061206
);
1207-
return match in_elem.kind() {
1207+
return match *in_elem.kind() {
12081208
ty::Int(_) | ty::Uint(_) => Ok(bx.$int_red(args[0].immediate())),
12091209
ty::Float(_) => Ok(bx.$float_red(args[0].immediate())),
12101210
_ => return_error!(InvalidMonomorphization::UnsupportedSymbol {
@@ -1233,7 +1233,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
12331233
);
12341234
args[0].immediate()
12351235
} else {
1236-
match in_elem.kind() {
1236+
match *in_elem.kind() {
12371237
ty::Int(_) | ty::Uint(_) => {}
12381238
_ => return_error!(InvalidMonomorphization::UnsupportedSymbol {
12391239
span,
@@ -1247,7 +1247,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
12471247

12481248
args[0].immediate()
12491249
};
1250-
return match in_elem.kind() {
1250+
return match *in_elem.kind() {
12511251
ty::Int(_) | ty::Uint(_) => {
12521252
let r = bx.vector_reduce_op(input, $op);
12531253
Ok(if !$boolean {

src/type_of.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ fn uncached_gcc_type<'gcc, 'tcx>(
9090
Abi::Uninhabited | Abi::Aggregate { .. } => {}
9191
}
9292

93-
let name = match layout.ty.kind() {
93+
let name = match *layout.ty.kind() {
9494
// FIXME(eddyb) producing readable type names for trait objects can result
9595
// in problematically distinct types due to HRTB and subtyping (see #47638).
9696
// ty::Dynamic(..) |

0 commit comments

Comments
 (0)