Skip to content

Commit 9d25831

Browse files
committed
---
yaml --- r: 212444 b: refs/heads/master c: db0c1cb h: refs/heads/master v: v3
1 parent c264ce2 commit 9d25831

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+197
-117
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 63da18b269128c6594b0fa60064b187a9b5d0418
2+
refs/heads/master: db0c1cb13c9a1e68c09e2074b6d3a7b38122fb76
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: ba0e1cd8147d452c356aacb29fb87568ca26f111
55
refs/heads/try: 1864973ae17213c5a58c4dd3f9af6d1b6c7d2e05

trunk/src/doc/trpl/enums.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,45 @@ equality yet, but we’ll find out in the [`traits`][traits] section.
6464
[match]: match.html
6565
[if-let]: if-let.html
6666
[traits]: traits.html
67+
68+
# Constructors as functions
69+
70+
An enum’s constructors can also be used like functions. For example:
71+
72+
```rust
73+
# enum Message {
74+
# Write(String),
75+
# }
76+
let m = Message::Write("Hello, world".to_string());
77+
```
78+
79+
Is the same as
80+
81+
```rust
82+
# enum Message {
83+
# Write(String),
84+
# }
85+
fn foo(x: String) -> Message {
86+
Message::Write(x)
87+
}
88+
89+
let x = foo("Hello, world".to_string());
90+
```
91+
92+
This is not immediately useful to us, but when we get to
93+
[`closures`][closures], we’ll talk about passing functions as arguments to
94+
other functions. For example, with [`iterators`][iterators], we can do this
95+
to convert a vector of `String`s into a vector of `Message::Write`s:
96+
97+
```rust
98+
# enum Message {
99+
# Write(String),
100+
# }
101+
102+
let v = vec!["Hello".to_string(), "World".to_string()];
103+
104+
let v1: Vec<Message> = v.into_iter().map(Message::Write).collect();
105+
```
106+
107+
[closures]: closures.html
108+
[iterators]: iterators.html

trunk/src/doc/trpl/ffi.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ However it is often desired that the callback is targeted to a special
238238
Rust object. This could be the object that represents the wrapper for the
239239
respective C object.
240240
241-
This can be achieved by passing an unsafe pointer to the object down to the
241+
This can be achieved by passing an raw pointer to the object down to the
242242
C library. The C library can then include the pointer to the Rust object in
243243
the notification. This will allow the callback to unsafely access the
244244
referenced Rust object.
@@ -370,7 +370,7 @@ On OSX, frameworks behave with the same semantics as a dynamic library.
370370
371371
# Unsafe blocks
372372
373-
Some operations, like dereferencing unsafe pointers or calling functions that have been marked
373+
Some operations, like dereferencing raw pointers or calling functions that have been marked
374374
unsafe are only allowed inside unsafe blocks. Unsafe blocks isolate unsafety and are a promise to
375375
the compiler that the unsafety does not leak out of the block.
376376

trunk/src/doc/trpl/functions.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ an expression, and a `let` can only begin a statement, not an expression.
144144
Note that assigning to an already-bound variable (e.g. `y = 5`) is still an
145145
expression, although its value is not particularly useful. Unlike other
146146
languages where an assignment evaluates to the assigned value (e.g. `5` in the
147-
previous example), in Rust the value of an assignment is an empty tuple `()`:
147+
previous example), in Rust the value of an assignment is an empty tuple `()`
148+
because the assigned value can have [just one owner](ownership.html), and any
149+
other returned value would be too surprising:
148150

