aboutsummaryrefslogtreecommitdiff
path: root/crates/syntax
diff options
context:
space:
mode:
Diffstat (limited to 'crates/syntax')
-rw-r--r--crates/syntax/src/algo.rs4
-rw-r--r--crates/syntax/src/ast/make.rs2
-rw-r--r--crates/syntax/src/ast/node_ext.rs2
-rw-r--r--crates/syntax/src/parsing/lexer.rs8
-rw-r--r--crates/syntax/src/validation.rs6
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0002_use_tree_list.rast98
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0002_use_tree_list.rs2
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0039_type_arg.rast28
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0039_type_arg.rs2
9 files changed, 81 insertions, 71 deletions
diff --git a/crates/syntax/src/algo.rs b/crates/syntax/src/algo.rs
index 22ab36cd2..384d031e7 100644
--- a/crates/syntax/src/algo.rs
+++ b/crates/syntax/src/algo.rs
@@ -88,8 +88,8 @@ pub fn least_common_ancestor(u: &SyntaxNode, v: &SyntaxNode) -> Option<SyntaxNod
88 let keep = u_depth.min(v_depth); 88 let keep = u_depth.min(v_depth);
89 89
90 let u_candidates = u.ancestors().skip(u_depth - keep); 90 let u_candidates = u.ancestors().skip(u_depth - keep);
91 let v_canidates = v.ancestors().skip(v_depth - keep); 91 let v_candidates = v.ancestors().skip(v_depth - keep);
92 let (res, _) = u_candidates.zip(v_canidates).find(|(x, y)| x == y)?; 92 let (res, _) = u_candidates.zip(v_candidates).find(|(x, y)| x == y)?;
93 Some(res) 93 Some(res)
94} 94}
95 95
diff --git a/crates/syntax/src/ast/make.rs b/crates/syntax/src/ast/make.rs
index cafa4c198..1ed8a96e5 100644
--- a/crates/syntax/src/ast/make.rs
+++ b/crates/syntax/src/ast/make.rs
@@ -241,7 +241,7 @@ pub fn wildcard_pat() -> ast::WildcardPat {
241 } 241 }
242} 242}
243 243
244/// Creates a tuple of patterns from an interator of patterns. 244/// Creates a tuple of patterns from an iterator of patterns.
245/// 245///
246/// Invariant: `pats` must be length > 1 246/// Invariant: `pats` must be length > 1
247/// 247///
diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs
index 2aa472fb4..27381ba80 100644
--- a/crates/syntax/src/ast/node_ext.rs
+++ b/crates/syntax/src/ast/node_ext.rs
@@ -133,7 +133,7 @@ impl ast::Attr {
133 first_token.and_then(|token| token.next_token()).as_ref().map(SyntaxToken::kind); 133 first_token.and_then(|token| token.next_token()).as_ref().map(SyntaxToken::kind);
134 134
135 match (first_token_kind, second_token_kind) { 135 match (first_token_kind, second_token_kind) {
136 (Some(SyntaxKind::POUND), Some(T![!])) => AttrKind::Inner, 136 (Some(T![#]), Some(T![!])) => AttrKind::Inner,
137 _ => AttrKind::Outer, 137 _ => AttrKind::Outer,
138 } 138 }
139 } 139 }
diff --git a/crates/syntax/src/parsing/lexer.rs b/crates/syntax/src/parsing/lexer.rs
index 0cbba73c5..7c8d0a4c4 100644
--- a/crates/syntax/src/parsing/lexer.rs
+++ b/crates/syntax/src/parsing/lexer.rs
@@ -24,7 +24,7 @@ pub struct Token {
24/// Beware that it checks for shebang first and its length contributes to resulting 24/// Beware that it checks for shebang first and its length contributes to resulting
25/// tokens offsets. 25/// tokens offsets.
26pub fn tokenize(text: &str) -> (Vec<Token>, Vec<SyntaxError>) { 26pub fn tokenize(text: &str) -> (Vec<Token>, Vec<SyntaxError>) {
27 // non-empty string is a precondtion of `rustc_lexer::strip_shebang()`. 27 // non-empty string is a precondition of `rustc_lexer::strip_shebang()`.
28 if text.is_empty() { 28 if text.is_empty() {
29 return Default::default(); 29 return Default::default();
30 } 30 }
@@ -76,7 +76,7 @@ pub fn lex_single_syntax_kind(text: &str) -> Option<(SyntaxKind, Option<SyntaxEr
76} 76}
77 77
78/// The same as `lex_single_syntax_kind()` but returns only `SyntaxKind` and 78/// The same as `lex_single_syntax_kind()` but returns only `SyntaxKind` and
79/// returns `None` if any tokenization error occured. 79/// returns `None` if any tokenization error occurred.
80/// 80///
81/// Beware that unescape errors are not checked at tokenization time. 81/// Beware that unescape errors are not checked at tokenization time.
82pub fn lex_single_valid_syntax_kind(text: &str) -> Option<SyntaxKind> { 82pub fn lex_single_valid_syntax_kind(text: &str) -> Option<SyntaxKind> {
@@ -96,7 +96,7 @@ pub fn lex_single_valid_syntax_kind(text: &str) -> Option<SyntaxKind> {
96/// 96///
97/// Beware that unescape errors are not checked at tokenization time. 97/// Beware that unescape errors are not checked at tokenization time.
98fn lex_first_token(text: &str) -> Option<(Token, Option<SyntaxError>)> { 98fn lex_first_token(text: &str) -> Option<(Token, Option<SyntaxError>)> {
99 // non-empty string is a precondtion of `rustc_lexer::first_token()`. 99 // non-empty string is a precondition of `rustc_lexer::first_token()`.
100 if text.is_empty() { 100 if text.is_empty() {
101 return None; 101 return None;
102 } 102 }
@@ -117,7 +117,7 @@ fn rustc_token_kind_to_syntax_kind(
117 token_text: &str, 117 token_text: &str,
118) -> (SyntaxKind, Option<&'static str>) { 118) -> (SyntaxKind, Option<&'static str>) {
119 // A note on an intended tradeoff: 119 // A note on an intended tradeoff:
120 // We drop some useful infromation here (see patterns with double dots `..`) 120 // We drop some useful information here (see patterns with double dots `..`)
121 // Storing that info in `SyntaxKind` is not possible due to its layout requirements of 121 // Storing that info in `SyntaxKind` is not possible due to its layout requirements of
122 // being `u16` that come from `rowan::SyntaxKind`. 122 // being `u16` that come from `rowan::SyntaxKind`.
123 123
diff --git a/crates/syntax/src/validation.rs b/crates/syntax/src/validation.rs
index 2ddaeb176..bfa2dc4ba 100644
--- a/crates/syntax/src/validation.rs
+++ b/crates/syntax/src/validation.rs
@@ -173,7 +173,7 @@ pub(crate) fn validate_block_structure(root: &SyntaxNode) {
173 assert_eq!( 173 assert_eq!(
174 node.parent(), 174 node.parent(),
175 pair.parent(), 175 pair.parent(),
176 "\nunpaired curleys:\n{}\n{:#?}\n", 176 "\nunpaired curlys:\n{}\n{:#?}\n",
177 root.text(), 177 root.text(),
178 root, 178 root,
179 ); 179 );
@@ -344,9 +344,9 @@ fn validate_trait_object_ty(ty: ast::DynTraitType) -> Option<SyntaxError> {
344 344
345 if tbl.bounds().count() > 1 { 345 if tbl.bounds().count() > 1 {
346 let dyn_token = ty.dyn_token()?; 346 let dyn_token = ty.dyn_token()?;
347 let potential_parentheses = 347 let potential_parenthesis =
348 algo::skip_trivia_token(dyn_token.prev_token()?, Direction::Prev)?; 348 algo::skip_trivia_token(dyn_token.prev_token()?, Direction::Prev)?;
349 let kind = potential_parentheses.kind(); 349 let kind = potential_parenthesis.kind();
350 if !matches!(kind, T!['('] | T![<] | T![=]) { 350 if !matches!(kind, T!['('] | T![<] | T![=]) {
351 return Some(SyntaxError::new("ambiguous `+` in a type", ty.syntax().text_range())); 351 return Some(SyntaxError::new("ambiguous `+` in a type", ty.syntax().text_range()));
352 } 352 }
diff --git a/crates/syntax/test_data/parser/inline/ok/0002_use_tree_list.rast b/crates/syntax/test_data/parser/inline/ok/0002_use_tree_list.rast
index b1fb75ed1..f40500e38 100644
--- a/crates/syntax/test_data/parser/inline/ok/0002_use_tree_list.rast
+++ b/crates/syntax/test_data/parser/inline/ok/0002_use_tree_list.rast
@@ -1,4 +1,4 @@
1[email protected]9 1[email protected]8
2 [email protected] 2 [email protected]
3 [email protected] "use" 3 [email protected] "use"
4 [email protected] " " 4 [email protected] " "
@@ -75,62 +75,62 @@ [email protected]
75 [email protected] "}" 75 [email protected] "}"
76 [email protected] ";" 76 [email protected] ";"
77 [email protected] " " 77 [email protected] " "
78 [email protected]6 78 [email protected]5
79 [email protected] "// Rust 2015" 79 [email protected] "// Rust 2015"
80 [email protected] "\n" 80 [email protected] "\n"
81 [email protected] "use" 81 [email protected] "use"
82 [email protected] " " 82 [email protected] " "
83 [email protected]5 83 [email protected]4
84 [email protected] "::" 84 [email protected] "::"
85 [email protected]5 85 [email protected]4
86 [email protected] "{" 86 [email protected] "{"
87 [email protected]4 87 [email protected]3
88 [email protected]4 88 [email protected]3
89 [email protected]8 89 [email protected]7
90 [email protected] 90 [email protected]
91 [email protected] 91 [email protected]
92 [email protected] 92 [email protected]
93 [email protected] "some" 93 [email protected] "some"
94 [email protected] "::" 94 [email protected] "::"
95 [email protected]8 95 [email protected]7
96 [email protected]8 96 [email protected]7
97 [email protected]8 "arbritrary" 97 [email protected]7 "arbitrary"
98 COLON2@158..160 "::" 98 COLON2@157..159 "::"
99 PATH_SEGMENT@160..164 99 PATH_SEGMENT@159..163
100 NAME_REF@160..164 100 NAME_REF@159..163
101 IDENT@160..164 "path" 101 IDENT@159..163 "path"
102 R_CURLY@164..165 "}" 102 R_CURLY@163..164 "}"
103 SEMICOLON@165..166 ";" 103 SEMICOLON@164..165 ";"
104 WHITESPACE@166..167 " " 104 WHITESPACE@165..166 " "
105 USE@167..205 105 USE@166..204
106 COMMENT@167..179 "// Rust 2015" 106 COMMENT@166..178 "// Rust 2015"
107 WHITESPACE@179..180 "\n" 107 WHITESPACE@178..179 "\n"
108 USE_KW@180..183 "use" 108 USE_KW@179..182 "use"
109 WHITESPACE@183..184 " " 109 WHITESPACE@182..183 " "
110 USE_TREE@184..204 110 USE_TREE@183..203
111 COLON2@184..186 "::" 111 COLON2@183..185 "::"
112 USE_TREE_LIST@186..204 112 USE_TREE_LIST@185..203
113 L_CURLY@186..187 "{" 113 L_CURLY@185..186 "{"
114 USE_TREE@187..203 114 USE_TREE@186..202
115 USE_TREE_LIST@187..203 115 USE_TREE_LIST@186..202
116 L_CURLY@187..188 "{" 116 L_CURLY@186..187 "{"
117 USE_TREE@188..202 117 USE_TREE@187..201
118 USE_TREE_LIST@188..202 118 USE_TREE_LIST@187..201
119 L_CURLY@188..189 "{" 119 L_CURLY@187..188 "{"
120 USE_TREE@189..201 120 USE_TREE@188..200
121 PATH@189..201 121 PATH@188..200
122 PATH@189..193 122 PATH@188..192
123 PATH_SEGMENT@189..193 123 PATH_SEGMENT@188..192
124 NAME_REF@189..193 124 NAME_REF@188..192
125 IDENT@189..193 "root" 125 IDENT@188..192 "root"
126 COLON2@193..195 "::" 126 COLON2@192..194 "::"
127 PATH_SEGMENT@195..201 127 PATH_SEGMENT@194..200
128 NAME_REF@195..201 128 NAME_REF@194..200
129 IDENT@195..201 "export" 129 IDENT@194..200 "export"
130 R_CURLY@201..202 "}" 130 R_CURLY@200..201 "}"
131 R_CURLY@202..203 "}" 131 R_CURLY@201..202 "}"
132 R_CURLY@203..204 "}" 132 R_CURLY@202..203 "}"
133 SEMICOLON@204..205 ";" 133 SEMICOLON@203..204 ";"
134 WHITESPACE@205..206 " " 134 WHITESPACE@204..205 " "
135 COMMENT@206..248 "// Nonsensical but pe ..." 135 COMMENT@205..247 "// Nonsensical but pe ..."
136 WHITESPACE@248..249 "\n" 136 WHITESPACE@247..248 "\n"
diff --git a/crates/syntax/test_data/parser/inline/ok/0002_use_tree_list.rs b/crates/syntax/test_data/parser/inline/ok/0002_use_tree_list.rs
index 381cba1e2..02af4b446 100644
--- a/crates/syntax/test_data/parser/inline/ok/0002_use_tree_list.rs
+++ b/crates/syntax/test_data/parser/inline/ok/0002_use_tree_list.rs
@@ -1,4 +1,4 @@
1use {crate::path::from::root, or::path::from::crate_name}; // Rust 2018 (with a crate named `or`) 1use {crate::path::from::root, or::path::from::crate_name}; // Rust 2018 (with a crate named `or`)
2use {path::from::root}; // Rust 2015 2use {path::from::root}; // Rust 2015
3use ::{some::arbritrary::path}; // Rust 2015 3use ::{some::arbitrary::path}; // Rust 2015
4use ::{{{root::export}}}; // Nonsensical but perfectly legal nesting 4use ::{{{root::export}}}; // Nonsensical but perfectly legal nesting
diff --git a/crates/syntax/test_data/parser/inline/ok/0039_type_arg.rast b/crates/syntax/test_data/parser/inline/ok/0039_type_arg.rast
index 51e881a8e..68c0f1c66 100644
--- a/crates/syntax/test_data/parser/inline/ok/0039_type_arg.rast
+++ b/crates/syntax/test_data/parser/inline/ok/0039_type_arg.rast
@@ -1,5 +1,5 @@
1SOURCE_FILE@0..46 1SOURCE_FILE@0..59
2 TYPE_ALIAS@0..45 2 [email protected]8
3 [email protected] "type" 3 [email protected] "type"
4 [email protected] " " 4 [email protected] " "
5 [email protected] 5 [email protected]
@@ -7,12 +7,12 @@ [email protected]
7 [email protected] " " 7 [email protected] " "
8 [email protected] "=" 8 [email protected] "="
9 [email protected] " " 9 [email protected] " "
10 PATH_TYPE@9..44 10 PATH_TYPE@9..57
11 PATH@9..44 11 PATH@9..57
12 PATH_SEGMENT@9..44 12 PATH_SEGMENT@9..57
13 [email protected] 13 [email protected]
14 [email protected] "B" 14 [email protected] "B"
15 GENERIC_ARG_LIST@10..44 15 GENERIC_ARG_LIST@10..57
16 [email protected] "<" 16 [email protected] "<"
17 [email protected] 17 [email protected]
18 [email protected] 18 [email protected]
@@ -51,6 +51,16 @@ [email protected]
51 [email protected] 51 [email protected]
52 [email protected] 52 [email protected]
53 [email protected] "u64" 53 [email protected] "u64"
54 [email protected] ">" 54 [email protected] ","
55 [email protected] ";" 55 [email protected] " "
56 [email protected] "\n" 56 [email protected]
57 [email protected]
58 [email protected] "true"
59 [email protected] ","
60 [email protected] " "
61 [email protected]
62 [email protected]
63 [email protected] "false"
64 [email protected] ">"
65 [email protected] ";"
66 [email protected] "\n"
diff --git a/crates/syntax/test_data/parser/inline/ok/0039_type_arg.rs b/crates/syntax/test_data/parser/inline/ok/0039_type_arg.rs
index 0d07d7651..6a8721a73 100644
--- a/crates/syntax/test_data/parser/inline/ok/0039_type_arg.rs
+++ b/crates/syntax/test_data/parser/inline/ok/0039_type_arg.rs
@@ -1 +1 @@
type A = B<'static, i32, 1, { 2 }, Item=u64>; type A = B<'static, i32, 1, { 2 }, Item=u64, true, false>;