Skip to content

Commit 11cd4ff

Browse files
committed
Auto merge of #109852 - Nilstrieb:rollup-g3mgxxw, r=Nilstrieb
Rollup of 4 pull requests Successful merges: - #109839 (Improve grammar of Iterator.partition_in_place) - #109840 (Fix typo in std/src/os/fd/owned.rs) - #109844 (a couple clippy::complexity fixes) - #109846 (more clippy::complexity fixes (iter_kv_map, map_flatten, nonminimal_bool)) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 637d7fd + 59f394b commit 11cd4ff

File tree

27 files changed

+44
-66
lines changed

27 files changed

+44
-66
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_codegen_llvm/src/common.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,7 @@ pub(crate) fn get_dllimport<'tcx>(
378378
name: &str,
379379
) -> Option<&'tcx DllImport> {
380380
tcx.native_library(id)
381-
.map(|lib| lib.dll_imports.iter().find(|di| di.name.as_str() == name))
382-
.flatten()
381+
.and_then(|lib| lib.dll_imports.iter().find(|di| di.name.as_str() == name))
383382
}
384383

385384
pub(crate) fn is_mingw_gnu_toolchain(target: &Target) -> bool {

compiler/rustc_const_eval/src/transform/validate.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -677,8 +677,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
677677
);
678678
}
679679
if let Rvalue::CopyForDeref(place) = rvalue {
680-
if !place.ty(&self.body.local_decls, self.tcx).ty.builtin_deref(true).is_some()
681-
{
680+
if place.ty(&self.body.local_decls, self.tcx).ty.builtin_deref(true).is_none() {
682681
self.fail(
683682
location,
684683
"`CopyForDeref` should only be used for dereferenceable types",

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_hir_analysis/src/astconv/errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
483483
[segment] if segment.args.is_none() => {
484484
trait_bound_spans = vec![segment.ident.span];
485485
associated_types = associated_types
486-
.into_iter()
487-
.map(|(_, items)| (segment.ident.span, items))
486+
.into_values()
487+
.map(|items| (segment.ident.span, items))
488488
.collect();
489489
}
490490
_ => {}

compiler/rustc_hir_typeck/src/expr_use_visitor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
559559
// struct; however, when EUV is run during typeck, it
560560
// may not. This will generate an error earlier in typeck,
561561
// so we can just ignore it.
562-
if !self.tcx().sess.has_errors().is_some() {
562+
if self.tcx().sess.has_errors().is_none() {
563563
span_bug!(with_expr.span, "with expression doesn't evaluate to a struct");
564564
}
565565
}

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

+6-10
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
978978
let (_, sig, reg) = ty::print::FmtPrinter::new(self.tcx, Namespace::TypeNS)
979979
.name_all_regions(sig)
980980
.unwrap();
981-
let lts: Vec<String> = reg.into_iter().map(|(_, kind)| kind.to_string()).collect();
981+
let lts: Vec<String> = reg.into_values().map(|kind| kind.to_string()).collect();
982982
(if lts.is_empty() { String::new() } else { format!("for<{}> ", lts.join(", ")) }, sig)
983983
};
984984

@@ -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_middle/src/middle/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub mod lib_features {
1919
.stable
2020
.iter()
2121
.map(|(f, (s, _))| (*f, Some(*s)))
22-
.chain(self.unstable.iter().map(|(f, _)| (*f, None)))
22+
.chain(self.unstable.keys().map(|f| (*f, None)))
2323
.collect();
2424
all_features.sort_unstable_by(|a, b| a.0.as_str().partial_cmp(b.0.as_str()).unwrap());
2525
all_features

compiler/rustc_middle/src/ty/consts/valtree.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl<'tcx> ValTree<'tcx> {
7979
}
8080

8181
pub fn try_to_target_usize(self, tcx: TyCtxt<'tcx>) -> Option<u64> {
82-
self.try_to_scalar_int().map(|s| s.try_to_target_usize(tcx).ok()).flatten()
82+
self.try_to_scalar_int().and_then(|s| s.try_to_target_usize(tcx).ok())
8383
}
8484

8585
/// Get the values inside the ValTree as a slice of bytes. This only works for

compiler/rustc_mir_build/src/build/expr/as_constant.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,21 @@ pub fn as_constant_inner<'tcx>(
6262
Constant { span, user_ty: None, literal }
6363
}
6464
ExprKind::NonHirLiteral { lit, ref user_ty } => {
65-
let user_ty = user_ty.as_ref().map(push_cuta).flatten();
65+
let user_ty = user_ty.as_ref().and_then(push_cuta);
6666

6767
let literal = ConstantKind::Val(ConstValue::Scalar(Scalar::Int(lit)), ty);
6868

6969
Constant { span, user_ty, literal }
7070
}
7171
ExprKind::ZstLiteral { ref user_ty } => {
72-
let user_ty = user_ty.as_ref().map(push_cuta).flatten();
72+
let user_ty = user_ty.as_ref().and_then(push_cuta);
7373

7474
let literal = ConstantKind::Val(ConstValue::ZeroSized, ty);
7575

7676
Constant { span, user_ty, literal }
7777
}
7878
ExprKind::NamedConst { def_id, substs, ref user_ty } => {
79-
let user_ty = user_ty.as_ref().map(push_cuta).flatten();
79+
let user_ty = user_ty.as_ref().and_then(push_cuta);
8080

8181
let uneval = mir::UnevaluatedConst::new(ty::WithOptConstParam::unknown(def_id), substs);
8282
let literal = ConstantKind::Unevaluated(uneval, ty);

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_monomorphize/src/partitioning/default.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,7 @@ impl<'tcx> Partitioner<'tcx> for DefaultPartitioning {
8989
}
9090

9191
PreInliningPartitioning {
92-
codegen_units: codegen_units
93-
.into_iter()
94-
.map(|(_, codegen_unit)| codegen_unit)
95-
.collect(),
92+
codegen_units: codegen_units.into_values().map(|codegen_unit| codegen_unit).collect(),
9693
roots,
9794
internalization_candidates,
9895
}

compiler/rustc_passes/src/entry.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_>) {
206206
// The file may be empty, which leads to the diagnostic machinery not emitting this
207207
// note. This is a relatively simple way to detect that case and emit a span-less
208208
// note instead.
209-
let file_empty = !tcx.sess.source_map().lookup_line(sp.hi()).is_ok();
209+
let file_empty = tcx.sess.source_map().lookup_line(sp.hi()).is_err();
210210

211211
tcx.sess.emit_err(NoMainErr {
212212
sp,

compiler/rustc_resolve/src/diagnostics.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1669,8 +1669,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
16691669
) -> Option<Symbol> {
16701670
let mut candidates = self
16711671
.extern_prelude
1672-
.iter()
1673-
.map(|(ident, _)| ident.name)
1672+
.keys()
1673+
.map(|ident| ident.name)
16741674
.chain(
16751675
self.module_map
16761676
.iter()
@@ -2007,7 +2007,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
20072007
// 1) some consistent ordering for emitted diagnostics, and
20082008
// 2) `std` suggestions before `core` suggestions.
20092009
let mut extern_crate_names =
2010-
self.extern_prelude.iter().map(|(ident, _)| ident.name).collect::<Vec<_>>();
2010+
self.extern_prelude.keys().map(|ident| ident.name).collect::<Vec<_>>();
20112011
extern_crate_names.sort_by(|a, b| b.as_str().partial_cmp(a.as_str()).unwrap());
20122012

20132013
for name in extern_crate_names.into_iter() {

compiler/rustc_resolve/src/ident.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
389389
}
390390
}
391391

392-
assert!(force || !finalize.is_some()); // `finalize` implies `force`
392+
assert!(force || finalize.is_none()); // `finalize` implies `force`
393393

394394
// Make sure `self`, `super` etc produce an error when passed to here.
395395
if orig_ident.is_path_segment_keyword() {

compiler/rustc_resolve/src/late.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2421,8 +2421,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
24212421
.iter()
24222422
.rfind(|r| matches!(r.kind, ItemRibKind(_)))
24232423
.expect("associated item outside of an item");
2424-
seen_bindings
2425-
.extend(parent_rib.bindings.iter().map(|(ident, _)| (*ident, ident.span)));
2424+
seen_bindings.extend(parent_rib.bindings.keys().map(|ident| (*ident, ident.span)));
24262425
};
24272426
add_bindings_for_ns(ValueNS);
24282427
add_bindings_for_ns(TypeNS);

compiler/rustc_session/src/options.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ mod parse {
911911
let mut seen_instruction_threshold = false;
912912
let mut seen_skip_entry = false;
913913
let mut seen_skip_exit = false;
914-
for option in v.into_iter().map(|v| v.split(',')).flatten() {
914+
for option in v.into_iter().flat_map(|v| v.split(',')) {
915915
match option {
916916
"always" if !seen_always && !seen_never => {
917917
options.always = true;

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![];

compiler/rustc_trait_selection/src/traits/outlives_bounds.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ impl<'a, 'tcx: 'a> InferCtxtExt<'a, 'tcx> for InferCtxt<'tcx> {
110110
body_id: LocalDefId,
111111
tys: FxIndexSet<Ty<'tcx>>,
112112
) -> Bounds<'a, 'tcx> {
113-
tys.into_iter()
114-
.map(move |ty| self.implied_outlives_bounds(param_env, body_id, ty))
115-
.flatten()
113+
tys.into_iter().flat_map(move |ty| self.implied_outlives_bounds(param_env, body_id, ty))
116114
}
117115
}

compiler/rustc_traits/src/chalk/lowering.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -909,8 +909,7 @@ pub(crate) fn collect_bound_vars<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
909909
.or_else(|| bug!("Skipped bound var index: parameters={:?}", parameters));
910910
});
911911

912-
let binders =
913-
chalk_ir::VariableKinds::from_iter(interner, parameters.into_iter().map(|(_, v)| v));
912+
let binders = chalk_ir::VariableKinds::from_iter(interner, parameters.into_values());
914913

915914
(new_ty, binders, named_parameters)
916915
}

library/core/src/iter/traits/iterator.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2120,8 +2120,8 @@ pub trait Iterator {
21202120
///
21212121
/// # Current implementation
21222122
///
2123-
/// Current algorithms tries finding the first element for which the predicate evaluates
2124-
/// to false, and the last element for which it evaluates to true and repeatedly swaps them.
2123+
/// The current algorithm tries to find the first element for which the predicate evaluates
2124+
/// to false and the last element for which it evaluates to true, and repeatedly swaps them.
21252125
///
21262126
/// Time complexity: *O*(*n*)
21272127
///

library/std/src/os/fd/owned.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ impl AsFd for OwnedFd {
268268
#[inline]
269269
fn as_fd(&self) -> BorrowedFd<'_> {
270270
// Safety: `OwnedFd` and `BorrowedFd` have the same validity
271-
// invariants, and the `BorrowdFd` is bounded by the lifetime
271+
// invariants, and the `BorrowedFd` is bounded by the lifetime
272272
// of `&self`.
273273
unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) }
274274
}

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)