-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Accept multiple --error-format flags #62134
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// compile-flags: --error-format=human --error-format=json | ||
|
||
fn foo(_: u32) {} | ||
|
||
fn main() { | ||
foo("Bonjour".to_owned()); | ||
let x = 0u32; | ||
x.salut(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{"message":"mismatched types","code":{"code":"E0308","explanation":" | ||
This error occurs when the compiler was unable to infer the concrete type of a | ||
variable. It can occur for several cases, the most common of which is a | ||
mismatch in the expected type that the compiler inferred for a variable's | ||
initializing expression, and the actual type explicitly assigned to the | ||
variable. | ||
|
||
For example: | ||
|
||
```compile_fail,E0308 | ||
let x: i32 = \"I am not a number!\"; | ||
// ~~~ ~~~~~~~~~~~~~~~~~~~~ | ||
// | | | ||
// | initializing expression; | ||
// | compiler infers type `&str` | ||
// | | ||
// type `i32` assigned to variable `x` | ||
``` | ||
"},"level":"error","spans":[{"file_name":"$DIR/error-format-precedence.rs","byte_start":99,"byte_end":119,"line_start":6,"line_end":6,"column_start":9,"column_end":29,"is_primary":true,"text":[{"text":" foo(\"Bonjour\".to_owned());","highlight_start":9,"highlight_end":29}],"label":"expected u32, found struct `std::string::String`","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"expected type `u32` | ||
found type `std::string::String`","code":null,"level":"note","spans":[],"children":[],"rendered":null}],"rendered":"error[E0308]: mismatched types | ||
--> $DIR/error-format-precedence.rs:6:9 | ||
| | ||
LL | foo(\"Bonjour\".to_owned()); | ||
| ^^^^^^^^^^^^^^^^^^^^ expected u32, found struct `std::string::String` | ||
| | ||
= note: expected type `u32` | ||
found type `std::string::String` | ||
|
||
"} | ||
{"message":"no method named `salut` found for type `u32` in the current scope","code":{"code":"E0599","explanation":" | ||
This error occurs when a method is used on a type which doesn't implement it: | ||
|
||
Erroneous code example: | ||
|
||
```compile_fail,E0599 | ||
struct Mouth; | ||
|
||
let x = Mouth; | ||
x.chocolate(); // error: no method named `chocolate` found for type `Mouth` | ||
// in the current scope | ||
``` | ||
"},"level":"error","spans":[{"file_name":"$DIR/error-format-precedence.rs","byte_start":146,"byte_end":151,"line_start":8,"line_end":8,"column_start":7,"column_end":12,"is_primary":true,"text":[{"text":" x.salut();","highlight_start":7,"highlight_end":12}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":"error[E0599]: no method named `salut` found for type `u32` in the current scope | ||
--> $DIR/error-format-precedence.rs:8:7 | ||
| | ||
LL | x.salut(); | ||
| ^^^^^ | ||
|
||
"} | ||
{"message":"aborting due to 2 previous errors","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to 2 previous errors | ||
|
||
"} | ||
{"message":"Some errors have detailed explanations: E0308, E0599.","code":null,"level":"","spans":[],"children":[],"rendered":"Some errors have detailed explanations: E0308, E0599. | ||
"} | ||
{"message":"For more information about an error, try `rustc --explain E0308`.","code":null,"level":"","spans":[],"children":[],"rendered":"For more information about an error, try `rustc --explain E0308`. | ||
"} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I feel like this is abusing the
multi
argument config. Whilegetopts
doesn't support this kind of "pick last" feature, maybe it would make more sense to teach it about it than work around it here by suggesting that giving an argument multiple times makes sense.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 could also stop using
getopts
, it's not that great.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.
I think we'd either have to
multi*_last
which only differs by returning optionally a single element (picked last) ormulti*
but different strategies might have different requirements and return different values (single or multiple)which I think is more trouble than it's worth in this case?