Skip to content

Commit

Permalink
Use Unsafety instead of BlockCheckMode
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Dec 22, 2016
1 parent 0047c71 commit 7b03591
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 33 deletions.
39 changes: 8 additions & 31 deletions src/expr.rs
Expand Up @@ -88,7 +88,7 @@ pub enum ExprKind {
/// A closure (for example, `move |a, b, c| {a + b + c}`)
Closure(CaptureBy, Box<FnDecl>, Block),
/// A block (`{ ... }` or `unsafe { ... }`)
Block(BlockCheckMode, Block),
Block(Unsafety, Block),

/// An assignment (`a = foo()`)
Assign(Box<Expr>, Box<Expr>),
Expand Down Expand Up @@ -161,12 +161,6 @@ pub struct Block {
pub stmts: Vec<Stmt>,
}

#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum BlockCheckMode {
Default,
Unsafe,
}

#[derive(Debug, Clone, Eq, PartialEq)]
pub enum Stmt {
/// A local (let) binding.
Expand Down Expand Up @@ -321,7 +315,7 @@ pub mod parsing {
use mac::parsing::{mac, token_trees};
use nom::IResult::{self, Error};
use op::parsing::{assign_op, binop, unop};
use ty::parsing::{mutability, path, qpath, ty};
use ty::parsing::{mutability, path, qpath, ty, unsafety};

// Struct literals are ambiguous in certain positions
// https://github.com/rust-lang/rfcs/pull/92
Expand Down Expand Up @@ -474,7 +468,7 @@ pub mod parsing {
punct!("}") >>
(ExprKind::InPlace(
Box::new(place),
Box::new(ExprKind::Block(BlockCheckMode::Default, Block {
Box::new(ExprKind::Block(Unsafety::Normal, Block {
stmts: value,
}).into()),
))
Expand Down Expand Up @@ -571,7 +565,7 @@ pub mod parsing {
punct!("{") >>
else_block: within_block >>
punct!("}") >>
(ExprKind::Block(BlockCheckMode::Default, Block {
(ExprKind::Block(Unsafety::Normal, Block {
stmts: else_block,
}).into())
)
Expand Down Expand Up @@ -632,7 +626,7 @@ pub mod parsing {
));

fn arm_requires_comma(arm: &Arm) -> bool {
if let ExprKind::Block(BlockCheckMode::Default, _) = arm.body.node {
if let ExprKind::Block(Unsafety::Normal, _) = arm.body.node {
false
} else {
true
Expand All @@ -645,7 +639,7 @@ pub mod parsing {
guard: option!(preceded!(keyword!("if"), expr)) >>
punct!("=>") >>
body: alt!(
map!(block, |blk| ExprKind::Block(BlockCheckMode::Default, blk).into())
map!(block, |blk| ExprKind::Block(Unsafety::Normal, blk).into())
|
expr
) >>
Expand Down Expand Up @@ -777,7 +771,7 @@ pub mod parsing {
));

named!(expr_block -> ExprKind, do_parse!(
rules: block_check_mode >>
rules: unsafety >>
b: block >>
(ExprKind::Block(rules, Block {
stmts: b.stmts,
Expand Down Expand Up @@ -835,12 +829,6 @@ pub mod parsing {
})
));

named!(block_check_mode -> BlockCheckMode, alt!(
keyword!("unsafe") => { |_| BlockCheckMode::Unsafe }
|
epsilon!() => { |_| BlockCheckMode::Default }
));

named!(pub within_block -> Vec<Stmt>, do_parse!(
many0!(punct!(";")) >>
mut standalone: many0!(terminated!(standalone_stmt, many0!(punct!(";")))) >>
Expand Down Expand Up @@ -1467,7 +1455,7 @@ mod printing {
tokens.append("=>");
self.body.to_tokens(tokens);
match self.body.node {
ExprKind::Block(BlockCheckMode::Default, _) => {
ExprKind::Block(Unsafety::Normal, _) => {
// no comma
}
_ => tokens.append(","),
Expand Down Expand Up @@ -1648,17 +1636,6 @@ mod printing {
}
}

impl ToTokens for BlockCheckMode {
fn to_tokens(&self, tokens: &mut Tokens) {
match *self {
BlockCheckMode::Default => {
// nothing
}
BlockCheckMode::Unsafe => tokens.append("unsafe"),
}
}
}

impl ToTokens for Stmt {
fn to_tokens(&self, tokens: &mut Tokens) {
match *self {
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Expand Up @@ -37,8 +37,8 @@ mod escape;
#[cfg(feature = "full")]
mod expr;
#[cfg(feature = "full")]
pub use expr::{Arm, BindingMode, Block, BlockCheckMode, CaptureBy, Expr, ExprKind, FieldPat,
FieldValue, Local, MacStmtStyle, Pat, RangeLimits, Stmt};
pub use expr::{Arm, BindingMode, Block, CaptureBy, Expr, ExprKind, FieldPat, FieldValue,
Local, MacStmtStyle, Pat, RangeLimits, Stmt};

mod generics;
pub use generics::{Generics, Lifetime, LifetimeDef, TraitBoundModifier, TyParam, TyParamBound,
Expand Down

0 comments on commit 7b03591

Please sign in to comment.