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

In save-analysis, enum variant ref ids are inconsistent to def ids #61302

Closed
est31 opened this issue May 29, 2019 · 0 comments
Closed

In save-analysis, enum variant ref ids are inconsistent to def ids #61302

est31 opened this issue May 29, 2019 · 0 comments
Labels
A-save-analysis Area: saving results of analyses such as inference and borrowck results to a file. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@est31
Copy link
Member

est31 commented May 29, 2019

In rls/vscode, if you right-click on an enum name, it shows you all its uses. If you right click on a name of one of its variants, there are no uses shown despite there being some.

This doesn't seem to be fault of rls. Apparently the save-analysis info fed to rls is wrong. See the output presented here. In the defs table, the Foo enum has index 12 while the Foo::Bar variant has index 13. In the refs table, the correct index 12 is used to reference the enum, but the enum variant is referenced with index 14 which doesn't even exist in the defs table.

$ cargo new save-analysis-demo
$ cd save-analysis-demo
$ cat src/main.rs
enum Foo {
        Bar,
}
fn main() {
        let v = Foo::Bar;
}
$ RUSTFLAGS="-Z save-analysis" cargo +nightly check
$ cat target/debug/deps/save-analysis/save_analysis_demo-*.json  | jq '.defs'
[...]
  {
    "kind": "TupleVariant",
    "id": {
      "krate": 0,
      "index": 13
    },
    "span": {
      "file_name": "src/main.rs",
      "byte_start": 12,
      "byte_end": 15,
      "line_start": 2,
      "line_end": 2,
      "column_start": 2,
      "column_end": 5
    },
    "name": "Bar",
    "qualname": "::Foo::Bar",
    "value": "Foo::Bar",
    "parent": {
      "krate": 0,
      "index": 12
    },
    "children": [],
    "decl_id": null,
    "docs": "",
    "sig": null,
    "attributes": []
  },
  {
    "kind": "Enum",
    "id": {
      "krate": 0,
      "index": 12
    },
    "span": {
      "file_name": "src/main.rs",
      "byte_start": 5,
      "byte_end": 8,
      "line_start": 1,
      "line_end": 1,
      "column_start": 6,
      "column_end": 9
    },
    "name": "Foo",
    "qualname": "::Foo",
    "value": "Foo::{Bar}",
    "parent": null,
    "children": [
      {
        "krate": 0,
        "index": 13
      }
    ],
    "decl_id": null,
    "docs": "",
    "sig": null,
    "attributes": []
  },
[...]
$ cat target/debug/deps/save-analysis/save_analysis_demo-*.json  | jq '.refs'
[
  {
    "kind": "Variable",
    "span": {
      "file_name": "src/main.rs",
      "byte_start": 45,
      "byte_end": 48,
      "line_start": 5,
      "line_end": 5,
      "column_start": 15,
      "column_end": 18
    },
    "ref_id": {
      "krate": 0,
      "index": 14
    }
  },
  {
    "kind": "Type",
    "span": {
      "file_name": "src/main.rs",
      "byte_start": 40,
      "byte_end": 43,
      "line_start": 5,
      "line_end": 5,
      "column_start": 10,
      "column_end": 13
    },
    "ref_id": {
      "krate": 0,
      "index": 12
    }
  }
]
@jonas-schievink jonas-schievink added A-save-analysis Area: saving results of analyses such as inference and borrowck results to a file. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 29, 2019
@bors bors closed this as completed in 5bfa7f0 Jun 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-save-analysis Area: saving results of analyses such as inference and borrowck results to a file. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants