Skip to content

Very confusing diagnostics #46388

Closed
Closed
@est31

Description

@est31

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 :).

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions