Skip to content

Commit 28efc23

Browse files
committed
libcore: Fix obsolete syntax in extfmt
1 parent e2fde83 commit 28efc23

File tree

5 files changed

+49
-56
lines changed

5 files changed

+49
-56
lines changed

doc/rust.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ The keywords are the following strings:
206206
~~~~~~~~ {.keyword}
207207
as
208208
break
209-
const copy
209+
copy
210210
do drop
211211
else enum extern
212212
false fn for
@@ -1099,7 +1099,7 @@ const_item : "const" ident ':' type '=' expr ';' ;
10991099

11001100
A *constant* is a named value stored in read-only memory in a crate.
11011101
The value bound to a constant is evaluated at compile time.
1102-
Constants are declared with the `const` keyword.
1102+
Constants are declared with the `static` keyword.
11031103
A constant item must have an expression giving its definition.
11041104
The definition expression of a constant is limited to expression forms that can be evaluated at compile time.
11051105

@@ -1108,18 +1108,18 @@ The derived types are borrowed pointers, static arrays, tuples, and structs.
11081108
Borrowed pointers must be have the `'static` lifetime.
11091109

11101110
~~~~
1111-
const bit1: uint = 1 << 0;
1112-
const bit2: uint = 1 << 1;
1111+
static bit1: uint = 1 << 0;
1112+
static bit2: uint = 1 << 1;
11131113
1114-
const bits: [uint * 2] = [bit1, bit2];
1115-
const string: &'static str = "bitstring";
1114+
static bits: [uint, ..2] = [bit1, bit2];
1115+
static string: &'static str = "bitstring";
11161116
11171117
struct BitsNStrings {
1118-
mybits: [uint *2],
1118+
mybits: [uint, ..2],
11191119
mystring: &'self str
11201120
}
11211121
1122-
const bits_n_strings: BitsNStrings<'static> = BitsNStrings {
1122+
static bits_n_strings: BitsNStrings<'static> = BitsNStrings {
11231123
mybits: bits,
11241124
mystring: string
11251125
};
@@ -1206,10 +1206,10 @@ For example:
12061206

12071207
~~~~
12081208
trait Num {
1209-
static fn from_int(n: int) -> Self;
1209+
fn from_int(n: int) -> Self;
12101210
}
12111211
impl Num for float {
1212-
static fn from_int(n: int) -> float { n as float }
1212+
fn from_int(n: int) -> float { n as float }
12131213
}
12141214
let x: float = Num::from_int(42);
12151215
~~~~

