提交 28efc234 编写于 作者: P Patrick Walton

libcore: Fix obsolete syntax in extfmt

上级 e2fde83c
......@@ -206,7 +206,7 @@ The keywords are the following strings:
~~~~~~~~ {.keyword}
as
break
const copy
copy
do drop
else enum extern
false fn for
......@@ -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.
......@@ -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
};
......@@ -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);
~~~~
......
......@@ -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,
......
......@@ -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;
~~~~
......@@ -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)} }
}
}
......@@ -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];
......@@ -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]),
_ => ()
......@@ -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,
......@@ -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);
~~~~
......@@ -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;
......@@ -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
......
......@@ -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);
}
......@@ -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",
......
......@@ -483,12 +483,12 @@ pub mod rt {
use vec;
use option::{Some, None, Option};
pub const flag_none : u32 = 0u32;
pub const flag_left_justify : u32 = 0b00000000000001u32;
pub const flag_left_zero_pad : u32 = 0b00000000000010u32;
pub const flag_space_for_sign : u32 = 0b00000000000100u32;
pub const flag_sign_always : u32 = 0b00000000001000u32;
pub const flag_alternate : u32 = 0b00000000010000u32;
pub static flag_none : u32 = 0u32;
pub static flag_left_justify : u32 = 0b00000000000001u32;
pub static flag_left_zero_pad : u32 = 0b00000000000010u32;
pub static flag_space_for_sign : u32 = 0b00000000000100u32;
pub static flag_sign_always : u32 = 0b00000000001000u32;
pub static flag_alternate : u32 = 0b00000000010000u32;
pub enum Count { CountIs(uint), CountImplied, }
......@@ -501,7 +501,7 @@ pub struct Conv {
ty: Ty,
}
pub pure fn conv_int(cv: Conv, i: int, buf: &mut ~str) {
pub fn conv_int(cv: Conv, i: int, buf: &mut ~str) {
let radix = 10;
let prec = get_int_precision(cv);
let mut s : ~str = uint_to_str_prec(int::abs(i) as uint, radix, prec);
......@@ -517,7 +517,7 @@ pub struct Conv {
} else { Some('-') };
unsafe { pad(cv, s, head, PadSigned, buf) };
}
pub pure fn conv_uint(cv: Conv, u: uint, buf: &mut ~str) {
pub fn conv_uint(cv: Conv, u: uint, buf: &mut ~str) {
let prec = get_int_precision(cv);
let mut rs =
match cv.ty {
......@@ -529,16 +529,16 @@ pub struct Conv {
};
unsafe { pad(cv, rs, None, PadUnsigned, buf) };
}
pub pure fn conv_bool(cv: Conv, b: bool, buf: &mut ~str) {
pub fn conv_bool(cv: Conv, b: bool, buf: &mut ~str) {
let s = if b { "true" } else { "false" };
// run the boolean conversion through the string conversion logic,
// giving it the same rules for precision, etc.
conv_str(cv, s, buf);
}
pub pure fn conv_char(cv: Conv, c: char, buf: &mut ~str) {
pub fn conv_char(cv: Conv, c: char, buf: &mut ~str) {
unsafe { pad(cv, "", Some(c), PadNozero, buf) };
}
pub pure fn conv_str(cv: Conv, s: &str, buf: &mut ~str) {
pub fn conv_str(cv: Conv, s: &str, buf: &mut ~str) {
// For strings, precision is the maximum characters
// displayed
let mut unpadded = match cv.precision {
......@@ -551,7 +551,7 @@ pub struct Conv {
};
unsafe { pad(cv, unpadded, None, PadNozero, buf) };
}
pub pure fn conv_float(cv: Conv, f: float, buf: &mut ~str) {
pub fn conv_float(cv: Conv, f: float, buf: &mut ~str) {
let (to_str, digits) = match cv.precision {
CountIs(c) => (float::to_str_exact, c as uint),
CountImplied => (float::to_str_digits, 6u)
......@@ -568,7 +568,7 @@ pub struct Conv {
} else { None };
unsafe { pad(cv, s, head, PadFloat, buf) };
}
pub pure fn conv_poly<T>(cv: Conv, v: &T, buf: &mut ~str) {
pub fn conv_poly<T>(cv: Conv, v: &T, buf: &mut ~str) {
let s = sys::log_str(v);
conv_str(cv, s, buf);
}
......@@ -576,8 +576,7 @@ pub struct Conv {
// Convert a uint to string with a minimum number of digits. If precision
// is 0 and num is 0 then the result is the empty string. Could move this
// to uint: but it doesn't seem all that useful.
pub pure fn uint_to_str_prec(num: uint, radix: uint,
prec: uint) -> ~str {
pub fn uint_to_str_prec(num: uint, radix: uint, prec: uint) -> ~str {
return if prec == 0u && num == 0u {
~""
} else {
......@@ -590,7 +589,7 @@ pub struct Conv {
} else { s }
};
}
pub pure fn get_int_precision(cv: Conv) -> uint {
pub fn get_int_precision(cv: Conv) -> uint {
return match cv.precision {
CountIs(c) => c as uint,
CountImplied => 1u
......@@ -637,7 +636,7 @@ pub fn pad(cv: Conv, mut s: &str, head: Option<char>, mode: PadMode,
PadFloat => (true, true),
PadUnsigned => (true, false)
};
pure fn have_precision(cv: Conv) -> bool {
fn have_precision(cv: Conv) -> bool {
return match cv.precision { CountImplied => false, _ => true };
}
let zero_padding = {
......@@ -672,7 +671,7 @@ pub fn pad(cv: Conv, mut s: &str, head: Option<char>, mode: PadMode,
buf.push_str(s);
}
#[inline(always)]
pub pure fn have_flag(flags: u32, f: u32) -> bool {
pub fn have_flag(flags: u32, f: u32) -> bool {
flags & f != 0
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册