1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // Const qualification, from partial to completely promotable.
13 #[derive(RustcEncodable, RustcDecodable)]
14 flags ConstQualif: u8 {
15 // Inner mutability (can not be placed behind a reference) or behind
16 // &mut in a non-global expression. Can be copied from static memory.
17 const MUTABLE_MEM = 1 << 0,
18 // Constant value with a type that implements Drop. Can be copied
19 // from static memory, similar to MUTABLE_MEM.
20 const NEEDS_DROP = 1 << 1,
21 // Even if the value can be placed in static memory, copying it from
22 // there is more expensive than in-place instantiation, and/or it may
23 // be too large. This applies to [T; N] and everything containing it.
24 // N.B.: references need to clear this flag to not end up on the stack.
25 const PREFER_IN_PLACE = 1 << 2,
26 // May use more than 0 bytes of memory, doesn't impact the constness
27 // directly, but is not allowed to be borrowed mutably in a constant.
28 const NON_ZERO_SIZED = 1 << 3,
29 // Actually borrowed, has to always be in static memory. Does not
30 // propagate, and requires the expression to behave like a 'static
31 // lvalue. The set of expressions with this flag is the minimum
32 // that have to be promoted.
33 const HAS_STATIC_BORROWS = 1 << 4,
34 // Invalid const for miscellaneous reasons (e.g. not implemented).
35 const NOT_CONST = 1 << 5,
37 // Borrowing the expression won't produce &'static T if any of these
38 // bits are set, though the value could be copied from static memory
39 // if `NOT_CONST` isn't set.
40 const NON_STATIC_BORROWS = ConstQualif::MUTABLE_MEM.bits |
41 ConstQualif::NEEDS_DROP.bits |
42 ConstQualif::NOT_CONST.bits