Confusing diagnostic for mismatched opaque types #102311
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
I just spent some time being quite confused by an error message I got when mistakenly using an
async fn
whose return type contains animpl Trait
in multiple branches of amatch
statement. On my local toolchain, which is still on 1.62, the corresponding output is:(This is using
tokio_modbus
, there's a reduced repro below.) On current stable (1.64) and nightly (1.66.0-nightly (2022-09-25 f5193a9)), the message seems to have improved with some additional information about what other types the compiler has looked at while trying to match the opaque type. So currently, given the following code (playground):The output is:
While this gives more context on what code might be involved in the error,
usize
, foundbool
", which might be true in some sense, but the actual mismatched types are different instances ofimpl Error
whose only relation to the mentioned primitive types is that the latter occur in the type parameters to the function that produces theimpl Error
,impl Error
return type, which is always confusing because it makes it seem that expected and found are the same (in which case, why is there an error),note
s claim that theFuture::Output
parameters of theasync fn
s used to invokemaybe
are expected/found opaque types. This is still confusing to me, because (as in the case above) the error is about theimpl Error
, and in this caseOutput = Result<usize, std::io::Error>
, which is neither opaque nor the problem (the only thing that would somewhat make sense to me here is thatasync fn
desugars toimpl Future
, which is opaque. But that's not present in the diagnostic at all),(`bool`)
and(`usize`)
in the finalnote
were confusing to me, because they don't appear anywhere in the type (neither the printed abbreviation nor the real type, which at the point of the error is areadyResult<Result<(), io::Error>, impl Error>
) and the message doesn't say what they mean and what they've got to do with the error, andimpl Trait
return types are different when instantiating generic functions with different parametersasync fn two() -> Result<usize, io::Error>
produces an error which points to the locations of the two functions (playground)Possible output that would have helped me better identify the issue:
For completeness, the error is resolved as expected by replacing the opaque type with its concrete type.
The latest change to the message for this error that I could find is #63167, but that doesn't yet include the
(`bool`)
(it just says "opaque type" and adds a source location). #93519 might be similar.The text was updated successfully, but these errors were encountered: