Skip to content

Commit

Permalink
auto merge of #5125 : nikomatsakis/rust/issue-4846-lifetime-defaults,…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
bors committed Mar 6, 2013
2 parents 0262387 + 078fd23 commit 8c3728f
Show file tree
Hide file tree
Showing 128 changed files with 686 additions and 601 deletions.
19 changes: 10 additions & 9 deletions doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -1144,22 +1144,23 @@ Constants are declared with the `const` keyword.
A constant item must have an expression giving its definition.
The definition expression of a constant is limited to expression forms that can be evaluated at compile time.

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

~~~~
const bit1: uint = 1 << 0;
const bit2: uint = 1 << 1;
const bits: [uint * 2] = [bit1, bit2];
const string: &str = "bitstring";
const string: &'static str = "bitstring";
struct BitsNStrings {
mybits: [uint *2],
mystring: &str
mystring: &'self str
}
const bits_n_strings: BitsNStrings = BitsNStrings {
const bits_n_strings: BitsNStrings<'static> = BitsNStrings {
mybits: bits,
mystring: string
};
Expand Down Expand Up @@ -1630,7 +1631,7 @@ The following are examples of structure expressions:
~~~~
# struct Point { x: float, y: float }
# struct TuplePoint(float, float);
# mod game { pub struct User { name: &str, age: uint, score: uint } }
# mod game { pub struct User<'self> { name: &'self str, age: uint, score: uint } }
# struct Cookie; fn some_fn<T>(t: T) {}
Point {x: 10f, y: 20f};
TuplePoint(10f, 20f);
Expand Down Expand Up @@ -2556,8 +2557,8 @@ order specified by the tuple type.
An example of a tuple type and its use:

