Skip to content

Fix some more clippy warnings #78424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions compiler/rustc_arena/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ impl<T> TypedArena<T> {
// bytes, then this chunk will be least double the previous
// chunk's size.
new_cap = last_chunk.storage.len().min(HUGE_PAGE / elem_size / 2);
new_cap = new_cap * 2;
new_cap *= 2;
} else {
new_cap = PAGE / elem_size;
}
Expand Down Expand Up @@ -346,7 +346,7 @@ impl DroplessArena {
// bytes, then this chunk will be least double the previous
// chunk's size.
new_cap = last_chunk.storage.len().min(HUGE_PAGE / 2);
new_cap = new_cap * 2;
new_cap *= 2;
} else {
new_cap = PAGE;
}
Expand Down Expand Up @@ -562,10 +562,8 @@ impl DropArena {
// Record the destructors after doing the allocation as that may panic
// and would cause `object`'s destructor to run twice if it was recorded before
for i in 0..len {
destructors.push(DropType {
drop_fn: drop_for_type::<T>,
obj: start_ptr.offset(i as isize) as *mut u8,
});
destructors
.push(DropType { drop_fn: drop_for_type::<T>, obj: start_ptr.add(i) as *mut u8 });
}

slice::from_raw_parts_mut(start_ptr, len)
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,10 +490,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let count = generics
.params
.iter()
.filter(|param| match param.kind {
ast::GenericParamKind::Lifetime { .. } => true,
_ => false,
})
.filter(|param| matches!(param.kind, ast::GenericParamKind::Lifetime { .. }))
.count();
self.lctx.type_def_lifetime_params.insert(def_id.to_def_id(), count);
}
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_ast_lowering/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
self.lower_angle_bracketed_parameter_data(&Default::default(), param_mode, itctx)
};

let has_lifetimes = generic_args.args.iter().any(|arg| match arg {
GenericArg::Lifetime(_) => true,
_ => false,
});
let has_lifetimes =
generic_args.args.iter().any(|arg| matches!(arg, GenericArg::Lifetime(_)));
let first_generic_span = generic_args
.args
.iter()
Expand Down
12 changes: 5 additions & 7 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,13 +639,11 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
fn break_offset_if_not_bol(&mut self, n: usize, off: isize) {
if !self.is_beginning_of_line() {
self.break_offset(n, off)
} else {
if off != 0 && self.last_token().is_hardbreak_tok() {
// We do something pretty sketchy here: tuck the nonzero
// offset-adjustment we were going to deposit along with the
// break into the previous hardbreak.
self.replace_last_token(pp::Printer::hardbreak_tok_offset(off));
}
} else if off != 0 && self.last_token().is_hardbreak_tok() {
// We do something pretty sketchy here: tuck the nonzero
// offset-adjustment we were going to deposit along with the
// break into the previous hardbreak.
self.replace_last_token(pp::Printer::hardbreak_tok_offset(off));
}
}

