Skip to content

Delifetime #5504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 23, 2013
20 changes: 10 additions & 10 deletions doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ The keywords are the following strings:
~~~~~~~~ {.keyword}
as
break
const copy
copy
do drop
else enum extern
false fn for
Expand Down Expand Up @@ -1099,7 +1099,7 @@ const_item : "const" ident ':' type '=' expr ';' ;

A *constant* is a named value stored in read-only memory in a crate.
The value bound to a constant is evaluated at compile time.
Constants are declared with the `const` keyword.
Constants are declared with the `static` 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.

Expand All @@ -1108,18 +1108,18 @@ 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;
static bit1: uint = 1 << 0;
static bit2: uint = 1 << 1;

const bits: [uint * 2] = [bit1, bit2];
const string: &'static str = "bitstring";
static bits: [uint, ..2] = [bit1, bit2];
static string: &'static str = "bitstring";

struct BitsNStrings {
mybits: [uint *2],
mybits: [uint, ..2],
mystring: &'self str
}

const bits_n_strings: BitsNStrings<'static> = BitsNStrings {
static bits_n_strings: BitsNStrings<'static> = BitsNStrings {
mybits: bits,
mystring: string
};
Expand Down Expand Up @@ -1206,10 +1206,10 @@ For example:

~~~~
trait Num {
static fn from_int(n: int) -> Self;
fn from_int(n: int) -> Self;
}
impl Num for float {
static fn from_int(n: int) -> float { n as float }
fn from_int(n: int) -> float { n as float }
}
let x: float = Num::from_int(42);
~~~~
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial-borrowed-ptr.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ copying.
# Circle(Point, float), // origin, radius
# Rectangle(Point, Size) // upper-left, dimensions
# }
# const tau: float = 6.28f;
# static tau: float = 6.28f;
fn compute_area(shape: &Shape) -> float {
match *shape {
Circle(_, radius) => 0.5 * tau * radius * radius,
Expand Down
44 changes: 19 additions & 25 deletions doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ can specify a variable's type by following it with a colon, then the type
name. Constants, on the other hand, always require a type annotation.

~~~~
const monster_factor: float = 57.8;
static monster_factor: float = 57.8;
let monster_size = monster_factor * 10.0;
let monster_size: int = 50;
~~~~
Expand Down Expand Up @@ -916,7 +916,7 @@ use core::libc::types::os::arch::c95::size_t;
struct Blob { priv ptr: *c_void }

impl Blob {
static fn new() -> Blob {
fn new() -> Blob {
unsafe { Blob{ptr: calloc(1, int::bytes as size_t)} }
}
}
Expand Down Expand Up @@ -1222,7 +1222,7 @@ pointers to vectors are also called 'slices'.
# Black, BlizzardBlue, Blue
# }
// A fixed-size stack vector
let stack_crayons: [Crayon * 3] = [Almond, AntiqueBrass, Apricot];
let stack_crayons: [Crayon, ..3] = [Almond, AntiqueBrass, Apricot];

// A borrowed pointer to stack-allocated vector
let stack_crayons: &[Crayon] = &[Aquamarine, Asparagus, AtomicTangerine];
Expand Down Expand Up @@ -1264,7 +1264,7 @@ Square brackets denote indexing into a vector:
# Aquamarine, Asparagus, AtomicTangerine,
# BananaMania, Beaver, Bittersweet };
# fn draw_scene(c: Crayon) { }
let crayons: [Crayon * 3] = [BananaMania, Beaver, Bittersweet];
let crayons: [Crayon, ..3] = [BananaMania, Beaver, Bittersweet];
match crayons[0] {
Bittersweet => draw_scene(crayons[0]),
_ => ()
Expand All @@ -1274,7 +1274,7 @@ match crayons[0] {
A vector can be destructured using pattern matching:

~~~~
let numbers: [int * 3] = [1, 2, 3];
let numbers: [int, ..3] = [1, 2, 3];
let score = match numbers {
[] => 0,
[a] => a * 10,
Expand Down Expand Up @@ -1768,32 +1768,25 @@ s.draw_borrowed();
(&@~s).draw_borrowed();
~~~

Implementations may also define _static_ methods,
which don't have an explicit `self` argument.
The `static` keyword distinguishes static methods from methods that have a `self`:
Implementations may also define standalone (sometimes called "static")
methods. The absence of a `self` paramater distinguishes such methods.
These methods are the preferred way to define constructor functions.

~~~~ {.xfail-test}
impl Circle {
fn area(&self) -> float { ... }
static fn new(area: float) -> Circle { ... }
fn new(area: float) -> Circle { ... }
}
~~~~

> ***Note***: In the future the `static` keyword will be removed and static methods
> will be distinguished solely by the presence or absence of the `self` argument.
> In the current langugage instance methods may also be declared without an explicit
> `self` argument, in which case `self` is an implicit reference.
> That form of method is deprecated.

Constructors are one common application for static methods, as in `new` above.
To call a static method, you have to prefix it with the type name and a double colon:
To call such a method, just prefix it with the type name and a double colon:

~~~~
# use core::float::consts::pi;
# use core::float::sqrt;
struct Circle { radius: float }
impl Circle {
static fn new(area: float) -> Circle { Circle { radius: sqrt(area / pi) } }
fn new(area: float) -> Circle { Circle { radius: sqrt(area / pi) } }
}
let c = Circle::new(42.5);
~~~~
Expand Down Expand Up @@ -2055,22 +2048,23 @@ second parameter of type `self`.
In contrast, in the `impl`, `equals` takes a second parameter of
type `int`, only using `self` as the name of the receiver.

Traits can also define static methods which are called by prefixing
the method name with the trait name.
The compiler will use type inference to decide which implementation to call.
Just as in type implementations, traits can define standalone (static)
methods. These methods are called by prefixing the method name with the trait
name and a double colon. The compiler uses type inference to decide which
implementation to use.

~~~~
trait Shape { static fn new(area: float) -> Self; }
trait Shape { fn new(area: float) -> Self; }
# use core::float::consts::pi;
# use core::float::sqrt;
struct Circle { radius: float }
struct Square { length: float }

impl Shape for Circle {
static fn new(area: float) -> Circle { Circle { radius: sqrt(area / pi) } }
fn new(area: float) -> Circle { Circle { radius: sqrt(area / pi) } }
}
impl Shape for Square {
static fn new(area: float) -> Square { Square { length: sqrt(area) } }
fn new(area: float) -> Square { Square { length: sqrt(area) } }
}

let area = 42.5;
Expand Down Expand Up @@ -2312,7 +2306,7 @@ them. The `pub` keyword modifies an item's visibility, making it
visible outside its containing module. An expression with `::`, like
`farm::chicken`, can name an item outside of its containing
module. Items, such as those declared with `fn`, `struct`, `enum`,
`type`, or `const`, are module-private by default.
`type`, or `static`, are module-private by default.

Visibility restrictions in Rust exist only at module boundaries. This
is quite different from most object-oriented languages that also
Expand Down
4 changes: 2 additions & 2 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn run_rfail_test(config: config, props: TestProps, testfile: &Path) {
};

// The value our Makefile configures valgrind to return on failure
const valgrind_err: int = 100;
static valgrind_err: int = 100;
if ProcRes.status == valgrind_err {
fatal_ProcRes(~"run-fail test isn't valgrind-clean!", ProcRes);
}
Expand All @@ -92,7 +92,7 @@ fn run_rfail_test(config: config, props: TestProps, testfile: &Path) {

fn check_correct_failure_status(ProcRes: ProcRes) {
// The value the rust runtime returns on failure
const rust_err: int = 101;
static rust_err: int = 101;
if ProcRes.status != rust_err {
fatal_ProcRes(
fmt!("failure produced the wrong error code: %d",
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 @@ -291,7 +291,7 @@ pub fn test() {
}
}

fail_unless!(seq_range(10, 15) == @[10, 11, 12, 13, 14]);
assert_eq!(seq_range(10, 15), @[10, 11, 12, 13, 14]);
fail_unless!(from_fn(5, |x| x+1) == @[1, 2, 3, 4, 5]);
fail_unless!(from_elem(5, 3.14) == @[3.14, 3.14, 3.14, 3.14, 3.14]);
}
Expand Down
14 changes: 7 additions & 7 deletions src/libcore/condition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ pub struct Handler<T, U> {

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

pub impl<T, U> Condition/&self<T, U> {
fn trap(&self, h: &'self fn(T) -> U) -> Trap/&self<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);
let prev = task::local_data::local_data_get(self.key);
Expand Down Expand Up @@ -65,11 +65,11 @@ pub impl<T, U> Condition/&self<T, U> {
}

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

pub impl<T, U> Trap/&self<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,11 +81,11 @@ pub impl<T, U> Trap/&self<T, U> {
}

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

#[unsafe_destructor]
impl<T, U> Drop for Guard/&self<T, U> {
impl<T, U> Drop for Guard<'self, T, U> {
fn finalize(&self) {
unsafe {
debug!("Guard: popping handler from TLS");
Expand Down
8 changes: 4 additions & 4 deletions src/libcore/flate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ pub mod rustrt {
}
}

const lz_none : c_int = 0x0; // Huffman-coding only.
const lz_fast : c_int = 0x1; // LZ with only one probe
const lz_norm : c_int = 0x80; // LZ with 128 probes, "normal"
const lz_best : c_int = 0xfff; // LZ with 4095 probes, "best"
static lz_none : c_int = 0x0; // Huffman-coding only.
static lz_fast : c_int = 0x1; // LZ with only one probe
static lz_norm : c_int = 0x80; // LZ with 128 probes, "normal"
static lz_best : c_int = 0xfff; // LZ with 4095 probes, "best"

pub fn deflate_bytes(bytes: &[const u8]) -> ~[u8] {
do vec::as_const_buf(bytes) |b, len| {
Expand Down
8 changes: 4 additions & 4 deletions src/libcore/gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,11 @@ unsafe fn find_segment_for_frame(fp: *Word, segment: *StackSegment)

type Memory = uint;

const task_local_heap: Memory = 1;
const exchange_heap: Memory = 2;
const stack: Memory = 4;
static task_local_heap: Memory = 1;
static exchange_heap: Memory = 2;
static stack: Memory = 4;

const need_cleanup: Memory = exchange_heap | stack;
static need_cleanup: Memory = exchange_heap | stack;

// Walks stack, searching for roots of the requested type, and passes
// each root to the visitor.
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/hashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub mod linear {
use uint;
use vec;

const INITIAL_CAPACITY: uint = 32u; // 2^5
static INITIAL_CAPACITY: uint = 32u; // 2^5

struct Bucket<K,V> {
hash: uint,
Expand Down
Loading