Skip to content

Commit 8c3728f

Browse files
committed
auto merge of #5125 : nikomatsakis/rust/issue-4846-lifetime-defaults, r=nikomatsakis
Work towards #4846. - Institute new region defaults where all omitted regions get a fresh lifetime. - Require explicit region names except in functions. - Fix a bug in region parameterization inference. I've been putting this off because it will not be important when we remove RP inference in favor of explicit declarations, but then it was blocking this patch. r? @pcwalton
2 parents 0262387 + 078fd23 commit 8c3728f

File tree

128 files changed

+686
-601
lines changed

Some content is hidden

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

128 files changed

+686
-601
lines changed

doc/rust.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,22 +1144,23 @@ Constants are declared with the `const` keyword.
11441144
A constant item must have an expression giving its definition.
11451145
The definition expression of a constant is limited to expression forms that can be evaluated at compile time.
11461146

1147-
Constants must be explicitly typed. The type may be ```bool```, ```char```, a number, or a type derived from
1148-
those primitive types. The derived types are borrowed pointers, static arrays, tuples, and structs.
1147+
Constants must be explicitly typed. The type may be ```bool```, ```char```, a number, or a type derived from those primitive types.
1148+
The derived types are borrowed pointers, static arrays, tuples, and structs.
1149+
Borrowed pointers must be have the `'static` lifetime.
11491150

11501151
~~~~
11511152
const bit1: uint = 1 << 0;
11521153
const bit2: uint = 1 << 1;
11531154
11541155
const bits: [uint * 2] = [bit1, bit2];
1155-
const string: &str = "bitstring";
1156+
const string: &'static str = "bitstring";
11561157
11571158
struct BitsNStrings {
11581159
mybits: [uint *2],
1159-
mystring: &str
1160+
mystring: &'self str
11601161
}
11611162
1162-
const bits_n_strings: BitsNStrings = BitsNStrings {
1163+
const bits_n_strings: BitsNStrings<'static> = BitsNStrings {
11631164
mybits: bits,
11641165
mystring: string
11651166
};
@@ -1630,7 +1631,7 @@ The following are examples of structure expressions:
16301631
~~~~
16311632
# struct Point { x: float, y: float }
16321633
# struct TuplePoint(float, float);
1633-
# mod game { pub struct User { name: &str, age: uint, score: uint } }
1634+
# mod game { pub struct User<'self> { name: &'self str, age: uint, score: uint } }
16341635
# struct Cookie; fn some_fn<T>(t: T) {}
16351636
Point {x: 10f, y: 20f};
16361637
TuplePoint(10f, 20f);
@@ -2556,8 +2557,8 @@ order specified by the tuple type.
25562557
An example of a tuple type and its use:
25572558

