Skip to content

Commit ffe8292

Browse files
committed
---
yaml --- r: 212437 b: refs/heads/master c: bd7a6ec h: refs/heads/master i: 212435: 0c12bff v: v3
1 parent a0f6d18 commit ffe8292

Some content is hidden

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

46 files changed

+491
-158
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: cb31373dc26ca447f7a4a142b2ed352677fb55a0
2+
refs/heads/master: bd7a6ec8ecdf0dadd88aae0040a5cf0d00e2f32f
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: ba0e1cd8147d452c356aacb29fb87568ca26f111
55
refs/heads/try: 1864973ae17213c5a58c4dd3f9af6d1b6c7d2e05

trunk/src/doc/grammar.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@ type_path_tail : '<' type_expr [ ',' type_expr ] + '>'
281281
## Macros
282282

283283
```antlr
284-
expr_macro_rules : "macro_rules" '!' ident '(' macro_rule * ')' ;
284+
expr_macro_rules : "macro_rules" '!' ident '(' macro_rule * ')' ';'
285+
| "macro_rules" '!' ident '{' macro_rule * '}' ;
285286
macro_rule : '(' matcher * ')' "=>" '(' transcriber * ')' ';' ;
286287
matcher : '(' matcher * ')' | '[' matcher * ']'
287288
| '{' matcher * '}' | '$' ident ':' ident

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/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: 29 additions & 4 deletions
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
@@ -1180,9 +1180,8 @@ impl str {
11801180
/// matched by a pattern.
11811181
///
11821182
/// The pattern can be a simple `&str`, `char`, or a closure that
1183-
/// determines the split.
1184-
/// Additional libraries might provide more complex patterns like
1185-
/// regular expressions.
1183+
/// determines the split. Additional libraries might provide more complex
1184+
/// patterns like regular expressions.
11861185
///
11871186
/// # Iterator behavior
11881187
///
@@ -1224,6 +1223,32 @@ impl str {
12241223
/// let v: Vec<&str> = "abc1defXghi".split(|c| c == '1' || c == 'X').collect();
12251224
/// assert_eq!(v, ["abc", "def", "ghi"]);
12261225
/// ```
1226+
///
1227+
/// If a string contains multiple contiguous separators, you will end up
1228+
/// with empty strings in the output:
1229+
///
1230+
/// ```
1231+
/// let x = "||||a||b|c".to_string();
1232+
/// let d: Vec<_> = x.split('|').collect();
1233+
///
1234+
/// assert_eq!(d, &["", "", "", "", "a", "", "b", "c"]);
1235+
/// ```
1236+
///
1237+
/// This can lead to possibly surprising behavior when whitespace is used
1238+
/// as the separator. This code is correct:
1239+
///
1240+
/// ```
1241+
/// let x = " a b c".to_string();
1242+
/// let d: Vec<_> = x.split(' ').collect();
1243+
///
1244+
/// assert_eq!(d, &["", "", "", "", "a", "", "b", "c"]);
1245+
/// ```
1246+
///
1247+
/// It does _not_ give you:
1248+
///
1249+
/// ```rust,ignore
1250+
/// assert_eq!(d, &["a", "b", "c"]);
1251+
/// ```
12271252
#[stable(feature = "rust1", since = "1.0.0")]
12281253
pub fn split<'a, P: Pattern<'a>>(&'a self, pat: P) -> Split<'a, P> {
12291254
core_str::StrExt::split(&self[..], pat)

trunk/src/libcollections/vec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,7 @@ impl<T: PartialEq> Vec<T> {
12151215
let ln = self.len();
12161216
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/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/effect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EffectCheckVisitor<'a, 'tcx> {
162162
debug!("effect: unary case, base type is {}",
163163
ppaux::ty_to_string(self.tcx, base_type));
164164
if let ty::ty_ptr(_) = base_type.sty {
165-
self.require_unsafe(expr.span, "dereference of unsafe pointer")
165+
self.require_unsafe(expr.span, "dereference of raw pointer")
166166
}
167167
}
168168
ast::ExprAssign(ref base, _) | ast::ExprAssignOp(_, ref base, _) => {

trunk/src/librustc/middle/infer/freshen.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
104104
}
105105

106106
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
107+
if !ty::type_needs_infer(t) && !ty::type_has_erasable_regions(t) {
108+
return t;
109+
}
110+
107111
let tcx = self.infcx.tcx;
108112

109113
match t.sty {

trunk/src/librustc/middle/infer/higher_ranked/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ pub fn skolemize_late_bound_regions<'a,'tcx,T>(infcx: &InferCtxt<'a,'tcx>,
530530
* details.
531531
*/
532532

533-
let (result, map) = ty::replace_late_bound_regions(infcx.tcx, binder, |br| {
533+
let (result, map) = ty_fold::replace_late_bound_regions(infcx.tcx, binder, |br| {
534534
infcx.region_vars.new_skolemized(br, &snapshot.region_vars_snapshot)
535535
});
536536

trunk/src/librustc/middle/infer/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ use middle::free_region::FreeRegionMap;
2626
use middle::subst;
2727
use middle::subst::Substs;
2828
use middle::ty::{TyVid, IntVid, FloatVid, RegionVid, UnconstrainedNumeric};
29-
use middle::ty::replace_late_bound_regions;
3029
use middle::ty::{self, Ty};
31-
use middle::ty_fold::{TypeFolder, TypeFoldable};
30+
use middle::ty_fold::{self, TypeFolder, TypeFoldable};
3231
use middle::ty_relate::{Relate, RelateResult, TypeRelation};
3332
use rustc_data_structures::unify::{self, UnificationTable};
3433
use std::cell::{RefCell};
@@ -1038,7 +1037,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
10381037
-> (T, FnvHashMap<ty::BoundRegion,ty::Region>)
10391038
where T : TypeFoldable<'tcx> + Repr<'tcx>
10401039
{
1041-
ty::replace_late_bound_regions(
1040+
ty_fold::replace_late_bound_regions(
10421041
self.tcx,
10431042
value,
10441043
|br| self.next_region_var(LateBoundRegion(span, br, lbrct)))

trunk/src/librustc/middle/mem_categorization.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,7 +1410,7 @@ pub enum AliasableReason {
14101410

14111411
impl<'tcx> cmt_<'tcx> {
14121412
pub fn guarantor(&self) -> cmt<'tcx> {
1413-
//! Returns `self` after stripping away any owned pointer derefs or
1413+
//! Returns `self` after stripping away any derefs or
14141414
//! interior content. The return value is basically the `cmt` which
14151415
//! determines how long the value in `self` remains live.
14161416
@@ -1546,7 +1546,7 @@ impl<'tcx> cmt_<'tcx> {
15461546
format!("`Box` content")
15471547
}
15481548
UnsafePtr(..) => {
1549-
format!("dereference of unsafe pointer")
1549+
format!("dereference of raw pointer")
15501550
}
15511551
BorrowedPtr(..) => {
15521552
format!("borrowed content")

trunk/src/librustc/middle/pat_util.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,22 +135,34 @@ pub fn pat_contains_bindings(dm: &DefMap, pat: &ast::Pat) -> bool {
135135
contains_bindings
136136
}
137137

138-
/// Checks if the pattern contains any `ref` or `ref mut` bindings.
139-
pub fn pat_contains_ref_binding(dm: &DefMap, pat: &ast::Pat) -> bool {
140-
let mut result = false;
138+
/// Checks if the pattern contains any `ref` or `ref mut` bindings,
139+
/// and if yes wether its containing mutable ones or just immutables ones.
140+
pub fn pat_contains_ref_binding(dm: &DefMap, pat: &ast::Pat) -> Option<ast::Mutability> {
141+
let mut result = None;
141142
pat_bindings(dm, pat, |mode, _, _, _| {
142143
match mode {
143-
ast::BindingMode::BindByRef(_) => { result = true; }
144+
ast::BindingMode::BindByRef(m) => {
145+
// Pick Mutable as maximum
146+
match result {
147+
None | Some(ast::MutImmutable) => result = Some(m),
148+
_ => (),
149+
}
150+
}
144151
ast::BindingMode::BindByValue(_) => { }
145152
}
146153
});
147154
result
148155
}
149156

150157
/// Checks if the patterns for this arm contain any `ref` or `ref mut`
151-
/// bindings.
152-
pub fn arm_contains_ref_binding(dm: &DefMap, arm: &ast::Arm) -> bool {
153-
arm.pats.iter().any(|pat| pat_contains_ref_binding(dm, pat))
158+
/// bindings, and if yes wether its containing mutable ones or just immutables ones.
159+
pub fn arm_contains_ref_binding(dm: &DefMap, arm: &ast::Arm) -> Option<ast::Mutability> {
160+
arm.pats.iter()
161+
.filter_map(|pat| pat_contains_ref_binding(dm, pat))
162+
.max_by(|m| match *m {
163+
ast::MutMutable => 1,
164+
ast::MutImmutable => 0,
165+
})
154166
}
155167

156168
/// Checks if the pattern contains any patterns that bind something to

0 commit comments

Comments
 (0)