mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-22 10:05:06 +03:00
Merge pull request #360 from Manishearth/fix-ice
Fix a panic caused by while let
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "clippy"
|
||||
version = "0.0.17"
|
||||
version = "0.0.18"
|
||||
authors = [
|
||||
"Manish Goregaokar <manishsmail@gmail.com>",
|
||||
"Andre Bogus <bogusandre@gmail.com>",
|
||||
|
||||
+4
-2
@@ -312,7 +312,7 @@ fn is_iterable_array(ty: ty::Ty) -> bool {
|
||||
fn extract_expr_from_first_stmt(block: &Block) -> Option<&Expr> {
|
||||
match block.expr {
|
||||
Some(_) => None,
|
||||
None => match block.stmts[0].node {
|
||||
None if !block.stmts.is_empty() => match block.stmts[0].node {
|
||||
StmtDecl(ref decl, _) => match decl.node {
|
||||
DeclLocal(ref local) => match local.init {
|
||||
Some(ref expr) => Some(expr),
|
||||
@@ -322,6 +322,7 @@ fn extract_expr_from_first_stmt(block: &Block) -> Option<&Expr> {
|
||||
},
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -329,10 +330,11 @@ fn extract_expr_from_first_stmt(block: &Block) -> Option<&Expr> {
|
||||
fn extract_first_expr(block: &Block) -> Option<&Expr> {
|
||||
match block.expr {
|
||||
Some(ref expr) => Some(expr),
|
||||
None => match block.stmts[0].node {
|
||||
None if !block.stmts.is_empty() => match block.stmts[0].node {
|
||||
StmtExpr(ref expr, _) | StmtSemi(ref expr, _) => Some(expr),
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#![feature(plugin)]
|
||||
#![plugin(clippy)]
|
||||
|
||||
#[deny(while_let_loop)]
|
||||
#![deny(while_let_loop)]
|
||||
#![allow(dead_code, unused)]
|
||||
|
||||
fn main() {
|
||||
let y = Some(true);
|
||||
loop { //~ERROR
|
||||
@@ -44,3 +46,18 @@ fn main() {
|
||||
println!("{}", x);
|
||||
}
|
||||
}
|
||||
|
||||
// regression test (#360)
|
||||
// this should not panic
|
||||
// it's okay if further iterations of the lint
|
||||
// cause this function to trigger it
|
||||
fn no_panic<T>(slice: &[T]) {
|
||||
let mut iter = slice.iter();
|
||||
loop {
|
||||
let _ = match iter.next() {
|
||||
Some(ele) => ele,
|
||||
None => break
|
||||
};
|
||||
loop {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user