Skip to content

Rolling up PRs in the queue #16895

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 39 commits into from
Aug 31, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
6d2fe2e
doc: add missing word
tshepang Aug 24, 2014
2d72323
doc: use the more convenient 'cargo run' command
tshepang Aug 24, 2014
538ea3c
doc: slight consistency fix
tshepang Aug 24, 2014
c09c038
Added a note for usage of abs with ::MIN.
Aug 26, 2014
48a2876
Fix sorting order. Change `sync` to `share`
mdinger Aug 27, 2014
687db5d
Fix issue #15826.
jbcrail Aug 26, 2014
5f919cd
Cargo begins version number at 0.0.1 instead of 0.1.0.
SebastianZaha Aug 28, 2014
6138e83
Fix guide typo.
SebastianZaha Aug 28, 2014
080449d
Fixed misleading docs in liballoc
Aug 28, 2014
db7c7c2
doc: Clarify slice failure conditions.
michaelsproul Aug 29, 2014
5bf1b03
Tweak error message for use of a keyword in ident position.
treeman Aug 29, 2014
13bb83c
Updated mut_chunks doc comment to match argument name.
zsiciarz Aug 29, 2014
26b40be
doc: Runnable examples logging.
treeman Aug 29, 2014
0a84308
Fix spelling mistakes in the guide
nhowell Aug 29, 2014
eb28237
desugar -> destructure
steveklabnik Aug 29, 2014
d89b2a5
doc: make docs build
tshepang Aug 30, 2014
b79930e
Fix grammar of the accepted feature warning.
huonw Aug 29, 2014
02d96ac
guide: function -> closure in explanation of closures
emberian Aug 30, 2014
7e4a145
note about ref patterns in pointer guide
steveklabnik Aug 28, 2014
ea888ed
doc: Add another restriction to the list of ownership rules.
nham Aug 28, 2014
9fc29f1
rollup merge of #16716 : tshepang/temp
alexcrichton Aug 31, 2014
941b06b
rollup merge of #16721 : tshepang/convenience
alexcrichton Aug 31, 2014
e442406
rollup merge of #16726 : tshepang/consistency
alexcrichton Aug 31, 2014
6b3aa58
rollup merge of #16769 : rgawdzik/abs_doc_addition
alexcrichton Aug 31, 2014
c638ef6
rollup merge of #16778 : jbcrail/fix-issue-15826
alexcrichton Aug 31, 2014
f7f8b20
rollup merge of #16780 : mdinger/marker_types
alexcrichton Aug 31, 2014
c6fd2d3
rollup merge of #16807 : nham/guide_added_ownership_rule
alexcrichton Aug 31, 2014
fe848fc
rollup merge of #16828 : steveklabnik/more_pointer_guide
alexcrichton Aug 31, 2014
8accedd
rollup merge of #16830 : cgaebel/docfix
alexcrichton Aug 31, 2014
c50fffa
rollup merge of #16832 : SebastianZaha/fix-inconsistent-version-numbe…
alexcrichton Aug 31, 2014
89d1c9c
rollup merge of #16833 : SebastianZaha/fix-guide-typo
alexcrichton Aug 31, 2014
0bce667
rollup merge of #16835 : michaelsproul/doc-slice-failure
alexcrichton Aug 31, 2014
d1a5b27
rollup merge of #16839 : treeman/issue-15358
alexcrichton Aug 31, 2014
1bd0df3
rollup merge of #16840 : huonw/feature-has-added
alexcrichton Aug 31, 2014
f584392
rollup merge of #16842 : zsiciarz/master
alexcrichton Aug 31, 2014
daefa70
rollup merge of #16846 : treeman/debug-doc
alexcrichton Aug 31, 2014
963861f
rollup merge of #16849 : nhowell/patch-1
alexcrichton Aug 31, 2014
56a029f
rollup merge of #16852 : steveklabnik/desugar_destructure
alexcrichton Aug 31, 2014
33029c5
rollup merge of #16881 : cmr/guide-typo
alexcrichton Aug 31, 2014
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
25 changes: 25 additions & 0 deletions src/doc/guide-pointers.md
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,31 @@ This part is coming soon.

This part is coming soon.

# Patterns and `ref`

When you're trying to match something that's stored in a pointer, there may be
a situation where matching directly isn't the best option available. Let's see
how to properly handle this:

```{rust,ignore}
fn possibly_print(x: &Option<String>) {
match *x {
// BAD: cannot move out of a `&`
Some(s) => println!("{}", s)

// GOOD: instead take a reference into the memory of the `Option`
Some(ref s) => println!("{}", *s),
None => {}
}
}
```

The `ref s` here means that `s` will be of type `&String`, rather than type
`String`.

This is important when the type you're trying to get access to has a destructor
and you don't want to move it, you just want a reference to it.

# Cheat Sheet

Here's a quick rundown of Rust's pointer types:
Expand Down
61 changes: 33 additions & 28 deletions src/doc/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ $ mv hello_world.rs src/hello_world.rs
```

Cargo expects your source files to live inside a `src` directory. That leaves
the top level for other things, like READMEs, licence information, and anything
the top level for other things, like READMEs, license information, and anything
not related to your code. Cargo helps us keep our projects nice and tidy. A
place for everything, and everything in its place.

Expand All @@ -315,7 +315,7 @@ Put this inside:
[package]

name = "hello_world"
version = "0.1.0"
version = "0.0.1"
authors = [ "Your name <[email protected]>" ]

[[bin]]
Expand Down Expand Up @@ -630,7 +630,7 @@ In Rust, however, using `let` to introduce a binding is _not_ an expression. The
following will produce a compile-time error:

```{ignore}
let x = (let y = 5i); // found `let` in ident position
let x = (let y = 5i); // expected identifier, found keyword `let`
```

The compiler is telling us here that it was expecting to see the beginning of
Expand Down Expand Up @@ -1743,7 +1743,7 @@ fn main() {
}
```

Sometimes, this makes things more readable. Sometimes, less. Use your judgement
Sometimes, this makes things more readable. Sometimes, less. Use your judgment
here.

That's all you need to get basic input from the standard input! It's not too
Expand Down Expand Up @@ -1813,7 +1813,7 @@ Try it out:

```{notrust,ignore}
$ cargo run
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
Running `target/guessing_game`
Hello, world!
```
Expand Down Expand Up @@ -1959,7 +1959,7 @@ Try running our new program a few times:

```{notrust,ignore}
$ cargo run
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
Running `target/guessing_game`
Guess the number!
The secret number is: 7
Expand Down Expand Up @@ -2012,7 +2012,7 @@ And trying it out:

```{notrust,ignore}
$ cargo run
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
Running `target/guessing_game`
Guess the number!
The secret number is: 57
Expand Down Expand Up @@ -2283,7 +2283,7 @@ print an error message and return. Let's give this a shot:

```{notrust,ignore}
$ cargo run
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
Running `target/guessing_game`
Guess the number!
The secret number is: 17
Expand Down Expand Up @@ -2348,7 +2348,7 @@ Let's try it!

```{notrust,ignore}
$ cargo run
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
Running `target/guessing_game`
Guess the number!
The secret number is: 58
Expand Down Expand Up @@ -2425,7 +2425,7 @@ that `return`? If we give a non-number answer, we'll `return` and quit. Observe:

```{notrust,ignore}
$ cargo run
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
Running `target/guessing_game`
Guess the number!
The secret number is: 59
Expand Down Expand Up @@ -2557,7 +2557,7 @@ Now we should be good! Let's try:

```{notrust,ignore}
$ cargo run
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
Running `target/guessing_game`
Guess the number!
The secret number is: 61
Expand Down Expand Up @@ -2659,7 +2659,7 @@ modules, which can contain other modules, as deeply as you'd like.
Note that we haven't mentioned anything about files yet. Rust does not impose a
particular relationship between your filesystem structure and your module
structure. That said, there is a conventional approach to how Rust looks for
modules on the file system, but it's also overrideable.
modules on the file system, but it's also overridable.

Enough talk, let's build something! Let's make a new project called `modules`.

Expand All @@ -2670,10 +2670,10 @@ $ cargo new modules --bin

Let's double check our work by compiling:

