Auto merge of #142921 - JonathanBrouwer:rustc_attributes_parser, r=oli-obk
Port `#[rustc_layout_scalar_valid_range_start/end]` to the new attrib… Ports `rustc_layout_scalar_valid_range_start` and `rustc_layout_scalar_valid_range_end` to the new attribute parsing infrastructure for https://github.com/rust-lang/rust/issues/131229#issuecomment-2971353197 r? `@jdonszelmann`
This commit is contained in:
@@ -618,9 +618,6 @@ passes_rustc_force_inline_coro =
|
||||
attribute cannot be applied to a `async`, `gen` or `async gen` function
|
||||
.label = `async`, `gen` or `async gen` function
|
||||
|
||||
passes_rustc_layout_scalar_valid_range_arg =
|
||||
expected exactly one integer literal argument
|
||||
|
||||
passes_rustc_layout_scalar_valid_range_not_struct =
|
||||
attribute should be applied to a struct
|
||||
.label = not a struct
|
||||
|
||||
@@ -9,7 +9,7 @@ use std::cell::Cell;
|
||||
use std::collections::hash_map::Entry;
|
||||
|
||||
use rustc_abi::{Align, ExternAbi, Size};
|
||||
use rustc_ast::{AttrStyle, LitKind, MetaItemInner, MetaItemKind, MetaItemLit, ast};
|
||||
use rustc_ast::{AttrStyle, LitKind, MetaItemInner, MetaItemKind, ast};
|
||||
use rustc_attr_data_structures::{AttributeKind, InlineAttr, ReprAttr, find_attr};
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_errors::{Applicability, DiagCtxtHandle, IntoDiagArg, MultiSpan, StashKey};
|
||||
@@ -186,6 +186,10 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
||||
Attribute::Parsed(AttributeKind::TrackCaller(attr_span)) => {
|
||||
self.check_track_caller(hir_id, *attr_span, attrs, span, target)
|
||||
}
|
||||
Attribute::Parsed(
|
||||
AttributeKind::RustcLayoutScalarValidRangeStart(_num, attr_span)
|
||||
| AttributeKind::RustcLayoutScalarValidRangeEnd(_num, attr_span),
|
||||
) => self.check_rustc_layout_scalar_valid_range(*attr_span, span, target),
|
||||
Attribute::Parsed(
|
||||
AttributeKind::BodyStability { .. }
|
||||
| AttributeKind::ConstStabilityIndirect
|
||||
@@ -237,10 +241,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
||||
&mut doc_aliases,
|
||||
),
|
||||
[sym::no_link, ..] => self.check_no_link(hir_id, attr, span, target),
|
||||
[sym::rustc_layout_scalar_valid_range_start, ..]
|
||||
| [sym::rustc_layout_scalar_valid_range_end, ..] => {
|
||||
self.check_rustc_layout_scalar_valid_range(attr, span, target)
|
||||
}
|
||||
[sym::debugger_visualizer, ..] => self.check_debugger_visualizer(attr, target),
|
||||
[sym::rustc_std_internal_symbol, ..] => {
|
||||
self.check_rustc_std_internal_symbol(attr, span, target)
|
||||
@@ -1678,24 +1678,11 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_rustc_layout_scalar_valid_range(&self, attr: &Attribute, span: Span, target: Target) {
|
||||
fn check_rustc_layout_scalar_valid_range(&self, attr_span: Span, span: Span, target: Target) {
|
||||
if target != Target::Struct {
|
||||
self.dcx().emit_err(errors::RustcLayoutScalarValidRangeNotStruct {
|
||||
attr_span: attr.span(),
|
||||
span,
|
||||
});
|
||||
self.dcx().emit_err(errors::RustcLayoutScalarValidRangeNotStruct { attr_span, span });
|
||||
return;
|
||||
}
|
||||
|
||||
let Some(list) = attr.meta_item_list() else {
|
||||
return;
|
||||
};
|
||||
|
||||
if !matches!(&list[..], &[MetaItemInner::Lit(MetaItemLit { kind: LitKind::Int(..), .. })]) {
|
||||
self.tcx
|
||||
.dcx()
|
||||
.emit_err(errors::RustcLayoutScalarValidRangeArg { attr_span: attr.span() });
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks if `#[rustc_legacy_const_generics]` is applied to a function and has a valid argument.
|
||||
|
||||
@@ -535,13 +535,6 @@ pub(crate) struct RustcLayoutScalarValidRangeNotStruct {
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(passes_rustc_layout_scalar_valid_range_arg)]
|
||||
pub(crate) struct RustcLayoutScalarValidRangeArg {
|
||||
#[primary_span]
|
||||
pub attr_span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(passes_rustc_legacy_const_generics_only)]
|
||||
pub(crate) struct RustcLegacyConstGenericsOnly {
|
||||
|
||||
Reference in New Issue
Block a user