Skip to content

Commit 8ef3bf2

Browse files
committed
a couple clippy::complexity fixes
map_identity filter_next option_as_ref_deref unnecessary_find_map redundant_slicing unnecessary_unwrap bool_comparison derivable_impls manual_flatten needless_borrowed_reference
1 parent 0196c2b commit 8ef3bf2

File tree

10 files changed

+20
-33
lines changed

10 files changed

+20
-33
lines changed

compiler/rustc_codegen_llvm/src/builder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1190,8 +1190,8 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
11901190
// Set KCFI operand bundle
11911191
let is_indirect_call = unsafe { llvm::LLVMIsAFunction(llfn).is_none() };
11921192
let kcfi_bundle =
1193-
if self.tcx.sess.is_sanitizer_kcfi_enabled() && fn_abi.is_some() && is_indirect_call {
1194-
let kcfi_typeid = kcfi_typeid_for_fnabi(self.tcx, fn_abi.unwrap());
1193+
if let Some(fn_abi) = fn_abi && self.tcx.sess.is_sanitizer_kcfi_enabled() && is_indirect_call {
1194+
let kcfi_typeid = kcfi_typeid_for_fnabi(self.tcx, fn_abi);
11951195
Some(llvm::OperandBundleDef::new("kcfi", &[self.const_u32(kcfi_typeid)]))
11961196
} else {
11971197
None

compiler/rustc_errors/src/emitter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2235,7 +2235,7 @@ impl EmitterWriter {
22352235
}
22362236
} else if is_multiline {
22372237
buffer.puts(*row_num, 0, &self.maybe_anonymized(line_num), Style::LineNumber);
2238-
match &highlight_parts[..] {
2238+
match &highlight_parts {
22392239
[SubstitutionHighlight { start: 0, end }] if *end == line_to_add.len() => {
22402240
buffer.puts(*row_num, max_line_num_len + 1, "+ ", Style::Addition);
22412241
}

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -2399,10 +2399,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
23992399
let suggestion =
24002400
if has_lifetimes { format!(" + {}", sub) } else { format!(": {}", sub) };
24012401
let mut suggestions = vec![(sp, suggestion)];
2402-
for add_lt_sugg in add_lt_suggs {
2403-
if let Some(add_lt_sugg) = add_lt_sugg {
2404-
suggestions.push(add_lt_sugg);
2405-
}
2402+
for add_lt_sugg in add_lt_suggs.into_iter().flatten() {
2403+
suggestions.push(add_lt_sugg);
24062404
}
24072405
err.multipart_suggestion_verbose(
24082406
format!("{msg}..."),
@@ -2426,11 +2424,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
24262424
};
24272425
let mut sugg =
24282426
vec![(sp, suggestion), (span.shrink_to_hi(), format!(" + {}", new_lt))];
2429-
for add_lt_sugg in add_lt_suggs.clone() {
2430-
if let Some(lt) = add_lt_sugg {
2431-
sugg.push(lt);
2432-
sugg.rotate_right(1);
2433-
}
2427+
for lt in add_lt_suggs.clone().into_iter().flatten() {
2428+
sugg.push(lt);
2429+
sugg.rotate_right(1);
24342430
}
24352431
// `MaybeIncorrect` due to issue #41966.
24362432
err.multipart_suggestion(msg, sugg, Applicability::MaybeIncorrect);

compiler/rustc_monomorphize/src/collector.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,8 @@ fn check_type_length_limit<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) {
651651
let (shrunk, written_to_path) = shrunk_instance_name(tcx, &instance);
652652
let span = tcx.def_span(instance.def_id());
653653
let mut path = PathBuf::new();
654-
let was_written = if written_to_path.is_some() {
655-
path = written_to_path.unwrap();
654+
let was_written = if let Some(path2) = written_to_path {
655+
path = path2;
656656
Some(())
657657
} else {
658658
None

compiler/rustc_span/src/hygiene.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ fn assert_default_hashing_controls<CTX: HashStableContext>(ctx: &CTX, msg: &str)
109109
// This is the case for instance when building a hash for name mangling.
110110
// Such configuration must not be used for metadata.
111111
HashingControls { hash_spans }
112-
if hash_spans == !ctx.unstable_opts_incremental_ignore_spans() => {}
112+
if hash_spans != ctx.unstable_opts_incremental_ignore_spans() => {}
113113
other => panic!("Attempted hashing of {msg} with non-default HashingControls: {other:?}"),
114114
}
115115
}

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -3888,8 +3888,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
38883888
if let Some(slice_ty) = candidate_impls
38893889
.iter()
38903890
.map(|trait_ref| trait_ref.trait_ref.self_ty())
3891-
.filter(|t| is_slice(*t))
3892-
.next()
3891+
.find(|t| is_slice(*t))
38933892
{
38943893
let msg = &format!("convert the array to a `{}` slice instead", slice_ty);
38953894

@@ -3936,7 +3935,7 @@ fn hint_missing_borrow<'tcx>(
39363935
// This could be a variant constructor, for example.
39373936
let Some(fn_decl) = found_node.fn_decl() else { return; };
39383937

3939-
let args = fn_decl.inputs.iter().map(|ty| ty);
3938+
let args = fn_decl.inputs.iter();
39403939

39413940
fn get_deref_type_and_refs(mut ty: Ty<'_>) -> (Ty<'_>, Vec<hir::Mutability>) {
39423941
let mut refs = vec![];

src/librustdoc/config.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,13 @@ use crate::passes::{self, Condition};
3131
use crate::scrape_examples::{AllCallLocations, ScrapeExamplesOptions};
3232
use crate::theme;
3333

34-
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
34+
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
3535
pub(crate) enum OutputFormat {
3636
Json,
37+
#[default]
3738
Html,
3839
}
3940

40-
impl Default for OutputFormat {
41-
fn default() -> OutputFormat {
42-
OutputFormat::Html
43-
}
44-
}
45-
4641
impl OutputFormat {
4742
pub(crate) fn is_json(&self) -> bool {
4843
matches!(self, OutputFormat::Json)

src/librustdoc/html/highlight.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ impl<'a, 'tcx, F: Write> TokenHandler<'a, 'tcx, F> {
177177
} else {
178178
// We only want to "open" the tag ourselves if we have more than one pending and if the
179179
// current parent tag is not the same as our pending content.
180-
let close_tag = if self.pending_elems.len() > 1 && current_class.is_some() {
181-
Some(enter_span(self.out, current_class.unwrap(), &self.href_context))
180+
let close_tag = if self.pending_elems.len() > 1 && let Some(current_class) = current_class {
181+
Some(enter_span(self.out, current_class, &self.href_context))
182182
} else {
183183
None
184184
};

src/librustdoc/html/render/sidebar.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,8 @@ pub(super) fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buf
113113
} else {
114114
("", "")
115115
};
116-
let version = if it.is_crate() {
117-
cx.cache().crate_version.as_ref().map(String::as_str).unwrap_or_default()
118-
} else {
119-
""
120-
};
116+
let version =
117+
if it.is_crate() { cx.cache().crate_version.as_deref().unwrap_or_default() } else { "" };
121118
let path: String = if !it.is_mod() {
122119
cx.current.iter().map(|s| s.as_str()).intersperse("::").collect()
123120
} else {

src/librustdoc/passes/collect_intra_doc_links.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ fn trait_impls_for<'a>(
810810
///
811811
/// These are common and we should just resolve to the trait in that case.
812812
fn is_derive_trait_collision<T>(ns: &PerNS<Result<Vec<(Res, T)>, ResolutionFailure<'_>>>) -> bool {
813-
if let (&Ok(ref type_ns), &Ok(ref macro_ns)) = (&ns.type_ns, &ns.macro_ns) {
813+
if let (Ok(type_ns), Ok(macro_ns)) = (&ns.type_ns, &ns.macro_ns) {
814814
type_ns.iter().any(|(res, _)| matches!(res, Res::Def(DefKind::Trait, _)))
815815
&& macro_ns
816816
.iter()

0 commit comments

Comments
 (0)