Skip to content

Rollup of 6 pull requests #26212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jun 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/doc/complement-lang-faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@ You may also be interested in browsing [trending Rust repositories][github-rust]

## Is anyone using Rust in production?

Currently, Rust is still pre-1.0, and so we don't recommend that you use Rust
in production unless you know exactly what you're getting into.

That said, there are two production deployments of Rust that we're aware of:
Yes. For example (incomplete):

* [OpenDNS](http://labs.opendns.com/2013/10/04/zeromq-helping-us-block-malicious-domains/)
* [Skylight](http://skylight.io)

Let the fact that this is an easily countable number be a warning.
* [wit.ai](https://github.com/wit-ai/witd)
* [Codius](https://codius.org/blog/codius-rust/)
* [MaidSafe](http://maidsafe.net/)

## Does it run on Windows?

Expand Down
50 changes: 24 additions & 26 deletions src/doc/trpl/closures.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,37 +324,34 @@ first, it may seem strange, but we’ll figure it out. Here’s how you’d prob
try to return a closure from a function:

```rust,ignore
fn factory() -> (Fn(i32) -> Vec<i32>) {
let vec = vec![1, 2, 3];
fn factory() -> (Fn(i32) -> i32) {
let num = 5;

|n| vec.push(n)
|x| x + num
}

let f = factory();

let answer = f(4);
assert_eq!(vec![1, 2, 3, 4], answer);
let answer = f(1);
assert_eq!(6, answer);
```

This gives us these long, related errors:

```text
error: the trait `core::marker::Sized` is not implemented for the type
`core::ops::Fn(i32) -> collections::vec::Vec<i32>` [E0277]
f = factory();
^
note: `core::ops::Fn(i32) -> collections::vec::Vec<i32>` does not have a
constant size known at compile-time
f = factory();
^
error: the trait `core::marker::Sized` is not implemented for the type
`core::ops::Fn(i32) -> collections::vec::Vec<i32>` [E0277]
factory() -> (Fn(i32) -> Vec<i32>) {
^~~~~~~~~~~~~~~~~~~~~
note: `core::ops::Fn(i32) -> collections::vec::Vec<i32>` does not have a constant size known at compile-time
factory() -> (Fn(i32) -> Vec<i32>) {
^~~~~~~~~~~~~~~~~~~~~

`core::ops::Fn(i32) -> i32` [E0277]
fn factory() -> (Fn(i32) -> i32) {
^~~~~~~~~~~~~~~~
note: `core::ops::Fn(i32) -> i32` does not have a constant size known at compile-time
fn factory() -> (Fn(i32) -> i32) {
^~~~~~~~~~~~~~~~
error: the trait `core::marker::Sized` is not implemented for the type `core::ops::Fn(i32) -> i32` [E0277]
let f = factory();
^
note: `core::ops::Fn(i32) -> i32` does not have a constant size known at compile-time
let f = factory();
^
```

In order to return something from a function, Rust needs to know what
Expand All @@ -364,16 +361,16 @@ way to give something a size is to take a reference to it, as references
have a known size. So we’d write this:

```rust,ignore
fn factory() -> &(Fn(i32) -> Vec<i32>) {
let vec = vec![1, 2, 3];
fn factory() -> &(Fn(i32) -> i32) {
let num = 5;

|n| vec.push(n)
|x| x + num
}

let f = factory();

let answer = f(4);
assert_eq!(vec![1, 2, 3, 4], answer);
let answer = f(1);
assert_eq!(6, answer);
```

But we get another error:
Expand Down Expand Up @@ -448,7 +445,8 @@ assert_eq!(6, answer);
We use a trait object, by `Box`ing up the `Fn`. There’s just one last problem:

```text
error: `num` does not live long enough
error: closure may outlive the current function, but it borrows `num`,
which is owned by the current function [E0373]
Box::new(|x| x + num)
^~~~~~~~~~~
```
Expand Down
1 change: 1 addition & 0 deletions src/libcore/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3077,6 +3077,7 @@ pub fn empty<T>() -> Empty<T> {
}

/// An iterator that yields an element exactly once.
#[derive(Clone)]
#[unstable(feature="iter_once", reason = "new addition")]
pub struct Once<T> {
inner: ::option::IntoIter<T>
Expand Down
1 change: 1 addition & 0 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,7 @@ impl<'a, A> DoubleEndedIterator for IterMut<'a, A> {
impl<'a, A> ExactSizeIterator for IterMut<'a, A> {}

/// An iterator over the item contained inside an Option.
#[derive(Clone)]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct IntoIter<A> { inner: Item<A> }

Expand Down
103 changes: 94 additions & 9 deletions src/librustc_typeck/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,97 @@ create an infinite recursion of dereferencing, in which case the only fix is to
somehow break the recursion.
"##,

E0057: r##"
When invoking closures or other implementations of the function traits `Fn`,
`FnMut` or `FnOnce` using call notation, the number of parameters passed to the
function must match its definition.

An example using a closure:

```
let f = |x| x * 3;
let a = f(); // invalid, too few parameters
let b = f(4); // this works!
let c = f(2, 3); // invalid, too many parameters
```

A generic function must be treated similarly:

```
fn foo<F: Fn()>(f: F) {
f(); // this is valid, but f(3) would not work
}
```
"##,

E0059: r##"
The built-in function traits are generic over a tuple of the function arguments.
If one uses angle-bracket notation (`Fn<(T,), Output=U>`) instead of parentheses
(`Fn(T) -> U`) to denote the function trait, the type parameter should be a
tuple. Otherwise function call notation cannot be used and the trait will not be
implemented by closures.

The most likely source of this error is using angle-bracket notation without
wrapping the function argument type into a tuple, for example:

```
fn foo<F: Fn<i32>>(f: F) -> F::Output { f(3) }
```

It can be fixed by adjusting the trait bound like this:

```
fn foo<F: Fn<(i32,)>>(f: F) -> F::Output { f(3) }
```

Note that `(T,)` always denotes the type of a 1-tuple containing an element of
type `T`. The comma is necessary for syntactic disambiguation.
"##,

E0060: r##"
External C functions are allowed to be variadic. However, a variadic function
takes a minimum number of arguments. For example, consider C's variadic `printf`
function:

```
extern crate libc;
use libc::{ c_char, c_int };

extern "C" {
fn printf(_: *const c_char, ...) -> c_int;
}
```

Using this declaration, it must be called with at least one argument, so
simply calling `printf()` is illegal. But the following uses are allowed:

```
unsafe {
use std::ffi::CString;

printf(CString::new("test\n").unwrap().as_ptr());
printf(CString::new("number = %d\n").unwrap().as_ptr(), 3);
printf(CString::new("%d, %d\n").unwrap().as_ptr(), 10, 5);
}
```
"##,

E0061: r##"
The number of arguments passed to a function must match the number of arguments
specified in the function signature.

For example, a function like

```
fn f(a: u16, b: &str) {}
```

must always be called with exactly two arguments, e.g. `f(2, "test")`.

Note, that Rust does not have a notion of optional function arguments or
variadic functions (except for its C-FFI).
"##,

E0062: r##"
This error indicates that during an attempt to build a struct or struct-like
enum variant, one of the fields was specified more than once. Each field should
Expand Down Expand Up @@ -495,11 +586,9 @@ struct ListNode {
This type cannot have a well-defined size, because it needs to be arbitrarily
large (since we would be able to nest `ListNode`s to any depth). Specifically,

```
size of ListNode = 1 byte for head
+ 1 byte for the discriminant of the Option
+ size of ListNode
```
size of `ListNode` = 1 byte for `head`
+ 1 byte for the discriminant of the `Option`
+ size of `ListNode`

One way to fix this is by wrapping `ListNode` in a `Box`, like so:

Expand Down Expand Up @@ -1210,10 +1299,6 @@ register_diagnostics! {
E0036, // incorrect number of type parameters given for this method
E0044, // foreign items may not have type parameters
E0045, // variadic function must have C calling convention
E0057, // method has an incompatible type for trait
E0059,
E0060,
E0061,
E0068,
E0071,
E0074,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_unicode/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ impl char {
/// # Return value
///
/// Returns an iterator which yields the characters corresponding to the
/// lowercase equivalent of the character. If no conversion is possible then
/// titlecase equivalent of the character. If no conversion is possible then
/// an iterator with just the input character is returned.
#[unstable(feature = "unicode", reason = "recently added")]
#[inline]
Expand Down