Skip to content

bitflags! uses associated constants #24921

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,22 @@
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/nightly/")]

#![feature(associated_consts)]
#![feature(box_patterns)]
#![feature(box_syntax)]
#![feature(collections)]
#![feature(core)]
#![feature(hash)]
#![feature(into_cow)]
#![feature(libc)]
#![feature(path_ext)]
#![feature(quote)]
#![feature(rustc_diagnostic_macros)]
#![feature(rustc_private)]
#![feature(slice_patterns)]
#![feature(staged_api)]
#![feature(std_misc)]
#![feature(path_ext)]
#![feature(str_char)]
#![feature(into_cow)]
#![feature(slice_patterns)]
#![cfg_attr(test, feature(test))]

#![allow(trivial_casts)]
Expand Down
94 changes: 48 additions & 46 deletions src/librustc/middle/check_const.rs

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/librustc/middle/mem_categorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,20 +838,20 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
expr_ty: Ty<'tcx>)
-> cmt<'tcx> {
let qualif = self.tcx().const_qualif_map.borrow().get(&id).cloned()
.unwrap_or(check_const::NOT_CONST);
.unwrap_or(check_const::ConstQualif::NOT_CONST);

// Only promote `[T; 0]` before an RFC for rvalue promotions
// is accepted.
let qualif = match expr_ty.sty {
ty::ty_vec(_, Some(0)) => qualif,
_ => check_const::NOT_CONST
_ => check_const::ConstQualif::NOT_CONST
};

// 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::NON_STATIC_BORROWS {
check_const::PURE_CONST => ty::ReStatic,
let re = match qualif & check_const::ConstQualif::NON_STATIC_BORROWS {
check_const::ConstQualif::PURE_CONST => ty::ReStatic,
_ => self.temporary_scope(id),
};
let ret = self.cat_rvalue(id, span, re, expr_ty);
Expand Down
62 changes: 32 additions & 30 deletions src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -848,16 +848,18 @@ impl<'tcx> ctxt<'tcx> {
// recursing over the type itself.
bitflags! {
flags TypeFlags: u32 {
const NO_TYPE_FLAGS = 0b0,
const HAS_PARAMS = 0b1,
const HAS_SELF = 0b10,
const HAS_TY_INFER = 0b100,
const HAS_RE_INFER = 0b1000,
const HAS_RE_LATE_BOUND = 0b10000,
const HAS_REGIONS = 0b100000,
const HAS_TY_ERR = 0b1000000,
const HAS_PROJECTION = 0b10000000,
const NEEDS_SUBST = HAS_PARAMS.bits | HAS_SELF.bits | HAS_REGIONS.bits,
const NO_TYPE_FLAGS = 0,
const HAS_PARAMS = 1 << 0,
const HAS_SELF = 1 << 1,
const HAS_TY_INFER = 1 << 2,
const HAS_RE_INFER = 1 << 3,
const HAS_RE_LATE_BOUND = 1 << 4,
const HAS_REGIONS = 1 << 5,
const HAS_TY_ERR = 1 << 6,
const HAS_PROJECTION = 1 << 7,
const NEEDS_SUBST = TypeFlags::HAS_PARAMS.bits |
TypeFlags::HAS_SELF.bits |
TypeFlags::HAS_REGIONS.bits,
}
}

Expand Down Expand Up @@ -890,8 +892,8 @@ macro_rules! sty_debug_print {
ty::ty_err => /* unimportant */ continue,
$(ty::$variant(..) => &mut $variant,)*
};
let region = t.flags.intersects(ty::HAS_RE_INFER);
let ty = t.flags.intersects(ty::HAS_TY_INFER);
let region = t.flags.intersects(ty::TypeFlags::HAS_RE_INFER);
let ty = t.flags.intersects(ty::TypeFlags::HAS_TY_INFER);

variant.total += 1;
total.total += 1;
Expand Down Expand Up @@ -993,23 +995,23 @@ impl<'tcx> Borrow<sty<'tcx>> for InternedTy<'tcx> {
}

