Skip to content

Commit 57c6ed0

Browse files
committed
Fix even more clippy warnings
1 parent bfecb18 commit 57c6ed0

File tree

53 files changed

+276
-520
lines changed

Some content is hidden

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

53 files changed

+276
-520
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_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_feature/src/builtin_attrs.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,7 @@ impl std::fmt::Debug for AttributeGate {
8383

8484
impl AttributeGate {
8585
fn is_deprecated(&self) -> bool {
86-
match *self {
87-
Self::Gated(Stability::Deprecated(_, _), ..) => true,
88-
_ => false,
89-
}
86+
matches!(*self, Self::Gated(Stability::Deprecated(_, _), ..))
9087
}
9188
}
9289

0 commit comments

Comments
 (0)