aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-07-29 20:02:39 +0100
committerbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-07-29 20:02:39 +0100
commita5fe9f7a877bdb4dc35226d1cbac2b4870fde276 (patch)
tree578ec5757edfb8771a4c910479230db14055b020 /crates/ra_syntax
parent359b3376b32b38548c71e2b6e3a7393c4396ccf6 (diff)
parentd79dc38e99f522be79b776b4b10090ecf175013c (diff)
Merge #1604
1604: Fix failing type interference for floating point literal r=matklad a=theotherphil Fixes https://github.com/rust-analyzer/rust-analyzer/issues/1592 Co-authored-by: Phil Ellison <[email protected]>
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r--crates/ra_syntax/src/ast/expr_extensions.rs22
1 files changed, 19 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..8284f1b25 100644
--- a/crates/ra_syntax/src/ast/expr_extensions.rs
+++ b/crates/ra_syntax/src/ast/expr_extensions.rs
@@ -239,16 +239,32 @@ 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 = ["f32", "f64"];
251
246 let text = self.token().text().to_string(); 252 let text = self.token().text().to_string();
247 let suffix = allowed_suffix_list 253
254 let float_suffix = float_suffix_list
248 .iter() 255 .iter()
249 .find(|&s| text.ends_with(s)) 256 .find(|&s| text.ends_with(s))
250 .map(|&suf| SmolStr::new(suf)); 257 .map(|&suf| SmolStr::new(suf));
251 LiteralKind::IntNumber { suffix } 258
259 if float_suffix.is_some() {
260 LiteralKind::FloatNumber { suffix: float_suffix }
261 } else {
262 let suffix = int_suffix_list
263 .iter()
264 .find(|&s| text.ends_with(s))
265 .map(|&suf| SmolStr::new(suf));
266 LiteralKind::IntNumber { suffix }
267 }
252 } 268 }
253 FLOAT_NUMBER => { 269 FLOAT_NUMBER => {
254 let allowed_suffix_list = ["f64", "f32"]; 270 let allowed_suffix_list = ["f64", "f32"];