Skip to content

librustc: Stop reexporting the standard modules from prelude. #6797

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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 6 additions & 3 deletions doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -1840,6 +1840,7 @@ is bounds-checked at run-time. When the check fails, it will put the
task in a _failing state_.

~~~~
# use std::task;
# do task::spawn_unlinked {

([1, 2, 3, 4])[0];
Expand Down Expand Up @@ -2168,7 +2169,7 @@ fn ten_times(f: &fn(int)) {
}
}

ten_times(|j| io::println(fmt!("hello, %d", j)));
ten_times(|j| println(fmt!("hello, %d", j)));

~~~~

Expand All @@ -2189,7 +2190,7 @@ An example:
let mut i = 0;

while i < 10 {
io::println("hello\n");
println("hello\n");
i = i + 1;
}
~~~~
Expand Down Expand Up @@ -2335,6 +2336,7 @@ for v.each |e| {
An example of a for loop over a series of integers:

~~~~
# use std::uint;
# fn bar(b:uint) { }
for uint::range(0, 256) |i| {
bar(i);
Expand Down Expand Up @@ -2798,6 +2800,7 @@ the vtable pointer for the `T` implementation of `R`, and the pointer value of `
An example of an object type:

~~~~~~~~
# use std::int;
trait Printable {
fn to_str(&self) -> ~str;
}
Expand All @@ -2807,7 +2810,7 @@ impl Printable for int {
}

fn print(a: @Printable) {
io::println(a.to_str());
println(a.to_str());
}

fn main() {
Expand Down
2 changes: 2 additions & 0 deletions doc/tutorial-ffi.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ A type with the same functionality as owned boxes can be implemented by
wrapping `malloc` and `free`:

~~~~
use std::cast;
use std::libc::{c_void, size_t, malloc, free};
use std::ptr;
use std::unstable::intrinsics;
use std::util;

Expand Down
26 changes: 24 additions & 2 deletions doc/tutorial-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ should interleave the output in vaguely random order.
~~~
# use std::io::print;
# use std::task::spawn;
# use std::int;

for int::range(0, 20) |child_task_number| {
do spawn {
Expand Down Expand Up @@ -236,6 +237,7 @@ Instead we can use a `SharedChan`, a type that allows a single
~~~
# use std::task::spawn;
# use std::comm::{stream, SharedChan};
# use std::uint;

let (port, chan) = stream();
let chan = SharedChan::new(chan);
Expand Down Expand Up @@ -269,6 +271,7 @@ might look like the example below.
~~~
# use std::task::spawn;
# use std::comm::stream;
# use std::vec;

// Create a vector of ports, one for each child task
let ports = do vec::from_fn(3) |init_val| {
Expand Down Expand Up @@ -310,6 +313,8 @@ the future needs to be mutable so that it can save the result for next time `get
Here is another example showing how futures allow you to background computations. The workload will
be distributed on the available cores.
~~~
# use std::vec;
# use std::uint;
fn partial_sum(start: uint) -> f64 {
let mut local_sum = 0f64;
for uint::range(start*100000, (start+1)*100000) |num| {
Expand Down Expand Up @@ -343,14 +348,17 @@ acts as a reference to the shared data and only this reference is shared and clo
Here is a small example showing how to use ARCs. We wish to run concurrently several computations on
a single large vector of floats. Each task needs the full vector to perform its duty.
~~~
# use std::vec;
# use std::uint;
# use std::rand;
use extra::arc::ARC;

fn pnorm(nums: &~[float], p: uint) -> float {
(vec::foldl(0.0, *nums, |a,b| a+(*b).pow(p as float) )).pow(1f / (p as float))
}

fn main() {
let numbers=vec::from_fn(1000000, |_| rand::random::<float>());
let numbers = vec::from_fn(1000000, |_| rand::random::<float>());
println(fmt!("Inf-norm = %?", numbers.max()));

let numbers_arc = ARC(numbers);
Expand All @@ -373,12 +381,16 @@ at the power given as argument and takes the inverse power of this value). The A
created by the line
~~~
# use extra::arc::ARC;
# let numbers=vec::from_fn(1000000, |_| rand::random::<float>());
# use std::vec;
# use std::rand;
# let numbers = vec::from_fn(1000000, |_| rand::random::<float>());
let numbers_arc=ARC(numbers);
~~~
and a clone of it is sent to each task
~~~
# use extra::arc::ARC;
# use std::vec;
# use std::rand;
# let numbers=vec::from_fn(1000000, |_| rand::random::<float>());
# let numbers_arc = ARC(numbers);
# let (port, chan) = stream();
Expand All @@ -389,6 +401,8 @@ copying only the wrapper and not its contents.
Each task recovers the underlying data by
~~~
# use extra::arc::ARC;
# use std::vec;
# use std::rand;
# let numbers=vec::from_fn(1000000, |_| rand::random::<float>());
# let numbers_arc=ARC(numbers);
# let (port, chan) = stream();
Expand Down Expand Up @@ -416,6 +430,7 @@ of all tasks are intertwined: if one fails, so do all the others.

~~~
# use std::task::spawn;
# use std::task;
# fn do_some_work() { loop { task::yield() } }
# do task::try {
// Create a child task that fails
Expand All @@ -437,6 +452,7 @@ field (representing a successful result) or an `Err` result (representing
termination with an error).

~~~
# use std::task;
# fn some_condition() -> bool { false }
# fn calculate_result() -> int { 0 }
let result: Result<int, ()> = do task::try {
Expand Down Expand Up @@ -479,6 +495,7 @@ By default, task failure is _bidirectionally linked_, which means that if
either task fails, it kills the other one.

~~~
# use std::task;
# fn sleep_forever() { loop { task::yield() } }
# do task::try {
do spawn {
Expand All @@ -501,6 +518,7 @@ before returning. Hence:
~~~
# use std::comm::{stream, Chan, Port};
# use std::task::{spawn, try};
# use std::task;
# fn sleep_forever() { loop { task::yield() } }
# do task::try {
let (receiver, sender): (Port<int>, Chan<int>) = stream();
Expand Down Expand Up @@ -528,6 +546,7 @@ Supervised task failure propagates across multiple generations even if
an intermediate generation has already exited:

~~~
# use std::task;
# fn sleep_forever() { loop { task::yield() } }
# fn wait_for_a_while() { for 1000.times { task::yield() } }
# do task::try::<int> {
Expand All @@ -546,6 +565,7 @@ Finally, tasks can be configured to not propagate failure to each
other at all, using `task::spawn_unlinked` for _isolated failure_.

~~~
# use std::task;
# fn random() -> uint { 100 }
# fn sleep_for(i: uint) { for i.times { task::yield() } }
# do task::try::<()> {
Expand Down Expand Up @@ -574,6 +594,7 @@ Here is the function that implements the child task:

~~~~
# use extra::comm::DuplexStream;
# use std::uint;
fn stringifier(channel: &DuplexStream<~str, uint>) {
let mut value: uint;
loop {
Expand All @@ -596,6 +617,7 @@ Here is the code for the parent task:

~~~~
# use std::task::spawn;
# use std::uint;
# use extra::comm::DuplexStream;
# fn stringifier(channel: &DuplexStream<~str, uint>) {
# let mut value: uint;
Expand Down
5 changes: 5 additions & 0 deletions doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ types.
> items.

~~~~
# use std::float;
fn angle(vector: (float, float)) -> float {
let pi = float::consts::pi;
match vector {
Expand Down Expand Up @@ -556,6 +557,7 @@ while cake_amount > 0 {
`loop` denotes an infinite loop, and is the preferred way of writing `while true`:

~~~~
# use std::int;
let mut x = 5;
loop {
x += x - 3;
Expand Down Expand Up @@ -699,6 +701,7 @@ get at their contents. All variant constructors can be used as
patterns, as in this definition of `area`:

~~~~
# use std::float;
# struct Point {x: float, y: float}
# enum Shape { Circle(Point, float), Rectangle(Point, Point) }
fn area(sh: Shape) -> float {
Expand Down Expand Up @@ -1829,6 +1832,7 @@ vector consisting of the result of applying `function` to each element
of `vector`:

~~~~
# use std::vec;
fn map<T, U>(vector: &[T], function: &fn(v: &T) -> U) -> ~[U] {
let mut accumulator = ~[];
for vec::each(vector) |element| {
Expand Down Expand Up @@ -2026,6 +2030,7 @@ themselves contain type parameters. A trait for generalized sequence
types might look like the following:

~~~~
# use std::vec;
trait Seq<T> {
fn len(&self) -> uint;
fn iter(&self, b: &fn(v: &T));
Expand Down
13 changes: 10 additions & 3 deletions src/compiletest/compiletest.rc
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
#[no_std];

extern mod core(name = "std", vers = "0.7-pre");
extern mod std(name = "extra", vers = "0.7-pre");
extern mod extra(name = "extra", vers = "0.7-pre");

use core::prelude::*;
use core::*;

use std::getopts;
use std::test;
use extra::getopts;
use extra::test;

use core::result::{Ok, Err};

Expand All @@ -42,6 +42,13 @@ pub mod runtest;
pub mod common;
pub mod errors;

mod std {
pub use core::cmp;
pub use core::str;
pub use core::sys;
pub use core::unstable;
}

pub fn main() {
let args = os::args();
let config = parse_config(args);
Expand Down
3 changes: 3 additions & 0 deletions src/compiletest/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

use core::prelude::*;

use core::io;
use core::str;

pub struct ExpectedError { line: uint, kind: ~str, msg: ~str }

// Load any test directives embedded in the file
Expand Down
6 changes: 5 additions & 1 deletion src/compiletest/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@

use core::prelude::*;

use common;
use common::config;
use common;

use core::io;
use core::os;
use core::str;

pub struct TestProps {
// Lines that should be expected, in order, on standard out
Expand Down
6 changes: 6 additions & 0 deletions src/compiletest/procsrv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@

use core::prelude::*;

use core::comm;
use core::io;
use core::libc::c_int;
use core::os;
use core::run;
use core::str;
use core::task;

#[cfg(target_os = "win32")]
fn target_env(lib_path: &str, prog: &str) -> ~[(~str,~str)] {
Expand Down
6 changes: 6 additions & 0 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ use procsrv;
use util;
use util::logv;

use core::io;
use core::os;
use core::str;
use core::uint;
use core::vec;

pub fn run(config: config, testfile: ~str) {
if config.verbose {
// We're going to be dumping a lot of info. Start on a new line.
Expand Down
1 change: 1 addition & 0 deletions src/compiletest/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use core::prelude::*;

use common::config;

use core::io;
use core::os::getenv;

pub fn make_new_path(path: &str) -> ~str {
Expand Down
Loading