-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
This program (Playground):
use std::{process::Stdio, fs::File};
pub fn foo(_x: Stdio) {}
pub fn bar(x: File) { foo(x) }
errors with
error[E0308]: mismatched types
--> src/lib.rs:3:27
|
3 | pub fn bar(x: File) { foo(x) }
| ^ expected struct `std::process::Stdio`, found struct `std::fs::File`
|
= note: expected type `std::process::Stdio`
found type `std::fs::File`
error: aborting due to previous error
but there is an impl of From<File>
for Stdio
, such that this code (Playground):
use std::{process::Stdio, fs::File};
pub fn foo(_x: Stdio) {}
pub fn bar(x: File) { foo(x.into()) }
compiles and works as expected.
The error message should have a note stating that there is a conversion available, and a fix suggestion. That would be a huge boon for API discoverability. If there are multiple APIs that take File
and return Stdio
, the error message should suggest some of them with some sort of prioritization (From
/TryFrom
traits, ::from
/::new
methods, .as_...
methods, etc.)
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.