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

Diff for: doc/rust.md

+10-9
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
~~~~~~~~

Diff for: doc/tutorial.md

+3-3
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

Diff for: src/libcore/at_vec.rs

+1-1
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))

Diff for: src/libcore/cleanup.rs

+2-2
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

Diff for: src/libcore/condition.rs

+6-6
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");

Diff for: src/libcore/container.rs

-1
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 {

Diff for: src/libcore/gc.rs

+1-1
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.

Diff for: src/libcore/hash.rs

+1-1
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]) {

Diff for: src/libcore/hashmap.rs

+3-1
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| {

Diff for: src/libcore/io.rs

+2-2
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

Diff for: src/libcore/iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use option::{None, Option, Some};
2020
use vec;
2121

2222
/// A function used to initialize the elements of a sequence
23-
pub type InitOp<T> = &fn(uint) -> T;
23+
pub type InitOp<T> = &self/fn(uint) -> T;
2424

2525
pub trait BaseIter<A> {
2626
pure fn each(&self, blk: fn(v: &A) -> bool);

Diff for: src/libcore/os.rs

+26-26
Original file line numberDiff line numberDiff line change
@@ -1028,11 +1028,11 @@ pub mod consts {
10281028
pub use os::consts::windows::*;
10291029
10301030
pub mod unix {
1031-
pub const FAMILY: &str = "unix";
1031+
pub const FAMILY: &static/str = "unix";
10321032
}
10331033
10341034
pub mod windows {
1035-
pub const FAMILY: &str = "windows";
1035+
pub const FAMILY: &static/str = "windows";
10361036
}
10371037
10381038
#[cfg(target_os = "macos")]
@@ -1051,38 +1051,38 @@ pub mod consts {
10511051
pub use os::consts::win32::*;
10521052
10531053
pub mod macos {
1054-
pub const SYSNAME: &str = "macos";
1055-
pub const DLL_PREFIX: &str = "lib";
1056-
pub const DLL_SUFFIX: &str = ".dylib";
1057-
pub const EXE_SUFFIX: &str = "";
1054+
pub const SYSNAME: &static/str = "macos";
1055+
pub const DLL_PREFIX: &static/str = "lib";
1056+
pub const DLL_SUFFIX: &static/str = ".dylib";
1057+
pub const EXE_SUFFIX: &static/str = "";
10581058
}
10591059
10601060
pub mod freebsd {
1061-
pub const SYSNAME: &str = "freebsd";
1062-
pub const DLL_PREFIX: &str = "lib";
1063-
pub const DLL_SUFFIX: &str = ".so";
1064-
pub const EXE_SUFFIX: &str = "";
1061+
pub const SYSNAME: &static/str = "freebsd";
1062+
pub const DLL_PREFIX: &static/str = "lib";
1063+
pub const DLL_SUFFIX: &static/str = ".so";
1064+
pub const EXE_SUFFIX: &static/str = "";
10651065
}
10661066
10671067
pub mod linux {
1068-
pub const SYSNAME: &str = "linux";
1069-
pub const DLL_PREFIX: &str = "lib";
1070-
pub const DLL_SUFFIX: &str = ".so";
1071-
pub const EXE_SUFFIX: &str = "";
1068+
pub const SYSNAME: &static/str = "linux";
1069+
pub const DLL_PREFIX: &static/str = "lib";
1070+
pub const DLL_SUFFIX: &static/str = ".so";
1071+
pub const EXE_SUFFIX: &static/str = "";
10721072
}
10731073
10741074
pub mod android {
1075-
pub const SYSNAME: &str = "android";
1076-
pub const DLL_PREFIX: &str = "lib";
1077-
pub const DLL_SUFFIX: &str = ".so";
1078-
pub const EXE_SUFFIX: &str = "";
1075+
pub const SYSNAME: &static/str = "android";
1076+
pub const DLL_PREFIX: &static/str = "lib";
1077+
pub const DLL_SUFFIX: &static/str = ".so";
1078+
pub const EXE_SUFFIX: &static/str = "";
10791079
}
10801080
10811081
pub mod win32 {
1082-
pub const SYSNAME: &str = "win32";
1083-
pub const DLL_PREFIX: &str = "";
1084-
pub const DLL_SUFFIX: &str = ".dll";
1085-
pub const EXE_SUFFIX: &str = ".exe";
1082+
pub const SYSNAME: &static/str = "win32";
1083+
pub const DLL_PREFIX: &static/str = "";
1084+
pub const DLL_SUFFIX: &static/str = ".dll";
1085+
pub const EXE_SUFFIX: &static/str = ".exe";
10861086
}
10871087
10881088
@@ -1099,16 +1099,16 @@ pub mod consts {
10991099
use os::consts::mips::*;
11001100
11011101
pub mod x86 {
1102-
pub const ARCH: &str = "x86";
1102+
pub const ARCH: &'static str = "x86";
11031103
}
11041104
pub mod x86_64 {
1105-
pub const ARCH: &str = "x86_64";
1105+
pub const ARCH: &'static str = "x86_64";
11061106
}
11071107
pub mod arm {
1108-
pub const ARCH: &str = "arm";
1108+
pub const ARCH: &'static str = "arm";
11091109
}
11101110
pub mod mips {
1111-
pub const ARCH: &str = "mips";
1111+
pub const ARCH: &'static str = "mips";
11121112
}
11131113
}
11141114

Diff for: src/libcore/pipes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ pub fn try_recv<T:Owned,Tbuffer:Owned>(p: RecvPacketBuffered<T, Tbuffer>)
440440
let p = unsafe { &*p_ };
441441
442442
struct DropState {
443-
p: &PacketHeader,
443+
p: &self/PacketHeader,
444444
445445
drop {
446446
if task::failing() {

Diff for: src/libcore/ptr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl<T> Ord for *const T {
264264

265265
// Equality for region pointers
266266
#[cfg(notest)]
267-
impl<T:Eq> Eq for &const T {
267+
impl<T:Eq> Eq for &self/const T {
268268
#[inline(always)]
269269
pure fn eq(&self, other: & &self/const T) -> bool {
270270
return *(*self) == *(*other);
@@ -277,7 +277,7 @@ impl<T:Eq> Eq for &const T {
277277

278278
// Comparison for region pointers
279279
#[cfg(notest)]
280-
impl<T:Ord> Ord for &const T {
280+
impl<T:Ord> Ord for &self/const T {
281281
#[inline(always)]
282282
pure fn lt(&self, other: & &self/const T) -> bool {
283283
*(*self) < *(*other)

Diff for: src/libcore/str.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ pure fn cmp(a: &str, b: &str) -> Ordering {
787787
}
788788

789789
#[cfg(notest)]
790-
impl TotalOrd for &str {
790+
impl TotalOrd for &'self str {
791791
pure fn cmp(&self, other: & &self/str) -> Ordering { cmp(*self, *other) }
792792
}
793793

@@ -833,7 +833,7 @@ pure fn gt(a: &str, b: &str) -> bool {
833833
}
834834

835835
#[cfg(notest)]
836-
impl Eq for &str {
836+
impl Eq for &self/str {
837837
#[inline(always)]
838838
pure fn eq(&self, other: & &self/str) -> bool {
839839
eq_slice((*self), (*other))
@@ -875,7 +875,7 @@ impl Ord for ~str {
875875
}
876876

877877
#[cfg(notest)]
878-
impl Ord for &str {
878+
impl Ord for &self/str {
879879
#[inline(always)]
880880
pure fn lt(&self, other: & &self/str) -> bool { lt((*self), (*other)) }
881881
#[inline(always)]
@@ -899,7 +899,7 @@ impl Ord for @str {
899899
}
900900

901901
#[cfg(notest)]
902-
impl Equiv<~str> for &str {
902+
impl Equiv<~str> for &'self str {
903903
#[inline(always)]
904904
pure fn equiv(&self, other: &~str) -> bool { eq_slice(*self, *other) }
905905
}
@@ -2226,7 +2226,7 @@ pub mod traits {
22262226
use ops::Add;
22272227
use str::append;
22282228

2229-
impl Add<&str,~str> for ~str {
2229+
impl Add<&self/str,~str> for ~str {
22302230
#[inline(always)]
22312231
pure fn add(&self, rhs: & &self/str) -> ~str {
22322232
append(copy *self, (*rhs))
@@ -2270,7 +2270,7 @@ pub trait StrSlice {
22702270
}
22712271

22722272
/// Extension methods for strings
2273-
impl StrSlice for &str {
2273+
impl StrSlice for &self/str {
22742274
/**
22752275
* Return true if a predicate matches all characters or if the string
22762276
* contains no characters

Diff for: src/libcore/sys.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use libc::{c_void, c_char, size_t};
1919
use repr;
2020
use str;
2121

22-
pub type FreeGlue = fn(*TypeDesc, *c_void);
22+
pub type FreeGlue = &self/fn(*TypeDesc, *c_void);
2323

2424
// Corresponds to runtime type_desc type
2525
pub enum TypeDesc = {

Diff for: src/libcore/task/local_data.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use task::rt;
4444
*
4545
* These two cases aside, the interface is safe.
4646
*/
47-
pub type LocalDataKey<T> = &fn(v: @T);
47+
pub type LocalDataKey<T> = &self/fn(v: @T);
4848

4949
/**
5050
* Remove a task-local data value from the table, returning the

0 commit comments

Comments
 (0)