Skip to content

Commit 6ec5586

Browse files
committed
---
yaml --- r: 235246 b: refs/heads/stable c: fd8e175 h: refs/heads/master v: v3
1 parent 3656023 commit 6ec5586

File tree

15 files changed

+294
-68
lines changed

15 files changed

+294
-68
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ refs/heads/tmp: afae2ff723393b3ab4ccffef6ac7c6d1809e2da0
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: f859507de8c410b648d934d8f5ec1c52daac971d
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828
32-
refs/heads/stable: 45fd29621dc0827c12f4534976026f1f8d1676b5
32+
refs/heads/stable: fd8e175c4e39537b16beb40c704a17fcf9796852
3333
refs/tags/1.0.0: 55bd4f8ff2b323f317ae89e254ce87162d52a375
3434
refs/tags/1.1.0: bc3c16f09287e5545c1d3f76b7abd54f2eca868b
3535
refs/tags/1.2.0: f557861f822c34f07270347b94b5280de20a597e

branches/stable/src/doc/trpl/concurrency.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ system is up to the task, and gives you powerful ways to reason about
1010
concurrent code at compile time.
1111

1212
Before we talk about the concurrency features that come with Rust, it's important
13-
to understand something: Rust is low-level enough that all of this is provided
14-
by the standard library, not by the language. This means that if you don't like
15-
some aspect of the way Rust handles concurrency, you can implement an alternative
16-
way of doing things. [mio](https://github.com/carllerche/mio) is a real-world
17-
example of this principle in action.
13+
to understand something: Rust is low-level enough that the vast majority of
14+
this is provided by the standard library, not by the language. This means that
15+
if you don't like some aspect of the way Rust handles concurrency, you can
16+
implement an alternative way of doing things.
17+
[mio](https://github.com/carllerche/mio) is a real-world example of this
18+
principle in action.
1819

1920
## Background: `Send` and `Sync`
2021

branches/stable/src/doc/trpl/lifetimes.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ the lifetime `'a` has snuck in between the `&` and the `mut i32`. We read `&mut
101101
i32` as ‘a mutable reference to an i32’ and `&'a mut i32` as ‘a mutable
102102
reference to an `i32` with the lifetime `'a`’.
103103

104+
# In `struct`s
105+
104106
You’ll also need explicit lifetimes when working with [`struct`][structs]s:
105107

106108
```rust
@@ -137,6 +139,33 @@ x: &'a i32,
137139
uses it. So why do we need a lifetime here? We need to ensure that any reference
138140
to a `Foo` cannot outlive the reference to an `i32` it contains.
139141

142+
## `impl` blocks
143+
144+
Let’s implement a method on `Foo`:
145+
146+
```rust
147+
struct Foo<'a> {
148+
x: &'a i32,
149+
}
150+
151+
impl<'a> Foo<'a> {
152+
fn x(&self) -> &'a i32 { self.x }
153+
}
154+
155+
fn main() {
156+
let y = &5; // this is the same as `let _y = 5; let y = &_y;`
157+
let f = Foo { x: y };
158+
159+
println!("x is: {}", f.x());
160+
}
161+
```
162+
163+
As you can see, we need to declare a lifetime for `Foo` in the `impl` line. We repeat
164+
`'a` twice, just like on functions: `impl<'a>` defines a lifetime `'a`, and `Foo<'a>`
165+
uses it.
166+
167+
## Multiple lifetimes
168+
140169
If you have multiple references, you can use the same lifetime multiple times:
141170

142171
```rust

branches/stable/src/doc/trpl/unsafe.md

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ this, Rust has a keyword, `unsafe`. Code using `unsafe` has less restrictions
88
than normal code does.
99

1010
Let’s go over the syntax, and then we’ll talk semantics. `unsafe` is used in
11-
two contexts. The first one is to mark a function as unsafe:
11+
four contexts. The first one is to mark a function as unsafe:
1212

1313
```rust
1414
unsafe fn danger_will_robinson() {
@@ -27,15 +27,40 @@ unsafe {
2727
}
2828
```
2929

30+
The third is for unsafe traits:
31+
32+
```rust
33+
unsafe trait Scary { }
34+
```
35+
36+
And the fourth is for `impl`ementing one of those traits:
37+
38+
```rust
39+
# unsafe trait Scary { }
40+
unsafe impl Scary for i32 {}
41+
```
42+
3043
It’s important to be able to explicitly delineate code that may have bugs that
3144
cause big problems. If a Rust program segfaults, you can be sure it’s somewhere
3245
in the sections marked `unsafe`.
3346

3447
# What does ‘safe’ mean?
3548

36-
Safe, in the context of Rust, means “doesn’t do anything unsafe.” Easy!
49+
Safe, in the context of Rust, means ‘doesn’t do anything unsafe’. It’s also
50+
important to know that there are certain behaviors that are probably not
51+
desirable in your code, but are expressly _not_ unsafe:
3752

38-
Okay, let’s try again: what is not safe to do? Here’s a list:
53+
* Deadlocks
54+
* Leaks of memory or other resources
55+
* Exiting without calling destructors
56+
* Integer overflow
57+
58+
Rust cannot prevent all kinds of software problems. Buggy code can and will be
59+
written in Rust. These things aren’t great, but they don’t qualify as `unsafe`
60+
specifically.
61+
62+
In addition, the following are all undefined behaviors in Rust, and must be
63+
avoided, even when writing `unsafe` code:
3964

4065
* Data races
4166
* Dereferencing a null/dangling raw pointer
@@ -64,18 +89,6 @@ Okay, let’s try again: what is not safe to do? Here’s a list:
6489
[undef]: http://llvm.org/docs/LangRef.html#undefined-values
6590
[aliasing]: http://llvm.org/docs/LangRef.html#pointer-aliasing-rules
6691

67-
Whew! That’s a bunch of stuff. It’s also important to notice all kinds of
68-
behaviors that are certainly bad, but are expressly _not_ unsafe:
69-
70-
* Deadlocks
71-
* Leaks of memory or other resources
72-
* Exiting without calling destructors
73-
* Integer overflow
74-
75-
Rust cannot prevent all kinds of software problems. Buggy code can and will be
76-
written in Rust. These things aren’t great, but they don’t qualify as `unsafe`
77-
specifically.
78-
7992
# Unsafe Superpowers
8093

8194
In both unsafe functions and unsafe blocks, Rust will let you do three things

branches/stable/src/librustc/middle/stability.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,15 +289,19 @@ impl<'a, 'tcx> Checker<'a, 'tcx> {
289289
if !cross_crate { return }
290290

291291
match *stab {
292-
Some(&Stability { level: attr::Unstable, ref feature, ref reason, .. }) => {
292+
Some(&Stability { level: attr::Unstable, ref feature, ref reason, issue, .. }) => {
293293
self.used_features.insert(feature.clone(), attr::Unstable);
294294

295295
if !self.active_features.contains(feature) {
296-
let msg = match *reason {
296+
let mut msg = match *reason {
297297
Some(ref r) => format!("use of unstable library feature '{}': {}",
298298
&feature, &r),
299299
None => format!("use of unstable library feature '{}'", &feature)
300300
};
301+
if let Some(n) = issue {
302+
use std::fmt::Write;
303+
write!(&mut msg, " (see issue #{})", n).unwrap();
304+
}
301305

302306
emit_feature_err(&self.tcx.sess.parse_sess.span_diagnostic,
303307
&feature, span, &msg);

branches/stable/src/librustc_driver/driver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ pub fn phase_2_configure_and_expand(sess: &Session,
547547
sess.diagnostic()));
548548

549549
krate = time(time_passes, "prelude injection", krate, |krate|
550-
syntax::std_inject::maybe_inject_prelude(krate));
550+
syntax::std_inject::maybe_inject_prelude(&sess.parse_sess, krate));
551551

552552
time(time_passes, "checking that all macro invocations are gone", &krate, |krate|
553553
syntax::ext::expand::check_for_macros(&sess.parse_sess, krate));

branches/stable/src/librustc_typeck/diagnostics.rs

Lines changed: 81 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,6 +1368,62 @@ struct Foo {
13681368
```
13691369
"##,
13701370

1371+
E0128: r##"
1372+
Type parameter defaults can only use parameters that occur before them.
1373+
Erroneous code example:
1374+
1375+
```
1376+
pub struct Foo<T=U, U=()> {
1377+
field1: T,
1378+
filed2: U,
1379+
}
1380+
// error: type parameters with a default cannot use forward declared
1381+
// identifiers
1382+
```
1383+
1384+
Since type parameters are evaluated in-order, you may be able to fix this issue
1385+
by doing:
1386+
1387+
```
1388+
pub struct Foo<U=(), T=U> {
1389+
field1: T,
1390+
filed2: U,
1391+
}
1392+
```
1393+
1394+
Please also verify that this wasn't because of a name-clash and rename the type
1395+
parameter if so.
1396+
"##,
1397+
1398+
E0130: r##"
1399+
You declared a pattern as an argument in a foreign function declaration.
1400+
Erroneous code example:
1401+
1402+
```
1403+
extern {
1404+
fn foo((a, b): (u32, u32)); // error: patterns aren't allowed in foreign
1405+
// function declarations
1406+
}
1407+
```
1408+
1409+
Please replace the pattern argument with a regular one. Example:
1410+
1411+
```
1412+
struct SomeStruct {
1413+
a: u32,
1414+
b: u32,
1415+
}
1416+
1417+
extern {
1418+
fn foo(s: SomeStruct); // ok!
1419+
}
1420+
// or
1421+
extern {
1422+
fn foo(a: (u32, u32)); // ok!
1423+
}
1424+
```
1425+
"##,
1426+
13711427
E0131: r##"
13721428
It is not possible to define `main` with type parameters, or even with function
13731429
parameters. When `main` is present, it must take no arguments and return `()`.
@@ -1382,6 +1438,30 @@ fn(isize, *const *const u8) -> isize
13821438
```
13831439
"##,
13841440

1441+
E0159: r##"
1442+
You tried to use a trait as a struct constructor. Erroneous code example:
1443+
1444+
```
1445+
trait TraitNotAStruct {}
1446+
1447+
TraitNotAStruct{ value: 0 }; // error: use of trait `TraitNotAStruct` as a
1448+
// struct constructor
1449+
```
1450+
1451+
Please verify you used the correct type name or please implement the trait
1452+
on a struct and use this struct constructor. Example:
1453+
1454+
```
1455+
trait TraitNotAStruct {}
1456+
1457+
struct Foo {
1458+
value: i32
1459+
}
1460+
1461+
Foo{ value: 0 }; // ok!
1462+
```
1463+
"##,
1464+
13851465
E0166: r##"
13861466
This error means that the compiler found a return expression in a function
13871467
marked as diverging. A function diverges if it has `!` in the place of the
@@ -1467,6 +1547,7 @@ impl Foo for Bar {
14671547
// the impl
14681548
fn foo() {}
14691549
}
1550+
```
14701551
"##,
14711552

14721553
E0192: r##"
@@ -1978,11 +2059,8 @@ register_diagnostics! {
19782059
E0122,
19792060
E0123,
19802061
E0127,
1981-
E0128,
19822062
E0129,
1983-
E0130,
19842063
E0141,
1985-
E0159,
19862064
E0163,
19872065
E0164,
19882066
E0167,

branches/stable/src/libsyntax/attr.rs

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,8 @@ pub struct Stability {
378378
// The reason for the current stability level. If deprecated, the
379379
// reason for deprecation.
380380
pub reason: Option<InternedString>,
381+
// The relevant rust-lang issue
382+
pub issue: Option<u32>
381383
}
382384

383385
/// The available stability levels.
@@ -412,41 +414,54 @@ fn find_stability_generic<'a,
412414

413415
used_attrs.push(attr);
414416

415-
let (feature, since, reason) = match attr.meta_item_list() {
417+
let (feature, since, reason, issue) = match attr.meta_item_list() {
416418
Some(metas) => {
417419
let mut feature = None;
418420
let mut since = None;
419421
let mut reason = None;
422+
let mut issue = None;
420423
for meta in metas {
421-
if meta.name() == "feature" {
422-
match meta.value_str() {
423-
Some(v) => feature = Some(v),
424-
None => {
425-
diagnostic.span_err(meta.span, "incorrect meta item");
426-
continue 'outer;
424+
match &*meta.name() {
425+
"feature" => {
426+
match meta.value_str() {
427+
Some(v) => feature = Some(v),
428+
None => {
429+
diagnostic.span_err(meta.span, "incorrect meta item");
430+
continue 'outer;
431+
}
427432
}
428433
}
429-
}
430-
if &meta.name()[..] == "since" {
431-
match meta.value_str() {
432-
Some(v) => since = Some(v),
433-
None => {
434-
diagnostic.span_err(meta.span, "incorrect meta item");
435-
continue 'outer;
434+
"since" => {
435+
match meta.value_str() {
436+
Some(v) => since = Some(v),
437+
None => {
438+
diagnostic.span_err(meta.span, "incorrect meta item");
439+
continue 'outer;
440+
}
436441
}
437442
}
438-
}
439-
if &meta.name()[..] == "reason" {
440-
match meta.value_str() {
441-
Some(v) => reason = Some(v),
442-
None => {
443-
diagnostic.span_err(meta.span, "incorrect meta item");
444-
continue 'outer;
443+
"reason" => {
444+
match meta.value_str() {
445+
Some(v) => reason = Some(v),
446+
None => {
447+
diagnostic.span_err(meta.span, "incorrect meta item");
448+
continue 'outer;
449+
}
450+
}
451+
}
452+
"issue" => {
453+
match meta.value_str().and_then(|s| s.parse().ok()) {
454+
Some(v) => issue = Some(v),
455+
None => {
456+
diagnostic.span_err(meta.span, "incorrect meta item");
457+
continue 'outer;
458+
}
445459
}
446460
}
461+
_ => {}
447462
}
448463
}
449-
(feature, since, reason)
464+
(feature, since, reason, issue)
450465
}
451466
None => {
452467
diagnostic.span_err(attr.span(), "incorrect stability attribute type");
@@ -480,7 +495,8 @@ fn find_stability_generic<'a,
480495
feature: feature.unwrap_or(intern_and_get_ident("bogus")),
481496
since: since,
482497
deprecated_since: None,
483-
reason: reason
498+
reason: reason,
499+
issue: issue,
484500
});
485501
} else { // "deprecated"
486502
if deprecated.is_some() {
@@ -504,6 +520,12 @@ fn find_stability_generic<'a,
504520
either stable or unstable attribute");
505521
}
506522
}
523+
} else if stab.as_ref().map_or(false, |s| s.level == Unstable && s.issue.is_none()) {
524+
// non-deprecated unstable items need to point to issues.
525+
// FIXME: uncomment this error
526+
// diagnostic.span_err(item_sp,
527+
// "non-deprecated unstable items need to point \
528+
// to an issue with `issue = \"NNN\"`");
507529
}
508530

509531
(stab, used_attrs)

0 commit comments

Comments
 (0)