From b6560e3ebb80a7a96b3c3598ecba232f799fe93f Mon Sep 17 00:00:00 2001 From: adamrk Date: Tue, 28 Apr 2020 10:23:45 +0200 Subject: Treat comments beginning with four slashes as regular line comments --- crates/ra_syntax/src/ast.rs | 15 +++++++++++++++ crates/ra_syntax/src/ast/tokens.rs | 1 + 2 files changed, 16 insertions(+) (limited to 'crates/ra_syntax') diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index 7fca5661e..a716e525b 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs @@ -242,6 +242,21 @@ fn test_comments_preserve_trailing_whitespace() { ); } +#[test] +fn test_four_slash_line_comment() { + let file = SourceFile::parse( + r#" + //// too many slashes to be a doc comment + /// doc comment + mod foo {} + "#, + ) + .ok() + .unwrap(); + let module = file.syntax().descendants().find_map(Module::cast).unwrap(); + assert_eq!("doc comment", module.doc_comment_text().unwrap()); +} + #[test] fn test_where_predicates() { fn assert_bound(text: &str, bound: Option) { diff --git a/crates/ra_syntax/src/ast/tokens.rs b/crates/ra_syntax/src/ast/tokens.rs index 3865729b8..481813e38 100644 --- a/crates/ra_syntax/src/ast/tokens.rs +++ b/crates/ra_syntax/src/ast/tokens.rs @@ -48,6 +48,7 @@ pub enum CommentPlacement { const COMMENT_PREFIX_TO_KIND: &[(&str, CommentKind)] = { use {CommentPlacement::*, CommentShape::*}; &[ + ("////", CommentKind { shape: Line, doc: None }), ("///", CommentKind { shape: Line, doc: Some(Outer) }), ("//!", CommentKind { shape: Line, doc: Some(Inner) }), ("/**", CommentKind { shape: Block, doc: Some(Outer) }), -- cgit v1.2.3 From 0bd7d81805df16c8d1f200b13e485f6dda22f104 Mon Sep 17 00:00:00 2001 From: adamrk Date: Tue, 28 Apr 2020 21:13:37 +0200 Subject: Fix comment prefix method for four slash comments --- crates/ra_syntax/src/ast/tokens.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'crates/ra_syntax') diff --git a/crates/ra_syntax/src/ast/tokens.rs b/crates/ra_syntax/src/ast/tokens.rs index 481813e38..74906d8a6 100644 --- a/crates/ra_syntax/src/ast/tokens.rs +++ b/crates/ra_syntax/src/ast/tokens.rs @@ -13,7 +13,12 @@ impl Comment { } pub fn prefix(&self) -> &'static str { - prefix_by_kind(self.kind()) + for (prefix, k) in COMMENT_PREFIX_TO_KIND.iter() { + if *k == self.kind() && self.text().starts_with(prefix) { + return prefix; + } + } + unreachable!() } } @@ -70,15 +75,6 @@ fn kind_by_prefix(text: &str) -> CommentKind { panic!("bad comment text: {:?}", text) } -fn prefix_by_kind(kind: CommentKind) -> &'static str { - for (prefix, k) in COMMENT_PREFIX_TO_KIND.iter() { - if *k == kind { - return prefix; - } - } - unreachable!() -} - impl Whitespace { pub fn spans_multiple_lines(&self) -> bool { let text = self.text(); -- cgit v1.2.3 From b4dd4752570d5f1ba24f7ffda69be4b1c935cd04 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 29 Apr 2020 14:49:54 +0200 Subject: More principled approach for finding From trait --- crates/ra_syntax/src/ast/make.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'crates/ra_syntax') diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs index ee0f5cc40..492088353 100644 --- a/crates/ra_syntax/src/ast/make.rs +++ b/crates/ra_syntax/src/ast/make.rs @@ -22,8 +22,7 @@ pub fn path_unqualified(segment: ast::PathSegment) -> ast::Path { pub fn path_qualified(qual: ast::Path, segment: ast::PathSegment) -> ast::Path { path_from_text(&format!("{}::{}", qual, segment)) } - -pub fn path_from_text(text: &str) -> ast::Path { +fn path_from_text(text: &str) -> ast::Path { ast_from_text(text) } -- cgit v1.2.3 From 0af727da91e7ff3c8ed5518cb7e005e8d4f939b0 Mon Sep 17 00:00:00 2001 From: John Renner Date: Mon, 27 Apr 2020 10:02:47 -0700 Subject: Validate the location of `crate` in paths --- crates/ra_syntax/src/ast/generated/nodes.rs | 1 + crates/ra_syntax/src/validation.rs | 39 +++++++++++ .../parser/err/0040_illegal_crate_kw_location.rast | 76 ++++++++++++++++++++++ .../parser/err/0040_illegal_crate_kw_location.rs | 4 ++ 4 files changed, 120 insertions(+) create mode 100644 crates/ra_syntax/test_data/parser/err/0040_illegal_crate_kw_location.rast create mode 100644 crates/ra_syntax/test_data/parser/err/0040_illegal_crate_kw_location.rs (limited to 'crates/ra_syntax') diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index 2cb3ad011..3b5e05af9 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs @@ -1249,6 +1249,7 @@ pub struct PathSegment { } impl PathSegment { pub fn coloncolon_token(&self) -> Option { support::token(&self.syntax, T![::]) } + pub fn crate_token(&self) -> Option { support::token(&self.syntax, T![crate]) } pub fn l_angle_token(&self) -> Option { support::token(&self.syntax, T![<]) } pub fn name_ref(&self) -> Option { support::child(&self.syntax) } pub fn type_arg_list(&self) -> Option { support::child(&self.syntax) } diff --git a/crates/ra_syntax/src/validation.rs b/crates/ra_syntax/src/validation.rs index 5e93895ec..a30bc97bb 100644 --- a/crates/ra_syntax/src/validation.rs +++ b/crates/ra_syntax/src/validation.rs @@ -96,6 +96,7 @@ pub(crate) fn validate(root: &SyntaxNode) -> Vec { ast::RecordField(it) => validate_numeric_name(it.name_ref(), &mut errors), ast::Visibility(it) => validate_visibility(it, &mut errors), ast::RangeExpr(it) => validate_range_expr(it, &mut errors), + ast::PathSegment(it) => validate_crate_keyword_in_path_segment(it, &mut errors), _ => (), } } @@ -222,3 +223,41 @@ fn validate_range_expr(expr: ast::RangeExpr, errors: &mut Vec) { )); } } + +fn validate_crate_keyword_in_path_segment( + segment: ast::PathSegment, + errors: &mut Vec, +) { + const ERR_MSG: &str = "The `crate` keyword is only allowed as the first segment of a path"; + + let crate_token = match segment.crate_token() { + None => return, + Some(it) => it, + }; + + // Disallow both ::crate and foo::crate + let path = segment.parent_path(); + if segment.coloncolon_token().is_some() || path.qualifier().is_some() { + errors.push(SyntaxError::new(ERR_MSG, crate_token.text_range())); + return; + } + + // We now know that the path variable describes a complete path. + // For expressions and types, validation is complete, but we still have + // to handle UseItems like this: + // use foo:{crate}; + // so we crawl upwards looking for any preceding paths on `UseTree`s + for node in path.syntax().ancestors().skip(1) { + match_ast! { + match node { + ast::UseTree(it) => if let Some(tree_path) = it.path() { + if tree_path != path { + errors.push(SyntaxError::new(ERR_MSG, crate_token.text_range())); + } + }, + ast::UseTreeList(_it) => continue, + _ => return, + } + }; + } +} diff --git a/crates/ra_syntax/test_data/parser/err/0040_illegal_crate_kw_location.rast b/crates/ra_syntax/test_data/parser/err/0040_illegal_crate_kw_location.rast new file mode 100644 index 000000000..8306f7361 --- /dev/null +++ b/crates/ra_syntax/test_data/parser/err/0040_illegal_crate_kw_location.rast @@ -0,0 +1,76 @@ +SOURCE_FILE@0..83 + USE_ITEM@0..12 + USE_KW@0..3 "use" + WHITESPACE@3..4 " " + USE_TREE@4..11 + PATH@4..11 + PATH_SEGMENT@4..11 + COLON2@4..6 "::" + CRATE_KW@6..11 "crate" + SEMICOLON@11..12 ";" + WHITESPACE@12..13 "\n" + USE_ITEM@13..39 + USE_KW@13..16 "use" + WHITESPACE@16..17 " " + USE_TREE@17..38 + USE_TREE_LIST@17..38 + L_CURLY@17..18 "{" + USE_TREE@18..23 + PATH@18..23 + PATH_SEGMENT@18..23 + CRATE_KW@18..23 "crate" + COMMA@23..24 "," + WHITESPACE@24..25 " " + USE_TREE@25..37 + PATH@25..28 + PATH_SEGMENT@25..28 + NAME_REF@25..28 + IDENT@25..28 "foo" + COLON2@28..30 "::" + USE_TREE_LIST@30..37 + L_CURLY@30..31 "{" + USE_TREE@31..36 + PATH@31..36 + PATH_SEGMENT@31..36 + CRATE_KW@31..36 "crate" + R_CURLY@36..37 "}" + R_CURLY@37..38 "}" + SEMICOLON@38..39 ";" + WHITESPACE@39..40 "\n" + USE_ITEM@40..57 + USE_KW@40..43 "use" + WHITESPACE@43..44 " " + USE_TREE@44..56 + PATH@44..56 + PATH@44..49 + PATH_SEGMENT@44..49 + NAME_REF@44..49 + IDENT@44..49 "hello" + COLON2@49..51 "::" + PATH_SEGMENT@51..56 + CRATE_KW@51..56 "crate" + SEMICOLON@56..57 ";" + WHITESPACE@57..58 "\n" + USE_ITEM@58..82 + USE_KW@58..61 "use" + WHITESPACE@61..62 " " + USE_TREE@62..81 + PATH@62..81 + PATH@62..74 + PATH@62..67 + PATH_SEGMENT@62..67 + NAME_REF@62..67 + IDENT@62..67 "hello" + COLON2@67..69 "::" + PATH_SEGMENT@69..74 + CRATE_KW@69..74 "crate" + COLON2@74..76 "::" + PATH_SEGMENT@76..81 + NAME_REF@76..81 + IDENT@76..81 "there" + SEMICOLON@81..82 ";" + WHITESPACE@82..83 "\n" +error 6..11: The `crate` keyword is only allowed as the first segment of a path +error 31..36: The `crate` keyword is only allowed as the first segment of a path +error 51..56: The `crate` keyword is only allowed as the first segment of a path +error 69..74: The `crate` keyword is only allowed as the first segment of a path diff --git a/crates/ra_syntax/test_data/parser/err/0040_illegal_crate_kw_location.rs b/crates/ra_syntax/test_data/parser/err/0040_illegal_crate_kw_location.rs new file mode 100644 index 000000000..bead4c0b6 --- /dev/null +++ b/crates/ra_syntax/test_data/parser/err/0040_illegal_crate_kw_location.rs @@ -0,0 +1,4 @@ +use ::crate; +use {crate, foo::{crate}}; +use hello::crate; +use hello::crate::there; -- cgit v1.2.3 From c51c8bfb840d35709ee1cec190620c98b4fc3590 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Apr 2020 14:17:14 +0200 Subject: Special-case try macro to better support 2015 edition --- .../parser/inline/ok/0159_try_macro_fallback.rast | 35 ++++++++++++++++++++++ .../parser/inline/ok/0159_try_macro_fallback.rs | 1 + 2 files changed, 36 insertions(+) create mode 100644 crates/ra_syntax/test_data/parser/inline/ok/0159_try_macro_fallback.rast create mode 100644 crates/ra_syntax/test_data/parser/inline/ok/0159_try_macro_fallback.rs (limited to 'crates/ra_syntax') diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0159_try_macro_fallback.rast b/crates/ra_syntax/test_data/parser/inline/ok/0159_try_macro_fallback.rast new file mode 100644 index 000000000..beb6d8010 --- /dev/null +++ b/crates/ra_syntax/test_data/parser/inline/ok/0159_try_macro_fallback.rast @@ -0,0 +1,35 @@ +SOURCE_FILE@0..27 + FN_DEF@0..26 + FN_KW@0..2 "fn" + WHITESPACE@2..3 " " + NAME@3..6 + IDENT@3..6 "foo" + PARAM_LIST@6..8 + L_PAREN@6..7 "(" + R_PAREN@7..8 ")" + WHITESPACE@8..9 " " + BLOCK_EXPR@9..26 + BLOCK@9..26 + L_CURLY@9..10 "{" + WHITESPACE@10..11 " " + EXPR_STMT@11..24 + MACRO_CALL@11..23 + PATH@11..14 + PATH_SEGMENT@11..14 + NAME_REF@11..14 + IDENT@11..14 "try" + BANG@14..15 "!" + TOKEN_TREE@15..23 + L_PAREN@15..16 "(" + IDENT@16..18 "Ok" + TOKEN_TREE@18..22 + L_PAREN@18..19 "(" + TOKEN_TREE@19..21 + L_PAREN@19..20 "(" + R_PAREN@20..21 ")" + R_PAREN@21..22 ")" + R_PAREN@22..23 ")" + SEMICOLON@23..24 ";" + WHITESPACE@24..25 " " + R_CURLY@25..26 "}" + WHITESPACE@26..27 "\n" diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0159_try_macro_fallback.rs b/crates/ra_syntax/test_data/parser/inline/ok/0159_try_macro_fallback.rs new file mode 100644 index 000000000..61a6b46a0 --- /dev/null +++ b/crates/ra_syntax/test_data/parser/inline/ok/0159_try_macro_fallback.rs @@ -0,0 +1 @@ +fn foo() { try!(Ok(())); } -- cgit v1.2.3 From 45c4f620b1c5b8e462875b6e372db0e849bd6170 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Thu, 30 Apr 2020 22:07:46 +0800 Subject: Special-case try macro_rules --- .../parser/inline/ok/0160_try_macro_rules.rast | 27 ++++++++++++++++++++++ .../parser/inline/ok/0160_try_macro_rules.rs | 1 + 2 files changed, 28 insertions(+) create mode 100644 crates/ra_syntax/test_data/parser/inline/ok/0160_try_macro_rules.rast create mode 100644 crates/ra_syntax/test_data/parser/inline/ok/0160_try_macro_rules.rs (limited to 'crates/ra_syntax') diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0160_try_macro_rules.rast b/crates/ra_syntax/test_data/parser/inline/ok/0160_try_macro_rules.rast new file mode 100644 index 000000000..05b89d1c3 --- /dev/null +++ b/crates/ra_syntax/test_data/parser/inline/ok/0160_try_macro_rules.rast @@ -0,0 +1,27 @@ +SOURCE_FILE@0..30 + MACRO_CALL@0..29 + PATH@0..11 + PATH_SEGMENT@0..11 + NAME_REF@0..11 + IDENT@0..11 "macro_rules" + BANG@11..12 "!" + WHITESPACE@12..13 " " + NAME@13..16 + IDENT@13..16 "try" + WHITESPACE@16..17 " " + TOKEN_TREE@17..29 + L_CURLY@17..18 "{" + WHITESPACE@18..19 " " + TOKEN_TREE@19..21 + L_PAREN@19..20 "(" + R_PAREN@20..21 ")" + WHITESPACE@21..22 " " + EQ@22..23 "=" + R_ANGLE@23..24 ">" + WHITESPACE@24..25 " " + TOKEN_TREE@25..27 + L_CURLY@25..26 "{" + R_CURLY@26..27 "}" + WHITESPACE@27..28 " " + R_CURLY@28..29 "}" + WHITESPACE@29..30 "\n" diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0160_try_macro_rules.rs b/crates/ra_syntax/test_data/parser/inline/ok/0160_try_macro_rules.rs new file mode 100644 index 000000000..2e2ab6e60 --- /dev/null +++ b/crates/ra_syntax/test_data/parser/inline/ok/0160_try_macro_rules.rs @@ -0,0 +1 @@ +macro_rules! try { () => {} } -- cgit v1.2.3 From 513a3615f6d462852c0135dc4ac30a2086e25c5a Mon Sep 17 00:00:00 2001 From: John Renner Date: Thu, 30 Apr 2020 10:41:24 -0700 Subject: Report invalid, nested, multi-segment crate-paths Specifically, things like: use foo::{crate::bar}; Are now being caught, when before we only caught: use foo::{crate}; --- crates/ra_syntax/src/validation.rs | 29 +++++- .../parser/err/0040_illegal_crate_kw_location.rast | 113 ++++++++++++--------- .../parser/err/0040_illegal_crate_kw_location.rs | 2 +- .../parser/inline/ok/0002_use_tree_list.rast | 49 ++++----- .../parser/inline/ok/0002_use_tree_list.rs | 2 +- 5 files changed, 115 insertions(+), 80 deletions(-) (limited to 'crates/ra_syntax') diff --git a/crates/ra_syntax/src/validation.rs b/crates/ra_syntax/src/validation.rs index a30bc97bb..f0b3dec63 100644 --- a/crates/ra_syntax/src/validation.rs +++ b/crates/ra_syntax/src/validation.rs @@ -236,21 +236,40 @@ fn validate_crate_keyword_in_path_segment( }; // Disallow both ::crate and foo::crate - let path = segment.parent_path(); + let mut path = segment.parent_path(); if segment.coloncolon_token().is_some() || path.qualifier().is_some() { errors.push(SyntaxError::new(ERR_MSG, crate_token.text_range())); return; } - // We now know that the path variable describes a complete path. // For expressions and types, validation is complete, but we still have - // to handle UseItems like this: - // use foo:{crate}; - // so we crawl upwards looking for any preceding paths on `UseTree`s + // to handle invalid UseItems like this: + // + // use foo:{crate::bar::baz}; + // + // To handle this we must inspect the parent `UseItem`s and `UseTree`s + // but right now we're looking deep inside the nested `Path` nodes because + // `Path`s are left-associative: + // + // ((crate)::bar)::baz) + // ^ current value of path + // + // So we need to climb to the top + while let Some(parent) = path.parent_path() { + path = parent; + } + + // Now that we've found the whole path we need to see if there's a prefix + // somewhere in the UseTree hierarchy. This check is arbitrarily deep + // because rust allows arbitrary nesting like so: + // + // use {foo::{{{{crate::bar::baz}}}}}; for node in path.syntax().ancestors().skip(1) { match_ast! { match node { ast::UseTree(it) => if let Some(tree_path) = it.path() { + // Even a top-level path exists within a `UseTree` so we must explicitly + // allow our path but disallow anything else if tree_path != path { errors.push(SyntaxError::new(ERR_MSG, crate_token.text_range())); } diff --git a/crates/ra_syntax/test_data/parser/err/0040_illegal_crate_kw_location.rast b/crates/ra_syntax/test_data/parser/err/0040_illegal_crate_kw_location.rast index 8306f7361..d2a549273 100644 --- a/crates/ra_syntax/test_data/parser/err/0040_illegal_crate_kw_location.rast +++ b/crates/ra_syntax/test_data/parser/err/0040_illegal_crate_kw_location.rast @@ -1,4 +1,4 @@ -SOURCE_FILE@0..83 +SOURCE_FILE@0..98 USE_ITEM@0..12 USE_KW@0..3 "use" WHITESPACE@3..4 " " @@ -9,11 +9,11 @@ SOURCE_FILE@0..83 CRATE_KW@6..11 "crate" SEMICOLON@11..12 ";" WHITESPACE@12..13 "\n" - USE_ITEM@13..39 + USE_ITEM@13..54 USE_KW@13..16 "use" WHITESPACE@16..17 " " - USE_TREE@17..38 - USE_TREE_LIST@17..38 + USE_TREE@17..53 + USE_TREE_LIST@17..53 L_CURLY@17..18 "{" USE_TREE@18..23 PATH@18..23 @@ -21,56 +21,71 @@ SOURCE_FILE@0..83 CRATE_KW@18..23 "crate" COMMA@23..24 "," WHITESPACE@24..25 " " - USE_TREE@25..37 + USE_TREE@25..52 PATH@25..28 PATH_SEGMENT@25..28 NAME_REF@25..28 IDENT@25..28 "foo" COLON2@28..30 "::" - USE_TREE_LIST@30..37 + USE_TREE_LIST@30..52 L_CURLY@30..31 "{" - USE_TREE@31..36 - PATH@31..36 - PATH_SEGMENT@31..36 - CRATE_KW@31..36 "crate" - R_CURLY@36..37 "}" - R_CURLY@37..38 "}" - SEMICOLON@38..39 ";" - WHITESPACE@39..40 "\n" - USE_ITEM@40..57 - USE_KW@40..43 "use" - WHITESPACE@43..44 " " - USE_TREE@44..56 - PATH@44..56 - PATH@44..49 - PATH_SEGMENT@44..49 - NAME_REF@44..49 - IDENT@44..49 "hello" - COLON2@49..51 "::" - PATH_SEGMENT@51..56 - CRATE_KW@51..56 "crate" - SEMICOLON@56..57 ";" - WHITESPACE@57..58 "\n" - USE_ITEM@58..82 - USE_KW@58..61 "use" - WHITESPACE@61..62 " " - USE_TREE@62..81 - PATH@62..81 - PATH@62..74 - PATH@62..67 - PATH_SEGMENT@62..67 - NAME_REF@62..67 - IDENT@62..67 "hello" - COLON2@67..69 "::" - PATH_SEGMENT@69..74 - CRATE_KW@69..74 "crate" - COLON2@74..76 "::" - PATH_SEGMENT@76..81 - NAME_REF@76..81 - IDENT@76..81 "there" - SEMICOLON@81..82 ";" - WHITESPACE@82..83 "\n" + USE_TREE@31..51 + PATH@31..51 + PATH@31..46 + PATH@31..41 + PATH@31..36 + PATH_SEGMENT@31..36 + CRATE_KW@31..36 "crate" + COLON2@36..38 "::" + PATH_SEGMENT@38..41 + NAME_REF@38..41 + IDENT@38..41 "foo" + COLON2@41..43 "::" + PATH_SEGMENT@43..46 + NAME_REF@43..46 + IDENT@43..46 "bar" + COLON2@46..48 "::" + PATH_SEGMENT@48..51 + NAME_REF@48..51 + IDENT@48..51 "baz" + R_CURLY@51..52 "}" + R_CURLY@52..53 "}" + SEMICOLON@53..54 ";" + WHITESPACE@54..55 "\n" + USE_ITEM@55..72 + USE_KW@55..58 "use" + WHITESPACE@58..59 " " + USE_TREE@59..71 + PATH@59..71 + PATH@59..64 + PATH_SEGMENT@59..64 + NAME_REF@59..64 + IDENT@59..64 "hello" + COLON2@64..66 "::" + PATH_SEGMENT@66..71 + CRATE_KW@66..71 "crate" + SEMICOLON@71..72 ";" + WHITESPACE@72..73 "\n" + USE_ITEM@73..97 + USE_KW@73..76 "use" + WHITESPACE@76..77 " " + USE_TREE@77..96 + PATH@77..96 + PATH@77..89 + PATH@77..82 + PATH_SEGMENT@77..82 + NAME_REF@77..82 + IDENT@77..82 "hello" + COLON2@82..84 "::" + PATH_SEGMENT@84..89 + CRATE_KW@84..89 "crate" + COLON2@89..91 "::" + PATH_SEGMENT@91..96 + NAME_REF@91..96 + IDENT@91..96 "there" + SEMICOLON@96..97 ";" + WHITESPACE@97..98 "\n" error 6..11: The `crate` keyword is only allowed as the first segment of a path error 31..36: The `crate` keyword is only allowed as the first segment of a path -error 51..56: The `crate` keyword is only allowed as the first segment of a path -error 69..74: The `crate` keyword is only allowed as the first segment of a path +error 66..71: The `crate` keyword is only allowed as the first segment of a path +error 84..89: The `crate` keyword is only allowed as the first segment of a path diff --git a/crates/ra_syntax/test_data/parser/err/0040_illegal_crate_kw_location.rs b/crates/ra_syntax/test_data/parser/err/0040_illegal_crate_kw_location.rs index bead4c0b6..508def2c7 100644 --- a/crates/ra_syntax/test_data/parser/err/0040_illegal_crate_kw_location.rs +++ b/crates/ra_syntax/test_data/parser/err/0040_illegal_crate_kw_location.rs @@ -1,4 +1,4 @@ use ::crate; -use {crate, foo::{crate}}; +use {crate, foo::{crate::foo::bar::baz}}; use hello::crate; use hello::crate::there; diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0002_use_tree_list.rast b/crates/ra_syntax/test_data/parser/inline/ok/0002_use_tree_list.rast index bd74b44a6..cf3a90400 100644 --- a/crates/ra_syntax/test_data/parser/inline/ok/0002_use_tree_list.rast +++ b/crates/ra_syntax/test_data/parser/inline/ok/0002_use_tree_list.rast @@ -1,4 +1,4 @@ -SOURCE_FILE@0..250 +SOURCE_FILE@0..249 USE_ITEM@0..58 USE_KW@0..3 "use" WHITESPACE@3..4 " " @@ -104,32 +104,33 @@ SOURCE_FILE@0..250 WHITESPACE@166..167 " " COMMENT@167..179 "// Rust 2015" WHITESPACE@179..180 "\n" - USE_ITEM@180..206 + USE_ITEM@180..205 USE_KW@180..183 "use" WHITESPACE@183..184 " " - USE_TREE@184..205 + USE_TREE@184..204 COLON2@184..186 "::" - USE_TREE_LIST@186..205 + USE_TREE_LIST@186..204 L_CURLY@186..187 "{" - USE_TREE@187..204 - USE_TREE_LIST@187..204 + USE_TREE@187..203 + USE_TREE_LIST@187..203 L_CURLY@187..188 "{" - USE_TREE@188..203 - USE_TREE_LIST@188..203 + USE_TREE@188..202 + USE_TREE_LIST@188..202 L_CURLY@188..189 "{" - USE_TREE@189..202 - PATH@189..202 - PATH@189..194 - PATH_SEGMENT@189..194 - CRATE_KW@189..194 "crate" - COLON2@194..196 "::" - PATH_SEGMENT@196..202 - NAME_REF@196..202 - IDENT@196..202 "export" - R_CURLY@202..203 "}" - R_CURLY@203..204 "}" - R_CURLY@204..205 "}" - SEMICOLON@205..206 ";" - WHITESPACE@206..207 " " - COMMENT@207..249 "// Nonsensical but pe ..." - WHITESPACE@249..250 "\n" + USE_TREE@189..201 + PATH@189..201 + PATH@189..193 + PATH_SEGMENT@189..193 + NAME_REF@189..193 + IDENT@189..193 "root" + COLON2@193..195 "::" + PATH_SEGMENT@195..201 + NAME_REF@195..201 + IDENT@195..201 "export" + R_CURLY@201..202 "}" + R_CURLY@202..203 "}" + R_CURLY@203..204 "}" + SEMICOLON@204..205 ";" + WHITESPACE@205..206 " " + COMMENT@206..248 "// Nonsensical but pe ..." + WHITESPACE@248..249 "\n" diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0002_use_tree_list.rs b/crates/ra_syntax/test_data/parser/inline/ok/0002_use_tree_list.rs index 06c387cee..381cba1e2 100644 --- a/crates/ra_syntax/test_data/parser/inline/ok/0002_use_tree_list.rs +++ b/crates/ra_syntax/test_data/parser/inline/ok/0002_use_tree_list.rs @@ -1,4 +1,4 @@ use {crate::path::from::root, or::path::from::crate_name}; // Rust 2018 (with a crate named `or`) use {path::from::root}; // Rust 2015 use ::{some::arbritrary::path}; // Rust 2015 -use ::{{{crate::export}}}; // Nonsensical but perfectly legal nestnig +use ::{{{root::export}}}; // Nonsensical but perfectly legal nesting -- cgit v1.2.3 From 15cfa9a808be820ceafc2e957ea8532e8ec68f00 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Apr 2020 21:36:31 +0200 Subject: Fix a bunch of false-positives in join-lines --- crates/ra_syntax/src/ast/expr_extensions.rs | 5 ++++- crates/ra_syntax/src/ast/generated/nodes.rs | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'crates/ra_syntax') diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs index 93aa3d45f..ecf74fd36 100644 --- a/crates/ra_syntax/src/ast/expr_extensions.rs +++ b/crates/ra_syntax/src/ast/expr_extensions.rs @@ -368,12 +368,15 @@ impl ast::BlockExpr { /// const FOO: () = { stand_alone }; /// ``` pub fn is_standalone(&self) -> bool { + if self.unsafe_token().is_some() || self.async_token().is_some() { + return false; + } let kind = match self.syntax().parent() { None => return true, Some(it) => it.kind(), }; match kind { - FN_DEF | MATCH_ARM | IF_EXPR | WHILE_EXPR | LOOP_EXPR | TRY_BLOCK_EXPR => false, + FN_DEF | IF_EXPR | WHILE_EXPR | LOOP_EXPR | TRY_BLOCK_EXPR => false, _ => true, } } diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index 3b5e05af9..d2253d4af 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs @@ -554,6 +554,7 @@ impl ast::AttrsOwner for BlockExpr {} impl BlockExpr { pub fn label(&self) -> Option