From 0437a0c372be237b6796ac0791d5f0c828aa8b42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sun, 17 Mar 2024 13:37:54 +0100 Subject: [PATCH] some minor code simplifications --- compiler/rustc_hir_typeck/src/callee.rs | 2 +- .../rustc_mir_transform/src/coverage/spans/from_mir.rs | 5 ++--- compiler/rustc_session/src/config.rs | 8 +------- src/librustdoc/clean/mod.rs | 2 +- src/librustdoc/clean/utils.rs | 2 +- src/librustdoc/html/render/mod.rs | 4 ++-- 6 files changed, 8 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/callee.rs b/compiler/rustc_hir_typeck/src/callee.rs index 25d3453137988..9a500fa712bf3 100644 --- a/compiler/rustc_hir_typeck/src/callee.rs +++ b/compiler/rustc_hir_typeck/src/callee.rs @@ -755,7 +755,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if let hir::ExprKind::Path(hir::QPath::Resolved(None, path)) = callee_expr.kind && let Res::Local(_) = path.res - && let [segment] = &path.segments[..] + && let [segment] = &path.segments { for id in self.tcx.hir().items() { if let Some(node) = self.tcx.hir().get_if_local(id.owner_id.into()) diff --git a/compiler/rustc_mir_transform/src/coverage/spans/from_mir.rs b/compiler/rustc_mir_transform/src/coverage/spans/from_mir.rs index 86097bdcd9537..3f6a4156044e8 100644 --- a/compiler/rustc_mir_transform/src/coverage/spans/from_mir.rs +++ b/compiler/rustc_mir_transform/src/coverage/spans/from_mir.rs @@ -401,9 +401,8 @@ pub(super) fn extract_branch_mappings( } let (span, _) = unexpand_into_body_span_with_visible_macro(raw_span, body_span)?; - let bcb_from_marker = |marker: BlockMarkerId| { - Some(basic_coverage_blocks.bcb_from_bb(block_markers[marker]?)?) - }; + let bcb_from_marker = + |marker: BlockMarkerId| basic_coverage_blocks.bcb_from_bb(block_markers[marker]?); let true_bcb = bcb_from_marker(true_marker)?; let false_bcb = bcb_from_marker(false_marker)?; diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index b7ee2c9802541..e56684808bb50 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -144,18 +144,12 @@ pub enum InstrumentCoverage { } /// Individual flag values controlled by `-Z coverage-options`. -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Default)] pub struct CoverageOptions { /// Add branch coverage instrumentation. pub branch: bool, } -impl Default for CoverageOptions { - fn default() -> Self { - Self { branch: false } - } -} - /// Settings for `-Z instrument-xray` flag. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] pub struct InstrumentXRay { diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index dfc026fe50bb4..855fb132fc877 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1572,7 +1572,7 @@ fn first_non_private<'tcx>( path: &hir::Path<'tcx>, ) -> Option { let target_def_id = path.res.opt_def_id()?; - let (parent_def_id, ident) = match &path.segments[..] { + let (parent_def_id, ident) = match &path.segments { [] => return None, // Relative paths are available in the same scope as the owner. [leaf] => (cx.tcx.local_parent(hir_id.owner.def_id), leaf.ident), diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index 0b20cca3bcab2..365d63d965744 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -598,7 +598,7 @@ pub(crate) fn has_doc_flag(tcx: TyCtxt<'_>, did: DefId, flag: Symbol) -> bool { /// Set by `bootstrap::Builder::doc_rust_lang_org_channel` in order to keep tests passing on beta/stable. pub(crate) const DOC_RUST_LANG_ORG_CHANNEL: &str = env!("DOC_RUST_LANG_ORG_CHANNEL"); pub(crate) static DOC_CHANNEL: Lazy<&'static str> = - Lazy::new(|| DOC_RUST_LANG_ORG_CHANNEL.rsplit('/').filter(|c| !c.is_empty()).next().unwrap()); + Lazy::new(|| DOC_RUST_LANG_ORG_CHANNEL.rsplit('/').find(|c| !c.is_empty()).unwrap()); /// Render a sequence of macro arms in a format suitable for displaying to the user /// as part of an item declaration. diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 6c5040414bced..f1887684797a6 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -150,13 +150,13 @@ impl RenderType { string.push('{'); write_optional_id(self.id, string); string.push('{'); - for generic in &self.generics.as_ref().map(Vec::as_slice).unwrap_or_default()[..] { + for generic in &self.generics.as_deref().unwrap_or_default()[..] { generic.write_to_string(string); } string.push('}'); if self.bindings.is_some() { string.push('{'); - for binding in &self.bindings.as_ref().map(Vec::as_slice).unwrap_or_default()[..] { + for binding in &self.bindings.as_deref().unwrap_or_default()[..] { string.push('{'); binding.0.write_to_string(string); string.push('{');