Compile error in enums code
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 55/100
- Issue type
- Documentation
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- rust
- Domain
- documentation
Research direction
Open data-types.md and inspect the enum construction and matching snippets described in the issue. Update the examples so the enum variants are correctly namespaced or imported, then compile the snippets with rustc to confirm they no longer produce the reported errors.
Written by the indexing model from the issue text.
Description
In https://github.com/nrc/r4cppp/blob/master/data-types.md you write:
enum Expr {
Add(i32, i32),
Or(bool, bool),
Lit(i32)
}
fn foo() {
let x = Or(true, false); // x has type Expr
}
This code throws the following errors:
error[E0425]: cannot find function, tuple struct or tuple variant 'Or' in this scope
--> enums.rs:10:13
|
10 | let x = Or(true, false); // x has type Expr
| ^^
|
help: a tuple variant with a similar name exists
|
10 | let x = Ok(true, false); // x has type Expr
| ^^
help: possible candidate is found in another module, you can import it into scope
|
1 | use Expr::Or;
|
error: aborting due to previous error
For more information about this error, try 'rustc --explain E0425'..
rustc 1.42.0 (b8cedc004 2020-03-09)
Fix: Add namespace
let x = Expr::Or(true, false)
Same on the snippet below:
fn bar(e: Expr) {
match e {
Add(x, y) => println!("An `Add` variant: {} + {}", x, y),
Or(..) => println!("An `Or` variant"),
_ => println!("Something else (in this case, a `Lit`)"),
}
}
Same fix. Alternative:
use Expr::Add;
use Expr::Or;
- Dominant language
- Rust
- Stars
- 3.9k
- Forks
- 297
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from nrc/r4cppp
-
Difficulty 1/5 Under an hour Newbie friendliness 65/100
-
Difficulty 1/5 Under an hour Newbie friendliness 65/100
-
Difficulty 1/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 38/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 42/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
state:needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
zed-industries/zed#64680 · 2 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
RustPython/RustPython#8802 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
TheLarkInn/aipm#2390 ·