1
Fork 0

Manual cleanup of some is_{or_none|some_and} usages

This commit is contained in:
Yotam Ofek 2025-01-19 20:50:43 +00:00
parent 264fa0fc54
commit 1951d86a35
7 changed files with 12 additions and 8 deletions

View file

@ -463,7 +463,8 @@ impl DiagnosticSpan {
// is an empty string, increase the length to include the newline so we don't // is an empty string, increase the length to include the newline so we don't
// leave an empty line // leave an empty line
if start.col.0 == 0 if start.col.0 == 0
&& suggestion.is_some_and(|(s, _)| s.is_empty()) && let Some((suggestion, _)) = suggestion
&& suggestion.is_empty()
&& let Ok(after) = je.sm.span_to_next_source(span) && let Ok(after) = je.sm.span_to_next_source(span)
&& after.starts_with('\n') && after.starts_with('\n')
{ {

View file

@ -35,6 +35,7 @@ use std::backtrace::{Backtrace, BacktraceStatus};
use std::borrow::Cow; use std::borrow::Cow;
use std::cell::Cell; use std::cell::Cell;
use std::error::Report; use std::error::Report;
use std::ffi::OsStr;
use std::hash::Hash; use std::hash::Hash;
use std::io::Write; use std::io::Write;
use std::num::NonZero; use std::num::NonZero;
@ -1717,7 +1718,7 @@ impl DiagCtxtInner {
let bugs: Vec<_> = let bugs: Vec<_> =
std::mem::take(&mut self.delayed_bugs).into_iter().map(|(b, _)| b).collect(); std::mem::take(&mut self.delayed_bugs).into_iter().map(|(b, _)| b).collect();
let backtrace = std::env::var_os("RUST_BACKTRACE").is_none_or(|x| &x != "0"); let backtrace = std::env::var_os("RUST_BACKTRACE").as_deref() != Some(OsStr::new("0"));
let decorate = backtrace || self.ice_file.is_none(); let decorate = backtrace || self.ice_file.is_none();
let mut out = self let mut out = self
.ice_file .ice_file

View file

@ -417,7 +417,8 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
// Any descendants of `std` should be private. These crates are usually not marked // Any descendants of `std` should be private. These crates are usually not marked
// private in metadata, so we ignore that field. // private in metadata, so we ignore that field.
if extern_private.is_none() if extern_private.is_none()
&& dep_root.is_some_and(|d| STDLIB_STABLE_CRATES.contains(&d.name)) && let Some(dep) = dep_root
&& STDLIB_STABLE_CRATES.contains(&dep.name)
{ {
return true; return true;
} }

View file

@ -97,7 +97,7 @@ impl<Prov: Provenance> ProvenanceMap<Prov> {
debug_assert!(prov.len() <= 1); debug_assert!(prov.len() <= 1);
if let Some(entry) = prov.first() { if let Some(entry) = prov.first() {
// If it overlaps with this byte, it is on this byte. // If it overlaps with this byte, it is on this byte.
debug_assert!(self.bytes.as_ref().is_none_or(|b| b.get(&offset).is_none())); debug_assert!(self.bytes.as_ref().is_none_or(|b| !b.contains_key(&offset)));
Some(entry.1) Some(entry.1)
} else { } else {
// Look up per-byte provenance. // Look up per-byte provenance.

View file

@ -336,7 +336,7 @@ pub fn suggest_constraining_type_params<'a>(
.collect(); .collect();
constraints constraints
.retain(|(_, def_id, _)| def_id.map_or(true, |def| !bound_trait_defs.contains(&def))); .retain(|(_, def_id, _)| def_id.is_none_or(|def| !bound_trait_defs.contains(&def)));
if constraints.is_empty() { if constraints.is_empty() {
continue; continue;

View file

@ -675,7 +675,7 @@ impl OutputTypes {
/// Returns `true` if user specified a name and not just produced type /// Returns `true` if user specified a name and not just produced type
pub fn contains_explicit_name(&self, key: &OutputType) -> bool { pub fn contains_explicit_name(&self, key: &OutputType) -> bool {
self.0.get(key).is_some_and(|f| f.is_some()) matches!(self.0.get(key), Some(Some(..)))
} }
pub fn iter(&self) -> BTreeMapIter<'_, OutputType, Option<OutFileName>> { pub fn iter(&self) -> BTreeMapIter<'_, OutputType, Option<OutFileName>> {
@ -1951,7 +1951,7 @@ fn collect_print_requests(
matches: &getopts::Matches, matches: &getopts::Matches,
) -> Vec<PrintRequest> { ) -> Vec<PrintRequest> {
let mut prints = Vec::<PrintRequest>::new(); let mut prints = Vec::<PrintRequest>::new();
if cg.target_cpu.as_ref().is_some_and(|s| s == "help") { if cg.target_cpu.as_deref() == Some("help") {
prints.push(PrintRequest { kind: PrintKind::TargetCPUs, out: OutFileName::Stdout }); prints.push(PrintRequest { kind: PrintKind::TargetCPUs, out: OutFileName::Stdout });
cg.target_cpu = None; cg.target_cpu = None;
}; };

View file

@ -420,7 +420,8 @@ fn make_elided_region_spans_suggs<'a>(
let mut process_consecutive_brackets = let mut process_consecutive_brackets =
|span: Option<Span>, spans_suggs: &mut Vec<(Span, String)>| { |span: Option<Span>, spans_suggs: &mut Vec<(Span, String)>| {
if span.is_some_and(|span| bracket_span.is_none_or(|bracket_span| span == bracket_span)) if let Some(span) = span
&& bracket_span.is_none_or(|bracket_span| span == bracket_span)
{ {
consecutive_brackets += 1; consecutive_brackets += 1;
} else if let Some(bracket_span) = bracket_span.take() { } else if let Some(bracket_span) = bracket_span.take() {