Closed
Description
Code
// also available as a playground here:
// https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=4e1b3126262820b760f4ee5037d629e4
use std::fmt::Debug;
use std::marker::PhantomData;
#[allow(unused)]
struct Codec<EncodeLine, DecodeLine> {
phantom_decode: PhantomData<DecodeLine>,
phantom_encode: PhantomData<EncodeLine>,
}
pub enum ParseError {}
impl<EncodeLine, DecodeLine> Codec<EncodeLine, DecodeLine> where
DecodeLine: Debug + TryFrom<String>,
<DecodeLine as TryFrom<String>>::Error: ParseError,
// // suggested fix: replace the above two lines with the following one
// DecodeLine: Debug + TryFrom<String><Error = ParseError>,
// // actual fix: replace the above two lines with the following one
// DecodeLine: Debug + TryFrom<String, Error = ParseError>
{
}
Current output
Compiling playground v0.0.1 (/playground)
error[E0404]: expected trait, found enum `ParseError`
--> src/lib.rs:14:45
|
14 | <DecodeLine as TryFrom<String>>::Error: ParseError,
| ^^^^^^^^^^ not a trait
|
help: constrain the associated type to `ParseError`
|
14 | DecodeLine: TryFrom<String><Error = ParseError>,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
help: consider importing one of these items instead
|
1 + use nom::error::ParseError;
|
1 + use winnow::error::ParseError;
|
For more information about this error, try `rustc --explain E0404`.
Desired output
Compiling playground v0.0.1 (/playground)
error[E0404]: expected trait, found enum `ParseError`
--> src/lib.rs:14:45
|
14 | <DecodeLine as TryFrom<String>>::Error: ParseError,
| ^^^^^^^^^^ not a trait
|
help: constrain the associated type to `ParseError`
|
14 | DecodeLine: TryFrom<String, Error = ParseError>,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
help: consider importing one of these items instead
|
1 + use nom::error::ParseError;
|
1 + use winnow::error::ParseError;
|
For more information about this error, try `rustc --explain E0404`.
Rationale and extra context
The generated constraint recommendation appears not to be aware that TryFrom
already has defined generics and just plugs its own generic parameter at the end naively. (TryFrom<String><Error = ParseError>
)
Instead it ought to recognize and expand the generic parameters (like so: TryFrom<String, Error = ParseError>
)
Other cases
No response
Anything else?
No response