diff options
Diffstat (limited to 'crates/ra_hir_def')
-rw-r--r-- | crates/ra_hir_def/src/adt.rs | 25 |
1 files changed, 3 insertions, 22 deletions
diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs index 4ba694480..35c3a9140 100644 --- a/crates/ra_hir_def/src/adt.rs +++ b/crates/ra_hir_def/src/adt.rs | |||
@@ -12,11 +12,9 @@ use ra_syntax::ast::{self, NameOwner, VisibilityOwner}; | |||
12 | use tt::{Delimiter, DelimiterKind, Leaf, Subtree, TokenTree}; | 12 | use tt::{Delimiter, DelimiterKind, Leaf, Subtree, TokenTree}; |
13 | 13 | ||
14 | use crate::{ | 14 | use crate::{ |
15 | attr::{Attr, AttrInput}, | ||
16 | body::{CfgExpander, LowerCtx}, | 15 | body::{CfgExpander, LowerCtx}, |
17 | db::DefDatabase, | 16 | db::DefDatabase, |
18 | item_tree::{AttrOwner, Field, Fields, ItemTree, ModItem}, | 17 | item_tree::{AttrOwner, Field, Fields, ItemTree, ModItem}, |
19 | path::{ModPath, PathKind}, | ||
20 | src::HasChildSource, | 18 | src::HasChildSource, |
21 | src::HasSource, | 19 | src::HasSource, |
22 | trace::Trace, | 20 | trace::Trace, |
@@ -69,21 +67,7 @@ pub enum ReprKind { | |||
69 | } | 67 | } |
70 | 68 | ||
71 | fn repr_from_value(item_tree: &ItemTree, of: AttrOwner) -> Option<ReprKind> { | 69 | fn repr_from_value(item_tree: &ItemTree, of: AttrOwner) -> Option<ReprKind> { |
72 | item_tree.attrs(of).iter().find_map(|a| { | 70 | item_tree.attrs(of).by_key("repr").tt_values().find_map(parse_repr_tt) |
73 | if let Attr { | ||
74 | path: ModPath { kind: PathKind::Plain, segments }, | ||
75 | input: Some(AttrInput::TokenTree(subtree)), | ||
76 | } = a | ||
77 | { | ||
78 | if segments.len() == 1 && segments[0].to_string() == "repr" { | ||
79 | parse_repr_tt(subtree) | ||
80 | } else { | ||
81 | None | ||
82 | } | ||
83 | } else { | ||
84 | None | ||
85 | } | ||
86 | }) | ||
87 | } | 71 | } |
88 | 72 | ||
89 | fn parse_repr_tt(tt: &Subtree) -> Option<ReprKind> { | 73 | fn parse_repr_tt(tt: &Subtree) -> Option<ReprKind> { |
@@ -93,11 +77,8 @@ fn parse_repr_tt(tt: &Subtree) -> Option<ReprKind> { | |||
93 | } | 77 | } |
94 | 78 | ||
95 | let mut it = tt.token_trees.iter(); | 79 | let mut it = tt.token_trees.iter(); |
96 | match it.next() { | 80 | match it.next()? { |
97 | None => None, | 81 | TokenTree::Leaf(Leaf::Ident(ident)) if ident.text == "packed" => Some(ReprKind::Packed), |
98 | Some(TokenTree::Leaf(Leaf::Ident(ident))) if ident.text == "packed" => { | ||
99 | Some(ReprKind::Packed) | ||
100 | } | ||
101 | _ => Some(ReprKind::Other), | 82 | _ => Some(ReprKind::Other), |
102 | } | 83 | } |
103 | } | 84 | } |