Skip to content

Commit 1cffc48

Browse files
Wip
Signed-off-by: Jonathan Brouwer <[email protected]>
1 parent 84b631e commit 1cffc48

File tree

10 files changed

+68
-25
lines changed

10 files changed

+68
-25
lines changed

compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ impl<S: Stage> CombineAttributeParser<S> for AllowInternalUnstableParser {
1616
type Item = (Symbol, Span);
1717
const CONVERT: ConvertFn<Self::Item> =
1818
|items, span| AttributeKind::AllowInternalUnstable(items, span);
19-
const ALLOWED_TARGETS: &'static [Target] = &[Target::MacroDef];
19+
const ALLOWED_TARGETS: &'static [Target] = &[
20+
Target::MacroDef,
21+
Target::Fn, //TODO if proc macro
22+
];
2023
const TEMPLATE: AttributeTemplate = template!(Word, List: "feat1, feat2, ...");
2124

2225
fn extend<'c>(

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<S: Stage> NoArgsAttributeParser<S> for ColdParser {
6262
Target::Method(MethodKind::Trait { body: false }),
6363
Target::Method(MethodKind::Inherent),
6464
Target::ForeignFn,
65-
Target::Closure
65+
Target::Closure,
6666
];
6767
const CREATE: fn(Span) -> AttributeKind = AttributeKind::Cold;
6868
}
@@ -164,7 +164,11 @@ impl<S: Stage> AttributeParser<S> for NakedParser {
164164
this.span = Some(cx.attr_span);
165165
}
166166
})];
167-
const ALLOWED_TARGETS: &'static [Target] = &[Target::Fn];
167+
const ALLOWED_TARGETS: &'static [Target] = &[
168+
Target::Fn,
169+
Target::Method(MethodKind::Inherent),
170+
Target::Method(MethodKind::Trait { body: true }),
171+
];
168172

169173
fn finalize(self, cx: &FinalizeContext<'_, '_, S>) -> Option<AttributeKind> {
170174
// FIXME(jdonszelmann): upgrade this list to *parsed* attributes
@@ -261,6 +265,9 @@ impl<S: Stage> NoArgsAttributeParser<S> for TrackCallerParser {
261265
Target::Fn,
262266
Target::Method(MethodKind::Inherent),
263267
Target::Method(MethodKind::Trait { body: true }),
268+
Target::Method(MethodKind::Trait { body: false }),
269+
Target::ForeignFn,
270+
Target::Closure,
264271
];
265272
const CREATE: fn(Span) -> AttributeKind = AttributeKind::TrackCaller;
266273
}
@@ -269,7 +276,7 @@ pub(crate) struct NoMangleParser;
269276
impl<S: Stage> NoArgsAttributeParser<S> for NoMangleParser {
270277
const PATH: &[Symbol] = &[sym::no_mangle];
271278
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
272-
const ALLOWED_TARGETS: &'static [Target] = &[Target::Fn];
279+
const ALLOWED_TARGETS: &'static [Target] = &[Target::Fn, Target::Static];
273280
const CREATE: fn(Span) -> AttributeKind = AttributeKind::NoMangle;
274281
}
275282

@@ -408,5 +415,5 @@ impl<S: Stage> CombineAttributeParser<S> for TargetFeatureParser {
408415
features
409416
}
410417

411-
const ALLOWED_TARGETS: &'static [Target] = &[Target::Fn];
418+
const ALLOWED_TARGETS: &'static [Target] = &[Target::Fn, Target::Method(MethodKind::Inherent)];
412419
}

compiler/rustc_attr_parsing/src/attributes/confusables.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,7 @@ impl<S: Stage> AttributeParser<S> for ConfusablesParser {
4242
this.first_span.get_or_insert(cx.attr_span);
4343
},
4444
)];
45-
const ALLOWED_TARGETS: &'static [Target] = &[
46-
Target::Method(MethodKind::Inherent),
47-
Target::Method(MethodKind::Trait { body: false }),
48-
Target::Method(MethodKind::Trait { body: true }),
49-
];
45+
const ALLOWED_TARGETS: &'static [Target] = &[Target::Method(MethodKind::Inherent)];
5046

