Code
pub struct LooooooongObscureType<A, B>(A, B);
pub struct WrapperWithMismatchedParameters<W = usize, B = Vec<W>>(W, B);
pub struct MainType<H, L> {
g: H,
l: L,
}
pub fn f(
x: MainType<
LooooooongObscureType<Vec<&'static [usize]>, &'static [u64]>,
WrapperWithMismatchedParameters<usize, &'static [usize]>,
>,
) {
g(x);
}
pub fn g(
x: MainType<
LooooooongObscureType<Vec<&'static [usize]>, &'static [u64]>,
WrapperWithMismatchedParameters,
>,
) {
unimplemented!();
}
Current output
error[E0308]: mismatched types
--> src/lib.rs:15:7
|
15 | g(x);
| - ^ expected `Vec<usize>`, found `&'static [usize]`
| |
| arguments to this function are incorrect
|
= note: expected struct `MainType<_, WrapperWithMismatchedParameters<_>>` (`Vec<usize>`)
found struct `MainType<_, WrapperWithMismatchedParameters<_>>` (`&'static [usize]`)
note: function defined here
--> src/lib.rs:18:8
|
18 | pub fn g(
| ^
19 | / x: MainType<
20 | | LooooooongObscureType<Vec<&'static [usize]>, &'static [u64]>,
21 | | WrapperWithMismatchedParameters,
22 | | >,
| |_____-
For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` (lib) due to 1 previous error
Desired output
error[E0308]: mismatched types
--> src/lib.rs:15:7
|
15 | g(x);
| - ^ expected `Vec<usize>`, found `&'static [usize]`
| |
| arguments to this function are incorrect
|
= note: expected struct `MainType<_, WrapperWithMismatchedParameters<_, Vec<usize>>>`
found struct `MainType<_, WrapperWithMismatchedParameters<_, &'static [usize]>>`
note: function defined here
--> src/lib.rs:18:8
|
18 | pub fn g(
| ^
19 | / x: MainType<
20 | | LooooooongObscureType<Vec<&'static [usize]>, &'static [u64]>,
21 | | WrapperWithMismatchedParameters,
22 | | >,
| |_____-
For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` (lib) due to 1 previous error
or
error[E0308]: mismatched types
--> src/lib.rs:15:7
|
15 | g(x);
| - ^ expected `Vec<usize>`, found `&'static [usize]`
| |
| arguments to this function are incorrect
|
= note: expected struct `MainType<_, WrapperWithMismatchedParameters<_, Vec<usize>>>`
found struct `MainType<_, WrapperWithMismatchedParameters<_, &'static [usize]>>`
note: function defined here
--> src/lib.rs:18:8
|
18 | pub fn g(
| ^
19 | / x: MainType<
20 | | LooooooongObscureType<Vec<&'static [usize]>, &'static [u64]>,
21 | | WrapperWithMismatchedParameters<usize, Vec<usize>>,
22 | | >,
| |_____-
For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` (lib) due to 1 previous error
Rationale and extra context
The current error message does not tell me the mismatch is in WrapperWithMismatchedParameters rather than in LooooooongObscureType. It is also inconsistent with the error message I would get if WrapperWithMismatchedParameters has without the default types.
Other cases
When removing the default for the first parameter (which is not the mismatched one) like this:
pub struct LooooooongObscureType<A, B>(A, B);
pub struct WrapperWithMismatchedParameters<W, B = Vec<W>>(W, B);
pub struct MainType<H, L> {
g: H,
l: L,
}
pub fn f(
x: MainType<
LooooooongObscureType<Vec<&'static [usize]>, &'static [u64]>,
WrapperWithMismatchedParameters<usize, &'static [usize]>,
>,
) {
g(x);
}
pub fn g(
x: MainType<
LooooooongObscureType<Vec<&'static [usize]>, &'static [u64]>,
WrapperWithMismatchedParameters<usize>,
>,
) {
unimplemented!();
}
the error message is clearer:
error[E0308]: mismatched types
--> src/lib.rs:15:7
|
15 | g(x);
| - ^ expected `Vec<usize>`, found `&'static [usize]`
| |
| arguments to this function are incorrect
|
= note: expected struct `MainType<_, WrapperWithMismatchedParameters<_, Vec<usize>>>`
found struct `MainType<_, WrapperWithMismatchedParameters<_, &'static [usize]>>`
note: function defined here
--> src/lib.rs:18:8
|
18 | pub fn g(
| ^
19 | / x: MainType<
20 | | LooooooongObscureType<Vec<&'static [usize]>, &'static [u64]>,
21 | | WrapperWithMismatchedParameters<usize>,
22 | | >,
| |_____-
For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` (lib) due to 1 previous error
Rust Version
Anything else?
playground
Code
Current output
Desired output
or
Rationale and extra context
The current error message does not tell me the mismatch is in
WrapperWithMismatchedParametersrather than inLooooooongObscureType. It is also inconsistent with the error message I would get ifWrapperWithMismatchedParametershas without the default types.Other cases
When removing the default for the first parameter (which is not the mismatched one) like this:
the error message is clearer:
Rust Version
Anything else?
playground