-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an ASTC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
pub fn nth(n:u32)->Option<u32>{
let mut x:u32 = 2;
let mut m:u32 = 1;
let mut p:Vec<u32> = vec![2];
'outer: loop {
x += 1;
'inner: for i in p.iter() {
if x % i ==0{
continue 'outer;
}
}
p.push(x);
m+=1;
if n < 1 {
return None;
} else if n == 1 {
return Some(2);
} else m == n { // should be else if here
return Some(x);
}
}
}
fn main(){
println!("{:?}", nth(1));
}
The error here is if is missing in else if
but compiler reports: error:
error: expected identifier, found keyword `return`
--> src/main.rs:19:13
|
19 | return Some(x);
| ^^^^^^
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an ASTC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.