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

+4-6
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

+1-4
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

+2-4
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

+5-7
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

+28-30
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

+1-1
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

+4-6
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

+1-1
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

+1-4
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

+2-4
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);

compiler/rustc_codegen_llvm/src/context.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ pub unsafe fn create_module(
122122
if llvm_util::get_major_version() < 9 {
123123
target_data_layout = strip_function_ptr_alignment(target_data_layout);
124124
}
125-
if llvm_util::get_major_version() < 10 {
126-
if sess.target.arch == "x86" || sess.target.arch == "x86_64" {
127-
target_data_layout = strip_x86_address_spaces(target_data_layout);
128-
}
125+
if llvm_util::get_major_version() < 10
126+
&& (sess.target.arch == "x86" || sess.target.arch == "x86_64")
127+
{
128+
target_data_layout = strip_x86_address_spaces(target_data_layout);
129129
}
130130

131131
// Ensure the data-layout values hardcoded remain the defaults.
@@ -864,7 +864,7 @@ impl<'b, 'tcx> CodegenCx<'b, 'tcx> {
864864
// user defined names
865865
let mut name = String::with_capacity(prefix.len() + 6);
866866
name.push_str(prefix);
867-
name.push_str(".");
867+
name.push('.');
868868
base_n::push_str(idx as u128, base_n::ALPHANUMERIC_ONLY, &mut name);
869869
name
870870
}

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
435435
name_to_append_suffix_to.push('<');
436436
for (i, actual_type) in substs.types().enumerate() {
437437
if i != 0 {
438-
name_to_append_suffix_to.push_str(",");
438+
name_to_append_suffix_to.push(',');
439439
}
440440

441441
let actual_type =

compiler/rustc_data_structures/src/graph/scc/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,7 @@ where
307307
fn walk_unvisited_node(&mut self, depth: usize, node: G::Node) -> WalkReturn<S> {
308308
debug!("walk_unvisited_node(depth = {:?}, node = {:?})", depth, node);
309309

310-
debug_assert!(match self.node_states[node] {
311-
NodeState::NotVisited => true,
312-
_ => false,
313-
});
310+
debug_assert!(matches!(self.node_states[node], NodeState::NotVisited));
314311

315312
// Push `node` onto the stack.
316313
self.node_states[node] = NodeState::BeingVisited { depth };

compiler/rustc_data_structures/src/sso/map.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ where
395395
V: Copy,
396396
{
397397
fn extend<T: IntoIterator<Item = (&'a K, &'a V)>>(&mut self, iter: T) {
398-
self.extend(iter.into_iter().map(|(k, v)| (k.clone(), v.clone())))
398+
self.extend(iter.into_iter().map(|(k, v)| (*k, *v)))
399399
}
400400

401401
#[inline]
@@ -451,7 +451,7 @@ impl<'a, K, V> IntoIterator for &'a SsoHashMap<K, V> {
451451
fn into_iter(self) -> Self::IntoIter {
452452
match self {
453453
SsoHashMap::Array(array) => EitherIter::Left(array.into_iter().map(adapt_array_ref_it)),
454-
SsoHashMap::Map(map) => EitherIter::Right(map.into_iter()),
454+
SsoHashMap::Map(map) => EitherIter::Right(map.iter()),
455455
}
456456
}
457457
}
@@ -469,7 +469,7 @@ impl<'a, K, V> IntoIterator for &'a mut SsoHashMap<K, V> {
469469
fn into_iter(self) -> Self::IntoIter {
470470
match self {
471471
SsoHashMap::Array(array) => EitherIter::Left(array.into_iter().map(adapt_array_mut_it)),
472-
SsoHashMap::Map(map) => EitherIter::Right(map.into_iter()),
472+
SsoHashMap::Map(map) => EitherIter::Right(map.iter_mut()),
473473
}
474474
}
475475
}

compiler/rustc_driver/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ impl RustcDefaultCalls {
716716
TargetList => {
717717
let mut targets =
718718
rustc_target::spec::TARGETS.iter().copied().collect::<Vec<_>>();
719-
targets.sort();
719+
targets.sort_unstable();
720720
println!("{}", targets.join("\n"));
721721
}
722722
Sysroot => println!("{}", sess.sysroot.display()),

compiler/rustc_errors/src/json.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,7 @@ impl Emitter for JsonEmitter {
136136
}
137137

138138
fn should_show_explain(&self) -> bool {
139-
match self.json_rendered {
140-
HumanReadableErrorType::Short(_) => false,
141-
_ => true,
142-
}
139+
!matches!(self.json_rendered, HumanReadableErrorType::Short(_))
143140
}
144141
}
145142

compiler/rustc_errors/src/lib.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,7 @@ pub enum SuggestionStyle {
9191

9292
impl SuggestionStyle {
9393
fn hide_inline(&self) -> bool {
94-
match *self {
95-
SuggestionStyle::ShowCode => false,
96-
_ => true,
97-
}
94+
!matches!(*self, SuggestionStyle::ShowCode)
9895
}
9996
}
10097

@@ -1038,10 +1035,7 @@ impl Level {
10381035
}
10391036

10401037
pub fn is_failure_note(&self) -> bool {
1041-
match *self {
1042-
FailureNote => true,
1043-
_ => false,
1044-
}
1038+
matches!(*self, FailureNote)
10451039
}
10461040
}
10471041

compiler/rustc_errors/src/snippet.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,7 @@ impl Annotation {
158158

159159
pub fn takes_space(&self) -> bool {
160160
// Multiline annotations always have to keep vertical space.
161-
match self.annotation_type {
162-
AnnotationType::MultilineStart(_) | AnnotationType::MultilineEnd(_) => true,
163-
_ => false,
164-
}
161+
matches!(self.annotation_type, AnnotationType::MultilineStart(_) | AnnotationType::MultilineEnd(_))
165162
}
166163
}
167164

compiler/rustc_expand/src/mbe.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,7 @@ impl TokenTree {
102102

103103
/// Returns `true` if the given token tree is delimited.
104104
fn is_delimited(&self) -> bool {
105-
match *self {
106-
TokenTree::Delimited(..) => true,
107-
_ => false,
108-
}
105+
matches!(*self, TokenTree::Delimited(..))
109106
}
110107

111108
/// Returns `true` if the given token tree is a token of the given kind.

compiler/rustc_expand/src/mbe/macro_check.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,7 @@ enum Stack<'a, T> {
134134
impl<'a, T> Stack<'a, T> {
135135
/// Returns whether a stack is empty.
136136
fn is_empty(&self) -> bool {
137-
match *self {
138-
Stack::Empty => true,
139-
_ => false,
140-
}
137+
matches!(*self, Stack::Empty)
141138
}
142139

143140
/// Returns a new stack with an element of top.

compiler/rustc_expand/src/mbe/macro_rules.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1036,17 +1036,16 @@ fn token_can_be_followed_by_any(tok: &mbe::TokenTree) -> bool {
10361036
/// a fragment specifier (indeed, these fragments can be followed by
10371037
/// ANYTHING without fear of future compatibility hazards).
10381038
fn frag_can_be_followed_by_any(kind: NonterminalKind) -> bool {
1039-
match kind {
1039+
matches!(
1040+
kind,
10401041
NonterminalKind::Item // always terminated by `}` or `;`
10411042
| NonterminalKind::Block // exactly one token tree
10421043
| NonterminalKind::Ident // exactly one token tree
10431044
| NonterminalKind::Literal // exactly one token tree
10441045
| NonterminalKind::Meta // exactly one token tree
10451046
| NonterminalKind::Lifetime // exactly one token tree
1046-
| NonterminalKind::TT => true, // exactly one token tree
1047-
1048-
_ => false,
1049-
}
1047+
| NonterminalKind::TT // exactly one token tree
1048+
)
10501049
}
10511050

10521051
enum IsInFollow {

compiler/rustc_expand/src/placeholders.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,10 @@ impl<'a, 'b> MutVisitor for PlaceholderExpander<'a, 'b> {
345345

346346
fn visit_mod(&mut self, module: &mut ast::Mod) {
347347
noop_visit_mod(module, self);
348-
module.items.retain(|item| match item.kind {
349-
ast::ItemKind::MacCall(_) if !self.cx.ecfg.keep_macs => false, // remove macro definitions
350-
_ => true,
351-
});
348+
// remove macro definitions
349+
module.items.retain(
350+
|item| !matches!(item.kind, ast::ItemKind::MacCall(_) if !self.cx.ecfg.keep_macs),
351+
);
352352
}
353353

354354
fn visit_mac(&mut self, _mac: &mut ast::MacCall) {

0 commit comments

Comments
 (0)