Skip to content

Commit d505582

Browse files
authored
Rollup merge of #113084 - WaffleLapkin:less_map_or, r=Nilstrieb
Simplify some conditions r? `@Nilstrieb` Some things taken out of my `is_none_or` pr.
2 parents db11b77 + ef05533 commit d505582

File tree

11 files changed

+35
-45
lines changed

11 files changed

+35
-45
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -623,13 +623,12 @@ impl<'a> AstValidator<'a> {
623623
fn maybe_lint_missing_abi(&mut self, span: Span, id: NodeId) {
624624
// FIXME(davidtwco): This is a hack to detect macros which produce spans of the
625625
// call site which do not have a macro backtrace. See #61963.
626-
let is_macro_callsite = self
626+
if self
627627
.session
628628
.source_map()
629629
.span_to_snippet(span)
630-
.map(|snippet| snippet.starts_with("#["))
631-
.unwrap_or(true);
632-
if !is_macro_callsite {
630+
.is_ok_and(|snippet| !snippet.starts_with("#["))
631+
{
633632
self.lint_buffer.buffer_lint_with_diagnostic(
634633
MISSING_ABI,
635634
id,

compiler/rustc_expand/src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ impl<'a> StripUnconfigured<'a> {
445445
/// If attributes are not allowed on expressions, emit an error for `attr`
446446
#[instrument(level = "trace", skip(self))]
447447
pub(crate) fn maybe_emit_expr_attr_err(&self, attr: &Attribute) {
448-
if !self.features.map_or(true, |features| features.stmt_expr_attributes) {
448+
if self.features.is_some_and(|features| !features.stmt_expr_attributes) {
449449
let mut err = feature_err(
450450
&self.sess.parse_sess,
451451
sym::stmt_expr_attributes,

compiler/rustc_hir_analysis/src/coherence/inherent_impls_overlap.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -140,19 +140,19 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
140140
impl1_def_id: DefId,
141141
impl2_def_id: DefId,
142142
) {
143-
traits::overlapping_impls(
143+
let maybe_overlap = traits::overlapping_impls(
144144
self.tcx,
145145
impl1_def_id,
146146
impl2_def_id,
147147
// We go ahead and just skip the leak check for
148148
// inherent impls without warning.
149149
SkipLeakCheck::Yes,
150150
overlap_mode,
151-
)
152-
.map_or(true, |overlap| {
151+
);
152+
153+
if let Some(overlap) = maybe_overlap {
153154
self.check_for_common_items_in_impls(impl1_def_id, impl2_def_id, overlap);
154-
false
155-
});
155+
}
156156
}
157157

158158
fn check_item(&mut self, id: hir::ItemId) {

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -955,9 +955,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
955955
// - f(0, 1,)
956956
// + f()
957957
if only_extras_so_far
958-
&& errors
958+
&& !errors
959959
.peek()
960-
.map_or(true, |next_error| !matches!(next_error, Error::Extra(_)))
960+
.is_some_and(|next_error| matches!(next_error, Error::Extra(_)))
961961
{
962962
let next = provided_arg_tys
963963
.get(arg_idx + 1)

compiler/rustc_middle/src/lint.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,11 @@ pub fn struct_lint_level(
388388
// it'll become a hard error, so we have to emit *something*. Also,
389389
// if this lint occurs in the expansion of a macro from an external crate,
390390
// allow individual lints to opt-out from being reported.
391-
let not_future_incompatible =
392-
future_incompatible.map(|f| f.reason.edition().is_some()).unwrap_or(true);
393-
if not_future_incompatible && !lint.report_in_external_macro {
391+
let incompatible = future_incompatible.is_some_and(|f| f.reason.edition().is_none());
392+
393+
if !incompatible && !lint.report_in_external_macro {
394394
err.cancel();
395+
395396
// Don't continue further, since we don't want to have
396397
// `diag_span_note_once` called for a diagnostic that isn't emitted.
397398
return;

compiler/rustc_mir_transform/src/coverage/graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ impl BasicCoverageBlockData {
387387
// If the BCB has an edge counter (to be injected into a new `BasicBlock`), it can also
388388
// have an expression (to be injected into an existing `BasicBlock` represented by this
389389
// `BasicCoverageBlock`).
390-
if !self.counter_kind.as_ref().map_or(true, |c| c.is_expression()) {
390+
if self.counter_kind.as_ref().is_some_and(|c| !c.is_expression()) {
391391
return Error::from_string(format!(
392392
"attempt to add an incoming edge counter from {:?} when the target BCB already \
393393
has a `Counter`",

compiler/rustc_mir_transform/src/coverage/spans.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,10 @@ impl<'a, 'tcx> CoverageSpans<'a, 'tcx> {
480480

481481
fn check_invoked_macro_name_span(&mut self) {
482482
if let Some(visible_macro) = self.curr().visible_macro(self.body_span) {
483-
if self.prev_expn_span.map_or(true, |prev_expn_span| {
484-
self.curr().expn_span.ctxt() != prev_expn_span.ctxt()
485-
}) {
483+
if !self
484+
.prev_expn_span
485+
.is_some_and(|prev_expn_span| self.curr().expn_span.ctxt() == prev_expn_span.ctxt())
486+
{
486487
let merged_prefix_len = self.curr_original_span.lo() - self.curr().span.lo();
487488
let after_macro_bang =
488489
merged_prefix_len + BytePos(visible_macro.as_str().len() as u32 + 1);

compiler/rustc_parse/src/parser/attr.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -422,15 +422,12 @@ impl<'a> Parser<'a> {
422422
}
423423
}
424424

425-
pub fn maybe_needs_tokens(attrs: &[ast::Attribute]) -> bool {
426-
// One of the attributes may either itself be a macro,
427-
// or expand to macro attributes (`cfg_attr`).
428-
attrs.iter().any(|attr| {
429-
if attr.is_doc_comment() {
430-
return false;
431-
}
432-
attr.ident().map_or(true, |ident| {
433-
ident.name == sym::cfg_attr || !rustc_feature::is_builtin_attr_name(ident.name)
434-
})
425+
/// The attributes are complete if all attributes are either a doc comment or a builtin attribute other than `cfg_attr`
426+
pub fn is_complete(attrs: &[ast::Attribute]) -> bool {
427+
attrs.iter().all(|attr| {
428+
attr.is_doc_comment()
429+
|| attr.ident().is_some_and(|ident| {
430+
ident.name != sym::cfg_attr && rustc_feature::is_builtin_attr_name(ident.name)
431+
})
435432
})
436433
}

compiler/rustc_parse/src/parser/attr_wrapper.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ impl AttrWrapper {
6161
self.attrs.is_empty()
6262
}
6363

64-
pub fn maybe_needs_tokens(&self) -> bool {
65-
crate::parser::attr::maybe_needs_tokens(&self.attrs)
64+
pub fn is_complete(&self) -> bool {
65+
crate::parser::attr::is_complete(&self.attrs)
6666
}
6767
}
6868

@@ -201,7 +201,7 @@ impl<'a> Parser<'a> {
201201
// by definition
202202
if matches!(force_collect, ForceCollect::No)
203203
// None of our outer attributes can require tokens (e.g. a proc-macro)
204-
&& !attrs.maybe_needs_tokens()
204+
&& attrs.is_complete()
205205
// If our target supports custom inner attributes, then we cannot bail
206206
// out early, since we may need to capture tokens for a custom inner attribute
207207
// invocation.
@@ -244,9 +244,9 @@ impl<'a> Parser<'a> {
244244
// Now that we've parsed an AST node, we have more information available.
245245
if matches!(force_collect, ForceCollect::No)
246246
// We now have inner attributes available, so this check is more precise
247-
// than `attrs.maybe_needs_tokens()` at the start of the function.
247+
// than `attrs.is_complete()` at the start of the function.
248248
// As a result, we don't need to check `R::SUPPORTS_CUSTOM_INNER_ATTRS`
249-
&& !crate::parser::attr::maybe_needs_tokens(ret.attrs())
249+
&& crate::parser::attr::is_complete(ret.attrs())
250250
// Subtle: We call `has_cfg_or_cfg_attr` with the attrs from `ret`.
251251
// This ensures that we consider inner attributes (e.g. `#![cfg]`),
252252
// which require us to have tokens available

compiler/rustc_resolve/src/late/diagnostics.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -2183,10 +2183,9 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
21832183
None => {
21842184
debug!(?param.ident, ?param.ident.span);
21852185
let deletion_span = deletion_span();
2186-
// the give lifetime originates from expanded code so we won't be able to remove it #104432
2187-
let lifetime_only_in_expanded_code =
2188-
deletion_span.map(|sp| sp.in_derive_expansion()).unwrap_or(true);
2189-
if !lifetime_only_in_expanded_code {
2186+
2187+
// if the lifetime originates from expanded code, we won't be able to remove it #104432
2188+
if deletion_span.is_some_and(|sp| !sp.in_derive_expansion()) {
21902189
self.r.lint_buffer.buffer_lint_with_diagnostic(
21912190
lint::builtin::UNUSED_LIFETIMES,
21922191
param.id,

compiler/rustc_session/src/parse.rs

-7
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,6 @@ impl GatedSpans {
5151
debug_assert_eq!(span, removed_span);
5252
}
5353

54-
/// Is the provided `feature` gate ungated currently?
55-
///
56-
/// Using this is discouraged unless you have a really good reason to.
57-
pub fn is_ungated(&self, feature: Symbol) -> bool {
58-
self.spans.borrow().get(&feature).map_or(true, |spans| spans.is_empty())
59-
}
60-
6154
/// Prepend the given set of `spans` onto the set in `self`.
6255
pub fn merge(&self, mut spans: FxHashMap<Symbol, Vec<Span>>) {
6356
let mut inner = self.spans.borrow_mut();

0 commit comments

Comments
 (0)