Neomake: Incorrect error highlighting for Rust

Created on 11 Jan 2017  路  4Comments  路  Source: neomake/neomake

Only the first character in position where error occured is highlighted:

Expected behavior

The whole word selfff should be highlighted.

Steps to reproduce

Switch to nightly Rust: rustup default nightly
No special settings in vimrc, besides enabling neomake.
Open any Rust source with an error.
Run :Neomake

Output of the ":verb NeomakeInfo" command

Neomake debug information

Async support: 1
Current filetype: rust

Enabled makers

For the current filetype (with :Neomake):

  • rustc
    errorformat: '%-Gerror: aborting due to previous error,%-Gerror: aborting due to %\d%\+ previous errors,%-Gerror: Could not compile %s.,%Eerror[E%n]: %m,%Eerror: %m,%Wwarning: %m,%Inote: %m,%-Z %#--> %f:%l:%c,%G %#= %*[^:]: %m,%G %#| %#%\^%\+ %m,%I%>help: %#%m,%Z %#%m,%-G%s'
    exe: 'rustc'
    args: []
    NOTE: you can define g:neomake_rust_enabled_makers to configure it (or b:neomake_rust_enabled_makers).

For the project (with :Neomake!): None.
NOTE: you can define g:neomake_enabled_makers to configure it.

Default maker settings:

  • remove_invalid_entries: 0
  • buffer_output: 1
Settings
g:neomake_place_signs = 1


shell: /bin/bash
shellcmdflag: -c
Windows: 0

:version

NVIM 0.1.7
Build type: RelWithDebInfo
Compilation: /usr/bin/cc -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic -Wconversion -Wp,-U_FORTIFY_SOURCE -Wp,-D_FORTIFY_SOURCE=1 -O2 -g -DDISABLE_LOG -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wvla -fstack-protector-strong -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -DHAVE_CONFIG_H -D_GNU_SOURCE -I/builddir/build/BUILD/neovim-0.1.7/obj/config -I/builddir/build/BUILD/neovim-0.1.7/src -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/builddir/build/BUILD/neovim-0.1.7/obj/src/nvim/auto -I/builddir/build/BUILD/neovim-0.1.7/obj/include
Compiled by mockbuild

Optional features included (+) or not (-): +acl   +iconv    +jemalloc +tui      
For differences from Vim, see :help vim-differences

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

:messages

"work/contests/a.rs" 251L, 6925C

"a.rs" 251L, 6926C written
Already at newest change
1 change; before #213  10 seconds ago
"a.rs" 251L, 6925C written


"a.rs" 251L, 6928C written

NVIM 0.1.7
Build type: RelWithDebInfo
Compilation: /usr/bin/cc -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic -Wconversion -Wp,-U_FORTIFY_SOURCE -Wp,-D_FORTIFY_SOURCE=1 -O2 -g -DDISABLE_LOG -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wvla -fstack-protector-strong -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -DHAVE_CONFIG_H -D_GNU_SOURCE -I/builddir/build/BUILD/neovim-0.1.7/obj/config -I/builddir/build/BUILD/neovim-0.1.7/src -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/builddir/build/BUILD/neovim-0.1.7/obj/src/nvim/auto -I/builddir/build/BUILD/neovim-0.1.7/obj/include
enhancement maker

Most helpful comment

Just wanted to note that I my changes in #942 fix this issue.

All 4 comments

Yep, this could be done.
I started with some generic extraction of stuff between quotes, and expanding it to backticks would make this work.

Rust's compiler can output errors in JSON format. Example command: rustc --error-format json a.rs
From there you can easily extract precise positions of errors.

This is the error (formatted JSON for readability):

{
  "message":"unresolved name `selfff`",
  "code":{
    "code":"E0425",
    "explanation":"\nAn unresolved name was used.\n\nErroneous code examples:\n\n```compile_fail,E0425\nsomething_that_doesnt_exist::foo;\n// error: unresolved name `something_that_doesnt_exist::foo`\n\n// or:\n\ntrait Foo {\n    fn bar() {\n        Self; // error: unresolved name `Self`\n    }\n}\n\n// or:\n\nlet x = unknown_variable;  // error: unresolved name `unknown_variable`\n```\n\nPlease verify that the name wasn't misspelled and ensure that the\nidentifier being referred to is valid for the given situation. Example:\n\n```\nenum something_that_does_exist {\n    Foo,\n}\n```\n\nOr:\n\n```\nmod something_that_does_exist {\n    pub static foo : i32 = 0i32;\n}\n\nsomething_that_does_exist::foo; // ok!\n```\n\nOr:\n\n```\nlet unknown_variable = 12u32;\nlet x = unknown_variable; // ok!\n```\n\nIf the item is not defined in the current module, it must be imported using a\n`use` statement, like so:\n\n```ignore\nuse foo::bar;\nbar();\n```\n\nIf the item you are importing is not defined in some super-module of the\ncurrent module, then it must also be declared as public (e.g., `pub fn`).\n"
  },
  "level":"error",
  "spans":[
    {
      "file_name":"a.rs",
      "byte_start":1252,
      "byte_end":1258,
      "line_start":47,
      "line_end":47,
      "column_start":57,
      "column_end":63,
      "is_primary":true,
      "text":[
        {
          "text":"            unsafe { ptr::copy_nonoverlapping(self.src, selfff.dst, 1); }",
          "highlight_start":57,
          "highlight_end":63
        }
      ],
      "label":"did you mean `self`?",
      "suggested_replacement":null,
      "expansion":null
    }
  ],
  "children":[

  ],
  "rendered":null
}

Unfortunately we cannot handle JSON well yet..

Just wanted to note that I my changes in #942 fix this issue.

Was this page helpful?
0 / 5 - 0 ratings