It's too easy to forget the `rust` tag to test something.
Closes #11698
#[allow(non_camel_case_types)];
#[deny(warnings)];
-extern mod extra;
-extern mod getopts;
+extern crate extra;
+extern crate getopts;
use std::os;
use std::io;
-<link rel="shortcut icon" href="http://www.rust-lang.org/favicon.ico" />
\ No newline at end of file
+<link rel="shortcut icon" href="http://www.rust-lang.org/favicon.ico" />
let x = mem::uninit(); // dummy value to swap in
// We need to move the object out of the box, so that
// the destructor is called (at the end of this scope.)
- ptr::replace_ptr(self.ptr, x);
+ ptr::replace(self.ptr, x);
free(self.ptr as *mut c_void)
}
}
The former example showed how a global function can be called from C code.
However it is often desired that the callback is targetted to a special
Rust object. This could be the object that represents the wrapper for the
-respective C object.
+respective C object.
This can be achieved by passing an unsafe pointer to the object down to the
C library. The C library can then include the pointer to the Rust object in
fn main() {
// Create the object that will be referenced in the callback
let rust_object = ~RustObject{a: 5, ...};
-
+
unsafe {
// Gets a raw pointer to the object
let target_addr:*RustObject = ptr::to_unsafe_ptr(rust_object);
that invoked the callback into a Rust task.
If an asychronous callback targets a special object in the Rust address space
-it is also absolutely necessary that no more callbacks are performed by the
-C library after the respective Rust object gets destroyed.
+it is also absolutely necessary that no more callbacks are performed by the
+C library after the respective Rust object gets destroyed.
This can be achieved by unregistering the callback in the object's
destructor and designing the library in a way that guarantees that no
callback will be performed after unregistration.
Whereas this program explicitly opts into using a particular runtime
~~~{.rust}
-extern mod green;
+extern crate green;
#[start]
fn start(argc: int, argv: **u8) -> int {
The basic example below illustrates this.
~~~
-# extern mod sync;
+# extern crate sync;
# fn main() {
# fn make_a_sandwich() {};
be distributed on the available cores.
~~~
-# extern mod sync;
+# extern crate sync;
# use std::vec;
fn partial_sum(start: uint) -> f64 {
let mut local_sum = 0f64;
a single large vector of floats. Each task needs the full vector to perform its duty.
~~~
-# extern mod sync;
+# extern crate sync;
# use std::vec;
# use std::rand;
use sync::Arc;
created by the line
~~~
-# extern mod sync;
+# extern crate sync;
# use sync::Arc;
# use std::vec;
# use std::rand;
and a clone of it is sent to each task
~~~
-# extern mod sync;
+# extern crate sync;
# use sync::Arc;
# use std::vec;
# use std::rand;
Each task recovers the underlying data by
~~~
-# extern mod sync;
+# extern crate sync;
# use sync::Arc;
# use std::vec;
# use std::rand;
Here is the function that implements the child task:
~~~
-# extern mod sync;
+# extern crate sync;
# fn main() {
# use sync::DuplexStream;
fn stringifier(channel: &DuplexStream<~str, uint>) {
Here is the code for the parent task:
~~~
-# extern mod sync;
+# extern crate sync;
# use std::task::spawn;
# use sync::DuplexStream;
# fn stringifier(channel: &DuplexStream<~str, uint>) {
For example:
~~~
-extern mod extra;
+extern crate extra;
use std::vec;
use extra::test::BenchHarness;
it entirely.
~~~
-extern mod extra;
+extern crate extra;
use extra::test::BenchHarness;
#[bench]
#. type: Plain text
#: src/doc/complement-cheatsheet.md:122
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"~~~\n"
"struct Foo {\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#: src/doc/guide-conditions.md:262
#, fuzzy
#| msgid ""
-#| "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello "
+#| "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello "
#| "\" + world::explore()); } ~~~~"
msgid "fn main() {"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#. type: Plain text
#: src/doc/guide-container.md:85
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"impl Iterator<int> for ZeroStream {\n"
" fn next(&mut self) -> Option<int> {\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#. type: Plain text
#: src/doc/guide-ffi.md:323
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"struct RustObject {\n"
" a: i32,\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#: src/doc/guide-pointers.md:141 src/doc/guide-pointers.md:221
#: src/doc/guide-pointers.md:238 src/doc/guide-pointers.md:300
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"~~~rust\n"
"struct Point {\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#. type: Plain text
#: src/doc/guide-pointers.md:189
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"~~~rust\n"
"enum List<T> {\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#. type: Plain text
#: src/doc/guide-pointers.md:269
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"~~~rust{.ignore}\n"
"struct Point {\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#. type: Plain text
#: src/doc/guide-pointers.md:341
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"struct Point {\n"
" x: f32,\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#. type: Plain text
#: src/doc/guide-pointers.md:378
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"~~~rust{.ignore}\n"
"fn main() {\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#. type: Plain text
#: src/doc/guide-pointers.md:450
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"fn main() {\n"
" let x = ~5;\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#. type: Plain text
#: src/doc/guide-pointers.md:463
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"fn main() {\n"
" let x = ~5;\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#. type: Plain text
#: src/doc/guide-pointers.md:477
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"fn main() {\n"
" let x = ~5;\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#: src/doc/guide-runtime.md:231
#, fuzzy
#| msgid ""
-#| "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello "
+#| "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello "
#| "\" + world::explore()); } ~~~~"
msgid "~~~{.rust} fn main() {} ~~~"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#: src/doc/guide-runtime.md:236
#, fuzzy
#| msgid "~~~~ {.ignore} let foo = 10;"
-msgid "~~~{.rust} extern mod green;"
+msgid "~~~{.rust} extern crate green;"
msgstr ""
"~~~~ {.ignore}\n"
"let foo = 10;"
#: src/doc/guide-runtime.md:246
#, fuzzy
#| msgid ""
-#| "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello "
+#| "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello "
#| "\" + world::explore()); } ~~~~"
msgid "fn main() {} ~~~"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#: src/doc/guide-testing.md:131
#, fuzzy
#| msgid "~~~~ use std::task::spawn;"
-msgid "~~~ extern mod extra; use std::vec;"
+msgid "~~~ extern crate extra; use std::vec;"
msgstr ""
"~~~~\n"
"use std::task::spawn;"
#: src/doc/rust.md:786
#, fuzzy
#| msgid "## Using other crates"
-msgid "Four examples of `extern mod` declarations:"
+msgid "Four examples of `extern crate` declarations:"
msgstr "## 他のクレートの利用"
#. type: Plain text
#: src/doc/rust.md:789
#, fuzzy
#| msgid "~~~~ {.ignore} let foo = 10;"
-msgid "~~~~ {.ignore} extern mod pcre;"
+msgid "~~~~ {.ignore} extern crate pcre;"
msgstr ""
"~~~~ {.ignore}\n"
"let foo = 10;"
#| msgid "~~~~ {.ignore} let foo = 10;"
msgid ""
"mod foo {\n"
-" extern mod extra;\n"
+" extern crate extra;\n"
msgstr ""
"~~~~ {.ignore}\n"
"let foo = 10;"
#: src/doc/rust.md:901
#, fuzzy
#| msgid ""
-#| "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello "
+#| "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello "
#| "\" + world::explore()); } ~~~~"
msgid "fn main() {} ~~~~"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#. type: Plain text
#: src/doc/rust.md:1420
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"struct Circle {\n"
" radius: f64,\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#: src/doc/rust.md:1644 src/doc/rust.md:1665
#, fuzzy
#| msgid ""
-#| "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello "
+#| "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello "
#| "\" + world::explore()); } ~~~~"
msgid "# fn main() {} ~~~~"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#. type: Plain text
#: src/doc/rust.md:1953
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"~~~~\n"
"#[deriving(Eq, Clone)]\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#. type: Plain text
#: src/doc/rust.md:2702
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"while i < 10 {\n"
" println!(\"hello\");\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#. type: Plain text
#: src/doc/rust.md:2774
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"for e in v.iter() {\n"
" bar(*e);\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#. type: Plain text
#: src/doc/rust.md:3314
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"~~~~\n"
"trait Printable {\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#. type: Plain text
#: src/doc/rust.md:3318
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"impl Printable for int {\n"
" fn to_string(&self) -> ~str { self.to_str() }\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#. type: Plain text
#: src/doc/rust.md:3327
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"fn main() {\n"
" print(@10 as @Printable);\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#. type: Plain text
#: src/doc/rust.md:3359
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"~~~~\n"
"trait Printable {\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#. type: Plain text
#: src/doc/rust.md:3366
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"impl Printable for ~str {\n"
" fn make_string(&self) -> ~str {\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#. type: Plain text
#: src/doc/tutorial.md:136
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"~~~~\n"
"fn main() {\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#. type: Plain text
#: src/doc/tutorial.md:222
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"while count < 10 {\n"
" println!(\"count is {}\", count);\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#. type: Plain text
#: src/doc/tutorial.md:602
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"~~~~\n"
"struct Point {\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#. type: Plain text
#: src/doc/tutorial.md:986
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"struct Foo {\n"
" a: u32,\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#. type: Plain text
#: src/doc/tutorial.md:1376
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"~~~\n"
"struct Point {\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#. type: Plain text
#: src/doc/tutorial.md:2110
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"~~~\n"
"struct TimeBomb {\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#. type: Plain text
#: src/doc/tutorial.md:2135
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"~~~~\n"
"trait Printable {\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#. type: Plain text
#: src/doc/tutorial.md:2160 src/doc/tutorial.md:2206
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"impl Printable for ~str {\n"
" fn print(&self) { println!(\"{}\", *self) }\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#. type: Plain text
#: src/doc/tutorial.md:2185
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"impl Printable for bool {\n"
" fn print(&self) { println!(\"{:?}\", *self) }\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#. type: Plain text
#: src/doc/tutorial.md:2235
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"~~~~\n"
"trait Seq<T> {\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#. type: Plain text
#: src/doc/tutorial.md:2240
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"impl<T> Seq<T> for ~[T] {\n"
" fn length(&self) -> uint { self.len() }\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#. type: Plain text
#: src/doc/tutorial.md:2554
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"~~~~\n"
"// `main.rs`\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#. type: Plain text
#: src/doc/tutorial.md:2587
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"fn main() {\n"
" println!(\"Hello farm!\");\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#. type: Plain text
#: src/doc/tutorial.md:2607
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"fn main() {\n"
" println!(\"Hello chicken!\");\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#. type: Plain text
#: src/doc/tutorial.md:2639
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"fn main() {\n"
" println!(\"Hello chicken!\");\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#. type: Plain text
#: src/doc/tutorial.md:2719
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"fn main() {\n"
" println!(\"Hello farm!\");\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#: src/doc/tutorial.md:2897
#, fuzzy
#| msgid ""
-#| "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello "
+#| "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello "
#| "\" + world::explore()); } ~~~~"
msgid "fn main() { cow() } ~~~"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#. type: Plain text
#: src/doc/tutorial.md:2916
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"fn main() {\n"
" println!(\"Hello farm!\");\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#. type: Plain text
#: src/doc/tutorial.md:2923
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
" // Can now refer to those names directly:\n"
" chicken();\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#: src/doc/tutorial.md:2932
#, fuzzy
#| msgid ""
-#| "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello "
+#| "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello "
#| "\" + world::explore()); } ~~~~"
msgid ""
"~~~{.ignore} // `a.rs` - crate root use b::foo; mod b; fn main() { foo(); } "
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#: src/doc/tutorial.md:2939
#, fuzzy
#| msgid ""
-#| "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello "
+#| "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello "
#| "\" + world::explore()); } ~~~~"
msgid ""
"~~~{.ignore} // `b.rs` use b::c::bar; pub mod c; pub fn foo() { bar(); } ~~~"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#. type: Plain text
#: src/doc/tutorial.md:2985
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"fn main() {\n"
" egg_layer();\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#. type: Plain text
#: src/doc/tutorial.md:3014
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"fn main() {\n"
" farm::chicken();\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#: src/doc/tutorial.md:3035
#, fuzzy
#| msgid "## Using other crates"
-msgid "For that, Rust offers you the `extern mod` declaration:"
+msgid "For that, Rust offers you the `extern crate` declaration:"
msgstr "## 他のクレートの利用"
#. type: Plain text
#: src/doc/tutorial.md:3045
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"fn main() {\n"
" // The rational number '1/2':\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#: src/doc/tutorial.md:3068
#, fuzzy
#| msgid "~~~~ {.ignore} let foo = 10;"
-msgid "~~~ extern mod extra;"
+msgid "~~~ extern crate extra;"
msgstr ""
"~~~~ {.ignore}\n"
"let foo = 10;"
#. type: Plain text
#: src/doc/tutorial.md:3081
#, fuzzy, no-wrap
-#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
+#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"fn main() {\n"
" farm::dog();\n"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#: src/doc/tutorial.md:3123
#, fuzzy
#| msgid ""
-#| "~~~~ {.ignore} extern mod farm; extern mod my_farm (name = \"farm\", vers "
-#| "= \"2.5\"); extern mod my_auxiliary_farm (name = \"farm\", author = \"mjh"
+#| "~~~~ {.ignore} extern crate farm; extern crate my_farm (name = \"farm\", vers "
+#| "= \"2.5\"); extern crate my_auxiliary_farm (name = \"farm\", author = \"mjh"
#| "\"); ~~~~"
msgid ""
-"~~~~ {.ignore} extern mod farm; extern mod farm = \"farm#2.5\"; extern mod "
+"~~~~ {.ignore} extern crate farm; extern crate farm = \"farm#2.5\"; extern crate "
"my_farm = \"farm\"; ~~~~"
msgstr ""
"~~~~ {.ignore}\n"
-"extern mod farm;\n"
-"extern mod my_farm (name = \"farm\", vers = \"2.5\");\n"
-"extern mod my_auxiliary_farm (name = \"farm\", author = \"mjh\");\n"
+"extern crate farm;\n"
+"extern crate my_farm (name = \"farm\", vers = \"2.5\");\n"
+"extern crate my_auxiliary_farm (name = \"farm\", author = \"mjh\");\n"
"~~~~"
#. type: Plain text
#| "~~~~ // world.rs #[link(name = \"world\", vers = \"1.0\")]; pub fn "
#| "explore() -> &str { \"world\" } ~~~~"
msgid ""
-"~~~~ // `world.rs` #[crate_id = \"world#0.42\"]; # extern mod extra; pub fn "
+"~~~~ // `world.rs` #[crate_id = \"world#0.42\"]; # extern crate extra; pub fn "
"explore() -> &'static str { \"world\" } # fn main() {} ~~~~"
msgstr ""
"~~~~\n"
#: src/doc/tutorial.md:3159
#, fuzzy
#| msgid ""
-#| "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello "
+#| "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello "
#| "\" + world::explore()); } ~~~~"
msgid ""
-"~~~~ {.ignore} // `main.rs` extern mod world; fn main() { println!(\"hello "
+"~~~~ {.ignore} // `main.rs` extern crate world; fn main() { println!(\"hello "
"{}\", world::explore()); } ~~~~"
msgstr ""
"~~~~ {.ignore}\n"
"// main.rs\n"
-"extern mod world;\n"
+"extern crate world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
"~~~~"
#: src/doc/tutorial.md:3187
#, fuzzy
#| msgid "~~~~ {.ignore} let foo = 10;"
-msgid "~~~ {.ignore} extern mod std; ~~~"
+msgid "~~~ {.ignore} extern crate std; ~~~"
msgstr ""
"~~~~ {.ignore}\n"
"let foo = 10;"
View items do not define new items, but rather, simply change other items' visibility.
There are several kinds of view item:
- * [`extern mod` declarations](#extern-mod-declarations)
+ * [`extern crate` declarations](#extern-mod-declarations)
* [`use` declarations](#use-declarations)
##### Extern mod declarations
link_attr : ident '=' literal ;
~~~~
-An _`extern mod` declaration_ specifies a dependency on an external crate.
+An _`extern crate` declaration_ specifies a dependency on an external crate.
The external crate is then bound into the declaring scope
as the `ident` provided in the `extern_mod_decl`.
it was compiled. If no `crateid` is provided, a default `name` attribute is
assumed, equal to the `ident` given in the `extern_mod_decl`.
-Four examples of `extern mod` declarations:
+Four examples of `extern crate` declarations:
~~~~ {.ignore}
-extern mod pcre;
+extern crate pcre;
-extern mod extra; // equivalent to: extern mod extra = "extra";
+extern crate extra; // equivalent to: extern crate extra = "extra";
-extern mod rustextra = "extra"; // linking to 'extra' under another name
+extern crate rustextra = "extra"; // linking to 'extra' under another name
-extern mod foo = "some/where/rust-foo#foo:1.0"; // a full package ID for external tools
+extern crate foo = "some/where/rust-foo#foo:1.0"; // a full package ID for external tools
~~~~
##### Use declarations
*Note*: Unlike in many languages,
`use` declarations in Rust do *not* declare linkage dependency with external crates.
-Rather, [`extern mod` declarations](#extern-mod-declarations) declare linkage dependencies.
+Rather, [`extern crate` declarations](#extern-mod-declarations) declare linkage dependencies.
Use declarations support a number of convenient shortcuts:
of the declared modules within `use` items is desired. It is also possible to use `self` and `super`
at the beginning of a `use` item to refer to the current and direct parent modules respectively.
All rules regarding accessing declared modules in `use` declarations applies to both module declarations
-and `extern mod` declarations.
+and `extern crate` declarations.
An example of what will and will not work for `use` items:
use foo::baz::foobaz; // good: foo is at the root of the crate
mod foo {
- extern mod extra;
+ extern crate extra;
use foo::extra::time; // good: foo is at crate root
// use extra::*; // bad: extra is not at the crate root
To generate the docs, run `rustdoc universe.rs`. By default, it generates a
directory called `doc`, with the documentation for `universe` being in
-`doc/universe/index.html`. If you are using other crates with `extern mod`,
+`doc/universe/index.html`. If you are using other crates with `extern crate`,
rustdoc will even link to them when you use their types, as long as their
documentation has already been generated by a previous run of rustdoc, or the
crate advertises that its documentation is hosted at a given URL.
When testing a library, code examples will often show how functions are used,
and this code often requires `use`-ing paths from the crate. To accomodate this,
-rustdoc will implicitly add `extern mod <crate>;` where `<crate>` is the name of
+rustdoc will implicitly add `extern crate <crate>;` where `<crate>` is the name of
the crate being tested to the top of each code example. This means that rustdoc
must be able to find a compiled version of the library crate being tested. Extra
search paths may be added via the `-L` flag to `rustdoc`.
function, and the module `farm`. The module `farm` also contains two functions and a third module `barn`,
which contains a function `hay`.
-(In case you already stumbled over `extern mod`: It isn't directly related to a bare `mod`, we'll get to it later. )
+(In case you already stumbled over `extern crate`: It isn't directly related to a bare `mod`, we'll get to it later. )
## Paths and visibility
In Rust terminology, we need a way to refer to other crates.
-For that, Rust offers you the `extern mod` declaration:
+For that, Rust offers you the `extern crate` declaration:
~~~
-extern mod num;
+extern crate num;
// `num` ships with Rust (much like `extra`; more details further down).
fn main() {
}
~~~
-Despite its name, `extern mod` is a distinct construct from regular `mod` declarations:
-A statement of the form `extern mod foo;` will cause `rustc` to search for the crate `foo`,
+Despite its name, `extern crate` is a distinct construct from regular `mod` declarations:
+A statement of the form `extern crate foo;` will cause `rustc` to search for the crate `foo`,
and if it finds a matching binary it lets you use it from inside your crate.
The effect it has on your module hierarchy mirrors aspects of both `mod` and `use`:
- Like `mod`, it causes `rustc` to actually emit code:
The linkage information the binary needs to use the library `foo`.
-- But like `use`, all `extern mod` statements that refer to the same library are interchangeable,
+- But like `use`, all `extern crate` statements that refer to the same library are interchangeable,
as each one really just presents an alias to an external module (the crate root of the library
you're linking against).
Remember how `use`-statements have to go before local declarations because the latter shadows the former?
-Well, `extern mod` statements also have their own rules in that regard:
-Both `use` and local declarations can shadow them, so the rule is that `extern mod` has to go in front
+Well, `extern crate` statements also have their own rules in that regard:
+Both `use` and local declarations can shadow them, so the rule is that `extern crate` has to go in front
of both `use` and local declarations.
Which can result in something like this:
~~~
-extern mod num;
+extern crate num;
use farm::dog;
use num::rational::Ratio;
## Package ids
-If you use `extern mod`, per default `rustc` will look for libraries in the library search path (which you can
+If you use `extern crate`, per default `rustc` will look for libraries in the library search path (which you can
extend with the `-L` switch).
## Crate metadata and settings
# fn farm() {}
~~~~
-You can also specify package ID information in a `extern mod` statement. For
-example, these `extern mod` statements would both accept and select the
+You can also specify package ID information in a `extern crate` statement. For
+example, these `extern crate` statements would both accept and select the
crate define above:
~~~~ {.ignore}
-extern mod farm;
-extern mod farm = "farm#2.5";
-extern mod my_farm = "farm";
+extern crate farm;
+extern crate farm = "farm#2.5";
+extern crate my_farm = "farm";
~~~~
Other crate settings and metadata include things like enabling/disabling certain errors or warnings,
~~~~
// `world.rs`
#[crate_id = "world#0.42"];
-# extern mod extra;
+# extern crate extra;
pub fn explore() -> &'static str { "world" }
# fn main() {}
~~~~
~~~~ {.ignore}
// `main.rs`
-extern mod world;
+extern crate world;
fn main() { println!("hello {}", world::explore()); }
~~~~
The only magical thing that happens is that `rustc` automatically inserts this line into your crate root:
~~~ {.ignore}
-extern mod std;
+extern crate std;
~~~
As well as this line into every module body:
Rust ships with crates such as the [extra library], an accumulation of useful things,
that are however not important enough to deserve a place in the standard
-library. You can link to a library such as `extra` with an `extern mod extra;`.
+library. You can link to a library such as `extra` with an `extern crate extra;`.
[extra library]: extra/index.html
* [Macros][macros]
* [The foreign function interface][ffi]
* [Containers and iterators][container]
-* [Error-handling and Conditions][conditions]
* [Documenting Rust code][rustdoc]
* [Testing Rust code][testing]
* [The Rust Runtime][runtime]
[macros]: guide-macros.html
[ffi]: guide-ffi.html
[container]: guide-container.html
-[conditions]: guide-conditions.html
[testing]: guide-testing.html
[runtime]: guide-runtime.html
[rustdoc]: rustdoc.html
<span class="white-sticker"><a href="http://rust-lang.org">Rust</a> VERSION</span><br>
<a href="http://github.com/mozilla/rust/commit/STAMP"
class="hash white-sticker">SHORT_HASH</a>
-</div>
\ No newline at end of file
+</div>
// except according to those terms.
#[cfg(rustdoc)]
-extern mod this = "rustdoc";
+extern crate this = "rustdoc";
#[cfg(rustc)]
-extern mod this = "rustc";
+extern crate this = "rustc";
fn main() { this::main() }
"""
// AUTO-GENERATED FILE: DO NOT EDIT
#[feature(globs, managed_boxes)];
-extern mod extra;
-extern mod run_pass_stage2;
+extern crate extra;
+extern crate run_pass_stage2;
use run_pass_stage2::*;
use std::io;
use std::io::Writer;
(defconst rust-mode-keywords
'("as"
"break"
- "continue"
- "crate"
+ "continue" "crate"
"do"
"else" "enum" "extern"
"false" "fn" "for"
Negative argument -N means move back to Nth preceding end of defun.
Assume that this is called after beginning-of-defun. So point is
-at the beginning of the defun body.
+at the beginning of the defun body.
This is written mainly to be used as `end-of-defun-function' for Rust."
(interactive "p")
COMMENT_REGEX = re.compile(r'^# ')
COMPILER_DIRECTIVE_REGEX = re.compile(r'\#\[(.*)\];')
ELLIPSES_REGEX = re.compile(r'\.\.\.')
-EXTERN_MOD_REGEX = re.compile(r'\bextern mod extra\b')
+EXTERN_CRATE_REGEX = re.compile(r'\bextern crate extra\b')
MAIN_FUNCTION_REGEX = re.compile(r'\bfn main\b')
TAGS_REGEX = re.compile(r'\.([\w-]*)')
def add_extern_mod(block):
if not has_extern_mod(block):
- # add `extern mod extra;` after compiler directives
+ # add `extern crate extra;` after compiler directives
directives = []
while len(block) and is_compiler_directive(block[0]):
directives.append(block.popleft())
- block.appendleft("\nextern mod extra;\n\n")
+ block.appendleft("\nextern crate extra;\n\n")
block.extendleft(reversed(directives))
return block
def has_extern_mod(block):
- """Checks if a code block has the line `extern mod extra`."""
- find_extern_mod = lambda x: re.search(EXTERN_MOD_REGEX, x)
+ """Checks if a code block has the line `extern crate extra`."""
+ find_extern_mod = lambda x: re.search(EXTERN_CRATE_REGEX, x)
return any(imap(find_extern_mod, block))
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
-extern mod extra;
+extern crate extra;
{error_deriving}
struct Error;
#[allow(missing_doc)];
#[feature(managed_boxes)];
-extern mod collections;
-
-#[cfg(test)] extern mod extra;
+extern crate collections;
use collections::list::{List, Cons, Nil};
use collections::list;
#[cfg(test)]
mod test {
+ extern crate extra;
use super::{Arena, TypedArena};
- use extra::test::BenchHarness;
+ use self::extra::test::BenchHarness;
struct Point {
x: int,
/// Like Option::Some for Rawlink
fn some(n: &mut T) -> Rawlink<T> {
- Rawlink{p: ptr::to_mut_unsafe_ptr(n)}
+ Rawlink{p: n}
}
/// Convert the `Rawlink` into an Option value
#[feature(macro_rules, managed_boxes)];
-#[cfg(test)] extern mod extra;
-
-extern mod serialize;
+extern crate serialize;
+#[cfg(test)] extern crate extra; // benchmark tests need this
pub use bitv::Bitv;
pub use btree::BTree;
pub mod priority_queue;
pub mod ringbuf;
pub mod smallintmap;
-pub mod treemap;
\ No newline at end of file
+pub mod treemap;
To encode using Encodable :
```rust
-extern mod serialize;
+extern crate serialize;
use extra::json;
use std::io;
use serialize::Encodable;
```rust
-extern mod collections;
+extern crate collections;
use extra::json;
use extra::json::ToJson;
To decode a json string using `Decodable` trait :
```rust
-extern mod serialize;
+extern crate serialize;
use serialize::Decodable;
#[deriving(Decodable)]
using the serialization API, using the derived serialization code.
```rust
-extern mod serialize;
+extern crate serialize;
use extra::json;
use serialize::{Encodable, Decodable};
Example of `ToJson` trait implementation for TestStruct1.
```rust
-extern mod serialize;
-extern mod collections;
+extern crate serialize;
+extern crate collections;
use extra::json;
use extra::json::ToJson;
#[deny(non_camel_case_types)];
#[deny(missing_doc)];
-extern mod sync;
-extern mod serialize;
+extern crate sync;
+extern crate serialize;
-extern mod collections;
+extern crate collections;
// Utility modules
// simplest interface possible for representing and running tests
// while providing a base that other test frameworks may build off of.
-extern mod getopts;
-extern mod term;
+extern crate getopts;
+extern crate term;
use json::ToJson;
use json;
```rust,ignore
#[phase(syntax)]
-extern mod fourcc;
+extern crate fourcc;
fn main() {
let val = fourcc!("\xC0\xFF\xEE!");
#[feature(macro_registrar, managed_boxes)];
-extern mod syntax;
+extern crate syntax;
use syntax::ast;
use syntax::ast::Name;
//! file name following `-o`, and accepts both `-h` and `--help` as optional flags.
//!
//! ~~~{.rust}
-//! extern mod getopts;
+//! extern crate getopts;
//! use getopts::{optopt,optflag,getopts,OptGroup};
//! use std::os;
//!
//! # Starting with libgreen
//!
//! ```rust
-//! extern mod green;
+//! extern crate green;
//!
//! #[start]
//! fn start(argc: int, argv: **u8) -> int { green::start(argc, argv, main) }
use std::rt::task::BlockedTask;
use std::rt::task::Task;
use std::sync::deque;
-use std::unstable::mutex::Mutex;
+use std::unstable::mutex::NativeMutex;
use std::unstable::raw;
use TaskState;
// is acquired here. This is the resumption points and the "bounce"
// that it is referring to.
unsafe {
- current_task.nasty_deschedule_lock.lock();
- current_task.nasty_deschedule_lock.unlock();
+ let _guard = current_task.nasty_deschedule_lock.lock();
}
return current_task;
}
// to it, but we're guaranteed that the task won't exit until we've
// unlocked the lock so there's no worry of this memory going away.
let cur = self.change_task_context(cur, next, |sched, mut task| {
- let lock: *mut Mutex = &mut task.nasty_deschedule_lock;
- unsafe { (*lock).lock() }
- f(sched, BlockedTask::block(task.swap()));
- unsafe { (*lock).unlock() }
+ let lock: *mut NativeMutex = &mut task.nasty_deschedule_lock;
+ unsafe {
+ let _guard = (*lock).lock();
+ f(sched, BlockedTask::block(task.swap()));
+ }
});
cur.put();
}
#[test]
fn test_spawn_sched_blocking() {
- use std::unstable::mutex::{Mutex, MUTEX_INIT};
- static mut LOCK: Mutex = MUTEX_INIT;
+ use std::unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
+ static mut LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
// Testing that a task in one scheduler can block in foreign code
// without affecting other schedulers
let mut handle = pool.spawn_sched();
handle.send(PinnedTask(pool.task(TaskOpts::new(), proc() {
unsafe {
- LOCK.lock();
+ let mut guard = LOCK.lock();
start_ch.send(());
- LOCK.wait(); // block the scheduler thread
- LOCK.signal(); // let them know we have the lock
- LOCK.unlock();
+ guard.wait(); // block the scheduler thread
+ guard.signal(); // let them know we have the lock
}
fin_ch.send(());
child_ch.send(20);
pingpong(&parent_po, &child_ch);
unsafe {
- LOCK.lock();
- LOCK.signal(); // wakeup waiting scheduler
- LOCK.wait(); // wait for them to grab the lock
- LOCK.unlock();
+ let mut guard = LOCK.lock();
+ guard.signal(); // wakeup waiting scheduler
+ guard.wait(); // wait for them to grab the lock
}
})));
drop(handle);
use std::rt::rtio;
use std::rt::task::{Task, BlockedTask};
use std::task::TaskOpts;
-use std::unstable::sync::LittleLock;
+use std::unstable::mutex::NativeMutex;
struct SimpleTask {
- lock: LittleLock,
+ lock: NativeMutex,
awoken: bool,
}
to_wake.put_runtime(self as ~Runtime);
unsafe {
cast::forget(to_wake);
- let _l = (*me).lock.lock();
+ let mut guard = (*me).lock.lock();
(*me).awoken = true;
- (*me).lock.signal();
+ guard.signal();
}
}
pub fn task() -> ~Task {
let mut task = ~Task::new();
task.put_runtime(~SimpleTask {
- lock: LittleLock::new(),
+ lock: unsafe {NativeMutex::new()},
awoken: false,
} as ~Runtime);
return task;
use std::rt::rtio;
use std::rt::task::{Task, BlockedTask, SendMessage};
use std::task::TaskOpts;
-use std::unstable::mutex::Mutex;
+use std::unstable::mutex::NativeMutex;
use std::unstable::raw;
use context::Context;
pool_id: uint,
// See the comments in the scheduler about why this is necessary
- nasty_deschedule_lock: Mutex,
+ nasty_deschedule_lock: NativeMutex,
}
pub enum TaskType {
task_type: task_type,
sched: None,
handle: None,
- nasty_deschedule_lock: unsafe { Mutex::new() },
+ nasty_deschedule_lock: unsafe { NativeMutex::new() },
task: Some(~Task::new()),
}
}
// uncontended except for when the task is rescheduled).
fn reawaken_remotely(mut ~self) {
unsafe {
- let mtx = &mut self.nasty_deschedule_lock as *mut Mutex;
+ let mtx = &mut self.nasty_deschedule_lock as *mut NativeMutex;
let handle = self.handle.get_mut_ref() as *mut SchedHandle;
- (*mtx).lock();
+ let _guard = (*mtx).lock();
(*handle).send(RunOnce(self));
- (*mtx).unlock();
}
}
}
fn wrap(~self) -> ~Any { self as ~Any }
}
-impl Drop for GreenTask {
- fn drop(&mut self) {
- unsafe { self.nasty_deschedule_lock.destroy(); }
- }
-}
-
#[cfg(test)]
mod tests {
use std::rt::Runtime;
//! The green counterpart for this is bookkeeping on sched pools.
use std::sync::atomics;
-use std::unstable::mutex::{Mutex, MUTEX_INIT};
+use std::unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
static mut TASK_COUNT: atomics::AtomicUint = atomics::INIT_ATOMIC_UINT;
-static mut TASK_LOCK: Mutex = MUTEX_INIT;
+static mut TASK_LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
pub fn increment() {
let _ = unsafe { TASK_COUNT.fetch_add(1, atomics::SeqCst) };
pub fn decrement() {
unsafe {
if TASK_COUNT.fetch_sub(1, atomics::SeqCst) == 1 {
- TASK_LOCK.lock();
- TASK_LOCK.signal();
- TASK_LOCK.unlock();
+ let mut guard = TASK_LOCK.lock();
+ guard.signal();
}
}
}
/// the entry points of native programs
pub fn wait_for_other_tasks() {
unsafe {
- TASK_LOCK.lock();
- while TASK_COUNT.load(atomics::SeqCst) > 0 {
- TASK_LOCK.wait();
+ {
+ let mut guard = TASK_LOCK.lock();
+ while TASK_COUNT.load(atomics::SeqCst) > 0 {
+ guard.wait();
+ }
}
- TASK_LOCK.unlock();
TASK_LOCK.destroy();
}
}
}
unsafe {
- use std::unstable::mutex::{Mutex, MUTEX_INIT};
+ use std::unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
static mut INITIALIZED: bool = false;
- static mut LOCK: Mutex = MUTEX_INIT;
+ static mut LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
- LOCK.lock();
+ let _guard = LOCK.lock();
if !INITIALIZED {
let mut data: WSADATA = mem::init();
let ret = WSAStartup(0x202, // version 2.2
assert_eq!(ret, 0);
INITIALIZED = true;
}
- LOCK.unlock();
}
}
use std::cast;
use std::rt;
-use std::unstable::mutex::{Mutex, MUTEX_INIT};
+use std::unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
use bookkeeping;
use io::timer::{Req, Shutdown};
static mut HELPER_SIGNAL: imp::signal = 0 as imp::signal;
pub fn boot(helper: fn(imp::signal, Port<Req>)) {
- static mut LOCK: Mutex = MUTEX_INIT;
+ static mut LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
static mut INITIALIZED: bool = false;
unsafe {
- LOCK.lock();
+ let mut _guard = LOCK.lock();
if !INITIALIZED {
let (msgp, msgc) = Chan::new();
// promote this to a shared channel
rt::at_exit(proc() { shutdown() });
INITIALIZED = true;
}
- LOCK.unlock();
}
}
//! # Starting with libnative
//!
//! ```rust
-//! extern mod native;
+//! extern crate native;
//!
//! #[start]
//! fn start(argc: int, argv: **u8) -> int { native::start(argc, argv, main) }
//! # Force spawning a native task
//!
//! ```rust
-//! extern mod native;
+//! extern crate native;
//!
//! fn main() {
//! // We're not sure whether this main function is run in 1:1 or M:N mode.
use std::rt::thread::Thread;
use std::rt;
use std::task::TaskOpts;
-use std::unstable::mutex::Mutex;
+use std::unstable::mutex::NativeMutex;
use std::unstable::stack;
use io;
fn ops() -> ~Ops {
~Ops {
- lock: unsafe { Mutex::new() },
+ lock: unsafe { NativeMutex::new() },
awoken: false,
io: io::IoFactory::new(),
// these *should* get overwritten
// This structure is the glue between channels and the 1:1 scheduling mode. This
// structure is allocated once per task.
struct Ops {
- lock: Mutex, // native synchronization
+ lock: NativeMutex, // native synchronization
awoken: bool, // used to prevent spurious wakeups
io: io::IoFactory, // local I/O factory
let task = BlockedTask::block(cur_task);
if times == 1 {
- (*me).lock.lock();
+ let mut guard = (*me).lock.lock();
(*me).awoken = false;
match f(task) {
Ok(()) => {
while !(*me).awoken {
- (*me).lock.wait();
+ guard.wait();
}
}
Err(task) => { cast::forget(task.wake()); }
}
- (*me).lock.unlock();
} else {
let mut iter = task.make_selectable(times);
- (*me).lock.lock();
+ let mut guard = (*me).lock.lock();
(*me).awoken = false;
let success = iter.all(|task| {
match f(task) {
}
});
while success && !(*me).awoken {
- (*me).lock.wait();
+ guard.wait();
}
- (*me).lock.unlock();
}
// re-acquire ownership of the task
cur_task = cast::transmute::<uint, ~Task>(cur_task_dupe);
let me = &mut *self as *mut Ops;
to_wake.put_runtime(self as ~rt::Runtime);
cast::forget(to_wake);
- (*me).lock.lock();
+ let mut guard = (*me).lock.lock();
(*me).awoken = true;
- (*me).lock.signal();
- (*me).lock.unlock();
+ guard.signal();
}
}
}
}
-impl Drop for Ops {
- fn drop(&mut self) {
- unsafe { self.lock.destroy() }
- }
-}
-
#[cfg(test)]
mod tests {
use std::rt::Runtime;
#[crate_type = "dylib"];
#[license = "MIT/ASL2"];
-extern mod extra;
+extern crate extra;
pub mod bigint;
pub mod rational;
mod __test {
#[!resolve_unexported]
- extern mod extra (name = "extra", vers = "...");
+ extern crate extra (name = "extra", vers = "...");
fn main() {
#[main];
extra::test::test_main_static(::os::args(), tests)
#[allow(unknown_features)]; // Note: remove it after a snapshot.
#[feature(quote)];
-extern mod extra;
-extern mod flate;
-extern mod arena;
-extern mod syntax;
-extern mod serialize;
-extern mod sync;
-extern mod getopts;
-extern mod collections;
+extern crate extra;
+extern crate flate;
+extern crate arena;
+extern crate syntax;
+extern crate serialize;
+extern crate sync;
+extern crate getopts;
+extern crate collections;
use back::link;
use driver::session;
match i.node {
ast::ViewItemExternMod(ident, ref path_opt, id) => {
let ident = token::get_ident(ident);
- debug!("resolving extern mod stmt. ident: {:?} path_opt: {:?}",
+ debug!("resolving extern crate stmt. ident: {:?} path_opt: {:?}",
ident, path_opt);
let (name, version) = match *path_opt {
Some((ref path_str, _)) => {
intr: @IdentInterner
}
-// Map from NodeId's of local extern mod statements to crate numbers
+// Map from NodeId's of local extern crate statements to crate numbers
type extern_mod_crate_map = HashMap<ast::NodeId, ast::CrateNum>;
impl CStore {
imports: RefCell<~[@ImportDirective]>,
// The external module children of this node that were declared with
- // `extern mod`.
+ // `extern crate`.
external_module_children: RefCell<HashMap<Name, @Module>>,
// The anonymous children of this node. Anonymous children are pseudo-
};
self.resolve_error(span,
format!("unresolved import. maybe \
- a missing `extern mod \
+ a missing `extern crate \
{}`?",
segment_name));
return Failed;
llvm::LLVMAddAttribute(llarg, lib::llvm::NoAliasAttribute as c_uint);
}
}
- _ => {}
+ _ => {
+ // For non-immediate arguments the callee gets its own copy of
+ // the value on the stack, so there are no aliases
+ if !type_is_immediate(ccx, arg_ty) {
+ unsafe {
+ llvm::LLVMAddAttribute(llarg, lib::llvm::NoAliasAttribute as c_uint);
+ }
+ }
+ }
}
}
use std::cmp;
use std::hashmap::{HashMap, HashSet};
use std::ops;
-use std::ptr::to_unsafe_ptr;
use std::rc::Rc;
use std::to_bytes;
use std::to_str::ToStr;
_ => {}
};
- let key = intern_key { sty: to_unsafe_ptr(&st) };
+ let key = intern_key { sty: &st };
{
let mut interner = cx.interner.borrow_mut();
flags: flags,
};
- let sty_ptr = to_unsafe_ptr(&t.sty);
+ let sty_ptr = &t.sty as *sty;
let key = intern_key {
sty: sty_ptr,
clean::ViewItemItem(ref item) => {
match item.inner {
clean::ExternMod(ref name, ref src, _) => {
- if_ok!(write!(w, "<tr><td><code>extern mod {}",
+ if_ok!(write!(w, "<tr><td><code>extern crate {}",
name.as_slice()));
match *src {
Some(ref src) => if_ok!(write!(w, " = \"{}\"",
#[feature(globs, struct_variant, managed_boxes)];
-extern mod syntax;
-extern mod rustc;
-extern mod extra;
-extern mod serialize;
-extern mod sync;
-extern mod getopts;
-extern mod collections;
+extern crate syntax;
+extern crate rustc;
+extern crate extra;
+extern crate serialize;
+extern crate sync;
+extern crate getopts;
+extern crate collections;
use std::local_data;
use std::io;
#[allow(unused_variable, dead_assignment, unused_mut, attribute_usage, dead_code)];
";
if s.contains("extra") {
- prog.push_str("extern mod extra;\n");
+ prog.push_str("extern crate extra;\n");
}
if s.contains(cratename) {
- prog.push_str(format!("extern mod {};\n", cratename));
+ prog.push_str(format!("extern crate {};\n", cratename));
}
if s.contains("fn main") {
prog.push_str(s);
#[feature(macro_rules)];
#[deny(unused_result, unused_must_use)];
-#[cfg(test)] extern mod green;
+#[cfg(test)] extern crate green;
use std::cast;
use std::io;
use std::cast;
use std::libc::{c_void, c_int};
use std::rt::task::BlockedTask;
-use std::unstable::sync::LittleLock;
+use std::unstable::mutex::NativeMutex;
use std::sync::arc::UnsafeArc;
use mpsc = std::sync::mpsc_queue;
struct State {
handle: *uvll::uv_async_t,
- lock: LittleLock, // see comments in async_cb for why this is needed
+ lock: NativeMutex, // see comments in async_cb for why this is needed
queue: mpsc::Queue<Message>,
}
let handle = UvHandle::alloc(None::<AsyncWatcher>, uvll::UV_ASYNC);
let state = UnsafeArc::new(State {
handle: handle,
- lock: LittleLock::new(),
+ lock: unsafe {NativeMutex::new()},
queue: mpsc::Queue::new(),
});
let q = ~QueuePool {
* # Example
*
* ```rust
- * extern mod serialize;
+ * extern crate serialize;
* use serialize::base64::{ToBase64, STANDARD};
*
* fn main () {
* This converts a string literal to base64 and back.
*
* ```rust
- * extern mod serialize;
+ * extern crate serialize;
* use serialize::base64::{ToBase64, FromBase64, STANDARD};
* use std::str;
*
* # Example
*
* ```rust
- * extern mod serialize;
+ * extern crate serialize;
* use serialize::hex::ToHex;
*
* fn main () {
* This converts a string literal to hexadecimal and back.
*
* ```rust
- * extern mod serialize;
+ * extern crate serialize;
* use serialize::hex::{FromHex, ToHex};
* use std::str;
*
// test harness access
#[cfg(test)]
-extern mod extra;
+extern crate extra;
pub use self::serialize::{Decoder, Encoder, Decodable, Encodable,
DecoderHelpers, EncoderHelpers};
use vec::{ImmutableVector, MutableVector};
use vec;
use rt::global_heap::malloc_raw;
+use unstable::raw::Slice;
/// The representation of a C String.
///
}
/// Converts the CString into a `&[u8]` without copying.
+ /// Includes the terminating NUL byte.
///
/// # Failure
///
pub fn as_bytes<'a>(&'a self) -> &'a [u8] {
if self.buf.is_null() { fail!("CString is null!"); }
unsafe {
- cast::transmute((self.buf, self.len() + 1))
+ cast::transmute(Slice { data: self.buf, len: self.len() + 1 })
+ }
+ }
+
+ /// Converts the CString into a `&[u8]` without copying.
+ /// Does not include the terminating NUL byte.
+ ///
+ /// # Failure
+ ///
+ /// Fails if the CString is null.
+ #[inline]
+ pub fn as_bytes_no_nul<'a>(&'a self) -> &'a [u8] {
+ if self.buf.is_null() { fail!("CString is null!"); }
+ unsafe {
+ cast::transmute(Slice { data: self.buf, len: self.len() })
}
}
/// Fails if the CString is null.
#[inline]
pub fn as_str<'a>(&'a self) -> Option<&'a str> {
- let buf = self.as_bytes();
- let buf = buf.slice_to(buf.len()-1); // chop off the trailing NUL
+ let buf = self.as_bytes_no_nul();
str::from_utf8(buf)
}
let expected = ["zero", "one"];
let mut it = expected.iter();
let result = from_c_multistring(ptr as *libc::c_char, None, |c| {
- let cbytes = c.as_bytes().slice_to(c.len());
+ let cbytes = c.as_bytes_no_nul();
assert_eq!(cbytes, it.next().unwrap().as_bytes());
});
assert_eq!(result, 2);
assert_eq!(c_str.as_bytes(), bytes!("foo", 0xff, 0));
}
+ #[test]
+ fn test_as_bytes_no_nul() {
+ let c_str = "hello".to_c_str();
+ assert_eq!(c_str.as_bytes_no_nul(), bytes!("hello"));
+ let c_str = "".to_c_str();
+ let exp: &[u8] = [];
+ assert_eq!(c_str.as_bytes_no_nul(), exp);
+ let c_str = bytes!("foo", 0xff).to_c_str();
+ assert_eq!(c_str.as_bytes_no_nul(), bytes!("foo", 0xff));
+ }
+
#[test]
#[should_fail]
fn test_as_bytes_fail() {
c_str.as_bytes();
}
+ #[test]
+ #[should_fail]
+ fn test_as_bytes_no_nul_fail() {
+ let c_str = unsafe { CString::new(ptr::null(), false) };
+ c_str.as_bytes_no_nul();
+ }
+
#[test]
fn test_as_str() {
let c_str = "hello".to_c_str();
use rt::task::{Task, BlockedTask};
use rt::thread::Thread;
use sync::atomics;
-use unstable::mutex::Mutex;
+use unstable::mutex::NativeMutex;
use vec::OwnedVector;
use mpsc = sync::mpsc_queue;
// this lock protects various portions of this implementation during
// select()
- select_lock: Mutex,
+ select_lock: NativeMutex,
}
pub enum Failure {
channels: atomics::AtomicInt::new(2),
port_dropped: atomics::AtomicBool::new(false),
sender_drain: atomics::AtomicInt::new(0),
- select_lock: unsafe { Mutex::new() },
+ select_lock: unsafe { NativeMutex::new() },
};
// see comments in inherit_blocker about why we grab this lock
- unsafe { p.select_lock.lock() }
+ unsafe { p.select_lock.lock_noguard() }
return p;
}
// interfere with this method. After we unlock this lock, we're
// signifying that we're done modifying self.cnt and self.to_wake and
// the port is ready for the world to continue using it.
- unsafe { self.select_lock.unlock() }
+ unsafe { self.select_lock.unlock_noguard() }
}
pub fn send(&mut self, t: T) -> bool {
// about looking at and dealing with to_wake. Once we have acquired the
// lock, we are guaranteed that inherit_blocker is done.
unsafe {
- self.select_lock.lock();
- self.select_lock.unlock();
+ let _guard = self.select_lock.lock();
}
// Like the stream implementation, we want to make sure that the count
assert_eq!(self.cnt.load(atomics::SeqCst), DISCONNECTED);
assert_eq!(self.to_wake.load(atomics::SeqCst), 0);
assert_eq!(self.channels.load(atomics::SeqCst), 0);
- self.select_lock.destroy();
}
}
}
}
impl<T> Pointer for *mut T {
fn fmt(&self, f: &mut Formatter) -> Result {
- secret_pointer(&(*self as *T), f)
+ secret_pointer::<*T>(&(*self as *T), f)
+ }
+}
+impl<'a, T> Pointer for &'a T {
+ fn fmt(&self, f: &mut Formatter) -> Result {
+ secret_pointer::<*T>(&(&**self as *T), f)
+ }
+}
+impl<'a, T> Pointer for &'a mut T {
+ fn fmt(&self, f: &mut Formatter) -> Result {
+ secret_pointer::<*T>(&(&**self as *T), f)
}
}
use clone::Clone;
use cmp::{Eq, Equiv, max};
use default::Default;
-#[cfg(not(stage0))] use fmt;
+use fmt;
use hash::Hash;
use iter;
use iter::{Iterator, FromIterator, Extendable};
use option::{None, Option, Some};
use rand::Rng;
use rand;
-#[cfg(not(stage0))] use result::{Ok, Err};
+use result::{Ok, Err};
use vec::{ImmutableVector, MutableVector, OwnedVector, Items, MutItems};
use vec_ng;
use vec_ng::Vec;
}
}
-#[cfg(not(stage0))]
impl<A: fmt::Show + Hash + Eq, B: fmt::Show> fmt::Show for HashMap<A, B> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if_ok!(write!(f.buf, r"\{"))
}
}
-#[cfg(not(stage0))]
impl<A: fmt::Show + Hash + Eq> fmt::Show for HashSet<A> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if_ok!(write!(f.buf, r"\{"))
self.read_byte().map(|i| i as i8)
}
+ /// Creates a wrapper around a mutable reference to the reader.
+ ///
+ /// This is useful to allow applying adaptors while still
+ /// retaining ownership of the original value.
+ fn by_ref<'a>(&'a mut self) -> RefReader<'a, Self> {
+ RefReader { inner: self }
+ }
}
impl Reader for ~Reader {
fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> { self.read(buf) }
}
+pub struct RefReader<'a, R> {
+ priv inner: &'a mut R
+}
+
+impl<'a, R: Reader> Reader for RefReader<'a, R> {
+ fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> { self.inner.read(buf) }
+}
+
fn extend_sign(val: u64, nbytes: uint) -> i64 {
let shift = (8 - nbytes) * 8;
(val << shift) as i64 >> shift
fn write_i8(&mut self, n: i8) -> IoResult<()> {
self.write([n as u8])
}
+
+ /// Creates a wrapper around a mutable reference to the writer.
+ ///
+ /// This is useful to allow applying wrappers while still
+ /// retaining ownership of the original value.
+ fn by_ref<'a>(&'a mut self) -> RefWriter<'a, Self> {
+ RefWriter { inner: self }
+ }
}
impl Writer for ~Writer {
fn flush(&mut self) -> IoResult<()> { self.flush() }
}
+pub struct RefWriter<'a, W> {
+ inner: &'a mut W
+}
+
+impl<'a, W: Writer> Writer for RefWriter<'a, W> {
+ fn write(&mut self, buf: &[u8]) -> IoResult<()> { self.inner.write(buf) }
+ fn flush(&mut self) -> IoResult<()> { self.inner.flush() }
+}
+
+
pub trait Stream: Reader + Writer { }
impl<T: Reader + Writer> Stream for T {}
pub unsafe fn raise_fd_limit() {
// The strategy here is to fetch the current resource limits, read the kern.maxfilesperproc
// sysctl value, and bump the soft resource limit for maxfiles up to the sysctl value.
- use ptr::{to_unsafe_ptr, to_mut_unsafe_ptr, mut_null};
+ use ptr::mut_null;
use mem::size_of_val;
use os::last_os_error;
let mut mib: [libc::c_int, ..2] = [CTL_KERN, KERN_MAXFILESPERPROC];
let mut maxfiles: libc::c_int = 0;
let mut size: libc::size_t = size_of_val(&maxfiles) as libc::size_t;
- if sysctl(to_mut_unsafe_ptr(&mut mib[0]), 2,
- to_mut_unsafe_ptr(&mut maxfiles) as *mut libc::c_void,
- to_mut_unsafe_ptr(&mut size),
+ if sysctl(&mut mib[0], 2, &mut maxfiles as *mut libc::c_int as *mut libc::c_void, &mut size,
mut_null(), 0) != 0 {
let err = last_os_error();
error!("raise_fd_limit: error calling sysctl: {}", err);
// Fetch the current resource limits
let mut rlim = rlimit{rlim_cur: 0, rlim_max: 0};
- if getrlimit(RLIMIT_NOFILE, to_mut_unsafe_ptr(&mut rlim)) != 0 {
+ if getrlimit(RLIMIT_NOFILE, &mut rlim) != 0 {
let err = last_os_error();
error!("raise_fd_limit: error calling getrlimit: {}", err);
return;
rlim.rlim_cur = ::cmp::min(maxfiles as rlim_t, rlim.rlim_max);
// Set our newly-increased resource limit
- if setrlimit(RLIMIT_NOFILE, to_unsafe_ptr(&rlim)) != 0 {
+ if setrlimit(RLIMIT_NOFILE, &rlim) != 0 {
let err = last_os_error();
error!("raise_fd_limit: error calling setrlimit: {}", err);
return;
use vec::bytes::MutableByteVector;
/// Wraps a `Reader`, limiting the number of bytes that can be read from it.
-pub struct LimitReader<'a, R> {
+pub struct LimitReader<R> {
priv limit: uint,
- priv inner: &'a mut R
+ priv inner: R
}
-impl<'a, R: Reader> LimitReader<'a, R> {
+impl<R: Reader> LimitReader<R> {
/// Creates a new `LimitReader`
- pub fn new<'a>(r: &'a mut R, limit: uint) -> LimitReader<'a, R> {
+ pub fn new(r: R, limit: uint) -> LimitReader<R> {
LimitReader { limit: limit, inner: r }
}
+ pub fn unwrap(self) -> R { self.inner }
}
-impl<'a, R: Reader> Reader for LimitReader<'a, R> {
+impl<R: Reader> Reader for LimitReader<R> {
fn read(&mut self, buf: &mut [u8]) -> io::IoResult<uint> {
if self.limit == 0 {
return Err(io::standard_error(io::EndOfFile));
fn test_bounded_reader_unlimited() {
let mut r = MemReader::new(~[0, 1, 2]);
{
- let mut r = LimitReader::new(&mut r, 4);
+ let mut r = LimitReader::new(r.by_ref(), 4);
assert_eq!(~[0, 1, 2], r.read_to_end().unwrap());
}
}
fn test_bound_reader_limited() {
let mut r = MemReader::new(~[0, 1, 2]);
{
- let mut r = LimitReader::new(&mut r, 2);
+ let mut r = LimitReader::new(r.by_ref(), 2);
assert_eq!(~[0, 1], r.read_to_end().unwrap());
}
assert_eq!(~[2], r.read_to_end().unwrap());
//! `std` is imported at the topmost level of every crate by default, as
//! if the first line of each crate was
//!
-//! extern mod std;
+//! extern crate std;
//!
//! This means that the contents of std can be accessed from any context
//! with the `std::` path prefix, as in `use std::vec`, `use std::task::spawn`,
// When testing libstd, bring in libuv as the I/O backend so tests can print
// things and all of the std::io tests have an I/O interface to run on top
// of
-#[cfg(test)] extern mod rustuv = "rustuv";
-#[cfg(test)] extern mod native = "native";
-#[cfg(test)] extern mod green = "green";
+#[cfg(test)] extern crate rustuv = "rustuv";
+#[cfg(test)] extern crate native = "native";
+#[cfg(test)] extern crate green = "green";
// Make extra accessible for benchmarking
-#[cfg(test)] extern mod extra = "extra";
+#[cfg(test)] extern crate extra = "extra";
// Make std testable by not duplicating lang items. See #2912
-#[cfg(test)] extern mod realstd = "std";
+#[cfg(test)] extern crate realstd = "std";
#[cfg(test)] pub use kinds = realstd::kinds;
#[cfg(test)] pub use ops = realstd::ops;
#[cfg(test)] pub use cmp = realstd::cmp;
//! Operations on managed box types
-use ptr::to_unsafe_ptr;
-
#[cfg(not(test))] use cmp::*;
/// Returns the refcount of a shared box (as just before calling this)
/// Determine if two shared boxes point to the same object
#[inline]
pub fn ptr_eq<T>(a: @T, b: @T) -> bool {
- let (a_ptr, b_ptr): (*T, *T) = (to_unsafe_ptr(&*a), to_unsafe_ptr(&*b));
- a_ptr == b_ptr
+ &*a as *T == &*b as *T
}
#[cfg(not(test))]
use str;
use str::{Str, StrSlice};
use fmt;
-use unstable::finally::Finally;
use sync::atomics::{AtomicInt, INIT_ATOMIC_INT, SeqCst};
use path::{Path, GenericPath};
use iter::Iterator;
#[cfg(unix)]
use c_str::ToCStr;
+#[cfg(windows)]
+use str::OwnedStr;
/// Delegates to the libc close() function, returning the same return value.
pub fn close(fd: int) -> int {
Serialize access through a global lock.
*/
fn with_env_lock<T>(f: || -> T) -> T {
- use unstable::mutex::{Mutex, MUTEX_INIT};
- use unstable::finally::Finally;
+ use unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
- static mut lock: Mutex = MUTEX_INIT;
+ static mut lock: StaticNativeMutex = NATIVE_MUTEX_INIT;
unsafe {
- return (|| {
- lock.lock();
- f()
- }).finally(|| lock.unlock());
+ let _guard = lock.lock();
+ f()
}
}
/// Returns a vector of (variable, value) pairs for all the environment
/// variables of the current process.
+///
+/// Invalid UTF-8 bytes are replaced with \uFFFD. See `str::from_utf8_lossy()`
+/// for details.
pub fn env() -> ~[(~str,~str)] {
+ env_as_bytes().move_iter().map(|(k,v)| {
+ let k = str::from_utf8_lossy(k).into_owned();
+ let v = str::from_utf8_lossy(v).into_owned();
+ (k,v)
+ }).collect()
+}
+
+/// Returns a vector of (variable, value) byte-vector pairs for all the
+/// environment variables of the current process.
+pub fn env_as_bytes() -> ~[(~[u8],~[u8])] {
unsafe {
#[cfg(windows)]
- unsafe fn get_env_pairs() -> ~[~str] {
+ unsafe fn get_env_pairs() -> ~[~[u8]] {
use c_str;
use str::StrSlice;
}
let mut result = ~[];
c_str::from_c_multistring(ch as *c_char, None, |cstr| {
- result.push(cstr.as_str().unwrap().to_owned());
+ result.push(cstr.as_bytes_no_nul().to_owned());
});
FreeEnvironmentStringsA(ch);
result
}
#[cfg(unix)]
- unsafe fn get_env_pairs() -> ~[~str] {
+ unsafe fn get_env_pairs() -> ~[~[u8]] {
+ use c_str::CString;
+
extern {
fn rust_env_pairs() -> **c_char;
}
}
let mut result = ~[];
ptr::array_each(environ, |e| {
- let env_pair = str::raw::from_c_str(e);
- debug!("get_env_pairs: {}", env_pair);
+ let env_pair = CString::new(e, false).as_bytes_no_nul().to_owned();
result.push(env_pair);
});
result
}
- fn env_convert(input: ~[~str]) -> ~[(~str, ~str)] {
+ fn env_convert(input: ~[~[u8]]) -> ~[(~[u8], ~[u8])] {
let mut pairs = ~[];
for p in input.iter() {
- let vs: ~[&str] = p.splitn('=', 1).collect();
- debug!("splitting: len: {}", vs.len());
- assert_eq!(vs.len(), 2);
- pairs.push((vs[0].to_owned(), vs[1].to_owned()));
+ let vs: ~[&[u8]] = p.splitn(1, |b| *b == '=' as u8).collect();
+ let key = vs[0].to_owned();
+ let val = (if vs.len() < 2 { ~[] } else { vs[1].to_owned() });
+ pairs.push((key, val));
}
pairs
}
#[cfg(unix)]
/// Fetches the environment variable `n` from the current process, returning
/// None if the variable isn't set.
+///
+/// Any invalid UTF-8 bytes in the value are replaced by \uFFFD. See
+/// `str::from_utf8_lossy()` for details.
+///
+/// # Failure
+///
+/// Fails if `n` has any interior NULs.
pub fn getenv(n: &str) -> Option<~str> {
+ getenv_as_bytes(n).map(|v| str::from_utf8_lossy(v).into_owned())
+}
+
+#[cfg(unix)]
+/// Fetches the environment variable `n` byte vector from the current process,
+/// returning None if the variable isn't set.
+///
+/// # Failure
+///
+/// Fails if `n` has any interior NULs.
+pub fn getenv_as_bytes(n: &str) -> Option<~[u8]> {
+ use c_str::CString;
+
unsafe {
with_env_lock(|| {
let s = n.with_c_str(|buf| libc::getenv(buf));
if s.is_null() {
None
} else {
- Some(str::raw::from_c_str(s))
+ Some(CString::new(s, false).as_bytes_no_nul().to_owned())
}
})
}
}
}
+#[cfg(windows)]
+/// Fetches the environment variable `n` byte vector from the current process,
+/// returning None if the variable isn't set.
+pub fn getenv_as_bytes(n: &str) -> Option<~[u8]> {
+ getenv(n).map(|s| s.into_bytes())
+}
+
#[cfg(unix)]
/// Sets the environment variable `n` to the value `v` for the currently running
/// process
+///
+/// # Failure
+///
+/// Fails if `n` or `v` have any interior NULs.
pub fn setenv(n: &str, v: &str) {
unsafe {
with_env_lock(|| {
}
/// Remove a variable from the environment entirely
+///
+/// # Failure
+///
+/// Fails (on unix) if `n` has any interior NULs.
pub fn unsetenv(n: &str) {
#[cfg(unix)]
fn _unsetenv(n: &str) {
}
#[cfg(target_os = "macos")]
-unsafe fn load_argc_and_argv(argc: int, argv: **c_char) -> ~[~str] {
+unsafe fn load_argc_and_argv(argc: int, argv: **c_char) -> ~[~[u8]] {
+ use c_str::CString;
+
let mut args = ~[];
for i in range(0u, argc as uint) {
- args.push(str::raw::from_c_str(*argv.offset(i as int)));
+ args.push(CString::new(*argv.offset(i as int), false).as_bytes_no_nul().to_owned())
}
args
}
* Returns a list of the command line arguments.
*/
#[cfg(target_os = "macos")]
-fn real_args() -> ~[~str] {
+fn real_args_as_bytes() -> ~[~[u8]] {
unsafe {
let (argc, argv) = (*_NSGetArgc() as int,
*_NSGetArgv() as **c_char);
#[cfg(target_os = "linux")]
#[cfg(target_os = "android")]
#[cfg(target_os = "freebsd")]
-fn real_args() -> ~[~str] {
+fn real_args_as_bytes() -> ~[~[u8]] {
use rt;
match rt::args::clone() {
}
}
+#[cfg(not(windows))]
+fn real_args() -> ~[~str] {
+ real_args_as_bytes().move_iter().map(|v| str::from_utf8_lossy(v).into_owned()).collect()
+}
+
#[cfg(windows)]
fn real_args() -> ~[~str] {
use vec;
return args;
}
+#[cfg(windows)]
+fn real_args_as_bytes() -> ~[~[u8]] {
+ real_args().move_iter().map(|s| s.into_bytes()).collect()
+}
+
type LPCWSTR = *u16;
#[cfg(windows)]
/// Returns the arguments which this program was started with (normally passed
/// via the command line).
+///
+/// The arguments are interpreted as utf-8, with invalid bytes replaced with \uFFFD.
+/// See `str::from_utf8_lossy` for details.
pub fn args() -> ~[~str] {
real_args()
}
+/// Returns the arguments which this program was started with (normally passed
+/// via the command line) as byte vectors.
+pub fn args_as_bytes() -> ~[~[u8]] {
+ real_args_as_bytes()
+}
+
#[cfg(target_os = "macos")]
extern {
// These functions are in crt_externs.h.
impl BytesContainer for CString {
#[inline]
fn container_as_bytes<'a>(&'a self) -> &'a [u8] {
- let s = self.as_bytes();
- s.slice_to(s.len()-1)
+ self.as_bytes_no_nul()
}
}
/**
* Swap the values at two mutable locations of the same type, without
- * deinitialising or copying either one.
+ * deinitialising either. They may overlap.
*/
#[inline]
-pub unsafe fn swap_ptr<T>(x: *mut T, y: *mut T) {
+pub unsafe fn swap<T>(x: *mut T, y: *mut T) {
// Give ourselves some scratch space to work with
let mut tmp: T = mem::uninit();
let t: *mut T = &mut tmp;
/**
* Replace the value at a mutable location with a new one, returning the old
- * value, without deinitialising or copying either one.
+ * value, without deinitialising either.
*/
#[inline]
-pub unsafe fn replace_ptr<T>(dest: *mut T, mut src: T) -> T {
+pub unsafe fn replace<T>(dest: *mut T, mut src: T) -> T {
mem::swap(cast::transmute(dest), &mut src); // cannot overlap
src
}
/**
- * Reads the value from `*src` and returns it. Does not copy `*src`.
+ * Reads the value from `*src` and returns it.
*/
#[inline(always)]
-pub unsafe fn read_ptr<T>(src: *T) -> T {
+pub unsafe fn read<T>(src: *T) -> T {
let mut tmp: T = mem::uninit();
copy_nonoverlapping_memory(&mut tmp, src, 1);
tmp
* This currently prevents destructors from executing.
*/
#[inline(always)]
-pub unsafe fn read_and_zero_ptr<T>(dest: *mut T) -> T {
+pub unsafe fn read_and_zero<T>(dest: *mut T) -> T {
// Copy the data out from `dest`:
- let tmp = read_ptr(&*dest);
+ let tmp = read(&*dest);
// Now zero out `dest`:
zero_memory(dest, 1);
tmp
}
-/// Transform a region pointer - &T - to an unsafe pointer - *T.
-#[inline]
-pub fn to_unsafe_ptr<T>(thing: &T) -> *T {
- thing as *T
-}
-
-/// Transform a mutable region pointer - &mut T - to a mutable unsafe pointer - *mut T.
-#[inline]
-pub fn to_mut_unsafe_ptr<T>(thing: &mut T) -> *mut T {
- thing as *mut T
-}
-
/**
Given a **T (pointer to an array of pointers),
iterate through each *T, up to the provided `len`,
*/
pub unsafe fn array_each_with_len<T>(arr: **T, len: uint, cb: |*T|) {
debug!("array_each_with_len: before iterate");
- if arr as uint == 0 {
+ if arr.is_null() {
fail!("ptr::array_each_with_len failure: arr input is null pointer");
}
//let start_ptr = *arr;
Dragons be here.
*/
pub unsafe fn array_each<T>(arr: **T, cb: |*T|) {
- if arr as uint == 0 {
+ if arr.is_null() {
fail!("ptr::array_each_with_len failure: arr input is null pointer");
}
let len = buf_len(arr);
array_each_with_len(arr, len, cb);
}
-#[allow(missing_doc)]
+/// Extension methods for raw pointers.
pub trait RawPtr<T> {
+ /// Returns the null pointer.
fn null() -> Self;
+ /// Returns true if the pointer is equal to the null pointer.
fn is_null(&self) -> bool;
- fn is_not_null(&self) -> bool;
+ /// Returns true if the pointer is not equal to the null pointer.
+ fn is_not_null(&self) -> bool { !self.is_null() }
+ /// Returns the value of this pointer (ie, the address it points to)
fn to_uint(&self) -> uint;
+ /// Returns `None` if the pointer is null, or else returns the value wrapped
+ /// in `Some`.
+ ///
+ /// # Safety Notes
+ ///
+ /// While this method is useful for null-safety, it is important to note
+ /// that this is still an unsafe operation because the returned value could
+ /// be pointing to invalid memory.
unsafe fn to_option(&self) -> Option<&T>;
+ /// Calculates the offset from a pointer. The offset *must* be in-bounds of
+ /// the object, or one-byte-past-the-end.
unsafe fn offset(self, count: int) -> Self;
}
-/// Extension methods for immutable pointers
impl<T> RawPtr<T> for *T {
- /// Returns the null pointer.
#[inline]
fn null() -> *T { null() }
- /// Returns true if the pointer is equal to the null pointer.
#[inline]
fn is_null(&self) -> bool { *self == RawPtr::null() }
- /// Returns true if the pointer is not equal to the null pointer.
#[inline]
- fn is_not_null(&self) -> bool { *self != RawPtr::null() }
+ fn to_uint(&self) -> uint { *self as uint }
- /// Returns the address of this pointer.
#[inline]
- fn to_uint(&self) -> uint { *self as uint }
+ unsafe fn offset(self, count: int) -> *T { intrinsics::offset(self, count) }
- ///
- /// Returns `None` if the pointer is null, or else returns the value wrapped
- /// in `Some`.
- ///
- /// # Safety Notes
- ///
- /// While this method is useful for null-safety, it is important to note
- /// that this is still an unsafe operation because the returned value could
- /// be pointing to invalid memory.
- ///
#[inline]
unsafe fn to_option(&self) -> Option<&T> {
- if self.is_null() { None } else {
+ if self.is_null() {
+ None
+ } else {
Some(cast::transmute(*self))
}
}
-
- /// Calculates the offset from a pointer. The offset *must* be in-bounds of
- /// the object, or one-byte-past-the-end.
- #[inline]
- unsafe fn offset(self, count: int) -> *T { intrinsics::offset(self, count) }
}
-/// Extension methods for mutable pointers
impl<T> RawPtr<T> for *mut T {
- /// Returns the null pointer.
#[inline]
fn null() -> *mut T { mut_null() }
- /// Returns true if the pointer is equal to the null pointer.
#[inline]
fn is_null(&self) -> bool { *self == RawPtr::null() }
- /// Returns true if the pointer is not equal to the null pointer.
#[inline]
- fn is_not_null(&self) -> bool { *self != RawPtr::null() }
+ fn to_uint(&self) -> uint { *self as uint }
- /// Returns the address of this pointer.
#[inline]
- fn to_uint(&self) -> uint { *self as uint }
+ unsafe fn offset(self, count: int) -> *mut T { intrinsics::offset(self as *T, count) as *mut T }
- ///
- /// Returns `None` if the pointer is null, or else returns the value wrapped
- /// in `Some`.
- ///
- /// # Safety Notes
- ///
- /// While this method is useful for null-safety, it is important to note
- /// that this is still an unsafe operation because the returned value could
- /// be pointing to invalid memory.
- ///
#[inline]
unsafe fn to_option(&self) -> Option<&T> {
- if self.is_null() { None } else {
+ if self.is_null() {
+ None
+ } else {
Some(cast::transmute(*self))
}
}
-
- /// Calculates the offset from a pointer. The offset *must* be in-bounds of
- /// the object, or one-byte-past-the-end. An arithmetic overflow is also
- /// undefined behaviour.
- ///
- /// This method should be preferred over `offset` when the guarantee can be
- /// satisfied, to enable better optimization.
- #[inline]
- unsafe fn offset(self, count: int) -> *mut T { intrinsics::offset(self as *T, count) as *mut T }
}
// Equality for pointers
*/
use cast::transmute;
-use ops::Drop;
-use cmp::{Eq, Ord};
use clone::{Clone, DeepClone};
+use cmp::{Eq, Ord};
use kinds::marker;
-use rt::global_heap::exchange_free;
-use ptr::read_ptr;
+use ops::Drop;
use option::{Option, Some, None};
+use ptr;
+use rt::global_heap::exchange_free;
struct RcBox<T> {
value: T,
if self.ptr != 0 as *mut RcBox<T> {
(*self.ptr).strong -= 1;
if (*self.ptr).strong == 0 {
- read_ptr(self.borrow()); // destroy the contained object
+ ptr::read(self.borrow()); // destroy the contained object
// remove the implicit "strong weak" pointer now
// that we've destroyed the contents.
use io;
use iter::Iterator;
use option::{Some, None, Option};
-use ptr;
use ptr::RawPtr;
use reflect;
use reflect::{MovePtr, align};
}
pub fn write_unboxed_vec_repr(&mut self, _: uint, v: &raw::Vec<()>, inner: *TyDesc) -> bool {
- self.write_vec_range(ptr::to_unsafe_ptr(&v.data), v.fill, inner)
+ self.write_vec_range(&v.data, v.fill, inner)
}
fn write_escaped_char(&mut self, ch: char, is_str: bool) -> bool {
if_ok!(self, self.writer.write(['@' as u8]));
self.write_mut_qualifier(mtbl);
self.get::<&raw::Box<()>>(|this, b| {
- let p = ptr::to_unsafe_ptr(&b.data) as *u8;
+ let p = &b.data as *() as *u8;
this.visit_ptr_inner(p, inner)
})
}
_: uint, inner: *TyDesc) -> bool {
let assumed_size = if sz == 0 { n } else { sz };
self.get::<()>(|this, b| {
- this.write_vec_range(ptr::to_unsafe_ptr(b), assumed_size, inner)
+ this.write_vec_range(b, assumed_size, inner)
})
}
pub fn write_repr<T>(writer: &mut io::Writer, object: &T) -> io::IoResult<()> {
unsafe {
- let ptr = ptr::to_unsafe_ptr(object) as *u8;
+ let ptr = object as *T as *u8;
let tydesc = get_tydesc::<T>();
let u = ReprVisitor(ptr, writer);
let mut v = reflect::MovePtrAdaptor(u);
#[cfg(test)] pub unsafe fn cleanup() { realargs::cleanup() }
/// Take the global arguments from global storage.
-#[cfg(not(test))] pub fn take() -> Option<~[~str]> { imp::take() }
-#[cfg(test)] pub fn take() -> Option<~[~str]> {
+#[cfg(not(test))] pub fn take() -> Option<~[~[u8]]> { imp::take() }
+#[cfg(test)] pub fn take() -> Option<~[~[u8]]> {
match realargs::take() {
realstd::option::Some(a) => Some(a),
realstd::option::None => None,
/// Give the global arguments to global storage.
///
/// It is an error if the arguments already exist.
-#[cfg(not(test))] pub fn put(args: ~[~str]) { imp::put(args) }
-#[cfg(test)] pub fn put(args: ~[~str]) { realargs::put(args) }
+#[cfg(not(test))] pub fn put(args: ~[~[u8]]) { imp::put(args) }
+#[cfg(test)] pub fn put(args: ~[~[u8]]) { realargs::put(args) }
/// Make a clone of the global arguments.
-#[cfg(not(test))] pub fn clone() -> Option<~[~str]> { imp::clone() }
-#[cfg(test)] pub fn clone() -> Option<~[~str]> {
+#[cfg(not(test))] pub fn clone() -> Option<~[~[u8]]> { imp::clone() }
+#[cfg(test)] pub fn clone() -> Option<~[~[u8]]> {
match realargs::clone() {
realstd::option::Some(a) => Some(a),
realstd::option::None => None,
mod imp {
use cast;
use clone::Clone;
- #[cfg(not(test))] use libc;
use option::{Option, Some, None};
use ptr::RawPtr;
use iter::Iterator;
- #[cfg(not(test))] use str;
- use unstable::finally::Finally;
- use unstable::mutex::{Mutex, MUTEX_INIT};
+ use unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
use mem;
- #[cfg(not(test))] use vec;
static mut global_args_ptr: uint = 0;
- static mut lock: Mutex = MUTEX_INIT;
+ static mut lock: StaticNativeMutex = NATIVE_MUTEX_INIT;
#[cfg(not(test))]
pub unsafe fn init(argc: int, argv: **u8) {
lock.destroy();
}
- pub fn take() -> Option<~[~str]> {
+ pub fn take() -> Option<~[~[u8]]> {
with_lock(|| unsafe {
let ptr = get_global_ptr();
let val = mem::replace(&mut *ptr, None);
- val.as_ref().map(|s: &~~[~str]| (**s).clone())
+ val.as_ref().map(|s: &~~[~[u8]]| (**s).clone())
})
}
- pub fn put(args: ~[~str]) {
+ pub fn put(args: ~[~[u8]]) {
with_lock(|| unsafe {
let ptr = get_global_ptr();
rtassert!((*ptr).is_none());
})
}
- pub fn clone() -> Option<~[~str]> {
+ pub fn clone() -> Option<~[~[u8]]> {
with_lock(|| unsafe {
let ptr = get_global_ptr();
- (*ptr).as_ref().map(|s: &~~[~str]| (**s).clone())
+ (*ptr).as_ref().map(|s: &~~[~[u8]]| (**s).clone())
})
}
fn with_lock<T>(f: || -> T) -> T {
- (|| {
- unsafe {
- lock.lock();
- f()
- }
- }).finally(|| {
- unsafe {
- lock.unlock();
- }
- })
+ unsafe {
+ let _guard = lock.lock();
+ f()
+ }
}
- fn get_global_ptr() -> *mut Option<~~[~str]> {
+ fn get_global_ptr() -> *mut Option<~~[~[u8]]> {
unsafe { cast::transmute(&global_args_ptr) }
}
// Copied from `os`.
#[cfg(not(test))]
- unsafe fn load_argc_and_argv(argc: int, argv: **u8) -> ~[~str] {
+ unsafe fn load_argc_and_argv(argc: int, argv: **u8) -> ~[~[u8]] {
+ use c_str::CString;
+ use {vec, libc};
+ use vec::CloneableVector;
+
vec::from_fn(argc as uint, |i| {
- str::raw::from_c_str(*(argv as **libc::c_char).offset(i as int))
+ let cs = CString::new(*(argv as **libc::c_char).offset(i as int), false);
+ cs.as_bytes_no_nul().to_owned()
})
}
// Preserve the actual global state.
let saved_value = take();
- let expected = ~[~"happy", ~"today?"];
+ let expected = ~[bytes!("happy").to_owned(), bytes!("today?").to_owned()];
put(expected.clone());
assert!(clone() == Some(expected.clone()));
pub fn cleanup() {
}
- pub fn take() -> Option<~[~str]> {
+ pub fn take() -> Option<~[~[u8]]> {
fail!()
}
- pub fn put(_args: ~[~str]) {
+ pub fn put(_args: ~[~[u8]]) {
fail!()
}
- pub fn clone() -> Option<~[~str]> {
+ pub fn clone() -> Option<~[~[u8]]> {
fail!()
}
}
//! Runtime environment settings
-// NOTE: remove `POISON_ON_FREE` after a snapshot
-
use from_str::from_str;
use option::{Some, None};
use os;
/// This default corresponds to 20M of cache per scheduler (at the default size).
static mut MAX_CACHED_STACKS: uint = 10;
static mut DEBUG_BORROW: bool = false;
-static mut POISON_ON_FREE: bool = false;
pub fn init() {
unsafe {
Some(_) => DEBUG_BORROW = true,
None => ()
}
- match os::getenv("RUST_POISON_ON_FREE") {
- Some(_) => POISON_ON_FREE = true,
- None => ()
- }
}
}
pub fn debug_borrow() -> bool {
unsafe { DEBUG_BORROW }
}
-
-pub fn poison_on_free() -> bool {
- unsafe { POISON_ON_FREE }
-}
use option::{Option, None, Some};
use ptr;
use ptr::RawPtr;
-use rt::env;
use rt::global_heap;
use rt::local::Local;
use rt::task::Task;
pub struct LocalHeap {
priv memory_region: MemoryRegion,
- priv poison_on_free: bool,
priv live_allocs: *mut raw::Box<()>,
}
};
LocalHeap {
memory_region: region,
- poison_on_free: env::poison_on_free(),
live_allocs: ptr::mut_null(),
}
}
// very unsafe method which the caller needs to treat specially in case a
// race is lost.
unsafe fn get(&self, i: int) -> T {
- ptr::read_ptr(self.storage.offset(i & self.mask()))
+ ptr::read(self.storage.offset(i & self.mask()))
}
// Unsafe because this unsafely overwrites possibly uninitialized or
let (p, ch) = Chan::<uint>::new();
let x = ~1;
- let x_in_parent = ptr::to_unsafe_ptr(&*x) as uint;
+ let x_in_parent = (&*x) as *int as uint;
spawnfn(proc() {
- let x_in_child = ptr::to_unsafe_ptr(&*x) as uint;
+ let x_in_child = (&*x) as *int as uint;
ch.send(x_in_child);
});
}
pub fn check_for_errors_in<T>(f: || -> T) -> Result<T, ~str> {
- use unstable::mutex::{Mutex, MUTEX_INIT};
- static mut lock: Mutex = MUTEX_INIT;
+ use unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
+ static mut lock: StaticNativeMutex = NATIVE_MUTEX_INIT;
unsafe {
// dlerror isn't thread safe, so we need to lock around this entire
// sequence
- lock.lock();
+ let _guard = lock.lock();
let _old_error = dlerror();
let result = f();
} else {
Err(str::raw::from_c_str(last_error))
};
- lock.unlock();
+
ret
}
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-//! A native mutex and condition variable type
+//! A native mutex and condition variable type.
//!
//! This module contains bindings to the platform's native mutex/condition
-//! variable primitives. It provides a single type, `Mutex`, which can be
-//! statically initialized via the `MUTEX_INIT` value. This object serves as both a
-//! mutex and a condition variable simultaneously.
+//! variable primitives. It provides two types: `StaticNativeMutex`, which can
+//! be statically initialized via the `NATIVE_MUTEX_INIT` value, and a simple
+//! wrapper `NativeMutex` that has a destructor to clean up after itself. These
+//! objects serve as both mutexes and condition variables simultaneously.
//!
-//! The lock is lazily initialized, but it can only be unsafely destroyed. A
-//! statically initialized lock doesn't necessarily have a time at which it can
-//! get deallocated. For this reason, there is no `Drop` implementation of the
-//! mutex, but rather the `destroy()` method must be invoked manually if
-//! destruction of the mutex is desired.
+//! The static lock is lazily initialized, but it can only be unsafely
+//! destroyed. A statically initialized lock doesn't necessarily have a time at
+//! which it can get deallocated. For this reason, there is no `Drop`
+//! implementation of the static mutex, but rather the `destroy()` method must
+//! be invoked manually if destruction of the mutex is desired.
//!
-//! It is not recommended to use this type for idiomatic rust use. This type is
-//! appropriate where no other options are available, but other rust concurrency
-//! primitives should be used before this type.
+//! The non-static `NativeMutex` type does have a destructor, but cannot be
+//! statically initialized.
+//!
+//! It is not recommended to use this type for idiomatic rust use. These types
+//! are appropriate where no other options are available, but other rust
+//! concurrency primitives should be used before them: the `sync` crate defines
+//! `StaticMutex` and `Mutex` types.
//!
//! # Example
//!
-//! use std::unstable::mutex::{Mutex, MUTEX_INIT};
+//! ```rust
+//! use std::unstable::mutex::{NativeMutex, StaticNativeMutex, NATIVE_MUTEX_INIT};
+//!
+//! // Use a statically initialized mutex
+//! static mut LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
+//!
+//! unsafe {
+//! let _guard = LOCK.lock();
+//! } // automatically unlocked here
//!
-//! // Use a statically initialized mutex
-//! static mut lock: Mutex = MUTEX_INIT;
+//! // Use a normally initialized mutex
+//! unsafe {
+//! let mut lock = NativeMutex::new();
//!
-//! unsafe {
-//! lock.lock();
-//! lock.unlock();
-//! }
+//! {
+//! let _guard = lock.lock();
+//! } // unlocked here
//!
-//! // Use a normally initialized mutex
-//! let mut lock = Mutex::new();
-//! unsafe {
-//! lock.lock();
-//! lock.unlock();
-//! lock.destroy();
-//! }
+//! // sometimes the RAII guard isn't appropriate
+//! lock.lock_noguard();
+//! lock.unlock_noguard();
+//! } // `lock` is deallocated here
+//! ```
#[allow(non_camel_case_types)];
-pub struct Mutex {
+use option::{Option, None, Some};
+use ops::Drop;
+
+/// A native mutex suitable for storing in statics (that is, it has
+/// the `destroy` method rather than a destructor).
+///
+/// Prefer the `NativeMutex` type where possible, since that does not
+/// require manual deallocation.
+pub struct StaticNativeMutex {
priv inner: imp::Mutex,
}
-pub static MUTEX_INIT: Mutex = Mutex {
+/// A native mutex with a destructor for clean-up.
+///
+/// See `StaticNativeMutex` for a version that is suitable for storing in
+/// statics.
+pub struct NativeMutex {
+ priv inner: StaticNativeMutex
+}
+
+/// Automatically unlocks the mutex that it was created from on
+/// destruction.
+///
+/// Using this makes lock-based code resilient to unwinding/task
+/// failure, because the lock will be automatically unlocked even
+/// then.
+#[must_use]
+pub struct LockGuard<'a> {
+ priv lock: &'a mut StaticNativeMutex
+}
+
+pub static NATIVE_MUTEX_INIT: StaticNativeMutex = StaticNativeMutex {
inner: imp::MUTEX_INIT,
};
-impl Mutex {
- /// Creates a new mutex
- pub unsafe fn new() -> Mutex {
- Mutex { inner: imp::Mutex::new() }
+impl StaticNativeMutex {
+ /// Creates a new mutex.
+ ///
+ /// Note that a mutex created in this way needs to be explicit
+ /// freed with a call to `destroy` or it will leak.
+ pub unsafe fn new() -> StaticNativeMutex {
+ StaticNativeMutex { inner: imp::Mutex::new() }
}
/// Acquires this lock. This assumes that the current thread does not
/// already hold the lock.
- pub unsafe fn lock(&mut self) { self.inner.lock() }
+ ///
+ /// # Example
+ /// ```rust
+ /// use std::unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
+ /// static mut LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
+ /// unsafe {
+ /// let _guard = LOCK.lock();
+ /// // critical section...
+ /// } // automatically unlocked in `_guard`'s destructor
+ /// ```
+ pub unsafe fn lock<'a>(&'a mut self) -> LockGuard<'a> {
+ self.inner.lock();
+
+ LockGuard { lock: self }
+ }
+
+ /// Attempts to acquire the lock. The value returned is `Some` if
+ /// the attempt succeeded.
+ pub unsafe fn trylock<'a>(&'a mut self) -> Option<LockGuard<'a>> {
+ if self.inner.trylock() {
+ Some(LockGuard { lock: self })
+ } else {
+ None
+ }
+ }
- /// Attempts to acquire the lock. The value returned is whether the lock was
- /// acquired or not
- pub unsafe fn trylock(&mut self) -> bool { self.inner.trylock() }
+ /// Acquire the lock without creating a `LockGuard`.
+ ///
+ /// These needs to be paired with a call to `.unlock_noguard`. Prefer using
+ /// `.lock`.
+ pub unsafe fn lock_noguard(&mut self) { self.inner.lock() }
+
+ /// Attempts to acquire the lock without creating a
+ /// `LockGuard`. The value returned is whether the lock was
+ /// acquired or not.
+ ///
+ /// If `true` is returned, this needs to be paired with a call to
+ /// `.unlock_noguard`. Prefer using `.trylock`.
+ pub unsafe fn trylock_noguard(&mut self) -> bool {
+ self.inner.trylock()
+ }
/// Unlocks the lock. This assumes that the current thread already holds the
/// lock.
- pub unsafe fn unlock(&mut self) { self.inner.unlock() }
+ pub unsafe fn unlock_noguard(&mut self) { self.inner.unlock() }
/// Block on the internal condition variable.
///
- /// This function assumes that the lock is already held
- pub unsafe fn wait(&mut self) { self.inner.wait() }
+ /// This function assumes that the lock is already held. Prefer
+ /// using `LockGuard.wait` since that guarantees that the lock is
+ /// held.
+ pub unsafe fn wait_noguard(&mut self) { self.inner.wait() }
/// Signals a thread in `wait` to wake up
- pub unsafe fn signal(&mut self) { self.inner.signal() }
+ pub unsafe fn signal_noguard(&mut self) { self.inner.signal() }
/// This function is especially unsafe because there are no guarantees made
/// that no other thread is currently holding the lock or waiting on the
pub unsafe fn destroy(&mut self) { self.inner.destroy() }
}
+impl NativeMutex {
+ /// Creates a new mutex.
+ ///
+ /// The user must be careful to ensure the mutex is not locked when its is
+ /// being destroyed.
+ pub unsafe fn new() -> NativeMutex {
+ NativeMutex { inner: StaticNativeMutex::new() }
+ }
+
+ /// Acquires this lock. This assumes that the current thread does not
+ /// already hold the lock.
+ ///
+ /// # Example
+ /// ```rust
+ /// use std::unstable::mutex::NativeMutex;
+ /// unsafe {
+ /// let mut lock = NativeMutex::new();
+ ///
+ /// {
+ /// let _guard = lock.lock();
+ /// // critical section...
+ /// } // automatically unlocked in `_guard`'s destructor
+ /// }
+ /// ```
+ pub unsafe fn lock<'a>(&'a mut self) -> LockGuard<'a> {
+ self.inner.lock()
+ }
+
+ /// Attempts to acquire the lock. The value returned is `Some` if
+ /// the attempt succeeded.
+ pub unsafe fn trylock<'a>(&'a mut self) -> Option<LockGuard<'a>> {
+ self.inner.trylock()
+ }
+
+ /// Acquire the lock without creating a `LockGuard`.
+ ///
+ /// These needs to be paired with a call to `.unlock_noguard`. Prefer using
+ /// `.lock`.
+ pub unsafe fn lock_noguard(&mut self) { self.inner.lock_noguard() }
+
+ /// Attempts to acquire the lock without creating a
+ /// `LockGuard`. The value returned is whether the lock was
+ /// acquired or not.
+ ///
+ /// If `true` is returned, this needs to be paired with a call to
+ /// `.unlock_noguard`. Prefer using `.trylock`.
+ pub unsafe fn trylock_noguard(&mut self) -> bool {
+ self.inner.trylock_noguard()
+ }
+
+ /// Unlocks the lock. This assumes that the current thread already holds the
+ /// lock.
+ pub unsafe fn unlock_noguard(&mut self) { self.inner.unlock_noguard() }
+
+ /// Block on the internal condition variable.
+ ///
+ /// This function assumes that the lock is already held. Prefer
+ /// using `LockGuard.wait` since that guarantees that the lock is
+ /// held.
+ pub unsafe fn wait_noguard(&mut self) { self.inner.wait_noguard() }
+
+ /// Signals a thread in `wait` to wake up
+ pub unsafe fn signal_noguard(&mut self) { self.inner.signal_noguard() }
+}
+
+impl Drop for NativeMutex {
+ fn drop(&mut self) {
+ unsafe {self.inner.destroy()}
+ }
+}
+
+impl<'a> LockGuard<'a> {
+ /// Block on the internal condition variable.
+ pub unsafe fn wait(&mut self) {
+ self.lock.wait_noguard()
+ }
+
+ /// Signals a thread in `wait` to wake up.
+ pub unsafe fn signal(&mut self) {
+ self.lock.signal_noguard()
+ }
+}
+
+#[unsafe_destructor]
+impl<'a> Drop for LockGuard<'a> {
+ fn drop(&mut self) {
+ unsafe {self.lock.unlock_noguard()}
+ }
+}
+
#[cfg(unix)]
mod imp {
use libc;
mod test {
use prelude::*;
- use super::{Mutex, MUTEX_INIT};
+ use mem::drop;
+ use super::{StaticNativeMutex, NATIVE_MUTEX_INIT};
use rt::thread::Thread;
#[test]
- fn somke_lock() {
- static mut lock: Mutex = MUTEX_INIT;
+ fn smoke_lock() {
+ static mut lock: StaticNativeMutex = NATIVE_MUTEX_INIT;
unsafe {
- lock.lock();
- lock.unlock();
+ let _guard = lock.lock();
}
}
#[test]
- fn somke_cond() {
- static mut lock: Mutex = MUTEX_INIT;
+ fn smoke_cond() {
+ static mut lock: StaticNativeMutex = NATIVE_MUTEX_INIT;
unsafe {
- lock.lock();
+ let mut guard = lock.lock();
let t = Thread::start(proc() {
- lock.lock();
- lock.signal();
- lock.unlock();
+ let mut guard = lock.lock();
+ guard.signal();
});
- lock.wait();
- lock.unlock();
+ guard.wait();
+ drop(guard);
+
+ t.join();
+ }
+ }
+
+ #[test]
+ fn smoke_lock_noguard() {
+ static mut lock: StaticNativeMutex = NATIVE_MUTEX_INIT;
+ unsafe {
+ lock.lock_noguard();
+ lock.unlock_noguard();
+ }
+ }
+
+ #[test]
+ fn smoke_cond_noguard() {
+ static mut lock: StaticNativeMutex = NATIVE_MUTEX_INIT;
+ unsafe {
+ lock.lock_noguard();
+ let t = Thread::start(proc() {
+ lock.lock_noguard();
+ lock.signal_noguard();
+ lock.unlock_noguard();
+ });
+ lock.wait_noguard();
+ lock.unlock_noguard();
+
t.join();
}
}
#[test]
fn destroy_immediately() {
unsafe {
- let mut m = Mutex::new();
+ let mut m = StaticNativeMutex::new();
m.destroy();
}
}
use clone::Clone;
use kinds::Send;
-use ops::Drop;
-use option::{Option,Some,None};
use sync::arc::UnsafeArc;
-use unstable::mutex::Mutex;
-
-pub struct LittleLock {
- priv l: Mutex,
-}
-
-pub struct LittleGuard<'a> {
- priv l: &'a mut Mutex,
-}
-
-impl Drop for LittleLock {
- fn drop(&mut self) {
- unsafe { self.l.destroy(); }
- }
-}
-
-#[unsafe_destructor]
-impl<'a> Drop for LittleGuard<'a> {
- fn drop(&mut self) {
- unsafe { self.l.unlock(); }
- }
-}
-
-impl LittleLock {
- pub fn new() -> LittleLock {
- unsafe { LittleLock { l: Mutex::new() } }
- }
-
- pub unsafe fn lock<'a>(&'a mut self) -> LittleGuard<'a> {
- self.l.lock();
- LittleGuard { l: &mut self.l }
- }
-
- pub unsafe fn try_lock<'a>(&'a mut self) -> Option<LittleGuard<'a>> {
- if self.l.trylock() {
- Some(LittleGuard { l: &mut self.l })
- } else {
- None
- }
- }
-
- pub unsafe fn signal(&mut self) {
- self.l.signal();
- }
-}
-
-impl<'a> LittleGuard<'a> {
- pub unsafe fn wait(&mut self) {
- self.l.wait();
- }
-}
+use unstable::mutex::NativeMutex;
struct ExData<T> {
- lock: LittleLock,
+ lock: NativeMutex,
failed: bool,
data: T,
}
impl<T:Send> Exclusive<T> {
pub fn new(user_data: T) -> Exclusive<T> {
let data = ExData {
- lock: LittleLock::new(),
+ lock: unsafe {NativeMutex::new()},
failed: false,
data: user_data
};
}
}
- // Exactly like std::arc::MutexArc,access(), but with the LittleLock
- // instead of a proper mutex. Same reason for being unsafe.
+ // Exactly like sync::MutexArc.access(). Same reason for being
+ // unsafe.
//
// Currently, scheduling operations (i.e., descheduling, receiving on a pipe,
// accessing the provided condition variable) are prohibited while inside
#[inline]
pub unsafe fn hold_and_signal(&self, f: |x: &mut T|) {
let rec = self.x.get();
- let _l = (*rec).lock.lock();
+ let mut guard = (*rec).lock.lock();
if (*rec).failed {
fail!("Poisoned Exclusive::new - another task failed inside!");
}
(*rec).failed = true;
f(&mut (*rec).data);
(*rec).failed = false;
- (*rec).lock.signal();
+ guard.signal();
}
#[inline]
#[warn(non_camel_case_types)];
use cast;
+use cast::transmute;
use ops::Drop;
use clone::{Clone, DeepClone};
use container::{Container, Mutable};
use cmp::{Eq, TotalOrd, Ordering, Less, Equal, Greater};
use cmp;
use default::Default;
-#[cfg(not(stage0))] use fmt;
+use fmt;
use iter::*;
use num::{Integer, CheckedAdd, Saturating, checked_next_power_of_two};
use option::{None, Option, Some};
-use ptr::to_unsafe_ptr;
use ptr;
use ptr::RawPtr;
use rt::global_heap::{malloc_raw, realloc_raw, exchange_free};
-#[cfg(not(stage0))] use result::{Ok, Err};
+use result::{Ok, Err};
use mem;
use mem::size_of;
use kinds::marker;
let ptr = malloc_raw(size) as *mut Vec<()>;
(*ptr).alloc = alloc;
(*ptr).fill = 0;
- cast::transmute(ptr)
+ transmute(ptr)
}
}
*/
pub fn ref_slice<'a, A>(s: &'a A) -> &'a [A] {
unsafe {
- cast::transmute(Slice { data: s, len: 1 })
+ transmute(Slice { data: s, len: 1 })
}
}
*/
pub fn mut_ref_slice<'a, A>(s: &'a mut A) -> &'a mut [A] {
unsafe {
- let ptr: *A = cast::transmute(s);
- cast::transmute(Slice { data: ptr, len: 1 })
+ let ptr: *A = transmute(s);
+ transmute(Slice { data: ptr, len: 1 })
}
}
assert!(start <= end);
assert!(end <= self.len());
unsafe {
- cast::transmute(Slice {
+ transmute(Slice {
data: self.as_ptr().offset(start as int),
len: (end - start)
})
#[inline]
unsafe fn unsafe_ref(self, index: uint) -> &'a T {
- cast::transmute(self.repr().data.offset(index as int))
+ transmute(self.repr().data.offset(index as int))
}
#[inline]
fn shift_ref(&mut self) -> Option<&'a T> {
if self.len() == 0 { return None; }
unsafe {
- let s: &mut Slice<T> = cast::transmute(self);
+ let s: &mut Slice<T> = transmute(self);
Some(&*raw::shift_ptr(s))
}
}
fn pop_ref(&mut self) -> Option<&'a T> {
if self.len() == 0 { return None; }
unsafe {
- let s: &mut Slice<T> = cast::transmute(self);
+ let s: &mut Slice<T> = transmute(self);
Some(&*raw::pop_ptr(s))
}
}
#[inline]
fn move_iter(self) -> MoveItems<T> {
unsafe {
- let iter = cast::transmute(self.iter());
- let ptr = cast::transmute(self);
+ let iter = transmute(self.iter());
+ let ptr = transmute(self);
MoveItems { allocation: ptr, iter: iter }
}
}
// Only make the (slow) call into the runtime if we have to
if self.capacity() < n {
unsafe {
- let ptr: *mut *mut Vec<()> = cast::transmute(self);
+ let ptr: *mut *mut Vec<()> = transmute(self);
let alloc = n * mem::nonzero_size_of::<T>();
let size = alloc + mem::size_of::<Vec<()>>();
if alloc / mem::nonzero_size_of::<T>() != n || size < alloc {
#[inline]
fn capacity(&self) -> uint {
unsafe {
- let repr: **Vec<()> = cast::transmute(self);
+ let repr: **Vec<()> = transmute(self);
(**repr).alloc / mem::nonzero_size_of::<T>()
}
}
fn shrink_to_fit(&mut self) {
unsafe {
- let ptr: *mut *mut Vec<()> = cast::transmute(self);
+ let ptr: *mut *mut Vec<()> = transmute(self);
let alloc = (**ptr).fill;
let size = alloc + mem::size_of::<Vec<()>>();
*ptr = realloc_raw(*ptr as *mut u8, size) as *mut Vec<()>;
#[inline]
fn push(&mut self, t: T) {
unsafe {
- let repr: **Vec<()> = cast::transmute(&mut *self);
+ let repr: **Vec<()> = transmute(&mut *self);
let fill = (**repr).fill;
if (**repr).alloc <= fill {
self.reserve_additional(1);
// This doesn't bother to make sure we have space.
#[inline] // really pretty please
unsafe fn push_fast<T>(this: &mut ~[T], t: T) {
- let repr: **mut Vec<u8> = cast::transmute(this);
+ let repr: **mut Vec<u8> = transmute(this);
let fill = (**repr).fill;
(**repr).fill += mem::nonzero_size_of::<T>();
- let p = to_unsafe_ptr(&((**repr).data));
+ let p = &((**repr).data) as *u8;
let p = p.offset(fill as int) as *mut T;
mem::move_val_init(&mut(*p), t);
}
match self.len() {
0 => None,
ln => {
- let valptr = ptr::to_mut_unsafe_ptr(&mut self[ln - 1u]);
+ let valptr = &mut self[ln - 1u] as *mut T;
unsafe {
self.set_len(ln - 1u);
- Some(ptr::read_ptr(&*valptr))
+ Some(ptr::read(&*valptr))
}
}
}
let ptr = self.as_mut_ptr().offset(i as int);
// copy it out, unsafely having a copy of the value on
// the stack and in the vector at the same time.
- let ret = Some(ptr::read_ptr(ptr as *T));
+ let ret = Some(ptr::read(ptr as *T));
// Shift everything down to fill in that spot.
ptr::copy_memory(ptr, &*ptr.offset(1), len - i - 1);
let p = self.as_mut_ptr();
// This loop is optimized out for non-drop types.
for i in range(newlen, oldlen) {
- ptr::read_and_zero_ptr(p.offset(i as int));
+ ptr::read_and_zero(p.offset(i as int));
}
}
unsafe { self.set_len(newlen); }
#[inline]
unsafe fn set_len(&mut self, new_len: uint) {
- let repr: **mut Vec<()> = cast::transmute(self);
+ let repr: **mut Vec<()> = transmute(self);
(**repr).fill = new_len * mem::nonzero_size_of::<T>();
}
}
// `.offset(j)` is always in bounds.
if i != j {
- let tmp = ptr::read_ptr(read_ptr);
+ let tmp = ptr::read(read_ptr);
ptr::copy_memory(buf_v.offset(j + 1),
&*buf_v.offset(j),
(i - j) as uint);
assert!(start <= end);
assert!(end <= self.len());
unsafe {
- cast::transmute(Slice {
+ transmute(Slice {
data: self.as_mut_ptr().offset(start as int) as *T,
len: (end - start)
})
fn mut_shift_ref(&mut self) -> Option<&'a mut T> {
if self.len() == 0 { return None; }
unsafe {
- let s: &mut Slice<T> = cast::transmute(self);
+ let s: &mut Slice<T> = transmute(self);
Some(cast::transmute_mut(&*raw::shift_ptr(s)))
}
}
fn mut_pop_ref(&mut self) -> Option<&'a mut T> {
if self.len() == 0 { return None; }
unsafe {
- let s: &mut Slice<T> = cast::transmute(self);
+ let s: &mut Slice<T> = transmute(self);
Some(cast::transmute_mut(&*raw::pop_ptr(s)))
}
}
// them to their raw pointers to do the swap
let pa: *mut T = &mut self[a];
let pb: *mut T = &mut self[b];
- ptr::swap_ptr(pa, pb);
+ ptr::swap(pa, pb);
}
}
#[inline]
unsafe fn unsafe_mut_ref(self, index: uint) -> &'a mut T {
- cast::transmute((self.repr().data as *mut T).offset(index as int))
+ transmute((self.repr().data as *mut T).offset(index as int))
}
#[inline]
/// Unsafe operations
pub mod raw {
- use cast;
+ use cast::transmute;
use ptr;
use ptr::RawPtr;
use vec::{with_capacity, MutableVector, OwnedVector};
#[inline]
pub unsafe fn buf_as_slice<T,U>(p: *T, len: uint, f: |v: &[T]| -> U)
-> U {
- f(cast::transmute(Slice {
+ f(transmute(Slice {
data: p,
len: len
}))
len: uint,
f: |v: &mut [T]| -> U)
-> U {
- f(cast::transmute(Slice {
+ f(transmute(Slice {
data: p as *T,
len: len
}))
}
}
-#[cfg(not(stage0))]
impl<'a, T: fmt::Show> fmt::Show for &'a [T] {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if_ok!(write!(f.buf, "["));
}
}
-#[cfg(not(stage0))]
impl<T: fmt::Show> fmt::Show for ~[T] {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.as_slice().fmt(f)
// purposefully don't use 'ptr.offset' because for
// vectors with 0-size elements this would return the
// same pointer.
- cast::transmute(self.ptr as uint + 1)
+ transmute(self.ptr as uint + 1)
} else {
self.ptr.offset(1)
};
- Some(cast::transmute(old))
+ Some(transmute(old))
}
}
}
} else {
self.end = if mem::size_of::<T>() == 0 {
// See above for why 'ptr.offset' isn't used
- cast::transmute(self.end as uint - 1)
+ transmute(self.end as uint - 1)
} else {
self.end.offset(-1)
};
- Some(cast::transmute(self.end))
+ Some(transmute(self.end))
}
}
}
fn idx(&self, index: uint) -> Option<&'a T> {
unsafe {
if index < self.indexable() {
- cast::transmute(self.ptr.offset(index as int))
+ transmute(self.ptr.offset(index as int))
} else {
None
}
#[inline]
fn next(&mut self) -> Option<T> {
unsafe {
- self.iter.next().map(|x| ptr::read_ptr(x))
+ self.iter.next().map(|x| ptr::read(x))
}
}
#[inline]
fn next_back(&mut self) -> Option<T> {
unsafe {
- self.iter.next_back().map(|x| ptr::read_ptr(x))
+ self.iter.next_back().map(|x| ptr::read(x))
}
}
}
use rt::global_heap::{malloc_raw, realloc_raw};
use vec::{ImmutableVector, Items, MutableVector};
use unstable::raw::Slice;
-use ptr::read_ptr;
+use ptr;
use ptr::RawPtr;
use libc::{free, c_void};
} else {
unsafe {
self.len -= 1;
- Some(read_ptr(self.as_slice().unsafe_ref(self.len())))
+ Some(ptr::read(self.as_slice().unsafe_ref(self.len())))
}
}
}
let mut i = len;
// drop any extra elements
while i < self.len {
- read_ptr(self.as_slice().unsafe_ref(i));
+ ptr::read(self.as_slice().unsafe_ref(i));
i += 1;
}
}
fn drop(&mut self) {
unsafe {
for x in self.as_mut_slice().iter() {
- read_ptr(x);
+ ptr::read(x);
}
free(self.ptr as *mut c_void)
}
#[inline]
fn next(&mut self) -> Option<T> {
unsafe {
- self.iter.next().map(|x| read_ptr(x))
+ self.iter.next().map(|x| ptr::read(x))
}
}
#[inline]
fn next_back(&mut self) -> Option<T> {
unsafe {
- self.iter.next_back().map(|x| read_ptr(x))
+ self.iter.next_back().map(|x| ptr::read(x))
}
}
}
/// uint-cast of the native thread waiting for this mutex
priv native_blocker: uint,
/// an OS mutex used by native threads
- priv lock: mutex::Mutex,
+ priv lock: mutex::StaticNativeMutex,
/// A concurrent mpsc queue used by green threads, along with a count used
/// to figure out when to dequeue and enqueue.
/// An RAII implementation of a "scoped lock" of a mutex. When this structure is
/// dropped (falls out of scope), the lock will be unlocked.
+#[must_use]
pub struct Guard<'a> {
priv lock: &'a mut StaticMutex,
}
/// Static initialization of a mutex. This constant can be used to initialize
/// other mutex constants.
pub static MUTEX_INIT: StaticMutex = StaticMutex {
- lock: mutex::MUTEX_INIT,
+ lock: mutex::NATIVE_MUTEX_INIT,
state: atomics::INIT_ATOMIC_UINT,
flavor: Unlocked,
green_blocker: 0,
// `lock()` function on an OS mutex
fn native_lock(&mut self, t: ~Task) {
Local::put(t);
- unsafe { self.lock.lock(); }
+ unsafe { self.lock.lock_noguard(); }
}
fn native_unlock(&mut self) {
- unsafe { self.lock.unlock(); }
+ unsafe { self.lock.unlock_noguard(); }
}
fn green_lock(&mut self, t: ~Task) {
native_blocker: 0,
green_cnt: atomics::AtomicUint::new(0),
q: q::Queue::new(),
- lock: unsafe { mutex::Mutex::new() },
+ lock: unsafe { mutex::StaticNativeMutex::new() },
}
}
}
#[cfg(test)]
mod test {
- extern mod native;
+ extern crate native;
use super::{Mutex, StaticMutex, MUTEX_INIT};
#[test]
// ident: name used to refer to this crate in the code
// optional (InternedString,StrStyle): if present, this is a location
// (containing arbitrary characters) from which to fetch the crate sources
- // For example, extern mod whatever = "github.com/mozilla/rust"
+ // For example, extern crate whatever = "github.com/mozilla/rust"
ViewItemExternMod(Ident, Option<(InternedString,StrStyle)>, NodeId),
ViewItemUse(~[@ViewPath]),
}
#[deny(non_camel_case_types)];
-#[cfg(test)] extern mod extra;
-extern mod serialize;
-extern mod term;
-extern mod collections;
+#[cfg(test)] extern crate extra;
+extern crate serialize;
+extern crate term;
+extern crate collections;
pub mod util {
pub mod interner;
// parse one of the items or view items allowed by the
// flags; on failure, return IoviNone.
// NB: this function no longer parses the items inside an
- // extern mod.
+ // extern crate.
fn parse_item_or_view_item(&mut self,
attrs: ~[Attribute],
macros_allowed: bool)
let next_is_mod = self.eat_keyword(keywords::Mod);
if next_is_mod || self.eat_keyword(keywords::Crate) {
- // NOTE(flaper87): Uncomment this when this changes gets into stage0
- //
- // if next_is_mod {
- // self.span_err(self.span,
- // format!("`extern mod` is obsolete, use `extern crate` instead \
- // to refer to external crates."))
- // }
+ if next_is_mod {
+ self.span_err(mk_sp(lo, self.last_span.hi),
+ format!("`extern mod` is obsolete, use \
+ `extern crate` instead \
+ to refer to external crates."))
+ }
return self.parse_item_extern_crate(lo, visibility, attrs);
}
let mut items = ~[];
// I think this code would probably read better as a single
- // loop with a mutable three-state-variable (for extern mods,
+ // loop with a mutable three-state-variable (for extern crates,
// view items, and regular items) ... except that because
// of macros, I'd like to delay that entire check until later.
loop {
IoviViewItem(view_item) => {
match view_item.node {
ViewItemUse(..) => {
- // `extern mod` must precede `use`.
+ // `extern crate` must precede `use`.
extern_mod_allowed = false;
}
ViewItemExternMod(..) if !extern_mod_allowed => {
self.span_err(view_item.span,
- "\"extern mod\" declarations are not allowed here");
+ "\"extern crate\" declarations are not allowed here");
}
ViewItemExternMod(..) => {}
}
IoviViewItem(view_item) => {
attrs = self.parse_outer_attributes();
self.span_err(view_item.span,
- "`use` and `extern mod` declarations must precede items");
+ "`use` and `extern crate` declarations must precede items");
}
IoviItem(item) => {
attrs = self.parse_outer_attributes();
IoviViewItem(view_item) => {
// I think this can't occur:
self.span_err(view_item.span,
- "`use` and `extern mod` declarations must precede items");
+ "`use` and `extern crate` declarations must precede items");
}
IoviItem(item) => {
// FIXME #5668: this will occur for a macro invocation:
if_ok!(print_visibility(s, item.vis));
match item.node {
ast::ViewItemExternMod(id, ref optional_path, _) => {
- if_ok!(head(s, "extern mod"));
+ if_ok!(head(s, "extern crate"));
if_ok!(print_ident(s, id));
for &(ref p, style) in optional_path.iter() {
if_ok!(space(&mut s.s));
// test harness access
#[cfg(test)]
-extern mod extra;
-extern mod serialize;
+extern crate extra;
+extern crate serialize;
use std::str;
use std::vec;
+S 2014-02-14 18477ac
+ freebsd-x86_64 102df7dfab2a1c59d9e2f16a3f02f368310dd022
+ linux-i386 fcf5891e9b3c7c9ef5ee5ea37e62089346099425
+ linux-x86_64 d7c2df185fd2e25b4b8f5b2caad277b5ba664b81
+ macos-i386 c15faa408339ceebbb68e952e9bf7f2624ceb9e0
+ macos-x86_64 445c6759db5e69250b8a8631ea7751d1474e4250
+ winnt-i386 f78a892f47627f34233e44c2ff4a00b68063a2ce
+
S 2014-02-12 c62f6ce
freebsd-x86_64 737a423c5f803119ff5a692eac432fa9d0c595a8
linux-i386 a7e90e27e8b6a3fa79ddc15f0ed217ccbade875d
#[crate_id="crateresolve4b#0.1"];
#[crate_type = "lib"];
-extern mod crateresolve4a = "crateresolve4a#0.2";
+extern crate crateresolve4a = "crateresolve4a#0.2";
pub fn f() -> int { crateresolve4a::g() }
#[crate_id="crateresolve4b#0.2"];
#[crate_type = "lib"];
-extern mod crateresolve4a = "crateresolve4a#0.1";
+extern crate crateresolve4a = "crateresolve4a#0.1";
pub fn g() -> int { crateresolve4a::f() }
// These both have the same version but differ in other metadata
pub mod a {
- extern mod cr_1 (name = "crateresolve_calories", vers = "0.1", calories="100");
+ extern crate cr_1 (name = "crateresolve_calories", vers = "0.1", calories="100");
pub fn f() -> int { cr_1::f() }
}
pub mod b {
- extern mod cr_2 (name = "crateresolve_calories", vers = "0.1", calories="200");
+ extern crate cr_2 (name = "crateresolve_calories", vers = "0.1", calories="200");
pub fn f() -> int { cr_2::f() }
}
// except according to those terms.
#[crate_id="crateresolve_calories#0.1"];
-// NOTE: remove after the next snapshot
-#[link(name = "crateresolve_calories",
- vers = "0.1",
- calories = "100")];
-
#[crate_type = "lib"];
pub fn f() -> int { 100 }
// except according to those terms.
#[crate_id="crateresolve_calories#0.1"];
-// NOTE: remove after the next snapshot
-#[link(name = "crateresolve_calories",
- vers = "0.1",
- calories = "200")];
-
#[crate_type = "lib"];
pub fn f() -> int { 200 }
#[crate_id="b#0.1"];
#[crate_type = "lib"];
-extern mod a;
+extern crate a;
#[crate_id="issue_2526#0.2"];
#[crate_type = "lib"];
-extern mod extra;
+extern crate extra;
struct arc_destruct<T> {
_data: int,
#[crate_id="req"];
#[crate_type = "lib"];
-extern mod extra;
+extern crate extra;
use std::cell::RefCell;
use std::hashmap::HashMap;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-// ignore-fast windows doesn't like extern mod
+// ignore-fast windows doesn't like extern crate
// aux-build:issue-9906.rs
pub use other::FooBar;
#[crate_type = "lib"];
-extern mod issue2378a;
+extern crate issue2378a;
use issue2378a::maybe;
#[crate_id="c#0.1"];
#[crate_type = "lib"];
-extern mod a;
+extern crate a;
use a::to_strz;
#[allow(unused_imports)];
#[feature(globs)];
-extern mod issue_2316_a;
+extern crate issue_2316_a;
pub mod cloth {
use issue_2316_a::*;
#[feature(macro_registrar)];
-extern mod syntax;
+extern crate syntax;
use std::any::Any;
use std::local_data;
#[feature(globs, macro_registrar, macro_rules, quote)];
-extern mod syntax;
+extern crate syntax;
use syntax::ast::{Name, TokenTree};
use syntax::codemap::Span;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod pub_use_xcrate1;
+extern crate pub_use_xcrate1;
pub use pub_use_xcrate1::Foo;
// aux-build:trait_default_method_xc_aux.rs
-extern mod aux = "trait_default_method_xc_aux";
+extern crate aux = "trait_default_method_xc_aux";
use aux::A;
pub struct a_struct { x: int }
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod extra;
-extern mod collections;
+extern crate extra;
+extern crate collections;
use extra::time;
use collections::TreeMap;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod extra;
-extern mod collections;
+extern crate extra;
+extern crate collections;
use collections::bitv::BitvSet;
use collections::TreeSet;
#[feature(macro_rules)];
-extern mod extra;
+extern crate extra;
use extra::time::precise_time_s;
use std::mem::swap;
// different scalability characteristics compared to the select
// version.
-extern mod extra;
+extern crate extra;
use std::comm;
use std::os;
//
// I *think* it's the same, more or less.
-extern mod extra;
+extern crate extra;
use std::os;
use std::task;
// This also serves as a pipes test, because Arcs are implemented with pipes.
-extern mod extra;
-extern mod sync;
+extern crate extra;
+extern crate sync;
use sync::Arc;
use sync::MutexArc;
// This also serves as a pipes test, because Arcs are implemented with pipes.
-extern mod extra;
-extern mod sync;
+extern crate extra;
+extern crate sync;
use sync::RWArc;
use sync::Future;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-// Perlin noise benchmark from https://gist.github.com/1170424
+// Multi-language Perlin noise benchmark.
+// See https://github.com/nsf/pnoise for timings and alternative implementations.
-use std::f64;
-use std::rand::Rng;
-use std::rand;
+use std::f32::consts::PI;
+use std::rand::{Rng, StdRng};
struct Vec2 {
x: f32,
y: f32,
}
-#[inline(always)]
fn lerp(a: f32, b: f32, v: f32) -> f32 { a * (1.0 - v) + b * v }
-#[inline(always)]
fn smooth(v: f32) -> f32 { v * v * (3.0 - 2.0 * v) }
-fn random_gradient<R:Rng>(r: &mut R) -> Vec2 {
- let v = 2.0 * f64::consts::PI * r.gen();
- Vec2 {
- x: v.cos() as f32,
- y: v.sin() as f32,
- }
+fn random_gradient<R: Rng>(r: &mut R) -> Vec2 {
+ let v = PI * 2.0 * r.gen();
+ Vec2 { x: v.cos(), y: v.sin() }
}
fn gradient(orig: Vec2, grad: Vec2, p: Vec2) -> f32 {
- let sp = Vec2 {x: p.x - orig.x, y: p.y - orig.y};
- grad.x * sp.x + grad.y * sp.y
+ (p.x - orig.x) * grad.x + (p.y - orig.y) * grad.y
}
struct Noise2DContext {
rgradients: [Vec2, ..256],
- permutations: [int, ..256],
+ permutations: [i32, ..256],
}
impl Noise2DContext {
- pub fn new() -> Noise2DContext {
- let mut r = rand::rng();
- let mut rgradients = [ Vec2 { x: 0.0, y: 0.0 }, ..256 ];
- for i in range(0, 256) {
- rgradients[i] = random_gradient(&mut r);
- }
- let mut permutations = [ 0, ..256 ];
- for i in range(0, 256) {
- permutations[i] = i;
+ fn new() -> Noise2DContext {
+ let mut rng = StdRng::new();
+
+ let mut rgradients = [Vec2 { x: 0.0, y: 0.0 }, ..256];
+ for x in rgradients.mut_iter() {
+ *x = random_gradient(&mut rng);
}
- r.shuffle_mut(permutations);
- Noise2DContext {
- rgradients: rgradients,
- permutations: permutations,
+ let mut permutations = [0i32, ..256];
+ for (i, x) in permutations.mut_iter().enumerate() {
+ *x = i as i32;
}
+ rng.shuffle_mut(permutations);
+
+ Noise2DContext { rgradients: rgradients, permutations: permutations }
}
- #[inline(always)]
- pub fn get_gradient(&self, x: int, y: int) -> Vec2 {
+ fn get_gradient(&self, x: i32, y: i32) -> Vec2 {
let idx = self.permutations[x & 255] + self.permutations[y & 255];
self.rgradients[idx & 255]
}
- #[inline]
- pub fn get_gradients(&self,
- gradients: &mut [Vec2, ..4],
- origins: &mut [Vec2, ..4],
- x: f32,
- y: f32) {
+ fn get_gradients(&self, x: f32, y: f32) -> ([Vec2, ..4], [Vec2, ..4]) {
let x0f = x.floor();
let y0f = y.floor();
- let x0 = x0f as int;
- let y0 = y0f as int;
+ let x1f = x0f + 1.0;
+ let y1f = y0f + 1.0;
+
+ let x0 = x0f as i32;
+ let y0 = y0f as i32;
let x1 = x0 + 1;
let y1 = y0 + 1;
- gradients[0] = self.get_gradient(x0, y0);
- gradients[1] = self.get_gradient(x1, y0);
- gradients[2] = self.get_gradient(x0, y1);
- gradients[3] = self.get_gradient(x1, y1);
-
- origins[0] = Vec2 {x: x0f + 0.0, y: y0f + 0.0};
- origins[1] = Vec2 {x: x0f + 1.0, y: y0f + 0.0};
- origins[2] = Vec2 {x: x0f + 0.0, y: y0f + 1.0};
- origins[3] = Vec2 {x: x0f + 1.0, y: y0f + 1.0};
+ ([self.get_gradient(x0, y0), self.get_gradient(x1, y0),
+ self.get_gradient(x0, y1), self.get_gradient(x1, y1)],
+ [Vec2 { x: x0f, y: y0f }, Vec2 { x: x1f, y: y0f },
+ Vec2 { x: x0f, y: y1f }, Vec2 { x: x1f, y: y1f }])
}
- #[inline]
- pub fn get(&self, x: f32, y: f32) -> f32 {
+ fn get(&self, x: f32, y: f32) -> f32 {
let p = Vec2 {x: x, y: y};
- let mut gradients = [ Vec2 { x: 0.0, y: 0.0 }, ..4 ];
- let mut origins = [ Vec2 { x: 0.0, y: 0.0 }, ..4 ];
- self.get_gradients(&mut gradients, &mut origins, x, y);
+ let (gradients, origins) = self.get_gradients(x, y);
+
let v0 = gradient(origins[0], gradients[0], p);
let v1 = gradient(origins[1], gradients[1], p);
let v2 = gradient(origins[2], gradients[2], p);
let v3 = gradient(origins[3], gradients[3], p);
+
let fx = smooth(x - origins[0].x);
let vx0 = lerp(v0, v1, fx);
let vx1 = lerp(v2, v3, fx);
let fy = smooth(y - origins[0].y);
+
lerp(vx0, vx1, fy)
}
}
fn main() {
- let symbols = [" ", "░", "▒", "▓", "█", "█"];
+ let symbols = [' ', '░', '▒', '▓', '█', '█'];
let mut pixels = [0f32, ..256*256];
- let n2d = ~Noise2DContext::new();
- for _ in range(0, 100u) {
+ let n2d = Noise2DContext::new();
+
+ for _ in range(0, 100) {
for y in range(0, 256) {
for x in range(0, 256) {
- let v = n2d.get(
- x as f32 * 0.1f32,
- y as f32 * 0.1f32
- ) * 0.5f32 + 0.5f32;
- pixels[y*256+x] = v;
- };
- };
- };
+ let v = n2d.get(x as f32 * 0.1, y as f32 * 0.1);
+ pixels[y*256+x] = v * 0.5 + 0.5;
+ }
+ }
+ }
for y in range(0, 256) {
for x in range(0, 256) {
- print!("{}", symbols[(pixels[y*256+x] / 0.2f32) as int]);
+ let idx = (pixels[y*256+x] / 0.2) as uint;
+ print!("{:c}", symbols[idx]);
}
- println!("");
+ print!("\n");
}
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod extra;
+extern crate extra;
use std::os;
use std::uint;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod extra;
+extern crate extra;
use std::os;
use std::uint;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod extra;
+extern crate extra;
use std::task::spawn;
use std::os;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod extra;
+extern crate extra;
use std::os;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod sync;
-extern mod arena;
+extern crate sync;
+extern crate arena;
use std::iter::range_step;
use sync::Future;
// chameneos
-extern mod extra;
+extern crate extra;
use std::option;
use std::os;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod extra;
+extern crate extra;
use std::os;
// ignore-pretty the `let to_child` line gets an extra newline
// multi tasking k-nucleotide
-extern mod extra;
+extern crate extra;
use std::cmp::Ord;
use std::comm;
// ignore-test
-extern mod extra;
+extern crate extra;
use std::cast::transmute;
use std::i32::range;
*/
-extern mod extra;
-extern mod getopts;
+extern crate extra;
+extern crate getopts;
use extra::time;
use std::os;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod num;
+extern crate num;
use std::from_str::FromStr;
use std::num::One;
// ignore-test arcs no longer unwrap
-extern mod sync;
+extern crate sync;
use std::from_str::FromStr;
use std::iter::count;
// Microbenchmark for the smallintmap library
-extern mod extra;
-extern mod collections;
+extern crate extra;
+extern crate collections;
use collections::SmallIntMap;
use std::os;
#[feature(managed_boxes)];
-extern mod extra;
+extern crate extra;
use std::io;
use std::io::stdio::StdReader;
#[feature(managed_boxes)];
-extern mod extra;
-extern mod collections;
+extern crate extra;
+extern crate collections;
use collections::list::{List, Cons, Nil};
use extra::time::precise_time_s;
// ignore-fast aux-build
// aux-build:ambig_impl_2_lib.rs
-extern mod ambig_impl_2_lib;
+extern crate ambig_impl_2_lib;
use ambig_impl_2_lib::me;
trait me {
fn me(&self) -> uint;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod sync;
+extern crate sync;
use sync::RWArc;
fn main() {
// except according to those terms.
// error-pattern: lifetime of return value does not outlive the function call
-extern mod sync;
+extern crate sync;
use sync::RWArc;
fn main() {
let x = ~RWArc::new(1);
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod sync;
+extern crate sync;
use sync::RWArc;
fn main() {
let x = ~RWArc::new(1);
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod sync;
+extern crate sync;
use sync::RWArc;
fn main() {
let x = ~RWArc::new(1);
// except according to those terms.
// error-pattern: lifetime of variable does not enclose its declaration
-extern mod sync;
+extern crate sync;
use sync::RWArc;
fn main() {
let x = ~RWArc::new(1);
// except according to those terms.
// error-pattern: lifetime of variable does not enclose its declaration
-extern mod sync;
+extern crate sync;
use sync::RWArc;
fn main() {
let x = ~RWArc::new(1);
// Test for traits inheriting from the builtin kinds cross-crate.
// Mostly tests correctness of metadata.
-extern mod trait_superkinds_in_metadata;
+extern crate trait_superkinds_in_metadata;
use trait_superkinds_in_metadata::{RequiresRequiresFreezeAndSend, RequiresFreeze};
struct X<T>(T);
// Tests that methods that implement a trait cannot be invoked
// unless the trait is imported.
-extern mod coherence_inherent_cc_lib;
+extern crate coherence_inherent_cc_lib;
mod Import {
// Trait is in scope here:
// 'conflicting implementations' error message.
// aux-build:trait_impl_conflict.rs
-extern mod trait_impl_conflict;
+extern crate trait_impl_conflict;
use trait_impl_conflict::Foo;
impl<A> Foo for A {
// aux-build:crateresolve1-3.rs
// error-pattern:multiple matching crates for `crateresolve1`
-extern mod crateresolve1;
+extern crate crateresolve1;
fn main() {
}
// aux-build:crateresolve2-3.rs
// error-pattern:using multiple versions of crate `crateresolve2`
-extern mod crateresolve2 = "crateresolve2#0.1";
+extern crate crateresolve2 = "crateresolve2#0.1";
mod m {
- pub extern mod crateresolve2 = "crateresolve2#0.2";
+ pub extern crate crateresolve2 = "crateresolve2#0.2";
}
fn main() {
// aux-build:crateresolve5-1.rs
// aux-build:crateresolve5-2.rs
-extern mod cr5_1 = "crateresolve5#0.1";
-extern mod cr5_2 = "crateresolve5#0.2";
+extern crate cr5_1 = "crateresolve5#0.1";
+extern crate cr5_2 = "crateresolve5#0.2";
fn main() {
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
-extern mod extra;
+extern crate extra;
struct Error;
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
-extern mod extra;
+extern crate extra;
struct Error;
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
-extern mod extra;
+extern crate extra;
struct Error;
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
-extern mod extra;
+extern crate extra;
struct Error;
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
-extern mod extra;
+extern crate extra;
#[deriving(Clone)]
struct Error;
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
-extern mod extra;
+extern crate extra;
#[deriving(Clone)]
struct Error;
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
-extern mod extra;
+extern crate extra;
#[deriving(Clone)]
struct Error;
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
-extern mod extra;
+extern crate extra;
#[deriving(Clone)]
struct Error;
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
-extern mod extra;
+extern crate extra;
struct Error;
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
-extern mod extra;
+extern crate extra;
struct Error;
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
-extern mod extra;
+extern crate extra;
struct Error;
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
-extern mod extra;
+extern crate extra;
struct Error;
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
-extern mod extra;
+extern crate extra;
struct Error;
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
-extern mod extra;
+extern crate extra;
struct Error;
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
-extern mod extra;
+extern crate extra;
struct Error;
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
-extern mod extra;
+extern crate extra;
struct Error;
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
-extern mod extra;
+extern crate extra;
struct Error;
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
-extern mod extra;
+extern crate extra;
struct Error;
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
-extern mod extra;
+extern crate extra;
struct Error;
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
-extern mod extra;
+extern crate extra;
struct Error;
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
-extern mod extra;
+extern crate extra;
struct Error;
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
-extern mod extra;
+extern crate extra;
struct Error;
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
-extern mod extra;
+extern crate extra;
struct Error;
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
-extern mod extra;
+extern crate extra;
struct Error;
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
-extern mod extra;
+extern crate extra;
struct Error;
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
-extern mod extra;
+extern crate extra;
struct Error;
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
-extern mod extra;
+extern crate extra;
struct Error;
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
-extern mod extra;
+extern crate extra;
struct Error;
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
-extern mod extra;
+extern crate extra;
struct Error;
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
-extern mod extra;
+extern crate extra;
struct Error;
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
-extern mod extra;
+extern crate extra;
#[deriving(TotalEq)]
struct Error;
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
-extern mod extra;
+extern crate extra;
#[deriving(TotalEq)]
struct Error;
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
-extern mod extra;
+extern crate extra;
#[deriving(TotalEq)]
struct Error;
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
-extern mod extra;
+extern crate extra;
#[deriving(TotalEq)]
struct Error;
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
-extern mod extra;
+extern crate extra;
struct Error;
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
-extern mod extra;
+extern crate extra;
struct Error;
// issue 7327
// ignore-fast #7103
-extern mod sync;
+extern crate sync;
use sync::Arc;
struct A { y: Arc<int>, x: Arc<int> }
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod sync;
+extern crate sync;
use sync::Future;
#[feature(struct_variant)];
-extern mod bäz; //~ ERROR non-ascii idents
+extern crate bäz; //~ ERROR non-ascii idents
use föö::bar; //~ ERROR non-ascii idents
#[phase(syntax)]
//~^ ERROR compile time crate loading is experimental and possibly buggy
-extern mod macro_crate_test;
+extern crate macro_crate_test;
fn main() {}
#[simd]
pub struct i64x2(i64, i64); //~ ERROR: SIMD types are experimental
-fn main() {}
\ No newline at end of file
+fn main() {}
// aux-build:private_trait_xc.rs
-extern mod private_trait_xc;
+extern crate private_trait_xc;
struct Bar;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod extra;
+extern crate extra;
fn siphash(k0 : u64) {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod extra;
+extern crate extra;
fn siphash<T>() {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod extra;
+extern crate extra;
trait siphash {
fn result(&self) -> u64;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod extra;
+extern crate extra;
trait SipHash {
fn reset(&self);
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use std::ptr;
-
enum bottom { }
fn main() {
- let x = ptr::to_unsafe_ptr(&()) as *bottom;
+ let x = &() as *() as *bottom;
match x { } //~ ERROR non-exhaustive patterns
}
// except according to those terms.
// aux-build:issue_3907.rs
-extern mod issue_3907;
+extern crate issue_3907;
type Foo = issue_3907::Foo; //~ ERROR: reference to trait
//aux-build:issue_5844_aux.rs
-extern mod issue_5844_aux;
+extern crate issue_5844_aux;
fn main () {
issue_5844_aux::rand(); //~ ERROR: requires unsafe
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-pub extern mod std; //~ ERROR: `pub` visibility is not allowed
-priv extern mod std; //~ ERROR: unnecessary visibility qualifier
-extern mod std;
+pub extern crate std; //~ ERROR: `pub` visibility is not allowed
+priv extern crate std; //~ ERROR: unnecessary visibility qualifier
+extern crate std;
pub use std::bool;
priv use std::bool; //~ ERROR: unnecessary visibility qualifier
#[allow(dead_code)];
mod cross_crate {
- extern mod lint_stability;
+ extern crate lint_stability;
use self::lint_stability::*;
fn test() {
fn main() {
log_syntax!() //~ ERROR `log_syntax!` is not stable enough
-}
\ No newline at end of file
+}
#[feature(phase)];
#[phase(syntax)]
-extern mod macro_crate_test;
+extern crate macro_crate_test;
fn main() {
assert_eq!(3, unexported_macro!()); //~ ERROR macro undefined: 'unexported_macro'
#[feature(phase)];
#[phase(syntax)]
-extern mod doesnt_exist; //~ ERROR can't find crate
+extern crate doesnt_exist; //~ ERROR can't find crate
fn main() {}
// temporary kinds wound up being stored in a cache and used later.
// See middle::ty::type_contents() for more information.
-extern mod extra;
+extern crate extra;
struct List { key: int, next: Option<~List> }
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod sync;
+extern crate sync;
use std::task;
use sync::MutexArc;
// error-pattern: use of moved value
-extern mod sync;
+extern crate sync;
use sync::Arc;
use std::task;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod sync;
+extern crate sync;
use sync::Arc;
use std::task;
// aux-build:noexporttypelib.rs
-extern mod noexporttypelib;
+extern crate noexporttypelib;
fn main() {
// Here, the type returned by foo() is not exported.
// This program would segfault if it were legal.
#[feature(once_fns)];
-extern mod sync;
+extern crate sync;
use sync::Arc;
fn foo(blk: proc()) {
// This program would segfault if it were legal.
#[feature(once_fns)];
-extern mod sync;
+extern crate sync;
use sync::Arc;
fn foo(blk: once ||) {
// Testing guarantees provided by once functions.
// This program would segfault if it were legal.
-extern mod sync;
+extern crate sync;
use sync::Arc;
fn foo(blk: ||) {
// except according to those terms.
-extern mod extra;
+extern crate extra;
enum bar { t1((), Option<~[int]>), t2, }
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod extra;
+extern crate extra;
// error-pattern: mismatched types
#[feature(phase)];
#[phase(syntax)]
-extern mod macro_crate_test;
+extern crate macro_crate_test;
fn main() {
macro_crate_test::foo();
// ignore-fast
// aux-build:cci_class_5.rs
-extern mod cci_class_5;
+extern crate cci_class_5;
use cci_class_5::kitties::cat;
fn main() {
// except according to those terms.
// aux-build:cci_class.rs
-extern mod cci_class;
+extern crate cci_class;
use cci_class::kitties::cat;
fn main() {
// ignore-test
// aux-build:private_variant_xc.rs
-extern mod private_variant_xc;
+extern crate private_variant_xc;
pub fn main() {
let _ = private_variant_xc::Bar;
// ignore-test
// aux-build:private_variant_1.rs
-extern mod private_variant_1;
+extern crate private_variant_1;
fn main() {
let _x = private_variant_1::super_sekrit::baz; //~ ERROR baz is private
#[feature(quote)];
-extern mod extra;
-extern mod syntax;
+extern crate extra;
+extern crate syntax;
use io::*;
#[feature(quote)];
-extern mod extra;
-extern mod syntax;
+extern crate extra;
+extern crate syntax;
use extra::io::*;
// except according to those terms.
mod argparse {
- extern mod extra;
+ extern crate extra;
pub struct Flag<'a> {
name: &'a str,
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod extra;
+extern crate extra;
fn main() {
trait seq { }
// error-pattern: mismatched types
-extern mod extra;
+extern crate extra;
use std::task;
// aux-build:static_priv_by_default.rs
-extern mod static_priv_by_default;
+extern crate static_priv_by_default;
mod child {
pub mod childs_child {
// aux-build:static_priv_by_default.rs
-extern mod static_priv_by_default;
+extern crate static_priv_by_default;
mod child {
pub mod childs_child {
// aux-build:struct-field-privacy.rs
-extern mod xc = "struct-field-privacy";
+extern crate xc = "struct-field-privacy";
struct A {
a: int,
// except according to those terms.
// error-pattern: lifetime of variable does not enclose its declaration
-extern mod sync;
+extern crate sync;
use sync::Mutex;
fn main() {
// except according to those terms.
// error-pattern: lifetime of method receiver does not outlive the method call
-extern mod sync;
+extern crate sync;
use sync::RWLock;
fn main() {
let x = ~RWLock::new();
// except according to those terms.
// error-pattern: cannot infer
-extern mod sync;
+extern crate sync;
use sync::RWLock;
fn main() {
let x = ~RWLock::new();
// except according to those terms.
// error-pattern: lifetime of variable does not enclose its declaration
-extern mod sync;
+extern crate sync;
use sync::RWLock;
fn main() {
let x = ~RWLock::new();
// except according to those terms.
// error-pattern: lifetime of variable does not enclose its declaration
-extern mod sync;
+extern crate sync;
use sync::RWLock;
fn main() {
let x = ~RWLock::new();
#[feature(phase)];
#[phase(syntax)]
-extern mod fourcc;
+extern crate fourcc;
fn main() {
let val = fourcc!("foo"); //~ ERROR string literal with len != 4 in fourcc!
#[feature(phase)];
#[phase(syntax)]
-extern mod fourcc;
+extern crate fourcc;
fn main() {
let val = fourcc!("foo ", bork); //~ ERROR invalid endian directive in fourcc!
#[feature(phase)];
#[phase(syntax)]
-extern mod fourcc;
+extern crate fourcc;
fn main() {
let v = fourcc!("fooλ"); //~ ERROR fourcc! literal character out of range 0-255
#[feature(phase)];
#[phase(syntax)]
-extern mod fourcc;
+extern crate fourcc;
fn main() {
let val = fourcc!(foo); //~ ERROR non-literal in fourcc!
#[feature(phase)];
#[phase(syntax)]
-extern mod fourcc;
+extern crate fourcc;
fn main() {
let val = fourcc!(45f32); //~ ERROR unsupported literal in fourcc!
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod extra;
+extern crate extra;
use extra; //~ ERROR unresolved import (maybe you meant `extra::*`?)
fn main() {}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use foo::bar; //~ ERROR unresolved import. maybe a missing `extern mod foo`?
+use foo::bar; //~ ERROR unresolved import. maybe a missing `extern crate foo`?
//~^ ERROR failed to resolve import `foo::bar`
use x = bar::baz; //~ ERROR unresolved import: there is no `baz` in `bar`
//~^ ERROR failed to resolve import `bar::baz`
// aux-build:use_from_trait_xc.rs
-extern mod use_from_trait_xc;
+extern crate use_from_trait_xc;
use use_from_trait_xc::Trait::foo; //~ ERROR cannot import from a trait or type implementation
//~^ ERROR failed to resolve import
// error-pattern:can't find crate for `extra`
-extern mod extra = "fake-crate";
+extern crate extra = "fake-crate";
fn main() { }
// error-pattern:can't find crate for `std`
-extern mod std = "std#bogus";
+extern crate std = "std#bogus";
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod extra;
+extern crate extra;
fn f() {
}
-use extra::net; //~ ERROR `use` and `extern mod` declarations must precede items
+use extra::net; //~ ERROR `use` and `extern crate` declarations must precede items
fn main() {
}
// ignore-fast
// aux-build:xc_private_method_lib.rs
-extern mod xc_private_method_lib;
+extern crate xc_private_method_lib;
fn main() {
let _ = xc_private_method_lib::Struct::static_meth_struct();
// ignore-fast
// aux-build:xc_private_method_lib.rs
-extern mod xc_private_method_lib;
+extern crate xc_private_method_lib;
fn main() {
let _ = xc_private_method_lib::Struct{ x: 10 }.meth_struct();
// aux-build:static_priv_by_default.rs
-extern mod static_priv_by_default;
+extern crate static_priv_by_default;
fn foo<T>() {}
// Make sure that when we have cross-crate unit structs we don't accidentally
// make values out of cross-crate structs that aren't unit.
-extern mod xcrate_unit_struct;
+extern crate xcrate_unit_struct;
fn main() {
let _ = xcrate_unit_struct::StructWithFields; //~ ERROR: unresolved name
#[feature(asm)];
#[cfg = r#"just parse this"#]
-extern mod blah = r##"blah"##;
+extern crate blah = r##"blah"##;
fn main() { unsafe { asm!(r###"blah"###); } }
// except according to those terms.
// error-pattern:moop
-extern mod extra;
+extern crate extra;
fn main() { fail!("moop"); }
// except according to those terms.
// error-pattern:meh
-extern mod extra;
+extern crate extra;
fn main() { let str_var: ~str = ~"meh"; fail!("{}", str_var); }
// except according to those terms.
// error-pattern:moop
-extern mod extra;
+extern crate extra;
fn main() { for _ in range(0u, 10u) { fail!("moop"); } }
// error-pattern:explicit failure
-extern mod sync;
+extern crate sync;
use sync::Arc;
enum e<T> { e(Arc<T>) }
// ignore-test linked failure
// error-pattern:1 == 2
-extern mod extra;
+extern crate extra;
use std::comm;
use std::task;
// See the hack in upcall_call_shim_on_c_stack where it messes
// with the stack limit.
-extern mod extra;
+extern crate extra;
use std::libc;
use std::task;
// Just testing unwinding
-extern mod extra;
+extern crate extra;
use std::task;
// Just testing unwinding
-extern mod extra;
+extern crate extra;
use std::task;
#[no_uv];
-extern mod native;
+extern crate native;
#[start]
fn start(argc: int, argv: **u8) -> int {
// compile-flags:--test
// check-stdout
-extern mod extra;
+extern crate extra;
mod m {
pub fn exported() { }
// ignore-test linked failure
// error-pattern:explicit
-extern mod extra;
+extern crate extra;
use std::task;
#[crate_type="dylib"];
#[no_uv];
-extern mod rustuv;
-extern mod green;
+extern crate rustuv;
+extern crate green;
#[no_mangle] // this needs to get called from C
pub extern "C" fn foo(argc: int, argv: **u8) -> int {
#[crate_type="dylib"];
#[no_uv];
-extern mod native;
+extern crate native;
#[no_mangle] // this needs to get called from C
pub extern "C" fn foo(argc: int, argv: **u8) -> int {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod foo;
+extern crate foo;
fn main() {
foo::rsfoo();
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod foo;
+extern crate foo;
fn main() {
foo::rsfoo();
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod foo;
+extern crate foo;
fn main() {
foo::rsfoo();
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod foo;
+extern crate foo;
fn main() {
foo::rsfoo();
// except according to those terms.
#[crate_type = "dylib"];
-extern mod m1;
+extern crate m1;
pub fn m2() { m1::m1() }
// except according to those terms.
#[crate_type = "dylib"];
-extern mod m2;
+extern crate m2;
pub fn m3() { m2::m2() }
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod m3;
+extern crate m3;
fn main() { m3::m3() }
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod lib;
+extern crate lib;
fn main() {}
// except according to those terms.
#[crate_type = "dylib"];
-extern mod both;
+extern crate both;
use std::cast;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod dylib;
-extern mod both;
+extern crate dylib;
+extern crate both;
use std::cast;
// except according to those terms.
#[crate_type = "dylib"];
-extern mod rlib;
+extern crate rlib;
pub fn dylib() { rlib::rlib() }
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod dylib;
-extern mod rlib;
+extern crate dylib;
+extern crate rlib;
fn main() {
dylib::dylib();
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod bar;
+extern crate bar;
fn main() {
bar::bar();
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod bar;
+extern crate bar;
fn main() {
bar::bar();
// except according to those terms.
#[crate_type = "rlib"];
-extern mod m1;
+extern crate m1;
pub fn m2() { m1::m1() }
// except according to those terms.
#[crate_type = "rlib"];
-extern mod m2;
+extern crate m2;
pub fn m3() { m2::m2() }
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod m3;
+extern crate m3;
fn main() { m3::m3() }
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod bar;
+extern crate bar;
fn main() {
bar::bar();
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod bar;
+extern crate bar;
fn main() {
bar::bar();
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod lib;
+extern crate lib;
use std::task;
#[feature(phase)];
#[phase(syntax)]
-extern mod macro_crate_outlive_expansion_phase;
+extern crate macro_crate_outlive_expansion_phase;
pub fn main() {}
#[feature(phase)];
#[phase(syntax)]
-extern mod macro_crate_test;
+extern crate macro_crate_test;
pub fn main() {
assert_eq!(1, make_a_1!());
#[feature(quote)];
-extern mod extra;
-extern mod syntax;
+extern crate extra;
+extern crate syntax;
use std::io::*;
#[feature(quote)];
#[feature(managed_boxes)];
-extern mod syntax;
+extern crate syntax;
use syntax::ext::base::ExtCtxt;
#[feature(quote)];
#[deny(unused_variable)];
-extern mod syntax;
+extern crate syntax;
use syntax::ext::base::ExtCtxt;
#[feature(phase)];
#[phase(syntax)]
-extern mod fourcc;
+extern crate fourcc;
static static_val: u32 = fourcc!("foo ");
static static_val_be: u32 = fourcc!("foo ", big);
// ignore-fast
// ignore-pretty
// aux-build:anon-extern-mod-cross-crate-1.rs
-extern mod anonexternmod;
+extern crate anonexternmod;
use anonexternmod::rust_get_test_int;
// ignore-fast - check-fast doesn't understand aux-build
// aux-build:anon_trait_static_method_lib.rs
-extern mod anon_trait_static_method_lib;
+extern crate anon_trait_static_method_lib;
use anon_trait_static_method_lib::Foo;
pub fn main() {
// error-pattern:expected item
#[foo = "bar"]
-extern mod extra;
+extern crate extra;
pub fn main() {
}
mod m {
#[foo = "bar"]
- extern mod extra;
+ extern crate extra;
}
pub fn main() {
#[feature(managed_boxes)];
-extern mod extra;
+extern crate extra;
// These tests used to be separate files, but I wanted to refactor all
// the common code.
// except according to those terms.
// ignore-fast
-extern mod sync;
+extern crate sync;
use sync::Arc;
fn dispose(_x: Arc<bool>) { }
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod collections;
+extern crate collections;
use collections::Bitv;
fn bitv_test() {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod extra;
+extern crate extra;
fn asSendfn(f: proc() -> uint) -> uint {
return f();
#[feature(managed_boxes)];
-use std::ptr;
-
fn borrow(x: &int, f: |x: &int|) {
f(x)
}
fn test1(x: @~int) {
borrow(&*(*x).clone(), |p| {
- let x_a = ptr::to_unsafe_ptr(&**x);
+ let x_a = &**x as *int;
assert!((x_a as uint) != (p as *int as uint));
assert_eq!(unsafe{*x_a}, *p);
})
#[feature(managed_boxes)];
-use std::ptr;
-
fn borrow(x: &int, f: |x: &int|) {
let before = *x;
f(x);
let mut x = @F {f: ~3};
borrow(x.f, |b_x| {
assert_eq!(*b_x, 3);
- assert_eq!(ptr::to_unsafe_ptr(&(*x.f)), ptr::to_unsafe_ptr(&(*b_x)));
+ assert_eq!(&(*x.f) as *int, &(*b_x) as *int);
x = @F {f: ~4};
- info!("ptr::to_unsafe_ptr(*b_x) = {:x}",
- ptr::to_unsafe_ptr(&(*b_x)) as uint);
+ info!("&*b_x = {:p}", &(*b_x));
assert_eq!(*b_x, 3);
- assert!(ptr::to_unsafe_ptr(&(*x.f)) != ptr::to_unsafe_ptr(&(*b_x)));
+ assert!(&(*x.f) as *int != &(*b_x) as *int);
})
}
#[feature(managed_boxes)];
-use std::ptr;
-
fn borrow(x: &int, f: |x: &int|) {
let before = *x;
f(x);
let mut x = ~@F{f: ~3};
borrow(x.f, |b_x| {
assert_eq!(*b_x, 3);
- assert_eq!(ptr::to_unsafe_ptr(&(*x.f)), ptr::to_unsafe_ptr(&(*b_x)));
+ assert_eq!(&(*x.f) as *int, &(*b_x) as *int);
*x = @F{f: ~4};
- info!("ptr::to_unsafe_ptr(*b_x) = {:x}",
- ptr::to_unsafe_ptr(&(*b_x)) as uint);
+ info!("&*b_x = {:p}", &(*b_x));
assert_eq!(*b_x, 3);
- assert!(ptr::to_unsafe_ptr(&(*x.f)) != ptr::to_unsafe_ptr(&(*b_x)));
+ assert!(&(*x.f) as *int != &(*b_x) as *int);
})
}
#[feature(managed_boxes)];
-use std::ptr;
-
fn borrow(x: &int, f: |x: &int|) {
let before = *x;
f(x);
let mut x = @3;
borrow(x, |b_x| {
assert_eq!(*b_x, 3);
- assert_eq!(ptr::to_unsafe_ptr(&(*x)), ptr::to_unsafe_ptr(&(*b_x)));
+ assert_eq!(&(*x) as *int, &(*b_x) as *int);
x = @22;
- info!("ptr::to_unsafe_ptr(*b_x) = {:x}",
- ptr::to_unsafe_ptr(&(*b_x)) as uint);
+ info!("&*b_x = {:p}", &(*b_x));
assert_eq!(*b_x, 3);
- assert!(ptr::to_unsafe_ptr(&(*x)) != ptr::to_unsafe_ptr(&(*b_x)));
+ assert!(&(*x) as *int != &(*b_x) as *int);
})
}
#[feature(managed_boxes)];
-use std::ptr;
-
fn borrow(x: &int, f: |x: &int|) {
let before = *x;
f(x);
let mut x = @F {f: ~3};
borrow((*x).f, |b_x| {
assert_eq!(*b_x, 3);
- assert_eq!(ptr::to_unsafe_ptr(&(*x.f)), ptr::to_unsafe_ptr(&(*b_x)));
+ assert_eq!(&(*x.f) as *int, &(*b_x) as *int);
x = @F {f: ~4};
- info!("ptr::to_unsafe_ptr(*b_x) = {:x}",
- ptr::to_unsafe_ptr(&(*b_x)) as uint);
+ info!("&*b_x = {:p}", &(*b_x));
assert_eq!(*b_x, 3);
- assert!(ptr::to_unsafe_ptr(&(*x.f)) != ptr::to_unsafe_ptr(&(*b_x)));
+ assert!(&(*x.f) as *int != &(*b_x) as *int);
})
}
// Tests "capabilities" granted by traits with super-builtin-kinds,
// even when using them cross-crate.
-extern mod trait_superkinds_in_metadata;
+extern crate trait_superkinds_in_metadata;
use trait_superkinds_in_metadata::{RequiresRequiresFreezeAndSend, RequiresFreeze};
#[deriving(Eq)]
// Tests (correct) usage of trait super-builtin-kinds cross-crate.
-extern mod trait_superkinds_in_metadata;
+extern crate trait_superkinds_in_metadata;
use trait_superkinds_in_metadata::{RequiresRequiresFreezeAndSend, RequiresFreeze};
use trait_superkinds_in_metadata::{RequiresPod};
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-use std::ptr;
-
-pub fn main() {
- let x = ~3;
- let y = ptr::to_unsafe_ptr(&(*x)) as uint;
- let snd_move: proc() -> uint = proc() ptr::to_unsafe_ptr(&(*x)) as uint;
- assert_eq!(snd_move(), y);
-
- let x = ~4;
- let y = ptr::to_unsafe_ptr(&(*x)) as uint;
- let lam_move: proc() -> uint = proc() ptr::to_unsafe_ptr(&(*x)) as uint;
- assert_eq!(lam_move(), y);
-}
// exec-env:RUST_LOG=info
#[no_uv];
-extern mod native;
+extern crate native;
use std::fmt;
use std::io::{PortReader, ChanWriter};
#[feature(managed_boxes)];
-extern mod cci_borrow_lib;
+extern crate cci_borrow_lib;
use cci_borrow_lib::foo;
pub fn main() {
// This test makes sure we can do cross-crate inlining on functions
// that use capture clauses.
-extern mod cci_capture_clause;
+extern crate cci_capture_clause;
pub fn main() {
cci_capture_clause::foo(()).recv()
// ignore-fast - check-fast doesn't understand aux-build
// aux-build:cci_impl_lib.rs
-extern mod cci_impl_lib;
+extern crate cci_impl_lib;
use cci_impl_lib::uint_helpers;
pub fn main() {
// ignore-fast - check-fast doesn't understand aux-build
// aux-build:cci_iter_lib.rs
-extern mod cci_iter_lib;
+extern crate cci_iter_lib;
pub fn main() {
//let bt0 = sys::rusti::frame_address(1u32);
#[feature(globs, managed_boxes)];
-extern mod cci_nested_lib;
+extern crate cci_nested_lib;
use cci_nested_lib::*;
pub fn main() {
// ignore-fast - check-fast doesn't understand aux-build
// aux-build:cci_no_inline_lib.rs
-extern mod cci_no_inline_lib;
+extern crate cci_no_inline_lib;
use cci_no_inline_lib::iter;
pub fn main() {
// aux-build:cfg_inner_static.rs
// ignore-fast
-extern mod cfg_inner_static;
+extern crate cfg_inner_static;
pub fn main() {
cfg_inner_static::foo();
// ignore-fast
// aux-build:cci_class_cast.rs
-extern mod cci_class_cast;
+extern crate cci_class_cast;
use std::to_str::ToStr;
use cci_class_cast::kitty::cat;
// ignore-fast
// aux-build:cci_class_trait.rs
-extern mod cci_class_trait;
+extern crate cci_class_trait;
use cci_class_trait::animals::noisy;
struct cat {
// ignore-fast
// aux-build:cci_class_2.rs
-extern mod cci_class_2;
+extern crate cci_class_2;
use cci_class_2::kitties::cat;
pub fn main() {
// ignore-fast
// aux-build:cci_class_3.rs
-extern mod cci_class_3;
+extern crate cci_class_3;
use cci_class_3::kitties::cat;
pub fn main() {
// ignore-fast
// aux-build:cci_class_6.rs
-extern mod cci_class_6;
+extern crate cci_class_6;
use cci_class_6::kitties::cat;
pub fn main() {
// ignore-fast
// aux-build:cci_class_4.rs
-extern mod cci_class_4;
+extern crate cci_class_4;
use cci_class_4::kitties::cat;
pub fn main() {
// ignore-fast
// aux-build:cci_class.rs
-extern mod cci_class;
+extern crate cci_class;
use cci_class::kitties::cat;
pub fn main() {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod extra;
+extern crate extra;
use std::task::spawn;
struct Pair {
// ignore-fast
// aux-build:cci_const.rs
-extern mod cci_const;
+extern crate cci_const;
static foo: &'static str = cci_const::foopy;
static a: uint = cci_const::uint_val;
static b: uint = cci_const::uint_expr + 5;
// ignore-fast
// aux-build:cci_const.rs
-extern mod cci_const;
+extern crate cci_const;
use cci_const::bar;
static foo: extern "C" fn() = bar;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use std::ptr;
-
type Big = [u64, ..8];
struct Pair<'a> { a: int, b: &'a Big }
static x: &'static Big = &([13, 14, 10, 13, 11, 14, 14, 15]);
static y: &'static Pair<'static> = &Pair {a: 15, b: x};
pub fn main() {
- assert_eq!(ptr::to_unsafe_ptr(x), ptr::to_unsafe_ptr(y.b));
+ assert_eq!(x as *Big, y.b as *Big);
}
// ignore-fast
// aux-build:crate-method-reexport-grrrrrrr2.rs
-extern mod crate_method_reexport_grrrrrrr2;
+extern crate crate_method_reexport_grrrrrrr2;
pub fn main() {
use crate_method_reexport_grrrrrrr2::rust::add;
// aux-build:crateresolve1-2.rs
// aux-build:crateresolve1-3.rs
-extern mod crateresolve1 = "crateresolve1#0.2";
+extern crate crateresolve1 = "crateresolve1#0.2";
pub fn main() {
assert_eq!(crateresolve1::f(), 20);
// aux-build:crateresolve2-3.rs
mod a {
- extern mod crateresolve2 = "crateresolve2#0.1";
+ extern crate crateresolve2 = "crateresolve2#0.1";
pub fn f() { assert!(crateresolve2::f() == 10); }
}
mod b {
- extern mod crateresolve2 = "crateresolve2#0.2";
+ extern crate crateresolve2 = "crateresolve2#0.2";
pub fn f() { assert!(crateresolve2::f() == 20); }
}
mod c {
- extern mod crateresolve2 = "crateresolve2#0.3";
+ extern crate crateresolve2 = "crateresolve2#0.3";
pub fn f() { assert!(crateresolve2::f() == 30); }
}
// as long as no name collision on invoked functions.
mod a {
- extern mod crateresolve3 = "crateresolve3#0.1";
+ extern crate crateresolve3 = "crateresolve3#0.1";
pub fn f() { assert!(crateresolve3::f() == 10); }
}
mod b {
- extern mod crateresolve3 = "crateresolve3#0.2";
+ extern crate crateresolve3 = "crateresolve3#0.2";
pub fn f() { assert!(crateresolve3::g() == 20); }
}
// aux-build:crateresolve4b-2.rs
pub mod a {
- extern mod crateresolve4b = "crateresolve4b#0.1";
+ extern crate crateresolve4b = "crateresolve4b#0.1";
pub fn f() { assert!(crateresolve4b::f() == 20); }
}
pub mod b {
- extern mod crateresolve4b = "crateresolve4b#0.2";
+ extern crate crateresolve4b = "crateresolve4b#0.2";
pub fn f() { assert!(crateresolve4b::g() == 10); }
}
// aux-build:crateresolve5-1.rs
// aux-build:crateresolve5-2.rs
-extern mod cr5_1 = "crateresolve5#0.1";
-extern mod cr5_2 = "crateresolve5#0.2";
+extern crate cr5_1 = "crateresolve5#0.1";
+extern crate cr5_2 = "crateresolve5#0.2";
pub fn main() {
// Structural types can be used between two versions of the same crate
#[crate_id="crateresolve8#0.1"];
-extern mod crateresolve8 = "crateresolve8#0.1";
-//extern mod crateresolve8(vers = "0.1");
+extern crate crateresolve8 = "crateresolve8#0.1";
+//extern crate crateresolve8(vers = "0.1");
pub fn main() {
assert_eq!(crateresolve8::f(), 20);
// ignore-fast
// aux-build:cci_const.rs
-extern mod cci_const;
+extern crate cci_const;
pub fn main() {
let x = cci_const::uint_val;
// ignore-fast
// aux-build:newtype_struct_xc.rs
-extern mod newtype_struct_xc;
+extern crate newtype_struct_xc;
pub fn main() {
let x = newtype_struct_xc::Au(21);
#[feature(struct_variant, managed_boxes)];
-extern mod serialize;
+extern crate serialize;
use std::io::MemWriter;
use std::rand::{random, Rand};
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-// ignore-fast #7103 `extern mod` does not work on check-fast
+// ignore-fast #7103 `extern crate` does not work on check-fast
// ignore-pretty - does not converge
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod serialize; // {En,De}codable
+extern crate serialize; // {En,De}codable
mod submod {
// if any of these are implemented without global calls for any
// function calls, then being in a submodule will (correctly)
// ignore-test
-extern mod extra;
+extern crate extra;
use list = extra::oldmap::chained;
use extra::list;
// ignore-fast
// aux-build:anon-extern-mod-cross-crate-1.rs
// aux-build:anon-extern-mod-cross-crate-1.rs
-extern mod anonexternmod;
+extern crate anonexternmod;
pub fn main() { }
// except according to those terms.
use std::cast;
-use std::ptr;
use std::mem;
fn addr_of<T>(ptr: &T) -> uint {
- let ptr = ptr::to_unsafe_ptr(ptr);
- ptr as uint
+ ptr as *T as uint
}
fn is_aligned<T>(ptr: &T) -> bool {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod extra;
+extern crate extra;
/**
* A function that returns a hash of a value
// ignore-fast
// aux-build:explicit_self_xcrate.rs
-extern mod explicit_self_xcrate;
+extern crate explicit_self_xcrate;
use explicit_self_xcrate::{Foo, Bar};
pub fn main() {
// ignore-fast: aux-build not compatible with fast
// aux-build:extern_calling_convention.rs
-extern mod extern_calling_convention;
+extern crate extern_calling_convention;
use extern_calling_convention::foo;
// ignore-fast
//aux-build:extern-crosscrate-source.rs
-extern mod externcallback = "externcallback#0.1";
+extern crate externcallback = "externcallback#0.1";
fn fact(n: uint) -> uint {
unsafe {
// except according to those terms.
extern crate extra;
-extern mod mystd = "std";
+extern crate mystd = "std";
pub fn main() {}
// aux-build:extern_mod_ordering_lib.rs
// ignore-fast
-extern mod extern_mod_ordering_lib;
+extern crate extern_mod_ordering_lib;
use extern_mod_ordering_lib::extern_mod_ordering_lib;
#[allow(unused_imports)];
-extern mod extra;
+extern crate extra;
use extra::json::Object;
pub fn main() {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod extra;
+extern crate extra;
use std::num::Float;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod extra;
+extern crate extra;
mod libc {
use std::libc::{c_char, size_t};
#[allow(default_type_param_usage)];
-extern mod default_type_params_xc;
+extern crate default_type_params_xc;
struct Vec<T, A = default_type_params_xc::Heap>;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod getopts;
+extern crate getopts;
use getopts::{optopt, getopts};
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-// ignore-fast check-fast doesn't like 'extern mod extra'
+// ignore-fast check-fast doesn't like 'extern crate extra'
// ignore-win32 TempDir may cause IoError on windows: #10462
-extern mod extra;
-extern mod glob;
+extern crate extra;
+extern crate glob;
use glob::glob;
use extra::tempfile::TempDir;
// aux-build:impl_privacy_xc_1.rs
// ignore-fast
-extern mod impl_privacy_xc_1;
+extern crate impl_privacy_xc_1;
pub fn main() {
let fish = impl_privacy_xc_1::Fish { x: 1 };
// aux-build:impl_privacy_xc_2.rs
// ignore-fast
-extern mod impl_privacy_xc_2;
+extern crate impl_privacy_xc_2;
pub fn main() {
let fish1 = impl_privacy_xc_2::Fish { x: 1 };
#[feature(globs)];
#[allow(dead_assignment)];
-extern mod extra;
+extern crate extra;
use std::vec::*;
pub fn main() {
*/
// ignore-test
-extern mod extra;
+extern crate extra;
fn loopy(n: int) {
if n > 0 { spawn(proc() { loopy(n - 1) }); spawn(proc() { loopy(n - 1) }); }
// aux-build:inner_static.rs
// ignore-fast
-extern mod inner_static;
+extern crate inner_static;
pub fn main() {
let a = inner_static::A::<()>;
// ignore-fast - check-fast doesn't understand aux-build
// aux-build:cci_intrinsic.rs
-extern mod cci_intrinsic;
+extern crate cci_intrinsic;
use cci_intrinsic::atomic_xchg;
pub fn main() {
#[feature(globs)];
-extern mod extra;
+extern crate extra;
mod rusti {
extern "rust-intrinsic" {
// successfully (and safely) invoke external, cdecl
// functions from outside the crate.
-extern mod foreign_lib;
+extern crate foreign_lib;
pub fn main() {
unsafe {
// ignore-fast - check-fast doesn't understand aux-build
// aux-build:issue_10031_aux.rs
-extern mod issue_10031_aux;
+extern crate issue_10031_aux;
pub fn main() {
let _ = issue_10031_aux::Wrap(());
// aux-build:issue-11224.rs
// ignore-fast
-extern mod unused = "issue-11224";
+extern crate unused = "issue-11224";
pub fn main() {}
// aux-build:issue-11225-1.rs
// ignore-fast
-extern mod foo = "issue-11225-1";
+extern crate foo = "issue-11225-1";
pub fn main() {
foo::foo(1);
// aux-build:issue-11225-2.rs
// ignore-fast
-extern mod foo = "issue-11225-2";
+extern crate foo = "issue-11225-2";
pub fn main() {
foo::foo(1);
// aux-build:issue_2316_a.rs
// aux-build:issue_2316_b.rs
-extern mod issue_2316_b;
+extern crate issue_2316_b;
use issue_2316_b::cloth;
pub fn main() {
// ignore-fast
// aux-build:issue-2380.rs
-extern mod a;
+extern crate a;
pub fn main() {
a::f::<()>();
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod collections;
+extern crate collections;
use collections::RingBuf;
use collections::Deque;
// aux-build:issue-2414-a.rs
// aux-build:issue-2414-b.rs
-extern mod b;
+extern crate b;
pub fn main() {}
// aux-build:issue_2472_b.rs
// ignore-fast
-extern mod issue_2472_b;
+extern crate issue_2472_b;
use issue_2472_b::{S, T};
#[feature(globs)];
#[allow(unused_imports)];
-extern mod issue_2526;
+extern crate issue_2526;
use issue_2526::*;
pub fn main() {}
// ignore-fast
// aux-build:issue-2631-a.rs
-extern mod req;
+extern crate req;
use req::request;
use std::cell::RefCell;
// ignore-fast: aux-build not compatible with fast
// aux-build:issue_2723_a.rs
-extern mod issue_2723_a;
+extern crate issue_2723_a;
use issue_2723_a::f;
pub fn main() {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod extra;
+extern crate extra;
use extra::json;
use std::hashmap::HashMap;
/// Map representation
-extern mod extra;
+extern crate extra;
use std::io;
use std::to_str;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod extra;
+extern crate extra;
use std::vec;
#[feature(managed_boxes)];
-extern mod socketlib;
+extern crate socketlib;
use socketlib::socket;
use std::libc;
// except according to those terms.
// rustc --test ignores2.rs && ./ignores2
-extern mod extra;
+extern crate extra;
use std::path::{Path};
use std::path;
#[feature(managed_boxes)];
-extern mod extra;
+extern crate extra;
enum Token {
Text(@~str),
// However the extra library is designed to be optional (for code that must run on constrained
// environments like embedded devices or special environments like kernel code) so it must
// be explicitly linked in.
-extern mod extra;
+extern crate extra;
// Extern mod controls linkage. Use controls the visibility of names to modules that are
// already linked in. Using WriterUtil allows us to use the write_line method.
#[allow(unnecessary_allocation)];
// rustc --test match_borrowed_str.rs.rs && ./match_borrowed_str.rs
-extern mod extra;
+extern crate extra;
fn compare(x: &str, y: &str) -> bool
{
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod extra;
+extern crate extra;
use std::comm::Chan;
use std::task;
// ignore-fast
// aux-build:issue_3979_traits.rs
-extern mod issue_3979_traits;
+extern crate issue_3979_traits;
use issue_3979_traits::{Positioned, Movable};
struct Point { x: int, y: int }
// ignore-fast
-extern mod extra;
-extern mod serialize;
+extern crate extra;
+extern crate serialize;
use extra::json;
use serialize::Decodable;
// Issue #4036: Test for an issue that arose around fixing up type inference
// byproducts in vtable records.
-extern mod extra;
-extern mod serialize;
+extern crate extra;
+extern crate serialize;
use extra::json;
use serialize::Decodable;
// aux-build:issue-4208-cc.rs
// ignore-fast - check-fast hates cross-crate tests
-extern mod numeric;
+extern crate numeric;
use numeric::{sin, Angle};
fn foo<T, A:Angle<T>>(theta: A) -> T { sin(&theta) }
// ignore-fast
// ignore-test needs networking
-extern mod extra;
+extern crate extra;
use extra::net::tcp::TcpSocketBuf;
// ignore-fast check-fast doesn't like aux-build
// aux-build:issue-4545.rs
-extern mod somelib = "issue-4545";
+extern crate somelib = "issue-4545";
pub fn main() { somelib::mk::<int>(); }
#[feature(managed_boxes)];
-extern mod foo = "issue-5521";
+extern crate foo = "issue-5521";
fn foo(a: foo::map) {
if false {
// ignore-fast
#[crate_id="issue-6919"];
-extern mod issue6919_3;
+extern crate issue6919_3;
pub fn main() {
issue6919_3::D.k;
// ignore-fast
// aux-build:issue-7178.rs
-extern mod cross_crate_self = "issue-7178";
+extern crate cross_crate_self = "issue-7178";
pub fn main() {
let _ = cross_crate_self::Foo::new(&1i);
// ignore-fast check-fast doesn't like aux-build
// aux-build:issue-8044.rs
-extern mod minimal = "issue-8044";
+extern crate minimal = "issue-8044";
use minimal::{BTree, leaf};
pub fn main() {
// ignore-fast
// aux-build:issue-8259.rs
-extern mod other = "issue-8259";
+extern crate other = "issue-8259";
static a: other::Foo<'static> = other::A;
pub fn main() {}
// aux-build:issue_8401.rs
// ignore-fast
-extern mod issue_8401;
+extern crate issue_8401;
pub fn main() {}
// ignore-fast
-extern mod green;
+extern crate green;
static mut DROP: int = 0i;
static mut DROP_S: int = 0i;
// ignore-fast check-fast doesn't like aux-build
// aux-build:issue_9123.rs
-extern mod issue_9123;
+extern crate issue_9123;
pub fn main() {}
// aux-build:issue_9188.rs
// ignore-fast check-fast doesn't like aux-build
-extern mod issue_9188;
+extern crate issue_9188;
pub fn main() {
let a = issue_9188::bar();
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-// ignore-fast check-fast doesn't like extern mod
+// ignore-fast check-fast doesn't like extern crate
// aux-build:issue-9906.rs
-extern mod testmod = "issue-9906";
+extern crate testmod = "issue-9906";
pub fn main() {
testmod::foo();
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-// ignore-fast check-fast doesn't like extern mod
+// ignore-fast check-fast doesn't like extern crate
// aux-build:issue-9968.rs
-extern mod lib = "issue-9968";
+extern crate lib = "issue-9968";
use lib::{Trait, Struct};
// ignore-fast - check-fail fast doesn't under aux-build
// aux-build:issue2170lib.rs
-extern mod issue2170lib;
+extern crate issue2170lib;
pub fn main() {
// let _ = issue2170lib::rsrc(2i32);
// aux-build:issue2378b.rs
// ignore-fast - check-fast doesn't understand aux-build
-extern mod issue2378a;
-extern mod issue2378b;
+extern crate issue2378a;
+extern crate issue2378b;
use issue2378a::{just};
use issue2378b::{two_maybes};
// ignore-fast - check-fast doesn't understand aux-build
// aux-build:issue_3136_a.rc
-extern mod issue_3136_a;
+extern crate issue_3136_a;
pub fn main() {}
// aux-build:issue_9155.rs
// ignore-fast check-fast doesn't like the aux-build
-extern mod issue_9155;
+extern crate issue_9155;
struct Baz;
}
mod test_distinguish_syntax_ext {
- extern mod extra;
+ extern crate extra;
pub fn f() {
format!("test{}", "s");
// Tests that metadata serialization works for the `Pod` kind.
-extern mod kinds_in_metadata;
+extern crate kinds_in_metadata;
use kinds_in_metadata::f;
// except according to those terms.
// aux-build:linkage-visibility.rs
-// ignore-fast check-fast doesn't like 'extern mod'
+// ignore-fast check-fast doesn't like 'extern crate'
// ignore-android: FIXME(#10379)
// ignore-win32: std::unstable::dynamic_lib does not work on win32 well
-extern mod foo = "linkage-visibility";
+extern crate foo = "linkage-visibility";
pub fn main() {
foo::test();
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod collections;
+extern crate collections;
use collections::list;
#[deriving(Clone)]
// longer happens by enabling logging for *this* crate and then invoking a
// function in an external crate which will fail when logging is enabled.
-extern mod logging_right_crate;
+extern crate logging_right_crate;
pub fn main() {
// this function fails if logging is turned on
// ignore-test linked failure
-extern mod extra;
+extern crate extra;
use std::task;
#[feature(phase)];
#[phase(syntax)]
-extern mod macro_crate_def_only;
+extern crate macro_crate_def_only;
pub fn main() {
assert_eq!(5, make_a_5!());
#[feature(phase)];
#[phase(syntax)]
-extern mod macro_export_inner_module;
+extern crate macro_export_inner_module;
pub fn main() {
assert_eq!(1, foo!());
// except according to those terms.
-extern mod extra;
+extern crate extra;
fn foo<T>(y: Option<T>) {
let mut x: int;
#[feature(managed_boxes)];
-extern mod extra;
+extern crate extra;
trait Serializer {
}
// This test will call __morestack with various minimum stack sizes
-extern mod extra;
+extern crate extra;
use std::task;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod extra;
+extern crate extra;
#[deriving(Clone)]
struct Triple {
#[feature(managed_boxes)];
-extern mod extra;
+extern crate extra;
struct Triple { x: int, y: int, z: int }
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod extra;
+extern crate extra;
struct Triple {a: int, b: int, c: int}
#[feature(managed_boxes)];
-extern mod extra;
+extern crate extra;
struct Triple { a: int, b: int, c: int }
// ignore-fast
// aux-build:moves_based_on_type_lib.rs
-extern mod moves_based_on_type_lib;
+extern crate moves_based_on_type_lib;
use moves_based_on_type_lib::f;
pub fn main() {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod extra;
+extern crate extra;
fn grow(v: &mut ~[int]) {
v.push(1);
// ignore-fast
// ignore-android (FIXME #11419)
-extern mod native;
+extern crate native;
static mut set: bool = false;
// aux-build:nested_item.rs
// ignore-fast
-extern mod nested_item;
+extern crate nested_item;
pub fn main() {
assert_eq!(2, nested_item::foo::<()>());
// ignore-fast
// aux-build:newtype_struct_xc.rs
-extern mod newtype_struct_xc;
+extern crate newtype_struct_xc;
use newtype_struct_xc::Au;
fn f() -> Au {
// ignore-fast
// aux-build:newtype_struct_xc.rs
-extern mod newtype_struct_xc;
+extern crate newtype_struct_xc;
pub fn main() {
let _ = newtype_struct_xc::Au(2);
// This tests that crates which link to std can also be linked to crates with
// #[no_std] that have no lang items.
-extern mod no_std_crate;
+extern crate no_std_crate;
pub fn main() {
no_std_crate::foo();
#[no_std];
-extern mod no_std_crate;
+extern crate no_std_crate;
// This is an unfortunate thing to have to do on linux :(
#[cfg(target_os = "linux")]
#[feature(managed_boxes)];
-extern mod collections;
+extern crate collections;
use collections::list::{List, Cons, Nil, head, is_empty};
// ignore-fast
#[feature(once_fns)];
-extern mod sync;
+extern crate sync;
use sync::Arc;
fn foo(blk: proc()) {
// ignore-fast
#[feature(once_fns)];
-extern mod sync;
+extern crate sync;
use sync::Arc;
fn foo(blk: once ||) {
// ignore-fast
// aux-build:packed.rs
-extern mod packed;
+extern crate packed;
use std::mem;
#[feature(phase)];
#[phase(syntax, link)]
-extern mod macro_crate_test;
+extern crate macro_crate_test;
fn main() {
assert_eq!(1, make_a_1!());
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod arena;
+extern crate arena;
use arena::Arena;
pub fn main() {
// This checks that preemption works.
// note: halfway done porting to modern rust
-extern mod extra;
+extern crate extra;
use std::comm;
use extra::comm;
// ignore-fast
// aux-build:priv-impl-prim-ty.rs
-extern mod bar = "priv-impl-prim-ty";
+extern crate bar = "priv-impl-prim-ty";
pub fn main() {
bar::frob(1i);
// ignore-fast
// aux-build:privacy_reexport.rs
-extern mod privacy_reexport;
+extern crate privacy_reexport;
pub fn main() {
privacy_reexport::bar::frob();
// aux-build:pub_use_xcrate1.rs
// aux-build:pub_use_xcrate2.rs
-extern mod pub_use_xcrate2;
+extern crate pub_use_xcrate2;
use pub_use_xcrate2::Foo;
#[allow(unused_imports)];
-extern mod pub_use_mods_xcrate;
+extern crate pub_use_mods_xcrate;
use pub_use_mods_xcrate::a::c;
pub fn main(){}
// except according to those terms.
// aux-build:reexport-should-still-link.rs
-// ignore-fast check-fast doesn't like extern mod
+// ignore-fast check-fast doesn't like extern crate
-extern mod foo = "reexport-should-still-link";
+extern crate foo = "reexport-should-still-link";
pub fn main() {
foo::bar();
// ignore-fast
// aux-build:reexported_static_methods.rs
-extern mod reexported_static_methods;
+extern crate reexported_static_methods;
use reexported_static_methods::Foo;
use reexported_static_methods::Baz;
// This test verifies that temporary lifetime is correctly computed
// for static objects in enclosing scopes.
-extern mod extra;
+extern crate extra;
use std::cmp::Eq;
fn f<T:Eq>(o: &mut Option<T>) {
// - Multiple lifetime parameters
// - Arenas
-extern mod arena;
+extern crate arena;
use arena::Arena;
use std::hashmap::HashMap;
// because it needs TempDir, which is in extra
// ignore-fast
-extern mod extra;
+extern crate extra;
use extra::tempfile::TempDir;
use std::os;
// except according to those terms.
// ignore-test linked failure
-extern mod extra;
+extern crate extra;
use std::comm;
use std::task;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod collections;
+extern crate collections;
use std::clone::{Clone, DeepClone};
use std::cmp::{TotalEq, Ord, TotalOrd, Equiv};
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod extra;
+extern crate extra;
use std::task;
// Issue #2040
-use std::ptr;
-
pub fn main() {
let foo = 1;
- assert_eq!(ptr::to_unsafe_ptr(&foo), ptr::to_unsafe_ptr(&foo));
+ assert_eq!(&foo as *int, &foo as *int);
}
// ignore-fast
-extern mod extra;
+extern crate extra;
use extra::tempfile;
use std::io::File;
// ignore-fast
// aux-build:static_fn_inline_xc_aux.rs
-extern mod mycore = "static_fn_inline_xc_aux";
+extern crate mycore = "static_fn_inline_xc_aux";
use mycore::num;
// aux-build:static_fn_trait_xc_aux.rs
// ignore-fast
-extern mod mycore = "static_fn_trait_xc_aux";
+extern crate mycore = "static_fn_trait_xc_aux";
use mycore::num;
// ignore-fast
// aux-build:static-function-pointer-aux.rs
-extern mod aux = "static-function-pointer-aux";
+extern crate aux = "static-function-pointer-aux";
fn f(x: int) -> int { x }
// ignore-fast
// aux-build:static-methods-crate.rs
-extern mod static_methods_crate;
+extern crate static_methods_crate;
use static_methods_crate::read;
// ignore-fast
// aux-build:static_mut_xc.rs
-extern mod static_mut_xc;
+extern crate static_mut_xc;
unsafe fn static_bound(_: &'static int) {}
-extern mod extra;
+extern crate extra;
fn test1() {
let mut s: ~str = ~"hello";
-extern mod extra;
+extern crate extra;
pub fn main() {
let a: ~str = ~"this \
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod extra;
+extern crate extra;
pub fn main() {
// Make sure we properly handle repeated self-appends.
// ignore-fast
// aux-build:struct_destructuring_cross_crate.rs
-extern mod struct_destructuring_cross_crate;
+extern crate struct_destructuring_cross_crate;
pub fn main() {
let x = struct_destructuring_cross_crate::S { x: 1, y: 2 };
// ignore-fast - check-fast doesn't understand aux-build
// aux-build:struct_variant_xc_aux.rs
-extern mod struct_variant_xc_aux;
+extern crate struct_variant_xc_aux;
use struct_variant_xc_aux::Variant;
fn do_swap(test: &mut TestDescAndFn) {
unsafe {
- ptr::swap_ptr(test, test);
+ ptr::swap(test, test);
}
}
// ignore-fast
-extern mod extra;
+extern crate extra;
use std::task;
// ignore-fast
-extern mod extra;
+extern crate extra;
use std::task;
// ignore-fast
-extern mod extra;
+extern crate extra;
use std::task;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod extra;
+extern crate extra;
use std::task;
// ignore-fast
-extern mod extra;
+extern crate extra;
use std::task;
// ignore-fast
-extern mod extra;
+extern crate extra;
use std::task;
// This test is specifically about spawning temporary closures.
-extern mod extra;
+extern crate extra;
use std::task;
// ignore-fast
-extern mod extra;
+extern crate extra;
use std::task;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod extra;
+extern crate extra;
pub fn main() { test00(); }
#[allow(dead_assignment)];
-extern mod extra;
+extern crate extra;
use std::task;
// ignore-fast
-extern mod extra;
+extern crate extra;
use std::task;
// except according to those terms.
-extern mod extra;
+extern crate extra;
// rustboot can't transmit nils across channels because they don't have
// any size, but rustc currently can because they do have size. Whether
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod extra;
+extern crate extra;
use std::task;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use std::ptr;
use std::task;
pub fn main() {
let (p, ch) = Chan::<uint>::new();
let x = ~1;
- let x_in_parent = ptr::to_unsafe_ptr(&(*x)) as uint;
+ let x_in_parent = &(*x) as *int as uint;
task::spawn(proc() {
- let x_in_child = ptr::to_unsafe_ptr(&(*x)) as uint;
+ let x_in_child = &(*x) as *int as uint;
ch.send(x_in_child);
});
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-// ignore-fast check-fast doesn't like 'extern mod'
+// ignore-fast check-fast doesn't like 'extern crate'
// ignore-win32 TempDir may cause IoError on windows: #10463
// These tests are here to exercise the functionality of the `tempfile` module.
// they're in a different location than before. Hence, these tests are all run
// serially here.
-extern mod extra;
+extern crate extra;
use extra::tempfile::TempDir;
use std::io::fs;
// Issue #787
// Don't try to clean up uninitialized locals
-extern mod extra;
+extern crate extra;
use std::task;
// compile-flags: --test --cfg ignorecfg
// ignore-fast
-extern mod extra;
+extern crate extra;
#[test]
#[ignore(cfg(ignorecfg))]
// ignore-fast
// ignore-win32 #10872
-extern mod extra;
+extern crate extra;
// Building as a test runner means that a synthetic main will be run,
// not ours
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod extra;
+extern crate extra;
use std::task;
// ignore-fast
-extern mod sync;
+extern crate sync;
use sync::Arc;
use std::task;
// aux-build:trait_default_method_xc_aux_2.rs
-extern mod aux = "trait_default_method_xc_aux";
-extern mod aux2 = "trait_default_method_xc_aux_2";
+extern crate aux = "trait_default_method_xc_aux";
+extern crate aux2 = "trait_default_method_xc_aux_2";
use aux::A;
use aux2::{a_struct, welp};
// ignore-fast
// aux-build:trait_default_method_xc_aux.rs
-extern mod aux = "trait_default_method_xc_aux";
+extern crate aux = "trait_default_method_xc_aux";
use aux::{A, TestEquality, Something};
use aux::B;
// ignore-fast
// aux-build:trait_inheritance_auto_xc_2_aux.rs
-extern mod aux = "trait_inheritance_auto_xc_2_aux";
+extern crate aux = "trait_inheritance_auto_xc_2_aux";
// aux defines impls of Foo, Bar and Baz for A
use aux::{Foo, Bar, Baz, A};
// ignore-fast
// aux-build:trait_inheritance_auto_xc_aux.rs
-extern mod aux = "trait_inheritance_auto_xc_aux";
+extern crate aux = "trait_inheritance_auto_xc_aux";
use aux::{Foo, Bar, Baz, Quux};
// ignore-fast
// aux-build:trait_inheritance_cross_trait_call_xc_aux.rs
-extern mod aux = "trait_inheritance_cross_trait_call_xc_aux";
+extern crate aux = "trait_inheritance_cross_trait_call_xc_aux";
use aux::Foo;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod extra;
+extern crate extra;
use std::cmp::{Eq, Ord};
use std::num::NumCast;
// A more complex example of numeric extensions
-extern mod extra;
+extern crate extra;
use std::cmp::{Eq, Ord};
// ignore-fast - check-fast doesn't understand aux-build
// aux-build:trait_inheritance_overloading_xc.rs
-extern mod trait_inheritance_overloading_xc;
+extern crate trait_inheritance_overloading_xc;
use trait_inheritance_overloading_xc::{MyNum, MyInt};
fn f<T:MyNum>(x: T, y: T) -> (T, T, T) {
// ignore-test FIXME: #3907
// aux-build:trait_typedef_cc.rs
-extern mod trait_typedef_cc;
+extern crate trait_typedef_cc;
type Foo = trait_typedef_cc::Foo;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod std;
+extern crate std;
use std::mem::size_of;
struct t {a: u8, b: i8}
// aux-build:typeid-intrinsic.rs
// aux-build:typeid-intrinsic2.rs
-extern mod other1 = "typeid-intrinsic";
-extern mod other2 = "typeid-intrinsic2";
+extern crate other1 = "typeid-intrinsic";
+extern crate other2 = "typeid-intrinsic2";
use std::unstable::intrinsics;
use std::unstable::intrinsics::TypeId;
// Tests that the tail expr in null() has its type
// unified with the type *T, and so the type variable
// in that type gets resolved.
-extern mod extra;
+extern crate extra;
use std::cast;
#[feature(managed_boxes)];
use std::cell::RefCell;
-use std::ptr;
enum maybe_pointy {
none,
}
fn make_uniq_closure<A:Send>(a: A) -> proc() -> uint {
- let result: proc() -> uint = proc() ptr::to_unsafe_ptr(&a) as uint;
+ let result: proc() -> uint = proc() &a as *A as uint;
result
}
#[feature(managed_boxes)];
-extern mod extra;
+extern crate extra;
use std::task;
// ignore-fast
-extern mod extra;
+extern crate extra;
use std::task;
#[feature(managed_boxes)];
-extern mod extra;
+extern crate extra;
use std::task;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod extra;
+extern crate extra;
use std::task;
// except according to those terms.
// Issue #1706
-extern mod stdlib = "extra";
+extern crate stdlib = "extra";
pub fn main() {}
#[allow(unused_imports)];
#[no_std];
-extern mod std;
-extern mod zed = "std";
-extern mod bar = "std#0.10-pre";
+extern crate std;
+extern crate zed = "std";
+extern crate bar = "std#0.10-pre";
use std::str;
// aux-build:inline_dtor.rs
// ignore-fast
-extern mod inline_dtor;
+extern crate inline_dtor;
pub fn main() {
let _x = inline_dtor::Foo;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod extra;
+extern crate extra;
use std::str;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-extern mod extra;
+extern crate extra;
fn test_heap_to_heap() {
// a spills onto the heap
// ignore-fast check-fast doesn't like aux-build
// aux-build:xcrate_address_insignificant.rs
-extern mod foo = "xcrate_address_insignificant";
+extern crate foo = "xcrate_address_insignificant";
pub fn main() {
assert_eq!(foo::foo::<f64>(), foo::bar());
// ignore-fast
// aux-build:xcrate_static_addresses.rs
-extern mod xcrate_static_addresses;
+extern crate xcrate_static_addresses;
use other = xcrate_static_addresses;
// ignore-fast
// aux-build:xcrate-trait-lifetime-param.rs
-extern mod other = "xcrate-trait-lifetime-param";
+extern crate other = "xcrate-trait-lifetime-param";
struct Reader<'a> {
b : &'a [u8]
// aux-build:xcrate_unit_struct.rs
// ignore-fast
-extern mod xcrate_unit_struct;
+extern crate xcrate_unit_struct;
static s1: xcrate_unit_struct::Struct = xcrate_unit_struct::Struct;
static s2: xcrate_unit_struct::Unit = xcrate_unit_struct::Unit;