Skip to content

Commit 3f4061f

Browse files
WIP
1 parent f836cf7 commit 3f4061f

File tree

5 files changed

+14
-5
lines changed

5 files changed

+14
-5
lines changed

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
994994
let (defaultness, _) = self.lower_defaultness(i.kind.defaultness(), has_value);
995995
let hir_id = hir::HirId::make_owner(self.current_hir_id_owner.def_id);
996996
let attrs =
997-
self.lower_attrs(hir_id, &i.attrs, i.span, Target::Impl { of_trait: is_in_trait_impl });
997+
self.lower_attrs(hir_id, &i.attrs, i.span, Target::from_ast_item()); //TODO this is not correct
998998

999999
let (ident, (generics, kind)) = match &i.kind {
10001000
AssocItemKind::Const(box ConstItem {

compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl<S: Stage> AttributeParser<S> for MacroUseParser {
110110
}
111111
},
112112
)];
113-
const ALLOWED_TARGETS: &'static [Target] = &[Target::Mod, Target::ExternCrate, Target::Crate]; //TODO crate?
113+
const ALLOWED_TARGETS: &'static [Target] = &[Target::Mod, Target::ExternCrate];
114114

115115
fn finalize(self, _cx: &FinalizeContext<'_, '_, S>) -> Option<AttributeKind> {
116116
Some(AttributeKind::MacroUse { span: self.first_span?, arguments: self.state })

compiler/rustc_attr_parsing/src/attributes/path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ impl<S: Stage> SingleAttributeParser<S> for PathParser {
1313
const PATH: &[Symbol] = &[sym::path];
1414
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
1515
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
16-
const ALLOWED_TARGETS: &'static [Target] = &[Target::Use];
16+
const ALLOWED_TARGETS: &'static [Target] = &[Target::Mod];
1717
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "file");
1818

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

compiler/rustc_attr_parsing/src/attributes/stability.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ const ALLOWED_TARGETS: &[Target] = &[Target::Fn,
3030
Target::Struct,
3131
Target::Method(MethodKind::Inherent),
3232
Target::Impl { of_trait: true },
33-
Target::MacroDef];
33+
Target::MacroDef,
34+
Target::Crate,
35+
Target::Mod,
36+
Target::Use,
37+
Target::Const
38+
];
3439

3540
#[derive(Default)]
3641
pub(crate) struct StabilityParser {

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,11 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
851851

852852
(accept.accept_fn)(&mut cx, args);
853853

854-
if !accept.allowed_targets.contains(&target) {
854+
if self.stage.should_emit().should_emit() && !accept.allowed_targets.contains(&target) {
855+
if parts == &[sym::unstable] && target == (Target::Impl { of_trait: false}) {
856+
panic!();
857+
}
858+
855859
self.dcx().span_bug(n.item.span(), format!("{:?} target {target:?} not allowed {:?}", parts, accept.allowed_targets));
856860
}
857861
} else {

0 commit comments

Comments
 (0)