5147
fn finalize(self, _cx: &FinalizeContext<'_, '_, S>) -> Option<AttributeKind> {
5248
if self.confusables.is_empty() {

compiler/rustc_attr_parsing/src/attributes/deprecation.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ impl<S: Stage> SingleAttributeParser<S> for DeprecationParser {
5151
Target::Method(MethodKind::Inherent),
5252
Target::TyAlias,
5353
Target::Use,
54+
Target::ForeignFn,
55+
Target::Field,
56+
Target::Trait,
5457
];
5558
const TEMPLATE: AttributeTemplate = template!(
5659
Word,

compiler/rustc_attr_parsing/src/attributes/dummy.rs

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_feature::{AttributeTemplate, template};
2-
use rustc_hir::Target;
32
use rustc_hir::attrs::AttributeKind;
3+
use rustc_hir::{MethodKind, Target};
44
use rustc_span::{Symbol, sym};
55

66
use crate::attributes::{AttributeOrder, OnDuplicate, SingleAttributeParser};
@@ -12,7 +12,46 @@ impl<S: Stage> SingleAttributeParser<S> for DummyParser {
1212
const PATH: &[Symbol] = &[sym::rustc_dummy];
1313
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost;
1414
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Ignore;
15-
const ALLOWED_TARGETS: &'static [Target] = &[];
15+
const ALLOWED_TARGETS: &'static [Target] = &[
16+
//TODO better solution than listing everything here?
17+
Target::ExternCrate,
18+
Target::Use,
19+
Target::Static,
20+
Target::Const,
21+
Target::Fn,
22+
Target::Closure,
23+
Target::Mod,
24+
Target::ForeignMod,
25+
Target::GlobalAsm,
26+
Target::TyAlias,
27+
Target::Enum,
28+
Target::Variant,
29+
Target::Struct,
30+
Target::Field,
31+
Target::Union,
32+
Target::Trait,
33+
Target::TraitAlias,
34+
Target::Impl { of_trait: false },
35+
Target::Impl { of_trait: true },
36+
Target::Expression,
37+
Target::Statement,
38+
Target::Arm,
39+
Target::AssocConst,
40+
Target::Method(MethodKind::Inherent),
41+
Target::Method(MethodKind::Trait { body: false }),
42+
Target::Method(MethodKind::Trait { body: true }),
43+
Target::AssocTy,
44+
Target::ForeignFn,
45+
Target::ForeignStatic,
46+
Target::ForeignTy,
47+
Target::MacroDef,
48+
Target::Param,
49+
Target::PatField,
50+
Target::ExprField,
51+
Target::WherePredicate,
52+
Target::MacroCall,
53+
Target::Crate,
54+
];
1655
const TEMPLATE: AttributeTemplate = template!(Word); // Anything, really
1756

1857
fn convert(_: &mut AcceptContext<'_, '_, S>, _: &ArgParser<'_>) -> Option<AttributeKind> {

compiler/rustc_attr_parsing/src/attributes/inline.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ impl<S: Stage> SingleAttributeParser<S> for InlineParser {
2424
Target::Method(MethodKind::Inherent),
2525
Target::Method(MethodKind::Trait { body: false }),
2626
Target::Method(MethodKind::Trait { body: true }),
27+
Target::Closure,
2728
];
2829
const TEMPLATE: AttributeTemplate = template!(Word, List: "always|never");
2930

compiler/rustc_attr_parsing/src/attributes/link_attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl<S: Stage> SingleAttributeParser<S> for LinkSectionParser {
4040
const PATH: &[Symbol] = &[sym::link_section];
4141
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost;
4242
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
43-
const ALLOWED_TARGETS: &'static [Target] = &[Target::ForeignMod];
43+
const ALLOWED_TARGETS: &'static [Target] = &[Target::Static, Target::Fn];
4444
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "name");
4545

4646
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {

compiler/rustc_attr_parsing/src/attributes/stability.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ const ALLOWED_TARGETS: &[Target] = &[
4646
Target::TyAlias,
4747
Target::Variant,
4848
Target::Field,
49-
Target::Param
49+
Target::Param,
50+
Target::Static,
5051
];
5152

5253
#[derive(Default)]
@@ -179,7 +180,7 @@ pub(crate) struct ConstStabilityIndirectParser;
179180
impl<S: Stage> NoArgsAttributeParser<S> for ConstStabilityIndirectParser {
180181
const PATH: &[Symbol] = &[sym::rustc_const_stable_indirect];
181182
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Ignore;
182-
const ALLOWED_TARGETS: &'static [Target] = &[Target::Fn];
183+
const ALLOWED_TARGETS: &'static [Target] = &[Target::Fn, Target::Method(MethodKind::Inherent)];
183184
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::ConstStabilityIndirect;
184185
}
185186

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -854,11 +854,7 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
854854
if self.stage.should_emit().should_emit()
855855
&& !accept.allowed_targets.contains(&target)
856856
{
857-
if parts == &[sym::cold] && target == (Target::Expression) {
858-
panic!();
859-
}
860-
861-
self.dcx().span_bug(
857+
self.dcx().span_delayed_bug(
862858
n.item.span(),
863859
format!(
864860
"{:?} target {target:?} not allowed {:?}",

compiler/rustc_hir/src/target.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use std::fmt::{self, Display};
88

99
use rustc_ast::{AssocItemKind, ForeignItemKind, ast};
10+
1011
use crate::def::DefKind;
1112
use crate::{Item, ItemKind, TraitItem, TraitItemKind, hir};
1213

@@ -237,11 +238,7 @@ impl Target {
237238
}
238239

239240
pub fn from_expr(expr: &ast::Expr) -> Self {
240-
if let ast::ExprKind::Closure(..) = expr.kind {
241-
Self::Closure
242-
} else {
243-
Self::Expression
244-
}
241+
if let ast::ExprKind::Closure(..) = expr.kind { Self::Closure } else { Self::Expression }
245242
}
246243

247244
pub fn name(self) -> &'static str {

0 commit comments

Comments
 (0)