Skip to content

Commit 1cfece6

Browse files
committed
---
yaml --- r: 85703 b: refs/heads/dist-snap c: 35ec01a h: refs/heads/master i: 85701: 1b570ed 85699: f08ceb0 85695: 768d2ea v: v3
1 parent afe20d0 commit 1cfece6

File tree

8 files changed

+73
-36
lines changed

8 files changed

+73
-36
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: 0983ebe5310d4eb6d289f636f7ed0536c08bbc0e
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: 77df8b809a3927ffcdd2c43d48783c97a25712a8
9+
refs/heads/dist-snap: 35ec01a3f72313d098722163e74f84bd1d047296
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/doc/rust.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,38 @@ In this example, the module `quux` re-exports all of the public names defined in
851851

852852
Also note that the paths contained in `use` items are relative to the crate root.
853853
So, in the previous example, the `use` refers to `quux::foo::*`, and not simply to `foo::*`.
854+
This also means that top-level module declarations should be at the crate root if direct usage
855+
of the declared modules within `use` items is desired. It is also possible to use `self` and `super`
856+
at the beginning of a `use` item to refer to the current and direct parent modules respectively.
857+
All rules regarding accessing declared modules in `use` declarations applies to both module declarations
858+
and `extern mod` declarations.
859+
860+
An example of what will and will not work for `use` items:
861+
~~~~
862+
# #[allow(unused_imports)];
863+
use foo::extra; // good: foo is at the root of the crate
864+
use foo::baz::foobaz; // good: foo is at the root of the crate
865+
866+
mod foo {
867+
extern mod extra;
868+
869+
use foo::extra::list; // good: foo is at crate root
870+
// use extra::*; // bad: extra is not at the crate root
871+
use self::baz::foobaz; // good: self refers to module 'foo'
872+
use foo::bar::foobar; // good: foo is at crate root
873+
874+
pub mod bar {
875+
pub fn foobar() { }
876+
}
877+
878+
pub mod baz {
879+
use super::bar::foobar; // good: super refers to module 'foo'
880+
pub fn foobaz() { }
881+
}
882+
}
883+
884+
fn main() {}
885+
~~~~
854886

855887
### Functions
856888

branches/dist-snap/src/librust/rust.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl ValidUsage {
4545

4646
enum Action {
4747
Call(extern "Rust" fn(args: &[~str]) -> ValidUsage),
48-
CallMain(&'static str, extern "Rust" fn(&[~str])),
48+
CallMain(&'static str, extern "Rust" fn()),
4949
}
5050

5151
enum UsageSource<'self> {
@@ -69,7 +69,7 @@ static NUM_OF_COMMANDS: uint = 7;
6969
static COMMANDS: [Command<'static>, .. NUM_OF_COMMANDS] = [
7070
Command{
7171
cmd: "build",
72-
action: CallMain("rustc", rustc::main_args),
72+
action: CallMain("rustc", rustc::main),
7373
usage_line: "compile rust source files",
7474
usage_full: UsgCall(rustc_help),
7575
},
@@ -95,19 +95,19 @@ static COMMANDS: [Command<'static>, .. NUM_OF_COMMANDS] = [
9595
},
9696
Command{
9797
cmd: "doc",
98-
action: CallMain("rustdoc", rustdoc::main_args),
98+
action: CallMain("rustdoc", rustdoc::main),
9999
usage_line: "generate documentation from doc comments",
100100
usage_full: UsgCall(rustdoc::config::usage),
101101
},
102102
Command{
103103
cmd: "pkg",
104-
action: CallMain("rustpkg", rustpkg::main_args),
104+
action: CallMain("rustpkg", rustpkg::main),
105105
usage_line: "download, build, install rust packages",
106106
usage_full: UsgCall(rustpkg::usage::general),
107107
},
108108
Command{
109109
cmd: "sketch",
110-
action: CallMain("rusti", rusti::main_args),
110+
action: CallMain("rusti", rusti::main),
111111
usage_line: "run a rust interpreter",
112112
usage_full: UsgStr("\nUsage:\trusti"),
113113
},
@@ -164,7 +164,7 @@ fn cmd_test(args: &[~str]) -> ValidUsage {
164164
[ref filename] => {
165165
let test_exec = Path(*filename).filestem().unwrap() + "test~";
166166
invoke("rustc", &[~"--test", filename.to_owned(),
167-
~"-o", test_exec.to_owned()], rustc::main_args);
167+
~"-o", test_exec.to_owned()], rustc::main);
168168
let exit_code = run::process_status(~"./" + test_exec, []);
169169
Valid(exit_code)
170170
}
@@ -177,18 +177,19 @@ fn cmd_run(args: &[~str]) -> ValidUsage {
177177
[ref filename, ..prog_args] => {
178178
let exec = Path(*filename).filestem().unwrap() + "~";
179179
invoke("rustc", &[filename.to_owned(), ~"-o", exec.to_owned()],
180-
rustc::main_args);
180+
rustc::main);
181181
let exit_code = run::process_status(~"./"+exec, prog_args);
182182
Valid(exit_code)
183183
}
184184
_ => Invalid
185185
}
186186
}
187187

188-
fn invoke(prog: &str, args: &[~str], f: &fn(&[~str])) {
188+
fn invoke(prog: &str, args: &[~str], f: &fn()) {
189189
let mut osargs = ~[prog.to_owned()];
190190
osargs.push_all_move(args.to_owned());
191-
f(osargs);
191+
os::set_args(osargs);
192+
f();
192193
}
193194

194195
fn do_command(command: &Command, args: &[~str]) -> ValidUsage {

branches/dist-snap/src/librustc/rustc.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,11 @@ pub fn describe_debug_flags() {
191191
}
192192
}
193193

194-
pub fn run_compiler(args: &[~str], demitter: diagnostic::Emitter) {
194+
pub fn run_compiler(args: &~[~str], demitter: diagnostic::Emitter) {
195195
// Don't display log spew by default. Can override with RUST_LOG.
196196
::std::logging::console_off();
197197

198-
let mut args = args.to_owned();
198+
let mut args = (*args).clone();
199199
let binary = args.shift().to_managed();
200200

201201
if args.is_empty() { usage(binary); return; }
@@ -381,12 +381,7 @@ pub fn monitor(f: ~fn(diagnostic::Emitter)) {
381381

382382
pub fn main() {
383383
let args = os::args();
384-
main_args(args);
385-
}
386-
387-
pub fn main_args(args: &[~str]) {
388-
let owned_args = args.to_owned();
389384
do monitor |demitter| {
390-
run_compiler(owned_args, demitter);
385+
run_compiler(&args, demitter);
391386
}
392387
}

branches/dist-snap/src/librustdoc/rustdoc.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,7 @@ pub mod prune_private_pass;
5959

6060
pub fn main() {
6161
let args = os::args();
62-
main_args(args);
63-
}
6462

65-
pub fn main_args(args: &[~str]) {
6663
if args.iter().any(|x| "-h" == *x) || args.iter().any(|x| "--help" == *x) {
6764
config::usage();
6865
return;

branches/dist-snap/src/librusti/rusti.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -498,13 +498,9 @@ pub fn run_line(repl: &mut Repl, input: @io::Reader, out: @io::Writer, line: ~st
498498
}
499499

500500
pub fn main() {
501-
let args = os::args();
502-
main_args(args);
503-
}
504-
505-
pub fn main_args(args: &[~str]) {
506501
#[fixed_stack_segment]; #[inline(never)];
507502

503+
let args = os::args();
508504
let input = io::stdin();
509505
let out = io::stdout();
510506
let mut repl = Repl {

branches/dist-snap/src/librustpkg/rustpkg.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -466,11 +466,8 @@ impl CtxMethods for Ctx {
466466

467467
pub fn main() {
468468
io::println("WARNING: The Rust package manager is experimental and may be unstable");
469-
let args = os::args();
470-
main_args(args);
471-
}
472469

473-
pub fn main_args(args: &[~str]) {
470+
let args = os::args();
474471
let opts = ~[getopts::optflag("h"), getopts::optflag("help"),
475472
getopts::optflag("j"), getopts::optflag("json"),
476473
getopts::optmulti("c"), getopts::optmulti("cfg")];

branches/dist-snap/src/libstd/os.rs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use iterator::range;
3636
use libc;
3737
use libc::{c_char, c_void, c_int, size_t};
3838
use libc::FILE;
39+
use local_data;
3940
use option::{Some, None};
4041
use os;
4142
use prelude::*;
@@ -1187,7 +1188,7 @@ unsafe fn load_argc_and_argv(argc: c_int, argv: **c_char) -> ~[~str] {
11871188
* Returns a list of the command line arguments.
11881189
*/
11891190
#[cfg(target_os = "macos")]
1190-
fn real_args() -> ~[~str] {
1191+
pub fn real_args() -> ~[~str] {
11911192
#[fixed_stack_segment]; #[inline(never)];
11921193

11931194
unsafe {
@@ -1200,7 +1201,7 @@ fn real_args() -> ~[~str] {
12001201
#[cfg(target_os = "linux")]
12011202
#[cfg(target_os = "android")]
12021203
#[cfg(target_os = "freebsd")]
1203-
fn real_args() -> ~[~str] {
1204+
pub fn real_args() -> ~[~str] {
12041205
use rt;
12051206

12061207
match rt::args::clone() {
@@ -1210,7 +1211,7 @@ fn real_args() -> ~[~str] {
12101211
}
12111212

12121213
#[cfg(windows)]
1213-
fn real_args() -> ~[~str] {
1214+
pub fn real_args() -> ~[~str] {
12141215
#[fixed_stack_segment]; #[inline(never)];
12151216

12161217
let mut nArgs: c_int = 0;
@@ -1260,10 +1261,28 @@ struct OverriddenArgs {
12601261
val: ~[~str]
12611262
}
12621263

1264+
static overridden_arg_key: local_data::Key<@OverriddenArgs> = &local_data::Key;
1265+
12631266
/// Returns the arguments which this program was started with (normally passed
12641267
/// via the command line).
1268+
///
1269+
/// The return value of the function can be changed by invoking the
1270+
/// `os::set_args` function.
12651271
pub fn args() -> ~[~str] {
1266-
real_args()
1272+
match local_data::get(overridden_arg_key, |k| k.map(|&k| *k)) {
1273+
None => real_args(),
1274+
Some(args) => args.val.clone()
1275+
}
1276+
}
1277+
1278+
/// For the current task, overrides the task-local cache of the arguments this
1279+
/// program had when it started. These new arguments are only available to the
1280+
/// current task via the `os::args` method.
1281+
pub fn set_args(new_args: ~[~str]) {
1282+
let overridden_args = @OverriddenArgs {
1283+
val: new_args.clone()
1284+
};
1285+
local_data::set(overridden_arg_key, overridden_args);
12671286
}
12681287

12691288
// FIXME #6100 we should really use an internal implementation of this - using
@@ -1751,7 +1770,7 @@ mod tests {
17511770
use libc;
17521771
use option::Some;
17531772
use option;
1754-
use os::{env, getcwd, getenv, make_absolute, args};
1773+
use os::{env, getcwd, getenv, make_absolute, real_args};
17551774
use os::{remove_file, setenv, unsetenv};
17561775
use os;
17571776
use path::Path;
@@ -1769,7 +1788,7 @@ mod tests {
17691788
17701789
#[test]
17711790
pub fn test_args() {
1772-
let a = args();
1791+
let a = real_args();
17731792
assert!(a.len() >= 1);
17741793
}
17751794

0 commit comments

Comments
 (0)