racer icon indicating copy to clipboard operation
racer copied to clipboard

Racer Crashing On Pretty Much Everything

Open nko12 opened this issue 8 years ago • 11 comments

Using Racer version 1.2.10, and I'm using it from within Visual Studio Code, version 1.2.1.

Unfortunately, as helpful as this extension is, it is incredibly annoying to use. If my mouse is above either a string or a comment, VS reports that racer crashes, with the exact same error every time:

Racer Error: thread main panicked at assertion failed: begin <= end, ../src/libcore\str/mod.rs:1569

Anything I can do to fix this? I'm brand new to Rust and I heavily rely on code completion to help me learn the APIs of a language faster.

nko12 avatar Jun 23 '16 08:06 nko12

Can you post the complete point that crashes racer?

yodalee avatar Jul 08 '16 14:07 yodalee

I'm not sure what you mean by the "complete point". Additionally, it seems to have gotten worse. It now just randomly crashes when mousing over various things, not just comments and static strings anymore. My Visual Studio Code version is now 1.3.1.

nko12 avatar Jul 19 '16 06:07 nko12

At this point, Racer just crashes any time I move my mouse over anything in the code. Does not work at all. Visual Studio Code 1.3.1, Rust Compiler 1.10.0 MSVC, installed via Rustup, Windows 10 1511 (10586.494).

nko12 avatar Jul 20 '16 04:07 nko12

I think I've determined the crash that @nko12 is talking about. when the find-definition command is executed and the linenum and charnum point to a static string or comment racer crashes with:

thread '<main>' panicked at 'begin <= end (101 <= 96) when slicing <source code of file here>, ../src/libcore\str/mod.rs:1750

stack backtrace:
   0:           0x96701c - <unknown>
   1:           0x966537 - <unknown>
   2:           0x92bbc4 - <unknown>
   3:           0x9680c5 - <unknown>
   4:           0x92db05 - <unknown>
   5:           0x967d2c - <unknown>
   6:           0x97b415 - <unknown>
   7:           0x9a2b1d - <unknown>
   8:           0x4f14a4 - <unknown>
   9:           0x4e4f80 - <unknown>
  10:           0x49cd66 - <unknown>
  11:           0x4a1207 - <unknown>
  12:           0x4a0980 - <unknown>
  13:           0x42f7f0 - <unknown>
  14:           0x431fc9 - <unknown>
  15:           0x965cfc - <unknown>
  16:           0x9764d8 - <unknown>
  17:           0x965af4 - <unknown>
  18:           0x4013b4 - <unknown>
  19:           0x4014e7 - <unknown>
  20:     0x7ffc69a08363 - <unknown>

racer version is 1.2.10, compiled rustc 1.10 window gnu.

I suggest changing the name of this issue to more accurately reflect the issue.

ZoeyR avatar Jul 24 '16 21:07 ZoeyR

I created a minimal snippet of code that can generate the crash.

Command: racer find-definition 2 10 <path to source>

Source code:

pub fn test() {
    // crash racer
    let x = 5;
}

Crash report:

thread '<main>' panicked at 'begin <= end (41 <= 20) when slicing `pub fn test() {
    // crash racer
    let x = 5;
}`', ../src/libcore\str/mod.rs:1750
stack backtrace:
   0:           0x96701c - <unknown>
   1:           0x966537 - <unknown>
   2:           0x92bbc4 - <unknown>
   3:           0x9680c5 - <unknown>
   4:           0x92db05 - <unknown>
   5:           0x967d2c - <unknown>
   6:           0x97b415 - <unknown>
   7:           0x9a2b1d - <unknown>
   8:           0x4f14a4 - <unknown>
   9:           0x4e4f80 - <unknown>
  10:           0x49cd66 - <unknown>
  11:           0x4a1207 - <unknown>
  12:           0x4a0980 - <unknown>
  13:           0x42f7f0 - <unknown>
  14:           0x431fc9 - <unknown>
  15:           0x965cfc - <unknown>
  16:           0x9764d8 - <unknown>
  17:           0x965af4 - <unknown>
  18:           0x4013b4 - <unknown>
  19:           0x4014e7 - <unknown>
  20:     0x7ffc69a08363 - <unknown>

ZoeyR avatar Jul 24 '16 21:07 ZoeyR

Further investigation narrows down the issue to scopes::get_start_of_search_expr which will only return a single word in a comment or string literal. This combines with scopes::split_into_context_and_completion to cause racer to try an incorrect completion.

ZoeyR avatar Jul 24 '16 23:07 ZoeyR

Here is my trace result: nameres.rs: 201, it call scopes::find_stmt_start(), which return stmtstart at position after scopestart There is a simple solution that the function will immediately return an iterator to empty vector if stmtstart is larger than scopestart. In my testing, it may find nothing but at least not crash. The find_stmt_start() failed to find correct position with following code:

msrc.from(scopestart).iter_stmts()
    .find(|&(_, end)| scopestart + end > point)
    .map(|(start, _)| scopestart + start)

I didn't dig into it, yet. It is quite difficult to trace code with iterator and functional programming Orz.

yodalee avatar Jul 27 '16 13:07 yodalee

I tried to figure out what's happening:

For the sake of simplicity, this is the code I used:

fn test() { /* crash */ let x = 5; }

racer find-definition 1 18 main.rs reproduces the bug. I added some extra debug messages, here's the output:

DEBUG:racer::nameres: searching scope Both start: 14 point: 15 'crash' "main.rs" ExactMatch local: true, session: Session { .. }
DEBUG:racer::nameres: search_scope found matches ExactMatch []
DEBUG:racer::nameres: search_scope_headers for |crash| pt: 13
DEBUG:racer::scopes: scope_start masked_src: "fn test() { "
DEBUG:racer::scopes: scope_start count: 1
DEBUG:racer::scopes: find_stmt_start scopestart: 12
DEBUG:racer::scopes: find_stmt_start found, before mapping: Some((12, 22))
DEBUG:racer::nameres: search_scope_headers stmtstart: 24

scopes::scope_start finds the { character in fn test() { , so in scopes::find_stmt_start, scopestart becomes 12, but the found statement is let x = 5;, because comments are already erased from msrc. I'm not familiar enough with the codebase to figure out what's wrong exactly, I'll investigate further if I have some time.

pmarcelll avatar Dec 27 '16 20:12 pmarcelll

Does this still repro on v2.0.9?

TedDriggs avatar Jul 14 '17 23:07 TedDriggs

still same thing on a few toolchains including nightly-2019-04-26-i686-pc-windows-msvc, but also on stable

vhnatyk avatar Apr 28 '19 08:04 vhnatyk

Same issue persists with rustc 1.46.0-nightly (ff5b446d2 2020-06-23) with VSCodium version 1.47.3 x64

orhun avatar Aug 17 '20 13:08 orhun