diff options
Diffstat (limited to 'crates')
26 files changed, 229 insertions, 103 deletions
diff --git a/crates/gen_lsp_server/Cargo.toml b/crates/gen_lsp_server/Cargo.toml index d375606d0..d14bcf694 100644 --- a/crates/gen_lsp_server/Cargo.toml +++ b/crates/gen_lsp_server/Cargo.toml | |||
@@ -15,4 +15,4 @@ serde = { version = "1.0.83", features = ["derive"] } | |||
15 | crossbeam-channel = "0.3.5" | 15 | crossbeam-channel = "0.3.5" |
16 | 16 | ||
17 | [dev-dependencies] | 17 | [dev-dependencies] |
18 | flexi_logger = "0.11.0" | 18 | flexi_logger = "0.13.0" |
diff --git a/crates/ra_cli/Cargo.toml b/crates/ra_cli/Cargo.toml index 57bd0c3d7..301145b5d 100644 --- a/crates/ra_cli/Cargo.toml +++ b/crates/ra_cli/Cargo.toml | |||
@@ -8,7 +8,7 @@ publish = false | |||
8 | [dependencies] | 8 | [dependencies] |
9 | clap = "2.32.0" | 9 | clap = "2.32.0" |
10 | join_to_string = "0.1.1" | 10 | join_to_string = "0.1.1" |
11 | flexi_logger = "0.11.0" | 11 | flexi_logger = "0.13.0" |
12 | indicatif = "0.11.0" | 12 | indicatif = "0.11.0" |
13 | 13 | ||
14 | ra_syntax = { path = "../ra_syntax" } | 14 | ra_syntax = { path = "../ra_syntax" } |
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index a5f4e489f..c103503bd 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs | |||
@@ -31,9 +31,23 @@ pub struct SourceRootId(pub u32); | |||
31 | 31 | ||
32 | #[derive(Default, Clone, Debug, PartialEq, Eq)] | 32 | #[derive(Default, Clone, Debug, PartialEq, Eq)] |
33 | pub struct SourceRoot { | 33 | pub struct SourceRoot { |
34 | /// Sysroot or crates.io library. | ||
35 | /// | ||
36 | /// Libraries are considered mostly immutable, this assumption is used to | ||
37 | /// optimize salsa's query structure | ||
38 | pub is_library: bool, | ||
34 | pub files: FxHashMap<RelativePathBuf, FileId>, | 39 | pub files: FxHashMap<RelativePathBuf, FileId>, |
35 | } | 40 | } |
36 | 41 | ||
42 | impl SourceRoot { | ||
43 | pub fn new() -> SourceRoot { | ||
44 | Default::default() | ||
45 | } | ||
46 | pub fn new_library() -> SourceRoot { | ||
47 | SourceRoot { is_library: true, ..SourceRoot::new() } | ||
48 | } | ||
49 | } | ||
50 | |||
37 | /// `CrateGraph` is a bit of information which turns a set of text files into a | 51 | /// `CrateGraph` is a bit of information which turns a set of text files into a |
38 | /// number of Rust crates. Each crate is defined by the `FileId` of its root module, | 52 | /// number of Rust crates. Each crate is defined by the `FileId` of its root module, |
39 | /// the set of cfg flags (not yet implemented) and the set of dependencies. Note | 53 | /// the set of cfg flags (not yet implemented) and the set of dependencies. Note |
diff --git a/crates/ra_hir/Cargo.toml b/crates/ra_hir/Cargo.toml index aaace85e5..e44e144d6 100644 --- a/crates/ra_hir/Cargo.toml +++ b/crates/ra_hir/Cargo.toml | |||
@@ -10,7 +10,7 @@ log = "0.4.5" | |||
10 | relative-path = "0.4.0" | 10 | relative-path = "0.4.0" |
11 | rustc-hash = "1.0" | 11 | rustc-hash = "1.0" |
12 | parking_lot = "0.8.0" | 12 | parking_lot = "0.8.0" |
13 | ena = "0.11" | 13 | ena = "0.13" |
14 | join_to_string = "0.1.3" | 14 | join_to_string = "0.1.3" |
15 | once_cell = "0.2" | 15 | once_cell = "0.2" |
16 | 16 | ||
@@ -28,5 +28,5 @@ chalk-ir = { git = "https://github.com/flodiebold/chalk.git", branch = "fuel" } | |||
28 | lalrpop-intern = "0.15.1" | 28 | lalrpop-intern = "0.15.1" |
29 | 29 | ||
30 | [dev-dependencies] | 30 | [dev-dependencies] |
31 | flexi_logger = "0.11.0" | 31 | flexi_logger = "0.13.0" |
32 | insta = "0.8.1" | 32 | insta = "0.8.1" |
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 6602d1220..ebbc37c0e 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -282,7 +282,7 @@ impl Module { | |||
282 | .collect() | 282 | .collect() |
283 | } | 283 | } |
284 | 284 | ||
285 | pub fn impl_blocks(self, db: &impl HirDatabase) -> Vec<ImplBlock> { | 285 | pub fn impl_blocks(self, db: &impl DefDatabase) -> Vec<ImplBlock> { |
286 | let module_impl_blocks = db.impls_in_module(self); | 286 | let module_impl_blocks = db.impls_in_module(self); |
287 | module_impl_blocks | 287 | module_impl_blocks |
288 | .impls | 288 | .impls |
@@ -519,9 +519,8 @@ pub struct Function { | |||
519 | pub(crate) id: FunctionId, | 519 | pub(crate) id: FunctionId, |
520 | } | 520 | } |
521 | 521 | ||
522 | /// The declared signature of a function. | ||
523 | #[derive(Debug, Clone, PartialEq, Eq)] | 522 | #[derive(Debug, Clone, PartialEq, Eq)] |
524 | pub struct FnSignature { | 523 | pub struct FnData { |
525 | pub(crate) name: Name, | 524 | pub(crate) name: Name, |
526 | pub(crate) params: Vec<TypeRef>, | 525 | pub(crate) params: Vec<TypeRef>, |
527 | pub(crate) ret_type: TypeRef, | 526 | pub(crate) ret_type: TypeRef, |
@@ -530,11 +529,11 @@ pub struct FnSignature { | |||
530 | pub(crate) has_self_param: bool, | 529 | pub(crate) has_self_param: bool, |
531 | } | 530 | } |
532 | 531 | ||
533 | impl FnSignature { | 532 | impl FnData { |
534 | pub(crate) fn fn_signature_query( | 533 | pub(crate) fn fn_data_query( |
535 | db: &(impl DefDatabase + AstDatabase), | 534 | db: &(impl DefDatabase + AstDatabase), |
536 | func: Function, | 535 | func: Function, |
537 | ) -> Arc<FnSignature> { | 536 | ) -> Arc<FnData> { |
538 | let src = func.source(db); | 537 | let src = func.source(db); |
539 | let name = src.ast.name().map(|n| n.as_name()).unwrap_or_else(Name::missing); | 538 | let name = src.ast.name().map(|n| n.as_name()).unwrap_or_else(Name::missing); |
540 | let mut params = Vec::new(); | 539 | let mut params = Vec::new(); |
@@ -569,7 +568,7 @@ impl FnSignature { | |||
569 | TypeRef::unit() | 568 | TypeRef::unit() |
570 | }; | 569 | }; |
571 | 570 | ||
572 | let sig = FnSignature { name, params, ret_type, has_self_param }; | 571 | let sig = FnData { name, params, ret_type, has_self_param }; |
573 | Arc::new(sig) | 572 | Arc::new(sig) |
574 | } | 573 | } |
575 | pub fn name(&self) -> &Name { | 574 | pub fn name(&self) -> &Name { |
@@ -597,7 +596,7 @@ impl Function { | |||
597 | } | 596 | } |
598 | 597 | ||
599 | pub fn name(self, db: &impl HirDatabase) -> Name { | 598 | pub fn name(self, db: &impl HirDatabase) -> Name { |
600 | self.signature(db).name.clone() | 599 | self.data(db).name.clone() |
601 | } | 600 | } |
602 | 601 | ||
603 | pub(crate) fn body_source_map(self, db: &impl HirDatabase) -> Arc<BodySourceMap> { | 602 | pub(crate) fn body_source_map(self, db: &impl HirDatabase) -> Arc<BodySourceMap> { |
@@ -612,8 +611,8 @@ impl Function { | |||
612 | db.type_for_def(self.into(), Namespace::Values) | 611 | db.type_for_def(self.into(), Namespace::Values) |
613 | } | 612 | } |
614 | 613 | ||
615 | pub fn signature(self, db: &impl HirDatabase) -> Arc<FnSignature> { | 614 | pub fn data(self, db: &impl HirDatabase) -> Arc<FnData> { |
616 | db.fn_signature(self) | 615 | db.fn_data(self) |
617 | } | 616 | } |
618 | 617 | ||
619 | pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> { | 618 | pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> { |
@@ -670,8 +669,8 @@ impl Const { | |||
670 | self.id.module(db) | 669 | self.id.module(db) |
671 | } | 670 | } |
672 | 671 | ||
673 | pub fn signature(self, db: &impl HirDatabase) -> Arc<ConstSignature> { | 672 | pub fn data(self, db: &impl HirDatabase) -> Arc<ConstData> { |
674 | db.const_signature(self) | 673 | db.const_data(self) |
675 | } | 674 | } |
676 | 675 | ||
677 | pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> { | 676 | pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> { |
@@ -696,14 +695,13 @@ impl Const { | |||
696 | } | 695 | } |
697 | } | 696 | } |
698 | 697 | ||
699 | /// The declared signature of a const. | ||
700 | #[derive(Debug, Clone, PartialEq, Eq)] | 698 | #[derive(Debug, Clone, PartialEq, Eq)] |
701 | pub struct ConstSignature { | 699 | pub struct ConstData { |
702 | pub(crate) name: Name, | 700 | pub(crate) name: Name, |
703 | pub(crate) type_ref: TypeRef, | 701 | pub(crate) type_ref: TypeRef, |
704 | } | 702 | } |
705 | 703 | ||
706 | impl ConstSignature { | 704 | impl ConstData { |
707 | pub fn name(&self) -> &Name { | 705 | pub fn name(&self) -> &Name { |
708 | &self.name | 706 | &self.name |
709 | } | 707 | } |
@@ -712,27 +710,27 @@ impl ConstSignature { | |||
712 | &self.type_ref | 710 | &self.type_ref |
713 | } | 711 | } |
714 | 712 | ||
715 | pub(crate) fn const_signature_query( | 713 | pub(crate) fn const_data_query( |
716 | db: &(impl DefDatabase + AstDatabase), | 714 | db: &(impl DefDatabase + AstDatabase), |
717 | konst: Const, | 715 | konst: Const, |
718 | ) -> Arc<ConstSignature> { | 716 | ) -> Arc<ConstData> { |
719 | let node = konst.source(db).ast; | 717 | let node = konst.source(db).ast; |
720 | const_signature_for(&*node) | 718 | const_data_for(&*node) |
721 | } | 719 | } |
722 | 720 | ||
723 | pub(crate) fn static_signature_query( | 721 | pub(crate) fn static_data_query( |
724 | db: &(impl DefDatabase + AstDatabase), | 722 | db: &(impl DefDatabase + AstDatabase), |
725 | konst: Static, | 723 | konst: Static, |
726 | ) -> Arc<ConstSignature> { | 724 | ) -> Arc<ConstData> { |
727 | let node = konst.source(db).ast; | 725 | let node = konst.source(db).ast; |
728 | const_signature_for(&*node) | 726 | const_data_for(&*node) |
729 | } | 727 | } |
730 | } | 728 | } |
731 | 729 | ||
732 | fn const_signature_for<N: NameOwner + TypeAscriptionOwner>(node: &N) -> Arc<ConstSignature> { | 730 | fn const_data_for<N: NameOwner + TypeAscriptionOwner>(node: &N) -> Arc<ConstData> { |
733 | let name = node.name().map(|n| n.as_name()).unwrap_or_else(Name::missing); | 731 | let name = node.name().map(|n| n.as_name()).unwrap_or_else(Name::missing); |
734 | let type_ref = TypeRef::from_ast_opt(node.ascribed_type()); | 732 | let type_ref = TypeRef::from_ast_opt(node.ascribed_type()); |
735 | let sig = ConstSignature { name, type_ref }; | 733 | let sig = ConstData { name, type_ref }; |
736 | Arc::new(sig) | 734 | Arc::new(sig) |
737 | } | 735 | } |
738 | 736 | ||
@@ -746,8 +744,8 @@ impl Static { | |||
746 | self.id.module(db) | 744 | self.id.module(db) |
747 | } | 745 | } |
748 | 746 | ||
749 | pub fn signature(self, db: &impl HirDatabase) -> Arc<ConstSignature> { | 747 | pub fn data(self, db: &impl HirDatabase) -> Arc<ConstData> { |
750 | db.static_signature(self) | 748 | db.static_data(self) |
751 | } | 749 | } |
752 | 750 | ||
753 | /// Builds a resolver for code inside this item. | 751 | /// Builds a resolver for code inside this item. |
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index c4dd54596..d8832a9de 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs | |||
@@ -6,9 +6,9 @@ use ra_db::{SourceDatabase, salsa}; | |||
6 | 6 | ||
7 | use crate::{ | 7 | use crate::{ |
8 | HirFileId, MacroDefId, AstIdMap, ErasedFileAstId, Crate, Module, MacroCallLoc, | 8 | HirFileId, MacroDefId, AstIdMap, ErasedFileAstId, Crate, Module, MacroCallLoc, |
9 | Function, FnSignature, ExprScopes, TypeAlias, | 9 | Function, FnData, ExprScopes, TypeAlias, |
10 | Struct, Enum, StructField, | 10 | Struct, Enum, StructField, |
11 | Const, ConstSignature, Static, | 11 | Const, ConstData, Static, |
12 | DefWithBody, Trait, | 12 | DefWithBody, Trait, |
13 | ids, | 13 | ids, |
14 | nameres::{Namespace, ImportSourceMap, RawItems, CrateDefMap}, | 14 | nameres::{Namespace, ImportSourceMap, RawItems, CrateDefMap}, |
@@ -109,17 +109,20 @@ pub trait DefDatabase: SourceDatabase { | |||
109 | #[salsa::invoke(crate::generics::GenericParams::generic_params_query)] | 109 | #[salsa::invoke(crate::generics::GenericParams::generic_params_query)] |
110 | fn generic_params(&self, def: GenericDef) -> Arc<GenericParams>; | 110 | fn generic_params(&self, def: GenericDef) -> Arc<GenericParams>; |
111 | 111 | ||
112 | #[salsa::invoke(crate::FnSignature::fn_signature_query)] | 112 | #[salsa::invoke(crate::FnData::fn_data_query)] |
113 | fn fn_signature(&self, func: Function) -> Arc<FnSignature>; | 113 | fn fn_data(&self, func: Function) -> Arc<FnData>; |
114 | 114 | ||
115 | #[salsa::invoke(crate::type_alias::type_alias_data_query)] | 115 | #[salsa::invoke(crate::type_alias::type_alias_data_query)] |
116 | fn type_alias_data(&self, typ: TypeAlias) -> Arc<TypeAliasData>; | 116 | fn type_alias_data(&self, typ: TypeAlias) -> Arc<TypeAliasData>; |
117 | 117 | ||
118 | #[salsa::invoke(crate::ConstSignature::const_signature_query)] | 118 | #[salsa::invoke(crate::ConstData::const_data_query)] |
119 | fn const_signature(&self, konst: Const) -> Arc<ConstSignature>; | 119 | fn const_data(&self, konst: Const) -> Arc<ConstData>; |
120 | 120 | ||
121 | #[salsa::invoke(crate::ConstSignature::static_signature_query)] | 121 | #[salsa::invoke(crate::ConstData::static_data_query)] |
122 | fn static_signature(&self, konst: Static) -> Arc<ConstSignature>; | 122 | fn static_data(&self, konst: Static) -> Arc<ConstData>; |
123 | |||
124 | #[salsa::invoke(crate::lang_item::LangItems::module_lang_items_query)] | ||
125 | fn module_lang_items(&self, module: Module) -> Option<Arc<LangItems>>; | ||
123 | 126 | ||
124 | #[salsa::invoke(crate::lang_item::LangItems::lang_items_query)] | 127 | #[salsa::invoke(crate::lang_item::LangItems::lang_items_query)] |
125 | fn lang_items(&self, krate: Crate) -> Arc<LangItems>; | 128 | fn lang_items(&self, krate: Crate) -> Arc<LangItems>; |
diff --git a/crates/ra_hir/src/lang_item.rs b/crates/ra_hir/src/lang_item.rs index 18ac0fcf9..48b60f2dd 100644 --- a/crates/ra_hir/src/lang_item.rs +++ b/crates/ra_hir/src/lang_item.rs | |||
@@ -31,7 +31,7 @@ impl LangItemTarget { | |||
31 | } | 31 | } |
32 | } | 32 | } |
33 | 33 | ||
34 | #[derive(Debug, Clone, PartialEq, Eq)] | 34 | #[derive(Default, Debug, Clone, PartialEq, Eq)] |
35 | pub struct LangItems { | 35 | pub struct LangItems { |
36 | items: FxHashMap<SmolStr, LangItemTarget>, | 36 | items: FxHashMap<SmolStr, LangItemTarget>, |
37 | } | 37 | } |
@@ -46,15 +46,28 @@ impl LangItems { | |||
46 | db: &(impl DefDatabase + AstDatabase), | 46 | db: &(impl DefDatabase + AstDatabase), |
47 | krate: Crate, | 47 | krate: Crate, |
48 | ) -> Arc<LangItems> { | 48 | ) -> Arc<LangItems> { |
49 | let mut lang_items = LangItems { items: FxHashMap::default() }; | 49 | let mut lang_items = LangItems::default(); |
50 | 50 | ||
51 | if let Some(module) = krate.root_module(db) { | 51 | if let Some(module) = krate.root_module(db) { |
52 | lang_items.collect_lang_items_recursive(db, &module); | 52 | lang_items.collect_lang_items_recursive(db, module); |
53 | } | 53 | } |
54 | 54 | ||
55 | Arc::new(lang_items) | 55 | Arc::new(lang_items) |
56 | } | 56 | } |
57 | 57 | ||
58 | pub(crate) fn module_lang_items_query( | ||
59 | db: &(impl DefDatabase + AstDatabase), | ||
60 | module: Module, | ||
61 | ) -> Option<Arc<LangItems>> { | ||
62 | let mut lang_items = LangItems::default(); | ||
63 | lang_items.collect_lang_items(db, module); | ||
64 | if lang_items.items.is_empty() { | ||
65 | None | ||
66 | } else { | ||
67 | Some(Arc::new(lang_items)) | ||
68 | } | ||
69 | } | ||
70 | |||
58 | /// Salsa query. Look for a lang item, starting from the specified crate and recursively | 71 | /// Salsa query. Look for a lang item, starting from the specified crate and recursively |
59 | /// traversing its dependencies. | 72 | /// traversing its dependencies. |
60 | pub(crate) fn lang_item_query( | 73 | pub(crate) fn lang_item_query( |
@@ -78,19 +91,14 @@ impl LangItems { | |||
78 | } | 91 | } |
79 | } | 92 | } |
80 | 93 | ||
81 | fn collect_lang_items_recursive( | 94 | fn collect_lang_items(&mut self, db: &(impl DefDatabase + AstDatabase), module: Module) { |
82 | &mut self, | ||
83 | db: &(impl DefDatabase + AstDatabase), | ||
84 | module: &Module, | ||
85 | ) { | ||
86 | // Look for impl targets | 95 | // Look for impl targets |
87 | let (impl_blocks, source_map) = db.impls_in_module_with_source_map(module.clone()); | 96 | for impl_block in module.impl_blocks(db) { |
88 | let source = module.definition_source(db).ast; | 97 | let src = impl_block.source(db); |
89 | for (impl_id, _) in impl_blocks.impls.iter() { | 98 | if let Some(lang_item_name) = lang_item_name(&*src.ast) { |
90 | let impl_block = source_map.get(&source, impl_id); | 99 | self.items |
91 | if let Some(lang_item_name) = lang_item_name(&*impl_block) { | 100 | .entry(lang_item_name) |
92 | let imp = ImplBlock::from_id(*module, impl_id); | 101 | .or_insert_with(|| LangItemTarget::ImplBlock(impl_block)); |
93 | self.items.entry(lang_item_name).or_insert_with(|| LangItemTarget::ImplBlock(imp)); | ||
94 | } | 102 | } |
95 | } | 103 | } |
96 | 104 | ||
@@ -106,10 +114,20 @@ impl LangItems { | |||
106 | _ => {} | 114 | _ => {} |
107 | } | 115 | } |
108 | } | 116 | } |
117 | } | ||
118 | |||
119 | fn collect_lang_items_recursive( | ||
120 | &mut self, | ||
121 | db: &(impl DefDatabase + AstDatabase), | ||
122 | module: Module, | ||
123 | ) { | ||
124 | if let Some(module_lang_items) = db.module_lang_items(module) { | ||
125 | self.items.extend(module_lang_items.items.iter().map(|(k, v)| (k.clone(), v.clone()))) | ||
126 | } | ||
109 | 127 | ||
110 | // Look for lang items in the children | 128 | // Look for lang items in the children |
111 | for child in module.children(db) { | 129 | for child in module.children(db) { |
112 | self.collect_lang_items_recursive(db, &child); | 130 | self.collect_lang_items_recursive(db, child); |
113 | } | 131 | } |
114 | } | 132 | } |
115 | 133 | ||
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 2e99bdac8..f07a36926 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs | |||
@@ -75,9 +75,9 @@ pub use self::code_model::{ | |||
75 | DefWithBody, | 75 | DefWithBody, |
76 | Module, ModuleDef, ModuleSource, | 76 | Module, ModuleDef, ModuleSource, |
77 | Struct, Union, Enum, EnumVariant, | 77 | Struct, Union, Enum, EnumVariant, |
78 | Function, FnSignature, | 78 | Function, FnData, |
79 | StructField, FieldSource, | 79 | StructField, FieldSource, |
80 | Static, Const, ConstSignature, | 80 | Static, Const, ConstData, |
81 | Trait, TypeAlias, MacroDef, Container, | 81 | Trait, TypeAlias, MacroDef, Container, |
82 | BuiltinType, | 82 | BuiltinType, |
83 | src::{Source, HasSource}, | 83 | src::{Source, HasSource}, |
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 1ee40c70a..2c05ca734 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs | |||
@@ -27,7 +27,7 @@ use ra_prof::profile; | |||
27 | use test_utils::tested_by; | 27 | use test_utils::tested_by; |
28 | 28 | ||
29 | use crate::{ | 29 | use crate::{ |
30 | Function, StructField, Path, Name, FnSignature, AdtDef, ConstSignature, HirDatabase, | 30 | Function, StructField, Path, Name, FnData, AdtDef, ConstData, HirDatabase, |
31 | DefWithBody, ImplItem, | 31 | DefWithBody, ImplItem, |
32 | type_ref::{TypeRef, Mutability}, | 32 | type_ref::{TypeRef, Mutability}, |
33 | expr::{ | 33 | expr::{ |
@@ -59,9 +59,9 @@ pub fn infer_query(db: &impl HirDatabase, def: DefWithBody) -> Arc<InferenceResu | |||
59 | let mut ctx = InferenceContext::new(db, body, resolver); | 59 | let mut ctx = InferenceContext::new(db, body, resolver); |
60 | 60 | ||
61 | match def { | 61 | match def { |
62 | DefWithBody::Const(ref c) => ctx.collect_const_signature(&c.signature(db)), | 62 | DefWithBody::Const(ref c) => ctx.collect_const(&c.data(db)), |
63 | DefWithBody::Function(ref f) => ctx.collect_fn_signature(&f.signature(db)), | 63 | DefWithBody::Function(ref f) => ctx.collect_fn(&f.data(db)), |
64 | DefWithBody::Static(ref s) => ctx.collect_const_signature(&s.signature(db)), | 64 | DefWithBody::Static(ref s) => ctx.collect_const(&s.data(db)), |
65 | } | 65 | } |
66 | 66 | ||
67 | ctx.infer_body(); | 67 | ctx.infer_body(); |
@@ -509,8 +509,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
509 | let item: crate::ModuleDef = ty.iterate_impl_items(self.db, krate, |item| { | 509 | let item: crate::ModuleDef = ty.iterate_impl_items(self.db, krate, |item| { |
510 | let matching_def: Option<crate::ModuleDef> = match item { | 510 | let matching_def: Option<crate::ModuleDef> = match item { |
511 | crate::ImplItem::Method(func) => { | 511 | crate::ImplItem::Method(func) => { |
512 | let sig = func.signature(self.db); | 512 | if segment.name == func.name(self.db) { |
513 | if segment.name == *sig.name() { | ||
514 | Some(func.into()) | 513 | Some(func.into()) |
515 | } else { | 514 | } else { |
516 | None | 515 | None |
@@ -518,8 +517,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
518 | } | 517 | } |
519 | 518 | ||
520 | crate::ImplItem::Const(konst) => { | 519 | crate::ImplItem::Const(konst) => { |
521 | let sig = konst.signature(self.db); | 520 | let data = konst.data(self.db); |
522 | if segment.name == *sig.name() { | 521 | if segment.name == *data.name() { |
523 | Some(konst.into()) | 522 | Some(konst.into()) |
524 | } else { | 523 | } else { |
525 | None | 524 | None |
@@ -1283,18 +1282,18 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1283 | ty | 1282 | ty |
1284 | } | 1283 | } |
1285 | 1284 | ||
1286 | fn collect_const_signature(&mut self, signature: &ConstSignature) { | 1285 | fn collect_const(&mut self, data: &ConstData) { |
1287 | self.return_ty = self.make_ty(signature.type_ref()); | 1286 | self.return_ty = self.make_ty(data.type_ref()); |
1288 | } | 1287 | } |
1289 | 1288 | ||
1290 | fn collect_fn_signature(&mut self, signature: &FnSignature) { | 1289 | fn collect_fn(&mut self, data: &FnData) { |
1291 | let body = Arc::clone(&self.body); // avoid borrow checker problem | 1290 | let body = Arc::clone(&self.body); // avoid borrow checker problem |
1292 | for (type_ref, pat) in signature.params().iter().zip(body.params()) { | 1291 | for (type_ref, pat) in data.params().iter().zip(body.params()) { |
1293 | let ty = self.make_ty(type_ref); | 1292 | let ty = self.make_ty(type_ref); |
1294 | 1293 | ||
1295 | self.infer_pat(*pat, &ty, BindingMode::default()); | 1294 | self.infer_pat(*pat, &ty, BindingMode::default()); |
1296 | } | 1295 | } |
1297 | self.return_ty = self.make_ty(signature.ret_type()); | 1296 | self.return_ty = self.make_ty(data.ret_type()); |
1298 | } | 1297 | } |
1299 | 1298 | ||
1300 | fn infer_body(&mut self) { | 1299 | fn infer_body(&mut self) { |
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs index 300616a53..cb494baf4 100644 --- a/crates/ra_hir/src/ty/lower.rs +++ b/crates/ra_hir/src/ty/lower.rs | |||
@@ -353,11 +353,10 @@ pub(crate) fn generic_defaults(db: &impl HirDatabase, def: GenericDef) -> Substs | |||
353 | } | 353 | } |
354 | 354 | ||
355 | fn fn_sig_for_fn(db: &impl HirDatabase, def: Function) -> FnSig { | 355 | fn fn_sig_for_fn(db: &impl HirDatabase, def: Function) -> FnSig { |
356 | let signature = def.signature(db); | 356 | let data = def.data(db); |
357 | let resolver = def.resolver(db); | 357 | let resolver = def.resolver(db); |
358 | let params = | 358 | let params = data.params().iter().map(|tr| Ty::from_hir(db, &resolver, tr)).collect::<Vec<_>>(); |
359 | signature.params().iter().map(|tr| Ty::from_hir(db, &resolver, tr)).collect::<Vec<_>>(); | 359 | let ret = Ty::from_hir(db, &resolver, data.ret_type()); |
360 | let ret = Ty::from_hir(db, &resolver, signature.ret_type()); | ||
361 | FnSig::from_params_and_return(params, ret) | 360 | FnSig::from_params_and_return(params, ret) |
362 | } | 361 | } |
363 | 362 | ||
@@ -371,18 +370,18 @@ fn type_for_fn(db: &impl HirDatabase, def: Function) -> Ty { | |||
371 | 370 | ||
372 | /// Build the declared type of a const. | 371 | /// Build the declared type of a const. |
373 | fn type_for_const(db: &impl HirDatabase, def: Const) -> Ty { | 372 | fn type_for_const(db: &impl HirDatabase, def: Const) -> Ty { |
374 | let signature = def.signature(db); | 373 | let data = def.data(db); |
375 | let resolver = def.resolver(db); | 374 | let resolver = def.resolver(db); |
376 | 375 | ||
377 | Ty::from_hir(db, &resolver, signature.type_ref()) | 376 | Ty::from_hir(db, &resolver, data.type_ref()) |
378 | } | 377 | } |
379 | 378 | ||
380 | /// Build the declared type of a static. | 379 | /// Build the declared type of a static. |
381 | fn type_for_static(db: &impl HirDatabase, def: Static) -> Ty { | 380 | fn type_for_static(db: &impl HirDatabase, def: Static) -> Ty { |
382 | let signature = def.signature(db); | 381 | let data = def.data(db); |
383 | let resolver = def.resolver(db); | 382 | let resolver = def.resolver(db); |
384 | 383 | ||
385 | Ty::from_hir(db, &resolver, signature.type_ref()) | 384 | Ty::from_hir(db, &resolver, data.type_ref()) |
386 | } | 385 | } |
387 | 386 | ||
388 | /// Build the declared type of a static. | 387 | /// Build the declared type of a static. |
diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs index ad26d591c..46ec136bd 100644 --- a/crates/ra_hir/src/ty/method_resolution.rs +++ b/crates/ra_hir/src/ty/method_resolution.rs | |||
@@ -192,8 +192,8 @@ fn iterate_trait_method_candidates<T>( | |||
192 | let mut known_implemented = false; | 192 | let mut known_implemented = false; |
193 | for item in data.items() { | 193 | for item in data.items() { |
194 | if let TraitItem::Function(m) = *item { | 194 | if let TraitItem::Function(m) = *item { |
195 | let sig = m.signature(db); | 195 | let data = m.data(db); |
196 | if name.map_or(true, |name| sig.name() == name) && sig.has_self_param() { | 196 | if name.map_or(true, |name| data.name() == name) && data.has_self_param() { |
197 | if !known_implemented { | 197 | if !known_implemented { |
198 | let trait_ref = canonical_trait_ref(db, t, ty.clone()); | 198 | let trait_ref = canonical_trait_ref(db, t, ty.clone()); |
199 | if db.implements(krate, trait_ref).is_none() { | 199 | if db.implements(krate, trait_ref).is_none() { |
@@ -227,8 +227,8 @@ fn iterate_inherent_methods<T>( | |||
227 | for impl_block in impls.lookup_impl_blocks(&ty.value) { | 227 | for impl_block in impls.lookup_impl_blocks(&ty.value) { |
228 | for item in impl_block.items(db) { | 228 | for item in impl_block.items(db) { |
229 | if let ImplItem::Method(f) = item { | 229 | if let ImplItem::Method(f) = item { |
230 | let sig = f.signature(db); | 230 | let data = f.data(db); |
231 | if name.map_or(true, |name| sig.name() == name) && sig.has_self_param() { | 231 | if name.map_or(true, |name| data.name() == name) && data.has_self_param() { |
232 | if let Some(result) = callback(&ty.value, f) { | 232 | if let Some(result) = callback(&ty.value, f) { |
233 | return Some(result); | 233 | return Some(result); |
234 | } | 234 | } |
diff --git a/crates/ra_ide_api/src/call_info.rs b/crates/ra_ide_api/src/call_info.rs index bd08e183d..2948c646b 100644 --- a/crates/ra_ide_api/src/call_info.rs +++ b/crates/ra_ide_api/src/call_info.rs | |||
@@ -35,7 +35,7 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<Cal | |||
35 | 35 | ||
36 | // If we have a calling expression let's find which argument we are on | 36 | // If we have a calling expression let's find which argument we are on |
37 | let num_params = call_info.parameters().len(); | 37 | let num_params = call_info.parameters().len(); |
38 | let has_self = function.signature(db).has_self_param(); | 38 | let has_self = function.data(db).has_self_param(); |
39 | 39 | ||
40 | if num_params == 1 { | 40 | if num_params == 1 { |
41 | if !has_self { | 41 | if !has_self { |
diff --git a/crates/ra_ide_api/src/change.rs b/crates/ra_ide_api/src/change.rs index ce03a0f95..8d9918d16 100644 --- a/crates/ra_ide_api/src/change.rs +++ b/crates/ra_ide_api/src/change.rs | |||
@@ -163,7 +163,8 @@ impl RootDatabase { | |||
163 | if !change.new_roots.is_empty() { | 163 | if !change.new_roots.is_empty() { |
164 | let mut local_roots = Vec::clone(&self.local_roots()); | 164 | let mut local_roots = Vec::clone(&self.local_roots()); |
165 | for (root_id, is_local) in change.new_roots { | 165 | for (root_id, is_local) in change.new_roots { |
166 | self.set_source_root(root_id, Default::default()); | 166 | let root = if is_local { SourceRoot::new() } else { SourceRoot::new_library() }; |
167 | self.set_source_root(root_id, Arc::new(root)); | ||
167 | if is_local { | 168 | if is_local { |
168 | local_roots.push(root_id); | 169 | local_roots.push(root_id); |
169 | } | 170 | } |
@@ -226,9 +227,12 @@ impl RootDatabase { | |||
226 | 227 | ||
227 | self.query(ra_db::ParseQuery).sweep(sweep); | 228 | self.query(ra_db::ParseQuery).sweep(sweep); |
228 | self.query(hir::db::ParseMacroQuery).sweep(sweep); | 229 | self.query(hir::db::ParseMacroQuery).sweep(sweep); |
229 | self.query(hir::db::MacroDefQuery).sweep(sweep); | 230 | |
230 | self.query(hir::db::MacroArgQuery).sweep(sweep); | 231 | // Macros do take significant space, but less then the syntax trees |
231 | self.query(hir::db::MacroExpandQuery).sweep(sweep); | 232 | // self.query(hir::db::MacroDefQuery).sweep(sweep); |
233 | // self.query(hir::db::MacroArgQuery).sweep(sweep); | ||
234 | // self.query(hir::db::MacroExpandQuery).sweep(sweep); | ||
235 | |||
232 | self.query(hir::db::AstIdMapQuery).sweep(sweep); | 236 | self.query(hir::db::AstIdMapQuery).sweep(sweep); |
233 | 237 | ||
234 | self.query(hir::db::RawItemsWithSourceMapQuery).sweep(sweep); | 238 | self.query(hir::db::RawItemsWithSourceMapQuery).sweep(sweep); |
diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index f26fd06b3..40bd1e75e 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs | |||
@@ -37,8 +37,8 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) | |||
37 | 37 | ||
38 | fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) { | 38 | fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) { |
39 | ctx.analyzer.iterate_method_candidates(ctx.db, receiver, None, |_ty, func| { | 39 | ctx.analyzer.iterate_method_candidates(ctx.db, receiver, None, |_ty, func| { |
40 | let sig = func.signature(ctx.db); | 40 | let data = func.data(ctx.db); |
41 | if sig.has_self_param() { | 41 | if data.has_self_param() { |
42 | acc.add_function(ctx, func); | 42 | acc.add_function(ctx, func); |
43 | } | 43 | } |
44 | None::<()> | 44 | None::<()> |
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index 99da24142..c14af593b 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs | |||
@@ -49,8 +49,8 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { | |||
49 | ty.iterate_impl_items(ctx.db, krate, |item| { | 49 | ty.iterate_impl_items(ctx.db, krate, |item| { |
50 | match item { | 50 | match item { |
51 | hir::ImplItem::Method(func) => { | 51 | hir::ImplItem::Method(func) => { |
52 | let sig = func.signature(ctx.db); | 52 | let data = func.data(ctx.db); |
53 | if !sig.has_self_param() { | 53 | if !data.has_self_param() { |
54 | acc.add_function(ctx, func); | 54 | acc.add_function(ctx, func); |
55 | } | 55 | } |
56 | } | 56 | } |
diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index f4ff4404b..973936736 100644 --- a/crates/ra_ide_api/src/completion/presentation.rs +++ b/crates/ra_ide_api/src/completion/presentation.rs | |||
@@ -98,13 +98,13 @@ impl Completions { | |||
98 | name: Option<String>, | 98 | name: Option<String>, |
99 | func: hir::Function, | 99 | func: hir::Function, |
100 | ) { | 100 | ) { |
101 | let sig = func.signature(ctx.db); | 101 | let data = func.data(ctx.db); |
102 | let name = name.unwrap_or_else(|| sig.name().to_string()); | 102 | let name = name.unwrap_or_else(|| data.name().to_string()); |
103 | let ast_node = func.source(ctx.db).ast; | 103 | let ast_node = func.source(ctx.db).ast; |
104 | let detail = function_label(&ast_node); | 104 | let detail = function_label(&ast_node); |
105 | 105 | ||
106 | let mut builder = CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name) | 106 | let mut builder = CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name) |
107 | .kind(if sig.has_self_param() { | 107 | .kind(if data.has_self_param() { |
108 | CompletionItemKind::Method | 108 | CompletionItemKind::Method |
109 | } else { | 109 | } else { |
110 | CompletionItemKind::Function | 110 | CompletionItemKind::Function |
@@ -115,10 +115,10 @@ impl Completions { | |||
115 | if ctx.use_item_syntax.is_none() && !ctx.is_call { | 115 | if ctx.use_item_syntax.is_none() && !ctx.is_call { |
116 | tested_by!(inserts_parens_for_function_calls); | 116 | tested_by!(inserts_parens_for_function_calls); |
117 | let snippet = | 117 | let snippet = |
118 | if sig.params().is_empty() || sig.has_self_param() && sig.params().len() == 1 { | 118 | if data.params().is_empty() || data.has_self_param() && data.params().len() == 1 { |
119 | format!("{}()$0", sig.name()) | 119 | format!("{}()$0", data.name()) |
120 | } else { | 120 | } else { |
121 | format!("{}($0)", sig.name()) | 121 | format!("{}($0)", data.name()) |
122 | }; | 122 | }; |
123 | builder = builder.insert_snippet(snippet); | 123 | builder = builder.insert_snippet(snippet); |
124 | } | 124 | } |
diff --git a/crates/ra_lsp_server/Cargo.toml b/crates/ra_lsp_server/Cargo.toml index 142467cc9..a1fcf6cee 100644 --- a/crates/ra_lsp_server/Cargo.toml +++ b/crates/ra_lsp_server/Cargo.toml | |||
@@ -10,7 +10,7 @@ relative-path = "0.4.0" | |||
10 | serde_json = "1.0.34" | 10 | serde_json = "1.0.34" |
11 | serde = { version = "1.0.83", features = ["derive"] } | 11 | serde = { version = "1.0.83", features = ["derive"] } |
12 | crossbeam-channel = "0.3.5" | 12 | crossbeam-channel = "0.3.5" |
13 | flexi_logger = "0.11.0" | 13 | flexi_logger = "0.13.0" |
14 | log = "0.4.3" | 14 | log = "0.4.3" |
15 | url_serde = "0.2.0" | 15 | url_serde = "0.2.0" |
16 | lsp-types = { version = "0.57.1", features = ["proposed"] } | 16 | lsp-types = { version = "0.57.1", features = ["proposed"] } |
diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs index 725fb99f6..41be283d0 100644 --- a/crates/ra_parser/src/grammar/expressions/atom.rs +++ b/crates/ra_parser/src/grammar/expressions/atom.rs | |||
@@ -74,6 +74,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar | |||
74 | T![if] => if_expr(p), | 74 | T![if] => if_expr(p), |
75 | 75 | ||
76 | T![loop] => loop_expr(p, None), | 76 | T![loop] => loop_expr(p, None), |
77 | T![box] => box_expr(p, None), | ||
77 | T![for] => for_expr(p, None), | 78 | T![for] => for_expr(p, None), |
78 | T![while] => while_expr(p, None), | 79 | T![while] => while_expr(p, None), |
79 | T![try] => try_block_expr(p, None), | 80 | T![try] => try_block_expr(p, None), |
@@ -507,3 +508,17 @@ fn try_block_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker { | |||
507 | block(p); | 508 | block(p); |
508 | m.complete(p, TRY_EXPR) | 509 | m.complete(p, TRY_EXPR) |
509 | } | 510 | } |
511 | |||
512 | // test box_expr | ||
513 | // fn foo() { | ||
514 | // let x = box 1i32; | ||
515 | // } | ||
516 | fn box_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker { | ||
517 | assert!(p.at(T![box])); | ||
518 | let m = m.unwrap_or_else(|| p.start()); | ||
519 | p.bump(); | ||
520 | if p.at_ts(EXPR_FIRST) { | ||
521 | expr(p); | ||
522 | } | ||
523 | m.complete(p, BOX_EXPR) | ||
524 | } | ||
diff --git a/crates/ra_parser/src/grammar/patterns.rs b/crates/ra_parser/src/grammar/patterns.rs index 16ae9da63..46034942a 100644 --- a/crates/ra_parser/src/grammar/patterns.rs +++ b/crates/ra_parser/src/grammar/patterns.rs | |||
@@ -60,6 +60,7 @@ fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> { | |||
60 | let la1 = p.nth(1); | 60 | let la1 = p.nth(1); |
61 | if la0 == T![ref] | 61 | if la0 == T![ref] |
62 | || la0 == T![mut] | 62 | || la0 == T![mut] |
63 | || la0 == T![box] | ||
63 | || (la0 == IDENT && !(la1 == T![::] || la1 == T!['('] || la1 == T!['{'] || la1 == T![!])) | 64 | || (la0 == IDENT && !(la1 == T![::] || la1 == T!['('] || la1 == T!['{'] || la1 == T![!])) |
64 | { | 65 | { |
65 | return Some(bind_pat(p, true)); | 66 | return Some(bind_pat(p, true)); |
@@ -260,9 +261,11 @@ fn pat_list(p: &mut Parser, ket: SyntaxKind) { | |||
260 | // let ref mut d = (); | 261 | // let ref mut d = (); |
261 | // let e @ _ = (); | 262 | // let e @ _ = (); |
262 | // let ref mut f @ g @ _ = (); | 263 | // let ref mut f @ g @ _ = (); |
264 | // let box i = Box::new(1i32); | ||
263 | // } | 265 | // } |
264 | fn bind_pat(p: &mut Parser, with_at: bool) -> CompletedMarker { | 266 | fn bind_pat(p: &mut Parser, with_at: bool) -> CompletedMarker { |
265 | let m = p.start(); | 267 | let m = p.start(); |
268 | p.eat(T![box]); | ||
266 | p.eat(T![ref]); | 269 | p.eat(T![ref]); |
267 | p.eat(T![mut]); | 270 | p.eat(T![mut]); |
268 | name(p); | 271 | name(p); |
diff --git a/crates/ra_parser/src/syntax_kind/generated.rs b/crates/ra_parser/src/syntax_kind/generated.rs index 036415eac..374fd5aec 100644 --- a/crates/ra_parser/src/syntax_kind/generated.rs +++ b/crates/ra_parser/src/syntax_kind/generated.rs | |||
@@ -104,6 +104,7 @@ pub enum SyntaxKind { | |||
104 | MOVE_KW, | 104 | MOVE_KW, |
105 | RETURN_KW, | 105 | RETURN_KW, |
106 | TRY_KW, | 106 | TRY_KW, |
107 | BOX_KW, | ||
107 | AUTO_KW, | 108 | AUTO_KW, |
108 | DEFAULT_KW, | 109 | DEFAULT_KW, |
109 | EXISTENTIAL_KW, | 110 | EXISTENTIAL_KW, |
@@ -187,6 +188,7 @@ pub enum SyntaxKind { | |||
187 | NAMED_FIELD_LIST, | 188 | NAMED_FIELD_LIST, |
188 | NAMED_FIELD, | 189 | NAMED_FIELD, |
189 | TRY_BLOCK_EXPR, | 190 | TRY_BLOCK_EXPR, |
191 | BOX_EXPR, | ||
190 | CALL_EXPR, | 192 | CALL_EXPR, |
191 | INDEX_EXPR, | 193 | INDEX_EXPR, |
192 | METHOD_CALL_EXPR, | 194 | METHOD_CALL_EXPR, |
@@ -335,6 +337,7 @@ macro_rules! T { | |||
335 | (move) => { $crate::SyntaxKind::MOVE_KW }; | 337 | (move) => { $crate::SyntaxKind::MOVE_KW }; |
336 | (return) => { $crate::SyntaxKind::RETURN_KW }; | 338 | (return) => { $crate::SyntaxKind::RETURN_KW }; |
337 | (try) => { $crate::SyntaxKind::TRY_KW }; | 339 | (try) => { $crate::SyntaxKind::TRY_KW }; |
340 | (box) => { $crate::SyntaxKind::BOX_KW }; | ||
338 | (auto) => { $crate::SyntaxKind::AUTO_KW }; | 341 | (auto) => { $crate::SyntaxKind::AUTO_KW }; |
339 | (default) => { $crate::SyntaxKind::DEFAULT_KW }; | 342 | (default) => { $crate::SyntaxKind::DEFAULT_KW }; |
340 | (existential) => { $crate::SyntaxKind::EXISTENTIAL_KW }; | 343 | (existential) => { $crate::SyntaxKind::EXISTENTIAL_KW }; |
@@ -394,6 +397,7 @@ impl SyntaxKind { | |||
394 | | MOVE_KW | 397 | | MOVE_KW |
395 | | RETURN_KW | 398 | | RETURN_KW |
396 | | TRY_KW | 399 | | TRY_KW |
400 | | BOX_KW | ||
397 | | AUTO_KW | 401 | | AUTO_KW |
398 | | DEFAULT_KW | 402 | | DEFAULT_KW |
399 | | EXISTENTIAL_KW | 403 | | EXISTENTIAL_KW |
@@ -567,6 +571,7 @@ impl SyntaxKind { | |||
567 | MOVE_KW => &SyntaxInfo { name: "MOVE_KW" }, | 571 | MOVE_KW => &SyntaxInfo { name: "MOVE_KW" }, |
568 | RETURN_KW => &SyntaxInfo { name: "RETURN_KW" }, | 572 | RETURN_KW => &SyntaxInfo { name: "RETURN_KW" }, |
569 | TRY_KW => &SyntaxInfo { name: "TRY_KW" }, | 573 | TRY_KW => &SyntaxInfo { name: "TRY_KW" }, |
574 | BOX_KW => &SyntaxInfo { name: "BOX_KW" }, | ||
570 | AUTO_KW => &SyntaxInfo { name: "AUTO_KW" }, | 575 | AUTO_KW => &SyntaxInfo { name: "AUTO_KW" }, |
571 | DEFAULT_KW => &SyntaxInfo { name: "DEFAULT_KW" }, | 576 | DEFAULT_KW => &SyntaxInfo { name: "DEFAULT_KW" }, |
572 | EXISTENTIAL_KW => &SyntaxInfo { name: "EXISTENTIAL_KW" }, | 577 | EXISTENTIAL_KW => &SyntaxInfo { name: "EXISTENTIAL_KW" }, |
@@ -650,6 +655,7 @@ impl SyntaxKind { | |||
650 | NAMED_FIELD_LIST => &SyntaxInfo { name: "NAMED_FIELD_LIST" }, | 655 | NAMED_FIELD_LIST => &SyntaxInfo { name: "NAMED_FIELD_LIST" }, |
651 | NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" }, | 656 | NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" }, |
652 | TRY_BLOCK_EXPR => &SyntaxInfo { name: "TRY_BLOCK_EXPR" }, | 657 | TRY_BLOCK_EXPR => &SyntaxInfo { name: "TRY_BLOCK_EXPR" }, |
658 | BOX_EXPR => &SyntaxInfo { name: "BOX_EXPR" }, | ||
653 | CALL_EXPR => &SyntaxInfo { name: "CALL_EXPR" }, | 659 | CALL_EXPR => &SyntaxInfo { name: "CALL_EXPR" }, |
654 | INDEX_EXPR => &SyntaxInfo { name: "INDEX_EXPR" }, | 660 | INDEX_EXPR => &SyntaxInfo { name: "INDEX_EXPR" }, |
655 | METHOD_CALL_EXPR => &SyntaxInfo { name: "METHOD_CALL_EXPR" }, | 661 | METHOD_CALL_EXPR => &SyntaxInfo { name: "METHOD_CALL_EXPR" }, |
@@ -745,6 +751,7 @@ impl SyntaxKind { | |||
745 | "move" => MOVE_KW, | 751 | "move" => MOVE_KW, |
746 | "return" => RETURN_KW, | 752 | "return" => RETURN_KW, |
747 | "try" => TRY_KW, | 753 | "try" => TRY_KW, |
754 | "box" => BOX_KW, | ||
748 | _ => return None, | 755 | _ => return None, |
749 | }; | 756 | }; |
750 | Some(kw) | 757 | Some(kw) |
diff --git a/crates/ra_project_model/Cargo.toml b/crates/ra_project_model/Cargo.toml index c1a91d950..a1f7bf6dc 100644 --- a/crates/ra_project_model/Cargo.toml +++ b/crates/ra_project_model/Cargo.toml | |||
@@ -11,7 +11,7 @@ relative-path = "0.4.0" | |||
11 | 11 | ||
12 | walkdir = "2.2.7" | 12 | walkdir = "2.2.7" |
13 | 13 | ||
14 | cargo_metadata = "0.7.0" | 14 | cargo_metadata = "0.8.0" |
15 | 15 | ||
16 | ra_arena = { path = "../ra_arena" } | 16 | ra_arena = { path = "../ra_arena" } |
17 | ra_db = { path = "../ra_db" } | 17 | ra_db = { path = "../ra_db" } |
diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron index eab55058b..6c075a700 100644 --- a/crates/ra_syntax/src/grammar.ron +++ b/crates/ra_syntax/src/grammar.ron | |||
@@ -96,6 +96,7 @@ Grammar( | |||
96 | "move", | 96 | "move", |
97 | "return", | 97 | "return", |
98 | "try", | 98 | "try", |
99 | "box", | ||
99 | ], | 100 | ], |
100 | contextual_keywords: [ | 101 | contextual_keywords: [ |
101 | "auto", | 102 | "auto", |
@@ -192,6 +193,7 @@ Grammar( | |||
192 | "NAMED_FIELD_LIST", | 193 | "NAMED_FIELD_LIST", |
193 | "NAMED_FIELD", | 194 | "NAMED_FIELD", |
194 | "TRY_BLOCK_EXPR", | 195 | "TRY_BLOCK_EXPR", |
196 | "BOX_EXPR", | ||
195 | 197 | ||
196 | // postfix | 198 | // postfix |
197 | "CALL_EXPR", | 199 | "CALL_EXPR", |
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0112_bind_pat.rs b/crates/ra_syntax/tests/data/parser/inline/ok/0112_bind_pat.rs index 820a9e72c..5a93469af 100644 --- a/crates/ra_syntax/tests/data/parser/inline/ok/0112_bind_pat.rs +++ b/crates/ra_syntax/tests/data/parser/inline/ok/0112_bind_pat.rs | |||
@@ -5,4 +5,5 @@ fn main() { | |||
5 | let ref mut d = (); | 5 | let ref mut d = (); |
6 | let e @ _ = (); | 6 | let e @ _ = (); |
7 | let ref mut f @ g @ _ = (); | 7 | let ref mut f @ g @ _ = (); |
8 | let box i = Box::new(1i32); | ||
8 | } | 9 | } |
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0112_bind_pat.txt b/crates/ra_syntax/tests/data/parser/inline/ok/0112_bind_pat.txt index ab0f88507..189254a19 100644 --- a/crates/ra_syntax/tests/data/parser/inline/ok/0112_bind_pat.txt +++ b/crates/ra_syntax/tests/data/parser/inline/ok/0112_bind_pat.txt | |||
@@ -1,5 +1,5 @@ | |||
1 | SOURCE_FILE@[0; 146) | 1 | SOURCE_FILE@[0; 178) |
2 | FN_DEF@[0; 145) | 2 | FN_DEF@[0; 177) |
3 | FN_KW@[0; 2) "fn" | 3 | FN_KW@[0; 2) "fn" |
4 | WHITESPACE@[2; 3) " " | 4 | WHITESPACE@[2; 3) " " |
5 | NAME@[3; 7) | 5 | NAME@[3; 7) |
@@ -8,7 +8,7 @@ SOURCE_FILE@[0; 146) | |||
8 | L_PAREN@[7; 8) "(" | 8 | L_PAREN@[7; 8) "(" |
9 | R_PAREN@[8; 9) ")" | 9 | R_PAREN@[8; 9) ")" |
10 | WHITESPACE@[9; 10) " " | 10 | WHITESPACE@[9; 10) " " |
11 | BLOCK@[10; 145) | 11 | BLOCK@[10; 177) |
12 | L_CURLY@[10; 11) "{" | 12 | L_CURLY@[10; 11) "{" |
13 | WHITESPACE@[11; 16) "\n " | 13 | WHITESPACE@[11; 16) "\n " |
14 | LET_STMT@[16; 27) | 14 | LET_STMT@[16; 27) |
@@ -122,6 +122,35 @@ SOURCE_FILE@[0; 146) | |||
122 | L_PAREN@[140; 141) "(" | 122 | L_PAREN@[140; 141) "(" |
123 | R_PAREN@[141; 142) ")" | 123 | R_PAREN@[141; 142) ")" |
124 | SEMI@[142; 143) ";" | 124 | SEMI@[142; 143) ";" |
125 | WHITESPACE@[143; 144) "\n" | 125 | WHITESPACE@[143; 148) "\n " |
126 | R_CURLY@[144; 145) "}" | 126 | LET_STMT@[148; 175) |
127 | WHITESPACE@[145; 146) "\n" | 127 | LET_KW@[148; 151) "let" |
128 | WHITESPACE@[151; 152) " " | ||
129 | BIND_PAT@[152; 157) | ||
130 | BOX_KW@[152; 155) "box" | ||
131 | WHITESPACE@[155; 156) " " | ||
132 | NAME@[156; 157) | ||
133 | IDENT@[156; 157) "i" | ||
134 | WHITESPACE@[157; 158) " " | ||
135 | EQ@[158; 159) "=" | ||
136 | WHITESPACE@[159; 160) " " | ||
137 | CALL_EXPR@[160; 174) | ||
138 | PATH_EXPR@[160; 168) | ||
139 | PATH@[160; 168) | ||
140 | PATH@[160; 163) | ||
141 | PATH_SEGMENT@[160; 163) | ||
142 | NAME_REF@[160; 163) | ||
143 | IDENT@[160; 163) "Box" | ||
144 | COLONCOLON@[163; 165) "::" | ||
145 | PATH_SEGMENT@[165; 168) | ||
146 | NAME_REF@[165; 168) | ||
147 | IDENT@[165; 168) "new" | ||
148 | ARG_LIST@[168; 174) | ||
149 | L_PAREN@[168; 169) "(" | ||
150 | LITERAL@[169; 173) | ||
151 | INT_NUMBER@[169; 173) "1i32" | ||
152 | R_PAREN@[173; 174) ")" | ||
153 | SEMI@[174; 175) ";" | ||
154 | WHITESPACE@[175; 176) "\n" | ||
155 | R_CURLY@[176; 177) "}" | ||
156 | WHITESPACE@[177; 178) "\n" | ||
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0132_box_expr.rs b/crates/ra_syntax/tests/data/parser/inline/ok/0132_box_expr.rs new file mode 100644 index 000000000..e69c81e22 --- /dev/null +++ b/crates/ra_syntax/tests/data/parser/inline/ok/0132_box_expr.rs | |||
@@ -0,0 +1,3 @@ | |||
1 | fn foo() { | ||
2 | let x = box 1i32; | ||
3 | } | ||
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0132_box_expr.txt b/crates/ra_syntax/tests/data/parser/inline/ok/0132_box_expr.txt new file mode 100644 index 000000000..f4eeb7e24 --- /dev/null +++ b/crates/ra_syntax/tests/data/parser/inline/ok/0132_box_expr.txt | |||
@@ -0,0 +1,31 @@ | |||
1 | SOURCE_FILE@[0; 35) | ||
2 | FN_DEF@[0; 34) | ||
3 | FN_KW@[0; 2) "fn" | ||
4 | WHITESPACE@[2; 3) " " | ||
5 | NAME@[3; 6) | ||
6 | IDENT@[3; 6) "foo" | ||
7 | PARAM_LIST@[6; 8) | ||
8 | L_PAREN@[6; 7) "(" | ||
9 | R_PAREN@[7; 8) ")" | ||
10 | WHITESPACE@[8; 9) " " | ||
11 | BLOCK@[9; 34) | ||
12 | L_CURLY@[9; 10) "{" | ||
13 | WHITESPACE@[10; 15) "\n " | ||
14 | LET_STMT@[15; 32) | ||
15 | LET_KW@[15; 18) "let" | ||
16 | WHITESPACE@[18; 19) " " | ||
17 | BIND_PAT@[19; 20) | ||
18 | NAME@[19; 20) | ||
19 | IDENT@[19; 20) "x" | ||
20 | WHITESPACE@[20; 21) " " | ||
21 | EQ@[21; 22) "=" | ||
22 | WHITESPACE@[22; 23) " " | ||
23 | BOX_EXPR@[23; 31) | ||
24 | BOX_KW@[23; 26) "box" | ||
25 | WHITESPACE@[26; 27) " " | ||
26 | LITERAL@[27; 31) | ||
27 | INT_NUMBER@[27; 31) "1i32" | ||
28 | SEMI@[31; 32) ";" | ||
29 | WHITESPACE@[32; 33) "\n" | ||
30 | R_CURLY@[33; 34) "}" | ||
31 | WHITESPACE@[34; 35) "\n" | ||