rust/crates
bors[bot] faddea9353
Merge #6158
6158: Fix for negative literals in macros r=matklad a=cutsoy

_This pull request fixes #6028._

When writing `-42.0f32` in Rust, it is usually parsed as two different tokens (a minus operator and a float literal).

But a procedural macro can also generate new tokens, including negative [float literals](https://doc.rust-lang.org/stable/proc_macro/struct.Literal.html#method.f32_suffixed):

```rust
#[proc_macro]
fn example_verbose(input: TokenStream) -> TokenStream {
    let literal = Literal::f32_suffixed(-42.0);
    quote! { #literal }
}
```

or even shorter

```rust
#[proc_macro]
fn example(input: TokenStream) -> TokenStream {
    let literal = -42.0f32;
    quote! { #literal }
}
```

Unfortunately, these currently cause RA to crash:

```
thread '<unnamed>' panicked at 'Fail to convert given literal Literal {
    text: "-42.0f32",
    id: TokenId(
        4294967295,
    ),
}', crates/mbe/src/subtree_source.rs:161:28
```

This pull request contains both a fix 8cf9362 and a unit test 27798ee. In addition, I installed the patched server with `cargo xtask install --server` and verified in VSCode that it no longer crashes when a procedural macro returns a negative number literal.

Co-authored-by: Tim <tim@glacyr.com>
2020-10-07 09:32:47 +00:00
..
arena
assists Move ModPath->ast::Path function to IDE layer 2020-10-06 16:19:18 +02:00
base_db Properly name the field 2020-10-02 21:38:22 +03:00
cfg
flycheck Spawn a flycheck instance per workspace 2020-09-27 19:41:54 +02:00
hir Move ModPath->ast::Path function to IDE layer 2020-10-06 16:19:18 +02:00
hir_def Add test makr 2020-10-06 19:20:56 +02:00
hir_expand Merge #6033 2020-09-28 11:03:47 +00:00
hir_ty Fix trait object hir formatting behind pointer and references 2020-10-06 14:40:27 +02:00
ide Merge #6128 2020-10-06 18:17:49 +00:00
ide_db Move ide::AnalysisChange -> base_db::Change 2020-10-02 16:45:08 +02:00
mbe Added unit test for negative number literals in macros. 2020-10-06 22:28:13 +02:00
parser Rename record_field_pat to record_pat_field 2020-09-10 18:56:04 +02:00
paths
proc_macro_api
proc_macro_srv
proc_macro_test
profile
project_model Fix the hover dash issues 2020-10-02 21:16:22 +03:00
rust-analyzer Merge #6140 2020-10-06 17:51:20 +00:00
ssr Minor clippy performance suggestions 2020-09-30 15:22:49 -04:00
stdx Add panic_context module for better panic messages 2020-09-29 20:20:47 +02:00
syntax Merge #6160 2020-10-07 09:12:09 +00:00
test_utils
text_edit Actually assert disjointness 2020-09-03 13:37:36 +02:00
toolchain
tt
vfs Rename the method to avoid false promises 2020-09-10 01:45:49 +03:00
vfs-notify