25582559
~~~~
2559-
type Pair = (int,&str);
2560-
let p: Pair = (10,"hello");
2560+
type Pair<'self> = (int,&'self str);
2561+
let p: Pair<'static> = (10,"hello");
25612562
let (a, b) = p;
25622563
assert b != "world";
25632564
~~~~
@@ -2718,7 +2719,7 @@ fn add(x: int, y: int) -> int {
27182719
27192720
let mut x = add(5,7);
27202721
2721-
type Binop = fn(int,int) -> int;
2722+
type Binop<'self> = &'self fn(int,int) -> int;
27222723
let bo: Binop = add;
27232724
x = bo(5,7);
27242725
~~~~~~~~

doc/tutorial.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,7 +1951,7 @@ trait Printable {
19511951
Traits may be implemented for specific types with [impls]. An impl
19521952
that implements a trait includes the name of the trait at the start of
19531953
the definition, as in the following impls of `Printable` for `int`
1954-
and `&str`.
1954+
and `~str`.
19551955

19561956
[impls]: #functions-and-methods
19571957

@@ -1961,12 +1961,12 @@ impl Printable for int {
19611961
fn print(&self) { io::println(fmt!("%d", *self)) }
19621962
}
19631963
1964-
impl Printable for &str {
1964+
impl Printable for ~str {
19651965
fn print(&self) { io::println(*self) }
19661966
}
19671967
19681968
# 1.print();
1969-
# ("foo").print();
1969+
# (~"foo").print();
19701970
~~~~
19711971

19721972
Methods defined in an implementation of a trait may be called just like

src/libcore/at_vec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ pub mod traits {
168168
use kinds::Copy;
169169
use ops::Add;
170170

171-
impl<T:Copy> Add<&[const T],@[T]> for @[T] {
171+
impl<T:Copy> Add<&self/[const T],@[T]> for @[T] {
172172
#[inline(always)]
173173
pure fn add(&self, rhs: & &self/[const T]) -> @[T] {
174174
append(*self, (*rhs))

src/libcore/cleanup.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ use cast::transmute;
2222
* NB: These must match the representation in the C++ runtime.
2323
*/
2424

25-
type DropGlue = fn(**TypeDesc, *c_void);
26-
type FreeGlue = fn(**TypeDesc, *c_void);
25+
type DropGlue = &self/fn(**TypeDesc, *c_void);
26+
type FreeGlue = &self/fn(**TypeDesc, *c_void);
2727

2828
type TaskID = uintptr_t;
2929

src/libcore/condition.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ pub struct Handler<T, U> {
2222

2323
pub struct Condition<T, U> {
2424
name: &static/str,
25-
key: task::local_data::LocalDataKey<Handler<T, U>>
25+
key: task::local_data::LocalDataKey/&self<Handler<T, U>>
2626
}
2727

28-
pub impl<T, U> Condition<T, U> {
28+
pub impl<T, U> Condition/&self<T, U> {
2929
fn trap(&self, h: &self/fn(T) -> U) -> Trap/&self<T, U> {
3030
unsafe {
3131
let p : *RustClosure = ::cast::transmute(&h);
@@ -65,11 +65,11 @@ pub impl<T, U> Condition<T, U> {
6565
}
6666

6767
struct Trap<T, U> {
68-
cond: &Condition<T, U>,
68+
cond: &self/Condition/&self<T, U>,
6969
handler: @Handler<T, U>
7070
}
7171

72-
pub impl<T, U> Trap<T, U> {
72+
pub impl<T, U> Trap/&self<T, U> {
7373
fn in<V>(&self, inner: &self/fn() -> V) -> V {
7474
unsafe {
7575
let _g = Guard { cond: self.cond };
@@ -81,10 +81,10 @@ pub impl<T, U> Trap<T, U> {
8181
}
8282

8383
struct Guard<T, U> {
84-
cond: &Condition<T, U>
84+
cond: &self/Condition/&self<T, U>
8585
}
8686

87-
impl<T, U> Drop for Guard<T, U> {
87+
impl<T, U> Drop for Guard/&self<T, U> {
8888
fn finalize(&self) {
8989
unsafe {
9090
debug!("Guard: popping handler from TLS");

src/libcore/container.rs

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

1111
//! Container traits
1212
13-
use cmp::Equiv;
1413
use option::Option;
1514

1615
pub trait Container {

src/libcore/gc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ unsafe fn is_safe_point(pc: *Word) -> Option<SafePoint> {
115115
return None;
116116
}
117117

118-
type Visitor = fn(root: **Word, tydesc: *Word) -> bool;
118+
type Visitor = &self/fn(root: **Word, tydesc: *Word) -> bool;
119119

120120
// Walks the list of roots for the given safe point, and calls visitor
121121
// on each root.

src/libcore/hash.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ impl io::Writer for SipState {
298298
}
299299
}
300300

301-
impl Streaming for &SipState {
301+
impl Streaming for SipState {
302302

303303
#[inline(always)]
304304
fn input(&self, buf: &[const u8]) {

src/libcore/hashmap.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,9 @@ pub mod linear {
268268
}
269269
}
270270
271-
impl<K:Hash + IterBytes + Eq,V> BaseIter<(&K, &V)> for LinearMap<K, V> {
271+
impl<K:Hash + IterBytes + Eq,V>
272+
BaseIter<(&self/K, &self/V)> for LinearMap<K, V>
273+
{
272274
/// Visit all key-value pairs
273275
pure fn each(&self, blk: fn(&(&self/K, &self/V)) -> bool) {
274276
for uint::range(0, self.buckets.len()) |i| {

src/libcore/io.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,11 +585,11 @@ pub fn file_reader(path: &Path) -> Result<@Reader, ~str> {
585585
586586
// Byte readers
587587
pub struct BytesReader {
588-
bytes: &[u8],
588+
bytes: &self/[u8],
589589
mut pos: uint
590590
}
591591
592-
impl Reader for BytesReader {
592+
impl Reader for BytesReader/&self {
593593
fn read(&self, bytes: &mut [u8], len: uint) -> uint {
594594
let count = uint::min(len, self.bytes.len() - self.pos);
595595

0 commit comments

Comments
 (0)