Skip to content

Commit

Permalink
Manual cleanup of some is_{or_none|some_and} usages
Browse files Browse the repository at this point in the history
  • Loading branch information
yotamofek committed Jan 19, 2025
1 parent 264fa0f commit 1951d86
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 8 deletions.
3 changes: 2 additions & 1 deletion compiler/rustc_errors/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,8 @@ impl DiagnosticSpan {
// is an empty string, increase the length to include the newline so we don't
// leave an empty line
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)
&& after.starts_with('\n')
{
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use std::backtrace::{Backtrace, BacktraceStatus};
use std::borrow::Cow;
use std::cell::Cell;
use std::error::Report;
use std::ffi::OsStr;
use std::hash::Hash;
use std::io::Write;
use std::num::NonZero;
Expand Down Expand Up @@ -1717,7 +1718,7 @@ impl DiagCtxtInner {
let bugs: Vec<_> =
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 mut out = self
.ice_file
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_metadata/src/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,8 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
// Any descendants of `std` should be private. These crates are usually not marked
// private in metadata, so we ignore that field.
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl<Prov: Provenance> ProvenanceMap<Prov> {
debug_assert!(prov.len() <= 1);
if let Some(entry) = prov.first() {
// 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)
} else {
// Look up per-byte provenance.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ pub fn suggest_constraining_type_params<'a>(
.collect();

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() {
continue;
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ impl OutputTypes {

/// Returns `true` if user specified a name and not just produced type
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>> {
Expand Down Expand Up @@ -1951,7 +1951,7 @@ fn collect_print_requests(
matches: &getopts::Matches,
) -> Vec<PrintRequest> {
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 });
cg.target_cpu = None;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,8 @@ fn make_elided_region_spans_suggs<'a>(

let mut process_consecutive_brackets =
|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;
} else if let Some(bracket_span) = bracket_span.take() {
Expand Down

0 comments on commit 1951d86

Please sign in to comment.