diff options
Diffstat (limited to 'crates/ra_syntax/src/validation')
-rw-r--r-- | crates/ra_syntax/src/validation/block.rs | 6 | ||||
-rw-r--r-- | crates/ra_syntax/src/validation/byte.rs | 30 | ||||
-rw-r--r-- | crates/ra_syntax/src/validation/byte_string.rs | 20 | ||||
-rw-r--r-- | crates/ra_syntax/src/validation/char.rs | 20 | ||||
-rw-r--r-- | crates/ra_syntax/src/validation/string.rs | 20 |
5 files changed, 16 insertions, 80 deletions
diff --git a/crates/ra_syntax/src/validation/block.rs b/crates/ra_syntax/src/validation/block.rs index 9e1949124..4e77c15b6 100644 --- a/crates/ra_syntax/src/validation/block.rs +++ b/crates/ra_syntax/src/validation/block.rs | |||
@@ -17,8 +17,6 @@ pub(crate) fn validate_block_node(node: &ast::Block, errors: &mut Vec<SyntaxErro | |||
17 | _ => {} | 17 | _ => {} |
18 | } | 18 | } |
19 | } | 19 | } |
20 | errors.extend( | 20 | errors |
21 | node.attrs() | 21 | .extend(node.attrs().map(|attr| SyntaxError::new(InvalidBlockAttr, attr.syntax().range()))) |
22 | .map(|attr| SyntaxError::new(InvalidBlockAttr, attr.syntax().range())), | ||
23 | ) | ||
24 | } | 22 | } |
diff --git a/crates/ra_syntax/src/validation/byte.rs b/crates/ra_syntax/src/validation/byte.rs index 9bddabc80..d51fabcf9 100644 --- a/crates/ra_syntax/src/validation/byte.rs +++ b/crates/ra_syntax/src/validation/byte.rs | |||
@@ -28,10 +28,7 @@ pub(super) fn validate_byte_node(node: &ast::Byte, errors: &mut Vec<SyntaxError> | |||
28 | } | 28 | } |
29 | 29 | ||
30 | if let Some(range) = components.suffix { | 30 | if let Some(range) = components.suffix { |
31 | errors.push(SyntaxError::new( | 31 | errors.push(SyntaxError::new(InvalidSuffix, range + literal_range.start())); |
32 | InvalidSuffix, | ||
33 | range + literal_range.start(), | ||
34 | )); | ||
35 | } | 32 | } |
36 | 33 | ||
37 | if len == 0 { | 34 | if len == 0 { |
@@ -55,10 +52,7 @@ pub(super) fn validate_byte_component( | |||
55 | AsciiCodeEscape => validate_byte_code_escape(text, range, errors), | 52 | AsciiCodeEscape => validate_byte_code_escape(text, range, errors), |
56 | UnicodeEscape => errors.push(SyntaxError::new(UnicodeEscapeForbidden, range)), | 53 | UnicodeEscape => errors.push(SyntaxError::new(UnicodeEscapeForbidden, range)), |
57 | CodePoint => { | 54 | CodePoint => { |
58 | let c = text | 55 | let c = text.chars().next().expect("Code points should be one character long"); |
59 | .chars() | ||
60 | .next() | ||
61 | .expect("Code points should be one character long"); | ||
62 | 56 | ||
63 | // These bytes must always be escaped | 57 | // These bytes must always be escaped |
64 | if c == '\t' || c == '\r' || c == '\n' { | 58 | if c == '\t' || c == '\r' || c == '\n' { |
@@ -93,10 +87,7 @@ fn validate_byte_code_escape(text: &str, range: TextRange, errors: &mut Vec<Synt | |||
93 | } else if text.chars().count() < 4 { | 87 | } else if text.chars().count() < 4 { |
94 | errors.push(SyntaxError::new(TooShortByteCodeEscape, range)); | 88 | errors.push(SyntaxError::new(TooShortByteCodeEscape, range)); |
95 | } else { | 89 | } else { |
96 | assert!( | 90 | assert!(text.chars().count() == 4, "ByteCodeEscape cannot be longer than 4 chars"); |
97 | text.chars().count() == 4, | ||
98 | "ByteCodeEscape cannot be longer than 4 chars" | ||
99 | ); | ||
100 | 91 | ||
101 | if u8::from_str_radix(&text[2..], 16).is_err() { | 92 | if u8::from_str_radix(&text[2..], 16).is_err() { |
102 | errors.push(SyntaxError::new(MalformedByteCodeEscape, range)); | 93 | errors.push(SyntaxError::new(MalformedByteCodeEscape, range)); |
@@ -115,12 +106,7 @@ mod test { | |||
115 | 106 | ||
116 | fn assert_valid_byte(literal: &str) { | 107 | fn assert_valid_byte(literal: &str) { |
117 | let file = build_file(literal); | 108 | let file = build_file(literal); |
118 | assert!( | 109 | assert!(file.errors().len() == 0, "Errors for literal '{}': {:?}", literal, file.errors()); |
119 | file.errors().len() == 0, | ||
120 | "Errors for literal '{}': {:?}", | ||
121 | literal, | ||
122 | file.errors() | ||
123 | ); | ||
124 | } | 110 | } |
125 | 111 | ||
126 | fn assert_invalid_byte(literal: &str) { | 112 | fn assert_invalid_byte(literal: &str) { |
@@ -193,13 +179,7 @@ mod test { | |||
193 | 179 | ||
194 | #[test] | 180 | #[test] |
195 | fn test_invalid_unicode_escape() { | 181 | fn test_invalid_unicode_escape() { |
196 | let well_formed = [ | 182 | let well_formed = [r"\u{FF}", r"\u{0}", r"\u{F}", r"\u{10FFFF}", r"\u{1_0__FF___FF_____}"]; |
197 | r"\u{FF}", | ||
198 | r"\u{0}", | ||
199 | r"\u{F}", | ||
200 | r"\u{10FFFF}", | ||
201 | r"\u{1_0__FF___FF_____}", | ||
202 | ]; | ||
203 | for c in &well_formed { | 183 | for c in &well_formed { |
204 | assert_invalid_byte(c); | 184 | assert_invalid_byte(c); |
205 | } | 185 | } |
diff --git a/crates/ra_syntax/src/validation/byte_string.rs b/crates/ra_syntax/src/validation/byte_string.rs index bdb147545..7abe8f330 100644 --- a/crates/ra_syntax/src/validation/byte_string.rs +++ b/crates/ra_syntax/src/validation/byte_string.rs | |||
@@ -34,10 +34,7 @@ pub(crate) fn validate_byte_string_node(node: &ast::ByteString, errors: &mut Vec | |||
34 | } | 34 | } |
35 | 35 | ||
36 | if let Some(range) = components.suffix { | 36 | if let Some(range) = components.suffix { |
37 | errors.push(SyntaxError::new( | 37 | errors.push(SyntaxError::new(InvalidSuffix, range + literal_range.start())); |
38 | InvalidSuffix, | ||
39 | range + literal_range.start(), | ||
40 | )); | ||
41 | } | 38 | } |
42 | } | 39 | } |
43 | 40 | ||
@@ -53,12 +50,7 @@ mod test { | |||
53 | 50 | ||
54 | fn assert_valid_str(literal: &str) { | 51 | fn assert_valid_str(literal: &str) { |
55 | let file = build_file(literal); | 52 | let file = build_file(literal); |
56 | assert!( | 53 | assert!(file.errors().len() == 0, "Errors for literal '{}': {:?}", literal, file.errors()); |
57 | file.errors().len() == 0, | ||
58 | "Errors for literal '{}': {:?}", | ||
59 | literal, | ||
60 | file.errors() | ||
61 | ); | ||
62 | } | 54 | } |
63 | 55 | ||
64 | fn assert_invalid_str(literal: &str) { | 56 | fn assert_invalid_str(literal: &str) { |
@@ -130,13 +122,7 @@ mod test { | |||
130 | 122 | ||
131 | #[test] | 123 | #[test] |
132 | fn test_invalid_unicode_escape() { | 124 | fn test_invalid_unicode_escape() { |
133 | let well_formed = [ | 125 | let well_formed = [r"\u{FF}", r"\u{0}", r"\u{F}", r"\u{10FFFF}", r"\u{1_0__FF___FF_____}"]; |
134 | r"\u{FF}", | ||
135 | r"\u{0}", | ||
136 | r"\u{F}", | ||
137 | r"\u{10FFFF}", | ||
138 | r"\u{1_0__FF___FF_____}", | ||
139 | ]; | ||
140 | for c in &well_formed { | 126 | for c in &well_formed { |
141 | assert_invalid_str(c); | 127 | assert_invalid_str(c); |
142 | } | 128 | } |
diff --git a/crates/ra_syntax/src/validation/char.rs b/crates/ra_syntax/src/validation/char.rs index e3ac5836b..012594db3 100644 --- a/crates/ra_syntax/src/validation/char.rs +++ b/crates/ra_syntax/src/validation/char.rs | |||
@@ -31,10 +31,7 @@ pub(super) fn validate_char_node(node: &ast::Char, errors: &mut Vec<SyntaxError> | |||
31 | } | 31 | } |
32 | 32 | ||
33 | if let Some(range) = components.suffix { | 33 | if let Some(range) = components.suffix { |
34 | errors.push(SyntaxError::new( | 34 | errors.push(SyntaxError::new(InvalidSuffix, range + literal_range.start())); |
35 | InvalidSuffix, | ||
36 | range + literal_range.start(), | ||
37 | )); | ||
38 | } | 35 | } |
39 | 36 | ||
40 | if len == 0 { | 37 | if len == 0 { |
@@ -184,12 +181,7 @@ mod test { | |||
184 | 181 | ||
185 | fn assert_valid_char(literal: &str) { | 182 | fn assert_valid_char(literal: &str) { |
186 | let file = build_file(literal); | 183 | let file = build_file(literal); |
187 | assert!( | 184 | assert!(file.errors().len() == 0, "Errors for literal '{}': {:?}", literal, file.errors()); |
188 | file.errors().len() == 0, | ||
189 | "Errors for literal '{}': {:?}", | ||
190 | literal, | ||
191 | file.errors() | ||
192 | ); | ||
193 | } | 185 | } |
194 | 186 | ||
195 | fn assert_invalid_char(literal: &str) { | 187 | fn assert_invalid_char(literal: &str) { |
@@ -258,13 +250,7 @@ mod test { | |||
258 | 250 | ||
259 | #[test] | 251 | #[test] |
260 | fn test_valid_unicode_escape() { | 252 | fn test_valid_unicode_escape() { |
261 | let valid = [ | 253 | let valid = [r"\u{FF}", r"\u{0}", r"\u{F}", r"\u{10FFFF}", r"\u{1_0__FF___FF_____}"]; |
262 | r"\u{FF}", | ||
263 | r"\u{0}", | ||
264 | r"\u{F}", | ||
265 | r"\u{10FFFF}", | ||
266 | r"\u{1_0__FF___FF_____}", | ||
267 | ]; | ||
268 | for c in &valid { | 254 | for c in &valid { |
269 | assert_valid_char(c); | 255 | assert_valid_char(c); |
270 | } | 256 | } |
diff --git a/crates/ra_syntax/src/validation/string.rs b/crates/ra_syntax/src/validation/string.rs index 365fe8d2d..4fd7fffdf 100644 --- a/crates/ra_syntax/src/validation/string.rs +++ b/crates/ra_syntax/src/validation/string.rs | |||
@@ -29,10 +29,7 @@ pub(crate) fn validate_string_node(node: &ast::String, errors: &mut Vec<SyntaxEr | |||
29 | } | 29 | } |
30 | 30 | ||
31 | if let Some(range) = components.suffix { | 31 | if let Some(range) = components.suffix { |
32 | errors.push(SyntaxError::new( | 32 | errors.push(SyntaxError::new(InvalidSuffix, range + literal_range.start())); |
33 | InvalidSuffix, | ||
34 | range + literal_range.start(), | ||
35 | )); | ||
36 | } | 33 | } |
37 | } | 34 | } |
38 | 35 | ||
@@ -48,12 +45,7 @@ mod test { | |||
48 | 45 | ||
49 | fn assert_valid_str(literal: &str) { | 46 | fn assert_valid_str(literal: &str) { |
50 | let file = build_file(literal); | 47 | let file = build_file(literal); |
51 | assert!( | 48 | assert!(file.errors().len() == 0, "Errors for literal '{}': {:?}", literal, file.errors()); |
52 | file.errors().len() == 0, | ||
53 | "Errors for literal '{}': {:?}", | ||
54 | literal, | ||
55 | file.errors() | ||
56 | ); | ||
57 | } | 49 | } |
58 | 50 | ||
59 | fn assert_invalid_str(literal: &str) { | 51 | fn assert_invalid_str(literal: &str) { |
@@ -121,13 +113,7 @@ mod test { | |||
121 | 113 | ||
122 | #[test] | 114 | #[test] |
123 | fn test_valid_unicode_escape() { | 115 | fn test_valid_unicode_escape() { |
124 | let valid = [ | 116 | let valid = [r"\u{FF}", r"\u{0}", r"\u{F}", r"\u{10FFFF}", r"\u{1_0__FF___FF_____}"]; |
125 | r"\u{FF}", | ||
126 | r"\u{0}", | ||
127 | r"\u{F}", | ||
128 | r"\u{10FFFF}", | ||
129 | r"\u{1_0__FF___FF_____}", | ||
130 | ]; | ||
131 | for c in &valid { | 117 | for c in &valid { |
132 | assert_valid_str(c); | 118 | assert_valid_str(c); |
133 | } | 119 | } |