diff options
Diffstat (limited to 'crates')
5 files changed, 73 insertions, 24 deletions
diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs index bc942ae01..ab8fb9f6e 100644 --- a/crates/ra_parser/src/grammar/expressions/atom.rs +++ b/crates/ra_parser/src/grammar/expressions/atom.rs | |||
@@ -414,6 +414,8 @@ pub(crate) fn match_arm_list(p: &mut Parser) { | |||
414 | // X | Y if Z => (), | 414 | // X | Y if Z => (), |
415 | // | X | Y if Z => (), | 415 | // | X | Y if Z => (), |
416 | // | X => (), | 416 | // | X => (), |
417 | // box X => (), | ||
418 | // Some(box X) => (), | ||
417 | // }; | 419 | // }; |
418 | // } | 420 | // } |
419 | fn match_arm(p: &mut Parser) -> BlockLike { | 421 | fn match_arm(p: &mut Parser) -> BlockLike { |
diff --git a/crates/ra_parser/src/grammar/patterns.rs b/crates/ra_parser/src/grammar/patterns.rs index df6000707..1f6a6fd48 100644 --- a/crates/ra_parser/src/grammar/patterns.rs +++ b/crates/ra_parser/src/grammar/patterns.rs | |||
@@ -2,7 +2,7 @@ use super::*; | |||
2 | 2 | ||
3 | pub(super) const PATTERN_FIRST: TokenSet = expressions::LITERAL_FIRST | 3 | pub(super) const PATTERN_FIRST: TokenSet = expressions::LITERAL_FIRST |
4 | .union(paths::PATH_FIRST) | 4 | .union(paths::PATH_FIRST) |
5 | .union(token_set![REF_KW, MUT_KW, L_PAREN, L_BRACK, AMP, UNDERSCORE, MINUS]); | 5 | .union(token_set![BOX_KW, REF_KW, MUT_KW, L_PAREN, L_BRACK, AMP, UNDERSCORE, MINUS]); |
6 | 6 | ||
7 | pub(super) fn pattern(p: &mut Parser) { | 7 | pub(super) fn pattern(p: &mut Parser) { |
8 | pattern_r(p, PAT_RECOVERY_SET); | 8 | pattern_r(p, PAT_RECOVERY_SET); |
diff --git a/crates/ra_project_model/src/sysroot.rs b/crates/ra_project_model/src/sysroot.rs index 2a7927f7e..0c27d4f4b 100644 --- a/crates/ra_project_model/src/sysroot.rs +++ b/crates/ra_project_model/src/sysroot.rs | |||
@@ -1,4 +1,5 @@ | |||
1 | use std::{ | 1 | use std::{ |
2 | env, | ||
2 | path::{Path, PathBuf}, | 3 | path::{Path, PathBuf}, |
3 | process::Command, | 4 | process::Command, |
4 | }; | 5 | }; |
@@ -33,21 +34,13 @@ impl Sysroot { | |||
33 | } | 34 | } |
34 | 35 | ||
35 | pub fn discover(cargo_toml: &Path) -> Result<Sysroot> { | 36 | pub fn discover(cargo_toml: &Path) -> Result<Sysroot> { |
36 | let rustc_output = Command::new("rustc") | 37 | let src = try_find_src_path(cargo_toml)?; |
37 | .current_dir(cargo_toml.parent().unwrap()) | 38 | |
38 | .args(&["--print", "sysroot"]) | ||
39 | .output()?; | ||
40 | if !rustc_output.status.success() { | ||
41 | Err("failed to locate sysroot")? | ||
42 | } | ||
43 | let stdout = String::from_utf8(rustc_output.stdout)?; | ||
44 | let sysroot_path = Path::new(stdout.trim()); | ||
45 | let src = sysroot_path.join("lib/rustlib/src/rust/src"); | ||
46 | if !src.exists() { | 39 | if !src.exists() { |
47 | Err(format!( | 40 | Err(format!( |
48 | "can't load standard library from sysroot\n\ | 41 | "can't load standard library from sysroot\n\ |
49 | {:?}\n\ | 42 | {:?}\n\ |
50 | try running `rustup component add rust-src`", | 43 | try running `rustup component add rust-src` or set `RUST_SRC_PATH`", |
51 | src, | 44 | src, |
52 | ))?; | 45 | ))?; |
53 | } | 46 | } |
@@ -83,6 +76,23 @@ impl Sysroot { | |||
83 | } | 76 | } |
84 | } | 77 | } |
85 | 78 | ||
79 | fn try_find_src_path(cargo_toml: &Path) -> Result<PathBuf> { | ||
80 | if let Ok(path) = env::var("RUST_SRC_PATH") { | ||
81 | return Ok(path.into()); | ||
82 | } | ||
83 | |||
84 | let rustc_output = Command::new("rustc") | ||
85 | .current_dir(cargo_toml.parent().unwrap()) | ||
86 | .args(&["--print", "sysroot"]) | ||
87 | .output()?; | ||
88 | if !rustc_output.status.success() { | ||
89 | Err("failed to locate sysroot")?; | ||
90 | } | ||
91 | let stdout = String::from_utf8(rustc_output.stdout)?; | ||
92 | let sysroot_path = Path::new(stdout.trim()); | ||
93 | Ok(sysroot_path.join("lib/rustlib/src/rust/src")) | ||
94 | } | ||
95 | |||
86 | impl SysrootCrate { | 96 | impl SysrootCrate { |
87 | pub fn name(self, sysroot: &Sysroot) -> &str { | 97 | pub fn name(self, sysroot: &Sysroot) -> &str { |
88 | &sysroot.crates[self].name | 98 | &sysroot.crates[self].name |
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0066_match_arm.rs b/crates/ra_syntax/test_data/parser/inline/ok/0066_match_arm.rs index 9e009e24f..2d476278d 100644 --- a/crates/ra_syntax/test_data/parser/inline/ok/0066_match_arm.rs +++ b/crates/ra_syntax/test_data/parser/inline/ok/0066_match_arm.rs | |||
@@ -5,5 +5,7 @@ fn foo() { | |||
5 | X | Y if Z => (), | 5 | X | Y if Z => (), |
6 | | X | Y if Z => (), | 6 | | X | Y if Z => (), |
7 | | X => (), | 7 | | X => (), |
8 | box X => (), | ||
9 | Some(box X) => (), | ||
8 | }; | 10 | }; |
9 | } | 11 | } |
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0066_match_arm.txt b/crates/ra_syntax/test_data/parser/inline/ok/0066_match_arm.txt index 041e7179e..28d501459 100644 --- a/crates/ra_syntax/test_data/parser/inline/ok/0066_match_arm.txt +++ b/crates/ra_syntax/test_data/parser/inline/ok/0066_match_arm.txt | |||
@@ -1,5 +1,5 @@ | |||
1 | SOURCE_FILE@[0; 167) | 1 | SOURCE_FILE@[0; 215) |
2 | FN_DEF@[0; 166) | 2 | FN_DEF@[0; 214) |
3 | FN_KW@[0; 2) "fn" | 3 | FN_KW@[0; 2) "fn" |
4 | WHITESPACE@[2; 3) " " | 4 | WHITESPACE@[2; 3) " " |
5 | NAME@[3; 6) | 5 | NAME@[3; 6) |
@@ -8,18 +8,18 @@ SOURCE_FILE@[0; 167) | |||
8 | L_PAREN@[6; 7) "(" | 8 | L_PAREN@[6; 7) "(" |
9 | R_PAREN@[7; 8) ")" | 9 | R_PAREN@[7; 8) ")" |
10 | WHITESPACE@[8; 9) " " | 10 | WHITESPACE@[8; 9) " " |
11 | BLOCK@[9; 166) | 11 | BLOCK@[9; 214) |
12 | L_CURLY@[9; 10) "{" | 12 | L_CURLY@[9; 10) "{" |
13 | WHITESPACE@[10; 15) "\n " | 13 | WHITESPACE@[10; 15) "\n " |
14 | EXPR_STMT@[15; 164) | 14 | EXPR_STMT@[15; 212) |
15 | MATCH_EXPR@[15; 163) | 15 | MATCH_EXPR@[15; 211) |
16 | MATCH_KW@[15; 20) "match" | 16 | MATCH_KW@[15; 20) "match" |
17 | WHITESPACE@[20; 21) " " | 17 | WHITESPACE@[20; 21) " " |
18 | TUPLE_EXPR@[21; 23) | 18 | TUPLE_EXPR@[21; 23) |
19 | L_PAREN@[21; 22) "(" | 19 | L_PAREN@[21; 22) "(" |
20 | R_PAREN@[22; 23) ")" | 20 | R_PAREN@[22; 23) ")" |
21 | WHITESPACE@[23; 24) " " | 21 | WHITESPACE@[23; 24) " " |
22 | MATCH_ARM_LIST@[24; 163) | 22 | MATCH_ARM_LIST@[24; 211) |
23 | L_CURLY@[24; 25) "{" | 23 | L_CURLY@[24; 25) "{" |
24 | WHITESPACE@[25; 34) "\n " | 24 | WHITESPACE@[25; 34) "\n " |
25 | MATCH_ARM@[34; 41) | 25 | MATCH_ARM@[34; 41) |
@@ -141,9 +141,44 @@ SOURCE_FILE@[0; 167) | |||
141 | L_PAREN@[154; 155) "(" | 141 | L_PAREN@[154; 155) "(" |
142 | R_PAREN@[155; 156) ")" | 142 | R_PAREN@[155; 156) ")" |
143 | COMMA@[156; 157) "," | 143 | COMMA@[156; 157) "," |
144 | WHITESPACE@[157; 162) "\n " | 144 | WHITESPACE@[157; 166) "\n " |
145 | R_CURLY@[162; 163) "}" | 145 | MATCH_ARM@[166; 177) |
146 | SEMI@[163; 164) ";" | 146 | BIND_PAT@[166; 171) |
147 | WHITESPACE@[164; 165) "\n" | 147 | BOX_KW@[166; 169) "box" |
148 | R_CURLY@[165; 166) "}" | 148 | WHITESPACE@[169; 170) " " |
149 | WHITESPACE@[166; 167) "\n" | 149 | NAME@[170; 171) |
150 | IDENT@[170; 171) "X" | ||
151 | WHITESPACE@[171; 172) " " | ||
152 | FAT_ARROW@[172; 174) "=>" | ||
153 | WHITESPACE@[174; 175) " " | ||
154 | TUPLE_EXPR@[175; 177) | ||
155 | L_PAREN@[175; 176) "(" | ||
156 | R_PAREN@[176; 177) ")" | ||
157 | COMMA@[177; 178) "," | ||
158 | WHITESPACE@[178; 187) "\n " | ||
159 | MATCH_ARM@[187; 204) | ||
160 | TUPLE_STRUCT_PAT@[187; 198) | ||
161 | PATH@[187; 191) | ||
162 | PATH_SEGMENT@[187; 191) | ||
163 | NAME_REF@[187; 191) | ||
164 | IDENT@[187; 191) "Some" | ||
165 | L_PAREN@[191; 192) "(" | ||
166 | BIND_PAT@[192; 197) | ||
167 | BOX_KW@[192; 195) "box" | ||
168 | WHITESPACE@[195; 196) " " | ||
169 | NAME@[196; 197) | ||
170 | IDENT@[196; 197) "X" | ||
171 | R_PAREN@[197; 198) ")" | ||
172 | WHITESPACE@[198; 199) " " | ||
173 | FAT_ARROW@[199; 201) "=>" | ||
174 | WHITESPACE@[201; 202) " " | ||
175 | TUPLE_EXPR@[202; 204) | ||
176 | L_PAREN@[202; 203) "(" | ||
177 | R_PAREN@[203; 204) ")" | ||
178 | COMMA@[204; 205) "," | ||
179 | WHITESPACE@[205; 210) "\n " | ||
180 | R_CURLY@[210; 211) "}" | ||
181 | SEMI@[211; 212) ";" | ||
182 | WHITESPACE@[212; 213) "\n" | ||
183 | R_CURLY@[213; 214) "}" | ||
184 | WHITESPACE@[214; 215) "\n" | ||