Skip to content

Commit 102ab57

Browse files
committed
Auto merge of #21582 - FlaPer87:rollup, r=brson
- Successful merges: #21108, #21445, #21498, #21504, #21532, #21535, #21539, #21540, #21541, #21550, #21560, #21573, #21579 - Failed merges:
2 parents 0899807 + 7e83e46 commit 102ab57

File tree

16 files changed

+257
-215
lines changed

16 files changed

+257
-215
lines changed

configure

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ need_ok() {
2828

2929
need_cmd() {
3030
if command -v $1 >/dev/null 2>&1
31-
then msg "found $1"
32-
else err "need $1"
31+
then msg "found program $1"
32+
else err "need program $1"
3333
fi
3434
}
3535

@@ -340,6 +340,7 @@ need_cmd date
340340
need_cmd tr
341341
need_cmd sed
342342
need_cmd file
343+
need_cmd make
343344

344345
msg "inspecting environment"
345346

mk/main.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ CFG_PACKAGE_VERS=$(CFG_RELEASE_NUM)
3030
CFG_DISABLE_UNSTABLE_FEATURES=1
3131
endif
3232
ifeq ($(CFG_RELEASE_CHANNEL),beta)
33-
CFG_RELEASE=$(CFG_RELEASE_NUM)-beta(CFG_PRERELEASE_VERSION)
34-
CFG_PACKAGE_VERS=$(CFG_RELEASE_NUM)-beta(CFG_PRERELEASE_VERSION)
33+
CFG_RELEASE=$(CFG_RELEASE_NUM)-beta$(CFG_PRERELEASE_VERSION)
34+
CFG_PACKAGE_VERS=$(CFG_RELEASE_NUM)-beta$(CFG_PRERELEASE_VERSION)
3535
CFG_DISABLE_UNSTABLE_FEATURES=1
3636
endif
3737
ifeq ($(CFG_RELEASE_CHANNEL),nightly)

src/compiletest/common.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,20 @@ pub use self::Mode::*;
1212
use std::fmt;
1313
use std::str::FromStr;
1414

15+
#[cfg(stage0)] // NOTE: remove impl after snapshot
16+
#[derive(Clone, PartialEq, Show)]
17+
pub enum Mode {
18+
CompileFail,
19+
RunFail,
20+
RunPass,
21+
RunPassValgrind,
22+
Pretty,
23+
DebugInfoGdb,
24+
DebugInfoLldb,
25+
Codegen
26+
}
27+
28+
#[cfg(not(stage0))] // NOTE: remove cfg after snapshot
1529
#[derive(Clone, PartialEq, Debug)]
1630
pub enum Mode {
1731
CompileFail,
@@ -24,6 +38,7 @@ pub enum Mode {
2438
Codegen
2539
}
2640

41+
2742
impl Copy for Mode {}
2843

2944
impl FromStr for Mode {

src/doc/reference.md

Lines changed: 2 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -2291,136 +2291,7 @@ The name `str_eq` has a special meaning to the Rust compiler, and the presence
22912291
of this definition means that it will use this definition when generating calls
22922292
to the string equality function.
22932293

2294-
A complete list of the built-in language items follows:
2295-
2296-
#### Built-in Traits
2297-
2298-
* `copy`
2299-
: Types that do not move ownership when used by-value.
2300-
* `drop`
2301-
: Have destructors.
2302-
* `send`
2303-
: Able to be sent across thread boundaries.
2304-
* `sized`
2305-
: Has a size known at compile time.
2306-
* `sync`
2307-
: Able to be safely shared between threads when aliased.
2308-
2309-
#### Operators
2310-
2311-
These language items are traits:
2312-
2313-
* `add`
2314-
: Elements can be added (for example, integers and floats).
2315-
* `sub`
2316-
: Elements can be subtracted.
2317-
* `mul`
2318-
: Elements can be multiplied.
2319-
* `div`
2320-
: Elements have a division operation.
2321-
* `rem`
2322-
: Elements have a remainder operation.
2323-
* `neg`
2324-
: Elements can be negated arithmetically.
2325-
* `not`
2326-
: Elements can be negated logically.
2327-
* `bitxor`
2328-
: Elements have an exclusive-or operation.
2329-
* `bitand`
2330-
: Elements have a bitwise `and` operation.
2331-
* `bitor`
2332-
: Elements have a bitwise `or` operation.
2333-
* `shl`
2334-
: Elements have a left shift operation.
2335-
* `shr`
2336-
: Elements have a right shift operation.
2337-
* `index`
2338-
: Elements can be indexed.
2339-
* `index_mut`
2340-
: ___Needs filling in___
2341-
* `eq`
2342-
: Elements can be compared for equality.
2343-
* `ord`
2344-
: Elements have a partial ordering.
2345-
* `deref`
2346-
: `*` can be applied, yielding a reference to another type.
2347-
* `deref_mut`
2348-
: `*` can be applied, yielding a mutable reference to another type.
2349-
2350-
These are functions:
2351-
2352-
* `fn`
2353-
: ___Needs filling in___
2354-
* `fn_mut`
2355-
: ___Needs filling in___
2356-
* `fn_once`
2357-
: ___Needs filling in___
2358-
* `str_eq`
2359-
: Compare two strings (`&str`) for equality.
2360-
* `strdup_uniq`
2361-
: Return a new unique string
2362-
containing a copy of the contents of a unique string.
2363-
2364-
#### Types
2365-
2366-
* `type_id`
2367-
: The type returned by the `type_id` intrinsic.
2368-
* `unsafe`
2369-
: A type whose contents can be mutated through an immutable reference.
2370-
2371-
#### Marker types
2372-
2373-
These types help drive the compiler's analysis
2374-
2375-
* `begin_unwind`
2376-
: ___Needs filling in___
2377-
* `no_copy_bound`
2378-
: This type does not implement "copy", even if eligible.
2379-
* `eh_personality`
2380-
: ___Needs filling in___
2381-
* `exchange_free`
2382-
: Free memory that was allocated on the exchange heap.
2383-
* `exchange_malloc`
2384-
: Allocate memory on the exchange heap.
2385-
* `closure_exchange_malloc`
2386-
: ___Needs filling in___
2387-
* `panic`
2388-
: Abort the program with an error.
2389-
* `fail_bounds_check`
2390-
: Abort the program with a bounds check error.
2391-
* `free`
2392-
: Free memory that was allocated on the managed heap.
2393-
* `gc`
2394-
: ___Needs filling in___
2395-
* `exchange_heap`
2396-
: ___Needs filling in___
2397-
* `iterator`
2398-
: ___Needs filling in___
2399-
* `contravariant_lifetime`
2400-
: The lifetime parameter should be considered contravariant.
2401-
* `covariant_lifetime`
2402-
: The lifetime parameter should be considered covariant.
2403-
* `invariant_lifetime`
2404-
: The lifetime parameter should be considered invariant.
2405-
* `malloc`
2406-
: Allocate memory on the managed heap.
2407-
* `owned_box`
2408-
: ___Needs filling in___
2409-
* `stack_exhausted`
2410-
: ___Needs filling in___
2411-
* `start`
2412-
: ___Needs filling in___
2413-
* `contravariant_type`
2414-
: The type parameter should be considered contravariant.
2415-
* `covariant_type`
2416-
: The type parameter should be considered covariant.
2417-
* `invariant_type`
2418-
: The type parameter should be considered invariant.
2419-
* `ty_desc`
2420-
: ___Needs filling in___
2421-
2422-
> **Note:** This list is likely to become out of date. We should auto-generate
2423-
> it from `librustc/middle/lang_items.rs`.
2294+
A complete list of the built-in language items will be added in the future.
24242295

24252296
### Inline attributes
24262297

@@ -2652,9 +2523,7 @@ The currently implemented features of the reference compiler are:
26522523
declare a `static` as being unique per-thread leveraging
26532524
LLVM's implementation which works in concert with the kernel
26542525
loader and dynamic linker. This is not necessarily available
2655-
on all platforms, and usage of it is discouraged (rust
2656-
focuses more on thread-local data instead of thread-local
2657-
data).
2526+
on all platforms, and usage of it is discouraged.
26582527

26592528
* `trace_macros` - Allows use of the `trace_macros` macro, which is a nasty
26602529
hack that will certainly be removed.

src/doc/trpl/installing-rust.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ If not, there are a number of places where you can get help. The easiest is
8383
you can access through
8484
[Mibbit](http://chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust). Click
8585
that link, and you'll be chatting with other Rustaceans (a silly nickname we
86-
call ourselves), and we can help you out. Other great resources include [our
87-
forum](http://discuss.rust-lang.org/), [the /r/rust
88-
subreddit](http://www.reddit.com/r/rust), and [Stack
86+
call ourselves), and we can help you out. Other great resources include [the
87+
/r/rust subreddit](http://www.reddit.com/r/rust), and [Stack
8988
Overflow](http://stackoverflow.com/questions/tagged/rust).

src/doc/trpl/method-syntax.md

Lines changed: 112 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ x.foo().bar().baz();
1818
Luckily, as you may have guessed with the leading question, you can! Rust provides
1919
the ability to use this *method call syntax* via the `impl` keyword.
2020

21+
## Method calls
22+
2123
Here's how it works:
2224

2325
```{rust}
@@ -56,11 +58,56 @@ other parameter. Because we know it's a `Circle`, we can access the `radius`
5658
just like we would with any other struct. An import of π and some
5759
multiplications later, and we have our area.
5860

61+
## Chaining method calls
62+
63+
So, now we know how to call a method, such as `foo.bar()`. But what about our
64+
original example, `foo.bar().baz()`? This is called 'method chaining', and we
65+
can do it by returning `self`.
66+
67+
```
68+
struct Circle {
69+
x: f64,
70+
y: f64,
71+
radius: f64,
72+
}
73+
74+
impl Circle {
75+
fn area(&self) -> f64 {
76+
std::f64::consts::PI * (self.radius * self.radius)
77+
}
78+
79+
fn grow(&self) -> Circle {
80+
Circle { x: self.x, y: self.y, radius: (self.radius * 10.0) }
81+
}
82+
}
83+
84+
fn main() {
85+
let c = Circle { x: 0.0, y: 0.0, radius: 2.0 };
86+
println!("{}", c.area());
87+
88+
let d = c.grow().area();
89+
println!("{}", d);
90+
}
91+
```
92+
93+
Check the return type:
94+
95+
```
96+
# struct Circle;
97+
# impl Circle {
98+
fn grow(&self) -> Circle {
99+
# Circle } }
100+
```
101+
102+
We just say we're returning a `Circle`. With this, we can grow a new circle
103+
that's twice as big as the old one.
104+
105+
## Static methods
106+
59107
You can also define methods that do not take a `self` parameter. Here's a
60108
pattern that's very common in Rust code:
61109

62-
```{rust}
63-
# #![allow(non_shorthand_field_patterns)]
110+
```
64111
struct Circle {
65112
x: f64,
66113
y: f64,
@@ -86,3 +133,66 @@ This *static method* builds a new `Circle` for us. Note that static methods
86133
are called with the `Struct::method()` syntax, rather than the `ref.method()`
87134
syntax.
88135

136+
## Builder Pattern
137+
138+
Let's say that we want our users to be able to create Circles, but we will
139+
allow them to only set the properties they care about. Otherwise, the `x`
140+
and `y` attributes will be `0.0`, and the `radius` will be `1.0`. Rust doesn't
141+
have method overloading, named arguments, or variable arguments. We employ
142+
the builder pattern instead. It looks like this:
143+
144+
```
145+
struct Circle {
146+
x: f64,
147+
y: f64,
148+
radius: f64,
149+
}
150+
151+
impl Circle {
152+
fn area(&self) -> f64 {
153+
std::f64::consts::PI * (self.radius * self.radius)
154+
}
155+
}
156+
157+
struct CircleBuilder {
158+
coordinate: f64,
159+
radius: f64,
160+
}
161+
162+
impl CircleBuilder {
163+
fn new() -> CircleBuilder {
164+
CircleBuilder { coordinate: 0.0, radius: 0.0, }
165+
}
166+
167+
fn coordinate(&mut self, coordinate: f64) -> &mut CircleBuilder {
168+
self.coordinate = coordinate;
169+
self
170+
}
171+
172+
fn radius(&mut self, radius: f64) -> &mut CircleBuilder {
173+
self.radius = radius;
174+
self
175+
}
176+
177+
fn finalize(&self) -> Circle {
178+
Circle { x: self.coordinate, y: self.coordinate, radius: self.radius }
179+
}
180+
}
181+
182+
fn main() {
183+
let c = CircleBuilder::new()
184+
.coordinate(10.0)
185+
.radius(5.0)
186+
.finalize();
187+
188+
189+
println!("area: {}", c.area());
190+
}
191+
```
192+
193+
What we've done here is make another struct, `CircleBuilder`. We've defined our
194+
builder methods on it. We've also defined our `area()` method on `Circle`. We
195+
also made one more method on `CircleBuilder`: `finalize()`. This method creates
196+
our final `Circle` from the builder. Now, we've used the type system to enforce
197+
our concerns: we can use the methods on `CircleBuilder` to constrain making
198+
`Circle`s in any way we choose.

0 commit comments

Comments
 (0)