diff options
| author | Daniel Micay <danielmicay@gmail.com> | 2013-05-05 15:48:28 -0400 |
|---|---|---|
| committer | Daniel Micay <danielmicay@gmail.com> | 2013-05-05 15:50:10 -0400 |
| commit | bc52224d479c0af1e36d2b12e5cf00c0c0fb3810 (patch) | |
| tree | 97ed0ca858a29f029c2742cb02ec422cf4dcaf81 /src | |
| parent | 66842c857635f7f35523bea87fc04700d68dfad7 (diff) | |
| download | rust-bc52224d479c0af1e36d2b12e5cf00c0c0fb3810.tar.gz rust-bc52224d479c0af1e36d2b12e5cf00c0c0fb3810.zip | |
factor out the has_attr checks
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/middle/ty.rs | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index a4e5849e3c6..476ec2c1103 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -2022,13 +2022,7 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents { if ty::has_dtor(cx, did) { res += TC_DTOR; } - if has_attr(cx, did, "mutable") { - res += TC_MUTABLE; - } - if has_attr(cx, did, "non_owned") { - res += TC_NON_OWNED; - } - res + apply_tc_attr(cx, did, res) } ty_tup(ref tys) => { @@ -2037,7 +2031,7 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents { ty_enum(did, ref substs) => { let variants = substd_enum_variants(cx, did, substs); - let mut res = if variants.is_empty() { + let res = if variants.is_empty() { // we somewhat arbitrary declare that empty enums // are non-copyable TC_EMPTY_ENUM @@ -2048,13 +2042,7 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents { |tc, arg_ty| *tc + tc_ty(cx, *arg_ty, cache)) }) }; - if has_attr(cx, did, "mutable") { - res += TC_MUTABLE; - } - if has_attr(cx, did, "non_owned") { - res += TC_NON_OWNED; - } - res + apply_tc_attr(cx, did, res) } ty_param(p) => { @@ -2114,6 +2102,16 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents { mc + tc_ty(cx, mt.ty, cache) } + fn apply_tc_attr(cx: ctxt, did: def_id, mut tc: TypeContents) -> TypeContents { + if has_attr(cx, did, "mutable") { + tc += TC_MUTABLE; + } + if has_attr(cx, did, "non_owned") { + tc += TC_NON_OWNED; + } + tc + } + fn borrowed_contents(region: ty::Region, mutbl: ast::mutability) -> TypeContents { |
