Skip to content

rust-cargo munges paths incorrectly for project with nested crates #1397

@msherry

Description

@msherry

I have noticed that rust-cargo fails to produce output for projects with nested crates, and have produced a minimal repro test case.

I created a project structured like this:

├── Cargo.toml
├── project
│   └── subproj
│       ├── Cargo.toml
│       └── src
│           └── lib.rs

Editing lib.rs to contain just the string xxx gives no error output, when it should be giving an error message. I believe that flycheck is setting subproj to be the working directory, but cargo is giving error messages relative to the top-level Cargo.toml file.

I placed a debugging (message) statement at the end of flycheck-fill-and-expand-error-file-names, after filename expansion had been performed -- this was the output:

(#s(flycheck-error lib.rs|subproj rust-cargo /Users/msherry/projects/rust-debug/project/subproj/project/subproj/src/lib.rs 1 1 expected one of `!` or `::`, found `<eof>` (expected one of `!` or `::` here) error nil group))

Note that the path is given as /Users/msherry/projects/rust-debug/project/subproj/project/subproj/src/lib.rs, which has a duplicate project/subproj/ component -- the full path should be /Users/msherry/projects/rust-debug/project/subproj/src/lib.rs.

I have temporarily worked around this by redefining flycheck-fill-and-expand-error-file-names as follows, but obviously this is just a local hack:

(defun flycheck-fill-and-expand-error-file-names (errors directory)
  "Fill and expand file names in ERRORS relative to DIRECTORY.

Expand all file names of ERRORS against DIRECTORY.  If the file
name of an error is nil fill in the result of function
`buffer-file-name' in the current buffer.

Return ERRORS, modified in-place."
  (seq-do (lambda (err)
            (setf (flycheck-error-filename err)
                  (buffer-file-name)))
          errors)
  errors)

M-x flycheck-verify-setup:

Syntax checkers for buffer lib.rs|subproj in rust-mode:

  rust-cargo
    - may enable:  yes
    - predicate:   t
    - executable:  Found at /Users/msherry/src/client/virtual_env/rust/bin/cargo
    - Cargo.toml:  Found
    - Crate type:  lib
    - Binary name: Not required

  rust
    - may enable: yes
    - predicate:  t
    - executable: Found at /Users/msherry/src/client/virtual_env/rust/bin/rustc

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

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

Flycheck version: 32snapshot (package: 20180204.1346)
Emacs version:    27.0.50
System:           x86_64-apple-darwin16.7.0
Window system:    ns

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions