Commit Graph

33051 Commits

Author SHA1 Message Date
bors
f9fc49c06e auto merge of #17853 : alexcrichton/rust/issue-17718, r=pcwalton
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]
Closes #17718 

[rfc]: https://github.com/rust-lang/rfcs/pull/246
2014-10-10 00:07:08 +00:00
Alex Crichton
0b517117b3 Test fixes and rebase conflicts 2014-10-09 16:36:07 -07:00
bors
8b12fb326b auto merge of #17891 : brson/rust/verbump, r=alexcrichton 2014-10-09 21:12:03 +00:00
bors
79d056f94b auto merge of #17558 : kaseyc/rust/fix_bitvset_union, r=aturon
Updates the other_op function shared by the union/intersect/difference/symmetric_difference -with functions to fix an issue where certain elements would not be present in the result. To fix this, when other op is called, we resize self's nbits to account for any new elements that may be added to the set.

Example:
```rust
	let mut a = BitvSet::new();
	let mut b = BitvSet::new();
	a.insert(0);
	b.insert(5);
	a.union_with(&b);
	println!("{}", a); //Prints "{0}" instead of "{0, 5}"
```
2014-10-09 19:02:06 +00:00
Brian Anderson
5c92a8e054 Use the same html_root_url for all docs 2014-10-09 10:50:13 -07:00
Brian Anderson
afc1b20d8e Bump version to 0.13.0 2014-10-09 10:41:23 -07:00
Brian Anderson
6beddcfd83 Revert "Update html_root_url for 0.12.0 release"
This reverts commit 2288f33230.
2014-10-09 10:34:34 -07:00
bors
eb04229f7a auto merge of #17880 : pcwalton/rust/duplicate-bindings-in-parameter-list, r=alexcrichton
parameter list.

This breaks code like:

    fn f(a: int, a: int) { ... }
    fn g<T,T>(a: T) { ... }

Change this code to not use the same name for a parameter. For example:

    fn f(a: int, b: int) { ... }
    fn g<T,U>(a: T) { ... }

Code like this is *not* affected, since `_` is not an identifier:

    fn f(_: int, _: int) { ... } // OK

Closes #17568.

r? @alexcrichton 
[breaking-change]
2014-10-09 16:57:03 +00:00
Alex Crichton
a3e8f41212 doc: Document constants in the reference 2014-10-09 09:44:52 -07:00
Alex Crichton
d03a4b0046 test: Convert statics to constants
Additionally, add lots of tests for new functionality around statics and
`static mut`.
2014-10-09 09:44:52 -07:00
Alex Crichton
9c09c94347 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]
2014-10-09 09:44:51 -07:00
Alex Crichton
01d58fe2cb rustdoc: Implement constant documentation
At the same time, migrate statics to constants.
2014-10-09 09:44:51 -07:00
Alex Crichton
1bfe450a5e num: Convert statics to constants 2014-10-09 09:44:51 -07:00
Alex Crichton
831f909484 rustc: Convert statics to constants 2014-10-09 09:44:51 -07:00
Alex Crichton
b8fb0cf789 rustrt: Convert statics to constants 2014-10-09 09:44:51 -07:00
Alex Crichton
d3eaf32900 serialize: Convert statics to constants 2014-10-09 09:44:51 -07:00
Alex Crichton
edf8841642 syntax: Convert statics to constants 2014-10-09 09:44:51 -07:00
Alex Crichton
8ccb616092 native: Convert statics to constants 2014-10-09 09:44:51 -07:00
Alex Crichton
6532a8c95a log: Convert statics to constants 2014-10-09 09:44:51 -07:00
Alex Crichton
a64bb6623c regex: Convert statics to constants
This require a bit of finesse to work around the changes with libunicode, but
nothing too major!
2014-10-09 09:44:51 -07:00
Alex Crichton
abb1b2a309 alloc: Convert statics to constants 2014-10-09 09:44:51 -07:00
Alex Crichton
6d4cf378e6 term: Convert statics to constants 2014-10-09 09:44:51 -07:00
Alex Crichton
ab5935c88d 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]
2014-10-09 09:44:51 -07:00
Alex Crichton
d9874bfb40 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.
2014-10-09 09:44:51 -07:00
Alex Crichton
3370053232 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.
2014-10-09 09:44:51 -07:00
Alex Crichton
abb3d3e444 collections: Convert statics to constants 2014-10-09 09:44:51 -07:00
Alex Crichton
34d66de52a 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.
2014-10-09 09:44:51 -07:00
Alex Crichton
1a433770e3 sync: Convert statics to constants 2014-10-09 09:44:51 -07:00
Alex Crichton
4d87af9dce core: Convert statics to constants 2014-10-09 09:44:50 -07:00
Alex Crichton
90d03d7926 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
2014-10-09 09:44:50 -07:00
Alex Crichton
a89ad58710 rustc: Reformat check_const with modern style
Remove a bunch of two-space tabs
2014-10-09 09:44:01 -07:00
Brian Anderson
158eaa643b 0.12.0 release
-----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1
 
 iQIcBAABAgAGBQJUNrj+AAoJEIWrlub6G+X+4TMQAIlyIoTpbZfA7MgaqHmrqp/O
 DkWH4sjoiTL3pdqHitbaJWFzStLjmM+hzOKYVYxXJGqpHuZv7pbnN2sQCKvJ6m9E
 htojoy9ZVeOUjkqz3+PYc6mh+SuQq4bpAhnnt60tLSxZCda7uTpdTcsOgDlwhu8P
 /YIbnBHo6brcQi6kEK27uN7U2MsluRR/ZhAmZH1mvrTtjKrGsKTEdta2NW1tUzNT
 sDluM9D0/WFjwSA9OohjtpUI7KYudqChOCRaqREgNq6xc/9at/TQHULsjzxLFIiC
 tAttF7ZZ2s1TmS4qzmx3AAWl8n8xYrDo+CpfPqKvSGwDegfHN9Epa+24Cdf2Q5GO
 9RSup89NlNNo3tjmK+G1cUqi/K9RseiZNPSJSoLlR2L9QFg/VFEVbcaZX+oX+CQF
 pfWkKqsfLqj50EimO+vuXRZhShHlu/McOdN0cd+S0KEGdd7ngqU3d7YJf9Ppm1mV
 d1VUqnPxvDrGQTGqk4cpGMIv+LmT6vY2iix3ha583zMYcU9VWrC9VEmR3I4XZefE
 UgsbAx2jIgagWa6ylDpes7X8dn/7qj3BA6l3Bt9aGrs9KnyQ+a3xOyz8dFvRJwks
 T8izOhfJXpxW4CLFZjDIQ9RD/joJuvuqTSIqf7zGIxIbMUQFB9EC/Rn7a3ftidds
 aZVZSl2li1vOa3DucW64
 =4lHl
 -----END PGP SIGNATURE-----

Merge tag '0.12.0'

0.12.0 release
2014-10-09 09:36:30 -07:00
bors
dfd52817ee auto merge of #17875 : dotdash/rust/static_bool, r=alexcrichton
While booleans are represented as i1 in SSA values, LLVM expects them
to be stored/loaded as i8 values. Using i1 as we do now works, but
kills some optimizations, so we should switch to i8, just like we do
everywhere else.

Fixes #16959.
2014-10-09 12:47:01 +00:00
bors
e6cfb56a5c auto merge of #17870 : thestinger/rust/alloc, r=eddyb
Using reallocate(old_ptr, old_size, new_size, align) makes a lot more
sense than reallocate(old_ptr, new_size, align, old_size) and matches up
with the order used by existing platform APIs like mremap.

Closes #17837

[breaking-change]
2014-10-09 10:57:25 +00:00
Björn Steinbrink
6fa5a2f66f Properly translate boolean statics to be stored as i8
While booleans are represented as i1 in SSA values, LLVM expects them
to be stored/loaded as i8 values. Using i1 as we do now works, but
kills some optimizations, so we should switch to i8, just like we do
everywhere else.

Fixes #16959.
2014-10-09 11:09:17 +02:00
bors
1b46b007d7 auto merge of #17784 : bkoropoff/rust/issue-17780, r=pcwalton
This fixes a soundness problem where `Fn` unboxed closures can mutate free variables in the environment.
The following presently builds:

```rust
#![feature(unboxed_closures, overloaded_calls)]

fn main() {
    let mut x = 0u;
    let _f = |&:| x = 42;
}
```

However, this is equivalent to writing the following, which borrowck rightly rejects:

```rust
struct F<'a> {
    x: &'a mut uint
}

impl<'a> Fn<(),()> for F<'a> {
    #[rust_call_abi_hack]
    fn call(&self, _: ()) {
        *self.x = 42; // error: cannot assign to data in a `&` reference
    }
}

fn main() {
    let mut x = 0u;
    let _f = F { x: &mut x };
}
```

This problem is unique to unboxed closures; boxed closures cannot be invoked through an immutable reference and are not subject to it.

This change marks upvars of `Fn` unboxed closures as freely aliasable in mem_categorization, which causes borrowck to reject attempts to mutate or mutably borrow them.

@zwarich pointed out that even with this change, there are remaining soundness issues related to regionck (issue #17403).  This region issue affects boxed closures as well.

Closes issue #17780
2014-10-09 07:12:30 +00:00
Patrick Walton
1498814195 librustc: Forbid duplicate name bindings in the same parameter or type
parameter list.

This breaks code like:

    fn f(a: int, a: int) { ... }
    fn g<T,T>(a: T) { ... }

Change this code to not use the same name for a parameter. For example:

    fn f(a: int, b: int) { ... }
    fn g<T,U>(a: T) { ... }

Code like this is *not* affected, since `_` is not an identifier:

    fn f(_: int, _: int) { ... } // OK

Closes #17568.

[breaking-change]
2014-10-08 22:41:23 -07:00
bors
8f96590150 auto merge of #17873 : steveklabnik/rust/gh16413, r=alexcrichton
A fix for the issues mentioned in https://github.com/rust-lang/rust/issues/16413
2014-10-09 05:22:27 +00:00
bors
d569dfe37e auto merge of #17871 : michaelwoerister/rust/lldb-versioning, r=alexcrichton
Apart from making the build system determine the LLDB version, this PR also fixes an issue with enums in LLDB pretty printers. In order for GDB's pretty printers to know for sure if a field of some value is an enum discriminant, I had rustc mark discriminant fields with the `artificial` DWARF tag. This worked out nicely for GDB but it turns out that one can't access artificial fields from LLDB. So I changed the debuginfo representation so that enum discriminants are marked by the special field name `RUST$ENUM$DISR` instead, which works in both cases.

The PR does not activate the LLDB test suite yet.
2014-10-09 03:07:27 +00:00
Kasey Carrothers
dd4fa906fc Clean up the implementations of Bitv and BitvSet.
Functions that add bits now ensure that any unused bits are set to 0.
`into_bitv` sanitizes the nbits of the Bitv/BitvSet it returns by setting the nbits to the current capacity.
Fix a bug with `union_with` and `symmetric_difference` with due to not updating nbits properly
Add test cases to the _with functions
Remove `get_mut_ref`

This is a [breaking-change]. The things you will need to fix are:

1. BitvSet's `unwrap()` has been renamed to `into_bitv`
2. BitvSet's `get_mut_ref()` has been removed. Use `into_bitv()` and `from_bitv()` instead.
2014-10-08 18:35:29 -07:00
bors
63fe80e1ff auto merge of #17867 : jbcrail/rust/unclear-macros-doc, r=alexcrichton
I rearranged one sentence in the macros guide to make it less awkward.
2014-10-08 23:42:39 +00:00
bors
218cb4bc99 auto merge of #17748 : mahkoh/rust/int_slice, r=aturon 2014-10-08 21:22:32 +00:00
Steve Klabnik
557014cd83 add mention of test attribute
Fixes #16413
2014-10-08 16:46:01 -04:00
Steve Klabnik
3f1ed8608d remove crate_id attribute, add crate_name one
this is true as of https://github.com/rust-lang/rust/pull/15319
2014-10-08 16:44:40 -04:00
Julian Orth
bd527909e7 add {Imm,M}utableIntSlice 2014-10-08 20:51:31 +02:00
bors
afb5fcd553 auto merge of #17843 : coffeejunk/rust/guide-macros, r=steveklabnik
The old version switched in between examples from the value `5i` to `"Hello"` and back.

Additionally, the code generated by `rustc print.rs --pretty=expanded` is not as verbose anymore.
2014-10-08 17:52:08 +00:00
Daniel Micay
1c6fd76f80 saner parameter order for reallocation functions
Using reallocate(old_ptr, old_size, new_size, align) makes a lot more
sense than reallocate(old_ptr, new_size, align, old_size) and matches up
with the order used by existing platform APIs like mremap.

Closes #17837

[breaking-change]
2014-10-08 12:46:09 -04:00
bors
c588e407b9 auto merge of #17866 : jgallagher/rust/reserve-inheritance-keywords, r=huonw
Closes #17862
2014-10-08 13:47:13 +00:00
bors
eb2240aca3 auto merge of #17855 : steveklabnik/rust/fix_table_reference, r=alexcrichton
Markdown tables require a header, and we don't want one.

Fixes #17528
2014-10-08 11:32:11 +00:00
Michael Woerister
98a0f9166c debuginfo: Don't mark struct fields as artificial.
LLDB doesn't allow for reading 'artifical' fields (fields that are generated by the compiler). So do not mark, slice fields, enum discriminants, and GcBox value fields as artificial.
2014-10-08 11:52:06 +02:00