mirror of https://github.com/rust-lang/rust.git
factor out the has_attr checks
This commit is contained in:
parent
66842c8576
commit
bc52224d47
|
@ -2022,13 +2022,7 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
|
||||||
if ty::has_dtor(cx, did) {
|
if ty::has_dtor(cx, did) {
|
||||||
res += TC_DTOR;
|
res += TC_DTOR;
|
||||||
}
|
}
|
||||||
if has_attr(cx, did, "mutable") {
|
apply_tc_attr(cx, did, res)
|
||||||
res += TC_MUTABLE;
|
|
||||||
}
|
|
||||||
if has_attr(cx, did, "non_owned") {
|
|
||||||
res += TC_NON_OWNED;
|
|
||||||
}
|
|
||||||
res
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ty_tup(ref tys) => {
|
ty_tup(ref tys) => {
|
||||||
|
@ -2037,7 +2031,7 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
|
||||||
|
|
||||||
ty_enum(did, ref substs) => {
|
ty_enum(did, ref substs) => {
|
||||||
let variants = substd_enum_variants(cx, did, 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
|
// we somewhat arbitrary declare that empty enums
|
||||||
// are non-copyable
|
// are non-copyable
|
||||||
TC_EMPTY_ENUM
|
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))
|
|tc, arg_ty| *tc + tc_ty(cx, *arg_ty, cache))
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
if has_attr(cx, did, "mutable") {
|
apply_tc_attr(cx, did, res)
|
||||||
res += TC_MUTABLE;
|
|
||||||
}
|
|
||||||
if has_attr(cx, did, "non_owned") {
|
|
||||||
res += TC_NON_OWNED;
|
|
||||||
}
|
|
||||||
res
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ty_param(p) => {
|
ty_param(p) => {
|
||||||
|
@ -2114,6 +2102,16 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
|
||||||
mc + tc_ty(cx, mt.ty, cache)
|
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,
|
fn borrowed_contents(region: ty::Region,
|
||||||
mutbl: ast::mutability) -> TypeContents
|
mutbl: ast::mutability) -> TypeContents
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue