diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index 3799623563f..ae1b50a4176 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -1272,9 +1272,7 @@ pub fn parse_macro_name_and_helper_attrs( // Once we've located the `#[proc_macro_derive]` attribute, verify // that it's of the form `#[proc_macro_derive(Foo)]` or // `#[proc_macro_derive(Foo, attributes(A, ..))]` - let Some(list) = attr.meta_item_list() else { - return None; - }; + let list = attr.meta_item_list()?; if list.len() != 1 && list.len() != 2 { diag.span_err(attr.span, "attribute must have either one or two arguments"); return None; diff --git a/compiler/rustc_index/src/bit_set.rs b/compiler/rustc_index/src/bit_set.rs index cdc05095e68..33a8d6c11ff 100644 --- a/compiler/rustc_index/src/bit_set.rs +++ b/compiler/rustc_index/src/bit_set.rs @@ -1714,7 +1714,7 @@ impl SparseBitMatrix { } pub fn row(&self, row: R) -> Option<&HybridBitSet> { - if let Some(Some(row)) = self.rows.get(row) { Some(row) } else { None } + self.rows.get(row)?.as_ref() } /// Intersects `row` with `set`. `set` can be either `BitSet` or diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/find_anon_type.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/find_anon_type.rs index 135714af2a6..66d73f546af 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/find_anon_type.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/find_anon_type.rs @@ -25,21 +25,16 @@ pub(crate) fn find_anon_type<'tcx>( region: Region<'tcx>, br: &ty::BoundRegionKind, ) -> Option<(&'tcx hir::Ty<'tcx>, &'tcx hir::FnSig<'tcx>)> { - if let Some(anon_reg) = tcx.is_suitable_region(region) { - let hir_id = tcx.hir().local_def_id_to_hir_id(anon_reg.def_id); - let Some(fn_sig) = tcx.hir().get(hir_id).fn_sig() else { - return None - }; + let anon_reg = tcx.is_suitable_region(region)?; + let hir_id = tcx.hir().local_def_id_to_hir_id(anon_reg.def_id); + let fn_sig = tcx.hir().get(hir_id).fn_sig()?; - fn_sig - .decl - .inputs - .iter() - .find_map(|arg| find_component_for_bound_region(tcx, arg, br)) - .map(|ty| (ty, fn_sig)) - } else { - None - } + fn_sig + .decl + .inputs + .iter() + .find_map(|arg| find_component_for_bound_region(tcx, arg, br)) + .map(|ty| (ty, fn_sig)) } // This method creates a FindNestedTypeVisitor which returns the type corresponding diff --git a/compiler/rustc_mir_transform/src/early_otherwise_branch.rs b/compiler/rustc_mir_transform/src/early_otherwise_branch.rs index 5bde0c01412..33f201cbd28 100644 --- a/compiler/rustc_mir_transform/src/early_otherwise_branch.rs +++ b/compiler/rustc_mir_transform/src/early_otherwise_branch.rs @@ -336,9 +336,7 @@ fn evaluate_candidate<'tcx>( Some(poss) } }; - let Some((_, child)) = targets.iter().next() else { - return None - }; + let (_, child) = targets.iter().next()?; let child_terminator = &bbs[child].terminator(); let TerminatorKind::SwitchInt { switch_ty: child_ty, diff --git a/compiler/rustc_parse/src/lexer/unicode_chars.rs b/compiler/rustc_parse/src/lexer/unicode_chars.rs index 1d63b79adc5..2e8e23a50eb 100644 --- a/compiler/rustc_parse/src/lexer/unicode_chars.rs +++ b/compiler/rustc_parse/src/lexer/unicode_chars.rs @@ -338,9 +338,7 @@ pub(super) fn check_for_substitution<'a>( ch: char, err: &mut Diagnostic, ) -> Option { - let Some(&(_u_char, u_name, ascii_char)) = UNICODE_ARRAY.iter().find(|&&(c, _, _)| c == ch) else { - return None; - }; + let &(_u_char, u_name, ascii_char) = UNICODE_ARRAY.iter().find(|&&(c, _, _)| c == ch)?; let span = Span::with_root_ctxt(pos, pos + Pos::from_usize(ch.len_utf8())); diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index d77cc917e2f..4f08a61b623 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -1183,9 +1183,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { ident: Symbol, kind: &AssocItemKind, ) -> Option { - let Some((module, _)) = &self.current_trait_ref else { - return None; - }; + let (module, _) = self.current_trait_ref.as_ref()?; if ident == kw::Underscore { // We do nothing for `_`. return None; diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs index 152be4bd538..8feb7170983 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs @@ -757,7 +757,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { formal_args: &[Ty<'tcx>], ) -> Option>> { let formal_ret = self.resolve_vars_with_obligations(formal_ret); - let Some(ret_ty) = expected_ret.only_has_type(self) else { return None }; + let ret_ty = expected_ret.only_has_type(self)?; // HACK(oli-obk): This is a hack to keep RPIT and TAIT in sync wrt their behaviour. // Without it, the inference diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index a070cef2272..476a89523a5 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1305,7 +1305,7 @@ fn clean_qpath(hir_ty: &hir::Ty<'_>, cx: &mut DocContext<'_>) -> Type { fn maybe_expand_private_type_alias(cx: &mut DocContext<'_>, path: &hir::Path<'_>) -> Option { let Res::Def(DefKind::TyAlias, def_id) = path.res else { return None }; // Substitute private type aliases - let Some(def_id) = def_id.as_local() else { return None }; + let def_id = def_id.as_local()?; let alias = if !cx.cache.access_levels.is_exported(def_id.to_def_id()) { &cx.tcx.hir().expect_item(def_id).kind } else {