Skip to content

Commit eda04d0

Browse files
committed
Allow matching on argument parsers
1 parent d13e537 commit eda04d0

File tree

6 files changed

+24
-4
lines changed

6 files changed

+24
-4
lines changed

,

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4 } else if let Some((feature, level)) = parse_stability(cx, args) { │ 3 (<unsize>&*&[sym::unstable], <closure-to-fn-pointer>|this: &mut StabilityGroup, cx: &AttributeAcceptContext<_ args:

compiler/rustc_attr_parsing/messages.ftl

+6
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ attr_parsing_multiple_stability_levels =
9090
attr_parsing_non_ident_feature =
9191
'feature' is not an identifier
9292
93+
attr_parsing_repr_ident =
94+
meta item in `repr` must be an identifier
9395
attr_parsing_rustc_allowed_unstable_pairing =
9496
`rustc_allowed_through_unstable_modules` attribute must be paired with a `stable` attribute
9597
@@ -108,6 +110,10 @@ attr_parsing_unknown_meta_item =
108110
attr_parsing_unknown_version_literal =
109111
unknown version literal format, assuming it refers to a future version
110112
113+
attr_parsing_unrecognized_repr_hint =
114+
unrecognized representation hint
115+
.help = valid reprs are `Rust` (default), `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
116+
111117
attr_parsing_unstable_cfg_target_compact =
112118
compact `cfg(target(..))` is experimental and subject to change
113119

compiler/rustc_attr_parsing/src/attributes/confusables.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ use rustc_attr_data_structures::AttributeKind;
22
use rustc_span::{Span, Symbol, sym};
33
use thin_vec::ThinVec;
44

5-
use super::{AcceptMapping, AttributeParser};
6-
use crate::context::FinalizeContext;
75
use crate::session_diagnostics;
86

7+
use super::{AcceptMapping, AttributeParser, FinalizeContext};
8+
99
#[derive(Default)]
1010
pub(crate) struct ConfusablesParser {
1111
confusables: ThinVec<Symbol>,

compiler/rustc_attr_parsing/src/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ impl<'sess> AttributeParser<'sess> {
243243
// }))
244244
// }
245245
ast::AttrKind::Normal(n) => {
246-
let parser = MetaItemParser::from_attr(&n, self.dcx());
246+
let parser = MetaItemParser::from_attr(n, self.dcx());
247247
let (path, args) = parser.deconstruct();
248248
let parts = path.segments().map(|i| i.name).collect::<Vec<_>>();
249249

compiler/rustc_hir/src/hir.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,9 @@ impl AttributeExt for Attribute {
11051105
fn span(&self) -> Span {
11061106
match &self {
11071107
Attribute::Unparsed(u) => u.span,
1108-
_ => panic!(),
1108+
// FIXME: should not be needed anymore when all attrs are parsed
1109+
Attribute::Parsed(AttributeKind::Deprecation { span, .. }) => *span,
1110+
a => panic!("can't get the span of an arbitrary parsed attribute: {a:?}"),
11091111
}
11101112
}
11111113

compiler/rustc_passes/src/check_attr.rs

+11
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,17 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
604604
continue;
605605
}
606606

607+
// FIXME(jdonszelmann): once naked uses new-style parsing,
608+
// this check can be part of the parser and be removed here
609+
match other_attr {
610+
Attribute::Parsed(
611+
AttributeKind::Deprecation { .. } | AttributeKind::Repr { .. },
612+
) => {
613+
continue;
614+
}
615+
_ => {}
616+
}
617+
607618
if !ALLOW_LIST.iter().any(|name| other_attr.has_name(*name)) {
608619
self.dcx().emit_err(errors::NakedFunctionIncompatibleAttribute {
609620
span: other_attr.span(),

0 commit comments

Comments
 (0)