-
-
Notifications
You must be signed in to change notification settings - Fork 15.4k
Fix confusing compiler diagnostic messages and error code docs #159315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,6 +52,9 @@ pub(crate) struct RlinkCorruptFile<'a> { | |
|
|
||
| #[derive(Diagnostic)] | ||
| #[diag("the compiler unexpectedly panicked. This is a bug")] | ||
| #[note("we would appreciate a bug report with a minimal reproduction at the URL below")] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The "URL below" is on a line that says: So this is not really new information? |
||
| #[note("set `RUST_BACKTRACE=1` environment variable to display a backtrace")] | ||
| #[note("try running `cargo clean` and rebuilding; transient failures do sometimes occur")] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We want to know when incremental errors are repeatedly recurring, and this feels like it tacitly encourages people to not report them. We could say something but I'm not sure it is this sort of "don't worry about it" thing? |
||
| pub(crate) struct Ice; | ||
|
|
||
| #[derive(Diagnostic)] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| The type parameter list on a method call was provided, but the method in | ||
| question doesn't accept type parameters directly at the call site. | ||
|
|
||
| Note: E0035 was previously used for "argument count mismatch" but has since been | ||
| merged into E0087/E0089. The most common way to encounter a related message | ||
| today is when using turbofish syntax on a **trait method** that does not accept | ||
| type parameters at the call site. | ||
|
|
||
| ## Turbofish on trait methods | ||
|
|
||
| A common mistake is trying to specify the output type of a trait method like | ||
| `into()` using turbofish syntax: | ||
|
|
||
| ```rust,ignore | ||
| let x: u32 = y.into::<u32>(); // This does not work | ||
| ``` | ||
|
|
||
| Trait methods do not accept turbofish syntax because the type is resolved by | ||
| the trait bound, not by the call site. Attempting this produces an error | ||
| because `Into::into` takes no type parameters. | ||
|
|
||
| The correct approach is to annotate the **variable binding** with the expected | ||
| type, which lets the compiler infer the correct trait implementation: | ||
|
|
||
| ``` | ||
| let y: i32 = 42; | ||
| let x: u32 = y.into(); // ok: compiler infers `Into<u32>` from the type of `x` | ||
| ``` | ||
|
|
||
| Alternatively, use the fully-qualified syntax which does allow you to name the | ||
| trait explicitly: | ||
|
|
||
| ``` | ||
| let y: i32 = 42; | ||
| let x = Into::<u32>::into(y); // ok: fully-qualified call names the trait | ||
| ``` | ||
|
|
||
| When the type must be specified at the call site for another method, use a | ||
| type annotation on the variable instead of turbofish: | ||
|
|
||
| ``` | ||
| // Instead of: let x = some_value.method::<Type>() | ||
| // Write: let x: Type = some_value.method() | ||
| let x: Vec<char> = "hello".chars().rev().collect(); // ok | ||
| ``` | ||
|
|
||
| See also [E0283] for the "type annotations required" error that often precedes | ||
| the turbofish attempt. | ||
|
|
||
| [E0283]: https://doc.rust-lang.org/error_codes/E0283.html |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not require a minimal reproduction. We need any reproducer. And the link itself contains explanation of what we are hoping for in an ideal bug report.