|
4 | 4 | //! conflicts between multiple such attributes attached to the same
|
5 | 5 | //! item.
|
6 | 6 |
|
7 |
| -use crate::hir::map::Map; |
8 |
| -use crate::ty::query::Providers; |
9 |
| -use crate::ty::TyCtxt; |
| 7 | +use rustc::hir::check_attr::{MethodKind, Target}; |
| 8 | +use rustc::hir::map::Map; |
| 9 | +use rustc::ty::query::Providers; |
| 10 | +use rustc::ty::TyCtxt; |
10 | 11 |
|
11 | 12 | use rustc_errors::struct_span_err;
|
12 | 13 | use rustc_hir as hir;
|
13 | 14 | use rustc_hir::def_id::DefId;
|
14 | 15 | use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
|
15 | 16 | use rustc_hir::DUMMY_HIR_ID;
|
16 |
| -use rustc_hir::{self, HirId, Item, ItemKind, TraitItem, TraitItemKind}; |
| 17 | +use rustc_hir::{self, HirId, Item, ItemKind, TraitItem}; |
17 | 18 | use rustc_session::lint::builtin::{CONFLICTING_REPR_HINTS, UNUSED_ATTRIBUTES};
|
18 | 19 | use rustc_span::symbol::sym;
|
19 | 20 | use rustc_span::Span;
|
20 | 21 | use syntax::ast::Attribute;
|
21 | 22 | use syntax::attr;
|
22 | 23 |
|
23 |
| -use std::fmt::{self, Display}; |
24 |
| - |
25 |
| -#[derive(Copy, Clone, PartialEq)] |
26 |
| -pub(crate) enum MethodKind { |
27 |
| - Trait { body: bool }, |
28 |
| - Inherent, |
29 |
| -} |
30 |
| - |
31 |
| -#[derive(Copy, Clone, PartialEq)] |
32 |
| -pub(crate) enum Target { |
33 |
| - ExternCrate, |
34 |
| - Use, |
35 |
| - Static, |
36 |
| - Const, |
37 |
| - Fn, |
38 |
| - Closure, |
39 |
| - Mod, |
40 |
| - ForeignMod, |
41 |
| - GlobalAsm, |
42 |
| - TyAlias, |
43 |
| - OpaqueTy, |
44 |
| - Enum, |
45 |
| - Struct, |
46 |
| - Union, |
47 |
| - Trait, |
48 |
| - TraitAlias, |
49 |
| - Impl, |
50 |
| - Expression, |
51 |
| - Statement, |
52 |
| - AssocConst, |
53 |
| - Method(MethodKind), |
54 |
| - AssocTy, |
55 |
| - ForeignFn, |
56 |
| - ForeignStatic, |
57 |
| - ForeignTy, |
| 24 | +pub(crate) trait TargetExt { |
| 25 | + fn from_impl_item<'tcx>(tcx: TyCtxt<'tcx>, impl_item: &hir::ImplItem<'_>) -> Target; |
58 | 26 | }
|
59 | 27 |
|
60 |
| -impl Display for Target { |
61 |
| - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
62 |
| - write!( |
63 |
| - f, |
64 |
| - "{}", |
65 |
| - match *self { |
66 |
| - Target::ExternCrate => "extern crate", |
67 |
| - Target::Use => "use", |
68 |
| - Target::Static => "static item", |
69 |
| - Target::Const => "constant item", |
70 |
| - Target::Fn => "function", |
71 |
| - Target::Closure => "closure", |
72 |
| - Target::Mod => "module", |
73 |
| - Target::ForeignMod => "foreign module", |
74 |
| - Target::GlobalAsm => "global asm", |
75 |
| - Target::TyAlias => "type alias", |
76 |
| - Target::OpaqueTy => "opaque type", |
77 |
| - Target::Enum => "enum", |
78 |
| - Target::Struct => "struct", |
79 |
| - Target::Union => "union", |
80 |
| - Target::Trait => "trait", |
81 |
| - Target::TraitAlias => "trait alias", |
82 |
| - Target::Impl => "item", |
83 |
| - Target::Expression => "expression", |
84 |
| - Target::Statement => "statement", |
85 |
| - Target::AssocConst => "associated const", |
86 |
| - Target::Method(_) => "method", |
87 |
| - Target::AssocTy => "associated type", |
88 |
| - Target::ForeignFn => "foreign function", |
89 |
| - Target::ForeignStatic => "foreign static item", |
90 |
| - Target::ForeignTy => "foreign type", |
91 |
| - } |
92 |
| - ) |
93 |
| - } |
94 |
| -} |
95 |
| - |
96 |
| -impl Target { |
97 |
| - pub(crate) fn from_item(item: &Item<'_>) -> Target { |
98 |
| - match item.kind { |
99 |
| - ItemKind::ExternCrate(..) => Target::ExternCrate, |
100 |
| - ItemKind::Use(..) => Target::Use, |
101 |
| - ItemKind::Static(..) => Target::Static, |
102 |
| - ItemKind::Const(..) => Target::Const, |
103 |
| - ItemKind::Fn(..) => Target::Fn, |
104 |
| - ItemKind::Mod(..) => Target::Mod, |
105 |
| - ItemKind::ForeignMod(..) => Target::ForeignMod, |
106 |
| - ItemKind::GlobalAsm(..) => Target::GlobalAsm, |
107 |
| - ItemKind::TyAlias(..) => Target::TyAlias, |
108 |
| - ItemKind::OpaqueTy(..) => Target::OpaqueTy, |
109 |
| - ItemKind::Enum(..) => Target::Enum, |
110 |
| - ItemKind::Struct(..) => Target::Struct, |
111 |
| - ItemKind::Union(..) => Target::Union, |
112 |
| - ItemKind::Trait(..) => Target::Trait, |
113 |
| - ItemKind::TraitAlias(..) => Target::TraitAlias, |
114 |
| - ItemKind::Impl { .. } => Target::Impl, |
115 |
| - } |
116 |
| - } |
117 |
| - |
118 |
| - fn from_trait_item(trait_item: &TraitItem<'_>) -> Target { |
119 |
| - match trait_item.kind { |
120 |
| - TraitItemKind::Const(..) => Target::AssocConst, |
121 |
| - TraitItemKind::Method(_, hir::TraitMethod::Required(_)) => { |
122 |
| - Target::Method(MethodKind::Trait { body: false }) |
123 |
| - } |
124 |
| - TraitItemKind::Method(_, hir::TraitMethod::Provided(_)) => { |
125 |
| - Target::Method(MethodKind::Trait { body: true }) |
126 |
| - } |
127 |
| - TraitItemKind::Type(..) => Target::AssocTy, |
128 |
| - } |
129 |
| - } |
130 |
| - |
131 |
| - fn from_foreign_item(foreign_item: &hir::ForeignItem<'_>) -> Target { |
132 |
| - match foreign_item.kind { |
133 |
| - hir::ForeignItemKind::Fn(..) => Target::ForeignFn, |
134 |
| - hir::ForeignItemKind::Static(..) => Target::ForeignStatic, |
135 |
| - hir::ForeignItemKind::Type => Target::ForeignTy, |
136 |
| - } |
137 |
| - } |
138 |
| - |
| 28 | +impl TargetExt for Target { |
139 | 29 | fn from_impl_item<'tcx>(tcx: TyCtxt<'tcx>, impl_item: &hir::ImplItem<'_>) -> Target {
|
140 | 30 | match impl_item.kind {
|
141 | 31 | hir::ImplItemKind::Const(..) => Target::AssocConst,
|
|
0 commit comments