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

ra_cargo_watch: unsigned integer unferflow panic on empty main.rs file #2973

Closed
Veetaha opened this issue Feb 1, 2020 · 16 comments
Closed

Comments

@Veetaha
Copy link
Contributor

Veetaha commented Feb 1, 2020

Reproduction

Tested on the following version (last commit): 12ac379
Note: the reproduction was built with debug symbols, i.e. with debug = 2:
https://github.com/rust-analyzer/rust-analyzer/blob/3f499489f79d05f8cc31b72055155e91bc78fddc/Cargo.toml#L7

Link to youtube

Shallow investigation

Underflow itself happens at this line:
https://github.com/rust-analyzer/rust-analyzer/blob/eba599d9863553d0f7d9d93f4c9050943da171cc/crates/ra_cargo_watch/src/conv.rs#L72

It seems that cargo check sends some invalid event data, because cargo_metadata docs claim that span.line_count is 1-based:

    /// 1-based. The line in the file.
    pub line_start: usize,
    /// 1-based. The line in the file.
    pub line_end: usize,

Maybe this is their bug, however, I am not entirely sure, because I didn't work with ra_cargo_watch crate at all.
@kiljacken, can you take a look, please ?

@kiljacken
Copy link
Contributor

I am unable to reproduce. With a completely empty file, I don't get a diagnostic due to cargo returning no spans, which makes sense. With a single space in the file, I correctly get a 1-indexed span for the diagnostic.

@Veetaha
Copy link
Contributor Author

Veetaha commented Feb 3, 2020

On my laptop it continues to reproduce stably on the latest version of ra. I'll try to get a repo with the reproduction

@Veetaha
Copy link
Contributor Author

Veetaha commented Feb 3, 2020

This is very very weird. I've entirely copied the project hello-world that I opened in extension host to minimize it to the new folder hello-world-2, but the problem doesn't appear in it, it appears only in the original forlder hello-world

@Veetaha
Copy link
Contributor Author

Veetaha commented Feb 3, 2020

I see that when I copy the project for extension host, target/.rustc_info.json file changes when I open a vscode instance. And some other dependencies' binaries also start to differ.

@kiljacken
Copy link
Contributor

we can probably just make it a saturating sub and call it good, will do that tomorrow, just to avoid crashes in debug on bad input :)

@Veetaha
Copy link
Contributor Author

Veetaha commented Feb 3, 2020

Hmm... I see I used 1.42 nightly there ...
But in the copied project I use 1.41 and thats why it works ok

@Veetaha
Copy link
Contributor Author

Veetaha commented Feb 3, 2020

I don't know why when I copy the project and open it in the extension host target/.rustc_info.json gets overriden from this

{
    "rustc_fingerprint": 3114702442570252495,
    "outputs": {
        "1164083562126845933": ["rustc 1.42.0-nightly (b5a3341f1 2020-01-20)\nbinary: rustc\ncommit-hash: b5a3341f1b8b475990e9d1b071b88d3c280936b4\ncommit-date: 2020-01-20\nhost: x86_64-unknown-linux-gnu\nrelease: 1.42.0-nightly\nLLVM version: 9.0\n", ""],
        "4476964694761187371": ["___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/veetaha/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu\ndebug_assertions\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"mmx\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_has_atomic_load_store=\"16\"\ntarget_has_atomic_load_store=\"32\"\ntarget_has_atomic_load_store=\"64\"\ntarget_has_atomic_load_store=\"8\"\ntarget_has_atomic_load_store=\"ptr\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_thread_local\ntarget_vendor=\"unknown\"\nunix\n", ""],
        "6783195907413256411": ["___\n", ""]
    },
    "successes": {}
}

to this

{
    "rustc_fingerprint": 9635345540727848879,
    "outputs": {
        "1164083562126845933": ["rustc 1.41.0 (5e1a79984 2020-01-27)\nbinary: rustc\ncommit-hash: 5e1a799842ba6ed4a57e91f7ab9435947482f7d8\ncommit-date: 2020-01-27\nhost: x86_64-unknown-linux-gnu\nrelease: 1.41.0\nLLVM version: 9.0\n", ""],
        "4476964694761187371": ["___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/veetaha/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\ndebug_assertions\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"unknown\"\nunix\n", ""]
    },
    "successes": {}
}

But when I open the original project hello-world no files are overriden and I suppose that cargo check 1.41 works with the data generated by cargo 1.42

@Veetaha
Copy link
Contributor Author

Veetaha commented Feb 3, 2020

@matklad, do you have any ideas on why .rustc_info.json in the original project is not overriden with 1.41 data, but remains the same when I open the extension host?
I literally cp -r hello-world hello-world-2 and then opened hello-world-2 in extension host and rustc_info.json was overriden, but with original hello-world it stays the same.
image

@SomeoneToIgnore
Copy link
Contributor

Can rustup override be involved somehow?
Run rustup override list to see all of them.

@Veetaha
Copy link
Contributor Author

Veetaha commented Feb 3, 2020

@SomeoneToIgnore yes, you are right, I see hello-world directory in the output of rustup override list. So this means that when I open this dir in vscode, rust-analyzer uses nightly cargo, doesn't it?

@SomeoneToIgnore
Copy link
Contributor

SomeoneToIgnore commented Feb 3, 2020

It means what whatever rust tooling related thing (including cargo commands) you try to do in that directory, nightly toolchain will be forced to be used.
RA uses the same rust tooling hence uses nightly implicitly.

@Veetaha
Copy link
Contributor Author

Veetaha commented Feb 3, 2020

Okay, I think I should forward this as a regression report to rustc team then...

@Veetaha
Copy link
Contributor Author

Veetaha commented Feb 3, 2020

@kiljacken I think you should not add a saturation here, an assert!() at max. I've filed a bug to cargo repo here

@lnicola
Copy link
Member

lnicola commented Feb 3, 2020

Beware, I've seen stuff break when renaming a project directory without a follow-up cargo clean.

@Veetaha
Copy link
Contributor Author

Veetaha commented Feb 3, 2020

@lnicola thank you for the precaution. For anyone curious, I've created a repo with the reproduction.

@Veetaha
Copy link
Contributor Author

Veetaha commented Feb 4, 2020

I'll close the issue since this is a regression of rustc-1.42-nightly.

@Veetaha Veetaha closed this as completed Feb 4, 2020
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

4 participants