```{bash,ignore}
$ cargo build
```{bash,notrust}
$ cargo run
Compiling modules v0.0.1 (file:///home/you/projects/modules)
$ ./target/modules
Running `target/modules`
Hello, world!
```

Expand Down Expand Up @@ -3011,7 +3011,7 @@ markers.
Rust provides six attributes to indicate the stability level of various
parts of your library. The six levels are:

* deprecated: this item should no longer be used. No guarantee of backwards
* deprecated: This item should no longer be used. No guarantee of backwards
compatibility.
* experimental: This item was only recently introduced or is otherwise in a
state of flux. It may change significantly, or even be removed. No guarantee
Expand Down Expand Up @@ -3300,7 +3300,7 @@ To learn more, run the command again with --verbose.

Rust can't find this function. That makes sense, as we didn't write it yet!

In order to share this codes with our tests, we'll need to make a library crate.
In order to share this code with our tests, we'll need to make a library crate.
This is also just good software design: as we mentioned before, it's a good idea
to put most of your functionality into a library crate, and have your executable
crate use that library. This allows for code re-use.
Expand Down Expand Up @@ -3511,7 +3511,7 @@ exporting the name again, somewhere else.

We've now covered the basics of testing. Rust's tools are primitive, but they
work well in the simple cases. There are some Rustaceans working on building
more complicated frameworks on top of all of this, but thery're just starting
more complicated frameworks on top of all of this, but they're just starting
out.

# Pointers
Expand Down Expand Up @@ -3668,15 +3668,20 @@ because it's easy. And if you need precise control over when something is
deallocated, leaving it up to your runtime can make this difficult.

Rust chooses a different path, and that path is called **ownership**. Any
binding that creates a resource is the **owner** of that resource. Being an
owner gives you three privileges, with two restrictions:
binding that creates a resource is the **owner** of that resource.

Being an owner affords you some privileges:

1. You control when that resource is deallocated.
2. You may lend that resource, immutably, to as many borrowers as you'd like.
3. You may lend that resource, mutably, to a single borrower. **BUT**
4. Once you've done so, you may not also lend it out otherwise, mutably or
immutably.
5. You may not lend it out mutably if you're currently lending it to someone.
3. You may lend that resource, mutably, to a single borrower.

But it also comes with some restrictions:

1. If someone is borrowing your resource (either mutably or immutably), you may
not mutate the resource or mutably lend it to someone.
2. If someone is mutably borrowing your resource, you may not lend it out at
all (mutably or immutably) or access it in any way.

What's up with all this 'lending' and 'borrowing'? When you allocate memory,
you get a pointer to that memory. This pointer allows you to manipulate said
Expand Down Expand Up @@ -4063,7 +4068,7 @@ match x {
}
```

If you have a struct, you can desugar it inside of a pattern:
If you have a struct, you can destructure it inside of a pattern:

```{rust}
struct Point {
Expand Down Expand Up @@ -4223,7 +4228,7 @@ don't need to declare one. This is different from named functions, which
default to returning unit (`()`).

There's one big difference between a closure and named functions, and it's in
the name: a function "closes over its environment." What's that mean? It means
the name: a closure "closes over its environment." What's that mean? It means
this:

```{rust}
Expand Down Expand Up @@ -5494,7 +5499,7 @@ fn main() {

Whew! This isn't too terrible. You can see that we still `let x = 5i`,
but then things get a little bit hairy. Three more bindings get set: a
static format string, an argument vector, and the aruments. We then
static format string, an argument vector, and the arguments. We then
invoke the `println_args` function with the generated arguments.

This is the code (well, the full version) that Rust actually compiles. You can
Expand All @@ -5510,7 +5515,7 @@ Guide can help you if you want to write your own.

# Unsafe

Finally, there's one more concept that you should be aware in Rust: `unsafe`.
Finally, there's one more Rust concept that you should be aware of: `unsafe`.
There are two circumstances where Rust's safety provisions don't work well.
The first is when interfacing with C code, and the second is when building
certain kinds of abstractions.
Expand Down
8 changes: 4 additions & 4 deletions src/doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -2215,14 +2215,14 @@ These types help drive the compiler's analysis

* `begin_unwind`
: ___Needs filling in___
* `managed_bound`
: This type implements "managed"
* `no_copy_bound`
: This type does not implement "copy", even if eligible
* `no_send_bound`
: This type does not implement "send", even if eligible
* `no_sync_bound`
: This type does not implement "sync", even if eligible
* `managed_bound`
: This type implements "managed"
* `no_share_bound`
: This type does not implement "share", even if eligible
* `eh_personality`
: ___Needs filling in___
* `exchange_free`
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//!
//! This is the lowest level library through which allocation in Rust can be
//! performed where the allocation is assumed to succeed. This library will
//! trigger a task failure when allocation fails.
//! abort the process when allocation fails.
//!
//! This library, like libcore, is not intended for general usage, but rather as
//! a building block of other libraries. The types and interfaces in this
Expand Down
8 changes: 6 additions & 2 deletions src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ pub trait Signed: Num + Neg<Self> {
/// Computes the absolute value.
///
/// For `f32` and `f64`, `NaN` will be returned if the number is `NaN`.
///
/// For signed integers, `::MIN` will be returned if the number is `::MIN`.
fn abs(&self) -> Self;

/// The positive difference of two numbers.
Expand All @@ -176,7 +178,7 @@ pub trait Signed: Num + Neg<Self> {
/// * `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY`
/// * `NaN` if the number is `NaN`
///
/// For `int`:
/// For signed integers:
///
/// * `0` if the number is zero
/// * `1` if the number is positive
Expand Down Expand Up @@ -272,6 +274,8 @@ signed_float_impl!(f64, f64::NAN, f64::INFINITY, f64::NEG_INFINITY,
/// Computes the absolute value.
///
/// For `f32` and `f64`, `NaN` will be returned if the number is `NaN`
///
/// For signed integers, `::MIN` will be returned if the number is `::MIN`.
#[inline(always)]
pub fn abs<T: Signed>(value: T) -> T {
value.abs()
Expand All @@ -294,7 +298,7 @@ pub fn abs_sub<T: Signed>(x: T, y: T) -> T {
/// * `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY`
/// * `NaN` if the number is `NaN`
///
/// For int:
/// For signed integers:
///
/// * `0` if the number is zero
/// * `1` if the number is positive
Expand Down
Loading