Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust error parsing ignores spans with useful replacement text in children #1393

Closed
tchajed opened this issue Feb 2, 2018 · 2 comments
Closed

Comments

@tchajed
Copy link

tchajed commented Feb 2, 2018

Flycheck does not capture all of the information in Rust's error message for the following mistake (a misspelled macro):

fn main() {
  prnt!("")
}

Flycheck reports the following:

     2   5 error           cannot find macro `prnt!` in this scope (rust)
     2   5 info            you could try the macro (rust)

but Rust's rendered error is:

error: cannot find macro `printf!` in this scope
  --> src/main.rs:13:5
   |
13 |     printf!("%s\n", fname)
   |     ^^^^^^ help: you could try the macro: `print`

Here's Rust's JSON error (just the message field of this error):

{
  "children": [
    {
      "children": [],
      "code": null,
      "level": "help",
      "message": "you could try the macro",
      "rendered": null,
      "spans": [
        {
          "byte_end": 355,
          "byte_start": 349,
          "column_end": 11,
          "column_start": 5,
          "expansion": null,
          "file_name": "src/main.rs",
          "is_primary": true,
          "label": null,
          "line_end": 13,
          "line_start": 13,
          "suggested_replacement": "print",
          "text": [
            {
              "highlight_end": 11,
              "highlight_start": 5,
              "text": "    printf!(\"%s\\n\", fname)"
            }
          ]
        }
      ]
    }
  ],
  "code": null,
  "level": "error",
  "message": "cannot find macro `printf!` in this scope",
  "rendered": "error: cannot find macro `printf!` in this scope\n  --> src/main.rs:13:5\n   |\n13 |     printf!(\"%s\\n\", fname)\n   |     ^^^^^^ help: you could try the macro: `print`\n\n",
  "spans": [
    {
      "byte_end": 355,
      "byte_start": 349,
      "column_end": 11,
      "column_start": 5,
      "expansion": null,
      "file_name": "src/main.rs",
      "is_primary": true,
      "label": null,
      "line_end": 13,
      "line_start": 13,
      "suggested_replacement": null,
      "text": [
        {
          "highlight_end": 11,
          "highlight_start": 5,
          "text": "    printf!(\"%s\\n\", fname)"
        }
      ]
    }
  ]
}

Note that "you could try the macro: print" is represented as "you could try the macro" plus a suggested replacement. It looks like flycheck ignores spans in children under the assumption they aren't used, but this seems to be a counter example.

Setup information

I'm using Rust nightly (1.25.0, 2018-02-01), but I double checked the JSON from Rust stable (1.23.0) and it has the same structure.

I didn't try to reproduce this in emacs -Q.

M-x flycheck-verify-setup:

Syntax checkers for buffer test.rs in rust-mode:

  rust-cargo (disabled)
    - may enable:  Automatically disabled!
    - predicate:   t
    - executable:  Found at /Users/tchajed/.cargo/bin/cargo
    - Cargo.toml:  Missing
    - Crate type:  lib
    - Binary name: Not required

  rust
    - may enable: yes
    - predicate:  t
    - executable: Found at /Users/tchajed/.cargo/bin/rustc

Flycheck Mode is enabled. Use SPC u C-c ! x to enable disabled checkers.

--------------------

Flycheck version: 32snapshot (package: 20180123.1419)
Emacs version:    25.2.1
System:           x86_64-apple-darwin13.4.0
Window system:    ns

operating system: OS X 10.11
emacs version: GNU Emacs 25.2.1 (x86_64-apple-darwin13.4.0, NS appkit-1265.21 Version 10.9.5 (Build 13F1911)) of 2017-04-21
Flycheck version: 32snapshot (package: 20180123.1419)

@fmdkdd
Copy link
Member

fmdkdd commented Feb 2, 2018

Thank you for the report.

I think I fixed that in #1385. Could you try that branch (or just the patch to flycheck-rustc-parse) and see if that works for you?

@tchajed
Copy link
Author

tchajed commented May 6, 2018

Sorry for the late response - I can confirm this is fixed on the master branch, and Spacemacs gets dependencies from MELPA rather than MELPA Stable so that version is used by default.

@tchajed tchajed closed this as completed May 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants