aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-09-27 03:58:26 +0100
committerGitHub <[email protected]>2019-09-27 03:58:26 +0100
commit2b69c84396cf376b496e7de3c954400e51b5fc24 (patch)
tree385a5a3cb167877096534bad2a7c3efdee3c9c1d /crates/ra_syntax
parentfc218ec0d04577e33db509e956a044293c12ea67 (diff)
parentedadeb95be16a69175e94a0e211ae9bb74267abb (diff)
Merge #1815
1815: Support correct `$crate` expansion in macros r=uHOOCCOOHu a=uHOOCCOOHu This PR makes normal use cases of `$crate` from macros work as expected. It makes more macros from `std` work. Type inference works well with `panic`, `unimplemented`, `format`, and maybe more. Sadly that `vec![1, 2, 3]` still not works, but it is not longer an issue about macro. Screenshot: ![Screenshot_20190927_022136](https://user-images.githubusercontent.com/14816024/65714465-b4568f80-e0cd-11e9-8043-dd44c2ae8040.png) Co-authored-by: uHOOCCOOHu <[email protected]>
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r--crates/ra_syntax/src/ast/extensions.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs
index 5f7e9f5b1..0433edb84 100644
--- a/crates/ra_syntax/src/ast/extensions.rs
+++ b/crates/ra_syntax/src/ast/extensions.rs
@@ -21,6 +21,16 @@ impl ast::NameRef {
21 pub fn text(&self) -> &SmolStr { 21 pub fn text(&self) -> &SmolStr {
22 text_of_first_token(self.syntax()) 22 text_of_first_token(self.syntax())
23 } 23 }
24
25 pub fn as_tuple_field(&self) -> Option<usize> {
26 self.syntax().children_with_tokens().find_map(|c| {
27 if c.kind() == SyntaxKind::INT_NUMBER {
28 c.as_token().and_then(|tok| tok.text().as_str().parse().ok())
29 } else {
30 None
31 }
32 })
33 }
24} 34}
25 35
26fn text_of_first_token(node: &SyntaxNode) -> &SmolStr { 36fn text_of_first_token(node: &SyntaxNode) -> &SmolStr {