Auto merge of #25281 - steveklabnik:rollup, r=steveklabnik

- Successful merges: #24948, #25158, #25188, #25222, #25239, #25240, #25241, #25255, #25257, #25263
- Failed merges:
This commit is contained in:
bors 2015-05-10 20:44:45 +00:00
commit 9ecc9896de
11 changed files with 100 additions and 11 deletions

View file

@ -713,7 +713,7 @@ variety of numbers, we need to give Rust a hint as to the exact type of number
we want. Hence, `let guess: u32`. The colon (`:`) after `guess` tells Rust
were going to annotate its type. `u32` is an unsigned, thirty-two bit
integer. Rust has [a number of built-in number types][number], but weve
chosen `u32`. Its a good default choice for a small positive numer.
chosen `u32`. Its a good default choice for a small positive number.
[parse]: ../std/primitive.str.html#method.parse
[number]: primitive-types.html#numeric-types
@ -922,7 +922,7 @@ failure. Each contains more information: the successful parsed integer, or an
error type. In this case, we `match` on `Ok(num)`, which sets the inner value
of the `Ok` to the name `num`, and then we just return it on the right-hand
side. In the `Err` case, we dont care what kind of error it is, so we just
use `_` intead of a name. This ignores the error, and `continue` causes us
use `_` instead of a name. This ignores the error, and `continue` causes us
to go to the next iteration of the `loop`.
Now we should be good! Lets try:

View file

@ -50,7 +50,7 @@ side of a `let` binding or directly where an expression is used:
```rust
let x = 5;
let numer = match x {
let number = match x {
1 => "one",
2 => "two",
3 => "three",

View file

@ -78,8 +78,8 @@ When we call `clone()`, the `Arc<T>` needs to update the reference count. Yet
weve not used any `mut`s here, `x` is an immutable binding, and we didnt take
`&mut 5` or anything. So what gives?
To this, we have to go back to the core of Rusts guiding philosophy, memory
safety, and the mechanism by which Rust guarantees it, the
To understand this, we have to go back to the core of Rusts guiding
philosophy, memory safety, and the mechanism by which Rust guarantees it, the
[ownership][ownership] system, and more specifically, [borrowing][borrowing]:
> You may have one or the other of these two kinds of borrows, but not both at

View file

@ -174,7 +174,7 @@ fn foo(v: Vec<i32>) -> Vec<i32> {
}
```
This would get very tedius. It gets worse the more things we want to take ownership of:
This would get very tedious. It gets worse the more things we want to take ownership of:
```rust
fn foo(v1: Vec<i32>, v2: Vec<i32>) -> (Vec<i32>, Vec<i32>, i32) {

View file

@ -176,7 +176,7 @@ Slices have type `&[T]`. Well talk about that `T` when we cover
[generics]: generics.html
You can find more documentation for `slices`s [in the standard library
You can find more documentation for slices [in the standard library
documentation][slice].
[slice]: ../std/primitive.slice.html

View file

@ -312,6 +312,7 @@ println!("{}", y);
We get this error:
```text
error: `x` does not live long enough
y = &x;
^
@ -334,3 +335,37 @@ In other words, `y` is only valid for the scope where `x` exists. As soon as
`x` goes away, it becomes invalid to refer to it. As such, the error says that
the borrow doesnt live long enough because its not valid for the right
amount of time.
The same problem occurs when the reference is declared _before_ the variable it refers to:
```rust,ignore
let y: &i32;
let x = 5;
y = &x;
println!("{}", y);
```
We get this error:
```text
error: `x` does not live long enough
y = &x;
^
note: reference must be valid for the block suffix following statement 0 at
2:16...
let y: &i32;
let x = 5;
y = &x;
println!("{}", y);
}
note: ...but borrowed value is only valid for the block suffix following
statement 1 at 3:14
let x = 5;
y = &x;
println!("{}", y);
}
```

View file

@ -1,6 +1,8 @@
# Configs
Here are some links to repos with configs which ease the use of rust:
These are some links to repos with configs which ease the use of rust.
## Officially Maintained Configs
* [rust.vim](https://github.com/rust-lang/rust.vim)
* [emacs rust-mode](https://github.com/rust-lang/rust-mode)
@ -8,3 +10,7 @@ Here are some links to repos with configs which ease the use of rust:
* [kate-config](https://github.com/rust-lang/kate-config)
* [nano-config](https://github.com/rust-lang/nano-config)
* [zsh-config](https://github.com/rust-lang/zsh-config)
## Community-maintained Configs
* [.editorconfig](https://gist.github.com/derhuerst/c9d1b9309e308d9851fa) ([what is this?](http://editorconfig.org/))

View file

@ -1052,6 +1052,7 @@ impl<T: fmt::Display + ?Sized> ToString for T {
#[stable(feature = "rust1", since = "1.0.0")]
impl AsRef<str> for String {
#[inline]
fn as_ref(&self) -> &str {
self
}

View file

@ -173,6 +173,7 @@ impl<T> AsMut<[T]> for [T] {
#[stable(feature = "rust1", since = "1.0.0")]
impl AsRef<str> for str {
#[inline]
fn as_ref(&self) -> &str {
self
}

View file

@ -46,6 +46,23 @@ enum variant, one of the fields was not provided. Each field should be specified
exactly once.
"##,
E0067: r##"
The left-hand side of an assignment operator must be an lvalue expression. An
lvalue expression represents a memory location and includes item paths (ie,
namespaced variables), dereferences, indexing expressions, and field references.
```
use std::collections::LinkedList;
// Good
let mut list = LinkedList::new();
// Bad: assignment to non-lvalue expression
LinkedList::new() += 1;
```
"##,
E0081: r##"
Enum discriminants are used to differentiate enum variants stored in memory.
This error indicates that the same value was used for two or more variants,
@ -119,6 +136,20 @@ construct an instance of the following type using only safe code:
```
enum Empty {}
```
"##,
E0131: r##"
It is not possible to define `main` with type parameters, or even with function
parameters. When `main` is present, it must take no arguments and return `()`.
"##,
E0132: r##"
It is not possible to declare type parameters on a function that has the `start`
attribute. Such a function must have the following type signature:
```
fn(isize, *const *const u8) -> isize
```
"##
}
@ -149,7 +180,6 @@ register_diagnostics! {
E0060,
E0061,
E0066,
E0067,
E0068,
E0069,
E0070,
@ -189,8 +219,6 @@ register_diagnostics! {
E0128,
E0129,
E0130,
E0131,
E0132,
E0141,
E0159,
E0163,

View file

@ -916,6 +916,24 @@ impl<K, V, S> HashMap<K, V, S>
}
/// Gets the given key's corresponding entry in the map for in-place manipulation.
///
/// # Examples
///
/// ```
/// use std::collections::HashMap;
///
/// let mut letters = HashMap::new();
///
/// for ch in "a short treatise on fungi".chars() {
/// let counter = letters.entry(ch).or_insert(0);
/// *counter += 1;
/// }
///
/// assert_eq!(letters[&'s'], 2);
/// assert_eq!(letters[&'t'], 3);
/// assert_eq!(letters[&'u'], 1);
/// assert_eq!(letters.get(&'y'), None);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn entry(&mut self, key: K) -> Entry<K, V> {
// Gotta resize now.