doc/tutorial-borrowed-ptr.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ copying.
394394
# Circle(Point, float), // origin, radius
395395
# Rectangle(Point, Size) // upper-left, dimensions
396396
# }
397-
# const tau: float = 6.28f;
397+
# static tau: float = 6.28f;
398398
fn compute_area(shape: &Shape) -> float {
399399
match *shape {
400400
Circle(_, radius) => 0.5 * tau * radius * radius,

doc/tutorial.md

+19-25
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ can specify a variable's type by following it with a colon, then the type
237237
name. Constants, on the other hand, always require a type annotation.
238238

239239
~~~~
240-
const monster_factor: float = 57.8;
240+
static monster_factor: float = 57.8;
241241
let monster_size = monster_factor * 10.0;
242242
let monster_size: int = 50;
243243
~~~~
@@ -916,7 +916,7 @@ use core::libc::types::os::arch::c95::size_t;
916916
struct Blob { priv ptr: *c_void }
917917
918918
impl Blob {
919-
static fn new() -> Blob {
919+
fn new() -> Blob {
920920
unsafe { Blob{ptr: calloc(1, int::bytes as size_t)} }
921921
}
922922
}
@@ -1222,7 +1222,7 @@ pointers to vectors are also called 'slices'.
12221222
# Black, BlizzardBlue, Blue
12231223
# }
12241224
// A fixed-size stack vector
1225-
let stack_crayons: [Crayon * 3] = [Almond, AntiqueBrass, Apricot];
1225+
let stack_crayons: [Crayon, ..3] = [Almond, AntiqueBrass, Apricot];
12261226

12271227
// A borrowed pointer to stack-allocated vector
12281228
let stack_crayons: &[Crayon] = &[Aquamarine, Asparagus, AtomicTangerine];
@@ -1264,7 +1264,7 @@ Square brackets denote indexing into a vector:
12641264
# Aquamarine, Asparagus, AtomicTangerine,
12651265
# BananaMania, Beaver, Bittersweet };
12661266
# fn draw_scene(c: Crayon) { }
1267-
let crayons: [Crayon * 3] = [BananaMania, Beaver, Bittersweet];
1267+
let crayons: [Crayon, ..3] = [BananaMania, Beaver, Bittersweet];
12681268
match crayons[0] {
12691269
Bittersweet => draw_scene(crayons[0]),
12701270
_ => ()
@@ -1274,7 +1274,7 @@ match crayons[0] {
12741274
A vector can be destructured using pattern matching:
12751275
12761276
~~~~
1277-
let numbers: [int * 3] = [1, 2, 3];
1277+
let numbers: [int, ..3] = [1, 2, 3];
12781278
let score = match numbers {
12791279
[] => 0,
12801280
[a] => a * 10,
@@ -1768,32 +1768,25 @@ s.draw_borrowed();
17681768
(&@~s).draw_borrowed();
17691769
~~~
17701770

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

17751775
~~~~ {.xfail-test}
17761776
impl Circle {
17771777
fn area(&self) -> float { ... }
1778-
static fn new(area: float) -> Circle { ... }
1778+
fn new(area: float) -> Circle { ... }
17791779
}
17801780
~~~~
17811781

1782-
> ***Note***: In the future the `static` keyword will be removed and static methods
1783-
> will be distinguished solely by the presence or absence of the `self` argument.
1784-
> In the current langugage instance methods may also be declared without an explicit
1785-
> `self` argument, in which case `self` is an implicit reference.
1786-
> That form of method is deprecated.
1787-
1788-
Constructors are one common application for static methods, as in `new` above.
1789-
To call a static method, you have to prefix it with the type name and a double colon:
1782+
To call such a method, just prefix it with the type name and a double colon:
17901783

17911784
~~~~
17921785
# use core::float::consts::pi;
17931786
# use core::float::sqrt;
17941787
struct Circle { radius: float }
17951788
impl Circle {
1796-
static fn new(area: float) -> Circle { Circle { radius: sqrt(area / pi) } }
1789+
fn new(area: float) -> Circle { Circle { radius: sqrt(area / pi) } }
17971790
}
17981791
let c = Circle::new(42.5);
17991792
~~~~
@@ -2055,22 +2048,23 @@ second parameter of type `self`.
20552048
In contrast, in the `impl`, `equals` takes a second parameter of
20562049
type `int`, only using `self` as the name of the receiver.
20572050

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

20622056
~~~~
2063-
trait Shape { static fn new(area: float) -> Self; }
2057+
trait Shape { fn new(area: float) -> Self; }
20642058
# use core::float::consts::pi;
20652059
# use core::float::sqrt;
20662060
struct Circle { radius: float }
20672061
struct Square { length: float }
20682062
20692063
impl Shape for Circle {
2070-
static fn new(area: float) -> Circle { Circle { radius: sqrt(area / pi) } }
2064+
fn new(area: float) -> Circle { Circle { radius: sqrt(area / pi) } }
20712065
}
20722066
impl Shape for Square {
2073-
static fn new(area: float) -> Square { Square { length: sqrt(area) } }
2067+
fn new(area: float) -> Square { Square { length: sqrt(area) } }
20742068
}
20752069
20762070
let area = 42.5;
@@ -2312,7 +2306,7 @@ them. The `pub` keyword modifies an item's visibility, making it
23122306
visible outside its containing module. An expression with `::`, like
23132307
`farm::chicken`, can name an item outside of its containing
23142308
module. Items, such as those declared with `fn`, `struct`, `enum`,
2315-
`type`, or `const`, are module-private by default.
2309+
`type`, or `static`, are module-private by default.
23162310

23172311
Visibility restrictions in Rust exist only at module boundaries. This
23182312
is quite different from most object-oriented languages that also

src/compiletest/runtest.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ fn run_rfail_test(config: config, props: TestProps, testfile: &Path) {
8181
};
8282
8383
// The value our Makefile configures valgrind to return on failure
84-
const valgrind_err: int = 100;
84+
static valgrind_err: int = 100;
8585
if ProcRes.status == valgrind_err {
8686
fatal_ProcRes(~"run-fail test isn't valgrind-clean!", ProcRes);
8787
}
@@ -92,7 +92,7 @@ fn run_rfail_test(config: config, props: TestProps, testfile: &Path) {
9292
9393
fn check_correct_failure_status(ProcRes: ProcRes) {
9494
// The value the rust runtime returns on failure
95-
const rust_err: int = 101;
95+
static rust_err: int = 101;
9696
if ProcRes.status != rust_err {
9797
fatal_ProcRes(
9898
fmt!("failure produced the wrong error code: %d",

src/libcore/unstable/extfmt.rs

+17-18
Original file line numberDiff line numberDiff line change
@@ -483,12 +483,12 @@ pub mod rt {
483483
use vec;
484484
use option::{Some, None, Option};
485485
486-
pub const flag_none : u32 = 0u32;
487-
pub const flag_left_justify : u32 = 0b00000000000001u32;
488-
pub const flag_left_zero_pad : u32 = 0b00000000000010u32;
489-
pub const flag_space_for_sign : u32 = 0b00000000000100u32;
490-
pub const flag_sign_always : u32 = 0b00000000001000u32;
491-
pub const flag_alternate : u32 = 0b00000000010000u32;
486+
pub static flag_none : u32 = 0u32;
487+
pub static flag_left_justify : u32 = 0b00000000000001u32;
488+
pub static flag_left_zero_pad : u32 = 0b00000000000010u32;
489+
pub static flag_space_for_sign : u32 = 0b00000000000100u32;
490+
pub static flag_sign_always : u32 = 0b00000000001000u32;
491+
pub static flag_alternate : u32 = 0b00000000010000u32;
492492
493493
pub enum Count { CountIs(uint), CountImplied, }
494494
@@ -501,7 +501,7 @@ pub mod rt {
501501
ty: Ty,
502502
}
503503
504-
pub pure fn conv_int(cv: Conv, i: int, buf: &mut ~str) {
504+
pub fn conv_int(cv: Conv, i: int, buf: &mut ~str) {
505505
let radix = 10;
506506
let prec = get_int_precision(cv);
507507
let mut s : ~str = uint_to_str_prec(int::abs(i) as uint, radix, prec);
@@ -517,7 +517,7 @@ pub mod rt {
517517
} else { Some('-') };
518518
unsafe { pad(cv, s, head, PadSigned, buf) };
519519
}
520-
pub pure fn conv_uint(cv: Conv, u: uint, buf: &mut ~str) {
520+
pub fn conv_uint(cv: Conv, u: uint, buf: &mut ~str) {
521521
let prec = get_int_precision(cv);
522522
let mut rs =
523523
match cv.ty {
@@ -529,16 +529,16 @@ pub mod rt {
529529
};
530530
unsafe { pad(cv, rs, None, PadUnsigned, buf) };
531531
}
532-
pub pure fn conv_bool(cv: Conv, b: bool, buf: &mut ~str) {
532+
pub fn conv_bool(cv: Conv, b: bool, buf: &mut ~str) {
533533
let s = if b { "true" } else { "false" };
534534
// run the boolean conversion through the string conversion logic,
535535
// giving it the same rules for precision, etc.
536536
conv_str(cv, s, buf);
537537
}
538-
pub pure fn conv_char(cv: Conv, c: char, buf: &mut ~str) {
538+
pub fn conv_char(cv: Conv, c: char, buf: &mut ~str) {
539539
unsafe { pad(cv, "", Some(c), PadNozero, buf) };
540540
}
541-
pub pure fn conv_str(cv: Conv, s: &str, buf: &mut ~str) {
541+
pub fn conv_str(cv: Conv, s: &str, buf: &mut ~str) {
542542
// For strings, precision is the maximum characters
543543
// displayed
544544
let mut unpadded = match cv.precision {
@@ -551,7 +551,7 @@ pub mod rt {
551551
};
552552
unsafe { pad(cv, unpadded, None, PadNozero, buf) };
553553
}
554-
pub pure fn conv_float(cv: Conv, f: float, buf: &mut ~str) {
554+
pub fn conv_float(cv: Conv, f: float, buf: &mut ~str) {
555555
let (to_str, digits) = match cv.precision {
556556
CountIs(c) => (float::to_str_exact, c as uint),
557557
CountImplied => (float::to_str_digits, 6u)
@@ -568,16 +568,15 @@ pub mod rt {
568568
} else { None };
569569
unsafe { pad(cv, s, head, PadFloat, buf) };
570570
}
571-
pub pure fn conv_poly<T>(cv: Conv, v: &T, buf: &mut ~str) {
571+
pub fn conv_poly<T>(cv: Conv, v: &T, buf: &mut ~str) {
572572
let s = sys::log_str(v);
573573
conv_str(cv, s, buf);
574574
}
575575
576576
// Convert a uint to string with a minimum number of digits. If precision
577577
// is 0 and num is 0 then the result is the empty string. Could move this
578578
// to uint: but it doesn't seem all that useful.
579-
pub pure fn uint_to_str_prec(num: uint, radix: uint,
580-
prec: uint) -> ~str {
579+
pub fn uint_to_str_prec(num: uint, radix: uint, prec: uint) -> ~str {
581580
return if prec == 0u && num == 0u {
582581
~""
583582
} else {
@@ -590,7 +589,7 @@ pub mod rt {
590589
} else { s }
591590
};
592591
}
593-
pub pure fn get_int_precision(cv: Conv) -> uint {
592+
pub fn get_int_precision(cv: Conv) -> uint {
594593
return match cv.precision {
595594
CountIs(c) => c as uint,
596595
CountImplied => 1u
@@ -637,7 +636,7 @@ pub mod rt {
637636
PadFloat => (true, true),
638637
PadUnsigned => (true, false)
639638
};
640-
pure fn have_precision(cv: Conv) -> bool {
639+
fn have_precision(cv: Conv) -> bool {
641640
return match cv.precision { CountImplied => false, _ => true };
642641
}
643642
let zero_padding = {
@@ -672,7 +671,7 @@ pub mod rt {
672671
buf.push_str(s);
673672
}
674673
#[inline(always)]
675-
pub pure fn have_flag(flags: u32, f: u32) -> bool {
674+
pub fn have_flag(flags: u32, f: u32) -> bool {
676675
flags & f != 0
677676
}
678677
}

0 commit comments

Comments
 (0)