From e8d6e3f57d1cf91bf670ace9466d23c8c190ef9f Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Sat, 23 Jul 2022 21:00:58 +0800 Subject: [PATCH] Add unreachable comments. --- codegen/src/rhai_module.rs | 2 +- src/optimizer.rs | 4 ++-- src/packages/iter_basic.rs | 2 +- src/parser.rs | 6 +++--- src/tokenizer.rs | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/codegen/src/rhai_module.rs b/codegen/src/rhai_module.rs index dc26e958..b5c8df4a 100644 --- a/codegen/src/rhai_module.rs +++ b/codegen/src/rhai_module.rs @@ -200,7 +200,7 @@ pub fn generate_body( let ns_str = syn::Ident::new( match namespace { - FnNamespaceAccess::Unset => unreachable!(), + FnNamespaceAccess::Unset => unreachable!("`namespace` should be set"), FnNamespaceAccess::Global => "Global", FnNamespaceAccess::Internal => "Internal", }, diff --git a/src/optimizer.rs b/src/optimizer.rs index ad3058c5..f0f7461c 100644 --- a/src/optimizer.rs +++ b/src/optimizer.rs @@ -895,7 +895,7 @@ fn optimize_stmt(stmt: &mut Stmt, state: &mut OptimizerState, preserve_result: b *stmt = stmt_block.into(); } Expr::Stmt(..) => *stmt = Stmt::Noop(expr.position()), - _ => unreachable!(), + _ => unreachable!("`Expr::Stmt`"), } } @@ -950,7 +950,7 @@ fn optimize_expr(expr: &mut Expr, state: &mut OptimizerState, _chaining: bool) { optimize_expr(&mut e, state, false); *expr = *e; } - _ => unreachable!() + _ => unreachable!("`Expr::Stmt`") } } // { stmt; ... } - do not count promotion as dirty because it gets turned back into an array diff --git a/src/packages/iter_basic.rs b/src/packages/iter_basic.rs index 367bf5ff..4f6d4317 100644 --- a/src/packages/iter_basic.rs +++ b/src/packages/iter_basic.rs @@ -105,7 +105,7 @@ impl Iterator for StepRange { self.dir = 0; } } else { - unreachable!(); + unreachable!("`dir` != 0"); } Some(v) diff --git a/src/parser.rs b/src/parser.rs index 184b8b1a..cb431797 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -798,7 +798,7 @@ impl Engine { match token { Token::LeftBracket => ASTFlags::NONE, Token::QuestionBracket => ASTFlags::NEGATED, - _ => unreachable!(), + _ => unreachable!("`[` or `?[`"), }, false, settings.level_up(), @@ -1693,7 +1693,7 @@ impl Engine { let opt = match token { Token::LeftBracket => ASTFlags::NONE, Token::QuestionBracket => ASTFlags::NEGATED, - _ => unreachable!(), + _ => unreachable!("`[` or `?[`"), }; self.parse_index_chain(input, state, lib, expr, opt, true, settings.level_up())? } @@ -1717,7 +1717,7 @@ impl Engine { let op_flags = match op { Token::Period => ASTFlags::NONE, Token::Elvis => ASTFlags::NEGATED, - _ => unreachable!(), + _ => unreachable!("`.` or `?.`"), }; Self::make_dot_expr(state, expr, rhs, ASTFlags::NONE, op_flags, tail_pos)? } diff --git a/src/tokenizer.rs b/src/tokenizer.rs index eda7720c..121ecdc2 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -248,7 +248,7 @@ impl fmt::Debug for Position { } #[cfg(feature = "no_position")] - unreachable!(); + unreachable!("no position"); } } }