diff options
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r-- | crates/ra_hir_def/src/adt.rs | 42 | ||||
-rw-r--r-- | crates/ra_hir_def/src/diagnostics.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/type_ref.rs | 6 |
3 files changed, 42 insertions, 8 deletions
diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs index 6cb56a1cd..35c3a9140 100644 --- a/crates/ra_hir_def/src/adt.rs +++ b/crates/ra_hir_def/src/adt.rs | |||
@@ -9,11 +9,12 @@ use hir_expand::{ | |||
9 | }; | 9 | }; |
10 | use ra_arena::{map::ArenaMap, Arena}; | 10 | use ra_arena::{map::ArenaMap, Arena}; |
11 | use ra_syntax::ast::{self, NameOwner, VisibilityOwner}; | 11 | use ra_syntax::ast::{self, NameOwner, VisibilityOwner}; |
12 | use tt::{Delimiter, DelimiterKind, Leaf, Subtree, TokenTree}; | ||
12 | 13 | ||
13 | use crate::{ | 14 | use crate::{ |
14 | body::{CfgExpander, LowerCtx}, | 15 | body::{CfgExpander, LowerCtx}, |
15 | db::DefDatabase, | 16 | db::DefDatabase, |
16 | item_tree::{Field, Fields, ItemTree}, | 17 | item_tree::{AttrOwner, Field, Fields, ItemTree, ModItem}, |
17 | src::HasChildSource, | 18 | src::HasChildSource, |
18 | src::HasSource, | 19 | src::HasSource, |
19 | trace::Trace, | 20 | trace::Trace, |
@@ -29,6 +30,7 @@ use ra_cfg::CfgOptions; | |||
29 | pub struct StructData { | 30 | pub struct StructData { |
30 | pub name: Name, | 31 | pub name: Name, |
31 | pub variant_data: Arc<VariantData>, | 32 | pub variant_data: Arc<VariantData>, |
33 | pub repr: Option<ReprKind>, | ||
32 | } | 34 | } |
33 | 35 | ||
34 | #[derive(Debug, Clone, PartialEq, Eq)] | 36 | #[derive(Debug, Clone, PartialEq, Eq)] |
@@ -58,26 +60,58 @@ pub struct FieldData { | |||
58 | pub visibility: RawVisibility, | 60 | pub visibility: RawVisibility, |
59 | } | 61 | } |
60 | 62 | ||
63 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
64 | pub enum ReprKind { | ||
65 | Packed, | ||
66 | Other, | ||
67 | } | ||
68 | |||
69 | fn repr_from_value(item_tree: &ItemTree, of: AttrOwner) -> Option<ReprKind> { | ||
70 | item_tree.attrs(of).by_key("repr").tt_values().find_map(parse_repr_tt) | ||
71 | } | ||
72 | |||
73 | fn parse_repr_tt(tt: &Subtree) -> Option<ReprKind> { | ||
74 | match tt.delimiter { | ||
75 | Some(Delimiter { kind: DelimiterKind::Parenthesis, .. }) => {} | ||
76 | _ => return None, | ||
77 | } | ||
78 | |||
79 | let mut it = tt.token_trees.iter(); | ||
80 | match it.next()? { | ||
81 | TokenTree::Leaf(Leaf::Ident(ident)) if ident.text == "packed" => Some(ReprKind::Packed), | ||
82 | _ => Some(ReprKind::Other), | ||
83 | } | ||
84 | } | ||
85 | |||
61 | impl StructData { | 86 | impl StructData { |
62 | pub(crate) fn struct_data_query(db: &dyn DefDatabase, id: StructId) -> Arc<StructData> { | 87 | pub(crate) fn struct_data_query(db: &dyn DefDatabase, id: StructId) -> Arc<StructData> { |
63 | let loc = id.lookup(db); | 88 | let loc = id.lookup(db); |
64 | let item_tree = db.item_tree(loc.id.file_id); | 89 | let item_tree = db.item_tree(loc.id.file_id); |
90 | let repr = repr_from_value(&item_tree, ModItem::from(loc.id.value).into()); | ||
65 | let cfg_options = db.crate_graph()[loc.container.module(db).krate].cfg_options.clone(); | 91 | let cfg_options = db.crate_graph()[loc.container.module(db).krate].cfg_options.clone(); |
66 | 92 | ||
67 | let strukt = &item_tree[loc.id.value]; | 93 | let strukt = &item_tree[loc.id.value]; |
68 | let variant_data = lower_fields(&item_tree, &cfg_options, &strukt.fields); | 94 | let variant_data = lower_fields(&item_tree, &cfg_options, &strukt.fields); |
69 | 95 | Arc::new(StructData { | |
70 | Arc::new(StructData { name: strukt.name.clone(), variant_data: Arc::new(variant_data) }) | 96 | name: strukt.name.clone(), |
97 | variant_data: Arc::new(variant_data), | ||
98 | repr, | ||
99 | }) | ||
71 | } | 100 | } |
72 | pub(crate) fn union_data_query(db: &dyn DefDatabase, id: UnionId) -> Arc<StructData> { | 101 | pub(crate) fn union_data_query(db: &dyn DefDatabase, id: UnionId) -> Arc<StructData> { |
73 | let loc = id.lookup(db); | 102 | let loc = id.lookup(db); |
74 | let item_tree = db.item_tree(loc.id.file_id); | 103 | let item_tree = db.item_tree(loc.id.file_id); |
104 | let repr = repr_from_value(&item_tree, ModItem::from(loc.id.value).into()); | ||
75 | let cfg_options = db.crate_graph()[loc.container.module(db).krate].cfg_options.clone(); | 105 | let cfg_options = db.crate_graph()[loc.container.module(db).krate].cfg_options.clone(); |
76 | 106 | ||
77 | let union = &item_tree[loc.id.value]; | 107 | let union = &item_tree[loc.id.value]; |
78 | let variant_data = lower_fields(&item_tree, &cfg_options, &union.fields); | 108 | let variant_data = lower_fields(&item_tree, &cfg_options, &union.fields); |
79 | 109 | ||
80 | Arc::new(StructData { name: union.name.clone(), variant_data: Arc::new(variant_data) }) | 110 | Arc::new(StructData { |
111 | name: union.name.clone(), | ||
112 | variant_data: Arc::new(variant_data), | ||
113 | repr, | ||
114 | }) | ||
81 | } | 115 | } |
82 | } | 116 | } |
83 | 117 | ||
diff --git a/crates/ra_hir_def/src/diagnostics.rs b/crates/ra_hir_def/src/diagnostics.rs index 30db48f86..71d177070 100644 --- a/crates/ra_hir_def/src/diagnostics.rs +++ b/crates/ra_hir_def/src/diagnostics.rs | |||
@@ -18,7 +18,7 @@ impl Diagnostic for UnresolvedModule { | |||
18 | fn message(&self) -> String { | 18 | fn message(&self) -> String { |
19 | "unresolved module".to_string() | 19 | "unresolved module".to_string() |
20 | } | 20 | } |
21 | fn source(&self) -> InFile<SyntaxNodePtr> { | 21 | fn display_source(&self) -> InFile<SyntaxNodePtr> { |
22 | InFile::new(self.file, self.decl.clone().into()) | 22 | InFile::new(self.file, self.decl.clone().into()) |
23 | } | 23 | } |
24 | fn as_any(&self) -> &(dyn Any + Send + 'static) { | 24 | fn as_any(&self) -> &(dyn Any + Send + 'static) { |
diff --git a/crates/ra_hir_def/src/type_ref.rs b/crates/ra_hir_def/src/type_ref.rs index fe6619d9f..6f7884ffe 100644 --- a/crates/ra_hir_def/src/type_ref.rs +++ b/crates/ra_hir_def/src/type_ref.rs | |||
@@ -94,7 +94,7 @@ impl TypeRef { | |||
94 | .map(TypeRef::Path) | 94 | .map(TypeRef::Path) |
95 | .unwrap_or(TypeRef::Error) | 95 | .unwrap_or(TypeRef::Error) |
96 | } | 96 | } |
97 | ast::Type::PointerType(inner) => { | 97 | ast::Type::PtrType(inner) => { |
98 | let inner_ty = TypeRef::from_ast_opt(&ctx, inner.ty()); | 98 | let inner_ty = TypeRef::from_ast_opt(&ctx, inner.ty()); |
99 | let mutability = Mutability::from_mutable(inner.mut_token().is_some()); | 99 | let mutability = Mutability::from_mutable(inner.mut_token().is_some()); |
100 | TypeRef::RawPtr(Box::new(inner_ty), mutability) | 100 | TypeRef::RawPtr(Box::new(inner_ty), mutability) |
@@ -105,13 +105,13 @@ impl TypeRef { | |||
105 | ast::Type::SliceType(inner) => { | 105 | ast::Type::SliceType(inner) => { |
106 | TypeRef::Slice(Box::new(TypeRef::from_ast_opt(&ctx, inner.ty()))) | 106 | TypeRef::Slice(Box::new(TypeRef::from_ast_opt(&ctx, inner.ty()))) |
107 | } | 107 | } |
108 | ast::Type::ReferenceType(inner) => { | 108 | ast::Type::RefType(inner) => { |
109 | let inner_ty = TypeRef::from_ast_opt(&ctx, inner.ty()); | 109 | let inner_ty = TypeRef::from_ast_opt(&ctx, inner.ty()); |
110 | let mutability = Mutability::from_mutable(inner.mut_token().is_some()); | 110 | let mutability = Mutability::from_mutable(inner.mut_token().is_some()); |
111 | TypeRef::Reference(Box::new(inner_ty), mutability) | 111 | TypeRef::Reference(Box::new(inner_ty), mutability) |
112 | } | 112 | } |
113 | ast::Type::InferType(_inner) => TypeRef::Placeholder, | 113 | ast::Type::InferType(_inner) => TypeRef::Placeholder, |
114 | ast::Type::FnPointerType(inner) => { | 114 | ast::Type::FnPtrType(inner) => { |
115 | let ret_ty = inner | 115 | let ret_ty = inner |
116 | .ret_type() | 116 | .ret_type() |
117 | .and_then(|rt| rt.ty()) | 117 | .and_then(|rt| rt.ty()) |