-
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.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
estebank commentedon Mar 26, 2018
The output in the current beta already points out at the place where the
else if
should be, even if it doesn't suggest it:estebank commentedon May 20, 2022
The current output is:
I still wish the parser to detect that the code immediately following
else
is a binary operation followed by a block, so that we can instead emitestebank commentedon May 20, 2022
CC @compiler-errors, in case you might be interested in looking at the parser :)
compiler-errors commentedon May 20, 2022
this seems like a neat fix, i'll take a stab at it
else
as a condition if followed by{
#97298Rollup merge of rust-lang#97298 - compiler-errors:if-else-stmt-braces…
Rollup merge of rust-lang#97298 - compiler-errors:if-else-stmt-braces…
2 remaining items