Commit graph

27136 commits

Author SHA1 Message Date
Alex Crichton
770b6e2fc2 rustc: Fix cfg(not(a, b)) to be not(a && b)
Previously, the cfg attribute `cfg(not(a, b))` was translated to `(!a && !b)`,
but this isn't very useful because that can already be expressed as
`cfg(not(a), not(b))`. This commit changes the translation to `!(a && b)` which
is more symmetrical of the rest of the `cfg` attribute.

Put another way, I would expect `cfg(clause)` to be the opposite of
`cfg(not(clause))`, but this is not currently the case with multiple element
clauses.
2014-03-14 10:32:22 -07:00
bors
2585803ec1 auto merge of #12764 : Kimundi/rust/partial_typehint, r=nikomatsakis
# Summary

This patch introduces the `_` token into the type grammar, with the meaning "infer this type".
With this change, the following two lines become equivalent:
```
let x = foo();
let x: _ = foo();
```
But due to its composability, it enables partial type hints like this:
```
let x: Bar<_> = baz();
```

Using it on the item level is explicitly forbidden, as the Rust language does not enable global type inference by design.

This implements the feature requested in https://github.com/mozilla/rust/issues/9508.

# Things requiring clarification

- The change to enable it is very small, but I have only limited understanding of the related code, so the approach here might be wrong.
  - In particular, while this patch works, it does so in a way not originally intended according to the code comments.
- This probably needs more tests, or rather feedback for which tests are still missing.
- I'm unsure how this interacts with lifetime parameters, and whether it is correct in regard to them.
- Partial type hints on the right side of `as` like `&foo as *_` work in both a normal function contexts and in constexprs like `static foo: *int = &'static 123 as *_`. The question is whether this should be allowed in general.

# Todo for this PR

- The manual and tutorial still needs updating.

# Bugs I'm unsure how to fix

- Requesting inference for the top level of the right hand side of a `as` fails to infer correctly, even if all possible hints are given:

  ```
.../type_hole_1.rs:35:18: 35:22 error: the type of this value must be known in this context
.../type_hole_1.rs:35     let a: int = 1u32 as _;
                                           ^~~~
```
2014-03-14 08:01:28 -07:00
Marvin Löbel
eb69eb36f8 Added support for type placeholders (explicit requested type
inference in a type with `_` ). This enables partial type inference.
2014-03-14 14:57:31 +01:00
bors
339f8163d6 auto merge of #12875 : alexcrichton/rust/demangle-more-things, r=brson
Add some more infrastructure support for demangling `$`-sequences, as well as fixing demangling of closure symbol names if there's more than one closure in a function.
2014-03-14 06:41:26 -07:00
bors
a1c7ebee1a auto merge of #12874 : huonw/rust/printier-rustc, r=alexcrichton
rustc: make stack traces print for .span_bug/.bug.

Previously a call to either of those to diagnostic printers would defer
to the `fatal` equivalents, which explicitly silence the stderr
printing, including a stack trace from `RUST_LOG=std::rt::backtrace`.

This splits the bug printers out to their own diagnostic type so that
things work properly.

Also, this removes the `Ok(...)` that was being printed around the
subtask's stderr output.
2014-03-14 05:26:29 -07:00
bors
d367482491 auto merge of #12871 : aochagavia/rust/Optimize-while_some, r=alexcrichton
The old 'while' needed to match 2 times for each iteration. With the new 'loop' there is just one match needed.

I have also replaced 'blk' by 'f' to be more consistent with parameter names in other functions that are implemented for Option<T>
2014-03-14 04:06:31 -07:00
bors
29756a3b76 auto merge of #12867 : alexcrichton/rust/issue-12860, r=thestinger
This switches a "tail call" to a manual loop to get around LLVM not optimizing
to a tail call.

Close #12860
2014-03-14 02:01:34 -07:00
bors
6c895d1d58 auto merge of #12864 : huonw/rust/hash-docs, r=alexcrichton
collections: move hashmap's example to the struct.

Most people go straight to the struct, not looking at the module, so the
example was well hidden.
2014-03-14 00:41:34 -07:00
bors
b35e8fbfcb auto merge of #12861 : huonw/rust/lint-owned-vecs, r=thestinger
lint: add lint for use of a `~[T]`.

This is useless at the moment (since pretty much every crate uses
`~[]`), but should help avoid regressions once completely removed from a
crate.
2014-03-13 22:26:35 -07:00
bors
4443fb3cfa auto merge of #12855 : alexcrichton/rust/shutdown, r=brson
This is something that is plausibly useful, and is provided by libuv. This is
not currently surfaced as part of the `TcpStream` type, but it may possibly
appear in the future. For now only the raw functionality is provided through the
Rtio objects.
2014-03-13 21:06:34 -07:00
bors
98fa0f89b1 auto merge of #12798 : pczarn/rust/inline-asm, r=alexcrichton
## read+write modifier '+'
This small sugar was left out in the original implementation (#5359).
 
When an output operand with the '+' modifier is encountered, we store the index of that operand alongside the expression to create and append an input operand later. The following lines are equivalent:
```
asm!("" : "+m"(expr));
asm!("" : "=m"(expr) : "0"(expr));
```
## misplaced options and clobbers give a warning
It's really annoying when a small typo might change behavior without any warning.
```
asm!("mov $1, $0" : "=r"(x) : "r"(8u) : "cc" , "volatile");
//~^ WARNING expected a clobber, but found an option
```
## liveness
Fixed incorrect order of propagation.
Sometimes it caused spurious warnings in code: `warning: value assigned to `i` is never read, #[warn(dead_assignment)] on by default`

~~Note: Rebased on top of another PR. (uses other changes)~~

* [x] Implement read+write
* [x] Warn about misplaced options
* [x] Fix liveness (`dead_assignment` lint)
* [x] Add all tests
2014-03-13 18:41:35 -07:00
Huon Wilson
adc357abe6 std: render the vec_ng docs.
These are wildly incomplete, but having something there is better than
nothing, e.g. so that people know it exists, and many of the functions
behaviour can be guessed from the name or by checking the source: it's
knowing they exist at all that's the hard part.
2014-03-14 11:28:39 +11:00
Huon Wilson
62792f09f2 lint: add lint for use of a ~[T].
This is useless at the moment (since pretty much every crate uses
`~[]`), but should help avoid regressions once completely removed from a
crate.
2014-03-14 11:28:39 +11:00
Alex Crichton
a07149b138 rustc: Prevent collisions in names of closures
This commit goes back to using `gensym` to generate unique tokens to put into
the names of closures, allowing closures to be able to get demangled in
backtraces.

Closes #12400
2014-03-13 16:24:46 -07:00
Alex Crichton
6298900895 std: Demangle more escapes in backtraces
The rust compiler not only outputs symbols in the form that C++ does, but it
also mangle symbols like '&' and '~' to special compiler-defined escape
sequences. For convenience, these symbols are demangled when printing
backtraces.
2014-03-13 16:23:10 -07:00
Huon Wilson
edb6b025c4 rustc: make stack traces print for .span_bug/.bug.
Previously a call to either of those to diagnostic printers would defer
to the `fatal` equivalents, which explicitly silence the stderr
printing, including a stack trace from `RUST_LOG=std::rt::backtrace`.

This splits the bug printers out to their own diagnostic type so that
things work properly.

Also, this removes the `Ok(...)` that was being printed around the
subtask's stderr output.
2014-03-14 10:17:14 +11:00
Alex Crichton
a63deeb3d3 io: Bind to shutdown() for TCP streams
This is something that is plausibly useful, and is provided by libuv. This is
not currently surfaced as part of the `TcpStream` type, but it may possibly
appear in the future. For now only the raw functionality is provided through the
Rtio objects.
2014-03-13 15:52:37 -07:00
Piotr Czarnecki
2a1bd2ff9f Fix and improve inline assembly.
Read+write modifier
Some documentation in asm.rs
rpass and cfail tests
2014-03-13 22:38:15 +01:00
bors
b4d324334c auto merge of #12815 : alexcrichton/rust/chan-rename, r=brson
* Chan<T> => Sender<T>
* Port<T> => Receiver<T>
* Chan::new() => channel()
* constructor returns (Sender, Receiver) instead of (Receiver, Sender)
* local variables named `port` renamed to `rx`
* local variables named `chan` renamed to `tx`

Closes #11765
2014-03-13 14:06:37 -07:00
aochagavia
6ff207b415 Refactored while_some (libstd/option.rs)
The old 'while' needed to match 2 times for each iteration. With the new
'loop' there is just one match needed.

I have also replaced 'blk' by 'f' to be more consistent with parameter
names in other functions that are implemented for Option
2014-03-13 21:45:21 +01:00
Alex Crichton
7858065113 std: Rename Chan/Port types and constructor
* Chan<T> => Sender<T>
* Port<T> => Receiver<T>
* Chan::new() => channel()
* constructor returns (Sender, Receiver) instead of (Receiver, Sender)
* local variables named `port` renamed to `rx`
* local variables named `chan` renamed to `tx`

Closes #11765
2014-03-13 13:23:29 -07:00
bors
6ff3c9995e auto merge of #12573 : lbonn/rust/unrecurs, r=alexcrichton
As mentioned in #6109, ```mkdir_recursive``` doesn't really need to use recursive calls, so here is an iterative version.
The other points of the proposed overhaul (renaming and existing permissions) still need to be resolved.

I also bundled an iterative ```rmdir_recursive```, for the same reason.

Please do not hesitate to provide feedback on style as this is my first code change in rust.
2014-03-13 12:16:34 -07:00
bors
47a8c76a43 auto merge of #12561 : pzol/rust/char-case, r=alexcrichton
Added common and simple case folding, i.e. mapping one to one character mapping. For more information see http://www.unicode.org/faq/casemap_charprop.html

Removed auto-generated dead code which wasn't used.
2014-03-13 10:56:35 -07:00
Alex Crichton
05c991c4bb collections: Don't recurse in hashmap robin_hood
This switches a "tail call" to a manual loop to get around LLVM not optimizing
to a tail call.

Close #12860
2014-03-13 09:50:19 -07:00
bors
3fbee34a89 auto merge of #12238 : ktt3ja/rust/lifetime-error-msg, r=nikomatsakis
For the following code snippet:

```rust
struct Foo { bar: int }
fn foo1(x: &Foo) -> &int {
    &x.bar
}
```

This PR generates the following error message:

```rust
test.rs:2:1: 4:2 note: consider using an explicit lifetime parameter as shown: fn foo1<'a>(x: &'a Foo) -> &'a int
test.rs:2 fn foo1(x: &Foo) -> &int {
test.rs:3     &x.bar
test.rs:4 }
test.rs:3:5: 3:11 error: cannot infer an appropriate lifetime for borrow expression due to conflicting requirements
test.rs:3     &x.bar
              ^~~~~~
```

Currently it does not support methods.
2014-03-13 09:41:35 -07:00
bors
6ca57736cc auto merge of #12852 : itdaniher/rust/master, r=alexcrichton
This enables the lowering of llvm 64b intrinsics to hardware ops, resolving issues around `__kernel_cmpxchg64` on older kernels on ARM devices, and also enables use of the hardware floating point unit, resolving https://github.com/mozilla/rust/issues/10482.
2014-03-13 08:26:40 -07:00
bors
05975a4928 auto merge of #12849 : nick29581/rust/doubles, r=alexcrichton 2014-03-13 07:11:41 -07:00
bors
50fb2a4f1f auto merge of #12610 : eddyb/rust/deref-now-auto, r=nikomatsakis
Enables the dereference overloads introduced by #12491 to be applied wherever automatic dereferences would be used (field accesses, method calls and indexing).
2014-03-13 05:51:40 -07:00
Niko Matsakis
01a15d5870 Tweak comments 2014-03-13 14:21:46 +02:00
Niko Matsakis
a7db0d5d30 compile-fail: Beef up borrowck test to include some scenarios where we borrow mutably twice in a row 2014-03-13 14:21:46 +02:00
Eduard Burtescu
27c62449db Region + borrow checker support and tests for overloaded autoderef. 2014-03-13 14:21:46 +02:00
Eduard Burtescu
feedd37653 Apply @nikomatsakis' nits and comments patch. 2014-03-13 14:21:45 +02:00
Eduard Burtescu
26398b4f6d Introduce a common recursion limit for auto-dereference and monomorphization. 2014-03-13 14:21:45 +02:00
Eduard Burtescu
20b4e159ed Implement automatic overloaded dereference.
Closes #7141.
2014-03-13 14:21:45 +02:00
Eduard Burtescu
cdc18b96d6 Remove Rc's borrow method to avoid conflicts with RefCell's borrow in Rc<RefCell<T>>. 2014-03-13 14:21:45 +02:00
bors
2c8bce1c76 auto merge of #12845 : eddyb/rust/vec-no-drop-flag, r=thestinger 2014-03-13 04:36:36 -07:00
Huon Wilson
d06266995c collections: move hashmap's example to the struct.
Most people go straight to the struct, not looking at the module, so the
example was well hidden.
2014-03-13 22:31:56 +11:00
Piotr Zolnierek
dba5625cb8 Remove code duplication
Remove whitespace

Update documentation for to_uppercase, to_lowercase
2014-03-13 12:23:24 +01:00
Piotr Zolnierek
04170b0a41 Implement lower, upper case conversion for char 2014-03-13 09:32:05 +01:00
Piotr Zolnierek
4a00211916 std::unicode: remove unused category tables 2014-03-13 09:32:05 +01:00
bors
12b2607572 auto merge of #12602 : alexcrichton/rust/backtrace, r=brson
Whenever a failure happens, if a program is run with
`RUST_LOG=std::rt::backtrace` a backtrace will be printed to the task's stderr
handle. Stack traces are uncondtionally printed on double-failure and
rtabort!().

This ended up having a nontrivial implementation, and here's some highlights of
it:

* We're bundling libbacktrace for everything but OSX and Windows
* We use libgcc_s and its libunwind apis to get a backtrace of instruction
  pointers
* On OSX we use dladdr() to go from an instruction pointer to a symbol
* On unix that isn't OSX, we use libbacktrace to get symbols
* Windows, as usual, has an entirely separate implementation

Lots more fun details and comments can be found in the source itself.

Closes #10128
2014-03-13 01:11:39 -07:00
Alex Crichton
829df69f9f Add basic backtrace functionality
Whenever a failure happens, if a program is run with
`RUST_LOG=std::rt::backtrace` a backtrace will be printed to the task's stderr
handle. Stack traces are uncondtionally printed on double-failure and
rtabort!().

This ended up having a nontrivial implementation, and here's some highlights of
it:

* We're bundling libbacktrace for everything but OSX and Windows
* We use libgcc_s and its libunwind apis to get a backtrace of instruction
  pointers
* On OSX we use dladdr() to go from an instruction pointer to a symbol
* On unix that isn't OSX, we use libbacktrace to get symbols
* Windows, as usual, has an entirely separate implementation

Lots more fun details and comments can be found in the source itself.

Closes #10128
2014-03-13 00:24:20 -07:00
bors
6cbba7c54e auto merge of #12414 : DaGenix/rust/failing-iterator-wrappers, r=alexcrichton
Most IO related functions return an IoResult so that the caller can handle failure in whatever way is appropriate. However, the `lines`, `bytes`, and `chars` iterators all supress errors. This means that code that needs to handle errors can't use any of these iterators. All three of these iterators were updated to produce IoResults.
    
Fixes #12368
2014-03-12 23:51:40 -07:00
bors
792da8424f auto merge of #12823 : alexcrichton/rust/issue-12666, r=pcwalton
If a TTY fails to get initialized, it still needs to have uv_close invoked on
it. This fixes the problem by constructing the TtyWatcher struct before the call
to uv_tty_init. The struct has a destructor on it which will close the handle
properly.

Closes #12666
2014-03-12 22:36:40 -07:00
bors
e86e1d88b2 auto merge of #12822 : erickt/rust/cleanup, r=acrichto
This PR makes `std::io::FileStat` hashable, and `Path` serializable as a byte array.
2014-03-12 21:21:44 -07:00
Palmer Cox
9ba6bb5a71 Update io iterators to produce IoResults
Most IO related functions return an IoResult so that the caller can handle failure
in whatever way is appropriate. However, the `lines`, `bytes`, and `chars` iterators all
supress errors. This means that code that needs to handle errors can't use any of these
iterators. All three of these iterators were updated to produce IoResults.

Fixes #12368
2014-03-12 22:42:50 -04:00
bors
a53242a1a3 auto merge of #12756 : pongad/rust/remove_owned_str_pat, r=alexcrichton
match-drop-strs-issue-4541.rs deleted as it's the same with issue-4541.rs
2014-03-12 19:21:44 -07:00
Erick Tryzelaar
62026fd6b6 syntax: change the #[deriving(Hash)] typaram variable name 2014-03-12 18:58:54 -07:00
Erick Tryzelaar
d2cfd543f7 serialize: make Paths serializable 2014-03-12 18:58:54 -07:00
Erick Tryzelaar
be12c9f753 std: allow io::File* structs to be hashable 2014-03-12 18:58:54 -07:00