1
Fork 0

Use empty() instead of a special const

This commit is contained in:
Tamir Duberstein 2015-04-29 14:58:43 -07:00
parent 252b5444da
commit 5cfa713a1c
5 changed files with 11 additions and 14 deletions

View file

@ -45,8 +45,6 @@ use std::collections::hash_map::Entry;
bitflags! { bitflags! {
#[derive(RustcEncodable, RustcDecodable)] #[derive(RustcEncodable, RustcDecodable)]
flags ConstQualif: u8 { 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 // Inner mutability (can not be placed behind a reference) or behind
// &mut in a non-global expression. Can be copied from static memory. // &mut in a non-global expression. Can be copied from static memory.
const MUTABLE_MEM = 1 << 0, const MUTABLE_MEM = 1 << 0,
@ -104,7 +102,7 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> {
{ {
let (old_mode, old_qualif) = (self.mode, self.qualif); let (old_mode, old_qualif) = (self.mode, self.qualif);
self.mode = mode; self.mode = mode;
self.qualif = ConstQualif::PURE_CONST; self.qualif = ConstQualif::empty();
let r = f(self); let r = f(self);
self.mode = old_mode; self.mode = old_mode;
self.qualif = old_qualif; self.qualif = old_qualif;
@ -128,7 +126,7 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> {
Entry::Occupied(entry) => return *entry.get(), Entry::Occupied(entry) => return *entry.get(),
Entry::Vacant(entry) => { Entry::Vacant(entry) => {
// Prevent infinite recursion on re-entry. // Prevent infinite recursion on re-entry.
entry.insert(ConstQualif::PURE_CONST); entry.insert(ConstQualif::empty());
} }
} }
self.with_mode(mode, |this| { self.with_mode(mode, |this| {
@ -273,7 +271,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
fn visit_expr(&mut self, ex: &ast::Expr) { fn visit_expr(&mut self, ex: &ast::Expr) {
let mut outer = self.qualif; 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); let node_ty = ty::node_id_to_type(self.tcx, ex.id);
check_expr(self, ex, node_ty); check_expr(self, ex, node_ty);

View file

@ -850,9 +850,10 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
// Compute maximum lifetime of this rvalue. This is 'static if // Compute maximum lifetime of this rvalue. This is 'static if
// we can promote to a constant, otherwise equal to enclosing temp // we can promote to a constant, otherwise equal to enclosing temp
// lifetime. // lifetime.
let re = match qualif & check_const::ConstQualif::NON_STATIC_BORROWS { let re = if qualif.intersects(check_const::ConstQualif::NON_STATIC_BORROWS) {
check_const::ConstQualif::PURE_CONST => ty::ReStatic, self.temporary_scope(id)
_ => self.temporary_scope(id), } else {
ty::ReStatic
}; };
let ret = self.cat_rvalue(id, span, re, expr_ty); let ret = self.cat_rvalue(id, span, re, expr_ty);
debug!("cat_rvalue_node ret {}", ret.repr(self.tcx())); debug!("cat_rvalue_node ret {}", ret.repr(self.tcx()));

View file

@ -849,7 +849,6 @@ impl<'tcx> ctxt<'tcx> {
// recursing over the type itself. // recursing over the type itself.
bitflags! { bitflags! {
flags TypeFlags: u32 { flags TypeFlags: u32 {
const NO_TYPE_FLAGS = 0,
const HAS_PARAMS = 1 << 0, const HAS_PARAMS = 1 << 0,
const HAS_SELF = 1 << 1, const HAS_SELF = 1 << 1,
const HAS_TY_INFER = 1 << 2, const HAS_TY_INFER = 1 << 2,
@ -2925,7 +2924,7 @@ struct FlagComputation {
impl FlagComputation { impl FlagComputation {
fn new() -> FlagComputation { fn new() -> FlagComputation {
FlagComputation { flags: TypeFlags::NO_TYPE_FLAGS, depth: 0 } FlagComputation { flags: TypeFlags::empty(), depth: 0 }
} }
fn for_sty(st: &sty) -> FlagComputation { fn for_sty(st: &sty) -> FlagComputation {

View file

@ -186,7 +186,7 @@ fn get_const_val(ccx: &CrateContext,
ref_expr: &ast::Expr) -> ValueRef { ref_expr: &ast::Expr) -> ValueRef {
let expr = get_const_expr(ccx, def_id, ref_expr); let expr = get_const_expr(ccx, def_id, ref_expr);
let empty_substs = ccx.tcx().mk_substs(Substs::trans_empty()); 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>, pub fn get_const_expr_as_global<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,

View file

@ -88,7 +88,6 @@ use std::slice;
bitflags! { bitflags! {
flags Restrictions: u8 { flags Restrictions: u8 {
const UNRESTRICTED = 0,
const RESTRICTION_STMT_EXPR = 1 << 0, const RESTRICTION_STMT_EXPR = 1 << 0,
const RESTRICTION_NO_STRUCT_LITERAL = 1 << 1, const RESTRICTION_NO_STRUCT_LITERAL = 1 << 1,
} }
@ -339,7 +338,7 @@ impl<'a> Parser<'a> {
buffer_start: 0, buffer_start: 0,
buffer_end: 0, buffer_end: 0,
tokens_consumed: 0, tokens_consumed: 0,
restrictions: Restrictions::UNRESTRICTED, restrictions: Restrictions::empty(),
quote_depth: 0, quote_depth: 0,
obsolete_set: HashSet::new(), obsolete_set: HashSet::new(),
mod_path_stack: Vec::new(), mod_path_stack: Vec::new(),
@ -2991,7 +2990,7 @@ impl<'a> Parser<'a> {
/// Parse an expression /// Parse an expression
pub fn parse_expr_nopanic(&mut self) -> PResult<P<Expr>> { 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 /// Parse an expression, subject to the given restrictions