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

Unhelpful compiler advice when using context #30

Closed
ChrisJefferson opened this issue Oct 21, 2019 · 2 comments · Fixed by #31
Closed

Unhelpful compiler advice when using context #30

ChrisJefferson opened this issue Oct 21, 2019 · 2 comments · Fixed by #31

Comments

@ChrisJefferson
Copy link

I'm not sure if this is anyhow's fault, or the compiler's fault.

When using .context, I get the following error:

error[E0599]: no method named `context` found for type `std::result::Result<(), anyhow::error::Error>` in the current scope
  --> src/main.rs:83:13
   |
83 |             context(format!("failure in {} with nesting", c.name))?;
   |             ^^^^^^^ method not found in `std::result::Result<(), anyhow::error::Error>`
   |
   = 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:
   |
19 | use anyhow::context::Context;

That last line is awful advice, as that just leads to:

error[E0603]: module `context` is private
  --> src/main.rs:24:13
   |
24 | use anyhow::context::Context;
   |             ^^^^^^^

The real fix is: use anyhow::Context. I don't know how to fix this message, but I feel it would make anyhow more usable if it was fixed.

@dtolnay
Copy link
Owner

dtolnay commented Oct 21, 2019

Thanks! This is the compiler being dumb. It shouldn't put private paths in suggestions like that. Could you check whether there is an issue already filed for this in rust-lang/rust and file one if you can't find an existing one?

I implemented a temporary workaround in #31.

@ChrisJefferson
Copy link
Author

I think this is rust-lang/rust#59269

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

Successfully merging a pull request may close this issue.

2 participants