Skip to content

Commit ffe5288

Browse files
committed
Auto merge of rust-lang#78424 - jyn514:THE-PAPERCLIP-COMETH, r=davidtwco
Fix some more clippy warnings Found while working on rust-lang#77351. It turns out that `x.py clippy --fix` does work on that branch as long as you pass `CARGOFLAGS=--lib`.
2 parents 388ef34 + 5339bd1 commit ffe5288

File tree

69 files changed

+349
-616
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+349
-616
lines changed

compiler/rustc_arena/src/lib.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ impl<T> TypedArena<T> {
228228
// bytes, then this chunk will be least double the previous
229229
// chunk's size.
230230
new_cap = last_chunk.storage.len().min(HUGE_PAGE / elem_size / 2);
231-
new_cap = new_cap * 2;
231+
new_cap *= 2;
232232
} else {
233233
new_cap = PAGE / elem_size;
234234
}
@@ -346,7 +346,7 @@ impl DroplessArena {
346346
// bytes, then this chunk will be least double the previous
347347
// chunk's size.
348348
new_cap = last_chunk.storage.len().min(HUGE_PAGE / 2);
349-
new_cap = new_cap * 2;
349+
new_cap *= 2;
350350
} else {
351351
new_cap = PAGE;
352352
}
@@ -562,10 +562,8 @@ impl DropArena {
562562
// Record the destructors after doing the allocation as that may panic
563563
// and would cause `object`'s destructor to run twice if it was recorded before
564564
for i in 0..len {
565-
destructors.push(DropType {
566-
drop_fn: drop_for_type::<T>,
567-
obj: start_ptr.offset(i as isize) as *mut u8,
568-
});
565+
destructors
566+
.push(DropType { drop_fn: drop_for_type::<T>, obj: start_ptr.add(i) as *mut u8 });
569567
}
570568

571569
slice::from_raw_parts_mut(start_ptr, len)

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -490,10 +490,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
490490
let count = generics
491491
.params
492492
.iter()
493-
.filter(|param| match param.kind {
494-
ast::GenericParamKind::Lifetime { .. } => true,
495-
_ => false,
496-
})
493+
.filter(|param| matches!(param.kind, ast::GenericParamKind::Lifetime { .. }))
497494
.count();
498495
self.lctx.type_def_lifetime_params.insert(def_id.to_def_id(), count);
499496
}

compiler/rustc_ast_lowering/src/path.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
262262
self.lower_angle_bracketed_parameter_data(&Default::default(), param_mode, itctx)
263263
};
264264

265-
let has_lifetimes = generic_args.args.iter().any(|arg| match arg {
266-
GenericArg::Lifetime(_) => true,
267-
_ => false,
268-
});
265+
let has_lifetimes =
266+
generic_args.args.iter().any(|arg| matches!(arg, GenericArg::Lifetime(_)));
269267
let first_generic_span = generic_args
270268
.args
271269
.iter()

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -639,13 +639,11 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
639639
fn break_offset_if_not_bol(&mut self, n: usize, off: isize) {
640640
if !self.is_beginning_of_line() {
641641
self.break_offset(n, off)
642-
} else {
643-
if off != 0 && self.last_token().is_hardbreak_tok() {
644-
// We do something pretty sketchy here: tuck the nonzero
645-
// offset-adjustment we were going to deposit along with the
646-
// break into the previous hardbreak.
647-
self.replace_last_token(pp::Printer::hardbreak_tok_offset(off));
648-
}
642+
} else if off != 0 && self.last_token().is_hardbreak_tok() {
643+
// We do something pretty sketchy here: tuck the nonzero
644+
// offset-adjustment we were going to deposit along with the
645+
// break into the previous hardbreak.
646+
self.replace_last_token(pp::Printer::hardbreak_tok_offset(off));
649647
}
650648
}
651649

compiler/rustc_attr/src/builtin.rs

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -901,38 +901,36 @@ pub fn find_repr_attrs(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
901901
)
902902
.emit();
903903
}
904-
} else {
905-
if let Some(meta_item) = item.meta_item() {
906-
if meta_item.has_name(sym::align) {
907-
if let MetaItemKind::NameValue(ref value) = meta_item.kind {
908-
recognised = true;
909-
let mut err = struct_span_err!(
910-
diagnostic,
911-
item.span(),
912-
E0693,
913-
"incorrect `repr(align)` attribute format"
914-
);
915-
match value.kind {
916-
ast::LitKind::Int(int, ast::LitIntType::Unsuffixed) => {
917-
err.span_suggestion(
918-
item.span(),
919-
"use parentheses instead",
920-
format!("align({})", int),
921-
Applicability::MachineApplicable,
922-
);
923-
}
924-
ast::LitKind::Str(s, _) => {
925-
err.span_suggestion(
926-
item.span(),
927-
"use parentheses instead",
928-
format!("align({})", s),
929-
Applicability::MachineApplicable,
930-
);
931-
}
932-
_ => {}
904+
} else if let Some(meta_item) = item.meta_item() {
905+
if meta_item.has_name(sym::align) {
906+
if let MetaItemKind::NameValue(ref value) = meta_item.kind {
907+
recognised = true;
908+
let mut err = struct_span_err!(
909+
diagnostic,
910+
item.span(),
911+
E0693,
912+
"incorrect `repr(align)` attribute format"
913+
);
914+
match value.kind {
915+
ast::LitKind::Int(int, ast::LitIntType::Unsuffixed) => {
916+
err.span_suggestion(
917+
item.span(),
918+
"use parentheses instead",
919+
format!("align({})", int),
920+
Applicability::MachineApplicable,
921+
);
922+
}
923+
ast::LitKind::Str(s, _) => {
924+
err.span_suggestion(
925+
item.span(),
926+
"use parentheses instead",
927+
format!("align({})", s),
928+
Applicability::MachineApplicable,
929+
);
933930
}
934-
err.emit();
931+
_ => {}
935932
}
933+
err.emit();
936934
}
937935
}
938936
}

compiler/rustc_codegen_llvm/src/allocator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pub(crate) unsafe fn codegen(
9393
let args = [usize, usize]; // size, align
9494

9595
let ty = llvm::LLVMFunctionType(void, args.as_ptr(), args.len() as c_uint, False);
96-
let name = format!("__rust_alloc_error_handler");
96+
let name = "__rust_alloc_error_handler".to_string();
9797
let llfn = llvm::LLVMRustGetOrInsertFunction(llmod, name.as_ptr().cast(), name.len(), ty);
9898
// -> ! DIFlagNoReturn
9999
llvm::Attribute::NoReturn.apply_llfn(llvm::AttributePlace::Function, llfn);

compiler/rustc_codegen_llvm/src/asm.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,13 +302,11 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
302302
} else if options.contains(InlineAsmOptions::READONLY) {
303303
llvm::Attribute::ReadOnly.apply_callsite(llvm::AttributePlace::Function, result);
304304
}
305+
} else if options.contains(InlineAsmOptions::NOMEM) {
306+
llvm::Attribute::InaccessibleMemOnly
307+
.apply_callsite(llvm::AttributePlace::Function, result);
305308
} else {
306-
if options.contains(InlineAsmOptions::NOMEM) {
307-
llvm::Attribute::InaccessibleMemOnly
308-
.apply_callsite(llvm::AttributePlace::Function, result);
309-
} else {
310-
// LLVM doesn't have an attribute to represent ReadOnly + SideEffect
311-
}
309+
// LLVM doesn't have an attribute to represent ReadOnly + SideEffect
312310
}
313311

314312
// Write results to outputs

compiler/rustc_codegen_llvm/src/back/lto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ impl ThinLTOKeysMap {
900900
let file = File::open(path)?;
901901
for line in io::BufReader::new(file).lines() {
902902
let line = line?;
903-
let mut split = line.split(" ");
903+
let mut split = line.split(' ');
904904
let module = split.next().unwrap();
905905
let key = split.next().unwrap();
906906
assert_eq!(split.next(), None, "Expected two space-separated values, found {:?}", line);

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -732,10 +732,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
732732
let src_ty = self.cx.val_ty(val);
733733
let float_width = self.cx.float_width(src_ty);
734734
let int_width = self.cx.int_width(dest_ty);
735-
match (int_width, float_width) {
736-
(32, 32) | (32, 64) | (64, 32) | (64, 64) => true,
737-
_ => false,
738-
}
735+
matches!((int_width, float_width), (32, 32) | (32, 64) | (64, 32) | (64, 64))
739736
}
740737

741738
fn fptoui(&mut self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {

compiler/rustc_codegen_llvm/src/consts.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,10 +397,8 @@ impl StaticMethods for CodegenCx<'ll, 'tcx> {
397397

398398
// As an optimization, all shared statics which do not have interior
399399
// mutability are placed into read-only memory.
400-
if !is_mutable {
401-
if self.type_is_freeze(ty) {
402-
llvm::LLVMSetGlobalConstant(g, llvm::True);
403-
}
400+
if !is_mutable && self.type_is_freeze(ty) {
401+
llvm::LLVMSetGlobalConstant(g, llvm::True);
404402
}
405403

406404
debuginfo::create_global_var_metadata(&self, def_id, g);

0 commit comments

Comments
 (0)