-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Librustc_resolve diagnostics fixes #33493
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 |
---|---|---|
|
@@ -497,6 +497,91 @@ impl Bar { | |
``` | ||
"##, | ||
|
||
E0408: r##" | ||
An "or" pattern was used where the variable bindings are not consistently bound | ||
across patterns. | ||
|
||
Example of erroneous code: | ||
|
||
```compile_fail | ||
match x { | ||
Some(y) | None => { /* use y */ } // error: variable `y` from pattern #1 is | ||
// not bound in pattern #2 | ||
_ => () | ||
} | ||
``` | ||
|
||
Here, `y` is bound to the contents of the `Some` and can be used within the | ||
block corresponding to the match arm. However, in case `x` is `None`, we have | ||
not specified what `y` is, and the block will use a nonexistent variable. | ||
|
||
To fix this error, either split into multiple match arms: | ||
|
||
``` | ||
let x = Some(1); | ||
match x { | ||
Some(y) => { /* use y */ } | ||
None => { /* ... */ } | ||
} | ||
``` | ||
|
||
or, bind the variable to a field of the same type in all sub-patterns of the | ||
or pattern: | ||
|
||
``` | ||
let x = (0, 2); | ||
match x { | ||
(0, y) | (y, 0) => { /* use y */} | ||
_ => {} | ||
} | ||
``` | ||
|
||
In this example, if `x` matches the pattern `(0, _)`, the second field is set | ||
to `y`. If it matches `(_, 0)`, the first field is set to `y`; so in all | ||
cases `y` is set to some value. | ||
"##, | ||
|
||
E0409: r##" | ||
An "or" pattern was used where the variable bindings are not consistently bound | ||
across patterns. | ||
|
||
Example of erroneous code: | ||
|
||
```compile_fail | ||
let x = (0, 2); | ||
match x { | ||
(0, ref y) | (y, 0) => { /* use y */} // error: variable `y` is bound with | ||
// different mode in pattern #2 | ||
// than in pattern #1 | ||
_ => () | ||
} | ||
``` | ||
|
||
Here, `y` is bound by-value in one case and by-reference in the other. | ||
|
||
To fix this error, just use the same mode in both cases. | ||
Generally using `ref` or `ref mut` where not already used will fix this: | ||
|
||
```ignore | ||
let x = (0, 2); | ||
match x { | ||
(0, ref y) | (ref y, 0) => { /* use y */} | ||
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. http://buildbot.rust-lang.org/builders/auto-linux-64-opt-rustbuild/builds/1038/steps/test/logs/stdio <- it looks like this fails the rollup 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. That's an ICE. I already filed it. We need to add "ignore" on this one or to find a workaround... 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. Fixed. r? (I didn't mention a bug number here since this is supposed to be read by the user. I've left a note on the ICE bug.) |
||
_ => () | ||
} | ||
``` | ||
|
||
Alternatively, split the pattern: | ||
|
||
``` | ||
let x = (0, 2); | ||
match x { | ||
(y, 0) => { /* use y */ } | ||
(0, ref y) => { /* use y */} | ||
_ => () | ||
} | ||
``` | ||
"##, | ||
|
||
E0411: r##" | ||
The `Self` keyword was used outside an impl or a trait. Erroneous code example: | ||
|
||
|
@@ -1145,10 +1230,7 @@ register_diagnostics! { | |
// E0258, | ||
E0402, // cannot use an outer type parameter in this context | ||
E0406, // undeclared associated type | ||
E0408, // variable from pattern #1 is not bound in pattern # | ||
E0409, // variable is bound with different mode in pattern # than in | ||
// pattern #1 | ||
E0410, // variable from pattern is not bound in pattern 1 | ||
// E0410, merged into 408 | ||
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. I think it can be totally removed. Not sure about this. cc @steveklabnik 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. No, we need to keep it mentioned like the other obsolete ones |
||
E0418, // is not an enum variant, struct or const | ||
E0420, // is not an associated const | ||
E0421, // unresolved associated const | ||
|
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.
Shouldn't "or" be "Or"?
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.
And I think the comma is too much here.
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.
It's part of the same sentence
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 still think the comma is too much. ;)