Skip to content

Commit 814869b

Browse files
wip
Signed-off-by: Jonathan Brouwer <[email protected]>
1 parent 3f4061f commit 814869b

File tree

6 files changed

+24
-8
lines changed

6 files changed

+24
-8
lines changed

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_errors::{E0570, ErrorGuaranteed, struct_span_code_err};
66
use rustc_hir::attrs::AttributeKind;
77
use rustc_hir::def::{DefKind, PerNS, Res};
88
use rustc_hir::def_id::{CRATE_DEF_ID, LocalDefId};
9-
use rustc_hir::{self as hir, HirId, LifetimeSource, PredicateOrigin, Target, find_attr};
9+
use rustc_hir::{self as hir, HirId, LifetimeSource, PredicateOrigin, Target, find_attr, MethodKind};
1010
use rustc_index::{IndexSlice, IndexVec};
1111
use rustc_middle::span_bug;
1212
use rustc_middle::ty::{ResolverAstLowering, TyCtxt};
@@ -822,6 +822,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
822822

823823
fn lower_trait_item(&mut self, i: &AssocItem) -> &'hir hir::TraitItem<'hir> {
824824
let hir_id = hir::HirId::make_owner(self.current_hir_id_owner.def_id);
825+
Target::from_trait_item(&i.kind) //TODO
825826
let attrs = self.lower_attrs(hir_id, &i.attrs, i.span, Target::Trait);
826827
let trait_item_def_id = hir_id.expect_owner();
827828

@@ -993,8 +994,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
993994
let has_value = true;
994995
let (defaultness, _) = self.lower_defaultness(i.kind.defaultness(), has_value);
995996
let hir_id = hir::HirId::make_owner(self.current_hir_id_owner.def_id);
997+
let target = match i.kind {
998+
AssocItemKind::Const(_) => Target::AssocConst,
999+
AssocItemKind::Fn(_) => Target::Method(if is_in_trait_impl {
1000+
MethodKind::Trait { body: true }
1001+
} else {
1002+
MethodKind::Inherent
1003+
}),
1004+
AssocItemKind::Type(_) => Target::AssocTy,
1005+
_ => unreachable!(),
1006+
};
9961007
let attrs =
997-
self.lower_attrs(hir_id, &i.attrs, i.span, Target::from_ast_item()); //TODO this is not correct
1008+
self.lower_attrs(hir_id, &i.attrs, i.span, target); //TODO this is not correct
9981009

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

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub(crate) struct ColdParser;
5656
impl<S: Stage> NoArgsAttributeParser<S> for ColdParser {
5757
const PATH: &[Symbol] = &[sym::cold];
5858
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
59-
const ALLOWED_TARGETS: &'static [Target] = &[Target::Fn];
59+
const ALLOWED_TARGETS: &'static [Target] = &[Target::Fn, Target::Method(MethodKind::Trait { body: true }), Target::Method(MethodKind::Inherent)];
6060
const CREATE: fn(Span) -> AttributeKind = AttributeKind::Cold;
6161
}
6262

@@ -250,7 +250,7 @@ pub(crate) struct TrackCallerParser;
250250
impl<S: Stage> NoArgsAttributeParser<S> for TrackCallerParser {
251251
const PATH: &[Symbol] = &[sym::track_caller];
252252
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
253-
const ALLOWED_TARGETS: &'static [Target] = &[Target::Fn, Target::Method(MethodKind::Inherent)];
253+
const ALLOWED_TARGETS: &'static [Target] = &[Target::Fn, Target::Method(MethodKind::Inherent), Target::Method(MethodKind::Trait { body: true })];
254254
const CREATE: fn(Span) -> AttributeKind = AttributeKind::TrackCaller;
255255
}
256256

compiler/rustc_attr_parsing/src/attributes/deprecation.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc_feature::{AttributeTemplate, template};
2-
use rustc_hir::Target;
2+
use rustc_hir::{MethodKind, Target};
33
use rustc_hir::attrs::{AttributeKind, DeprecatedSince, Deprecation};
44
use rustc_span::{Span, Symbol, sym};
55

@@ -48,6 +48,7 @@ impl<S: Stage> SingleAttributeParser<S> for DeprecationParser {
4848
Target::Const,
4949
Target::Static,
5050
Target::MacroDef,
51+
Target::Method(MethodKind::Inherent),
5152
];
5253
const TEMPLATE: AttributeTemplate = template!(
5354
Word,

compiler/rustc_attr_parsing/src/attributes/repr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl<S: Stage> CombineAttributeParser<S> for ReprParser {
6060
reprs
6161
}
6262

63-
const ALLOWED_TARGETS: &'static [Target] = &[Target::Struct, Target::Enum];
63+
const ALLOWED_TARGETS: &'static [Target] = &[Target::Struct, Target::Enum, Target::Union];
6464
}
6565

6666
macro_rules! int_pat {

compiler/rustc_attr_parsing/src/attributes/stability.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,16 @@ macro_rules! reject_outside_std {
2929
const ALLOWED_TARGETS: &[Target] = &[Target::Fn,
3030
Target::Struct,
3131
Target::Method(MethodKind::Inherent),
32+
Target::Impl { of_trait: false },
3233
Target::Impl { of_trait: true },
3334
Target::MacroDef,
3435
Target::Crate,
3536
Target::Mod,
3637
Target::Use,
37-
Target::Const
38+
Target::Const,
39+
Target::AssocConst,
40+
Target::Trait,
41+
Target::TraitAlias,
3842
];
3943

4044
#[derive(Default)]

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
852852
(accept.accept_fn)(&mut cx, args);
853853

854854
if self.stage.should_emit().should_emit() && !accept.allowed_targets.contains(&target) {
855-
if parts == &[sym::unstable] && target == (Target::Impl { of_trait: false}) {
855+
if parts == &[sym::must_use] && target == (Target::Trait) {
856856
panic!();
857857
}
858858

0 commit comments

Comments
 (0)