pub fn type_has_params(ty: Ty) -> bool {
ty.flags.intersects(HAS_PARAMS)
ty.flags.intersects(TypeFlags::HAS_PARAMS)
}
pub fn type_has_self(ty: Ty) -> bool {
ty.flags.intersects(HAS_SELF)
ty.flags.intersects(TypeFlags::HAS_SELF)
}
pub fn type_has_ty_infer(ty: Ty) -> bool {
ty.flags.intersects(HAS_TY_INFER)
ty.flags.intersects(TypeFlags::HAS_TY_INFER)
}
pub fn type_needs_infer(ty: Ty) -> bool {
ty.flags.intersects(HAS_TY_INFER | HAS_RE_INFER)
ty.flags.intersects(TypeFlags::HAS_TY_INFER | TypeFlags::HAS_RE_INFER)
}
pub fn type_has_projection(ty: Ty) -> bool {
ty.flags.intersects(HAS_PROJECTION)
ty.flags.intersects(TypeFlags::HAS_PROJECTION)
}

pub fn type_has_late_bound_regions(ty: Ty) -> bool {
ty.flags.intersects(HAS_RE_LATE_BOUND)
ty.flags.intersects(TypeFlags::HAS_RE_LATE_BOUND)
}

/// An "escaping region" is a bound region whose binder is not part of `t`.
Expand Down Expand Up @@ -2810,7 +2812,7 @@ struct FlagComputation {

impl FlagComputation {
fn new() -> FlagComputation {
FlagComputation { flags: NO_TYPE_FLAGS, depth: 0 }
FlagComputation { flags: TypeFlags::NO_TYPE_FLAGS, depth: 0 }
}

fn for_sty(st: &sty) -> FlagComputation {
Expand Down Expand Up @@ -2855,20 +2857,20 @@ impl FlagComputation {

// You might think that we could just return ty_err for
// any type containing ty_err as a component, and get
// rid of the HAS_TY_ERR flag -- likewise for ty_bot (with
// rid of the TypeFlags::HAS_TY_ERR flag -- likewise for ty_bot (with
// the exception of function types that return bot).
// But doing so caused sporadic memory corruption, and
// neither I (tjc) nor nmatsakis could figure out why,
// so we're doing it this way.
&ty_err => {
self.add_flags(HAS_TY_ERR)
self.add_flags(TypeFlags::HAS_TY_ERR)
}

&ty_param(ref p) => {
if p.space == subst::SelfSpace {
self.add_flags(HAS_SELF);
self.add_flags(TypeFlags::HAS_SELF);
} else {
self.add_flags(HAS_PARAMS);
self.add_flags(TypeFlags::HAS_PARAMS);
}
}

Expand All @@ -2877,15 +2879,15 @@ impl FlagComputation {
}

&ty_infer(_) => {
self.add_flags(HAS_TY_INFER)
self.add_flags(TypeFlags::HAS_TY_INFER)
}

&ty_enum(_, substs) | &ty_struct(_, substs) => {
self.add_substs(substs);
}

&ty_projection(ref data) => {
self.add_flags(HAS_PROJECTION);
self.add_flags(TypeFlags::HAS_PROJECTION);
self.add_projection_ty(data);
}

Expand Down Expand Up @@ -2949,11 +2951,11 @@ impl FlagComputation {
}

fn add_region(&mut self, r: Region) {
self.add_flags(HAS_REGIONS);
self.add_flags(TypeFlags::HAS_REGIONS);
match r {
ty::ReInfer(_) => { self.add_flags(HAS_RE_INFER); }
ty::ReInfer(_) => { self.add_flags(TypeFlags::HAS_RE_INFER); }
ty::ReLateBound(debruijn, _) => {
self.add_flags(HAS_RE_LATE_BOUND);
self.add_flags(TypeFlags::HAS_RE_LATE_BOUND);
self.add_depth(debruijn.depth);
}
_ => { }
Expand Down Expand Up @@ -3307,11 +3309,11 @@ pub fn type_is_nil(ty: Ty) -> bool {
}

pub fn type_is_error(ty: Ty) -> bool {
ty.flags.intersects(HAS_TY_ERR)
ty.flags.intersects(TypeFlags::HAS_TY_ERR)
}

pub fn type_needs_subst(ty: Ty) -> bool {
ty.flags.intersects(NEEDS_SUBST)
ty.flags.intersects(TypeFlags::NEEDS_SUBST)
}

pub fn trait_ref_contains_error(tref: &ty::TraitRef) -> bool {
Expand Down
Loading