From a89ad587101b4603c8334f344d303ae6eaa99827 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 6 Oct 2014 21:32:58 -0700 Subject: [PATCH 01/24] rustc: Reformat check_const with modern style Remove a bunch of two-space tabs --- src/librustc/middle/check_const.rs | 144 ++++++++++++++++------------- 1 file changed, 78 insertions(+), 66 deletions(-) diff --git a/src/librustc/middle/check_const.rs b/src/librustc/middle/check_const.rs index 5b6b0799235d0..bb62a96f0adc6 100644 --- a/src/librustc/middle/check_const.rs +++ b/src/librustc/middle/check_const.rs @@ -47,7 +47,9 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> { check_pat(self, p); } fn visit_expr(&mut self, ex: &Expr) { - check_expr(self, ex); + if check_expr(self, ex) { + visit::walk_expr(v, e); + } } } @@ -96,73 +98,80 @@ fn check_pat(v: &mut CheckCrateVisitor, p: &Pat) { } } -fn check_expr(v: &mut CheckCrateVisitor, e: &Expr) { - if v.in_const { - match e.node { - ExprUnary(UnDeref, _) => { } - ExprUnary(UnUniq, _) => { - span_err!(v.tcx.sess, e.span, E0010, "cannot do allocations in constant expressions"); - return; - } - ExprLit(ref lit) if ast_util::lit_is_str(&**lit) => {} - ExprBinary(..) | ExprUnary(..) => { +fn check_expr(v: &mut CheckCrateVisitor, e: &Expr) -> bool { + if !v.in_const { return true } + + match e.node { + ExprUnary(UnDeref, _) => {} + ExprUnary(UnUniq, _) => { + span_err!(v.tcx.sess, e.span, E0010, + "cannot do allocations in constant expressions"); + return false; + } + ExprLit(ref lit) if ast_util::lit_is_str(&**lit) => {} + ExprBinary(..) | ExprUnary(..) => { let method_call = typeck::MethodCall::expr(e.id); if v.tcx.method_map.borrow().contains_key(&method_call) { span_err!(v.tcx.sess, e.span, E0011, - "user-defined operators are not allowed in constant expressions"); + "user-defined operators are not allowed in constant \ + expressions"); } - } - ExprLit(_) => (), - ExprCast(_, _) => { + } + ExprLit(_) => (), + ExprCast(_, _) => { let ety = ty::expr_ty(v.tcx, e); if !ty::type_is_numeric(ety) && !ty::type_is_unsafe_ptr(ety) { span_err!(v.tcx.sess, e.span, E0012, - "can not cast to `{}` in a constant expression", - ppaux::ty_to_string(v.tcx, ety) - ); + "can not cast to `{}` in a constant expression", + ppaux::ty_to_string(v.tcx, ety)); } - } - ExprPath(ref pth) => { + } + ExprPath(ref pth) => { // NB: In the future you might wish to relax this slightly // to handle on-demand instantiation of functions via // foo:: in a const. Currently that is only done on // a path in trans::callee that only works in block contexts. if !pth.segments.iter().all(|segment| segment.types.is_empty()) { span_err!(v.tcx.sess, e.span, E0013, - "paths in constants may only refer to items without type parameters"); + "paths in constants may only refer to items without \ + type parameters"); } match v.tcx.def_map.borrow().find(&e.id) { - Some(&DefStatic(..)) | - Some(&DefFn(..)) | - Some(&DefVariant(_, _, _)) | - Some(&DefStruct(_)) => { } - - Some(&def) => { - debug!("(checking const) found bad def: {:?}", def); - span_err!(v.tcx.sess, e.span, E0014, - "paths in constants may only refer to constants or functions"); - } - None => { - v.tcx.sess.span_bug(e.span, "unbound path in const?!"); - } + Some(&DefStatic(..)) | + Some(&DefFn(..)) | + Some(&DefVariant(_, _, _)) | + Some(&DefStruct(_)) => { } + + Some(&def) => { + debug!("(checking const) found bad def: {:?}", def); + span_err!(v.tcx.sess, e.span, E0014, + "paths in constants may only refer to constants \ + or functions"); + } + None => { + v.tcx.sess.span_bug(e.span, "unbound path in const?!"); + } } - } - ExprCall(ref callee, _) => { + } + ExprCall(ref callee, _) => { match v.tcx.def_map.borrow().find(&callee.id) { Some(&DefStruct(..)) | Some(&DefVariant(..)) => {} // OK. + _ => { span_err!(v.tcx.sess, e.span, E0015, - "function calls in constants are limited to struct and enum constructors"); + "function calls in constants are limited to \ + struct and enum constructors"); } } - } - ExprBlock(ref block) => { + } + ExprBlock(ref block) => { // Check all statements in the block for stmt in block.stmts.iter() { let block_span_err = |span| span_err!(v.tcx.sess, span, E0016, - "blocks in constants are limited to items and tail expressions"); + "blocks in constants are limited to items and \ + tail expressions"); match stmt.node { StmtDecl(ref span, _) => { match span.node { @@ -174,40 +183,43 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr) { } StmtExpr(ref expr, _) => block_span_err(expr.span), StmtSemi(ref semi, _) => block_span_err(semi.span), - StmtMac(..) => v.tcx.sess.span_bug(e.span, - "unexpanded statement macro in const?!") + StmtMac(..) => { + v.tcx.sess.span_bug(e.span, "unexpanded statement \ + macro in const?!") + } } } match block.expr { Some(ref expr) => check_expr(v, &**expr), None => {} } - } - ExprVec(_) | - ExprAddrOf(MutImmutable, _) | - ExprParen(..) | - ExprField(..) | - ExprTupField(..) | - ExprIndex(..) | - ExprTup(..) | - ExprRepeat(..) | - ExprStruct(..) => { } - ExprAddrOf(_, ref inner) => { - match inner.node { - // Mutable slices are allowed. - ExprVec(_) => {} - _ => span_err!(v.tcx.sess, e.span, E0017, - "references in constants may only refer to immutable values") + } + ExprVec(_) | + ExprAddrOf(MutImmutable, _) | + ExprParen(..) | + ExprField(..) | + ExprTupField(..) | + ExprIndex(..) | + ExprTup(..) | + ExprRepeat(..) | + ExprStruct(..) => {} - } - }, + ExprAddrOf(_, ref inner) => { + match inner.node { + // Mutable slices are allowed. + ExprVec(_) => {} + _ => span_err!(v.tcx.sess, e.span, E0017, + "references in constants may only refer \ + to immutable values") + + } + } - _ => { - span_err!(v.tcx.sess, e.span, E0019, - "constant contains unimplemented expression type"); - return; - } + _ => { + span_err!(v.tcx.sess, e.span, E0019, + "constant contains unimplemented expression type"); + return false; } } - visit::walk_expr(v, e); + true } From 90d03d792669fed99b659d1efbe835d4b9b8873c Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 6 Oct 2014 08:17:01 -0700 Subject: [PATCH 02/24] rustc: Add `const` globals to the language This change is an implementation of [RFC 69][rfc] which adds a third kind of global to the language, `const`. This global is most similar to what the old `static` was, and if you're unsure about what to use then you should use a `const`. The semantics of these three kinds of globals are: * A `const` does not represent a memory location, but only a value. Constants are translated as rvalues, which means that their values are directly inlined at usage location (similar to a #define in C/C++). Constant values are, well, constant, and can not be modified. Any "modification" is actually a modification to a local value on the stack rather than the actual constant itself. Almost all values are allowed inside constants, whether they have interior mutability or not. There are a few minor restrictions listed in the RFC, but they should in general not come up too often. * A `static` now always represents a memory location (unconditionally). Any references to the same `static` are actually a reference to the same memory location. Only values whose types ascribe to `Sync` are allowed in a `static`. This restriction is in place because many threads may access a `static` concurrently. Lifting this restriction (and allowing unsafe access) is a future extension not implemented at this time. * A `static mut` continues to always represent a memory location. All references to a `static mut` continue to be `unsafe`. This is a large breaking change, and many programs will need to be updated accordingly. A summary of the breaking changes is: * Statics may no longer be used in patterns. Statics now always represent a memory location, which can sometimes be modified. To fix code, repurpose the matched-on-`static` to a `const`. static FOO: uint = 4; match n { FOO => { /* ... */ } _ => { /* ... */ } } change this code to: const FOO: uint = 4; match n { FOO => { /* ... */ } _ => { /* ... */ } } * Statics may no longer refer to other statics by value. Due to statics being able to change at runtime, allowing them to reference one another could possibly lead to confusing semantics. If you are in this situation, use a constant initializer instead. Note, however, that statics may reference other statics by address, however. * Statics may no longer be used in constant expressions, such as array lengths. This is due to the same restrictions as listed above. Use a `const` instead. [breaking-change] [rfc]: https://github.com/rust-lang/rfcs/pull/246 --- src/librustc/lint/builtin.rs | 5 +- src/librustc/metadata/decoder.rs | 5 +- src/librustc/metadata/encoder.rs | 24 +- src/librustc/middle/astencode.rs | 1 + .../middle/borrowck/gather_loans/mod.rs | 14 +- src/librustc/middle/borrowck/mod.rs | 3 +- src/librustc/middle/check_const.rs | 8 +- src/librustc/middle/check_match.rs | 64 ++-- src/librustc/middle/check_static.rs | 307 ++++++++++++++---- src/librustc/middle/check_static_recursion.rs | 28 +- src/librustc/middle/const_eval.rs | 6 +- src/librustc/middle/dead.rs | 3 +- src/librustc/middle/def.rs | 3 +- src/librustc/middle/expr_use_visitor.rs | 2 +- src/librustc/middle/mem_categorization.rs | 4 +- src/librustc/middle/pat_util.rs | 2 +- src/librustc/middle/privacy.rs | 5 +- src/librustc/middle/reachable.rs | 39 +-- src/librustc/middle/resolve.rs | 21 +- src/librustc/middle/resolve_lifetime.rs | 2 +- src/librustc/middle/save/mod.rs | 29 ++ src/librustc/middle/traexpr | 0 src/librustc/middle/trans/_match.rs | 48 ++- src/librustc/middle/trans/base.rs | 110 +++---- src/librustc/middle/trans/callee.rs | 1 + src/librustc/middle/trans/consts.rs | 206 ++++++------ src/librustc/middle/trans/context.rs | 21 +- src/librustc/middle/trans/debuginfo.rs | 1 + src/librustc/middle/trans/expr.rs | 75 +++-- src/librustc/middle/trans/inline.rs | 17 +- src/librustc/middle/ty.rs | 3 + src/librustc/middle/typeck/check/mod.rs | 6 +- src/librustc/middle/typeck/check/wf.rs | 3 + src/librustc/middle/typeck/collect.rs | 2 +- src/librustc/middle/typeck/infer/test.rs | 2 +- src/librustc/middle/typeck/variance.rs | 2 + src/libsyntax/ast.rs | 1 + src/libsyntax/ast_map/mod.rs | 1 + src/libsyntax/ast_util.rs | 14 - src/libsyntax/ext/build.rs | 16 + src/libsyntax/fold.rs | 3 + src/libsyntax/parse/parser.rs | 14 +- src/libsyntax/print/pprust.rs | 14 + src/libsyntax/test.rs | 9 +- src/libsyntax/visit.rs | 3 +- .../issue-17718-const-destructors.rs | 19 ++ 46 files changed, 721 insertions(+), 445 deletions(-) create mode 100644 src/librustc/middle/traexpr create mode 100644 src/test/compile-fail/issue-17718-const-destructors.rs diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 4c147517a7f03..451d39fbc3def 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -978,7 +978,8 @@ impl LintPass for NonUppercaseStatics { fn check_item(&mut self, cx: &Context, it: &ast::Item) { match it.node { // only check static constants - ast::ItemStatic(_, ast::MutImmutable, _) => { + ast::ItemStatic(_, ast::MutImmutable, _) | + ast::ItemConst(..) => { let s = token::get_ident(it.ident); // check for lowercase letters rather than non-uppercase // ones (some scripts don't have a concept of @@ -998,7 +999,7 @@ impl LintPass for NonUppercaseStatics { fn check_pat(&mut self, cx: &Context, p: &ast::Pat) { // Lint for constants that look like binding identifiers (#7526) match (&p.node, cx.tcx.def_map.borrow().find(&p.id)) { - (&ast::PatIdent(_, ref path1, _), Some(&def::DefStatic(_, false))) => { + (&ast::PatIdent(_, ref path1, _), Some(&def::DefConst(..))) => { let s = token::get_ident(path1.node); if s.get().chars().any(|c| c.is_lowercase()) { cx.span_lint(NON_UPPERCASE_STATICS, path1.span, diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index 58d0f132e06a2..dcf394aa3f406 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -126,12 +126,14 @@ enum Family { Trait, // I Struct, // S PublicField, // g - InheritedField // N + InheritedField, // N + Constant, // C } fn item_family(item: rbml::Doc) -> Family { let fam = reader::get_doc(item, tag_items_data_item_family); match reader::doc_as_u8(fam) as char { + 'C' => Constant, 'c' => ImmStatic, 'b' => MutStatic, 'f' => Fn, @@ -303,6 +305,7 @@ fn item_to_def_like(item: rbml::Doc, did: ast::DefId, cnum: ast::CrateNum) -> DefLike { let fam = item_family(item); match fam { + Constant => DlDef(def::DefConst(did)), ImmStatic => DlDef(def::DefStatic(did, false)), MutStatic => DlDef(def::DefStatic(did, true)), Struct => DlDef(def::DefStruct(did)), diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index 642f66e259a62..94d86956f7005 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -69,7 +69,6 @@ pub struct EncodeParams<'a, 'tcx: 'a> { pub tcx: &'a ty::ctxt<'tcx>, pub reexports2: &'a middle::resolve::ExportMap2, pub item_symbols: &'a RefCell>, - pub non_inlineable_statics: &'a RefCell, pub link_meta: &'a LinkMeta, pub cstore: &'a cstore::CStore, pub encode_inlined_item: EncodeInlinedItem<'a>, @@ -81,7 +80,6 @@ pub struct EncodeContext<'a, 'tcx: 'a> { pub tcx: &'a ty::ctxt<'tcx>, pub reexports2: &'a middle::resolve::ExportMap2, pub item_symbols: &'a RefCell>, - pub non_inlineable_statics: &'a RefCell, pub link_meta: &'a LinkMeta, pub cstore: &'a cstore::CStore, pub encode_inlined_item: RefCell>, @@ -1069,12 +1067,20 @@ fn encode_info_for_item(ecx: &EncodeContext, encode_symbol(ecx, rbml_w, item.id); encode_name(rbml_w, item.ident.name); encode_path(rbml_w, path); - - let inlineable = !ecx.non_inlineable_statics.borrow().contains(&item.id); - - if inlineable { - encode_inlined_item(ecx, rbml_w, IIItemRef(item)); - } + encode_visibility(rbml_w, vis); + encode_stability(rbml_w, stab); + encode_attributes(rbml_w, item.attrs.as_slice()); + rbml_w.end_tag(); + } + ItemConst(_, _) => { + add_to_index(item, rbml_w, index); + rbml_w.start_tag(tag_items_data_item); + encode_def_id(rbml_w, def_id); + encode_family(rbml_w, 'C'); + encode_bounds_and_type(rbml_w, ecx, &lookup_item_type(tcx, def_id)); + encode_name(rbml_w, item.ident.name); + encode_path(rbml_w, path); + encode_inlined_item(ecx, rbml_w, IIItemRef(item)); encode_visibility(rbml_w, vis); encode_stability(rbml_w, stab); rbml_w.end_tag(); @@ -2076,7 +2082,6 @@ fn encode_metadata_inner(wr: &mut SeekableMemWriter, parms: EncodeParams, krate: cstore, encode_inlined_item, link_meta, - non_inlineable_statics, reachable, .. } = parms; @@ -2085,7 +2090,6 @@ fn encode_metadata_inner(wr: &mut SeekableMemWriter, parms: EncodeParams, krate: tcx: tcx, reexports2: reexports2, item_symbols: item_symbols, - non_inlineable_statics: non_inlineable_statics, link_meta: link_meta, cstore: cstore, encode_inlined_item: RefCell::new(encode_inlined_item), diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index 2bd145706aaad..955228c99deed 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -460,6 +460,7 @@ impl tr for def::Def { def::DefMod(did) => { def::DefMod(did.tr(dcx)) } def::DefForeignMod(did) => { def::DefForeignMod(did.tr(dcx)) } def::DefStatic(did, m) => { def::DefStatic(did.tr(dcx), m) } + def::DefConst(did) => { def::DefConst(did.tr(dcx)) } def::DefLocal(nid) => { def::DefLocal(dcx.tr_id(nid)) } def::DefVariant(e_did, v_did, is_s) => { def::DefVariant(e_did.tr(dcx), v_did.tr(dcx), is_s) diff --git a/src/librustc/middle/borrowck/gather_loans/mod.rs b/src/librustc/middle/borrowck/gather_loans/mod.rs index cd003432ef22c..f2ff104ba1d10 100644 --- a/src/librustc/middle/borrowck/gather_loans/mod.rs +++ b/src/librustc/middle/borrowck/gather_loans/mod.rs @@ -169,15 +169,11 @@ fn check_aliasability(bccx: &BorrowckCtxt, // Borrow of an immutable static item: match safety { mc::InteriorUnsafe => { - // If the static item contains an Unsafe, it has interior mutability. - // In such cases, we cannot permit it to be borrowed, because the - // static item resides in immutable memory and mutating it would - // cause segfaults. - bccx.tcx.sess.span_err(borrow_span, - "borrow of immutable static items \ - with unsafe interior is not \ - allowed"); - Err(()) + // If the static item contains an Unsafe, it has interior + // mutability. In such cases, another phase of the compiler + // will ensure that the type is `Sync` and then trans will + // not put it in rodata, so this is ok to allow. + Ok(()) } mc::InteriorSafe => { // Immutable static can be borrowed, no problem. diff --git a/src/librustc/middle/borrowck/mod.rs b/src/librustc/middle/borrowck/mod.rs index a86ae42006595..7d0d99443b0d8 100644 --- a/src/librustc/middle/borrowck/mod.rs +++ b/src/librustc/middle/borrowck/mod.rs @@ -106,7 +106,8 @@ fn borrowck_item(this: &mut BorrowckCtxt, item: &ast::Item) { // loan step is intended for things that have a data // flow dependent conditions. match item.node { - ast::ItemStatic(_, _, ref ex) => { + ast::ItemStatic(_, _, ref ex) | + ast::ItemConst(_, ref ex) => { gather_loans::gather_loans_in_static_initializer(this, &**ex); } _ => { diff --git a/src/librustc/middle/check_const.rs b/src/librustc/middle/check_const.rs index bb62a96f0adc6..f0455db6e3bb6 100644 --- a/src/librustc/middle/check_const.rs +++ b/src/librustc/middle/check_const.rs @@ -48,7 +48,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> { } fn visit_expr(&mut self, ex: &Expr) { if check_expr(self, ex) { - visit::walk_expr(v, e); + visit::walk_expr(self, ex); } } } @@ -61,7 +61,8 @@ pub fn check_crate(tcx: &ty::ctxt) { fn check_item(v: &mut CheckCrateVisitor, it: &Item) { match it.node { - ItemStatic(_, _, ref ex) => { + ItemStatic(_, _, ref ex) | + ItemConst(_, ref ex) => { v.inside_const(|v| v.visit_expr(&**ex)); } ItemEnum(ref enum_definition, _) => { @@ -138,6 +139,7 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr) -> bool { } match v.tcx.def_map.borrow().find(&e.id) { Some(&DefStatic(..)) | + Some(&DefConst(..)) | Some(&DefFn(..)) | Some(&DefVariant(_, _, _)) | Some(&DefStruct(_)) => { } @@ -190,7 +192,7 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr) -> bool { } } match block.expr { - Some(ref expr) => check_expr(v, &**expr), + Some(ref expr) => { check_expr(v, &**expr); } None => {} } } diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index 92f04b108c19b..297640707687c 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -32,7 +32,7 @@ use syntax::ptr::P; use syntax::visit::{mod, Visitor, FnKind}; use util::ppaux::ty_to_string; -static DUMMY_WILD_PAT: Pat = Pat { +pub const DUMMY_WILD_PAT: Pat = Pat { id: DUMMY_NODE_ID, node: PatWild(PatWildSingle), span: DUMMY_SP @@ -299,9 +299,10 @@ fn raw_pat<'a>(p: &'a Pat) -> &'a Pat { fn check_exhaustive(cx: &MatchCheckCtxt, sp: Span, matrix: &Matrix) { match is_useful(cx, matrix, &[&DUMMY_WILD_PAT], ConstructWitness) { UsefulWithWitness(pats) => { + let dummy = DUMMY_WILD_PAT.clone(); let witness = match pats.as_slice() { [ref witness] => &**witness, - [] => &DUMMY_WILD_PAT, + [] => &dummy, _ => unreachable!() }; span_err!(cx.tcx.sess, sp, E0004, @@ -349,7 +350,7 @@ impl<'a, 'tcx> Folder for StaticInliner<'a, 'tcx> { PatIdent(..) | PatEnum(..) => { let def = self.tcx.def_map.borrow().find_copy(&pat.id); match def { - Some(DefStatic(did, _)) => match lookup_const_by_id(self.tcx, did) { + Some(DefConst(did)) => match lookup_const_by_id(self.tcx, did) { Some(const_expr) => { const_expr_to_pat(self.tcx, const_expr).map(|mut new_pat| { new_pat.span = pat.span; @@ -359,7 +360,7 @@ impl<'a, 'tcx> Folder for StaticInliner<'a, 'tcx> { None => { self.failed = true; span_err!(self.tcx.sess, pat.span, E0158, - "extern statics cannot be referenced in patterns"); + "statics cannot be referenced in patterns"); pat } }, @@ -555,8 +556,9 @@ fn is_useful(cx: &MatchCheckCtxt, let arity = constructor_arity(cx, &c, left_ty); let mut result = { let pat_slice = pats.as_slice(); + let dummy = DUMMY_WILD_PAT.clone(); let subpats = Vec::from_fn(arity, |i| { - pat_slice.get(i).map_or(&DUMMY_WILD_PAT, |p| &**p) + pat_slice.get(i).map_or(&dummy, |p| &**p) }); vec![construct_witness(cx, &c, subpats, left_ty)] }; @@ -578,8 +580,9 @@ fn is_useful(cx: &MatchCheckCtxt, }).collect(); match is_useful(cx, &matrix, v.tail(), witness) { UsefulWithWitness(pats) => { + let dummy = DUMMY_WILD_PAT.clone(); let arity = constructor_arity(cx, &constructor, left_ty); - let wild_pats = Vec::from_elem(arity, &DUMMY_WILD_PAT); + let wild_pats = Vec::from_elem(arity, &dummy); let enum_pat = construct_witness(cx, &constructor, wild_pats, left_ty); let mut new_pats = vec![enum_pat]; new_pats.extend(pats.into_iter()); @@ -600,10 +603,11 @@ fn is_useful_specialized(cx: &MatchCheckCtxt, &Matrix(ref m): &Matrix, v: &[&Pat], ctor: Constructor, lty: ty::t, witness: WitnessPreference) -> Usefulness { let arity = constructor_arity(cx, &ctor, lty); + let dummy = DUMMY_WILD_PAT.clone(); let matrix = Matrix(m.iter().filter_map(|r| { - specialize(cx, r.as_slice(), &ctor, 0u, arity) + specialize(cx, r.as_slice(), &dummy, &ctor, 0u, arity) }).collect()); - match specialize(cx, v, &ctor, 0u, arity) { + match specialize(cx, v, &dummy, &ctor, 0u, arity) { Some(v) => is_useful(cx, &matrix, v.as_slice(), witness), None => NotUseful } @@ -624,23 +628,26 @@ fn pat_constructors(cx: &MatchCheckCtxt, p: &Pat, match pat.node { PatIdent(..) => match cx.tcx.def_map.borrow().find(&pat.id) { - Some(&DefStatic(..)) => - cx.tcx.sess.span_bug(pat.span, "static pattern should've been rewritten"), + Some(&DefConst(..)) => + cx.tcx.sess.span_bug(pat.span, "const pattern should've \ + been rewritten"), Some(&DefStruct(_)) => vec!(Single), Some(&DefVariant(_, id, _)) => vec!(Variant(id)), _ => vec!() }, PatEnum(..) => match cx.tcx.def_map.borrow().find(&pat.id) { - Some(&DefStatic(..)) => - cx.tcx.sess.span_bug(pat.span, "static pattern should've been rewritten"), + Some(&DefConst(..)) => + cx.tcx.sess.span_bug(pat.span, "static pattern should've \ + been rewritten"), Some(&DefVariant(_, id, _)) => vec!(Variant(id)), _ => vec!(Single) }, PatStruct(..) => match cx.tcx.def_map.borrow().find(&pat.id) { - Some(&DefStatic(..)) => - cx.tcx.sess.span_bug(pat.span, "static pattern should've been rewritten"), + Some(&DefConst(..)) => + cx.tcx.sess.span_bug(pat.span, "static pattern should've \ + been rewritten"), Some(&DefVariant(_, id, _)) => vec!(Variant(id)), _ => vec!(Single) }, @@ -722,7 +729,7 @@ fn range_covered_by_constructor(ctor: &Constructor, /// different patterns. /// Structure patterns with a partial wild pattern (Foo { a: 42, .. }) have their missing /// fields filled with wild patterns. -pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat], +pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat], dummy: &'a Pat, constructor: &Constructor, col: uint, arity: uint) -> Option> { let &Pat { id: pat_id, node: ref node, span: pat_span @@ -730,32 +737,34 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat], let head: Option> = match node { &PatWild(_) => - Some(Vec::from_elem(arity, &DUMMY_WILD_PAT)), + Some(Vec::from_elem(arity, dummy)), &PatIdent(_, _, _) => { let opt_def = cx.tcx.def_map.borrow().find_copy(&pat_id); match opt_def { - Some(DefStatic(..)) => - cx.tcx.sess.span_bug(pat_span, "static pattern should've been rewritten"), + Some(DefConst(..)) => + cx.tcx.sess.span_bug(pat_span, "const pattern should've \ + been rewritten"), Some(DefVariant(_, id, _)) => if *constructor == Variant(id) { Some(vec!()) } else { None }, - _ => Some(Vec::from_elem(arity, &DUMMY_WILD_PAT)) + _ => Some(Vec::from_elem(arity, dummy)) } } &PatEnum(_, ref args) => { let def = cx.tcx.def_map.borrow().get_copy(&pat_id); match def { - DefStatic(..) => - cx.tcx.sess.span_bug(pat_span, "static pattern should've been rewritten"), + DefConst(..) => + cx.tcx.sess.span_bug(pat_span, "const pattern should've \ + been rewritten"), DefVariant(_, id, _) if *constructor != Variant(id) => None, DefVariant(..) | DefStruct(..) => { Some(match args { &Some(ref args) => args.iter().map(|p| &**p).collect(), - &None => Vec::from_elem(arity, &DUMMY_WILD_PAT) + &None => Vec::from_elem(arity, dummy) }) } _ => None @@ -766,8 +775,9 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat], // Is this a struct or an enum variant? let def = cx.tcx.def_map.borrow().get_copy(&pat_id); let class_id = match def { - DefStatic(..) => - cx.tcx.sess.span_bug(pat_span, "static pattern should've been rewritten"), + DefConst(..) => + cx.tcx.sess.span_bug(pat_span, "const pattern should've \ + been rewritten"), DefVariant(_, variant_id, _) => if *constructor == Variant(variant_id) { Some(variant_id) } else { @@ -790,7 +800,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat], let args = struct_fields.iter().map(|sf| { match pattern_fields.iter().find(|f| f.ident.name == sf.name) { Some(ref f) => &*f.pat, - _ => &DUMMY_WILD_PAT + _ => dummy } }).collect(); args @@ -833,13 +843,13 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat], // Fixed-length vectors. Single => { let mut pats: Vec<&Pat> = before.iter().map(|p| &**p).collect(); - pats.grow_fn(arity - before.len() - after.len(), |_| &DUMMY_WILD_PAT); + pats.grow_fn(arity - before.len() - after.len(), |_| dummy); pats.extend(after.iter().map(|p| &**p)); Some(pats) }, Slice(length) if before.len() + after.len() <= length && slice.is_some() => { let mut pats: Vec<&Pat> = before.iter().map(|p| &**p).collect(); - pats.grow_fn(arity - before.len() - after.len(), |_| &DUMMY_WILD_PAT); + pats.grow_fn(arity - before.len() - after.len(), |_| dummy); pats.extend(after.iter().map(|p| &**p)); Some(pats) }, diff --git a/src/librustc/middle/check_static.rs b/src/librustc/middle/check_static.rs index 64e4d7ff28425..9cc1f92dc9304 100644 --- a/src/librustc/middle/check_static.rs +++ b/src/librustc/middle/check_static.rs @@ -25,48 +25,103 @@ // by borrowck::gather_loans use middle::ty; +use middle::def; +use middle::typeck; +use middle::traits; +use middle::mem_categorization as mc; +use middle::expr_use_visitor as euv; +use util::nodemap::NodeSet; use syntax::ast; +use syntax::print::pprust; use syntax::visit::Visitor; +use syntax::codemap::{DUMMY_SP, Span}; use syntax::visit; -use syntax::print::pprust; - - -fn safe_type_for_static_mut(cx: &ty::ctxt, e: &ast::Expr) -> Option { - let node_ty = ty::node_id_to_type(cx, e.id); - let tcontents = ty::type_contents(cx, node_ty); - debug!("safe_type_for_static_mut(dtor={}, managed={}, owned={})", - tcontents.has_dtor(), tcontents.owns_managed(), tcontents.owns_owned()) - - let suffix = if tcontents.has_dtor() { - "destructors" - } else if tcontents.owns_managed() { - "managed pointers" - } else if tcontents.owns_owned() { - "owned pointers" - } else { - return None; - }; - Some(format!("mutable static items are not allowed to have {}", suffix)) +#[deriving(Eq, PartialEq)] +enum Mode { + InConstant, + InStatic, + InStaticMut, + InNothing, } struct CheckStaticVisitor<'a, 'tcx: 'a> { tcx: &'a ty::ctxt<'tcx>, - in_const: bool + mode: Mode, + checker: &'a mut GlobalChecker, +} + +struct GlobalVisitor<'a, 'b, 't: 'b>(euv::ExprUseVisitor<'a, 'b, ty::ctxt<'t>>); +struct GlobalChecker { + static_consumptions: NodeSet, + const_borrows: NodeSet, + static_interior_borrows: NodeSet, } pub fn check_crate(tcx: &ty::ctxt) { - visit::walk_crate(&mut CheckStaticVisitor { tcx: tcx, in_const: false }, - tcx.map.krate()) + let mut checker = GlobalChecker { + static_consumptions: NodeSet::new(), + const_borrows: NodeSet::new(), + static_interior_borrows: NodeSet::new(), + }; + { + let visitor = euv::ExprUseVisitor::new(&mut checker, tcx); + visit::walk_crate(&mut GlobalVisitor(visitor), tcx.map.krate()); + } + visit::walk_crate(&mut CheckStaticVisitor { + tcx: tcx, + mode: InNothing, + checker: &mut checker, + }, tcx.map.krate()); } impl<'a, 'tcx> CheckStaticVisitor<'a, 'tcx> { - fn with_const(&mut self, in_const: bool, f: |&mut CheckStaticVisitor<'a, 'tcx>|) { - let was_const = self.in_const; - self.in_const = in_const; + fn with_mode(&mut self, mode: Mode, f: |&mut CheckStaticVisitor<'a, 'tcx>|) { + let old = self.mode; + self.mode = mode; f(self); - self.in_const = was_const; + self.mode = old; + } + + fn msg(&self) -> &'static str { + match self.mode { + InConstant => "constants", + InStaticMut | InStatic => "statics", + InNothing => unreachable!(), + } + } + + fn check_static_mut_type(&self, e: &ast::Expr) { + let node_ty = ty::node_id_to_type(self.tcx, e.id); + let tcontents = ty::type_contents(self.tcx, node_ty); + + let suffix = if tcontents.has_dtor() { + "destructors" + } else if tcontents.owns_owned() { + "owned pointers" + } else { + return + }; + + self.tcx.sess.span_err(e.span, format!("mutable statics are not allowed \ + to have {}", suffix).as_slice()); + } + + fn check_static_type(&self, e: &ast::Expr) { + let ty = ty::node_id_to_type(self.tcx, e.id); + let infcx = typeck::infer::new_infer_ctxt(self.tcx); + let mut fulfill_cx = traits::FulfillmentContext::new(); + let cause = traits::ObligationCause::misc(DUMMY_SP); + let obligation = traits::obligation_for_builtin_bound(self.tcx, cause, ty, + ty::BoundSync); + fulfill_cx.register_obligation(self.tcx, obligation.unwrap()); + let env = ty::empty_parameter_environment(); + let result = fulfill_cx.select_all_or_error(&infcx, &env, self.tcx).is_ok(); + if !result { + self.tcx.sess.span_err(e.span, "shared static items must have a \ + type which implements Sync"); + } } } @@ -74,22 +129,20 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckStaticVisitor<'a, 'tcx> { fn visit_item(&mut self, i: &ast::Item) { debug!("visit_item(item={})", pprust::item_to_string(i)); match i.node { - ast::ItemStatic(_, mutability, ref expr) => { - match mutability { - ast::MutImmutable => { - self.with_const(true, |v| v.visit_expr(&**expr)); - } - ast::MutMutable => { - match safe_type_for_static_mut(self.tcx, &**expr) { - Some(msg) => { - self.tcx.sess.span_err(expr.span, msg.as_slice()); - } - None => {} - } - } - } + ast::ItemStatic(_, ast::MutImmutable, ref expr) => { + self.check_static_type(&**expr); + self.with_mode(InStatic, |v| v.visit_expr(&**expr)); + } + ast::ItemStatic(_, ast::MutMutable, ref expr) => { + self.check_static_mut_type(&**expr); + self.with_mode(InStaticMut, |v| v.visit_expr(&**expr)); + } + ast::ItemConst(_, ref expr) => { + self.with_mode(InConstant, |v| v.visit_expr(&**expr)); + } + _ => { + self.with_mode(InNothing, |v| visit::walk_item(v, i)); } - _ => self.with_const(false, |v| visit::walk_item(v, i)) } } @@ -100,42 +153,170 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckStaticVisitor<'a, 'tcx> { /// of a static item, this method does nothing but walking /// down through it. fn visit_expr(&mut self, e: &ast::Expr) { - debug!("visit_expr(expr={})", pprust::expr_to_string(e)); - - if !self.in_const { + if self.mode == InNothing { return visit::walk_expr(self, e); } - match e.node { - ast::ExprField(..) | ast::ExprTupField(..) | ast::ExprVec(..) | - ast::ExprBlock(..) | ast::ExprTup(..) => { - visit::walk_expr(self, e); + let node_ty = ty::node_id_to_type(self.tcx, e.id); + + match ty::get(node_ty).sty { + ty::ty_struct(did, _) | + ty::ty_enum(did, _) if ty::has_dtor(self.tcx, did) => { + self.tcx.sess.span_err(e.span, + format!("{} are not allowed to have \ + destructors", self.msg()).as_slice()) } + _ => {} + } + + // statics cannot be consumed by value at any time, that would imply + // that they're an initializer (what a const is for) or kept in sync + // over time (not feasible), so deny it outright. + if self.checker.static_consumptions.remove(&e.id) { + self.tcx.sess.span_err(e.span, "cannot refer to other statics by \ + value, use the address-of operator \ + or a constant instead"); + } + + // Borrowed statics can specifically *only* have their address taken, + // not any number of other borrows such as borrowing fields, reading + // elements of an array, etc. + if self.checker.static_interior_borrows.remove(&e.id) { + self.tcx.sess.span_err(e.span, "cannot refer to the interior of \ + another static, use a constant \ + instead"); + } + + // constants cannot be borrowed if they contain interior mutability as + // it means that our "silent insertion of statics" could change + // initializer values (very bad). + if self.checker.const_borrows.remove(&e.id) { + let node_ty = ty::node_id_to_type(self.tcx, e.id); + let tcontents = ty::type_contents(self.tcx, node_ty); + if tcontents.interior_unsafe() { + self.tcx.sess.span_err(e.span, "cannot borrow a constant which \ + contains interior mutability, \ + create a static instead"); + } + } + + match e.node { ast::ExprAddrOf(ast::MutMutable, _) => { - span_err!(self.tcx.sess, e.span, E0020, - "static items are not allowed to have mutable slices"); + if self.mode != InStaticMut { + span_err!(self.tcx.sess, e.span, E0020, + "{} are not allowed to have mutable references", + self.msg()); + } }, ast::ExprBox(..) | ast::ExprUnary(ast::UnUniq, _) => { span_err!(self.tcx.sess, e.span, E0022, - "static items are not allowed to have custom pointers"); + "{} are not allowed to have custom pointers", + self.msg()); } - _ => { - let node_ty = ty::node_id_to_type(self.tcx, e.id); - - match ty::get(node_ty).sty { - ty::ty_struct(did, _) | - ty::ty_enum(did, _) => { - if ty::has_dtor(self.tcx, did) { - self.tcx.sess.span_err(e.span, - "static items are not allowed to have destructors"); - return; - } + ast::ExprPath(..) => { + match ty::resolve_expr(self.tcx, e) { + def::DefStatic(..) if self.mode == InConstant => { + let msg = "constants cannot refer to other statics, \ + insert an intermediate constant \ + instead"; + self.tcx.sess.span_err(e.span, msg.as_slice()); } _ => {} } - visit::walk_expr(self, e); } + _ => {} + } + visit::walk_expr(self, e); + } +} + +impl<'a, 'b, 't, 'v> Visitor<'v> for GlobalVisitor<'a, 'b, 't> { + fn visit_item(&mut self, item: &ast::Item) { + match item.node { + ast::ItemConst(_, ref e) | + ast::ItemStatic(_, _, ref e) => { + let GlobalVisitor(ref mut v) = *self; + v.consume_expr(&**e); + } + _ => {} } + visit::walk_item(self, item); } } + +impl euv::Delegate for GlobalChecker { + fn consume(&mut self, + consume_id: ast::NodeId, + _consume_span: Span, + cmt: mc::cmt, + _mode: euv::ConsumeMode) { + let mut cur = &cmt; + loop { + match cur.cat { + mc::cat_static_item => { + self.static_consumptions.insert(consume_id); + break + } + mc::cat_deref(ref cmt, _, _) | + mc::cat_discr(ref cmt, _) | + mc::cat_downcast(ref cmt) | + mc::cat_interior(ref cmt, _) => cur = cmt, + + mc::cat_rvalue(..) | + mc::cat_copied_upvar(..) | + mc::cat_upvar(..) | + mc::cat_local(..) => break, + } + } + } + fn borrow(&mut self, + borrow_id: ast::NodeId, + _borrow_span: Span, + cmt: mc::cmt, + _loan_region: ty::Region, + _bk: ty::BorrowKind, + _loan_cause: euv::LoanCause) { + let mut cur = &cmt; + let mut is_interior = false; + loop { + match cur.cat { + mc::cat_rvalue(..) => { + self.const_borrows.insert(borrow_id); + break + } + mc::cat_static_item => { + if is_interior { + self.static_interior_borrows.insert(borrow_id); + } + break + } + mc::cat_deref(ref cmt, _, _) | + mc::cat_interior(ref cmt, _) => { + is_interior = true; + cur = cmt; + } + + mc::cat_downcast(..) | + mc::cat_discr(..) | + mc::cat_copied_upvar(..) | + mc::cat_upvar(..) | + mc::cat_local(..) => unreachable!(), + } + } + } + + fn decl_without_init(&mut self, + _id: ast::NodeId, + _span: Span) {} + fn mutate(&mut self, + _assignment_id: ast::NodeId, + _assignment_span: Span, + _assignee_cmt: mc::cmt, + _mode: euv::MutateMode) {} + fn consume_pat(&mut self, + _consume_pat: &ast::Pat, + _cmt: mc::cmt, + _mode: euv::ConsumeMode) {} +} + diff --git a/src/librustc/middle/check_static_recursion.rs b/src/librustc/middle/check_static_recursion.rs index b571a18c1ece7..1f76d9dba2635 100644 --- a/src/librustc/middle/check_static_recursion.rs +++ b/src/librustc/middle/check_static_recursion.rs @@ -13,9 +13,9 @@ use driver::session::Session; use middle::resolve; -use middle::def::DefStatic; +use middle::def::{DefStatic, DefConst}; -use syntax::ast::{Crate, Expr, ExprPath, Item, ItemStatic, NodeId}; +use syntax::ast; use syntax::{ast_util, ast_map}; use syntax::visit::Visitor; use syntax::visit; @@ -27,13 +27,13 @@ struct CheckCrateVisitor<'a, 'ast: 'a> { } impl<'v, 'a, 'ast> Visitor<'v> for CheckCrateVisitor<'a, 'ast> { - fn visit_item(&mut self, i: &Item) { + fn visit_item(&mut self, i: &ast::Item) { check_item(self, i); } } pub fn check_crate<'ast>(sess: &Session, - krate: &Crate, + krate: &ast::Crate, def_map: &resolve::DefMap, ast_map: &ast_map::Map<'ast>) { let mut visitor = CheckCrateVisitor { @@ -45,9 +45,10 @@ pub fn check_crate<'ast>(sess: &Session, sess.abort_if_errors(); } -fn check_item(v: &mut CheckCrateVisitor, it: &Item) { +fn check_item(v: &mut CheckCrateVisitor, it: &ast::Item) { match it.node { - ItemStatic(_, _, ref ex) => { + ast::ItemStatic(_, _, ref ex) | + ast::ItemConst(_, ref ex) => { check_item_recursion(v.sess, v.ast_map, v.def_map, it); visit::walk_expr(v, &**ex) }, @@ -56,11 +57,11 @@ fn check_item(v: &mut CheckCrateVisitor, it: &Item) { } struct CheckItemRecursionVisitor<'a, 'ast: 'a> { - root_it: &'a Item, + root_it: &'a ast::Item, sess: &'a Session, ast_map: &'a ast_map::Map<'ast>, def_map: &'a resolve::DefMap, - idstack: Vec + idstack: Vec } // Make sure a const item doesn't recursively refer to itself @@ -68,7 +69,7 @@ struct CheckItemRecursionVisitor<'a, 'ast: 'a> { pub fn check_item_recursion<'a>(sess: &'a Session, ast_map: &'a ast_map::Map, def_map: &'a resolve::DefMap, - it: &'a Item) { + it: &'a ast::Item) { let mut visitor = CheckItemRecursionVisitor { root_it: it, @@ -81,7 +82,7 @@ pub fn check_item_recursion<'a>(sess: &'a Session, } impl<'a, 'ast, 'v> Visitor<'v> for CheckItemRecursionVisitor<'a, 'ast> { - fn visit_item(&mut self, it: &Item) { + fn visit_item(&mut self, it: &ast::Item) { if self.idstack.iter().any(|x| x == &(it.id)) { self.sess.span_err(self.root_it.span, "recursive constant"); return; @@ -91,11 +92,12 @@ impl<'a, 'ast, 'v> Visitor<'v> for CheckItemRecursionVisitor<'a, 'ast> { self.idstack.pop(); } - fn visit_expr(&mut self, e: &Expr) { + fn visit_expr(&mut self, e: &ast::Expr) { match e.node { - ExprPath(..) => { + ast::ExprPath(..) => { match self.def_map.borrow().find(&e.id) { - Some(&DefStatic(def_id, _)) if + Some(&DefStatic(def_id, _)) | + Some(&DefConst(def_id)) if ast_util::is_local(def_id) => { self.visit_item(&*self.ast_map.expect_item(def_id.node)); } diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index 98d2cefac0fcf..abcdc45bdcfde 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -87,7 +87,7 @@ pub fn join_all>(mut cs: It) -> constness { fn lookup_const<'a>(tcx: &'a ty::ctxt, e: &Expr) -> Option<&'a Expr> { let opt_def = tcx.def_map.borrow().find_copy(&e.id); match opt_def { - Some(def::DefStatic(def_id, false)) => { + Some(def::DefConst(def_id)) => { lookup_const_by_id(tcx, def_id) } Some(def::DefVariant(enum_def, variant_def, _)) => { @@ -155,7 +155,7 @@ pub fn lookup_const_by_id<'a>(tcx: &'a ty::ctxt, def_id: ast::DefId) match tcx.map.find(def_id.node) { None => None, Some(ast_map::NodeItem(it)) => match it.node { - ItemStatic(_, ast::MutImmutable, ref const_expr) => { + ItemConst(_, ref const_expr) => { Some(&**const_expr) } _ => None @@ -173,7 +173,7 @@ pub fn lookup_const_by_id<'a>(tcx: &'a ty::ctxt, def_id: ast::DefId) let expr_id = match csearch::maybe_get_item_ast(tcx, def_id, |a, b, c, d| astencode::decode_inlined_item(a, b, c, d)) { csearch::found(&ast::IIItem(ref item)) => match item.node { - ItemStatic(_, ast::MutImmutable, ref const_expr) => Some(const_expr.id), + ItemConst(_, ref const_expr) => Some(const_expr.id), _ => None }, _ => None diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index 1b2f62a9385a2..ff3720381009c 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -215,7 +215,8 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> { ast::ItemFn(..) | ast::ItemEnum(..) | ast::ItemTy(..) - | ast::ItemStatic(..) => { + | ast::ItemStatic(..) + | ast::ItemConst(..) => { visit::walk_item(self, &*item); } _ => () diff --git a/src/librustc/middle/def.rs b/src/librustc/middle/def.rs index bd42586435f26..3b7af9788ac57 100644 --- a/src/librustc/middle/def.rs +++ b/src/librustc/middle/def.rs @@ -20,6 +20,7 @@ pub enum Def { DefMod(ast::DefId), DefForeignMod(ast::DefId), DefStatic(ast::DefId, bool /* is_mutbl */), + DefConst(ast::DefId), DefLocal(ast::NodeId), DefVariant(ast::DefId /* enum */, ast::DefId /* variant */, bool /* is_structure */), DefTy(ast::DefId, bool /* is_enum */), @@ -61,7 +62,7 @@ impl Def { DefForeignMod(id) | DefStatic(id, _) | DefVariant(_, id, _) | DefTy(id, _) | DefAssociatedTy(id) | DefTyParam(_, id, _) | DefUse(id) | DefStruct(id) | DefTrait(id) | - DefMethod(id, _) => { + DefMethod(id, _) | DefConst(id) => { id } DefLocal(id) | diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index 51cdbfcf2514c..6cfdac93efc8a 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -267,7 +267,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,TYPER> { } } - fn consume_expr(&mut self, expr: &ast::Expr) { + pub fn consume_expr(&mut self, expr: &ast::Expr) { debug!("consume_expr(expr={})", expr.repr(self.tcx())); let cmt = return_if_err!(self.mc.cat_expr(expr)); diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 9a0885ca30135..fa494b357c19d 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -544,7 +544,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { match def { def::DefStruct(..) | def::DefVariant(..) | def::DefFn(..) | - def::DefStaticMethod(..) => { + def::DefStaticMethod(..) | def::DefConst(..) => { Ok(self.cat_rvalue_node(id, span, expr_ty)) } def::DefMod(_) | def::DefForeignMod(_) | def::DefUse(_) | @@ -1104,7 +1104,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { |x,y,z| op(x,y,z))); } } - Some(&def::DefStatic(..)) => { + Some(&def::DefConst(..)) => { for subpat in subpats.iter() { if_ok!(self.cat_pattern(cmt.clone(), &**subpat, |x,y,z| op(x,y,z))); } diff --git a/src/librustc/middle/pat_util.rs b/src/librustc/middle/pat_util.rs index e3806f02ed4c8..4d61baca70874 100644 --- a/src/librustc/middle/pat_util.rs +++ b/src/librustc/middle/pat_util.rs @@ -46,7 +46,7 @@ pub fn pat_is_const(dm: &resolve::DefMap, pat: &Pat) -> bool { match pat.node { PatIdent(_, _, None) | PatEnum(..) => { match dm.borrow().find(&pat.id) { - Some(&DefStatic(_, false)) => true, + Some(&DefConst(..)) => true, _ => false } } diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs index 7e415d1f5c1a7..e434d859993c0 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -805,6 +805,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> { def::DefStaticMethod(..) => ck("static method"), def::DefFn(..) => ck("function"), def::DefStatic(..) => ck("static"), + def::DefConst(..) => ck("const"), def::DefVariant(..) => ck("variant"), def::DefTy(_, false) => ck("type"), def::DefTy(_, true) => ck("enum"), @@ -1181,7 +1182,7 @@ impl<'a, 'tcx> SanePrivacyVisitor<'a, 'tcx> { } } - ast::ItemStatic(..) | ast::ItemStruct(..) | + ast::ItemConst(..) | ast::ItemStatic(..) | ast::ItemStruct(..) | ast::ItemFn(..) | ast::ItemMod(..) | ast::ItemTy(..) | ast::ItemMac(..) => {} } @@ -1245,7 +1246,7 @@ impl<'a, 'tcx> SanePrivacyVisitor<'a, 'tcx> { } } - ast::ItemStatic(..) | + ast::ItemStatic(..) | ast::ItemConst(..) | ast::ItemFn(..) | ast::ItemMod(..) | ast::ItemTy(..) | ast::ItemMac(..) => {} } diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index 555a033a568d1..5d6f7048b82e1 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -27,7 +27,6 @@ use syntax::abi; use syntax::ast; use syntax::ast_map; use syntax::ast_util::{is_local, PostExpansionMethod}; -use syntax::ast_util; use syntax::attr::{InlineAlways, InlineHint, InlineNever, InlineNone}; use syntax::attr; use syntax::visit::Visitor; @@ -121,15 +120,14 @@ impl<'a, 'tcx, 'v> Visitor<'v> for ReachableContext<'a, 'tcx> { self.worklist.push(def_id.node) } else { match def { - // If this path leads to a static, then we may have - // to do some work to figure out whether the static - // is indeed reachable. (Inlineable statics are - // never reachable.) - def::DefStatic(..) => { + // If this path leads to a constant, then we need to + // recurse into the constant to continue finding + // items that are reachable. + def::DefConst(..) => { self.worklist.push(def_id.node); } - // If this wasn't a static, then this destination is + // If this wasn't a static, then the destination is // surely reachable. _ => { self.reachable_symbols.insert(def_id.node); @@ -238,15 +236,14 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { fn propagate(&mut self) { let mut scanned = HashSet::new(); loop { - if self.worklist.len() == 0 { - break - } - let search_item = self.worklist.pop().unwrap(); - if scanned.contains(&search_item) { + let search_item = match self.worklist.pop() { + Some(item) => item, + None => break, + }; + if !scanned.insert(search_item) { continue } - scanned.insert(search_item); match self.tcx.map.find(search_item) { Some(ref item) => self.propagate_node(item, search_item), None if search_item == ast::CRATE_NODE_ID => {} @@ -297,21 +294,17 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { } } - // Statics with insignificant addresses are not reachable - // because they're inlined specially into all other crates. - ast::ItemStatic(_, mutbl, ref init) => { - if !ast_util::static_has_significant_address( - mutbl, - item.attrs.as_slice()) { - self.reachable_symbols.remove(&search_item); - } - visit::walk_expr(self, &**init); + // Reachable constants will be inlined into other crates + // unconditionally, so we need to make sure that their + // contents are also reachable. + ast::ItemConst(_, ref init) => { + self.visit_expr(&**init); } // These are normal, nothing reachable about these // inherently and their children are already in the // worklist, as determined by the privacy pass - ast::ItemTy(..) | + ast::ItemTy(..) | ast::ItemStatic(_, _, _) | ast::ItemMod(..) | ast::ItemForeignMod(..) | ast::ItemImpl(..) | ast::ItemTrait(..) | ast::ItemStruct(..) | ast::ItemEnum(..) => {} diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 595739585a398..318bc05d05f88 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -29,7 +29,7 @@ use syntax::ast::{ExprPath, ExprProc, ExprStruct, ExprUnboxedFn, FnDecl}; use syntax::ast::{ForeignItem, ForeignItemFn, ForeignItemStatic, Generics}; use syntax::ast::{Ident, ImplItem, Item, ItemEnum, ItemFn, ItemForeignMod}; use syntax::ast::{ItemImpl, ItemMac, ItemMod, ItemStatic, ItemStruct}; -use syntax::ast::{ItemTrait, ItemTy, LOCAL_CRATE, Local}; +use syntax::ast::{ItemTrait, ItemTy, LOCAL_CRATE, Local, ItemConst}; use syntax::ast::{MethodImplItem, Mod, Name, NamedField, NodeId}; use syntax::ast::{Pat, PatEnum, PatIdent, PatLit}; use syntax::ast::{PatRange, PatStruct, Path, PathListIdent, PathListMod}; @@ -1243,6 +1243,12 @@ impl<'a> Resolver<'a> { (DefStatic(local_def(item.id), mutbl), sp, is_public); parent } + ItemConst(_, _) => { + self.add_child(ident, parent.clone(), ForbidDuplicateValues, sp) + .define_value(DefConst(local_def(item.id)), + sp, is_public); + parent + } ItemFn(_, fn_style, _, _, _) => { let name_bindings = self.add_child(ident, parent.clone(), ForbidDuplicateValues, sp); @@ -1829,7 +1835,7 @@ impl<'a> Resolver<'a> { csearch::get_tuple_struct_definition_if_ctor(&self.session.cstore, ctor_id) .map_or(def, |_| DefStruct(ctor_id)), DUMMY_SP, is_public); } - DefFn(..) | DefStaticMethod(..) | DefStatic(..) => { + DefFn(..) | DefStaticMethod(..) | DefStatic(..) | DefConst(..) => { debug!("(building reduced graph for external \ crate) building value (fn/static) {}", final_ident); child_name_bindings.define_value(def, DUMMY_SP, is_public); @@ -4216,7 +4222,7 @@ impl<'a> Resolver<'a> { &**block); } - ItemStatic(..) => { + ItemConst(..) | ItemStatic(..) => { self.with_constant_rib(|this| { visit::walk_item(this, item); }); @@ -5084,6 +5090,7 @@ impl<'a> Resolver<'a> { Some(def @ (DefFn(..), _)) | Some(def @ (DefVariant(..), _)) | Some(def @ (DefStruct(..), _)) | + Some(def @ (DefConst(..), _)) | Some(def @ (DefStatic(..), _)) => { self.record_def(pattern.id, def); } @@ -5171,12 +5178,14 @@ impl<'a> Resolver<'a> { def @ DefVariant(..) | def @ DefStruct(..) => { return FoundStructOrEnumVariant(def, LastMod(AllPublic)); } - def @ DefStatic(_, false) => { + def @ DefConst(..) => { return FoundConst(def, LastMod(AllPublic)); } - DefStatic(_, true) => { + DefStatic(..) => { self.resolve_error(span, - "mutable static variables cannot be referenced in a pattern"); + "static variables cannot be \ + referenced in a pattern, \ + use a `const` instead"); return BareIdentifierPatternUnresolved; } _ => { diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 42ae877122490..6d84b8cb49dd2 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -92,7 +92,7 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> { ast::ItemMod(..) | ast::ItemMac(..) | ast::ItemForeignMod(..) | - ast::ItemStatic(..) => { + ast::ItemStatic(..) | ast::ItemConst(..) => { self.with(|_, f| f(RootScope), |v| visit::walk_item(v, item)); return; } diff --git a/src/librustc/middle/save/mod.rs b/src/librustc/middle/save/mod.rs index debcfe3933c03..4aba29d7bae16 100644 --- a/src/librustc/middle/save/mod.rs +++ b/src/librustc/middle/save/mod.rs @@ -230,6 +230,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { def::DefAssociatedTy(..) | def::DefTrait(_) => Some(recorder::TypeRef), def::DefStatic(_, _) | + def::DefConst(_) | def::DefLocal(_) | def::DefVariant(_, _, _) | def::DefUpvar(..) => Some(recorder::VarRef), @@ -521,6 +522,29 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { self.visit_expr(expr); } + fn process_const(&mut self, + item: &ast::Item, + typ: &ast::Ty, + expr: &ast::Expr) + { + let qualname = self.analysis.ty_cx.map.path_to_string(item.id); + + let sub_span = self.span.sub_span_after_keyword(item.span, + keywords::Const); + self.fmt.static_str(item.span, + sub_span, + item.id, + get_ident(item.ident).get(), + qualname.as_slice(), + "", + ty_to_string(&*typ).as_slice(), + self.cur_scope); + + // walk type and init value + self.visit_ty(&*typ); + self.visit_expr(expr); + } + fn process_struct(&mut self, item: &ast::Item, def: &ast::StructDef, @@ -740,6 +764,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { def::DefUpvar(..) | def::DefLocal(..) | def::DefStatic(..) | + def::DefConst(..) | def::DefVariant(..) => self.fmt.ref_str(recorder::VarRef, ex.span, sub_span, @@ -807,6 +832,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { }, def::DefLocal(_) | def::DefStatic(_,_) | + def::DefConst(..) | def::DefStruct(_) | def::DefFn(..) => self.write_sub_paths_truncated(path), _ => {}, @@ -1008,6 +1034,8 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> { self.process_fn(item, &**decl, ty_params, &**body), ast::ItemStatic(ref typ, mt, ref expr) => self.process_static(item, &**typ, mt, &**expr), + ast::ItemConst(ref typ, ref expr) => + self.process_const(item, &**typ, &**expr), ast::ItemStruct(ref def, ref ty_params) => self.process_struct(item, &**def, ty_params), ast::ItemEnum(ref def, ref ty_params) => self.process_enum(item, def, ty_params), ast::ItemImpl(ref ty_params, @@ -1386,6 +1414,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> { self.cur_scope), // FIXME(nrc) what is this doing here? def::DefStatic(_, _) => {} + def::DefConst(..) => {} _ => error!("unexpected definition kind when processing collected paths: {:?}", *def) } diff --git a/src/librustc/middle/traexpr b/src/librustc/middle/traexpr new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index 38f09d1957252..9eb02717f04a1 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -271,14 +271,14 @@ impl<'a> Opt<'a> { match *self { ConstantValue(ConstantExpr(lit_expr)) => { let lit_ty = ty::node_id_to_type(bcx.tcx(), lit_expr.id); - let (llval, _, _) = consts::const_expr(ccx, &*lit_expr, true); + let (llval, _) = consts::const_expr(ccx, &*lit_expr); let lit_datum = immediate_rvalue(llval, lit_ty); let lit_datum = unpack_datum!(bcx, lit_datum.to_appropriate_datum(bcx)); SingleResult(Result::new(bcx, lit_datum.val)) } ConstantRange(ConstantExpr(ref l1), ConstantExpr(ref l2)) => { - let (l1, _, _) = consts::const_expr(ccx, &**l1, true); - let (l2, _, _) = consts::const_expr(ccx, &**l2, true); + let (l1, _) = consts::const_expr(ccx, &**l1); + let (l2, _) = consts::const_expr(ccx, &**l2); RangeResult(Result::new(bcx, l1), Result::new(bcx, l2)) } Variant(disr_val, ref repr, _) => { @@ -350,7 +350,20 @@ struct ArmData<'p, 'blk, 'tcx: 'blk> { struct Match<'a, 'p: 'a, 'blk: 'a, 'tcx: 'blk> { pats: Vec<&'p ast::Pat>, data: &'a ArmData<'p, 'blk, 'tcx>, - bound_ptrs: Vec<(Ident, ValueRef)> + bound_ptrs: Vec<(Ident, ValueRef)>, + + // This is a pointer to an instance of check_match::DUMMY_WILD_PAT. The + // check_match code requires that we pass this in (with the same lifetime as + // the patterns passed in). Unfortunately this is required to be propagated + // into this structure in order to get the lifetimes to work. + // + // Lots of the `check_match` code will deal with &DUMMY_WILD_PAT when + // returning references, which used to have the `'static` lifetime before + // const was added to the language. The DUMMY_WILD_PAT does not implement + // Sync, however, so it must be a const, which longer has a static lifetime, + // hence we're passing it in here. This certainly isn't crucial, and if it + // can be removed, please do! + dummy: &'p ast::Pat, } impl<'a, 'p, 'blk, 'tcx> Repr for Match<'a, 'p, 'blk, 'tcx> { @@ -403,21 +416,22 @@ fn expand_nested_bindings<'a, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>, *pats.get_mut(col) = pat; Match { pats: pats, + dummy: br.dummy, data: &*br.data, bound_ptrs: bound_ptrs } }).collect() } -type EnterPatterns<'a> = <'p> |&[&'p ast::Pat]|: 'a -> Option>; +type EnterPatterns<'a, 'p> = |&[&'p ast::Pat]|: 'a -> Option>; -fn enter_match<'a, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>, - dm: &DefMap, - m: &[Match<'a, 'p, 'blk, 'tcx>], - col: uint, - val: ValueRef, - e: EnterPatterns) - -> Vec> { +fn enter_match<'a, 'b, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + dm: &DefMap, + m: &[Match<'a, 'p, 'blk, 'tcx>], + col: uint, + val: ValueRef, + e: EnterPatterns<'b, 'p>) + -> Vec> { debug!("enter_match(bcx={}, m={}, col={}, val={})", bcx.to_str(), m.repr(bcx.tcx()), @@ -450,6 +464,7 @@ fn enter_match<'a, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>, } Match { pats: pats, + dummy: br.dummy, data: br.data, bound_ptrs: bound_ptrs } @@ -544,7 +559,8 @@ fn enter_opt<'a, 'p, 'blk, 'tcx>( let mcx = check_match::MatchCheckCtxt { tcx: bcx.tcx() }; enter_match(bcx, dm, m, col, val, |pats| - check_match::specialize(&mcx, pats.as_slice(), &ctor, col, variant_size) + check_match::specialize(&mcx, pats.as_slice(), m[0].dummy, &ctor, col, + variant_size) ) } @@ -1025,7 +1041,9 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, match adt_vals { Some(field_vals) => { let pats = enter_match(bcx, dm, m, col, val, |pats| - check_match::specialize(&mcx, pats, &check_match::Single, col, field_vals.len()) + check_match::specialize(&mcx, pats, m[0].dummy, + &check_match::Single, col, + field_vals.len()) ); let vals = field_vals.append(vals_left.as_slice()); compile_submatch(bcx, pats.as_slice(), vals.as_slice(), chk, has_genuine_default); @@ -1347,6 +1365,7 @@ fn trans_match_inner<'blk, 'tcx>(scope_cx: Block<'blk, 'tcx>, bindings_map: create_bindings_map(bcx, &**arm.pats.get(0), discr_expr, &*arm.body) }).collect(); + let dummy = check_match::DUMMY_WILD_PAT.clone(); let mut static_inliner = StaticInliner::new(scope_cx.tcx()); let arm_pats: Vec>> = arm_datas.iter().map(|arm_data| { arm_data.arm.pats.iter().map(|p| static_inliner.fold_pat((*p).clone())).collect() @@ -1355,6 +1374,7 @@ fn trans_match_inner<'blk, 'tcx>(scope_cx: Block<'blk, 'tcx>, for (arm_data, pats) in arm_datas.iter().zip(arm_pats.iter()) { matches.extend(pats.iter().map(|p| Match { pats: vec![&**p], + dummy: &dummy, data: arm_data, bound_ptrs: Vec::new(), })); diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index d175919fb8108..8df5b375a8167 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -32,7 +32,7 @@ use driver::config::{NoDebugInfo, FullDebugInfo}; use driver::driver::{CrateAnalysis, CrateTranslation, ModuleTranslation}; use driver::session::Session; use lint; -use llvm::{BasicBlockRef, ModuleRef, ValueRef, Vector, get_param}; +use llvm::{BasicBlockRef, ValueRef, Vector, get_param}; use llvm; use metadata::{csearch, encoder, loader}; use middle::astencode; @@ -89,7 +89,7 @@ use std::rc::Rc; use std::{i8, i16, i32, i64}; use syntax::abi::{X86, X86_64, Arm, Mips, Mipsel, Rust, RustCall}; use syntax::abi::{RustIntrinsic, Abi, OsWindows}; -use syntax::ast_util::{local_def, is_local}; +use syntax::ast_util::local_def; use syntax::attr::AttrMetaMethods; use syntax::attr; use syntax::codemap::Span; @@ -317,17 +317,31 @@ pub fn decl_internal_rust_fn(ccx: &CrateContext, fn_ty: ty::t, name: &str) -> Va llfn } -pub fn get_extern_const(externs: &mut ExternMap, llmod: ModuleRef, - name: &str, ty: Type) -> ValueRef { - match externs.find_equiv(&name) { +pub fn get_extern_const(ccx: &CrateContext, did: ast::DefId, + t: ty::t) -> ValueRef { + let name = csearch::get_symbol(&ccx.sess().cstore, did); + let ty = type_of(ccx, t); + match ccx.externs().borrow_mut().find(&name) { Some(n) => return *n, None => () } unsafe { let c = name.with_c_str(|buf| { - llvm::LLVMAddGlobal(llmod, ty.to_ref(), buf) + llvm::LLVMAddGlobal(ccx.llmod(), ty.to_ref(), buf) }); - externs.insert(name.to_string(), c); + // Thread-local statics in some other crate need to *always* be linked + // against in a thread-local fashion, so we need to be sure to apply the + // thread-local attribute locally if it was present remotely. If we + // don't do this then linker errors can be generated where the linker + // complains that one object files has a thread local version of the + // symbol and another one doesn't. + ty::each_attr(ccx.tcx(), did, |attr| { + if attr.check_name("thread_local") { + llvm::set_thread_local(c, true); + } + true + }); + ccx.externs().borrow_mut().insert(name.to_string(), c); return c; } } @@ -935,11 +949,7 @@ pub fn trans_external_path(ccx: &CrateContext, did: ast::DefId, t: ty::t) -> Val get_extern_rust_fn(ccx, t, name.as_slice(), did) } _ => { - let llty = type_of(ccx, t); - get_extern_const(&mut *ccx.externs().borrow_mut(), - ccx.llmod(), - name.as_slice(), - llty) + get_extern_const(ccx, did, t) } } } @@ -2228,21 +2238,19 @@ pub fn trans_item(ccx: &CrateContext, item: &ast::Item) { ast::ItemEnum(ref enum_definition, _) => { enum_variant_size_lint(ccx, enum_definition, item.span, item.id); } + ast::ItemConst(_, ref expr) => { + // Recurse on the expression to catch items in blocks + let mut v = TransItemVisitor{ ccx: ccx }; + v.visit_expr(&**expr); + } ast::ItemStatic(_, m, ref expr) => { // Recurse on the expression to catch items in blocks let mut v = TransItemVisitor{ ccx: ccx }; v.visit_expr(&**expr); - let trans_everywhere = attr::requests_inline(item.attrs.as_slice()); - for (ref ccx, is_origin) in ccx.maybe_iter(!from_external && trans_everywhere) { - consts::trans_const(ccx, m, item.id); - - let g = get_item_val(ccx, item.id); - update_linkage(ccx, - g, - Some(item.id), - if is_origin { OriginalTranslation } else { InlinedCopy }); - } + consts::trans_static(ccx, m, item.id); + let g = get_item_val(ccx, item.id); + update_linkage(ccx, g, Some(item.id), OriginalTranslation); // Do static_assert checking. It can't really be done much earlier // because we need to get the value of the bool out of LLVM @@ -2253,7 +2261,7 @@ pub fn trans_item(ccx: &CrateContext, item: &ast::Item) { static"); } - let v = ccx.const_values().borrow().get_copy(&item.id); + let v = ccx.static_values().borrow().get_copy(&item.id); unsafe { if !(llvm::LLVMConstIntGetZExtValue(v) != 0) { ccx.sess().span_fatal(expr.span, "static assertion failed"); @@ -2667,23 +2675,21 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef { let val = match item { ast_map::NodeItem(i) => { let ty = ty::node_id_to_type(ccx.tcx(), i.id); - let sym = exported_name(ccx, id, ty, i.attrs.as_slice()); + let sym = || exported_name(ccx, id, ty, i.attrs.as_slice()); let v = match i.node { - ast::ItemStatic(_, mutbl, ref expr) => { + ast::ItemStatic(_, _, ref expr) => { // If this static came from an external crate, then // we need to get the symbol from csearch instead of // using the current crate's name/version // information in the hash of the symbol + let sym = sym(); debug!("making {}", sym); - let is_local = !ccx.external_srcs().borrow().contains_key(&id); // We need the translated value here, because for enums the // LLVM type is not fully determined by the Rust type. - let (v, inlineable, ty) = consts::const_expr(ccx, &**expr, is_local); - ccx.const_values().borrow_mut().insert(id, v); - let mut inlineable = inlineable; - + let (v, ty) = consts::const_expr(ccx, &**expr); + ccx.static_values().borrow_mut().insert(id, v); unsafe { // boolean SSA values are i1, but they have to be stored in i8 slots, // otherwise some LLVM optimization passes don't work as expected @@ -2694,55 +2700,30 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef { }; if contains_null(sym.as_slice()) { ccx.sess().fatal( - format!("Illegal null byte in export_name value: `{}`", - sym).as_slice()); + format!("Illegal null byte in export_name \ + value: `{}`", sym).as_slice()); } let g = sym.as_slice().with_c_str(|buf| { llvm::LLVMAddGlobal(ccx.llmod(), llty, buf) }); - // Apply the `unnamed_addr` attribute if - // requested - if !ast_util::static_has_significant_address( - mutbl, - i.attrs.as_slice()) { - llvm::SetUnnamedAddr(g, true); - - // This is a curious case where we must make - // all of these statics inlineable. If a - // global is not tagged as `#[inline(never)]`, - // then LLVM won't coalesce globals unless they - // have an internal linkage type. This means that - // external crates cannot use this global. - // This is a problem for things like inner - // statics in generic functions, because the - // function will be inlined into another - // crate and then attempt to link to the - // static in the original crate, only to - // find that it's not there. On the other - // side of inlining, the crates knows to - // not declare this static as - // available_externally (because it isn't) - inlineable = true; - } - if attr::contains_name(i.attrs.as_slice(), "thread_local") { llvm::set_thread_local(g, true); } - - if !inlineable { - debug!("{} not inlined", sym); - ccx.non_inlineable_statics().borrow_mut() - .insert(id); - } - ccx.item_symbols().borrow_mut().insert(i.id, sym); g } } + ast::ItemConst(_, ref expr) => { + let (v, _) = consts::const_expr(ccx, &**expr); + ccx.const_values().borrow_mut().insert(id, v); + v + } + ast::ItemFn(_, _, abi, _, _) => { + let sym = sym(); let llfn = if abi == Rust { register_fn(ccx, i.span, sym, i.id, ty) } else { @@ -2911,7 +2892,6 @@ pub fn crate_ctxt_to_encode_parms<'a, 'tcx>(cx: &'a SharedCrateContext<'tcx>, tcx: cx.tcx(), reexports2: cx.exp_map2(), item_symbols: cx.item_symbols(), - non_inlineable_statics: cx.non_inlineable_statics(), link_meta: cx.link_meta(), cstore: &cx.sess().cstore, encode_inlined_item: ie, diff --git a/src/librustc/middle/trans/callee.rs b/src/librustc/middle/trans/callee.rs index 7942a0211e4e6..bc562b39c98f7 100644 --- a/src/librustc/middle/trans/callee.rs +++ b/src/librustc/middle/trans/callee.rs @@ -196,6 +196,7 @@ fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr) } } def::DefStatic(..) | + def::DefConst(..) | def::DefLocal(..) | def::DefUpvar(..) => { datum_callee(bcx, ref_expr) diff --git a/src/librustc/middle/trans/consts.rs b/src/librustc/middle/trans/consts.rs index 5e4692bd0f617..ec357f7bfd7c6 100644 --- a/src/librustc/middle/trans/consts.rs +++ b/src/librustc/middle/trans/consts.rs @@ -33,7 +33,6 @@ use middle::ty; use util::ppaux::{Repr, ty_to_string}; use std::c_str::ToCStr; -use std::vec; use libc::c_uint; use syntax::{ast, ast_util}; use syntax::ptr::P; @@ -96,24 +95,20 @@ pub fn const_ptrcast(cx: &CrateContext, a: ValueRef, t: Type) -> ValueRef { } } -// Helper function because we don't have tuple-swizzling. -fn first_two((a, b, _): (R, S, T)) -> (R, S) { - (a, b) -} - fn const_vec(cx: &CrateContext, e: &ast::Expr, - es: &[P], is_local: bool) -> (ValueRef, Type, bool) { + es: &[P]) -> (ValueRef, Type) { let vec_ty = ty::expr_ty(cx.tcx(), e); let unit_ty = ty::sequence_element_type(cx.tcx(), vec_ty); let llunitty = type_of::type_of(cx, unit_ty); - let (vs, inlineable) = vec::unzip(es.iter().map(|e| first_two(const_expr(cx, &**e, is_local)))); + let vs = es.iter().map(|e| const_expr(cx, &**e).val0()) + .collect::>(); // If the vector contains enums, an LLVM array won't work. let v = if vs.iter().any(|vi| val_ty(*vi) != llunitty) { C_struct(cx, vs.as_slice(), false) } else { C_array(llunitty, vs.as_slice()) }; - (v, llunitty, inlineable.iter().fold(true, |a, &b| a && b)) + (v, llunitty) } pub fn const_addr_of(cx: &CrateContext, cv: ValueRef, mutbl: ast::Mutability) -> ValueRef { @@ -177,7 +172,7 @@ fn const_deref(cx: &CrateContext, v: ValueRef, t: ty::t, explicit: bool) } pub fn get_const_val(cx: &CrateContext, - mut def_id: ast::DefId) -> (ValueRef, bool) { + mut def_id: ast::DefId) -> ValueRef { let contains_key = cx.const_values().borrow().contains_key(&def_id.node); if !ast_util::is_local(def_id) || !contains_key { if !ast_util::is_local(def_id) { @@ -185,21 +180,17 @@ pub fn get_const_val(cx: &CrateContext, } match cx.tcx().map.expect_item(def_id.node).node { - ast::ItemStatic(_, ast::MutImmutable, _) => { - trans_const(cx, ast::MutImmutable, def_id.node); - } + ast::ItemConst(..) => { base::get_item_val(cx, def_id.node); } _ => {} } } - (cx.const_values().borrow().get_copy(&def_id.node), - !cx.non_inlineable_statics().borrow().contains(&def_id.node)) + cx.const_values().borrow().get_copy(&def_id.node) } -pub fn const_expr(cx: &CrateContext, e: &ast::Expr, is_local: bool) -> (ValueRef, bool, ty::t) { - let (llconst, inlineable) = const_expr_unadjusted(cx, e, is_local); +pub fn const_expr(cx: &CrateContext, e: &ast::Expr) -> (ValueRef, ty::t) { + let llconst = const_expr_unadjusted(cx, e); let mut llconst = llconst; - let mut inlineable = inlineable; let ety = ty::expr_ty(cx.tcx(), e); let mut ety_adjusted = ty::expr_ty_adjusted(cx.tcx(), e); let opt_adj = cx.tcx().adjustments.borrow().find_copy(&e.id); @@ -213,7 +204,7 @@ pub fn const_expr(cx: &CrateContext, e: &ast::Expr, is_local: bool) -> (ValueRef ety_adjusted, def, llconst, - is_local); + true); llconst = C_struct(cx, [wrapper, C_null(Type::i8p(cx))], false) } ty::AdjustAddEnv(store) => { @@ -250,7 +241,6 @@ pub fn const_expr(cx: &CrateContext, e: &ast::Expr, is_local: bool) -> (ValueRef // Don't copy data to do a deref+ref // (i.e., skip the last auto-deref). if adj.autoderefs == 0 { - inlineable = false; llconst = const_addr_of(cx, llconst, ast::MutImmutable); } } @@ -271,7 +261,6 @@ pub fn const_expr(cx: &CrateContext, e: &ast::Expr, is_local: bool) -> (ValueRef match ty::get(ty).sty { ty::ty_vec(unit_ty, Some(len)) => { - inlineable = false; let llunitty = type_of::type_of(cx, unit_ty); let llptr = const_ptrcast(cx, llconst, llunitty); assert_eq!(abi::slice_elt_base, 0); @@ -314,29 +303,25 @@ pub fn const_expr(cx: &CrateContext, e: &ast::Expr, is_local: bool) -> (ValueRef e.repr(cx.tcx()), ty_to_string(cx.tcx(), ety), csize, tsize).as_slice()); } - (llconst, inlineable, ety_adjusted) + (llconst, ety_adjusted) } // the bool returned is whether this expression can be inlined into other crates // if it's assigned to a static. -fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr, - is_local: bool) -> (ValueRef, bool) { +fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr) -> ValueRef { let map_list = |exprs: &[P]| { - exprs.iter().map(|e| first_two(const_expr(cx, &**e, is_local))) - .fold((Vec::new(), true), - |(l, all_inlineable), (val, inlineable)| { - (l.append_one(val), all_inlineable && inlineable) - }) + exprs.iter().map(|e| const_expr(cx, &**e).val0()) + .fold(Vec::new(), |l, val| l.append_one(val)) }; unsafe { let _icx = push_ctxt("const_expr"); return match e.node { ast::ExprLit(ref lit) => { - (consts::const_lit(cx, e, &**lit), true) + consts::const_lit(cx, e, &**lit) } ast::ExprBinary(b, ref e1, ref e2) => { - let (te1, _, _) = const_expr(cx, &**e1, is_local); - let (te2, _, _) = const_expr(cx, &**e2, is_local); + let (te1, _) = const_expr(cx, &**e1); + let (te2, _) = const_expr(cx, &**e2); let te2 = base::cast_shift_const_rhs(b, te1, te2); @@ -345,7 +330,7 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr, let ty = ty::expr_ty(cx.tcx(), &**e1); let is_float = ty::type_is_fp(ty); let signed = ty::type_is_signed(ty); - return (match b { + return match b { ast::BiAdd => { if is_float { llvm::LLVMConstFAdd(te1, te2) } else { llvm::LLVMConstAdd(te1, te2) } @@ -414,13 +399,13 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr, else { ConstICmp(IntUGT, te1, te2) } } }, - }, true) + } }, ast::ExprUnary(u, ref e) => { - let (te, _, _) = const_expr(cx, &**e, is_local); + let (te, _) = const_expr(cx, &**e); let ty = ty::expr_ty(cx.tcx(), &**e); let is_float = ty::type_is_fp(ty); - return (match u { + return match u { ast::UnUniq | ast::UnDeref => { let (dv, _dt) = const_deref(cx, te, ty, true); dv @@ -430,26 +415,26 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr, if is_float { llvm::LLVMConstFNeg(te) } else { llvm::LLVMConstNeg(te) } } - }, true) + } } ast::ExprField(ref base, field, _) => { - let (bv, inlineable, bt) = const_expr(cx, &**base, is_local); + let (bv, bt) = const_expr(cx, &**base); let brepr = adt::represent_type(cx, bt); expr::with_field_tys(cx.tcx(), bt, None, |discr, field_tys| { let ix = ty::field_idx_strict(cx.tcx(), field.node.name, field_tys); - (adt::const_get_field(cx, &*brepr, bv, discr, ix), inlineable) + adt::const_get_field(cx, &*brepr, bv, discr, ix) }) } ast::ExprTupField(ref base, idx, _) => { - let (bv, inlineable, bt) = const_expr(cx, &**base, is_local); + let (bv, bt) = const_expr(cx, &**base); let brepr = adt::represent_type(cx, bt); expr::with_field_tys(cx.tcx(), bt, None, |discr, _| { - (adt::const_get_field(cx, &*brepr, bv, discr, idx.node), inlineable) + adt::const_get_field(cx, &*brepr, bv, discr, idx.node) }) } ast::ExprIndex(ref base, ref index) => { - let (bv, inlineable, bt) = const_expr(cx, &**base, is_local); + let (bv, bt) = const_expr(cx, &**base); let iv = match const_eval::eval_const_expr(cx.tcx(), &**index) { const_eval::const_int(i) => i as u64, const_eval::const_uint(u) => u, @@ -500,13 +485,13 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr, cx.sess().span_err(e.span, "const index-expr is out of bounds"); } - (const_get_elt(cx, arr, [iv as c_uint]), inlineable) + const_get_elt(cx, arr, [iv as c_uint]) } ast::ExprCast(ref base, _) => { let ety = ty::expr_ty(cx.tcx(), e); let llty = type_of::type_of(cx, ety); - let (v, inlineable, basety) = const_expr(cx, &**base, is_local); - return (match (expr::cast_type_kind(cx.tcx(), basety), + let (v, basety) = const_expr(cx, &**base); + return match (expr::cast_type_kind(cx.tcx(), basety), expr::cast_type_kind(cx.tcx(), ety)) { (expr::cast_integral, expr::cast_integral) => { @@ -554,17 +539,38 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr, cx.sess().impossible_case(e.span, "bad combination of types for cast") } - }, inlineable) + } } ast::ExprAddrOf(mutbl, ref sub) => { - let (e, _, _) = const_expr(cx, &**sub, is_local); - (const_addr_of(cx, e, mutbl), false) + // If this is the address of some static, then we need to return + // the actual address of the static itself (short circuit the rest + // of const eval). + let mut cur = sub; + loop { + match cur.node { + ast::ExprParen(ref sub) => cur = sub, + _ => break, + } + } + let opt_def = cx.tcx().def_map.borrow().find_copy(&cur.id); + match opt_def { + Some(def::DefStatic(def_id, _)) => { + let ty = ty::expr_ty(cx.tcx(), e); + return get_static_val(cx, def_id, ty); + } + _ => {} + } + + // If this isn't the address of a static, then keep going through + // normal constant evaluation. + let (e, _) = const_expr(cx, &**sub); + const_addr_of(cx, e, mutbl) } ast::ExprTup(ref es) => { let ety = ty::expr_ty(cx.tcx(), e); let repr = adt::represent_type(cx, ety); - let (vals, inlineable) = map_list(es.as_slice()); - (adt::trans_const(cx, &*repr, 0, vals.as_slice()), inlineable) + let vals = map_list(es.as_slice()); + adt::trans_const(cx, &*repr, 0, vals.as_slice()) } ast::ExprStruct(_, ref fs, ref base_opt) => { let ety = ty::expr_ty(cx.tcx(), e); @@ -572,36 +578,34 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr, let tcx = cx.tcx(); let base_val = match *base_opt { - Some(ref base) => Some(const_expr(cx, &**base, is_local)), + Some(ref base) => Some(const_expr(cx, &**base)), None => None }; expr::with_field_tys(tcx, ety, Some(e.id), |discr, field_tys| { - let (cs, inlineable) = vec::unzip(field_tys.iter().enumerate() - .map(|(ix, &field_ty)| { + let cs = field_tys.iter().enumerate() + .map(|(ix, &field_ty)| { match fs.iter().find(|f| field_ty.ident.name == f.ident.node.name) { - Some(ref f) => first_two(const_expr(cx, &*f.expr, is_local)), + Some(ref f) => const_expr(cx, &*f.expr).val0(), None => { match base_val { - Some((bv, inlineable, _)) => { - (adt::const_get_field(cx, &*repr, bv, discr, ix), - inlineable) - } - None => cx.sess().span_bug(e.span, "missing struct field") + Some((bv, _)) => { + adt::const_get_field(cx, &*repr, bv, + discr, ix) + } + None => { + cx.sess().span_bug(e.span, + "missing struct field") + } } } } - })); - (adt::trans_const(cx, &*repr, discr, cs.as_slice()), - inlineable.iter().fold(true, |a, &b| a && b)) + }).collect::>(); + adt::trans_const(cx, &*repr, discr, cs.as_slice()) }) } ast::ExprVec(ref es) => { - let (v, _, inlineable) = const_vec(cx, - e, - es.as_slice(), - is_local); - (v, inlineable) + const_vec(cx, e, es.as_slice()).val0() } ast::ExprRepeat(ref elem, ref count) => { let vec_ty = ty::expr_ty(cx.tcx(), e); @@ -612,13 +616,12 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr, const_eval::const_uint(i) => i as uint, _ => cx.sess().span_bug(count.span, "count must be integral const expression.") }; - let vs = Vec::from_elem(n, const_expr(cx, &**elem, is_local).val0()); - let v = if vs.iter().any(|vi| val_ty(*vi) != llunitty) { + let vs = Vec::from_elem(n, const_expr(cx, &**elem).val0()); + if vs.iter().any(|vi| val_ty(*vi) != llunitty) { C_struct(cx, vs.as_slice(), false) } else { C_array(llunitty, vs.as_slice()) - }; - (v, true) + } } ast::ExprPath(ref pth) => { // Assert that there are no type parameters in this path. @@ -629,13 +632,13 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr, Some(def::DefFn(def_id, _fn_style, _)) => { if !ast_util::is_local(def_id) { let ty = csearch::get_type(cx.tcx(), def_id).ty; - (base::trans_external_path(cx, def_id, ty), true) + base::trans_external_path(cx, def_id, ty) } else { assert!(ast_util::is_local(def_id)); - (base::get_item_val(cx, def_id.node), true) + base::get_item_val(cx, def_id.node) } } - Some(def::DefStatic(def_id, false)) => { + Some(def::DefConst(def_id)) => { get_const_val(cx, def_id) } Some(def::DefVariant(enum_did, variant_did, _)) => { @@ -644,15 +647,16 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr, let vinfo = ty::enum_variant_with_id(cx.tcx(), enum_did, variant_did); - (adt::trans_const(cx, &*repr, vinfo.disr_val, []), true) + adt::trans_const(cx, &*repr, vinfo.disr_val, []) } Some(def::DefStruct(_)) => { let ety = ty::expr_ty(cx.tcx(), e); let llty = type_of::type_of(cx, ety); - (C_null(llty), true) + C_null(llty) } _ => { - cx.sess().span_bug(e.span, "expected a const, fn, struct, or variant def") + cx.sess().span_bug(e.span, "expected a const, fn, struct, \ + or variant def") } } } @@ -662,9 +666,8 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr, Some(def::DefStruct(_)) => { let ety = ty::expr_ty(cx.tcx(), e); let repr = adt::represent_type(cx, ety); - let (arg_vals, inlineable) = map_list(args.as_slice()); - (adt::trans_const(cx, &*repr, 0, arg_vals.as_slice()), - inlineable) + let arg_vals = map_list(args.as_slice()); + adt::trans_const(cx, &*repr, 0, arg_vals.as_slice()) } Some(def::DefVariant(enum_did, variant_did, _)) => { let ety = ty::expr_ty(cx.tcx(), e); @@ -672,20 +675,20 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr, let vinfo = ty::enum_variant_with_id(cx.tcx(), enum_did, variant_did); - let (arg_vals, inlineable) = map_list(args.as_slice()); - (adt::trans_const(cx, - &*repr, - vinfo.disr_val, - arg_vals.as_slice()), inlineable) + let arg_vals = map_list(args.as_slice()); + adt::trans_const(cx, + &*repr, + vinfo.disr_val, + arg_vals.as_slice()) } _ => cx.sess().span_bug(e.span, "expected a struct or variant def") } } - ast::ExprParen(ref e) => first_two(const_expr(cx, &**e, is_local)), + ast::ExprParen(ref e) => const_expr(cx, &**e).val0(), ast::ExprBlock(ref block) => { match block.expr { - Some(ref expr) => first_two(const_expr(cx, &**expr, is_local)), - None => (C_nil(cx), true) + Some(ref expr) => const_expr(cx, &**expr).val0(), + None => C_nil(cx) } } _ => cx.sess().span_bug(e.span, @@ -694,13 +697,13 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr, } } -pub fn trans_const(ccx: &CrateContext, m: ast::Mutability, id: ast::NodeId) { +pub fn trans_static(ccx: &CrateContext, m: ast::Mutability, id: ast::NodeId) { unsafe { - let _icx = push_ctxt("trans_const"); + let _icx = push_ctxt("trans_static"); let g = base::get_item_val(ccx, id); // At this point, get_item_val has already translated the // constant's initializer to determine its LLVM type. - let v = ccx.const_values().borrow().get_copy(&id); + let v = ccx.static_values().borrow().get_copy(&id); // boolean SSA values are i1, but they have to be stored in i8 slots, // otherwise some LLVM optimization passes don't work as expected let v = if llvm::LLVMTypeOf(v) == Type::i1(ccx).to_ref() { @@ -710,17 +713,20 @@ pub fn trans_const(ccx: &CrateContext, m: ast::Mutability, id: ast::NodeId) { }; llvm::LLVMSetInitializer(g, v); - // `get_item_val` left `g` with external linkage, but we just set an - // initializer for it. But we don't know yet if `g` should really be - // defined in this compilation unit, so we set its linkage to - // `AvailableExternallyLinkage`. (It's still a definition, but acts - // like a declaration for most purposes.) If `g` really should be - // declared here, then `trans_item` will fix up the linkage later on. - llvm::SetLinkage(g, llvm::AvailableExternallyLinkage); - + // As an optimization, all shared statics which do not have interior + // mutability are placed into read-only memory. if m != ast::MutMutable { - llvm::LLVMSetGlobalConstant(g, True); + let node_ty = ty::node_id_to_type(ccx.tcx(), id); + let tcontents = ty::type_contents(ccx.tcx(), node_ty); + if !tcontents.interior_unsafe() { + llvm::LLVMSetGlobalConstant(g, True); + } } debuginfo::create_global_var_metadata(ccx, id, g); } } + +fn get_static_val(ccx: &CrateContext, did: ast::DefId, ty: ty::t) -> ValueRef { + if ast_util::is_local(did) { return base::get_item_val(ccx, did.node) } + base::trans_external_path(ccx, did, ty) +} diff --git a/src/librustc/middle/trans/context.rs b/src/librustc/middle/trans/context.rs index 5c8c6a24b4fa5..ee5ba61a295cf 100644 --- a/src/librustc/middle/trans/context.rs +++ b/src/librustc/middle/trans/context.rs @@ -66,10 +66,6 @@ pub struct SharedCrateContext<'tcx> { reachable: NodeSet, item_symbols: RefCell>, link_meta: LinkMeta, - /// A set of static items which cannot be inlined into other crates. This - /// will prevent in IIItem() structures from being encoded into the metadata - /// that is generated - non_inlineable_statics: RefCell, symbol_hasher: RefCell, tcx: ty::ctxt<'tcx>, stats: Stats, @@ -121,6 +117,9 @@ pub struct LocalCrateContext { /// Cache of emitted const values const_values: RefCell>, + /// Cache of emitted static values + static_values: RefCell>, + /// Cache of external const values extern_const_values: RefCell>, @@ -259,7 +258,6 @@ impl<'tcx> SharedCrateContext<'tcx> { reachable: reachable, item_symbols: RefCell::new(NodeMap::new()), link_meta: link_meta, - non_inlineable_statics: RefCell::new(NodeSet::new()), symbol_hasher: RefCell::new(symbol_hasher), tcx: tcx, stats: Stats { @@ -351,10 +349,6 @@ impl<'tcx> SharedCrateContext<'tcx> { &self.link_meta } - pub fn non_inlineable_statics<'a>(&'a self) -> &'a RefCell { - &self.non_inlineable_statics - } - pub fn symbol_hasher<'a>(&'a self) -> &'a RefCell { &self.symbol_hasher } @@ -414,6 +408,7 @@ impl LocalCrateContext { const_cstr_cache: RefCell::new(HashMap::new()), const_globals: RefCell::new(HashMap::new()), const_values: RefCell::new(NodeMap::new()), + static_values: RefCell::new(NodeMap::new()), extern_const_values: RefCell::new(DefIdMap::new()), impl_method_cache: RefCell::new(HashMap::new()), closure_bare_wrapper_cache: RefCell::new(HashMap::new()), @@ -610,10 +605,6 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> { &self.local.external_srcs } - pub fn non_inlineable_statics<'a>(&'a self) -> &'a RefCell { - &self.shared.non_inlineable_statics - } - pub fn monomorphized<'a>(&'a self) -> &'a RefCell> { &self.local.monomorphized } @@ -638,6 +629,10 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> { &self.local.const_values } + pub fn static_values<'a>(&'a self) -> &'a RefCell> { + &self.local.static_values + } + pub fn extern_const_values<'a>(&'a self) -> &'a RefCell> { &self.local.extern_const_values } diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs index a2b7cb159d9dc..ec92f935c49be 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -776,6 +776,7 @@ pub fn create_global_var_metadata(cx: &CrateContext, ast_map::NodeItem(item) => { match item.node { ast::ItemStatic(..) => (item.ident, item.span), + ast::ItemConst(..) => (item.ident, item.span), _ => { cx.sess() .span_bug(item.span, diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index cd4ad85d0942c..19c9c5e0119d2 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -36,7 +36,6 @@ use back::abi; use llvm; use llvm::{ValueRef}; -use metadata::csearch; use middle::def; use middle::mem_categorization::Typer; use middle::subst; @@ -839,25 +838,20 @@ fn trans_def<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, trans_def_fn_unadjusted(bcx, ref_expr, def) } def::DefStatic(did, _) => { - // There are three things that may happen here: + // There are two things that may happen here: // 1) If the static item is defined in this crate, it will be // translated using `get_item_val`, and we return a pointer to // the result. - // 2) If the static item is defined in another crate, but is - // marked inlineable, then it will be inlined into this crate - // and then translated with `get_item_val`. Again, we return a - // pointer to the result. - // 3) If the static item is defined in another crate and is not - // marked inlineable, then we add (or reuse) a declaration of - // an external global, and return a pointer to that. + // 2) If the static item is defined in another crate then we add + // (or reuse) a declaration of an external global, and return a + // pointer to that. let const_ty = expr_ty(bcx, ref_expr); - fn get_val<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, did: ast::DefId, const_ty: ty::t) - -> ValueRef { + fn get_val<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, did: ast::DefId, + const_ty: ty::t) -> ValueRef { // For external constants, we don't inline. if did.krate == ast::LOCAL_CRATE { - // Case 1 or 2. (The inlining in case 2 produces a new - // DefId in LOCAL_CRATE.) + // Case 1. // The LLVM global has the type of its initializer, // which may not be equal to the enum's type for @@ -866,36 +860,41 @@ fn trans_def<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, let pty = type_of::type_of(bcx.ccx(), const_ty).ptr_to(); PointerCast(bcx, val, pty) } else { - // Case 3. - match bcx.ccx().extern_const_values().borrow().find(&did) { - None => {} // Continue. - Some(llval) => { - return *llval; - } - } - - unsafe { - let llty = type_of::type_of(bcx.ccx(), const_ty); - let symbol = csearch::get_symbol( - &bcx.ccx().sess().cstore, - did); - let llval = symbol.as_slice().with_c_str(|buf| { - llvm::LLVMAddGlobal(bcx.ccx().llmod(), - llty.to_ref(), - buf) - }); - bcx.ccx().extern_const_values().borrow_mut() - .insert(did, llval); - llval - } + // Case 2. + base::get_extern_const(bcx.ccx(), did, const_ty) } } - // The DefId produced by `maybe_instantiate_inline` - // may be in the LOCAL_CRATE or not. - let did = inline::maybe_instantiate_inline(bcx.ccx(), did); let val = get_val(bcx, did, const_ty); DatumBlock::new(bcx, Datum::new(val, const_ty, LvalueExpr)) } + def::DefConst(did) => { + // First, inline any external constants into the local crate so we + // can be sure to get the LLVM value corresponding to it. + let did = inline::maybe_instantiate_inline(bcx.ccx(), did); + if did.krate != ast::LOCAL_CRATE { + bcx.tcx().sess.span_bug(ref_expr.span, + "cross crate constant could not \ + be inlined"); + } + let val = base::get_item_val(bcx.ccx(), did.node); + + // Next, we need to crate a ByRef rvalue datum to return. We can't + // use the normal .to_ref_datum() function because the type of + // `val` is not actually the same as `const_ty`. + // + // To get around this, we make a custom alloca slot with the + // appropriate type (const_ty), and then we cast it to a pointer of + // typeof(val), store the value, and then hand this slot over to + // the datum infrastructure. + let const_ty = expr_ty(bcx, ref_expr); + let llty = type_of::type_of(bcx.ccx(), const_ty); + let slot = alloca(bcx, llty, "const"); + let pty = Type::from_ref(unsafe { llvm::LLVMTypeOf(val) }).ptr_to(); + Store(bcx, val, PointerCast(bcx, slot, pty)); + + let datum = Datum::new(slot, const_ty, Rvalue::new(ByRef)); + DatumBlock::new(bcx, datum.to_expr_datum()) + } _ => { DatumBlock::new(bcx, trans_local_var(bcx, def).to_expr_datum()) } diff --git a/src/librustc/middle/trans/inline.rs b/src/librustc/middle/trans/inline.rs index e5c8d4d0ab343..048402782a6d9 100644 --- a/src/librustc/middle/trans/inline.rs +++ b/src/librustc/middle/trans/inline.rs @@ -17,7 +17,6 @@ use middle::ty; use syntax::ast; use syntax::ast_util::{local_def, PostExpansionMethod}; -use syntax::ast_util; fn instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId) -> Option { @@ -76,21 +75,7 @@ fn instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId) } } } - ast::ItemStatic(_, mutbl, _) => { - if !ast_util::static_has_significant_address(mutbl, item.attrs.as_slice()) { - // Inlined static items use internal linkage when - // possible, so that LLVM will coalesce globals with - // identical initializers. (It only does this for - // globals with unnamed_addr and either internal or - // private linkage.) - Some(InternalLinkage) - } else { - // The address is significant, so we can't create an - // internal copy of the static. (The copy would have a - // different address from the original.) - Some(AvailableExternallyLinkage) - } - } + ast::ItemConst(..) => None, _ => unreachable!(), }; diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 10bc1da3acb54..e1491c1f49be2 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -1374,6 +1374,7 @@ impl ParameterEnvironment { ast::ItemEnum(..) | ast::ItemStruct(..) | ast::ItemImpl(..) | + ast::ItemConst(..) | ast::ItemStatic(..) => { let def_id = ast_util::local_def(id); let pty = ty::lookup_item_type(cx, def_id); @@ -3576,6 +3577,8 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind { def::DefUpvar(..) | def::DefLocal(..) => LvalueExpr, + def::DefConst(..) => RvalueDatumExpr, + def => { tcx.sess.span_bug( expr.span, diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 4af71bfda8b35..68bb3fcf94544 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -677,7 +677,8 @@ pub fn check_item(ccx: &CrateCtxt, it: &ast::Item) { let _indenter = indenter(); match it.node { - ast::ItemStatic(_, _, ref e) => check_const(ccx, it.span, &**e, it.id), + ast::ItemStatic(_, _, ref e) | + ast::ItemConst(_, ref e) => check_const(ccx, it.span, &**e, it.id), ast::ItemEnum(ref enum_definition, _) => { check_enum_variants(ccx, it.span, @@ -5083,7 +5084,7 @@ pub fn polytype_for_def(fcx: &FnCtxt, } def::DefFn(id, _, _) | def::DefStaticMethod(id, _, _) | def::DefStatic(id, _) | def::DefVariant(_, id, _) | - def::DefStruct(id) => { + def::DefStruct(id) | def::DefConst(id) => { return ty::lookup_item_type(fcx.ccx.tcx, id); } def::DefTrait(_) | @@ -5211,6 +5212,7 @@ pub fn instantiate_path(fcx: &FnCtxt, // Case 2. Reference to a top-level value. def::DefFn(..) | + def::DefConst(..) | def::DefStatic(..) => { segment_spaces = Vec::from_elem(path.segments.len() - 1, None); segment_spaces.push(Some(subst::FnSpace)); diff --git a/src/librustc/middle/typeck/check/wf.rs b/src/librustc/middle/typeck/check/wf.rs index 587aa072fa863..4c3cec1aff42f 100644 --- a/src/librustc/middle/typeck/check/wf.rs +++ b/src/librustc/middle/typeck/check/wf.rs @@ -69,6 +69,9 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { ast::ItemStatic(..) => { self.check_item_type(item); } + ast::ItemConst(..) => { + self.check_item_type(item); + } ast::ItemStruct(ref struct_def, _) => { self.check_type_defn(item, |fcx| { vec![struct_variant(fcx, &**struct_def)] diff --git a/src/librustc/middle/typeck/collect.rs b/src/librustc/middle/typeck/collect.rs index 40c52fd36b9c1..0b5c86fea7123 100644 --- a/src/librustc/middle/typeck/collect.rs +++ b/src/librustc/middle/typeck/collect.rs @@ -1550,7 +1550,7 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::Item) _ => {} } match it.node { - ast::ItemStatic(ref t, _, _) => { + ast::ItemStatic(ref t, _, _) | ast::ItemConst(ref t, _) => { let typ = ccx.to_ty(&ExplicitRscope, &**t); let pty = no_params(typ); diff --git a/src/librustc/middle/typeck/infer/test.rs b/src/librustc/middle/typeck/infer/test.rs index 29cd2e77e8b1f..6ef2143b624f8 100644 --- a/src/librustc/middle/typeck/infer/test.rs +++ b/src/librustc/middle/typeck/infer/test.rs @@ -197,7 +197,7 @@ impl<'a, 'tcx> Env<'a, 'tcx> { } return match it.node { - ast::ItemStatic(..) | ast::ItemFn(..) | + ast::ItemConst(..) | ast::ItemStatic(..) | ast::ItemFn(..) | ast::ItemForeignMod(..) | ast::ItemTy(..) => { None } diff --git a/src/librustc/middle/typeck/variance.rs b/src/librustc/middle/typeck/variance.rs index 9317ba2c7fa93..60a7aa7790442 100644 --- a/src/librustc/middle/typeck/variance.rs +++ b/src/librustc/middle/typeck/variance.rs @@ -384,6 +384,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for TermsContext<'a, 'tcx> { ast::ItemImpl(..) | ast::ItemStatic(..) | + ast::ItemConst(..) | ast::ItemFn(..) | ast::ItemMod(..) | ast::ItemForeignMod(..) | @@ -528,6 +529,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for ConstraintContext<'a, 'tcx> { } ast::ItemStatic(..) | + ast::ItemConst(..) | ast::ItemFn(..) | ast::ItemMod(..) | ast::ItemForeignMod(..) | diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 0a87c0a344e52..c47d6b0fc9dc8 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1309,6 +1309,7 @@ pub struct Item { #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub enum Item_ { ItemStatic(P, Mutability, P), + ItemConst(P, P), ItemFn(P, FnStyle, Abi, Generics, P), ItemMod(Mod), ItemForeignMod(ForeignMod), diff --git a/src/libsyntax/ast_map/mod.rs b/src/libsyntax/ast_map/mod.rs index 257bfc632d882..2d0cea2fefc9d 100644 --- a/src/libsyntax/ast_map/mod.rs +++ b/src/libsyntax/ast_map/mod.rs @@ -1018,6 +1018,7 @@ fn node_id_to_string(map: &Map, id: NodeId) -> String { let path_str = map.path_to_str_with_ident(id, item.ident); let item_str = match item.node { ItemStatic(..) => "static", + ItemConst(..) => "const", ItemFn(..) => "fn", ItemMod(..) => "mod", ItemForeignMod(..) => "foreign mod", diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index f746e1f14822a..f51c2985f0bf4 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -12,8 +12,6 @@ use abi::Abi; use ast::*; use ast; use ast_util; -use attr::{InlineNever, InlineNone}; -use attr; use codemap; use codemap::Span; use owned_slice::OwnedSlice; @@ -706,18 +704,6 @@ pub fn lit_is_str(lit: &Lit) -> bool { } } -/// Returns true if the static with the given mutability and attributes -/// has a significant address and false otherwise. -pub fn static_has_significant_address(mutbl: ast::Mutability, - attrs: &[ast::Attribute]) - -> bool { - if mutbl == ast::MutMutable { - return true - } - let inline = attr::find_inline_attr(attrs); - inline == InlineNever || inline == InlineNone -} - /// Macro invocations are guaranteed not to occur after expansion is complete. /// Extracting fields of a method requires a dynamic check to make sure that it's /// not a macro invocation. This check is guaranteed to succeed, assuming diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 1fdb6dd505f45..87983e1aea3a9 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -250,6 +250,13 @@ pub trait AstBuilder { expr: P) -> P; + fn item_const(&self, + span: Span, + name: Ident, + ty: P, + expr: P) + -> P; + fn item_ty_poly(&self, span: Span, name: Ident, @@ -1033,6 +1040,15 @@ impl<'a> AstBuilder for ExtCtxt<'a> { self.item(span, name, Vec::new(), ast::ItemStatic(ty, mutbl, expr)) } + fn item_const(&self, + span: Span, + name: Ident, + ty: P, + expr: P) + -> P { + self.item(span, name, Vec::new(), ast::ItemConst(ty, expr)) + } + fn item_ty_poly(&self, span: Span, name: Ident, ty: P, generics: Generics) -> P { self.item(span, name, Vec::new(), ast::ItemTy(ty, generics)) diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 84de6c3b91339..32e226361e9d4 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -903,6 +903,9 @@ pub fn noop_fold_item_underscore(i: Item_, folder: &mut T) -> Item_ { ItemStatic(t, m, e) => { ItemStatic(folder.fold_ty(t), m, folder.fold_expr(e)) } + ItemConst(t, e) => { + ItemConst(folder.fold_ty(t), folder.fold_expr(e)) + } ItemFn(decl, fn_style, abi, generics, body) => { ItemFn( folder.fold_fn_decl(decl), diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 9bfb593786ef1..e73ffd7e58123 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -32,7 +32,7 @@ use ast::{FnUnboxedClosureKind, FnMutUnboxedClosureKind}; use ast::{FnOnceUnboxedClosureKind}; use ast::{ForeignItem, ForeignItemStatic, ForeignItemFn, ForeignMod}; use ast::{Ident, NormalFn, Inherited, ImplItem, Item, Item_, ItemStatic}; -use ast::{ItemEnum, ItemFn, ItemForeignMod, ItemImpl}; +use ast::{ItemEnum, ItemFn, ItemForeignMod, ItemImpl, ItemConst}; use ast::{ItemMac, ItemMod, ItemStruct, ItemTrait, ItemTy}; use ast::{LifetimeDef, Lit, Lit_}; use ast::{LitBool, LitChar, LitByte, LitBinary}; @@ -4739,14 +4739,18 @@ impl<'a> Parser<'a> { } } - fn parse_item_const(&mut self, m: Mutability) -> ItemInfo { + fn parse_item_const(&mut self, m: Option) -> ItemInfo { let id = self.parse_ident(); self.expect(&token::COLON); let ty = self.parse_ty(true); self.expect(&token::EQ); let e = self.parse_expr(); self.commit_expr_expecting(&*e, token::SEMI); - (id, ItemStatic(ty, m, e), None) + let item = match m { + Some(m) => ItemStatic(ty, m, e), + None => ItemConst(ty, e), + }; + (id, item, None) } /// Parse a `mod { ... }` or `mod ;` item @@ -5296,7 +5300,7 @@ impl<'a> Parser<'a> { // STATIC ITEM self.bump(); let m = if self.eat_keyword(keywords::Mut) {MutMutable} else {MutImmutable}; - let (ident, item_, extra_attrs) = self.parse_item_const(m); + let (ident, item_, extra_attrs) = self.parse_item_const(Some(m)); let last_span = self.last_span; let item = self.mk_item(lo, last_span.hi, @@ -5314,7 +5318,7 @@ impl<'a> Parser<'a> { self.span_err(last_span, "const globals cannot be mutable, \ did you mean to declare a static?"); } - let (ident, item_, extra_attrs) = self.parse_item_const(MutImmutable); + let (ident, item_, extra_attrs) = self.parse_item_const(None); let last_span = self.last_span; let item = self.mk_item(lo, last_span.hi, diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index c3a3848019a5d..321b00db47eaf 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -757,6 +757,20 @@ impl<'a> State<'a> { try!(word(&mut self.s, ";")); try!(self.end()); // end the outer cbox } + ast::ItemConst(ref ty, ref expr) => { + try!(self.head(visibility_qualified(item.vis, + "const").as_slice())); + try!(self.print_ident(item.ident)); + try!(self.word_space(":")); + try!(self.print_type(&**ty)); + try!(space(&mut self.s)); + try!(self.end()); // end the head-ibox + + try!(self.word_space("=")); + try!(self.print_expr(&**expr)); + try!(word(&mut self.s, ";")); + try!(self.end()); // end the outer cbox + } ast::ItemFn(ref decl, fn_style, abi, ref typarams, ref body) => { try!(self.print_fn( &**decl, diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index 3f5b524a9b5b2..9fb5742bb9b15 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -493,11 +493,10 @@ fn mk_tests(cx: &TestCtxt) -> P { Some(static_lt), ast::MutImmutable); // static TESTS: $static_type = &[...]; - ecx.item_static(sp, - ecx.ident_of("TESTS"), - static_type, - ast::MutImmutable, - test_descs) + ecx.item_const(sp, + ecx.ident_of("TESTS"), + static_type, + test_descs) } fn is_test_crate(krate: &ast::Crate) -> bool { diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 249f87d3102dd..5c7b144f4ab6e 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -211,7 +211,8 @@ pub fn walk_trait_ref_helper<'v,V>(visitor: &mut V, trait_ref: &'v TraitRef) pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) { visitor.visit_ident(item.span, item.ident); match item.node { - ItemStatic(ref typ, _, ref expr) => { + ItemStatic(ref typ, _, ref expr) | + ItemConst(ref typ, ref expr) => { visitor.visit_ty(&**typ); visitor.visit_expr(&**expr); } diff --git a/src/test/compile-fail/issue-17718-const-destructors.rs b/src/test/compile-fail/issue-17718-const-destructors.rs new file mode 100644 index 0000000000000..dffbfe155646a --- /dev/null +++ b/src/test/compile-fail/issue-17718-const-destructors.rs @@ -0,0 +1,19 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +struct A; +impl Drop for A { + fn drop(&mut self) {} +} + +const FOO: A = A; +//~ ERROR: constants are not allowed to have destructors + +fn main() {} From 4d87af9dce7b53a90ae9f6a84c14c61c4849cd2e Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 6 Oct 2014 16:14:00 -0700 Subject: [PATCH 03/24] core: Convert statics to constants --- src/libcore/atomic.rs | 8 ++--- src/libcore/cell.rs | 4 +-- src/libcore/char.rs | 2 +- src/libcore/num/f32.rs | 66 +++++++++++++++++----------------- src/libcore/num/f64.rs | 66 +++++++++++++++++----------------- src/libcore/num/int_macros.rs | 8 ++--- src/libcore/num/uint_macros.rs | 8 ++--- src/libcore/str.rs | 4 +-- 8 files changed, 83 insertions(+), 83 deletions(-) diff --git a/src/libcore/atomic.rs b/src/libcore/atomic.rs index 3e53746f58fe9..cc6fe06665bc8 100644 --- a/src/libcore/atomic.rs +++ b/src/libcore/atomic.rs @@ -77,19 +77,19 @@ pub enum Ordering { /// An `AtomicBool` initialized to `false` #[unstable = "may be renamed, pending conventions for static initalizers"] -pub static INIT_ATOMIC_BOOL: AtomicBool = +pub const INIT_ATOMIC_BOOL: AtomicBool = AtomicBool { v: UnsafeCell { value: 0 }, nocopy: marker::NoCopy }; /// An `AtomicInt` initialized to `0` #[unstable = "may be renamed, pending conventions for static initalizers"] -pub static INIT_ATOMIC_INT: AtomicInt = +pub const INIT_ATOMIC_INT: AtomicInt = AtomicInt { v: UnsafeCell { value: 0 }, nocopy: marker::NoCopy }; /// An `AtomicUint` initialized to `0` #[unstable = "may be renamed, pending conventions for static initalizers"] -pub static INIT_ATOMIC_UINT: AtomicUint = +pub const INIT_ATOMIC_UINT: AtomicUint = AtomicUint { v: UnsafeCell { value: 0, }, nocopy: marker::NoCopy }; // NB: Needs to be -1 (0b11111111...) to make fetch_nand work correctly -static UINT_TRUE: uint = -1; +const UINT_TRUE: uint = -1; #[stable] impl AtomicBool { diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 1cad9a3f8ca22..d644fd0063ed3 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -219,8 +219,8 @@ pub struct RefCell { // Values [1, MAX-1] represent the number of `Ref` active // (will not outgrow its range since `uint` is the size of the address space) type BorrowFlag = uint; -static UNUSED: BorrowFlag = 0; -static WRITING: BorrowFlag = -1; +const UNUSED: BorrowFlag = 0; +const WRITING: BorrowFlag = -1; impl RefCell { /// Create a new `RefCell` containing `value` diff --git a/src/libcore/char.rs b/src/libcore/char.rs index 1e87d11d37367..8f3ecf0633cf3 100644 --- a/src/libcore/char.rs +++ b/src/libcore/char.rs @@ -63,7 +63,7 @@ static MAX_THREE_B: u32 = 0x10000u32; */ /// The highest valid code point -pub static MAX: char = '\U0010ffff'; +pub const MAX: char = '\U0010ffff'; /// Converts from `u32` to a `char` #[inline] diff --git a/src/libcore/num/f32.rs b/src/libcore/num/f32.rs index bcea4bd8d3c29..b439f5577cbea 100644 --- a/src/libcore/num/f32.rs +++ b/src/libcore/num/f32.rs @@ -20,29 +20,29 @@ use num::{FPNormal, FPCategory, FPZero, FPSubnormal, FPInfinite, FPNaN}; use num::Float; use option::Option; -pub static RADIX: uint = 2u; +pub const RADIX: uint = 2u; -pub static MANTISSA_DIGITS: uint = 24u; -pub static DIGITS: uint = 6u; +pub const MANTISSA_DIGITS: uint = 24u; +pub const DIGITS: uint = 6u; -pub static EPSILON: f32 = 1.19209290e-07_f32; +pub const EPSILON: f32 = 1.19209290e-07_f32; /// Smallest finite f32 value -pub static MIN_VALUE: f32 = -3.40282347e+38_f32; +pub const MIN_VALUE: f32 = -3.40282347e+38_f32; /// Smallest positive, normalized f32 value -pub static MIN_POS_VALUE: f32 = 1.17549435e-38_f32; +pub const MIN_POS_VALUE: f32 = 1.17549435e-38_f32; /// Largest finite f32 value -pub static MAX_VALUE: f32 = 3.40282347e+38_f32; +pub const MAX_VALUE: f32 = 3.40282347e+38_f32; -pub static MIN_EXP: int = -125; -pub static MAX_EXP: int = 128; +pub const MIN_EXP: int = -125; +pub const MAX_EXP: int = 128; -pub static MIN_10_EXP: int = -37; -pub static MAX_10_EXP: int = 38; +pub const MIN_10_EXP: int = -37; +pub const MAX_10_EXP: int = 38; -pub static NAN: f32 = 0.0_f32/0.0_f32; -pub static INFINITY: f32 = 1.0_f32/0.0_f32; -pub static NEG_INFINITY: f32 = -1.0_f32/0.0_f32; +pub const NAN: f32 = 0.0_f32/0.0_f32; +pub const INFINITY: f32 = 1.0_f32/0.0_f32; +pub const NEG_INFINITY: f32 = -1.0_f32/0.0_f32; /// Various useful constants. pub mod consts { @@ -53,55 +53,55 @@ pub mod consts { // of `Float`. /// Archimedes' constant - pub static PI: f32 = 3.14159265358979323846264338327950288_f32; + pub const PI: f32 = 3.14159265358979323846264338327950288_f32; /// pi * 2.0 - pub static PI_2: f32 = 6.28318530717958647692528676655900576_f32; + pub const PI_2: f32 = 6.28318530717958647692528676655900576_f32; /// pi/2.0 - pub static FRAC_PI_2: f32 = 1.57079632679489661923132169163975144_f32; + pub const FRAC_PI_2: f32 = 1.57079632679489661923132169163975144_f32; /// pi/3.0 - pub static FRAC_PI_3: f32 = 1.04719755119659774615421446109316763_f32; + pub const FRAC_PI_3: f32 = 1.04719755119659774615421446109316763_f32; /// pi/4.0 - pub static FRAC_PI_4: f32 = 0.785398163397448309615660845819875721_f32; + pub const FRAC_PI_4: f32 = 0.785398163397448309615660845819875721_f32; /// pi/6.0 - pub static FRAC_PI_6: f32 = 0.52359877559829887307710723054658381_f32; + pub const FRAC_PI_6: f32 = 0.52359877559829887307710723054658381_f32; /// pi/8.0 - pub static FRAC_PI_8: f32 = 0.39269908169872415480783042290993786_f32; + pub const FRAC_PI_8: f32 = 0.39269908169872415480783042290993786_f32; /// 1.0/pi - pub static FRAC_1_PI: f32 = 0.318309886183790671537767526745028724_f32; + pub const FRAC_1_PI: f32 = 0.318309886183790671537767526745028724_f32; /// 2.0/pi - pub static FRAC_2_PI: f32 = 0.636619772367581343075535053490057448_f32; + pub const FRAC_2_PI: f32 = 0.636619772367581343075535053490057448_f32; /// 2.0/sqrt(pi) - pub static FRAC_2_SQRTPI: f32 = 1.12837916709551257389615890312154517_f32; + pub const FRAC_2_SQRTPI: f32 = 1.12837916709551257389615890312154517_f32; /// sqrt(2.0) - pub static SQRT2: f32 = 1.41421356237309504880168872420969808_f32; + pub const SQRT2: f32 = 1.41421356237309504880168872420969808_f32; /// 1.0/sqrt(2.0) - pub static FRAC_1_SQRT2: f32 = 0.707106781186547524400844362104849039_f32; + pub const FRAC_1_SQRT2: f32 = 0.707106781186547524400844362104849039_f32; /// Euler's number - pub static E: f32 = 2.71828182845904523536028747135266250_f32; + pub const E: f32 = 2.71828182845904523536028747135266250_f32; /// log2(e) - pub static LOG2_E: f32 = 1.44269504088896340735992468100189214_f32; + pub const LOG2_E: f32 = 1.44269504088896340735992468100189214_f32; /// log10(e) - pub static LOG10_E: f32 = 0.434294481903251827651128918916605082_f32; + pub const LOG10_E: f32 = 0.434294481903251827651128918916605082_f32; /// ln(2.0) - pub static LN_2: f32 = 0.693147180559945309417232121458176568_f32; + pub const LN_2: f32 = 0.693147180559945309417232121458176568_f32; /// ln(10.0) - pub static LN_10: f32 = 2.30258509299404568401799145468436421_f32; + pub const LN_10: f32 = 2.30258509299404568401799145468436421_f32; } impl Float for f32 { @@ -143,8 +143,8 @@ impl Float for f32 { /// is going to be tested, it is generally faster to use the specific /// predicate instead. fn classify(self) -> FPCategory { - static EXP_MASK: u32 = 0x7f800000; - static MAN_MASK: u32 = 0x007fffff; + const EXP_MASK: u32 = 0x7f800000; + const MAN_MASK: u32 = 0x007fffff; let bits: u32 = unsafe { mem::transmute(self) }; match (bits & MAN_MASK, bits & EXP_MASK) { diff --git a/src/libcore/num/f64.rs b/src/libcore/num/f64.rs index a3ae8e7c79ea3..d980009c0db0d 100644 --- a/src/libcore/num/f64.rs +++ b/src/libcore/num/f64.rs @@ -24,31 +24,31 @@ use option::Option; // constants are implemented in favour of referencing the respective // members of `Bounded` and `Float`. -pub static RADIX: uint = 2u; +pub const RADIX: uint = 2u; -pub static MANTISSA_DIGITS: uint = 53u; -pub static DIGITS: uint = 15u; +pub const MANTISSA_DIGITS: uint = 53u; +pub const DIGITS: uint = 15u; -pub static EPSILON: f64 = 2.2204460492503131e-16_f64; +pub const EPSILON: f64 = 2.2204460492503131e-16_f64; /// Smallest finite f64 value -pub static MIN_VALUE: f64 = -1.7976931348623157e+308_f64; +pub const MIN_VALUE: f64 = -1.7976931348623157e+308_f64; /// Smallest positive, normalized f64 value -pub static MIN_POS_VALUE: f64 = 2.2250738585072014e-308_f64; +pub const MIN_POS_VALUE: f64 = 2.2250738585072014e-308_f64; /// Largest finite f64 value -pub static MAX_VALUE: f64 = 1.7976931348623157e+308_f64; +pub const MAX_VALUE: f64 = 1.7976931348623157e+308_f64; -pub static MIN_EXP: int = -1021; -pub static MAX_EXP: int = 1024; +pub const MIN_EXP: int = -1021; +pub const MAX_EXP: int = 1024; -pub static MIN_10_EXP: int = -307; -pub static MAX_10_EXP: int = 308; +pub const MIN_10_EXP: int = -307; +pub const MAX_10_EXP: int = 308; -pub static NAN: f64 = 0.0_f64/0.0_f64; +pub const NAN: f64 = 0.0_f64/0.0_f64; -pub static INFINITY: f64 = 1.0_f64/0.0_f64; +pub const INFINITY: f64 = 1.0_f64/0.0_f64; -pub static NEG_INFINITY: f64 = -1.0_f64/0.0_f64; +pub const NEG_INFINITY: f64 = -1.0_f64/0.0_f64; /// Various useful constants. pub mod consts { @@ -59,55 +59,55 @@ pub mod consts { // of `Float`. /// Archimedes' constant - pub static PI: f64 = 3.14159265358979323846264338327950288_f64; + pub const PI: f64 = 3.14159265358979323846264338327950288_f64; /// pi * 2.0 - pub static PI_2: f64 = 6.28318530717958647692528676655900576_f64; + pub const PI_2: f64 = 6.28318530717958647692528676655900576_f64; /// pi/2.0 - pub static FRAC_PI_2: f64 = 1.57079632679489661923132169163975144_f64; + pub const FRAC_PI_2: f64 = 1.57079632679489661923132169163975144_f64; /// pi/3.0 - pub static FRAC_PI_3: f64 = 1.04719755119659774615421446109316763_f64; + pub const FRAC_PI_3: f64 = 1.04719755119659774615421446109316763_f64; /// pi/4.0 - pub static FRAC_PI_4: f64 = 0.785398163397448309615660845819875721_f64; + pub const FRAC_PI_4: f64 = 0.785398163397448309615660845819875721_f64; /// pi/6.0 - pub static FRAC_PI_6: f64 = 0.52359877559829887307710723054658381_f64; + pub const FRAC_PI_6: f64 = 0.52359877559829887307710723054658381_f64; /// pi/8.0 - pub static FRAC_PI_8: f64 = 0.39269908169872415480783042290993786_f64; + pub const FRAC_PI_8: f64 = 0.39269908169872415480783042290993786_f64; /// 1.0/pi - pub static FRAC_1_PI: f64 = 0.318309886183790671537767526745028724_f64; + pub const FRAC_1_PI: f64 = 0.318309886183790671537767526745028724_f64; /// 2.0/pi - pub static FRAC_2_PI: f64 = 0.636619772367581343075535053490057448_f64; + pub const FRAC_2_PI: f64 = 0.636619772367581343075535053490057448_f64; /// 2.0/sqrt(pi) - pub static FRAC_2_SQRTPI: f64 = 1.12837916709551257389615890312154517_f64; + pub const FRAC_2_SQRTPI: f64 = 1.12837916709551257389615890312154517_f64; /// sqrt(2.0) - pub static SQRT2: f64 = 1.41421356237309504880168872420969808_f64; + pub const SQRT2: f64 = 1.41421356237309504880168872420969808_f64; /// 1.0/sqrt(2.0) - pub static FRAC_1_SQRT2: f64 = 0.707106781186547524400844362104849039_f64; + pub const FRAC_1_SQRT2: f64 = 0.707106781186547524400844362104849039_f64; /// Euler's number - pub static E: f64 = 2.71828182845904523536028747135266250_f64; + pub const E: f64 = 2.71828182845904523536028747135266250_f64; /// log2(e) - pub static LOG2_E: f64 = 1.44269504088896340735992468100189214_f64; + pub const LOG2_E: f64 = 1.44269504088896340735992468100189214_f64; /// log10(e) - pub static LOG10_E: f64 = 0.434294481903251827651128918916605082_f64; + pub const LOG10_E: f64 = 0.434294481903251827651128918916605082_f64; /// ln(2.0) - pub static LN_2: f64 = 0.693147180559945309417232121458176568_f64; + pub const LN_2: f64 = 0.693147180559945309417232121458176568_f64; /// ln(10.0) - pub static LN_10: f64 = 2.30258509299404568401799145468436421_f64; + pub const LN_10: f64 = 2.30258509299404568401799145468436421_f64; } impl Float for f64 { @@ -149,8 +149,8 @@ impl Float for f64 { /// is going to be tested, it is generally faster to use the specific /// predicate instead. fn classify(self) -> FPCategory { - static EXP_MASK: u64 = 0x7ff0000000000000; - static MAN_MASK: u64 = 0x000fffffffffffff; + const EXP_MASK: u64 = 0x7ff0000000000000; + const MAN_MASK: u64 = 0x000fffffffffffff; let bits: u64 = unsafe { mem::transmute(self) }; match (bits & MAN_MASK, bits & EXP_MASK) { diff --git a/src/libcore/num/int_macros.rs b/src/libcore/num/int_macros.rs index ff0494725f849..0f8950344c8a0 100644 --- a/src/libcore/num/int_macros.rs +++ b/src/libcore/num/int_macros.rs @@ -16,20 +16,20 @@ macro_rules! int_module (($T:ty, $bits:expr) => ( // FIXME(#11621): Should be deprecated once CTFE is implemented in favour of // calling the `mem::size_of` function. #[unstable] -pub static BITS : uint = $bits; +pub const BITS : uint = $bits; // FIXME(#11621): Should be deprecated once CTFE is implemented in favour of // calling the `mem::size_of` function. #[unstable] -pub static BYTES : uint = ($bits / 8); +pub const BYTES : uint = ($bits / 8); // FIXME(#11621): Should be deprecated once CTFE is implemented in favour of // calling the `Bounded::min_value` function. #[unstable] -pub static MIN: $T = (-1 as $T) << (BITS - 1); +pub const MIN: $T = (-1 as $T) << (BITS - 1); // FIXME(#9837): Compute MIN like this so the high bits that shouldn't exist are 0. // FIXME(#11621): Should be deprecated once CTFE is implemented in favour of // calling the `Bounded::max_value` function. #[unstable] -pub static MAX: $T = !MIN; +pub const MAX: $T = !MIN; )) diff --git a/src/libcore/num/uint_macros.rs b/src/libcore/num/uint_macros.rs index b0c570af04ac0..2a94f851646c4 100644 --- a/src/libcore/num/uint_macros.rs +++ b/src/libcore/num/uint_macros.rs @@ -14,13 +14,13 @@ macro_rules! uint_module (($T:ty, $T_SIGNED:ty, $bits:expr) => ( #[unstable] -pub static BITS : uint = $bits; +pub const BITS : uint = $bits; #[unstable] -pub static BYTES : uint = ($bits / 8); +pub const BYTES : uint = ($bits / 8); #[unstable] -pub static MIN: $T = 0 as $T; +pub const MIN: $T = 0 as $T; #[unstable] -pub static MAX: $T = 0 as $T - 1 as $T; +pub const MAX: $T = 0 as $T - 1 as $T; )) diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 6099af0e78fb6..1cbe955274b65 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -1049,9 +1049,9 @@ pub struct CharRange { } /// Mask of the value bits of a continuation byte -static CONT_MASK: u8 = 0b0011_1111u8; +const CONT_MASK: u8 = 0b0011_1111u8; /// Value of the tag bits (tag mask is !CONT_MASK) of a continuation byte -static TAG_CONT_U8: u8 = 0b1000_0000u8; +const TAG_CONT_U8: u8 = 0b1000_0000u8; /// Unsafe operations pub mod raw { From 1a433770e3141c476a7ac5b12cfdc15be022073e Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 6 Oct 2014 16:14:30 -0700 Subject: [PATCH 04/24] sync: Convert statics to constants --- src/libsync/comm/oneshot.rs | 6 +++--- src/libsync/comm/shared.rs | 8 ++++---- src/libsync/comm/stream.rs | 6 +++--- src/libsync/mutex.rs | 8 ++++---- src/libsync/one.rs | 2 +- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/libsync/comm/oneshot.rs b/src/libsync/comm/oneshot.rs index 5b3cf33ebf093..053b5dc4c8a74 100644 --- a/src/libsync/comm/oneshot.rs +++ b/src/libsync/comm/oneshot.rs @@ -43,9 +43,9 @@ use atomic; use comm::Receiver; // Various states you can find a port in. -static EMPTY: uint = 0; -static DATA: uint = 1; -static DISCONNECTED: uint = 2; +const EMPTY: uint = 0; +const DATA: uint = 1; +const DISCONNECTED: uint = 2; pub struct Packet { // Internal state of the chan/port pair (stores the blocked task as well) diff --git a/src/libsync/comm/shared.rs b/src/libsync/comm/shared.rs index cb35bd8afb772..cfd045d08821a 100644 --- a/src/libsync/comm/shared.rs +++ b/src/libsync/comm/shared.rs @@ -31,12 +31,12 @@ use rustrt::thread::Thread; use atomic; use mpsc_queue as mpsc; -static DISCONNECTED: int = int::MIN; -static FUDGE: int = 1024; +const DISCONNECTED: int = int::MIN; +const FUDGE: int = 1024; #[cfg(test)] -static MAX_STEALS: int = 5; +const MAX_STEALS: int = 5; #[cfg(not(test))] -static MAX_STEALS: int = 1 << 20; +const MAX_STEALS: int = 1 << 20; pub struct Packet { queue: mpsc::Queue, diff --git a/src/libsync/comm/stream.rs b/src/libsync/comm/stream.rs index 36fe335128e4d..8e433c6a585f3 100644 --- a/src/libsync/comm/stream.rs +++ b/src/libsync/comm/stream.rs @@ -30,11 +30,11 @@ use atomic; use comm::Receiver; use spsc_queue as spsc; -static DISCONNECTED: int = int::MIN; +const DISCONNECTED: int = int::MIN; #[cfg(test)] -static MAX_STEALS: int = 5; +const MAX_STEALS: int = 5; #[cfg(not(test))] -static MAX_STEALS: int = 1 << 20; +const MAX_STEALS: int = 1 << 20; pub struct Packet { queue: spsc::Queue>, // internal queue for all message diff --git a/src/libsync/mutex.rs b/src/libsync/mutex.rs index 12de615a81b79..c6413d0d09cc7 100644 --- a/src/libsync/mutex.rs +++ b/src/libsync/mutex.rs @@ -70,9 +70,9 @@ use rustrt::thread::Thread; use mpsc_intrusive as q; -pub static LOCKED: uint = 1 << 0; -pub static GREEN_BLOCKED: uint = 1 << 1; -pub static NATIVE_BLOCKED: uint = 1 << 2; +pub const LOCKED: uint = 1 << 0; +pub const GREEN_BLOCKED: uint = 1 << 1; +pub const NATIVE_BLOCKED: uint = 1 << 2; /// A mutual exclusion primitive useful for protecting shared data /// @@ -163,7 +163,7 @@ pub struct Guard<'a> { /// Static initialization of a mutex. This constant can be used to initialize /// other mutex constants. -pub static MUTEX_INIT: StaticMutex = StaticMutex { +pub const MUTEX_INIT: StaticMutex = StaticMutex { lock: mutex::NATIVE_MUTEX_INIT, state: atomic::INIT_ATOMIC_UINT, flavor: UnsafeCell { value: Unlocked }, diff --git a/src/libsync/one.rs b/src/libsync/one.rs index 4594345d2a3f6..c740c4f3d2e95 100644 --- a/src/libsync/one.rs +++ b/src/libsync/one.rs @@ -45,7 +45,7 @@ pub struct Once { } /// Initialization value for static `Once` values. -pub static ONCE_INIT: Once = Once { +pub const ONCE_INIT: Once = Once { mutex: MUTEX_INIT, cnt: atomic::INIT_ATOMIC_INT, lock_cnt: atomic::INIT_ATOMIC_INT, From 34d66de52a8338b0fd1f1d4842916bc37cc81f75 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 6 Oct 2014 16:14:38 -0700 Subject: [PATCH 05/24] unicode: Make statics legal The tables in libunicode are far too large to want to be inlined into any other program, so these tables are all going to remain `static`. For them to be legal, they cannot reference one another by value, but instead use references now. This commit also modifies the src/etc/unicode.py script to generate the right tables. --- src/etc/unicode.py | 8 +- src/libunicode/normalize.rs | 18 ++-- src/libunicode/tables.rs | 205 ++++++++++++++++++------------------ 3 files changed, 116 insertions(+), 115 deletions(-) diff --git a/src/etc/unicode.py b/src/etc/unicode.py index a74bb74897135..0b128686690f0 100755 --- a/src/etc/unicode.py +++ b/src/etc/unicode.py @@ -333,14 +333,14 @@ def emit_property_module(f, mod, tbl, emit_fn): def emit_regex_module(f, cats, w_data): f.write("pub mod regex {\n") regex_class = "&'static [(char, char)]" - class_table = "&'static [(&'static str, %s)]" % regex_class + class_table = "&'static [(&'static str, &'static %s)]" % regex_class emit_table(f, "UNICODE_CLASSES", cats, class_table, - pfun=lambda x: "(\"%s\",super::%s::%s_table)" % (x[0], x[1], x[0])) + pfun=lambda x: "(\"%s\",&super::%s::%s_table)" % (x[0], x[1], x[0])) - f.write(" pub static PERLD: %s = super::general_category::Nd_table;\n\n" + f.write(" pub static PERLD: &'static %s = &super::general_category::Nd_table;\n\n" % regex_class) - f.write(" pub static PERLS: %s = super::property::White_Space_table;\n\n" + f.write(" pub static PERLS: &'static %s = &super::property::White_Space_table;\n\n" % regex_class) emit_table(f, "PERLW", w_data, regex_class) diff --git a/src/libunicode/normalize.rs b/src/libunicode/normalize.rs index a60e95c38272b..76a9476d1fc8d 100644 --- a/src/libunicode/normalize.rs +++ b/src/libunicode/normalize.rs @@ -100,15 +100,15 @@ pub fn compose(a: char, b: char) -> Option { } // Constants from Unicode 6.3.0 Section 3.12 Conjoining Jamo Behavior -static S_BASE: u32 = 0xAC00; -static L_BASE: u32 = 0x1100; -static V_BASE: u32 = 0x1161; -static T_BASE: u32 = 0x11A7; -static L_COUNT: u32 = 19; -static V_COUNT: u32 = 21; -static T_COUNT: u32 = 28; -static N_COUNT: u32 = (V_COUNT * T_COUNT); -static S_COUNT: u32 = (L_COUNT * N_COUNT); +const S_BASE: u32 = 0xAC00; +const L_BASE: u32 = 0x1100; +const V_BASE: u32 = 0x1161; +const T_BASE: u32 = 0x11A7; +const L_COUNT: u32 = 19; +const V_COUNT: u32 = 21; +const T_COUNT: u32 = 28; +const N_COUNT: u32 = (V_COUNT * T_COUNT); +const S_COUNT: u32 = (L_COUNT * N_COUNT); // Decompose a precomposed Hangul syllable #[inline(always)] diff --git a/src/libunicode/tables.rs b/src/libunicode/tables.rs index 135b267262cc6..e359883295f42 100644 --- a/src/libunicode/tables.rs +++ b/src/libunicode/tables.rs @@ -3636,108 +3636,109 @@ pub mod property { } pub mod regex { - pub static UNICODE_CLASSES: &'static [(&'static str, &'static [(char, char)])] = &[ - ("Alphabetic", super::derived_property::Alphabetic_table), ("Arabic", - super::script::Arabic_table), ("Armenian", super::script::Armenian_table), ("Avestan", - super::script::Avestan_table), ("Balinese", super::script::Balinese_table), ("Bamum", - super::script::Bamum_table), ("Bassa_Vah", super::script::Bassa_Vah_table), ("Batak", - super::script::Batak_table), ("Bengali", super::script::Bengali_table), ("Bopomofo", - super::script::Bopomofo_table), ("Brahmi", super::script::Brahmi_table), ("Braille", - super::script::Braille_table), ("Buginese", super::script::Buginese_table), ("Buhid", - super::script::Buhid_table), ("C", super::general_category::C_table), - ("Canadian_Aboriginal", super::script::Canadian_Aboriginal_table), ("Carian", - super::script::Carian_table), ("Caucasian_Albanian", - super::script::Caucasian_Albanian_table), ("Cc", super::general_category::Cc_table), ("Cf", - super::general_category::Cf_table), ("Chakma", super::script::Chakma_table), ("Cham", - super::script::Cham_table), ("Cherokee", super::script::Cherokee_table), ("Cn", - super::general_category::Cn_table), ("Co", super::general_category::Co_table), ("Common", - super::script::Common_table), ("Coptic", super::script::Coptic_table), ("Cuneiform", - super::script::Cuneiform_table), ("Cypriot", super::script::Cypriot_table), ("Cyrillic", - super::script::Cyrillic_table), ("Default_Ignorable_Code_Point", - super::derived_property::Default_Ignorable_Code_Point_table), ("Deseret", - super::script::Deseret_table), ("Devanagari", super::script::Devanagari_table), ("Duployan", - super::script::Duployan_table), ("Egyptian_Hieroglyphs", - super::script::Egyptian_Hieroglyphs_table), ("Elbasan", super::script::Elbasan_table), - ("Ethiopic", super::script::Ethiopic_table), ("Georgian", super::script::Georgian_table), - ("Glagolitic", super::script::Glagolitic_table), ("Gothic", super::script::Gothic_table), - ("Grantha", super::script::Grantha_table), ("Greek", super::script::Greek_table), - ("Gujarati", super::script::Gujarati_table), ("Gurmukhi", super::script::Gurmukhi_table), - ("Han", super::script::Han_table), ("Hangul", super::script::Hangul_table), ("Hanunoo", - super::script::Hanunoo_table), ("Hebrew", super::script::Hebrew_table), ("Hiragana", - super::script::Hiragana_table), ("Imperial_Aramaic", super::script::Imperial_Aramaic_table), - ("Inherited", super::script::Inherited_table), ("Inscriptional_Pahlavi", - super::script::Inscriptional_Pahlavi_table), ("Inscriptional_Parthian", - super::script::Inscriptional_Parthian_table), ("Javanese", super::script::Javanese_table), - ("Join_Control", super::property::Join_Control_table), ("Kaithi", - super::script::Kaithi_table), ("Kannada", super::script::Kannada_table), ("Katakana", - super::script::Katakana_table), ("Kayah_Li", super::script::Kayah_Li_table), ("Kharoshthi", - super::script::Kharoshthi_table), ("Khmer", super::script::Khmer_table), ("Khojki", - super::script::Khojki_table), ("Khudawadi", super::script::Khudawadi_table), ("L", - super::general_category::L_table), ("LC", super::general_category::LC_table), ("Lao", - super::script::Lao_table), ("Latin", super::script::Latin_table), ("Lepcha", - super::script::Lepcha_table), ("Limbu", super::script::Limbu_table), ("Linear_A", - super::script::Linear_A_table), ("Linear_B", super::script::Linear_B_table), ("Lisu", - super::script::Lisu_table), ("Ll", super::general_category::Ll_table), ("Lm", - super::general_category::Lm_table), ("Lo", super::general_category::Lo_table), ("Lowercase", - super::derived_property::Lowercase_table), ("Lt", super::general_category::Lt_table), ("Lu", - super::general_category::Lu_table), ("Lycian", super::script::Lycian_table), ("Lydian", - super::script::Lydian_table), ("M", super::general_category::M_table), ("Mahajani", - super::script::Mahajani_table), ("Malayalam", super::script::Malayalam_table), ("Mandaic", - super::script::Mandaic_table), ("Manichaean", super::script::Manichaean_table), ("Mc", - super::general_category::Mc_table), ("Me", super::general_category::Me_table), - ("Meetei_Mayek", super::script::Meetei_Mayek_table), ("Mende_Kikakui", - super::script::Mende_Kikakui_table), ("Meroitic_Cursive", - super::script::Meroitic_Cursive_table), ("Meroitic_Hieroglyphs", - super::script::Meroitic_Hieroglyphs_table), ("Miao", super::script::Miao_table), ("Mn", - super::general_category::Mn_table), ("Modi", super::script::Modi_table), ("Mongolian", - super::script::Mongolian_table), ("Mro", super::script::Mro_table), ("Myanmar", - super::script::Myanmar_table), ("N", super::general_category::N_table), ("Nabataean", - super::script::Nabataean_table), ("Nd", super::general_category::Nd_table), ("New_Tai_Lue", - super::script::New_Tai_Lue_table), ("Nko", super::script::Nko_table), ("Nl", - super::general_category::Nl_table), ("No", super::general_category::No_table), - ("Noncharacter_Code_Point", super::property::Noncharacter_Code_Point_table), ("Ogham", - super::script::Ogham_table), ("Ol_Chiki", super::script::Ol_Chiki_table), ("Old_Italic", - super::script::Old_Italic_table), ("Old_North_Arabian", - super::script::Old_North_Arabian_table), ("Old_Permic", super::script::Old_Permic_table), - ("Old_Persian", super::script::Old_Persian_table), ("Old_South_Arabian", - super::script::Old_South_Arabian_table), ("Old_Turkic", super::script::Old_Turkic_table), - ("Oriya", super::script::Oriya_table), ("Osmanya", super::script::Osmanya_table), ("P", - super::general_category::P_table), ("Pahawh_Hmong", super::script::Pahawh_Hmong_table), - ("Palmyrene", super::script::Palmyrene_table), ("Pau_Cin_Hau", - super::script::Pau_Cin_Hau_table), ("Pc", super::general_category::Pc_table), ("Pd", - super::general_category::Pd_table), ("Pe", super::general_category::Pe_table), ("Pf", - super::general_category::Pf_table), ("Phags_Pa", super::script::Phags_Pa_table), - ("Phoenician", super::script::Phoenician_table), ("Pi", super::general_category::Pi_table), - ("Po", super::general_category::Po_table), ("Ps", super::general_category::Ps_table), - ("Psalter_Pahlavi", super::script::Psalter_Pahlavi_table), ("Rejang", - super::script::Rejang_table), ("Runic", super::script::Runic_table), ("S", - super::general_category::S_table), ("Samaritan", super::script::Samaritan_table), - ("Saurashtra", super::script::Saurashtra_table), ("Sc", super::general_category::Sc_table), - ("Sharada", super::script::Sharada_table), ("Shavian", super::script::Shavian_table), - ("Siddham", super::script::Siddham_table), ("Sinhala", super::script::Sinhala_table), ("Sk", - super::general_category::Sk_table), ("Sm", super::general_category::Sm_table), ("So", - super::general_category::So_table), ("Sora_Sompeng", super::script::Sora_Sompeng_table), - ("Sundanese", super::script::Sundanese_table), ("Syloti_Nagri", - super::script::Syloti_Nagri_table), ("Syriac", super::script::Syriac_table), ("Tagalog", - super::script::Tagalog_table), ("Tagbanwa", super::script::Tagbanwa_table), ("Tai_Le", - super::script::Tai_Le_table), ("Tai_Tham", super::script::Tai_Tham_table), ("Tai_Viet", - super::script::Tai_Viet_table), ("Takri", super::script::Takri_table), ("Tamil", - super::script::Tamil_table), ("Telugu", super::script::Telugu_table), ("Thaana", - super::script::Thaana_table), ("Thai", super::script::Thai_table), ("Tibetan", - super::script::Tibetan_table), ("Tifinagh", super::script::Tifinagh_table), ("Tirhuta", - super::script::Tirhuta_table), ("Ugaritic", super::script::Ugaritic_table), ("Uppercase", - super::derived_property::Uppercase_table), ("Vai", super::script::Vai_table), - ("Warang_Citi", super::script::Warang_Citi_table), ("White_Space", - super::property::White_Space_table), ("XID_Continue", - super::derived_property::XID_Continue_table), ("XID_Start", - super::derived_property::XID_Start_table), ("Yi", super::script::Yi_table), ("Z", - super::general_category::Z_table), ("Zl", super::general_category::Zl_table), ("Zp", - super::general_category::Zp_table), ("Zs", super::general_category::Zs_table) - ]; - - pub static PERLD: &'static [(char, char)] = super::general_category::Nd_table; - - pub static PERLS: &'static [(char, char)] = super::property::White_Space_table; + pub static UNICODE_CLASSES: &'static [(&'static str, &'static &'static [(char, char)])] = &[ + ("Alphabetic", &super::derived_property::Alphabetic_table), ("Arabic", + &super::script::Arabic_table), ("Armenian", &super::script::Armenian_table), ("Avestan", + &super::script::Avestan_table), ("Balinese", &super::script::Balinese_table), ("Bamum", + &super::script::Bamum_table), ("Bassa_Vah", &super::script::Bassa_Vah_table), ("Batak", + &super::script::Batak_table), ("Bengali", &super::script::Bengali_table), ("Bopomofo", + &super::script::Bopomofo_table), ("Brahmi", &super::script::Brahmi_table), ("Braille", + &super::script::Braille_table), ("Buginese", &super::script::Buginese_table), ("Buhid", + &super::script::Buhid_table), ("C", &super::general_category::C_table), + ("Canadian_Aboriginal", &super::script::Canadian_Aboriginal_table), ("Carian", + &super::script::Carian_table), ("Caucasian_Albanian", + &super::script::Caucasian_Albanian_table), ("Cc", &super::general_category::Cc_table), + ("Cf", &super::general_category::Cf_table), ("Chakma", &super::script::Chakma_table), + ("Cham", &super::script::Cham_table), ("Cherokee", &super::script::Cherokee_table), ("Cn", + &super::general_category::Cn_table), ("Co", &super::general_category::Co_table), ("Common", + &super::script::Common_table), ("Coptic", &super::script::Coptic_table), ("Cuneiform", + &super::script::Cuneiform_table), ("Cypriot", &super::script::Cypriot_table), ("Cyrillic", + &super::script::Cyrillic_table), ("Default_Ignorable_Code_Point", + &super::derived_property::Default_Ignorable_Code_Point_table), ("Deseret", + &super::script::Deseret_table), ("Devanagari", &super::script::Devanagari_table), + ("Duployan", &super::script::Duployan_table), ("Egyptian_Hieroglyphs", + &super::script::Egyptian_Hieroglyphs_table), ("Elbasan", &super::script::Elbasan_table), + ("Ethiopic", &super::script::Ethiopic_table), ("Georgian", &super::script::Georgian_table), + ("Glagolitic", &super::script::Glagolitic_table), ("Gothic", &super::script::Gothic_table), + ("Grantha", &super::script::Grantha_table), ("Greek", &super::script::Greek_table), + ("Gujarati", &super::script::Gujarati_table), ("Gurmukhi", &super::script::Gurmukhi_table), + ("Han", &super::script::Han_table), ("Hangul", &super::script::Hangul_table), ("Hanunoo", + &super::script::Hanunoo_table), ("Hebrew", &super::script::Hebrew_table), ("Hiragana", + &super::script::Hiragana_table), ("Imperial_Aramaic", + &super::script::Imperial_Aramaic_table), ("Inherited", &super::script::Inherited_table), + ("Inscriptional_Pahlavi", &super::script::Inscriptional_Pahlavi_table), + ("Inscriptional_Parthian", &super::script::Inscriptional_Parthian_table), ("Javanese", + &super::script::Javanese_table), ("Join_Control", &super::property::Join_Control_table), + ("Kaithi", &super::script::Kaithi_table), ("Kannada", &super::script::Kannada_table), + ("Katakana", &super::script::Katakana_table), ("Kayah_Li", &super::script::Kayah_Li_table), + ("Kharoshthi", &super::script::Kharoshthi_table), ("Khmer", &super::script::Khmer_table), + ("Khojki", &super::script::Khojki_table), ("Khudawadi", &super::script::Khudawadi_table), + ("L", &super::general_category::L_table), ("LC", &super::general_category::LC_table), + ("Lao", &super::script::Lao_table), ("Latin", &super::script::Latin_table), ("Lepcha", + &super::script::Lepcha_table), ("Limbu", &super::script::Limbu_table), ("Linear_A", + &super::script::Linear_A_table), ("Linear_B", &super::script::Linear_B_table), ("Lisu", + &super::script::Lisu_table), ("Ll", &super::general_category::Ll_table), ("Lm", + &super::general_category::Lm_table), ("Lo", &super::general_category::Lo_table), + ("Lowercase", &super::derived_property::Lowercase_table), ("Lt", + &super::general_category::Lt_table), ("Lu", &super::general_category::Lu_table), ("Lycian", + &super::script::Lycian_table), ("Lydian", &super::script::Lydian_table), ("M", + &super::general_category::M_table), ("Mahajani", &super::script::Mahajani_table), + ("Malayalam", &super::script::Malayalam_table), ("Mandaic", &super::script::Mandaic_table), + ("Manichaean", &super::script::Manichaean_table), ("Mc", + &super::general_category::Mc_table), ("Me", &super::general_category::Me_table), + ("Meetei_Mayek", &super::script::Meetei_Mayek_table), ("Mende_Kikakui", + &super::script::Mende_Kikakui_table), ("Meroitic_Cursive", + &super::script::Meroitic_Cursive_table), ("Meroitic_Hieroglyphs", + &super::script::Meroitic_Hieroglyphs_table), ("Miao", &super::script::Miao_table), ("Mn", + &super::general_category::Mn_table), ("Modi", &super::script::Modi_table), ("Mongolian", + &super::script::Mongolian_table), ("Mro", &super::script::Mro_table), ("Myanmar", + &super::script::Myanmar_table), ("N", &super::general_category::N_table), ("Nabataean", + &super::script::Nabataean_table), ("Nd", &super::general_category::Nd_table), + ("New_Tai_Lue", &super::script::New_Tai_Lue_table), ("Nko", &super::script::Nko_table), + ("Nl", &super::general_category::Nl_table), ("No", &super::general_category::No_table), + ("Noncharacter_Code_Point", &super::property::Noncharacter_Code_Point_table), ("Ogham", + &super::script::Ogham_table), ("Ol_Chiki", &super::script::Ol_Chiki_table), ("Old_Italic", + &super::script::Old_Italic_table), ("Old_North_Arabian", + &super::script::Old_North_Arabian_table), ("Old_Permic", &super::script::Old_Permic_table), + ("Old_Persian", &super::script::Old_Persian_table), ("Old_South_Arabian", + &super::script::Old_South_Arabian_table), ("Old_Turkic", &super::script::Old_Turkic_table), + ("Oriya", &super::script::Oriya_table), ("Osmanya", &super::script::Osmanya_table), ("P", + &super::general_category::P_table), ("Pahawh_Hmong", &super::script::Pahawh_Hmong_table), + ("Palmyrene", &super::script::Palmyrene_table), ("Pau_Cin_Hau", + &super::script::Pau_Cin_Hau_table), ("Pc", &super::general_category::Pc_table), ("Pd", + &super::general_category::Pd_table), ("Pe", &super::general_category::Pe_table), ("Pf", + &super::general_category::Pf_table), ("Phags_Pa", &super::script::Phags_Pa_table), + ("Phoenician", &super::script::Phoenician_table), ("Pi", + &super::general_category::Pi_table), ("Po", &super::general_category::Po_table), ("Ps", + &super::general_category::Ps_table), ("Psalter_Pahlavi", + &super::script::Psalter_Pahlavi_table), ("Rejang", &super::script::Rejang_table), ("Runic", + &super::script::Runic_table), ("S", &super::general_category::S_table), ("Samaritan", + &super::script::Samaritan_table), ("Saurashtra", &super::script::Saurashtra_table), ("Sc", + &super::general_category::Sc_table), ("Sharada", &super::script::Sharada_table), ("Shavian", + &super::script::Shavian_table), ("Siddham", &super::script::Siddham_table), ("Sinhala", + &super::script::Sinhala_table), ("Sk", &super::general_category::Sk_table), ("Sm", + &super::general_category::Sm_table), ("So", &super::general_category::So_table), + ("Sora_Sompeng", &super::script::Sora_Sompeng_table), ("Sundanese", + &super::script::Sundanese_table), ("Syloti_Nagri", &super::script::Syloti_Nagri_table), + ("Syriac", &super::script::Syriac_table), ("Tagalog", &super::script::Tagalog_table), + ("Tagbanwa", &super::script::Tagbanwa_table), ("Tai_Le", &super::script::Tai_Le_table), + ("Tai_Tham", &super::script::Tai_Tham_table), ("Tai_Viet", &super::script::Tai_Viet_table), + ("Takri", &super::script::Takri_table), ("Tamil", &super::script::Tamil_table), ("Telugu", + &super::script::Telugu_table), ("Thaana", &super::script::Thaana_table), ("Thai", + &super::script::Thai_table), ("Tibetan", &super::script::Tibetan_table), ("Tifinagh", + &super::script::Tifinagh_table), ("Tirhuta", &super::script::Tirhuta_table), ("Ugaritic", + &super::script::Ugaritic_table), ("Uppercase", &super::derived_property::Uppercase_table), + ("Vai", &super::script::Vai_table), ("Warang_Citi", &super::script::Warang_Citi_table), + ("White_Space", &super::property::White_Space_table), ("XID_Continue", + &super::derived_property::XID_Continue_table), ("XID_Start", + &super::derived_property::XID_Start_table), ("Yi", &super::script::Yi_table), ("Z", + &super::general_category::Z_table), ("Zl", &super::general_category::Zl_table), ("Zp", + &super::general_category::Zp_table), ("Zs", &super::general_category::Zs_table) + ]; + + pub static PERLD: &'static &'static [(char, char)] = &super::general_category::Nd_table; + + pub static PERLS: &'static &'static [(char, char)] = &super::property::White_Space_table; pub static PERLW: &'static [(char, char)] = &[ ('\x30', '\x39'), ('\x41', '\x5a'), ('\x5f', '\x5f'), ('\x61', '\x7a'), ('\xaa', '\xaa'), From abb3d3e4443f38be5f829f833d40b6c35b31302b Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 6 Oct 2014 16:15:54 -0700 Subject: [PATCH 06/24] collections: Convert statics to constants --- src/libcollections/trie.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libcollections/trie.rs b/src/libcollections/trie.rs index 66f41d2ba1f32..fe8ced7f2aaaf 100644 --- a/src/libcollections/trie.rs +++ b/src/libcollections/trie.rs @@ -34,10 +34,10 @@ use slice::{Items, MutItems}; use slice; // FIXME: #5244: need to manually update the TrieNode constructor -static SHIFT: uint = 4; -static SIZE: uint = 1 << SHIFT; -static MASK: uint = SIZE - 1; -static NUM_CHUNKS: uint = uint::BITS / SHIFT; +const SHIFT: uint = 4; +const SIZE: uint = 1 << SHIFT; +const MASK: uint = SIZE - 1; +const NUM_CHUNKS: uint = uint::BITS / SHIFT; #[deriving(Clone)] enum Child { From 33700532325627d8127d531dd83cca610681d48f Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 6 Oct 2014 16:17:51 -0700 Subject: [PATCH 07/24] libc: Convert all statics to constant This crate is largely just one giant header file, so there's no need for any of these values to actually have a memory location, they're all just basically a regular #define. --- src/liblibc/lib.rs | 3540 ++++++++++++++++++++++---------------------- 1 file changed, 1770 insertions(+), 1770 deletions(-) diff --git a/src/liblibc/lib.rs b/src/liblibc/lib.rs index affa452eb49de..90416045b5cc8 100644 --- a/src/liblibc/lib.rs +++ b/src/liblibc/lib.rs @@ -2003,108 +2003,108 @@ pub mod consts { pub mod c95 { use types::os::arch::c95::{c_int, c_uint}; - pub static EXIT_FAILURE : c_int = 1; - pub static EXIT_SUCCESS : c_int = 0; - pub static RAND_MAX : c_int = 32767; - pub static EOF : c_int = -1; - pub static SEEK_SET : c_int = 0; - pub static SEEK_CUR : c_int = 1; - pub static SEEK_END : c_int = 2; - pub static _IOFBF : c_int = 0; - pub static _IONBF : c_int = 4; - pub static _IOLBF : c_int = 64; - pub static BUFSIZ : c_uint = 512_u32; - pub static FOPEN_MAX : c_uint = 20_u32; - pub static FILENAME_MAX : c_uint = 260_u32; - pub static L_tmpnam : c_uint = 16_u32; - pub static TMP_MAX : c_uint = 32767_u32; - - pub static WSAEINTR: c_int = 10004; - pub static WSAEBADF: c_int = 10009; - pub static WSAEACCES: c_int = 10013; - pub static WSAEFAULT: c_int = 10014; - pub static WSAEINVAL: c_int = 10022; - pub static WSAEMFILE: c_int = 10024; - pub static WSAEWOULDBLOCK: c_int = 10035; - pub static WSAEINPROGRESS: c_int = 10036; - pub static WSAEALREADY: c_int = 10037; - pub static WSAENOTSOCK: c_int = 10038; - pub static WSAEDESTADDRREQ: c_int = 10039; - pub static WSAEMSGSIZE: c_int = 10040; - pub static WSAEPROTOTYPE: c_int = 10041; - pub static WSAENOPROTOOPT: c_int = 10042; - pub static WSAEPROTONOSUPPORT: c_int = 10043; - pub static WSAESOCKTNOSUPPORT: c_int = 10044; - pub static WSAEOPNOTSUPP: c_int = 10045; - pub static WSAEPFNOSUPPORT: c_int = 10046; - pub static WSAEAFNOSUPPORT: c_int = 10047; - pub static WSAEADDRINUSE: c_int = 10048; - pub static WSAEADDRNOTAVAIL: c_int = 10049; - pub static WSAENETDOWN: c_int = 10050; - pub static WSAENETUNREACH: c_int = 10051; - pub static WSAENETRESET: c_int = 10052; - pub static WSAECONNABORTED: c_int = 10053; - pub static WSAECONNRESET: c_int = 10054; - pub static WSAENOBUFS: c_int = 10055; - pub static WSAEISCONN: c_int = 10056; - pub static WSAENOTCONN: c_int = 10057; - pub static WSAESHUTDOWN: c_int = 10058; - pub static WSAETOOMANYREFS: c_int = 10059; - pub static WSAETIMEDOUT: c_int = 10060; - pub static WSAECONNREFUSED: c_int = 10061; - pub static WSAELOOP: c_int = 10062; - pub static WSAENAMETOOLONG: c_int = 10063; - pub static WSAEHOSTDOWN: c_int = 10064; - pub static WSAEHOSTUNREACH: c_int = 10065; - pub static WSAENOTEMPTY: c_int = 10066; - pub static WSAEPROCLIM: c_int = 10067; - pub static WSAEUSERS: c_int = 10068; - pub static WSAEDQUOT: c_int = 10069; - pub static WSAESTALE: c_int = 10070; - pub static WSAEREMOTE: c_int = 10071; - pub static WSASYSNOTREADY: c_int = 10091; - pub static WSAVERNOTSUPPORTED: c_int = 10092; - pub static WSANOTINITIALISED: c_int = 10093; - pub static WSAEDISCON: c_int = 10101; - pub static WSAENOMORE: c_int = 10102; - pub static WSAECANCELLED: c_int = 10103; - pub static WSAEINVALIDPROCTABLE: c_int = 10104; - pub static WSAEINVALIDPROVIDER: c_int = 10105; - pub static WSAEPROVIDERFAILEDINIT: c_int = 10106; + pub const EXIT_FAILURE : c_int = 1; + pub const EXIT_SUCCESS : c_int = 0; + pub const RAND_MAX : c_int = 32767; + pub const EOF : c_int = -1; + pub const SEEK_SET : c_int = 0; + pub const SEEK_CUR : c_int = 1; + pub const SEEK_END : c_int = 2; + pub const _IOFBF : c_int = 0; + pub const _IONBF : c_int = 4; + pub const _IOLBF : c_int = 64; + pub const BUFSIZ : c_uint = 512_u32; + pub const FOPEN_MAX : c_uint = 20_u32; + pub const FILENAME_MAX : c_uint = 260_u32; + pub const L_tmpnam : c_uint = 16_u32; + pub const TMP_MAX : c_uint = 32767_u32; + + pub const WSAEINTR: c_int = 10004; + pub const WSAEBADF: c_int = 10009; + pub const WSAEACCES: c_int = 10013; + pub const WSAEFAULT: c_int = 10014; + pub const WSAEINVAL: c_int = 10022; + pub const WSAEMFILE: c_int = 10024; + pub const WSAEWOULDBLOCK: c_int = 10035; + pub const WSAEINPROGRESS: c_int = 10036; + pub const WSAEALREADY: c_int = 10037; + pub const WSAENOTSOCK: c_int = 10038; + pub const WSAEDESTADDRREQ: c_int = 10039; + pub const WSAEMSGSIZE: c_int = 10040; + pub const WSAEPROTOTYPE: c_int = 10041; + pub const WSAENOPROTOOPT: c_int = 10042; + pub const WSAEPROTONOSUPPORT: c_int = 10043; + pub const WSAESOCKTNOSUPPORT: c_int = 10044; + pub const WSAEOPNOTSUPP: c_int = 10045; + pub const WSAEPFNOSUPPORT: c_int = 10046; + pub const WSAEAFNOSUPPORT: c_int = 10047; + pub const WSAEADDRINUSE: c_int = 10048; + pub const WSAEADDRNOTAVAIL: c_int = 10049; + pub const WSAENETDOWN: c_int = 10050; + pub const WSAENETUNREACH: c_int = 10051; + pub const WSAENETRESET: c_int = 10052; + pub const WSAECONNABORTED: c_int = 10053; + pub const WSAECONNRESET: c_int = 10054; + pub const WSAENOBUFS: c_int = 10055; + pub const WSAEISCONN: c_int = 10056; + pub const WSAENOTCONN: c_int = 10057; + pub const WSAESHUTDOWN: c_int = 10058; + pub const WSAETOOMANYREFS: c_int = 10059; + pub const WSAETIMEDOUT: c_int = 10060; + pub const WSAECONNREFUSED: c_int = 10061; + pub const WSAELOOP: c_int = 10062; + pub const WSAENAMETOOLONG: c_int = 10063; + pub const WSAEHOSTDOWN: c_int = 10064; + pub const WSAEHOSTUNREACH: c_int = 10065; + pub const WSAENOTEMPTY: c_int = 10066; + pub const WSAEPROCLIM: c_int = 10067; + pub const WSAEUSERS: c_int = 10068; + pub const WSAEDQUOT: c_int = 10069; + pub const WSAESTALE: c_int = 10070; + pub const WSAEREMOTE: c_int = 10071; + pub const WSASYSNOTREADY: c_int = 10091; + pub const WSAVERNOTSUPPORTED: c_int = 10092; + pub const WSANOTINITIALISED: c_int = 10093; + pub const WSAEDISCON: c_int = 10101; + pub const WSAENOMORE: c_int = 10102; + pub const WSAECANCELLED: c_int = 10103; + pub const WSAEINVALIDPROCTABLE: c_int = 10104; + pub const WSAEINVALIDPROVIDER: c_int = 10105; + pub const WSAEPROVIDERFAILEDINIT: c_int = 10106; } pub mod c99 { } pub mod posix88 { use types::os::arch::c95::c_int; - pub static O_RDONLY : c_int = 0; - pub static O_WRONLY : c_int = 1; - pub static O_RDWR : c_int = 2; - pub static O_APPEND : c_int = 8; - pub static O_CREAT : c_int = 256; - pub static O_EXCL : c_int = 1024; - pub static O_TRUNC : c_int = 512; - pub static S_IFIFO : c_int = 4096; - pub static S_IFCHR : c_int = 8192; - pub static S_IFBLK : c_int = 12288; - pub static S_IFDIR : c_int = 16384; - pub static S_IFREG : c_int = 32768; - pub static S_IFLNK : c_int = 40960; - pub static S_IFMT : c_int = 61440; - pub static S_IEXEC : c_int = 64; - pub static S_IWRITE : c_int = 128; - pub static S_IREAD : c_int = 256; - pub static S_IRWXU : c_int = 448; - pub static S_IXUSR : c_int = 64; - pub static S_IWUSR : c_int = 128; - pub static S_IRUSR : c_int = 256; - pub static F_OK : c_int = 0; - pub static R_OK : c_int = 4; - pub static W_OK : c_int = 2; - pub static X_OK : c_int = 1; - pub static STDIN_FILENO : c_int = 0; - pub static STDOUT_FILENO : c_int = 1; - pub static STDERR_FILENO : c_int = 2; + pub const O_RDONLY : c_int = 0; + pub const O_WRONLY : c_int = 1; + pub const O_RDWR : c_int = 2; + pub const O_APPEND : c_int = 8; + pub const O_CREAT : c_int = 256; + pub const O_EXCL : c_int = 1024; + pub const O_TRUNC : c_int = 512; + pub const S_IFIFO : c_int = 4096; + pub const S_IFCHR : c_int = 8192; + pub const S_IFBLK : c_int = 12288; + pub const S_IFDIR : c_int = 16384; + pub const S_IFREG : c_int = 32768; + pub const S_IFLNK : c_int = 40960; + pub const S_IFMT : c_int = 61440; + pub const S_IEXEC : c_int = 64; + pub const S_IWRITE : c_int = 128; + pub const S_IREAD : c_int = 256; + pub const S_IRWXU : c_int = 448; + pub const S_IXUSR : c_int = 64; + pub const S_IWUSR : c_int = 128; + pub const S_IRUSR : c_int = 256; + pub const F_OK : c_int = 0; + pub const R_OK : c_int = 4; + pub const W_OK : c_int = 2; + pub const X_OK : c_int = 1; + pub const STDIN_FILENO : c_int = 0; + pub const STDOUT_FILENO : c_int = 1; + pub const STDERR_FILENO : c_int = 2; } pub mod posix01 { } @@ -2113,265 +2113,265 @@ pub mod consts { pub mod bsd44 { use types::os::arch::c95::c_int; - pub static AF_INET: c_int = 2; - pub static AF_INET6: c_int = 23; - pub static SOCK_STREAM: c_int = 1; - pub static SOCK_DGRAM: c_int = 2; - pub static SOCK_RAW: c_int = 3; - pub static IPPROTO_TCP: c_int = 6; - pub static IPPROTO_IP: c_int = 0; - pub static IPPROTO_IPV6: c_int = 41; - pub static IP_MULTICAST_TTL: c_int = 3; - pub static IP_MULTICAST_LOOP: c_int = 4; - pub static IP_ADD_MEMBERSHIP: c_int = 5; - pub static IP_DROP_MEMBERSHIP: c_int = 6; - pub static IPV6_ADD_MEMBERSHIP: c_int = 5; - pub static IPV6_DROP_MEMBERSHIP: c_int = 6; - pub static IP_TTL: c_int = 4; - pub static IP_HDRINCL: c_int = 2; - - pub static TCP_NODELAY: c_int = 0x0001; - pub static SOL_SOCKET: c_int = 0xffff; - pub static SO_KEEPALIVE: c_int = 8; - pub static SO_BROADCAST: c_int = 32; - pub static SO_REUSEADDR: c_int = 4; - pub static SO_ERROR: c_int = 0x1007; - - pub static IFF_LOOPBACK: c_int = 4; - - pub static SHUT_RD: c_int = 0; - pub static SHUT_WR: c_int = 1; - pub static SHUT_RDWR: c_int = 2; + pub const AF_INET: c_int = 2; + pub const AF_INET6: c_int = 23; + pub const SOCK_STREAM: c_int = 1; + pub const SOCK_DGRAM: c_int = 2; + pub const SOCK_RAW: c_int = 3; + pub const IPPROTO_TCP: c_int = 6; + pub const IPPROTO_IP: c_int = 0; + pub const IPPROTO_IPV6: c_int = 41; + pub const IP_MULTICAST_TTL: c_int = 3; + pub const IP_MULTICAST_LOOP: c_int = 4; + pub const IP_ADD_MEMBERSHIP: c_int = 5; + pub const IP_DROP_MEMBERSHIP: c_int = 6; + pub const IPV6_ADD_MEMBERSHIP: c_int = 5; + pub const IPV6_DROP_MEMBERSHIP: c_int = 6; + pub const IP_TTL: c_int = 4; + pub const IP_HDRINCL: c_int = 2; + + pub const TCP_NODELAY: c_int = 0x0001; + pub const SOL_SOCKET: c_int = 0xffff; + pub const SO_KEEPALIVE: c_int = 8; + pub const SO_BROADCAST: c_int = 32; + pub const SO_REUSEADDR: c_int = 4; + pub const SO_ERROR: c_int = 0x1007; + + pub const IFF_LOOPBACK: c_int = 4; + + pub const SHUT_RD: c_int = 0; + pub const SHUT_WR: c_int = 1; + pub const SHUT_RDWR: c_int = 2; } pub mod extra { use types::os::arch::c95::{c_int, c_long}; use types::os::arch::extra::{WORD, DWORD, BOOL, HANDLE}; - pub static TRUE : BOOL = 1; - pub static FALSE : BOOL = 0; - - pub static O_TEXT : c_int = 16384; - pub static O_BINARY : c_int = 32768; - pub static O_NOINHERIT: c_int = 128; - - pub static ERROR_SUCCESS : c_int = 0; - pub static ERROR_INVALID_FUNCTION: c_int = 1; - pub static ERROR_FILE_NOT_FOUND: c_int = 2; - pub static ERROR_ACCESS_DENIED: c_int = 5; - pub static ERROR_INVALID_HANDLE : c_int = 6; - pub static ERROR_BROKEN_PIPE: c_int = 109; - pub static ERROR_DISK_FULL : c_int = 112; - pub static ERROR_CALL_NOT_IMPLEMENTED : c_int = 120; - pub static ERROR_INSUFFICIENT_BUFFER : c_int = 122; - pub static ERROR_INVALID_NAME : c_int = 123; - pub static ERROR_ALREADY_EXISTS : c_int = 183; - pub static ERROR_PIPE_BUSY: c_int = 231; - pub static ERROR_NO_DATA: c_int = 232; - pub static ERROR_INVALID_ADDRESS : c_int = 487; - pub static ERROR_PIPE_CONNECTED: c_int = 535; - pub static ERROR_NOTHING_TO_TERMINATE: c_int = 758; - pub static ERROR_OPERATION_ABORTED: c_int = 995; - pub static ERROR_IO_PENDING: c_int = 997; - pub static ERROR_FILE_INVALID : c_int = 1006; - pub static ERROR_NOT_FOUND: c_int = 1168; - pub static INVALID_HANDLE_VALUE: HANDLE = -1 as HANDLE; - - pub static DELETE : DWORD = 0x00010000; - pub static READ_CONTROL : DWORD = 0x00020000; - pub static SYNCHRONIZE : DWORD = 0x00100000; - pub static WRITE_DAC : DWORD = 0x00040000; - pub static WRITE_OWNER : DWORD = 0x00080000; - - pub static PROCESS_CREATE_PROCESS : DWORD = 0x0080; - pub static PROCESS_CREATE_THREAD : DWORD = 0x0002; - pub static PROCESS_DUP_HANDLE : DWORD = 0x0040; - pub static PROCESS_QUERY_INFORMATION : DWORD = 0x0400; - pub static PROCESS_QUERY_LIMITED_INFORMATION : DWORD = 0x1000; - pub static PROCESS_SET_INFORMATION : DWORD = 0x0200; - pub static PROCESS_SET_QUOTA : DWORD = 0x0100; - pub static PROCESS_SUSPEND_RESUME : DWORD = 0x0800; - pub static PROCESS_TERMINATE : DWORD = 0x0001; - pub static PROCESS_VM_OPERATION : DWORD = 0x0008; - pub static PROCESS_VM_READ : DWORD = 0x0010; - pub static PROCESS_VM_WRITE : DWORD = 0x0020; - - pub static STARTF_FORCEONFEEDBACK : DWORD = 0x00000040; - pub static STARTF_FORCEOFFFEEDBACK : DWORD = 0x00000080; - pub static STARTF_PREVENTPINNING : DWORD = 0x00002000; - pub static STARTF_RUNFULLSCREEN : DWORD = 0x00000020; - pub static STARTF_TITLEISAPPID : DWORD = 0x00001000; - pub static STARTF_TITLEISLINKNAME : DWORD = 0x00000800; - pub static STARTF_USECOUNTCHARS : DWORD = 0x00000008; - pub static STARTF_USEFILLATTRIBUTE : DWORD = 0x00000010; - pub static STARTF_USEHOTKEY : DWORD = 0x00000200; - pub static STARTF_USEPOSITION : DWORD = 0x00000004; - pub static STARTF_USESHOWWINDOW : DWORD = 0x00000001; - pub static STARTF_USESIZE : DWORD = 0x00000002; - pub static STARTF_USESTDHANDLES : DWORD = 0x00000100; - - pub static WAIT_ABANDONED : DWORD = 0x00000080; - pub static WAIT_OBJECT_0 : DWORD = 0x00000000; - pub static WAIT_TIMEOUT : DWORD = 0x00000102; - pub static WAIT_FAILED : DWORD = -1; - - pub static DUPLICATE_CLOSE_SOURCE : DWORD = 0x00000001; - pub static DUPLICATE_SAME_ACCESS : DWORD = 0x00000002; - - pub static INFINITE : DWORD = -1; - pub static STILL_ACTIVE : DWORD = 259; - - pub static MEM_COMMIT : DWORD = 0x00001000; - pub static MEM_RESERVE : DWORD = 0x00002000; - pub static MEM_DECOMMIT : DWORD = 0x00004000; - pub static MEM_RELEASE : DWORD = 0x00008000; - pub static MEM_RESET : DWORD = 0x00080000; - pub static MEM_RESET_UNDO : DWORD = 0x1000000; - pub static MEM_LARGE_PAGES : DWORD = 0x20000000; - pub static MEM_PHYSICAL : DWORD = 0x00400000; - pub static MEM_TOP_DOWN : DWORD = 0x00100000; - pub static MEM_WRITE_WATCH : DWORD = 0x00200000; - - pub static PAGE_EXECUTE : DWORD = 0x10; - pub static PAGE_EXECUTE_READ : DWORD = 0x20; - pub static PAGE_EXECUTE_READWRITE : DWORD = 0x40; - pub static PAGE_EXECUTE_WRITECOPY : DWORD = 0x80; - pub static PAGE_NOACCESS : DWORD = 0x01; - pub static PAGE_READONLY : DWORD = 0x02; - pub static PAGE_READWRITE : DWORD = 0x04; - pub static PAGE_WRITECOPY : DWORD = 0x08; - pub static PAGE_GUARD : DWORD = 0x100; - pub static PAGE_NOCACHE : DWORD = 0x200; - pub static PAGE_WRITECOMBINE : DWORD = 0x400; - - pub static SEC_COMMIT : DWORD = 0x8000000; - pub static SEC_IMAGE : DWORD = 0x1000000; - pub static SEC_IMAGE_NO_EXECUTE : DWORD = 0x11000000; - pub static SEC_LARGE_PAGES : DWORD = 0x80000000; - pub static SEC_NOCACHE : DWORD = 0x10000000; - pub static SEC_RESERVE : DWORD = 0x4000000; - pub static SEC_WRITECOMBINE : DWORD = 0x40000000; - - pub static FILE_MAP_ALL_ACCESS : DWORD = 0xf001f; - pub static FILE_MAP_READ : DWORD = 0x4; - pub static FILE_MAP_WRITE : DWORD = 0x2; - pub static FILE_MAP_COPY : DWORD = 0x1; - pub static FILE_MAP_EXECUTE : DWORD = 0x20; - - pub static PROCESSOR_ARCHITECTURE_INTEL : WORD = 0; - pub static PROCESSOR_ARCHITECTURE_ARM : WORD = 5; - pub static PROCESSOR_ARCHITECTURE_IA64 : WORD = 6; - pub static PROCESSOR_ARCHITECTURE_AMD64 : WORD = 9; - pub static PROCESSOR_ARCHITECTURE_UNKNOWN : WORD = 0xffff; - - pub static MOVEFILE_COPY_ALLOWED: DWORD = 2; - pub static MOVEFILE_CREATE_HARDLINK: DWORD = 16; - pub static MOVEFILE_DELAY_UNTIL_REBOOT: DWORD = 4; - pub static MOVEFILE_FAIL_IF_NOT_TRACKABLE: DWORD = 32; - pub static MOVEFILE_REPLACE_EXISTING: DWORD = 1; - pub static MOVEFILE_WRITE_THROUGH: DWORD = 8; - - pub static SYMBOLIC_LINK_FLAG_DIRECTORY: DWORD = 1; - - pub static FILE_SHARE_DELETE: DWORD = 0x4; - pub static FILE_SHARE_READ: DWORD = 0x1; - pub static FILE_SHARE_WRITE: DWORD = 0x2; - - pub static CREATE_ALWAYS: DWORD = 2; - pub static CREATE_NEW: DWORD = 1; - pub static OPEN_ALWAYS: DWORD = 4; - pub static OPEN_EXISTING: DWORD = 3; - pub static TRUNCATE_EXISTING: DWORD = 5; - - pub static FILE_APPEND_DATA: DWORD = 0x00000004; - pub static FILE_READ_DATA: DWORD = 0x00000001; - pub static FILE_WRITE_DATA: DWORD = 0x00000002; - - pub static FILE_ATTRIBUTE_ARCHIVE: DWORD = 0x20; - pub static FILE_ATTRIBUTE_COMPRESSED: DWORD = 0x800; - pub static FILE_ATTRIBUTE_DEVICE: DWORD = 0x40; - pub static FILE_ATTRIBUTE_DIRECTORY: DWORD = 0x10; - pub static FILE_ATTRIBUTE_ENCRYPTED: DWORD = 0x4000; - pub static FILE_ATTRIBUTE_HIDDEN: DWORD = 0x2; - pub static FILE_ATTRIBUTE_INTEGRITY_STREAM: DWORD = 0x8000; - pub static FILE_ATTRIBUTE_NORMAL: DWORD = 0x80; - pub static FILE_ATTRIBUTE_NOT_CONTENT_INDEXED: DWORD = 0x2000; - pub static FILE_ATTRIBUTE_NO_SCRUB_DATA: DWORD = 0x20000; - pub static FILE_ATTRIBUTE_OFFLINE: DWORD = 0x1000; - pub static FILE_ATTRIBUTE_READONLY: DWORD = 0x1; - pub static FILE_ATTRIBUTE_REPARSE_POINT: DWORD = 0x400; - pub static FILE_ATTRIBUTE_SPARSE_FILE: DWORD = 0x200; - pub static FILE_ATTRIBUTE_SYSTEM: DWORD = 0x4; - pub static FILE_ATTRIBUTE_TEMPORARY: DWORD = 0x100; - pub static FILE_ATTRIBUTE_VIRTUAL: DWORD = 0x10000; - - pub static FILE_FLAG_BACKUP_SEMANTICS: DWORD = 0x02000000; - pub static FILE_FLAG_DELETE_ON_CLOSE: DWORD = 0x04000000; - pub static FILE_FLAG_NO_BUFFERING: DWORD = 0x20000000; - pub static FILE_FLAG_OPEN_NO_RECALL: DWORD = 0x00100000; - pub static FILE_FLAG_OPEN_REPARSE_POINT: DWORD = 0x00200000; - pub static FILE_FLAG_OVERLAPPED: DWORD = 0x40000000; - pub static FILE_FLAG_POSIX_SEMANTICS: DWORD = 0x0100000; - pub static FILE_FLAG_RANDOM_ACCESS: DWORD = 0x10000000; - pub static FILE_FLAG_SESSION_AWARE: DWORD = 0x00800000; - pub static FILE_FLAG_SEQUENTIAL_SCAN: DWORD = 0x08000000; - pub static FILE_FLAG_WRITE_THROUGH: DWORD = 0x80000000; - pub static FILE_FLAG_FIRST_PIPE_INSTANCE: DWORD = 0x00080000; - - pub static FILE_NAME_NORMALIZED: DWORD = 0x0; - pub static FILE_NAME_OPENED: DWORD = 0x8; - - pub static VOLUME_NAME_DOS: DWORD = 0x0; - pub static VOLUME_NAME_GUID: DWORD = 0x1; - pub static VOLUME_NAME_NONE: DWORD = 0x4; - pub static VOLUME_NAME_NT: DWORD = 0x2; - - pub static GENERIC_READ: DWORD = 0x80000000; - pub static GENERIC_WRITE: DWORD = 0x40000000; - pub static GENERIC_EXECUTE: DWORD = 0x20000000; - pub static GENERIC_ALL: DWORD = 0x10000000; - pub static FILE_WRITE_ATTRIBUTES: DWORD = 0x00000100; - pub static FILE_READ_ATTRIBUTES: DWORD = 0x00000080; - - pub static STANDARD_RIGHTS_READ: DWORD = 0x20000; - pub static STANDARD_RIGHTS_WRITE: DWORD = 0x20000; - pub static FILE_WRITE_EA: DWORD = 0x00000010; - pub static FILE_READ_EA: DWORD = 0x00000008; - pub static FILE_GENERIC_READ: DWORD = + pub const TRUE : BOOL = 1; + pub const FALSE : BOOL = 0; + + pub const O_TEXT : c_int = 16384; + pub const O_BINARY : c_int = 32768; + pub const O_NOINHERIT: c_int = 128; + + pub const ERROR_SUCCESS : c_int = 0; + pub const ERROR_INVALID_FUNCTION: c_int = 1; + pub const ERROR_FILE_NOT_FOUND: c_int = 2; + pub const ERROR_ACCESS_DENIED: c_int = 5; + pub const ERROR_INVALID_HANDLE : c_int = 6; + pub const ERROR_BROKEN_PIPE: c_int = 109; + pub const ERROR_DISK_FULL : c_int = 112; + pub const ERROR_CALL_NOT_IMPLEMENTED : c_int = 120; + pub const ERROR_INSUFFICIENT_BUFFER : c_int = 122; + pub const ERROR_INVALID_NAME : c_int = 123; + pub const ERROR_ALREADY_EXISTS : c_int = 183; + pub const ERROR_PIPE_BUSY: c_int = 231; + pub const ERROR_NO_DATA: c_int = 232; + pub const ERROR_INVALID_ADDRESS : c_int = 487; + pub const ERROR_PIPE_CONNECTED: c_int = 535; + pub const ERROR_NOTHING_TO_TERMINATE: c_int = 758; + pub const ERROR_OPERATION_ABORTED: c_int = 995; + pub const ERROR_IO_PENDING: c_int = 997; + pub const ERROR_FILE_INVALID : c_int = 1006; + pub const ERROR_NOT_FOUND: c_int = 1168; + pub const INVALID_HANDLE_VALUE: HANDLE = -1 as HANDLE; + + pub const DELETE : DWORD = 0x00010000; + pub const READ_CONTROL : DWORD = 0x00020000; + pub const SYNCHRONIZE : DWORD = 0x00100000; + pub const WRITE_DAC : DWORD = 0x00040000; + pub const WRITE_OWNER : DWORD = 0x00080000; + + pub const PROCESS_CREATE_PROCESS : DWORD = 0x0080; + pub const PROCESS_CREATE_THREAD : DWORD = 0x0002; + pub const PROCESS_DUP_HANDLE : DWORD = 0x0040; + pub const PROCESS_QUERY_INFORMATION : DWORD = 0x0400; + pub const PROCESS_QUERY_LIMITED_INFORMATION : DWORD = 0x1000; + pub const PROCESS_SET_INFORMATION : DWORD = 0x0200; + pub const PROCESS_SET_QUOTA : DWORD = 0x0100; + pub const PROCESS_SUSPEND_RESUME : DWORD = 0x0800; + pub const PROCESS_TERMINATE : DWORD = 0x0001; + pub const PROCESS_VM_OPERATION : DWORD = 0x0008; + pub const PROCESS_VM_READ : DWORD = 0x0010; + pub const PROCESS_VM_WRITE : DWORD = 0x0020; + + pub const STARTF_FORCEONFEEDBACK : DWORD = 0x00000040; + pub const STARTF_FORCEOFFFEEDBACK : DWORD = 0x00000080; + pub const STARTF_PREVENTPINNING : DWORD = 0x00002000; + pub const STARTF_RUNFULLSCREEN : DWORD = 0x00000020; + pub const STARTF_TITLEISAPPID : DWORD = 0x00001000; + pub const STARTF_TITLEISLINKNAME : DWORD = 0x00000800; + pub const STARTF_USECOUNTCHARS : DWORD = 0x00000008; + pub const STARTF_USEFILLATTRIBUTE : DWORD = 0x00000010; + pub const STARTF_USEHOTKEY : DWORD = 0x00000200; + pub const STARTF_USEPOSITION : DWORD = 0x00000004; + pub const STARTF_USESHOWWINDOW : DWORD = 0x00000001; + pub const STARTF_USESIZE : DWORD = 0x00000002; + pub const STARTF_USESTDHANDLES : DWORD = 0x00000100; + + pub const WAIT_ABANDONED : DWORD = 0x00000080; + pub const WAIT_OBJECT_0 : DWORD = 0x00000000; + pub const WAIT_TIMEOUT : DWORD = 0x00000102; + pub const WAIT_FAILED : DWORD = -1; + + pub const DUPLICATE_CLOSE_SOURCE : DWORD = 0x00000001; + pub const DUPLICATE_SAME_ACCESS : DWORD = 0x00000002; + + pub const INFINITE : DWORD = -1; + pub const STILL_ACTIVE : DWORD = 259; + + pub const MEM_COMMIT : DWORD = 0x00001000; + pub const MEM_RESERVE : DWORD = 0x00002000; + pub const MEM_DECOMMIT : DWORD = 0x00004000; + pub const MEM_RELEASE : DWORD = 0x00008000; + pub const MEM_RESET : DWORD = 0x00080000; + pub const MEM_RESET_UNDO : DWORD = 0x1000000; + pub const MEM_LARGE_PAGES : DWORD = 0x20000000; + pub const MEM_PHYSICAL : DWORD = 0x00400000; + pub const MEM_TOP_DOWN : DWORD = 0x00100000; + pub const MEM_WRITE_WATCH : DWORD = 0x00200000; + + pub const PAGE_EXECUTE : DWORD = 0x10; + pub const PAGE_EXECUTE_READ : DWORD = 0x20; + pub const PAGE_EXECUTE_READWRITE : DWORD = 0x40; + pub const PAGE_EXECUTE_WRITECOPY : DWORD = 0x80; + pub const PAGE_NOACCESS : DWORD = 0x01; + pub const PAGE_READONLY : DWORD = 0x02; + pub const PAGE_READWRITE : DWORD = 0x04; + pub const PAGE_WRITECOPY : DWORD = 0x08; + pub const PAGE_GUARD : DWORD = 0x100; + pub const PAGE_NOCACHE : DWORD = 0x200; + pub const PAGE_WRITECOMBINE : DWORD = 0x400; + + pub const SEC_COMMIT : DWORD = 0x8000000; + pub const SEC_IMAGE : DWORD = 0x1000000; + pub const SEC_IMAGE_NO_EXECUTE : DWORD = 0x11000000; + pub const SEC_LARGE_PAGES : DWORD = 0x80000000; + pub const SEC_NOCACHE : DWORD = 0x10000000; + pub const SEC_RESERVE : DWORD = 0x4000000; + pub const SEC_WRITECOMBINE : DWORD = 0x40000000; + + pub const FILE_MAP_ALL_ACCESS : DWORD = 0xf001f; + pub const FILE_MAP_READ : DWORD = 0x4; + pub const FILE_MAP_WRITE : DWORD = 0x2; + pub const FILE_MAP_COPY : DWORD = 0x1; + pub const FILE_MAP_EXECUTE : DWORD = 0x20; + + pub const PROCESSOR_ARCHITECTURE_INTEL : WORD = 0; + pub const PROCESSOR_ARCHITECTURE_ARM : WORD = 5; + pub const PROCESSOR_ARCHITECTURE_IA64 : WORD = 6; + pub const PROCESSOR_ARCHITECTURE_AMD64 : WORD = 9; + pub const PROCESSOR_ARCHITECTURE_UNKNOWN : WORD = 0xffff; + + pub const MOVEFILE_COPY_ALLOWED: DWORD = 2; + pub const MOVEFILE_CREATE_HARDLINK: DWORD = 16; + pub const MOVEFILE_DELAY_UNTIL_REBOOT: DWORD = 4; + pub const MOVEFILE_FAIL_IF_NOT_TRACKABLE: DWORD = 32; + pub const MOVEFILE_REPLACE_EXISTING: DWORD = 1; + pub const MOVEFILE_WRITE_THROUGH: DWORD = 8; + + pub const SYMBOLIC_LINK_FLAG_DIRECTORY: DWORD = 1; + + pub const FILE_SHARE_DELETE: DWORD = 0x4; + pub const FILE_SHARE_READ: DWORD = 0x1; + pub const FILE_SHARE_WRITE: DWORD = 0x2; + + pub const CREATE_ALWAYS: DWORD = 2; + pub const CREATE_NEW: DWORD = 1; + pub const OPEN_ALWAYS: DWORD = 4; + pub const OPEN_EXISTING: DWORD = 3; + pub const TRUNCATE_EXISTING: DWORD = 5; + + pub const FILE_APPEND_DATA: DWORD = 0x00000004; + pub const FILE_READ_DATA: DWORD = 0x00000001; + pub const FILE_WRITE_DATA: DWORD = 0x00000002; + + pub const FILE_ATTRIBUTE_ARCHIVE: DWORD = 0x20; + pub const FILE_ATTRIBUTE_COMPRESSED: DWORD = 0x800; + pub const FILE_ATTRIBUTE_DEVICE: DWORD = 0x40; + pub const FILE_ATTRIBUTE_DIRECTORY: DWORD = 0x10; + pub const FILE_ATTRIBUTE_ENCRYPTED: DWORD = 0x4000; + pub const FILE_ATTRIBUTE_HIDDEN: DWORD = 0x2; + pub const FILE_ATTRIBUTE_INTEGRITY_STREAM: DWORD = 0x8000; + pub const FILE_ATTRIBUTE_NORMAL: DWORD = 0x80; + pub const FILE_ATTRIBUTE_NOT_CONTENT_INDEXED: DWORD = 0x2000; + pub const FILE_ATTRIBUTE_NO_SCRUB_DATA: DWORD = 0x20000; + pub const FILE_ATTRIBUTE_OFFLINE: DWORD = 0x1000; + pub const FILE_ATTRIBUTE_READONLY: DWORD = 0x1; + pub const FILE_ATTRIBUTE_REPARSE_POINT: DWORD = 0x400; + pub const FILE_ATTRIBUTE_SPARSE_FILE: DWORD = 0x200; + pub const FILE_ATTRIBUTE_SYSTEM: DWORD = 0x4; + pub const FILE_ATTRIBUTE_TEMPORARY: DWORD = 0x100; + pub const FILE_ATTRIBUTE_VIRTUAL: DWORD = 0x10000; + + pub const FILE_FLAG_BACKUP_SEMANTICS: DWORD = 0x02000000; + pub const FILE_FLAG_DELETE_ON_CLOSE: DWORD = 0x04000000; + pub const FILE_FLAG_NO_BUFFERING: DWORD = 0x20000000; + pub const FILE_FLAG_OPEN_NO_RECALL: DWORD = 0x00100000; + pub const FILE_FLAG_OPEN_REPARSE_POINT: DWORD = 0x00200000; + pub const FILE_FLAG_OVERLAPPED: DWORD = 0x40000000; + pub const FILE_FLAG_POSIX_SEMANTICS: DWORD = 0x0100000; + pub const FILE_FLAG_RANDOM_ACCESS: DWORD = 0x10000000; + pub const FILE_FLAG_SESSION_AWARE: DWORD = 0x00800000; + pub const FILE_FLAG_SEQUENTIAL_SCAN: DWORD = 0x08000000; + pub const FILE_FLAG_WRITE_THROUGH: DWORD = 0x80000000; + pub const FILE_FLAG_FIRST_PIPE_INSTANCE: DWORD = 0x00080000; + + pub const FILE_NAME_NORMALIZED: DWORD = 0x0; + pub const FILE_NAME_OPENED: DWORD = 0x8; + + pub const VOLUME_NAME_DOS: DWORD = 0x0; + pub const VOLUME_NAME_GUID: DWORD = 0x1; + pub const VOLUME_NAME_NONE: DWORD = 0x4; + pub const VOLUME_NAME_NT: DWORD = 0x2; + + pub const GENERIC_READ: DWORD = 0x80000000; + pub const GENERIC_WRITE: DWORD = 0x40000000; + pub const GENERIC_EXECUTE: DWORD = 0x20000000; + pub const GENERIC_ALL: DWORD = 0x10000000; + pub const FILE_WRITE_ATTRIBUTES: DWORD = 0x00000100; + pub const FILE_READ_ATTRIBUTES: DWORD = 0x00000080; + + pub const STANDARD_RIGHTS_READ: DWORD = 0x20000; + pub const STANDARD_RIGHTS_WRITE: DWORD = 0x20000; + pub const FILE_WRITE_EA: DWORD = 0x00000010; + pub const FILE_READ_EA: DWORD = 0x00000008; + pub const FILE_GENERIC_READ: DWORD = STANDARD_RIGHTS_READ | FILE_READ_DATA | FILE_READ_ATTRIBUTES | FILE_READ_EA | SYNCHRONIZE; - pub static FILE_GENERIC_WRITE: DWORD = + pub const FILE_GENERIC_WRITE: DWORD = STANDARD_RIGHTS_WRITE | FILE_WRITE_DATA | FILE_WRITE_ATTRIBUTES | FILE_WRITE_EA | FILE_APPEND_DATA | SYNCHRONIZE; - pub static FILE_BEGIN: DWORD = 0; - pub static FILE_CURRENT: DWORD = 1; - pub static FILE_END: DWORD = 2; - - pub static MAX_PROTOCOL_CHAIN: DWORD = 7; - pub static WSAPROTOCOL_LEN: DWORD = 255; - pub static INVALID_SOCKET: DWORD = !0; - - pub static DETACHED_PROCESS: DWORD = 0x00000008; - pub static CREATE_NEW_PROCESS_GROUP: DWORD = 0x00000200; - pub static CREATE_UNICODE_ENVIRONMENT: DWORD = 0x00000400; - - pub static PIPE_ACCESS_DUPLEX: DWORD = 0x00000003; - pub static PIPE_ACCESS_INBOUND: DWORD = 0x00000001; - pub static PIPE_ACCESS_OUTBOUND: DWORD = 0x00000002; - pub static PIPE_TYPE_BYTE: DWORD = 0x00000000; - pub static PIPE_TYPE_MESSAGE: DWORD = 0x00000004; - pub static PIPE_READMODE_BYTE: DWORD = 0x00000000; - pub static PIPE_READMODE_MESSAGE: DWORD = 0x00000002; - pub static PIPE_WAIT: DWORD = 0x00000000; - pub static PIPE_NOWAIT: DWORD = 0x00000001; - pub static PIPE_ACCEPT_REMOTE_CLIENTS: DWORD = 0x00000000; - pub static PIPE_REJECT_REMOTE_CLIENTS: DWORD = 0x00000008; - pub static PIPE_UNLIMITED_INSTANCES: DWORD = 255; - - pub static IPPROTO_RAW: c_int = 255; - - pub static FIONBIO: c_long = -0x7FFB9982; + pub const FILE_BEGIN: DWORD = 0; + pub const FILE_CURRENT: DWORD = 1; + pub const FILE_END: DWORD = 2; + + pub const MAX_PROTOCOL_CHAIN: DWORD = 7; + pub const WSAPROTOCOL_LEN: DWORD = 255; + pub const INVALID_SOCKET: DWORD = !0; + + pub const DETACHED_PROCESS: DWORD = 0x00000008; + pub const CREATE_NEW_PROCESS_GROUP: DWORD = 0x00000200; + pub const CREATE_UNICODE_ENVIRONMENT: DWORD = 0x00000400; + + pub const PIPE_ACCESS_DUPLEX: DWORD = 0x00000003; + pub const PIPE_ACCESS_INBOUND: DWORD = 0x00000001; + pub const PIPE_ACCESS_OUTBOUND: DWORD = 0x00000002; + pub const PIPE_TYPE_BYTE: DWORD = 0x00000000; + pub const PIPE_TYPE_MESSAGE: DWORD = 0x00000004; + pub const PIPE_READMODE_BYTE: DWORD = 0x00000000; + pub const PIPE_READMODE_MESSAGE: DWORD = 0x00000002; + pub const PIPE_WAIT: DWORD = 0x00000000; + pub const PIPE_NOWAIT: DWORD = 0x00000001; + pub const PIPE_ACCEPT_REMOTE_CLIENTS: DWORD = 0x00000000; + pub const PIPE_REJECT_REMOTE_CLIENTS: DWORD = 0x00000008; + pub const PIPE_UNLIMITED_INSTANCES: DWORD = 255; + + pub const IPPROTO_RAW: c_int = 255; + + pub const FIONBIO: c_long = -0x7FFB9982; } pub mod sysconf { } @@ -2383,21 +2383,21 @@ pub mod consts { pub mod c95 { use types::os::arch::c95::{c_int, c_uint}; - pub static EXIT_FAILURE : c_int = 1; - pub static EXIT_SUCCESS : c_int = 0; - pub static RAND_MAX : c_int = 2147483647; - pub static EOF : c_int = -1; - pub static SEEK_SET : c_int = 0; - pub static SEEK_CUR : c_int = 1; - pub static SEEK_END : c_int = 2; - pub static _IOFBF : c_int = 0; - pub static _IONBF : c_int = 2; - pub static _IOLBF : c_int = 1; - pub static BUFSIZ : c_uint = 8192_u32; - pub static FOPEN_MAX : c_uint = 16_u32; - pub static FILENAME_MAX : c_uint = 4096_u32; - pub static L_tmpnam : c_uint = 20_u32; - pub static TMP_MAX : c_uint = 238328_u32; + pub const EXIT_FAILURE : c_int = 1; + pub const EXIT_SUCCESS : c_int = 0; + pub const RAND_MAX : c_int = 2147483647; + pub const EOF : c_int = -1; + pub const SEEK_SET : c_int = 0; + pub const SEEK_CUR : c_int = 1; + pub const SEEK_END : c_int = 2; + pub const _IOFBF : c_int = 0; + pub const _IONBF : c_int = 2; + pub const _IOLBF : c_int = 1; + pub const BUFSIZ : c_uint = 8192_u32; + pub const FOPEN_MAX : c_uint = 16_u32; + pub const FILENAME_MAX : c_uint = 4096_u32; + pub const L_tmpnam : c_uint = 20_u32; + pub const TMP_MAX : c_uint = 238328_u32; } pub mod c99 { } @@ -2409,210 +2409,210 @@ pub mod consts { use types::common::c95::c_void; use types::os::arch::posix88::mode_t; - pub static O_RDONLY : c_int = 0; - pub static O_WRONLY : c_int = 1; - pub static O_RDWR : c_int = 2; - pub static O_APPEND : c_int = 1024; - pub static O_CREAT : c_int = 64; - pub static O_EXCL : c_int = 128; - pub static O_TRUNC : c_int = 512; - pub static S_IFIFO : mode_t = 4096; - pub static S_IFCHR : mode_t = 8192; - pub static S_IFBLK : mode_t = 24576; - pub static S_IFDIR : mode_t = 16384; - pub static S_IFREG : mode_t = 32768; - pub static S_IFLNK : mode_t = 40960; - pub static S_IFMT : mode_t = 61440; - pub static S_IEXEC : mode_t = 64; - pub static S_IWRITE : mode_t = 128; - pub static S_IREAD : mode_t = 256; - pub static S_IRWXU : mode_t = 448; - pub static S_IXUSR : mode_t = 64; - pub static S_IWUSR : mode_t = 128; - pub static S_IRUSR : mode_t = 256; - pub static F_OK : c_int = 0; - pub static R_OK : c_int = 4; - pub static W_OK : c_int = 2; - pub static X_OK : c_int = 1; - pub static STDIN_FILENO : c_int = 0; - pub static STDOUT_FILENO : c_int = 1; - pub static STDERR_FILENO : c_int = 2; - pub static F_LOCK : c_int = 1; - pub static F_TEST : c_int = 3; - pub static F_TLOCK : c_int = 2; - pub static F_ULOCK : c_int = 0; - pub static SIGHUP : c_int = 1; - pub static SIGINT : c_int = 2; - pub static SIGQUIT : c_int = 3; - pub static SIGILL : c_int = 4; - pub static SIGABRT : c_int = 6; - pub static SIGFPE : c_int = 8; - pub static SIGKILL : c_int = 9; - pub static SIGSEGV : c_int = 11; - pub static SIGPIPE : c_int = 13; - pub static SIGALRM : c_int = 14; - pub static SIGTERM : c_int = 15; - - pub static PROT_NONE : c_int = 0; - pub static PROT_READ : c_int = 1; - pub static PROT_WRITE : c_int = 2; - pub static PROT_EXEC : c_int = 4; - - pub static MAP_FILE : c_int = 0x0000; - pub static MAP_SHARED : c_int = 0x0001; - pub static MAP_PRIVATE : c_int = 0x0002; - pub static MAP_FIXED : c_int = 0x0010; - pub static MAP_ANON : c_int = 0x0020; - - pub static MAP_FAILED : *mut c_void = -1 as *mut c_void; - - pub static MCL_CURRENT : c_int = 0x0001; - pub static MCL_FUTURE : c_int = 0x0002; - - pub static MS_ASYNC : c_int = 0x0001; - pub static MS_INVALIDATE : c_int = 0x0002; - pub static MS_SYNC : c_int = 0x0004; - - pub static EPERM : c_int = 1; - pub static ENOENT : c_int = 2; - pub static ESRCH : c_int = 3; - pub static EINTR : c_int = 4; - pub static EIO : c_int = 5; - pub static ENXIO : c_int = 6; - pub static E2BIG : c_int = 7; - pub static ENOEXEC : c_int = 8; - pub static EBADF : c_int = 9; - pub static ECHILD : c_int = 10; - pub static EAGAIN : c_int = 11; - pub static ENOMEM : c_int = 12; - pub static EACCES : c_int = 13; - pub static EFAULT : c_int = 14; - pub static ENOTBLK : c_int = 15; - pub static EBUSY : c_int = 16; - pub static EEXIST : c_int = 17; - pub static EXDEV : c_int = 18; - pub static ENODEV : c_int = 19; - pub static ENOTDIR : c_int = 20; - pub static EISDIR : c_int = 21; - pub static EINVAL : c_int = 22; - pub static ENFILE : c_int = 23; - pub static EMFILE : c_int = 24; - pub static ENOTTY : c_int = 25; - pub static ETXTBSY : c_int = 26; - pub static EFBIG : c_int = 27; - pub static ENOSPC : c_int = 28; - pub static ESPIPE : c_int = 29; - pub static EROFS : c_int = 30; - pub static EMLINK : c_int = 31; - pub static EPIPE : c_int = 32; - pub static EDOM : c_int = 33; - pub static ERANGE : c_int = 34; - - pub static EDEADLK: c_int = 35; - pub static ENAMETOOLONG: c_int = 36; - pub static ENOLCK: c_int = 37; - pub static ENOSYS: c_int = 38; - pub static ENOTEMPTY: c_int = 39; - pub static ELOOP: c_int = 40; - pub static EWOULDBLOCK: c_int = EAGAIN; - pub static ENOMSG: c_int = 42; - pub static EIDRM: c_int = 43; - pub static ECHRNG: c_int = 44; - pub static EL2NSYNC: c_int = 45; - pub static EL3HLT: c_int = 46; - pub static EL3RST: c_int = 47; - pub static ELNRNG: c_int = 48; - pub static EUNATCH: c_int = 49; - pub static ENOCSI: c_int = 50; - pub static EL2HLT: c_int = 51; - pub static EBADE: c_int = 52; - pub static EBADR: c_int = 53; - pub static EXFULL: c_int = 54; - pub static ENOANO: c_int = 55; - pub static EBADRQC: c_int = 56; - pub static EBADSLT: c_int = 57; - - pub static EDEADLOCK: c_int = EDEADLK; - - pub static EBFONT: c_int = 59; - pub static ENOSTR: c_int = 60; - pub static ENODATA: c_int = 61; - pub static ETIME: c_int = 62; - pub static ENOSR: c_int = 63; - pub static ENONET: c_int = 64; - pub static ENOPKG: c_int = 65; - pub static EREMOTE: c_int = 66; - pub static ENOLINK: c_int = 67; - pub static EADV: c_int = 68; - pub static ESRMNT: c_int = 69; - pub static ECOMM: c_int = 70; - pub static EPROTO: c_int = 71; - pub static EMULTIHOP: c_int = 72; - pub static EDOTDOT: c_int = 73; - pub static EBADMSG: c_int = 74; - pub static EOVERFLOW: c_int = 75; - pub static ENOTUNIQ: c_int = 76; - pub static EBADFD: c_int = 77; - pub static EREMCHG: c_int = 78; - pub static ELIBACC: c_int = 79; - pub static ELIBBAD: c_int = 80; - pub static ELIBSCN: c_int = 81; - pub static ELIBMAX: c_int = 82; - pub static ELIBEXEC: c_int = 83; - pub static EILSEQ: c_int = 84; - pub static ERESTART: c_int = 85; - pub static ESTRPIPE: c_int = 86; - pub static EUSERS: c_int = 87; - pub static ENOTSOCK: c_int = 88; - pub static EDESTADDRREQ: c_int = 89; - pub static EMSGSIZE: c_int = 90; - pub static EPROTOTYPE: c_int = 91; - pub static ENOPROTOOPT: c_int = 92; - pub static EPROTONOSUPPORT: c_int = 93; - pub static ESOCKTNOSUPPORT: c_int = 94; - pub static EOPNOTSUPP: c_int = 95; - pub static EPFNOSUPPORT: c_int = 96; - pub static EAFNOSUPPORT: c_int = 97; - pub static EADDRINUSE: c_int = 98; - pub static EADDRNOTAVAIL: c_int = 99; - pub static ENETDOWN: c_int = 100; - pub static ENETUNREACH: c_int = 101; - pub static ENETRESET: c_int = 102; - pub static ECONNABORTED: c_int = 103; - pub static ECONNRESET: c_int = 104; - pub static ENOBUFS: c_int = 105; - pub static EISCONN: c_int = 106; - pub static ENOTCONN: c_int = 107; - pub static ESHUTDOWN: c_int = 108; - pub static ETOOMANYREFS: c_int = 109; - pub static ETIMEDOUT: c_int = 110; - pub static ECONNREFUSED: c_int = 111; - pub static EHOSTDOWN: c_int = 112; - pub static EHOSTUNREACH: c_int = 113; - pub static EALREADY: c_int = 114; - pub static EINPROGRESS: c_int = 115; - pub static ESTALE: c_int = 116; - pub static EUCLEAN: c_int = 117; - pub static ENOTNAM: c_int = 118; - pub static ENAVAIL: c_int = 119; - pub static EISNAM: c_int = 120; - pub static EREMOTEIO: c_int = 121; - pub static EDQUOT: c_int = 122; - - pub static ENOMEDIUM: c_int = 123; - pub static EMEDIUMTYPE: c_int = 124; - pub static ECANCELED: c_int = 125; - pub static ENOKEY: c_int = 126; - pub static EKEYEXPIRED: c_int = 127; - pub static EKEYREVOKED: c_int = 128; - pub static EKEYREJECTED: c_int = 129; - - pub static EOWNERDEAD: c_int = 130; - pub static ENOTRECOVERABLE: c_int = 131; - - pub static ERFKILL: c_int = 132; - - pub static EHWPOISON: c_int = 133; + pub const O_RDONLY : c_int = 0; + pub const O_WRONLY : c_int = 1; + pub const O_RDWR : c_int = 2; + pub const O_APPEND : c_int = 1024; + pub const O_CREAT : c_int = 64; + pub const O_EXCL : c_int = 128; + pub const O_TRUNC : c_int = 512; + pub const S_IFIFO : mode_t = 4096; + pub const S_IFCHR : mode_t = 8192; + pub const S_IFBLK : mode_t = 24576; + pub const S_IFDIR : mode_t = 16384; + pub const S_IFREG : mode_t = 32768; + pub const S_IFLNK : mode_t = 40960; + pub const S_IFMT : mode_t = 61440; + pub const S_IEXEC : mode_t = 64; + pub const S_IWRITE : mode_t = 128; + pub const S_IREAD : mode_t = 256; + pub const S_IRWXU : mode_t = 448; + pub const S_IXUSR : mode_t = 64; + pub const S_IWUSR : mode_t = 128; + pub const S_IRUSR : mode_t = 256; + pub const F_OK : c_int = 0; + pub const R_OK : c_int = 4; + pub const W_OK : c_int = 2; + pub const X_OK : c_int = 1; + pub const STDIN_FILENO : c_int = 0; + pub const STDOUT_FILENO : c_int = 1; + pub const STDERR_FILENO : c_int = 2; + pub const F_LOCK : c_int = 1; + pub const F_TEST : c_int = 3; + pub const F_TLOCK : c_int = 2; + pub const F_ULOCK : c_int = 0; + pub const SIGHUP : c_int = 1; + pub const SIGINT : c_int = 2; + pub const SIGQUIT : c_int = 3; + pub const SIGILL : c_int = 4; + pub const SIGABRT : c_int = 6; + pub const SIGFPE : c_int = 8; + pub const SIGKILL : c_int = 9; + pub const SIGSEGV : c_int = 11; + pub const SIGPIPE : c_int = 13; + pub const SIGALRM : c_int = 14; + pub const SIGTERM : c_int = 15; + + pub const PROT_NONE : c_int = 0; + pub const PROT_READ : c_int = 1; + pub const PROT_WRITE : c_int = 2; + pub const PROT_EXEC : c_int = 4; + + pub const MAP_FILE : c_int = 0x0000; + pub const MAP_SHARED : c_int = 0x0001; + pub const MAP_PRIVATE : c_int = 0x0002; + pub const MAP_FIXED : c_int = 0x0010; + pub const MAP_ANON : c_int = 0x0020; + + pub const MAP_FAILED : *mut c_void = -1 as *mut c_void; + + pub const MCL_CURRENT : c_int = 0x0001; + pub const MCL_FUTURE : c_int = 0x0002; + + pub const MS_ASYNC : c_int = 0x0001; + pub const MS_INVALIDATE : c_int = 0x0002; + pub const MS_SYNC : c_int = 0x0004; + + pub const EPERM : c_int = 1; + pub const ENOENT : c_int = 2; + pub const ESRCH : c_int = 3; + pub const EINTR : c_int = 4; + pub const EIO : c_int = 5; + pub const ENXIO : c_int = 6; + pub const E2BIG : c_int = 7; + pub const ENOEXEC : c_int = 8; + pub const EBADF : c_int = 9; + pub const ECHILD : c_int = 10; + pub const EAGAIN : c_int = 11; + pub const ENOMEM : c_int = 12; + pub const EACCES : c_int = 13; + pub const EFAULT : c_int = 14; + pub const ENOTBLK : c_int = 15; + pub const EBUSY : c_int = 16; + pub const EEXIST : c_int = 17; + pub const EXDEV : c_int = 18; + pub const ENODEV : c_int = 19; + pub const ENOTDIR : c_int = 20; + pub const EISDIR : c_int = 21; + pub const EINVAL : c_int = 22; + pub const ENFILE : c_int = 23; + pub const EMFILE : c_int = 24; + pub const ENOTTY : c_int = 25; + pub const ETXTBSY : c_int = 26; + pub const EFBIG : c_int = 27; + pub const ENOSPC : c_int = 28; + pub const ESPIPE : c_int = 29; + pub const EROFS : c_int = 30; + pub const EMLINK : c_int = 31; + pub const EPIPE : c_int = 32; + pub const EDOM : c_int = 33; + pub const ERANGE : c_int = 34; + + pub const EDEADLK: c_int = 35; + pub const ENAMETOOLONG: c_int = 36; + pub const ENOLCK: c_int = 37; + pub const ENOSYS: c_int = 38; + pub const ENOTEMPTY: c_int = 39; + pub const ELOOP: c_int = 40; + pub const EWOULDBLOCK: c_int = EAGAIN; + pub const ENOMSG: c_int = 42; + pub const EIDRM: c_int = 43; + pub const ECHRNG: c_int = 44; + pub const EL2NSYNC: c_int = 45; + pub const EL3HLT: c_int = 46; + pub const EL3RST: c_int = 47; + pub const ELNRNG: c_int = 48; + pub const EUNATCH: c_int = 49; + pub const ENOCSI: c_int = 50; + pub const EL2HLT: c_int = 51; + pub const EBADE: c_int = 52; + pub const EBADR: c_int = 53; + pub const EXFULL: c_int = 54; + pub const ENOANO: c_int = 55; + pub const EBADRQC: c_int = 56; + pub const EBADSLT: c_int = 57; + + pub const EDEADLOCK: c_int = EDEADLK; + + pub const EBFONT: c_int = 59; + pub const ENOSTR: c_int = 60; + pub const ENODATA: c_int = 61; + pub const ETIME: c_int = 62; + pub const ENOSR: c_int = 63; + pub const ENONET: c_int = 64; + pub const ENOPKG: c_int = 65; + pub const EREMOTE: c_int = 66; + pub const ENOLINK: c_int = 67; + pub const EADV: c_int = 68; + pub const ESRMNT: c_int = 69; + pub const ECOMM: c_int = 70; + pub const EPROTO: c_int = 71; + pub const EMULTIHOP: c_int = 72; + pub const EDOTDOT: c_int = 73; + pub const EBADMSG: c_int = 74; + pub const EOVERFLOW: c_int = 75; + pub const ENOTUNIQ: c_int = 76; + pub const EBADFD: c_int = 77; + pub const EREMCHG: c_int = 78; + pub const ELIBACC: c_int = 79; + pub const ELIBBAD: c_int = 80; + pub const ELIBSCN: c_int = 81; + pub const ELIBMAX: c_int = 82; + pub const ELIBEXEC: c_int = 83; + pub const EILSEQ: c_int = 84; + pub const ERESTART: c_int = 85; + pub const ESTRPIPE: c_int = 86; + pub const EUSERS: c_int = 87; + pub const ENOTSOCK: c_int = 88; + pub const EDESTADDRREQ: c_int = 89; + pub const EMSGSIZE: c_int = 90; + pub const EPROTOTYPE: c_int = 91; + pub const ENOPROTOOPT: c_int = 92; + pub const EPROTONOSUPPORT: c_int = 93; + pub const ESOCKTNOSUPPORT: c_int = 94; + pub const EOPNOTSUPP: c_int = 95; + pub const EPFNOSUPPORT: c_int = 96; + pub const EAFNOSUPPORT: c_int = 97; + pub const EADDRINUSE: c_int = 98; + pub const EADDRNOTAVAIL: c_int = 99; + pub const ENETDOWN: c_int = 100; + pub const ENETUNREACH: c_int = 101; + pub const ENETRESET: c_int = 102; + pub const ECONNABORTED: c_int = 103; + pub const ECONNRESET: c_int = 104; + pub const ENOBUFS: c_int = 105; + pub const EISCONN: c_int = 106; + pub const ENOTCONN: c_int = 107; + pub const ESHUTDOWN: c_int = 108; + pub const ETOOMANYREFS: c_int = 109; + pub const ETIMEDOUT: c_int = 110; + pub const ECONNREFUSED: c_int = 111; + pub const EHOSTDOWN: c_int = 112; + pub const EHOSTUNREACH: c_int = 113; + pub const EALREADY: c_int = 114; + pub const EINPROGRESS: c_int = 115; + pub const ESTALE: c_int = 116; + pub const EUCLEAN: c_int = 117; + pub const ENOTNAM: c_int = 118; + pub const ENAVAIL: c_int = 119; + pub const EISNAM: c_int = 120; + pub const EREMOTEIO: c_int = 121; + pub const EDQUOT: c_int = 122; + + pub const ENOMEDIUM: c_int = 123; + pub const EMEDIUMTYPE: c_int = 124; + pub const ECANCELED: c_int = 125; + pub const ENOKEY: c_int = 126; + pub const EKEYEXPIRED: c_int = 127; + pub const EKEYREVOKED: c_int = 128; + pub const EKEYREJECTED: c_int = 129; + + pub const EOWNERDEAD: c_int = 130; + pub const ENOTRECOVERABLE: c_int = 131; + + pub const ERFKILL: c_int = 132; + + pub const EHWPOISON: c_int = 133; } #[cfg(any(target_arch = "mips", target_arch = "mipsel"))] @@ -2621,288 +2621,288 @@ pub mod consts { use types::common::c95::c_void; use types::os::arch::posix88::mode_t; - pub static O_RDONLY : c_int = 0; - pub static O_WRONLY : c_int = 1; - pub static O_RDWR : c_int = 2; - pub static O_APPEND : c_int = 8; - pub static O_CREAT : c_int = 256; - pub static O_EXCL : c_int = 1024; - pub static O_TRUNC : c_int = 512; - pub static S_IFIFO : mode_t = 4096; - pub static S_IFCHR : mode_t = 8192; - pub static S_IFBLK : mode_t = 24576; - pub static S_IFDIR : mode_t = 16384; - pub static S_IFREG : mode_t = 32768; - pub static S_IFLNK : mode_t = 40960; - pub static S_IFMT : mode_t = 61440; - pub static S_IEXEC : mode_t = 64; - pub static S_IWRITE : mode_t = 128; - pub static S_IREAD : mode_t = 256; - pub static S_IRWXU : mode_t = 448; - pub static S_IXUSR : mode_t = 64; - pub static S_IWUSR : mode_t = 128; - pub static S_IRUSR : mode_t = 256; - pub static F_OK : c_int = 0; - pub static R_OK : c_int = 4; - pub static W_OK : c_int = 2; - pub static X_OK : c_int = 1; - pub static STDIN_FILENO : c_int = 0; - pub static STDOUT_FILENO : c_int = 1; - pub static STDERR_FILENO : c_int = 2; - pub static F_LOCK : c_int = 1; - pub static F_TEST : c_int = 3; - pub static F_TLOCK : c_int = 2; - pub static F_ULOCK : c_int = 0; - pub static SIGHUP : c_int = 1; - pub static SIGINT : c_int = 2; - pub static SIGQUIT : c_int = 3; - pub static SIGILL : c_int = 4; - pub static SIGABRT : c_int = 6; - pub static SIGFPE : c_int = 8; - pub static SIGKILL : c_int = 9; - pub static SIGSEGV : c_int = 11; - pub static SIGPIPE : c_int = 13; - pub static SIGALRM : c_int = 14; - pub static SIGTERM : c_int = 15; - - pub static PROT_NONE : c_int = 0; - pub static PROT_READ : c_int = 1; - pub static PROT_WRITE : c_int = 2; - pub static PROT_EXEC : c_int = 4; - - pub static MAP_FILE : c_int = 0x0000; - pub static MAP_SHARED : c_int = 0x0001; - pub static MAP_PRIVATE : c_int = 0x0002; - pub static MAP_FIXED : c_int = 0x0010; - pub static MAP_ANON : c_int = 0x0800; - - pub static MAP_FAILED : *mut c_void = -1 as *mut c_void; - - pub static MCL_CURRENT : c_int = 0x0001; - pub static MCL_FUTURE : c_int = 0x0002; - - pub static MS_ASYNC : c_int = 0x0001; - pub static MS_INVALIDATE : c_int = 0x0002; - pub static MS_SYNC : c_int = 0x0004; - - pub static EPERM : c_int = 1; - pub static ENOENT : c_int = 2; - pub static ESRCH : c_int = 3; - pub static EINTR : c_int = 4; - pub static EIO : c_int = 5; - pub static ENXIO : c_int = 6; - pub static E2BIG : c_int = 7; - pub static ENOEXEC : c_int = 8; - pub static EBADF : c_int = 9; - pub static ECHILD : c_int = 10; - pub static EAGAIN : c_int = 11; - pub static ENOMEM : c_int = 12; - pub static EACCES : c_int = 13; - pub static EFAULT : c_int = 14; - pub static ENOTBLK : c_int = 15; - pub static EBUSY : c_int = 16; - pub static EEXIST : c_int = 17; - pub static EXDEV : c_int = 18; - pub static ENODEV : c_int = 19; - pub static ENOTDIR : c_int = 20; - pub static EISDIR : c_int = 21; - pub static EINVAL : c_int = 22; - pub static ENFILE : c_int = 23; - pub static EMFILE : c_int = 24; - pub static ENOTTY : c_int = 25; - pub static ETXTBSY : c_int = 26; - pub static EFBIG : c_int = 27; - pub static ENOSPC : c_int = 28; - pub static ESPIPE : c_int = 29; - pub static EROFS : c_int = 30; - pub static EMLINK : c_int = 31; - pub static EPIPE : c_int = 32; - pub static EDOM : c_int = 33; - pub static ERANGE : c_int = 34; - - pub static ENOMSG: c_int = 35; - pub static EIDRM: c_int = 36; - pub static ECHRNG: c_int = 37; - pub static EL2NSYNC: c_int = 38; - pub static EL3HLT: c_int = 39; - pub static EL3RST: c_int = 40; - pub static ELNRNG: c_int = 41; - pub static EUNATCH: c_int = 42; - pub static ENOCSI: c_int = 43; - pub static EL2HLT: c_int = 44; - pub static EDEADLK: c_int = 45; - pub static ENOLCK: c_int = 46; - pub static EBADE: c_int = 50; - pub static EBADR: c_int = 51; - pub static EXFULL: c_int = 52; - pub static ENOANO: c_int = 53; - pub static EBADRQC: c_int = 54; - pub static EBADSLT: c_int = 55; - pub static EDEADLOCK: c_int = 56; - pub static EBFONT: c_int = 59; - pub static ENOSTR: c_int = 60; - pub static ENODATA: c_int = 61; - pub static ETIME: c_int = 62; - pub static ENOSR: c_int = 63; - pub static ENONET: c_int = 64; - pub static ENOPKG: c_int = 65; - pub static EREMOTE: c_int = 66; - pub static ENOLINK: c_int = 67; - pub static EADV: c_int = 68; - pub static ESRMNT: c_int = 69; - pub static ECOMM: c_int = 70; - pub static EPROTO: c_int = 71; - pub static EDOTDOT: c_int = 73; - pub static EMULTIHOP: c_int = 74; - pub static EBADMSG: c_int = 77; - pub static ENAMETOOLONG: c_int = 78; - pub static EOVERFLOW: c_int = 79; - pub static ENOTUNIQ: c_int = 80; - pub static EBADFD: c_int = 81; - pub static EREMCHG: c_int = 82; - pub static ELIBACC: c_int = 83; - pub static ELIBBAD: c_int = 84; - pub static ELIBSCN: c_int = 95; - pub static ELIBMAX: c_int = 86; - pub static ELIBEXEC: c_int = 87; - pub static EILSEQ: c_int = 88; - pub static ENOSYS: c_int = 89; - pub static ELOOP: c_int = 90; - pub static ERESTART: c_int = 91; - pub static ESTRPIPE: c_int = 92; - pub static ENOTEMPTY: c_int = 93; - pub static EUSERS: c_int = 94; - pub static ENOTSOCK: c_int = 95; - pub static EDESTADDRREQ: c_int = 96; - pub static EMSGSIZE: c_int = 97; - pub static EPROTOTYPE: c_int = 98; - pub static ENOPROTOOPT: c_int = 99; - pub static EPROTONOSUPPORT: c_int = 120; - pub static ESOCKTNOSUPPORT: c_int = 121; - pub static EOPNOTSUPP: c_int = 122; - pub static EPFNOSUPPORT: c_int = 123; - pub static EAFNOSUPPORT: c_int = 124; - pub static EADDRINUSE: c_int = 125; - pub static EADDRNOTAVAIL: c_int = 126; - pub static ENETDOWN: c_int = 127; - pub static ENETUNREACH: c_int = 128; - pub static ENETRESET: c_int = 129; - pub static ECONNABORTED: c_int = 130; - pub static ECONNRESET: c_int = 131; - pub static ENOBUFS: c_int = 132; - pub static EISCONN: c_int = 133; - pub static ENOTCONN: c_int = 134; - pub static EUCLEAN: c_int = 135; - pub static ENOTNAM: c_int = 137; - pub static ENAVAIL: c_int = 138; - pub static EISNAM: c_int = 139; - pub static EREMOTEIO: c_int = 140; - pub static ESHUTDOWN: c_int = 143; - pub static ETOOMANYREFS: c_int = 144; - pub static ETIMEDOUT: c_int = 145; - pub static ECONNREFUSED: c_int = 146; - pub static EHOSTDOWN: c_int = 147; - pub static EHOSTUNREACH: c_int = 148; - pub static EWOULDBLOCK: c_int = EAGAIN; - pub static EALREADY: c_int = 149; - pub static EINPROGRESS: c_int = 150; - pub static ESTALE: c_int = 151; - pub static ECANCELED: c_int = 158; - - pub static ENOMEDIUM: c_int = 159; - pub static EMEDIUMTYPE: c_int = 160; - pub static ENOKEY: c_int = 161; - pub static EKEYEXPIRED: c_int = 162; - pub static EKEYREVOKED: c_int = 163; - pub static EKEYREJECTED: c_int = 164; - - pub static EOWNERDEAD: c_int = 165; - pub static ENOTRECOVERABLE: c_int = 166; - - pub static ERFKILL: c_int = 167; - - pub static EHWPOISON: c_int = 168; - - pub static EDQUOT: c_int = 1133; + pub const O_RDONLY : c_int = 0; + pub const O_WRONLY : c_int = 1; + pub const O_RDWR : c_int = 2; + pub const O_APPEND : c_int = 8; + pub const O_CREAT : c_int = 256; + pub const O_EXCL : c_int = 1024; + pub const O_TRUNC : c_int = 512; + pub const S_IFIFO : mode_t = 4096; + pub const S_IFCHR : mode_t = 8192; + pub const S_IFBLK : mode_t = 24576; + pub const S_IFDIR : mode_t = 16384; + pub const S_IFREG : mode_t = 32768; + pub const S_IFLNK : mode_t = 40960; + pub const S_IFMT : mode_t = 61440; + pub const S_IEXEC : mode_t = 64; + pub const S_IWRITE : mode_t = 128; + pub const S_IREAD : mode_t = 256; + pub const S_IRWXU : mode_t = 448; + pub const S_IXUSR : mode_t = 64; + pub const S_IWUSR : mode_t = 128; + pub const S_IRUSR : mode_t = 256; + pub const F_OK : c_int = 0; + pub const R_OK : c_int = 4; + pub const W_OK : c_int = 2; + pub const X_OK : c_int = 1; + pub const STDIN_FILENO : c_int = 0; + pub const STDOUT_FILENO : c_int = 1; + pub const STDERR_FILENO : c_int = 2; + pub const F_LOCK : c_int = 1; + pub const F_TEST : c_int = 3; + pub const F_TLOCK : c_int = 2; + pub const F_ULOCK : c_int = 0; + pub const SIGHUP : c_int = 1; + pub const SIGINT : c_int = 2; + pub const SIGQUIT : c_int = 3; + pub const SIGILL : c_int = 4; + pub const SIGABRT : c_int = 6; + pub const SIGFPE : c_int = 8; + pub const SIGKILL : c_int = 9; + pub const SIGSEGV : c_int = 11; + pub const SIGPIPE : c_int = 13; + pub const SIGALRM : c_int = 14; + pub const SIGTERM : c_int = 15; + + pub const PROT_NONE : c_int = 0; + pub const PROT_READ : c_int = 1; + pub const PROT_WRITE : c_int = 2; + pub const PROT_EXEC : c_int = 4; + + pub const MAP_FILE : c_int = 0x0000; + pub const MAP_SHARED : c_int = 0x0001; + pub const MAP_PRIVATE : c_int = 0x0002; + pub const MAP_FIXED : c_int = 0x0010; + pub const MAP_ANON : c_int = 0x0800; + + pub const MAP_FAILED : *mut c_void = -1 as *mut c_void; + + pub const MCL_CURRENT : c_int = 0x0001; + pub const MCL_FUTURE : c_int = 0x0002; + + pub const MS_ASYNC : c_int = 0x0001; + pub const MS_INVALIDATE : c_int = 0x0002; + pub const MS_SYNC : c_int = 0x0004; + + pub const EPERM : c_int = 1; + pub const ENOENT : c_int = 2; + pub const ESRCH : c_int = 3; + pub const EINTR : c_int = 4; + pub const EIO : c_int = 5; + pub const ENXIO : c_int = 6; + pub const E2BIG : c_int = 7; + pub const ENOEXEC : c_int = 8; + pub const EBADF : c_int = 9; + pub const ECHILD : c_int = 10; + pub const EAGAIN : c_int = 11; + pub const ENOMEM : c_int = 12; + pub const EACCES : c_int = 13; + pub const EFAULT : c_int = 14; + pub const ENOTBLK : c_int = 15; + pub const EBUSY : c_int = 16; + pub const EEXIST : c_int = 17; + pub const EXDEV : c_int = 18; + pub const ENODEV : c_int = 19; + pub const ENOTDIR : c_int = 20; + pub const EISDIR : c_int = 21; + pub const EINVAL : c_int = 22; + pub const ENFILE : c_int = 23; + pub const EMFILE : c_int = 24; + pub const ENOTTY : c_int = 25; + pub const ETXTBSY : c_int = 26; + pub const EFBIG : c_int = 27; + pub const ENOSPC : c_int = 28; + pub const ESPIPE : c_int = 29; + pub const EROFS : c_int = 30; + pub const EMLINK : c_int = 31; + pub const EPIPE : c_int = 32; + pub const EDOM : c_int = 33; + pub const ERANGE : c_int = 34; + + pub const ENOMSG: c_int = 35; + pub const EIDRM: c_int = 36; + pub const ECHRNG: c_int = 37; + pub const EL2NSYNC: c_int = 38; + pub const EL3HLT: c_int = 39; + pub const EL3RST: c_int = 40; + pub const ELNRNG: c_int = 41; + pub const EUNATCH: c_int = 42; + pub const ENOCSI: c_int = 43; + pub const EL2HLT: c_int = 44; + pub const EDEADLK: c_int = 45; + pub const ENOLCK: c_int = 46; + pub const EBADE: c_int = 50; + pub const EBADR: c_int = 51; + pub const EXFULL: c_int = 52; + pub const ENOANO: c_int = 53; + pub const EBADRQC: c_int = 54; + pub const EBADSLT: c_int = 55; + pub const EDEADLOCK: c_int = 56; + pub const EBFONT: c_int = 59; + pub const ENOSTR: c_int = 60; + pub const ENODATA: c_int = 61; + pub const ETIME: c_int = 62; + pub const ENOSR: c_int = 63; + pub const ENONET: c_int = 64; + pub const ENOPKG: c_int = 65; + pub const EREMOTE: c_int = 66; + pub const ENOLINK: c_int = 67; + pub const EADV: c_int = 68; + pub const ESRMNT: c_int = 69; + pub const ECOMM: c_int = 70; + pub const EPROTO: c_int = 71; + pub const EDOTDOT: c_int = 73; + pub const EMULTIHOP: c_int = 74; + pub const EBADMSG: c_int = 77; + pub const ENAMETOOLONG: c_int = 78; + pub const EOVERFLOW: c_int = 79; + pub const ENOTUNIQ: c_int = 80; + pub const EBADFD: c_int = 81; + pub const EREMCHG: c_int = 82; + pub const ELIBACC: c_int = 83; + pub const ELIBBAD: c_int = 84; + pub const ELIBSCN: c_int = 95; + pub const ELIBMAX: c_int = 86; + pub const ELIBEXEC: c_int = 87; + pub const EILSEQ: c_int = 88; + pub const ENOSYS: c_int = 89; + pub const ELOOP: c_int = 90; + pub const ERESTART: c_int = 91; + pub const ESTRPIPE: c_int = 92; + pub const ENOTEMPTY: c_int = 93; + pub const EUSERS: c_int = 94; + pub const ENOTSOCK: c_int = 95; + pub const EDESTADDRREQ: c_int = 96; + pub const EMSGSIZE: c_int = 97; + pub const EPROTOTYPE: c_int = 98; + pub const ENOPROTOOPT: c_int = 99; + pub const EPROTONOSUPPORT: c_int = 120; + pub const ESOCKTNOSUPPORT: c_int = 121; + pub const EOPNOTSUPP: c_int = 122; + pub const EPFNOSUPPORT: c_int = 123; + pub const EAFNOSUPPORT: c_int = 124; + pub const EADDRINUSE: c_int = 125; + pub const EADDRNOTAVAIL: c_int = 126; + pub const ENETDOWN: c_int = 127; + pub const ENETUNREACH: c_int = 128; + pub const ENETRESET: c_int = 129; + pub const ECONNABORTED: c_int = 130; + pub const ECONNRESET: c_int = 131; + pub const ENOBUFS: c_int = 132; + pub const EISCONN: c_int = 133; + pub const ENOTCONN: c_int = 134; + pub const EUCLEAN: c_int = 135; + pub const ENOTNAM: c_int = 137; + pub const ENAVAIL: c_int = 138; + pub const EISNAM: c_int = 139; + pub const EREMOTEIO: c_int = 140; + pub const ESHUTDOWN: c_int = 143; + pub const ETOOMANYREFS: c_int = 144; + pub const ETIMEDOUT: c_int = 145; + pub const ECONNREFUSED: c_int = 146; + pub const EHOSTDOWN: c_int = 147; + pub const EHOSTUNREACH: c_int = 148; + pub const EWOULDBLOCK: c_int = EAGAIN; + pub const EALREADY: c_int = 149; + pub const EINPROGRESS: c_int = 150; + pub const ESTALE: c_int = 151; + pub const ECANCELED: c_int = 158; + + pub const ENOMEDIUM: c_int = 159; + pub const EMEDIUMTYPE: c_int = 160; + pub const ENOKEY: c_int = 161; + pub const EKEYEXPIRED: c_int = 162; + pub const EKEYREVOKED: c_int = 163; + pub const EKEYREJECTED: c_int = 164; + + pub const EOWNERDEAD: c_int = 165; + pub const ENOTRECOVERABLE: c_int = 166; + + pub const ERFKILL: c_int = 167; + + pub const EHWPOISON: c_int = 168; + + pub const EDQUOT: c_int = 1133; } pub mod posix01 { use types::os::arch::c95::{c_int, size_t}; - pub static F_DUPFD : c_int = 0; - pub static F_GETFD : c_int = 1; - pub static F_SETFD : c_int = 2; - pub static F_GETFL : c_int = 3; - pub static F_SETFL : c_int = 4; - - pub static SIGTRAP : c_int = 5; - pub static SIGPIPE: c_int = 13; - pub static SIG_IGN: size_t = 1; - - pub static GLOB_ERR : c_int = 1 << 0; - pub static GLOB_MARK : c_int = 1 << 1; - pub static GLOB_NOSORT : c_int = 1 << 2; - pub static GLOB_DOOFFS : c_int = 1 << 3; - pub static GLOB_NOCHECK : c_int = 1 << 4; - pub static GLOB_APPEND : c_int = 1 << 5; - pub static GLOB_NOESCAPE : c_int = 1 << 6; - - pub static GLOB_NOSPACE : c_int = 1; - pub static GLOB_ABORTED : c_int = 2; - pub static GLOB_NOMATCH : c_int = 3; - - pub static POSIX_MADV_NORMAL : c_int = 0; - pub static POSIX_MADV_RANDOM : c_int = 1; - pub static POSIX_MADV_SEQUENTIAL : c_int = 2; - pub static POSIX_MADV_WILLNEED : c_int = 3; - pub static POSIX_MADV_DONTNEED : c_int = 4; - - pub static _SC_MQ_PRIO_MAX : c_int = 28; - pub static _SC_IOV_MAX : c_int = 60; - pub static _SC_GETGR_R_SIZE_MAX : c_int = 69; - pub static _SC_GETPW_R_SIZE_MAX : c_int = 70; - pub static _SC_LOGIN_NAME_MAX : c_int = 71; - pub static _SC_TTY_NAME_MAX : c_int = 72; - pub static _SC_THREADS : c_int = 67; - pub static _SC_THREAD_SAFE_FUNCTIONS : c_int = 68; - pub static _SC_THREAD_DESTRUCTOR_ITERATIONS : c_int = 73; - pub static _SC_THREAD_KEYS_MAX : c_int = 74; - pub static _SC_THREAD_STACK_MIN : c_int = 75; - pub static _SC_THREAD_THREADS_MAX : c_int = 76; - pub static _SC_THREAD_ATTR_STACKADDR : c_int = 77; - pub static _SC_THREAD_ATTR_STACKSIZE : c_int = 78; - pub static _SC_THREAD_PRIORITY_SCHEDULING : c_int = 79; - pub static _SC_THREAD_PRIO_INHERIT : c_int = 80; - pub static _SC_THREAD_PRIO_PROTECT : c_int = 81; - pub static _SC_THREAD_PROCESS_SHARED : c_int = 82; - pub static _SC_ATEXIT_MAX : c_int = 87; - pub static _SC_XOPEN_VERSION : c_int = 89; - pub static _SC_XOPEN_XCU_VERSION : c_int = 90; - pub static _SC_XOPEN_UNIX : c_int = 91; - pub static _SC_XOPEN_CRYPT : c_int = 92; - pub static _SC_XOPEN_ENH_I18N : c_int = 93; - pub static _SC_XOPEN_SHM : c_int = 94; - pub static _SC_XOPEN_LEGACY : c_int = 129; - pub static _SC_XOPEN_REALTIME : c_int = 130; - pub static _SC_XOPEN_REALTIME_THREADS : c_int = 131; - - pub static PTHREAD_CREATE_JOINABLE: c_int = 0; - pub static PTHREAD_CREATE_DETACHED: c_int = 1; + pub const F_DUPFD : c_int = 0; + pub const F_GETFD : c_int = 1; + pub const F_SETFD : c_int = 2; + pub const F_GETFL : c_int = 3; + pub const F_SETFL : c_int = 4; + + pub const SIGTRAP : c_int = 5; + pub const SIGPIPE: c_int = 13; + pub const SIG_IGN: size_t = 1; + + pub const GLOB_ERR : c_int = 1 << 0; + pub const GLOB_MARK : c_int = 1 << 1; + pub const GLOB_NOSORT : c_int = 1 << 2; + pub const GLOB_DOOFFS : c_int = 1 << 3; + pub const GLOB_NOCHECK : c_int = 1 << 4; + pub const GLOB_APPEND : c_int = 1 << 5; + pub const GLOB_NOESCAPE : c_int = 1 << 6; + + pub const GLOB_NOSPACE : c_int = 1; + pub const GLOB_ABORTED : c_int = 2; + pub const GLOB_NOMATCH : c_int = 3; + + pub const POSIX_MADV_NORMAL : c_int = 0; + pub const POSIX_MADV_RANDOM : c_int = 1; + pub const POSIX_MADV_SEQUENTIAL : c_int = 2; + pub const POSIX_MADV_WILLNEED : c_int = 3; + pub const POSIX_MADV_DONTNEED : c_int = 4; + + pub const _SC_MQ_PRIO_MAX : c_int = 28; + pub const _SC_IOV_MAX : c_int = 60; + pub const _SC_GETGR_R_SIZE_MAX : c_int = 69; + pub const _SC_GETPW_R_SIZE_MAX : c_int = 70; + pub const _SC_LOGIN_NAME_MAX : c_int = 71; + pub const _SC_TTY_NAME_MAX : c_int = 72; + pub const _SC_THREADS : c_int = 67; + pub const _SC_THREAD_SAFE_FUNCTIONS : c_int = 68; + pub const _SC_THREAD_DESTRUCTOR_ITERATIONS : c_int = 73; + pub const _SC_THREAD_KEYS_MAX : c_int = 74; + pub const _SC_THREAD_STACK_MIN : c_int = 75; + pub const _SC_THREAD_THREADS_MAX : c_int = 76; + pub const _SC_THREAD_ATTR_STACKADDR : c_int = 77; + pub const _SC_THREAD_ATTR_STACKSIZE : c_int = 78; + pub const _SC_THREAD_PRIORITY_SCHEDULING : c_int = 79; + pub const _SC_THREAD_PRIO_INHERIT : c_int = 80; + pub const _SC_THREAD_PRIO_PROTECT : c_int = 81; + pub const _SC_THREAD_PROCESS_SHARED : c_int = 82; + pub const _SC_ATEXIT_MAX : c_int = 87; + pub const _SC_XOPEN_VERSION : c_int = 89; + pub const _SC_XOPEN_XCU_VERSION : c_int = 90; + pub const _SC_XOPEN_UNIX : c_int = 91; + pub const _SC_XOPEN_CRYPT : c_int = 92; + pub const _SC_XOPEN_ENH_I18N : c_int = 93; + pub const _SC_XOPEN_SHM : c_int = 94; + pub const _SC_XOPEN_LEGACY : c_int = 129; + pub const _SC_XOPEN_REALTIME : c_int = 130; + pub const _SC_XOPEN_REALTIME_THREADS : c_int = 131; + + pub const PTHREAD_CREATE_JOINABLE: c_int = 0; + pub const PTHREAD_CREATE_DETACHED: c_int = 1; #[cfg(target_os = "android")] - pub static PTHREAD_STACK_MIN: size_t = 8192; + pub const PTHREAD_STACK_MIN: size_t = 8192; #[cfg(all(target_os = "linux", any(target_arch = "arm", target_arch = "x86", target_arch = "x86_64")))] - pub static PTHREAD_STACK_MIN: size_t = 16384; + pub const PTHREAD_STACK_MIN: size_t = 16384; #[cfg(all(target_os = "linux", any(target_arch = "mips", target_arch = "mipsel")))] - pub static PTHREAD_STACK_MIN: size_t = 131072; + pub const PTHREAD_STACK_MIN: size_t = 131072; - pub static CLOCK_REALTIME: c_int = 0; - pub static CLOCK_MONOTONIC: c_int = 1; + pub const CLOCK_REALTIME: c_int = 0; + pub const CLOCK_MONOTONIC: c_int = 1; } pub mod posix08 { } @@ -2912,93 +2912,93 @@ pub mod consts { pub mod bsd44 { use types::os::arch::c95::c_int; - pub static MADV_NORMAL : c_int = 0; - pub static MADV_RANDOM : c_int = 1; - pub static MADV_SEQUENTIAL : c_int = 2; - pub static MADV_WILLNEED : c_int = 3; - pub static MADV_DONTNEED : c_int = 4; - pub static MADV_REMOVE : c_int = 9; - pub static MADV_DONTFORK : c_int = 10; - pub static MADV_DOFORK : c_int = 11; - pub static MADV_MERGEABLE : c_int = 12; - pub static MADV_UNMERGEABLE : c_int = 13; - pub static MADV_HWPOISON : c_int = 100; - - pub static IFF_LOOPBACK: c_int = 0x8; - - pub static AF_UNIX: c_int = 1; - pub static AF_INET: c_int = 2; - pub static AF_INET6: c_int = 10; - pub static SOCK_STREAM: c_int = 1; - pub static SOCK_DGRAM: c_int = 2; - pub static SOCK_RAW: c_int = 3; - pub static IPPROTO_TCP: c_int = 6; - pub static IPPROTO_IP: c_int = 0; - pub static IPPROTO_IPV6: c_int = 41; - pub static IP_MULTICAST_TTL: c_int = 33; - pub static IP_MULTICAST_LOOP: c_int = 34; - pub static IP_TTL: c_int = 2; - pub static IP_HDRINCL: c_int = 3; - pub static IP_ADD_MEMBERSHIP: c_int = 35; - pub static IP_DROP_MEMBERSHIP: c_int = 36; - pub static IPV6_ADD_MEMBERSHIP: c_int = 20; - pub static IPV6_DROP_MEMBERSHIP: c_int = 21; - - pub static TCP_NODELAY: c_int = 1; - pub static SOL_SOCKET: c_int = 1; - pub static SO_KEEPALIVE: c_int = 9; - pub static SO_BROADCAST: c_int = 6; - pub static SO_REUSEADDR: c_int = 2; - pub static SO_ERROR: c_int = 4; - - pub static SHUT_RD: c_int = 0; - pub static SHUT_WR: c_int = 1; - pub static SHUT_RDWR: c_int = 2; + pub const MADV_NORMAL : c_int = 0; + pub const MADV_RANDOM : c_int = 1; + pub const MADV_SEQUENTIAL : c_int = 2; + pub const MADV_WILLNEED : c_int = 3; + pub const MADV_DONTNEED : c_int = 4; + pub const MADV_REMOVE : c_int = 9; + pub const MADV_DONTFORK : c_int = 10; + pub const MADV_DOFORK : c_int = 11; + pub const MADV_MERGEABLE : c_int = 12; + pub const MADV_UNMERGEABLE : c_int = 13; + pub const MADV_HWPOISON : c_int = 100; + + pub const IFF_LOOPBACK: c_int = 0x8; + + pub const AF_UNIX: c_int = 1; + pub const AF_INET: c_int = 2; + pub const AF_INET6: c_int = 10; + pub const SOCK_STREAM: c_int = 1; + pub const SOCK_DGRAM: c_int = 2; + pub const SOCK_RAW: c_int = 3; + pub const IPPROTO_TCP: c_int = 6; + pub const IPPROTO_IP: c_int = 0; + pub const IPPROTO_IPV6: c_int = 41; + pub const IP_MULTICAST_TTL: c_int = 33; + pub const IP_MULTICAST_LOOP: c_int = 34; + pub const IP_TTL: c_int = 2; + pub const IP_HDRINCL: c_int = 3; + pub const IP_ADD_MEMBERSHIP: c_int = 35; + pub const IP_DROP_MEMBERSHIP: c_int = 36; + pub const IPV6_ADD_MEMBERSHIP: c_int = 20; + pub const IPV6_DROP_MEMBERSHIP: c_int = 21; + + pub const TCP_NODELAY: c_int = 1; + pub const SOL_SOCKET: c_int = 1; + pub const SO_KEEPALIVE: c_int = 9; + pub const SO_BROADCAST: c_int = 6; + pub const SO_REUSEADDR: c_int = 2; + pub const SO_ERROR: c_int = 4; + + pub const SHUT_RD: c_int = 0; + pub const SHUT_WR: c_int = 1; + pub const SHUT_RDWR: c_int = 2; } #[cfg(any(target_arch = "mips", target_arch = "mipsel"))] pub mod bsd44 { use types::os::arch::c95::c_int; - pub static MADV_NORMAL : c_int = 0; - pub static MADV_RANDOM : c_int = 1; - pub static MADV_SEQUENTIAL : c_int = 2; - pub static MADV_WILLNEED : c_int = 3; - pub static MADV_DONTNEED : c_int = 4; - pub static MADV_REMOVE : c_int = 9; - pub static MADV_DONTFORK : c_int = 10; - pub static MADV_DOFORK : c_int = 11; - pub static MADV_MERGEABLE : c_int = 12; - pub static MADV_UNMERGEABLE : c_int = 13; - pub static MADV_HWPOISON : c_int = 100; - - pub static AF_UNIX: c_int = 1; - pub static AF_INET: c_int = 2; - pub static AF_INET6: c_int = 10; - pub static SOCK_STREAM: c_int = 2; - pub static SOCK_DGRAM: c_int = 1; - pub static SOCK_RAW: c_int = 3; - pub static IPPROTO_TCP: c_int = 6; - pub static IPPROTO_IP: c_int = 0; - pub static IPPROTO_IPV6: c_int = 41; - pub static IP_MULTICAST_TTL: c_int = 33; - pub static IP_MULTICAST_LOOP: c_int = 34; - pub static IP_TTL: c_int = 2; - pub static IP_HDRINCL: c_int = 3; - pub static IP_ADD_MEMBERSHIP: c_int = 35; - pub static IP_DROP_MEMBERSHIP: c_int = 36; - pub static IPV6_ADD_MEMBERSHIP: c_int = 20; - pub static IPV6_DROP_MEMBERSHIP: c_int = 21; - - pub static TCP_NODELAY: c_int = 1; - pub static SOL_SOCKET: c_int = 65535; - pub static SO_KEEPALIVE: c_int = 8; - pub static SO_BROADCAST: c_int = 32; - pub static SO_REUSEADDR: c_int = 4; - pub static SO_ERROR: c_int = 4103; - - pub static SHUT_RD: c_int = 0; - pub static SHUT_WR: c_int = 1; - pub static SHUT_RDWR: c_int = 2; + pub const MADV_NORMAL : c_int = 0; + pub const MADV_RANDOM : c_int = 1; + pub const MADV_SEQUENTIAL : c_int = 2; + pub const MADV_WILLNEED : c_int = 3; + pub const MADV_DONTNEED : c_int = 4; + pub const MADV_REMOVE : c_int = 9; + pub const MADV_DONTFORK : c_int = 10; + pub const MADV_DOFORK : c_int = 11; + pub const MADV_MERGEABLE : c_int = 12; + pub const MADV_UNMERGEABLE : c_int = 13; + pub const MADV_HWPOISON : c_int = 100; + + pub const AF_UNIX: c_int = 1; + pub const AF_INET: c_int = 2; + pub const AF_INET6: c_int = 10; + pub const SOCK_STREAM: c_int = 2; + pub const SOCK_DGRAM: c_int = 1; + pub const SOCK_RAW: c_int = 3; + pub const IPPROTO_TCP: c_int = 6; + pub const IPPROTO_IP: c_int = 0; + pub const IPPROTO_IPV6: c_int = 41; + pub const IP_MULTICAST_TTL: c_int = 33; + pub const IP_MULTICAST_LOOP: c_int = 34; + pub const IP_TTL: c_int = 2; + pub const IP_HDRINCL: c_int = 3; + pub const IP_ADD_MEMBERSHIP: c_int = 35; + pub const IP_DROP_MEMBERSHIP: c_int = 36; + pub const IPV6_ADD_MEMBERSHIP: c_int = 20; + pub const IPV6_DROP_MEMBERSHIP: c_int = 21; + + pub const TCP_NODELAY: c_int = 1; + pub const SOL_SOCKET: c_int = 65535; + pub const SO_KEEPALIVE: c_int = 8; + pub const SO_BROADCAST: c_int = 32; + pub const SO_REUSEADDR: c_int = 4; + pub const SO_ERROR: c_int = 4103; + + pub const SHUT_RD: c_int = 0; + pub const SHUT_WR: c_int = 1; + pub const SHUT_RDWR: c_int = 2; } #[cfg(any(target_arch = "x86", target_arch = "x86_64", @@ -3006,149 +3006,149 @@ pub mod consts { pub mod extra { use types::os::arch::c95::c_int; - pub static AF_PACKET : c_int = 17; - pub static IPPROTO_RAW : c_int = 255; - - pub static O_RSYNC : c_int = 1052672; - pub static O_DSYNC : c_int = 4096; - pub static O_NONBLOCK : c_int = 2048; - pub static O_SYNC : c_int = 1052672; - - pub static PROT_GROWSDOWN : c_int = 0x010000000; - pub static PROT_GROWSUP : c_int = 0x020000000; - - pub static MAP_TYPE : c_int = 0x000f; - pub static MAP_ANONYMOUS : c_int = 0x0020; - pub static MAP_32BIT : c_int = 0x0040; - pub static MAP_GROWSDOWN : c_int = 0x0100; - pub static MAP_DENYWRITE : c_int = 0x0800; - pub static MAP_EXECUTABLE : c_int = 0x01000; - pub static MAP_LOCKED : c_int = 0x02000; - pub static MAP_NONRESERVE : c_int = 0x04000; - pub static MAP_POPULATE : c_int = 0x08000; - pub static MAP_NONBLOCK : c_int = 0x010000; - pub static MAP_STACK : c_int = 0x020000; + pub const AF_PACKET : c_int = 17; + pub const IPPROTO_RAW : c_int = 255; + + pub const O_RSYNC : c_int = 1052672; + pub const O_DSYNC : c_int = 4096; + pub const O_NONBLOCK : c_int = 2048; + pub const O_SYNC : c_int = 1052672; + + pub const PROT_GROWSDOWN : c_int = 0x010000000; + pub const PROT_GROWSUP : c_int = 0x020000000; + + pub const MAP_TYPE : c_int = 0x000f; + pub const MAP_ANONYMOUS : c_int = 0x0020; + pub const MAP_32BIT : c_int = 0x0040; + pub const MAP_GROWSDOWN : c_int = 0x0100; + pub const MAP_DENYWRITE : c_int = 0x0800; + pub const MAP_EXECUTABLE : c_int = 0x01000; + pub const MAP_LOCKED : c_int = 0x02000; + pub const MAP_NONRESERVE : c_int = 0x04000; + pub const MAP_POPULATE : c_int = 0x08000; + pub const MAP_NONBLOCK : c_int = 0x010000; + pub const MAP_STACK : c_int = 0x020000; } #[cfg(any(target_arch = "mips", target_arch = "mipsel"))] pub mod extra { use types::os::arch::c95::c_int; - pub static AF_PACKET : c_int = 17; - pub static IPPROTO_RAW : c_int = 255; - - pub static O_RSYNC : c_int = 16400; - pub static O_DSYNC : c_int = 16; - pub static O_NONBLOCK : c_int = 128; - pub static O_SYNC : c_int = 16400; - - pub static PROT_GROWSDOWN : c_int = 0x01000000; - pub static PROT_GROWSUP : c_int = 0x02000000; - - pub static MAP_TYPE : c_int = 0x000f; - pub static MAP_ANONYMOUS : c_int = 0x0800; - pub static MAP_GROWSDOWN : c_int = 0x01000; - pub static MAP_DENYWRITE : c_int = 0x02000; - pub static MAP_EXECUTABLE : c_int = 0x04000; - pub static MAP_LOCKED : c_int = 0x08000; - pub static MAP_NONRESERVE : c_int = 0x0400; - pub static MAP_POPULATE : c_int = 0x010000; - pub static MAP_NONBLOCK : c_int = 0x020000; - pub static MAP_STACK : c_int = 0x040000; + pub const AF_PACKET : c_int = 17; + pub const IPPROTO_RAW : c_int = 255; + + pub const O_RSYNC : c_int = 16400; + pub const O_DSYNC : c_int = 16; + pub const O_NONBLOCK : c_int = 128; + pub const O_SYNC : c_int = 16400; + + pub const PROT_GROWSDOWN : c_int = 0x01000000; + pub const PROT_GROWSUP : c_int = 0x02000000; + + pub const MAP_TYPE : c_int = 0x000f; + pub const MAP_ANONYMOUS : c_int = 0x0800; + pub const MAP_GROWSDOWN : c_int = 0x01000; + pub const MAP_DENYWRITE : c_int = 0x02000; + pub const MAP_EXECUTABLE : c_int = 0x04000; + pub const MAP_LOCKED : c_int = 0x08000; + pub const MAP_NONRESERVE : c_int = 0x0400; + pub const MAP_POPULATE : c_int = 0x010000; + pub const MAP_NONBLOCK : c_int = 0x020000; + pub const MAP_STACK : c_int = 0x040000; } #[cfg(target_os = "linux")] pub mod sysconf { use types::os::arch::c95::c_int; - pub static _SC_ARG_MAX : c_int = 0; - pub static _SC_CHILD_MAX : c_int = 1; - pub static _SC_CLK_TCK : c_int = 2; - pub static _SC_NGROUPS_MAX : c_int = 3; - pub static _SC_OPEN_MAX : c_int = 4; - pub static _SC_STREAM_MAX : c_int = 5; - pub static _SC_TZNAME_MAX : c_int = 6; - pub static _SC_JOB_CONTROL : c_int = 7; - pub static _SC_SAVED_IDS : c_int = 8; - pub static _SC_REALTIME_SIGNALS : c_int = 9; - pub static _SC_PRIORITY_SCHEDULING : c_int = 10; - pub static _SC_TIMERS : c_int = 11; - pub static _SC_ASYNCHRONOUS_IO : c_int = 12; - pub static _SC_PRIORITIZED_IO : c_int = 13; - pub static _SC_SYNCHRONIZED_IO : c_int = 14; - pub static _SC_FSYNC : c_int = 15; - pub static _SC_MAPPED_FILES : c_int = 16; - pub static _SC_MEMLOCK : c_int = 17; - pub static _SC_MEMLOCK_RANGE : c_int = 18; - pub static _SC_MEMORY_PROTECTION : c_int = 19; - pub static _SC_MESSAGE_PASSING : c_int = 20; - pub static _SC_SEMAPHORES : c_int = 21; - pub static _SC_SHARED_MEMORY_OBJECTS : c_int = 22; - pub static _SC_AIO_LISTIO_MAX : c_int = 23; - pub static _SC_AIO_MAX : c_int = 24; - pub static _SC_AIO_PRIO_DELTA_MAX : c_int = 25; - pub static _SC_DELAYTIMER_MAX : c_int = 26; - pub static _SC_MQ_OPEN_MAX : c_int = 27; - pub static _SC_VERSION : c_int = 29; - pub static _SC_PAGESIZE : c_int = 30; - pub static _SC_RTSIG_MAX : c_int = 31; - pub static _SC_SEM_NSEMS_MAX : c_int = 32; - pub static _SC_SEM_VALUE_MAX : c_int = 33; - pub static _SC_SIGQUEUE_MAX : c_int = 34; - pub static _SC_TIMER_MAX : c_int = 35; - pub static _SC_BC_BASE_MAX : c_int = 36; - pub static _SC_BC_DIM_MAX : c_int = 37; - pub static _SC_BC_SCALE_MAX : c_int = 38; - pub static _SC_BC_STRING_MAX : c_int = 39; - pub static _SC_COLL_WEIGHTS_MAX : c_int = 40; - pub static _SC_EXPR_NEST_MAX : c_int = 42; - pub static _SC_LINE_MAX : c_int = 43; - pub static _SC_RE_DUP_MAX : c_int = 44; - pub static _SC_2_VERSION : c_int = 46; - pub static _SC_2_C_BIND : c_int = 47; - pub static _SC_2_C_DEV : c_int = 48; - pub static _SC_2_FORT_DEV : c_int = 49; - pub static _SC_2_FORT_RUN : c_int = 50; - pub static _SC_2_SW_DEV : c_int = 51; - pub static _SC_2_LOCALEDEF : c_int = 52; - pub static _SC_2_CHAR_TERM : c_int = 95; - pub static _SC_2_C_VERSION : c_int = 96; - pub static _SC_2_UPE : c_int = 97; - pub static _SC_XBS5_ILP32_OFF32 : c_int = 125; - pub static _SC_XBS5_ILP32_OFFBIG : c_int = 126; - pub static _SC_XBS5_LPBIG_OFFBIG : c_int = 128; + pub const _SC_ARG_MAX : c_int = 0; + pub const _SC_CHILD_MAX : c_int = 1; + pub const _SC_CLK_TCK : c_int = 2; + pub const _SC_NGROUPS_MAX : c_int = 3; + pub const _SC_OPEN_MAX : c_int = 4; + pub const _SC_STREAM_MAX : c_int = 5; + pub const _SC_TZNAME_MAX : c_int = 6; + pub const _SC_JOB_CONTROL : c_int = 7; + pub const _SC_SAVED_IDS : c_int = 8; + pub const _SC_REALTIME_SIGNALS : c_int = 9; + pub const _SC_PRIORITY_SCHEDULING : c_int = 10; + pub const _SC_TIMERS : c_int = 11; + pub const _SC_ASYNCHRONOUS_IO : c_int = 12; + pub const _SC_PRIORITIZED_IO : c_int = 13; + pub const _SC_SYNCHRONIZED_IO : c_int = 14; + pub const _SC_FSYNC : c_int = 15; + pub const _SC_MAPPED_FILES : c_int = 16; + pub const _SC_MEMLOCK : c_int = 17; + pub const _SC_MEMLOCK_RANGE : c_int = 18; + pub const _SC_MEMORY_PROTECTION : c_int = 19; + pub const _SC_MESSAGE_PASSING : c_int = 20; + pub const _SC_SEMAPHORES : c_int = 21; + pub const _SC_SHARED_MEMORY_OBJECTS : c_int = 22; + pub const _SC_AIO_LISTIO_MAX : c_int = 23; + pub const _SC_AIO_MAX : c_int = 24; + pub const _SC_AIO_PRIO_DELTA_MAX : c_int = 25; + pub const _SC_DELAYTIMER_MAX : c_int = 26; + pub const _SC_MQ_OPEN_MAX : c_int = 27; + pub const _SC_VERSION : c_int = 29; + pub const _SC_PAGESIZE : c_int = 30; + pub const _SC_RTSIG_MAX : c_int = 31; + pub const _SC_SEM_NSEMS_MAX : c_int = 32; + pub const _SC_SEM_VALUE_MAX : c_int = 33; + pub const _SC_SIGQUEUE_MAX : c_int = 34; + pub const _SC_TIMER_MAX : c_int = 35; + pub const _SC_BC_BASE_MAX : c_int = 36; + pub const _SC_BC_DIM_MAX : c_int = 37; + pub const _SC_BC_SCALE_MAX : c_int = 38; + pub const _SC_BC_STRING_MAX : c_int = 39; + pub const _SC_COLL_WEIGHTS_MAX : c_int = 40; + pub const _SC_EXPR_NEST_MAX : c_int = 42; + pub const _SC_LINE_MAX : c_int = 43; + pub const _SC_RE_DUP_MAX : c_int = 44; + pub const _SC_2_VERSION : c_int = 46; + pub const _SC_2_C_BIND : c_int = 47; + pub const _SC_2_C_DEV : c_int = 48; + pub const _SC_2_FORT_DEV : c_int = 49; + pub const _SC_2_FORT_RUN : c_int = 50; + pub const _SC_2_SW_DEV : c_int = 51; + pub const _SC_2_LOCALEDEF : c_int = 52; + pub const _SC_2_CHAR_TERM : c_int = 95; + pub const _SC_2_C_VERSION : c_int = 96; + pub const _SC_2_UPE : c_int = 97; + pub const _SC_XBS5_ILP32_OFF32 : c_int = 125; + pub const _SC_XBS5_ILP32_OFFBIG : c_int = 126; + pub const _SC_XBS5_LPBIG_OFFBIG : c_int = 128; } #[cfg(target_os = "android")] pub mod sysconf { use types::os::arch::c95::c_int; - pub static _SC_ARG_MAX : c_int = 0; - pub static _SC_BC_BASE_MAX : c_int = 1; - pub static _SC_BC_DIM_MAX : c_int = 2; - pub static _SC_BC_SCALE_MAX : c_int = 3; - pub static _SC_BC_STRING_MAX : c_int = 4; - pub static _SC_CHILD_MAX : c_int = 5; - pub static _SC_CLK_TCK : c_int = 6; - pub static _SC_COLL_WEIGHTS_MAX : c_int = 7; - pub static _SC_EXPR_NEST_MAX : c_int = 8; - pub static _SC_LINE_MAX : c_int = 9; - pub static _SC_NGROUPS_MAX : c_int = 10; - pub static _SC_OPEN_MAX : c_int = 11; - pub static _SC_2_C_BIND : c_int = 13; - pub static _SC_2_C_DEV : c_int = 14; - pub static _SC_2_C_VERSION : c_int = 15; - pub static _SC_2_CHAR_TERM : c_int = 16; - pub static _SC_2_FORT_DEV : c_int = 17; - pub static _SC_2_FORT_RUN : c_int = 18; - pub static _SC_2_LOCALEDEF : c_int = 19; - pub static _SC_2_SW_DEV : c_int = 20; - pub static _SC_2_UPE : c_int = 21; - pub static _SC_2_VERSION : c_int = 22; - pub static _SC_JOB_CONTROL : c_int = 23; - pub static _SC_SAVED_IDS : c_int = 24; - pub static _SC_VERSION : c_int = 25; - pub static _SC_RE_DUP_MAX : c_int = 26; - pub static _SC_STREAM_MAX : c_int = 27; - pub static _SC_TZNAME_MAX : c_int = 28; - pub static _SC_PAGESIZE : c_int = 39; + pub const _SC_ARG_MAX : c_int = 0; + pub const _SC_BC_BASE_MAX : c_int = 1; + pub const _SC_BC_DIM_MAX : c_int = 2; + pub const _SC_BC_SCALE_MAX : c_int = 3; + pub const _SC_BC_STRING_MAX : c_int = 4; + pub const _SC_CHILD_MAX : c_int = 5; + pub const _SC_CLK_TCK : c_int = 6; + pub const _SC_COLL_WEIGHTS_MAX : c_int = 7; + pub const _SC_EXPR_NEST_MAX : c_int = 8; + pub const _SC_LINE_MAX : c_int = 9; + pub const _SC_NGROUPS_MAX : c_int = 10; + pub const _SC_OPEN_MAX : c_int = 11; + pub const _SC_2_C_BIND : c_int = 13; + pub const _SC_2_C_DEV : c_int = 14; + pub const _SC_2_C_VERSION : c_int = 15; + pub const _SC_2_CHAR_TERM : c_int = 16; + pub const _SC_2_FORT_DEV : c_int = 17; + pub const _SC_2_FORT_RUN : c_int = 18; + pub const _SC_2_LOCALEDEF : c_int = 19; + pub const _SC_2_SW_DEV : c_int = 20; + pub const _SC_2_UPE : c_int = 21; + pub const _SC_2_VERSION : c_int = 22; + pub const _SC_JOB_CONTROL : c_int = 23; + pub const _SC_SAVED_IDS : c_int = 24; + pub const _SC_VERSION : c_int = 25; + pub const _SC_RE_DUP_MAX : c_int = 26; + pub const _SC_STREAM_MAX : c_int = 27; + pub const _SC_TZNAME_MAX : c_int = 28; + pub const _SC_PAGESIZE : c_int = 39; } } @@ -3157,21 +3157,21 @@ pub mod consts { pub mod c95 { use types::os::arch::c95::{c_int, c_uint}; - pub static EXIT_FAILURE : c_int = 1; - pub static EXIT_SUCCESS : c_int = 0; - pub static RAND_MAX : c_int = 2147483647; - pub static EOF : c_int = -1; - pub static SEEK_SET : c_int = 0; - pub static SEEK_CUR : c_int = 1; - pub static SEEK_END : c_int = 2; - pub static _IOFBF : c_int = 0; - pub static _IONBF : c_int = 2; - pub static _IOLBF : c_int = 1; - pub static BUFSIZ : c_uint = 1024_u32; - pub static FOPEN_MAX : c_uint = 20_u32; - pub static FILENAME_MAX : c_uint = 1024_u32; - pub static L_tmpnam : c_uint = 1024_u32; - pub static TMP_MAX : c_uint = 308915776_u32; + pub const EXIT_FAILURE : c_int = 1; + pub const EXIT_SUCCESS : c_int = 0; + pub const RAND_MAX : c_int = 2147483647; + pub const EOF : c_int = -1; + pub const SEEK_SET : c_int = 0; + pub const SEEK_CUR : c_int = 1; + pub const SEEK_END : c_int = 2; + pub const _IOFBF : c_int = 0; + pub const _IONBF : c_int = 2; + pub const _IOLBF : c_int = 1; + pub const BUFSIZ : c_uint = 1024_u32; + pub const FOPEN_MAX : c_uint = 20_u32; + pub const FILENAME_MAX : c_uint = 1024_u32; + pub const L_tmpnam : c_uint = 1024_u32; + pub const TMP_MAX : c_uint = 308915776_u32; } pub mod c99 { } @@ -3180,384 +3180,384 @@ pub mod consts { use types::os::arch::c95::c_int; use types::os::arch::posix88::mode_t; - pub static O_RDONLY : c_int = 0; - pub static O_WRONLY : c_int = 1; - pub static O_RDWR : c_int = 2; - pub static O_APPEND : c_int = 8; - pub static O_CREAT : c_int = 512; - pub static O_EXCL : c_int = 2048; - pub static O_TRUNC : c_int = 1024; - pub static S_IFIFO : mode_t = 4096; - pub static S_IFCHR : mode_t = 8192; - pub static S_IFBLK : mode_t = 24576; - pub static S_IFDIR : mode_t = 16384; - pub static S_IFREG : mode_t = 32768; - pub static S_IFLNK : mode_t = 40960; - pub static S_IFMT : mode_t = 61440; - pub static S_IEXEC : mode_t = 64; - pub static S_IWRITE : mode_t = 128; - pub static S_IREAD : mode_t = 256; - pub static S_IRWXU : mode_t = 448; - pub static S_IXUSR : mode_t = 64; - pub static S_IWUSR : mode_t = 128; - pub static S_IRUSR : mode_t = 256; - pub static F_OK : c_int = 0; - pub static R_OK : c_int = 4; - pub static W_OK : c_int = 2; - pub static X_OK : c_int = 1; - pub static STDIN_FILENO : c_int = 0; - pub static STDOUT_FILENO : c_int = 1; - pub static STDERR_FILENO : c_int = 2; - pub static F_LOCK : c_int = 1; - pub static F_TEST : c_int = 3; - pub static F_TLOCK : c_int = 2; - pub static F_ULOCK : c_int = 0; - pub static SIGHUP : c_int = 1; - pub static SIGINT : c_int = 2; - pub static SIGQUIT : c_int = 3; - pub static SIGILL : c_int = 4; - pub static SIGABRT : c_int = 6; - pub static SIGFPE : c_int = 8; - pub static SIGKILL : c_int = 9; - pub static SIGSEGV : c_int = 11; - pub static SIGPIPE : c_int = 13; - pub static SIGALRM : c_int = 14; - pub static SIGTERM : c_int = 15; - - pub static PROT_NONE : c_int = 0; - pub static PROT_READ : c_int = 1; - pub static PROT_WRITE : c_int = 2; - pub static PROT_EXEC : c_int = 4; - - pub static MAP_FILE : c_int = 0x0000; - pub static MAP_SHARED : c_int = 0x0001; - pub static MAP_PRIVATE : c_int = 0x0002; - pub static MAP_FIXED : c_int = 0x0010; - pub static MAP_ANON : c_int = 0x1000; - - pub static MAP_FAILED : *mut c_void = -1 as *mut c_void; - - pub static MCL_CURRENT : c_int = 0x0001; - pub static MCL_FUTURE : c_int = 0x0002; - - pub static MS_SYNC : c_int = 0x0000; - pub static MS_ASYNC : c_int = 0x0001; - pub static MS_INVALIDATE : c_int = 0x0002; - - pub static EPERM : c_int = 1; - pub static ENOENT : c_int = 2; - pub static ESRCH : c_int = 3; - pub static EINTR : c_int = 4; - pub static EIO : c_int = 5; - pub static ENXIO : c_int = 6; - pub static E2BIG : c_int = 7; - pub static ENOEXEC : c_int = 8; - pub static EBADF : c_int = 9; - pub static ECHILD : c_int = 10; - pub static EDEADLK : c_int = 11; - pub static ENOMEM : c_int = 12; - pub static EACCES : c_int = 13; - pub static EFAULT : c_int = 14; - pub static ENOTBLK : c_int = 15; - pub static EBUSY : c_int = 16; - pub static EEXIST : c_int = 17; - pub static EXDEV : c_int = 18; - pub static ENODEV : c_int = 19; - pub static ENOTDIR : c_int = 20; - pub static EISDIR : c_int = 21; - pub static EINVAL : c_int = 22; - pub static ENFILE : c_int = 23; - pub static EMFILE : c_int = 24; - pub static ENOTTY : c_int = 25; - pub static ETXTBSY : c_int = 26; - pub static EFBIG : c_int = 27; - pub static ENOSPC : c_int = 28; - pub static ESPIPE : c_int = 29; - pub static EROFS : c_int = 30; - pub static EMLINK : c_int = 31; - pub static EPIPE : c_int = 32; - pub static EDOM : c_int = 33; - pub static ERANGE : c_int = 34; - pub static EAGAIN : c_int = 35; - pub static EWOULDBLOCK : c_int = 35; - pub static EINPROGRESS : c_int = 36; - pub static EALREADY : c_int = 37; - pub static ENOTSOCK : c_int = 38; - pub static EDESTADDRREQ : c_int = 39; - pub static EMSGSIZE : c_int = 40; - pub static EPROTOTYPE : c_int = 41; - pub static ENOPROTOOPT : c_int = 42; - pub static EPROTONOSUPPORT : c_int = 43; - pub static ESOCKTNOSUPPORT : c_int = 44; - pub static EOPNOTSUPP : c_int = 45; - pub static EPFNOSUPPORT : c_int = 46; - pub static EAFNOSUPPORT : c_int = 47; - pub static EADDRINUSE : c_int = 48; - pub static EADDRNOTAVAIL : c_int = 49; - pub static ENETDOWN : c_int = 50; - pub static ENETUNREACH : c_int = 51; - pub static ENETRESET : c_int = 52; - pub static ECONNABORTED : c_int = 53; - pub static ECONNRESET : c_int = 54; - pub static ENOBUFS : c_int = 55; - pub static EISCONN : c_int = 56; - pub static ENOTCONN : c_int = 57; - pub static ESHUTDOWN : c_int = 58; - pub static ETOOMANYREFS : c_int = 59; - pub static ETIMEDOUT : c_int = 60; - pub static ECONNREFUSED : c_int = 61; - pub static ELOOP : c_int = 62; - pub static ENAMETOOLONG : c_int = 63; - pub static EHOSTDOWN : c_int = 64; - pub static EHOSTUNREACH : c_int = 65; - pub static ENOTEMPTY : c_int = 66; - pub static EPROCLIM : c_int = 67; - pub static EUSERS : c_int = 68; - pub static EDQUOT : c_int = 69; - pub static ESTALE : c_int = 70; - pub static EREMOTE : c_int = 71; - pub static EBADRPC : c_int = 72; - pub static ERPCMISMATCH : c_int = 73; - pub static EPROGUNAVAIL : c_int = 74; - pub static EPROGMISMATCH : c_int = 75; - pub static EPROCUNAVAIL : c_int = 76; - pub static ENOLCK : c_int = 77; - pub static ENOSYS : c_int = 78; - pub static EFTYPE : c_int = 79; - pub static EAUTH : c_int = 80; - pub static ENEEDAUTH : c_int = 81; - pub static EIDRM : c_int = 82; - pub static ENOMSG : c_int = 83; - pub static EOVERFLOW : c_int = 84; - pub static ECANCELED : c_int = 85; - pub static EILSEQ : c_int = 86; - pub static ENOATTR : c_int = 87; - pub static EDOOFUS : c_int = 88; - pub static EBADMSG : c_int = 89; - pub static EMULTIHOP : c_int = 90; - pub static ENOLINK : c_int = 91; - pub static EPROTO : c_int = 92; - pub static ENOMEDIUM : c_int = 93; - pub static EUNUSED94 : c_int = 94; - pub static EUNUSED95 : c_int = 95; - pub static EUNUSED96 : c_int = 96; - pub static EUNUSED97 : c_int = 97; - pub static EUNUSED98 : c_int = 98; - pub static EASYNC : c_int = 99; - pub static ELAST : c_int = 99; + pub const O_RDONLY : c_int = 0; + pub const O_WRONLY : c_int = 1; + pub const O_RDWR : c_int = 2; + pub const O_APPEND : c_int = 8; + pub const O_CREAT : c_int = 512; + pub const O_EXCL : c_int = 2048; + pub const O_TRUNC : c_int = 1024; + pub const S_IFIFO : mode_t = 4096; + pub const S_IFCHR : mode_t = 8192; + pub const S_IFBLK : mode_t = 24576; + pub const S_IFDIR : mode_t = 16384; + pub const S_IFREG : mode_t = 32768; + pub const S_IFLNK : mode_t = 40960; + pub const S_IFMT : mode_t = 61440; + pub const S_IEXEC : mode_t = 64; + pub const S_IWRITE : mode_t = 128; + pub const S_IREAD : mode_t = 256; + pub const S_IRWXU : mode_t = 448; + pub const S_IXUSR : mode_t = 64; + pub const S_IWUSR : mode_t = 128; + pub const S_IRUSR : mode_t = 256; + pub const F_OK : c_int = 0; + pub const R_OK : c_int = 4; + pub const W_OK : c_int = 2; + pub const X_OK : c_int = 1; + pub const STDIN_FILENO : c_int = 0; + pub const STDOUT_FILENO : c_int = 1; + pub const STDERR_FILENO : c_int = 2; + pub const F_LOCK : c_int = 1; + pub const F_TEST : c_int = 3; + pub const F_TLOCK : c_int = 2; + pub const F_ULOCK : c_int = 0; + pub const SIGHUP : c_int = 1; + pub const SIGINT : c_int = 2; + pub const SIGQUIT : c_int = 3; + pub const SIGILL : c_int = 4; + pub const SIGABRT : c_int = 6; + pub const SIGFPE : c_int = 8; + pub const SIGKILL : c_int = 9; + pub const SIGSEGV : c_int = 11; + pub const SIGPIPE : c_int = 13; + pub const SIGALRM : c_int = 14; + pub const SIGTERM : c_int = 15; + + pub const PROT_NONE : c_int = 0; + pub const PROT_READ : c_int = 1; + pub const PROT_WRITE : c_int = 2; + pub const PROT_EXEC : c_int = 4; + + pub const MAP_FILE : c_int = 0x0000; + pub const MAP_SHARED : c_int = 0x0001; + pub const MAP_PRIVATE : c_int = 0x0002; + pub const MAP_FIXED : c_int = 0x0010; + pub const MAP_ANON : c_int = 0x1000; + + pub const MAP_FAILED : *mut c_void = -1 as *mut c_void; + + pub const MCL_CURRENT : c_int = 0x0001; + pub const MCL_FUTURE : c_int = 0x0002; + + pub const MS_SYNC : c_int = 0x0000; + pub const MS_ASYNC : c_int = 0x0001; + pub const MS_INVALIDATE : c_int = 0x0002; + + pub const EPERM : c_int = 1; + pub const ENOENT : c_int = 2; + pub const ESRCH : c_int = 3; + pub const EINTR : c_int = 4; + pub const EIO : c_int = 5; + pub const ENXIO : c_int = 6; + pub const E2BIG : c_int = 7; + pub const ENOEXEC : c_int = 8; + pub const EBADF : c_int = 9; + pub const ECHILD : c_int = 10; + pub const EDEADLK : c_int = 11; + pub const ENOMEM : c_int = 12; + pub const EACCES : c_int = 13; + pub const EFAULT : c_int = 14; + pub const ENOTBLK : c_int = 15; + pub const EBUSY : c_int = 16; + pub const EEXIST : c_int = 17; + pub const EXDEV : c_int = 18; + pub const ENODEV : c_int = 19; + pub const ENOTDIR : c_int = 20; + pub const EISDIR : c_int = 21; + pub const EINVAL : c_int = 22; + pub const ENFILE : c_int = 23; + pub const EMFILE : c_int = 24; + pub const ENOTTY : c_int = 25; + pub const ETXTBSY : c_int = 26; + pub const EFBIG : c_int = 27; + pub const ENOSPC : c_int = 28; + pub const ESPIPE : c_int = 29; + pub const EROFS : c_int = 30; + pub const EMLINK : c_int = 31; + pub const EPIPE : c_int = 32; + pub const EDOM : c_int = 33; + pub const ERANGE : c_int = 34; + pub const EAGAIN : c_int = 35; + pub const EWOULDBLOCK : c_int = 35; + pub const EINPROGRESS : c_int = 36; + pub const EALREADY : c_int = 37; + pub const ENOTSOCK : c_int = 38; + pub const EDESTADDRREQ : c_int = 39; + pub const EMSGSIZE : c_int = 40; + pub const EPROTOTYPE : c_int = 41; + pub const ENOPROTOOPT : c_int = 42; + pub const EPROTONOSUPPORT : c_int = 43; + pub const ESOCKTNOSUPPORT : c_int = 44; + pub const EOPNOTSUPP : c_int = 45; + pub const EPFNOSUPPORT : c_int = 46; + pub const EAFNOSUPPORT : c_int = 47; + pub const EADDRINUSE : c_int = 48; + pub const EADDRNOTAVAIL : c_int = 49; + pub const ENETDOWN : c_int = 50; + pub const ENETUNREACH : c_int = 51; + pub const ENETRESET : c_int = 52; + pub const ECONNABORTED : c_int = 53; + pub const ECONNRESET : c_int = 54; + pub const ENOBUFS : c_int = 55; + pub const EISCONN : c_int = 56; + pub const ENOTCONN : c_int = 57; + pub const ESHUTDOWN : c_int = 58; + pub const ETOOMANYREFS : c_int = 59; + pub const ETIMEDOUT : c_int = 60; + pub const ECONNREFUSED : c_int = 61; + pub const ELOOP : c_int = 62; + pub const ENAMETOOLONG : c_int = 63; + pub const EHOSTDOWN : c_int = 64; + pub const EHOSTUNREACH : c_int = 65; + pub const ENOTEMPTY : c_int = 66; + pub const EPROCLIM : c_int = 67; + pub const EUSERS : c_int = 68; + pub const EDQUOT : c_int = 69; + pub const ESTALE : c_int = 70; + pub const EREMOTE : c_int = 71; + pub const EBADRPC : c_int = 72; + pub const ERPCMISMATCH : c_int = 73; + pub const EPROGUNAVAIL : c_int = 74; + pub const EPROGMISMATCH : c_int = 75; + pub const EPROCUNAVAIL : c_int = 76; + pub const ENOLCK : c_int = 77; + pub const ENOSYS : c_int = 78; + pub const EFTYPE : c_int = 79; + pub const EAUTH : c_int = 80; + pub const ENEEDAUTH : c_int = 81; + pub const EIDRM : c_int = 82; + pub const ENOMSG : c_int = 83; + pub const EOVERFLOW : c_int = 84; + pub const ECANCELED : c_int = 85; + pub const EILSEQ : c_int = 86; + pub const ENOATTR : c_int = 87; + pub const EDOOFUS : c_int = 88; + pub const EBADMSG : c_int = 89; + pub const EMULTIHOP : c_int = 90; + pub const ENOLINK : c_int = 91; + pub const EPROTO : c_int = 92; + pub const ENOMEDIUM : c_int = 93; + pub const EUNUSED94 : c_int = 94; + pub const EUNUSED95 : c_int = 95; + pub const EUNUSED96 : c_int = 96; + pub const EUNUSED97 : c_int = 97; + pub const EUNUSED98 : c_int = 98; + pub const EASYNC : c_int = 99; + pub const ELAST : c_int = 99; } pub mod posix01 { use types::os::arch::c95::{c_int, size_t}; - pub static F_DUPFD : c_int = 0; - pub static F_GETFD : c_int = 1; - pub static F_SETFD : c_int = 2; - pub static F_GETFL : c_int = 3; - pub static F_SETFL : c_int = 4; - - pub static SIGTRAP : c_int = 5; - pub static SIGPIPE: c_int = 13; - pub static SIG_IGN: size_t = 1; - - pub static GLOB_APPEND : c_int = 0x0001; - pub static GLOB_DOOFFS : c_int = 0x0002; - pub static GLOB_ERR : c_int = 0x0004; - pub static GLOB_MARK : c_int = 0x0008; - pub static GLOB_NOCHECK : c_int = 0x0010; - pub static GLOB_NOSORT : c_int = 0x0020; - pub static GLOB_NOESCAPE : c_int = 0x2000; - - pub static GLOB_NOSPACE : c_int = -1; - pub static GLOB_ABORTED : c_int = -2; - pub static GLOB_NOMATCH : c_int = -3; - - pub static POSIX_MADV_NORMAL : c_int = 0; - pub static POSIX_MADV_RANDOM : c_int = 1; - pub static POSIX_MADV_SEQUENTIAL : c_int = 2; - pub static POSIX_MADV_WILLNEED : c_int = 3; - pub static POSIX_MADV_DONTNEED : c_int = 4; - - pub static _SC_IOV_MAX : c_int = 56; - pub static _SC_GETGR_R_SIZE_MAX : c_int = 70; - pub static _SC_GETPW_R_SIZE_MAX : c_int = 71; - pub static _SC_LOGIN_NAME_MAX : c_int = 73; - pub static _SC_MQ_PRIO_MAX : c_int = 75; - pub static _SC_THREAD_ATTR_STACKADDR : c_int = 82; - pub static _SC_THREAD_ATTR_STACKSIZE : c_int = 83; - pub static _SC_THREAD_DESTRUCTOR_ITERATIONS : c_int = 85; - pub static _SC_THREAD_KEYS_MAX : c_int = 86; - pub static _SC_THREAD_PRIO_INHERIT : c_int = 87; - pub static _SC_THREAD_PRIO_PROTECT : c_int = 88; - pub static _SC_THREAD_PRIORITY_SCHEDULING : c_int = 89; - pub static _SC_THREAD_PROCESS_SHARED : c_int = 90; - pub static _SC_THREAD_SAFE_FUNCTIONS : c_int = 91; - pub static _SC_THREAD_STACK_MIN : c_int = 93; - pub static _SC_THREAD_THREADS_MAX : c_int = 94; - pub static _SC_THREADS : c_int = 96; - pub static _SC_TTY_NAME_MAX : c_int = 101; - pub static _SC_ATEXIT_MAX : c_int = 107; - pub static _SC_XOPEN_CRYPT : c_int = 108; - pub static _SC_XOPEN_ENH_I18N : c_int = 109; - pub static _SC_XOPEN_LEGACY : c_int = 110; - pub static _SC_XOPEN_REALTIME : c_int = 111; - pub static _SC_XOPEN_REALTIME_THREADS : c_int = 112; - pub static _SC_XOPEN_SHM : c_int = 113; - pub static _SC_XOPEN_UNIX : c_int = 115; - pub static _SC_XOPEN_VERSION : c_int = 116; - pub static _SC_XOPEN_XCU_VERSION : c_int = 117; - - pub static PTHREAD_CREATE_JOINABLE: c_int = 0; - pub static PTHREAD_CREATE_DETACHED: c_int = 1; + pub const F_DUPFD : c_int = 0; + pub const F_GETFD : c_int = 1; + pub const F_SETFD : c_int = 2; + pub const F_GETFL : c_int = 3; + pub const F_SETFL : c_int = 4; + + pub const SIGTRAP : c_int = 5; + pub const SIGPIPE: c_int = 13; + pub const SIG_IGN: size_t = 1; + + pub const GLOB_APPEND : c_int = 0x0001; + pub const GLOB_DOOFFS : c_int = 0x0002; + pub const GLOB_ERR : c_int = 0x0004; + pub const GLOB_MARK : c_int = 0x0008; + pub const GLOB_NOCHECK : c_int = 0x0010; + pub const GLOB_NOSORT : c_int = 0x0020; + pub const GLOB_NOESCAPE : c_int = 0x2000; + + pub const GLOB_NOSPACE : c_int = -1; + pub const GLOB_ABORTED : c_int = -2; + pub const GLOB_NOMATCH : c_int = -3; + + pub const POSIX_MADV_NORMAL : c_int = 0; + pub const POSIX_MADV_RANDOM : c_int = 1; + pub const POSIX_MADV_SEQUENTIAL : c_int = 2; + pub const POSIX_MADV_WILLNEED : c_int = 3; + pub const POSIX_MADV_DONTNEED : c_int = 4; + + pub const _SC_IOV_MAX : c_int = 56; + pub const _SC_GETGR_R_SIZE_MAX : c_int = 70; + pub const _SC_GETPW_R_SIZE_MAX : c_int = 71; + pub const _SC_LOGIN_NAME_MAX : c_int = 73; + pub const _SC_MQ_PRIO_MAX : c_int = 75; + pub const _SC_THREAD_ATTR_STACKADDR : c_int = 82; + pub const _SC_THREAD_ATTR_STACKSIZE : c_int = 83; + pub const _SC_THREAD_DESTRUCTOR_ITERATIONS : c_int = 85; + pub const _SC_THREAD_KEYS_MAX : c_int = 86; + pub const _SC_THREAD_PRIO_INHERIT : c_int = 87; + pub const _SC_THREAD_PRIO_PROTECT : c_int = 88; + pub const _SC_THREAD_PRIORITY_SCHEDULING : c_int = 89; + pub const _SC_THREAD_PROCESS_SHARED : c_int = 90; + pub const _SC_THREAD_SAFE_FUNCTIONS : c_int = 91; + pub const _SC_THREAD_STACK_MIN : c_int = 93; + pub const _SC_THREAD_THREADS_MAX : c_int = 94; + pub const _SC_THREADS : c_int = 96; + pub const _SC_TTY_NAME_MAX : c_int = 101; + pub const _SC_ATEXIT_MAX : c_int = 107; + pub const _SC_XOPEN_CRYPT : c_int = 108; + pub const _SC_XOPEN_ENH_I18N : c_int = 109; + pub const _SC_XOPEN_LEGACY : c_int = 110; + pub const _SC_XOPEN_REALTIME : c_int = 111; + pub const _SC_XOPEN_REALTIME_THREADS : c_int = 112; + pub const _SC_XOPEN_SHM : c_int = 113; + pub const _SC_XOPEN_UNIX : c_int = 115; + pub const _SC_XOPEN_VERSION : c_int = 116; + pub const _SC_XOPEN_XCU_VERSION : c_int = 117; + + pub const PTHREAD_CREATE_JOINABLE: c_int = 0; + pub const PTHREAD_CREATE_DETACHED: c_int = 1; #[cfg(target_arch = "arm")] - pub static PTHREAD_STACK_MIN: size_t = 4096; + pub const PTHREAD_STACK_MIN: size_t = 4096; #[cfg(all(target_os = "freebsd", any(target_arch = "mips", target_arch = "mipsel", target_arch = "x86", target_arch = "x86_64")))] - pub static PTHREAD_STACK_MIN: size_t = 2048; + pub const PTHREAD_STACK_MIN: size_t = 2048; #[cfg(target_os = "dragonfly")] - pub static PTHREAD_STACK_MIN: size_t = 1024; + pub const PTHREAD_STACK_MIN: size_t = 1024; - pub static CLOCK_REALTIME: c_int = 0; - pub static CLOCK_MONOTONIC: c_int = 4; + pub const CLOCK_REALTIME: c_int = 0; + pub const CLOCK_MONOTONIC: c_int = 4; } pub mod posix08 { } pub mod bsd44 { use types::os::arch::c95::c_int; - pub static MADV_NORMAL : c_int = 0; - pub static MADV_RANDOM : c_int = 1; - pub static MADV_SEQUENTIAL : c_int = 2; - pub static MADV_WILLNEED : c_int = 3; - pub static MADV_DONTNEED : c_int = 4; - pub static MADV_FREE : c_int = 5; - pub static MADV_NOSYNC : c_int = 6; - pub static MADV_AUTOSYNC : c_int = 7; - pub static MADV_NOCORE : c_int = 8; - pub static MADV_CORE : c_int = 9; - pub static MADV_PROTECT : c_int = 10; - - pub static MINCORE_INCORE : c_int = 0x1; - pub static MINCORE_REFERENCED : c_int = 0x2; - pub static MINCORE_MODIFIED : c_int = 0x4; - pub static MINCORE_REFERENCED_OTHER : c_int = 0x8; - pub static MINCORE_MODIFIED_OTHER : c_int = 0x10; - pub static MINCORE_SUPER : c_int = 0x20; - - pub static AF_INET: c_int = 2; - pub static AF_INET6: c_int = 28; - pub static AF_UNIX: c_int = 1; - pub static SOCK_STREAM: c_int = 1; - pub static SOCK_DGRAM: c_int = 2; - pub static SOCK_RAW: c_int = 3; - pub static IPPROTO_TCP: c_int = 6; - pub static IPPROTO_IP: c_int = 0; - pub static IPPROTO_IPV6: c_int = 41; - pub static IP_MULTICAST_TTL: c_int = 10; - pub static IP_MULTICAST_LOOP: c_int = 11; - pub static IP_TTL: c_int = 4; - pub static IP_HDRINCL: c_int = 2; - pub static IP_ADD_MEMBERSHIP: c_int = 12; - pub static IP_DROP_MEMBERSHIP: c_int = 13; - pub static IPV6_ADD_MEMBERSHIP: c_int = 12; - pub static IPV6_DROP_MEMBERSHIP: c_int = 13; - - pub static TCP_NODELAY: c_int = 1; - pub static TCP_KEEPIDLE: c_int = 256; - pub static SOL_SOCKET: c_int = 0xffff; - pub static SO_KEEPALIVE: c_int = 0x0008; - pub static SO_BROADCAST: c_int = 0x0020; - pub static SO_REUSEADDR: c_int = 0x0004; - pub static SO_ERROR: c_int = 0x1007; - - pub static IFF_LOOPBACK: c_int = 0x8; - - pub static SHUT_RD: c_int = 0; - pub static SHUT_WR: c_int = 1; - pub static SHUT_RDWR: c_int = 2; + pub const MADV_NORMAL : c_int = 0; + pub const MADV_RANDOM : c_int = 1; + pub const MADV_SEQUENTIAL : c_int = 2; + pub const MADV_WILLNEED : c_int = 3; + pub const MADV_DONTNEED : c_int = 4; + pub const MADV_FREE : c_int = 5; + pub const MADV_NOSYNC : c_int = 6; + pub const MADV_AUTOSYNC : c_int = 7; + pub const MADV_NOCORE : c_int = 8; + pub const MADV_CORE : c_int = 9; + pub const MADV_PROTECT : c_int = 10; + + pub const MINCORE_INCORE : c_int = 0x1; + pub const MINCORE_REFERENCED : c_int = 0x2; + pub const MINCORE_MODIFIED : c_int = 0x4; + pub const MINCORE_REFERENCED_OTHER : c_int = 0x8; + pub const MINCORE_MODIFIED_OTHER : c_int = 0x10; + pub const MINCORE_SUPER : c_int = 0x20; + + pub const AF_INET: c_int = 2; + pub const AF_INET6: c_int = 28; + pub const AF_UNIX: c_int = 1; + pub const SOCK_STREAM: c_int = 1; + pub const SOCK_DGRAM: c_int = 2; + pub const SOCK_RAW: c_int = 3; + pub const IPPROTO_TCP: c_int = 6; + pub const IPPROTO_IP: c_int = 0; + pub const IPPROTO_IPV6: c_int = 41; + pub const IP_MULTICAST_TTL: c_int = 10; + pub const IP_MULTICAST_LOOP: c_int = 11; + pub const IP_TTL: c_int = 4; + pub const IP_HDRINCL: c_int = 2; + pub const IP_ADD_MEMBERSHIP: c_int = 12; + pub const IP_DROP_MEMBERSHIP: c_int = 13; + pub const IPV6_ADD_MEMBERSHIP: c_int = 12; + pub const IPV6_DROP_MEMBERSHIP: c_int = 13; + + pub const TCP_NODELAY: c_int = 1; + pub const TCP_KEEPIDLE: c_int = 256; + pub const SOL_SOCKET: c_int = 0xffff; + pub const SO_KEEPALIVE: c_int = 0x0008; + pub const SO_BROADCAST: c_int = 0x0020; + pub const SO_REUSEADDR: c_int = 0x0004; + pub const SO_ERROR: c_int = 0x1007; + + pub const IFF_LOOPBACK: c_int = 0x8; + + pub const SHUT_RD: c_int = 0; + pub const SHUT_WR: c_int = 1; + pub const SHUT_RDWR: c_int = 2; } pub mod extra { use types::os::arch::c95::c_int; - pub static O_SYNC : c_int = 128; - pub static O_NONBLOCK : c_int = 4; - pub static CTL_KERN: c_int = 1; - pub static KERN_PROC: c_int = 14; + pub const O_SYNC : c_int = 128; + pub const O_NONBLOCK : c_int = 4; + pub const CTL_KERN: c_int = 1; + pub const KERN_PROC: c_int = 14; #[cfg(target_os = "freebsd")] - pub static KERN_PROC_PATHNAME: c_int = 12; + pub const KERN_PROC_PATHNAME: c_int = 12; #[cfg(target_os = "dragonfly")] - pub static KERN_PROC_PATHNAME: c_int = 9; + pub const KERN_PROC_PATHNAME: c_int = 9; - pub static MAP_COPY : c_int = 0x0002; - pub static MAP_RENAME : c_int = 0x0020; - pub static MAP_NORESERVE : c_int = 0x0040; - pub static MAP_HASSEMAPHORE : c_int = 0x0200; - pub static MAP_STACK : c_int = 0x0400; - pub static MAP_NOSYNC : c_int = 0x0800; - pub static MAP_NOCORE : c_int = 0x020000; + pub const MAP_COPY : c_int = 0x0002; + pub const MAP_RENAME : c_int = 0x0020; + pub const MAP_NORESERVE : c_int = 0x0040; + pub const MAP_HASSEMAPHORE : c_int = 0x0200; + pub const MAP_STACK : c_int = 0x0400; + pub const MAP_NOSYNC : c_int = 0x0800; + pub const MAP_NOCORE : c_int = 0x020000; - pub static IPPROTO_RAW : c_int = 255; + pub const IPPROTO_RAW : c_int = 255; } pub mod sysconf { use types::os::arch::c95::c_int; - pub static _SC_ARG_MAX : c_int = 1; - pub static _SC_CHILD_MAX : c_int = 2; - pub static _SC_CLK_TCK : c_int = 3; - pub static _SC_NGROUPS_MAX : c_int = 4; - pub static _SC_OPEN_MAX : c_int = 5; - pub static _SC_JOB_CONTROL : c_int = 6; - pub static _SC_SAVED_IDS : c_int = 7; - pub static _SC_VERSION : c_int = 8; - pub static _SC_BC_BASE_MAX : c_int = 9; - pub static _SC_BC_DIM_MAX : c_int = 10; - pub static _SC_BC_SCALE_MAX : c_int = 11; - pub static _SC_BC_STRING_MAX : c_int = 12; - pub static _SC_COLL_WEIGHTS_MAX : c_int = 13; - pub static _SC_EXPR_NEST_MAX : c_int = 14; - pub static _SC_LINE_MAX : c_int = 15; - pub static _SC_RE_DUP_MAX : c_int = 16; - pub static _SC_2_VERSION : c_int = 17; - pub static _SC_2_C_BIND : c_int = 18; - pub static _SC_2_C_DEV : c_int = 19; - pub static _SC_2_CHAR_TERM : c_int = 20; - pub static _SC_2_FORT_DEV : c_int = 21; - pub static _SC_2_FORT_RUN : c_int = 22; - pub static _SC_2_LOCALEDEF : c_int = 23; - pub static _SC_2_SW_DEV : c_int = 24; - pub static _SC_2_UPE : c_int = 25; - pub static _SC_STREAM_MAX : c_int = 26; - pub static _SC_TZNAME_MAX : c_int = 27; - pub static _SC_ASYNCHRONOUS_IO : c_int = 28; - pub static _SC_MAPPED_FILES : c_int = 29; - pub static _SC_MEMLOCK : c_int = 30; - pub static _SC_MEMLOCK_RANGE : c_int = 31; - pub static _SC_MEMORY_PROTECTION : c_int = 32; - pub static _SC_MESSAGE_PASSING : c_int = 33; - pub static _SC_PRIORITIZED_IO : c_int = 34; - pub static _SC_PRIORITY_SCHEDULING : c_int = 35; - pub static _SC_REALTIME_SIGNALS : c_int = 36; - pub static _SC_SEMAPHORES : c_int = 37; - pub static _SC_FSYNC : c_int = 38; - pub static _SC_SHARED_MEMORY_OBJECTS : c_int = 39; - pub static _SC_SYNCHRONIZED_IO : c_int = 40; - pub static _SC_TIMERS : c_int = 41; - pub static _SC_AIO_LISTIO_MAX : c_int = 42; - pub static _SC_AIO_MAX : c_int = 43; - pub static _SC_AIO_PRIO_DELTA_MAX : c_int = 44; - pub static _SC_DELAYTIMER_MAX : c_int = 45; - pub static _SC_MQ_OPEN_MAX : c_int = 46; - pub static _SC_PAGESIZE : c_int = 47; - pub static _SC_RTSIG_MAX : c_int = 48; - pub static _SC_SEM_NSEMS_MAX : c_int = 49; - pub static _SC_SEM_VALUE_MAX : c_int = 50; - pub static _SC_SIGQUEUE_MAX : c_int = 51; - pub static _SC_TIMER_MAX : c_int = 52; + pub const _SC_ARG_MAX : c_int = 1; + pub const _SC_CHILD_MAX : c_int = 2; + pub const _SC_CLK_TCK : c_int = 3; + pub const _SC_NGROUPS_MAX : c_int = 4; + pub const _SC_OPEN_MAX : c_int = 5; + pub const _SC_JOB_CONTROL : c_int = 6; + pub const _SC_SAVED_IDS : c_int = 7; + pub const _SC_VERSION : c_int = 8; + pub const _SC_BC_BASE_MAX : c_int = 9; + pub const _SC_BC_DIM_MAX : c_int = 10; + pub const _SC_BC_SCALE_MAX : c_int = 11; + pub const _SC_BC_STRING_MAX : c_int = 12; + pub const _SC_COLL_WEIGHTS_MAX : c_int = 13; + pub const _SC_EXPR_NEST_MAX : c_int = 14; + pub const _SC_LINE_MAX : c_int = 15; + pub const _SC_RE_DUP_MAX : c_int = 16; + pub const _SC_2_VERSION : c_int = 17; + pub const _SC_2_C_BIND : c_int = 18; + pub const _SC_2_C_DEV : c_int = 19; + pub const _SC_2_CHAR_TERM : c_int = 20; + pub const _SC_2_FORT_DEV : c_int = 21; + pub const _SC_2_FORT_RUN : c_int = 22; + pub const _SC_2_LOCALEDEF : c_int = 23; + pub const _SC_2_SW_DEV : c_int = 24; + pub const _SC_2_UPE : c_int = 25; + pub const _SC_STREAM_MAX : c_int = 26; + pub const _SC_TZNAME_MAX : c_int = 27; + pub const _SC_ASYNCHRONOUS_IO : c_int = 28; + pub const _SC_MAPPED_FILES : c_int = 29; + pub const _SC_MEMLOCK : c_int = 30; + pub const _SC_MEMLOCK_RANGE : c_int = 31; + pub const _SC_MEMORY_PROTECTION : c_int = 32; + pub const _SC_MESSAGE_PASSING : c_int = 33; + pub const _SC_PRIORITIZED_IO : c_int = 34; + pub const _SC_PRIORITY_SCHEDULING : c_int = 35; + pub const _SC_REALTIME_SIGNALS : c_int = 36; + pub const _SC_SEMAPHORES : c_int = 37; + pub const _SC_FSYNC : c_int = 38; + pub const _SC_SHARED_MEMORY_OBJECTS : c_int = 39; + pub const _SC_SYNCHRONIZED_IO : c_int = 40; + pub const _SC_TIMERS : c_int = 41; + pub const _SC_AIO_LISTIO_MAX : c_int = 42; + pub const _SC_AIO_MAX : c_int = 43; + pub const _SC_AIO_PRIO_DELTA_MAX : c_int = 44; + pub const _SC_DELAYTIMER_MAX : c_int = 45; + pub const _SC_MQ_OPEN_MAX : c_int = 46; + pub const _SC_PAGESIZE : c_int = 47; + pub const _SC_RTSIG_MAX : c_int = 48; + pub const _SC_SEM_NSEMS_MAX : c_int = 49; + pub const _SC_SEM_VALUE_MAX : c_int = 50; + pub const _SC_SIGQUEUE_MAX : c_int = 51; + pub const _SC_TIMER_MAX : c_int = 52; } } @@ -3566,21 +3566,21 @@ pub mod consts { pub mod c95 { use types::os::arch::c95::{c_int, c_uint}; - pub static EXIT_FAILURE : c_int = 1; - pub static EXIT_SUCCESS : c_int = 0; - pub static RAND_MAX : c_int = 2147483647; - pub static EOF : c_int = -1; - pub static SEEK_SET : c_int = 0; - pub static SEEK_CUR : c_int = 1; - pub static SEEK_END : c_int = 2; - pub static _IOFBF : c_int = 0; - pub static _IONBF : c_int = 2; - pub static _IOLBF : c_int = 1; - pub static BUFSIZ : c_uint = 1024_u32; - pub static FOPEN_MAX : c_uint = 20_u32; - pub static FILENAME_MAX : c_uint = 1024_u32; - pub static L_tmpnam : c_uint = 1024_u32; - pub static TMP_MAX : c_uint = 308915776_u32; + pub const EXIT_FAILURE : c_int = 1; + pub const EXIT_SUCCESS : c_int = 0; + pub const RAND_MAX : c_int = 2147483647; + pub const EOF : c_int = -1; + pub const SEEK_SET : c_int = 0; + pub const SEEK_CUR : c_int = 1; + pub const SEEK_END : c_int = 2; + pub const _IOFBF : c_int = 0; + pub const _IONBF : c_int = 2; + pub const _IOLBF : c_int = 1; + pub const BUFSIZ : c_uint = 1024_u32; + pub const FOPEN_MAX : c_uint = 20_u32; + pub const FILENAME_MAX : c_uint = 1024_u32; + pub const L_tmpnam : c_uint = 1024_u32; + pub const TMP_MAX : c_uint = 308915776_u32; } pub mod c99 { } @@ -3589,378 +3589,378 @@ pub mod consts { use types::os::arch::c95::c_int; use types::os::arch::posix88::mode_t; - pub static O_RDONLY : c_int = 0; - pub static O_WRONLY : c_int = 1; - pub static O_RDWR : c_int = 2; - pub static O_APPEND : c_int = 8; - pub static O_CREAT : c_int = 512; - pub static O_EXCL : c_int = 2048; - pub static O_TRUNC : c_int = 1024; - pub static S_IFIFO : mode_t = 4096; - pub static S_IFCHR : mode_t = 8192; - pub static S_IFBLK : mode_t = 24576; - pub static S_IFDIR : mode_t = 16384; - pub static S_IFREG : mode_t = 32768; - pub static S_IFLNK : mode_t = 40960; - pub static S_IFMT : mode_t = 61440; - pub static S_IEXEC : mode_t = 64; - pub static S_IWRITE : mode_t = 128; - pub static S_IREAD : mode_t = 256; - pub static S_IRWXU : mode_t = 448; - pub static S_IXUSR : mode_t = 64; - pub static S_IWUSR : mode_t = 128; - pub static S_IRUSR : mode_t = 256; - pub static F_OK : c_int = 0; - pub static R_OK : c_int = 4; - pub static W_OK : c_int = 2; - pub static X_OK : c_int = 1; - pub static STDIN_FILENO : c_int = 0; - pub static STDOUT_FILENO : c_int = 1; - pub static STDERR_FILENO : c_int = 2; - pub static F_LOCK : c_int = 1; - pub static F_TEST : c_int = 3; - pub static F_TLOCK : c_int = 2; - pub static F_ULOCK : c_int = 0; - pub static SIGHUP : c_int = 1; - pub static SIGINT : c_int = 2; - pub static SIGQUIT : c_int = 3; - pub static SIGILL : c_int = 4; - pub static SIGABRT : c_int = 6; - pub static SIGFPE : c_int = 8; - pub static SIGKILL : c_int = 9; - pub static SIGSEGV : c_int = 11; - pub static SIGPIPE : c_int = 13; - pub static SIGALRM : c_int = 14; - pub static SIGTERM : c_int = 15; - - pub static PROT_NONE : c_int = 0; - pub static PROT_READ : c_int = 1; - pub static PROT_WRITE : c_int = 2; - pub static PROT_EXEC : c_int = 4; - - pub static MAP_FILE : c_int = 0x0000; - pub static MAP_SHARED : c_int = 0x0001; - pub static MAP_PRIVATE : c_int = 0x0002; - pub static MAP_FIXED : c_int = 0x0010; - pub static MAP_ANON : c_int = 0x1000; - - pub static MAP_FAILED : *mut c_void = -1 as *mut c_void; - - pub static MCL_CURRENT : c_int = 0x0001; - pub static MCL_FUTURE : c_int = 0x0002; - - pub static MS_ASYNC : c_int = 0x0001; - pub static MS_INVALIDATE : c_int = 0x0002; - pub static MS_SYNC : c_int = 0x0010; - - pub static MS_KILLPAGES : c_int = 0x0004; - pub static MS_DEACTIVATE : c_int = 0x0008; - - pub static EPERM : c_int = 1; - pub static ENOENT : c_int = 2; - pub static ESRCH : c_int = 3; - pub static EINTR : c_int = 4; - pub static EIO : c_int = 5; - pub static ENXIO : c_int = 6; - pub static E2BIG : c_int = 7; - pub static ENOEXEC : c_int = 8; - pub static EBADF : c_int = 9; - pub static ECHILD : c_int = 10; - pub static EDEADLK : c_int = 11; - pub static ENOMEM : c_int = 12; - pub static EACCES : c_int = 13; - pub static EFAULT : c_int = 14; - pub static ENOTBLK : c_int = 15; - pub static EBUSY : c_int = 16; - pub static EEXIST : c_int = 17; - pub static EXDEV : c_int = 18; - pub static ENODEV : c_int = 19; - pub static ENOTDIR : c_int = 20; - pub static EISDIR : c_int = 21; - pub static EINVAL : c_int = 22; - pub static ENFILE : c_int = 23; - pub static EMFILE : c_int = 24; - pub static ENOTTY : c_int = 25; - pub static ETXTBSY : c_int = 26; - pub static EFBIG : c_int = 27; - pub static ENOSPC : c_int = 28; - pub static ESPIPE : c_int = 29; - pub static EROFS : c_int = 30; - pub static EMLINK : c_int = 31; - pub static EPIPE : c_int = 32; - pub static EDOM : c_int = 33; - pub static ERANGE : c_int = 34; - pub static EAGAIN : c_int = 35; - pub static EWOULDBLOCK : c_int = EAGAIN; - pub static EINPROGRESS : c_int = 36; - pub static EALREADY : c_int = 37; - pub static ENOTSOCK : c_int = 38; - pub static EDESTADDRREQ : c_int = 39; - pub static EMSGSIZE : c_int = 40; - pub static EPROTOTYPE : c_int = 41; - pub static ENOPROTOOPT : c_int = 42; - pub static EPROTONOSUPPORT : c_int = 43; - pub static ESOCKTNOSUPPORT : c_int = 44; - pub static ENOTSUP : c_int = 45; - pub static EPFNOSUPPORT : c_int = 46; - pub static EAFNOSUPPORT : c_int = 47; - pub static EADDRINUSE : c_int = 48; - pub static EADDRNOTAVAIL : c_int = 49; - pub static ENETDOWN : c_int = 50; - pub static ENETUNREACH : c_int = 51; - pub static ENETRESET : c_int = 52; - pub static ECONNABORTED : c_int = 53; - pub static ECONNRESET : c_int = 54; - pub static ENOBUFS : c_int = 55; - pub static EISCONN : c_int = 56; - pub static ENOTCONN : c_int = 57; - pub static ESHUTDOWN : c_int = 58; - pub static ETOOMANYREFS : c_int = 59; - pub static ETIMEDOUT : c_int = 60; - pub static ECONNREFUSED : c_int = 61; - pub static ELOOP : c_int = 62; - pub static ENAMETOOLONG : c_int = 63; - pub static EHOSTDOWN : c_int = 64; - pub static EHOSTUNREACH : c_int = 65; - pub static ENOTEMPTY : c_int = 66; - pub static EPROCLIM : c_int = 67; - pub static EUSERS : c_int = 68; - pub static EDQUOT : c_int = 69; - pub static ESTALE : c_int = 70; - pub static EREMOTE : c_int = 71; - pub static EBADRPC : c_int = 72; - pub static ERPCMISMATCH : c_int = 73; - pub static EPROGUNAVAIL : c_int = 74; - pub static EPROGMISMATCH : c_int = 75; - pub static EPROCUNAVAIL : c_int = 76; - pub static ENOLCK : c_int = 77; - pub static ENOSYS : c_int = 78; - pub static EFTYPE : c_int = 79; - pub static EAUTH : c_int = 80; - pub static ENEEDAUTH : c_int = 81; - pub static EPWROFF : c_int = 82; - pub static EDEVERR : c_int = 83; - pub static EOVERFLOW : c_int = 84; - pub static EBADEXEC : c_int = 85; - pub static EBADARCH : c_int = 86; - pub static ESHLIBVERS : c_int = 87; - pub static EBADMACHO : c_int = 88; - pub static ECANCELED : c_int = 89; - pub static EIDRM : c_int = 90; - pub static ENOMSG : c_int = 91; - pub static EILSEQ : c_int = 92; - pub static ENOATTR : c_int = 93; - pub static EBADMSG : c_int = 94; - pub static EMULTIHOP : c_int = 95; - pub static ENODATA : c_int = 96; - pub static ENOLINK : c_int = 97; - pub static ENOSR : c_int = 98; - pub static ENOSTR : c_int = 99; - pub static EPROTO : c_int = 100; - pub static ETIME : c_int = 101; - pub static EOPNOTSUPP : c_int = 102; - pub static ENOPOLICY : c_int = 103; - pub static ENOTRECOVERABLE : c_int = 104; - pub static EOWNERDEAD : c_int = 105; - pub static EQFULL : c_int = 106; - pub static ELAST : c_int = 106; + pub const O_RDONLY : c_int = 0; + pub const O_WRONLY : c_int = 1; + pub const O_RDWR : c_int = 2; + pub const O_APPEND : c_int = 8; + pub const O_CREAT : c_int = 512; + pub const O_EXCL : c_int = 2048; + pub const O_TRUNC : c_int = 1024; + pub const S_IFIFO : mode_t = 4096; + pub const S_IFCHR : mode_t = 8192; + pub const S_IFBLK : mode_t = 24576; + pub const S_IFDIR : mode_t = 16384; + pub const S_IFREG : mode_t = 32768; + pub const S_IFLNK : mode_t = 40960; + pub const S_IFMT : mode_t = 61440; + pub const S_IEXEC : mode_t = 64; + pub const S_IWRITE : mode_t = 128; + pub const S_IREAD : mode_t = 256; + pub const S_IRWXU : mode_t = 448; + pub const S_IXUSR : mode_t = 64; + pub const S_IWUSR : mode_t = 128; + pub const S_IRUSR : mode_t = 256; + pub const F_OK : c_int = 0; + pub const R_OK : c_int = 4; + pub const W_OK : c_int = 2; + pub const X_OK : c_int = 1; + pub const STDIN_FILENO : c_int = 0; + pub const STDOUT_FILENO : c_int = 1; + pub const STDERR_FILENO : c_int = 2; + pub const F_LOCK : c_int = 1; + pub const F_TEST : c_int = 3; + pub const F_TLOCK : c_int = 2; + pub const F_ULOCK : c_int = 0; + pub const SIGHUP : c_int = 1; + pub const SIGINT : c_int = 2; + pub const SIGQUIT : c_int = 3; + pub const SIGILL : c_int = 4; + pub const SIGABRT : c_int = 6; + pub const SIGFPE : c_int = 8; + pub const SIGKILL : c_int = 9; + pub const SIGSEGV : c_int = 11; + pub const SIGPIPE : c_int = 13; + pub const SIGALRM : c_int = 14; + pub const SIGTERM : c_int = 15; + + pub const PROT_NONE : c_int = 0; + pub const PROT_READ : c_int = 1; + pub const PROT_WRITE : c_int = 2; + pub const PROT_EXEC : c_int = 4; + + pub const MAP_FILE : c_int = 0x0000; + pub const MAP_SHARED : c_int = 0x0001; + pub const MAP_PRIVATE : c_int = 0x0002; + pub const MAP_FIXED : c_int = 0x0010; + pub const MAP_ANON : c_int = 0x1000; + + pub const MAP_FAILED : *mut c_void = -1 as *mut c_void; + + pub const MCL_CURRENT : c_int = 0x0001; + pub const MCL_FUTURE : c_int = 0x0002; + + pub const MS_ASYNC : c_int = 0x0001; + pub const MS_INVALIDATE : c_int = 0x0002; + pub const MS_SYNC : c_int = 0x0010; + + pub const MS_KILLPAGES : c_int = 0x0004; + pub const MS_DEACTIVATE : c_int = 0x0008; + + pub const EPERM : c_int = 1; + pub const ENOENT : c_int = 2; + pub const ESRCH : c_int = 3; + pub const EINTR : c_int = 4; + pub const EIO : c_int = 5; + pub const ENXIO : c_int = 6; + pub const E2BIG : c_int = 7; + pub const ENOEXEC : c_int = 8; + pub const EBADF : c_int = 9; + pub const ECHILD : c_int = 10; + pub const EDEADLK : c_int = 11; + pub const ENOMEM : c_int = 12; + pub const EACCES : c_int = 13; + pub const EFAULT : c_int = 14; + pub const ENOTBLK : c_int = 15; + pub const EBUSY : c_int = 16; + pub const EEXIST : c_int = 17; + pub const EXDEV : c_int = 18; + pub const ENODEV : c_int = 19; + pub const ENOTDIR : c_int = 20; + pub const EISDIR : c_int = 21; + pub const EINVAL : c_int = 22; + pub const ENFILE : c_int = 23; + pub const EMFILE : c_int = 24; + pub const ENOTTY : c_int = 25; + pub const ETXTBSY : c_int = 26; + pub const EFBIG : c_int = 27; + pub const ENOSPC : c_int = 28; + pub const ESPIPE : c_int = 29; + pub const EROFS : c_int = 30; + pub const EMLINK : c_int = 31; + pub const EPIPE : c_int = 32; + pub const EDOM : c_int = 33; + pub const ERANGE : c_int = 34; + pub const EAGAIN : c_int = 35; + pub const EWOULDBLOCK : c_int = EAGAIN; + pub const EINPROGRESS : c_int = 36; + pub const EALREADY : c_int = 37; + pub const ENOTSOCK : c_int = 38; + pub const EDESTADDRREQ : c_int = 39; + pub const EMSGSIZE : c_int = 40; + pub const EPROTOTYPE : c_int = 41; + pub const ENOPROTOOPT : c_int = 42; + pub const EPROTONOSUPPORT : c_int = 43; + pub const ESOCKTNOSUPPORT : c_int = 44; + pub const ENOTSUP : c_int = 45; + pub const EPFNOSUPPORT : c_int = 46; + pub const EAFNOSUPPORT : c_int = 47; + pub const EADDRINUSE : c_int = 48; + pub const EADDRNOTAVAIL : c_int = 49; + pub const ENETDOWN : c_int = 50; + pub const ENETUNREACH : c_int = 51; + pub const ENETRESET : c_int = 52; + pub const ECONNABORTED : c_int = 53; + pub const ECONNRESET : c_int = 54; + pub const ENOBUFS : c_int = 55; + pub const EISCONN : c_int = 56; + pub const ENOTCONN : c_int = 57; + pub const ESHUTDOWN : c_int = 58; + pub const ETOOMANYREFS : c_int = 59; + pub const ETIMEDOUT : c_int = 60; + pub const ECONNREFUSED : c_int = 61; + pub const ELOOP : c_int = 62; + pub const ENAMETOOLONG : c_int = 63; + pub const EHOSTDOWN : c_int = 64; + pub const EHOSTUNREACH : c_int = 65; + pub const ENOTEMPTY : c_int = 66; + pub const EPROCLIM : c_int = 67; + pub const EUSERS : c_int = 68; + pub const EDQUOT : c_int = 69; + pub const ESTALE : c_int = 70; + pub const EREMOTE : c_int = 71; + pub const EBADRPC : c_int = 72; + pub const ERPCMISMATCH : c_int = 73; + pub const EPROGUNAVAIL : c_int = 74; + pub const EPROGMISMATCH : c_int = 75; + pub const EPROCUNAVAIL : c_int = 76; + pub const ENOLCK : c_int = 77; + pub const ENOSYS : c_int = 78; + pub const EFTYPE : c_int = 79; + pub const EAUTH : c_int = 80; + pub const ENEEDAUTH : c_int = 81; + pub const EPWROFF : c_int = 82; + pub const EDEVERR : c_int = 83; + pub const EOVERFLOW : c_int = 84; + pub const EBADEXEC : c_int = 85; + pub const EBADARCH : c_int = 86; + pub const ESHLIBVERS : c_int = 87; + pub const EBADMACHO : c_int = 88; + pub const ECANCELED : c_int = 89; + pub const EIDRM : c_int = 90; + pub const ENOMSG : c_int = 91; + pub const EILSEQ : c_int = 92; + pub const ENOATTR : c_int = 93; + pub const EBADMSG : c_int = 94; + pub const EMULTIHOP : c_int = 95; + pub const ENODATA : c_int = 96; + pub const ENOLINK : c_int = 97; + pub const ENOSR : c_int = 98; + pub const ENOSTR : c_int = 99; + pub const EPROTO : c_int = 100; + pub const ETIME : c_int = 101; + pub const EOPNOTSUPP : c_int = 102; + pub const ENOPOLICY : c_int = 103; + pub const ENOTRECOVERABLE : c_int = 104; + pub const EOWNERDEAD : c_int = 105; + pub const EQFULL : c_int = 106; + pub const ELAST : c_int = 106; } pub mod posix01 { use types::os::arch::c95::{c_int, size_t}; - pub static F_DUPFD : c_int = 0; - pub static F_GETFD : c_int = 1; - pub static F_SETFD : c_int = 2; - pub static F_GETFL : c_int = 3; - pub static F_SETFL : c_int = 4; - - pub static SIGTRAP : c_int = 5; - pub static SIGPIPE: c_int = 13; - pub static SIG_IGN: size_t = 1; - - pub static GLOB_APPEND : c_int = 0x0001; - pub static GLOB_DOOFFS : c_int = 0x0002; - pub static GLOB_ERR : c_int = 0x0004; - pub static GLOB_MARK : c_int = 0x0008; - pub static GLOB_NOCHECK : c_int = 0x0010; - pub static GLOB_NOSORT : c_int = 0x0020; - pub static GLOB_NOESCAPE : c_int = 0x2000; - - pub static GLOB_NOSPACE : c_int = -1; - pub static GLOB_ABORTED : c_int = -2; - pub static GLOB_NOMATCH : c_int = -3; - - pub static POSIX_MADV_NORMAL : c_int = 0; - pub static POSIX_MADV_RANDOM : c_int = 1; - pub static POSIX_MADV_SEQUENTIAL : c_int = 2; - pub static POSIX_MADV_WILLNEED : c_int = 3; - pub static POSIX_MADV_DONTNEED : c_int = 4; - - pub static _SC_IOV_MAX : c_int = 56; - pub static _SC_GETGR_R_SIZE_MAX : c_int = 70; - pub static _SC_GETPW_R_SIZE_MAX : c_int = 71; - pub static _SC_LOGIN_NAME_MAX : c_int = 73; - pub static _SC_MQ_PRIO_MAX : c_int = 75; - pub static _SC_THREAD_ATTR_STACKADDR : c_int = 82; - pub static _SC_THREAD_ATTR_STACKSIZE : c_int = 83; - pub static _SC_THREAD_DESTRUCTOR_ITERATIONS : c_int = 85; - pub static _SC_THREAD_KEYS_MAX : c_int = 86; - pub static _SC_THREAD_PRIO_INHERIT : c_int = 87; - pub static _SC_THREAD_PRIO_PROTECT : c_int = 88; - pub static _SC_THREAD_PRIORITY_SCHEDULING : c_int = 89; - pub static _SC_THREAD_PROCESS_SHARED : c_int = 90; - pub static _SC_THREAD_SAFE_FUNCTIONS : c_int = 91; - pub static _SC_THREAD_STACK_MIN : c_int = 93; - pub static _SC_THREAD_THREADS_MAX : c_int = 94; - pub static _SC_THREADS : c_int = 96; - pub static _SC_TTY_NAME_MAX : c_int = 101; - pub static _SC_ATEXIT_MAX : c_int = 107; - pub static _SC_XOPEN_CRYPT : c_int = 108; - pub static _SC_XOPEN_ENH_I18N : c_int = 109; - pub static _SC_XOPEN_LEGACY : c_int = 110; - pub static _SC_XOPEN_REALTIME : c_int = 111; - pub static _SC_XOPEN_REALTIME_THREADS : c_int = 112; - pub static _SC_XOPEN_SHM : c_int = 113; - pub static _SC_XOPEN_UNIX : c_int = 115; - pub static _SC_XOPEN_VERSION : c_int = 116; - pub static _SC_XOPEN_XCU_VERSION : c_int = 121; - - pub static PTHREAD_CREATE_JOINABLE: c_int = 1; - pub static PTHREAD_CREATE_DETACHED: c_int = 2; - pub static PTHREAD_STACK_MIN: size_t = 8192; + pub const F_DUPFD : c_int = 0; + pub const F_GETFD : c_int = 1; + pub const F_SETFD : c_int = 2; + pub const F_GETFL : c_int = 3; + pub const F_SETFL : c_int = 4; + + pub const SIGTRAP : c_int = 5; + pub const SIGPIPE: c_int = 13; + pub const SIG_IGN: size_t = 1; + + pub const GLOB_APPEND : c_int = 0x0001; + pub const GLOB_DOOFFS : c_int = 0x0002; + pub const GLOB_ERR : c_int = 0x0004; + pub const GLOB_MARK : c_int = 0x0008; + pub const GLOB_NOCHECK : c_int = 0x0010; + pub const GLOB_NOSORT : c_int = 0x0020; + pub const GLOB_NOESCAPE : c_int = 0x2000; + + pub const GLOB_NOSPACE : c_int = -1; + pub const GLOB_ABORTED : c_int = -2; + pub const GLOB_NOMATCH : c_int = -3; + + pub const POSIX_MADV_NORMAL : c_int = 0; + pub const POSIX_MADV_RANDOM : c_int = 1; + pub const POSIX_MADV_SEQUENTIAL : c_int = 2; + pub const POSIX_MADV_WILLNEED : c_int = 3; + pub const POSIX_MADV_DONTNEED : c_int = 4; + + pub const _SC_IOV_MAX : c_int = 56; + pub const _SC_GETGR_R_SIZE_MAX : c_int = 70; + pub const _SC_GETPW_R_SIZE_MAX : c_int = 71; + pub const _SC_LOGIN_NAME_MAX : c_int = 73; + pub const _SC_MQ_PRIO_MAX : c_int = 75; + pub const _SC_THREAD_ATTR_STACKADDR : c_int = 82; + pub const _SC_THREAD_ATTR_STACKSIZE : c_int = 83; + pub const _SC_THREAD_DESTRUCTOR_ITERATIONS : c_int = 85; + pub const _SC_THREAD_KEYS_MAX : c_int = 86; + pub const _SC_THREAD_PRIO_INHERIT : c_int = 87; + pub const _SC_THREAD_PRIO_PROTECT : c_int = 88; + pub const _SC_THREAD_PRIORITY_SCHEDULING : c_int = 89; + pub const _SC_THREAD_PROCESS_SHARED : c_int = 90; + pub const _SC_THREAD_SAFE_FUNCTIONS : c_int = 91; + pub const _SC_THREAD_STACK_MIN : c_int = 93; + pub const _SC_THREAD_THREADS_MAX : c_int = 94; + pub const _SC_THREADS : c_int = 96; + pub const _SC_TTY_NAME_MAX : c_int = 101; + pub const _SC_ATEXIT_MAX : c_int = 107; + pub const _SC_XOPEN_CRYPT : c_int = 108; + pub const _SC_XOPEN_ENH_I18N : c_int = 109; + pub const _SC_XOPEN_LEGACY : c_int = 110; + pub const _SC_XOPEN_REALTIME : c_int = 111; + pub const _SC_XOPEN_REALTIME_THREADS : c_int = 112; + pub const _SC_XOPEN_SHM : c_int = 113; + pub const _SC_XOPEN_UNIX : c_int = 115; + pub const _SC_XOPEN_VERSION : c_int = 116; + pub const _SC_XOPEN_XCU_VERSION : c_int = 121; + + pub const PTHREAD_CREATE_JOINABLE: c_int = 1; + pub const PTHREAD_CREATE_DETACHED: c_int = 2; + pub const PTHREAD_STACK_MIN: size_t = 8192; } pub mod posix08 { } pub mod bsd44 { use types::os::arch::c95::c_int; - pub static MADV_NORMAL : c_int = 0; - pub static MADV_RANDOM : c_int = 1; - pub static MADV_SEQUENTIAL : c_int = 2; - pub static MADV_WILLNEED : c_int = 3; - pub static MADV_DONTNEED : c_int = 4; - pub static MADV_FREE : c_int = 5; - pub static MADV_ZERO_WIRED_PAGES : c_int = 6; - pub static MADV_FREE_REUSABLE : c_int = 7; - pub static MADV_FREE_REUSE : c_int = 8; - pub static MADV_CAN_REUSE : c_int = 9; - - pub static MINCORE_INCORE : c_int = 0x1; - pub static MINCORE_REFERENCED : c_int = 0x2; - pub static MINCORE_MODIFIED : c_int = 0x4; - pub static MINCORE_REFERENCED_OTHER : c_int = 0x8; - pub static MINCORE_MODIFIED_OTHER : c_int = 0x10; - - pub static AF_UNIX: c_int = 1; - pub static AF_INET: c_int = 2; - pub static AF_INET6: c_int = 30; - pub static SOCK_STREAM: c_int = 1; - pub static SOCK_DGRAM: c_int = 2; - pub static SOCK_RAW: c_int = 3; - pub static IPPROTO_TCP: c_int = 6; - pub static IPPROTO_IP: c_int = 0; - pub static IPPROTO_IPV6: c_int = 41; - pub static IP_MULTICAST_TTL: c_int = 10; - pub static IP_MULTICAST_LOOP: c_int = 11; - pub static IP_TTL: c_int = 4; - pub static IP_HDRINCL: c_int = 2; - pub static IP_ADD_MEMBERSHIP: c_int = 12; - pub static IP_DROP_MEMBERSHIP: c_int = 13; - pub static IPV6_ADD_MEMBERSHIP: c_int = 12; - pub static IPV6_DROP_MEMBERSHIP: c_int = 13; - - pub static TCP_NODELAY: c_int = 0x01; - pub static TCP_KEEPALIVE: c_int = 0x10; - pub static SOL_SOCKET: c_int = 0xffff; - pub static SO_KEEPALIVE: c_int = 0x0008; - pub static SO_BROADCAST: c_int = 0x0020; - pub static SO_REUSEADDR: c_int = 0x0004; - pub static SO_ERROR: c_int = 0x1007; - - pub static IFF_LOOPBACK: c_int = 0x8; - - pub static SHUT_RD: c_int = 0; - pub static SHUT_WR: c_int = 1; - pub static SHUT_RDWR: c_int = 2; + pub const MADV_NORMAL : c_int = 0; + pub const MADV_RANDOM : c_int = 1; + pub const MADV_SEQUENTIAL : c_int = 2; + pub const MADV_WILLNEED : c_int = 3; + pub const MADV_DONTNEED : c_int = 4; + pub const MADV_FREE : c_int = 5; + pub const MADV_ZERO_WIRED_PAGES : c_int = 6; + pub const MADV_FREE_REUSABLE : c_int = 7; + pub const MADV_FREE_REUSE : c_int = 8; + pub const MADV_CAN_REUSE : c_int = 9; + + pub const MINCORE_INCORE : c_int = 0x1; + pub const MINCORE_REFERENCED : c_int = 0x2; + pub const MINCORE_MODIFIED : c_int = 0x4; + pub const MINCORE_REFERENCED_OTHER : c_int = 0x8; + pub const MINCORE_MODIFIED_OTHER : c_int = 0x10; + + pub const AF_UNIX: c_int = 1; + pub const AF_INET: c_int = 2; + pub const AF_INET6: c_int = 30; + pub const SOCK_STREAM: c_int = 1; + pub const SOCK_DGRAM: c_int = 2; + pub const SOCK_RAW: c_int = 3; + pub const IPPROTO_TCP: c_int = 6; + pub const IPPROTO_IP: c_int = 0; + pub const IPPROTO_IPV6: c_int = 41; + pub const IP_MULTICAST_TTL: c_int = 10; + pub const IP_MULTICAST_LOOP: c_int = 11; + pub const IP_TTL: c_int = 4; + pub const IP_HDRINCL: c_int = 2; + pub const IP_ADD_MEMBERSHIP: c_int = 12; + pub const IP_DROP_MEMBERSHIP: c_int = 13; + pub const IPV6_ADD_MEMBERSHIP: c_int = 12; + pub const IPV6_DROP_MEMBERSHIP: c_int = 13; + + pub const TCP_NODELAY: c_int = 0x01; + pub const TCP_KEEPALIVE: c_int = 0x10; + pub const SOL_SOCKET: c_int = 0xffff; + pub const SO_KEEPALIVE: c_int = 0x0008; + pub const SO_BROADCAST: c_int = 0x0020; + pub const SO_REUSEADDR: c_int = 0x0004; + pub const SO_ERROR: c_int = 0x1007; + + pub const IFF_LOOPBACK: c_int = 0x8; + + pub const SHUT_RD: c_int = 0; + pub const SHUT_WR: c_int = 1; + pub const SHUT_RDWR: c_int = 2; } pub mod extra { use types::os::arch::c95::c_int; - pub static O_DSYNC : c_int = 4194304; - pub static O_SYNC : c_int = 128; - pub static O_NONBLOCK : c_int = 4; - pub static F_FULLFSYNC : c_int = 51; - - pub static MAP_COPY : c_int = 0x0002; - pub static MAP_RENAME : c_int = 0x0020; - pub static MAP_NORESERVE : c_int = 0x0040; - pub static MAP_NOEXTEND : c_int = 0x0100; - pub static MAP_HASSEMAPHORE : c_int = 0x0200; - pub static MAP_NOCACHE : c_int = 0x0400; - pub static MAP_JIT : c_int = 0x0800; - pub static MAP_STACK : c_int = 0; - - pub static IPPROTO_RAW : c_int = 255; + pub const O_DSYNC : c_int = 4194304; + pub const O_SYNC : c_int = 128; + pub const O_NONBLOCK : c_int = 4; + pub const F_FULLFSYNC : c_int = 51; + + pub const MAP_COPY : c_int = 0x0002; + pub const MAP_RENAME : c_int = 0x0020; + pub const MAP_NORESERVE : c_int = 0x0040; + pub const MAP_NOEXTEND : c_int = 0x0100; + pub const MAP_HASSEMAPHORE : c_int = 0x0200; + pub const MAP_NOCACHE : c_int = 0x0400; + pub const MAP_JIT : c_int = 0x0800; + pub const MAP_STACK : c_int = 0; + + pub const IPPROTO_RAW : c_int = 255; } pub mod sysconf { use types::os::arch::c95::c_int; - pub static _SC_ARG_MAX : c_int = 1; - pub static _SC_CHILD_MAX : c_int = 2; - pub static _SC_CLK_TCK : c_int = 3; - pub static _SC_NGROUPS_MAX : c_int = 4; - pub static _SC_OPEN_MAX : c_int = 5; - pub static _SC_JOB_CONTROL : c_int = 6; - pub static _SC_SAVED_IDS : c_int = 7; - pub static _SC_VERSION : c_int = 8; - pub static _SC_BC_BASE_MAX : c_int = 9; - pub static _SC_BC_DIM_MAX : c_int = 10; - pub static _SC_BC_SCALE_MAX : c_int = 11; - pub static _SC_BC_STRING_MAX : c_int = 12; - pub static _SC_COLL_WEIGHTS_MAX : c_int = 13; - pub static _SC_EXPR_NEST_MAX : c_int = 14; - pub static _SC_LINE_MAX : c_int = 15; - pub static _SC_RE_DUP_MAX : c_int = 16; - pub static _SC_2_VERSION : c_int = 17; - pub static _SC_2_C_BIND : c_int = 18; - pub static _SC_2_C_DEV : c_int = 19; - pub static _SC_2_CHAR_TERM : c_int = 20; - pub static _SC_2_FORT_DEV : c_int = 21; - pub static _SC_2_FORT_RUN : c_int = 22; - pub static _SC_2_LOCALEDEF : c_int = 23; - pub static _SC_2_SW_DEV : c_int = 24; - pub static _SC_2_UPE : c_int = 25; - pub static _SC_STREAM_MAX : c_int = 26; - pub static _SC_TZNAME_MAX : c_int = 27; - pub static _SC_ASYNCHRONOUS_IO : c_int = 28; - pub static _SC_PAGESIZE : c_int = 29; - pub static _SC_MEMLOCK : c_int = 30; - pub static _SC_MEMLOCK_RANGE : c_int = 31; - pub static _SC_MEMORY_PROTECTION : c_int = 32; - pub static _SC_MESSAGE_PASSING : c_int = 33; - pub static _SC_PRIORITIZED_IO : c_int = 34; - pub static _SC_PRIORITY_SCHEDULING : c_int = 35; - pub static _SC_REALTIME_SIGNALS : c_int = 36; - pub static _SC_SEMAPHORES : c_int = 37; - pub static _SC_FSYNC : c_int = 38; - pub static _SC_SHARED_MEMORY_OBJECTS : c_int = 39; - pub static _SC_SYNCHRONIZED_IO : c_int = 40; - pub static _SC_TIMERS : c_int = 41; - pub static _SC_AIO_LISTIO_MAX : c_int = 42; - pub static _SC_AIO_MAX : c_int = 43; - pub static _SC_AIO_PRIO_DELTA_MAX : c_int = 44; - pub static _SC_DELAYTIMER_MAX : c_int = 45; - pub static _SC_MQ_OPEN_MAX : c_int = 46; - pub static _SC_MAPPED_FILES : c_int = 47; - pub static _SC_RTSIG_MAX : c_int = 48; - pub static _SC_SEM_NSEMS_MAX : c_int = 49; - pub static _SC_SEM_VALUE_MAX : c_int = 50; - pub static _SC_SIGQUEUE_MAX : c_int = 51; - pub static _SC_TIMER_MAX : c_int = 52; - pub static _SC_XBS5_ILP32_OFF32 : c_int = 122; - pub static _SC_XBS5_ILP32_OFFBIG : c_int = 123; - pub static _SC_XBS5_LP64_OFF64 : c_int = 124; - pub static _SC_XBS5_LPBIG_OFFBIG : c_int = 125; + pub const _SC_ARG_MAX : c_int = 1; + pub const _SC_CHILD_MAX : c_int = 2; + pub const _SC_CLK_TCK : c_int = 3; + pub const _SC_NGROUPS_MAX : c_int = 4; + pub const _SC_OPEN_MAX : c_int = 5; + pub const _SC_JOB_CONTROL : c_int = 6; + pub const _SC_SAVED_IDS : c_int = 7; + pub const _SC_VERSION : c_int = 8; + pub const _SC_BC_BASE_MAX : c_int = 9; + pub const _SC_BC_DIM_MAX : c_int = 10; + pub const _SC_BC_SCALE_MAX : c_int = 11; + pub const _SC_BC_STRING_MAX : c_int = 12; + pub const _SC_COLL_WEIGHTS_MAX : c_int = 13; + pub const _SC_EXPR_NEST_MAX : c_int = 14; + pub const _SC_LINE_MAX : c_int = 15; + pub const _SC_RE_DUP_MAX : c_int = 16; + pub const _SC_2_VERSION : c_int = 17; + pub const _SC_2_C_BIND : c_int = 18; + pub const _SC_2_C_DEV : c_int = 19; + pub const _SC_2_CHAR_TERM : c_int = 20; + pub const _SC_2_FORT_DEV : c_int = 21; + pub const _SC_2_FORT_RUN : c_int = 22; + pub const _SC_2_LOCALEDEF : c_int = 23; + pub const _SC_2_SW_DEV : c_int = 24; + pub const _SC_2_UPE : c_int = 25; + pub const _SC_STREAM_MAX : c_int = 26; + pub const _SC_TZNAME_MAX : c_int = 27; + pub const _SC_ASYNCHRONOUS_IO : c_int = 28; + pub const _SC_PAGESIZE : c_int = 29; + pub const _SC_MEMLOCK : c_int = 30; + pub const _SC_MEMLOCK_RANGE : c_int = 31; + pub const _SC_MEMORY_PROTECTION : c_int = 32; + pub const _SC_MESSAGE_PASSING : c_int = 33; + pub const _SC_PRIORITIZED_IO : c_int = 34; + pub const _SC_PRIORITY_SCHEDULING : c_int = 35; + pub const _SC_REALTIME_SIGNALS : c_int = 36; + pub const _SC_SEMAPHORES : c_int = 37; + pub const _SC_FSYNC : c_int = 38; + pub const _SC_SHARED_MEMORY_OBJECTS : c_int = 39; + pub const _SC_SYNCHRONIZED_IO : c_int = 40; + pub const _SC_TIMERS : c_int = 41; + pub const _SC_AIO_LISTIO_MAX : c_int = 42; + pub const _SC_AIO_MAX : c_int = 43; + pub const _SC_AIO_PRIO_DELTA_MAX : c_int = 44; + pub const _SC_DELAYTIMER_MAX : c_int = 45; + pub const _SC_MQ_OPEN_MAX : c_int = 46; + pub const _SC_MAPPED_FILES : c_int = 47; + pub const _SC_RTSIG_MAX : c_int = 48; + pub const _SC_SEM_NSEMS_MAX : c_int = 49; + pub const _SC_SEM_VALUE_MAX : c_int = 50; + pub const _SC_SIGQUEUE_MAX : c_int = 51; + pub const _SC_TIMER_MAX : c_int = 52; + pub const _SC_XBS5_ILP32_OFF32 : c_int = 122; + pub const _SC_XBS5_ILP32_OFFBIG : c_int = 123; + pub const _SC_XBS5_LP64_OFF64 : c_int = 124; + pub const _SC_XBS5_LPBIG_OFFBIG : c_int = 125; } } } @@ -4356,7 +4356,7 @@ pub mod funcs { use types::os::arch::posix88::{gid_t, off_t, pid_t}; use types::os::arch::posix88::{ssize_t, uid_t}; - pub static _PC_NAME_MAX: c_int = 4; + pub const _PC_NAME_MAX: c_int = 4; extern { pub fn access(path: *const c_char, amode: c_int) -> c_int; From d9874bfb4079876dabc092c035d99b2d5b7f8a1c Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 6 Oct 2014 16:18:57 -0700 Subject: [PATCH 08/24] rand: Convert statics to constants This leaves the ziggurat tables as `pub static` as they're likely too large to want to go into the metadata anyway. --- src/librand/chacha.rs | 6 +++--- src/librand/isaac.rs | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/librand/chacha.rs b/src/librand/chacha.rs index df33e6e2ced0c..83d03bb265e95 100644 --- a/src/librand/chacha.rs +++ b/src/librand/chacha.rs @@ -14,9 +14,9 @@ use core::prelude::*; use {Rng, SeedableRng, Rand}; -static KEY_WORDS : uint = 8; // 8 words for the 256-bit key -static STATE_WORDS : uint = 16; -static CHACHA_ROUNDS: uint = 20; // Cryptographically secure from 8 upwards as of this writing +const KEY_WORDS : uint = 8; // 8 words for the 256-bit key +const STATE_WORDS : uint = 16; +const CHACHA_ROUNDS: uint = 20; // Cryptographically secure from 8 upwards as of this writing /// A random number generator that uses the ChaCha20 algorithm [1]. /// diff --git a/src/librand/isaac.rs b/src/librand/isaac.rs index 0a857da92bbe4..9bfd9177e348b 100644 --- a/src/librand/isaac.rs +++ b/src/librand/isaac.rs @@ -16,9 +16,9 @@ use core::slice::raw; use {Rng, SeedableRng, Rand}; -static RAND_SIZE_LEN: u32 = 8; -static RAND_SIZE: u32 = 1 << (RAND_SIZE_LEN as uint); -static RAND_SIZE_UINT: uint = 1 << (RAND_SIZE_LEN as uint); +const RAND_SIZE_LEN: u32 = 8; +const RAND_SIZE: u32 = 1 << (RAND_SIZE_LEN as uint); +const RAND_SIZE_UINT: uint = 1 << (RAND_SIZE_LEN as uint); /// A random number generator that uses the ISAAC algorithm[1]. /// @@ -251,8 +251,8 @@ impl Rand for IsaacRng { } } -static RAND_SIZE_64_LEN: uint = 8; -static RAND_SIZE_64: uint = 1 << RAND_SIZE_64_LEN; +const RAND_SIZE_64_LEN: uint = 8; +const RAND_SIZE_64: uint = 1 << RAND_SIZE_64_LEN; /// A random number generator that uses ISAAC-64[1], the 64-bit /// variant of the ISAAC algorithm. @@ -356,8 +356,8 @@ impl Isaac64Rng { // abbreviations let mut a = self.a; let mut b = self.b + self.c; - static MIDPOINT: uint = RAND_SIZE_64 / 2; - static MP_VEC: [(uint, uint), .. 2] = [(0,MIDPOINT), (MIDPOINT, 0)]; + const MIDPOINT: uint = RAND_SIZE_64 / 2; + const MP_VEC: [(uint, uint), .. 2] = [(0,MIDPOINT), (MIDPOINT, 0)]; macro_rules! ind ( ($x:expr) => { *self.mem.unsafe_get(($x as uint >> 3) & (RAND_SIZE_64 - 1)) From ab5935c88d259d511561ccb4177bb6924dab4a06 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 6 Oct 2014 16:29:47 -0700 Subject: [PATCH 09/24] std: Convert statics to constants This commit repurposes most statics as constants in the standard library itself, with the exception of TLS keys which precisely have their own memory location as an implementation detail. This commit also rewrites the bitflags syntax to use `const` instead of `static`. All invocations will need to replace the word `static` with `const` when declaring flags. Due to the modification of the `bitflags!` syntax, this is a: [breaking-change] --- src/libstd/bitflags.rs | 34 ++++---- src/libstd/collections/hashmap/map.rs | 4 +- src/libstd/collections/hashmap/table.rs | 2 +- src/libstd/io/mod.rs | 68 +++++++-------- src/libstd/io/process.rs | 8 +- src/libstd/os.rs | 106 ++++++++++++------------ src/libstd/path/posix.rs | 4 +- src/libstd/path/windows.rs | 8 +- src/libstd/time/duration.rs | 26 +++--- 9 files changed, 130 insertions(+), 130 deletions(-) diff --git a/src/libstd/bitflags.rs b/src/libstd/bitflags.rs index 7966040ed7bc6..adb55f2cc8cff 100644 --- a/src/libstd/bitflags.rs +++ b/src/libstd/bitflags.rs @@ -24,12 +24,12 @@ /// ```{.rust} /// bitflags! { /// flags Flags: u32 { -/// static FLAG_A = 0x00000001, -/// static FLAG_B = 0x00000010, -/// static FLAG_C = 0x00000100, -/// static FLAG_ABC = FLAG_A.bits -/// | FLAG_B.bits -/// | FLAG_C.bits, +/// const FLAG_A = 0x00000001, +/// const FLAG_B = 0x00000010, +/// const FLAG_C = 0x00000100, +/// const FLAG_ABC = FLAG_A.bits +/// | FLAG_B.bits +/// | FLAG_C.bits, /// } /// } /// @@ -50,8 +50,8 @@ /// /// bitflags! { /// flags Flags: u32 { -/// static FLAG_A = 0x00000001, -/// static FLAG_B = 0x00000010, +/// const FLAG_A = 0x00000001, +/// const FLAG_B = 0x00000010, /// } /// } /// @@ -115,7 +115,7 @@ #[macro_export] macro_rules! bitflags { ($(#[$attr:meta])* flags $BitFlags:ident: $T:ty { - $($(#[$Flag_attr:meta])* static $Flag:ident = $value:expr),+ + $($(#[$Flag_attr:meta])* const $Flag:ident = $value:expr),+ }) => { #[deriving(PartialEq, Eq, Clone, PartialOrd, Ord, Hash)] $(#[$attr])* @@ -123,7 +123,7 @@ macro_rules! bitflags { bits: $T, } - $($(#[$Flag_attr])* pub static $Flag: $BitFlags = $BitFlags { bits: $value };)+ + $($(#[$Flag_attr])* pub const $Flag: $BitFlags = $BitFlags { bits: $value };)+ impl $BitFlags { /// Returns an empty set of flags. @@ -235,12 +235,12 @@ macro_rules! bitflags { } }; ($(#[$attr:meta])* flags $BitFlags:ident: $T:ty { - $($(#[$Flag_attr:meta])* static $Flag:ident = $value:expr),+, + $($(#[$Flag_attr:meta])* const $Flag:ident = $value:expr),+, }) => { bitflags! { $(#[$attr])* flags $BitFlags: $T { - $($(#[$Flag_attr])* static $Flag = $value),+ + $($(#[$Flag_attr])* const $Flag = $value),+ } } }; @@ -259,14 +259,14 @@ mod tests { #[doc = "> "] #[doc = "> - Richard Feynman"] flags Flags: u32 { - static FlagA = 0x00000001, + const FlagA = 0x00000001, #[doc = " macros are way better at generating code than trans is"] - static FlagB = 0x00000010, - static FlagC = 0x00000100, + const FlagB = 0x00000010, + const FlagC = 0x00000100, #[doc = "* cmr bed"] #[doc = "* strcat table"] #[doc = " wait what?"] - static FlagABC = FlagA.bits + const FlagABC = FlagA.bits | FlagB.bits | FlagC.bits, } @@ -274,7 +274,7 @@ mod tests { bitflags! { flags AnotherSetOfFlags: uint { - static AnotherFlag = 1u, + const AnotherFlag = 1u, } } diff --git a/src/libstd/collections/hashmap/map.rs b/src/libstd/collections/hashmap/map.rs index 6b9c76e1568d2..ef40402105b54 100644 --- a/src/libstd/collections/hashmap/map.rs +++ b/src/libstd/collections/hashmap/map.rs @@ -41,8 +41,8 @@ use super::table::{ SafeHash }; -static INITIAL_LOG2_CAP: uint = 5; -pub static INITIAL_CAPACITY: uint = 1 << INITIAL_LOG2_CAP; // 2^5 +const INITIAL_LOG2_CAP: uint = 5; +pub const INITIAL_CAPACITY: uint = 1 << INITIAL_LOG2_CAP; // 2^5 /// The default behavior of HashMap implements a load factor of 90.9%. /// This behavior is characterized by the following conditions: diff --git a/src/libstd/collections/hashmap/table.rs b/src/libstd/collections/hashmap/table.rs index bad5ce3e47525..ee64a7931c062 100644 --- a/src/libstd/collections/hashmap/table.rs +++ b/src/libstd/collections/hashmap/table.rs @@ -24,7 +24,7 @@ use ptr::{RawPtr, copy_nonoverlapping_memory, zero_memory}; use ptr; use rt::heap::{allocate, deallocate}; -static EMPTY_BUCKET: u64 = 0u64; +const EMPTY_BUCKET: u64 = 0u64; /// The raw hashtable, providing safe-ish access to the unzipped and highly /// optimized arrays of hashes, keys, and values. diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 280aff71e2327..d18b3cdf2e750 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -283,7 +283,7 @@ pub mod util; /// The default buffer size for various I/O operations // libuv recommends 64k buffers to maximize throughput // https://groups.google.com/forum/#!topic/libuv/oQO1HJAIDdA -static DEFAULT_BUF_SIZE: uint = 1024 * 64; +const DEFAULT_BUF_SIZE: uint = 1024 * 64; /// A convenient typedef of the return value of any I/O action. pub type IoResult = Result; @@ -1803,93 +1803,93 @@ bitflags! { #[doc = "A set of permissions for a file or directory is represented"] #[doc = "by a set of flags which are or'd together."] flags FilePermission: u32 { - static USER_READ = 0o400, - static USER_WRITE = 0o200, - static USER_EXECUTE = 0o100, - static GROUP_READ = 0o040, - static GROUP_WRITE = 0o020, - static GROUP_EXECUTE = 0o010, - static OTHER_READ = 0o004, - static OTHER_WRITE = 0o002, - static OTHER_EXECUTE = 0o001, - - static USER_RWX = USER_READ.bits | USER_WRITE.bits | USER_EXECUTE.bits, - static GROUP_RWX = GROUP_READ.bits | GROUP_WRITE.bits | GROUP_EXECUTE.bits, - static OTHER_RWX = OTHER_READ.bits | OTHER_WRITE.bits | OTHER_EXECUTE.bits, + const USER_READ = 0o400, + const USER_WRITE = 0o200, + const USER_EXECUTE = 0o100, + const GROUP_READ = 0o040, + const GROUP_WRITE = 0o020, + const GROUP_EXECUTE = 0o010, + const OTHER_READ = 0o004, + const OTHER_WRITE = 0o002, + const OTHER_EXECUTE = 0o001, + + const USER_RWX = USER_READ.bits | USER_WRITE.bits | USER_EXECUTE.bits, + const GROUP_RWX = GROUP_READ.bits | GROUP_WRITE.bits | GROUP_EXECUTE.bits, + const OTHER_RWX = OTHER_READ.bits | OTHER_WRITE.bits | OTHER_EXECUTE.bits, #[doc = "Permissions for user owned files, equivalent to 0644 on"] #[doc = "unix-like systems."] - static USER_FILE = USER_READ.bits | USER_WRITE.bits | GROUP_READ.bits | OTHER_READ.bits, + const USER_FILE = USER_READ.bits | USER_WRITE.bits | GROUP_READ.bits | OTHER_READ.bits, #[doc = "Permissions for user owned directories, equivalent to 0755 on"] #[doc = "unix-like systems."] - static USER_DIR = USER_RWX.bits | GROUP_READ.bits | GROUP_EXECUTE.bits | + const USER_DIR = USER_RWX.bits | GROUP_READ.bits | GROUP_EXECUTE.bits | OTHER_READ.bits | OTHER_EXECUTE.bits, #[doc = "Permissions for user owned executables, equivalent to 0755"] #[doc = "on unix-like systems."] - static USER_EXEC = USER_DIR.bits, + const USER_EXEC = USER_DIR.bits, #[doc = "All possible permissions enabled."] - static ALL_PERMISSIONS = USER_RWX.bits | GROUP_RWX.bits | OTHER_RWX.bits, + const ALL_PERMISSIONS = USER_RWX.bits | GROUP_RWX.bits | OTHER_RWX.bits, // Deprecated names #[allow(non_uppercase_statics)] #[deprecated = "use USER_READ instead"] - static UserRead = USER_READ.bits, + const UserRead = USER_READ.bits, #[allow(non_uppercase_statics)] #[deprecated = "use USER_WRITE instead"] - static UserWrite = USER_WRITE.bits, + const UserWrite = USER_WRITE.bits, #[allow(non_uppercase_statics)] #[deprecated = "use USER_EXECUTE instead"] - static UserExecute = USER_EXECUTE.bits, + const UserExecute = USER_EXECUTE.bits, #[allow(non_uppercase_statics)] #[deprecated = "use GROUP_READ instead"] - static GroupRead = GROUP_READ.bits, + const GroupRead = GROUP_READ.bits, #[allow(non_uppercase_statics)] #[deprecated = "use GROUP_WRITE instead"] - static GroupWrite = GROUP_WRITE.bits, + const GroupWrite = GROUP_WRITE.bits, #[allow(non_uppercase_statics)] #[deprecated = "use GROUP_EXECUTE instead"] - static GroupExecute = GROUP_EXECUTE.bits, + const GroupExecute = GROUP_EXECUTE.bits, #[allow(non_uppercase_statics)] #[deprecated = "use OTHER_READ instead"] - static OtherRead = OTHER_READ.bits, + const OtherRead = OTHER_READ.bits, #[allow(non_uppercase_statics)] #[deprecated = "use OTHER_WRITE instead"] - static OtherWrite = OTHER_WRITE.bits, + const OtherWrite = OTHER_WRITE.bits, #[allow(non_uppercase_statics)] #[deprecated = "use OTHER_EXECUTE instead"] - static OtherExecute = OTHER_EXECUTE.bits, + const OtherExecute = OTHER_EXECUTE.bits, #[allow(non_uppercase_statics)] #[deprecated = "use USER_RWX instead"] - static UserRWX = USER_RWX.bits, + const UserRWX = USER_RWX.bits, #[allow(non_uppercase_statics)] #[deprecated = "use GROUP_RWX instead"] - static GroupRWX = GROUP_RWX.bits, + const GroupRWX = GROUP_RWX.bits, #[allow(non_uppercase_statics)] #[deprecated = "use OTHER_RWX instead"] - static OtherRWX = OTHER_RWX.bits, + const OtherRWX = OTHER_RWX.bits, #[doc = "Deprecated: use `USER_FILE` instead."] #[allow(non_uppercase_statics)] #[deprecated = "use USER_FILE instead"] - static UserFile = USER_FILE.bits, + const UserFile = USER_FILE.bits, #[doc = "Deprecated: use `USER_DIR` instead."] #[allow(non_uppercase_statics)] #[deprecated = "use USER_DIR instead"] - static UserDir = USER_DIR.bits, + const UserDir = USER_DIR.bits, #[doc = "Deprecated: use `USER_EXEC` instead."] #[allow(non_uppercase_statics)] #[deprecated = "use USER_EXEC instead"] - static UserExec = USER_EXEC.bits, + const UserExec = USER_EXEC.bits, #[doc = "Deprecated: use `ALL_PERMISSIONS` instead"] #[allow(non_uppercase_statics)] #[deprecated = "use ALL_PERMISSIONS instead"] - static AllPermissions = ALL_PERMISSIONS.bits, + const AllPermissions = ALL_PERMISSIONS.bits, } } diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs index ef336bc7b4f99..5de4bc10e1aec 100644 --- a/src/libstd/io/process.rs +++ b/src/libstd/io/process.rs @@ -32,16 +32,16 @@ use std::hash::sip::SipState; /// Signal a process to exit, without forcibly killing it. Corresponds to /// SIGTERM on unix platforms. -#[cfg(windows)] pub static PleaseExitSignal: int = 15; +#[cfg(windows)] pub const PleaseExitSignal: int = 15; /// Signal a process to exit immediately, forcibly killing it. Corresponds to /// SIGKILL on unix platforms. -#[cfg(windows)] pub static MustDieSignal: int = 9; +#[cfg(windows)] pub const MustDieSignal: int = 9; /// Signal a process to exit, without forcibly killing it. Corresponds to /// SIGTERM on unix platforms. -#[cfg(not(windows))] pub static PleaseExitSignal: int = libc::SIGTERM as int; +#[cfg(not(windows))] pub const PleaseExitSignal: int = libc::SIGTERM as int; /// Signal a process to exit immediately, forcibly killing it. Corresponds to /// SIGKILL on unix platforms. -#[cfg(not(windows))] pub static MustDieSignal: int = libc::SIGKILL as int; +#[cfg(not(windows))] pub const MustDieSignal: int = libc::SIGKILL as int; /// Representation of a running or exited child process. /// diff --git a/src/libstd/os.rs b/src/libstd/os.rs index bb642f1e48f71..60386ec0631b7 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -66,8 +66,8 @@ pub fn num_cpus() -> uint { } } -pub static TMPBUF_SZ : uint = 1000u; -static BUF_BYTES : uint = 2048u; +pub const TMPBUF_SZ : uint = 1000u; +const BUF_BYTES : uint = 2048u; /// Returns the current working directory as a Path. /// @@ -1672,230 +1672,230 @@ impl MemoryMap { pub mod consts { pub use os::arch_consts::ARCH; - pub static FAMILY: &'static str = "unix"; + pub const FAMILY: &'static str = "unix"; /// A string describing the specific operating system in use: in this /// case, `linux`. - pub static SYSNAME: &'static str = "linux"; + pub const SYSNAME: &'static str = "linux"; /// Specifies the filename prefix used for shared libraries on this /// platform: in this case, `lib`. - pub static DLL_PREFIX: &'static str = "lib"; + pub const DLL_PREFIX: &'static str = "lib"; /// Specifies the filename suffix used for shared libraries on this /// platform: in this case, `.so`. - pub static DLL_SUFFIX: &'static str = ".so"; + pub const DLL_SUFFIX: &'static str = ".so"; /// Specifies the file extension used for shared libraries on this /// platform that goes after the dot: in this case, `so`. - pub static DLL_EXTENSION: &'static str = "so"; + pub const DLL_EXTENSION: &'static str = "so"; /// Specifies the filename suffix used for executable binaries on this /// platform: in this case, the empty string. - pub static EXE_SUFFIX: &'static str = ""; + pub const EXE_SUFFIX: &'static str = ""; /// Specifies the file extension, if any, used for executable binaries /// on this platform: in this case, the empty string. - pub static EXE_EXTENSION: &'static str = ""; + pub const EXE_EXTENSION: &'static str = ""; } #[cfg(target_os = "macos")] pub mod consts { pub use os::arch_consts::ARCH; - pub static FAMILY: &'static str = "unix"; + pub const FAMILY: &'static str = "unix"; /// A string describing the specific operating system in use: in this /// case, `macos`. - pub static SYSNAME: &'static str = "macos"; + pub const SYSNAME: &'static str = "macos"; /// Specifies the filename prefix used for shared libraries on this /// platform: in this case, `lib`. - pub static DLL_PREFIX: &'static str = "lib"; + pub const DLL_PREFIX: &'static str = "lib"; /// Specifies the filename suffix used for shared libraries on this /// platform: in this case, `.dylib`. - pub static DLL_SUFFIX: &'static str = ".dylib"; + pub const DLL_SUFFIX: &'static str = ".dylib"; /// Specifies the file extension used for shared libraries on this /// platform that goes after the dot: in this case, `dylib`. - pub static DLL_EXTENSION: &'static str = "dylib"; + pub const DLL_EXTENSION: &'static str = "dylib"; /// Specifies the filename suffix used for executable binaries on this /// platform: in this case, the empty string. - pub static EXE_SUFFIX: &'static str = ""; + pub const EXE_SUFFIX: &'static str = ""; /// Specifies the file extension, if any, used for executable binaries /// on this platform: in this case, the empty string. - pub static EXE_EXTENSION: &'static str = ""; + pub const EXE_EXTENSION: &'static str = ""; } #[cfg(target_os = "ios")] pub mod consts { pub use os::arch_consts::ARCH; - pub static FAMILY: &'static str = "unix"; + pub const FAMILY: &'static str = "unix"; /// A string describing the specific operating system in use: in this /// case, `ios`. - pub static SYSNAME: &'static str = "ios"; + pub const SYSNAME: &'static str = "ios"; /// Specifies the filename suffix used for executable binaries on this /// platform: in this case, the empty string. - pub static EXE_SUFFIX: &'static str = ""; + pub const EXE_SUFFIX: &'static str = ""; /// Specifies the file extension, if any, used for executable binaries /// on this platform: in this case, the empty string. - pub static EXE_EXTENSION: &'static str = ""; + pub const EXE_EXTENSION: &'static str = ""; } #[cfg(target_os = "freebsd")] pub mod consts { pub use os::arch_consts::ARCH; - pub static FAMILY: &'static str = "unix"; + pub const FAMILY: &'static str = "unix"; /// A string describing the specific operating system in use: in this /// case, `freebsd`. - pub static SYSNAME: &'static str = "freebsd"; + pub const SYSNAME: &'static str = "freebsd"; /// Specifies the filename prefix used for shared libraries on this /// platform: in this case, `lib`. - pub static DLL_PREFIX: &'static str = "lib"; + pub const DLL_PREFIX: &'static str = "lib"; /// Specifies the filename suffix used for shared libraries on this /// platform: in this case, `.so`. - pub static DLL_SUFFIX: &'static str = ".so"; + pub const DLL_SUFFIX: &'static str = ".so"; /// Specifies the file extension used for shared libraries on this /// platform that goes after the dot: in this case, `so`. - pub static DLL_EXTENSION: &'static str = "so"; + pub const DLL_EXTENSION: &'static str = "so"; /// Specifies the filename suffix used for executable binaries on this /// platform: in this case, the empty string. - pub static EXE_SUFFIX: &'static str = ""; + pub const EXE_SUFFIX: &'static str = ""; /// Specifies the file extension, if any, used for executable binaries /// on this platform: in this case, the empty string. - pub static EXE_EXTENSION: &'static str = ""; + pub const EXE_EXTENSION: &'static str = ""; } #[cfg(target_os = "dragonfly")] pub mod consts { pub use os::arch_consts::ARCH; - pub static FAMILY: &'static str = "unix"; + pub const FAMILY: &'static str = "unix"; /// A string describing the specific operating system in use: in this /// case, `dragonfly`. - pub static SYSNAME: &'static str = "dragonfly"; + pub const SYSNAME: &'static str = "dragonfly"; /// Specifies the filename prefix used for shared libraries on this /// platform: in this case, `lib`. - pub static DLL_PREFIX: &'static str = "lib"; + pub const DLL_PREFIX: &'static str = "lib"; /// Specifies the filename suffix used for shared libraries on this /// platform: in this case, `.so`. - pub static DLL_SUFFIX: &'static str = ".so"; + pub const DLL_SUFFIX: &'static str = ".so"; /// Specifies the file extension used for shared libraries on this /// platform that goes after the dot: in this case, `so`. - pub static DLL_EXTENSION: &'static str = "so"; + pub const DLL_EXTENSION: &'static str = "so"; /// Specifies the filename suffix used for executable binaries on this /// platform: in this case, the empty string. - pub static EXE_SUFFIX: &'static str = ""; + pub const EXE_SUFFIX: &'static str = ""; /// Specifies the file extension, if any, used for executable binaries /// on this platform: in this case, the empty string. - pub static EXE_EXTENSION: &'static str = ""; + pub const EXE_EXTENSION: &'static str = ""; } #[cfg(target_os = "android")] pub mod consts { pub use os::arch_consts::ARCH; - pub static FAMILY: &'static str = "unix"; + pub const FAMILY: &'static str = "unix"; /// A string describing the specific operating system in use: in this /// case, `android`. - pub static SYSNAME: &'static str = "android"; + pub const SYSNAME: &'static str = "android"; /// Specifies the filename prefix used for shared libraries on this /// platform: in this case, `lib`. - pub static DLL_PREFIX: &'static str = "lib"; + pub const DLL_PREFIX: &'static str = "lib"; /// Specifies the filename suffix used for shared libraries on this /// platform: in this case, `.so`. - pub static DLL_SUFFIX: &'static str = ".so"; + pub const DLL_SUFFIX: &'static str = ".so"; /// Specifies the file extension used for shared libraries on this /// platform that goes after the dot: in this case, `so`. - pub static DLL_EXTENSION: &'static str = "so"; + pub const DLL_EXTENSION: &'static str = "so"; /// Specifies the filename suffix used for executable binaries on this /// platform: in this case, the empty string. - pub static EXE_SUFFIX: &'static str = ""; + pub const EXE_SUFFIX: &'static str = ""; /// Specifies the file extension, if any, used for executable binaries /// on this platform: in this case, the empty string. - pub static EXE_EXTENSION: &'static str = ""; + pub const EXE_EXTENSION: &'static str = ""; } #[cfg(target_os = "windows")] pub mod consts { pub use os::arch_consts::ARCH; - pub static FAMILY: &'static str = "windows"; + pub const FAMILY: &'static str = "windows"; /// A string describing the specific operating system in use: in this /// case, `windows`. - pub static SYSNAME: &'static str = "windows"; + pub const SYSNAME: &'static str = "windows"; /// Specifies the filename prefix used for shared libraries on this /// platform: in this case, the empty string. - pub static DLL_PREFIX: &'static str = ""; + pub const DLL_PREFIX: &'static str = ""; /// Specifies the filename suffix used for shared libraries on this /// platform: in this case, `.dll`. - pub static DLL_SUFFIX: &'static str = ".dll"; + pub const DLL_SUFFIX: &'static str = ".dll"; /// Specifies the file extension used for shared libraries on this /// platform that goes after the dot: in this case, `dll`. - pub static DLL_EXTENSION: &'static str = "dll"; + pub const DLL_EXTENSION: &'static str = "dll"; /// Specifies the filename suffix used for executable binaries on this /// platform: in this case, `.exe`. - pub static EXE_SUFFIX: &'static str = ".exe"; + pub const EXE_SUFFIX: &'static str = ".exe"; /// Specifies the file extension, if any, used for executable binaries /// on this platform: in this case, `exe`. - pub static EXE_EXTENSION: &'static str = "exe"; + pub const EXE_EXTENSION: &'static str = "exe"; } #[cfg(target_arch = "x86")] mod arch_consts { - pub static ARCH: &'static str = "x86"; + pub const ARCH: &'static str = "x86"; } #[cfg(target_arch = "x86_64")] mod arch_consts { - pub static ARCH: &'static str = "x86_64"; + pub const ARCH: &'static str = "x86_64"; } #[cfg(target_arch = "arm")] mod arch_consts { - pub static ARCH: &'static str = "arm"; + pub const ARCH: &'static str = "arm"; } #[cfg(target_arch = "mips")] mod arch_consts { - pub static ARCH: &'static str = "mips"; + pub const ARCH: &'static str = "mips"; } #[cfg(target_arch = "mipsel")] mod arch_consts { - pub static ARCH: &'static str = "mipsel"; + pub const ARCH: &'static str = "mipsel"; } #[cfg(test)] diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index 196ac7507ea86..f7fb9adb1fb64 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -42,10 +42,10 @@ pub struct Path { } /// The standard path separator character -pub static SEP: char = '/'; +pub const SEP: char = '/'; /// The standard path separator byte -pub static SEP_BYTE: u8 = SEP as u8; +pub const SEP_BYTE: u8 = SEP as u8; /// Returns whether the given byte is a path separator #[inline] diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index ec3f87bc45a53..5bd738ed58bd3 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -958,14 +958,14 @@ pub fn make_non_verbatim(path: &Path) -> Option { } /// The standard path separator character -pub static SEP: char = '\\'; +pub const SEP: char = '\\'; /// The standard path separator byte -pub static SEP_BYTE: u8 = SEP as u8; +pub const SEP_BYTE: u8 = SEP as u8; /// The alternative path separator character -pub static SEP2: char = '/'; +pub const SEP2: char = '/'; /// The alternative path separator character -pub static SEP2_BYTE: u8 = SEP2 as u8; +pub const SEP2_BYTE: u8 = SEP2 as u8; /// Returns whether the given char is a path separator. /// Allows both the primary separator '\' and the alternative separator '/'. diff --git a/src/libstd/time/duration.rs b/src/libstd/time/duration.rs index 85aed47265fc3..751eb00bfaecc 100644 --- a/src/libstd/time/duration.rs +++ b/src/libstd/time/duration.rs @@ -20,23 +20,23 @@ use num::{CheckedAdd, CheckedMul}; use result::{Result, Ok, Err}; /// The number of nanoseconds in a microsecond. -static NANOS_PER_MICRO: i32 = 1000; +const NANOS_PER_MICRO: i32 = 1000; /// The number of nanoseconds in a millisecond. -static NANOS_PER_MILLI: i32 = 1000_000; +const NANOS_PER_MILLI: i32 = 1000_000; /// The number of nanoseconds in seconds. -static NANOS_PER_SEC: i32 = 1_000_000_000; +const NANOS_PER_SEC: i32 = 1_000_000_000; /// The number of microseconds per second. -static MICROS_PER_SEC: i64 = 1000_000; +const MICROS_PER_SEC: i64 = 1000_000; /// The number of milliseconds per second. -static MILLIS_PER_SEC: i64 = 1000; +const MILLIS_PER_SEC: i64 = 1000; /// The number of seconds in a minute. -static SECS_PER_MINUTE: i64 = 60; +const SECS_PER_MINUTE: i64 = 60; /// The number of seconds in an hour. -static SECS_PER_HOUR: i64 = 3600; +const SECS_PER_HOUR: i64 = 3600; /// The number of (non-leap) seconds in days. -static SECS_PER_DAY: i64 = 86400; +const SECS_PER_DAY: i64 = 86400; /// The number of (non-leap) seconds in a week. -static SECS_PER_WEEK: i64 = 604800; +const SECS_PER_WEEK: i64 = 604800; macro_rules! try_opt( ($e:expr) => (match $e { Some(v) => v, None => return None }) @@ -52,13 +52,13 @@ pub struct Duration { } /// The minimum possible `Duration`: `i64::MIN` milliseconds. -pub static MIN: Duration = Duration { +pub const MIN: Duration = Duration { secs: i64::MIN / MILLIS_PER_SEC - 1, nanos: NANOS_PER_SEC + (i64::MIN % MILLIS_PER_SEC) as i32 * NANOS_PER_MILLI }; /// The maximum possible `Duration`: `i64::MAX` milliseconds. -pub static MAX: Duration = Duration { +pub const MAX: Duration = Duration { secs: i64::MAX / MILLIS_PER_SEC, nanos: (i64::MAX % MILLIS_PER_SEC) as i32 * NANOS_PER_MILLI }; @@ -456,7 +456,7 @@ mod tests { assert_eq!(MIN.num_microseconds(), None); // overflow checks - static MICROS_PER_DAY: i64 = 86400_000_000; + const MICROS_PER_DAY: i64 = 86400_000_000; assert_eq!(Duration::days(i64::MAX / MICROS_PER_DAY).num_microseconds(), Some(i64::MAX / MICROS_PER_DAY * MICROS_PER_DAY)); assert_eq!(Duration::days(i64::MIN / MICROS_PER_DAY).num_microseconds(), @@ -477,7 +477,7 @@ mod tests { assert_eq!(MIN.num_nanoseconds(), None); // overflow checks - static NANOS_PER_DAY: i64 = 86400_000_000_000; + const NANOS_PER_DAY: i64 = 86400_000_000_000; assert_eq!(Duration::days(i64::MAX / NANOS_PER_DAY).num_nanoseconds(), Some(i64::MAX / NANOS_PER_DAY * NANOS_PER_DAY)); assert_eq!(Duration::days(i64::MIN / NANOS_PER_DAY).num_nanoseconds(), From 6d4cf378e6a58a2564a8be9f9eb32271a9c3687e Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 6 Oct 2014 16:31:39 -0700 Subject: [PATCH 10/24] term: Convert statics to constants --- src/libterm/lib.rs | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/libterm/lib.rs b/src/libterm/lib.rs index b05e0a4bff398..6a62484f55b4f 100644 --- a/src/libterm/lib.rs +++ b/src/libterm/lib.rs @@ -155,23 +155,23 @@ pub mod color { /// Number for a terminal color pub type Color = u16; - pub static BLACK: Color = 0u16; - pub static RED: Color = 1u16; - pub static GREEN: Color = 2u16; - pub static YELLOW: Color = 3u16; - pub static BLUE: Color = 4u16; - pub static MAGENTA: Color = 5u16; - pub static CYAN: Color = 6u16; - pub static WHITE: Color = 7u16; - - pub static BRIGHT_BLACK: Color = 8u16; - pub static BRIGHT_RED: Color = 9u16; - pub static BRIGHT_GREEN: Color = 10u16; - pub static BRIGHT_YELLOW: Color = 11u16; - pub static BRIGHT_BLUE: Color = 12u16; - pub static BRIGHT_MAGENTA: Color = 13u16; - pub static BRIGHT_CYAN: Color = 14u16; - pub static BRIGHT_WHITE: Color = 15u16; + pub const BLACK: Color = 0u16; + pub const RED: Color = 1u16; + pub const GREEN: Color = 2u16; + pub const YELLOW: Color = 3u16; + pub const BLUE: Color = 4u16; + pub const MAGENTA: Color = 5u16; + pub const CYAN: Color = 6u16; + pub const WHITE: Color = 7u16; + + pub const BRIGHT_BLACK: Color = 8u16; + pub const BRIGHT_RED: Color = 9u16; + pub const BRIGHT_GREEN: Color = 10u16; + pub const BRIGHT_YELLOW: Color = 11u16; + pub const BRIGHT_BLUE: Color = 12u16; + pub const BRIGHT_MAGENTA: Color = 13u16; + pub const BRIGHT_CYAN: Color = 14u16; + pub const BRIGHT_WHITE: Color = 15u16; } /// Terminal attributes From abb1b2a309acfca78e89e6dac574f94a0ce4d916 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 6 Oct 2014 16:32:00 -0700 Subject: [PATCH 11/24] alloc: Convert statics to constants --- src/liballoc/heap.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/liballoc/heap.rs b/src/liballoc/heap.rs index 9a4390747198c..5a0f860ff844e 100644 --- a/src/liballoc/heap.rs +++ b/src/liballoc/heap.rs @@ -85,7 +85,7 @@ pub fn stats_print() { /// /// This preserves the non-null invariant for types like `Box`. The address may overlap with /// non-zero-size memory allocations. -pub static EMPTY: *mut () = 0x1 as *mut (); +pub const EMPTY: *mut () = 0x1 as *mut (); /// The allocator for unique pointers. #[cfg(not(test))] From a64bb6623c0732e2b3f7f371f375dc70b58629b7 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 6 Oct 2014 16:32:48 -0700 Subject: [PATCH 12/24] regex: Convert statics to constants This require a bit of finesse to work around the changes with libunicode, but nothing too major! --- src/libregex/parse.rs | 59 ++++++++++++++++++++++++-------------- src/libregex/re.rs | 2 +- src/libregex_macros/lib.rs | 2 +- 3 files changed, 39 insertions(+), 24 deletions(-) diff --git a/src/libregex/parse.rs b/src/libregex/parse.rs index bf57643263139..1d1d1a0e9c5ca 100644 --- a/src/libregex/parse.rs +++ b/src/libregex/parse.rs @@ -162,12 +162,12 @@ impl BuildAst { /// expression. pub type Flags = u8; -pub static FLAG_EMPTY: u8 = 0; -pub static FLAG_NOCASE: u8 = 1 << 0; // i -pub static FLAG_MULTI: u8 = 1 << 1; // m -pub static FLAG_DOTNL: u8 = 1 << 2; // s -pub static FLAG_SWAP_GREED: u8 = 1 << 3; // U -pub static FLAG_NEGATED: u8 = 1 << 4; // char class or not word boundary +pub const FLAG_EMPTY: u8 = 0; +pub const FLAG_NOCASE: u8 = 1 << 0; // i +pub const FLAG_MULTI: u8 = 1 << 1; // m +pub const FLAG_DOTNL: u8 = 1 << 2; // s +pub const FLAG_SWAP_GREED: u8 = 1 << 3; // U +pub const FLAG_NEGATED: u8 = 1 << 4; // char class or not word boundary struct Parser<'a> { // The input, parsed only as a sequence of UTF8 code points. @@ -1025,7 +1025,7 @@ fn find_class(classes: NamedClasses, name: &str) -> Option> { } type Class = &'static [(char, char)]; -type NamedClasses = &'static [(&'static str, Class)]; +type NamedClasses = &'static [(&'static str, &'static Class)]; static ASCII_CLASSES: NamedClasses = &[ // Classes must be in alphabetical order so that bsearch works. @@ -1044,19 +1044,34 @@ static ASCII_CLASSES: NamedClasses = &[ // [:word:] word characters (== [0-9A-Za-z_]) // [:xdigit:] hex digit (== [0-9A-Fa-f]) // Taken from: http://golang.org/pkg/regex/syntax/ - ("alnum", &[('0', '9'), ('A', 'Z'), ('a', 'z')]), - ("alpha", &[('A', 'Z'), ('a', 'z')]), - ("ascii", &[('\x00', '\x7F')]), - ("blank", &[(' ', ' '), ('\t', '\t')]), - ("cntrl", &[('\x00', '\x1F'), ('\x7F', '\x7F')]), - ("digit", &[('0', '9')]), - ("graph", &[('!', '~')]), - ("lower", &[('a', 'z')]), - ("print", &[(' ', '~')]), - ("punct", &[('!', '/'), (':', '@'), ('[', '`'), ('{', '~')]), - ("space", &[('\t', '\t'), ('\n', '\n'), ('\x0B', '\x0B'), ('\x0C', '\x0C'), - ('\r', '\r'), (' ', ' ')]), - ("upper", &[('A', 'Z')]), - ("word", &[('0', '9'), ('A', 'Z'), ('a', 'z'), ('_', '_')]), - ("xdigit", &[('0', '9'), ('A', 'F'), ('a', 'f')]), + ("alnum", &ALNUM), + ("alpha", &ALPHA), + ("ascii", &ASCII), + ("blank", &BLANK), + ("cntrl", &CNTRL), + ("digit", &DIGIT), + ("graph", &GRAPH), + ("lower", &LOWER), + ("print", &PRINT), + ("punct", &PUNCT), + ("space", &SPACE), + ("upper", &UPPER), + ("word", &WORD), + ("xdigit", &XDIGIT), ]; + +static ALNUM: Class = &[('0', '9'), ('A', 'Z'), ('a', 'z')]; +static ALPHA: Class = &[('A', 'Z'), ('a', 'z')]; +static ASCII: Class = &[('\x00', '\x7F')]; +static BLANK: Class = &[(' ', ' '), ('\t', '\t')]; +static CNTRL: Class = &[('\x00', '\x1F'), ('\x7F', '\x7F')]; +static DIGIT: Class = &[('0', '9')]; +static GRAPH: Class = &[('!', '~')]; +static LOWER: Class = &[('a', 'z')]; +static PRINT: Class = &[(' ', '~')]; +static PUNCT: Class = &[('!', '/'), (':', '@'), ('[', '`'), ('{', '~')]; +static SPACE: Class = &[('\t', '\t'), ('\n', '\n'), ('\x0B', '\x0B'), + ('\x0C', '\x0C'), ('\r', '\r'), (' ', ' ')]; +static UPPER: Class = &[('A', 'Z')]; +static WORD: Class = &[('0', '9'), ('A', 'Z'), ('a', 'z'), ('_', '_')]; +static XDIGIT: Class = &[('0', '9'), ('A', 'F'), ('a', 'f')]; diff --git a/src/libregex/re.rs b/src/libregex/re.rs index 0b5aeb215e66c..eebe9b85e3b9d 100644 --- a/src/libregex/re.rs +++ b/src/libregex/re.rs @@ -128,7 +128,7 @@ pub struct ExNative { #[doc(hidden)] pub original: &'static str, #[doc(hidden)] - pub names: &'static [Option<&'static str>], + pub names: &'static &'static [Option<&'static str>], #[doc(hidden)] pub prog: fn(MatchKind, &str, uint, uint) -> Vec> } diff --git a/src/libregex_macros/lib.rs b/src/libregex_macros/lib.rs index 67018769fb371..c48b35a49808c 100644 --- a/src/libregex_macros/lib.rs +++ b/src/libregex_macros/lib.rs @@ -324,7 +324,7 @@ fn exec<'t>(which: ::regex::native::MatchKind, input: &'t str, ::regex::native::Native(::regex::native::ExNative { original: $regex, - names: CAP_NAMES, + names: &CAP_NAMES, prog: exec, }) }) From 6532a8c95ac5ac4d695d689a944ca725716fc0a4 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 6 Oct 2014 16:33:13 -0700 Subject: [PATCH 13/24] log: Convert statics to constants --- src/liblog/lib.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/liblog/lib.rs b/src/liblog/lib.rs index aa853b0474a03..b6d6e9dfe5052 100644 --- a/src/liblog/lib.rs +++ b/src/liblog/lib.rs @@ -188,10 +188,10 @@ mod directive; /// Maximum logging level of a module that can be specified. Common logging /// levels are found in the DEBUG/INFO/WARN/ERROR constants. -pub static MAX_LOG_LEVEL: u32 = 255; +pub const MAX_LOG_LEVEL: u32 = 255; /// The default logging level of a crate if no other is specified. -static DEFAULT_LOG_LEVEL: u32 = 1; +const DEFAULT_LOG_LEVEL: u32 = 1; /// An unsafe constant that is the maximum logging level of any module /// specified. This is the first line of defense to determining whether a @@ -205,13 +205,13 @@ static mut DIRECTIVES: *const Vec = static mut FILTER: *const Regex = 0 as *const _; /// Debug log level -pub static DEBUG: u32 = 4; +pub const DEBUG: u32 = 4; /// Info log level -pub static INFO: u32 = 3; +pub const INFO: u32 = 3; /// Warn log level -pub static WARN: u32 = 2; +pub const WARN: u32 = 2; /// Error log level -pub static ERROR: u32 = 1; +pub const ERROR: u32 = 1; local_data_key!(local_logger: Box) From 8ccb61609238063b2f1b0cd038974426cdf81bc8 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 6 Oct 2014 16:33:29 -0700 Subject: [PATCH 14/24] native: Convert statics to constants --- src/libnative/io/c_unix.rs | 70 +++++++++++++++++------------------ src/libnative/io/c_windows.rs | 38 +++++++++---------- 2 files changed, 54 insertions(+), 54 deletions(-) diff --git a/src/libnative/io/c_unix.rs b/src/libnative/io/c_unix.rs index a8ebcda3cdd1a..c2af9c03c42c1 100644 --- a/src/libnative/io/c_unix.rs +++ b/src/libnative/io/c_unix.rs @@ -23,41 +23,41 @@ use libc; target_os = "ios", target_os = "freebsd", target_os = "dragonfly"))] -pub static FIONBIO: libc::c_ulong = 0x8004667e; +pub const FIONBIO: libc::c_ulong = 0x8004667e; #[cfg(any(all(target_os = "linux", any(target_arch = "x86", target_arch = "x86_64", target_arch = "arm")), target_os = "android"))] -pub static FIONBIO: libc::c_ulong = 0x5421; +pub const FIONBIO: libc::c_ulong = 0x5421; #[cfg(all(target_os = "linux", any(target_arch = "mips", target_arch = "mipsel")))] -pub static FIONBIO: libc::c_ulong = 0x667e; +pub const FIONBIO: libc::c_ulong = 0x667e; #[cfg(any(target_os = "macos", target_os = "ios", target_os = "freebsd", target_os = "dragonfly"))] -pub static FIOCLEX: libc::c_ulong = 0x20006601; +pub const FIOCLEX: libc::c_ulong = 0x20006601; #[cfg(any(all(target_os = "linux", any(target_arch = "x86", target_arch = "x86_64", target_arch = "arm")), target_os = "android"))] -pub static FIOCLEX: libc::c_ulong = 0x5451; +pub const FIOCLEX: libc::c_ulong = 0x5451; #[cfg(all(target_os = "linux", any(target_arch = "mips", target_arch = "mipsel")))] -pub static FIOCLEX: libc::c_ulong = 0x6601; +pub const FIOCLEX: libc::c_ulong = 0x6601; #[cfg(any(target_os = "macos", target_os = "ios", target_os = "freebsd", target_os = "dragonfly"))] -pub static MSG_DONTWAIT: libc::c_int = 0x80; +pub const MSG_DONTWAIT: libc::c_int = 0x80; #[cfg(any(target_os = "linux", target_os = "android"))] -pub static MSG_DONTWAIT: libc::c_int = 0x40; +pub const MSG_DONTWAIT: libc::c_int = 0x40; -pub static WNOHANG: libc::c_int = 1; +pub const WNOHANG: libc::c_int = 1; extern { pub fn gettimeofday(timeval: *mut libc::timeval, @@ -89,7 +89,7 @@ extern { #[cfg(any(target_os = "macos", target_os = "ios"))] mod select { - pub static FD_SETSIZE: uint = 1024; + pub const FD_SETSIZE: uint = 1024; #[repr(C)] pub struct fd_set { @@ -109,7 +109,7 @@ mod select { use std::uint; use libc; - pub static FD_SETSIZE: uint = 1024; + pub const FD_SETSIZE: uint = 1024; #[repr(C)] pub struct fd_set { @@ -131,14 +131,14 @@ mod select { mod signal { use libc; - pub static SA_NOCLDSTOP: libc::c_ulong = 0x00000001; - pub static SA_NOCLDWAIT: libc::c_ulong = 0x00000002; - pub static SA_NODEFER: libc::c_ulong = 0x40000000; - pub static SA_ONSTACK: libc::c_ulong = 0x08000000; - pub static SA_RESETHAND: libc::c_ulong = 0x80000000; - pub static SA_RESTART: libc::c_ulong = 0x10000000; - pub static SA_SIGINFO: libc::c_ulong = 0x00000004; - pub static SIGCHLD: libc::c_int = 17; + pub const SA_NOCLDSTOP: libc::c_ulong = 0x00000001; + pub const SA_NOCLDWAIT: libc::c_ulong = 0x00000002; + pub const SA_NODEFER: libc::c_ulong = 0x40000000; + pub const SA_ONSTACK: libc::c_ulong = 0x08000000; + pub const SA_RESETHAND: libc::c_ulong = 0x80000000; + pub const SA_RESTART: libc::c_ulong = 0x10000000; + pub const SA_SIGINFO: libc::c_ulong = 0x00000004; + pub const SIGCHLD: libc::c_int = 17; // This definition is not as accurate as it could be, {pid, uid, status} is // actually a giant union. Currently we're only interested in these fields, @@ -179,14 +179,14 @@ mod signal { mod signal { use libc; - pub static SA_NOCLDSTOP: libc::c_ulong = 0x00000001; - pub static SA_NOCLDWAIT: libc::c_ulong = 0x00010000; - pub static SA_NODEFER: libc::c_ulong = 0x40000000; - pub static SA_ONSTACK: libc::c_ulong = 0x08000000; - pub static SA_RESETHAND: libc::c_ulong = 0x80000000; - pub static SA_RESTART: libc::c_ulong = 0x10000000; - pub static SA_SIGINFO: libc::c_ulong = 0x00000008; - pub static SIGCHLD: libc::c_int = 18; + pub const SA_NOCLDSTOP: libc::c_ulong = 0x00000001; + pub const SA_NOCLDWAIT: libc::c_ulong = 0x00010000; + pub const SA_NODEFER: libc::c_ulong = 0x40000000; + pub const SA_ONSTACK: libc::c_ulong = 0x08000000; + pub const SA_RESETHAND: libc::c_ulong = 0x80000000; + pub const SA_RESTART: libc::c_ulong = 0x10000000; + pub const SA_SIGINFO: libc::c_ulong = 0x00000008; + pub const SIGCHLD: libc::c_int = 18; // This definition is not as accurate as it could be, {pid, uid, status} is // actually a giant union. Currently we're only interested in these fields, @@ -223,14 +223,14 @@ mod signal { mod signal { use libc; - pub static SA_ONSTACK: libc::c_int = 0x0001; - pub static SA_RESTART: libc::c_int = 0x0002; - pub static SA_RESETHAND: libc::c_int = 0x0004; - pub static SA_NOCLDSTOP: libc::c_int = 0x0008; - pub static SA_NODEFER: libc::c_int = 0x0010; - pub static SA_NOCLDWAIT: libc::c_int = 0x0020; - pub static SA_SIGINFO: libc::c_int = 0x0040; - pub static SIGCHLD: libc::c_int = 20; + pub const SA_ONSTACK: libc::c_int = 0x0001; + pub const SA_RESTART: libc::c_int = 0x0002; + pub const SA_RESETHAND: libc::c_int = 0x0004; + pub const SA_NOCLDSTOP: libc::c_int = 0x0008; + pub const SA_NODEFER: libc::c_int = 0x0010; + pub const SA_NOCLDWAIT: libc::c_int = 0x0020; + pub const SA_SIGINFO: libc::c_int = 0x0040; + pub const SIGCHLD: libc::c_int = 20; #[cfg(any(target_os = "macos", target_os = "ios"))] pub type sigset_t = u32; diff --git a/src/libnative/io/c_windows.rs b/src/libnative/io/c_windows.rs index 909b37895b7b5..2266f41eff9af 100644 --- a/src/libnative/io/c_windows.rs +++ b/src/libnative/io/c_windows.rs @@ -14,26 +14,26 @@ use libc; -pub static WSADESCRIPTION_LEN: uint = 256; -pub static WSASYS_STATUS_LEN: uint = 128; -pub static FIONBIO: libc::c_long = 0x8004667e; +pub const WSADESCRIPTION_LEN: uint = 256; +pub const WSASYS_STATUS_LEN: uint = 128; +pub const FIONBIO: libc::c_long = 0x8004667e; static FD_SETSIZE: uint = 64; -pub static MSG_DONTWAIT: libc::c_int = 0; -pub static ERROR_ILLEGAL_CHARACTER: libc::c_int = 582; -pub static ENABLE_ECHO_INPUT: libc::DWORD = 0x4; -pub static ENABLE_EXTENDED_FLAGS: libc::DWORD = 0x80; -pub static ENABLE_INSERT_MODE: libc::DWORD = 0x20; -pub static ENABLE_LINE_INPUT: libc::DWORD = 0x2; -pub static ENABLE_PROCESSED_INPUT: libc::DWORD = 0x1; -pub static ENABLE_QUICK_EDIT_MODE: libc::DWORD = 0x40; -pub static WSA_INVALID_EVENT: WSAEVENT = 0 as WSAEVENT; - -pub static FD_ACCEPT: libc::c_long = 0x08; -pub static FD_MAX_EVENTS: uint = 10; -pub static WSA_INFINITE: libc::DWORD = libc::INFINITE; -pub static WSA_WAIT_TIMEOUT: libc::DWORD = libc::consts::os::extra::WAIT_TIMEOUT; -pub static WSA_WAIT_EVENT_0: libc::DWORD = libc::consts::os::extra::WAIT_OBJECT_0; -pub static WSA_WAIT_FAILED: libc::DWORD = libc::consts::os::extra::WAIT_FAILED; +pub const MSG_DONTWAIT: libc::c_int = 0; +pub const ERROR_ILLEGAL_CHARACTER: libc::c_int = 582; +pub const ENABLE_ECHO_INPUT: libc::DWORD = 0x4; +pub const ENABLE_EXTENDED_FLAGS: libc::DWORD = 0x80; +pub const ENABLE_INSERT_MODE: libc::DWORD = 0x20; +pub const ENABLE_LINE_INPUT: libc::DWORD = 0x2; +pub const ENABLE_PROCESSED_INPUT: libc::DWORD = 0x1; +pub const ENABLE_QUICK_EDIT_MODE: libc::DWORD = 0x40; +pub const WSA_INVALID_EVENT: WSAEVENT = 0 as WSAEVENT; + +pub const FD_ACCEPT: libc::c_long = 0x08; +pub const FD_MAX_EVENTS: uint = 10; +pub const WSA_INFINITE: libc::DWORD = libc::INFINITE; +pub const WSA_WAIT_TIMEOUT: libc::DWORD = libc::consts::os::extra::WAIT_TIMEOUT; +pub const WSA_WAIT_EVENT_0: libc::DWORD = libc::consts::os::extra::WAIT_OBJECT_0; +pub const WSA_WAIT_FAILED: libc::DWORD = libc::consts::os::extra::WAIT_FAILED; #[repr(C)] #[cfg(target_arch = "x86")] From edf88416426d82d0099fc888e443bf21feeb1f04 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 6 Oct 2014 16:33:44 -0700 Subject: [PATCH 15/24] syntax: Convert statics to constants --- src/libsyntax/abi.rs | 4 ++-- src/libsyntax/ast.rs | 10 +++++----- src/libsyntax/codemap.rs | 4 ++-- src/libsyntax/parse/parser.rs | 8 ++++---- src/libsyntax/parse/token.rs | 16 ++++++++-------- src/libsyntax/print/pprust.rs | 4 ++-- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/libsyntax/abi.rs b/src/libsyntax/abi.rs index 3a02d74edffb7..03325ad470668 100644 --- a/src/libsyntax/abi.rs +++ b/src/libsyntax/abi.rs @@ -48,9 +48,9 @@ pub enum Architecture { } #[allow(non_uppercase_statics)] -static IntelBits: u32 = (1 << (X86 as uint)) | (1 << (X86_64 as uint)); +const IntelBits: u32 = (1 << (X86 as uint)) | (1 << (X86_64 as uint)); #[allow(non_uppercase_statics)] -static ArmBits: u32 = (1 << (Arm as uint)); +const ArmBits: u32 = (1 << (Arm as uint)); pub struct AbiData { abi: Abi, diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index c47d6b0fc9dc8..274bb2e39e019 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -104,8 +104,8 @@ impl PartialEq for Ident { // this uint is a reference to a table stored in thread-local // storage. pub type SyntaxContext = u32; -pub static EMPTY_CTXT : SyntaxContext = 0; -pub static ILLEGAL_CTXT : SyntaxContext = 1; +pub const EMPTY_CTXT : SyntaxContext = 0; +pub const ILLEGAL_CTXT : SyntaxContext = 1; /// A name is a part of an identifier, representing a string or gensym. It's /// the result of interning. @@ -198,13 +198,13 @@ pub struct DefId { /// Item definitions in the currently-compiled crate would have the CrateNum /// LOCAL_CRATE in their DefId. -pub static LOCAL_CRATE: CrateNum = 0; -pub static CRATE_NODE_ID: NodeId = 0; +pub const LOCAL_CRATE: CrateNum = 0; +pub const CRATE_NODE_ID: NodeId = 0; /// When parsing and doing expansions, we initially give all AST nodes this AST /// node value. Then later, in the renumber pass, we renumber them to have /// small, positive ids. -pub static DUMMY_NODE_ID: NodeId = -1; +pub const DUMMY_NODE_ID: NodeId = -1; /// The AST represents all type param bounds as types. /// typeck::collect::compute_bounds matches these against diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index dda4107043106..5d96cc359c2ff 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -96,7 +96,7 @@ pub struct Span { pub expn_id: ExpnId } -pub static DUMMY_SP: Span = Span { lo: BytePos(0), hi: BytePos(0), expn_id: NO_EXPANSION }; +pub const DUMMY_SP: Span = Span { lo: BytePos(0), hi: BytePos(0), expn_id: NO_EXPANSION }; #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub struct Spanned { @@ -227,7 +227,7 @@ pub struct ExpnInfo { #[deriving(PartialEq, Eq, Clone, Show, Hash, Encodable, Decodable)] pub struct ExpnId(u32); -pub static NO_EXPANSION: ExpnId = ExpnId(-1); +pub const NO_EXPANSION: ExpnId = ExpnId(-1); impl ExpnId { pub fn from_llvm_cookie(cookie: c_uint) -> ExpnId { diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index e73ffd7e58123..e7f40cf072296 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -91,10 +91,10 @@ use std::iter; bitflags! { flags Restrictions: u8 { - static UNRESTRICTED = 0b0000, - static RESTRICTION_STMT_EXPR = 0b0001, - static RESTRICTION_NO_BAR_OP = 0b0010, - static RESTRICTION_NO_STRUCT_LITERAL = 0b0100 + const UNRESTRICTED = 0b0000, + const RESTRICTION_STMT_EXPR = 0b0001, + const RESTRICTION_NO_BAR_OP = 0b0010, + const RESTRICTION_NO_STRUCT_LITERAL = 0b0100 } } diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 7cc78891d91d1..fa6b0c5ad4ae7 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -385,13 +385,13 @@ macro_rules! declare_special_idents_and_keywords {( use ast::{Ident, Name}; $( #[allow(non_uppercase_statics)] - pub static $si_static: Ident = Ident { name: Name($si_name), ctxt: 0 }; + pub const $si_static: Ident = Ident { name: Name($si_name), ctxt: 0 }; )* } pub mod special_names { use ast::Name; - $( #[allow(non_uppercase_statics)] pub static $si_static: Name = Name($si_name); )* + $( #[allow(non_uppercase_statics)] pub const $si_static: Name = Name($si_name); )* } /** @@ -432,13 +432,13 @@ macro_rules! declare_special_idents_and_keywords {( }} // If the special idents get renumbered, remember to modify these two as appropriate -pub static SELF_KEYWORD_NAME: Name = Name(SELF_KEYWORD_NAME_NUM); -static STATIC_KEYWORD_NAME: Name = Name(STATIC_KEYWORD_NAME_NUM); -static SUPER_KEYWORD_NAME: Name = Name(SUPER_KEYWORD_NAME_NUM); +pub const SELF_KEYWORD_NAME: Name = Name(SELF_KEYWORD_NAME_NUM); +const STATIC_KEYWORD_NAME: Name = Name(STATIC_KEYWORD_NAME_NUM); +const SUPER_KEYWORD_NAME: Name = Name(SUPER_KEYWORD_NAME_NUM); -pub static SELF_KEYWORD_NAME_NUM: u32 = 1; -static STATIC_KEYWORD_NAME_NUM: u32 = 2; -static SUPER_KEYWORD_NAME_NUM: u32 = 3; +pub const SELF_KEYWORD_NAME_NUM: u32 = 1; +const STATIC_KEYWORD_NAME_NUM: u32 = 2; +const SUPER_KEYWORD_NAME_NUM: u32 = 3; // NB: leaving holes in the ident table is bad! a different ident will get // interned with the id from the hole, but it will be between the min and max diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 321b00db47eaf..e1a2b2aeefeea 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -90,10 +90,10 @@ pub fn rust_printer_annotated<'a>(writer: Box, } #[allow(non_uppercase_statics)] -pub static indent_unit: uint = 4u; +pub const indent_unit: uint = 4u; #[allow(non_uppercase_statics)] -pub static default_columns: uint = 78u; +pub const default_columns: uint = 78u; /// Requires you to pass an input filename and reader so that /// it can scan the input text for comments and literals to From d3eaf3290048a9da680b2c13b158fd6aeb307902 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 6 Oct 2014 16:33:56 -0700 Subject: [PATCH 16/24] serialize: Convert statics to constants --- src/libserialize/json.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index a9ac5ec3ab4f6..5d9211caac1b1 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -360,18 +360,16 @@ fn escape_char(writer: &mut io::Writer, v: char) -> Result<(), io::IoError> { } fn spaces(wr: &mut io::Writer, mut n: uint) -> Result<(), io::IoError> { - #[allow(non_uppercase_statics)] - static len: uint = 16; - #[allow(non_uppercase_statics)] - static buf: [u8, ..len] = [b' ', ..len]; + const LEN: uint = 16; + static BUF: [u8, ..LEN] = [b' ', ..LEN]; - while n >= len { - try!(wr.write(buf)); - n -= len; + while n >= LEN { + try!(wr.write(BUF)); + n -= LEN; } if n > 0 { - wr.write(buf[..n]) + wr.write(BUF[..n]) } else { Ok(()) } From b8fb0cf789289fb7d350cc553d871f880e1b2b02 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 6 Oct 2014 16:35:11 -0700 Subject: [PATCH 17/24] rustrt: Convert statics to constants --- src/librustrt/c_str.rs | 2 +- src/librustrt/lib.rs | 2 +- src/librustrt/libunwind.rs | 10 ++++---- src/librustrt/mutex.rs | 48 +++++++++++++++++++------------------- src/librustrt/stack.rs | 2 +- src/librustrt/unwind.rs | 2 +- src/librustrt/util.rs | 6 ++--- 7 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/librustrt/c_str.rs b/src/librustrt/c_str.rs index 934fb0ddd3ce4..a5ac70286fe81 100644 --- a/src/librustrt/c_str.rs +++ b/src/librustrt/c_str.rs @@ -414,7 +414,7 @@ impl ToCStr for String { } // The length of the stack allocated buffer for `vec.with_c_str()` -static BUF_LEN: uint = 128; +const BUF_LEN: uint = 128; impl<'a> ToCStr for &'a [u8] { fn to_c_str(&self) -> CString { diff --git a/src/librustrt/lib.rs b/src/librustrt/lib.rs index d3ea07291a423..26fc399968cd5 100644 --- a/src/librustrt/lib.rs +++ b/src/librustrt/lib.rs @@ -100,7 +100,7 @@ pub trait Runtime { /// The default error code of the rust runtime if the main task fails instead /// of exiting cleanly. -pub static DEFAULT_ERROR_CODE: int = 101; +pub const DEFAULT_ERROR_CODE: int = 101; /// One-time runtime initialization. /// diff --git a/src/librustrt/libunwind.rs b/src/librustrt/libunwind.rs index bb7a1227e0e47..6867cb2e76b34 100644 --- a/src/librustrt/libunwind.rs +++ b/src/librustrt/libunwind.rs @@ -57,19 +57,19 @@ pub type _Unwind_Exception_Class = u64; pub type _Unwind_Word = libc::uintptr_t; #[cfg(target_arch = "x86")] -pub static unwinder_private_data_size: uint = 5; +pub const unwinder_private_data_size: uint = 5; #[cfg(target_arch = "x86_64")] -pub static unwinder_private_data_size: uint = 6; +pub const unwinder_private_data_size: uint = 6; #[cfg(all(target_arch = "arm", not(target_os = "ios")))] -pub static unwinder_private_data_size: uint = 20; +pub const unwinder_private_data_size: uint = 20; #[cfg(all(target_arch = "arm", target_os = "ios"))] -pub static unwinder_private_data_size: uint = 5; +pub const unwinder_private_data_size: uint = 5; #[cfg(any(target_arch = "mips", target_arch = "mipsel"))] -pub static unwinder_private_data_size: uint = 2; +pub const unwinder_private_data_size: uint = 2; #[repr(C)] pub struct _Unwind_Exception { diff --git a/src/librustrt/mutex.rs b/src/librustrt/mutex.rs index 28b0256f2e6e3..d10ba69386695 100644 --- a/src/librustrt/mutex.rs +++ b/src/librustrt/mutex.rs @@ -88,7 +88,7 @@ pub struct LockGuard<'a> { lock: &'a StaticNativeMutex } -pub static NATIVE_MUTEX_INIT: StaticNativeMutex = StaticNativeMutex { +pub const NATIVE_MUTEX_INIT: StaticNativeMutex = StaticNativeMutex { inner: imp::MUTEX_INIT, }; @@ -353,9 +353,9 @@ mod imp { pub type pthread_mutex_t = *mut libc::c_void; pub type pthread_cond_t = *mut libc::c_void; - pub static PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = + pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = 0 as pthread_mutex_t; - pub static PTHREAD_COND_INITIALIZER: pthread_cond_t = + pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = 0 as pthread_cond_t; } @@ -390,11 +390,11 @@ mod imp { __opaque: [u8, ..__PTHREAD_COND_SIZE__], } - pub static PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { + pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { __sig: _PTHREAD_MUTEX_SIG_INIT, __opaque: [0, ..__PTHREAD_MUTEX_SIZE__], }; - pub static PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { + pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { __sig: _PTHREAD_COND_SIG_INIT, __opaque: [0, ..__PTHREAD_COND_SIZE__], }; @@ -406,25 +406,25 @@ mod imp { // minus 8 because we have an 'align' field #[cfg(target_arch = "x86_64")] - static __SIZEOF_PTHREAD_MUTEX_T: uint = 40 - 8; + const __SIZEOF_PTHREAD_MUTEX_T: uint = 40 - 8; #[cfg(target_arch = "x86")] - static __SIZEOF_PTHREAD_MUTEX_T: uint = 24 - 8; + const __SIZEOF_PTHREAD_MUTEX_T: uint = 24 - 8; #[cfg(target_arch = "arm")] - static __SIZEOF_PTHREAD_MUTEX_T: uint = 24 - 8; + const __SIZEOF_PTHREAD_MUTEX_T: uint = 24 - 8; #[cfg(target_arch = "mips")] - static __SIZEOF_PTHREAD_MUTEX_T: uint = 24 - 8; + const __SIZEOF_PTHREAD_MUTEX_T: uint = 24 - 8; #[cfg(target_arch = "mipsel")] - static __SIZEOF_PTHREAD_MUTEX_T: uint = 24 - 8; + const __SIZEOF_PTHREAD_MUTEX_T: uint = 24 - 8; #[cfg(target_arch = "x86_64")] - static __SIZEOF_PTHREAD_COND_T: uint = 48 - 8; + const __SIZEOF_PTHREAD_COND_T: uint = 48 - 8; #[cfg(target_arch = "x86")] - static __SIZEOF_PTHREAD_COND_T: uint = 48 - 8; + const __SIZEOF_PTHREAD_COND_T: uint = 48 - 8; #[cfg(target_arch = "arm")] - static __SIZEOF_PTHREAD_COND_T: uint = 48 - 8; + const __SIZEOF_PTHREAD_COND_T: uint = 48 - 8; #[cfg(target_arch = "mips")] - static __SIZEOF_PTHREAD_COND_T: uint = 48 - 8; + const __SIZEOF_PTHREAD_COND_T: uint = 48 - 8; #[cfg(target_arch = "mipsel")] - static __SIZEOF_PTHREAD_COND_T: uint = 48 - 8; + const __SIZEOF_PTHREAD_COND_T: uint = 48 - 8; #[repr(C)] pub struct pthread_mutex_t { @@ -437,11 +437,11 @@ mod imp { size: [u8, ..__SIZEOF_PTHREAD_COND_T], } - pub static PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { + pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { __align: 0, size: [0, ..__SIZEOF_PTHREAD_MUTEX_T], }; - pub static PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { + pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { __align: 0, size: [0, ..__SIZEOF_PTHREAD_COND_T], }; @@ -455,10 +455,10 @@ mod imp { #[repr(C)] pub struct pthread_cond_t { value: libc::c_int } - pub static PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { + pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { value: 0, }; - pub static PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { + pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { value: 0, }; } @@ -468,7 +468,7 @@ mod imp { cond: UnsafeCell, } - pub static MUTEX_INIT: Mutex = Mutex { + pub const MUTEX_INIT: Mutex = Mutex { lock: UnsafeCell { value: PTHREAD_MUTEX_INITIALIZER }, cond: UnsafeCell { value: PTHREAD_COND_INITIALIZER }, }; @@ -523,11 +523,11 @@ mod imp { use libc; type LPCRITICAL_SECTION = *mut c_void; - static SPIN_COUNT: DWORD = 4000; + const SPIN_COUNT: DWORD = 4000; #[cfg(target_arch = "x86")] - static CRIT_SECTION_SIZE: uint = 24; + const CRIT_SECTION_SIZE: uint = 24; #[cfg(target_arch = "x86_64")] - static CRIT_SECTION_SIZE: uint = 40; + const CRIT_SECTION_SIZE: uint = 40; pub struct Mutex { // pointers for the lock/cond handles, atomically updated @@ -535,7 +535,7 @@ mod imp { cond: atomic::AtomicUint, } - pub static MUTEX_INIT: Mutex = Mutex { + pub const MUTEX_INIT: Mutex = Mutex { lock: atomic::INIT_ATOMIC_UINT, cond: atomic::INIT_ATOMIC_UINT, }; diff --git a/src/librustrt/stack.rs b/src/librustrt/stack.rs index 5c94ef61bfdb7..4034000e28f33 100644 --- a/src/librustrt/stack.rs +++ b/src/librustrt/stack.rs @@ -46,7 +46,7 @@ // corresponding prolog, decision was taken to disable segmented // stack support on iOS. -pub static RED_ZONE: uint = 20 * 1024; +pub const RED_ZONE: uint = 20 * 1024; /// This function is invoked from rust's current __morestack function. Segmented /// stacks are currently not enabled as segmented stacks, but rather one giant diff --git a/src/librustrt/unwind.rs b/src/librustrt/unwind.rs index f07e8ecc335d7..2a2fa29eca0b2 100644 --- a/src/librustrt/unwind.rs +++ b/src/librustrt/unwind.rs @@ -91,7 +91,7 @@ pub type Callback = fn(msg: &Any + Send, file: &'static str, line: uint); // Variables used for invoking callbacks when a task starts to unwind. // // For more information, see below. -static MAX_CALLBACKS: uint = 16; +const MAX_CALLBACKS: uint = 16; static mut CALLBACKS: [atomic::AtomicUint, ..MAX_CALLBACKS] = [atomic::INIT_ATOMIC_UINT, atomic::INIT_ATOMIC_UINT, atomic::INIT_ATOMIC_UINT, atomic::INIT_ATOMIC_UINT, diff --git a/src/librustrt/util.rs b/src/librustrt/util.rs index ab1ef2fc5aa68..a94da33e54357 100644 --- a/src/librustrt/util.rs +++ b/src/librustrt/util.rs @@ -23,15 +23,15 @@ use libc; // // FIXME: Once the runtime matures remove the `true` below to turn off rtassert, // etc. -pub static ENFORCE_SANITY: bool = true || !cfg!(rtopt) || cfg!(rtdebug) || +pub const ENFORCE_SANITY: bool = true || !cfg!(rtopt) || cfg!(rtdebug) || cfg!(rtassert); pub struct Stdio(libc::c_int); #[allow(non_uppercase_statics)] -pub static Stdout: Stdio = Stdio(libc::STDOUT_FILENO); +pub const Stdout: Stdio = Stdio(libc::STDOUT_FILENO); #[allow(non_uppercase_statics)] -pub static Stderr: Stdio = Stdio(libc::STDERR_FILENO); +pub const Stderr: Stdio = Stdio(libc::STDERR_FILENO); impl fmt::FormatWriter for Stdio { fn write(&mut self, data: &[u8]) -> fmt::Result { From 831f909484176c20a6acba0a689cb9787948e9d7 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 6 Oct 2014 17:30:54 -0700 Subject: [PATCH 18/24] rustc: Convert statics to constants --- src/librustc/back/link.rs | 10 +- src/librustc/driver/config.rs | 6 +- src/librustc/lint/context.rs | 4 +- src/librustc/lint/mod.rs | 4 +- src/librustc/metadata/common.rs | 202 ++++++++++---------- src/librustc/metadata/encoder.rs | 2 +- src/librustc/metadata/loader.rs | 24 +-- src/librustc/middle/graph.rs | 8 +- src/librustc/middle/trans/cleanup.rs | 6 +- src/librustc/middle/ty.rs | 6 +- src/librustc/middle/typeck/astconv.rs | 4 +- src/librustc/middle/typeck/infer/resolve.rs | 26 +-- src/librustc_back/abi.rs | 20 +- src/librustc_llvm/lib.rs | 56 +++--- 14 files changed, 189 insertions(+), 189 deletions(-) diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs index 295768d468eac..fc5d726bf67c2 100644 --- a/src/librustc/back/link.rs +++ b/src/librustc/back/link.rs @@ -55,22 +55,22 @@ use syntax::parse::token; // This is the "magic number" expected at the beginning of a LLVM bytecode // object in an rlib. -pub static RLIB_BYTECODE_OBJECT_MAGIC: &'static [u8] = b"RUST_OBJECT"; +pub const RLIB_BYTECODE_OBJECT_MAGIC: &'static [u8] = b"RUST_OBJECT"; // The version number this compiler will write to bytecode objects in rlibs -pub static RLIB_BYTECODE_OBJECT_VERSION: u32 = 1; +pub const RLIB_BYTECODE_OBJECT_VERSION: u32 = 1; // The offset in bytes the bytecode object format version number can be found at -pub static RLIB_BYTECODE_OBJECT_VERSION_OFFSET: uint = 11; +pub const RLIB_BYTECODE_OBJECT_VERSION_OFFSET: uint = 11; // The offset in bytes the size of the compressed bytecode can be found at in // format version 1 -pub static RLIB_BYTECODE_OBJECT_V1_DATASIZE_OFFSET: uint = +pub const RLIB_BYTECODE_OBJECT_V1_DATASIZE_OFFSET: uint = RLIB_BYTECODE_OBJECT_VERSION_OFFSET + 4; // The offset in bytes the compressed LLVM bytecode can be found at in format // version 1 -pub static RLIB_BYTECODE_OBJECT_V1_DATA_OFFSET: uint = +pub const RLIB_BYTECODE_OBJECT_V1_DATA_OFFSET: uint = RLIB_BYTECODE_OBJECT_V1_DATASIZE_OFFSET + 8; diff --git a/src/librustc/driver/config.rs b/src/librustc/driver/config.rs index 9ce012502446d..fdd3c5b5a2608 100644 --- a/src/librustc/driver/config.rs +++ b/src/librustc/driver/config.rs @@ -154,10 +154,10 @@ pub enum CrateType { macro_rules! debugging_opts( ([ $opt:ident ] $cnt:expr ) => ( - pub static $opt: u64 = 1 << $cnt; + pub const $opt: u64 = 1 << $cnt; ); ([ $opt:ident, $($rest:ident),* ] $cnt:expr ) => ( - pub static $opt: u64 = 1 << $cnt; + pub const $opt: u64 = 1 << $cnt; debugging_opts!([ $($rest),* ] $cnt + 1) ) ) @@ -268,7 +268,7 @@ macro_rules! cgoptions( } pub type CodegenSetter = fn(&mut CodegenOptions, v: Option<&str>) -> bool; - pub static CG_OPTIONS: &'static [(&'static str, CodegenSetter, + pub const CG_OPTIONS: &'static [(&'static str, CodegenSetter, &'static str)] = &[ $( (stringify!($opt), cgsetters::$opt, $desc) ),* ]; diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index bb277511463b9..6d00724fb41fc 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -112,9 +112,9 @@ impl LintStore { pub fn register_pass(&mut self, sess: Option<&Session>, from_plugin: bool, pass: LintPassObject) { for &lint in pass.get_lints().iter() { - self.lints.push((lint, from_plugin)); + self.lints.push((*lint, from_plugin)); - let id = LintId::of(lint); + let id = LintId::of(*lint); if !self.by_name.insert(lint.name_lower(), id) { let msg = format!("duplicate specification of lint {}", lint.name_lower()); match (sess, from_plugin) { diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index 8047c12efc291..5afe5326171d7 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -99,12 +99,12 @@ macro_rules! declare_lint ( macro_rules! lint_array ( ($( $lint:expr ),*) => ( { #[allow(non_uppercase_statics)] - static array: LintArray = &[ $( $lint ),* ]; + static array: LintArray = &[ $( &$lint ),* ]; array } )) -pub type LintArray = &'static [&'static Lint]; +pub type LintArray = &'static [&'static &'static Lint]; /// Trait for types providing lint checks. /// diff --git a/src/librustc/metadata/common.rs b/src/librustc/metadata/common.rs index ef88795762e43..492feee6f84b3 100644 --- a/src/librustc/metadata/common.rs +++ b/src/librustc/metadata/common.rs @@ -15,83 +15,83 @@ use back::svh::Svh; // EBML enum definitions and utils shared by the encoder and decoder -pub static tag_items: uint = 0x00; +pub const tag_items: uint = 0x00; -pub static tag_paths_data_name: uint = 0x01; +pub const tag_paths_data_name: uint = 0x01; -pub static tag_def_id: uint = 0x02; +pub const tag_def_id: uint = 0x02; -pub static tag_items_data: uint = 0x03; +pub const tag_items_data: uint = 0x03; -pub static tag_items_data_item: uint = 0x04; +pub const tag_items_data_item: uint = 0x04; -pub static tag_items_data_item_family: uint = 0x05; +pub const tag_items_data_item_family: uint = 0x05; -pub static tag_items_data_item_type: uint = 0x07; +pub const tag_items_data_item_type: uint = 0x07; -pub static tag_items_data_item_symbol: uint = 0x08; +pub const tag_items_data_item_symbol: uint = 0x08; -pub static tag_items_data_item_variant: uint = 0x09; +pub const tag_items_data_item_variant: uint = 0x09; -pub static tag_items_data_parent_item: uint = 0x0a; +pub const tag_items_data_parent_item: uint = 0x0a; -pub static tag_items_data_item_is_tuple_struct_ctor: uint = 0x0b; +pub const tag_items_data_item_is_tuple_struct_ctor: uint = 0x0b; -pub static tag_index: uint = 0x0c; +pub const tag_index: uint = 0x0c; -pub static tag_index_buckets: uint = 0x0d; +pub const tag_index_buckets: uint = 0x0d; -pub static tag_index_buckets_bucket: uint = 0x0e; +pub const tag_index_buckets_bucket: uint = 0x0e; -pub static tag_index_buckets_bucket_elt: uint = 0x0f; +pub const tag_index_buckets_bucket_elt: uint = 0x0f; -pub static tag_index_table: uint = 0x10; +pub const tag_index_table: uint = 0x10; -pub static tag_meta_item_name_value: uint = 0x11; +pub const tag_meta_item_name_value: uint = 0x11; -pub static tag_meta_item_name: uint = 0x12; +pub const tag_meta_item_name: uint = 0x12; -pub static tag_meta_item_value: uint = 0x13; +pub const tag_meta_item_value: uint = 0x13; -pub static tag_attributes: uint = 0x14; +pub const tag_attributes: uint = 0x14; -pub static tag_attribute: uint = 0x15; +pub const tag_attribute: uint = 0x15; -pub static tag_meta_item_word: uint = 0x16; +pub const tag_meta_item_word: uint = 0x16; -pub static tag_meta_item_list: uint = 0x17; +pub const tag_meta_item_list: uint = 0x17; // The list of crates that this crate depends on -pub static tag_crate_deps: uint = 0x18; +pub const tag_crate_deps: uint = 0x18; // A single crate dependency -pub static tag_crate_dep: uint = 0x19; +pub const tag_crate_dep: uint = 0x19; -pub static tag_crate_hash: uint = 0x1a; -pub static tag_crate_crate_name: uint = 0x1b; +pub const tag_crate_hash: uint = 0x1a; +pub const tag_crate_crate_name: uint = 0x1b; -pub static tag_crate_dep_crate_name: uint = 0x1d; -pub static tag_crate_dep_hash: uint = 0x1e; +pub const tag_crate_dep_crate_name: uint = 0x1d; +pub const tag_crate_dep_hash: uint = 0x1e; -pub static tag_mod_impl: uint = 0x1f; +pub const tag_mod_impl: uint = 0x1f; -pub static tag_item_trait_item: uint = 0x20; +pub const tag_item_trait_item: uint = 0x20; -pub static tag_item_trait_ref: uint = 0x21; -pub static tag_item_super_trait_ref: uint = 0x22; +pub const tag_item_trait_ref: uint = 0x21; +pub const tag_item_super_trait_ref: uint = 0x22; // discriminator value for variants -pub static tag_disr_val: uint = 0x23; +pub const tag_disr_val: uint = 0x23; // used to encode ast_map::PathElem -pub static tag_path: uint = 0x24; -pub static tag_path_len: uint = 0x25; -pub static tag_path_elem_mod: uint = 0x26; -pub static tag_path_elem_name: uint = 0x27; -pub static tag_item_field: uint = 0x28; -pub static tag_item_field_origin: uint = 0x29; - -pub static tag_item_variances: uint = 0x2a; +pub const tag_path: uint = 0x24; +pub const tag_path_len: uint = 0x25; +pub const tag_path_elem_mod: uint = 0x26; +pub const tag_path_elem_name: uint = 0x27; +pub const tag_item_field: uint = 0x28; +pub const tag_item_field_origin: uint = 0x29; + +pub const tag_item_variances: uint = 0x2a; /* trait items contain tag_item_trait_item elements, impl items contain tag_item_impl_item elements, and classes @@ -100,15 +100,15 @@ pub static tag_item_variances: uint = 0x2a; both, tag_item_trait_item and tag_item_impl_item have to be two different tags. */ -pub static tag_item_impl_item: uint = 0x30; -pub static tag_item_trait_method_explicit_self: uint = 0x31; +pub const tag_item_impl_item: uint = 0x30; +pub const tag_item_trait_method_explicit_self: uint = 0x31; // Reexports are found within module tags. Each reexport contains def_ids // and names. -pub static tag_items_data_item_reexport: uint = 0x38; -pub static tag_items_data_item_reexport_def_id: uint = 0x39; -pub static tag_items_data_item_reexport_name: uint = 0x3a; +pub const tag_items_data_item_reexport: uint = 0x38; +pub const tag_items_data_item_reexport_def_id: uint = 0x39; +pub const tag_items_data_item_reexport_name: uint = 0x3a; // used to encode crate_ctxt side tables #[deriving(PartialEq)] @@ -153,15 +153,15 @@ impl astencode_tag { } } -pub static tag_item_trait_item_sort: uint = 0x60; +pub const tag_item_trait_item_sort: uint = 0x60; -pub static tag_item_trait_parent_sort: uint = 0x61; +pub const tag_item_trait_parent_sort: uint = 0x61; -pub static tag_item_impl_type_basename: uint = 0x62; +pub const tag_item_impl_type_basename: uint = 0x62; -pub static tag_crate_triple: uint = 0x66; +pub const tag_crate_triple: uint = 0x66; -pub static tag_dylib_dependency_formats: uint = 0x67; +pub const tag_dylib_dependency_formats: uint = 0x67; // Language items are a top-level directory (for speed). Hierarchy: // @@ -170,51 +170,51 @@ pub static tag_dylib_dependency_formats: uint = 0x67; // - tag_lang_items_item_id: u32 // - tag_lang_items_item_node_id: u32 -pub static tag_lang_items: uint = 0x70; -pub static tag_lang_items_item: uint = 0x71; -pub static tag_lang_items_item_id: uint = 0x72; -pub static tag_lang_items_item_node_id: uint = 0x73; -pub static tag_lang_items_missing: uint = 0x74; +pub const tag_lang_items: uint = 0x70; +pub const tag_lang_items_item: uint = 0x71; +pub const tag_lang_items_item_id: uint = 0x72; +pub const tag_lang_items_item_node_id: uint = 0x73; +pub const tag_lang_items_missing: uint = 0x74; -pub static tag_item_unnamed_field: uint = 0x75; -pub static tag_items_data_item_visibility: uint = 0x76; +pub const tag_item_unnamed_field: uint = 0x75; +pub const tag_items_data_item_visibility: uint = 0x76; -pub static tag_item_method_tps: uint = 0x79; -pub static tag_item_method_fty: uint = 0x7a; +pub const tag_item_method_tps: uint = 0x79; +pub const tag_item_method_fty: uint = 0x7a; -pub static tag_mod_child: uint = 0x7b; -pub static tag_misc_info: uint = 0x7c; -pub static tag_misc_info_crate_items: uint = 0x7d; +pub const tag_mod_child: uint = 0x7b; +pub const tag_misc_info: uint = 0x7c; +pub const tag_misc_info_crate_items: uint = 0x7d; -pub static tag_item_method_provided_source: uint = 0x7e; -pub static tag_item_impl_vtables: uint = 0x7f; +pub const tag_item_method_provided_source: uint = 0x7e; +pub const tag_item_impl_vtables: uint = 0x7f; -pub static tag_impls: uint = 0x80; -pub static tag_impls_impl: uint = 0x81; +pub const tag_impls: uint = 0x80; +pub const tag_impls_impl: uint = 0x81; -pub static tag_items_data_item_inherent_impl: uint = 0x82; -pub static tag_items_data_item_extension_impl: uint = 0x83; +pub const tag_items_data_item_inherent_impl: uint = 0x82; +pub const tag_items_data_item_extension_impl: uint = 0x83; // GAP 0x84, 0x85, 0x86 -pub static tag_native_libraries: uint = 0x87; -pub static tag_native_libraries_lib: uint = 0x88; -pub static tag_native_libraries_name: uint = 0x89; -pub static tag_native_libraries_kind: uint = 0x8a; +pub const tag_native_libraries: uint = 0x87; +pub const tag_native_libraries_lib: uint = 0x88; +pub const tag_native_libraries_name: uint = 0x89; +pub const tag_native_libraries_kind: uint = 0x8a; -pub static tag_plugin_registrar_fn: uint = 0x8b; -pub static tag_exported_macros: uint = 0x8c; -pub static tag_macro_def: uint = 0x8d; +pub const tag_plugin_registrar_fn: uint = 0x8b; +pub const tag_exported_macros: uint = 0x8c; +pub const tag_macro_def: uint = 0x8d; -pub static tag_method_argument_names: uint = 0x8e; -pub static tag_method_argument_name: uint = 0x8f; +pub const tag_method_argument_names: uint = 0x8e; +pub const tag_method_argument_name: uint = 0x8f; -pub static tag_reachable_extern_fns: uint = 0x90; -pub static tag_reachable_extern_fn_id: uint = 0x91; +pub const tag_reachable_extern_fns: uint = 0x90; +pub const tag_reachable_extern_fn_id: uint = 0x91; -pub static tag_items_data_item_stability: uint = 0x92; +pub const tag_items_data_item_stability: uint = 0x92; -pub static tag_items_data_item_repr: uint = 0x93; +pub const tag_items_data_item_repr: uint = 0x93; #[deriving(Clone, Show)] pub struct LinkMeta { @@ -222,29 +222,29 @@ pub struct LinkMeta { pub crate_hash: Svh, } -pub static tag_unboxed_closures: uint = 0x95; -pub static tag_unboxed_closure: uint = 0x96; -pub static tag_unboxed_closure_type: uint = 0x97; -pub static tag_unboxed_closure_kind: uint = 0x98; +pub const tag_unboxed_closures: uint = 0x95; +pub const tag_unboxed_closure: uint = 0x96; +pub const tag_unboxed_closure_type: uint = 0x97; +pub const tag_unboxed_closure_kind: uint = 0x98; -pub static tag_struct_fields: uint = 0x99; -pub static tag_struct_field: uint = 0x9a; -pub static tag_struct_field_id: uint = 0x9b; +pub const tag_struct_fields: uint = 0x99; +pub const tag_struct_field: uint = 0x9a; +pub const tag_struct_field_id: uint = 0x9b; -pub static tag_attribute_is_sugared_doc: uint = 0x9c; +pub const tag_attribute_is_sugared_doc: uint = 0x9c; -pub static tag_trait_def_bounds: uint = 0x9d; +pub const tag_trait_def_bounds: uint = 0x9d; -pub static tag_items_data_region: uint = 0x9e; +pub const tag_items_data_region: uint = 0x9e; -pub static tag_region_param_def: uint = 0xa0; -pub static tag_region_param_def_ident: uint = 0xa1; -pub static tag_region_param_def_def_id: uint = 0xa2; -pub static tag_region_param_def_space: uint = 0xa3; -pub static tag_region_param_def_index: uint = 0xa4; +pub const tag_region_param_def: uint = 0xa0; +pub const tag_region_param_def_ident: uint = 0xa1; +pub const tag_region_param_def_def_id: uint = 0xa2; +pub const tag_region_param_def_space: uint = 0xa3; +pub const tag_region_param_def_index: uint = 0xa4; -pub static tag_type_param_def: uint = 0xa5; +pub const tag_type_param_def: uint = 0xa5; -pub static tag_item_generics: uint = 0xa6; -pub static tag_method_ty_generics: uint = 0xa7; +pub const tag_item_generics: uint = 0xa6; +pub const tag_method_ty_generics: uint = 0xa7; diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index 94d86956f7005..02f6a4a78dbc8 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -2035,7 +2035,7 @@ fn encode_dylib_dependency_formats(rbml_w: &mut Encoder, ecx: &EncodeContext) { // NB: Increment this as you change the metadata encoding version. #[allow(non_uppercase_statics)] -pub static metadata_encoding_version : &'static [u8] = &[b'r', b'u', b's', b't', 0, 0, 0, 1 ]; +pub const metadata_encoding_version : &'static [u8] = &[b'r', b'u', b's', b't', 0, 0, 0, 1 ]; pub fn encode_metadata(parms: EncodeParams, krate: &Crate) -> Vec { let mut wr = SeekableMemWriter::new(); diff --git a/src/librustc/metadata/loader.rs b/src/librustc/metadata/loader.rs index dc97b6c0df8cc..62c179f598c96 100644 --- a/src/librustc/metadata/loader.rs +++ b/src/librustc/metadata/loader.rs @@ -241,23 +241,23 @@ use std::collections::hashmap::{Occupied, Vacant}; use flate; use time; -pub static MACOS_DLL_PREFIX: &'static str = "lib"; -pub static MACOS_DLL_SUFFIX: &'static str = ".dylib"; +pub const MACOS_DLL_PREFIX: &'static str = "lib"; +pub const MACOS_DLL_SUFFIX: &'static str = ".dylib"; -pub static WIN32_DLL_PREFIX: &'static str = ""; -pub static WIN32_DLL_SUFFIX: &'static str = ".dll"; +pub const WIN32_DLL_PREFIX: &'static str = ""; +pub const WIN32_DLL_SUFFIX: &'static str = ".dll"; -pub static LINUX_DLL_PREFIX: &'static str = "lib"; -pub static LINUX_DLL_SUFFIX: &'static str = ".so"; +pub const LINUX_DLL_PREFIX: &'static str = "lib"; +pub const LINUX_DLL_SUFFIX: &'static str = ".so"; -pub static FREEBSD_DLL_PREFIX: &'static str = "lib"; -pub static FREEBSD_DLL_SUFFIX: &'static str = ".so"; +pub const FREEBSD_DLL_PREFIX: &'static str = "lib"; +pub const FREEBSD_DLL_SUFFIX: &'static str = ".so"; -pub static DRAGONFLY_DLL_PREFIX: &'static str = "lib"; -pub static DRAGONFLY_DLL_SUFFIX: &'static str = ".so"; +pub const DRAGONFLY_DLL_PREFIX: &'static str = "lib"; +pub const DRAGONFLY_DLL_SUFFIX: &'static str = ".so"; -pub static ANDROID_DLL_PREFIX: &'static str = "lib"; -pub static ANDROID_DLL_SUFFIX: &'static str = ".so"; +pub const ANDROID_DLL_PREFIX: &'static str = "lib"; +pub const ANDROID_DLL_SUFFIX: &'static str = ".so"; pub struct CrateMismatch { path: Path, diff --git a/src/librustc/middle/graph.rs b/src/librustc/middle/graph.rs index 9135ca07935a5..8484ec9293496 100644 --- a/src/librustc/middle/graph.rs +++ b/src/librustc/middle/graph.rs @@ -58,20 +58,20 @@ pub struct Edge { #[deriving(Clone, PartialEq, Show)] pub struct NodeIndex(pub uint); #[allow(non_uppercase_statics)] -pub static InvalidNodeIndex: NodeIndex = NodeIndex(uint::MAX); +pub const InvalidNodeIndex: NodeIndex = NodeIndex(uint::MAX); #[deriving(PartialEq)] pub struct EdgeIndex(pub uint); #[allow(non_uppercase_statics)] -pub static InvalidEdgeIndex: EdgeIndex = EdgeIndex(uint::MAX); +pub const InvalidEdgeIndex: EdgeIndex = EdgeIndex(uint::MAX); // Use a private field here to guarantee no more instances are created: #[deriving(Show)] pub struct Direction { repr: uint } #[allow(non_uppercase_statics)] -pub static Outgoing: Direction = Direction { repr: 0 }; +pub const Outgoing: Direction = Direction { repr: 0 }; #[allow(non_uppercase_statics)] -pub static Incoming: Direction = Direction { repr: 1 }; +pub const Incoming: Direction = Direction { repr: 1 }; impl NodeIndex { fn get(&self) -> uint { let NodeIndex(v) = *self; v } diff --git a/src/librustc/middle/trans/cleanup.rs b/src/librustc/middle/trans/cleanup.rs index 20fd0b0eb3d8f..392436d3a8069 100644 --- a/src/librustc/middle/trans/cleanup.rs +++ b/src/librustc/middle/trans/cleanup.rs @@ -49,9 +49,9 @@ pub struct CustomScopeIndex { index: uint } -pub static EXIT_BREAK: uint = 0; -pub static EXIT_LOOP: uint = 1; -pub static EXIT_MAX: uint = 2; +pub const EXIT_BREAK: uint = 0; +pub const EXIT_LOOP: uint = 1; +pub const EXIT_MAX: uint = 2; pub enum CleanupScopeKind<'blk, 'tcx: 'blk> { CustomScopeKind, diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index e1491c1f49be2..cea74c6573d54 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -68,7 +68,7 @@ use std::collections::enum_set::{EnumSet, CLike}; pub type Disr = u64; -pub static INITIAL_DISCRIMINANT_VALUE: Disr = 0; +pub const INITIAL_DISCRIMINANT_VALUE: Disr = 0; // Data types @@ -918,7 +918,7 @@ mod primitives { flags: super::has_ty_err as uint, }; - pub static LAST_PRIMITIVE_ID: uint = 18; + pub const LAST_PRIMITIVE_ID: uint = 18; } // NB: If you change this, you'll probably want to change the corresponding @@ -2200,7 +2200,7 @@ macro_rules! def_type_content_sets( use middle::ty::TypeContents; $( #[allow(non_uppercase_statics)] - pub static $name: TypeContents = TypeContents { bits: $bits }; + pub const $name: TypeContents = TypeContents { bits: $bits }; )+ } } diff --git a/src/librustc/middle/typeck/astconv.rs b/src/librustc/middle/typeck/astconv.rs index 4d21090dd2c2a..efd0a2a0e48b2 100644 --- a/src/librustc/middle/typeck/astconv.rs +++ b/src/librustc/middle/typeck/astconv.rs @@ -440,8 +440,8 @@ pub fn ast_path_to_ty_relaxed<'tcx, AC: AstConv<'tcx>, } } -pub static NO_REGIONS: uint = 1; -pub static NO_TPS: uint = 2; +pub const NO_REGIONS: uint = 1; +pub const NO_TPS: uint = 2; fn check_path_args(tcx: &ty::ctxt, path: &ast::Path, diff --git a/src/librustc/middle/typeck/infer/resolve.rs b/src/librustc/middle/typeck/infer/resolve.rs index 13659d4b77e1c..87f3fd987871c 100644 --- a/src/librustc/middle/typeck/infer/resolve.rs +++ b/src/librustc/middle/typeck/infer/resolve.rs @@ -57,21 +57,21 @@ use middle::typeck::infer::{unresolved_int_ty,unresolved_float_ty,unresolved_ty} use syntax::codemap::Span; use util::ppaux::{Repr, ty_to_string}; -pub static resolve_nested_tvar: uint = 0b0000000001; -pub static resolve_rvar: uint = 0b0000000010; -pub static resolve_ivar: uint = 0b0000000100; -pub static resolve_fvar: uint = 0b0000001000; -pub static resolve_all: uint = 0b0000001111; -pub static force_tvar: uint = 0b0000100000; -pub static force_rvar: uint = 0b0001000000; -pub static force_ivar: uint = 0b0010000000; -pub static force_fvar: uint = 0b0100000000; -pub static force_all: uint = 0b0111100000; +pub const resolve_nested_tvar: uint = 0b0000000001; +pub const resolve_rvar: uint = 0b0000000010; +pub const resolve_ivar: uint = 0b0000000100; +pub const resolve_fvar: uint = 0b0000001000; +pub const resolve_all: uint = 0b0000001111; +pub const force_tvar: uint = 0b0000100000; +pub const force_rvar: uint = 0b0001000000; +pub const force_ivar: uint = 0b0010000000; +pub const force_fvar: uint = 0b0100000000; +pub const force_all: uint = 0b0111100000; -pub static not_regions: uint = !(force_rvar | resolve_rvar); +pub const not_regions: uint = !(force_rvar | resolve_rvar); -pub static try_resolve_tvar_shallow: uint = 0; -pub static resolve_and_force_all_but_regions: uint = +pub const try_resolve_tvar_shallow: uint = 0; +pub const resolve_and_force_all_but_regions: uint = (resolve_all | force_all) & not_regions; pub struct ResolveState<'a, 'tcx: 'a> { diff --git a/src/librustc_back/abi.rs b/src/librustc_back/abi.rs index 1e69ce003c557..bf525db7661b0 100644 --- a/src/librustc_back/abi.rs +++ b/src/librustc_back/abi.rs @@ -10,20 +10,20 @@ #![allow(non_uppercase_statics)] -pub static box_field_refcnt: uint = 0u; -pub static box_field_drop_glue: uint = 1u; -pub static box_field_body: uint = 4u; +pub const box_field_refcnt: uint = 0u; +pub const box_field_drop_glue: uint = 1u; +pub const box_field_body: uint = 4u; -pub static tydesc_field_visit_glue: uint = 3u; +pub const tydesc_field_visit_glue: uint = 3u; // The two halves of a closure: code and environment. -pub static fn_field_code: uint = 0u; -pub static fn_field_box: uint = 1u; +pub const fn_field_code: uint = 0u; +pub const fn_field_box: uint = 1u; // The two fields of a trait object/trait instance: vtable and box. // The vtable contains the type descriptor as first element. -pub static trt_field_box: uint = 0u; -pub static trt_field_vtable: uint = 1u; +pub const trt_field_box: uint = 0u; +pub const trt_field_vtable: uint = 1u; -pub static slice_elt_base: uint = 0u; -pub static slice_elt_len: uint = 1u; +pub const slice_elt_base: uint = 0u; +pub const slice_elt_len: uint = 1u; diff --git a/src/librustc_llvm/lib.rs b/src/librustc_llvm/lib.rs index ad2b6891dc99e..aa6023326d6c1 100644 --- a/src/librustc_llvm/lib.rs +++ b/src/librustc_llvm/lib.rs @@ -43,8 +43,8 @@ pub mod diagnostic; pub type Opcode = u32; pub type Bool = c_uint; -pub static True: Bool = 1 as Bool; -pub static False: Bool = 0 as Bool; +pub const True: Bool = 1 as Bool; +pub const False: Bool = 0 as Bool; // Consts for the LLVM CallConv type, pre-cast to uint. @@ -93,32 +93,32 @@ pub enum DiagnosticSeverity { bitflags! { flags Attribute : u32 { - static ZExtAttribute = 1 << 0, - static SExtAttribute = 1 << 1, - static NoReturnAttribute = 1 << 2, - static InRegAttribute = 1 << 3, - static StructRetAttribute = 1 << 4, - static NoUnwindAttribute = 1 << 5, - static NoAliasAttribute = 1 << 6, - static ByValAttribute = 1 << 7, - static NestAttribute = 1 << 8, - static ReadNoneAttribute = 1 << 9, - static ReadOnlyAttribute = 1 << 10, - static NoInlineAttribute = 1 << 11, - static AlwaysInlineAttribute = 1 << 12, - static OptimizeForSizeAttribute = 1 << 13, - static StackProtectAttribute = 1 << 14, - static StackProtectReqAttribute = 1 << 15, - static AlignmentAttribute = 31 << 16, - static NoCaptureAttribute = 1 << 21, - static NoRedZoneAttribute = 1 << 22, - static NoImplicitFloatAttribute = 1 << 23, - static NakedAttribute = 1 << 24, - static InlineHintAttribute = 1 << 25, - static StackAttribute = 7 << 26, - static ReturnsTwiceAttribute = 1 << 29, - static UWTableAttribute = 1 << 30, - static NonLazyBindAttribute = 1 << 31, + const ZExtAttribute = 1 << 0, + const SExtAttribute = 1 << 1, + const NoReturnAttribute = 1 << 2, + const InRegAttribute = 1 << 3, + const StructRetAttribute = 1 << 4, + const NoUnwindAttribute = 1 << 5, + const NoAliasAttribute = 1 << 6, + const ByValAttribute = 1 << 7, + const NestAttribute = 1 << 8, + const ReadNoneAttribute = 1 << 9, + const ReadOnlyAttribute = 1 << 10, + const NoInlineAttribute = 1 << 11, + const AlwaysInlineAttribute = 1 << 12, + const OptimizeForSizeAttribute = 1 << 13, + const StackProtectAttribute = 1 << 14, + const StackProtectReqAttribute = 1 << 15, + const AlignmentAttribute = 31 << 16, + const NoCaptureAttribute = 1 << 21, + const NoRedZoneAttribute = 1 << 22, + const NoImplicitFloatAttribute = 1 << 23, + const NakedAttribute = 1 << 24, + const InlineHintAttribute = 1 << 25, + const StackAttribute = 7 << 26, + const ReturnsTwiceAttribute = 1 << 29, + const UWTableAttribute = 1 << 30, + const NonLazyBindAttribute = 1 << 31, } } From 1bfe450a5ed0396c23185fc739d77ac9f79efe15 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 6 Oct 2014 17:41:03 -0700 Subject: [PATCH 19/24] num: Convert statics to constants --- src/libnum/bigint.rs | 6 +++--- src/libnum/complex.rs | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/libnum/bigint.rs b/src/libnum/bigint.rs index af2ff747fe968..e52d62a040be8 100644 --- a/src/libnum/bigint.rs +++ b/src/libnum/bigint.rs @@ -77,7 +77,7 @@ pub type BigDigit = u32; /// size is the double of the size of `BigDigit`. pub type DoubleBigDigit = u64; -pub static ZERO_BIG_DIGIT: BigDigit = 0; +pub const ZERO_BIG_DIGIT: BigDigit = 0; static ZERO_VEC: [BigDigit, ..1] = [ZERO_BIG_DIGIT]; #[allow(non_snake_case)] @@ -87,10 +87,10 @@ pub mod BigDigit { // `DoubleBigDigit` size dependent #[allow(non_uppercase_statics)] - pub static bits: uint = 32; + pub const bits: uint = 32; #[allow(non_uppercase_statics)] - pub static base: DoubleBigDigit = 1 << bits; + pub const base: DoubleBigDigit = 1 << bits; #[allow(non_uppercase_statics)] static lo_mask: DoubleBigDigit = (-1 as DoubleBigDigit) >> bits; diff --git a/src/libnum/complex.rs b/src/libnum/complex.rs index 0e70527cdca79..6690b1d5ddc7a 100644 --- a/src/libnum/complex.rs +++ b/src/libnum/complex.rs @@ -194,13 +194,13 @@ mod test { use std::num::{Zero, One, Float}; use std::hash::hash; - pub static _0_0i : Complex64 = Complex { re: 0.0, im: 0.0 }; - pub static _1_0i : Complex64 = Complex { re: 1.0, im: 0.0 }; - pub static _1_1i : Complex64 = Complex { re: 1.0, im: 1.0 }; - pub static _0_1i : Complex64 = Complex { re: 0.0, im: 1.0 }; - pub static _neg1_1i : Complex64 = Complex { re: -1.0, im: 1.0 }; - pub static _05_05i : Complex64 = Complex { re: 0.5, im: 0.5 }; - pub static all_consts : [Complex64, .. 5] = [_0_0i, _1_0i, _1_1i, _neg1_1i, _05_05i]; + pub const _0_0i : Complex64 = Complex { re: 0.0, im: 0.0 }; + pub const _1_0i : Complex64 = Complex { re: 1.0, im: 0.0 }; + pub const _1_1i : Complex64 = Complex { re: 1.0, im: 1.0 }; + pub const _0_1i : Complex64 = Complex { re: 0.0, im: 1.0 }; + pub const _neg1_1i : Complex64 = Complex { re: -1.0, im: 1.0 }; + pub const _05_05i : Complex64 = Complex { re: 0.5, im: 0.5 }; + pub const all_consts : [Complex64, .. 5] = [_0_0i, _1_0i, _1_1i, _neg1_1i, _05_05i]; #[test] fn test_consts() { From 01d58fe2cbad0872f92571960ca3d8a5b01d0784 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 6 Oct 2014 17:41:15 -0700 Subject: [PATCH 20/24] rustdoc: Implement constant documentation At the same time, migrate statics to constants. --- src/librustdoc/clean/mod.rs | 25 ++++++++++++++ src/librustdoc/doctree.rs | 13 ++++++++ src/librustdoc/flock.rs | 32 +++++++++--------- src/librustdoc/html/item_type.rs | 3 ++ src/librustdoc/html/markdown.rs | 20 +++++------ src/librustdoc/html/render.rs | 53 ++++++++++++++++++++---------- src/librustdoc/html/static/main.js | 4 ++- src/librustdoc/passes.rs | 3 +- src/librustdoc/visit_ast.rs | 13 ++++++++ 9 files changed, 120 insertions(+), 46 deletions(-) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 5c78bb976f1e3..7e9bb2844a7c7 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -300,6 +300,7 @@ pub enum ItemEnum { ModuleItem(Module), TypedefItem(Typedef), StaticItem(Static), + ConstantItem(Constant), TraitItem(Trait), ImplItem(Impl), /// `use` and `extern crate` @@ -347,6 +348,7 @@ impl Clean for doctree::Module { self.mods.clean(cx), self.typedefs.clean(cx), self.statics.clean(cx), + self.constants.clean(cx), self.traits.clean(cx), self.impls.clean(cx), self.view_items.clean(cx).into_iter() @@ -1741,6 +1743,29 @@ impl Clean for doctree::Static { } } +#[deriving(Clone, Encodable, Decodable)] +pub struct Constant { + pub type_: Type, + pub expr: String, +} + +impl Clean for doctree::Constant { + fn clean(&self, cx: &DocContext) -> Item { + Item { + name: Some(self.name.clean(cx)), + attrs: self.attrs.clean(cx), + source: self.whence.clean(cx), + def_id: ast_util::local_def(self.id), + visibility: self.vis.clean(cx), + stability: self.stab.clean(cx), + inner: ConstantItem(Constant { + type_: self.type_.clean(cx), + expr: self.expr.span.to_src(cx), + }), + } + } +} + #[deriving(Show, Clone, Encodable, Decodable, PartialEq)] pub enum Mutability { Mutable, diff --git a/src/librustdoc/doctree.rs b/src/librustdoc/doctree.rs index 72964609049bf..b173f0f16e30d 100644 --- a/src/librustdoc/doctree.rs +++ b/src/librustdoc/doctree.rs @@ -30,6 +30,7 @@ pub struct Module { pub id: NodeId, pub typedefs: Vec, pub statics: Vec, + pub constants: Vec, pub traits: Vec, pub vis: ast::Visibility, pub stab: Option, @@ -56,6 +57,7 @@ impl Module { mods : Vec::new(), typedefs : Vec::new(), statics : Vec::new(), + constants : Vec::new(), traits : Vec::new(), impls : Vec::new(), view_items : Vec::new(), @@ -151,6 +153,17 @@ pub struct Static { pub whence: Span, } +pub struct Constant { + pub type_: P, + pub expr: P, + pub name: Ident, + pub attrs: Vec, + pub vis: ast::Visibility, + pub stab: Option, + pub id: ast::NodeId, + pub whence: Span, +} + pub struct Trait { pub name: Ident, pub items: Vec, //should be TraitItem diff --git a/src/librustdoc/flock.rs b/src/librustdoc/flock.rs index d1cc37497dc44..ef921a84cfb8e 100644 --- a/src/librustdoc/flock.rs +++ b/src/librustdoc/flock.rs @@ -38,10 +38,10 @@ mod imp { pub l_sysid: libc::c_int, } - pub static F_WRLCK: libc::c_short = 1; - pub static F_UNLCK: libc::c_short = 2; - pub static F_SETLK: libc::c_int = 6; - pub static F_SETLKW: libc::c_int = 7; + pub const F_WRLCK: libc::c_short = 1; + pub const F_UNLCK: libc::c_short = 2; + pub const F_SETLK: libc::c_int = 6; + pub const F_SETLKW: libc::c_int = 7; } #[cfg(target_os = "freebsd")] @@ -57,10 +57,10 @@ mod imp { pub l_sysid: libc::c_int, } - pub static F_UNLCK: libc::c_short = 2; - pub static F_WRLCK: libc::c_short = 3; - pub static F_SETLK: libc::c_int = 12; - pub static F_SETLKW: libc::c_int = 13; + pub const F_UNLCK: libc::c_short = 2; + pub const F_WRLCK: libc::c_short = 3; + pub const F_SETLK: libc::c_int = 12; + pub const F_SETLKW: libc::c_int = 13; } #[cfg(target_os = "dragonfly")] @@ -78,10 +78,10 @@ mod imp { pub l_sysid: libc::c_int, } - pub static F_UNLCK: libc::c_short = 2; - pub static F_WRLCK: libc::c_short = 3; - pub static F_SETLK: libc::c_int = 8; - pub static F_SETLKW: libc::c_int = 9; + pub const F_UNLCK: libc::c_short = 2; + pub const F_WRLCK: libc::c_short = 3; + pub const F_SETLK: libc::c_int = 8; + pub const F_SETLKW: libc::c_int = 9; } #[cfg(any(target_os = "macos", target_os = "ios"))] @@ -99,10 +99,10 @@ mod imp { pub l_sysid: libc::c_int, } - pub static F_UNLCK: libc::c_short = 2; - pub static F_WRLCK: libc::c_short = 3; - pub static F_SETLK: libc::c_int = 8; - pub static F_SETLKW: libc::c_int = 9; + pub const F_UNLCK: libc::c_short = 2; + pub const F_WRLCK: libc::c_short = 3; + pub const F_SETLK: libc::c_int = 8; + pub const F_SETLKW: libc::c_int = 9; } pub struct Lock { diff --git a/src/librustdoc/html/item_type.rs b/src/librustdoc/html/item_type.rs index e18ab0bd14f59..0b35f8ddc6963 100644 --- a/src/librustdoc/html/item_type.rs +++ b/src/librustdoc/html/item_type.rs @@ -39,6 +39,7 @@ pub enum ItemType { Macro = 15, Primitive = 16, AssociatedType = 17, + Constant = 18, } impl ItemType { @@ -62,6 +63,7 @@ impl ItemType { Macro => "macro", Primitive => "primitive", AssociatedType => "associatedtype", + Constant => "constant", } } } @@ -86,6 +88,7 @@ pub fn shortty(item: &clean::Item) -> ItemType { clean::FunctionItem(..) => Function, clean::TypedefItem(..) => Typedef, clean::StaticItem(..) => Static, + clean::ConstantItem(..) => Constant, clean::TraitItem(..) => Trait, clean::ImplItem(..) => Impl, clean::ViewItemItem(..) => ViewItem, diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index faf361f029059..a5c6f79ef6b17 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -48,16 +48,16 @@ pub struct Markdown<'a>(pub &'a str); /// table of contents. pub struct MarkdownWithToc<'a>(pub &'a str); -static DEF_OUNIT: libc::size_t = 64; -static HOEDOWN_EXT_NO_INTRA_EMPHASIS: libc::c_uint = 1 << 10; -static HOEDOWN_EXT_TABLES: libc::c_uint = 1 << 0; -static HOEDOWN_EXT_FENCED_CODE: libc::c_uint = 1 << 1; -static HOEDOWN_EXT_AUTOLINK: libc::c_uint = 1 << 3; -static HOEDOWN_EXT_STRIKETHROUGH: libc::c_uint = 1 << 4; -static HOEDOWN_EXT_SUPERSCRIPT: libc::c_uint = 1 << 8; -static HOEDOWN_EXT_FOOTNOTES: libc::c_uint = 1 << 2; - -static HOEDOWN_EXTENSIONS: libc::c_uint = +const DEF_OUNIT: libc::size_t = 64; +const HOEDOWN_EXT_NO_INTRA_EMPHASIS: libc::c_uint = 1 << 10; +const HOEDOWN_EXT_TABLES: libc::c_uint = 1 << 0; +const HOEDOWN_EXT_FENCED_CODE: libc::c_uint = 1 << 1; +const HOEDOWN_EXT_AUTOLINK: libc::c_uint = 1 << 3; +const HOEDOWN_EXT_STRIKETHROUGH: libc::c_uint = 1 << 4; +const HOEDOWN_EXT_SUPERSCRIPT: libc::c_uint = 1 << 8; +const HOEDOWN_EXT_FOOTNOTES: libc::c_uint = 1 << 2; + +const HOEDOWN_EXTENSIONS: libc::c_uint = HOEDOWN_EXT_NO_INTRA_EMPHASIS | HOEDOWN_EXT_TABLES | HOEDOWN_EXT_FENCED_CODE | HOEDOWN_EXT_AUTOLINK | HOEDOWN_EXT_STRIKETHROUGH | HOEDOWN_EXT_SUPERSCRIPT | diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index e9d65b0a40cf2..497bbd3a1cd6b 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1471,6 +1471,8 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context, (_, &clean::StructItem(..)) => Greater, (&clean::EnumItem(..), _) => Less, (_, &clean::EnumItem(..)) => Greater, + (&clean::ConstantItem(..), _) => Less, + (_, &clean::ConstantItem(..)) => Greater, (&clean::StaticItem(..), _) => Less, (_, &clean::StaticItem(..)) => Greater, (&clean::ForeignFunctionItem(..), _) => Less, @@ -1507,6 +1509,7 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context, clean::FunctionItem(..) => ("functions", "Functions"), clean::TypedefItem(..) => ("types", "Type Definitions"), clean::StaticItem(..) => ("statics", "Statics"), + clean::ConstantItem(..) => ("constants", "Constants"), clean::TraitItem(..) => ("traits", "Traits"), clean::ImplItem(..) => ("impls", "Implementations"), clean::ViewItemItem(..) => ("reexports", "Reexports"), @@ -1526,28 +1529,28 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context, id = short, name = name)); } - match myitem.inner { - clean::StaticItem(ref s) | clean::ForeignStaticItem(ref s) => { - struct Initializer<'a>(&'a str, Item<'a>); - impl<'a> fmt::Show for Initializer<'a> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let Initializer(s, item) = *self; - if s.len() == 0 { return Ok(()); } - try!(write!(f, " = ")); - if s.contains("\n") { - match item.href() { - Some(url) => { - write!(f, "[definition]", - url) - } - None => Ok(()), - } - } else { - write!(f, "{}", s.as_slice()) + struct Initializer<'a>(&'a str, Item<'a>); + impl<'a> fmt::Show for Initializer<'a> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let Initializer(s, item) = *self; + if s.len() == 0 { return Ok(()); } + try!(write!(f, " = ")); + if s.contains("\n") { + match item.href() { + Some(url) => { + write!(f, "[definition]", + url) } + None => Ok(()), } + } else { + write!(f, "{}", s.as_slice()) } + } + } + match myitem.inner { + clean::StaticItem(ref s) | clean::ForeignStaticItem(ref s) => { try!(write!(w, " {}{}static {}{}: {}{} @@ -1562,6 +1565,20 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context, Initializer(s.expr.as_slice(), Item { cx: cx, item: myitem }), Markdown(blank(myitem.doc_value())))); } + clean::ConstantItem(ref s) => { + try!(write!(w, " + + {}{}const {}: {}{} + {}  + + ", + ConciseStability(&myitem.stability), + VisSpace(myitem.visibility), + *myitem.name.get_ref(), + s.type_, + Initializer(s.expr.as_slice(), Item { cx: cx, item: myitem }), + Markdown(blank(myitem.doc_value())))); + } clean::ViewItemItem(ref item) => { match item.inner { diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 6992a96659295..7c6f7ed3fe230 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -569,7 +569,9 @@ "ffi", "ffs", "macro", - "primitive"]; + "primitive", + "associatedtype", + "constant"]; function itemTypeFromName(typename) { for (var i = 0; i < itemTypes.length; ++i) { diff --git a/src/librustdoc/passes.rs b/src/librustdoc/passes.rs index 3c66a7c785094..1a9dd226f87df 100644 --- a/src/librustdoc/passes.rs +++ b/src/librustdoc/passes.rs @@ -134,7 +134,8 @@ impl<'a> fold::DocFolder for Stripper<'a> { clean::StructItem(..) | clean::EnumItem(..) | clean::TraitItem(..) | clean::FunctionItem(..) | clean::VariantItem(..) | clean::MethodItem(..) | - clean::ForeignFunctionItem(..) | clean::ForeignStaticItem(..) => { + clean::ForeignFunctionItem(..) | clean::ForeignStaticItem(..) | + clean::ConstantItem(..) => { if ast_util::is_local(i.def_id) && !self.exported_items.contains(&i.def_id.node) { return None; diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index d4a1a35790936..6456f4acd30c3 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -308,6 +308,19 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { }; om.statics.push(s); }, + ast::ItemConst(ref ty, ref exp) => { + let s = Constant { + type_: ty.clone(), + expr: exp.clone(), + id: item.id, + name: name, + attrs: item.attrs.clone(), + whence: item.span, + vis: item.vis, + stab: self.stability(item.id), + }; + om.constants.push(s); + }, ast::ItemTrait(ref gen, _, ref b, ref items) => { let t = Trait { name: name, From 9c09c9434764127f857a9599b93dc090ac63cc2b Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 6 Oct 2014 19:15:08 -0700 Subject: [PATCH 21/24] syntax: Tweak the return value of bytes!() Instead of returning &'static [u8], an invocation of `bytes!()` now returns `&'static [u8, ..N]` where `N` is the length of the byte vector. This should functionally be the same, but there are some cases where an explicit cast may be needed, so this is a: [breaking-change] --- src/libsyntax/ext/bytes.rs | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/libsyntax/ext/bytes.rs b/src/libsyntax/ext/bytes.rs index 3c9e40d850bac..a93295815e0ed 100644 --- a/src/libsyntax/ext/bytes.rs +++ b/src/libsyntax/ext/bytes.rs @@ -104,19 +104,14 @@ pub fn expand_syntax_ext<'cx>(cx: &'cx mut ExtCtxt, return DummyResult::expr(sp); } - let e = cx.expr_vec_slice(sp, bytes); - let ty = cx.ty(sp, ast::TyVec(cx.ty_ident(sp, cx.ident_of("u8")))); - let lifetime = cx.lifetime(sp, cx.ident_of("'static").name); - let item = cx.item_static(sp, - cx.ident_of("BYTES"), - cx.ty_rptr(sp, - ty, - Some(lifetime), - ast::MutImmutable), - ast::MutImmutable, - e); - let e = cx.expr_block(cx.block(sp, - vec!(cx.stmt_item(sp, item)), - Some(cx.expr_ident(sp, cx.ident_of("BYTES"))))); + let len = bytes.len(); + let e = cx.expr_vec(sp, bytes); + let ty = cx.ty(sp, ast::TyFixedLengthVec(cx.ty_ident(sp, cx.ident_of("u8")), + cx.expr_uint(sp, len))); + let item = cx.item_static(sp, cx.ident_of("BYTES"), ty, ast::MutImmutable, e); + let ret = cx.expr_ident(sp, cx.ident_of("BYTES")); + let ret = cx.expr_addr_of(sp, ret); + let e = cx.expr_block(cx.block(sp, vec![cx.stmt_item(sp, item)], + Some(ret))); MacExpr::new(e) } From d03a4b0046a27968fc4eeaf1847776b90a48264b Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 6 Oct 2014 21:16:35 -0700 Subject: [PATCH 22/24] test: Convert statics to constants Additionally, add lots of tests for new functionality around statics and `static mut`. --- src/test/auxiliary/cci_const.rs | 6 +- src/test/auxiliary/iss.rs | 2 +- src/test/auxiliary/issue-13620-1.rs | 2 +- .../auxiliary/issue-17718-const-privacy.rs | 18 ++++ src/test/auxiliary/issue-17718.rs | 22 +++++ src/test/auxiliary/issue13213aux.rs | 2 +- src/test/bench/shootout-fasta-redux.rs | 16 ++-- src/test/bench/shootout-fasta.rs | 4 +- src/test/bench/shootout-mandelbrot.rs | 8 +- src/test/bench/shootout-nbody.rs | 8 +- .../check-static-immutable-mut-slices.rs | 2 +- .../check-static-values-constraints.rs | 50 ++++++----- src/test/compile-fail/issue-15524.rs | 2 +- src/test/compile-fail/issue-16149.rs | 2 +- .../issue-17718-borrow-interior.rs | 24 ++++++ .../issue-17718-const-bad-values.rs | 20 +++++ .../compile-fail/issue-17718-const-borrow.rs | 24 ++++++ .../issue-17718-const-destructors.rs | 2 +- .../compile-fail/issue-17718-const-naming.rs | 16 ++++ .../compile-fail/issue-17718-const-privacy.rs | 26 ++++++ .../issue-17718-constants-not-static.rs | 17 ++++ .../compile-fail/issue-17718-extern-const.rs | 15 ++++ src/test/compile-fail/issue-17718-patterns.rs | 22 +++++ .../compile-fail/issue-17718-recursive.rs | 14 ++++ .../compile-fail/issue-17718-references.rs | 33 ++++++++ .../compile-fail/issue-17718-static-move.rs | 19 +++++ .../compile-fail/issue-17718-static-sync.rs | 19 +++++ src/test/compile-fail/issue-4968.rs | 2 +- src/test/compile-fail/issue-7364.rs | 3 +- src/test/compile-fail/issue-9243.rs | 2 +- src/test/compile-fail/lint-dead-code-1.rs | 16 ++-- src/test/compile-fail/match-arm-statics.rs | 10 +-- .../compile-fail/match-static-const-lc.rs | 6 +- .../compile-fail/static-mut-not-constant.rs | 3 +- src/test/compile-fail/static-mut-not-pat.rs | 6 +- .../compile-fail/std-uncopyable-atomics.rs | 6 +- src/test/pretty/issue-4264.pp | 2 +- src/test/pretty/issue-4264.rs | 2 +- src/test/run-make/sepcomp-cci-copies/Makefile | 1 - .../run-make/sepcomp-cci-copies/cci_lib.rs | 3 - src/test/run-make/sepcomp-cci-copies/foo.rs | 7 +- src/test/run-pass/bytes-macro-static.rs | 2 +- src/test/run-pass/cast-in-array-size.rs | 2 +- src/test/run-pass/check-static-slice.rs | 12 +-- src/test/run-pass/const-cast.rs | 4 +- src/test/run-pass/const-const.rs | 4 +- src/test/run-pass/const-deref.rs | 2 +- src/test/run-pass/const-enum-vec-index.rs | 4 +- .../const-expr-in-fixed-length-vec.rs | 2 +- src/test/run-pass/const-expr-in-vec-repeat.rs | 2 +- .../run-pass/const-fields-and-indexing.rs | 8 +- .../run-pass/const-region-ptrs-noncopy.rs | 4 +- src/test/run-pass/const-region-ptrs.rs | 4 +- src/test/run-pass/const-str-ptr.rs | 6 +- src/test/run-pass/const-struct.rs | 8 +- src/test/run-pass/consts-in-patterns.rs | 4 +- src/test/run-pass/enum-vec-initializer.rs | 6 +- src/test/run-pass/issue-11940.rs | 2 +- src/test/run-pass/issue-13763.rs | 2 +- src/test/run-pass/issue-17074.rs | 6 +- .../issue-17718-static-unsafe-interior.rs} | 10 +-- src/test/run-pass/issue-17718.rs | 83 +++++++++++++++++++ src/test/run-pass/issue-2428.rs | 2 +- src/test/run-pass/issue-5353.rs | 4 +- src/test/run-pass/issue-7222.rs | 2 +- src/test/run-pass/issue-9942.rs | 2 +- src/test/run-pass/match-arm-statics.rs | 32 +++---- src/test/run-pass/match-range-static.rs | 4 +- .../run-pass/match-static-const-rename.rs | 4 +- src/test/run-pass/resolve-issue-2428.rs | 2 +- src/test/run-pass/sepcomp-statics.rs | 4 +- src/test/run-pass/syntax-extension-bytes.rs | 6 +- src/test/run-pass/vector-sort-failure-safe.rs | 2 +- src/test/run-pass/xcrate-unit-struct.rs | 2 +- 74 files changed, 535 insertions(+), 172 deletions(-) create mode 100644 src/test/auxiliary/issue-17718-const-privacy.rs create mode 100644 src/test/auxiliary/issue-17718.rs create mode 100644 src/test/compile-fail/issue-17718-borrow-interior.rs create mode 100644 src/test/compile-fail/issue-17718-const-bad-values.rs create mode 100644 src/test/compile-fail/issue-17718-const-borrow.rs create mode 100644 src/test/compile-fail/issue-17718-const-naming.rs create mode 100644 src/test/compile-fail/issue-17718-const-privacy.rs create mode 100644 src/test/compile-fail/issue-17718-constants-not-static.rs create mode 100644 src/test/compile-fail/issue-17718-extern-const.rs create mode 100644 src/test/compile-fail/issue-17718-patterns.rs create mode 100644 src/test/compile-fail/issue-17718-recursive.rs create mode 100644 src/test/compile-fail/issue-17718-references.rs create mode 100644 src/test/compile-fail/issue-17718-static-move.rs create mode 100644 src/test/compile-fail/issue-17718-static-sync.rs rename src/test/{compile-fail/borrowck-forbid-static-unsafe-interior.rs => run-pass/issue-17718-static-unsafe-interior.rs} (69%) create mode 100644 src/test/run-pass/issue-17718.rs diff --git a/src/test/auxiliary/cci_const.rs b/src/test/auxiliary/cci_const.rs index 17029b9d3778a..945004ede6de8 100644 --- a/src/test/auxiliary/cci_const.rs +++ b/src/test/auxiliary/cci_const.rs @@ -11,6 +11,6 @@ pub extern fn bar() { } -pub static foopy: &'static str = "hi there"; -pub static uint_val: uint = 12; -pub static uint_expr: uint = (1 << uint_val) - 1; +pub const foopy: &'static str = "hi there"; +pub const uint_val: uint = 12; +pub const uint_expr: uint = (1 << uint_val) - 1; diff --git a/src/test/auxiliary/iss.rs b/src/test/auxiliary/iss.rs index 75728c075d1eb..3a9d76406e10a 100644 --- a/src/test/auxiliary/iss.rs +++ b/src/test/auxiliary/iss.rs @@ -17,7 +17,7 @@ pub struct C<'a> { } fn no_op() { } -pub static D : C<'static> = C { +pub const D : C<'static> = C { k: no_op }; diff --git a/src/test/auxiliary/issue-13620-1.rs b/src/test/auxiliary/issue-13620-1.rs index ddd1012017f78..e373421fabfac 100644 --- a/src/test/auxiliary/issue-13620-1.rs +++ b/src/test/auxiliary/issue-13620-1.rs @@ -14,6 +14,6 @@ pub struct Foo { extern fn the_foo() {} -pub static FOO: Foo = Foo { +pub const FOO: Foo = Foo { foo: the_foo }; diff --git a/src/test/auxiliary/issue-17718-const-privacy.rs b/src/test/auxiliary/issue-17718-const-privacy.rs new file mode 100644 index 0000000000000..3657d39ff77e4 --- /dev/null +++ b/src/test/auxiliary/issue-17718-const-privacy.rs @@ -0,0 +1,18 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +pub use foo::FOO2; + +pub const FOO: uint = 3; +const BAR: uint = 3; + +mod foo { + pub const FOO2: uint = 3; +} diff --git a/src/test/auxiliary/issue-17718.rs b/src/test/auxiliary/issue-17718.rs new file mode 100644 index 0000000000000..f0b431b1db932 --- /dev/null +++ b/src/test/auxiliary/issue-17718.rs @@ -0,0 +1,22 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use std::sync::atomic; + +pub const C1: uint = 1; +pub const C2: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT; +pub const C3: fn() = foo; +pub const C4: uint = C1 * C1 + C1 / C1; +pub const C5: &'static uint = &C4; + +pub static S1: uint = 3; +pub static S2: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT; + +fn foo() {} diff --git a/src/test/auxiliary/issue13213aux.rs b/src/test/auxiliary/issue13213aux.rs index ad8c823b99179..5bd52ef501068 100644 --- a/src/test/auxiliary/issue13213aux.rs +++ b/src/test/auxiliary/issue13213aux.rs @@ -21,7 +21,7 @@ mod private { pub struct P { p: i32, } - pub static THREE: P = P { p: 3 }; + pub const THREE: P = P { p: 3 }; } pub static A: S = S { p: private::THREE }; diff --git a/src/test/bench/shootout-fasta-redux.rs b/src/test/bench/shootout-fasta-redux.rs index b8af76ce17cec..e151369ff38ac 100644 --- a/src/test/bench/shootout-fasta-redux.rs +++ b/src/test/bench/shootout-fasta-redux.rs @@ -45,16 +45,16 @@ use std::io::{stdout, IoResult}; use std::os; use std::slice::bytes::copy_memory; -static LINE_LEN: uint = 60; -static LOOKUP_SIZE: uint = 4 * 1024; -static LOOKUP_SCALE: f32 = (LOOKUP_SIZE - 1) as f32; +const LINE_LEN: uint = 60; +const LOOKUP_SIZE: uint = 4 * 1024; +const LOOKUP_SCALE: f32 = (LOOKUP_SIZE - 1) as f32; // Random number generator constants -static IM: u32 = 139968; -static IA: u32 = 3877; -static IC: u32 = 29573; +const IM: u32 = 139968; +const IA: u32 = 3877; +const IC: u32 = 29573; -static ALU: &'static str = "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTG\ +const ALU: &'static str = "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTG\ GGAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGA\ GACCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAA\ AATACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAAT\ @@ -62,7 +62,7 @@ static ALU: &'static str = "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTG\ CCGGGAGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTG\ CACTCCAGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA"; -static NULL_AMINO_ACID: AminoAcid = AminoAcid { c: ' ' as u8, p: 0.0 }; +const NULL_AMINO_ACID: AminoAcid = AminoAcid { c: ' ' as u8, p: 0.0 }; static IUB: [AminoAcid, ..15] = [ AminoAcid { c: 'a' as u8, p: 0.27 }, diff --git a/src/test/bench/shootout-fasta.rs b/src/test/bench/shootout-fasta.rs index 7565525bc8cc0..77311edba4e7a 100644 --- a/src/test/bench/shootout-fasta.rs +++ b/src/test/bench/shootout-fasta.rs @@ -45,8 +45,8 @@ use std::io::{BufferedWriter, File}; use std::cmp::min; use std::os; -static LINE_LENGTH: uint = 60; -static IM: u32 = 139968; +const LINE_LENGTH: uint = 60; +const IM: u32 = 139968; struct MyRandom { last: u32 diff --git a/src/test/bench/shootout-mandelbrot.rs b/src/test/bench/shootout-mandelbrot.rs index 28db9ed14a77b..66fe52d9ec7ed 100644 --- a/src/test/bench/shootout-mandelbrot.rs +++ b/src/test/bench/shootout-mandelbrot.rs @@ -49,9 +49,9 @@ use std::os; use std::simd::f64x2; use std::sync::{Arc, Future}; -static ITER: int = 50; -static LIMIT: f64 = 2.0; -static WORKERS: uint = 16; +const ITER: int = 50; +const LIMIT: f64 = 2.0; +const WORKERS: uint = 16; #[inline(always)] fn mandelbrot(w: uint, mut out: W) -> io::IoResult<()> { @@ -144,7 +144,7 @@ fn mandelbrot(w: uint, mut out: W) -> io::IoResult<()> { fn write_line(init_i: f64, vec_init_r: &[f64], res: &mut Vec) { let v_init_i : f64x2 = f64x2(init_i, init_i); let v_2 : f64x2 = f64x2(2.0, 2.0); - static LIMIT_SQUARED: f64 = LIMIT * LIMIT; + const LIMIT_SQUARED: f64 = LIMIT * LIMIT; for chunk_init_r in vec_init_r.chunks(8) { let mut cur_byte = 0xff; diff --git a/src/test/bench/shootout-nbody.rs b/src/test/bench/shootout-nbody.rs index 6a39d2fdbb1a3..a945e0f7796d1 100644 --- a/src/test/bench/shootout-nbody.rs +++ b/src/test/bench/shootout-nbody.rs @@ -38,10 +38,10 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED // OF THE POSSIBILITY OF SUCH DAMAGE. -static PI: f64 = 3.141592653589793; -static SOLAR_MASS: f64 = 4.0 * PI * PI; -static YEAR: f64 = 365.24; -static N_BODIES: uint = 5; +const PI: f64 = 3.141592653589793; +const SOLAR_MASS: f64 = 4.0 * PI * PI; +const YEAR: f64 = 365.24; +const N_BODIES: uint = 5; static BODIES: [Planet, ..N_BODIES] = [ // Sun diff --git a/src/test/compile-fail/check-static-immutable-mut-slices.rs b/src/test/compile-fail/check-static-immutable-mut-slices.rs index 73ce488cbc669..2945a05024792 100644 --- a/src/test/compile-fail/check-static-immutable-mut-slices.rs +++ b/src/test/compile-fail/check-static-immutable-mut-slices.rs @@ -11,6 +11,6 @@ // Checks that immutable static items can't have mutable slices static TEST: &'static mut [int] = &mut []; -//~^ ERROR static items are not allowed to have mutable slices +//~^ ERROR statics are not allowed to have mutable references pub fn main() { } diff --git a/src/test/compile-fail/check-static-values-constraints.rs b/src/test/compile-fail/check-static-values-constraints.rs index e29be22ca9acc..d23aa317247c0 100644 --- a/src/test/compile-fail/check-static-values-constraints.rs +++ b/src/test/compile-fail/check-static-values-constraints.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// Verifies all possible restrictions for static items values. +// Verifies all possible restrictions for statics values. use std::kinds::marker; @@ -21,7 +21,7 @@ impl Drop for WithDtor { // This enum will be used to test the following rules: // 1. Variants are safe for static // 2. Expr calls are allowed as long as they arguments are safe -// 3. Expr calls with unsafe arguments for static items are rejected +// 3. Expr calls with unsafe arguments for statics are rejected enum SafeEnum { Variant1, Variant2(int), @@ -35,7 +35,7 @@ static STATIC2: SafeEnum = Variant2(0); // This one should fail static STATIC3: SafeEnum = Variant3(WithDtor); -//~^ ERROR static items are not allowed to have destructors +//~^ ERROR statics are not allowed to have destructors // This enum will be used to test that variants @@ -52,9 +52,9 @@ impl Drop for UnsafeEnum { static STATIC4: UnsafeEnum = Variant5; -//~^ ERROR static items are not allowed to have destructors +//~^ ERROR statics are not allowed to have destructors static STATIC5: UnsafeEnum = Variant6(0); -//~^ ERROR static items are not allowed to have destructors +//~^ ERROR statics are not allowed to have destructors struct SafeStruct { @@ -68,7 +68,7 @@ static STATIC6: SafeStruct = SafeStruct{field1: Variant1, field2: Variant2(0)}; // field2 has an unsafe value, hence this should fail static STATIC7: SafeStruct = SafeStruct{field1: Variant1, field2: Variant3(WithDtor)}; -//~^ ERROR static items are not allowed to have destructors +//~^ ERROR statics are not allowed to have destructors // Test variadic constructor for structs. The base struct should be examined // as well as every field present in the constructor. @@ -79,7 +79,7 @@ static STATIC8: SafeStruct = SafeStruct{field1: Variant1, // This example should fail because field1 in the base struct is not safe static STATIC9: SafeStruct = SafeStruct{field1: Variant1, ..SafeStruct{field1: Variant3(WithDtor), field2: Variant1}}; -//~^ ERROR static items are not allowed to have destructors +//~^ ERROR statics are not allowed to have destructors struct UnsafeStruct; @@ -89,44 +89,48 @@ impl Drop for UnsafeStruct { // Types with destructors are not allowed for statics static STATIC10: UnsafeStruct = UnsafeStruct; -//~^ ERROR static items are not allowed to have destructor +//~^ ERROR statics are not allowed to have destructor struct MyOwned; static STATIC11: Box = box MyOwned; -//~^ ERROR static items are not allowed to have custom pointers +//~^ ERROR statics are not allowed to have custom pointers // The following examples test that mutable structs are just forbidden // to have types with destructors // These should fail static mut STATIC12: UnsafeStruct = UnsafeStruct; -//~^ ERROR mutable static items are not allowed to have destructors +//~^ ERROR mutable statics are not allowed to have destructors +//~^^ ERROR statics are not allowed to have destructors static mut STATIC13: SafeStruct = SafeStruct{field1: Variant1, field2: Variant3(WithDtor)}; -//~^ ERROR mutable static items are not allowed to have destructors +//~^ ERROR mutable statics are not allowed to have destructors +//~^^ ERROR: statics are not allowed to have destructors static mut STATIC14: SafeStruct = SafeStruct { -//~^ ERROR mutable static items are not allowed to have destructors +//~^ ERROR mutable statics are not allowed to have destructors field1: Variant1, field2: Variant4("str".to_string()) }; -static STATIC15: &'static [Box] = &[box MyOwned, box MyOwned]; -//~^ ERROR static items are not allowed to have custom pointers -//~^^ ERROR static items are not allowed to have custom pointers +static STATIC15: &'static [Box] = &[ + box MyOwned, //~ ERROR statics are not allowed to have custom pointers + box MyOwned, //~ ERROR statics are not allowed to have custom pointers +]; -static STATIC16: (&'static Box, &'static Box) = - (&box MyOwned, &box MyOwned); -//~^ ERROR static items are not allowed to have custom pointers -//~^^ ERROR static items are not allowed to have custom pointers +static STATIC16: (&'static Box, &'static Box) = ( + &box MyOwned, //~ ERROR statics are not allowed to have custom pointers + &box MyOwned, //~ ERROR statics are not allowed to have custom pointers +); static mut STATIC17: SafeEnum = Variant1; -//~^ ERROR mutable static items are not allowed to have destructors +//~^ ERROR mutable statics are not allowed to have destructors -static STATIC19: Box = box 3; -//~^ ERROR static items are not allowed to have custom pointers +static STATIC19: Box = + box 3; +//~^ ERROR statics are not allowed to have custom pointers pub fn main() { let y = { static x: Box = box 3; x }; - //~^ ERROR static items are not allowed to have custom pointers + //~^ ERROR statics are not allowed to have custom pointers } diff --git a/src/test/compile-fail/issue-15524.rs b/src/test/compile-fail/issue-15524.rs index 1e7bd6fc623a8..6d9657ab28912 100644 --- a/src/test/compile-fail/issue-15524.rs +++ b/src/test/compile-fail/issue-15524.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -static N: int = 1; +const N: int = 1; enum Foo { A = 1, diff --git a/src/test/compile-fail/issue-16149.rs b/src/test/compile-fail/issue-16149.rs index c52c53ec2e9ca..aa586e58f7084 100644 --- a/src/test/compile-fail/issue-16149.rs +++ b/src/test/compile-fail/issue-16149.rs @@ -15,7 +15,7 @@ extern { fn main() { let boolValue = match 42 { externalValue => true, - //~^ ERROR extern statics cannot be referenced in patterns + //~^ ERROR static variables cannot be referenced in a pattern _ => false }; } diff --git a/src/test/compile-fail/issue-17718-borrow-interior.rs b/src/test/compile-fail/issue-17718-borrow-interior.rs new file mode 100644 index 0000000000000..1f763dbdc9fa6 --- /dev/null +++ b/src/test/compile-fail/issue-17718-borrow-interior.rs @@ -0,0 +1,24 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +struct S { a: uint } +static A: S = S { a: 3 }; +static B: &'static uint = &A.a; +//~^ ERROR: cannot refer to the interior of another static +static C: &'static uint = &(A.a); +//~^ ERROR: cannot refer to the interior of another static + +static D: [uint, ..1] = [1]; +static E: uint = D[0]; +//~^ ERROR: cannot refer to other statics by value +static F: &'static uint = &D[0]; +//~^ ERROR: cannot refer to the interior of another static + +fn main() {} diff --git a/src/test/compile-fail/issue-17718-const-bad-values.rs b/src/test/compile-fail/issue-17718-const-bad-values.rs new file mode 100644 index 0000000000000..6425dbda5c6c9 --- /dev/null +++ b/src/test/compile-fail/issue-17718-const-bad-values.rs @@ -0,0 +1,20 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +const C1: &'static mut [uint] = &mut []; +//~^ ERROR: constants are not allowed to have mutable references + +static mut S: uint = 3; +const C2: &'static mut uint = &mut S; +//~^ ERROR: constants cannot refer to other statics +//~^^ ERROR: are not allowed to have mutable references + +fn main() {} + diff --git a/src/test/compile-fail/issue-17718-const-borrow.rs b/src/test/compile-fail/issue-17718-const-borrow.rs new file mode 100644 index 0000000000000..21cc9a757cf19 --- /dev/null +++ b/src/test/compile-fail/issue-17718-const-borrow.rs @@ -0,0 +1,24 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use std::cell::UnsafeCell; + +const A: UnsafeCell = UnsafeCell { value: 1 }; +const B: &'static UnsafeCell = &A; +//~^ ERROR: cannot borrow a constant which contains interior mutability + +struct C { a: UnsafeCell } +const D: C = C { a: UnsafeCell { value: 1 } }; +const E: &'static UnsafeCell = &D.a; +//~^ ERROR: cannot borrow a constant which contains interior mutability +const F: &'static C = &D; +//~^ ERROR: cannot borrow a constant which contains interior mutability + +fn main() {} diff --git a/src/test/compile-fail/issue-17718-const-destructors.rs b/src/test/compile-fail/issue-17718-const-destructors.rs index dffbfe155646a..e888f917741ab 100644 --- a/src/test/compile-fail/issue-17718-const-destructors.rs +++ b/src/test/compile-fail/issue-17718-const-destructors.rs @@ -14,6 +14,6 @@ impl Drop for A { } const FOO: A = A; -//~ ERROR: constants are not allowed to have destructors +//~^ ERROR: constants are not allowed to have destructors fn main() {} diff --git a/src/test/compile-fail/issue-17718-const-naming.rs b/src/test/compile-fail/issue-17718-const-naming.rs new file mode 100644 index 0000000000000..046f038847b7b --- /dev/null +++ b/src/test/compile-fail/issue-17718-const-naming.rs @@ -0,0 +1,16 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#[deny(warnings)] + +const foo: int = 3; +//~^ ERROR: should have an uppercase name such as + +fn main() {} diff --git a/src/test/compile-fail/issue-17718-const-privacy.rs b/src/test/compile-fail/issue-17718-const-privacy.rs new file mode 100644 index 0000000000000..d3be9f3dd3f77 --- /dev/null +++ b/src/test/compile-fail/issue-17718-const-privacy.rs @@ -0,0 +1,26 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:issue-17718-const-privacy.rs + +extern crate "issue-17718-const-privacy" as other; + +use a::B; //~ ERROR: const `B` is private +use other::{ + FOO, + BAR, //~ ERROR: const `BAR` is private + FOO2, +}; + +mod a { + const B: uint = 3; +} + +fn main() {} diff --git a/src/test/compile-fail/issue-17718-constants-not-static.rs b/src/test/compile-fail/issue-17718-constants-not-static.rs new file mode 100644 index 0000000000000..8c51b592054a5 --- /dev/null +++ b/src/test/compile-fail/issue-17718-constants-not-static.rs @@ -0,0 +1,17 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +const FOO: uint = 3; + +fn foo() -> &'static uint { &FOO } +//~^ ERROR: borrowed value does not live long enough + +fn main() { +} diff --git a/src/test/compile-fail/issue-17718-extern-const.rs b/src/test/compile-fail/issue-17718-extern-const.rs new file mode 100644 index 0000000000000..235d1222d81c0 --- /dev/null +++ b/src/test/compile-fail/issue-17718-extern-const.rs @@ -0,0 +1,15 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +extern { + const FOO: uint; //~ ERROR: unexpected token: `const` +} + +fn main() {} diff --git a/src/test/compile-fail/issue-17718-patterns.rs b/src/test/compile-fail/issue-17718-patterns.rs new file mode 100644 index 0000000000000..01dfb1b4af93c --- /dev/null +++ b/src/test/compile-fail/issue-17718-patterns.rs @@ -0,0 +1,22 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +static A1: uint = 1; +static mut A2: uint = 1; +const A3: uint = 1; + +fn main() { + match 1u { + A1 => {} //~ ERROR: static variables cannot be referenced in a pattern + A2 => {} //~ ERROR: static variables cannot be referenced in a pattern + A3 => {} + _ => {} + } +} diff --git a/src/test/compile-fail/issue-17718-recursive.rs b/src/test/compile-fail/issue-17718-recursive.rs new file mode 100644 index 0000000000000..a13dfe639c12b --- /dev/null +++ b/src/test/compile-fail/issue-17718-recursive.rs @@ -0,0 +1,14 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +const A: uint = B; //~ ERROR: recursive constant +const B: uint = A; //~ ERROR: recursive constant + +fn main() {} diff --git a/src/test/compile-fail/issue-17718-references.rs b/src/test/compile-fail/issue-17718-references.rs new file mode 100644 index 0000000000000..7b272e1610c7f --- /dev/null +++ b/src/test/compile-fail/issue-17718-references.rs @@ -0,0 +1,33 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +struct Struct { a: uint } + +const C: uint = 1; +static S: uint = 1; + +const T1: &'static uint = &C; +const T2: &'static uint = &S; //~ ERROR: constants cannot refer to other statics +static T3: &'static uint = &C; +static T4: &'static uint = &S; + +const T5: uint = C; +const T6: uint = S; //~ ERROR: constants cannot refer to other statics +//~^ cannot refer to other statics +static T7: uint = C; +static T8: uint = S; //~ ERROR: cannot refer to other statics by value + +const T9: Struct = Struct { a: C }; +const T10: Struct = Struct { a: S }; //~ ERROR: cannot refer to other statics by value +//~^ ERROR: constants cannot refer to other statics +static T11: Struct = Struct { a: C }; +static T12: Struct = Struct { a: S }; //~ ERROR: cannot refer to other statics by value + +fn main() {} diff --git a/src/test/compile-fail/issue-17718-static-move.rs b/src/test/compile-fail/issue-17718-static-move.rs new file mode 100644 index 0000000000000..c57df9a3af4a4 --- /dev/null +++ b/src/test/compile-fail/issue-17718-static-move.rs @@ -0,0 +1,19 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use std::kinds::marker; + +struct Foo { nc: marker::NoCopy } +const INIT: Foo = Foo { nc: marker::NoCopy }; +static FOO: Foo = INIT; + +fn main() { + let _a = FOO; //~ ERROR: cannot move out of static item +} diff --git a/src/test/compile-fail/issue-17718-static-sync.rs b/src/test/compile-fail/issue-17718-static-sync.rs new file mode 100644 index 0000000000000..2304b18adb63d --- /dev/null +++ b/src/test/compile-fail/issue-17718-static-sync.rs @@ -0,0 +1,19 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use std::kinds::marker; + +struct Foo { marker: marker::NoSync } + +static FOO: uint = 3; +static BAR: Foo = Foo { marker: marker::NoSync }; +//~^ ERROR: shared static items must have a type which implements Sync + +fn main() {} diff --git a/src/test/compile-fail/issue-4968.rs b/src/test/compile-fail/issue-4968.rs index 220fb76411abb..a181215f4184d 100644 --- a/src/test/compile-fail/issue-4968.rs +++ b/src/test/compile-fail/issue-4968.rs @@ -10,7 +10,7 @@ // Regression test for issue #4968 -static A: (int,int) = (4,2); +const A: (int,int) = (4,2); fn main() { match 42 { A => () } //~^ ERROR mismatched types: expected ``, found `(int,int)` diff --git a/src/test/compile-fail/issue-7364.rs b/src/test/compile-fail/issue-7364.rs index e29b8bc04d80e..7f0d9ef3b11ec 100644 --- a/src/test/compile-fail/issue-7364.rs +++ b/src/test/compile-fail/issue-7364.rs @@ -13,6 +13,7 @@ use std::cell::RefCell; // Regresion test for issue 7364 static boxed: Box> = box RefCell::new(0); -//~^ ERROR static items are not allowed to have custom pointers +//~^ ERROR statics are not allowed to have custom pointers +//~^^ ERROR: shared static items must have a type which implements Sync fn main() { } diff --git a/src/test/compile-fail/issue-9243.rs b/src/test/compile-fail/issue-9243.rs index f1400c06ca23a..eb3618c9f0408 100644 --- a/src/test/compile-fail/issue-9243.rs +++ b/src/test/compile-fail/issue-9243.rs @@ -14,7 +14,7 @@ struct Test { mem: int, } -pub static g_test: Test = Test {mem: 0}; //~ ERROR static items are not allowed to have destructors +pub static g_test: Test = Test {mem: 0}; //~ ERROR statics are not allowed to have destructors impl Drop for Test { fn drop(&mut self) {} diff --git a/src/test/compile-fail/lint-dead-code-1.rs b/src/test/compile-fail/lint-dead-code-1.rs index 45380235a2a8b..a4320b8dc7751 100644 --- a/src/test/compile-fail/lint-dead-code-1.rs +++ b/src/test/compile-fail/lint-dead-code-1.rs @@ -13,14 +13,12 @@ #![allow(non_camel_case_types)] #![allow(non_uppercase_statics)] #![deny(dead_code)] -#![feature(lang_items)] #![crate_type="lib"] -pub use foo2::Bar2; +extern crate core; -#[lang="sized"] -pub trait Sized {} +pub use foo2::Bar2; mod foo { pub struct Bar; //~ ERROR: struct is never used @@ -32,10 +30,10 @@ mod foo2 { pub static pub_static: int = 0; static priv_static: int = 0; //~ ERROR: static item is never used -static used_static: int = 0; +const used_static: int = 0; pub static used_static2: int = used_static; -static USED_STATIC: int = 0; -static STATIC_USED_IN_ENUM_DISCRIMINANT: int = 10; +const USED_STATIC: int = 0; +const STATIC_USED_IN_ENUM_DISCRIMINANT: int = 10; pub type typ = *const UsedStruct4; pub struct PubStruct; @@ -107,7 +105,3 @@ fn bar() { //~ ERROR: function is never used #[allow(dead_code)] fn g() { h(); } fn h() {} - -// Similarly, lang items are live -#[lang="fail"] -fn fail(_: *const u8, _: *const u8, _: uint) -> ! { loop {} } diff --git a/src/test/compile-fail/match-arm-statics.rs b/src/test/compile-fail/match-arm-statics.rs index 69cb626b75a46..cedc0098c00f5 100644 --- a/src/test/compile-fail/match-arm-statics.rs +++ b/src/test/compile-fail/match-arm-statics.rs @@ -17,7 +17,7 @@ enum Direction { West } -static TRUE_TRUE: (bool, bool) = (true, true); +const TRUE_TRUE: (bool, bool) = (true, true); fn nonexhaustive_1() { match (true, false) { @@ -39,8 +39,8 @@ fn unreachable_1() { } } -static NONE: Option = None; -static EAST: Direction = East; +const NONE: Option = None; +const EAST: Direction = East; fn nonexhaustive_2() { match Some(Some(North)) { @@ -66,13 +66,13 @@ fn unreachable_2() { } } -static NEW_FALSE: NewBool = NewBool(false); +const NEW_FALSE: NewBool = NewBool(false); struct Foo { bar: Option, baz: NewBool } -static STATIC_FOO: Foo = Foo { bar: None, baz: NEW_FALSE }; +const STATIC_FOO: Foo = Foo { bar: None, baz: NEW_FALSE }; fn nonexhaustive_3() { match (Foo { bar: Some(North), baz: NewBool(true) }) { diff --git a/src/test/compile-fail/match-static-const-lc.rs b/src/test/compile-fail/match-static-const-lc.rs index a5dce6ecc6f3e..af7938948a70f 100644 --- a/src/test/compile-fail/match-static-const-lc.rs +++ b/src/test/compile-fail/match-static-const-lc.rs @@ -14,7 +14,7 @@ #![deny(non_uppercase_statics)] #[allow(non_uppercase_statics)] -pub static a : int = 97; +pub const a : int = 97; fn f() { let r = match (0,0) { @@ -27,7 +27,7 @@ fn f() { mod m { #[allow(non_uppercase_statics)] - pub static aha : int = 7; + pub const aha : int = 7; } fn g() { @@ -41,7 +41,7 @@ fn g() { } mod n { - pub static OKAY : int = 8; + pub const OKAY : int = 8; } fn h() { diff --git a/src/test/compile-fail/static-mut-not-constant.rs b/src/test/compile-fail/static-mut-not-constant.rs index 927006adc9e26..84c72de5548a2 100644 --- a/src/test/compile-fail/static-mut-not-constant.rs +++ b/src/test/compile-fail/static-mut-not-constant.rs @@ -10,6 +10,7 @@ static mut a: Box = box 3; -//~^ ERROR mutable static items are not allowed to have owned pointers +//~^ ERROR statics are not allowed to have custom pointers +//~^^ ERROR mutable statics are not allowed to have owned pointers fn main() {} diff --git a/src/test/compile-fail/static-mut-not-pat.rs b/src/test/compile-fail/static-mut-not-pat.rs index b3e93daccab8d..b3ffcb0b98967 100644 --- a/src/test/compile-fail/static-mut-not-pat.rs +++ b/src/test/compile-fail/static-mut-not-pat.rs @@ -20,7 +20,7 @@ fn main() { // instead of spitting out a custom error about some identifier collisions // (we should allow shadowing) match 4i { - a => {} //~ ERROR mutable static variables cannot be referenced in a pattern + a => {} //~ ERROR static variables cannot be referenced in a pattern _ => {} } } @@ -32,7 +32,7 @@ enum Direction { South, West } -static NEW_FALSE: NewBool = NewBool(false); +const NEW_FALSE: NewBool = NewBool(false); struct Foo { bar: Option, baz: NewBool @@ -44,7 +44,7 @@ fn mutable_statics() { match (Foo { bar: Some(North), baz: NewBool(true) }) { Foo { bar: None, baz: NewBool(true) } => (), STATIC_MUT_FOO => (), - //~^ ERROR mutable static variables cannot be referenced in a pattern + //~^ ERROR static variables cannot be referenced in a pattern Foo { bar: Some(South), .. } => (), Foo { bar: Some(EAST), .. } => (), Foo { bar: Some(North), baz: NewBool(true) } => (), diff --git a/src/test/compile-fail/std-uncopyable-atomics.rs b/src/test/compile-fail/std-uncopyable-atomics.rs index 0e8c2f38afbed..c0122b8a2a97a 100644 --- a/src/test/compile-fail/std-uncopyable-atomics.rs +++ b/src/test/compile-fail/std-uncopyable-atomics.rs @@ -16,11 +16,11 @@ use std::sync::atomic::*; use std::ptr; fn main() { - let x = INIT_ATOMIC_BOOL; //~ ERROR cannot move out of static item + let x = INIT_ATOMIC_BOOL; let x = *&x; //~ ERROR: cannot move out of dereference - let x = INIT_ATOMIC_INT; //~ ERROR cannot move out of static item + let x = INIT_ATOMIC_INT; let x = *&x; //~ ERROR: cannot move out of dereference - let x = INIT_ATOMIC_UINT; //~ ERROR cannot move out of static item + let x = INIT_ATOMIC_UINT; let x = *&x; //~ ERROR: cannot move out of dereference let x: AtomicPtr = AtomicPtr::new(ptr::null_mut()); let x = *&x; //~ ERROR: cannot move out of dereference diff --git a/src/test/pretty/issue-4264.pp b/src/test/pretty/issue-4264.pp index 2bc09d7e96e58..c5229f0f9f971 100644 --- a/src/test/pretty/issue-4264.pp +++ b/src/test/pretty/issue-4264.pp @@ -25,7 +25,7 @@ pub fn foo(_: [int, ..(3 as uint)]) { } pub fn bar() { - static FOO: uint = ((5u as uint) - (4u as uint) as uint); + const FOO: uint = ((5u as uint) - (4u as uint) as uint); let _: [(), ..(FOO as uint)] = ([(() as ())] as [(), ..1]); let _: [(), ..(1u as uint)] = ([(() as ())] as [(), ..1]); diff --git a/src/test/pretty/issue-4264.rs b/src/test/pretty/issue-4264.rs index ad407f48a7ae3..ad0954e6eabc3 100644 --- a/src/test/pretty/issue-4264.rs +++ b/src/test/pretty/issue-4264.rs @@ -17,7 +17,7 @@ pub fn foo(_: [int, ..3]) {} pub fn bar() { - static FOO: uint = 5u - 4u; + const FOO: uint = 5u - 4u; let _: [(), ..FOO] = [()]; let _ : [(), ..1u] = [()]; diff --git a/src/test/run-make/sepcomp-cci-copies/Makefile b/src/test/run-make/sepcomp-cci-copies/Makefile index fdb39f851970f..65db841b0c0ed 100644 --- a/src/test/run-make/sepcomp-cci-copies/Makefile +++ b/src/test/run-make/sepcomp-cci-copies/Makefile @@ -7,4 +7,3 @@ all: $(RUSTC) cci_lib.rs $(RUSTC) foo.rs --emit=ir -C codegen-units=3 [ "$$(cat "$(TMPDIR)"/foo.?.ll | grep -c define\ .*cci_fn)" -eq "2" ] - [ "$$(cat "$(TMPDIR)"/foo.?.ll | grep -c CCI_STATIC.*=.*constant)" -eq "2" ] diff --git a/src/test/run-make/sepcomp-cci-copies/cci_lib.rs b/src/test/run-make/sepcomp-cci-copies/cci_lib.rs index 099101d6f2679..a7cd85db4a2d1 100644 --- a/src/test/run-make/sepcomp-cci-copies/cci_lib.rs +++ b/src/test/run-make/sepcomp-cci-copies/cci_lib.rs @@ -14,6 +14,3 @@ pub fn cci_fn() -> uint { 1234 } - -#[inline] -pub static CCI_STATIC: uint = 2345; diff --git a/src/test/run-make/sepcomp-cci-copies/foo.rs b/src/test/run-make/sepcomp-cci-copies/foo.rs index c702e578c0965..b0642b64cdaac 100644 --- a/src/test/run-make/sepcomp-cci-copies/foo.rs +++ b/src/test/run-make/sepcomp-cci-copies/foo.rs @@ -9,10 +9,10 @@ // except according to those terms. extern crate cci_lib; -use cci_lib::{cci_fn, CCI_STATIC}; +use cci_lib::{cci_fn}; fn call1() -> uint { - cci_fn() + CCI_STATIC + cci_fn() } mod a { @@ -23,9 +23,8 @@ mod a { } mod b { - use cci_lib::CCI_STATIC; pub fn call3() -> uint { - CCI_STATIC + 0 } } diff --git a/src/test/run-pass/bytes-macro-static.rs b/src/test/run-pass/bytes-macro-static.rs index 7f4bbda8e30d8..2ce8c40c77183 100644 --- a/src/test/run-pass/bytes-macro-static.rs +++ b/src/test/run-pass/bytes-macro-static.rs @@ -11,7 +11,7 @@ static FOO: &'static [u8] = bytes!("hello, world"); pub fn main() { - let b = match true { + let b: &'static [u8] = match true { true => bytes!("test"), false => unreachable!() }; diff --git a/src/test/run-pass/cast-in-array-size.rs b/src/test/run-pass/cast-in-array-size.rs index 13e5b89b84e04..aaffb013ad8c7 100644 --- a/src/test/run-pass/cast-in-array-size.rs +++ b/src/test/run-pass/cast-in-array-size.rs @@ -10,7 +10,7 @@ // issues #10618 and #16382 -static SIZE: int = 25; +const SIZE: int = 25; fn main() { let _a: [bool, ..1 as uint]; diff --git a/src/test/run-pass/check-static-slice.rs b/src/test/run-pass/check-static-slice.rs index 17957dbcc1389..60daedec4c79f 100644 --- a/src/test/run-pass/check-static-slice.rs +++ b/src/test/run-pass/check-static-slice.rs @@ -11,12 +11,12 @@ // Check that the various ways of getting to a reference to a vec (both sized // and unsized) work properly. -static aa: [int, ..3] = [1, 2, 3]; -static ab: &'static [int, ..3] = &aa; -static ac: &'static [int] = ab; -static ad: &'static [int] = &aa; -static ae: &'static [int, ..3] = &[1, 2, 3]; -static af: &'static [int] = &[1, 2, 3]; +const aa: [int, ..3] = [1, 2, 3]; +const ab: &'static [int, ..3] = &aa; +const ac: &'static [int] = ab; +const ad: &'static [int] = &aa; +const ae: &'static [int, ..3] = &[1, 2, 3]; +const af: &'static [int] = &[1, 2, 3]; static ca: int = aa[0]; static cb: int = ab[1]; diff --git a/src/test/run-pass/const-cast.rs b/src/test/run-pass/const-cast.rs index 87a4fd1153f82..5d8e31f934411 100644 --- a/src/test/run-pass/const-cast.rs +++ b/src/test/run-pass/const-cast.rs @@ -12,9 +12,9 @@ extern crate libc; extern fn foo() {} -static x: extern "C" fn() = foo; +const x: extern "C" fn() = foo; static y: *const libc::c_void = x as *const libc::c_void; -static a: &'static int = &10; +const a: &'static int = &10; static b: *const int = a as *const int; pub fn main() { diff --git a/src/test/run-pass/const-const.rs b/src/test/run-pass/const-const.rs index bdb2b3d211043..ba2947f736790 100644 --- a/src/test/run-pass/const-const.rs +++ b/src/test/run-pass/const-const.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -static a: int = 1; -static b: int = a + 2; +const a: int = 1; +const b: int = a + 2; pub fn main() { assert_eq!(b, 3); diff --git a/src/test/run-pass/const-deref.rs b/src/test/run-pass/const-deref.rs index 7c2771c3544f7..480fb50a1ffe5 100644 --- a/src/test/run-pass/const-deref.rs +++ b/src/test/run-pass/const-deref.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -static C: &'static int = &1000; +const C: &'static int = &1000; static D: int = *C; pub fn main() { diff --git a/src/test/run-pass/const-enum-vec-index.rs b/src/test/run-pass/const-enum-vec-index.rs index 5be21696bd1ed..2a00daa3c038c 100644 --- a/src/test/run-pass/const-enum-vec-index.rs +++ b/src/test/run-pass/const-enum-vec-index.rs @@ -9,10 +9,10 @@ // except according to those terms. enum E { V1(int), V0 } -static C: &'static [E] = &[V0, V1(0xDEADBEE)]; +const C: &'static [E] = &[V0, V1(0xDEADBEE)]; static C0: E = C[0]; static C1: E = C[1]; -static D: &'static [E, ..2] = &[V0, V1(0xDEADBEE)]; +const D: &'static [E, ..2] = &[V0, V1(0xDEADBEE)]; static D0: E = C[0]; static D1: E = C[1]; diff --git a/src/test/run-pass/const-expr-in-fixed-length-vec.rs b/src/test/run-pass/const-expr-in-fixed-length-vec.rs index 0440a771e98f8..317a54e927f31 100644 --- a/src/test/run-pass/const-expr-in-fixed-length-vec.rs +++ b/src/test/run-pass/const-expr-in-fixed-length-vec.rs @@ -13,7 +13,7 @@ pub fn main() { - static FOO: uint = 2; + const FOO: uint = 2; let _v: [int, ..FOO*3]; } diff --git a/src/test/run-pass/const-expr-in-vec-repeat.rs b/src/test/run-pass/const-expr-in-vec-repeat.rs index 5dd9f829d0a2c..54386b33dd9da 100644 --- a/src/test/run-pass/const-expr-in-vec-repeat.rs +++ b/src/test/run-pass/const-expr-in-vec-repeat.rs @@ -12,7 +12,7 @@ pub fn main() { - static FOO: uint = 2; + const FOO: uint = 2; let _v = [0i, ..FOO*3*2/2]; } diff --git a/src/test/run-pass/const-fields-and-indexing.rs b/src/test/run-pass/const-fields-and-indexing.rs index ff44c76048fab..fc098ff93574b 100644 --- a/src/test/run-pass/const-fields-and-indexing.rs +++ b/src/test/run-pass/const-fields-and-indexing.rs @@ -10,20 +10,20 @@ extern crate debug; -static x : [int, ..4] = [1,2,3,4]; +const x : [int, ..4] = [1,2,3,4]; static p : int = x[2]; -static y : &'static [int] = &[1,2,3,4]; +const y : &'static [int] = &[1,2,3,4]; static q : int = y[2]; struct S {a: int, b: int} -static s : S = S {a: 10, b: 20}; +const s : S = S {a: 10, b: 20}; static t : int = s.b; struct K {a: int, b: int, c: D} struct D { d: int, e: int } -static k : K = K {a: 10, b: 20, c: D {d: 30, e: 40}}; +const k : K = K {a: 10, b: 20, c: D {d: 30, e: 40}}; static m : int = k.c.e; pub fn main() { diff --git a/src/test/run-pass/const-region-ptrs-noncopy.rs b/src/test/run-pass/const-region-ptrs-noncopy.rs index 36fe021b97e14..5e417efb4b583 100644 --- a/src/test/run-pass/const-region-ptrs-noncopy.rs +++ b/src/test/run-pass/const-region-ptrs-noncopy.rs @@ -10,8 +10,8 @@ type Big = [u64, ..8]; struct Pair<'a> { a: int, b: &'a Big } -static x: &'static Big = &([13, 14, 10, 13, 11, 14, 14, 15]); -static y: &'static Pair<'static> = &Pair {a: 15, b: x}; +const x: &'static Big = &([13, 14, 10, 13, 11, 14, 14, 15]); +const y: &'static Pair<'static> = &Pair {a: 15, b: x}; pub fn main() { assert_eq!(x as *const Big, y.b as *const Big); diff --git a/src/test/run-pass/const-region-ptrs.rs b/src/test/run-pass/const-region-ptrs.rs index 113f13dc4bf40..e5d3f0ece0cf5 100644 --- a/src/test/run-pass/const-region-ptrs.rs +++ b/src/test/run-pass/const-region-ptrs.rs @@ -10,9 +10,9 @@ struct Pair<'a> { a: int, b: &'a int } -static x: &'static int = &10; +const x: &'static int = &10; -static y: &'static Pair<'static> = &Pair {a: 15, b: x}; +const y: &'static Pair<'static> = &Pair {a: 15, b: x}; pub fn main() { println!("x = {}", *x); diff --git a/src/test/run-pass/const-str-ptr.rs b/src/test/run-pass/const-str-ptr.rs index 0fef3dd4aac24..7395a997a05c5 100644 --- a/src/test/run-pass/const-str-ptr.rs +++ b/src/test/run-pass/const-str-ptr.rs @@ -10,9 +10,9 @@ use std::{str, string}; -static A: [u8, ..2] = ['h' as u8, 'i' as u8]; -static B: &'static [u8, ..2] = &A; -static C: *const u8 = B as *const u8; +const A: [u8, ..2] = ['h' as u8, 'i' as u8]; +const B: &'static [u8, ..2] = &A; +const C: *const u8 = B as *const u8; pub fn main() { unsafe { diff --git a/src/test/run-pass/const-struct.rs b/src/test/run-pass/const-struct.rs index 0a83d007a06a1..f2db119156960 100644 --- a/src/test/run-pass/const-struct.rs +++ b/src/test/run-pass/const-struct.rs @@ -22,10 +22,10 @@ impl cmp::PartialEq for foo { fn ne(&self, other: &foo) -> bool { !(*self).eq(other) } } -static x : foo = foo { a:1, b:2, c: 3 }; -static y : foo = foo { b:2, c:3, a: 1 }; -static z : &'static foo = &foo { a: 10, b: 22, c: 12 }; -static w : foo = foo { a:5, ..x }; +const x : foo = foo { a:1, b:2, c: 3 }; +const y : foo = foo { b:2, c:3, a: 1 }; +const z : &'static foo = &foo { a: 10, b: 22, c: 12 }; +const w : foo = foo { a:5, ..x }; pub fn main() { assert_eq!(x.b, 2); diff --git a/src/test/run-pass/consts-in-patterns.rs b/src/test/run-pass/consts-in-patterns.rs index 2a15774fb17a8..87b7fcad38522 100644 --- a/src/test/run-pass/consts-in-patterns.rs +++ b/src/test/run-pass/consts-in-patterns.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -static FOO: int = 10; -static BAR: int = 3; +const FOO: int = 10; +const BAR: int = 3; pub fn main() { let x: int = 3i; diff --git a/src/test/run-pass/enum-vec-initializer.rs b/src/test/run-pass/enum-vec-initializer.rs index b04f5e11042c8..d51562d2490de 100644 --- a/src/test/run-pass/enum-vec-initializer.rs +++ b/src/test/run-pass/enum-vec-initializer.rs @@ -12,13 +12,13 @@ enum Flopsy { Bunny = 2 } -static BAR:uint = Bunny as uint; -static BAR2:uint = BAR; +const BAR:uint = Bunny as uint; +const BAR2:uint = BAR; pub fn main() { let _v = [0i, .. Bunny as uint]; let _v = [0i, .. BAR]; let _v = [0i, .. BAR2]; - static BAR3:uint = BAR2; + const BAR3:uint = BAR2; let _v = [0i, .. BAR3]; } diff --git a/src/test/run-pass/issue-11940.rs b/src/test/run-pass/issue-11940.rs index bbe7eff229b00..1540679b099b4 100644 --- a/src/test/run-pass/issue-11940.rs +++ b/src/test/run-pass/issue-11940.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -static TEST_STR: &'static str = "abcd"; +const TEST_STR: &'static str = "abcd"; fn main() { let s = "abcd"; diff --git a/src/test/run-pass/issue-13763.rs b/src/test/run-pass/issue-13763.rs index 242836dbe029f..8b2b732415ee0 100644 --- a/src/test/run-pass/issue-13763.rs +++ b/src/test/run-pass/issue-13763.rs @@ -10,7 +10,7 @@ use std::u8; -static NUM: uint = u8::BITS as uint; +const NUM: uint = u8::BITS as uint; struct MyStruct { nums: [uint, ..8] } diff --git a/src/test/run-pass/issue-17074.rs b/src/test/run-pass/issue-17074.rs index e346148691d86..d35c3a587c5a5 100644 --- a/src/test/run-pass/issue-17074.rs +++ b/src/test/run-pass/issue-17074.rs @@ -8,8 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -static X: u64 = -1 as u16 as u64; -static Y: u64 = -1 as u32 as u64; +static X2: u64 = -1 as u16 as u64; +static Y2: u64 = -1 as u32 as u64; +const X: u64 = -1 as u16 as u64; +const Y: u64 = -1 as u32 as u64; fn main() { assert_eq!(match 1 { diff --git a/src/test/compile-fail/borrowck-forbid-static-unsafe-interior.rs b/src/test/run-pass/issue-17718-static-unsafe-interior.rs similarity index 69% rename from src/test/compile-fail/borrowck-forbid-static-unsafe-interior.rs rename to src/test/run-pass/issue-17718-static-unsafe-interior.rs index 01a6e33467ee4..8f76d95c54815 100644 --- a/src/test/compile-fail/borrowck-forbid-static-unsafe-interior.rs +++ b/src/test/run-pass/issue-17718-static-unsafe-interior.rs @@ -8,9 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// Verify that it is not possible to take the address of -// static items with unsafe interior. - use std::kinds::marker; use std::cell::UnsafeCell; @@ -30,10 +27,10 @@ enum UnsafeEnum { static STATIC1: UnsafeEnum = VariantSafe; static STATIC2: UnsafeCell = UnsafeCell { value: 1 }; -static STATIC3: MyUnsafe = MyUnsafe{value: STATIC2}; +const CONST: UnsafeCell = UnsafeCell { value: 1 }; +static STATIC3: MyUnsafe = MyUnsafe{value: CONST}; static STATIC4: &'static UnsafeCell = &STATIC2; -//~^ ERROR borrow of immutable static items with unsafe interior is not allowed struct Wrap { value: T @@ -41,14 +38,11 @@ struct Wrap { static UNSAFE: UnsafeCell = UnsafeCell{value: 1}; static WRAPPED_UNSAFE: Wrap<&'static UnsafeCell> = Wrap { value: &UNSAFE }; -//~^ ERROR borrow of immutable static items with unsafe interior is not allowed fn main() { let a = &STATIC1; - //~^ ERROR borrow of immutable static items with unsafe interior is not allowed STATIC3.forbidden() - //~^ ERROR borrow of immutable static items with unsafe interior is not allowed } diff --git a/src/test/run-pass/issue-17718.rs b/src/test/run-pass/issue-17718.rs new file mode 100644 index 0000000000000..90a102222ba17 --- /dev/null +++ b/src/test/run-pass/issue-17718.rs @@ -0,0 +1,83 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:issue-17718.rs + +extern crate "issue-17718" as other; + +use std::sync::atomic; + +const C1: uint = 1; +const C2: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT; +const C3: fn() = foo; +const C4: uint = C1 * C1 + C1 / C1; +const C5: &'static uint = &C4; +const C6: uint = { + const C: uint = 3; + C +}; + +static S1: uint = 3; +static S2: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT; + +mod test { + static A: uint = 4; + static B: &'static uint = &A; + static C: &'static uint = &(A); +} + +fn foo() {} + +fn main() { + assert_eq!(C1, 1); + assert_eq!(C3(), ()); + assert_eq!(C2.fetch_add(1, atomic::SeqCst), 0); + assert_eq!(C2.fetch_add(1, atomic::SeqCst), 0); + assert_eq!(C4, 2); + assert_eq!(*C5, 2); + assert_eq!(C6, 3); + assert_eq!(S1, 3); + assert_eq!(S2.fetch_add(1, atomic::SeqCst), 0); + assert_eq!(S2.fetch_add(1, atomic::SeqCst), 1); + + match 1 { + C1 => {} + _ => unreachable!(), + } + + let _a = C1; + let _a = C2; + let _a = C3; + let _a = C4; + let _a = C5; + let _a = C6; + let _a = S1; + + assert_eq!(other::C1, 1); + assert_eq!(other::C3(), ()); + assert_eq!(other::C2.fetch_add(1, atomic::SeqCst), 0); + assert_eq!(other::C2.fetch_add(1, atomic::SeqCst), 0); + assert_eq!(other::C4, 2); + assert_eq!(*other::C5, 2); + assert_eq!(other::S1, 3); + assert_eq!(other::S2.fetch_add(1, atomic::SeqCst), 0); + assert_eq!(other::S2.fetch_add(1, atomic::SeqCst), 1); + + let _a = other::C1; + let _a = other::C2; + let _a = other::C3; + let _a = other::C4; + let _a = other::C5; + + match 1 { + other::C1 => {} + _ => unreachable!(), + } +} diff --git a/src/test/run-pass/issue-2428.rs b/src/test/run-pass/issue-2428.rs index 8c8b9d5df1359..b2ebbf3b148cf 100644 --- a/src/test/run-pass/issue-2428.rs +++ b/src/test/run-pass/issue-2428.rs @@ -10,7 +10,7 @@ pub fn main() { let _foo = 100i; - static quux: int = 5; + const quux: int = 5; enum Stuff { Bar = quux diff --git a/src/test/run-pass/issue-5353.rs b/src/test/run-pass/issue-5353.rs index 2d729f8ced8d8..1f6493d961c5a 100644 --- a/src/test/run-pass/issue-5353.rs +++ b/src/test/run-pass/issue-5353.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -static INVALID_ENUM : u32 = 0; -static INVALID_VALUE : u32 = 1; +const INVALID_ENUM : u32 = 0; +const INVALID_VALUE : u32 = 1; fn gl_err_str(err: u32) -> String { diff --git a/src/test/run-pass/issue-7222.rs b/src/test/run-pass/issue-7222.rs index b86b9a83e35bc..65ea895c2c85f 100644 --- a/src/test/run-pass/issue-7222.rs +++ b/src/test/run-pass/issue-7222.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - static FOO: f64 = 10.0; + const FOO: f64 = 10.0; match 0.0 { 0.0 ... FOO => (), diff --git a/src/test/run-pass/issue-9942.rs b/src/test/run-pass/issue-9942.rs index aa86f488906e6..b9410ffdb43ec 100644 --- a/src/test/run-pass/issue-9942.rs +++ b/src/test/run-pass/issue-9942.rs @@ -9,5 +9,5 @@ // except according to those terms. pub fn main() { - static S: uint = 23 as uint; [0i, ..S]; () + const S: uint = 23 as uint; [0i, ..S]; () } diff --git a/src/test/run-pass/match-arm-statics.rs b/src/test/run-pass/match-arm-statics.rs index 6eb0a4dad1b6a..29972c0efd0db 100644 --- a/src/test/run-pass/match-arm-statics.rs +++ b/src/test/run-pass/match-arm-statics.rs @@ -29,19 +29,19 @@ enum EnumWithStructVariants { } } -static TRUE_TRUE: (bool, bool) = (true, true); -static NONE: Option = None; -static EAST: Direction = East; -static NEW_FALSE: NewBool = NewBool(false); -static STATIC_FOO: Foo = Foo { bar: Some(South), baz: NEW_FALSE }; -static VARIANT2_NORTH: EnumWithStructVariants = Variant2 { dir: North }; +const TRUE_TRUE: (bool, bool) = (true, true); +const NONE: Option = None; +const EAST: Direction = East; +const NEW_FALSE: NewBool = NewBool(false); +const STATIC_FOO: Foo = Foo { bar: Some(South), baz: NEW_FALSE }; +const VARIANT2_NORTH: EnumWithStructVariants = Variant2 { dir: North }; pub mod glfw { pub struct InputState(uint); - pub static RELEASE : InputState = InputState(0); - pub static PRESS : InputState = InputState(1); - pub static REPEAT : InputState = InputState(2); + pub const RELEASE : InputState = InputState(0); + pub const PRESS : InputState = InputState(1); + pub const REPEAT : InputState = InputState(2); } fn issue_6533() { @@ -63,7 +63,7 @@ fn issue_6533() { } fn issue_13626() { - static VAL: [u8, ..1] = [0]; + const VAL: [u8, ..1] = [0]; match [1] { VAL => unreachable!(), _ => () @@ -72,8 +72,8 @@ fn issue_13626() { fn issue_14576() { type Foo = (i32, i32); - static ON: Foo = (1, 1); - static OFF: Foo = (0, 0); + const ON: Foo = (1, 1); + const OFF: Foo = (0, 0); match (1, 1) { OFF => unreachable!(), @@ -82,14 +82,14 @@ fn issue_14576() { } enum C { D = 3, E = 4 } - static F : C = D; + const F : C = D; assert_eq!(match D { F => 1i, _ => 2, }, 1); } fn issue_13731() { enum A { AA(()) } - static B: A = AA(()); + const B: A = AA(()); match AA(()) { B => () @@ -102,8 +102,8 @@ fn issue_15393() { bits: uint } - static FOO: Flags = Flags { bits: 0x01 }; - static BAR: Flags = Flags { bits: 0x02 }; + const FOO: Flags = Flags { bits: 0x01 }; + const BAR: Flags = Flags { bits: 0x02 }; match (Flags { bits: 0x02 }) { FOO => unreachable!(), BAR => (), diff --git a/src/test/run-pass/match-range-static.rs b/src/test/run-pass/match-range-static.rs index 088756992453e..0feeea70221a4 100644 --- a/src/test/run-pass/match-range-static.rs +++ b/src/test/run-pass/match-range-static.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -static s: int = 1; -static e: int = 42; +const s: int = 1; +const e: int = 42; pub fn main() { match 7 { diff --git a/src/test/run-pass/match-static-const-rename.rs b/src/test/run-pass/match-static-const-rename.rs index 9028e68da1fd9..f3fe93650af5e 100644 --- a/src/test/run-pass/match-static-const-rename.rs +++ b/src/test/run-pass/match-static-const-rename.rs @@ -18,7 +18,7 @@ #![deny(non_uppercase_statics)] -pub static A : int = 97; +pub const A : int = 97; fn f() { let r = match (0,0) { @@ -35,7 +35,7 @@ fn f() { mod m { #[allow(non_uppercase_statics)] - pub static aha : int = 7; + pub const aha : int = 7; } fn g() { diff --git a/src/test/run-pass/resolve-issue-2428.rs b/src/test/run-pass/resolve-issue-2428.rs index 57f6596d1d720..8aa12aa3e98ad 100644 --- a/src/test/run-pass/resolve-issue-2428.rs +++ b/src/test/run-pass/resolve-issue-2428.rs @@ -8,6 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -static foo: int = 4 >> 1; +const foo: int = 4 >> 1; enum bs { thing = foo } pub fn main() { assert!((thing as int == foo)); } diff --git a/src/test/run-pass/sepcomp-statics.rs b/src/test/run-pass/sepcomp-statics.rs index 26a652ae0ea4f..26a5c4d1c5026 100644 --- a/src/test/run-pass/sepcomp-statics.rs +++ b/src/test/run-pass/sepcomp-statics.rs @@ -14,7 +14,7 @@ fn pad() -> uint { 0 } -static ONE: uint = 1; +const ONE: uint = 1; mod b { // Separate compilation always switches to the LLVM module with the fewest @@ -28,7 +28,7 @@ mod b { mod a { fn pad() -> uint { 0 } - pub static TWO: uint = ::ONE + ::ONE; + pub const TWO: uint = ::ONE + ::ONE; } fn main() { diff --git a/src/test/run-pass/syntax-extension-bytes.rs b/src/test/run-pass/syntax-extension-bytes.rs index 8d5333e5b3fc5..1f92677fb6f89 100644 --- a/src/test/run-pass/syntax-extension-bytes.rs +++ b/src/test/run-pass/syntax-extension-bytes.rs @@ -11,15 +11,15 @@ static static_vec: &'static [u8] = bytes!("abc", 0xFF, '!'); pub fn main() { - let vec = bytes!("abc"); + let vec: &'static [u8] = bytes!("abc"); let expected: &[u8] = &[97_u8, 98_u8, 99_u8]; assert_eq!(vec, expected); - let vec = bytes!("null", 0); + let vec: &'static [u8] = bytes!("null", 0); let expected: &[u8] = &[110_u8, 117_u8, 108_u8, 108_u8, 0_u8]; assert_eq!(vec, expected); - let vec = bytes!(' ', " ", 32, 32u8); + let vec: &'static [u8] = bytes!(' ', " ", 32, 32u8); let expected: &[u8] = &[32_u8, 32_u8, 32_u8, 32_u8]; assert_eq!(vec, expected); diff --git a/src/test/run-pass/vector-sort-failure-safe.rs b/src/test/run-pass/vector-sort-failure-safe.rs index 542f4dbdf2391..a8ab0e48ccf8a 100644 --- a/src/test/run-pass/vector-sort-failure-safe.rs +++ b/src/test/run-pass/vector-sort-failure-safe.rs @@ -11,7 +11,7 @@ use std::task; use std::rand::{task_rng, Rng}; -static MAX_LEN: uint = 20; +const MAX_LEN: uint = 20; static mut drop_counts: [uint, .. MAX_LEN] = [0, .. MAX_LEN]; static mut clone_count: uint = 0; diff --git a/src/test/run-pass/xcrate-unit-struct.rs b/src/test/run-pass/xcrate-unit-struct.rs index f66caa5fbfc6e..7eb73968db5ef 100644 --- a/src/test/run-pass/xcrate-unit-struct.rs +++ b/src/test/run-pass/xcrate-unit-struct.rs @@ -11,7 +11,7 @@ // aux-build:xcrate_unit_struct.rs extern crate xcrate_unit_struct; -static s1: xcrate_unit_struct::Struct = xcrate_unit_struct::Struct; +const s1: xcrate_unit_struct::Struct = xcrate_unit_struct::Struct; static s2: xcrate_unit_struct::Unit = xcrate_unit_struct::UnitVariant; static s3: xcrate_unit_struct::Unit = xcrate_unit_struct::Argument(xcrate_unit_struct::Struct); From a3e8f41212a04b702596f4261b89f2c3254338d7 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 7 Oct 2014 08:33:52 -0700 Subject: [PATCH 23/24] doc: Document constants in the reference --- src/doc/reference.md | 84 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 65 insertions(+), 19 deletions(-) diff --git a/src/doc/reference.md b/src/doc/reference.md index ebcea7cf9de68..c34a136a68e88 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -1383,44 +1383,87 @@ a = Cat { name: "Spotty".to_string(), weight: 2.7 }; In this example, `Cat` is a _struct-like enum variant_, whereas `Dog` is simply called an enum variant. -### Static items +### Constant items ```{.ebnf .gram} -static_item : "static" ident ':' type '=' expr ';' ; +const_item : "const" ident ':' type '=' expr ';' ; ``` -A *static item* is a named _constant value_ stored in the global data section -of a crate. Immutable static items are stored in the read-only data section. -The constant value bound to a static item is, like all constant values, -evaluated at compile time. Static items have the `static` lifetime, which -outlives all other lifetimes in a Rust program. Only values stored in the -global data section (such as string constants and static items) can have the -`static` lifetime; dynamically constructed values cannot safely be assigned the -`static` lifetime. Static items are declared with the `static` keyword. A -static item must have a _constant expression_ giving its definition. +A *constant item* is a named _constant value_ which is not associated with a +specific memory location in the program. Constants are essentially inlined +wherever they are used, meaning that they are copied directly into the relevant +context when used. References to the same constant are not necessarily +guaranteed to refer to the same memory address. + +Constant values must not have destructors, and otherwise permit most forms of +data. Constants may refer to the address of other constants, in which case the +address will have the `static` lifetime. The compiler is, however, still at +liberty to translate the constant many times, so the address referred to may not +be stable. -Static items must be explicitly typed. The type may be `bool`, `char`, -a number, or a type derived from those primitive types. The derived types are -references with the `static` lifetime, fixed-size arrays, tuples, and structs. +Constants must be explicitly typed. The type may be `bool`, `char`, a number, or +a type derived from those primitive types. The derived types are references with +the `static` lifetime, fixed-size arrays, tuples, enum variants, and structs. ``` -static BIT1: uint = 1 << 0; -static BIT2: uint = 1 << 1; +const BIT1: uint = 1 << 0; +const BIT2: uint = 1 << 1; -static BITS: [uint, ..2] = [BIT1, BIT2]; -static STRING: &'static str = "bitstring"; +const BITS: [uint, ..2] = [BIT1, BIT2]; +const STRING: &'static str = "bitstring"; struct BitsNStrings<'a> { mybits: [uint, ..2], mystring: &'a str } -static BITS_N_STRINGS: BitsNStrings<'static> = BitsNStrings { +const BITS_N_STRINGS: BitsNStrings<'static> = BitsNStrings { mybits: BITS, mystring: STRING }; ``` +### Static items + +```{.ebnf .gram} +static_item : "static" ident ':' type '=' expr ';' ; +``` + +A *static item* is similar to a *constant*, except that it represents a precise +memory location in the program. A static is never "inlined" at the usage site, +and all references to it refer to the same memory location. Static items have +the `static` lifetime, which outlives all other lifetimes in a Rust program. +Static items may be placed in read-only memory if they do not contain any +interior mutability. + +Statics may contain interior mutability through the `UnsafeCell` language item. +All access to a static is safe, but there are a number of restrictions on +statics: + +* Statics may not contain any destructors. +* The types of static values must ascribe to `Sync` to allow threadsafe access. +* Statics may not refer to other statics by value, only by reference. +* Constants cannot refer to statics. + +Constants should in general be preferred over statics, unless large amounts of +data are being stored, or single-address and mutability properties are required. + +``` +use std::sync::atomic; + +// Note that INIT_ATOMIC_UINT is a *const*, but it may be used to initialize a +// static. This static can be modified, so it is not placed in read-only memory. +static COUNTER: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT; + +// This table is a candidate to be placed in read-only memory. +static TABLE: &'static [uint] = &[1, 2, 3, /* ... */]; + +for slot in TABLE.iter() { + println!("{}", slot); +} +COUNTER.fetch_add(1, atomic::SeqCst); +``` + #### Mutable statics If a static item is declared with the `mut` keyword, then it is allowed to @@ -1455,6 +1498,9 @@ unsafe fn bump_levels_unsafe2() -> uint { } ``` +Mutable statics have the same restrictions as normal statics, except that the +type of the value is not required to ascribe to `Sync`. + ### Traits A _trait_ describes a set of method types. From 0b517117b3ac9c4981bbe00a529e48e4019554d1 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 9 Oct 2014 11:59:03 -0700 Subject: [PATCH 24/24] Test fixes and rebase conflicts --- src/libnative/io/c_windows.rs | 2 +- src/librustrt/mutex.rs | 16 ++++++++-------- src/libstd/rt/backtrace.rs | 16 ++++++++-------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/libnative/io/c_windows.rs b/src/libnative/io/c_windows.rs index 2266f41eff9af..067a31166a500 100644 --- a/src/libnative/io/c_windows.rs +++ b/src/libnative/io/c_windows.rs @@ -17,7 +17,7 @@ use libc; pub const WSADESCRIPTION_LEN: uint = 256; pub const WSASYS_STATUS_LEN: uint = 128; pub const FIONBIO: libc::c_long = 0x8004667e; -static FD_SETSIZE: uint = 64; +pub const FD_SETSIZE: uint = 64; pub const MSG_DONTWAIT: libc::c_int = 0; pub const ERROR_ILLEGAL_CHARACTER: libc::c_int = 582; pub const ENABLE_ECHO_INPUT: libc::DWORD = 0x4; diff --git a/src/librustrt/mutex.rs b/src/librustrt/mutex.rs index d10ba69386695..bd47874d64720 100644 --- a/src/librustrt/mutex.rs +++ b/src/librustrt/mutex.rs @@ -364,20 +364,20 @@ mod imp { use libc; #[cfg(target_arch = "x86_64")] - static __PTHREAD_MUTEX_SIZE__: uint = 56; + const __PTHREAD_MUTEX_SIZE__: uint = 56; #[cfg(target_arch = "x86_64")] - static __PTHREAD_COND_SIZE__: uint = 40; + const __PTHREAD_COND_SIZE__: uint = 40; #[cfg(target_arch = "x86")] - static __PTHREAD_MUTEX_SIZE__: uint = 40; + const __PTHREAD_MUTEX_SIZE__: uint = 40; #[cfg(target_arch = "x86")] - static __PTHREAD_COND_SIZE__: uint = 24; + const __PTHREAD_COND_SIZE__: uint = 24; #[cfg(target_arch = "arm")] - static __PTHREAD_MUTEX_SIZE__: uint = 40; + const __PTHREAD_MUTEX_SIZE__: uint = 40; #[cfg(target_arch = "arm")] - static __PTHREAD_COND_SIZE__: uint = 24; + const __PTHREAD_COND_SIZE__: uint = 24; - static _PTHREAD_MUTEX_SIG_INIT: libc::c_long = 0x32AAABA7; - static _PTHREAD_COND_SIG_INIT: libc::c_long = 0x3CB0B1BB; + const _PTHREAD_MUTEX_SIG_INIT: libc::c_long = 0x32AAABA7; + const _PTHREAD_COND_SIG_INIT: libc::c_long = 0x3CB0B1BB; #[repr(C)] pub struct pthread_mutex_t { diff --git a/src/libstd/rt/backtrace.rs b/src/libstd/rt/backtrace.rs index e1925fc79d0dc..6cbbc0af3909e 100644 --- a/src/libstd/rt/backtrace.rs +++ b/src/libstd/rt/backtrace.rs @@ -45,8 +45,8 @@ pub fn log_enabled() -> bool { val == 2 } -#[cfg(target_word_size = "64")] static HEX_WIDTH: uint = 18; -#[cfg(target_word_size = "32")] static HEX_WIDTH: uint = 10; +#[cfg(target_word_size = "64")] const HEX_WIDTH: uint = 18; +#[cfg(target_word_size = "32")] const HEX_WIDTH: uint = 10; // All rust symbols are in theory lists of "::"-separated identifiers. Some // assemblers, however, can't handle these characters in symbol names. To get @@ -273,7 +273,7 @@ mod imp { try!(writeln!(w, "stack backtrace:")); // 100 lines should be enough - static SIZE: uint = 100; + const SIZE: uint = 100; let mut buf: [*mut libc::c_void, ..SIZE] = unsafe {mem::zeroed()}; let cnt = unsafe { backtrace(buf.as_mut_ptr(), SIZE as libc::c_int) as uint}; @@ -697,10 +697,10 @@ mod imp { *mut libc::c_void, *mut libc::c_void, *mut libc::c_void, *mut libc::c_void) -> libc::BOOL; - static MAX_SYM_NAME: uint = 2000; - static IMAGE_FILE_MACHINE_I386: libc::DWORD = 0x014c; - static IMAGE_FILE_MACHINE_IA64: libc::DWORD = 0x0200; - static IMAGE_FILE_MACHINE_AMD64: libc::DWORD = 0x8664; + const MAX_SYM_NAME: uint = 2000; + const IMAGE_FILE_MACHINE_I386: libc::DWORD = 0x014c; + const IMAGE_FILE_MACHINE_IA64: libc::DWORD = 0x0200; + const IMAGE_FILE_MACHINE_AMD64: libc::DWORD = 0x8664; #[repr(C)] struct SYMBOL_INFO { @@ -772,7 +772,7 @@ mod imp { mod arch { use libc; - static MAXIMUM_SUPPORTED_EXTENSION: uint = 512; + const MAXIMUM_SUPPORTED_EXTENSION: uint = 512; #[repr(C)] pub struct CONTEXT {