aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock22
-rw-r--r--crates/completion/src/render.rs3
-rw-r--r--crates/hir_expand/src/builtin_macro.rs24
-rw-r--r--crates/ide/src/display/navigation_target.rs1
-rw-r--r--crates/ide_db/src/symbol_index.rs14
-rw-r--r--crates/parser/src/grammar/items/consts.rs2
-rw-r--r--crates/profile/Cargo.toml2
-rw-r--r--crates/syntax/Cargo.toml2
-rw-r--r--crates/syntax/src/validation.rs16
-rw-r--r--crates/syntax/test_data/parser/err/0047_mutable_const_item.rast22
-rw-r--r--crates/syntax/test_data/parser/err/0047_mutable_const_item.rs1
-rw-r--r--crates/syntax/test_data/parser/ok/0024_const_item.rast23
-rw-r--r--crates/syntax/test_data/parser/ok/0024_const_item.rs1
-rw-r--r--docs/dev/README.md2
-rw-r--r--editors/code/src/net.ts16
15 files changed, 82 insertions, 69 deletions
diff --git a/Cargo.lock b/Cargo.lock
index bf1b9e417..efd1c6d33 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -275,9 +275,9 @@ checksum = "28b9d6de7f49e22cf97ad17fc4036ece69300032f45f78f30b4a4482cdc3f4a6"
275 275
276[[package]] 276[[package]]
277name = "countme" 277name = "countme"
278version = "2.0.0-pre.2" 278version = "2.0.0"
279source = "registry+https://github.com/rust-lang/crates.io-index" 279source = "registry+https://github.com/rust-lang/crates.io-index"
280checksum = "c5716604cba7c02a846ecad3f4a3fd2d2b641faccc2a24a51efb21aff0d01f35" 280checksum = "4f8038ded86523aa26c1321dfe8bb432707d0a3e2608f9d0108803727546e089"
281dependencies = [ 281dependencies = [
282 "dashmap", 282 "dashmap",
283 "once_cell", 283 "once_cell",
@@ -1400,9 +1400,9 @@ checksum = "b5eb417147ba9860a96cfe72a0b93bf88fee1744b5636ec99ab20c1aa9376581"
1400 1400
1401[[package]] 1401[[package]]
1402name = "rowan" 1402name = "rowan"
1403version = "0.12.1" 1403version = "0.12.2"
1404source = "registry+https://github.com/rust-lang/crates.io-index" 1404source = "registry+https://github.com/rust-lang/crates.io-index"
1405checksum = "24c2d78254049413f9d73495f883e7fa0b7a7d4b88468cd72a3bbbd0ad585cd1" 1405checksum = "5e05df24c035422fb2b845d66ef3542d6c4f8572eafe077175a30787b0254207"
1406dependencies = [ 1406dependencies = [
1407 "countme", 1407 "countme",
1408 "hashbrown", 1408 "hashbrown",
@@ -1663,9 +1663,9 @@ dependencies = [
1663 1663
1664[[package]] 1664[[package]]
1665name = "syn" 1665name = "syn"
1666version = "1.0.58" 1666version = "1.0.59"
1667source = "registry+https://github.com/rust-lang/crates.io-index" 1667source = "registry+https://github.com/rust-lang/crates.io-index"
1668checksum = "cc60a3d73ea6594cd712d830cc1f0390fd71542d8c8cd24e70cc54cdfd5e05d5" 1668checksum = "07cb8b1b4ebf86a89ee88cbd201b022b94138c623644d035185c84d3f41b7e66"
1669dependencies = [ 1669dependencies = [
1670 "proc-macro2", 1670 "proc-macro2",
1671 "quote", 1671 "quote",
@@ -1742,11 +1742,11 @@ dependencies = [
1742 1742
1743[[package]] 1743[[package]]
1744name = "thread_local" 1744name = "thread_local"
1745version = "1.1.0" 1745version = "1.1.1"
1746source = "registry+https://github.com/rust-lang/crates.io-index" 1746source = "registry+https://github.com/rust-lang/crates.io-index"
1747checksum = "bb9bc092d0d51e76b2b19d9d85534ffc9ec2db959a2523cdae0697e2972cd447" 1747checksum = "301bdd13d23c49672926be451130892d274d3ba0b410c18e00daa7990ff38d99"
1748dependencies = [ 1748dependencies = [
1749 "lazy_static", 1749 "once_cell",
1750] 1750]
1751 1751
1752[[package]] 1752[[package]]
@@ -1897,9 +1897,9 @@ checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c"
1897 1897
1898[[package]] 1898[[package]]
1899name = "ungrammar" 1899name = "ungrammar"
1900version = "1.9.3" 1900version = "1.10.0"
1901source = "registry+https://github.com/rust-lang/crates.io-index" 1901source = "registry+https://github.com/rust-lang/crates.io-index"
1902checksum = "f5901372c0f3a6a1a9d880aef134c8eaf5e54409343637508c0a344270b42d7b" 1902checksum = "ce24866975a8858d3a35eba845efc6b42962c5067afd2bc1a07b9ce0108d335c"
1903 1903
1904[[package]] 1904[[package]]
1905name = "unicase" 1905name = "unicase"
diff --git a/crates/completion/src/render.rs b/crates/completion/src/render.rs
index 6eb20df2b..e11b881ca 100644
--- a/crates/completion/src/render.rs
+++ b/crates/completion/src/render.rs
@@ -201,8 +201,7 @@ impl<'a> Render<'a> {
201 ScopeDef::ModuleDef(Module(..)) => CompletionItemKind::SymbolKind(SymbolKind::Module), 201 ScopeDef::ModuleDef(Module(..)) => CompletionItemKind::SymbolKind(SymbolKind::Module),
202 ScopeDef::ModuleDef(Adt(adt)) => CompletionItemKind::SymbolKind(match adt { 202 ScopeDef::ModuleDef(Adt(adt)) => CompletionItemKind::SymbolKind(match adt {
203 hir::Adt::Struct(_) => SymbolKind::Struct, 203 hir::Adt::Struct(_) => SymbolKind::Struct,
204 // FIXME: add CompletionItemKind::Union 204 hir::Adt::Union(_) => SymbolKind::Union,
205 hir::Adt::Union(_) => SymbolKind::Struct,
206 hir::Adt::Enum(_) => SymbolKind::Enum, 205 hir::Adt::Enum(_) => SymbolKind::Enum,
207 }), 206 }),
208 ScopeDef::ModuleDef(Const(..)) => CompletionItemKind::SymbolKind(SymbolKind::Const), 207 ScopeDef::ModuleDef(Const(..)) => CompletionItemKind::SymbolKind(SymbolKind::Const),
diff --git a/crates/hir_expand/src/builtin_macro.rs b/crates/hir_expand/src/builtin_macro.rs
index 80b60d59f..2806842cd 100644
--- a/crates/hir_expand/src/builtin_macro.rs
+++ b/crates/hir_expand/src/builtin_macro.rs
@@ -327,17 +327,12 @@ fn concat_expand(
327 // concat works with string and char literals, so remove any quotes. 327 // concat works with string and char literals, so remove any quotes.
328 // It also works with integer, float and boolean literals, so just use the rest 328 // It also works with integer, float and boolean literals, so just use the rest
329 // as-is. 329 // as-is.
330 330 let component = unquote_str(&it).unwrap_or_else(|| it.text.to_string());
331 text += it 331 text.push_str(&component);
332 .text 332 }
333 .trim_start_matches(|c| match c { 333 // handle boolean literals
334 'r' | '#' | '\'' | '"' => true, 334 tt::TokenTree::Leaf(tt::Leaf::Ident(id)) if i % 2 == 0 => {
335 _ => false, 335 text.push_str(id.text.as_str());
336 })
337 .trim_end_matches(|c| match c {
338 '#' | '\'' | '"' => true,
339 _ => false,
340 });
341 } 336 }
342 tt::TokenTree::Leaf(tt::Leaf::Punct(punct)) if i % 2 == 1 && punct.char == ',' => (), 337 tt::TokenTree::Leaf(tt::Leaf::Punct(punct)) if i % 2 == 1 && punct.char == ',' => (),
343 _ => { 338 _ => {
@@ -345,7 +340,6 @@ fn concat_expand(
345 } 340 }
346 } 341 }
347 } 342 }
348
349 ExpandResult { value: Some((quote!(#text), FragmentKind::Expr)), err } 343 ExpandResult { value: Some((quote!(#text), FragmentKind::Expr)), err }
350} 344}
351 345
@@ -745,12 +739,10 @@ mod tests {
745 r##" 739 r##"
746 #[rustc_builtin_macro] 740 #[rustc_builtin_macro]
747 macro_rules! concat {} 741 macro_rules! concat {}
748 concat!("foo", 0, r#"bar"#); 742 concat!("foo", r, 0, r#"bar"#, false);
749 "##, 743 "##,
750 ); 744 );
751 745
752 assert_eq!(expanded, r#""foo0bar""#); 746 assert_eq!(expanded, r#""foor0barfalse""#);
753
754 // FIXME: `true`/`false` literals don't work.
755 } 747 }
756} 748}
diff --git a/crates/ide/src/display/navigation_target.rs b/crates/ide/src/display/navigation_target.rs
index 16fa828ad..f178dd744 100644
--- a/crates/ide/src/display/navigation_target.rs
+++ b/crates/ide/src/display/navigation_target.rs
@@ -173,6 +173,7 @@ impl ToNav for FileSymbol {
173 FileSymbolKind::Const => SymbolKind::Const, 173 FileSymbolKind::Const => SymbolKind::Const,
174 FileSymbolKind::Static => SymbolKind::Static, 174 FileSymbolKind::Static => SymbolKind::Static,
175 FileSymbolKind::Macro => SymbolKind::Macro, 175 FileSymbolKind::Macro => SymbolKind::Macro,
176 FileSymbolKind::Union => SymbolKind::Union,
176 }), 177 }),
177 full_range: self.range, 178 full_range: self.range,
178 focus_range: self.name_range, 179 focus_range: self.name_range,
diff --git a/crates/ide_db/src/symbol_index.rs b/crates/ide_db/src/symbol_index.rs
index e954bd72e..9ed9568ce 100644
--- a/crates/ide_db/src/symbol_index.rs
+++ b/crates/ide_db/src/symbol_index.rs
@@ -356,15 +356,16 @@ pub struct FileSymbol {
356 356
357#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)] 357#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
358pub enum FileSymbolKind { 358pub enum FileSymbolKind {
359 Const,
360 Enum,
359 Function, 361 Function,
362 Macro,
363 Module,
364 Static,
360 Struct, 365 Struct,
361 Enum,
362 Trait, 366 Trait,
363 Module,
364 TypeAlias, 367 TypeAlias,
365 Const, 368 Union,
366 Static,
367 Macro,
368} 369}
369 370
370impl FileSymbolKind { 371impl FileSymbolKind {
@@ -375,6 +376,7 @@ impl FileSymbolKind {
375 | FileSymbolKind::Enum 376 | FileSymbolKind::Enum
376 | FileSymbolKind::Trait 377 | FileSymbolKind::Trait
377 | FileSymbolKind::TypeAlias 378 | FileSymbolKind::TypeAlias
379 | FileSymbolKind::Union
378 ) 380 )
379 } 381 }
380} 382}
@@ -425,6 +427,7 @@ fn to_symbol(node: &SyntaxNode) -> Option<(SmolStr, SyntaxNodePtr, TextRange)> {
425 ast::Const(it) => decl(it), 427 ast::Const(it) => decl(it),
426 ast::Static(it) => decl(it), 428 ast::Static(it) => decl(it),
427 ast::MacroRules(it) => decl(it), 429 ast::MacroRules(it) => decl(it),
430 ast::Union(it) => decl(it),
428 _ => None, 431 _ => None,
429 } 432 }
430 } 433 }
@@ -443,6 +446,7 @@ fn to_file_symbol(node: &SyntaxNode, file_id: FileId) -> Option<FileSymbol> {
443 CONST => FileSymbolKind::Const, 446 CONST => FileSymbolKind::Const,
444 STATIC => FileSymbolKind::Static, 447 STATIC => FileSymbolKind::Static,
445 MACRO_RULES => FileSymbolKind::Macro, 448 MACRO_RULES => FileSymbolKind::Macro,
449 UNION => FileSymbolKind::Union,
446 kind => unreachable!("{:?}", kind), 450 kind => unreachable!("{:?}", kind),
447 }, 451 },
448 range: node.text_range(), 452 range: node.text_range(),
diff --git a/crates/parser/src/grammar/items/consts.rs b/crates/parser/src/grammar/items/consts.rs
index eb7d1f828..12130df40 100644
--- a/crates/parser/src/grammar/items/consts.rs
+++ b/crates/parser/src/grammar/items/consts.rs
@@ -13,7 +13,7 @@ pub(super) fn konst(p: &mut Parser, m: Marker) {
13fn const_or_static(p: &mut Parser, m: Marker, kw: SyntaxKind, def: SyntaxKind) { 13fn const_or_static(p: &mut Parser, m: Marker, kw: SyntaxKind, def: SyntaxKind) {
14 assert!(p.at(kw)); 14 assert!(p.at(kw));
15 p.bump(kw); 15 p.bump(kw);
16 p.eat(T![mut]); // FIXME: validator to forbid const mut 16 p.eat(T![mut]);
17 17
18 // Allow `_` in place of an identifier in a `const`. 18 // Allow `_` in place of an identifier in a `const`.
19 let is_const_underscore = kw == T![const] && p.eat(T![_]); 19 let is_const_underscore = kw == T![const] && p.eat(T![_]);
diff --git a/crates/profile/Cargo.toml b/crates/profile/Cargo.toml
index cc7da27f7..4dd9acc98 100644
--- a/crates/profile/Cargo.toml
+++ b/crates/profile/Cargo.toml
@@ -14,7 +14,7 @@ once_cell = "1.3.1"
14cfg-if = "1" 14cfg-if = "1"
15libc = "0.2.73" 15libc = "0.2.73"
16la-arena = { version = "0.2.0", path = "../../lib/arena" } 16la-arena = { version = "0.2.0", path = "../../lib/arena" }
17countme = { version = "2.0.0-pre.2", features = ["enable"] } 17countme = { version = "2.0.0", features = ["enable"] }
18jemalloc-ctl = { version = "0.3.3", optional = true } 18jemalloc-ctl = { version = "0.3.3", optional = true }
19 19
20[target.'cfg(target_os = "linux")'.dependencies] 20[target.'cfg(target_os = "linux")'.dependencies]
diff --git a/crates/syntax/Cargo.toml b/crates/syntax/Cargo.toml
index 24298fbfa..e70fbba9c 100644
--- a/crates/syntax/Cargo.toml
+++ b/crates/syntax/Cargo.toml
@@ -12,7 +12,7 @@ doctest = false
12 12
13[dependencies] 13[dependencies]
14itertools = "0.10.0" 14itertools = "0.10.0"
15rowan = "0.12" 15rowan = "0.12.2"
16rustc_lexer = { version = "700.0.0", package = "rustc-ap-rustc_lexer" } 16rustc_lexer = { version = "700.0.0", package = "rustc-ap-rustc_lexer" }
17rustc-hash = "1.1.0" 17rustc-hash = "1.1.0"
18arrayvec = "0.5.1" 18arrayvec = "0.5.1"
diff --git a/crates/syntax/src/validation.rs b/crates/syntax/src/validation.rs
index 7694e8834..3e216fb70 100644
--- a/crates/syntax/src/validation.rs
+++ b/crates/syntax/src/validation.rs
@@ -1,4 +1,6 @@
1//! FIXME: write short doc here 1//! This module implements syntax validation that the parser doesn't handle.
2//!
3//! A failed validation emits a diagnostic.
2 4
3mod block; 5mod block;
4 6
@@ -92,6 +94,7 @@ pub(crate) fn validate(root: &SyntaxNode) -> Vec<SyntaxError> {
92 match_ast! { 94 match_ast! {
93 match node { 95 match node {
94 ast::Literal(it) => validate_literal(it, &mut errors), 96 ast::Literal(it) => validate_literal(it, &mut errors),
97 ast::Const(it) => validate_const(it, &mut errors),
95 ast::BlockExpr(it) => block::validate_block_expr(it, &mut errors), 98 ast::BlockExpr(it) => block::validate_block_expr(it, &mut errors),
96 ast::FieldExpr(it) => validate_numeric_name(it.name_ref(), &mut errors), 99 ast::FieldExpr(it) => validate_numeric_name(it.name_ref(), &mut errors),
97 ast::RecordExprField(it) => validate_numeric_name(it.name_ref(), &mut errors), 100 ast::RecordExprField(it) => validate_numeric_name(it.name_ref(), &mut errors),
@@ -362,3 +365,14 @@ fn validate_macro_rules(mac: ast::MacroRules, errors: &mut Vec<SyntaxError>) {
362 )); 365 ));
363 } 366 }
364} 367}
368
369fn validate_const(const_: ast::Const, errors: &mut Vec<SyntaxError>) {
370 if let Some(mut_token) = const_
371 .const_token()
372 .and_then(|t| t.next_token())
373 .and_then(|t| algo::skip_trivia_token(t, Direction::Next))
374 .filter(|t| t.kind() == T![mut])
375 {
376 errors.push(SyntaxError::new("const globals cannot be mutable", mut_token.text_range()));
377 }
378}
diff --git a/crates/syntax/test_data/parser/err/0047_mutable_const_item.rast b/crates/syntax/test_data/parser/err/0047_mutable_const_item.rast
new file mode 100644
index 000000000..c7eb312c9
--- /dev/null
+++ b/crates/syntax/test_data/parser/err/0047_mutable_const_item.rast
@@ -0,0 +1,22 @@
1[email protected]
2 [email protected]
3 [email protected] "const"
4 [email protected] " "
5 [email protected] "mut"
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] " "
17 [email protected]
18 [email protected] "("
19 [email protected] ")"
20 [email protected] ";"
21 [email protected] "\n"
22error 6..9: const globals cannot be mutable
diff --git a/crates/syntax/test_data/parser/err/0047_mutable_const_item.rs b/crates/syntax/test_data/parser/err/0047_mutable_const_item.rs
new file mode 100644
index 000000000..b34336f3f
--- /dev/null
+++ b/crates/syntax/test_data/parser/err/0047_mutable_const_item.rs
@@ -0,0 +1 @@
const mut FOO: () = ();
diff --git a/crates/syntax/test_data/parser/ok/0024_const_item.rast b/crates/syntax/test_data/parser/ok/0024_const_item.rast
index dd1b9c9a0..b89ed6f98 100644
--- a/crates/syntax/test_data/parser/ok/0024_const_item.rast
+++ b/crates/syntax/test_data/parser/ok/0024_const_item.rast
@@ -1,4 +1,4 @@
1SOURCE_FILE@0..64 1SOURCE_FILE@0..39
2 [email protected] 2 [email protected]
3 [email protected] "const" 3 [email protected] "const"
4 [email protected] " " 4 [email protected] " "
@@ -36,24 +36,3 @@ [email protected]
36 [email protected] "92" 36 [email protected] "92"
37 [email protected] ";" 37 [email protected] ";"
38 [email protected] "\n" 38 [email protected] "\n"
39 [email protected]
40 [email protected] "const"
41 [email protected] " "
42 [email protected] "mut"
43 [email protected] " "
44 [email protected]
45 [email protected] "BAR"
46 [email protected] ":"
47 [email protected] " "
48 [email protected]
49 [email protected]
50 [email protected]
51 [email protected]
52 [email protected] "u32"
53 [email protected] " "
54 [email protected] "="
55 [email protected] " "
56 [email protected]
57 [email protected] "62"
58 [email protected] ";"
59 [email protected] "\n"
diff --git a/crates/syntax/test_data/parser/ok/0024_const_item.rs b/crates/syntax/test_data/parser/ok/0024_const_item.rs
index a806a209d..1f2ffa0da 100644
--- a/crates/syntax/test_data/parser/ok/0024_const_item.rs
+++ b/crates/syntax/test_data/parser/ok/0024_const_item.rs
@@ -1,3 +1,2 @@
1const _: u32 = 0; 1const _: u32 = 0;
2const FOO: u32 = 92; 2const FOO: u32 = 92;
3const mut BAR: u32 = 62;
diff --git a/docs/dev/README.md b/docs/dev/README.md
index 24197b332..6a6ba1443 100644
--- a/docs/dev/README.md
+++ b/docs/dev/README.md
@@ -212,7 +212,7 @@ To log all communication between the server and the client, there are two choice
212 212
213* you can log on the server side, by running something like 213* you can log on the server side, by running something like
214 ``` 214 ```
215 env RA_LOG=gen_lsp_server=trace code . 215 env RA_LOG=lsp_server=debug code .
216 ``` 216 ```
217 217
218* you can log on the client side, by enabling `"rust-analyzer.trace.server": 218* you can log on the client side, by enabling `"rust-analyzer.trace.server":
diff --git a/editors/code/src/net.ts b/editors/code/src/net.ts
index 1ab21e726..3e50d352c 100644
--- a/editors/code/src/net.ts
+++ b/editors/code/src/net.ts
@@ -99,13 +99,15 @@ export async function download(opts: DownloadOpts) {
99 async (progress, _cancellationToken) => { 99 async (progress, _cancellationToken) => {
100 let lastPercentage = 0; 100 let lastPercentage = 0;
101 await downloadFile(opts.url, tempFile, opts.mode, !!opts.gunzip, (readBytes, totalBytes) => { 101 await downloadFile(opts.url, tempFile, opts.mode, !!opts.gunzip, (readBytes, totalBytes) => {
102 const newPercentage = (readBytes / totalBytes) * 100; 102 const newPercentage = Math.round((readBytes / totalBytes) * 100);
103 progress.report({ 103 if (newPercentage !== lastPercentage) {
104 message: newPercentage.toFixed(0) + "%", 104 progress.report({
105 increment: newPercentage - lastPercentage 105 message: `${newPercentage.toFixed(0)}%`,
106 }); 106 increment: newPercentage - lastPercentage
107 107 });
108 lastPercentage = newPercentage; 108
109 lastPercentage = newPercentage;
110 }
109 }); 111 });
110 } 112 }
111 ); 113 );