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

Very confusing diagnostics #46388

Closed
est31 opened this issue Nov 30, 2017 · 0 comments
Closed

Very confusing diagnostics #46388

est31 opened this issue Nov 30, 2017 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@est31
Copy link
Member

est31 commented Nov 30, 2017

Let's presume you have the following code in your Cargo.toml:

[dependencies]
flate2 = "0.2"
syntect = "1.8"

And this inside main.rs:

extern crate syntect;
extern crate flate2;

use flate2::FlateReadExt;
use std::io::Read;

pub fn decompress<T :Read>(r :T) -> String {
	let mut decoded = r.gz_decode().unwrap();
	let mut s = String::new();
	decoded.read_to_string(&mut s).unwrap();
	s
}

This works fine.

Now you decide to update flate2 from 0.2 to 1.0 and change the line in Cargo.toml to flate2="1.0", not doing anything else.
You will get an error message that is super confusing:

error[E0432]: unresolved import `flate2::FlateReadExt`
 --> src/lib.rs:4:5
  |
4 | use flate2::FlateReadExt;
  |     ^^^^^^^^^^^^^^^^^^^^ no `FlateReadExt` in the root

warning: unused import: `flate2::FlateReadExt`
 --> src/lib.rs:4:5
  |
4 | use flate2::FlateReadExt;
  |     ^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(unused_imports)] on by default

error[E0599]: no method named `gz_decode` found for type `T` in the current scope
 --> src/lib.rs:8:22
  |
8 |  let mut decoded = r.gz_decode().unwrap();
  |                      ^^^^^^^^^
  |
  = help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope, perhaps add a `use` for it:
  |
4 | use flate2::FlateReadExt;
  |

First it says it can't find the trait. That is the only true thing that rustc says. Version 1.0 of flate2 has removed that trait, so you must change your code.

Second, it says that the trait is not used anywhere. This is wrong, we want to use it, right below!

Third, it suggests to add a use for the trait. But we have done precisely that!

I can even live with the second error, but the suggestion inside the third error is definitely bad.

The underlying issue is probably that syntect version 1.8.x depends on flate2 0.2 so rustc has the metadata of flate2 0.2 loaded. It seems to mix up the versions somehow :).

@nagisa nagisa added the A-diagnostics Area: Messages for errors, warnings, and lints label Nov 30, 2017
@XAMPPRocky XAMPPRocky added C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 26, 2018
@est31 est31 closed this as completed Oct 19, 2018
@rust-lang rust-lang locked and limited conversation to collaborators Oct 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. 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

3 participants