I tried this code:
use serde::Deserialize;
use std::error::Error;
pub struct S<ErrorType: Error> {
p: std::marker::PhantomData<ErrorType>,
}
impl<ErrorType> S<ErrorType> {
fn f(&self) {
}
}
I expected to see an error like this:
error[E0277]: the trait bound `ErrorType: std::error::Error` is not satisfied
--> src/lib.rs:8:17
|
4 | pub struct S<ErrorType: Error> {
| ----- required by this bound in `S`
...
8 | impl<ErrorType> S<ErrorType> {
| ^^^^^^^^^^^^ the trait `std::error::Error` is not implemented for `ErrorType`
|
help: consider restricting type parameter `ErrorType`
|
8 | impl<ErrorType: std::error::Error> S<ErrorType> {
| ^^^^^^^^^^^^^^^^^^^
Instead, I saw an error like this:
error[E0277]: the trait bound `ErrorType: StdError` is not satisfied
--> src/lib.rs:8:17
|
4 | pub struct S<ErrorType: Error> {
| ----- required by this bound in `S`
...
8 | impl<ErrorType> S<ErrorType> {
| ^^^^^^^^^^^^ the trait `StdError` is not implemented for `ErrorType`
|
help: consider restricting type parameter `ErrorType`
|
8 | impl<ErrorType: StdError> S<ErrorType> {
| ^^^^^^^^^^
Note that the compiler is referring to StdError -- that's not a type in my code nor in scope where the error occurs. I found that if I comment out the use serde::Deserialize; at the top, then the compiler refers to the trait as std::error::Error (as I'd expect). serde does have this in it (under some conditions):
pub use std::error::Error as StdError;
but I haven't pulled that name into scope here.
You can play with this here:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=44c3501773900c0afe548a9a4b871f09
Meta
With the playground link above, the behavior looks the same on stable 1.49, beta 1.50.0-beta.9, and nightly.
I tried this code:
I expected to see an error like this:
Instead, I saw an error like this:
Note that the compiler is referring to
StdError-- that's not a type in my code nor in scope where the error occurs. I found that if I comment out theuse serde::Deserialize;at the top, then the compiler refers to the trait asstd::error::Error(as I'd expect). serde does have this in it (under some conditions):but I haven't pulled that name into scope here.
You can play with this here:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=44c3501773900c0afe548a9a4b871f09
Meta
With the playground link above, the behavior looks the same on stable 1.49, beta 1.50.0-beta.9, and nightly.