提交 5cfa713a 编写于 作者: T Tamir Duberstein

Use `empty()` instead of a special const

上级 252b5444
......@@ -45,8 +45,6 @@
bitflags! {
#[derive(RustcEncodable, RustcDecodable)]
flags ConstQualif: u8 {
// Const rvalue which can be placed behind a reference.
const PURE_CONST = 0,
// Inner mutability (can not be placed behind a reference) or behind
// &mut in a non-global expression. Can be copied from static memory.
const MUTABLE_MEM = 1 << 0,
......@@ -104,7 +102,7 @@ fn with_mode<F, R>(&mut self, mode: Mode, f: F) -> R where
{
let (old_mode, old_qualif) = (self.mode, self.qualif);
self.mode = mode;
self.qualif = ConstQualif::PURE_CONST;
self.qualif = ConstQualif::empty();
let r = f(self);
self.mode = old_mode;
self.qualif = old_qualif;
......@@ -128,7 +126,7 @@ fn global_expr(&mut self, mode: Mode, expr: &ast::Expr) -> ConstQualif {
Entry::Occupied(entry) => return *entry.get(),
Entry::Vacant(entry) => {
// Prevent infinite recursion on re-entry.
entry.insert(ConstQualif::PURE_CONST);
entry.insert(ConstQualif::empty());
}
}
self.with_mode(mode, |this| {
......@@ -273,7 +271,7 @@ fn visit_pat(&mut self, p: &ast::Pat) {
fn visit_expr(&mut self, ex: &ast::Expr) {
let mut outer = self.qualif;
self.qualif = ConstQualif::PURE_CONST;
self.qualif = ConstQualif::empty();
let node_ty = ty::node_id_to_type(self.tcx, ex.id);
check_expr(self, ex, node_ty);
......
......@@ -850,9 +850,10 @@ pub fn cat_rvalue_node(&self,
// Compute maximum lifetime of this rvalue. This is 'static if
// we can promote to a constant, otherwise equal to enclosing temp
// lifetime.
let re = match qualif & check_const::ConstQualif::NON_STATIC_BORROWS {
check_const::ConstQualif::PURE_CONST => ty::ReStatic,
_ => self.temporary_scope(id),
let re = if qualif.intersects(check_const::ConstQualif::NON_STATIC_BORROWS) {
self.temporary_scope(id)
} else {
ty::ReStatic
};
let ret = self.cat_rvalue(id, span, re, expr_ty);
debug!("cat_rvalue_node ret {}", ret.repr(self.tcx()));
......
......@@ -849,7 +849,6 @@ pub fn free_region_map(&self, id: NodeId) -> FreeRegionMap {
// recursing over the type itself.
bitflags! {
flags TypeFlags: u32 {
const NO_TYPE_FLAGS = 0,
const HAS_PARAMS = 1 << 0,
const HAS_SELF = 1 << 1,
const HAS_TY_INFER = 1 << 2,
......@@ -2925,7 +2924,7 @@ struct FlagComputation {
impl FlagComputation {
fn new() -> FlagComputation {
FlagComputation { flags: TypeFlags::NO_TYPE_FLAGS, depth: 0 }
FlagComputation { flags: TypeFlags::empty(), depth: 0 }
}
fn for_sty(st: &sty) -> FlagComputation {
......
......@@ -186,7 +186,7 @@ fn get_const_val(ccx: &CrateContext,
ref_expr: &ast::Expr) -> ValueRef {
let expr = get_const_expr(ccx, def_id, ref_expr);
let empty_substs = ccx.tcx().mk_substs(Substs::trans_empty());
get_const_expr_as_global(ccx, expr, check_const::ConstQualif::PURE_CONST, empty_substs)
get_const_expr_as_global(ccx, expr, check_const::ConstQualif::empty(), empty_substs)
}
pub fn get_const_expr_as_global<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
......
......@@ -88,7 +88,6 @@
bitflags! {
flags Restrictions: u8 {
const UNRESTRICTED = 0,
const RESTRICTION_STMT_EXPR = 1 << 0,
const RESTRICTION_NO_STRUCT_LITERAL = 1 << 1,
}
......@@ -339,7 +338,7 @@ pub fn new(sess: &'a ParseSess,
buffer_start: 0,
buffer_end: 0,
tokens_consumed: 0,
restrictions: Restrictions::UNRESTRICTED,
restrictions: Restrictions::empty(),
quote_depth: 0,
obsolete_set: HashSet::new(),
mod_path_stack: Vec::new(),
......@@ -2991,7 +2990,7 @@ pub fn parse_arm_nopanic(&mut self) -> PResult<Arm> {
/// Parse an expression
pub fn parse_expr_nopanic(&mut self) -> PResult<P<Expr>> {
return self.parse_expr_res(Restrictions::UNRESTRICTED);
self.parse_expr_res(Restrictions::empty())
}
/// Parse an expression, subject to the given restrictions
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册