forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#40775 - estebank:variant-as-type, r=petroch…
…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.
- Loading branch information
Showing
3 changed files
with
150 additions
and
0 deletions.
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,44 @@ | ||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
enum Fruit { | ||
Apple(i64), | ||
Orange(i64), | ||
} | ||
|
||
fn should_return_fruit() -> Apple { | ||
Apple(5) | ||
} | ||
|
||
fn should_return_fruit_too() -> Fruit::Apple { | ||
Apple(5) | ||
} | ||
|
||
fn foo() -> Ok { | ||
Ok(()) | ||
} | ||
|
||
fn bar() -> Variant3 { | ||
} | ||
|
||
fn qux() -> Some { | ||
Some(1) | ||
} | ||
|
||
fn main() {} | ||
|
||
mod x { | ||
enum Enum { | ||
Variant1, | ||
Variant2(), | ||
Variant3(usize), | ||
Variant4 {}, | ||
} | ||
} |
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,74 @@ | ||
error[E0412]: cannot find type `Apple` in this scope | ||
--> $DIR/issue-35675.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`? | ||
--> $DIR/issue-35675.rs:12:5 | ||
| | ||
12 | Apple(i64), | ||
| ^^^^^^^^^^ | ||
|
||
error[E0425]: cannot find function `Apple` in this scope | ||
--> $DIR/issue-35675.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;` | ||
|
||
error[E0573]: expected type, found variant `Fruit::Apple` | ||
--> $DIR/issue-35675.rs:20:33 | ||
| | ||
20 | fn should_return_fruit_too() -> Fruit::Apple { | ||
| ^^^^^^^^^^^^ not a type | ||
| | ||
help: there is an enum variant `Fruit::Apple`, did you mean to use `Fruit`? | ||
--> $DIR/issue-35675.rs:12:5 | ||
| | ||
12 | Apple(i64), | ||
| ^^^^^^^^^^ | ||
|
||
error[E0425]: cannot find function `Apple` in this scope | ||
--> $DIR/issue-35675.rs:21:5 | ||
| | ||
21 | Apple(5) | ||
| ^^^^^ not found in this scope | ||
| | ||
= help: possible candidate is found in another module, you can import it into scope: | ||
`use Fruit::Apple;` | ||
|
||
error[E0573]: expected type, found variant `Ok` | ||
--> $DIR/issue-35675.rs:24:13 | ||
| | ||
24 | fn foo() -> Ok { | ||
| ^^ not a type | ||
| | ||
= help: there is an enum variant `std::prelude::v1::Ok`, did you mean to use `std::prelude::v1`? | ||
= help: there is an enum variant `std::prelude::v1::Result::Ok`, did you mean to use `std::prelude::v1::Result`? | ||
|
||
error[E0412]: cannot find type `Variant3` in this scope | ||
--> $DIR/issue-35675.rs:28:13 | ||
| | ||
28 | fn bar() -> Variant3 { | ||
| ^^^^^^^^ not found in this scope | ||
| | ||
help: there is an enum variant `x::Enum::Variant3`, did you mean to use `x::Enum`? | ||
--> $DIR/issue-35675.rs:41:9 | ||
| | ||
41 | Variant3(usize), | ||
| ^^^^^^^^^^^^^^^ | ||
|
||
error[E0573]: expected type, found variant `Some` | ||
--> $DIR/issue-35675.rs:31:13 | ||
| | ||
31 | fn qux() -> Some { | ||
| ^^^^ not a type | ||
| | ||
= help: there is an enum variant `std::prelude::v1::Option::Some`, did you mean to use `std::prelude::v1::Option`? | ||
= help: there is an enum variant `std::prelude::v1::Some`, did you mean to use `std::prelude::v1`? | ||
|
||
error: aborting due to 7 previous errors | ||
|