mirror of https://github.com/rust-lang/rust.git
Simplify some conditions
This commit is contained in:
parent
97bf23d26b
commit
ef05533c39
|
@ -623,13 +623,12 @@ impl<'a> AstValidator<'a> {
|
||||||
fn maybe_lint_missing_abi(&mut self, span: Span, id: NodeId) {
|
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
|
// 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.
|
// call site which do not have a macro backtrace. See #61963.
|
||||||
let is_macro_callsite = self
|
if self
|
||||||
.session
|
.session
|
||||||
.source_map()
|
.source_map()
|
||||||
.span_to_snippet(span)
|
.span_to_snippet(span)
|
||||||
.map(|snippet| snippet.starts_with("#["))
|
.is_ok_and(|snippet| !snippet.starts_with("#["))
|
||||||
.unwrap_or(true);
|
{
|
||||||
if !is_macro_callsite {
|
|
||||||
self.lint_buffer.buffer_lint_with_diagnostic(
|
self.lint_buffer.buffer_lint_with_diagnostic(
|
||||||
MISSING_ABI,
|
MISSING_ABI,
|
||||||
id,
|
id,
|
||||||
|
|
|
@ -445,7 +445,7 @@ impl<'a> StripUnconfigured<'a> {
|
||||||
/// If attributes are not allowed on expressions, emit an error for `attr`
|
/// If attributes are not allowed on expressions, emit an error for `attr`
|
||||||
#[instrument(level = "trace", skip(self))]
|
#[instrument(level = "trace", skip(self))]
|
||||||
pub(crate) fn maybe_emit_expr_attr_err(&self, attr: &Attribute) {
|
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(
|
let mut err = feature_err(
|
||||||
&self.sess.parse_sess,
|
&self.sess.parse_sess,
|
||||||
sym::stmt_expr_attributes,
|
sym::stmt_expr_attributes,
|
||||||
|
|
|
@ -140,7 +140,7 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
|
||||||
impl1_def_id: DefId,
|
impl1_def_id: DefId,
|
||||||
impl2_def_id: DefId,
|
impl2_def_id: DefId,
|
||||||
) {
|
) {
|
||||||
traits::overlapping_impls(
|
let maybe_overlap = traits::overlapping_impls(
|
||||||
self.tcx,
|
self.tcx,
|
||||||
impl1_def_id,
|
impl1_def_id,
|
||||||
impl2_def_id,
|
impl2_def_id,
|
||||||
|
@ -148,11 +148,11 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
|
||||||
// inherent impls without warning.
|
// inherent impls without warning.
|
||||||
SkipLeakCheck::Yes,
|
SkipLeakCheck::Yes,
|
||||||
overlap_mode,
|
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);
|
self.check_for_common_items_in_impls(impl1_def_id, impl2_def_id, overlap);
|
||||||
false
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_item(&mut self, id: hir::ItemId) {
|
fn check_item(&mut self, id: hir::ItemId) {
|
||||||
|
|
|
@ -955,9 +955,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
// - f(0, 1,)
|
// - f(0, 1,)
|
||||||
// + f()
|
// + f()
|
||||||
if only_extras_so_far
|
if only_extras_so_far
|
||||||
&& errors
|
&& !errors
|
||||||
.peek()
|
.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
|
let next = provided_arg_tys
|
||||||
.get(arg_idx + 1)
|
.get(arg_idx + 1)
|
||||||
|
|
|
@ -388,10 +388,11 @@ pub fn struct_lint_level(
|
||||||
// it'll become a hard error, so we have to emit *something*. Also,
|
// 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,
|
// if this lint occurs in the expansion of a macro from an external crate,
|
||||||
// allow individual lints to opt-out from being reported.
|
// allow individual lints to opt-out from being reported.
|
||||||
let not_future_incompatible =
|
let incompatible = future_incompatible.is_some_and(|f| f.reason.edition().is_none());
|
||||||
future_incompatible.map(|f| f.reason.edition().is_some()).unwrap_or(true);
|
|
||||||
if not_future_incompatible && !lint.report_in_external_macro {
|
if !incompatible && !lint.report_in_external_macro {
|
||||||
err.cancel();
|
err.cancel();
|
||||||
|
|
||||||
// Don't continue further, since we don't want to have
|
// Don't continue further, since we don't want to have
|
||||||
// `diag_span_note_once` called for a diagnostic that isn't emitted.
|
// `diag_span_note_once` called for a diagnostic that isn't emitted.
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -387,7 +387,7 @@ impl BasicCoverageBlockData {
|
||||||
// If the BCB has an edge counter (to be injected into a new `BasicBlock`), it can also
|
// 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
|
// have an expression (to be injected into an existing `BasicBlock` represented by this
|
||||||
// `BasicCoverageBlock`).
|
// `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!(
|
return Error::from_string(format!(
|
||||||
"attempt to add an incoming edge counter from {:?} when the target BCB already \
|
"attempt to add an incoming edge counter from {:?} when the target BCB already \
|
||||||
has a `Counter`",
|
has a `Counter`",
|
||||||
|
|
|
@ -480,9 +480,10 @@ impl<'a, 'tcx> CoverageSpans<'a, 'tcx> {
|
||||||
|
|
||||||
fn check_invoked_macro_name_span(&mut self) {
|
fn check_invoked_macro_name_span(&mut self) {
|
||||||
if let Some(visible_macro) = self.curr().visible_macro(self.body_span) {
|
if let Some(visible_macro) = self.curr().visible_macro(self.body_span) {
|
||||||
if self.prev_expn_span.map_or(true, |prev_expn_span| {
|
if !self
|
||||||
self.curr().expn_span.ctxt() != prev_expn_span.ctxt()
|
.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 merged_prefix_len = self.curr_original_span.lo() - self.curr().span.lo();
|
||||||
let after_macro_bang =
|
let after_macro_bang =
|
||||||
merged_prefix_len + BytePos(visible_macro.as_str().len() as u32 + 1);
|
merged_prefix_len + BytePos(visible_macro.as_str().len() as u32 + 1);
|
||||||
|
|
|
@ -422,15 +422,12 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn maybe_needs_tokens(attrs: &[ast::Attribute]) -> bool {
|
/// The attributes are complete if all attributes are either a doc comment or a builtin attribute other than `cfg_attr`
|
||||||
// One of the attributes may either itself be a macro,
|
pub fn is_complete(attrs: &[ast::Attribute]) -> bool {
|
||||||
// or expand to macro attributes (`cfg_attr`).
|
attrs.iter().all(|attr| {
|
||||||
attrs.iter().any(|attr| {
|
attr.is_doc_comment()
|
||||||
if attr.is_doc_comment() {
|
|| attr.ident().is_some_and(|ident| {
|
||||||
return false;
|
ident.name != sym::cfg_attr && rustc_feature::is_builtin_attr_name(ident.name)
|
||||||
}
|
})
|
||||||
attr.ident().map_or(true, |ident| {
|
|
||||||
ident.name == sym::cfg_attr || !rustc_feature::is_builtin_attr_name(ident.name)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,8 +61,8 @@ impl AttrWrapper {
|
||||||
self.attrs.is_empty()
|
self.attrs.is_empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn maybe_needs_tokens(&self) -> bool {
|
pub fn is_complete(&self) -> bool {
|
||||||
crate::parser::attr::maybe_needs_tokens(&self.attrs)
|
crate::parser::attr::is_complete(&self.attrs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,7 +201,7 @@ impl<'a> Parser<'a> {
|
||||||
// by definition
|
// by definition
|
||||||
if matches!(force_collect, ForceCollect::No)
|
if matches!(force_collect, ForceCollect::No)
|
||||||
// None of our outer attributes can require tokens (e.g. a proc-macro)
|
// 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
|
// 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
|
// out early, since we may need to capture tokens for a custom inner attribute
|
||||||
// invocation.
|
// invocation.
|
||||||
|
@ -244,9 +244,9 @@ impl<'a> Parser<'a> {
|
||||||
// Now that we've parsed an AST node, we have more information available.
|
// Now that we've parsed an AST node, we have more information available.
|
||||||
if matches!(force_collect, ForceCollect::No)
|
if matches!(force_collect, ForceCollect::No)
|
||||||
// We now have inner attributes available, so this check is more precise
|
// 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`
|
// 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`.
|
// Subtle: We call `has_cfg_or_cfg_attr` with the attrs from `ret`.
|
||||||
// This ensures that we consider inner attributes (e.g. `#![cfg]`),
|
// This ensures that we consider inner attributes (e.g. `#![cfg]`),
|
||||||
// which require us to have tokens available
|
// which require us to have tokens available
|
||||||
|
|
|
@ -2182,10 +2182,9 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
||||||
None => {
|
None => {
|
||||||
debug!(?param.ident, ?param.ident.span);
|
debug!(?param.ident, ?param.ident.span);
|
||||||
let deletion_span = deletion_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 =
|
// if the lifetime originates from expanded code, we won't be able to remove it #104432
|
||||||
deletion_span.map(|sp| sp.in_derive_expansion()).unwrap_or(true);
|
if deletion_span.is_some_and(|sp| !sp.in_derive_expansion()) {
|
||||||
if !lifetime_only_in_expanded_code {
|
|
||||||
self.r.lint_buffer.buffer_lint_with_diagnostic(
|
self.r.lint_buffer.buffer_lint_with_diagnostic(
|
||||||
lint::builtin::UNUSED_LIFETIMES,
|
lint::builtin::UNUSED_LIFETIMES,
|
||||||
param.id,
|
param.id,
|
||||||
|
|
|
@ -51,13 +51,6 @@ impl GatedSpans {
|
||||||
debug_assert_eq!(span, removed_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`.
|
/// Prepend the given set of `spans` onto the set in `self`.
|
||||||
pub fn merge(&self, mut spans: FxHashMap<Symbol, Vec<Span>>) {
|
pub fn merge(&self, mut spans: FxHashMap<Symbol, Vec<Span>>) {
|
||||||
let mut inner = self.spans.borrow_mut();
|
let mut inner = self.spans.borrow_mut();
|
||||||
|
|
Loading…
Reference in New Issue