Skip to content

Commit 276f26a

Browse files
committed
---
yaml --- r: 235257 b: refs/heads/stable c: 80f9d93 h: refs/heads/master i: 235255: fe59a62 v: v3
1 parent 77694d7 commit 276f26a

File tree

26 files changed

+404
-109
lines changed

26 files changed

+404
-109
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: 8d9f1bab756720fce7337d3d8cc5960b036a266e
32+
refs/heads/stable: 80f9d935859a8ae783fdc85656fe498a59e8ebc2
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/complement-design-faq.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ Second, it makes cost explicit. In general, the only safe way to have a
9999
non-exhaustive match would be to panic the thread if nothing is matched, though
100100
it could fall through if the type of the `match` expression is `()`. This sort
101101
of hidden cost and special casing is against the language's philosophy. It's
102-
easy to ignore certain cases by using the `_` wildcard:
102+
easy to ignore all unspecified cases by using the `_` wildcard:
103103

104104
```rust,ignore
105105
match val.do_something() {

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/libcore/fmt/mod.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ impl<'a> Display for Arguments<'a> {
273273
///
274274
/// Generally speaking, you should just `derive` a `Debug` implementation.
275275
///
276+
/// When used with the alternate format specifier `#?`, the output is pretty-printed.
277+
///
276278
/// For more information on formatters, see [the module-level documentation][module].
277279
///
278280
/// [module]: ../index.html
@@ -314,13 +316,42 @@ impl<'a> Display for Arguments<'a> {
314316
/// println!("The origin is: {:?}", origin);
315317
/// ```
316318
///
319+
/// This outputs:
320+
///
321+
/// ```text
322+
/// The origin is: Point { x: 0, y: 0 }
323+
/// ```
324+
///
317325
/// There are a number of `debug_*` methods on `Formatter` to help you with manual
318326
/// implementations, such as [`debug_struct`][debug_struct].
319327
///
320328
/// `Debug` implementations using either `derive` or the debug builder API
321329
/// on `Formatter` support pretty printing using the alternate flag: `{:#?}`.
322330
///
323331
/// [debug_struct]: ../std/fmt/struct.Formatter.html#method.debug_struct
332+
///
333+
/// Pretty printing with `#?`:
334+
///
335+
/// ```
336+
/// #[derive(Debug)]
337+
/// struct Point {
338+
/// x: i32,
339+
/// y: i32,
340+
/// }
341+
///
342+
/// let origin = Point { x: 0, y: 0 };
343+
///
344+
/// println!("The origin is: {:#?}", origin);
345+
/// ```
346+
///
347+
/// This outputs:
348+
///
349+
/// ```text
350+
/// The origin is: Point {
351+
/// x: 0,
352+
/// y: 0
353+
/// }
354+
/// ```
324355
#[stable(feature = "rust1", since = "1.0.0")]
325356
#[rustc_on_unimplemented = "`{Self}` cannot be formatted using `:?`; if it is \
326357
defined in your crate, add `#[derive(Debug)]` or \
@@ -379,6 +410,8 @@ pub trait Display {
379410
///
380411
/// The `Octal` trait should format its output as a number in base-8.
381412
///
413+
/// The alternate flag, `#`, adds a `0o` in front of the output.
414+
///
382415
/// For more information on formatters, see [the module-level documentation][module].
383416
///
384417
/// [module]: ../index.html
@@ -391,6 +424,7 @@ pub trait Display {
391424
/// let x = 42; // 42 is '52' in octal
392425
///
393426
/// assert_eq!(format!("{:o}", x), "52");
427+
/// assert_eq!(format!("{:#o}", x), "0o52");
394428
/// ```
395429
///
396430
/// Implementing `Octal` on a type:
@@ -423,6 +457,8 @@ pub trait Octal {
423457
///
424458
/// The `Binary` trait should format its output as a number in binary.
425459
///
460+
/// The alternate flag, `#`, adds a `0b` in front of the output.
461+
///
426462
/// For more information on formatters, see [the module-level documentation][module].
427463
///
428464
/// [module]: ../index.html
@@ -435,6 +471,7 @@ pub trait Octal {
435471
/// let x = 42; // 42 is '101010' in binary
436472
///
437473
/// assert_eq!(format!("{:b}", x), "101010");
474+
/// assert_eq!(format!("{:#b}", x), "0b101010");
438475
/// ```
439476
///
440477
/// Implementing `Binary` on a type:
@@ -468,6 +505,8 @@ pub trait Binary {
468505
/// The `LowerHex` trait should format its output as a number in hexidecimal, with `a` through `f`
469506
/// in lower case.
470507
///
508+
/// The alternate flag, `#`, adds a `0x` in front of the output.
509+
///
471510
/// For more information on formatters, see [the module-level documentation][module].
472511
///
473512
/// [module]: ../index.html
@@ -480,6 +519,7 @@ pub trait Binary {
480519
/// let x = 42; // 42 is '2a' in hex
481520
///
482521
/// assert_eq!(format!("{:x}", x), "2a");
522+
/// assert_eq!(format!("{:#x}", x), "0x2a");
483523
/// ```
484524
///
485525
/// Implementing `LowerHex` on a type:
@@ -513,6 +553,8 @@ pub trait LowerHex {
513553
/// The `UpperHex` trait should format its output as a number in hexidecimal, with `A` through `F`
514554
/// in upper case.
515555
///
556+
/// The alternate flag, `#`, adds a `0x` in front of the output.
557+
///
516558
/// For more information on formatters, see [the module-level documentation][module].
517559
///
518560
/// [module]: ../index.html
@@ -525,6 +567,7 @@ pub trait LowerHex {
525567
/// let x = 42; // 42 is '2A' in hex
526568
///
527569
/// assert_eq!(format!("{:X}", x), "2A");
570+
/// assert_eq!(format!("{:#X}", x), "0x2A");
528571
/// ```
529572
///
530573
/// Implementing `UpperHex` on a type:

branches/stable/src/librustc/diagnostics.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1237,5 +1237,6 @@ register_diagnostics! {
12371237
E0314, // closure outlives stack frame
12381238
E0315, // cannot invoke closure outside of its lifetime
12391239
E0316, // nested quantification of lifetimes
1240-
E0370 // discriminant overflow
1240+
E0370, // discriminant overflow
1241+
E0400 // overloaded derefs are not allowed in constants
12411242
}

branches/stable/src/librustc/middle/cfg/construct.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
332332
}
333333

334334
ast::ExprIndex(ref l, ref r) |
335-
ast::ExprBinary(_, ref l, ref r) if self.is_method_call(expr) => {
335+
ast::ExprBinary(_, ref l, ref r) if self.tcx.is_method_call(expr.id) => {
336336
self.call(expr, pred, &**l, Some(&**r).into_iter())
337337
}
338338

@@ -342,7 +342,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
342342
self.straightline(expr, pred, fields)
343343
}
344344

345-
ast::ExprUnary(_, ref e) if self.is_method_call(expr) => {
345+
ast::ExprUnary(_, ref e) if self.tcx.is_method_call(expr.id) => {
346346
self.call(expr, pred, &**e, None::<ast::Expr>.iter())
347347
}
348348

@@ -631,9 +631,4 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
631631
}
632632
}
633633
}
634-
635-
fn is_method_call(&self, expr: &ast::Expr) -> bool {
636-
let method_call = ty::MethodCall::expr(expr.id);
637-
self.tcx.tables.borrow().method_map.contains_key(&method_call)
638-
}
639634
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
405405

406406
let node_ty = self.tcx.node_id_to_type(ex.id);
407407
check_expr(self, ex, node_ty);
408+
check_adjustments(self, ex);
408409

409410
// Special-case some expressions to avoid certain flags bubbling up.
410411
match ex.node {
@@ -777,6 +778,25 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
777778
}
778779
}
779780

781+
/// Check the adjustments of an expression
782+
fn check_adjustments<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>, e: &ast::Expr) {
783+
match v.tcx.tables.borrow().adjustments.get(&e.id) {
784+
None | Some(&ty::AdjustReifyFnPointer) | Some(&ty::AdjustUnsafeFnPointer) => {}
785+
Some(&ty::AdjustDerefRef(ty::AutoDerefRef { autoderefs, .. })) => {
786+
if (0..autoderefs as u32).any(|autoderef| {
787+
v.tcx.is_overloaded_autoderef(e.id, autoderef)
788+
}) {
789+
v.add_qualif(ConstQualif::NOT_CONST);
790+
if v.mode != Mode::Var {
791+
span_err!(v.tcx.sess, e.span, E0400,
792+
"user-defined dereference operators are not allowed in {}s",
793+
v.msg());
794+
}
795+
}
796+
}
797+
}
798+
}
799+
780800
pub fn check_crate(tcx: &ty::ctxt) {
781801
visit::walk_crate(&mut CheckCrateVisitor {
782802
tcx: tcx,

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/middle/ty.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6631,6 +6631,11 @@ impl<'tcx> ctxt<'tcx> {
66316631
self.tables.borrow().method_map.contains_key(&MethodCall::expr(expr_id))
66326632
}
66336633

6634+
pub fn is_overloaded_autoderef(&self, expr_id: ast::NodeId, autoderefs: u32) -> bool {
6635+
self.tables.borrow().method_map.contains_key(&MethodCall::autoderef(expr_id,
6636+
autoderefs))
6637+
}
6638+
66346639
pub fn upvar_capture(&self, upvar_id: ty::UpvarId) -> Option<ty::UpvarCapture> {
66356640
Some(self.tables.borrow().upvar_capture_map.get(&upvar_id).unwrap().clone())
66366641
}

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));

0 commit comments

Comments
 (0)