Skip to content

Commit 4cdf9d0

Browse files
committed
---
yaml --- r: 59054 b: refs/heads/incoming c: d546493 h: refs/heads/master v: v3
1 parent a3650b5 commit 4cdf9d0

File tree

5 files changed

+77
-49
lines changed

5 files changed

+77
-49
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: c50a9d5b664478e533ba1d1d353213d70c8ad589
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/incoming: 017e7e8be1906841451284de53c536e475046dc9
9+
refs/heads/incoming: d546493096f35e68cbcd9b5d3d7654e7a9345744
1010
refs/heads/dist-snap: 00dbbd01c2aee72982b3e0f9511ae1d4428c3ba9
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/doc/tutorial.md

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ we have a file `hello.rs` containing this program:
129129

130130
~~~~
131131
fn main() {
132-
println("hello?");
132+
io::println("hello?");
133133
}
134134
~~~~
135135

@@ -139,12 +139,12 @@ Windows) which, upon running, will likely do exactly what you expect.
139139

140140
The Rust compiler tries to provide useful information when it encounters an
141141
error. If you introduce an error into the program (for example, by changing
142-
`println` to some nonexistent function), and then compile it, you'll see
142+
`io::println` to some nonexistent function), and then compile it, you'll see
143143
an error message like this:
144144

145145
~~~~ {.notrust}
146-
hello.rs:2:4: 2:16 error: unresolved name: print_with_unicorns
147-
hello.rs:2 print_with_unicorns("hello?");
146+
hello.rs:2:4: 2:16 error: unresolved name: io::print_with_unicorns
147+
hello.rs:2 io::print_with_unicorns("hello?");
148148
^~~~~~~~~~~~~~~~~~~~~~~
149149
~~~~
150150

@@ -227,7 +227,7 @@ let hi = "hi";
227227
let mut count = 0;
228228
229229
while count < 10 {
230-
println(fmt!("count: %?", count));
230+
io::println(fmt!("count: %?", count));
231231
count += 1;
232232
}
233233
~~~~
@@ -400,10 +400,10 @@ don't match the types of the arguments.
400400
~~~~
401401
# let mystery_object = ();
402402
403-
println(fmt!("%s is %d", "the answer", 43));
403+
io::println(fmt!("%s is %d", "the answer", 43));
404404
405405
// %? will conveniently print any type
406-
println(fmt!("what is this thing: %?", mystery_object));
406+
io::println(fmt!("what is this thing: %?", mystery_object));
407407
~~~~
408408

409409
[pf]: http://en.cppreference.com/w/cpp/io/c/fprintf
@@ -422,11 +422,11 @@ compulsory, an `if` can have an optional `else` clause, and multiple
422422

423423
~~~~
424424
if false {
425-
println("that's odd");
425+
io::println("that's odd");
426426
} else if true {
427-
println("right");
427+
io::println("right");
428428
} else {
429-
println("neither true nor false");
429+
io::println("neither true nor false");
430430
}
431431
~~~~
432432

@@ -454,10 +454,10 @@ executes its corresponding arm.
454454
~~~~
455455
# let my_number = 1;
456456
match my_number {
457-
0 => println("zero"),
458-
1 | 2 => println("one or two"),
459-
3..10 => println("three to ten"),
460-
_ => println("something else")
457+
0 => io::println("zero"),
458+
1 | 2 => io::println("one or two"),
459+
3..10 => io::println("three to ten"),
460+
_ => io::println("something else")
461461
}
462462
~~~~
463463

@@ -483,8 +483,8 @@ commas are optional.
483483
~~~
484484
# let my_number = 1;
485485
match my_number {
486-
0 => { println("zero") }
487-
_ => { println("something else") }
486+
0 => { io::println("zero") }
487+
_ => { io::println("something else") }
488488
}
489489
~~~
490490

@@ -560,7 +560,7 @@ let mut x = 5;
560560
loop {
561561
x += x - 3;
562562
if x % 5 == 0 { break; }
563-
println(int::to_str(x));
563+
io::println(int::to_str(x));
564564
}
565565
~~~~
566566

