2016-08-21 21:18:58 +00:00
|
|
|
//! Checks for continue statements in loops that are redundant.
|
|
|
|
//!
|
|
|
|
//! For example, the lint would catch
|
|
|
|
//!
|
2018-06-25 19:22:53 +00:00
|
|
|
//! ```ignore
|
2016-08-21 21:18:58 +00:00
|
|
|
//! while condition() {
|
|
|
|
//! update_condition();
|
|
|
|
//! if x {
|
|
|
|
//! // ...
|
|
|
|
//! } else {
|
|
|
|
//! continue;
|
|
|
|
//! }
|
|
|
|
//! println!("Hello, world");
|
|
|
|
//! }
|
|
|
|
//! ```
|
|
|
|
//!
|
|
|
|
//! And suggest something like this:
|
|
|
|
//!
|
2018-06-25 19:22:53 +00:00
|
|
|
//! ```ignore
|
2016-08-21 21:18:58 +00:00
|
|
|
//! while condition() {
|
|
|
|
//! update_condition();
|
|
|
|
//! if x {
|
|
|
|
//! // ...
|
|
|
|
//! println!("Hello, world");
|
|
|
|
//! }
|
|
|
|
//! }
|
|
|
|
//! ```
|
|
|
|
//!
|
|
|
|
//! This lint is **warn** by default.
|
|
|
|
use rustc::lint::*;
|
2018-07-19 07:53:23 +00:00
|
|
|
use rustc::{declare_lint, lint_array};
|
2016-08-21 21:18:58 +00:00
|
|
|
use syntax::ast;
|
2017-05-03 12:13:50 +00:00
|
|
|
use syntax::codemap::{original_sp, DUMMY_SP};
|
2017-04-09 12:07:11 +00:00
|
|
|
use std::borrow::Cow;
|
2016-08-21 21:18:58 +00:00
|
|
|
|
2018-05-30 08:15:50 +00:00
|
|
|
use crate::utils::{in_macro, snippet, snippet_block, span_help_and_lint, trim_multiline};
|
2016-08-21 21:18:58 +00:00
|
|
|
|
|
|
|
/// **What it does:** The lint checks for `if`-statements appearing in loops
|
|
|
|
/// that contain a `continue` statement in either their main blocks or their
|
|
|
|
/// `else`-blocks, when omitting the `else`-block possibly with some
|
|
|
|
/// rearrangement of code can make the code easier to understand.
|
|
|
|
///
|
|
|
|
/// **Why is this bad?** Having explicit `else` blocks for `if` statements
|
|
|
|
/// containing `continue` in their THEN branch adds unnecessary branching and
|
|
|
|
/// nesting to the code. Having an else block containing just `continue` can
|
|
|
|
/// also be better written by grouping the statements following the whole `if`
|
|
|
|
/// statement within the THEN block and omitting the else block completely.
|
|
|
|
///
|
|
|
|
/// **Known problems:** None
|
|
|
|
///
|
|
|
|
/// **Example:**
|
|
|
|
/// ```rust
|
|
|
|
/// while condition() {
|
|
|
|
/// update_condition();
|
|
|
|
/// if x {
|
|
|
|
/// // ...
|
|
|
|
/// } else {
|
|
|
|
/// continue;
|
|
|
|
/// }
|
|
|
|
/// println!("Hello, world");
|
|
|
|
/// }
|
|
|
|
/// ```
|
|
|
|
///
|
|
|
|
/// Could be rewritten as
|
|
|
|
///
|
|
|
|
/// ```rust
|
|
|
|
/// while condition() {
|
|
|
|
/// update_condition();
|
|
|
|
/// if x {
|
|
|
|
/// // ...
|
|
|
|
/// println!("Hello, world");
|
|
|
|
/// }
|
|
|
|
/// }
|
|
|
|
/// ```
|
|
|
|
///
|
|
|
|
/// As another example, the following code
|
|
|
|
///
|
|
|
|
/// ```rust
|
|
|
|
/// loop {
|
|
|
|
/// if waiting() {
|
|
|
|
/// continue;
|
|
|
|
/// } else {
|
|
|
|
/// // Do something useful
|
|
|
|
/// }
|
|
|
|
/// }
|
|
|
|
/// ```
|
|
|
|
/// Could be rewritten as
|
|
|
|
///
|
|
|
|
/// ```rust
|
|
|
|
/// loop {
|
|
|
|
/// if waiting() {
|
|
|
|
/// continue;
|
|
|
|
/// }
|
|
|
|
/// // Do something useful
|
|
|
|
/// }
|
|
|
|
/// ```
|
2018-03-28 13:24:26 +00:00
|
|
|
declare_clippy_lint! {
|
2016-08-21 21:18:58 +00:00
|
|
|
pub NEEDLESS_CONTINUE,
|
2018-03-28 13:24:26 +00:00
|
|
|
pedantic,
|
2016-08-21 21:18:58 +00:00
|
|
|
"`continue` statements that can be replaced by a rearrangement of code"
|
|
|
|
}
|
|
|
|
|
2017-08-09 07:30:56 +00:00
|
|
|
#[derive(Copy, Clone)]
|
2016-08-21 21:18:58 +00:00
|
|
|
pub struct NeedlessContinue;
|
|
|
|
|
|
|
|
impl LintPass for NeedlessContinue {
|
|
|
|
fn get_lints(&self) -> LintArray {
|
|
|
|
lint_array!(NEEDLESS_CONTINUE)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl EarlyLintPass for NeedlessContinue {
|
|
|
|
fn check_expr(&mut self, ctx: &EarlyContext, expr: &ast::Expr) {
|
2017-04-09 12:07:11 +00:00
|
|
|
if !in_macro(expr.span) {
|
2016-08-21 21:18:58 +00:00
|
|
|
check_and_warn(ctx, expr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-09 07:30:56 +00:00
|
|
|
/* This lint has to mainly deal with two cases of needless continue
|
|
|
|
* statements. */
|
|
|
|
// Case 1 [Continue inside else block]:
|
|
|
|
//
|
|
|
|
// loop {
|
|
|
|
// // region A
|
|
|
|
// if cond {
|
|
|
|
// // region B
|
|
|
|
// } else {
|
|
|
|
// continue;
|
|
|
|
// }
|
|
|
|
// // region C
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// This code can better be written as follows:
|
|
|
|
//
|
|
|
|
// loop {
|
|
|
|
// // region A
|
|
|
|
// if cond {
|
|
|
|
// // region B
|
|
|
|
// // region C
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// Case 2 [Continue inside then block]:
|
|
|
|
//
|
|
|
|
// loop {
|
|
|
|
// // region A
|
|
|
|
// if cond {
|
|
|
|
// continue;
|
|
|
|
// // potentially more code here.
|
|
|
|
// } else {
|
|
|
|
// // region B
|
|
|
|
// }
|
|
|
|
// // region C
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// This snippet can be refactored to:
|
|
|
|
//
|
|
|
|
// loop {
|
|
|
|
// // region A
|
|
|
|
// if !cond {
|
|
|
|
// // region B
|
|
|
|
// // region C
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
2016-12-31 21:35:39 +00:00
|
|
|
|
|
|
|
/// Given an expression, returns true if either of the following is true
|
2016-08-21 21:18:58 +00:00
|
|
|
///
|
2016-12-31 21:35:39 +00:00
|
|
|
/// - The expression is a `continue` node.
|
2017-08-09 07:30:56 +00:00
|
|
|
/// - The expression node is a block with the first statement being a
|
|
|
|
/// `continue`.
|
2016-08-21 21:18:58 +00:00
|
|
|
///
|
|
|
|
fn needless_continue_in_else(else_expr: &ast::Expr) -> bool {
|
|
|
|
match else_expr.node {
|
2018-05-17 09:21:15 +00:00
|
|
|
ast::ExprKind::Block(ref else_block, _) => is_first_block_stmt_continue(else_block),
|
2016-12-31 21:35:39 +00:00
|
|
|
ast::ExprKind::Continue(_) => true,
|
|
|
|
_ => false,
|
|
|
|
}
|
2016-08-21 21:18:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn is_first_block_stmt_continue(block: &ast::Block) -> bool {
|
2016-12-31 21:35:39 +00:00
|
|
|
block.stmts.get(0).map_or(false, |stmt| match stmt.node {
|
2017-09-05 09:33:04 +00:00
|
|
|
ast::StmtKind::Semi(ref e) | ast::StmtKind::Expr(ref e) => if let ast::ExprKind::Continue(_) = e.node {
|
|
|
|
true
|
|
|
|
} else {
|
|
|
|
false
|
2016-12-31 21:35:39 +00:00
|
|
|
},
|
|
|
|
_ => false,
|
|
|
|
})
|
2016-08-21 21:18:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// If `expr` is a loop expression (while/while let/for/loop), calls `func` with
|
|
|
|
/// the AST object representing the loop block of `expr`.
|
2017-05-03 12:13:50 +00:00
|
|
|
fn with_loop_block<F>(expr: &ast::Expr, mut func: F)
|
2017-08-09 07:30:56 +00:00
|
|
|
where
|
|
|
|
F: FnMut(&ast::Block),
|
2017-05-03 12:13:50 +00:00
|
|
|
{
|
2016-08-21 21:18:58 +00:00
|
|
|
match expr.node {
|
2017-05-03 12:13:50 +00:00
|
|
|
ast::ExprKind::While(_, ref loop_block, _) |
|
2016-08-21 21:18:58 +00:00
|
|
|
ast::ExprKind::WhileLet(_, _, ref loop_block, _) |
|
2017-05-03 12:13:50 +00:00
|
|
|
ast::ExprKind::ForLoop(_, _, ref loop_block, _) |
|
|
|
|
ast::ExprKind::Loop(ref loop_block, _) => func(loop_block),
|
2016-08-21 21:18:58 +00:00
|
|
|
_ => {},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-09 07:30:56 +00:00
|
|
|
/// If `stmt` is an if expression node with an `else` branch, calls func with
|
|
|
|
/// the
|
2016-08-21 21:18:58 +00:00
|
|
|
/// following:
|
|
|
|
///
|
2016-12-31 21:35:39 +00:00
|
|
|
/// - The `if` expression itself,
|
|
|
|
/// - The `if` condition expression,
|
|
|
|
/// - The `then` block, and
|
|
|
|
/// - The `else` expression.
|
2016-08-21 21:18:58 +00:00
|
|
|
///
|
|
|
|
fn with_if_expr<F>(stmt: &ast::Stmt, mut func: F)
|
2017-08-09 07:30:56 +00:00
|
|
|
where
|
|
|
|
F: FnMut(&ast::Expr, &ast::Expr, &ast::Block, &ast::Expr),
|
2017-05-03 12:13:50 +00:00
|
|
|
{
|
2016-08-21 21:18:58 +00:00
|
|
|
match stmt.node {
|
2017-09-05 09:33:04 +00:00
|
|
|
ast::StmtKind::Semi(ref e) | ast::StmtKind::Expr(ref e) => {
|
2016-08-21 21:18:58 +00:00
|
|
|
if let ast::ExprKind::If(ref cond, ref if_block, Some(ref else_expr)) = e.node {
|
|
|
|
func(e, cond, if_block, else_expr);
|
|
|
|
}
|
|
|
|
},
|
2017-05-03 12:13:50 +00:00
|
|
|
_ => {},
|
2016-08-21 21:18:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// A type to distinguish between the two distinct cases this lint handles.
|
2017-04-12 08:55:34 +00:00
|
|
|
#[derive(Copy, Clone, Debug)]
|
2016-08-21 21:18:58 +00:00
|
|
|
enum LintType {
|
|
|
|
ContinueInsideElseBlock,
|
|
|
|
ContinueInsideThenBlock,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Data we pass around for construction of help messages.
|
|
|
|
struct LintData<'a> {
|
2016-12-31 21:35:39 +00:00
|
|
|
/// The `if` expression encountered in the above loop.
|
|
|
|
if_expr: &'a ast::Expr,
|
|
|
|
/// The condition expression for the above `if`.
|
|
|
|
if_cond: &'a ast::Expr,
|
|
|
|
/// The `then` block of the `if` statement.
|
|
|
|
if_block: &'a ast::Block,
|
|
|
|
/// The `else` block of the `if` statement.
|
|
|
|
/// Note that we only work with `if` exprs that have an `else` branch.
|
|
|
|
else_expr: &'a ast::Expr,
|
|
|
|
/// The 0-based index of the `if` statement in the containing loop block.
|
|
|
|
stmt_idx: usize,
|
|
|
|
/// The statements of the loop block.
|
|
|
|
block_stmts: &'a [ast::Stmt],
|
2016-08-21 21:18:58 +00:00
|
|
|
}
|
|
|
|
|
2017-10-20 12:41:24 +00:00
|
|
|
const MSG_REDUNDANT_ELSE_BLOCK: &str = "This else block is redundant.\n";
|
2016-08-21 21:18:58 +00:00
|
|
|
|
2017-10-20 12:41:24 +00:00
|
|
|
const MSG_ELSE_BLOCK_NOT_NEEDED: &str = "There is no need for an explicit `else` block for this `if` \
|
2017-11-04 19:55:56 +00:00
|
|
|
expression\n";
|
2016-08-21 21:18:58 +00:00
|
|
|
|
2017-10-20 12:41:24 +00:00
|
|
|
const DROP_ELSE_BLOCK_AND_MERGE_MSG: &str = "Consider dropping the else clause and merging the code that \
|
2017-11-04 19:55:56 +00:00
|
|
|
follows (in the loop) with the if block, like so:\n";
|
2016-08-21 21:18:58 +00:00
|
|
|
|
2017-10-20 12:41:24 +00:00
|
|
|
const DROP_ELSE_BLOCK_MSG: &str = "Consider dropping the else clause, and moving out the code in the else \
|
2017-11-04 19:55:56 +00:00
|
|
|
block, like so:\n";
|
2016-08-21 21:18:58 +00:00
|
|
|
|
|
|
|
|
2017-05-03 12:13:50 +00:00
|
|
|
fn emit_warning<'a>(ctx: &EarlyContext, data: &'a LintData, header: &str, typ: LintType) {
|
2016-08-21 21:18:58 +00:00
|
|
|
// snip is the whole *help* message that appears after the warning.
|
|
|
|
// message is the warning message.
|
|
|
|
// expr is the expression which the lint warning message refers to.
|
|
|
|
let (snip, message, expr) = match typ {
|
2017-09-05 09:33:04 +00:00
|
|
|
LintType::ContinueInsideElseBlock => (
|
|
|
|
suggestion_snippet_for_continue_inside_else(ctx, data, header),
|
|
|
|
MSG_REDUNDANT_ELSE_BLOCK,
|
|
|
|
data.else_expr,
|
|
|
|
),
|
|
|
|
LintType::ContinueInsideThenBlock => (
|
|
|
|
suggestion_snippet_for_continue_inside_if(ctx, data, header),
|
|
|
|
MSG_ELSE_BLOCK_NOT_NEEDED,
|
|
|
|
data.if_expr,
|
|
|
|
),
|
2016-08-21 21:18:58 +00:00
|
|
|
};
|
2016-08-21 21:39:24 +00:00
|
|
|
span_help_and_lint(ctx, NEEDLESS_CONTINUE, expr.span, message, &snip);
|
2016-08-21 21:18:58 +00:00
|
|
|
}
|
|
|
|
|
2017-05-03 12:13:50 +00:00
|
|
|
fn suggestion_snippet_for_continue_inside_if<'a>(ctx: &EarlyContext, data: &'a LintData, header: &str) -> String {
|
2016-12-31 21:35:39 +00:00
|
|
|
let cond_code = snippet(ctx, data.if_cond.span, "..");
|
2016-08-21 21:18:58 +00:00
|
|
|
|
2017-05-03 12:13:50 +00:00
|
|
|
let if_code = format!("if {} {{\n continue;\n}}\n", cond_code);
|
|
|
|
/* ^^^^--- Four spaces of indentation. */
|
2016-08-21 21:18:58 +00:00
|
|
|
// region B
|
2016-08-21 21:39:24 +00:00
|
|
|
let else_code = snippet(ctx, data.else_expr.span, "..").into_owned();
|
2016-08-21 21:18:58 +00:00
|
|
|
let else_code = erode_block(&else_code);
|
2017-04-09 12:07:11 +00:00
|
|
|
let else_code = trim_multiline(Cow::from(else_code), false);
|
2016-08-21 21:18:58 +00:00
|
|
|
|
|
|
|
let mut ret = String::from(header);
|
|
|
|
ret.push_str(&if_code);
|
|
|
|
ret.push_str(&else_code);
|
|
|
|
ret.push_str("\n...");
|
|
|
|
ret
|
|
|
|
}
|
|
|
|
|
2017-05-03 12:13:50 +00:00
|
|
|
fn suggestion_snippet_for_continue_inside_else<'a>(ctx: &EarlyContext, data: &'a LintData, header: &str) -> String {
|
2016-12-31 21:35:39 +00:00
|
|
|
let cond_code = snippet(ctx, data.if_cond.span, "..");
|
2017-05-03 12:13:50 +00:00
|
|
|
let mut if_code = format!("if {} {{\n", cond_code);
|
2016-08-21 21:18:58 +00:00
|
|
|
|
|
|
|
// Region B
|
|
|
|
let block_code = &snippet(ctx, data.if_block.span, "..").into_owned();
|
|
|
|
let block_code = erode_block(block_code);
|
2017-04-09 12:07:11 +00:00
|
|
|
let block_code = trim_multiline(Cow::from(block_code), false);
|
2016-08-21 21:18:58 +00:00
|
|
|
|
|
|
|
if_code.push_str(&block_code);
|
|
|
|
|
|
|
|
// Region C
|
|
|
|
// These is the code in the loop block that follows the if/else construction
|
|
|
|
// we are complaining about. We want to pull all of this code into the
|
|
|
|
// `then` block of the `if` statement.
|
2017-05-03 12:13:50 +00:00
|
|
|
let to_annex = data.block_stmts[data.stmt_idx + 1..]
|
|
|
|
.iter()
|
|
|
|
.map(|stmt| original_sp(stmt.span, DUMMY_SP))
|
|
|
|
.map(|span| snippet_block(ctx, span, "..").into_owned())
|
|
|
|
.collect::<Vec<_>>()
|
|
|
|
.join("\n");
|
2016-08-21 21:18:58 +00:00
|
|
|
|
|
|
|
let mut ret = String::from(header);
|
2017-04-13 19:48:52 +00:00
|
|
|
|
|
|
|
ret.push_str(&if_code);
|
|
|
|
ret.push_str("\n// Merged code follows...");
|
|
|
|
ret.push_str(&to_annex);
|
2016-08-21 21:18:58 +00:00
|
|
|
ret.push_str("\n}\n");
|
|
|
|
ret
|
|
|
|
}
|
|
|
|
|
|
|
|
fn check_and_warn<'a>(ctx: &EarlyContext, expr: &'a ast::Expr) {
|
2017-11-04 19:55:56 +00:00
|
|
|
with_loop_block(expr, |loop_block| {
|
|
|
|
for (i, stmt) in loop_block.stmts.iter().enumerate() {
|
|
|
|
with_if_expr(stmt, |if_expr, cond, then_block, else_expr| {
|
|
|
|
let data = &LintData {
|
|
|
|
stmt_idx: i,
|
2018-03-15 15:07:15 +00:00
|
|
|
if_expr,
|
2017-11-04 19:55:56 +00:00
|
|
|
if_cond: cond,
|
|
|
|
if_block: then_block,
|
2018-03-15 15:07:15 +00:00
|
|
|
else_expr,
|
2017-11-04 19:55:56 +00:00
|
|
|
block_stmts: &loop_block.stmts,
|
|
|
|
};
|
|
|
|
if needless_continue_in_else(else_expr) {
|
|
|
|
emit_warning(ctx, data, DROP_ELSE_BLOCK_AND_MERGE_MSG, LintType::ContinueInsideElseBlock);
|
|
|
|
} else if is_first_block_stmt_continue(then_block) {
|
|
|
|
emit_warning(ctx, data, DROP_ELSE_BLOCK_MSG, LintType::ContinueInsideThenBlock);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-08-21 21:18:58 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Eats at `s` from the end till a closing brace `}` is encountered, and then
|
|
|
|
/// continues eating till a non-whitespace character is found.
|
|
|
|
/// e.g., the string
|
|
|
|
///
|
2017-04-12 08:55:34 +00:00
|
|
|
/// ```
|
2017-04-09 12:07:11 +00:00
|
|
|
/// {
|
|
|
|
/// let x = 5;
|
|
|
|
/// }
|
2017-04-12 08:55:34 +00:00
|
|
|
/// ```
|
2016-08-21 21:18:58 +00:00
|
|
|
///
|
|
|
|
/// is transformed to
|
|
|
|
///
|
2018-06-25 19:22:53 +00:00
|
|
|
/// ```ignore
|
2017-04-09 12:07:11 +00:00
|
|
|
/// {
|
2017-05-01 14:57:27 +00:00
|
|
|
/// let x = 5;
|
2017-04-12 08:55:34 +00:00
|
|
|
/// ```
|
2016-08-21 21:18:58 +00:00
|
|
|
///
|
2017-04-09 12:07:11 +00:00
|
|
|
/// NOTE: when there is no closing brace in `s`, `s` is _not_ preserved, i.e.,
|
|
|
|
/// an empty string will be returned in that case.
|
|
|
|
pub fn erode_from_back(s: &str) -> String {
|
2016-08-21 21:18:58 +00:00
|
|
|
let mut ret = String::from(s);
|
2017-05-03 12:13:50 +00:00
|
|
|
while ret.pop().map_or(false, |c| c != '}') {}
|
2016-08-21 21:18:58 +00:00
|
|
|
while let Some(c) = ret.pop() {
|
|
|
|
if !c.is_whitespace() {
|
|
|
|
ret.push(c);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ret
|
|
|
|
}
|
|
|
|
|
2017-04-09 12:07:11 +00:00
|
|
|
/// Eats at `s` from the front by first skipping all leading whitespace. Then,
|
|
|
|
/// any number of opening braces are eaten, followed by any number of newlines.
|
|
|
|
/// e.g., the string
|
|
|
|
///
|
2018-06-25 19:22:53 +00:00
|
|
|
/// ```ignore
|
2017-04-09 12:07:11 +00:00
|
|
|
/// {
|
|
|
|
/// something();
|
|
|
|
/// inside_a_block();
|
|
|
|
/// }
|
2017-04-12 08:55:34 +00:00
|
|
|
/// ```
|
2017-04-09 12:07:11 +00:00
|
|
|
///
|
|
|
|
/// is transformed to
|
|
|
|
///
|
2018-06-25 19:22:53 +00:00
|
|
|
/// ```ignore
|
2017-04-12 08:55:34 +00:00
|
|
|
/// something();
|
2017-04-09 12:07:11 +00:00
|
|
|
/// inside_a_block();
|
|
|
|
/// }
|
2017-04-12 08:55:34 +00:00
|
|
|
/// ```
|
2017-04-09 12:07:11 +00:00
|
|
|
///
|
|
|
|
pub fn erode_from_front(s: &str) -> String {
|
2016-08-21 21:18:58 +00:00
|
|
|
s.chars()
|
2017-05-03 12:13:50 +00:00
|
|
|
.skip_while(|c| c.is_whitespace())
|
|
|
|
.skip_while(|c| *c == '{')
|
|
|
|
.skip_while(|c| *c == '\n')
|
|
|
|
.collect::<String>()
|
2016-08-21 21:18:58 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 12:07:11 +00:00
|
|
|
/// If `s` contains the code for a block, delimited by braces, this function
|
2017-08-09 07:30:56 +00:00
|
|
|
/// tries to get the contents of the block. If there is no closing brace
|
|
|
|
/// present,
|
2017-04-09 12:07:11 +00:00
|
|
|
/// an empty string is returned.
|
|
|
|
pub fn erode_block(s: &str) -> String {
|
2016-08-21 21:18:58 +00:00
|
|
|
erode_from_back(&erode_from_front(s))
|
|
|
|
}
|