-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Suggest using enum when a variant is used as a type #40775
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
Conversation
|
r? @arielb1 (rust_highfive has picked a reviewer for you, use r? to override) |
ee5cd9e to
d7b5c35
Compare
src/librustc_resolve/lib.rs
Outdated
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.
This else block should run only if is_expected(Def::Enum) is true.
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.
Could you also move this logic into a separate function?
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.
Could you add an UI test where the found enum is not in scope? How does X in "did you mean to use X?" look in this case?
|
This patch covers the case "no resolution found -> candidate variants found elsewhere -> enums of these variants are suggested". |
|
I believe all cases are handled now, but the wording for the standard enums is a bit rough as it stands now: error[E0573]: expected type, found variant `Some`
--> $DIR/issue-35675.rs:27:13
|
27 | fn qux() -> Some {
| ^^^^ not a type
|
= help: there is an enum variant `std::prelude::v1::Some`, did you mean to use `std::prelude::v1`?
= help: there is an enum variant `std::prelude::v1::Option::Some`, did you mean to use `std::prelude::v1::Option`? |
7b1fa66 to
44d7726
Compare
You can use Could you also add a test for #40775 (comment)? enum Enum { Variant }
fn f() -> Enum::Variant // successfully resolved to variant, but enum is expected
{ ... } |
44d7726 to
30c544a
Compare
|
@petrochenkov done. |
30c544a to
9e835b5
Compare
Given a file:
```rust
enum Fruit {
Apple(i64),
Orange(i64),
}
fn should_return_fruit() -> Apple {
Apple(5)
}
```
Provide the following output:
```rust
error[E0412]: cannot find type `Apple` in this scope
--> file.rs:16:29
|
16 | fn should_return_fruit() -> Apple {
| ^^^^^ not found in this scope
|
help: there is an enum variant `Fruit::Apple`, did you mean to use `Fruit`?
--> file.rs:12:5
|
12 | Apple(i64),
| ^^^^^^^^^^
error[E0425]: cannot find function `Apple` in this scope
--> file.rs:17:5
|
17 | Apple(5)
| ^^^^^ not found in this scope
|
= help: possible candidate is found in another module, you can import it into scope:
`use Fruit::Apple;`
```
9e835b5 to
b946ecd
Compare
|
Travis failure in UI tests, otherwise r=me |
3a92c50 to
73f6f5e
Compare
|
@bors r=petrochenkov |
|
📌 Commit 73f6f5e has been approved by |
|
⌛ Testing commit 73f6f5e with merge 6700cf9... |
|
💔 Test failed - status-travis |
|
@bors retry |
…enkov
Suggest using enum when a variant is used as a type
Given a file:
```rust
enum Fruit {
Apple(i64),
Orange(i64),
}
fn should_return_fruit() -> Apple {
Apple(5)
}
```
Provide the following output:
```rust
error[E0412]: cannot find type `Apple` in this scope
--> file.rs:16:29
|
16 | fn should_return_fruit() -> Apple {
| ^^^^^ not found in this scope
|
help: there is an enum variant `Fruit::Apple`, did you mean to use `Fruit`?
--> file.rs:12:5
|
12 | Apple(i64),
| ^^^^^^^^^^
error[E0425]: cannot find function `Apple` in this scope
--> file.rs:17:5
|
17 | Apple(5)
| ^^^^^ not found in this scope
|
= help: possible candidate is found in another module, you can import it into scope:
`use Fruit::Apple;`
```
Fix rust-lang#35675.
|
Travis failure: @bors r- |
|
@arielb1 the stderr output of that file differs between my local system and the different travis environments. Is there a way to have fuzzy matching on the UI tests? On the |
d936b90 to
2b2eeda
Compare
|
Moved tests to @bors r=petrochenkov |
|
📌 Commit 2b2eeda has been approved by |
Suggest using enum when a variant is used as a type
Given a file:
```rust
enum Fruit {
Apple(i64),
Orange(i64),
}
fn should_return_fruit() -> Apple {
Apple(5)
}
```
Provide the following output:
```rust
error[E0412]: cannot find type `Apple` in this scope
--> file.rs:16:29
|
16 | fn should_return_fruit() -> Apple {
| ^^^^^ not found in this scope
|
help: there is an enum variant `Fruit::Apple`, did you mean to use `Fruit`?
--> file.rs:12:5
|
12 | Apple(i64),
| ^^^^^^^^^^
error[E0425]: cannot find function `Apple` in this scope
--> file.rs:17:5
|
17 | Apple(5)
| ^^^^^ not found in this scope
|
= help: possible candidate is found in another module, you can import it into scope:
`use Fruit::Apple;`
```
Fix #35675.
|
☀️ Test successful - status-appveyor, status-travis |
Given a file:
Provide the following output:
Fix #35675.