@@ -614,8 +614,8 @@ origin.y += 1.0; // ERROR: assigning to immutable field
614614
# struct Point { x: float, y: float }
615615
# let mypoint = Point { x: 0.0, y: 0.0 };
616616
match mypoint {
617-
Point { x: 0.0, y: yy } => { println(yy.to_str()); }
618-
Point { x: xx, y: yy } => { println(xx.to_str() + " " + yy.to_str()); }
617+
Point { x: 0.0, y: yy } => { io::println(yy.to_str()); }
618+
Point { x: xx, y: yy } => { io::println(xx.to_str() + " " + yy.to_str()); }
619619
}
620620
~~~~
621621

@@ -630,7 +630,7 @@ reuses the field name as the binding name.
630630
# struct Point { x: float, y: float }
631631
# let mypoint = Point { x: 0.0, y: 0.0 };
632632
match mypoint {
633-
Point { x, _ } => { println(x.to_str()) }
633+
Point { x, _ } => { io::println(x.to_str()) }
634634
}
635635
~~~
636636

@@ -1231,7 +1231,7 @@ something silly like
12311231
~~~
12321232
# struct Point { x: float, y: float }
12331233
let point = &@~Point { x: 10f, y: 20f };
1234-
println(fmt!("%f", point.x));
1234+
io::println(fmt!("%f", point.x));
12351235
~~~
12361236
12371237
The indexing operator (`[]`) also auto-dereferences.
@@ -1373,6 +1373,7 @@ and [`core::str`]. Here are some examples.
13731373
[`core::str`]: core/str.html
13741374

13751375
~~~
1376+
# use core::io::println;
13761377
# enum Crayon {
13771378
# Almond, AntiqueBrass, Apricot,
13781379
# Aquamarine, Asparagus, AtomicTangerine,
@@ -1427,6 +1428,7 @@ Rust also supports _closures_, functions that can access variables in
14271428
the enclosing scope.
14281429

