Simplify some conditions
This commit is contained in:
parent
97bf23d26b
commit
ef05533c39
@ -623,13 +623,12 @@ fn visit_ty_common(&mut self, ty: &'a Ty) {
|
||||
fn maybe_lint_missing_abi(&mut self, span: Span, id: NodeId) {
|
||||
// FIXME(davidtwco): This is a hack to detect macros which produce spans of the
|
||||
// call site which do not have a macro backtrace. See #61963.
|
||||
let is_macro_callsite = self
|
||||
if self
|
||||
.session
|
||||
.source_map()
|
||||
.span_to_snippet(span)
|
||||
.map(|snippet| snippet.starts_with("#["))
|
||||
.unwrap_or(true);
|
||||
if !is_macro_callsite {
|
||||
.is_ok_and(|snippet| !snippet.starts_with("#["))
|
||||
{
|
||||
self.lint_buffer.buffer_lint_with_diagnostic(
|
||||
MISSING_ABI,
|
||||
id,
|
||||
|
@ -445,7 +445,7 @@ pub(crate) fn cfg_true(&self, attr: &Attribute) -> (bool, Option<MetaItem>) {
|
||||
/// If attributes are not allowed on expressions, emit an error for `attr`
|
||||
#[instrument(level = "trace", skip(self))]
|
||||
pub(crate) fn maybe_emit_expr_attr_err(&self, attr: &Attribute) {
|
||||
if !self.features.map_or(true, |features| features.stmt_expr_attributes) {
|
||||
if self.features.is_some_and(|features| !features.stmt_expr_attributes) {
|
||||
let mut err = feature_err(
|
||||
&self.sess.parse_sess,
|
||||
sym::stmt_expr_attributes,
|
||||
|
@ -140,7 +140,7 @@ fn check_for_overlapping_inherent_impls(
|
||||
impl1_def_id: DefId,
|
||||
impl2_def_id: DefId,
|
||||
) {
|
||||
traits::overlapping_impls(
|
||||
let maybe_overlap = traits::overlapping_impls(
|
||||
self.tcx,
|
||||
impl1_def_id,
|
||||
impl2_def_id,
|
||||
@ -148,11 +148,11 @@ fn check_for_overlapping_inherent_impls(
|
||||
// inherent impls without warning.
|
||||
SkipLeakCheck::Yes,
|
||||
overlap_mode,
|
||||
)
|
||||
.map_or(true, |overlap| {
|
||||
);
|
||||
|
||||
if let Some(overlap) = maybe_overlap {
|
||||
self.check_for_common_items_in_impls(impl1_def_id, impl2_def_id, overlap);
|
||||
false
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn check_item(&mut self, id: hir::ItemId) {
|
||||
|
@ -955,9 +955,9 @@ enum SuggestionText {
|
||||
// - f(0, 1,)
|
||||
// + f()
|
||||
if only_extras_so_far
|
||||
&& errors
|
||||
&& !errors
|
||||
.peek()
|
||||
.map_or(true, |next_error| !matches!(next_error, Error::Extra(_)))
|
||||
.is_some_and(|next_error| matches!(next_error, Error::Extra(_)))
|
||||
{
|
||||
let next = provided_arg_tys
|
||||
.get(arg_idx + 1)
|
||||
|
@ -388,10 +388,11 @@ fn struct_lint_level_impl(
|
||||
// it'll become a hard error, so we have to emit *something*. Also,
|
||||
// if this lint occurs in the expansion of a macro from an external crate,
|
||||
// allow individual lints to opt-out from being reported.
|
||||
let not_future_incompatible =
|
||||
future_incompatible.map(|f| f.reason.edition().is_some()).unwrap_or(true);
|
||||
if not_future_incompatible && !lint.report_in_external_macro {
|
||||
let incompatible = future_incompatible.is_some_and(|f| f.reason.edition().is_none());
|
||||
|
||||
if !incompatible && !lint.report_in_external_macro {
|
||||
err.cancel();
|
||||
|
||||
// Don't continue further, since we don't want to have
|
||||
// `diag_span_note_once` called for a diagnostic that isn't emitted.
|
||||
return;
|
||||
|
@ -387,7 +387,7 @@ pub fn set_edge_counter_from(
|
||||
// If the BCB has an edge counter (to be injected into a new `BasicBlock`), it can also
|
||||
// have an expression (to be injected into an existing `BasicBlock` represented by this
|
||||
// `BasicCoverageBlock`).
|
||||
if !self.counter_kind.as_ref().map_or(true, |c| c.is_expression()) {
|
||||
if self.counter_kind.as_ref().is_some_and(|c| !c.is_expression()) {
|
||||
return Error::from_string(format!(
|
||||
"attempt to add an incoming edge counter from {:?} when the target BCB already \
|
||||
has a `Counter`",
|
||||
|
@ -480,9 +480,10 @@ fn push_refined_span(&mut self, covspan: CoverageSpan) {
|
||||
|
||||
fn check_invoked_macro_name_span(&mut self) {
|
||||
if let Some(visible_macro) = self.curr().visible_macro(self.body_span) {
|
||||
if self.prev_expn_span.map_or(true, |prev_expn_span| {
|
||||
self.curr().expn_span.ctxt() != prev_expn_span.ctxt()
|
||||
}) {
|
||||
if !self
|
||||
.prev_expn_span
|
||||
.is_some_and(|prev_expn_span| self.curr().expn_span.ctxt() == prev_expn_span.ctxt())
|
||||
{
|
||||
let merged_prefix_len = self.curr_original_span.lo() - self.curr().span.lo();
|
||||
let after_macro_bang =
|
||||
merged_prefix_len + BytePos(visible_macro.as_str().len() as u32 + 1);
|
||||
|
@ -422,15 +422,12 @@ fn parse_meta_item_inner(&mut self) -> PResult<'a, ast::NestedMetaItem> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn maybe_needs_tokens(attrs: &[ast::Attribute]) -> bool {
|
||||
// One of the attributes may either itself be a macro,
|
||||
// or expand to macro attributes (`cfg_attr`).
|
||||
attrs.iter().any(|attr| {
|
||||
if attr.is_doc_comment() {
|
||||
return false;
|
||||
}
|
||||
attr.ident().map_or(true, |ident| {
|
||||
ident.name == sym::cfg_attr || !rustc_feature::is_builtin_attr_name(ident.name)
|
||||
})
|
||||
/// The attributes are complete if all attributes are either a doc comment or a builtin attribute other than `cfg_attr`
|
||||
pub fn is_complete(attrs: &[ast::Attribute]) -> bool {
|
||||
attrs.iter().all(|attr| {
|
||||
attr.is_doc_comment()
|
||||
|| attr.ident().is_some_and(|ident| {
|
||||
ident.name != sym::cfg_attr && rustc_feature::is_builtin_attr_name(ident.name)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
@ -61,8 +61,8 @@ pub fn is_empty(&self) -> bool {
|
||||
self.attrs.is_empty()
|
||||
}
|
||||
|
||||
pub fn maybe_needs_tokens(&self) -> bool {
|
||||
crate::parser::attr::maybe_needs_tokens(&self.attrs)
|
||||
pub fn is_complete(&self) -> bool {
|
||||
crate::parser::attr::is_complete(&self.attrs)
|
||||
}
|
||||
}
|
||||
|
||||
@ -201,7 +201,7 @@ pub fn collect_tokens_trailing_token<R: HasAttrs + HasTokens>(
|
||||
// by definition
|
||||
if matches!(force_collect, ForceCollect::No)
|
||||
// None of our outer attributes can require tokens (e.g. a proc-macro)
|
||||
&& !attrs.maybe_needs_tokens()
|
||||
&& attrs.is_complete()
|
||||
// If our target supports custom inner attributes, then we cannot bail
|
||||
// out early, since we may need to capture tokens for a custom inner attribute
|
||||
// invocation.
|
||||
@ -244,9 +244,9 @@ pub fn collect_tokens_trailing_token<R: HasAttrs + HasTokens>(
|
||||
// Now that we've parsed an AST node, we have more information available.
|
||||
if matches!(force_collect, ForceCollect::No)
|
||||
// We now have inner attributes available, so this check is more precise
|
||||
// than `attrs.maybe_needs_tokens()` at the start of the function.
|
||||
// than `attrs.is_complete()` at the start of the function.
|
||||
// As a result, we don't need to check `R::SUPPORTS_CUSTOM_INNER_ATTRS`
|
||||
&& !crate::parser::attr::maybe_needs_tokens(ret.attrs())
|
||||
&& crate::parser::attr::is_complete(ret.attrs())
|
||||
// Subtle: We call `has_cfg_or_cfg_attr` with the attrs from `ret`.
|
||||
// This ensures that we consider inner attributes (e.g. `#![cfg]`),
|
||||
// which require us to have tokens available
|
||||
|
@ -2182,10 +2182,9 @@ pub(crate) fn maybe_report_lifetime_uses(
|
||||
None => {
|
||||
debug!(?param.ident, ?param.ident.span);
|
||||
let deletion_span = deletion_span();
|
||||
// the give lifetime originates from expanded code so we won't be able to remove it #104432
|
||||
let lifetime_only_in_expanded_code =
|
||||
deletion_span.map(|sp| sp.in_derive_expansion()).unwrap_or(true);
|
||||
if !lifetime_only_in_expanded_code {
|
||||
|
||||
// if the lifetime originates from expanded code, we won't be able to remove it #104432
|
||||
if deletion_span.is_some_and(|sp| !sp.in_derive_expansion()) {
|
||||
self.r.lint_buffer.buffer_lint_with_diagnostic(
|
||||
lint::builtin::UNUSED_LIFETIMES,
|
||||
param.id,
|
||||
|
@ -51,13 +51,6 @@ pub fn ungate_last(&self, feature: Symbol, span: Span) {
|
||||
debug_assert_eq!(span, removed_span);
|
||||
}
|
||||
|
||||
/// Is the provided `feature` gate ungated currently?
|
||||
///
|
||||
/// Using this is discouraged unless you have a really good reason to.
|
||||
pub fn is_ungated(&self, feature: Symbol) -> bool {
|
||||
self.spans.borrow().get(&feature).map_or(true, |spans| spans.is_empty())
|
||||
}
|
||||
|
||||
/// Prepend the given set of `spans` onto the set in `self`.
|
||||
pub fn merge(&self, mut spans: FxHashMap<Symbol, Vec<Span>>) {
|
||||
let mut inner = self.spans.borrow_mut();
|
||||
|
Loading…
Reference in New Issue
Block a user