aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast
diff options
context:
space:
mode:
authorPhil Ellison <[email protected]>2019-07-28 20:47:44 +0100
committerPhil Ellison <[email protected]>2019-07-28 20:47:44 +0100
commit4fd7ad908b6e7cee0ee7853fcf29fb5a38a19aa2 (patch)
tree30574ad27b93b2eecbda661547ee952e6b32d0fd /crates/ra_syntax/src/ast
parent578bc05ca41e095c61c64bdef255760c26736a11 (diff)
Add special case for f32 and f43 suffices on Literal.kind
Diffstat (limited to 'crates/ra_syntax/src/ast')
-rw-r--r--crates/ra_syntax/src/ast/expr_extensions.rs24
1 files changed, 21 insertions, 3 deletions
diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs
index f9190d877..745dece98 100644
--- a/crates/ra_syntax/src/ast/expr_extensions.rs
+++ b/crates/ra_syntax/src/ast/expr_extensions.rs
@@ -239,16 +239,34 @@ impl ast::Literal {
239 pub fn kind(&self) -> LiteralKind { 239 pub fn kind(&self) -> LiteralKind {
240 match self.token().kind() { 240 match self.token().kind() {
241 INT_NUMBER => { 241 INT_NUMBER => {
242 let allowed_suffix_list = [ 242 let int_suffix_list = [
243 "isize", "i128", "i64", "i32", "i16", "i8", "usize", "u128", "u64", "u32", 243 "isize", "i128", "i64", "i32", "i16", "i8", "usize", "u128", "u64", "u32",
244 "u16", "u8", 244 "u16", "u8",
245 ]; 245 ];
246
247 // The lexer treats e.g. `1f64` as an integer literal. See
248 // https://github.com/rust-analyzer/rust-analyzer/issues/1592
249 // and the comments on the linked PR.
250 let float_suffix_list = [
251 "f32", "f64"
252 ];
253
246 let text = self.token().text().to_string(); 254 let text = self.token().text().to_string();
247 let suffix = allowed_suffix_list 255
256 let float_suffix = float_suffix_list
248 .iter() 257 .iter()
249 .find(|&s| text.ends_with(s)) 258 .find(|&s| text.ends_with(s))
250 .map(|&suf| SmolStr::new(suf)); 259 .map(|&suf| SmolStr::new(suf));
251 LiteralKind::IntNumber { suffix } 260
261 if float_suffix.is_some() {
262 LiteralKind::FloatNumber { suffix: float_suffix }
263 } else {
264 let suffix = int_suffix_list
265 .iter()
266 .find(|&s| text.ends_with(s))
267 .map(|&suf| SmolStr::new(suf));
268 LiteralKind::IntNumber { suffix }
269 }
252 } 270 }
253 FLOAT_NUMBER => { 271 FLOAT_NUMBER => {
254 let allowed_suffix_list = ["f64", "f32"]; 272 let allowed_suffix_list = ["f64", "f32"];