Expand Down
58 changes: 28 additions & 30 deletions compiler/rustc_attr/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -901,38 +901,36 @@ pub fn find_repr_attrs(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
)
.emit();
}
} else {
if let Some(meta_item) = item.meta_item() {
if meta_item.has_name(sym::align) {
if let MetaItemKind::NameValue(ref value) = meta_item.kind {
recognised = true;
let mut err = struct_span_err!(
diagnostic,
item.span(),
E0693,
"incorrect `repr(align)` attribute format"
);
match value.kind {
ast::LitKind::Int(int, ast::LitIntType::Unsuffixed) => {
err.span_suggestion(
item.span(),
"use parentheses instead",
format!("align({})", int),
Applicability::MachineApplicable,
);
}
ast::LitKind::Str(s, _) => {
err.span_suggestion(
item.span(),
"use parentheses instead",
format!("align({})", s),
Applicability::MachineApplicable,
);
}
_ => {}
} else if let Some(meta_item) = item.meta_item() {
if meta_item.has_name(sym::align) {
if let MetaItemKind::NameValue(ref value) = meta_item.kind {
recognised = true;
let mut err = struct_span_err!(
diagnostic,
item.span(),
E0693,
"incorrect `repr(align)` attribute format"
);
match value.kind {
ast::LitKind::Int(int, ast::LitIntType::Unsuffixed) => {
err.span_suggestion(
item.span(),
"use parentheses instead",
format!("align({})", int),
Applicability::MachineApplicable,
);
}
ast::LitKind::Str(s, _) => {
err.span_suggestion(
item.span(),
"use parentheses instead",
format!("align({})", s),
Applicability::MachineApplicable,
);
}
err.emit();
_ => {}
}
err.emit();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub(crate) unsafe fn codegen(
let args = [usize, usize]; // size, align

let ty = llvm::LLVMFunctionType(void, args.as_ptr(), args.len() as c_uint, False);
let name = format!("__rust_alloc_error_handler");
let name = "__rust_alloc_error_handler".to_string();
let llfn = llvm::LLVMRustGetOrInsertFunction(llmod, name.as_ptr().cast(), name.len(), ty);
// -> ! DIFlagNoReturn
llvm::Attribute::NoReturn.apply_llfn(llvm::AttributePlace::Function, llfn);
Expand Down
10 changes: 4 additions & 6 deletions compiler/rustc_codegen_llvm/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,11 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
} else if options.contains(InlineAsmOptions::READONLY) {
llvm::Attribute::ReadOnly.apply_callsite(llvm::AttributePlace::Function, result);
}
} else if options.contains(InlineAsmOptions::NOMEM) {
llvm::Attribute::InaccessibleMemOnly
.apply_callsite(llvm::AttributePlace::Function, result);
} else {
if options.contains(InlineAsmOptions::NOMEM) {
llvm::Attribute::InaccessibleMemOnly
.apply_callsite(llvm::AttributePlace::Function, result);
} else {
// LLVM doesn't have an attribute to represent ReadOnly + SideEffect
}
// LLVM doesn't have an attribute to represent ReadOnly + SideEffect
}

// Write results to outputs
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ impl ThinLTOKeysMap {
let file = File::open(path)?;
for line in io::BufReader::new(file).lines() {
let line = line?;
let mut split = line.split(" ");
let mut split = line.split(' ');
let module = split.next().unwrap();
let key = split.next().unwrap();
assert_eq!(split.next(), None, "Expected two space-separated values, found {:?}", line);
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_codegen_llvm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,10 +732,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
let src_ty = self.cx.val_ty(val);
let float_width = self.cx.float_width(src_ty);
let int_width = self.cx.int_width(dest_ty);
match (int_width, float_width) {
(32, 32) | (32, 64) | (64, 32) | (64, 64) => true,
_ => false,
}
matches!((int_width, float_width), (32, 32) | (32, 64) | (64, 32) | (64, 64))
}

fn fptoui(&mut self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_codegen_llvm/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,8 @@ impl StaticMethods for CodegenCx<'ll, 'tcx> {

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

debuginfo::create_global_var_metadata(&self, def_id, g);
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_codegen_llvm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ pub unsafe fn create_module(
if llvm_util::get_major_version() < 9 {
target_data_layout = strip_function_ptr_alignment(target_data_layout);
}
if llvm_util::get_major_version() < 10 {
if sess.target.arch == "x86" || sess.target.arch == "x86_64" {
target_data_layout = strip_x86_address_spaces(target_data_layout);
}
if llvm_util::get_major_version() < 10
&& (sess.target.arch == "x86" || sess.target.arch == "x86_64")
{
target_data_layout = strip_x86_address_spaces(target_data_layout);
}

// Ensure the data-layout values hardcoded remain the defaults.
Expand Down Expand Up @@ -864,7 +864,7 @@ impl<'b, 'tcx> CodegenCx<'b, 'tcx> {
// user defined names
let mut name = String::with_capacity(prefix.len() + 6);
name.push_str(prefix);
name.push_str(".");
name.push('.');
base_n::push_str(idx as u128, base_n::ALPHANUMERIC_ONLY, &mut name);
name
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
name_to_append_suffix_to.push('<');
for (i, actual_type) in substs.types().enumerate() {
if i != 0 {
name_to_append_suffix_to.push_str(",");
name_to_append_suffix_to.push(',');
}

let actual_type =
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_data_structures/src/graph/scc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,7 @@ where
fn walk_unvisited_node(&mut self, depth: usize, node: G::Node) -> WalkReturn<S> {
debug!("walk_unvisited_node(depth = {:?}, node = {:?})", depth, node);

debug_assert!(match self.node_states[node] {
NodeState::NotVisited => true,
_ => false,
});
debug_assert!(matches!(self.node_states[node], NodeState::NotVisited));

// Push `node` onto the stack.
self.node_states[node] = NodeState::BeingVisited { depth };
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_data_structures/src/sso/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ where
V: Copy,
{
fn extend<T: IntoIterator<Item = (&'a K, &'a V)>>(&mut self, iter: T) {
self.extend(iter.into_iter().map(|(k, v)| (k.clone(), v.clone())))
self.extend(iter.into_iter().map(|(k, v)| (*k, *v)))
}

#[inline]
Expand Down Expand Up @@ -451,7 +451,7 @@ impl<'a, K, V> IntoIterator for &'a SsoHashMap<K, V> {
fn into_iter(self) -> Self::IntoIter {
match self {
SsoHashMap::Array(array) => EitherIter::Left(array.into_iter().map(adapt_array_ref_it)),
SsoHashMap::Map(map) => EitherIter::Right(map.into_iter()),
SsoHashMap::Map(map) => EitherIter::Right(map.iter()),
}
}
}
Expand All @@ -469,7 +469,7 @@ impl<'a, K, V> IntoIterator for &'a mut SsoHashMap<K, V> {
fn into_iter(self) -> Self::IntoIter {
match self {
SsoHashMap::Array(array) => EitherIter::Left(array.into_iter().map(adapt_array_mut_it)),
SsoHashMap::Map(map) => EitherIter::Right(map.into_iter()),
SsoHashMap::Map(map) => EitherIter::Right(map.iter_mut()),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ impl RustcDefaultCalls {
TargetList => {
let mut targets =
rustc_target::spec::TARGETS.iter().copied().collect::<Vec<_>>();
targets.sort();
targets.sort_unstable();
println!("{}", targets.join("\n"));
}
Sysroot => println!("{}", sess.sysroot.display()),
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_errors/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,7 @@ impl Emitter for JsonEmitter {
}

fn should_show_explain(&self) -> bool {
match self.json_rendered {
HumanReadableErrorType::Short(_) => false,
_ => true,
}
!matches!(self.json_rendered, HumanReadableErrorType::Short(_))
}
}

Expand Down
10 changes: 2 additions & 8 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,7 @@ pub enum SuggestionStyle {

impl SuggestionStyle {
fn hide_inline(&self) -> bool {
match *self {
SuggestionStyle::ShowCode => false,
_ => true,
}
!matches!(*self, SuggestionStyle::ShowCode)
}
}

Expand Down Expand Up @@ -1038,10 +1035,7 @@ impl Level {
}

pub fn is_failure_note(&self) -> bool {
match *self {
FailureNote => true,
_ => false,
}
matches!(*self, FailureNote)
}
}

Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_errors/src/snippet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,7 @@ impl Annotation {

pub fn takes_space(&self) -> bool {
// Multiline annotations always have to keep vertical space.
match self.annotation_type {
AnnotationType::MultilineStart(_) | AnnotationType::MultilineEnd(_) => true,
_ => false,
}
matches!(self.annotation_type, AnnotationType::MultilineStart(_) | AnnotationType::MultilineEnd(_))
}
}

Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_expand/src/mbe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,7 @@ impl TokenTree {

/// Returns `true` if the given token tree is delimited.
fn is_delimited(&self) -> bool {
match *self {
TokenTree::Delimited(..) => true,
_ => false,
}
matches!(*self, TokenTree::Delimited(..))
}

/// Returns `true` if the given token tree is a token of the given kind.
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_expand/src/mbe/macro_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,7 @@ enum Stack<'a, T> {
impl<'a, T> Stack<'a, T> {
/// Returns whether a stack is empty.
fn is_empty(&self) -> bool {
match *self {
Stack::Empty => true,
_ => false,
}
matches!(*self, Stack::Empty)
}

/// Returns a new stack with an element of top.
Expand Down
9 changes: 4 additions & 5 deletions compiler/rustc_expand/src/mbe/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1036,17 +1036,16 @@ fn token_can_be_followed_by_any(tok: &mbe::TokenTree) -> bool {
/// a fragment specifier (indeed, these fragments can be followed by
/// ANYTHING without fear of future compatibility hazards).
fn frag_can_be_followed_by_any(kind: NonterminalKind) -> bool {
match kind {
matches!(
kind,
NonterminalKind::Item // always terminated by `}` or `;`
| NonterminalKind::Block // exactly one token tree
| NonterminalKind::Ident // exactly one token tree
| NonterminalKind::Literal // exactly one token tree
| NonterminalKind::Meta // exactly one token tree
| NonterminalKind::Lifetime // exactly one token tree
| NonterminalKind::TT => true, // exactly one token tree

_ => false,
}
| NonterminalKind::TT // exactly one token tree
)
}

enum IsInFollow {
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_expand/src/placeholders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,10 @@ impl<'a, 'b> MutVisitor for PlaceholderExpander<'a, 'b> {

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

fn visit_mac(&mut self, _mac: &mut ast::MacCall) {
Expand Down
Loading