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

Multiple applicable provide methods in scope #185

Closed
dtolnay opened this issue Sep 5, 2022 · 0 comments · Fixed by #190
Closed

Multiple applicable provide methods in scope #185

dtolnay opened this issue Sep 5, 2022 · 0 comments · Fixed by #190

Comments

@dtolnay
Copy link
Owner

dtolnay commented Sep 5, 2022

#![feature(error_generic_member_access, provide_any)]

use thiserror::Error;
use std::error::Error;

#[derive(Error, Debug)]
#[error("...")]
struct MyError {
    #[source]
    #[backtrace]
    x: std::io::Error,
}

//use std::any::Provider;

This compiles, but if you uncomment the Provider import, it fails because both Error and Provider contain a method named provide (I consider this a flaw in the standard library API... rust-lang/rust#99301 rust-lang/rust#96024).

error[E0034]: multiple applicable items in scope
  --> src/main.rs:11:5
   |
11 |     x: std::io::Error,
   |     ^ multiple `provide` found
   |
   = note: candidate #1 is defined in an impl of the trait `Provider` for the type `E`
   = note: candidate #2 is defined in an impl of the trait `std::error::Error` for the type `std::io::Error`
help: disambiguate the associated function for candidate #1
   |
11 |     Provider::provide(&x, Error): std::io::Error,
   |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
help: disambiguate the associated function for candidate #2
   |
11 |     std::error::Error::provide(&x, Error): std::io::Error,
   |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.

1 participant