~~~~
type Pair = (int,&str);
let p: Pair = (10,"hello");
type Pair<'self> = (int,&'self str);
let p: Pair<'static> = (10,"hello");
let (a, b) = p;
assert b != "world";
~~~~
Expand Down Expand Up @@ -2718,7 +2719,7 @@ fn add(x: int, y: int) -> int {
let mut x = add(5,7);
type Binop = fn(int,int) -> int;
type Binop<'self> = &'self fn(int,int) -> int;
let bo: Binop = add;
x = bo(5,7);
~~~~~~~~
Expand Down
6 changes: 3 additions & 3 deletions doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -1951,7 +1951,7 @@ trait Printable {
Traits may be implemented for specific types with [impls]. An impl
that implements a trait includes the name of the trait at the start of
the definition, as in the following impls of `Printable` for `int`
and `&str`.
and `~str`.

[impls]: #functions-and-methods

Expand All @@ -1961,12 +1961,12 @@ impl Printable for int {
fn print(&self) { io::println(fmt!("%d", *self)) }
}
impl Printable for &str {
impl Printable for ~str {
fn print(&self) { io::println(*self) }
}
# 1.print();
# ("foo").print();
# (~"foo").print();
~~~~

Methods defined in an implementation of a trait may be called just like
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/at_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ pub mod traits {
use kinds::Copy;
use ops::Add;

impl<T:Copy> Add<&[const T],@[T]> for @[T] {
impl<T:Copy> Add<&self/[const T],@[T]> for @[T] {
#[inline(always)]
pure fn add(&self, rhs: & &self/[const T]) -> @[T] {
append(*self, (*rhs))
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/cleanup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use cast::transmute;
* NB: These must match the representation in the C++ runtime.
*/

type DropGlue = fn(**TypeDesc, *c_void);
type FreeGlue = fn(**TypeDesc, *c_void);
type DropGlue = &self/fn(**TypeDesc, *c_void);
type FreeGlue = &self/fn(**TypeDesc, *c_void);

type TaskID = uintptr_t;

Expand Down
12 changes: 6 additions & 6 deletions src/libcore/condition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ pub struct Handler<T, U> {

pub struct Condition<T, U> {
name: &static/str,
key: task::local_data::LocalDataKey<Handler<T, U>>
key: task::local_data::LocalDataKey/&self<Handler<T, U>>
}

pub impl<T, U> Condition<T, U> {
pub impl<T, U> Condition/&self<T, U> {
fn trap(&self, h: &self/fn(T) -> U) -> Trap/&self<T, U> {
unsafe {
let p : *RustClosure = ::cast::transmute(&h);
Expand Down Expand Up @@ -65,11 +65,11 @@ pub impl<T, U> Condition<T, U> {
}

struct Trap<T, U> {
cond: &Condition<T, U>,
cond: &self/Condition/&self<T, U>,
handler: @Handler<T, U>
}

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

struct Guard<T, U> {
cond: &Condition<T, U>
cond: &self/Condition/&self<T, U>
}

impl<T, U> Drop for Guard<T, U> {
impl<T, U> Drop for Guard/&self<T, U> {
fn finalize(&self) {
unsafe {
debug!("Guard: popping handler from TLS");
Expand Down
1 change: 0 additions & 1 deletion src/libcore/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

//! Container traits
use cmp::Equiv;
use option::Option;

pub trait Container {
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ unsafe fn is_safe_point(pc: *Word) -> Option<SafePoint> {
return None;
}

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

// Walks the list of roots for the given safe point, and calls visitor
// on each root.
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ impl io::Writer for SipState {
}
}

impl Streaming for &SipState {
impl Streaming for SipState {

#[inline(always)]
fn input(&self, buf: &[const u8]) {
Expand Down
4 changes: 3 additions & 1 deletion src/libcore/hashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,9 @@ pub mod linear {
}
}
impl<K:Hash + IterBytes + Eq,V> BaseIter<(&K, &V)> for LinearMap<K, V> {
impl<K:Hash + IterBytes + Eq,V>
BaseIter<(&self/K, &self/V)> for LinearMap<K, V>
{
/// Visit all key-value pairs
pure fn each(&self, blk: fn(&(&self/K, &self/V)) -> bool) {
for uint::range(0, self.buckets.len()) |i| {
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,11 +585,11 @@ pub fn file_reader(path: &Path) -> Result<@Reader, ~str> {
// Byte readers
pub struct BytesReader {
bytes: &[u8],
bytes: &self/[u8],
mut pos: uint
}
impl Reader for BytesReader {
impl Reader for BytesReader/&self {
fn read(&self, bytes: &mut [u8], len: uint) -> uint {
let count = uint::min(len, self.bytes.len() - self.pos);
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use option::{None, Option, Some};
use vec;

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

pub trait BaseIter<A> {
pure fn each(&self, blk: fn(v: &A) -> bool);
Expand Down
52 changes: 26 additions & 26 deletions src/libcore/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1028,11 +1028,11 @@ pub mod consts {
pub use os::consts::windows::*;
pub mod unix {
pub const FAMILY: &str = "unix";
pub const FAMILY: &static/str = "unix";
}
pub mod windows {
pub const FAMILY: &str = "windows";
pub const FAMILY: &static/str = "windows";
}
#[cfg(target_os = "macos")]
Expand All @@ -1051,38 +1051,38 @@ pub mod consts {
pub use os::consts::win32::*;
pub mod macos {
pub const SYSNAME: &str = "macos";
pub const DLL_PREFIX: &str = "lib";
pub const DLL_SUFFIX: &str = ".dylib";
pub const EXE_SUFFIX: &str = "";
pub const SYSNAME: &static/str = "macos";
pub const DLL_PREFIX: &static/str = "lib";
pub const DLL_SUFFIX: &static/str = ".dylib";
pub const EXE_SUFFIX: &static/str = "";
}
pub mod freebsd {
pub const SYSNAME: &str = "freebsd";
pub const DLL_PREFIX: &str = "lib";
pub const DLL_SUFFIX: &str = ".so";
pub const EXE_SUFFIX: &str = "";
pub const SYSNAME: &static/str = "freebsd";
pub const DLL_PREFIX: &static/str = "lib";
pub const DLL_SUFFIX: &static/str = ".so";
pub const EXE_SUFFIX: &static/str = "";
}
pub mod linux {
pub const SYSNAME: &str = "linux";
pub const DLL_PREFIX: &str = "lib";
pub const DLL_SUFFIX: &str = ".so";
pub const EXE_SUFFIX: &str = "";
pub const SYSNAME: &static/str = "linux";
pub const DLL_PREFIX: &static/str = "lib";
pub const DLL_SUFFIX: &static/str = ".so";
pub const EXE_SUFFIX: &static/str = "";
}
pub mod android {
pub const SYSNAME: &str = "android";
pub const DLL_PREFIX: &str = "lib";
pub const DLL_SUFFIX: &str = ".so";
pub const EXE_SUFFIX: &str = "";
pub const SYSNAME: &static/str = "android";
pub const DLL_PREFIX: &static/str = "lib";
pub const DLL_SUFFIX: &static/str = ".so";
pub const EXE_SUFFIX: &static/str = "";
}
pub mod win32 {
pub const SYSNAME: &str = "win32";
pub const DLL_PREFIX: &str = "";
pub const DLL_SUFFIX: &str = ".dll";
pub const EXE_SUFFIX: &str = ".exe";
pub const SYSNAME: &static/str = "win32";
pub const DLL_PREFIX: &static/str = "";
pub const DLL_SUFFIX: &static/str = ".dll";
pub const EXE_SUFFIX: &static/str = ".exe";
}
Expand All @@ -1099,16 +1099,16 @@ pub mod consts {
use os::consts::mips::*;
pub mod x86 {
pub const ARCH: &str = "x86";
pub const ARCH: &'static str = "x86";
}
pub mod x86_64 {
pub const ARCH: &str = "x86_64";
pub const ARCH: &'static str = "x86_64";
}
pub mod arm {
pub const ARCH: &str = "arm";
pub const ARCH: &'static str = "arm";
}
pub mod mips {
pub const ARCH: &str = "mips";
pub const ARCH: &'static str = "mips";
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/pipes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ pub fn try_recv<T:Owned,Tbuffer:Owned>(p: RecvPacketBuffered<T, Tbuffer>)
let p = unsafe { &*p_ };
struct DropState {
p: &PacketHeader,
p: &self/PacketHeader,
drop {
if task::failing() {
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ impl<T> Ord for *const T {

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

// Comparison for region pointers
#[cfg(notest)]
impl<T:Ord> Ord for &const T {
impl<T:Ord> Ord for &self/const T {
#[inline(always)]
pure fn lt(&self, other: & &self/const T) -> bool {
*(*self) < *(*other)
Expand Down
12 changes: 6 additions & 6 deletions src/libcore/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ pure fn cmp(a: &str, b: &str) -> Ordering {
}

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

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

#[cfg(notest)]
impl Eq for &str {
impl Eq for &self/str {
#[inline(always)]
pure fn eq(&self, other: & &self/str) -> bool {
eq_slice((*self), (*other))
Expand Down Expand Up @@ -875,7 +875,7 @@ impl Ord for ~str {
}

#[cfg(notest)]
impl Ord for &str {
impl Ord for &self/str {
#[inline(always)]
pure fn lt(&self, other: & &self/str) -> bool { lt((*self), (*other)) }
#[inline(always)]
Expand All @@ -899,7 +899,7 @@ impl Ord for @str {
}

#[cfg(notest)]
impl Equiv<~str> for &str {
impl Equiv<~str> for &'self str {
#[inline(always)]
pure fn equiv(&self, other: &~str) -> bool { eq_slice(*self, *other) }
}
Expand Down Expand Up @@ -2226,7 +2226,7 @@ pub mod traits {
use ops::Add;
use str::append;

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

/// Extension methods for strings
impl StrSlice for &str {
impl StrSlice for &self/str {
/**
* Return true if a predicate matches all characters or if the string
* contains no characters
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use libc::{c_void, c_char, size_t};
use repr;
use str;

pub type FreeGlue = fn(*TypeDesc, *c_void);
pub type FreeGlue = &self/fn(*TypeDesc, *c_void);

// Corresponds to runtime type_desc type
pub enum TypeDesc = {
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/task/local_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use task::rt;
*
* These two cases aside, the interface is safe.
*/
pub type LocalDataKey<T> = &fn(v: @T);
pub type LocalDataKey<T> = &self/fn(v: @T);

/**
* Remove a task-local data value from the table, returning the
Expand Down
Loading

0 comments on commit 8c3728f

Please sign in to comment.