Skip to content

Commit 063fe42

Browse files
WIP
1 parent 814869b commit 063fe42

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 3 additions & 14 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, MethodKind};
9+
use rustc_hir::{self as hir, HirId, LifetimeSource, PredicateOrigin, Target, find_attr};
1010
use rustc_index::{IndexSlice, IndexVec};
1111
use rustc_middle::span_bug;
1212
use rustc_middle::ty::{ResolverAstLowering, TyCtxt};
@@ -822,8 +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
826-
let attrs = self.lower_attrs(hir_id, &i.attrs, i.span, Target::Trait);
825+
let attrs = self.lower_attrs(hir_id, &i.attrs, i.span, Target::from_assoc_item_kind(&i.kind, false));
827826
let trait_item_def_id = hir_id.expect_owner();
828827

829828
let (ident, generics, kind, has_default) = match &i.kind {
@@ -994,18 +993,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
994993
let has_value = true;
995994
let (defaultness, _) = self.lower_defaultness(i.kind.defaultness(), has_value);
996995
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-
};
1007996
let attrs =
1008-
self.lower_attrs(hir_id, &i.attrs, i.span, target); //TODO this is not correct
997+
self.lower_attrs(hir_id, &i.attrs, i.span, Target::from_assoc_item_kind(&i.kind, is_in_trait_impl));
1009998

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

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -852,9 +852,9 @@ 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::must_use] && target == (Target::Trait) {
856-
panic!();
857-
}
855+
// if parts == &[sym::must_use] && target == (Target::Trait) {
856+
// panic!();
857+
// }
858858

859859
self.dcx().span_bug(n.item.span(), format!("{:?} target {target:?} not allowed {:?}", parts, accept.allowed_targets));
860860
}

compiler/rustc_hir/src/target.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
use std::fmt::{self, Display};
88

9-
use rustc_ast::{ForeignItemKind, ast};
9+
use rustc_ast::{ForeignItemKind, ast, AssocItemKind};
1010

1111
use crate::def::DefKind;
1212
use crate::{Item, ItemKind, TraitItem, TraitItemKind, hir};
@@ -224,6 +224,19 @@ impl Target {
224224
}
225225
}
226226

227+
pub fn from_assoc_item_kind(kind: &ast::AssocItemKind, is_in_trait_impl: bool) -> Target {
228+
match kind {
229+
AssocItemKind::Const(_) => Target::AssocConst,
230+
AssocItemKind::Fn(_) => Target::Method(if is_in_trait_impl {
231+
MethodKind::Trait { body: true }
232+
} else {
233+
MethodKind::Inherent
234+
}),
235+
AssocItemKind::Type(_) => Target::AssocTy,
236+
_ => unreachable!(),
237+
}
238+
}
239+
227240
pub fn name(self) -> &'static str {
228241
match self {
229242
Target::ExternCrate => "extern crate",

0 commit comments

Comments
 (0)