aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/ci.yaml18
-rw-r--r--Cargo.lock4
-rw-r--r--crates/expect/src/lib.rs2
-rw-r--r--crates/ra_assists/src/handlers/add_custom_impl.rs4
-rw-r--r--crates/ra_assists/src/handlers/apply_demorgan.rs2
-rw-r--r--crates/ra_assists/src/handlers/generate_impl.rs5
-rw-r--r--crates/ra_assists/src/handlers/generate_new.rs9
-rw-r--r--crates/ra_hir/src/code_model.rs18
-rw-r--r--crates/ra_hir/src/lib.rs2
-rw-r--r--crates/ra_hir/src/semantics.rs99
-rw-r--r--crates/ra_hir/src/source_analyzer.rs7
-rw-r--r--crates/ra_hir_def/src/adt.rs42
-rw-r--r--crates/ra_ide/src/completion/complete_snippet.rs8
-rw-r--r--crates/ra_ide/src/completion/presentation.rs31
-rw-r--r--crates/ra_ide/src/syntax_highlighting.rs89
-rw-r--r--crates/ra_ide/src/syntax_highlighting/injection.rs5
-rw-r--r--crates/ra_ide/src/syntax_highlighting/tests.rs33
-rw-r--r--crates/ra_ide/test_data/highlight_unsafe.html33
-rw-r--r--crates/ra_mbe/src/mbe_expander/matcher.rs2
-rw-r--r--crates/ra_parser/src/grammar.rs2
-rw-r--r--crates/ra_parser/src/grammar/expressions.rs3
-rw-r--r--crates/ra_parser/src/grammar/items.rs112
-rw-r--r--crates/ra_parser/src/grammar/items/traits.rs4
-rw-r--r--crates/ra_parser/src/parser.rs16
-rw-r--r--crates/ra_proc_macro/src/process.rs2
-rw-r--r--crates/ra_prof/src/memory_usage.rs2
-rw-r--r--crates/ra_syntax/src/ast/traits.rs5
-rw-r--r--crates/ra_syntax/test_data/parser/err/0043_default_const.rast40
-rw-r--r--crates/ra_syntax/test_data/parser/err/0043_default_const.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/err/0043_weird_blocks.rast (renamed from crates/ra_syntax/test_data/parser/err/0163_weird_blocks.rast)0
-rw-r--r--crates/ra_syntax/test_data/parser/err/0043_weird_blocks.rs (renamed from crates/ra_syntax/test_data/parser/err/0163_weird_blocks.rs)0
-rw-r--r--crates/ra_syntax/test_data/parser/err/0045_item_modifiers.rast (renamed from crates/ra_syntax/test_data/parser/inline/err/0010_wrong_order_fns.rast)0
-rw-r--r--crates/ra_syntax/test_data/parser/err/0045_item_modifiers.rs (renamed from crates/ra_syntax/test_data/parser/inline/err/0010_wrong_order_fns.rs)0
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0014_default_fn_type.rast58
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0014_default_fn_type.rs4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0016_unsafe_trait.rast13
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0016_unsafe_trait.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0036_unsafe_extern_fn.rast21
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0036_unsafe_extern_fn.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0047_unsafe_default_impl.rast18
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0047_unsafe_default_impl.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0057_const_fn.rast16
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0057_const_fn.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0087_unsafe_impl.rast16
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0087_unsafe_impl.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0089_extern_fn.rast17
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0089_extern_fn.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0091_auto_trait.rast13
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0091_auto_trait.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0094_unsafe_auto_trait.rast15
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0094_unsafe_auto_trait.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0097_default_impl.rast16
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0097_default_impl.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0098_const_unsafe_fn.rast18
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0098_const_unsafe_fn.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0101_unsafe_fn.rast16
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0101_unsafe_fn.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0124_async_fn.rast16
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0124_async_fn.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0128_combined_fns.rast35
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0128_combined_fns.rs2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0132_default_fn_type.rast55
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0132_default_fn_type.rs4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0151_fn.rast14
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0151_fn.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0152_impl.rast22
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0152_impl.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0153_trait.rast11
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0153_trait.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0163_default_unsafe_fn.rast40
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0163_default_unsafe_impl.rast18
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0163_default_unsafe_impl.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0163_default_unsafe_item.rast44
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0163_default_unsafe_item.rs (renamed from crates/ra_syntax/test_data/parser/inline/ok/0163_default_unsafe_fn.rs)2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0164_default_item.rast24
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0164_default_item.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0021_extern_fn.rast56
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0021_extern_fn.rs8
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0066_default_const.rast44
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0066_default_const.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0066_default_modifier.rast218
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0066_default_modifier.rs16
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0068_item_modifiers.rast218
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0068_item_modifiers.rs16
-rw-r--r--crates/ra_text_edit/src/lib.rs13
-rw-r--r--crates/ra_tt/src/lib.rs2
-rw-r--r--crates/stdx/src/lib.rs65
-rw-r--r--xtask/tests/tidy.rs15
88 files changed, 992 insertions, 829 deletions
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index 2acd44012..f977c88be 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -88,11 +88,14 @@ jobs:
88 if: matrix.os == 'windows-latest' 88 if: matrix.os == 'windows-latest'
89 run: Remove-Item ./target/debug/xtask.exe, ./target/debug/deps/xtask.exe 89 run: Remove-Item ./target/debug/xtask.exe, ./target/debug/deps/xtask.exe
90 90
91 # Weird target to catch non-portable code 91 # Weird targets to catch non-portable code
92 rust-power: 92 rust-cross:
93 name: Rust Power 93 name: Rust Cross
94 runs-on: ubuntu-latest 94 runs-on: ubuntu-latest
95 95
96 env:
97 targets: "powerpc-unknown-linux-gnu x86_64-unknown-linux-musl"
98
96 steps: 99 steps:
97 - name: Checkout repository 100 - name: Checkout repository
98 uses: actions/checkout@v2 101 uses: actions/checkout@v2
@@ -103,7 +106,9 @@ jobs:
103 toolchain: stable 106 toolchain: stable
104 profile: minimal 107 profile: minimal
105 override: true 108 override: true
106 target: 'powerpc-unknown-linux-gnu' 109
110 - name: Install Rust targets
111 run: rustup target add ${{ env.targets }}
107 112
108 - name: Cache cargo directories 113 - name: Cache cargo directories
109 uses: actions/cache@v2 114 uses: actions/cache@v2
@@ -114,7 +119,10 @@ jobs:
114 key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} 119 key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
115 120
116 - name: Check 121 - name: Check
117 run: cargo check --target=powerpc-unknown-linux-gnu --all-targets 122 run: |
123 for target in ${{ env.targets }}; do
124 cargo check --target=$target --all-targets
125 done
118 126
119 typescript: 127 typescript:
120 name: TypeScript 128 name: TypeScript
diff --git a/Cargo.lock b/Cargo.lock
index a094ec4f7..265889162 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -852,9 +852,9 @@ dependencies = [
852 852
853[[package]] 853[[package]]
854name = "perf-event-open-sys" 854name = "perf-event-open-sys"
855version = "0.3.1" 855version = "0.3.2"
856source = "registry+https://github.com/rust-lang/crates.io-index" 856source = "registry+https://github.com/rust-lang/crates.io-index"
857checksum = "95db63e37862bc1b842135d2234ef9418f222cc660c6752f45e7cf9ddfb97f96" 857checksum = "83e7183862f36d10263d0a1ccaef50fef734ade948bf026afd1bd97355c78273"
858dependencies = [ 858dependencies = [
859 "libc", 859 "libc",
860] 860]
diff --git a/crates/expect/src/lib.rs b/crates/expect/src/lib.rs
index 21a458d47..bd83895f7 100644
--- a/crates/expect/src/lib.rs
+++ b/crates/expect/src/lib.rs
@@ -74,7 +74,7 @@ impl fmt::Display for Position {
74impl Expect { 74impl Expect {
75 pub fn assert_eq(&self, actual: &str) { 75 pub fn assert_eq(&self, actual: &str) {
76 let trimmed = self.trimmed(); 76 let trimmed = self.trimmed();
77 if &trimmed == actual { 77 if trimmed == actual {
78 return; 78 return;
79 } 79 }
80 Runtime::fail_expect(self, &trimmed, actual); 80 Runtime::fail_expect(self, &trimmed, actual);
diff --git a/crates/ra_assists/src/handlers/add_custom_impl.rs b/crates/ra_assists/src/handlers/add_custom_impl.rs
index b67438b6b..ebdf00e67 100644
--- a/crates/ra_assists/src/handlers/add_custom_impl.rs
+++ b/crates/ra_assists/src/handlers/add_custom_impl.rs
@@ -1,10 +1,10 @@
1use itertools::Itertools;
1use ra_syntax::{ 2use ra_syntax::{
2 ast::{self, AstNode}, 3 ast::{self, AstNode},
3 Direction, SmolStr, 4 Direction, SmolStr,
4 SyntaxKind::{IDENT, WHITESPACE}, 5 SyntaxKind::{IDENT, WHITESPACE},
5 TextRange, TextSize, 6 TextRange, TextSize,
6}; 7};
7use stdx::SepBy;
8 8
9use crate::{ 9use crate::{
10 assist_context::{AssistContext, Assists}, 10 assist_context::{AssistContext, Assists},
@@ -61,9 +61,9 @@ pub(crate) fn add_custom_impl(acc: &mut Assists, ctx: &AssistContext) -> Option<
61 .filter(|t| t != trait_token.text()) 61 .filter(|t| t != trait_token.text())
62 .collect::<Vec<SmolStr>>(); 62 .collect::<Vec<SmolStr>>();
63 let has_more_derives = !new_attr_input.is_empty(); 63 let has_more_derives = !new_attr_input.is_empty();
64 let new_attr_input = new_attr_input.iter().sep_by(", ").surround_with("(", ")").to_string();
65 64
66 if has_more_derives { 65 if has_more_derives {
66 let new_attr_input = format!("({})", new_attr_input.iter().format(", "));
67 builder.replace(input.syntax().text_range(), new_attr_input); 67 builder.replace(input.syntax().text_range(), new_attr_input);
68 } else { 68 } else {
69 let attr_range = attr.syntax().text_range(); 69 let attr_range = attr.syntax().text_range();
diff --git a/crates/ra_assists/src/handlers/apply_demorgan.rs b/crates/ra_assists/src/handlers/apply_demorgan.rs
index de701f8b8..3ac4aed7d 100644
--- a/crates/ra_assists/src/handlers/apply_demorgan.rs
+++ b/crates/ra_assists/src/handlers/apply_demorgan.rs
@@ -4,7 +4,7 @@ use crate::{utils::invert_boolean_expression, AssistContext, AssistId, AssistKin
4 4
5// Assist: apply_demorgan 5// Assist: apply_demorgan
6// 6//
7// Apply [De Morgan's law](https://en.wikipedia.org/wiki/De_Morgan%27s_laws). 7// Apply https://en.wikipedia.org/wiki/De_Morgan%27s_laws[De Morgan's law].
8// This transforms expressions of the form `!l || !r` into `!(l && r)`. 8// This transforms expressions of the form `!l || !r` into `!(l && r)`.
9// This also works with `&&`. This assist can only be applied with the cursor 9// This also works with `&&`. This assist can only be applied with the cursor
10// on either `||` or `&&`, with both operands being a negation of some kind. 10// on either `||` or `&&`, with both operands being a negation of some kind.
diff --git a/crates/ra_assists/src/handlers/generate_impl.rs b/crates/ra_assists/src/handlers/generate_impl.rs
index d9b87c9c0..7162dc184 100644
--- a/crates/ra_assists/src/handlers/generate_impl.rs
+++ b/crates/ra_assists/src/handlers/generate_impl.rs
@@ -1,5 +1,6 @@
1use itertools::Itertools;
1use ra_syntax::ast::{self, AstNode, GenericParamsOwner, NameOwner}; 2use ra_syntax::ast::{self, AstNode, GenericParamsOwner, NameOwner};
2use stdx::{format_to, SepBy}; 3use stdx::format_to;
3 4
4use crate::{AssistContext, AssistId, AssistKind, Assists}; 5use crate::{AssistContext, AssistId, AssistKind, Assists};
5 6
@@ -50,7 +51,7 @@ pub(crate) fn generate_impl(acc: &mut Assists, ctx: &AssistContext) -> Option<()
50 .filter_map(|it| it.name()) 51 .filter_map(|it| it.name())
51 .map(|it| it.text().clone()); 52 .map(|it| it.text().clone());
52 53
53 let generic_params = lifetime_params.chain(type_params).sep_by(", "); 54 let generic_params = lifetime_params.chain(type_params).format(", ");
54 format_to!(buf, "<{}>", generic_params) 55 format_to!(buf, "<{}>", generic_params)
55 } 56 }
56 match ctx.config.snippet_cap { 57 match ctx.config.snippet_cap {
diff --git a/crates/ra_assists/src/handlers/generate_new.rs b/crates/ra_assists/src/handlers/generate_new.rs
index b84aa24b6..32dfed274 100644
--- a/crates/ra_assists/src/handlers/generate_new.rs
+++ b/crates/ra_assists/src/handlers/generate_new.rs
@@ -1,9 +1,10 @@
1use hir::Adt; 1use hir::Adt;
2use itertools::Itertools;
2use ra_syntax::{ 3use ra_syntax::{
3 ast::{self, AstNode, GenericParamsOwner, NameOwner, StructKind, VisibilityOwner}, 4 ast::{self, AstNode, GenericParamsOwner, NameOwner, StructKind, VisibilityOwner},
4 T, 5 T,
5}; 6};
6use stdx::{format_to, SepBy}; 7use stdx::format_to;
7 8
8use crate::{AssistContext, AssistId, AssistKind, Assists}; 9use crate::{AssistContext, AssistId, AssistKind, Assists};
9 10
@@ -52,8 +53,8 @@ pub(crate) fn generate_new(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
52 let params = field_list 53 let params = field_list
53 .fields() 54 .fields()
54 .filter_map(|f| Some(format!("{}: {}", f.name()?.syntax(), f.ty()?.syntax()))) 55 .filter_map(|f| Some(format!("{}: {}", f.name()?.syntax(), f.ty()?.syntax())))
55 .sep_by(", "); 56 .format(", ");
56 let fields = field_list.fields().filter_map(|f| f.name()).sep_by(", "); 57 let fields = field_list.fields().filter_map(|f| f.name()).format(", ");
57 58
58 format_to!(buf, " {}fn new({}) -> Self {{ Self {{ {} }} }}", vis, params, fields); 59 format_to!(buf, " {}fn new({}) -> Self {{ Self {{ {} }} }}", vis, params, fields);
59 60
@@ -102,7 +103,7 @@ fn generate_impl_text(strukt: &ast::Struct, code: &str) -> String {
102 .map(|it| it.text().clone()); 103 .map(|it| it.text().clone());
103 let type_params = 104 let type_params =
104 type_params.type_params().filter_map(|it| it.name()).map(|it| it.text().clone()); 105 type_params.type_params().filter_map(|it| it.name()).map(|it| it.text().clone());
105 format_to!(buf, "<{}>", lifetime_params.chain(type_params).sep_by(", ")) 106 format_to!(buf, "<{}>", lifetime_params.chain(type_params).format(", "))
106 } 107 }
107 108
108 format_to!(buf, " {{\n{}\n}}\n", code); 109 format_to!(buf, " {{\n{}\n}}\n", code);
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 44456e49e..0007d7fa8 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -4,6 +4,7 @@ use std::{iter, sync::Arc};
4use arrayvec::ArrayVec; 4use arrayvec::ArrayVec;
5use either::Either; 5use either::Either;
6use hir_def::{ 6use hir_def::{
7 adt::ReprKind,
7 adt::StructKind, 8 adt::StructKind,
8 adt::VariantData, 9 adt::VariantData,
9 builtin_type::BuiltinType, 10 builtin_type::BuiltinType,
@@ -431,6 +432,10 @@ impl Struct {
431 Type::from_def(db, self.id.lookup(db.upcast()).container.module(db.upcast()).krate, self.id) 432 Type::from_def(db, self.id.lookup(db.upcast()).container.module(db.upcast()).krate, self.id)
432 } 433 }
433 434
435 pub fn repr(self, db: &dyn HirDatabase) -> Option<ReprKind> {
436 db.struct_data(self.id).repr.clone()
437 }
438
434 fn variant_data(self, db: &dyn HirDatabase) -> Arc<VariantData> { 439 fn variant_data(self, db: &dyn HirDatabase) -> Arc<VariantData> {
435 db.struct_data(self.id).variant_data.clone() 440 db.struct_data(self.id).variant_data.clone()
436 } 441 }
@@ -1253,6 +1258,19 @@ impl Type {
1253 ) 1258 )
1254 } 1259 }
1255 1260
1261 pub fn is_packed(&self, db: &dyn HirDatabase) -> bool {
1262 let adt_id = match self.ty.value {
1263 Ty::Apply(ApplicationTy { ctor: TypeCtor::Adt(adt_id), .. }) => adt_id,
1264 _ => return false,
1265 };
1266
1267 let adt = adt_id.into();
1268 match adt {
1269 Adt::Struct(s) => matches!(s.repr(db), Some(ReprKind::Packed)),
1270 _ => false,
1271 }
1272 }
1273
1256 pub fn is_raw_ptr(&self) -> bool { 1274 pub fn is_raw_ptr(&self) -> bool {
1257 matches!(&self.ty.value, Ty::Apply(ApplicationTy { ctor: TypeCtor::RawPtr(..), .. })) 1275 matches!(&self.ty.value, Ty::Apply(ApplicationTy { ctor: TypeCtor::RawPtr(..), .. }))
1258 } 1276 }
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index 31f3241c9..34b02c536 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -49,7 +49,7 @@ pub use hir_def::{
49 docs::Documentation, 49 docs::Documentation,
50 nameres::ModuleSource, 50 nameres::ModuleSource,
51 path::{ModPath, Path, PathKind}, 51 path::{ModPath, Path, PathKind},
52 type_ref::Mutability, 52 type_ref::{Mutability, TypeRef},
53}; 53};
54pub use hir_expand::{ 54pub use hir_expand::{
55 hygiene::Hygiene, name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, 55 hygiene::Hygiene, name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc,
diff --git a/crates/ra_hir/src/semantics.rs b/crates/ra_hir/src/semantics.rs
index e3c417b41..36b688ccb 100644
--- a/crates/ra_hir/src/semantics.rs
+++ b/crates/ra_hir/src/semantics.rs
@@ -25,7 +25,8 @@ use crate::{
25 semantics::source_to_def::{ChildContainer, SourceToDefCache, SourceToDefCtx}, 25 semantics::source_to_def::{ChildContainer, SourceToDefCache, SourceToDefCtx},
26 source_analyzer::{resolve_hir_path, resolve_hir_path_qualifier, SourceAnalyzer}, 26 source_analyzer::{resolve_hir_path, resolve_hir_path_qualifier, SourceAnalyzer},
27 AssocItem, Callable, Crate, Field, Function, HirFileId, ImplDef, InFile, Local, MacroDef, 27 AssocItem, Callable, Crate, Field, Function, HirFileId, ImplDef, InFile, Local, MacroDef,
28 Module, ModuleDef, Name, Origin, Path, ScopeDef, Trait, Type, TypeAlias, TypeParam, VariantDef, 28 Module, ModuleDef, Name, Origin, Path, ScopeDef, Trait, Type, TypeAlias, TypeParam, TypeRef,
29 VariantDef,
29}; 30};
30use resolver::TypeNs; 31use resolver::TypeNs;
31 32
@@ -272,6 +273,18 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
272 pub fn assert_contains_node(&self, node: &SyntaxNode) { 273 pub fn assert_contains_node(&self, node: &SyntaxNode) {
273 self.imp.assert_contains_node(node) 274 self.imp.assert_contains_node(node)
274 } 275 }
276
277 pub fn is_unsafe_method_call(&self, method_call_expr: ast::MethodCallExpr) -> bool {
278 self.imp.is_unsafe_method_call(method_call_expr)
279 }
280
281 pub fn is_unsafe_ref_expr(&self, ref_expr: &ast::RefExpr) -> bool {
282 self.imp.is_unsafe_ref_expr(ref_expr)
283 }
284
285 pub fn is_unsafe_ident_pat(&self, ident_pat: &ast::IdentPat) -> bool {
286 self.imp.is_unsafe_ident_pat(ident_pat)
287 }
275} 288}
276 289
277impl<'db> SemanticsImpl<'db> { 290impl<'db> SemanticsImpl<'db> {
@@ -568,6 +581,90 @@ impl<'db> SemanticsImpl<'db> {
568 }); 581 });
569 InFile::new(file_id, node) 582 InFile::new(file_id, node)
570 } 583 }
584
585 pub fn is_unsafe_method_call(&self, method_call_expr: ast::MethodCallExpr) -> bool {
586 method_call_expr
587 .expr()
588 .and_then(|expr| {
589 let field_expr = if let ast::Expr::FieldExpr(field_expr) = expr {
590 field_expr
591 } else {
592 return None;
593 };
594 let ty = self.type_of_expr(&field_expr.expr()?)?;
595 if !ty.is_packed(self.db) {
596 return None;
597 }
598
599 let func = self.resolve_method_call(&method_call_expr).map(Function::from)?;
600 let is_unsafe = func.has_self_param(self.db)
601 && matches!(func.params(self.db).first(), Some(TypeRef::Reference(..)));
602 Some(is_unsafe)
603 })
604 .unwrap_or(false)
605 }
606
607 pub fn is_unsafe_ref_expr(&self, ref_expr: &ast::RefExpr) -> bool {
608 ref_expr
609 .expr()
610 .and_then(|expr| {
611 let field_expr = match expr {
612 ast::Expr::FieldExpr(field_expr) => field_expr,
613 _ => return None,
614 };
615 let expr = field_expr.expr()?;
616 self.type_of_expr(&expr)
617 })
618 // Binding a reference to a packed type is possibly unsafe.
619 .map(|ty| ty.is_packed(self.db))
620 .unwrap_or(false)
621
622 // FIXME This needs layout computation to be correct. It will highlight
623 // more than it should with the current implementation.
624 }
625
626 pub fn is_unsafe_ident_pat(&self, ident_pat: &ast::IdentPat) -> bool {
627 if !ident_pat.ref_token().is_some() {
628 return false;
629 }
630
631 ident_pat
632 .syntax()
633 .parent()
634 .and_then(|parent| {
635 // `IdentPat` can live under `RecordPat` directly under `RecordPatField` or
636 // `RecordPatFieldList`. `RecordPatField` also lives under `RecordPatFieldList`,
637 // so this tries to lookup the `IdentPat` anywhere along that structure to the
638 // `RecordPat` so we can get the containing type.
639 let record_pat = ast::RecordPatField::cast(parent.clone())
640 .and_then(|record_pat| record_pat.syntax().parent())
641 .or_else(|| Some(parent.clone()))
642 .and_then(|parent| {
643 ast::RecordPatFieldList::cast(parent)?
644 .syntax()
645 .parent()
646 .and_then(ast::RecordPat::cast)
647 });
648
649 // If this doesn't match a `RecordPat`, fallback to a `LetStmt` to see if
650 // this is initialized from a `FieldExpr`.
651 if let Some(record_pat) = record_pat {
652 self.type_of_pat(&ast::Pat::RecordPat(record_pat))
653 } else if let Some(let_stmt) = ast::LetStmt::cast(parent) {
654 let field_expr = match let_stmt.initializer()? {
655 ast::Expr::FieldExpr(field_expr) => field_expr,
656 _ => return None,
657 };
658
659 self.type_of_expr(&field_expr.expr()?)
660 } else {
661 None
662 }
663 })
664 // Binding a reference to a packed type is possibly unsafe.
665 .map(|ty| ty.is_packed(self.db))
666 .unwrap_or(false)
667 }
571} 668}
572 669
573pub trait ToDef: AstNode + Clone { 670pub trait ToDef: AstNode + Clone {
diff --git a/crates/ra_hir/src/source_analyzer.rs b/crates/ra_hir/src/source_analyzer.rs
index d0cb62ef0..d3d62debf 100644
--- a/crates/ra_hir/src/source_analyzer.rs
+++ b/crates/ra_hir/src/source_analyzer.rs
@@ -265,8 +265,7 @@ impl SourceAnalyzer {
265 } 265 }
266 266
267 // This must be a normal source file rather than macro file. 267 // This must be a normal source file rather than macro file.
268 let hir_path = 268 let hir_path = Path::from_src(path.clone(), &Hygiene::new(db.upcast(), self.file_id))?;
269 crate::Path::from_src(path.clone(), &Hygiene::new(db.upcast(), self.file_id))?;
270 269
271 // Case where path is a qualifier of another path, e.g. foo::bar::Baz where we 270 // Case where path is a qualifier of another path, e.g. foo::bar::Baz where we
272 // trying to resolve foo::bar. 271 // trying to resolve foo::bar.
@@ -451,7 +450,7 @@ fn adjust(
451pub(crate) fn resolve_hir_path( 450pub(crate) fn resolve_hir_path(
452 db: &dyn HirDatabase, 451 db: &dyn HirDatabase,
453 resolver: &Resolver, 452 resolver: &Resolver,
454 path: &crate::Path, 453 path: &Path,
455) -> Option<PathResolution> { 454) -> Option<PathResolution> {
456 let types = 455 let types =
457 resolver.resolve_path_in_type_ns_fully(db.upcast(), path.mod_path()).map(|ty| match ty { 456 resolver.resolve_path_in_type_ns_fully(db.upcast(), path.mod_path()).map(|ty| match ty {
@@ -512,7 +511,7 @@ pub(crate) fn resolve_hir_path(
512pub(crate) fn resolve_hir_path_qualifier( 511pub(crate) fn resolve_hir_path_qualifier(
513 db: &dyn HirDatabase, 512 db: &dyn HirDatabase,
514 resolver: &Resolver, 513 resolver: &Resolver,
515 path: &crate::Path, 514 path: &Path,
516) -> Option<PathResolution> { 515) -> Option<PathResolution> {
517 let items = resolver 516 let items = resolver
518 .resolve_module_path_in_items(db.upcast(), path.mod_path()) 517 .resolve_module_path_in_items(db.upcast(), path.mod_path())
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};
10use ra_arena::{map::ArenaMap, Arena}; 10use ra_arena::{map::ArenaMap, Arena};
11use ra_syntax::ast::{self, NameOwner, VisibilityOwner}; 11use ra_syntax::ast::{self, NameOwner, VisibilityOwner};
12use tt::{Delimiter, DelimiterKind, Leaf, Subtree, TokenTree};
12 13
13use crate::{ 14use 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;
29pub struct StructData { 30pub 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)]
64pub enum ReprKind {
65 Packed,
66 Other,
67}
68
69fn 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
73fn 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
61impl StructData { 86impl 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_ide/src/completion/complete_snippet.rs b/crates/ra_ide/src/completion/complete_snippet.rs
index 28d8f7876..4368e4eec 100644
--- a/crates/ra_ide/src/completion/complete_snippet.rs
+++ b/crates/ra_ide/src/completion/complete_snippet.rs
@@ -36,7 +36,7 @@ pub(super) fn complete_item_snippet(acc: &mut Completions, ctx: &CompletionConte
36 snippet( 36 snippet(
37 ctx, 37 ctx,
38 cap, 38 cap,
39 "Test module", 39 "tmod (Test module)",
40 "\ 40 "\
41#[cfg(test)] 41#[cfg(test)]
42mod tests { 42mod tests {
@@ -54,7 +54,7 @@ mod tests {
54 snippet( 54 snippet(
55 ctx, 55 ctx,
56 cap, 56 cap,
57 "Test function", 57 "tfn (Test function)",
58 "\ 58 "\
59#[test] 59#[test]
60fn ${1:feature}() { 60fn ${1:feature}() {
@@ -106,10 +106,10 @@ mod tests {
106} 106}
107"#, 107"#,
108 expect![[r#" 108 expect![[r#"
109 sn Test function
110 sn Test module
111 sn macro_rules 109 sn macro_rules
112 sn pub(crate) 110 sn pub(crate)
111 sn tfn (Test function)
112 sn tmod (Test module)
113 "#]], 113 "#]],
114 ) 114 )
115 } 115 }
diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs
index 9a94ff476..59f1b1424 100644
--- a/crates/ra_ide/src/completion/presentation.rs
+++ b/crates/ra_ide/src/completion/presentation.rs
@@ -2,8 +2,8 @@
2//! It also handles scoring (sorting) completions. 2//! It also handles scoring (sorting) completions.
3 3
4use hir::{Docs, HasAttrs, HasSource, HirDisplay, ModPath, ScopeDef, StructKind, Type}; 4use hir::{Docs, HasAttrs, HasSource, HirDisplay, ModPath, ScopeDef, StructKind, Type};
5use itertools::Itertools;
5use ra_syntax::ast::NameOwner; 6use ra_syntax::ast::NameOwner;
6use stdx::SepBy;
7use test_utils::mark; 7use test_utils::mark;
8 8
9use crate::{ 9use crate::{
@@ -289,16 +289,16 @@ impl Completions {
289 .map(|field| (field.name(ctx.db), field.signature_ty(ctx.db))); 289 .map(|field| (field.name(ctx.db), field.signature_ty(ctx.db)));
290 let variant_kind = variant.kind(ctx.db); 290 let variant_kind = variant.kind(ctx.db);
291 let detail = match variant_kind { 291 let detail = match variant_kind {
292 StructKind::Tuple | StructKind::Unit => detail_types 292 StructKind::Tuple | StructKind::Unit => format!(
293 .map(|(_, t)| t.display(ctx.db).to_string()) 293 "({})",
294 .sep_by(", ") 294 detail_types.map(|(_, t)| t.display(ctx.db).to_string()).format(", ")
295 .surround_with("(", ")") 295 ),
296 .to_string(), 296 StructKind::Record => format!(
297 StructKind::Record => detail_types 297 "{{ {} }}",
298 .map(|(n, t)| format!("{}: {}", n, t.display(ctx.db).to_string())) 298 detail_types
299 .sep_by(", ") 299 .map(|(n, t)| format!("{}: {}", n, t.display(ctx.db).to_string()))
300 .surround_with("{ ", " }") 300 .format(", ")
301 .to_string(), 301 ),
302 }; 302 };
303 let mut res = CompletionItem::new( 303 let mut res = CompletionItem::new(
304 CompletionKind::Reference, 304 CompletionKind::Reference,
@@ -412,11 +412,10 @@ impl Builder {
412 self = self.trigger_call_info(); 412 self = self.trigger_call_info();
413 let snippet = match (ctx.config.add_call_argument_snippets, params) { 413 let snippet = match (ctx.config.add_call_argument_snippets, params) {
414 (true, Params::Named(params)) => { 414 (true, Params::Named(params)) => {
415 let function_params_snippet = params 415 let function_params_snippet =
416 .iter() 416 params.iter().enumerate().format_with(", ", |(index, param_name), f| {
417 .enumerate() 417 f(&format_args!("${{{}:{}}}", index + 1, param_name))
418 .map(|(index, param_name)| format!("${{{}:{}}}", index + 1, param_name)) 418 });
419 .sep_by(", ");
420 format!("{}({})$0", name, function_params_snippet) 419 format!("{}({})$0", name, function_params_snippet)
421 } 420 }
422 _ => { 421 _ => {
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs
index 6b7874460..c10e15db8 100644
--- a/crates/ra_ide/src/syntax_highlighting.rs
+++ b/crates/ra_ide/src/syntax_highlighting.rs
@@ -497,9 +497,9 @@ fn highlight_element(
497 match name_kind { 497 match name_kind {
498 Some(NameClass::ExternCrate(_)) => HighlightTag::Module.into(), 498 Some(NameClass::ExternCrate(_)) => HighlightTag::Module.into(),
499 Some(NameClass::Definition(def)) => { 499 Some(NameClass::Definition(def)) => {
500 highlight_name(db, def, false) | HighlightModifier::Definition 500 highlight_name(sema, db, def, None, false) | HighlightModifier::Definition
501 } 501 }
502 Some(NameClass::ConstReference(def)) => highlight_name(db, def, false), 502 Some(NameClass::ConstReference(def)) => highlight_name(sema, db, def, None, false),
503 Some(NameClass::FieldShorthand { field, .. }) => { 503 Some(NameClass::FieldShorthand { field, .. }) => {
504 let mut h = HighlightTag::Field.into(); 504 let mut h = HighlightTag::Field.into();
505 if let Definition::Field(field) = field { 505 if let Definition::Field(field) = field {
@@ -532,7 +532,7 @@ fn highlight_element(
532 binding_hash = Some(calc_binding_hash(&name, *shadow_count)) 532 binding_hash = Some(calc_binding_hash(&name, *shadow_count))
533 } 533 }
534 }; 534 };
535 highlight_name(db, def, possibly_unsafe) 535 highlight_name(sema, db, def, Some(name_ref), possibly_unsafe)
536 } 536 }
537 NameRefClass::FieldShorthand { .. } => HighlightTag::Field.into(), 537 NameRefClass::FieldShorthand { .. } => HighlightTag::Field.into(),
538 }, 538 },
@@ -566,9 +566,20 @@ fn highlight_element(
566 } 566 }
567 } 567 }
568 p if p.is_punct() => match p { 568 p if p.is_punct() => match p {
569 T![::] | T![->] | T![=>] | T![&] | T![..] | T![=] | T![@] => { 569 T![&] => {
570 HighlightTag::Operator.into() 570 let h = HighlightTag::Operator.into();
571 let is_unsafe = element
572 .parent()
573 .and_then(ast::RefExpr::cast)
574 .map(|ref_expr| sema.is_unsafe_ref_expr(&ref_expr))
575 .unwrap_or(false);
576 if is_unsafe {
577 h | HighlightModifier::Unsafe
578 } else {
579 h
580 }
571 } 581 }
582 T![::] | T![->] | T![=>] | T![..] | T![=] | T![@] => HighlightTag::Operator.into(),
572 T![!] if element.parent().and_then(ast::MacroCall::cast).is_some() => { 583 T![!] if element.parent().and_then(ast::MacroCall::cast).is_some() => {
573 HighlightTag::Macro.into() 584 HighlightTag::Macro.into()
574 } 585 }
@@ -649,6 +660,18 @@ fn highlight_element(
649 HighlightTag::SelfKeyword.into() 660 HighlightTag::SelfKeyword.into()
650 } 661 }
651 } 662 }
663 T![ref] => element
664 .parent()
665 .and_then(ast::IdentPat::cast)
666 .and_then(|ident_pat| {
667 if sema.is_unsafe_ident_pat(&ident_pat) {
668 Some(HighlightModifier::Unsafe)
669 } else {
670 None
671 }
672 })
673 .map(|modifier| h | modifier)
674 .unwrap_or(h),
652 _ => h, 675 _ => h,
653 } 676 }
654 } 677 }
@@ -678,7 +701,13 @@ fn is_child_of_impl(element: &SyntaxElement) -> bool {
678 } 701 }
679} 702}
680 703
681fn highlight_name(db: &RootDatabase, def: Definition, possibly_unsafe: bool) -> Highlight { 704fn highlight_name(
705 sema: &Semantics<RootDatabase>,
706 db: &RootDatabase,
707 def: Definition,
708 name_ref: Option<ast::NameRef>,
709 possibly_unsafe: bool,
710) -> Highlight {
682 match def { 711 match def {
683 Definition::Macro(_) => HighlightTag::Macro, 712 Definition::Macro(_) => HighlightTag::Macro,
684 Definition::Field(field) => { 713 Definition::Field(field) => {
@@ -697,6 +726,15 @@ fn highlight_name(db: &RootDatabase, def: Definition, possibly_unsafe: bool) ->
697 let mut h = HighlightTag::Function.into(); 726 let mut h = HighlightTag::Function.into();
698 if func.is_unsafe(db) { 727 if func.is_unsafe(db) {
699 h |= HighlightModifier::Unsafe; 728 h |= HighlightModifier::Unsafe;
729 } else {
730 let is_unsafe = name_ref
731 .and_then(|name_ref| name_ref.syntax().parent())
732 .and_then(ast::MethodCallExpr::cast)
733 .map(|method_call_expr| sema.is_unsafe_method_call(method_call_expr))
734 .unwrap_or(false);
735 if is_unsafe {
736 h |= HighlightModifier::Unsafe;
737 }
700 } 738 }
701 return h; 739 return h;
702 } 740 }
@@ -768,8 +806,18 @@ fn highlight_name_ref_by_syntax(name: ast::NameRef, sema: &Semantics<RootDatabas
768 _ => return default.into(), 806 _ => return default.into(),
769 }; 807 };
770 808
771 let tag = match parent.kind() { 809 match parent.kind() {
772 METHOD_CALL_EXPR => HighlightTag::Function, 810 METHOD_CALL_EXPR => {
811 let mut h = Highlight::new(HighlightTag::Function);
812 let is_unsafe = ast::MethodCallExpr::cast(parent)
813 .map(|method_call_expr| sema.is_unsafe_method_call(method_call_expr))
814 .unwrap_or(false);
815 if is_unsafe {
816 h |= HighlightModifier::Unsafe;
817 }
818
819 h
820 }
773 FIELD_EXPR => { 821 FIELD_EXPR => {
774 let h = HighlightTag::Field; 822 let h = HighlightTag::Field;
775 let is_union = ast::FieldExpr::cast(parent) 823 let is_union = ast::FieldExpr::cast(parent)
@@ -782,7 +830,11 @@ fn highlight_name_ref_by_syntax(name: ast::NameRef, sema: &Semantics<RootDatabas
782 }) 830 })
783 }) 831 })
784 .unwrap_or(false); 832 .unwrap_or(false);
785 return if is_union { h | HighlightModifier::Unsafe } else { h.into() }; 833 if is_union {
834 h | HighlightModifier::Unsafe
835 } else {
836 h.into()
837 }
786 } 838 }
787 PATH_SEGMENT => { 839 PATH_SEGMENT => {
788 let path = match parent.parent().and_then(ast::Path::cast) { 840 let path = match parent.parent().and_then(ast::Path::cast) {
@@ -807,18 +859,15 @@ fn highlight_name_ref_by_syntax(name: ast::NameRef, sema: &Semantics<RootDatabas
807 }; 859 };
808 860
809 match parent.kind() { 861 match parent.kind() {
810 CALL_EXPR => HighlightTag::Function, 862 CALL_EXPR => HighlightTag::Function.into(),
811 _ => { 863 _ => if name.text().chars().next().unwrap_or_default().is_uppercase() {
812 if name.text().chars().next().unwrap_or_default().is_uppercase() { 864 HighlightTag::Struct.into()
813 HighlightTag::Struct 865 } else {
814 } else { 866 HighlightTag::Constant
815 HighlightTag::Constant
816 }
817 } 867 }
868 .into(),
818 } 869 }
819 } 870 }
820 _ => default, 871 _ => default.into(),
821 }; 872 }
822
823 tag.into()
824} 873}
diff --git a/crates/ra_ide/src/syntax_highlighting/injection.rs b/crates/ra_ide/src/syntax_highlighting/injection.rs
index 8665b480f..6046643ef 100644
--- a/crates/ra_ide/src/syntax_highlighting/injection.rs
+++ b/crates/ra_ide/src/syntax_highlighting/injection.rs
@@ -4,8 +4,8 @@ use std::{collections::BTreeMap, convert::TryFrom};
4 4
5use ast::{HasQuotes, HasStringValue}; 5use ast::{HasQuotes, HasStringValue};
6use hir::Semantics; 6use hir::Semantics;
7use itertools::Itertools;
7use ra_syntax::{ast, AstToken, SyntaxNode, SyntaxToken, TextRange, TextSize}; 8use ra_syntax::{ast, AstToken, SyntaxNode, SyntaxToken, TextRange, TextSize};
8use stdx::SepBy;
9 9
10use crate::{ 10use crate::{
11 call_info::ActiveParameter, Analysis, Highlight, HighlightModifier, HighlightTag, 11 call_info::ActiveParameter, Analysis, Highlight, HighlightModifier, HighlightTag,
@@ -129,8 +129,7 @@ pub(super) fn extract_doc_comments(
129 129
130 line[pos..].to_owned() 130 line[pos..].to_owned()
131 }) 131 })
132 .sep_by("\n") 132 .join("\n");
133 .to_string();
134 133
135 if doctest.is_empty() { 134 if doctest.is_empty() {
136 return None; 135 return None;
diff --git a/crates/ra_ide/src/syntax_highlighting/tests.rs b/crates/ra_ide/src/syntax_highlighting/tests.rs
index 09062c38e..a8087635a 100644
--- a/crates/ra_ide/src/syntax_highlighting/tests.rs
+++ b/crates/ra_ide/src/syntax_highlighting/tests.rs
@@ -292,10 +292,24 @@ struct TypeForStaticMut {
292 292
293static mut global_mut: TypeForStaticMut = TypeForStaticMut { a: 0 }; 293static mut global_mut: TypeForStaticMut = TypeForStaticMut { a: 0 };
294 294
295#[repr(packed)]
296struct Packed {
297 a: u16,
298}
299
300trait DoTheAutoref {
301 fn calls_autoref(&self);
302}
303
304impl DoTheAutoref for u16 {
305 fn calls_autoref(&self) {}
306}
307
295fn main() { 308fn main() {
296 let x = &5 as *const usize; 309 let x = &5 as *const _ as *const usize;
297 let u = Union { b: 0 }; 310 let u = Union { b: 0 };
298 unsafe { 311 unsafe {
312 // unsafe fn and method calls
299 unsafe_fn(); 313 unsafe_fn();
300 let b = u.b; 314 let b = u.b;
301 match u { 315 match u {
@@ -303,9 +317,22 @@ fn main() {
303 Union { a } => (), 317 Union { a } => (),
304 } 318 }
305 HasUnsafeFn.unsafe_method(); 319 HasUnsafeFn.unsafe_method();
306 let y = *(x); 320
307 let z = -x; 321 // unsafe deref
322 let y = *x;
323
324 // unsafe access to a static mut
308 let a = global_mut.a; 325 let a = global_mut.a;
326
327 // unsafe ref of packed fields
328 let packed = Packed { a: 0 };
329 let a = &packed.a;
330 let ref a = packed.a;
331 let Packed { ref a } = packed;
332 let Packed { a: ref _a } = packed;
333
334 // unsafe auto ref of packed field
335 packed.a.calls_autoref();
309 } 336 }
310} 337}
311"# 338"#
diff --git a/crates/ra_ide/test_data/highlight_unsafe.html b/crates/ra_ide/test_data/highlight_unsafe.html
index 79409fe81..552fea668 100644
--- a/crates/ra_ide/test_data/highlight_unsafe.html
+++ b/crates/ra_ide/test_data/highlight_unsafe.html
@@ -54,10 +54,24 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
54 54
55<span class="keyword">static</span> <span class="keyword">mut</span> <span class="static declaration mutable unsafe">global_mut</span><span class="punctuation">:</span> <span class="struct">TypeForStaticMut</span> <span class="operator">=</span> <span class="struct">TypeForStaticMut</span> <span class="punctuation">{</span> <span class="field">a</span><span class="punctuation">:</span> <span class="numeric_literal">0</span> <span class="punctuation">}</span><span class="punctuation">;</span> 55<span class="keyword">static</span> <span class="keyword">mut</span> <span class="static declaration mutable unsafe">global_mut</span><span class="punctuation">:</span> <span class="struct">TypeForStaticMut</span> <span class="operator">=</span> <span class="struct">TypeForStaticMut</span> <span class="punctuation">{</span> <span class="field">a</span><span class="punctuation">:</span> <span class="numeric_literal">0</span> <span class="punctuation">}</span><span class="punctuation">;</span>
56 56
57<span class="attribute">#</span><span class="attribute">[</span><span class="function attribute">repr</span><span class="punctuation">(</span><span class="attribute">packed</span><span class="punctuation">)</span><span class="attribute">]</span>
58<span class="keyword">struct</span> <span class="struct declaration">Packed</span> <span class="punctuation">{</span>
59 <span class="field declaration">a</span><span class="punctuation">:</span> <span class="builtin_type">u16</span><span class="punctuation">,</span>
60<span class="punctuation">}</span>
61
62<span class="keyword">trait</span> <span class="trait declaration">DoTheAutoref</span> <span class="punctuation">{</span>
63 <span class="keyword">fn</span> <span class="function declaration">calls_autoref</span><span class="punctuation">(</span><span class="operator">&</span><span class="self_keyword">self</span><span class="punctuation">)</span><span class="punctuation">;</span>
64<span class="punctuation">}</span>
65
66<span class="keyword">impl</span> <span class="trait">DoTheAutoref</span> <span class="keyword">for</span> <span class="builtin_type">u16</span> <span class="punctuation">{</span>
67 <span class="keyword">fn</span> <span class="function declaration">calls_autoref</span><span class="punctuation">(</span><span class="operator">&</span><span class="self_keyword">self</span><span class="punctuation">)</span> <span class="punctuation">{</span><span class="punctuation">}</span>
68<span class="punctuation">}</span>
69
57<span class="keyword">fn</span> <span class="function declaration">main</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="punctuation">{</span> 70<span class="keyword">fn</span> <span class="function declaration">main</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="punctuation">{</span>
58 <span class="keyword">let</span> <span class="variable declaration">x</span> <span class="operator">=</span> <span class="operator">&</span><span class="numeric_literal">5</span> <span class="keyword">as</span> <span class="keyword">*</span><span class="keyword">const</span> <span class="builtin_type">usize</span><span class="punctuation">;</span> 71 <span class="keyword">let</span> <span class="variable declaration">x</span> <span class="operator">=</span> <span class="operator">&</span><span class="numeric_literal">5</span> <span class="keyword">as</span> <span class="keyword">*</span><span class="keyword">const</span> <span class="punctuation">_</span> <span class="keyword">as</span> <span class="keyword">*</span><span class="keyword">const</span> <span class="builtin_type">usize</span><span class="punctuation">;</span>
59 <span class="keyword">let</span> <span class="variable declaration">u</span> <span class="operator">=</span> <span class="union">Union</span> <span class="punctuation">{</span> <span class="field">b</span><span class="punctuation">:</span> <span class="numeric_literal">0</span> <span class="punctuation">}</span><span class="punctuation">;</span> 72 <span class="keyword">let</span> <span class="variable declaration">u</span> <span class="operator">=</span> <span class="union">Union</span> <span class="punctuation">{</span> <span class="field">b</span><span class="punctuation">:</span> <span class="numeric_literal">0</span> <span class="punctuation">}</span><span class="punctuation">;</span>
60 <span class="keyword unsafe">unsafe</span> <span class="punctuation">{</span> 73 <span class="keyword unsafe">unsafe</span> <span class="punctuation">{</span>
74 <span class="comment">// unsafe fn and method calls</span>
61 <span class="function unsafe">unsafe_fn</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span> 75 <span class="function unsafe">unsafe_fn</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span>
62 <span class="keyword">let</span> <span class="variable declaration">b</span> <span class="operator">=</span> <span class="variable">u</span><span class="punctuation">.</span><span class="field unsafe">b</span><span class="punctuation">;</span> 76 <span class="keyword">let</span> <span class="variable declaration">b</span> <span class="operator">=</span> <span class="variable">u</span><span class="punctuation">.</span><span class="field unsafe">b</span><span class="punctuation">;</span>
63 <span class="keyword control">match</span> <span class="variable">u</span> <span class="punctuation">{</span> 77 <span class="keyword control">match</span> <span class="variable">u</span> <span class="punctuation">{</span>
@@ -65,8 +79,21 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
65 <span class="union">Union</span> <span class="punctuation">{</span> <span class="field unsafe">a</span> <span class="punctuation">}</span> <span class="operator">=&gt;</span> <span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">,</span> 79 <span class="union">Union</span> <span class="punctuation">{</span> <span class="field unsafe">a</span> <span class="punctuation">}</span> <span class="operator">=&gt;</span> <span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">,</span>
66 <span class="punctuation">}</span> 80 <span class="punctuation">}</span>
67 <span class="struct">HasUnsafeFn</span><span class="punctuation">.</span><span class="function unsafe">unsafe_method</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span> 81 <span class="struct">HasUnsafeFn</span><span class="punctuation">.</span><span class="function unsafe">unsafe_method</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span>
68 <span class="keyword">let</span> <span class="variable declaration">y</span> <span class="operator">=</span> <span class="operator unsafe">*</span><span class="punctuation">(</span><span class="variable">x</span><span class="punctuation">)</span><span class="punctuation">;</span> 82
69 <span class="keyword">let</span> <span class="variable declaration">z</span> <span class="operator">=</span> <span class="numeric_literal">-</span><span class="variable">x</span><span class="punctuation">;</span> 83 <span class="comment">// unsafe deref</span>
84 <span class="keyword">let</span> <span class="variable declaration">y</span> <span class="operator">=</span> <span class="operator unsafe">*</span><span class="variable">x</span><span class="punctuation">;</span>
85
86 <span class="comment">// unsafe access to a static mut</span>
70 <span class="keyword">let</span> <span class="variable declaration">a</span> <span class="operator">=</span> <span class="static mutable unsafe">global_mut</span><span class="punctuation">.</span><span class="field">a</span><span class="punctuation">;</span> 87 <span class="keyword">let</span> <span class="variable declaration">a</span> <span class="operator">=</span> <span class="static mutable unsafe">global_mut</span><span class="punctuation">.</span><span class="field">a</span><span class="punctuation">;</span>
88
89 <span class="comment">// unsafe ref of packed fields</span>
90 <span class="keyword">let</span> <span class="variable declaration">packed</span> <span class="operator">=</span> <span class="struct">Packed</span> <span class="punctuation">{</span> <span class="field">a</span><span class="punctuation">:</span> <span class="numeric_literal">0</span> <span class="punctuation">}</span><span class="punctuation">;</span>
91 <span class="keyword">let</span> <span class="variable declaration">a</span> <span class="operator">=</span> <span class="operator unsafe">&</span><span class="variable">packed</span><span class="punctuation">.</span><span class="field">a</span><span class="punctuation">;</span>
92 <span class="keyword">let</span> <span class="keyword unsafe">ref</span> <span class="variable declaration">a</span> <span class="operator">=</span> <span class="variable">packed</span><span class="punctuation">.</span><span class="field">a</span><span class="punctuation">;</span>
93 <span class="keyword">let</span> <span class="struct">Packed</span> <span class="punctuation">{</span> <span class="keyword unsafe">ref</span> <span class="field">a</span> <span class="punctuation">}</span> <span class="operator">=</span> <span class="variable">packed</span><span class="punctuation">;</span>
94 <span class="keyword">let</span> <span class="struct">Packed</span> <span class="punctuation">{</span> <span class="field">a</span><span class="punctuation">:</span> <span class="keyword unsafe">ref</span> <span class="variable declaration">_a</span> <span class="punctuation">}</span> <span class="operator">=</span> <span class="variable">packed</span><span class="punctuation">;</span>
95
96 <span class="comment">// unsafe auto ref of packed field</span>
97 <span class="variable">packed</span><span class="punctuation">.</span><span class="field">a</span><span class="punctuation">.</span><span class="function unsafe">calls_autoref</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span>
71 <span class="punctuation">}</span> 98 <span class="punctuation">}</span>
72<span class="punctuation">}</span></code></pre> \ No newline at end of file 99<span class="punctuation">}</span></code></pre> \ No newline at end of file
diff --git a/crates/ra_mbe/src/mbe_expander/matcher.rs b/crates/ra_mbe/src/mbe_expander/matcher.rs
index f9e515b81..933a3a3b5 100644
--- a/crates/ra_mbe/src/mbe_expander/matcher.rs
+++ b/crates/ra_mbe/src/mbe_expander/matcher.rs
@@ -276,7 +276,7 @@ impl<'a> TtIter<'a> {
276 Ok(tt::Subtree { 276 Ok(tt::Subtree {
277 delimiter: None, 277 delimiter: None,
278 token_trees: vec![ 278 token_trees: vec![
279 tt::Leaf::Punct(punct.clone()).into(), 279 tt::Leaf::Punct(*punct).into(),
280 tt::Leaf::Ident(ident.clone()).into(), 280 tt::Leaf::Ident(ident.clone()).into(),
281 ], 281 ],
282 } 282 }
diff --git a/crates/ra_parser/src/grammar.rs b/crates/ra_parser/src/grammar.rs
index c2e1d701e..88468bc97 100644
--- a/crates/ra_parser/src/grammar.rs
+++ b/crates/ra_parser/src/grammar.rs
@@ -110,7 +110,7 @@ pub(crate) mod fragments {
110 } 110 }
111 111
112 pub(crate) fn item(p: &mut Parser) { 112 pub(crate) fn item(p: &mut Parser) {
113 items::item_or_macro(p, true, items::ItemFlavor::Mod) 113 items::item_or_macro(p, true)
114 } 114 }
115 115
116 pub(crate) fn macro_items(p: &mut Parser) { 116 pub(crate) fn macro_items(p: &mut Parser) {
diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs
index e1c25a838..3291e3f14 100644
--- a/crates/ra_parser/src/grammar/expressions.rs
+++ b/crates/ra_parser/src/grammar/expressions.rs
@@ -73,7 +73,7 @@ pub(super) fn stmt(p: &mut Parser, with_semi: StmtWithSemi) {
73 73
74 // test block_items 74 // test block_items
75 // fn a() { fn b() {} } 75 // fn a() { fn b() {} }
76 let m = match items::maybe_item(p, m, items::ItemFlavor::Mod) { 76 let m = match items::maybe_item(p, m) {
77 Ok(()) => return, 77 Ok(()) => return,
78 Err(m) => m, 78 Err(m) => m,
79 }; 79 };
@@ -509,7 +509,6 @@ fn method_call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
509// x.1i32; 509// x.1i32;
510// x.0x01; 510// x.0x01;
511// } 511// }
512#[allow(clippy::if_same_then_else)]
513fn field_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { 512fn field_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
514 assert!(p.at(T![.])); 513 assert!(p.at(T![.]));
515 let m = lhs.precede(p); 514 let m = lhs.precede(p);
diff --git a/crates/ra_parser/src/grammar/items.rs b/crates/ra_parser/src/grammar/items.rs
index cca524cea..d091b0fbb 100644
--- a/crates/ra_parser/src/grammar/items.rs
+++ b/crates/ra_parser/src/grammar/items.rs
@@ -22,24 +22,19 @@ use super::*;
22pub(super) fn mod_contents(p: &mut Parser, stop_on_r_curly: bool) { 22pub(super) fn mod_contents(p: &mut Parser, stop_on_r_curly: bool) {
23 attributes::inner_attributes(p); 23 attributes::inner_attributes(p);
24 while !(stop_on_r_curly && p.at(T!['}']) || p.at(EOF)) { 24 while !(stop_on_r_curly && p.at(T!['}']) || p.at(EOF)) {
25 item_or_macro(p, stop_on_r_curly, ItemFlavor::Mod) 25 item_or_macro(p, stop_on_r_curly)
26 } 26 }
27} 27}
28 28
29pub(super) enum ItemFlavor {
30 Mod,
31 Trait,
32}
33
34pub(super) const ITEM_RECOVERY_SET: TokenSet = token_set![ 29pub(super) const ITEM_RECOVERY_SET: TokenSet = token_set![
35 FN_KW, STRUCT_KW, ENUM_KW, IMPL_KW, TRAIT_KW, CONST_KW, STATIC_KW, LET_KW, MOD_KW, PUB_KW, 30 FN_KW, STRUCT_KW, ENUM_KW, IMPL_KW, TRAIT_KW, CONST_KW, STATIC_KW, LET_KW, MOD_KW, PUB_KW,
36 CRATE_KW, USE_KW, MACRO_KW 31 CRATE_KW, USE_KW, MACRO_KW
37]; 32];
38 33
39pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemFlavor) { 34pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool) {
40 let m = p.start(); 35 let m = p.start();
41 attributes::outer_attributes(p); 36 attributes::outer_attributes(p);
42 let m = match maybe_item(p, m, flavor) { 37 let m = match maybe_item(p, m) {
43 Ok(()) => { 38 Ok(()) => {
44 if p.at(T![;]) { 39 if p.at(T![;]) {
45 p.err_and_bump( 40 p.err_and_bump(
@@ -76,7 +71,7 @@ pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemF
76 } 71 }
77} 72}
78 73
79pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Result<(), Marker> { 74pub(super) fn maybe_item(p: &mut Parser, m: Marker) -> Result<(), Marker> {
80 // test_err pub_expr 75 // test_err pub_expr
81 // fn foo() { pub 92; } 76 // fn foo() { pub 92; }
82 let has_visibility = opt_visibility(p); 77 let has_visibility = opt_visibility(p);
@@ -114,38 +109,31 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul
114 has_mods = true; 109 has_mods = true;
115 } 110 }
116 111
117 if p.at(IDENT) 112 // test default_item
118 && p.at_contextual_kw("default") 113 // default impl T for Foo {}
119 && (match p.nth(1) { 114 if p.at(IDENT) && p.at_contextual_kw("default") {
120 T![impl] => true, 115 match p.nth(1) {
116 T![fn] | T![type] | T![const] | T![impl] => {
117 p.bump_remap(T![default]);
118 has_mods = true;
119 }
121 T![unsafe] => { 120 T![unsafe] => {
122 // test default_unsafe_impl 121 // test default_unsafe_item
123 // default unsafe impl Foo {} 122 // default unsafe impl T for Foo {
124
125 // test default_unsafe_fn
126 // impl T for Foo {
127 // default unsafe fn foo() {} 123 // default unsafe fn foo() {}
128 // } 124 // }
129 if p.nth(2) == T![impl] || p.nth(2) == T![fn] { 125 if matches!(p.nth(2), T![impl] | T![fn]) {
130 p.bump_remap(T![default]); 126 p.bump_remap(T![default]);
131 p.bump(T![unsafe]); 127 p.bump(T![unsafe]);
132 has_mods = true; 128 has_mods = true;
133 } 129 }
134 false
135 } 130 }
136 T![fn] | T![type] | T![const] => { 131 _ => (),
137 if let ItemFlavor::Mod = flavor { 132 }
138 true
139 } else {
140 false
141 }
142 }
143 _ => false,
144 })
145 {
146 p.bump_remap(T![default]);
147 has_mods = true;
148 } 133 }
134
135 // test existential_type
136 // existential type Foo: Fn() -> usize;
149 if p.at(IDENT) && p.at_contextual_kw("existential") && p.nth(1) == T![type] { 137 if p.at(IDENT) && p.at_contextual_kw("existential") && p.nth(1) == T![type] {
150 p.bump_remap(T![existential]); 138 p.bump_remap(T![existential]);
151 has_mods = true; 139 has_mods = true;
@@ -153,79 +141,31 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul
153 141
154 // items 142 // items
155 match p.current() { 143 match p.current() {
156 // test async_fn 144 // test fn
157 // async fn foo() {} 145 // fn foo() {}
158
159 // test extern_fn
160 // extern fn foo() {}
161
162 // test const_fn
163 // const fn foo() {}
164
165 // test const_unsafe_fn
166 // const unsafe fn foo() {}
167
168 // test unsafe_extern_fn
169 // unsafe extern "C" fn foo() {}
170
171 // test unsafe_fn
172 // unsafe fn foo() {}
173
174 // test combined_fns
175 // async unsafe fn foo() {}
176 // const unsafe fn bar() {}
177
178 // test_err wrong_order_fns
179 // unsafe async fn foo() {}
180 // unsafe const fn bar() {}
181 T![fn] => { 146 T![fn] => {
182 fn_def(p); 147 fn_def(p);
183 m.complete(p, FN); 148 m.complete(p, FN);
184 } 149 }
185 150
186 // test unsafe_trait 151 // test trait
187 // unsafe trait T {} 152 // trait T {}
188
189 // test auto_trait
190 // auto trait T {}
191
192 // test unsafe_auto_trait
193 // unsafe auto trait T {}
194 T![trait] => { 153 T![trait] => {
195 traits::trait_def(p); 154 traits::trait_def(p);
196 m.complete(p, TRAIT); 155 m.complete(p, TRAIT);
197 } 156 }
198 157
199 // test unsafe_impl
200 // unsafe impl Foo {}
201
202 // test default_impl
203 // default impl Foo {}
204
205 // test_err default_fn_type
206 // trait T {
207 // default type T = Bar;
208 // default fn foo() {}
209 // }
210
211 // test default_fn_type
212 // impl T for Foo {
213 // default type T = Bar;
214 // default fn foo() {}
215 // }
216 T![const] => { 158 T![const] => {
217 consts::const_def(p, m); 159 consts::const_def(p, m);
218 } 160 }
219 161
220 // test unsafe_default_impl 162 // test impl
221 // unsafe default impl Foo {} 163 // impl T for S {}
222 T![impl] => { 164 T![impl] => {
223 traits::impl_def(p); 165 traits::impl_def(p);
224 m.complete(p, IMPL); 166 m.complete(p, IMPL);
225 } 167 }
226 168
227 // test existential_type
228 // existential type Foo: Fn() -> usize;
229 T![type] => { 169 T![type] => {
230 type_def(p, m); 170 type_def(p, m);
231 } 171 }
diff --git a/crates/ra_parser/src/grammar/items/traits.rs b/crates/ra_parser/src/grammar/items/traits.rs
index ef9c8ff5b..751ce65f2 100644
--- a/crates/ra_parser/src/grammar/items/traits.rs
+++ b/crates/ra_parser/src/grammar/items/traits.rs
@@ -47,7 +47,7 @@ pub(crate) fn trait_item_list(p: &mut Parser) {
47 error_block(p, "expected an item"); 47 error_block(p, "expected an item");
48 continue; 48 continue;
49 } 49 }
50 item_or_macro(p, true, ItemFlavor::Trait); 50 item_or_macro(p, true);
51 } 51 }
52 p.expect(T!['}']); 52 p.expect(T!['}']);
53 m.complete(p, ASSOC_ITEM_LIST); 53 m.complete(p, ASSOC_ITEM_LIST);
@@ -104,7 +104,7 @@ pub(crate) fn impl_item_list(p: &mut Parser) {
104 error_block(p, "expected an item"); 104 error_block(p, "expected an item");
105 continue; 105 continue;
106 } 106 }
107 item_or_macro(p, true, ItemFlavor::Mod); 107 item_or_macro(p, true);
108 } 108 }
109 p.expect(T!['}']); 109 p.expect(T!['}']);
110 m.complete(p, ASSOC_ITEM_LIST); 110 m.complete(p, ASSOC_ITEM_LIST);
diff --git a/crates/ra_parser/src/parser.rs b/crates/ra_parser/src/parser.rs
index d797f2cc9..d2487acc3 100644
--- a/crates/ra_parser/src/parser.rs
+++ b/crates/ra_parser/src/parser.rs
@@ -269,8 +269,8 @@ impl Marker {
269 pub(crate) fn complete(mut self, p: &mut Parser, kind: SyntaxKind) -> CompletedMarker { 269 pub(crate) fn complete(mut self, p: &mut Parser, kind: SyntaxKind) -> CompletedMarker {
270 self.bomb.defuse(); 270 self.bomb.defuse();
271 let idx = self.pos as usize; 271 let idx = self.pos as usize;
272 match p.events[idx] { 272 match &mut p.events[idx] {
273 Event::Start { kind: ref mut slot, .. } => { 273 Event::Start { kind: slot, .. } => {
274 *slot = kind; 274 *slot = kind;
275 } 275 }
276 _ => unreachable!(), 276 _ => unreachable!(),
@@ -320,8 +320,8 @@ impl CompletedMarker {
320 pub(crate) fn precede(self, p: &mut Parser) -> Marker { 320 pub(crate) fn precede(self, p: &mut Parser) -> Marker {
321 let new_pos = p.start(); 321 let new_pos = p.start();
322 let idx = self.start_pos as usize; 322 let idx = self.start_pos as usize;
323 match p.events[idx] { 323 match &mut p.events[idx] {
324 Event::Start { ref mut forward_parent, .. } => { 324 Event::Start { forward_parent, .. } => {
325 *forward_parent = Some(new_pos.pos - self.start_pos); 325 *forward_parent = Some(new_pos.pos - self.start_pos);
326 } 326 }
327 _ => unreachable!(), 327 _ => unreachable!(),
@@ -333,12 +333,12 @@ impl CompletedMarker {
333 pub(crate) fn undo_completion(self, p: &mut Parser) -> Marker { 333 pub(crate) fn undo_completion(self, p: &mut Parser) -> Marker {
334 let start_idx = self.start_pos as usize; 334 let start_idx = self.start_pos as usize;
335 let finish_idx = self.finish_pos as usize; 335 let finish_idx = self.finish_pos as usize;
336 match p.events[start_idx] { 336 match &mut p.events[start_idx] {
337 Event::Start { ref mut kind, forward_parent: None } => *kind = TOMBSTONE, 337 Event::Start { kind, forward_parent: None } => *kind = TOMBSTONE,
338 _ => unreachable!(), 338 _ => unreachable!(),
339 } 339 }
340 match p.events[finish_idx] { 340 match &mut p.events[finish_idx] {
341 ref mut slot @ Event::Finish => *slot = Event::tombstone(), 341 slot @ Event::Finish => *slot = Event::tombstone(),
342 _ => unreachable!(), 342 _ => unreachable!(),
343 } 343 }
344 Marker::new(self.start_pos) 344 Marker::new(self.start_pos)
diff --git a/crates/ra_proc_macro/src/process.rs b/crates/ra_proc_macro/src/process.rs
index 5bcdacb48..37dd3f496 100644
--- a/crates/ra_proc_macro/src/process.rs
+++ b/crates/ra_proc_macro/src/process.rs
@@ -90,7 +90,7 @@ impl ProcMacroProcessSrv {
90 } 90 }
91 Some(it) => it, 91 Some(it) => it,
92 }; 92 };
93 sender.send(Task { req: req.into(), result_tx }).unwrap(); 93 sender.send(Task { req, result_tx }).unwrap();
94 let res = result_rx 94 let res = result_rx
95 .recv() 95 .recv()
96 .map_err(|_| ra_tt::ExpansionError::Unknown("Proc macro thread is closed.".into()))?; 96 .map_err(|_| ra_tt::ExpansionError::Unknown("Proc macro thread is closed.".into()))?;
diff --git a/crates/ra_prof/src/memory_usage.rs b/crates/ra_prof/src/memory_usage.rs
index c2ecbd33c..83390212a 100644
--- a/crates/ra_prof/src/memory_usage.rs
+++ b/crates/ra_prof/src/memory_usage.rs
@@ -24,7 +24,7 @@ impl std::ops::Sub for MemoryUsage {
24impl MemoryUsage { 24impl MemoryUsage {
25 pub fn current() -> MemoryUsage { 25 pub fn current() -> MemoryUsage {
26 cfg_if! { 26 cfg_if! {
27 if #[cfg(target_os = "linux")] { 27 if #[cfg(all(target_os = "linux", target_env = "gnu"))] {
28 // Note: This is incredibly slow. 28 // Note: This is incredibly slow.
29 let alloc = unsafe { libc::mallinfo() }.uordblks as isize; 29 let alloc = unsafe { libc::mallinfo() }.uordblks as isize;
30 MemoryUsage { allocated: Bytes(alloc) } 30 MemoryUsage { allocated: Bytes(alloc) }
diff --git a/crates/ra_syntax/src/ast/traits.rs b/crates/ra_syntax/src/ast/traits.rs
index 3a56b1674..0bdc22d95 100644
--- a/crates/ra_syntax/src/ast/traits.rs
+++ b/crates/ra_syntax/src/ast/traits.rs
@@ -1,7 +1,7 @@
1//! Various traits that are implemented by ast nodes. 1//! Various traits that are implemented by ast nodes.
2//! 2//!
3//! The implementations are usually trivial, and live in generated.rs 3//! The implementations are usually trivial, and live in generated.rs
4use stdx::SepBy; 4use itertools::Itertools;
5 5
6use crate::{ 6use crate::{
7 ast::{self, support, AstChildren, AstNode, AstToken}, 7 ast::{self, support, AstChildren, AstNode, AstToken},
@@ -119,8 +119,7 @@ impl CommentIter {
119 // of a line in markdown. 119 // of a line in markdown.
120 line[pos..end].to_owned() 120 line[pos..end].to_owned()
121 }) 121 })
122 .sep_by("\n") 122 .join("\n");
123 .to_string();
124 123
125 if has_comments { 124 if has_comments {
126 Some(docs) 125 Some(docs)
diff --git a/crates/ra_syntax/test_data/parser/err/0043_default_const.rast b/crates/ra_syntax/test_data/parser/err/0043_default_const.rast
deleted file mode 100644
index 51ad2a846..000000000
--- a/crates/ra_syntax/test_data/parser/err/0043_default_const.rast
+++ /dev/null
@@ -1,40 +0,0 @@
1[email protected]
2 [email protected]
3 [email protected] "trait"
4 [email protected] " "
5 [email protected]
6 [email protected] "T"
7 [email protected] " "
8 [email protected]
9 [email protected] "{"
10 [email protected] "\n "
11 [email protected]
12 [email protected]
13 [email protected]
14 [email protected]
15 [email protected] "default"
16 [email protected] " "
17 [email protected]
18 [email protected] "const"
19 [email protected] " "
20 [email protected]
21 [email protected] "f"
22 [email protected] ":"
23 [email protected] " "
24 [email protected]
25 [email protected]
26 [email protected]
27 [email protected]
28 [email protected] "u8"
29 [email protected] " "
30 [email protected] "="
31 [email protected] " "
32 [email protected]
33 [email protected] "0"
34 [email protected] ";"
35 [email protected] "\n"
36 [email protected] "}"
37 [email protected] "\n"
38error 19..19: expected BANG
39error 19..19: expected `{`, `[`, `(`
40error 19..19: expected SEMICOLON
diff --git a/crates/ra_syntax/test_data/parser/err/0043_default_const.rs b/crates/ra_syntax/test_data/parser/err/0043_default_const.rs
deleted file mode 100644
index 80f15474a..000000000
--- a/crates/ra_syntax/test_data/parser/err/0043_default_const.rs
+++ /dev/null
@@ -1,3 +0,0 @@
1trait T {
2 default const f: u8 = 0;
3}
diff --git a/crates/ra_syntax/test_data/parser/err/0163_weird_blocks.rast b/crates/ra_syntax/test_data/parser/err/0043_weird_blocks.rast
index df29017e7..df29017e7 100644
--- a/crates/ra_syntax/test_data/parser/err/0163_weird_blocks.rast
+++ b/crates/ra_syntax/test_data/parser/err/0043_weird_blocks.rast
diff --git a/crates/ra_syntax/test_data/parser/err/0163_weird_blocks.rs b/crates/ra_syntax/test_data/parser/err/0043_weird_blocks.rs
index 8fa324c1a..8fa324c1a 100644
--- a/crates/ra_syntax/test_data/parser/err/0163_weird_blocks.rs
+++ b/crates/ra_syntax/test_data/parser/err/0043_weird_blocks.rs
diff --git a/crates/ra_syntax/test_data/parser/inline/err/0010_wrong_order_fns.rast b/crates/ra_syntax/test_data/parser/err/0045_item_modifiers.rast
index a6e6552a9..a6e6552a9 100644
--- a/crates/ra_syntax/test_data/parser/inline/err/0010_wrong_order_fns.rast
+++ b/crates/ra_syntax/test_data/parser/err/0045_item_modifiers.rast
diff --git a/crates/ra_syntax/test_data/parser/inline/err/0010_wrong_order_fns.rs b/crates/ra_syntax/test_data/parser/err/0045_item_modifiers.rs
index 731e58013..731e58013 100644
--- a/crates/ra_syntax/test_data/parser/inline/err/0010_wrong_order_fns.rs
+++ b/crates/ra_syntax/test_data/parser/err/0045_item_modifiers.rs
diff --git a/crates/ra_syntax/test_data/parser/inline/err/0014_default_fn_type.rast b/crates/ra_syntax/test_data/parser/inline/err/0014_default_fn_type.rast
deleted file mode 100644
index acd72094b..000000000
--- a/crates/ra_syntax/test_data/parser/inline/err/0014_default_fn_type.rast
+++ /dev/null
@@ -1,58 +0,0 @@
1[email protected]
2 [email protected]
3 [email protected] "trait"
4 [email protected] " "
5 [email protected]
6 [email protected] "T"
7 [email protected] " "
8 [email protected]
9 [email protected] "{"
10 [email protected] "\n "
11 [email protected]
12 [email protected]
13 [email protected]
14 [email protected]
15 [email protected] "default"
16 [email protected] " "
17 [email protected]
18 [email protected] "type"
19 [email protected] " "
20 [email protected]
21 [email protected] "T"
22 [email protected] " "
23 [email protected] "="
24 [email protected] " "
25 [email protected]
26 [email protected]
27 [email protected]
28 [email protected]
29 [email protected] "Bar"
30 [email protected] ";"
31 [email protected] "\n "
32 [email protected]
33 [email protected]
34 [email protected]
35 [email protected]
36 [email protected] "default"
37 [email protected] " "
38 [email protected]
39 [email protected] "fn"
40 [email protected] " "
41 [email protected]
42 [email protected] "foo"
43 [email protected]
44 [email protected] "("
45 [email protected] ")"
46 [email protected] " "
47 [email protected]
48 [email protected] "{"
49 [email protected] "}"
50 [email protected] "\n"
51 [email protected] "}"
52 [email protected] "\n"
53error 21..21: expected BANG
54error 21..21: expected `{`, `[`, `(`
55error 21..21: expected SEMICOLON
56error 47..47: expected BANG
57error 47..47: expected `{`, `[`, `(`
58error 47..47: expected SEMICOLON
diff --git a/crates/ra_syntax/test_data/parser/inline/err/0014_default_fn_type.rs b/crates/ra_syntax/test_data/parser/inline/err/0014_default_fn_type.rs
deleted file mode 100644
index 15ba8f4a8..000000000
--- a/crates/ra_syntax/test_data/parser/inline/err/0014_default_fn_type.rs
+++ /dev/null
@@ -1,4 +0,0 @@
1trait T {
2 default type T = Bar;
3 default fn foo() {}
4}
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0016_unsafe_trait.rast b/crates/ra_syntax/test_data/parser/inline/ok/0016_unsafe_trait.rast
deleted file mode 100644
index 625ab4c2d..000000000
--- a/crates/ra_syntax/test_data/parser/inline/ok/0016_unsafe_trait.rast
+++ /dev/null
@@ -1,13 +0,0 @@
1[email protected]
2 [email protected]
3 [email protected] "unsafe"
4 [email protected] " "
5 [email protected] "trait"
6 [email protected] " "
7 [email protected]
8 [email protected] "T"
9 [email protected] " "
10 [email protected]
11 [email protected] "{"
12 [email protected] "}"
13 [email protected] "\n"
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0016_unsafe_trait.rs b/crates/ra_syntax/test_data/parser/inline/ok/0016_unsafe_trait.rs
deleted file mode 100644
index 04e021550..000000000
--- a/crates/ra_syntax/test_data/parser/inline/ok/0016_unsafe_trait.rs
+++ /dev/null
@@ -1 +0,0 @@
1unsafe trait T {}
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0036_unsafe_extern_fn.rast b/crates/ra_syntax/test_data/parser/inline/ok/0036_unsafe_extern_fn.rast
deleted file mode 100644
index 293b1d64c..000000000
--- a/crates/ra_syntax/test_data/parser/inline/ok/0036_unsafe_extern_fn.rast
+++ /dev/null
@@ -1,21 +0,0 @@
1[email protected]
2 [email protected]
3 [email protected] "unsafe"
4 [email protected] " "
5 [email protected]
6 [email protected] "extern"
7 [email protected] " "
8 [email protected] "\"C\""
9 [email protected] " "
10 [email protected] "fn"
11 [email protected] " "
12 [email protected]
13 [email protected] "foo"
14 [email protected]
15 [email protected] "("
16 [email protected] ")"
17 [email protected] " "
18 [email protected]
19 [email protected] "{"
20 [email protected] "}"
21 [email protected] "\n"
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0036_unsafe_extern_fn.rs b/crates/ra_syntax/test_data/parser/inline/ok/0036_unsafe_extern_fn.rs
deleted file mode 100644
index 1295c2cd2..000000000
--- a/crates/ra_syntax/test_data/parser/inline/ok/0036_unsafe_extern_fn.rs
+++ /dev/null
@@ -1 +0,0 @@
1unsafe extern "C" fn foo() {}
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0047_unsafe_default_impl.rast b/crates/ra_syntax/test_data/parser/inline/ok/0047_unsafe_default_impl.rast
deleted file mode 100644
index d6dfa83b7..000000000
--- a/crates/ra_syntax/test_data/parser/inline/ok/0047_unsafe_default_impl.rast
+++ /dev/null
@@ -1,18 +0,0 @@
1[email protected]
2 [email protected]
3 [email protected] "unsafe"
4 [email protected] " "
5 [email protected] "default"
6 [email protected] " "
7 [email protected] "impl"
8 [email protected] " "
9 [email protected]
10 [email protected]
11 [email protected]
12 [email protected]
13 [email protected] "Foo"
14 [email protected] " "
15 [email protected]
16 [email protected] "{"
17 [email protected] "}"
18 [email protected] "\n"
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0047_unsafe_default_impl.rs b/crates/ra_syntax/test_data/parser/inline/ok/0047_unsafe_default_impl.rs
deleted file mode 100644
index 9cd6c57bd..000000000
--- a/crates/ra_syntax/test_data/parser/inline/ok/0047_unsafe_default_impl.rs
+++ /dev/null
@@ -1 +0,0 @@
1unsafe default impl Foo {}
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0057_const_fn.rast b/crates/ra_syntax/test_data/parser/inline/ok/0057_const_fn.rast
deleted file mode 100644
index 97548a5ee..000000000
--- a/crates/ra_syntax/test_data/parser/inline/ok/0057_const_fn.rast
+++ /dev/null
@@ -1,16 +0,0 @@
1[email protected]
2 [email protected]
3 [email protected] "const"
4 [email protected] " "
5 [email protected] "fn"
6 [email protected] " "
7 [email protected]
8 [email protected] "foo"
9 [email protected]
10 [email protected] "("
11 [email protected] ")"
12 [email protected] " "
13 [email protected]
14 [email protected] "{"
15 [email protected] "}"
16 [email protected] "\n"
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0057_const_fn.rs b/crates/ra_syntax/test_data/parser/inline/ok/0057_const_fn.rs
deleted file mode 100644
index 8c84d9cd7..000000000
--- a/crates/ra_syntax/test_data/parser/inline/ok/0057_const_fn.rs
+++ /dev/null
@@ -1 +0,0 @@
1const fn foo() {}
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0087_unsafe_impl.rast b/crates/ra_syntax/test_data/parser/inline/ok/0087_unsafe_impl.rast
deleted file mode 100644
index 43c09affe..000000000
--- a/crates/ra_syntax/test_data/parser/inline/ok/0087_unsafe_impl.rast
+++ /dev/null
@@ -1,16 +0,0 @@
1[email protected]
2 [email protected]
3 [email protected] "unsafe"
4 [email protected] " "
5 [email protected] "impl"
6 [email protected] " "
7 [email protected]
8 [email protected]
9 [email protected]
10 [email protected]
11 [email protected] "Foo"
12 [email protected] " "
13 [email protected]
14 [email protected] "{"
15 [email protected] "}"
16 [email protected] "\n"
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0087_unsafe_impl.rs b/crates/ra_syntax/test_data/parser/inline/ok/0087_unsafe_impl.rs
deleted file mode 100644
index 41055f41d..000000000
--- a/crates/ra_syntax/test_data/parser/inline/ok/0087_unsafe_impl.rs
+++ /dev/null
@@ -1 +0,0 @@
1unsafe impl Foo {}
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0089_extern_fn.rast b/crates/ra_syntax/test_data/parser/inline/ok/0089_extern_fn.rast
deleted file mode 100644
index 405b6a259..000000000
--- a/crates/ra_syntax/test_data/parser/inline/ok/0089_extern_fn.rast
+++ /dev/null
@@ -1,17 +0,0 @@
1[email protected]
2 [email protected]
3 [email protected]
4 [email protected] "extern"
5 [email protected] " "
6 [email protected] "fn"
7 [email protected] " "
8 [email protected]
9 [email protected] "foo"
10 [email protected]
11 [email protected] "("
12 [email protected] ")"
13 [email protected] " "
14 [email protected]
15 [email protected] "{"
16 [email protected] "}"
17 [email protected] "\n"
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0089_extern_fn.rs b/crates/ra_syntax/test_data/parser/inline/ok/0089_extern_fn.rs
deleted file mode 100644
index 394a049f0..000000000
--- a/crates/ra_syntax/test_data/parser/inline/ok/0089_extern_fn.rs
+++ /dev/null
@@ -1 +0,0 @@
1extern fn foo() {}
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0091_auto_trait.rast b/crates/ra_syntax/test_data/parser/inline/ok/0091_auto_trait.rast
deleted file mode 100644
index 0cac9ac43..000000000
--- a/crates/ra_syntax/test_data/parser/inline/ok/0091_auto_trait.rast
+++ /dev/null
@@ -1,13 +0,0 @@
1[email protected]
2 [email protected]
3 [email protected] "auto"
4 [email protected] " "
5 [email protected] "trait"
6 [email protected] " "
7 [email protected]
8 [email protected] "T"
9 [email protected] " "
10 [email protected]
11 [email protected] "{"
12 [email protected] "}"
13 [email protected] "\n"
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0091_auto_trait.rs b/crates/ra_syntax/test_data/parser/inline/ok/0091_auto_trait.rs
deleted file mode 100644
index 72adf6035..000000000
--- a/crates/ra_syntax/test_data/parser/inline/ok/0091_auto_trait.rs
+++ /dev/null
@@ -1 +0,0 @@
1auto trait T {}
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0094_unsafe_auto_trait.rast b/crates/ra_syntax/test_data/parser/inline/ok/0094_unsafe_auto_trait.rast
deleted file mode 100644
index 0ef11c682..000000000
--- a/crates/ra_syntax/test_data/parser/inline/ok/0094_unsafe_auto_trait.rast
+++ /dev/null
@@ -1,15 +0,0 @@
1[email protected]
2 [email protected]
3 [email protected] "unsafe"
4 [email protected] " "
5 [email protected] "auto"
6 [email protected] " "
7 [email protected] "trait"
8 [email protected] " "
9 [email protected]
10 [email protected] "T"
11 [email protected] " "
12 [email protected]
13 [email protected] "{"
14 [email protected] "}"
15 [email protected] "\n"
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0094_unsafe_auto_trait.rs b/crates/ra_syntax/test_data/parser/inline/ok/0094_unsafe_auto_trait.rs
deleted file mode 100644
index 03d29f324..000000000
--- a/crates/ra_syntax/test_data/parser/inline/ok/0094_unsafe_auto_trait.rs
+++ /dev/null
@@ -1 +0,0 @@
1unsafe auto trait T {}
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0097_default_impl.rast b/crates/ra_syntax/test_data/parser/inline/ok/0097_default_impl.rast
deleted file mode 100644
index 0a1b21d6e..000000000
--- a/crates/ra_syntax/test_data/parser/inline/ok/0097_default_impl.rast
+++ /dev/null
@@ -1,16 +0,0 @@
1[email protected]
2 [email protected]
3 [email protected] "default"
4 [email protected] " "
5 [email protected] "impl"
6 [email protected] " "
7 [email protected]
8 [email protected]
9 [email protected]
10 [email protected]
11 [email protected] "Foo"
12 [email protected] " "
13 [email protected]
14 [email protected] "{"
15 [email protected] "}"
16 [email protected] "\n"
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0097_default_impl.rs b/crates/ra_syntax/test_data/parser/inline/ok/0097_default_impl.rs
deleted file mode 100644
index ef6aa84a2..000000000
--- a/crates/ra_syntax/test_data/parser/inline/ok/0097_default_impl.rs
+++ /dev/null
@@ -1 +0,0 @@
1default impl Foo {}
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0098_const_unsafe_fn.rast b/crates/ra_syntax/test_data/parser/inline/ok/0098_const_unsafe_fn.rast
deleted file mode 100644
index 32a77ba49..000000000
--- a/crates/ra_syntax/test_data/parser/inline/ok/0098_const_unsafe_fn.rast
+++ /dev/null
@@ -1,18 +0,0 @@
1[email protected]
2 [email protected]
3 [email protected] "const"
4 [email protected] " "
5 [email protected] "unsafe"
6 [email protected] " "
7 [email protected] "fn"
8 [email protected] " "
9 [email protected]
10 [email protected] "foo"
11 [email protected]
12 [email protected] "("
13 [email protected] ")"
14 [email protected] " "
15 [email protected]
16 [email protected] "{"
17 [email protected] "}"
18 [email protected] "\n"
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0098_const_unsafe_fn.rs b/crates/ra_syntax/test_data/parser/inline/ok/0098_const_unsafe_fn.rs
deleted file mode 100644
index 31a1e435f..000000000
--- a/crates/ra_syntax/test_data/parser/inline/ok/0098_const_unsafe_fn.rs
+++ /dev/null
@@ -1 +0,0 @@
1const unsafe fn foo() {}
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0101_unsafe_fn.rast b/crates/ra_syntax/test_data/parser/inline/ok/0101_unsafe_fn.rast
deleted file mode 100644
index 73c94e5d4..000000000
--- a/crates/ra_syntax/test_data/parser/inline/ok/0101_unsafe_fn.rast
+++ /dev/null
@@ -1,16 +0,0 @@
1[email protected]
2 [email protected]
3 [email protected] "unsafe"
4 [email protected] " "
5 [email protected] "fn"
6 [email protected] " "
7 [email protected]
8 [email protected] "foo"
9 [email protected]
10 [email protected] "("
11 [email protected] ")"
12 [email protected] " "
13 [email protected]
14 [email protected] "{"
15 [email protected] "}"
16 [email protected] "\n"
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0101_unsafe_fn.rs b/crates/ra_syntax/test_data/parser/inline/ok/0101_unsafe_fn.rs
deleted file mode 100644
index 33cfc4cd7..000000000
--- a/crates/ra_syntax/test_data/parser/inline/ok/0101_unsafe_fn.rs
+++ /dev/null
@@ -1 +0,0 @@
1unsafe fn foo() {}
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0124_async_fn.rast b/crates/ra_syntax/test_data/parser/inline/ok/0124_async_fn.rast
deleted file mode 100644
index a7df188bd..000000000
--- a/crates/ra_syntax/test_data/parser/inline/ok/0124_async_fn.rast
+++ /dev/null
@@ -1,16 +0,0 @@
1[email protected]
2 [email protected]
3 [email protected] "async"
4 [email protected] " "
5 [email protected] "fn"
6 [email protected] " "
7 [email protected]
8 [email protected] "foo"
9 [email protected]
10 [email protected] "("
11 [email protected] ")"
12 [email protected] " "
13 [email protected]
14 [email protected] "{"
15 [email protected] "}"
16 [email protected] "\n"
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0124_async_fn.rs b/crates/ra_syntax/test_data/parser/inline/ok/0124_async_fn.rs
deleted file mode 100644
index f4adcb62b..000000000
--- a/crates/ra_syntax/test_data/parser/inline/ok/0124_async_fn.rs
+++ /dev/null
@@ -1 +0,0 @@
1async fn foo() {}
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0128_combined_fns.rast b/crates/ra_syntax/test_data/parser/inline/ok/0128_combined_fns.rast
deleted file mode 100644
index 98a20f36d..000000000
--- a/crates/ra_syntax/test_data/parser/inline/ok/0128_combined_fns.rast
+++ /dev/null
@@ -1,35 +0,0 @@
1[email protected]
2 [email protected]
3 [email protected] "async"
4 [email protected] " "
5 [email protected] "unsafe"
6 [email protected] " "
7 [email protected] "fn"
8 [email protected] " "
9 [email protected]
10 [email protected] "foo"
11 [email protected]
12 [email protected] "("
13 [email protected] ")"
14 [email protected] " "
15 [email protected]
16 [email protected] "{"
17 [email protected] "}"
18 [email protected] "\n"
19 [email protected]
20 [email protected] "const"
21 [email protected] " "
22 [email protected] "unsafe"
23 [email protected] " "
24 [email protected] "fn"
25 [email protected] " "
26 [email protected]
27 [email protected] "bar"
28 [email protected]
29 [email protected] "("
30 [email protected] ")"
31 [email protected] " "
32 [email protected]
33 [email protected] "{"
34 [email protected] "}"
35 [email protected] "\n"
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0128_combined_fns.rs b/crates/ra_syntax/test_data/parser/inline/ok/0128_combined_fns.rs
deleted file mode 100644
index 126287145..000000000
--- a/crates/ra_syntax/test_data/parser/inline/ok/0128_combined_fns.rs
+++ /dev/null
@@ -1,2 +0,0 @@
1async unsafe fn foo() {}
2const unsafe fn bar() {}
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0132_default_fn_type.rast b/crates/ra_syntax/test_data/parser/inline/ok/0132_default_fn_type.rast
deleted file mode 100644
index b8d26a53a..000000000
--- a/crates/ra_syntax/test_data/parser/inline/ok/0132_default_fn_type.rast
+++ /dev/null
@@ -1,55 +0,0 @@
1[email protected]
2 [email protected]
3 [email protected] "impl"
4 [email protected] " "
5 [email protected]
6 [email protected]
7 [email protected]
8 [email protected]
9 [email protected] "T"
10 [email protected] " "
11 [email protected] "for"
12 [email protected] " "
13 [email protected]
14 [email protected]
15 [email protected]
16 [email protected]
17 [email protected] "Foo"
18 [email protected] " "
19 [email protected]
20 [email protected] "{"
21 [email protected] "\n "
22 [email protected]
23 [email protected] "default"
24 [email protected] " "
25 [email protected] "type"
26 [email protected] " "
27 [email protected]
28 [email protected] "T"
29 [email protected] " "
30 [email protected] "="
31 [email protected] " "
32 [email protected]
33 [email protected]
34 [email protected]
35 [email protected]
36 [email protected] "Bar"
37 [email protected] ";"
38 [email protected] "\n "
39 [email protected]
40 [email protected] "default"
41 [email protected] " "
42 [email protected] "fn"
43 [email protected] " "
44 [email protected]
45 [email protected] "foo"
46 [email protected]
47 [email protected] "("
48 [email protected] ")"
49 [email protected] " "
50 [email protected]
51 [email protected] "{"
52 [email protected] "}"
53 [email protected] "\n"
54 [email protected] "}"
55 [email protected] "\n"
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0132_default_fn_type.rs b/crates/ra_syntax/test_data/parser/inline/ok/0132_default_fn_type.rs
deleted file mode 100644
index 8f5d61113..000000000
--- a/crates/ra_syntax/test_data/parser/inline/ok/0132_default_fn_type.rs
+++ /dev/null
@@ -1,4 +0,0 @@
1impl T for Foo {
2 default type T = Bar;
3 default fn foo() {}
4}
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0151_fn.rast b/crates/ra_syntax/test_data/parser/inline/ok/0151_fn.rast
new file mode 100644
index 000000000..23c4269b3
--- /dev/null
+++ b/crates/ra_syntax/test_data/parser/inline/ok/0151_fn.rast
@@ -0,0 +1,14 @@
1[email protected]
2 [email protected]
3 [email protected] "fn"
4 [email protected] " "
5 [email protected]
6 [email protected] "foo"
7 [email protected]
8 [email protected] "("
9 [email protected] ")"
10 [email protected] " "
11 [email protected]
12 [email protected] "{"
13 [email protected] "}"
14 [email protected] "\n"
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0151_fn.rs b/crates/ra_syntax/test_data/parser/inline/ok/0151_fn.rs
new file mode 100644
index 000000000..8f3b7ef11
--- /dev/null
+++ b/crates/ra_syntax/test_data/parser/inline/ok/0151_fn.rs
@@ -0,0 +1 @@
fn foo() {}
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0152_impl.rast b/crates/ra_syntax/test_data/parser/inline/ok/0152_impl.rast
new file mode 100644
index 000000000..7968cf9ff
--- /dev/null
+++ b/crates/ra_syntax/test_data/parser/inline/ok/0152_impl.rast
@@ -0,0 +1,22 @@
1[email protected]
2 [email protected]
3 [email protected] "impl"
4 [email protected] " "
5 [email protected]
6 [email protected]
7 [email protected]
8 [email protected]
9 [email protected] "T"
10 [email protected] " "
11 [email protected] "for"
12 [email protected] " "
13 [email protected]
14 [email protected]
15 [email protected]
16 [email protected]
17 [email protected] "S"
18 [email protected] " "
19 [email protected]
20 [email protected] "{"
21 [email protected] "}"
22 [email protected] "\n"
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0152_impl.rs b/crates/ra_syntax/test_data/parser/inline/ok/0152_impl.rs
new file mode 100644
index 000000000..a1a550d8a
--- /dev/null
+++ b/crates/ra_syntax/test_data/parser/inline/ok/0152_impl.rs
@@ -0,0 +1 @@
impl T for S {}
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0153_trait.rast b/crates/ra_syntax/test_data/parser/inline/ok/0153_trait.rast
new file mode 100644
index 000000000..9881e5048
--- /dev/null
+++ b/crates/ra_syntax/test_data/parser/inline/ok/0153_trait.rast
@@ -0,0 +1,11 @@
1[email protected]
2 [email protected]
3 [email protected] "trait"
4 [email protected] " "
5 [email protected]
6 [email protected] "T"
7 [email protected] " "
8 [email protected]
9 [email protected] "{"
10 [email protected] "}"
11 [email protected] "\n"
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0153_trait.rs b/crates/ra_syntax/test_data/parser/inline/ok/0153_trait.rs
new file mode 100644
index 000000000..8d183dbb5
--- /dev/null
+++ b/crates/ra_syntax/test_data/parser/inline/ok/0153_trait.rs
@@ -0,0 +1 @@
trait T {}
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0163_default_unsafe_fn.rast b/crates/ra_syntax/test_data/parser/inline/ok/0163_default_unsafe_fn.rast
deleted file mode 100644
index 1269621dc..000000000
--- a/crates/ra_syntax/test_data/parser/inline/ok/0163_default_unsafe_fn.rast
+++ /dev/null
@@ -1,40 +0,0 @@
1[email protected]
2 [email protected]
3 [email protected] "impl"
4 [email protected] " "
5 [email protected]
6 [email protected]
7 [email protected]
8 [email protected]
9 [email protected] "T"
10 [email protected] " "
11 [email protected] "for"
12 [email protected] " "
13 [email protected]
14 [email protected]
15 [email protected]
16 [email protected]
17 [email protected] "Foo"
18 [email protected] " "
19 [email protected]
20 [email protected] "{"
21 [email protected] "\n "
22 [email protected]
23 [email protected] "default"
24 [email protected] " "
25 [email protected] "unsafe"
26 [email protected] " "
27 [email protected] "fn"
28 [email protected] " "
29 [email protected]
30 [email protected] "foo"
31 [email protected]
32 [email protected] "("
33 [email protected] ")"
34 [email protected] " "
35 [email protected]
36 [email protected] "{"
37 [email protected] "}"
38 [email protected] "\n"
39 [email protected] "}"
40 [email protected] "\n"
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0163_default_unsafe_impl.rast b/crates/ra_syntax/test_data/parser/inline/ok/0163_default_unsafe_impl.rast
deleted file mode 100644
index 6bfe925af..000000000
--- a/crates/ra_syntax/test_data/parser/inline/ok/0163_default_unsafe_impl.rast
+++ /dev/null
@@ -1,18 +0,0 @@
1[email protected]
2 [email protected]
3 [email protected] "default"
4 [email protected] " "
5 [email protected] "unsafe"
6 [email protected] " "
7 [email protected] "impl"
8 [email protected] " "
9 [email protected]
10 [email protected]
11 [email protected]
12 [email protected]
13 [email protected] "Foo"
14 [email protected] " "
15 [email protected]
16 [email protected] "{"
17 [email protected] "}"
18 [email protected] "\n"
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0163_default_unsafe_impl.rs b/crates/ra_syntax/test_data/parser/inline/ok/0163_default_unsafe_impl.rs
deleted file mode 100644
index ba0998ff4..000000000
--- a/crates/ra_syntax/test_data/parser/inline/ok/0163_default_unsafe_impl.rs
+++ /dev/null
@@ -1 +0,0 @@
1default unsafe impl Foo {}
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0163_default_unsafe_item.rast b/crates/ra_syntax/test_data/parser/inline/ok/0163_default_unsafe_item.rast
new file mode 100644
index 000000000..f2e201460
--- /dev/null
+++ b/crates/ra_syntax/test_data/parser/inline/ok/0163_default_unsafe_item.rast
@@ -0,0 +1,44 @@
1[email protected]
2 [email protected]
3 [email protected] "default"
4 [email protected] " "
5 [email protected] "unsafe"
6 [email protected] " "
7 [email protected] "impl"
8 [email protected] " "
9 [email protected]
10 [email protected]
11 [email protected]
12 [email protected]
13 [email protected] "T"
14 [email protected] " "
15 [email protected] "for"
16 [email protected] " "
17 [email protected]
18 [email protected]
19 [email protected]
20 [email protected]
21 [email protected] "Foo"
22 [email protected] " "
23 [email protected]
24 [email protected] "{"
25 [email protected] "\n "
26 [email protected]
27 [email protected] "default"
28 [email protected] " "
29 [email protected] "unsafe"
30 [email protected] " "
31 [email protected] "fn"
32 [email protected] " "
33 [email protected]
34 [email protected] "foo"
35 [email protected]
36 [email protected] "("
37 [email protected] ")"
38 [email protected] " "
39 [email protected]
40 [email protected] "{"
41 [email protected] "}"
42 [email protected] "\n"
43 [email protected] "}"
44 [email protected] "\n"
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0163_default_unsafe_fn.rs b/crates/ra_syntax/test_data/parser/inline/ok/0163_default_unsafe_item.rs
index 12926cd8a..96340f84a 100644
--- a/crates/ra_syntax/test_data/parser/inline/ok/0163_default_unsafe_fn.rs
+++ b/crates/ra_syntax/test_data/parser/inline/ok/0163_default_unsafe_item.rs
@@ -1,3 +1,3 @@
1impl T for Foo { 1default unsafe impl T for Foo {
2 default unsafe fn foo() {} 2 default unsafe fn foo() {}
3} 3}
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0164_default_item.rast b/crates/ra_syntax/test_data/parser/inline/ok/0164_default_item.rast
new file mode 100644
index 000000000..9282772f3
--- /dev/null
+++ b/crates/ra_syntax/test_data/parser/inline/ok/0164_default_item.rast
@@ -0,0 +1,24 @@
1[email protected]
2 [email protected]
3 [email protected] "default"
4 [email protected] " "
5 [email protected] "impl"
6 [email protected] " "
7 [email protected]
8 [email protected]
9 [email protected]
10 [email protected]
11 [email protected] "T"
12 [email protected] " "
13 [email protected] "for"
14 [email protected] " "
15 [email protected]
16 [email protected]
17 [email protected]
18 [email protected]
19 [email protected] "Foo"
20 [email protected] " "
21 [email protected]
22 [email protected] "{"
23 [email protected] "}"
24 [email protected] "\n"
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0164_default_item.rs b/crates/ra_syntax/test_data/parser/inline/ok/0164_default_item.rs
new file mode 100644
index 000000000..a6836cbd5
--- /dev/null
+++ b/crates/ra_syntax/test_data/parser/inline/ok/0164_default_item.rs
@@ -0,0 +1 @@
default impl T for Foo {}
diff --git a/crates/ra_syntax/test_data/parser/ok/0021_extern_fn.rast b/crates/ra_syntax/test_data/parser/ok/0021_extern_fn.rast
deleted file mode 100644
index 5524efaaf..000000000
--- a/crates/ra_syntax/test_data/parser/ok/0021_extern_fn.rast
+++ /dev/null
@@ -1,56 +0,0 @@
1[email protected]
2 [email protected]
3 [email protected]
4 [email protected] "extern"
5 [email protected] " "
6 [email protected] "fn"
7 [email protected] " "
8 [email protected]
9 [email protected] "foo"
10 [email protected]
11 [email protected] "("
12 [email protected] ")"
13 [email protected] " "
14 [email protected]
15 [email protected] "{"
16 [email protected] "\n"
17 [email protected] "}"
18 [email protected] "\n\n"
19 [email protected]
20 [email protected]
21 [email protected] "extern"
22 [email protected] " "
23 [email protected] "\"C\""
24 [email protected] " "
25 [email protected] "fn"
26 [email protected] " "
27 [email protected]
28 [email protected] "bar"
29 [email protected]
30 [email protected] "("
31 [email protected] ")"
32 [email protected] " "
33 [email protected]
34 [email protected] "{"
35 [email protected] "\n"
36 [email protected] "}"
37 [email protected] "\n\n"
38 [email protected]
39 [email protected]
40 [email protected] "extern"
41 [email protected] " "
42 [email protected] "r\"D\""
43 [email protected] " "
44 [email protected] "fn"
45 [email protected] " "
46 [email protected]
47 [email protected] "baz"
48 [email protected]
49 [email protected] "("
50 [email protected] ")"
51 [email protected] " "
52 [email protected]
53 [email protected] "{"
54 [email protected] "\n"
55 [email protected] "}"
56 [email protected] "\n"
diff --git a/crates/ra_syntax/test_data/parser/ok/0021_extern_fn.rs b/crates/ra_syntax/test_data/parser/ok/0021_extern_fn.rs
deleted file mode 100644
index e929eef74..000000000
--- a/crates/ra_syntax/test_data/parser/ok/0021_extern_fn.rs
+++ /dev/null
@@ -1,8 +0,0 @@
1extern fn foo() {
2}
3
4extern "C" fn bar() {
5}
6
7extern r"D" fn baz() {
8}
diff --git a/crates/ra_syntax/test_data/parser/ok/0066_default_const.rast b/crates/ra_syntax/test_data/parser/ok/0066_default_const.rast
deleted file mode 100644
index 6246a31a6..000000000
--- a/crates/ra_syntax/test_data/parser/ok/0066_default_const.rast
+++ /dev/null
@@ -1,44 +0,0 @@
1[email protected]
2 [email protected]
3 [email protected] "impl"
4 [email protected] " "
5 [email protected]
6 [email protected]
7 [email protected]
8 [email protected]
9 [email protected] "T"
10 [email protected] " "
11 [email protected] "for"
12 [email protected] " "
13 [email protected]
14 [email protected]
15 [email protected]
16 [email protected]
17 [email protected] "Foo"
18 [email protected] " "
19 [email protected]
20 [email protected] "{"
21 [email protected] "\n "
22 [email protected]
23 [email protected] "default"
24 [email protected] " "
25 [email protected] "const"
26 [email protected] " "
27 [email protected]
28 [email protected] "f"
29 [email protected] ":"
30 [email protected] " "
31 [email protected]
32 [email protected]
33 [email protected]
34 [email protected]
35 [email protected] "u8"
36 [email protected] " "
37 [email protected] "="
38 [email protected] " "
39 [email protected]
40 [email protected] "0"
41 [email protected] ";"
42 [email protected] "\n"
43 [email protected] "}"
44 [email protected] "\n"
diff --git a/crates/ra_syntax/test_data/parser/ok/0066_default_const.rs b/crates/ra_syntax/test_data/parser/ok/0066_default_const.rs
deleted file mode 100644
index dfb3b92dc..000000000
--- a/crates/ra_syntax/test_data/parser/ok/0066_default_const.rs
+++ /dev/null
@@ -1,3 +0,0 @@
1impl T for Foo {
2 default const f: u8 = 0;
3}
diff --git a/crates/ra_syntax/test_data/parser/ok/0066_default_modifier.rast b/crates/ra_syntax/test_data/parser/ok/0066_default_modifier.rast
new file mode 100644
index 000000000..e9b57ec3b
--- /dev/null
+++ b/crates/ra_syntax/test_data/parser/ok/0066_default_modifier.rast
@@ -0,0 +1,218 @@
1[email protected]
2 [email protected]
3 [email protected] "trait"
4 [email protected] " "
5 [email protected]
6 [email protected] "T"
7 [email protected] " "
8 [email protected]
9 [email protected] "{"
10 [email protected] "\n "
11 [email protected]
12 [email protected] "default"
13 [email protected] " "
14 [email protected] "type"
15 [email protected] " "
16 [email protected]
17 [email protected] "T"
18 [email protected] " "
19 [email protected] "="
20 [email protected] " "
21 [email protected]
22 [email protected]
23 [email protected]
24 [email protected]
25 [email protected] "Bar"
26 [email protected] ";"
27 [email protected] "\n "
28 [email protected]
29 [email protected] "default"
30 [email protected] " "
31 [email protected] "const"
32 [email protected] " "
33 [email protected]
34 [email protected] "f"
35 [email protected] ":"
36 [email protected] " "
37 [email protected]
38 [email protected]
39 [email protected]
40 [email protected]
41 [email protected] "u8"
42 [email protected] " "
43 [email protected] "="
44 [email protected] " "
45 [email protected]
46 [email protected] "0"
47 [email protected] ";"
48 [email protected] "\n "
49 [email protected]
50 [email protected] "default"
51 [email protected] " "
52 [email protected] "fn"
53 [email protected] " "
54 [email protected]
55 [email protected] "foo"
56 [email protected]
57 [email protected] "("
58 [email protected] ")"
59 [email protected] " "
60 [email protected]
61 [email protected] "{"
62 [email protected] "}"
63 [email protected] "\n "
64 [email protected]
65 [email protected] "default"
66 [email protected] " "
67 [email protected] "unsafe"
68 [email protected] " "
69 [email protected] "fn"
70 [email protected] " "
71 [email protected]
72 [email protected] "bar"
73 [email protected]
74 [email protected] "("
75 [email protected] ")"
76 [email protected] " "
77 [email protected]
78 [email protected] "{"
79 [email protected] "}"
80 [email protected] "\n"
81 [email protected] "}"
82 [email protected] "\n\n"
83 [email protected]
84 [email protected] "impl"
85 [email protected] " "
86 [email protected]
87 [email protected]
88 [email protected]
89 [email protected]
90 [email protected] "T"
91 [email protected] " "
92 [email protected] "for"
93 [email protected] " "
94 [email protected]
95 [email protected]
96 [email protected]
97 [email protected]
98 [email protected] "Foo"
99 [email protected] " "
100 [email protected]
101 [email protected] "{"
102 [email protected] "\n "
103 [email protected]
104 [email protected] "default"
105 [email protected] " "
106 [email protected] "type"
107 [email protected] " "
108 [email protected]
109 [email protected] "T"
110 [email protected] " "
111 [email protected] "="
112 [email protected] " "
113 [email protected]
114 [email protected]
115 [email protected]
116 [email protected]
117 [email protected] "Bar"
118 [email protected] ";"
119 [email protected] "\n "
120 [email protected]
121 [email protected] "default"
122 [email protected] " "
123 [email protected] "const"
124 [email protected] " "
125 [email protected]
126 [email protected] "f"
127 [email protected] ":"
128 [email protected] " "
129 [email protected]
130 [email protected]
131 [email protected]
132 [email protected]
133 [email protected] "u8"
134 [email protected] " "
135 [email protected] "="
136 [email protected] " "
137 [email protected]
138 [email protected] "0"
139 [email protected] ";"
140 [email protected] "\n "
141 [email protected]
142 [email protected] "default"
143 [email protected] " "
144 [email protected] "fn"
145 [email protected] " "
146 [email protected]
147 [email protected] "foo"
148 [email protected]
149 [email protected] "("
150 [email protected] ")"
151 [email protected] " "
152 [email protected]
153 [email protected] "{"
154 [email protected] "}"
155 [email protected] "\n "
156 [email protected]
157 [email protected] "default"
158 [email protected] " "
159 [email protected] "unsafe"
160 [email protected] " "
161 [email protected] "fn"
162 [email protected] " "
163 [email protected]
164 [email protected] "bar"
165 [email protected]
166 [email protected] "("
167 [email protected] ")"
168 [email protected] " "
169 [email protected]
170 [email protected] "{"
171 [email protected] "}"
172 [email protected] "\n"
173 [email protected] "}"
174 [email protected] "\n\n"
175 [email protected]
176 [email protected] "default"
177 [email protected] " "
178 [email protected] "impl"
179 [email protected] " "
180 [email protected]
181 [email protected]
182 [email protected]
183 [email protected]
184 [email protected] "T"
185 [email protected] " "
186 [email protected] "for"
187 [email protected] " "
188 [email protected]
189 [email protected] "("
190 [email protected] ")"
191 [email protected] " "
192 [email protected]
193 [email protected] "{"
194 [email protected] "}"
195 [email protected] "\n"
196 [email protected]
197 [email protected] "default"
198 [email protected] " "
199 [email protected] "unsafe"
200 [email protected] " "
201 [email protected] "impl"
202 [email protected] " "
203 [email protected]
204 [email protected]
205 [email protected]
206 [email protected]
207 [email protected] "T"
208 [email protected] " "
209 [email protected] "for"
210 [email protected] " "
211 [email protected]
212 [email protected] "("
213 [email protected] ")"
214 [email protected] " "
215 [email protected]
216 [email protected] "{"
217 [email protected] "}"
218 [email protected] "\n"
diff --git a/crates/ra_syntax/test_data/parser/ok/0066_default_modifier.rs b/crates/ra_syntax/test_data/parser/ok/0066_default_modifier.rs
new file mode 100644
index 000000000..e443e3495
--- /dev/null
+++ b/crates/ra_syntax/test_data/parser/ok/0066_default_modifier.rs
@@ -0,0 +1,16 @@
1trait T {
2 default type T = Bar;
3 default const f: u8 = 0;
4 default fn foo() {}
5 default unsafe fn bar() {}
6}
7
8impl T for Foo {
9 default type T = Bar;
10 default const f: u8 = 0;
11 default fn foo() {}
12 default unsafe fn bar() {}
13}
14
15default impl T for () {}
16default unsafe impl T for () {}
diff --git a/crates/ra_syntax/test_data/parser/ok/0068_item_modifiers.rast b/crates/ra_syntax/test_data/parser/ok/0068_item_modifiers.rast
new file mode 100644
index 000000000..50a6d8ee9
--- /dev/null
+++ b/crates/ra_syntax/test_data/parser/ok/0068_item_modifiers.rast
@@ -0,0 +1,218 @@
1[email protected]
2 [email protected]
3 [email protected] "async"
4 [email protected] " "
5 [email protected] "fn"
6 [email protected] " "
7 [email protected]
8 [email protected] "foo"
9 [email protected]
10 [email protected] "("
11 [email protected] ")"
12 [email protected] " "
13 [email protected]
14 [email protected] "{"
15 [email protected] "}"
16 [email protected] "\n"
17 [email protected]
18 [email protected]
19 [email protected] "extern"
20 [email protected] " "
21 [email protected] "fn"
22 [email protected] " "
23 [email protected]
24 [email protected] "foo"
25 [email protected]
26 [email protected] "("
27 [email protected] ")"
28 [email protected] " "
29 [email protected]
30 [email protected] "{"
31 [email protected] "}"
32 [email protected] "\n"
33 [email protected]
34 [email protected] "const"
35 [email protected] " "
36 [email protected] "fn"
37 [email protected] " "
38 [email protected]
39 [email protected] "foo"
40 [email protected]
41 [email protected] "("
42 [email protected] ")"
43 [email protected] " "
44 [email protected]
45 [email protected] "{"
46 [email protected] "}"
47 [email protected] "\n"
48 [email protected]
49 [email protected] "const"
50 [email protected] " "
51 [email protected] "unsafe"
52 [email protected] " "
53 [email protected] "fn"
54 [email protected] " "
55 [email protected]
56 [email protected] "foo"
57 [email protected]
58 [email protected] "("
59 [email protected] ")"
60 [email protected] " "
61 [email protected]
62 [email protected] "{"
63 [email protected] "}"
64 [email protected] "\n"
65 [email protected]
66 [email protected] "unsafe"
67 [email protected] " "
68 [email protected]
69 [email protected] "extern"
70 [email protected] " "
71 [email protected] "\"C\""
72 [email protected] " "
73 [email protected] "fn"
74 [email protected] " "
75 [email protected]
76 [email protected] "foo"
77 [email protected]
78 [email protected] "("
79 [email protected] ")"
80 [email protected] " "
81 [email protected]
82 [email protected] "{"
83 [email protected] "}"
84 [email protected] "\n"
85 [email protected]
86 [email protected] "unsafe"
87 [email protected] " "
88 [email protected] "fn"
89 [email protected] " "
90 [email protected]
91 [email protected] "foo"
92 [email protected]
93 [email protected] "("
94 [email protected] ")"
95 [email protected] " "
96 [email protected]
97 [email protected] "{"
98 [email protected] "}"
99 [email protected] "\n"
100 [email protected]
101 [email protected] "async"
102 [email protected] " "
103 [email protected] "unsafe"
104 [email protected] " "
105 [email protected] "fn"
106 [email protected] " "
107 [email protected]
108 [email protected] "foo"
109 [email protected]
110 [email protected] "("
111 [email protected] ")"
112 [email protected] " "
113 [email protected]
114 [email protected] "{"
115 [email protected] "}"
116 [email protected] "\n"
117 [email protected]
118 [email protected] "const"
119 [email protected] " "
120 [email protected] "unsafe"
121 [email protected] " "
122 [email protected] "fn"
123 [email protected] " "
124 [email protected]
125 [email protected] "bar"
126 [email protected]
127 [email protected] "("
128 [email protected] ")"
129 [email protected] " "
130 [email protected]
131 [email protected] "{"
132 [email protected] "}"
133 [email protected] "\n\n"
134 [email protected]
135 [email protected] "unsafe"
136 [email protected] " "
137 [email protected] "trait"
138 [email protected] " "
139 [email protected]
140 [email protected] "T"
141 [email protected] " "
142 [email protected]
143 [email protected] "{"
144 [email protected] "}"
145 [email protected] "\n"
146 [email protected]
147 [email protected] "auto"
148 [email protected] " "
149 [email protected] "trait"
150 [email protected] " "
151 [email protected]
152 [email protected] "T"
153 [email protected] " "
154 [email protected]
155 [email protected] "{"
156 [email protected] "}"
157 [email protected] "\n"
158 [email protected]
159 [email protected] "unsafe"
160 [email protected] " "
161 [email protected] "auto"
162 [email protected] " "
163 [email protected] "trait"
164 [email protected] " "
165 [email protected]
166 [email protected] "T"
167 [email protected] " "
168 [email protected]
169 [email protected] "{"
170 [email protected] "}"
171 [email protected] "\n\n"
172 [email protected]
173 [email protected] "unsafe"
174 [email protected] " "
175 [email protected] "impl"
176 [email protected] " "
177 [email protected]
178 [email protected]
179 [email protected]
180 [email protected]
181 [email protected] "Foo"
182 [email protected] " "
183 [email protected]
184 [email protected] "{"
185 [email protected] "}"
186 [email protected] "\n"
187 [email protected]
188 [email protected] "default"
189 [email protected] " "
190 [email protected] "impl"
191 [email protected] " "
192 [email protected]
193 [email protected]
194 [email protected]
195 [email protected]
196 [email protected] "Foo"
197 [email protected] " "
198 [email protected]
199 [email protected] "{"
200 [email protected] "}"
201 [email protected] "\n"
202 [email protected]
203 [email protected] "unsafe"
204 [email protected] " "
205 [email protected] "default"
206 [email protected] " "
207 [email protected] "impl"
208 [email protected] " "
209 [email protected]
210 [email protected]
211 [email protected]
212 [email protected]
213 [email protected] "Foo"
214 [email protected] " "
215 [email protected]
216 [email protected] "{"
217 [email protected] "}"
218 [email protected] "\n"
diff --git a/crates/ra_syntax/test_data/parser/ok/0068_item_modifiers.rs b/crates/ra_syntax/test_data/parser/ok/0068_item_modifiers.rs
new file mode 100644
index 000000000..8d697c04b
--- /dev/null
+++ b/crates/ra_syntax/test_data/parser/ok/0068_item_modifiers.rs
@@ -0,0 +1,16 @@
1async fn foo() {}
2extern fn foo() {}
3const fn foo() {}
4const unsafe fn foo() {}
5unsafe extern "C" fn foo() {}
6unsafe fn foo() {}
7async unsafe fn foo() {}
8const unsafe fn bar() {}
9
10unsafe trait T {}
11auto trait T {}
12unsafe auto trait T {}
13
14unsafe impl Foo {}
15default impl Foo {}
16unsafe default impl Foo {}
diff --git a/crates/ra_text_edit/src/lib.rs b/crates/ra_text_edit/src/lib.rs
index 25554f583..d68791cf1 100644
--- a/crates/ra_text_edit/src/lib.rs
+++ b/crates/ra_text_edit/src/lib.rs
@@ -76,10 +76,6 @@ impl TextEdit {
76 self.indels.iter() 76 self.indels.iter()
77 } 77 }
78 78
79 pub fn into_iter(self) -> vec::IntoIter<Indel> {
80 self.indels.into_iter()
81 }
82
83 pub fn apply(&self, text: &mut String) { 79 pub fn apply(&self, text: &mut String) {
84 match self.len() { 80 match self.len() {
85 0 => return, 81 0 => return,
@@ -141,6 +137,15 @@ impl TextEdit {
141 } 137 }
142} 138}
143 139
140impl IntoIterator for TextEdit {
141 type Item = Indel;
142 type IntoIter = vec::IntoIter<Self::Item>;
143
144 fn into_iter(self) -> Self::IntoIter {
145 self.indels.into_iter()
146 }
147}
148
144impl TextEditBuilder { 149impl TextEditBuilder {
145 pub fn replace(&mut self, range: TextRange, replace_with: String) { 150 pub fn replace(&mut self, range: TextRange, replace_with: String) {
146 self.indels.push(Indel::replace(range, replace_with)) 151 self.indels.push(Indel::replace(range, replace_with))
diff --git a/crates/ra_tt/src/lib.rs b/crates/ra_tt/src/lib.rs
index 8faf1cc67..20c3f5eab 100644
--- a/crates/ra_tt/src/lib.rs
+++ b/crates/ra_tt/src/lib.rs
@@ -107,7 +107,7 @@ fn print_debug_subtree(f: &mut fmt::Formatter<'_>, subtree: &Subtree, level: usi
107 for (idx, child) in subtree.token_trees.iter().enumerate() { 107 for (idx, child) in subtree.token_trees.iter().enumerate() {
108 print_debug_token(f, child, level + 1)?; 108 print_debug_token(f, child, level + 1)?;
109 if idx != subtree.token_trees.len() - 1 { 109 if idx != subtree.token_trees.len() - 1 {
110 writeln!(f, "")?; 110 writeln!(f)?;
111 } 111 }
112 } 112 }
113 } 113 }
diff --git a/crates/stdx/src/lib.rs b/crates/stdx/src/lib.rs
index b65875c96..3c5027fe5 100644
--- a/crates/stdx/src/lib.rs
+++ b/crates/stdx/src/lib.rs
@@ -1,5 +1,5 @@
1//! Missing batteries for standard libraries. 1//! Missing batteries for standard libraries.
2use std::{cell::Cell, fmt, time::Instant}; 2use std::time::Instant;
3 3
4mod macros; 4mod macros;
5 5
@@ -8,69 +8,6 @@ pub fn is_ci() -> bool {
8 option_env!("CI").is_some() 8 option_env!("CI").is_some()
9} 9}
10 10
11pub trait SepBy: Sized {
12 /// Returns an `impl fmt::Display`, which joins elements via a separator.
13 fn sep_by<'a>(self, sep: &'a str) -> SepByBuilder<'a, Self>;
14}
15
16impl<I> SepBy for I
17where
18 I: Iterator,
19 I::Item: fmt::Display,
20{
21 fn sep_by<'a>(self, sep: &'a str) -> SepByBuilder<'a, Self> {
22 SepByBuilder::new(sep, self)
23 }
24}
25
26pub struct SepByBuilder<'a, I> {
27 sep: &'a str,
28 prefix: &'a str,
29 suffix: &'a str,
30 iter: Cell<Option<I>>,
31}
32
33impl<'a, I> SepByBuilder<'a, I> {
34 fn new(sep: &'a str, iter: I) -> SepByBuilder<'a, I> {
35 SepByBuilder { sep, prefix: "", suffix: "", iter: Cell::new(Some(iter)) }
36 }
37
38 pub fn prefix(mut self, prefix: &'a str) -> Self {
39 self.prefix = prefix;
40 self
41 }
42
43 pub fn suffix(mut self, suffix: &'a str) -> Self {
44 self.suffix = suffix;
45 self
46 }
47
48 /// Set both suffix and prefix.
49 pub fn surround_with(self, prefix: &'a str, suffix: &'a str) -> Self {
50 self.prefix(prefix).suffix(suffix)
51 }
52}
53
54impl<I> fmt::Display for SepByBuilder<'_, I>
55where
56 I: Iterator,
57 I::Item: fmt::Display,
58{
59 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
60 f.write_str(self.prefix)?;
61 let mut first = true;
62 for item in self.iter.take().unwrap() {
63 if !first {
64 f.write_str(self.sep)?;
65 }
66 first = false;
67 fmt::Display::fmt(&item, f)?;
68 }
69 f.write_str(self.suffix)?;
70 Ok(())
71 }
72}
73
74#[must_use] 11#[must_use]
75pub fn timeit(label: &'static str) -> impl Drop { 12pub fn timeit(label: &'static str) -> impl Drop {
76 struct Guard { 13 struct Guard {
diff --git a/xtask/tests/tidy.rs b/xtask/tests/tidy.rs
index d65a2acbc..4ff72865e 100644
--- a/xtask/tests/tidy.rs
+++ b/xtask/tests/tidy.rs
@@ -44,11 +44,26 @@ fn rust_files_are_tidy() {
44 let text = fs2::read_to_string(&path).unwrap(); 44 let text = fs2::read_to_string(&path).unwrap();
45 check_todo(&path, &text); 45 check_todo(&path, &text);
46 check_trailing_ws(&path, &text); 46 check_trailing_ws(&path, &text);
47 deny_clippy(&path, &text);
47 tidy_docs.visit(&path, &text); 48 tidy_docs.visit(&path, &text);
48 } 49 }
49 tidy_docs.finish(); 50 tidy_docs.finish();
50} 51}
51 52
53fn deny_clippy(path: &PathBuf, text: &String) {
54 if text.contains("[\u{61}llow(clippy") {
55 panic!(
56 "\n\nallowing lints is forbidden: {}.
57rust-analyzer intentionally doesn't check clippy on CI.
58You can allow lint globally via `xtask clippy`.
59See https://github.com/rust-lang/rust-clippy/issues/5537 for discussion.
60
61",
62 path.display()
63 )
64 }
65}
66
52#[test] 67#[test]
53fn check_licenses() { 68fn check_licenses() {
54 let expected = " 69 let expected = "