149151
```rust
150152
let mut y = 5;

trunk/src/doc/trpl/raw-pointers.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ println!("raw points at {}", *raw);
5252
It gives this error:
5353

5454
```text
55-
error: dereference of unsafe pointer requires unsafe function or block [E0133]
56-
println!("raw points at{}", *raw);
57-
^~~~
55+
error: dereference of raw pointer requires unsafe function or block [E0133]
56+
println!("raw points at {}", *raw);
57+
^~~~
5858
```
5959

6060
When you dereference a raw pointer, you’re taking responsibility that it’s not

trunk/src/doc/trpl/strings.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,30 @@ let dog = hachiko.chars().nth(1); // kinda like hachiko[1]
117117

118118
This emphasizes that we have to go through the whole list of `chars`.
119119

120+
## Slicing
121+
122+
You can get a slice of a string with slicing syntax:
123+
124+
```rust
125+
let dog = "hachiko";
126+
let hachi = &dog[0..5];
127+
```
128+
129+
But note that these are _byte_ offsets, not _character_ offsets. So
130+
this will fail at runtime:
131+
132+
```rust,should_panic
133+
let dog = "忠犬ハチ公";
134+
let hachi = &dog[0..2];
135+
```
136+
137+
with this error:
138+
139+
```text
140+
thread '<main>' panicked at 'index 0 and/or 2 in `忠犬ハチ公` do not lie on
141+
character boundary'
142+
```
143+
120144
## Concatenation
121145

122146
If you have a `String`, you can concatenate a `&str` to the end of it:

trunk/src/liballoc/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
//!
2323
//! ## Boxed values
2424
//!
25-
//! The [`Box`](boxed/index.html) type is the core owned pointer type in Rust.
26-
//! There can only be one owner of a `Box`, and the owner can decide to mutate
27-
//! the contents, which live on the heap.
25+
//! The [`Box`](boxed/index.html) type is a smart pointer type. There can
26+
//! only be one owner of a `Box`, and the owner can decide to mutate the
27+
//! contents, which live on the heap.
2828
//!
2929
//! This type can be sent among threads efficiently as the size of a `Box` value
3030
//! is the same as that of a pointer. Tree-like data structures are often built

trunk/src/libcollections/slice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ impl<T> [T] {
370370
core_slice::SliceExt::get_unchecked_mut(self, index)
371371
}
372372

373-
/// Returns an unsafe pointer to the slice's buffer
373+
/// Returns an raw pointer to the slice's buffer
374374
///
375375
/// The caller must ensure that the slice outlives the pointer this
376376
/// function returns, or else it will end up pointing to garbage.

trunk/src/libcollections/str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ impl str {
525525
core_str::StrExt::as_bytes(&self[..])
526526
}
527527

528-
/// Returns an unsafe pointer to the `&str`'s buffer.
528+
/// Returns a raw pointer to the `&str`'s buffer.
529529
///
530530
/// The caller must ensure that the string outlives this pointer, and
531531
/// that it is not

trunk/src/libcollections/vec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,9 +1213,9 @@ impl<T: PartialEq> Vec<T> {
12131213
// Duplicate, advance r. End of vec. Truncate to w.
12141214

12151215
let ln = self.len();
1216-
if ln < 1 { return; }
1216+
if ln <= 1 { return; }
12171217

1218-
// Avoid bounds checks by using unsafe pointers.
1218+
// Avoid bounds checks by using raw pointers.
12191219
let p = self.as_mut_ptr();
12201220
let mut r: usize = 1;
12211221
let mut w: usize = 1;

trunk/src/libcore/intrinsics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use marker::Sized;
4646

4747
extern "rust-intrinsic" {
4848

49-
// NB: These intrinsics take unsafe pointers because they mutate aliased
49+
// NB: These intrinsics take raw pointers because they mutate aliased
5050
// memory, which is not valid for either `&` or `&mut`.
5151

5252
pub fn atomic_cxchg<T>(dst: *mut T, old: T, src: T) -> T;

trunk/src/libcore/marker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ macro_rules! impls{
357357
/// struct is dropped, it may in turn drop one or more instances of
358358
/// the type `T`, though that may not be apparent from the other
359359
/// structure of the type itself. This is commonly necessary if the
360-
/// structure is using an unsafe pointer like `*mut T` whose referent
360+
/// structure is using a raw pointer like `*mut T` whose referent
361361
/// may be dropped when the type is dropped, as a `*mut T` is
362362
/// otherwise not treated as owned.
363363
///

trunk/src/libcore/ptr.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010

1111
// FIXME: talk about offset, copy_memory, copy_nonoverlapping_memory
1212

13-
//! Operations on unsafe pointers, `*const T`, and `*mut T`.
13+
//! Operations on raw pointers, `*const T`, and `*mut T`.
1414
//!
15-
//! Working with unsafe pointers in Rust is uncommon,
15+
//! Working with raw pointers in Rust is uncommon,
1616
//! typically limited to a few patterns.
1717
//!
1818
//! Use the `null` function to create null pointers, and the `is_null` method
1919
//! of the `*const T` type to check for null. The `*const T` type also defines
2020
//! the `offset` method, for pointer math.
2121
//!
22-
//! # Common ways to create unsafe pointers
22+
//! # Common ways to create raw pointers
2323
//!
2424
//! ## 1. Coerce a reference (`&T`) or mutable reference (`&mut T`).
2525
//!
@@ -86,7 +86,7 @@
8686
//!
8787
//! Usually you wouldn't literally use `malloc` and `free` from Rust,
8888
//! but C APIs hand out a lot of pointers generally, so are a common source
89-
//! of unsafe pointers in Rust.
89+
//! of raw pointers in Rust.
9090
9191
#![stable(feature = "rust1", since = "1.0.0")]
9292
#![doc(primitive = "pointer")]

trunk/src/libsyntax/ast_map/blocks.rs renamed to trunk/src/librustc/ast_map/blocks.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,12 @@
2323
2424
pub use self::Code::*;
2525

26-
use abi;
27-
use ast::{Block, FnDecl, NodeId};
28-
use ast;
29-
use ast_map::Node;
30-
use ast_map;
31-
use codemap::Span;
32-
use visit;
26+
use ast_map::{self, Node};
27+
use syntax::abi;
28+
use syntax::ast::{Block, FnDecl, NodeId};
29+
use syntax::ast;
30+
use syntax::codemap::Span;
31+
use syntax::visit;
3332

3433
/// An FnLikeNode is a Node that is like a fn, in that it has a decl
3534
/// and a body (as well as a NodeId, a span, etc).

trunk/src/libsyntax/ast_map/mod.rs renamed to trunk/src/librustc/ast_map/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ pub use self::Node::*;
1212
pub use self::PathElem::*;
1313
use self::MapEntry::*;
1414

15-
use abi;
16-
use ast::*;
17-
use ast_util;
18-
use codemap::{DUMMY_SP, Span, Spanned};
19-
use fold::Folder;
20-
use parse::token;
21-
use print::pprust;
22-
use visit::{self, Visitor};
15+
use syntax::abi;
16+
use syntax::ast::*;
17+
use syntax::ast_util;
18+
use syntax::codemap::{DUMMY_SP, Span, Spanned};
19+
use syntax::fold::Folder;
20+
use syntax::parse::token;
21+
use syntax::print::pprust;
22+
use syntax::visit::{self, Visitor};
2323

2424
use arena::TypedArena;
2525
use std::cell::RefCell;

trunk/src/librustc/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ pub mod back {
9292
pub use rustc_back::x86_64;
9393
}
9494

95+
pub mod ast_map;
96+
9597
pub mod middle {
9698
pub mod astconv_util;
9799
pub mod astencode;

trunk/src/librustc/metadata/csearch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
// Searching for information from the cstore
1212

13+
use ast_map;
1314
use metadata::common::*;
1415
use metadata::cstore;
1516
use metadata::decoder;
@@ -20,7 +21,6 @@ use rbml;
2021
use rbml::reader;
2122
use std::rc::Rc;
2223
use syntax::ast;
23-
use syntax::ast_map;
2424
use syntax::attr;
2525
use syntax::attr::AttrMetaMethods;
2626
use syntax::diagnostic::expect;

trunk/src/librustc/metadata/decoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
pub use self::DefLike::*;
1616
use self::Family::*;
1717

18+
use ast_map;
1819
use back::svh::Svh;
1920
use metadata::cstore::crate_metadata;
2021
use metadata::common::*;
@@ -44,7 +45,6 @@ use std::str;
4445
use rbml::reader;
4546
use rbml;
4647
use serialize::Decodable;
47-
use syntax::ast_map;
4848
use syntax::attr;
4949
use syntax::parse::token::{IdentInterner, special_idents};
5050
use syntax::parse::token;

trunk/src/librustc/metadata/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
pub use self::InlinedItemRef::*;
1717

18+
use ast_map::{self, LinkedPath, PathElem, PathElems};
1819
use back::svh::Svh;
1920
use session::config;
2021
use metadata::common::*;
@@ -34,7 +35,6 @@ use std::io::prelude::*;
3435
use std::io::{Cursor, SeekFrom};
3536
use syntax::abi;
3637
use syntax::ast::{self, DefId, NodeId};
37-
use syntax::ast_map::{self, LinkedPath, PathElem, PathElems};
3838
use syntax::ast_util::*;
3939
use syntax::ast_util;
4040
use syntax::attr;

trunk/src/librustc/middle/astencode.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// FIXME: remove this after snapshot, and Results are handled
1313
#![allow(unused_must_use)]
1414

15+
use ast_map;
1516
use metadata::common as c;
1617
use metadata::cstore as cstore;
1718
use session::Session;
@@ -32,7 +33,7 @@ use middle::subst::VecPerParamSpace;
3233
use middle::ty::{self, Ty, MethodCall, MethodCallee, MethodOrigin};
3334
use util::ppaux::ty_to_string;
3435

35-
use syntax::{ast, ast_map, ast_util, codemap, fold};
36+
use syntax::{ast, ast_util, codemap, fold};
3637
use syntax::codemap::Span;
3738
use syntax::fold::Folder;
3839
use syntax::parse::token;

trunk/src/librustc/middle/cfg/graphviz.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use std::borrow::IntoCow;
1717
use graphviz as dot;
1818

1919
use syntax::ast;
20-
use syntax::ast_map;
2120

21+
use ast_map;
2222
use middle::cfg;
2323

2424
pub type Node<'a> = (cfg::CFGIndex, &'a cfg::CFGNode);

trunk/src/librustc/middle/check_const.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
//
1414
// - For each *mutable* static item, it checks that its **type**:
1515
// - doesn't have a destructor
16-
// - doesn't own an owned pointer
16+
// - doesn't own a box
1717
//
1818
// - For each *immutable* static item, it checks that its **value**:
19-
// - doesn't own owned, managed pointers
19+
// - doesn't own a box
2020
// - doesn't contain a struct literal or a call to an enum variant / struct constructor where
2121
// - the type of the struct/enum has a dtor
2222
//

trunk/src/librustc/middle/check_static_recursion.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
// This compiler pass detects static items that refer to themselves
1212
// recursively.
1313

14+
use ast_map;
1415
use session::Session;
1516
use middle::def::{DefStatic, DefConst, DefAssociatedConst, DefMap};
1617

17-
use syntax::ast;
18-
use syntax::{ast_util, ast_map};
18+
use syntax::{ast, ast_util};
1919
use syntax::codemap::Span;
2020
use syntax::visit::Visitor;
2121
use syntax::visit;

trunk/src/librustc/middle/const_eval.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ pub use self::const_val::*;
1515

1616
use self::ErrKind::*;
1717

18+
use ast_map;
19+
use ast_map::blocks::FnLikeNode;
1820
use metadata::csearch;
1921
use middle::{astencode, def, infer, subst, traits};
2022
use middle::pat_util::def_to_path;
@@ -24,13 +26,12 @@ use util::num::ToPrimitive;
2426
use util::ppaux::Repr;
2527

2628
use syntax::ast::{self, Expr};
27-
use syntax::ast_map::blocks::FnLikeNode;
2829
use syntax::ast_util;
2930
use syntax::codemap::Span;
3031
use syntax::feature_gate;
3132
use syntax::parse::token::InternedString;
3233
use syntax::ptr::P;
33-
use syntax::{ast_map, codemap, visit};
34+
use syntax::{codemap, visit};
3435

3536
use std::borrow::{Cow, IntoCow};
3637
use std::num::wrapping::OverflowingOps;

0 commit comments

Comments
 (0)