Skip to content

Commit bc52224

Browse files
committed
factor out the has_attr checks
1 parent 66842c8 commit bc52224

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

src/librustc/middle/ty.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,13 +2022,7 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
20222022
if ty::has_dtor(cx, did) {
20232023
res += TC_DTOR;
20242024
}
2025-
if has_attr(cx, did, "mutable") {
2026-
res += TC_MUTABLE;
2027-
}
2028-
if has_attr(cx, did, "non_owned") {
2029-
res += TC_NON_OWNED;
2030-
}
2031-
res
2025+
apply_tc_attr(cx, did, res)
20322026
}
20332027
20342028
ty_tup(ref tys) => {
@@ -2037,7 +2031,7 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
20372031
20382032
ty_enum(did, ref substs) => {
20392033
let variants = substd_enum_variants(cx, did, substs);
2040-
let mut res = if variants.is_empty() {
2034+
let res = if variants.is_empty() {
20412035
// we somewhat arbitrary declare that empty enums
20422036
// are non-copyable
20432037
TC_EMPTY_ENUM
@@ -2048,13 +2042,7 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
20482042
|tc, arg_ty| *tc + tc_ty(cx, *arg_ty, cache))
20492043
})
20502044
};
2051-
if has_attr(cx, did, "mutable") {
2052-
res += TC_MUTABLE;
2053-
}
2054-
if has_attr(cx, did, "non_owned") {
2055-
res += TC_NON_OWNED;
2056-
}
2057-
res
2045+
apply_tc_attr(cx, did, res)
20582046
}
20592047
20602048
ty_param(p) => {
@@ -2114,6 +2102,16 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
21142102
mc + tc_ty(cx, mt.ty, cache)
21152103
}
21162104
2105+
fn apply_tc_attr(cx: ctxt, did: def_id, mut tc: TypeContents) -> TypeContents {
2106+
if has_attr(cx, did, "mutable") {
2107+
tc += TC_MUTABLE;
2108+
}
2109+
if has_attr(cx, did, "non_owned") {
2110+
tc += TC_NON_OWNED;
2111+
}
2112+
tc
2113+
}
2114+
21172115
fn borrowed_contents(region: ty::Region,
21182116
mutbl: ast::mutability) -> TypeContents
21192117
{

0 commit comments

Comments
 (0)