14291430
~~~~
1431+
# use println = core::io::println;
14301432
fn call_closure_with_ten(b: &fn(int)) { b(10); }
14311433
14321434
let captured_var = 20;
@@ -1488,7 +1490,7 @@ fn mk_appender(suffix: ~str) -> @fn(~str) -> ~str {
14881490
14891491
fn main() {
14901492
let shout = mk_appender(~"!");
1491-
println(shout(~"hey ho, let's go"));
1493+
io::println(shout(~"hey ho, let's go"));
14921494
}
14931495
~~~~
14941496

@@ -1630,6 +1632,7 @@ And using this function to iterate over a vector:
16301632

16311633
~~~~
16321634
# use each = core::vec::each;
1635+
# use println = core::io::println;
16331636
each([2, 4, 8, 5, 16], |n| {
16341637
if *n % 2 != 0 {
16351638
println("found odd number!");
@@ -1646,6 +1649,7 @@ to the next iteration, write `loop`.
16461649

16471650
~~~~
16481651
# use each = core::vec::each;
1652+
# use println = core::io::println;
16491653
for each([2, 4, 8, 5, 16]) |n| {
16501654
if *n % 2 != 0 {
16511655
println("found odd number!");
@@ -1978,7 +1982,7 @@ struct TimeBomb {
19781982
impl Drop for TimeBomb {
19791983
fn finalize(&self) {
19801984
for old_iter::repeat(self.explosivity) {
1981-
println("blam!");
1985+
io::println("blam!");
19821986
}
19831987
}
19841988
}
@@ -2010,11 +2014,11 @@ and `~str`.
20102014
~~~~
20112015
# trait Printable { fn print(&self); }
20122016
impl Printable for int {
2013-
fn print(&self) { println(fmt!("%d", *self)) }
2017+
fn print(&self) { io::println(fmt!("%d", *self)) }
20142018
}
20152019
20162020
impl Printable for ~str {
2017-
fn print(&self) { println(*self) }
2021+
fn print(&self) { io::println(*self) }
20182022
}
20192023
20202024
# 1.print();
@@ -2303,7 +2307,7 @@ mod farm {
23032307
}
23042308
23052309
fn main() {
2306-
println(farm::chicken());
2310+
io::println(farm::chicken());
23072311
}
23082312
~~~~
23092313

@@ -2503,7 +2507,7 @@ pub fn explore() -> &str { "world" }
25032507
~~~~ {.xfail-test}
25042508
// main.rs
25052509
extern mod world;
2506-
fn main() { println(~"hello " + world::explore()); }
2510+
fn main() { io::println(~"hello " + world::explore()); }
25072511
~~~~
25082512

25092513
Now compile and run like this (adjust to your platform if necessary):

branches/incoming/src/libcore/unstable/intrinsics.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,17 @@ pub extern "rust-intrinsic" {
4242

4343
pub fn get_tydesc<T>() -> *();
4444

45-
pub fn init<T>() -> T;
45+
/// init is unsafe because it returns a zeroed-out datum,
46+
/// which is unsafe unless T is POD. We don't have a POD
47+
/// kind yet. (See #4074)
48+
pub unsafe fn init<T>() -> T;
4649

4750
#[cfg(not(stage0))]
4851
pub unsafe fn uninit<T>() -> T;
4952

50-
pub fn forget<T>(_: T) -> ();
53+
/// forget is unsafe because the caller is responsible for
54+
/// ensuring the argument is deallocated already
55+
pub unsafe fn forget<T>(_: T) -> ();
5156

5257
pub fn needs_drop<T>() -> bool;
5358

branches/incoming/src/librustc/middle/trans/expr.rs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,10 @@ fn trans_lvalue_unadjusted(bcx: block, expr: @ast::expr) -> DatumBlock {
968968
}
969969

970970
fn get_val(bcx: block, did: ast::def_id, const_ty: ty::t)
971-
-> ValueRef {
971+
-> ValueRef {
972+
// For external constants, we don't inline.
973+
let extern_const_values =
974+
&mut *bcx.ccx().extern_const_values;
972975
if did.crate == ast::local_crate {
973976
// The LLVM global has the type of its initializer,
974977
// which may not be equal to the enum's type for
@@ -977,25 +980,24 @@ fn trans_lvalue_unadjusted(bcx: block, expr: @ast::expr) -> DatumBlock {
977980
base::get_item_val(bcx.ccx(), did.node),
978981
T_ptr(type_of(bcx.ccx(), const_ty)))
979982
} else {
980-
// For external constants, we don't inline.
981-
match bcx.ccx().extern_const_values.find(&did) {
982-
None => {
983-
unsafe {
984-
let llty = type_of(bcx.ccx(), const_ty);
985-
let symbol = csearch::get_symbol(
986-
bcx.ccx().sess.cstore,
987-
did);
988-
let llval = llvm::LLVMAddGlobal(
989-
bcx.ccx().llmod,
990-
llty,
991-
transmute::<&u8,*i8>(&symbol[0]));
992-
bcx.ccx().extern_const_values.insert(
993-
did,
994-
llval);
995-
llval
996-
}
983+
match extern_const_values.find(&did) {
984+
None => {} // Continue.
985+
Some(llval) => {
986+
return *llval;
997987
}
998-
Some(llval) => *llval
988+
}
989+
990+
unsafe {
991+
let llty = type_of(bcx.ccx(), const_ty);
992+
let symbol = csearch::get_symbol(
993+
bcx.ccx().sess.cstore,
994+
did);
995+
let llval = llvm::LLVMAddGlobal(
996+
bcx.ccx().llmod,
997+
llty,
998+
transmute::<&u8,*i8>(&symbol[0]));
999+
extern_const_values.insert(did, llval);
1000+
llval
9991001
}
10001002
}
10011003
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use core::unstable::intrinsics::{init, forget};
12+
13+
// Test that the `forget` and `init` intrinsics are really unsafe
14+
pub fn main() {
15+
let stuff = init::<int>(); //~ ERROR access to unsafe function requires unsafe
16+
forget(stuff); //~ ERROR access to unsafe function requires unsafe
17+
}

0 commit comments

Comments
 (0)