Auto merge of #22367 - Manishearth:rollup, r=steveklabnik

(still testing locally)
This commit is contained in:
bors 2015-02-16 00:46:43 +00:00
commit c5db290bf6
122 changed files with 1013 additions and 518 deletions

View File

@ -5,16 +5,10 @@ documentation.
## Quick Start
1. Download a [binary installer][installer] for your platform.
2. Read [The Rust Programming Language][trpl].
3. Enjoy!
Read ["Installing Rust"][install] from [The Book][trpl].
> ***Note:*** Windows users can read the detailed
> [using Rust on Windows][win-wiki] notes on the wiki.
[installer]: http://www.rust-lang.org/install.html
[install]: http://doc.rust-lang.org/book/installing-rust.html
[trpl]: http://doc.rust-lang.org/book/index.html
[win-wiki]: https://github.com/rust-lang/rust/wiki/Using-Rust-on-Windows
## Building from Source
@ -52,8 +46,6 @@ documentation.
When complete, `make install` will place several programs into
`/usr/local/bin`: `rustc`, the Rust compiler, and `rustdoc`, the
API-documentation tool.
3. Read [The Rust Programming Language][trpl].
4. Enjoy!
### Building on Windows
@ -81,7 +73,6 @@ $ pacman -S base-devel
[repo]: https://github.com/rust-lang/rust
[tarball]: https://static.rust-lang.org/dist/rustc-nightly-src.tar.gz
[trpl]: http://doc.rust-lang.org/book/index.html
## Notes

View File

@ -109,8 +109,6 @@ distcheck-tar-src: dist-tar-src
# Unix binary installer tarballs
######################################################################
NON_INSTALLED_PREFIXES=COPYRIGHT,LICENSE-APACHE,LICENSE-MIT,README.md,version
define DEF_INSTALLER
$$(eval $$(call DEF_PREPARE,dir-$(1)))
@ -124,19 +122,23 @@ dist-install-dir-$(1): PREPARE_LIB_CMD=$(DEFAULT_PREPARE_LIB_CMD)
dist-install-dir-$(1): PREPARE_MAN_CMD=$(DEFAULT_PREPARE_MAN_CMD)
dist-install-dir-$(1): PREPARE_CLEAN=true
dist-install-dir-$(1): prepare-base-dir-$(1) docs compiler-docs
$$(Q)$$(PREPARE_MAN_CMD) $$(S)COPYRIGHT $$(PREPARE_DEST_DIR)
$$(Q)$$(PREPARE_MAN_CMD) $$(S)LICENSE-APACHE $$(PREPARE_DEST_DIR)
$$(Q)$$(PREPARE_MAN_CMD) $$(S)LICENSE-MIT $$(PREPARE_DEST_DIR)
$$(Q)$$(PREPARE_MAN_CMD) $$(S)README.md $$(PREPARE_DEST_DIR)
$$(Q)mkdir -p $$(PREPARE_DEST_DIR)/share/doc/rust
$$(Q)$$(PREPARE_MAN_CMD) $$(S)COPYRIGHT $$(PREPARE_DEST_DIR)/share/doc/rust
$$(Q)$$(PREPARE_MAN_CMD) $$(S)LICENSE-APACHE $$(PREPARE_DEST_DIR)/share/doc/rust
$$(Q)$$(PREPARE_MAN_CMD) $$(S)LICENSE-MIT $$(PREPARE_DEST_DIR)/share/doc/rust
$$(Q)$$(PREPARE_MAN_CMD) $$(S)README.md $$(PREPARE_DEST_DIR)/share/doc/rust
# This tiny morsel of metadata is used by rust-packaging
$$(Q)echo "$(CFG_VERSION)" > $$(PREPARE_DEST_DIR)/version
dist/$$(PKG_NAME)-$(1).tar.gz: dist-install-dir-$(1)
prepare-overlay-$(1):
$$(Q)rm -Rf tmp/dist/$$(PKG_NAME)-$(1)-overlay
$$(Q)mkdir -p tmp/dist/$$(PKG_NAME)-$(1)-overlay
$$(Q)cp $$(S)COPYRIGHT tmp/dist/$$(PKG_NAME)-$(1)-overlay/
$$(Q)cp $$(S)LICENSE-APACHE tmp/dist/$$(PKG_NAME)-$(1)-overlay/
$$(Q)cp $$(S)LICENSE-MIT tmp/dist/$$(PKG_NAME)-$(1)-overlay/
$$(Q)cp $$(S)README.md tmp/dist/$$(PKG_NAME)-$(1)-overlay/
# This tiny morsel of metadata is used by rust-packaging
$$(Q)echo "$(CFG_VERSION)" > tmp/dist/$$(PKG_NAME)-$(1)-overlay/version
dist/$$(PKG_NAME)-$(1).tar.gz: dist-install-dir-$(1) prepare-overlay-$(1)
@$(call E, build: $$@)
# Copy essential gcc components into installer
ifdef CFG_WINDOWSY_$(1)
@ -146,13 +148,12 @@ ifdef CFG_WINDOWSY_$(1)
endif
$$(Q)$$(S)src/rust-installer/gen-installer.sh \
--product-name=Rust \
--verify-bin=rustc \
--rel-manifest-dir=rustlib \
--success-message=Rust-is-ready-to-roll. \
--image-dir=tmp/dist/$$(PKG_NAME)-$(1)-image \
--work-dir=tmp/dist \
--output-dir=dist \
--non-installed-prefixes=$$(NON_INSTALLED_PREFIXES) \
--non-installed-overlay=tmp/dist/$$(PKG_NAME)-$(1)-overlay \
--package-name=$$(PKG_NAME)-$(1) \
--component-name=rustc \
--legacy-manifest-dirs=rustlib,cargo

View File

@ -27,7 +27,7 @@
######################################################################
DOCS := index intro tutorial complement-bugreport \
complement-lang-faq complement-design-faq complement-project-faq \
rustdoc reference
rustdoc reference grammar
# Legacy guides, preserved for a while to reduce the number of 404s
DOCS += guide-crates guide-error-handling guide-ffi guide-macros guide \

View File

@ -18,7 +18,7 @@ CFG_RELEASE_NUM=1.0.0
# An optional number to put after the label, e.g. '.2' -> '-beta.2'
# NB Make sure it starts with a dot to conform to semver pre-release
# versions (section 9)
CFG_PRERELEASE_VERSION=.1
CFG_PRERELEASE_VERSION=.2
CFG_FILENAME_EXTRA=4e7c5e5c
@ -30,8 +30,8 @@ CFG_PACKAGE_VERS=$(CFG_RELEASE_NUM)
CFG_DISABLE_UNSTABLE_FEATURES=1
endif
ifeq ($(CFG_RELEASE_CHANNEL),beta)
CFG_RELEASE=$(CFG_RELEASE_NUM)-beta$(CFG_PRERELEASE_VERSION)
CFG_PACKAGE_VERS=$(CFG_RELEASE_NUM)-beta$(CFG_PRERELEASE_VERSION)
CFG_RELEASE=$(CFG_RELEASE_NUM)-alpha$(CFG_PRERELEASE_VERSION)
CFG_PACKAGE_VERS=$(CFG_RELEASE_NUM)-alpha$(CFG_PRERELEASE_VERSION)
CFG_DISABLE_UNSTABLE_FEATURES=1
endif
ifeq ($(CFG_RELEASE_CHANNEL),nightly)
@ -61,13 +61,16 @@ SPACE :=
SPACE +=
ifneq ($(CFG_GIT),)
ifneq ($(wildcard $(subst $(SPACE),\$(SPACE),$(CFG_GIT_DIR))),)
CFG_VER_DATE = $(shell git --git-dir='$(CFG_GIT_DIR)' log -1 --pretty=format:'%ci')
CFG_VER_DATE = $(shell git --git-dir='$(CFG_GIT_DIR)' log -1 --date=short --pretty=format:'%cd')
CFG_VER_HASH = $(shell git --git-dir='$(CFG_GIT_DIR)' rev-parse HEAD)
CFG_SHORT_VER_HASH = $(shell git --git-dir='$(CFG_GIT_DIR)' rev-parse --short=9 HEAD)
CFG_VERSION += ($(CFG_SHORT_VER_HASH) $(CFG_VER_DATE))
endif
endif
CFG_BUILD_DATE = $(shell date +%F)
CFG_VERSION += (built $(CFG_BUILD_DATE))
# Windows exe's need numeric versions - don't use anything but
# numbers and dots here
CFG_VERSION_WIN = $(CFG_RELEASE_NUM)
@ -317,6 +320,7 @@ endif
ifdef CFG_VER_HASH
export CFG_VER_HASH
endif
export CFG_BUILD_DATE
export CFG_VERSION
export CFG_VERSION_WIN
export CFG_RELEASE

View File

@ -16,7 +16,7 @@
#![feature(io)]
#![feature(path)]
#![feature(rustc_private)]
#![feature(slicing_syntax, unboxed_closures)]
#![feature(unboxed_closures)]
#![feature(std_misc)]
#![feature(test)]
#![feature(unicode)]

View File

@ -56,8 +56,6 @@ $ RUST_BACKTRACE=1 rustc ...
# I submitted a bug, but nobody has commented on it!
This is sad, but does happen sometimes, since we're short-staffed. If you
submit a bug and you haven't received a comment on it within 3 business days,
it's entirely reasonable to either ask on the #rust IRC channel,
or post on the [rust-dev mailing list](https://mail.mozilla.org/listinfo/rust-dev)
to ask what the status of the bug is.
This is sad, but does happen sometimes, since we're short-staffed. If you submit a
bug and you haven't received a comment on it within 3 business days, it's entirely
reasonable to ask about the status of the bug in #rust on irc.mozilla.org.

View File

@ -1,6 +1,4 @@
# **This is a work in progress**
% The Rust Grammar
% Grammar
# Introduction
@ -570,7 +568,7 @@ binop_expr : expr binop expr ;
The precedence of Rust binary operators is ordered as follows, going from
strong to weak:
```
```text
* / %
as
+ -

View File

@ -224,7 +224,7 @@ segfault when we allocate more memory?
The answer is that in the C++ version, `x` is a *reference* to the memory
location where the first element of the array is stored. But in Ruby, `x` is a
standalone value, not connected to the underyling array at all. Let's dig into
standalone value, not connected to the underlying array at all. Let's dig into
the details for a moment. Your program has access to memory, provided to it by
the operating system. Each location in memory has an address. So when we make
our vector, `v`, it's stored in a memory location somewhere:

View File

@ -5,9 +5,7 @@
This document is the primary reference for the Rust programming language. It
provides three kinds of material:
- Chapters that formally define the language grammar and, for each
construct, informally describe its semantics and give examples of its
use.
- Chapters that informally describe each language construct and their use.
- Chapters that informally describe the memory model, concurrency model,
runtime services, linkage model and debugging facilities.
- Appendix chapters providing rationale and references to languages that
@ -23,8 +21,11 @@ separately by extracting documentation attributes from their source code. Many
of the features that one might expect to be language features are library
features in Rust, so what you're looking for may be there, not here.
You may also be interested in the [grammar].
[book]: book/index.html
[standard]: std/index.html
[grammar]: grammar.html
# Notation
@ -2377,21 +2378,33 @@ considered off, and using the features will result in a compiler error.
The currently implemented features of the reference compiler are:
* `advanced_slice_patterns` - see the [match expressions](#match-expressions)
section for discussion; the exact semantics of
slice patterns are subject to change.
* `asm` - The `asm!` macro provides a means for inline assembly. This is often
useful, but the exact syntax for this feature along with its
semantics are likely to change, so this macro usage must be opted
into.
* `associated_types` - Allows type aliases in traits. Experimental.
* `box_patterns` - Allows `box` patterns, the exact semantics of which
is subject to change.
* `box_syntax` - Allows use of `box` expressions, the exact semantics of which
is subject to change.
* `concat_idents` - Allows use of the `concat_idents` macro, which is in many
ways insufficient for concatenating identifiers, and may be
removed entirely for something more wholesome.
* `default_type_params` - Allows use of default type parameters. The future of
this feature is uncertain.
* `intrinsics` - Allows use of the "rust-intrinsics" ABI. Compiler intrinsics
are inherently unstable and no promise about them is made.
* `int_uint` - Allows the use of the `int` and `uint` types, which are deprecated.
Use `isize` and `usize` instead.
* `lang_items` - Allows use of the `#[lang]` attribute. Like `intrinsics`,
lang items are inherently unstable and no promise about them
is made.
@ -2410,12 +2423,33 @@ The currently implemented features of the reference compiler are:
* `log_syntax` - Allows use of the `log_syntax` macro attribute, which is a
nasty hack that will certainly be removed.
* `main` - Allows use of the `#[main]` attribute, which changes the entry point
into a Rust program. This capabiilty is subject to change.
* `macro_reexport` - Allows macros to be re-exported from one crate after being imported
from another. This feature was originally designed with the sole
use case of the Rust standard library in mind, and is subject to
change.
* `non_ascii_idents` - The compiler supports the use of non-ascii identifiers,
but the implementation is a little rough around the
edges, so this can be seen as an experimental feature
for now until the specification of identifiers is fully
fleshed out.
* `no_std` - Allows the `#![no_std]` crate attribute, which disables the implicit
`extern crate std`. This typically requires use of the unstable APIs
behind the libstd "facade", such as libcore and libcollections. It
may also cause problems when using syntax extensions, including
`#[derive]`.
* `on_unimplemented` - Allows the `#[rustc_on_unimplemented]` attribute, which allows
trait definitions to add specialized notes to error messages
when an implementation was expected but not found.
* `optin_builtin_traits` - Allows the definition of default and negative trait
implementations. Experimental.
* `plugin` - Usage of [compiler plugins][plugin] for custom lints or syntax extensions.
These depend on compiler internals and are subject to change.
@ -2431,8 +2465,15 @@ The currently implemented features of the reference compiler are:
* `simd` - Allows use of the `#[simd]` attribute, which is overly simple and
not the SIMD interface we want to expose in the long term.
* `simd_ffi` - Allows use of SIMD vectors in signatures for foreign functions.
The SIMD interface is subject to change.
* `staged_api` - Allows usage of stability markers and `#![staged_api]` in a crate
* `start` - Allows use of the `#[start]` attribute, which changes the entry point
into a Rust program. This capabiilty, especially the signature for the
annotated function, is subject to change.
* `struct_inherit` - Allows using struct inheritance, which is barely
implemented and will probably be removed. Don't use this.
@ -2460,18 +2501,20 @@ The currently implemented features of the reference compiler are:
which is considered wildly unsafe and will be
obsoleted by language improvements.
* `unsafe_no_drop_flag` - Allows use of the `#[unsafe_no_drop_flag]` attribute,
which removes hidden flag added to a type that
implements the `Drop` trait. The design for the
`Drop` flag is subject to change, and this feature
may be removed in the future.
* `unmarked_api` - Allows use of items within a `#![staged_api]` crate
which have not been marked with a stability marker.
Such items should not be allowed by the compiler to exist,
so if you need this there probably is a compiler bug.
* `associated_types` - Allows type aliases in traits. Experimental.
* `no_std` - Allows the `#![no_std]` crate attribute, which disables the implicit
`extern crate std`. This typically requires use of the unstable APIs
behind the libstd "facade", such as libcore and libcollections. It
may also cause problems when using syntax extensions, including
`#[derive]`.
* `visible_private_types` - Allows public APIs to expose otherwise private
types, e.g. as the return type of a public function.
This capability may be removed in the future.
If a feature is promoted to a language feature, then all existing programs will
start to receive compilation warnings about #[feature] directives which enabled
@ -2591,9 +2634,8 @@ of any reference that points to it.
When a [local variable](#memory-slots) is used as an
[rvalue](#lvalues,-rvalues-and-temporaries) the variable will either be moved
or copied, depending on its type. For types that contain [owning
pointers](#pointer-types) or values that implement the special trait `Drop`,
the variable is moved. All other types are copied.
or copied, depending on its type. All values whose type implements `Copy` are
copied, all others are moved.
### Literal expressions
@ -2701,9 +2743,19 @@ items can bring new names into scopes and declared items are in scope for only
the block itself.
A block will execute each statement sequentially, and then execute the
expression (if given). If the final expression is omitted, the type and return
value of the block are `()`, but if it is provided, the type and return value
of the block are that of the expression itself.
expression (if given). If the block ends in a statement, its value is `()`:
```
let x: () = { println!("Hello."); };
```
If it ends in an expression, its value and type are that of the expression:
```
let x: i32 = { println!("Hello."); 5 };
assert_eq!(5, x);
```
### Method-call expressions
@ -3502,9 +3554,6 @@ elements, respectively, in a parenthesized, comma-separated list.
Because tuple elements don't have a name, they can only be accessed by
pattern-matching.
The members of a tuple are laid out in memory contiguously, in order specified
by the tuple type.
An example of a tuple type and its use:
```

View File

@ -49,8 +49,8 @@ languages.
A *vector* is a dynamic or "growable" array, implemented as the standard
library type [`Vec<T>`](../std/vec/) (we'll talk about what the `<T>` means
later). Vectors are to arrays what `String` is to `&str`. You can create them
with the `vec!` macro:
later). Vectors always allocate their data on the heap. Vectors are to slices
what `String` is to `&str`. You can create them with the `vec!` macro:
```{rust}
let v = vec![1, 2, 3]; // v: Vec<i32>

View File

@ -263,15 +263,12 @@ let four_is_smaller = four <= ten;
let four_equals_ten = four == ten;
```
This may seem rather limiting, particularly equality being invalid; in
many cases however, it's unnecessary. Rust provides the [`match`][match]
keyword, which will be examined in more detail in the next section, which
often allows better and easier branch control than a series of `if`/`else`
statements would. However, for our [game][game] we need the comparisons
to work so we will utilize the `Ordering` `enum` provided by the standard
library which supports such comparisons. It has this form:
This may seem rather limiting, but it's a limitation which we can overcome.
There are two ways: by implementing equality ourselves, or by using the
[`match`][match] keyword. We don't know enough about Rust to implement equality
yet, but we can use the `Ordering` enum from the standard library, which does:
```{rust}
```
enum Ordering {
Less,
Equal,

View File

@ -171,7 +171,7 @@ use std::time::Duration;
fn main() {
let mut data = vec![1u32, 2, 3];
for i in 0 .. 2 {
for i in 0..2 {
Thread::spawn(move || {
data[i] += 1;
});
@ -211,7 +211,7 @@ use std::sync::Mutex;
fn main() {
let mut data = Mutex::new(vec![1u32, 2, 3]);
for i in 0 .. 2 {
for i in 0..2 {
let data = data.lock().unwrap();
Thread::spawn(move || {
data[i] += 1;
@ -262,7 +262,7 @@ use std::time::Duration;
fn main() {
let data = Arc::new(Mutex::new(vec![1u32, 2, 3]));
for i in (0us..2) {
for i in 0us..2 {
let data = data.clone();
Thread::spawn(move || {
let mut data = data.lock().unwrap();
@ -285,7 +285,7 @@ thread more closely:
# use std::time::Duration;
# fn main() {
# let data = Arc::new(Mutex::new(vec![1u32, 2, 3]));
# for i in (0us..2) {
# for i in 0us..2 {
# let data = data.clone();
Thread::spawn(move || {
let mut data = data.lock().unwrap();
@ -323,7 +323,7 @@ fn main() {
let (tx, rx) = mpsc::channel();
for _ in (0..10) {
for _ in 0..10 {
let (data, tx) = (data.clone(), tx.clone());
Thread::spawn(move || {
@ -334,7 +334,7 @@ fn main() {
});
}
for _ in 0 .. 10 {
for _ in 0..10 {
rx.recv();
}
}

View File

@ -20,7 +20,7 @@ you to partition your code within the crate itself.
As an example, let's make a *phrases* crate, which will give us various phrases
in different languages. To keep things simple, we'll stick to "greetings" and
"farewells" as two kinds of phrases, and use English and Japanese (日本語 as
"farewells" as two kinds of phrases, and use English and Japanese (日本語) as
two languages for those phrases to be in. We'll use this module layout:
```text

View File

@ -1,4 +1,4 @@
% Rust Documentation
% Documentation
`rustdoc` is the built-in tool for generating documentation. It integrates
with the compiler to provide accurate hyperlinking between usage of types and
@ -294,3 +294,26 @@ Documentation` on the first line).
Like with a Rust crate, the `--test` argument will run the code
examples to check they compile, and obeys any `--test-args` flags. The
tests are named after the last `#` heading.
# Re-exports
Rustdoc will show the documentation for a publc re-export in both places:
```{rust,ignore}
extern crate foo;
pub use foo::bar;
```
This will create documentation for `bar` both inside the documentation for
the crate `foo`, as well as the documentation for your crate. It will use
the same documentation in both places.
This behavior can be supressed with `no_inline`:
```{rust,ignore}
extern crate foo;
#[doc(no_inline)]
pub use foo::bar;
```

View File

@ -420,7 +420,7 @@ fn main() {
```
Alternatively, you may need to alter global state provided by a foreign
interface. To do this, statics can be declared with `mut` so rust can mutate
interface. To do this, statics can be declared with `mut` so we can mutate
them.
```no_run
@ -436,12 +436,19 @@ extern {
fn main() {
let prompt = CString::from_slice(b"[my-awesome-shell] $");
unsafe { rl_prompt = prompt.as_ptr(); }
// get a line, process it
unsafe { rl_prompt = ptr::null(); }
unsafe {
rl_prompt = prompt.as_ptr();
println!("{:?}", rl_prompt);
rl_prompt = ptr::null();
}
}
```
Note that all interaction with a `static mut` is unsafe, both reading and
writing. Dealing with global mutable state requires a great deal of care.
# Foreign calling conventions
Most foreign code exposes a C ABI, and Rust uses the platform's C calling convention by default when

View File

@ -2,7 +2,7 @@
You've already seen one function so far, the `main` function:
```{rust}
```rust
fn main() {
}
```
@ -12,14 +12,14 @@ This is the simplest possible function declaration. As we mentioned before,
this function takes no arguments, and then some curly braces to indicate the
body. Here's a function named `foo`:
```{rust}
```rust
fn foo() {
}
```
So, what about taking arguments? Here's a function that prints a number:
```{rust}
```rust
fn print_number(x: i32) {
println!("x is: {}", x);
}
@ -27,7 +27,7 @@ fn print_number(x: i32) {
Here's a complete program that uses `print_number`:
```{rust}
```rust
fn main() {
print_number(5);
}
@ -42,7 +42,7 @@ you add a type to the argument name, after a colon.
Here's a complete program that adds two numbers together and prints them:
```{rust}
```rust
fn main() {
print_sum(5, 6);
}
@ -58,9 +58,9 @@ as when you declare it.
Unlike `let`, you _must_ declare the types of function arguments. This does
not work:
```{ignore}
```{rust,ignore}
fn print_sum(x, y) {
println!("x is: {}", x + y);
println!("sum is: {}", x + y);
}
```
@ -79,7 +79,7 @@ sweet spot between full inference and no inference.
What about returning a value? Here's a function that adds one to an integer:
```{rust}
```rust
fn add_one(x: i32) -> i32 {
x + 1
}
@ -90,7 +90,7 @@ Rust functions return exactly one value, and you declare the type after an
You'll note the lack of a semicolon here. If we added it in:
```{ignore}
```{rust,ignore}
fn add_one(x: i32) -> i32 {
x + 1;
}
@ -123,7 +123,7 @@ semicolon in a return position would cause a bug.
But what about early returns? Rust does have a keyword for that, `return`:
```{rust}
```rust
fn foo(x: i32) -> i32 {
if x < 5 { return x; }
@ -134,7 +134,7 @@ fn foo(x: i32) -> i32 {
Using a `return` as the last line of a function works, but is considered poor
style:
```{rust}
```rust
fn foo(x: i32) -> i32 {
if x < 5 { return x; }
@ -160,5 +160,34 @@ fn foo(x: i32) -> i32 {
Because `if` is an expression, and it's the only expression in this function,
the value will be the result of the `if`.
There are some additional ways to define functions, but they involve features
that we haven't learned about yet, so let's just leave it at that for now.
## Diverging functions
Rust has some special syntax for 'diverging functions', which are functions that
do not return:
```
fn diverges() -> ! {
panic!("This function never returns!");
}
```
`panic!` is a macro, similar to `println!()` that we've already seen. Unlike
`println!()`, `panic!()` causes the current thread of execution to crash with
the given message.
Because this function will cause a crash, it will never return, and so it has
the type '`!`', which is read "diverges." A diverging function can be used
as any type:
```should_fail
# fn diverges() -> ! {
# panic!("This function never returns!");
# }
let x: i32 = diverges();
let x: String = diverges();
```
We don't have a good use for diverging functions yet, because they're used in
conjunction with other Rust features. But when you see `-> !` later, you'll
know what it's called.

View File

@ -24,11 +24,11 @@ installer](https://static.rust-lang.org/dist/rust-nightly-x86_64-pc-windows-gnu.
and run it.
If you decide you don't want Rust anymore, we'll be a bit sad, but that's okay.
Not every programming language is great for everyone. Just pass an argument to
the script:
Not every programming language is great for everyone. Just run the uninstall
script:
```bash
$ curl -s https://static.rust-lang.org/rustup.sh | sudo sh -s -- --uninstall
$ sudo /usr/local/lib/rustlib/uninstall.sh
```
If you used the Windows installer, just re-run the `.exe` and it will give you

View File

@ -132,7 +132,16 @@ let one_to_one_hundred = (1..101i32).collect::<Vec<i32>>();
```
If you remember, the `::<>` syntax allows us to give a type hint,
and so we tell it that we want a vector of integers.
and so we tell it that we want a vector of integers. You don't always
need to use the whole type, though. Using a `_` will let you provide
a partial hint:
```rust
let one_to_one_hundred = range(1, 101).collect::<Vec<_>>();
```
This says "Collect into a `Vec<T>`, please, but infer what the `T` is for me."
`_` is sometimes called a "type placeholder" for this reason.
`collect()` is the most common consumer, but there are others too. `find()`
is one:

View File

@ -91,7 +91,7 @@ and only moving to this:
fn foo(s: String) {
```
If you have good reason. It's not polite to hold on to ownership you don't
if you have good reason. It's not polite to hold on to ownership you don't
need, and it can make your lifetimes more complex.
## Generic functions
@ -169,8 +169,8 @@ é
Note that `l` has the type `&str` here, since a single grapheme can consist of
multiple codepoints, so a `char` wouldn't be appropriate.
This will print out each visible character in turn, as you'd expect: first "u͔", then
"n͈̰̎", etc. If you wanted each individual codepoint of each grapheme, you can use `.chars()`:
This will print out each visible character in turn, as you'd expect: first `u͔`, then
`n͈̰̎`, etc. If you wanted each individual codepoint of each grapheme, you can use `.chars()`:
```
let s = "u͔n͈̰̎i̙̮͚̦c͚̉o̼̩̰͗d͔̆̓ͥé";

View File

@ -366,7 +366,7 @@ def emit_conversions_module(f, lowerupper, upperlower):
}
}
fn bsearch_case_table(c: char, table: &'static [(char, char)]) -> Option<uint> {
fn bsearch_case_table(c: char, table: &'static [(char, char)]) -> Option<usize> {
match table.binary_search(|&(key, _)| {
if c == key { Equal }
else if key < c { Less }
@ -449,13 +449,13 @@ def emit_charwidth_module(f, width_table):
""")
f.write("""
pub fn width(c: char, is_cjk: bool) -> Option<uint> {
match c as uint {
pub fn width(c: char, is_cjk: bool) -> Option<usize> {
match c as usize {
_c @ 0 => Some(0), // null is zero width
cu if cu < 0x20 => None, // control sequences have no width
cu if cu < 0x7F => Some(1), // ASCII
cu if cu < 0xA0 => None, // more control sequences
_ => Some(bsearch_range_value_table(c, is_cjk, charwidth_table) as uint)
_ => Some(bsearch_range_value_table(c, is_cjk, charwidth_table) as usize)
}
}
@ -610,7 +610,7 @@ if __name__ == "__main__":
rf.write("""
/// The version of [Unicode](http://www.unicode.org/)
/// that the `UnicodeChar` and `UnicodeStrPrelude` traits are based on.
pub const UNICODE_VERSION: (uint, uint, uint) = (%s, %s, %s);
pub const UNICODE_VERSION: (u64, u64, u64) = (%s, %s, %s);
""" % unicode_version)
(canon_decomp, compat_decomp, gencats, combines,
lowerupper, upperlower) = load_unicode_data("UnicodeData.txt")

View File

@ -560,7 +560,12 @@ impl<T> DList<T> {
/// Splits the list into two at the given index. Returns everything after the given index,
/// including the index.
///
/// # Panics
///
/// Panics if `at > len`.
///
/// This operation should compute in O(n) time.
///
/// # Examples
///
/// ```
@ -580,9 +585,11 @@ impl<T> DList<T> {
#[stable(feature = "rust1", since = "1.0.0")]
pub fn split_off(&mut self, at: usize) -> DList<T> {
let len = self.len();
assert!(at < len, "Cannot split off at a nonexistent index");
assert!(at <= len, "Cannot split off at a nonexistent index");
if at == 0 {
return mem::replace(self, DList::new());
} else if at == len {
return DList::new();
}
// Below, we iterate towards the `i-1`th node, either from the start or the end,
@ -1116,6 +1123,18 @@ mod tests {
}
}
// no-op on the last index
{
let mut m = DList::new();
m.push_back(1);
let p = m.split_off(1);
assert_eq!(m.len(), 1);
assert_eq!(p.len(), 0);
assert_eq!(m.back(), Some(&1));
assert_eq!(m.front(), Some(&1));
}
}
#[test]

View File

@ -27,7 +27,6 @@
#![feature(box_patterns)]
#![feature(core)]
#![feature(hash)]
#![feature(slicing_syntax)]
#![feature(staged_api)]
#![feature(unboxed_closures)]
#![feature(unicode)]

View File

@ -52,7 +52,6 @@
//! interval `[a, b)`:
//!
//! ```rust
//! #![feature(slicing_syntax)]
//! fn main() {
//! let numbers = [0, 1, 2];
//! let last_numbers = &numbers[1..3];

View File

@ -21,9 +21,9 @@
//!
//! Each method takes an `Ordering` which represents the strength of
//! the memory barrier for that operation. These orderings are the
//! same as [C++11 atomic orderings][1].
//! same as [LLVM atomic orderings][1].
//!
//! [1]: http://gcc.gnu.org/wiki/Atomic/GCCMM/AtomicSync
//! [1]: http://llvm.org/docs/LangRef.html#memory-model-for-concurrent-operations
//!
//! Atomic variables are safe to share between threads (they implement `Sync`)
//! but they do not themselves provide the mechanism for sharing. The most

View File

@ -649,7 +649,8 @@ impl<'b, T> DerefMut for RefMut<'b, T> {
///
/// **NOTE:** `UnsafeCell<T>`'s fields are public to allow static initializers. It is not
/// recommended to access its fields directly, `get` should be used instead.
#[lang="unsafe"]
#[cfg_attr(stage0, lang="unsafe")] // NOTE: remove after next snapshot
#[cfg_attr(not(stage0), lang="unsafe_cell")]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct UnsafeCell<T> {
/// Wrapped value

View File

@ -119,16 +119,16 @@ pub fn from_u32(i: u32) -> Option<char> {
/// ```
#[inline]
#[unstable(feature = "core", reason = "pending integer conventions")]
pub fn from_digit(num: uint, radix: uint) -> Option<char> {
pub fn from_digit(num: u32, radix: u32) -> Option<char> {
if radix > 36 {
panic!("from_digit: radix is too high (maximum 36)");
}
if num < radix {
unsafe {
if num < 10 {
Some(transmute(('0' as uint + num) as u32))
Some(transmute('0' as u32 + num))
} else {
Some(transmute(('a' as uint + num - 10) as u32))
Some(transmute('a' as u32 + num - 10))
}
}
} else {
@ -164,7 +164,7 @@ pub trait CharExt {
/// ```
#[unstable(feature = "core",
reason = "pending integer conventions")]
fn is_digit(self, radix: uint) -> bool;
fn is_digit(self, radix: u32) -> bool;
/// Converts a character to the corresponding digit.
///
@ -189,7 +189,7 @@ pub trait CharExt {
/// ```
#[unstable(feature = "core",
reason = "pending integer conventions")]
fn to_digit(self, radix: uint) -> Option<uint>;
fn to_digit(self, radix: u32) -> Option<u32>;
/// Returns an iterator that yields the hexadecimal Unicode escape of a character, as `char`s.
///
@ -275,7 +275,7 @@ pub trait CharExt {
/// assert_eq!(n, 2);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
fn len_utf8(self) -> uint;
fn len_utf8(self) -> usize;
/// Returns the number of bytes this character would need if encoded in UTF-16.
///
@ -287,7 +287,7 @@ pub trait CharExt {
/// assert_eq!(n, 1);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
fn len_utf16(self) -> uint;
fn len_utf16(self) -> usize;
/// Encodes this character as UTF-8 into the provided byte buffer, and then returns the number
/// of bytes written.
@ -317,7 +317,7 @@ pub trait CharExt {
/// assert_eq!(result, None);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
fn encode_utf8(self, dst: &mut [u8]) -> Option<uint>;
fn encode_utf8(self, dst: &mut [u8]) -> Option<usize>;
/// Encodes this character as UTF-16 into the provided `u16` buffer, and then returns the
/// number of `u16`s written.
@ -347,27 +347,27 @@ pub trait CharExt {
/// assert_eq!(result, None);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
fn encode_utf16(self, dst: &mut [u16]) -> Option<uint>;
fn encode_utf16(self, dst: &mut [u16]) -> Option<usize>;
}
#[stable(feature = "rust1", since = "1.0.0")]
impl CharExt for char {
#[unstable(feature = "core",
reason = "pending integer conventions")]
fn is_digit(self, radix: uint) -> bool {
fn is_digit(self, radix: u32) -> bool {
self.to_digit(radix).is_some()
}
#[unstable(feature = "core",
reason = "pending integer conventions")]
fn to_digit(self, radix: uint) -> Option<uint> {
fn to_digit(self, radix: u32) -> Option<u32> {
if radix > 36 {
panic!("to_digit: radix is too high (maximum 36)");
}
let val = match self {
'0' ... '9' => self as uint - ('0' as uint),
'a' ... 'z' => self as uint + 10 - ('a' as uint),
'A' ... 'Z' => self as uint + 10 - ('A' as uint),
'0' ... '9' => self as u32 - '0' as u32,
'a' ... 'z' => self as u32 - 'a' as u32 + 10,
'A' ... 'Z' => self as u32 - 'A' as u32 + 10,
_ => return None,
};
if val < radix { Some(val) }
@ -396,7 +396,7 @@ impl CharExt for char {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
fn len_utf8(self) -> uint {
fn len_utf8(self) -> usize {
let code = self as u32;
match () {
_ if code < MAX_ONE_B => 1,
@ -408,7 +408,7 @@ impl CharExt for char {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
fn len_utf16(self) -> uint {
fn len_utf16(self) -> usize {
let ch = self as u32;
if (ch & 0xFFFF_u32) == ch { 1 } else { 2 }
}
@ -416,14 +416,14 @@ impl CharExt for char {
#[inline]
#[unstable(feature = "core",
reason = "pending decision about Iterator/Writer/Reader")]
fn encode_utf8(self, dst: &mut [u8]) -> Option<uint> {
fn encode_utf8(self, dst: &mut [u8]) -> Option<usize> {
encode_utf8_raw(self as u32, dst)
}
#[inline]
#[unstable(feature = "core",
reason = "pending decision about Iterator/Writer/Reader")]
fn encode_utf16(self, dst: &mut [u16]) -> Option<uint> {
fn encode_utf16(self, dst: &mut [u16]) -> Option<usize> {
encode_utf16_raw(self as u32, dst)
}
}
@ -435,7 +435,7 @@ impl CharExt for char {
/// and a `None` will be returned.
#[inline]
#[unstable(feature = "core")]
pub fn encode_utf8_raw(code: u32, dst: &mut [u8]) -> Option<uint> {
pub fn encode_utf8_raw(code: u32, dst: &mut [u8]) -> Option<usize> {
// Marked #[inline] to allow llvm optimizing it away
if code < MAX_ONE_B && dst.len() >= 1 {
dst[0] = code as u8;
@ -467,7 +467,7 @@ pub fn encode_utf8_raw(code: u32, dst: &mut [u8]) -> Option<uint> {
/// and a `None` will be returned.
#[inline]
#[unstable(feature = "core")]
pub fn encode_utf16_raw(mut ch: u32, dst: &mut [u16]) -> Option<uint> {
pub fn encode_utf16_raw(mut ch: u32, dst: &mut [u16]) -> Option<usize> {
// Marked #[inline] to allow llvm optimizing it away
if (ch & 0xFFFF_u32) == ch && dst.len() >= 1 {
// The BMP falls through (assuming non-surrogate, as it should)
@ -499,7 +499,7 @@ enum EscapeUnicodeState {
Backslash,
Type,
LeftBrace,
Value(uint),
Value(usize),
RightBrace,
Done,
}

View File

@ -61,13 +61,13 @@ macro_rules! clone_impl {
}
}
clone_impl! { int }
clone_impl! { isize }
clone_impl! { i8 }
clone_impl! { i16 }
clone_impl! { i32 }
clone_impl! { i64 }
clone_impl! { uint }
clone_impl! { usize }
clone_impl! { u8 }
clone_impl! { u16 }
clone_impl! { u32 }

View File

@ -53,7 +53,7 @@ pub enum SignFormat {
SignNeg
}
static DIGIT_E_RADIX: uint = ('e' as uint) - ('a' as uint) + 11;
static DIGIT_E_RADIX: u32 = ('e' as u32) - ('a' as u32) + 11;
/// Converts a number to its string representation as a byte vector.
/// This is meant to be a common base implementation for all numeric string
@ -87,7 +87,7 @@ static DIGIT_E_RADIX: uint = ('e' as uint) - ('a' as uint) + 11;
/// between digit and exponent sign `'p'`.
pub fn float_to_str_bytes_common<T: Float, U, F>(
num: T,
radix: uint,
radix: u32,
negative_zero: bool,
sign: SignFormat,
digits: SignificantDigits,
@ -156,7 +156,7 @@ pub fn float_to_str_bytes_common<T: Float, U, F>(
deccum = deccum / radix_gen;
deccum = deccum.trunc();
let c = char::from_digit(current_digit.to_int().unwrap() as uint, radix);
let c = char::from_digit(current_digit.to_int().unwrap() as u32, radix);
buf[end] = c.unwrap() as u8;
end += 1;
@ -211,7 +211,7 @@ pub fn float_to_str_bytes_common<T: Float, U, F>(
// See note in first loop.
let current_digit = deccum.trunc().abs();
let c = char::from_digit(current_digit.to_int().unwrap() as uint,
let c = char::from_digit(current_digit.to_int().unwrap() as u32,
radix);
buf[end] = c.unwrap() as u8;
end += 1;
@ -228,7 +228,7 @@ pub fn float_to_str_bytes_common<T: Float, U, F>(
let ascii2value = |chr: u8| {
(chr as char).to_digit(radix).unwrap()
};
let value2ascii = |val: uint| {
let value2ascii = |val: u32| {
char::from_digit(val, radix).unwrap() as u8
};

View File

@ -2676,9 +2676,9 @@ impl<A: Int> Iterator for ::ops::Range<A> {
}
}
// Ranges of u64 and i64 are excluded because they cannot guarantee having
// a length <= usize::MAX, which is required by ExactSizeIterator.
range_exact_iter_impl!(usize u8 u16 u32 isize i8 i16 i32);
#[cfg(target_pointer_width = "64")]
range_exact_iter_impl!(u64 i64);
#[stable(feature = "rust1", since = "1.0.0")]
impl<A: Int> DoubleEndedIterator for ::ops::Range<A> {

View File

@ -64,7 +64,7 @@
#![feature(int_uint)]
#![feature(intrinsics, lang_items)]
#![feature(on_unimplemented)]
#![feature(simd, unsafe_destructor, slicing_syntax)]
#![feature(simd, unsafe_destructor)]
#![feature(staged_api)]
#![feature(unboxed_closures)]

View File

@ -35,14 +35,27 @@ pub const EPSILON: f32 = 1.19209290e-07_f32;
/// Smallest finite f32 value
#[stable(feature = "rust1", since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "use `std::f32::MIN`")]
pub const MIN_VALUE: f32 = -3.40282347e+38_f32;
/// Smallest positive, normalized f32 value
#[stable(feature = "rust1", since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "use `std::f32::MIN_POSITIVE`")]
pub const MIN_POS_VALUE: f32 = 1.17549435e-38_f32;
/// Largest finite f32 value
#[stable(feature = "rust1", since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "use `std::f32::MAX`")]
pub const MAX_VALUE: f32 = 3.40282347e+38_f32;
/// Smallest finite f32 value
#[stable(feature = "rust1", since = "1.0.0")]
pub const MIN: f32 = -3.40282347e+38_f32;
/// Smallest positive, normalized f32 value
#[stable(feature = "rust1", since = "1.0.0")]
pub const MIN_POSITIVE: f32 = 1.17549435e-38_f32;
/// Largest finite f32 value
#[stable(feature = "rust1", since = "1.0.0")]
pub const MAX: f32 = 3.40282347e+38_f32;
#[unstable(feature = "core", reason = "pending integer conventions")]
pub const MIN_EXP: int = -125;
#[unstable(feature = "core", reason = "pending integer conventions")]
@ -215,17 +228,17 @@ impl Float for f32 {
#[inline]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0")]
fn min_value() -> f32 { MIN_VALUE }
fn min_value() -> f32 { MIN }
#[inline]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0")]
fn min_pos_value(_: Option<f32>) -> f32 { MIN_POS_VALUE }
fn min_pos_value(_: Option<f32>) -> f32 { MIN_POSITIVE }
#[inline]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0")]
fn max_value() -> f32 { MAX_VALUE }
fn max_value() -> f32 { MAX }
/// Returns the mantissa, exponent and sign as integers.
fn integer_decode(self) -> (u64, i16, i8) {

View File

@ -38,14 +38,27 @@ pub const EPSILON: f64 = 2.2204460492503131e-16_f64;
/// Smallest finite f64 value
#[stable(feature = "rust1", since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "use `std::f64::MIN`")]
pub const MIN_VALUE: f64 = -1.7976931348623157e+308_f64;
/// Smallest positive, normalized f64 value
#[stable(feature = "rust1", since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "use `std::f64::MIN_POSITIVE`")]
pub const MIN_POS_VALUE: f64 = 2.2250738585072014e-308_f64;
/// Largest finite f64 value
#[stable(feature = "rust1", since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "use `std::f64::MAX`")]
pub const MAX_VALUE: f64 = 1.7976931348623157e+308_f64;
/// Smallest finite f64 value
#[stable(feature = "rust1", since = "1.0.0")]
pub const MIN: f64 = -1.7976931348623157e+308_f64;
/// Smallest positive, normalized f64 value
#[stable(feature = "rust1", since = "1.0.0")]
pub const MIN_POSITIVE: f64 = 2.2250738585072014e-308_f64;
/// Largest finite f64 value
#[stable(feature = "rust1", since = "1.0.0")]
pub const MAX: f64 = 1.7976931348623157e+308_f64;
#[unstable(feature = "core", reason = "pending integer conventions")]
pub const MIN_EXP: int = -1021;
#[unstable(feature = "core", reason = "pending integer conventions")]
@ -222,17 +235,17 @@ impl Float for f64 {
#[inline]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0")]
fn min_value() -> f64 { MIN_VALUE }
fn min_value() -> f64 { MIN }
#[inline]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0")]
fn min_pos_value(_: Option<f64>) -> f64 { MIN_POS_VALUE }
fn min_pos_value(_: Option<f64>) -> f64 { MIN_POSITIVE }
#[inline]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0")]
fn max_value() -> f64 { MAX_VALUE }
fn max_value() -> f64 { MAX }
/// Returns the mantissa, exponent and sign as integers.
fn integer_decode(self) -> (u64, i16, i8) {

View File

@ -956,7 +956,7 @@ macro_rules! impl_to_primitive_float_to_float {
Some($slf as $DstT)
} else {
let n = $slf as f64;
let max_value: $SrcT = ::$SrcT::MAX_VALUE;
let max_value: $SrcT = ::$SrcT::MAX;
if -max_value as f64 <= n && n <= max_value as f64 {
Some($slf as $DstT)
} else {
@ -1331,18 +1331,18 @@ pub trait Float
/// Returns the smallest finite value that this type can represent.
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0",
reason = "use `std::f32::MIN_VALUE` or `std::f64::MIN_VALUE` as appropriate")]
reason = "use `std::f32::MIN` or `std::f64::MIN` as appropriate")]
fn min_value() -> Self;
/// Returns the smallest normalized positive number that this type can represent.
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0",
reason = "use `std::f32::MIN_POS_VALUE` or \
`std::f64::MIN_POS_VALUE` as appropriate")]
reason = "use `std::f32::MIN_POSITIVE` or \
`std::f64::MIN_POSITIVE` as appropriate")]
fn min_pos_value(unused_self: Option<Self>) -> Self;
/// Returns the largest finite value that this type can represent.
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0",
reason = "use `std::f32::MAX_VALUE` or `std::f64::MAX_VALUE` as appropriate")]
reason = "use `std::f32::MAX` or `std::f64::MAX` as appropriate")]
fn max_value() -> Self;
/// Returns true if this value is NaN and false otherwise.
@ -1432,12 +1432,12 @@ pub trait Float
#[unstable(feature = "core", reason = "needs reevaluation")]
pub trait FromStrRadix {
type Err;
fn from_str_radix(str: &str, radix: uint) -> Result<Self, Self::Err>;
fn from_str_radix(str: &str, radix: u32) -> Result<Self, Self::Err>;
}
/// A utility function that just calls FromStrRadix::from_str_radix.
#[unstable(feature = "core", reason = "needs reevaluation")]
pub fn from_str_radix<T: FromStrRadix>(str: &str, radix: uint)
pub fn from_str_radix<T: FromStrRadix>(str: &str, radix: u32)
-> Result<T, T::Err> {
FromStrRadix::from_str_radix(str, radix)
}
@ -1501,7 +1501,7 @@ macro_rules! from_str_radix_float_impl {
/// `None` if the string did not represent a valid number.
/// Otherwise, `Some(n)` where `n` is the floating-point number
/// represented by `src`.
fn from_str_radix(src: &str, radix: uint)
fn from_str_radix(src: &str, radix: u32)
-> Result<$T, ParseFloatError> {
use self::FloatErrorKind::*;
use self::ParseFloatError as PFE;
@ -1661,7 +1661,7 @@ macro_rules! from_str_radix_int_impl {
#[stable(feature = "rust1", since = "1.0.0")]
impl FromStrRadix for $T {
type Err = ParseIntError;
fn from_str_radix(src: &str, radix: uint)
fn from_str_radix(src: &str, radix: u32)
-> Result<$T, ParseIntError> {
use self::IntErrorKind::*;
use self::ParseIntError as PIE;

View File

@ -162,7 +162,7 @@ use slice;
// `Iterator` is an enumeration with one type parameter and two variants,
// which basically means it must be `Option`.
/// The `Option` type.
/// The `Option` type. See [the module level documentation](../index.html) for more.
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
#[stable(feature = "rust1", since = "1.0.0")]
pub enum Option<T> {

View File

@ -21,27 +21,130 @@
use marker::Copy;
use mem;
/// The representation of a Rust slice
/// The representation of a slice like `&[T]`.
///
/// This struct is guaranteed to have the layout of types like `&[T]`,
/// `&str`, and `Box<[T]>`, but is not the type of such slices
/// (e.g. the fields are not directly accessible on a `&[T]`) nor does
/// it control that layout (changing the definition will not change
/// the layout of a `&[T]`). It is only designed to be used by unsafe
/// code that needs to manipulate the low-level details.
///
/// However, it is not recommended to use this type for such code,
/// since there are alternatives which may be safer:
///
/// - Creating a slice from a data pointer and length can be done with
/// `std::slice::from_raw_parts` or `std::slice::from_raw_parts_mut`
/// instead of `std::mem::transmute`ing a value of type `Slice`.
/// - Extracting the data pointer and length from a slice can be
/// performed with the `as_ptr` (or `as_mut_ptr`) and `len`
/// methods.
///
/// If one does decide to convert a slice value to a `Slice`, the
/// `Repr` trait in this module provides a method for a safe
/// conversion from `&[T]` (and `&str`) to a `Slice`, more type-safe
/// than a call to `transmute`.
///
/// # Examples
///
/// ```
/// use std::raw::{self, Repr};
///
/// let slice: &[u16] = &[1, 2, 3, 4];
///
/// let repr: raw::Slice<u16> = slice.repr();
/// println!("data pointer = {:?}, length = {}", repr.data, repr.len);
/// ```
#[repr(C)]
pub struct Slice<T> {
pub data: *const T,
pub len: uint,
pub len: usize,
}
impl<T> Copy for Slice<T> {}
/// The representation of a Rust closure
/// The representation of an old closure.
#[repr(C)]
#[derive(Copy)]
#[unstable(feature = "core")]
#[deprecated(reason = "unboxed new closures do not have a universal representation; \
`&Fn` (etc) trait objects should use `TraitObject` instead",
since= "1.0.0")]
pub struct Closure {
pub code: *mut (),
pub env: *mut (),
}
/// The representation of a Rust trait object.
/// The representation of a trait object like `&SomeTrait`.
///
/// This struct does not have a `Repr` implementation
/// because there is no way to refer to all trait objects generically.
/// This struct has the same layout as types like `&SomeTrait` and
/// `Box<AnotherTrait>`. The [Static and Dynamic Dispatch chapter of the
/// Book][moreinfo] contains more details about the precise nature of
/// these internals.
///
/// [moreinfo]: ../../book/static-and-dynamic-dispatch.html#representation
///
/// `TraitObject` is guaranteed to match layouts, but it is not the
/// type of trait objects (e.g. the fields are not directly accessible
/// on a `&SomeTrait`) nor does it control that layout (changing the
/// definition will not change the layout of a `&SometTrait`). It is
/// only designed to be used by unsafe code that needs to manipulate
/// the low-level details.
///
/// There is no `Repr` implementation for `TraitObject` because there
/// is no way to refer to all trait objects generically, so the only
/// way to create values of this type is with functions like
/// `std::mem::transmute`. Similarly, the only way to create a true
/// trait object from a `TraitObject` value is with `transmute`.
///
/// Synthesizing a trait object with mismatched types—one where the
/// vtable does not correspond to the type of the value to which the
/// data pointer points—is highly likely to lead to undefined
/// behaviour.
///
/// # Examples
///
/// ```
/// use std::mem;
/// use std::raw;
///
/// // an example trait
/// trait Foo {
/// fn bar(&self) -> i32;
/// }
/// impl Foo for i32 {
/// fn bar(&self) -> i32 {
/// *self + 1
/// }
/// }
///
/// let value: i32 = 123;
///
/// // let the compiler make a trait object
/// let object: &Foo = &value;
///
/// // look at the raw representation
/// let raw_object: raw::TraitObject = unsafe { mem::transmute(object) };
///
/// // the data pointer is the address of `value`
/// assert_eq!(raw_object.data as *const i32, &value as *const _);
///
///
/// let other_value: i32 = 456;
///
/// // construct a new object, pointing to a different `i32`, being
/// // careful to use the `i32` vtable from `object`
/// let synthesized: &Foo = unsafe {
/// mem::transmute(raw::TraitObject {
/// data: &other_value as *const _ as *mut (),
/// vtable: raw_object.vtable
/// })
/// };
///
/// // it should work just like we constructed a trait object out of
/// // `other_value` directly
/// assert_eq!(synthesized.bar(), 457);
/// ```
#[repr(C)]
#[derive(Copy)]
pub struct TraitObject {
@ -51,7 +154,7 @@ pub struct TraitObject {
/// This trait is meant to map equivalences between raw structs and their
/// corresponding rust values.
pub trait Repr<T> {
pub unsafe trait Repr<T> {
/// This function "unwraps" a rust value (without consuming it) into its raw
/// struct representation. This can be used to read/write different values
/// for the struct. This is a safe method because by default it does not
@ -60,5 +163,5 @@ pub trait Repr<T> {
fn repr(&self) -> T { unsafe { mem::transmute_copy(&self) } }
}
impl<T> Repr<Slice<T>> for [T] {}
impl Repr<Slice<u8>> for str {}
unsafe impl<T> Repr<Slice<T>> for [T] {}
unsafe impl Repr<Slice<u8>> for str {}

View File

@ -66,28 +66,28 @@ use raw::Slice as RawSlice;
pub trait SliceExt {
type Item;
fn split_at<'a>(&'a self, mid: uint) -> (&'a [Self::Item], &'a [Self::Item]);
fn split_at<'a>(&'a self, mid: usize) -> (&'a [Self::Item], &'a [Self::Item]);
fn iter<'a>(&'a self) -> Iter<'a, Self::Item>;
fn split<'a, P>(&'a self, pred: P) -> Split<'a, Self::Item, P>
where P: FnMut(&Self::Item) -> bool;
fn splitn<'a, P>(&'a self, n: uint, pred: P) -> SplitN<'a, Self::Item, P>
fn splitn<'a, P>(&'a self, n: usize, pred: P) -> SplitN<'a, Self::Item, P>
where P: FnMut(&Self::Item) -> bool;
fn rsplitn<'a, P>(&'a self, n: uint, pred: P) -> RSplitN<'a, Self::Item, P>
fn rsplitn<'a, P>(&'a self, n: usize, pred: P) -> RSplitN<'a, Self::Item, P>
where P: FnMut(&Self::Item) -> bool;
fn windows<'a>(&'a self, size: uint) -> Windows<'a, Self::Item>;
fn chunks<'a>(&'a self, size: uint) -> Chunks<'a, Self::Item>;
fn get<'a>(&'a self, index: uint) -> Option<&'a Self::Item>;
fn windows<'a>(&'a self, size: usize) -> Windows<'a, Self::Item>;
fn chunks<'a>(&'a self, size: usize) -> Chunks<'a, Self::Item>;
fn get<'a>(&'a self, index: usize) -> Option<&'a Self::Item>;
fn first<'a>(&'a self) -> Option<&'a Self::Item>;
fn tail<'a>(&'a self) -> &'a [Self::Item];
fn init<'a>(&'a self) -> &'a [Self::Item];
fn last<'a>(&'a self) -> Option<&'a Self::Item>;
unsafe fn get_unchecked<'a>(&'a self, index: uint) -> &'a Self::Item;
unsafe fn get_unchecked<'a>(&'a self, index: usize) -> &'a Self::Item;
fn as_ptr(&self) -> *const Self::Item;
fn binary_search_by<F>(&self, f: F) -> Result<uint, uint> where
fn binary_search_by<F>(&self, f: F) -> Result<usize, usize> where
F: FnMut(&Self::Item) -> Ordering;
fn len(&self) -> uint;
fn len(&self) -> usize;
fn is_empty(&self) -> bool { self.len() == 0 }
fn get_mut<'a>(&'a mut self, index: uint) -> Option<&'a mut Self::Item>;
fn get_mut<'a>(&'a mut self, index: usize) -> Option<&'a mut Self::Item>;
fn as_mut_slice<'a>(&'a mut self) -> &'a mut [Self::Item];
fn iter_mut<'a>(&'a mut self) -> IterMut<'a, Self::Item>;
fn first_mut<'a>(&'a mut self) -> Option<&'a mut Self::Item>;
@ -96,20 +96,20 @@ pub trait SliceExt {
fn last_mut<'a>(&'a mut self) -> Option<&'a mut Self::Item>;
fn split_mut<'a, P>(&'a mut self, pred: P) -> SplitMut<'a, Self::Item, P>
where P: FnMut(&Self::Item) -> bool;
fn splitn_mut<P>(&mut self, n: uint, pred: P) -> SplitNMut<Self::Item, P>
fn splitn_mut<P>(&mut self, n: usize, pred: P) -> SplitNMut<Self::Item, P>
where P: FnMut(&Self::Item) -> bool;
fn rsplitn_mut<P>(&mut self, n: uint, pred: P) -> RSplitNMut<Self::Item, P>
fn rsplitn_mut<P>(&mut self, n: usize, pred: P) -> RSplitNMut<Self::Item, P>
where P: FnMut(&Self::Item) -> bool;
fn chunks_mut<'a>(&'a mut self, chunk_size: uint) -> ChunksMut<'a, Self::Item>;
fn swap(&mut self, a: uint, b: uint);
fn split_at_mut<'a>(&'a mut self, mid: uint) -> (&'a mut [Self::Item], &'a mut [Self::Item]);
fn chunks_mut<'a>(&'a mut self, chunk_size: usize) -> ChunksMut<'a, Self::Item>;
fn swap(&mut self, a: usize, b: usize);
fn split_at_mut<'a>(&'a mut self, mid: usize) -> (&'a mut [Self::Item], &'a mut [Self::Item]);
fn reverse(&mut self);
unsafe fn get_unchecked_mut<'a>(&'a mut self, index: uint) -> &'a mut Self::Item;
unsafe fn get_unchecked_mut<'a>(&'a mut self, index: usize) -> &'a mut Self::Item;
fn as_mut_ptr(&mut self) -> *mut Self::Item;
fn position_elem(&self, t: &Self::Item) -> Option<uint> where Self::Item: PartialEq;
fn position_elem(&self, t: &Self::Item) -> Option<usize> where Self::Item: PartialEq;
fn rposition_elem(&self, t: &Self::Item) -> Option<uint> where Self::Item: PartialEq;
fn rposition_elem(&self, t: &Self::Item) -> Option<usize> where Self::Item: PartialEq;
fn contains(&self, x: &Self::Item) -> bool where Self::Item: PartialEq;
@ -117,11 +117,11 @@ pub trait SliceExt {
fn ends_with(&self, needle: &[Self::Item]) -> bool where Self::Item: PartialEq;
fn binary_search(&self, x: &Self::Item) -> Result<uint, uint> where Self::Item: Ord;
fn binary_search(&self, x: &Self::Item) -> Result<usize, usize> where Self::Item: Ord;
fn next_permutation(&mut self) -> bool where Self::Item: Ord;
fn prev_permutation(&mut self) -> bool where Self::Item: Ord;
fn clone_from_slice(&mut self, &[Self::Item]) -> uint where Self::Item: Clone;
fn clone_from_slice(&mut self, &[Self::Item]) -> usize where Self::Item: Clone;
}
#[unstable(feature = "core")]
@ -129,7 +129,7 @@ impl<T> SliceExt for [T] {
type Item = T;
#[inline]
fn split_at(&self, mid: uint) -> (&[T], &[T]) {
fn split_at(&self, mid: usize) -> (&[T], &[T]) {
(&self[..mid], &self[mid..])
}
@ -139,11 +139,11 @@ impl<T> SliceExt for [T] {
let p = self.as_ptr();
if mem::size_of::<T>() == 0 {
Iter {ptr: p,
end: (p as uint + self.len()) as *const T,
end: (p as usize + self.len()) as *const T,
marker: marker::ContravariantLifetime::<'a>}
} else {
Iter {ptr: p,
end: p.offset(self.len() as int),
end: p.offset(self.len() as isize),
marker: marker::ContravariantLifetime::<'a>}
}
}
@ -159,7 +159,7 @@ impl<T> SliceExt for [T] {
}
#[inline]
fn splitn<'a, P>(&'a self, n: uint, pred: P) -> SplitN<'a, T, P> where
fn splitn<'a, P>(&'a self, n: usize, pred: P) -> SplitN<'a, T, P> where
P: FnMut(&T) -> bool,
{
SplitN {
@ -172,7 +172,7 @@ impl<T> SliceExt for [T] {
}
#[inline]
fn rsplitn<'a, P>(&'a self, n: uint, pred: P) -> RSplitN<'a, T, P> where
fn rsplitn<'a, P>(&'a self, n: usize, pred: P) -> RSplitN<'a, T, P> where
P: FnMut(&T) -> bool,
{
RSplitN {
@ -185,19 +185,19 @@ impl<T> SliceExt for [T] {
}
#[inline]
fn windows(&self, size: uint) -> Windows<T> {
fn windows(&self, size: usize) -> Windows<T> {
assert!(size != 0);
Windows { v: self, size: size }
}
#[inline]
fn chunks(&self, size: uint) -> Chunks<T> {
fn chunks(&self, size: usize) -> Chunks<T> {
assert!(size != 0);
Chunks { v: self, size: size }
}
#[inline]
fn get(&self, index: uint) -> Option<&T> {
fn get(&self, index: usize) -> Option<&T> {
if index < self.len() { Some(&self[index]) } else { None }
}
@ -220,8 +220,8 @@ impl<T> SliceExt for [T] {
}
#[inline]
unsafe fn get_unchecked(&self, index: uint) -> &T {
transmute(self.repr().data.offset(index as int))
unsafe fn get_unchecked(&self, index: usize) -> &T {
transmute(self.repr().data.offset(index as isize))
}
#[inline]
@ -230,11 +230,11 @@ impl<T> SliceExt for [T] {
}
#[unstable(feature = "core")]
fn binary_search_by<F>(&self, mut f: F) -> Result<uint, uint> where
fn binary_search_by<F>(&self, mut f: F) -> Result<usize, usize> where
F: FnMut(&T) -> Ordering
{
let mut base : uint = 0;
let mut lim : uint = self.len();
let mut base : usize = 0;
let mut lim : usize = self.len();
while lim != 0 {
let ix = base + (lim >> 1);
@ -252,10 +252,10 @@ impl<T> SliceExt for [T] {
}
#[inline]
fn len(&self) -> uint { self.repr().len }
fn len(&self) -> usize { self.repr().len }
#[inline]
fn get_mut(&mut self, index: uint) -> Option<&mut T> {
fn get_mut(&mut self, index: usize) -> Option<&mut T> {
if index < self.len() { Some(&mut self[index]) } else { None }
}
@ -263,7 +263,7 @@ impl<T> SliceExt for [T] {
fn as_mut_slice(&mut self) -> &mut [T] { self }
#[inline]
fn split_at_mut(&mut self, mid: uint) -> (&mut [T], &mut [T]) {
fn split_at_mut(&mut self, mid: usize) -> (&mut [T], &mut [T]) {
unsafe {
let self2: &mut [T] = mem::transmute_copy(&self);
@ -278,11 +278,11 @@ impl<T> SliceExt for [T] {
let p = self.as_mut_ptr();
if mem::size_of::<T>() == 0 {
IterMut {ptr: p,
end: (p as uint + self.len()) as *mut T,
end: (p as usize + self.len()) as *mut T,
marker: marker::ContravariantLifetime::<'a>}
} else {
IterMut {ptr: p,
end: p.offset(self.len() as int),
end: p.offset(self.len() as isize),
marker: marker::ContravariantLifetime::<'a>}
}
}
@ -317,7 +317,7 @@ impl<T> SliceExt for [T] {
}
#[inline]
fn splitn_mut<'a, P>(&'a mut self, n: uint, pred: P) -> SplitNMut<'a, T, P> where
fn splitn_mut<'a, P>(&'a mut self, n: usize, pred: P) -> SplitNMut<'a, T, P> where
P: FnMut(&T) -> bool
{
SplitNMut {
@ -330,7 +330,7 @@ impl<T> SliceExt for [T] {
}
#[inline]
fn rsplitn_mut<'a, P>(&'a mut self, n: uint, pred: P) -> RSplitNMut<'a, T, P> where
fn rsplitn_mut<'a, P>(&'a mut self, n: usize, pred: P) -> RSplitNMut<'a, T, P> where
P: FnMut(&T) -> bool,
{
RSplitNMut {
@ -343,12 +343,12 @@ impl<T> SliceExt for [T] {
}
#[inline]
fn chunks_mut(&mut self, chunk_size: uint) -> ChunksMut<T> {
fn chunks_mut(&mut self, chunk_size: usize) -> ChunksMut<T> {
assert!(chunk_size > 0);
ChunksMut { v: self, chunk_size: chunk_size }
}
fn swap(&mut self, a: uint, b: uint) {
fn swap(&mut self, a: usize, b: usize) {
unsafe {
// Can't take two mutable loans from one vector, so instead just cast
// them to their raw pointers to do the swap
@ -359,7 +359,7 @@ impl<T> SliceExt for [T] {
}
fn reverse(&mut self) {
let mut i: uint = 0;
let mut i: usize = 0;
let ln = self.len();
while i < ln / 2 {
// Unsafe swap to avoid the bounds check in safe swap.
@ -373,8 +373,8 @@ impl<T> SliceExt for [T] {
}
#[inline]
unsafe fn get_unchecked_mut(&mut self, index: uint) -> &mut T {
transmute((self.repr().data as *mut T).offset(index as int))
unsafe fn get_unchecked_mut(&mut self, index: usize) -> &mut T {
transmute((self.repr().data as *mut T).offset(index as isize))
}
#[inline]
@ -383,12 +383,12 @@ impl<T> SliceExt for [T] {
}
#[inline]
fn position_elem(&self, x: &T) -> Option<uint> where T: PartialEq {
fn position_elem(&self, x: &T) -> Option<usize> where T: PartialEq {
self.iter().position(|y| *x == *y)
}
#[inline]
fn rposition_elem(&self, t: &T) -> Option<uint> where T: PartialEq {
fn rposition_elem(&self, t: &T) -> Option<usize> where T: PartialEq {
self.iter().rposition(|x| *x == *t)
}
@ -410,7 +410,7 @@ impl<T> SliceExt for [T] {
}
#[unstable(feature = "core")]
fn binary_search(&self, x: &T) -> Result<uint, uint> where T: Ord {
fn binary_search(&self, x: &T) -> Result<usize, usize> where T: Ord {
self.binary_search_by(|p| p.cmp(x))
}
@ -477,7 +477,7 @@ impl<T> SliceExt for [T] {
}
#[inline]
fn clone_from_slice(&mut self, src: &[T]) -> uint where T: Clone {
fn clone_from_slice(&mut self, src: &[T]) -> usize where T: Clone {
let min = cmp::min(self.len(), src.len());
let dst = &mut self[.. min];
let src = &src[.. min];
@ -489,53 +489,53 @@ impl<T> SliceExt for [T] {
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ops::Index<uint> for [T] {
impl<T> ops::Index<usize> for [T] {
type Output = T;
fn index(&self, &index: &uint) -> &T {
fn index(&self, &index: &usize) -> &T {
assert!(index < self.len());
unsafe { mem::transmute(self.repr().data.offset(index as int)) }
unsafe { mem::transmute(self.repr().data.offset(index as isize)) }
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ops::IndexMut<uint> for [T] {
fn index_mut(&mut self, &index: &uint) -> &mut T {
impl<T> ops::IndexMut<usize> for [T] {
fn index_mut(&mut self, &index: &usize) -> &mut T {
assert!(index < self.len());
unsafe { mem::transmute(self.repr().data.offset(index as int)) }
unsafe { mem::transmute(self.repr().data.offset(index as isize)) }
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ops::Index<ops::Range<uint>> for [T] {
impl<T> ops::Index<ops::Range<usize>> for [T] {
type Output = [T];
#[inline]
fn index(&self, index: &ops::Range<uint>) -> &[T] {
fn index(&self, index: &ops::Range<usize>) -> &[T] {
assert!(index.start <= index.end);
assert!(index.end <= self.len());
unsafe {
transmute(RawSlice {
data: self.as_ptr().offset(index.start as int),
data: self.as_ptr().offset(index.start as isize),
len: index.end - index.start
})
}
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ops::Index<ops::RangeTo<uint>> for [T] {
impl<T> ops::Index<ops::RangeTo<usize>> for [T] {
type Output = [T];
#[inline]
fn index(&self, index: &ops::RangeTo<uint>) -> &[T] {
fn index(&self, index: &ops::RangeTo<usize>) -> &[T] {
self.index(&ops::Range{ start: 0, end: index.end })
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ops::Index<ops::RangeFrom<uint>> for [T] {
impl<T> ops::Index<ops::RangeFrom<usize>> for [T] {
type Output = [T];
#[inline]
fn index(&self, index: &ops::RangeFrom<uint>) -> &[T] {
fn index(&self, index: &ops::RangeFrom<usize>) -> &[T] {
self.index(&ops::Range{ start: index.start, end: self.len() })
}
}
@ -549,30 +549,30 @@ impl<T> ops::Index<RangeFull> for [T] {
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ops::IndexMut<ops::Range<uint>> for [T] {
impl<T> ops::IndexMut<ops::Range<usize>> for [T] {
#[inline]
fn index_mut(&mut self, index: &ops::Range<uint>) -> &mut [T] {
fn index_mut(&mut self, index: &ops::Range<usize>) -> &mut [T] {
assert!(index.start <= index.end);
assert!(index.end <= self.len());
unsafe {
transmute(RawSlice {
data: self.as_ptr().offset(index.start as int),
data: self.as_ptr().offset(index.start as isize),
len: index.end - index.start
})
}
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ops::IndexMut<ops::RangeTo<uint>> for [T] {
impl<T> ops::IndexMut<ops::RangeTo<usize>> for [T] {
#[inline]
fn index_mut(&mut self, index: &ops::RangeTo<uint>) -> &mut [T] {
fn index_mut(&mut self, index: &ops::RangeTo<usize>) -> &mut [T] {
self.index_mut(&ops::Range{ start: 0, end: index.end })
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ops::IndexMut<ops::RangeFrom<uint>> for [T] {
impl<T> ops::IndexMut<ops::RangeFrom<usize>> for [T] {
#[inline]
fn index_mut(&mut self, index: &ops::RangeFrom<uint>) -> &mut [T] {
fn index_mut(&mut self, index: &ops::RangeFrom<usize>) -> &mut [T] {
let len = self.len();
self.index_mut(&ops::Range{ start: index.start, end: len })
}
@ -660,7 +660,7 @@ macro_rules! iterator {
// purposefully don't use 'ptr.offset' because for
// vectors with 0-size elements this would return the
// same pointer.
self.ptr = transmute(self.ptr as uint + 1);
self.ptr = transmute(self.ptr as usize + 1);
// Use a non-null pointer value
Some(&mut *(1 as *mut _))
@ -675,8 +675,8 @@ macro_rules! iterator {
}
#[inline]
fn size_hint(&self) -> (uint, Option<uint>) {
let diff = (self.end as uint) - (self.ptr as uint);
fn size_hint(&self) -> (usize, Option<usize>) {
let diff = (self.end as usize) - (self.ptr as usize);
let size = mem::size_of::<T>();
let exact = diff / (if size == 0 {1} else {size});
(exact, Some(exact))
@ -694,7 +694,7 @@ macro_rules! iterator {
} else {
if mem::size_of::<T>() == 0 {
// See above for why 'ptr.offset' isn't used
self.end = transmute(self.end as uint - 1);
self.end = transmute(self.end as usize - 1);
// Use a non-null pointer value
Some(&mut *(1 as *mut _))
@ -712,7 +712,7 @@ macro_rules! iterator {
macro_rules! make_slice {
($t: ty => $result: ty: $start: expr, $end: expr) => {{
let diff = $end as uint - $start as uint;
let diff = $end as usize - $start as usize;
let len = if mem::size_of::<T>() == 0 {
diff
} else {
@ -733,28 +733,28 @@ pub struct Iter<'a, T: 'a> {
}
#[unstable(feature = "core")]
impl<'a, T> ops::Index<ops::Range<uint>> for Iter<'a, T> {
impl<'a, T> ops::Index<ops::Range<usize>> for Iter<'a, T> {
type Output = [T];
#[inline]
fn index(&self, index: &ops::Range<uint>) -> &[T] {
fn index(&self, index: &ops::Range<usize>) -> &[T] {
self.as_slice().index(index)
}
}
#[unstable(feature = "core")]
impl<'a, T> ops::Index<ops::RangeTo<uint>> for Iter<'a, T> {
impl<'a, T> ops::Index<ops::RangeTo<usize>> for Iter<'a, T> {
type Output = [T];
#[inline]
fn index(&self, index: &ops::RangeTo<uint>) -> &[T] {
fn index(&self, index: &ops::RangeTo<usize>) -> &[T] {
self.as_slice().index(index)
}
}
#[unstable(feature = "core")]
impl<'a, T> ops::Index<ops::RangeFrom<uint>> for Iter<'a, T> {
impl<'a, T> ops::Index<ops::RangeFrom<usize>> for Iter<'a, T> {
type Output = [T];
#[inline]
fn index(&self, index: &ops::RangeFrom<uint>) -> &[T] {
fn index(&self, index: &ops::RangeFrom<usize>) -> &[T] {
self.as_slice().index(index)
}
}
@ -792,20 +792,20 @@ impl<'a, T> Clone for Iter<'a, T> {
#[unstable(feature = "core", reason = "trait is experimental")]
impl<'a, T> RandomAccessIterator for Iter<'a, T> {
#[inline]
fn indexable(&self) -> uint {
fn indexable(&self) -> usize {
let (exact, _) = self.size_hint();
exact
}
#[inline]
fn idx(&mut self, index: uint) -> Option<&'a T> {
fn idx(&mut self, index: usize) -> Option<&'a T> {
unsafe {
if index < self.indexable() {
if mem::size_of::<T>() == 0 {
// Use a non-null pointer value
Some(&mut *(1 as *mut _))
} else {
Some(transmute(self.ptr.offset(index as int)))
Some(transmute(self.ptr.offset(index as isize)))
}
} else {
None
@ -824,26 +824,26 @@ pub struct IterMut<'a, T: 'a> {
#[unstable(feature = "core")]
impl<'a, T> ops::Index<ops::Range<uint>> for IterMut<'a, T> {
impl<'a, T> ops::Index<ops::Range<usize>> for IterMut<'a, T> {
type Output = [T];
#[inline]
fn index(&self, index: &ops::Range<uint>) -> &[T] {
fn index(&self, index: &ops::Range<usize>) -> &[T] {
self.index(&RangeFull).index(index)
}
}
#[unstable(feature = "core")]
impl<'a, T> ops::Index<ops::RangeTo<uint>> for IterMut<'a, T> {
impl<'a, T> ops::Index<ops::RangeTo<usize>> for IterMut<'a, T> {
type Output = [T];
#[inline]
fn index(&self, index: &ops::RangeTo<uint>) -> &[T] {
fn index(&self, index: &ops::RangeTo<usize>) -> &[T] {
self.index(&RangeFull).index(index)
}
}
#[unstable(feature = "core")]
impl<'a, T> ops::Index<ops::RangeFrom<uint>> for IterMut<'a, T> {
impl<'a, T> ops::Index<ops::RangeFrom<usize>> for IterMut<'a, T> {
type Output = [T];
#[inline]
fn index(&self, index: &ops::RangeFrom<uint>) -> &[T] {
fn index(&self, index: &ops::RangeFrom<usize>) -> &[T] {
self.index(&RangeFull).index(index)
}
}
@ -857,23 +857,23 @@ impl<'a, T> ops::Index<RangeFull> for IterMut<'a, T> {
}
#[unstable(feature = "core")]
impl<'a, T> ops::IndexMut<ops::Range<uint>> for IterMut<'a, T> {
impl<'a, T> ops::IndexMut<ops::Range<usize>> for IterMut<'a, T> {
#[inline]
fn index_mut(&mut self, index: &ops::Range<uint>) -> &mut [T] {
fn index_mut(&mut self, index: &ops::Range<usize>) -> &mut [T] {
self.index_mut(&RangeFull).index_mut(index)
}
}
#[unstable(feature = "core")]
impl<'a, T> ops::IndexMut<ops::RangeTo<uint>> for IterMut<'a, T> {
impl<'a, T> ops::IndexMut<ops::RangeTo<usize>> for IterMut<'a, T> {
#[inline]
fn index_mut(&mut self, index: &ops::RangeTo<uint>) -> &mut [T] {
fn index_mut(&mut self, index: &ops::RangeTo<usize>) -> &mut [T] {
self.index_mut(&RangeFull).index_mut(index)
}
}
#[unstable(feature = "core")]
impl<'a, T> ops::IndexMut<ops::RangeFrom<uint>> for IterMut<'a, T> {
impl<'a, T> ops::IndexMut<ops::RangeFrom<usize>> for IterMut<'a, T> {
#[inline]
fn index_mut(&mut self, index: &ops::RangeFrom<uint>) -> &mut [T] {
fn index_mut(&mut self, index: &ops::RangeFrom<usize>) -> &mut [T] {
self.index_mut(&RangeFull).index_mut(index)
}
}
@ -952,7 +952,7 @@ impl<'a, T, P> Iterator for Split<'a, T, P> where P: FnMut(&T) -> bool {
}
#[inline]
fn size_hint(&self) -> (uint, Option<uint>) {
fn size_hint(&self) -> (usize, Option<usize>) {
if self.finished {
(0, Some(0))
} else {
@ -1030,7 +1030,7 @@ impl<'a, T, P> Iterator for SplitMut<'a, T, P> where P: FnMut(&T) -> bool {
}
#[inline]
fn size_hint(&self) -> (uint, Option<uint>) {
fn size_hint(&self) -> (usize, Option<usize>) {
if self.finished {
(0, Some(0))
} else {
@ -1070,7 +1070,7 @@ impl<'a, T, P> DoubleEndedIterator for SplitMut<'a, T, P> where
/// times.
struct GenericSplitN<I> {
iter: I,
count: uint,
count: usize,
invert: bool
}
@ -1088,7 +1088,7 @@ impl<T, I: SplitIter<Item=T>> Iterator for GenericSplitN<I> {
}
#[inline]
fn size_hint(&self) -> (uint, Option<uint>) {
fn size_hint(&self) -> (usize, Option<usize>) {
let (lower, upper_opt) = self.iter.size_hint();
(lower, upper_opt.map(|upper| cmp::min(self.count + 1, upper)))
}
@ -1138,7 +1138,7 @@ macro_rules! forward_iterator {
}
#[inline]
fn size_hint(&self) -> (uint, Option<uint>) {
fn size_hint(&self) -> (usize, Option<usize>) {
self.inner.size_hint()
}
}
@ -1155,7 +1155,7 @@ forward_iterator! { RSplitNMut: T, &'a mut [T] }
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Windows<'a, T:'a> {
v: &'a [T],
size: uint
size: usize
}
#[stable(feature = "rust1", since = "1.0.0")]
@ -1174,7 +1174,7 @@ impl<'a, T> Iterator for Windows<'a, T> {
}
#[inline]
fn size_hint(&self) -> (uint, Option<uint>) {
fn size_hint(&self) -> (usize, Option<usize>) {
if self.size > self.v.len() {
(0, Some(0))
} else {
@ -1204,12 +1204,12 @@ impl<'a, T> ExactSizeIterator for Windows<'a, T> {}
#[unstable(feature = "core", reason = "trait is experimental")]
impl<'a, T> RandomAccessIterator for Windows<'a, T> {
#[inline]
fn indexable(&self) -> uint {
fn indexable(&self) -> usize {
self.size_hint().0
}
#[inline]
fn idx(&mut self, index: uint) -> Option<&'a [T]> {
fn idx(&mut self, index: usize) -> Option<&'a [T]> {
if index + self.size > self.v.len() {
None
} else {
@ -1227,7 +1227,7 @@ impl<'a, T> RandomAccessIterator for Windows<'a, T> {
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Chunks<'a, T:'a> {
v: &'a [T],
size: uint
size: usize
}
#[stable(feature = "rust1", since = "1.0.0")]
@ -1247,7 +1247,7 @@ impl<'a, T> Iterator for Chunks<'a, T> {
}
#[inline]
fn size_hint(&self) -> (uint, Option<uint>) {
fn size_hint(&self) -> (usize, Option<usize>) {
if self.v.len() == 0 {
(0, Some(0))
} else {
@ -1281,12 +1281,12 @@ impl<'a, T> ExactSizeIterator for Chunks<'a, T> {}
#[unstable(feature = "core", reason = "trait is experimental")]
impl<'a, T> RandomAccessIterator for Chunks<'a, T> {
#[inline]
fn indexable(&self) -> uint {
fn indexable(&self) -> usize {
self.v.len()/self.size + if self.v.len() % self.size != 0 { 1 } else { 0 }
}
#[inline]
fn idx(&mut self, index: uint) -> Option<&'a [T]> {
fn idx(&mut self, index: usize) -> Option<&'a [T]> {
if index < self.indexable() {
let lo = index * self.size;
let mut hi = lo + self.size;
@ -1305,7 +1305,7 @@ impl<'a, T> RandomAccessIterator for Chunks<'a, T> {
#[stable(feature = "rust1", since = "1.0.0")]
pub struct ChunksMut<'a, T:'a> {
v: &'a mut [T],
chunk_size: uint
chunk_size: usize
}
#[stable(feature = "rust1", since = "1.0.0")]
@ -1326,7 +1326,7 @@ impl<'a, T> Iterator for ChunksMut<'a, T> {
}
#[inline]
fn size_hint(&self) -> (uint, Option<uint>) {
fn size_hint(&self) -> (usize, Option<usize>) {
if self.v.len() == 0 {
(0, Some(0))
} else {
@ -1402,7 +1402,7 @@ pub fn mut_ref_slice<'a, A>(s: &'a mut A) -> &'a mut [A] {
/// use std::slice;
///
/// // manifest a slice out of thin air!
/// let ptr = 0x1234 as *const uint;
/// let ptr = 0x1234 as *const usize;
/// let amt = 10;
/// unsafe {
/// let slice = slice::from_raw_parts(ptr, amt);
@ -1410,7 +1410,7 @@ pub fn mut_ref_slice<'a, A>(s: &'a mut A) -> &'a mut [A] {
/// ```
#[inline]
#[unstable(feature = "core")]
pub unsafe fn from_raw_parts<'a, T>(p: *const T, len: uint) -> &'a [T] {
pub unsafe fn from_raw_parts<'a, T>(p: *const T, len: usize) -> &'a [T] {
transmute(RawSlice { data: p, len: len })
}
@ -1422,7 +1422,7 @@ pub unsafe fn from_raw_parts<'a, T>(p: *const T, len: uint) -> &'a [T] {
/// mutable slice.
#[inline]
#[unstable(feature = "core")]
pub unsafe fn from_raw_parts_mut<'a, T>(p: *mut T, len: uint) -> &'a mut [T] {
pub unsafe fn from_raw_parts_mut<'a, T>(p: *mut T, len: usize) -> &'a mut [T] {
transmute(RawSlice { data: p, len: len })
}
@ -1445,7 +1445,7 @@ pub unsafe fn from_raw_parts_mut<'a, T>(p: *mut T, len: uint) -> &'a mut [T] {
/// use std::slice;
///
/// // manifest a slice out of thin air!
/// let ptr = 0x1234 as *const uint;
/// let ptr = 0x1234 as *const usize;
/// let amt = 10;
/// unsafe {
/// let slice = slice::from_raw_buf(&ptr, amt);
@ -1455,7 +1455,7 @@ pub unsafe fn from_raw_parts_mut<'a, T>(p: *mut T, len: uint) -> &'a mut [T] {
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0",
reason = "use from_raw_parts")]
pub unsafe fn from_raw_buf<'a, T>(p: &'a *const T, len: uint) -> &'a [T] {
pub unsafe fn from_raw_buf<'a, T>(p: &'a *const T, len: usize) -> &'a [T] {
transmute(RawSlice { data: *p, len: len })
}
@ -1469,7 +1469,7 @@ pub unsafe fn from_raw_buf<'a, T>(p: &'a *const T, len: uint) -> &'a [T] {
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0",
reason = "use from_raw_parts_mut")]
pub unsafe fn from_raw_mut_buf<'a, T>(p: &'a *mut T, len: uint) -> &'a mut [T] {
pub unsafe fn from_raw_mut_buf<'a, T>(p: &'a *mut T, len: usize) -> &'a mut [T] {
transmute(RawSlice { data: *p, len: len })
}
@ -1606,4 +1606,4 @@ impl_int_slices! { u8, i8 }
impl_int_slices! { u16, i16 }
impl_int_slices! { u32, i32 }
impl_int_slices! { u64, i64 }
impl_int_slices! { uint, int }
impl_int_slices! { usize, isize }

View File

@ -41,7 +41,7 @@ macro_rules! delegate_iter {
delegate_iter!{$te : $ti}
impl<'a> ExactSizeIterator for $ti {
#[inline]
fn len(&self) -> uint {
fn len(&self) -> usize {
self.0.len()
}
}
@ -56,7 +56,7 @@ macro_rules! delegate_iter {
self.0.next()
}
#[inline]
fn size_hint(&self) -> (uint, Option<uint>) {
fn size_hint(&self) -> (usize, Option<usize>) {
self.0.size_hint()
}
}
@ -78,7 +78,7 @@ macro_rules! delegate_iter {
self.0.next()
}
#[inline]
fn size_hint(&self) -> (uint, Option<uint>) {
fn size_hint(&self) -> (usize, Option<usize>) {
self.0.size_hint()
}
}
@ -100,7 +100,7 @@ macro_rules! delegate_iter {
self.0.next()
}
#[inline]
fn size_hint(&self) -> (uint, Option<uint>) {
fn size_hint(&self) -> (usize, Option<usize>) {
self.0.size_hint()
}
}
@ -178,7 +178,7 @@ pub enum Utf8Error {
/// The offset is guaranteed to be in bounds of the slice in question, and
/// the byte at the specified offset was the first invalid byte in the
/// sequence detected.
InvalidByte(uint),
InvalidByte(usize),
/// The byte slice was invalid because more bytes were needed but no more
/// bytes were available.
@ -227,7 +227,7 @@ pub unsafe fn from_utf8_unchecked<'a>(v: &'a [u8]) -> &'a str {
pub unsafe fn from_c_str(s: *const i8) -> &'static str {
let s = s as *const u8;
let mut len = 0;
while *s.offset(len as int) != 0 {
while *s.offset(len as isize) != 0 {
len += 1;
}
let v: &'static [u8] = ::mem::transmute(Slice { data: s, len: len });
@ -250,7 +250,7 @@ impl CharEq for char {
fn matches(&mut self, c: char) -> bool { *self == c }
#[inline]
fn only_ascii(&self) -> bool { (*self as uint) < 128 }
fn only_ascii(&self) -> bool { (*self as u32) < 128 }
}
impl<F> CharEq for F where F: FnMut(char) -> bool {
@ -383,7 +383,7 @@ impl<'a> Iterator for Chars<'a> {
}
#[inline]
fn size_hint(&self) -> (uint, Option<uint>) {
fn size_hint(&self) -> (usize, Option<usize>) {
let (len, _) = self.iter.size_hint();
(len.saturating_add(3) / 4, Some(len))
}
@ -428,16 +428,16 @@ impl<'a> DoubleEndedIterator for Chars<'a> {
#[derive(Clone)]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct CharIndices<'a> {
front_offset: uint,
front_offset: usize,
iter: Chars<'a>,
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> Iterator for CharIndices<'a> {
type Item = (uint, char);
type Item = (usize, char);
#[inline]
fn next(&mut self) -> Option<(uint, char)> {
fn next(&mut self) -> Option<(usize, char)> {
let (pre_len, _) = self.iter.iter.size_hint();
match self.iter.next() {
None => None,
@ -451,7 +451,7 @@ impl<'a> Iterator for CharIndices<'a> {
}
#[inline]
fn size_hint(&self) -> (uint, Option<uint>) {
fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint()
}
}
@ -459,7 +459,7 @@ impl<'a> Iterator for CharIndices<'a> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> DoubleEndedIterator for CharIndices<'a> {
#[inline]
fn next_back(&mut self) -> Option<(uint, char)> {
fn next_back(&mut self) -> Option<(usize, char)> {
match self.iter.next_back() {
None => None,
Some(ch) => {
@ -512,7 +512,7 @@ struct CharSplits<'a, Sep> {
struct CharSplitsN<'a, Sep> {
iter: CharSplits<'a, Sep>,
/// The number of splits remaining
count: uint,
count: usize,
invert: bool,
}
@ -636,7 +636,7 @@ impl<'a, Sep: CharEq> Iterator for CharSplitsN<'a, Sep> {
/// within a larger string using naive search
#[derive(Clone)]
struct NaiveSearcher {
position: uint
position: usize
}
impl NaiveSearcher {
@ -644,7 +644,7 @@ impl NaiveSearcher {
NaiveSearcher { position: 0 }
}
fn next(&mut self, haystack: &[u8], needle: &[u8]) -> Option<(uint, uint)> {
fn next(&mut self, haystack: &[u8], needle: &[u8]) -> Option<(usize, usize)> {
while self.position + needle.len() <= haystack.len() {
if &haystack[self.position .. self.position + needle.len()] == needle {
let match_pos = self.position;
@ -663,13 +663,13 @@ impl NaiveSearcher {
#[derive(Clone)]
struct TwoWaySearcher {
// constants
crit_pos: uint,
period: uint,
crit_pos: usize,
period: usize,
byteset: u64,
// variables
position: uint,
memory: uint
position: usize,
memory: usize
}
/*
@ -756,7 +756,7 @@ impl TwoWaySearcher {
// This isn't in the original algorithm, as far as I'm aware.
let byteset = needle.iter()
.fold(0, |a, &b| (1 << ((b & 0x3f) as uint)) | a);
.fold(0, |a, &b| (1 << ((b & 0x3f) as usize)) | a);
// A particularly readable explanation of what's going on here can be found
// in Crochemore and Rytter's book "Text Algorithms", ch 13. Specifically
@ -794,7 +794,8 @@ impl TwoWaySearcher {
// How far we can jump when we encounter a mismatch is all based on the fact
// that (u, v) is a critical factorization for the needle.
#[inline]
fn next(&mut self, haystack: &[u8], needle: &[u8], long_period: bool) -> Option<(uint, uint)> {
fn next(&mut self, haystack: &[u8], needle: &[u8], long_period: bool)
-> Option<(usize, usize)> {
'search: loop {
// Check that we have room to search in
if self.position + needle.len() > haystack.len() {
@ -804,7 +805,7 @@ impl TwoWaySearcher {
// Quickly skip by large portions unrelated to our substring
if (self.byteset >>
((haystack[self.position + needle.len() - 1] & 0x3f)
as uint)) & 1 == 0 {
as usize)) & 1 == 0 {
self.position += needle.len();
if !long_period {
self.memory = 0;
@ -851,7 +852,7 @@ impl TwoWaySearcher {
// Specifically, returns (i, p), where i is the starting index of v in some
// critical factorization (u, v) and p = period(v)
#[inline]
fn maximal_suffix(arr: &[u8], reversed: bool) -> (uint, uint) {
fn maximal_suffix(arr: &[u8], reversed: bool) -> (usize, usize) {
let mut left = -1; // Corresponds to i in the paper
let mut right = 0; // Corresponds to j in the paper
let mut offset = 1; // Corresponds to k in the paper
@ -937,16 +938,16 @@ pub struct MatchIndices<'a> {
#[unstable(feature = "core", reason = "type may be removed")]
pub struct SplitStr<'a> {
it: MatchIndices<'a>,
last_end: uint,
last_end: usize,
finished: bool
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> Iterator for MatchIndices<'a> {
type Item = (uint, uint);
type Item = (usize, usize);
#[inline]
fn next(&mut self) -> Option<(uint, uint)> {
fn next(&mut self) -> Option<(usize, usize)> {
match self.searcher {
Naive(ref mut searcher)
=> searcher.next(self.haystack.as_bytes(), self.needle.as_bytes()),
@ -991,8 +992,9 @@ Section: Comparing strings
/// to compare &[u8] byte slices that are not necessarily valid UTF-8.
#[inline]
fn eq_slice_(a: &str, b: &str) -> bool {
// NOTE: In theory n should be libc::size_t and not usize, but libc is not available here
#[allow(improper_ctypes)]
extern { fn memcmp(s1: *const i8, s2: *const i8, n: uint) -> i32; }
extern { fn memcmp(s1: *const i8, s2: *const i8, n: usize) -> i32; }
a.len() == b.len() && unsafe {
memcmp(a.as_ptr() as *const i8,
b.as_ptr() as *const i8,
@ -1049,7 +1051,7 @@ fn run_utf8_validation_iterator(iter: &mut slice::Iter<u8>)
// ASCII characters are always valid, so only large
// bytes need more examination.
if first >= 128 {
let w = UTF8_CHAR_WIDTH[first as uint] as uint;
let w = UTF8_CHAR_WIDTH[first as usize] as usize;
let second = next!();
// 2-byte encoding is for codepoints \u{0080} to \u{07ff}
// first C2 80 last DF BF
@ -1124,7 +1126,7 @@ pub struct CharRange {
/// Current `char`
pub ch: char,
/// Index of the first byte of the next `char`
pub next: uint,
pub next: usize,
}
/// Mask of the value bits of a continuation byte
@ -1209,10 +1211,10 @@ mod traits {
/// // &s[3 .. 100];
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
impl ops::Index<ops::Range<uint>> for str {
impl ops::Index<ops::Range<usize>> for str {
type Output = str;
#[inline]
fn index(&self, index: &ops::Range<uint>) -> &str {
fn index(&self, index: &ops::Range<usize>) -> &str {
// is_char_boundary checks that the index is in [0, .len()]
if index.start <= index.end &&
self.is_char_boundary(index.start) &&
@ -1232,10 +1234,10 @@ mod traits {
/// Panics when `end` does not point to a valid character, or is
/// out of bounds.
#[stable(feature = "rust1", since = "1.0.0")]
impl ops::Index<ops::RangeTo<uint>> for str {
impl ops::Index<ops::RangeTo<usize>> for str {
type Output = str;
#[inline]
fn index(&self, index: &ops::RangeTo<uint>) -> &str {
fn index(&self, index: &ops::RangeTo<usize>) -> &str {
// is_char_boundary checks that the index is in [0, .len()]
if self.is_char_boundary(index.end) {
unsafe { self.slice_unchecked(0, index.end) }
@ -1252,10 +1254,10 @@ mod traits {
/// Panics when `begin` does not point to a valid character, or is
/// out of bounds.
#[stable(feature = "rust1", since = "1.0.0")]
impl ops::Index<ops::RangeFrom<uint>> for str {
impl ops::Index<ops::RangeFrom<usize>> for str {
type Output = str;
#[inline]
fn index(&self, index: &ops::RangeFrom<uint>) -> &str {
fn index(&self, index: &ops::RangeFrom<usize>) -> &str {
// is_char_boundary checks that the index is in [0, .len()]
if self.is_char_boundary(index.start) {
unsafe { self.slice_unchecked(index.start, self.len()) }
@ -1332,40 +1334,40 @@ pub trait StrExt {
fn bytes<'a>(&'a self) -> Bytes<'a>;
fn char_indices<'a>(&'a self) -> CharIndices<'a>;
fn split<'a, P: CharEq>(&'a self, pat: P) -> Split<'a, P>;
fn splitn<'a, P: CharEq>(&'a self, count: uint, pat: P) -> SplitN<'a, P>;
fn splitn<'a, P: CharEq>(&'a self, count: usize, pat: P) -> SplitN<'a, P>;
fn split_terminator<'a, P: CharEq>(&'a self, pat: P) -> SplitTerminator<'a, P>;
fn rsplitn<'a, P: CharEq>(&'a self, count: uint, pat: P) -> RSplitN<'a, P>;
fn rsplitn<'a, P: CharEq>(&'a self, count: usize, pat: P) -> RSplitN<'a, P>;
fn match_indices<'a>(&'a self, sep: &'a str) -> MatchIndices<'a>;
fn split_str<'a>(&'a self, pat: &'a str) -> SplitStr<'a>;
fn lines<'a>(&'a self) -> Lines<'a>;
fn lines_any<'a>(&'a self) -> LinesAny<'a>;
fn char_len(&self) -> uint;
fn slice_chars<'a>(&'a self, begin: uint, end: uint) -> &'a str;
unsafe fn slice_unchecked<'a>(&'a self, begin: uint, end: uint) -> &'a str;
fn char_len(&self) -> usize;
fn slice_chars<'a>(&'a self, begin: usize, end: usize) -> &'a str;
unsafe fn slice_unchecked<'a>(&'a self, begin: usize, end: usize) -> &'a str;
fn starts_with(&self, pat: &str) -> bool;
fn ends_with(&self, pat: &str) -> bool;
fn trim_matches<'a, P: CharEq>(&'a self, pat: P) -> &'a str;
fn trim_left_matches<'a, P: CharEq>(&'a self, pat: P) -> &'a str;
fn trim_right_matches<'a, P: CharEq>(&'a self, pat: P) -> &'a str;
fn is_char_boundary(&self, index: uint) -> bool;
fn char_range_at(&self, start: uint) -> CharRange;
fn char_range_at_reverse(&self, start: uint) -> CharRange;
fn char_at(&self, i: uint) -> char;
fn char_at_reverse(&self, i: uint) -> char;
fn is_char_boundary(&self, index: usize) -> bool;
fn char_range_at(&self, start: usize) -> CharRange;
fn char_range_at_reverse(&self, start: usize) -> CharRange;
fn char_at(&self, i: usize) -> char;
fn char_at_reverse(&self, i: usize) -> char;
fn as_bytes<'a>(&'a self) -> &'a [u8];
fn find<P: CharEq>(&self, pat: P) -> Option<uint>;
fn rfind<P: CharEq>(&self, pat: P) -> Option<uint>;
fn find_str(&self, pat: &str) -> Option<uint>;
fn find<P: CharEq>(&self, pat: P) -> Option<usize>;
fn rfind<P: CharEq>(&self, pat: P) -> Option<usize>;
fn find_str(&self, pat: &str) -> Option<usize>;
fn slice_shift_char<'a>(&'a self) -> Option<(char, &'a str)>;
fn subslice_offset(&self, inner: &str) -> uint;
fn subslice_offset(&self, inner: &str) -> usize;
fn as_ptr(&self) -> *const u8;
fn len(&self) -> uint;
fn len(&self) -> usize;
fn is_empty(&self) -> bool;
fn parse<T: FromStr>(&self) -> Result<T, T::Err>;
}
#[inline(never)]
fn slice_error_fail(s: &str, begin: uint, end: uint) -> ! {
fn slice_error_fail(s: &str, begin: usize, end: usize) -> ! {
assert!(begin <= end);
panic!("index {} and/or {} in `{}` do not lie on character boundary",
begin, end, s);
@ -1409,7 +1411,7 @@ impl StrExt for str {
}
#[inline]
fn splitn<P: CharEq>(&self, count: uint, pat: P) -> SplitN<P> {
fn splitn<P: CharEq>(&self, count: usize, pat: P) -> SplitN<P> {
SplitN(CharSplitsN {
iter: self.split(pat).0,
count: count,
@ -1426,7 +1428,7 @@ impl StrExt for str {
}
#[inline]
fn rsplitn<P: CharEq>(&self, count: uint, pat: P) -> RSplitN<P> {
fn rsplitn<P: CharEq>(&self, count: usize, pat: P) -> RSplitN<P> {
RSplitN(CharSplitsN {
iter: self.split(pat).0,
count: count,
@ -1470,9 +1472,9 @@ impl StrExt for str {
}
#[inline]
fn char_len(&self) -> uint { self.chars().count() }
fn char_len(&self) -> usize { self.chars().count() }
fn slice_chars(&self, begin: uint, end: uint) -> &str {
fn slice_chars(&self, begin: usize, end: usize) -> &str {
assert!(begin <= end);
let mut count = 0;
let mut begin_byte = None;
@ -1496,9 +1498,9 @@ impl StrExt for str {
}
#[inline]
unsafe fn slice_unchecked(&self, begin: uint, end: uint) -> &str {
unsafe fn slice_unchecked(&self, begin: usize, end: usize) -> &str {
mem::transmute(Slice {
data: self.as_ptr().offset(begin as int),
data: self.as_ptr().offset(begin as isize),
len: end - begin,
})
}
@ -1550,7 +1552,7 @@ impl StrExt for str {
}
#[inline]
fn is_char_boundary(&self, index: uint) -> bool {
fn is_char_boundary(&self, index: usize) -> bool {
if index == self.len() { return true; }
match self.as_bytes().get(index) {
None => false,
@ -1559,13 +1561,13 @@ impl StrExt for str {
}
#[inline]
fn char_range_at(&self, i: uint) -> CharRange {
fn char_range_at(&self, i: usize) -> CharRange {
let (c, n) = char_range_at_raw(self.as_bytes(), i);
CharRange { ch: unsafe { mem::transmute(c) }, next: n }
}
#[inline]
fn char_range_at_reverse(&self, start: uint) -> CharRange {
fn char_range_at_reverse(&self, start: usize) -> CharRange {
let mut prev = start;
prev = prev.saturating_sub(1);
@ -1574,14 +1576,14 @@ impl StrExt for str {
}
// Multibyte case is a fn to allow char_range_at_reverse to inline cleanly
fn multibyte_char_range_at_reverse(s: &str, mut i: uint) -> CharRange {
fn multibyte_char_range_at_reverse(s: &str, mut i: usize) -> CharRange {
// while there is a previous byte == 10......
while i > 0 && s.as_bytes()[i] & !CONT_MASK == TAG_CONT_U8 {
i -= 1;
}
let mut val = s.as_bytes()[i] as u32;
let w = UTF8_CHAR_WIDTH[val as uint] as uint;
let w = UTF8_CHAR_WIDTH[val as usize] as usize;
assert!((w != 0));
val = utf8_first_byte!(val, w);
@ -1596,12 +1598,12 @@ impl StrExt for str {
}
#[inline]
fn char_at(&self, i: uint) -> char {
fn char_at(&self, i: usize) -> char {
self.char_range_at(i).ch
}
#[inline]
fn char_at_reverse(&self, i: uint) -> char {
fn char_at_reverse(&self, i: usize) -> char {
self.char_range_at_reverse(i).ch
}
@ -1610,7 +1612,7 @@ impl StrExt for str {
unsafe { mem::transmute(self) }
}
fn find<P: CharEq>(&self, mut pat: P) -> Option<uint> {
fn find<P: CharEq>(&self, mut pat: P) -> Option<usize> {
if pat.only_ascii() {
self.bytes().position(|b| pat.matches(b as char))
} else {
@ -1621,7 +1623,7 @@ impl StrExt for str {
}
}
fn rfind<P: CharEq>(&self, mut pat: P) -> Option<uint> {
fn rfind<P: CharEq>(&self, mut pat: P) -> Option<usize> {
if pat.only_ascii() {
self.bytes().rposition(|b| pat.matches(b as char))
} else {
@ -1632,7 +1634,7 @@ impl StrExt for str {
}
}
fn find_str(&self, needle: &str) -> Option<uint> {
fn find_str(&self, needle: &str) -> Option<usize> {
if needle.is_empty() {
Some(0)
} else {
@ -1653,10 +1655,10 @@ impl StrExt for str {
}
}
fn subslice_offset(&self, inner: &str) -> uint {
let a_start = self.as_ptr() as uint;
fn subslice_offset(&self, inner: &str) -> usize {
let a_start = self.as_ptr() as usize;
let a_end = a_start + self.len();
let b_start = inner.as_ptr() as uint;
let b_start = inner.as_ptr() as usize;
let b_end = b_start + inner.len();
assert!(a_start <= b_start);
@ -1670,7 +1672,7 @@ impl StrExt for str {
}
#[inline]
fn len(&self) -> uint { self.repr().len }
fn len(&self) -> usize { self.repr().len }
#[inline]
fn is_empty(&self) -> bool { self.len() == 0 }
@ -1683,15 +1685,15 @@ impl StrExt for str {
/// index of the next code point.
#[inline]
#[unstable(feature = "core")]
pub fn char_range_at_raw(bytes: &[u8], i: uint) -> (u32, usize) {
pub fn char_range_at_raw(bytes: &[u8], i: usize) -> (u32, usize) {
if bytes[i] < 128u8 {
return (bytes[i] as u32, i + 1);
}
// Multibyte case is a fn to allow char_range_at to inline cleanly
fn multibyte_char_range_at(bytes: &[u8], i: uint) -> (u32, usize) {
fn multibyte_char_range_at(bytes: &[u8], i: usize) -> (u32, usize) {
let mut val = bytes[i] as u32;
let w = UTF8_CHAR_WIDTH[val as uint] as uint;
let w = UTF8_CHAR_WIDTH[val as usize] as usize;
assert!((w != 0));
val = utf8_first_byte!(val, w);
@ -1718,7 +1720,7 @@ impl<'a> Iterator for Lines<'a> {
#[inline]
fn next(&mut self) -> Option<&'a str> { self.inner.next() }
#[inline]
fn size_hint(&self) -> (uint, Option<uint>) { self.inner.size_hint() }
fn size_hint(&self) -> (usize, Option<usize>) { self.inner.size_hint() }
}
#[stable(feature = "rust1", since = "1.0.0")]
@ -1734,7 +1736,7 @@ impl<'a> Iterator for LinesAny<'a> {
#[inline]
fn next(&mut self) -> Option<&'a str> { self.inner.next() }
#[inline]
fn size_hint(&self) -> (uint, Option<uint>) { self.inner.size_hint() }
fn size_hint(&self) -> (usize, Option<usize>) { self.inner.size_hint() }
}
#[stable(feature = "rust1", since = "1.0.0")]

View File

@ -11,7 +11,7 @@
#![feature(box_syntax)]
#![feature(int_uint)]
#![feature(unboxed_closures)]
#![feature(unsafe_destructor, slicing_syntax)]
#![feature(unsafe_destructor)]
#![allow(deprecated)] // rand
extern crate core;

View File

@ -25,7 +25,6 @@
html_playground_url = "http://play.rust-lang.org/")]
#![feature(int_uint)]
#![feature(slicing_syntax)]
#![feature(staged_api)]
#![feature(unicode)]
@ -422,7 +421,7 @@ impl<'a> Parser<'a> {
Some((_, c)) => {
match c.to_digit(10) {
Some(i) => {
cur = cur * 10 + i;
cur = cur * 10 + i as usize;
found = true;
self.cur.next();
}

View File

@ -91,7 +91,6 @@
#![deny(missing_docs)]
#![feature(collections)]
#![feature(int_uint)]
#![feature(slicing_syntax)]
#![feature(staged_api)]
#![cfg_attr(test, feature(rustc_private))]

View File

@ -273,7 +273,6 @@
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/nightly/")]
#![feature(slicing_syntax)]
#![feature(int_uint)]
#![feature(collections)]
#![feature(core)]

View File

@ -168,7 +168,6 @@
#![deny(missing_docs)]
#![feature(staged_api)]
#![feature(slicing_syntax)]
#![feature(box_syntax)]
#![feature(int_uint)]
#![feature(core)]

View File

@ -30,7 +30,6 @@
#![feature(int_uint)]
#![feature(io)]
#![feature(rustc_private)]
#![feature(slicing_syntax)]
#![feature(staged_api)]
extern crate serialize;

View File

@ -36,7 +36,7 @@
#![feature(quote)]
#![feature(rustc_diagnostic_macros)]
#![feature(rustc_private)]
#![feature(slicing_syntax, unsafe_destructor)]
#![feature(unsafe_destructor)]
#![feature(staged_api)]
#![feature(std_misc)]
#![feature(unicode)]

View File

@ -318,8 +318,8 @@ impl LintPass for TypeLimits {
fn float_ty_range(float_ty: ast::FloatTy) -> (f64, f64) {
match float_ty {
ast::TyF32 => (f32::MIN_VALUE as f64, f32::MAX_VALUE as f64),
ast::TyF64 => (f64::MIN_VALUE, f64::MAX_VALUE)
ast::TyF32 => (f32::MIN as f64, f32::MAX as f64),
ast::TyF64 => (f64::MIN, f64::MAX)
}
}
@ -674,6 +674,7 @@ impl LintPass for UnusedAttributes {
"stable",
"unstable",
"rustc_on_unimplemented",
"rustc_error",
// FIXME: #19470 this shouldn't be needed forever
"old_orphan_check",

View File

@ -271,7 +271,7 @@ lets_do_this! {
RangeToStructLangItem, "range_to", range_to_struct;
RangeFullStructLangItem, "range_full", range_full_struct;
UnsafeTypeLangItem, "unsafe", unsafe_type;
UnsafeCellTypeLangItem, "unsafe_cell", unsafe_cell_type;
DerefTraitLangItem, "deref", deref_trait;
DerefMutTraitLangItem, "deref_mut", deref_mut_trait;

View File

@ -1654,7 +1654,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
ty::BoundSync => {
if
Some(def_id) == tcx.lang_items.managed_bound() ||
Some(def_id) == tcx.lang_items.unsafe_type()
Some(def_id) == tcx.lang_items.unsafe_cell_type()
{
return Err(Unimplemented)
}

View File

@ -3577,7 +3577,7 @@ pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents {
-> TypeContents {
if Some(did) == cx.lang_items.managed_bound() {
tc | TC::Managed
} else if Some(did) == cx.lang_items.unsafe_type() {
} else if Some(did) == cx.lang_items.unsafe_cell_type() {
tc | TC::InteriorUnsafe
} else {
tc

View File

@ -73,8 +73,11 @@ fn pre_link_args(arch: Arch) -> Vec<String> {
fn target_cpu(arch: Arch) -> String {
match arch {
Armv7 => "cortex-a8", // iOS7 is supported on iPhone 4 and higher
Armv7s => "cortex-a9",
Arm64 => "cyclone",
I386 => "generic",
X86_64 => "x86-64",
_ => "generic",
}.to_string()
}

View File

@ -384,8 +384,7 @@ impl Target {
Path::new(target)
};
let target_path = env::var_os("RUST_TARGET_PATH")
.unwrap_or(OsString::from_str(""));
let target_path = env::var_os("RUST_TARGET_PATH").unwrap_or(OsString::from_str(""));
// FIXME 16351: add a sane default search path?

View File

@ -35,7 +35,7 @@
#![feature(quote)]
#![feature(rustc_diagnostic_macros)]
#![feature(rustc_private)]
#![feature(slicing_syntax, unsafe_destructor)]
#![feature(unsafe_destructor)]
#![feature(staged_api)]
#![feature(std_misc)]
#![feature(unicode)]
@ -477,6 +477,10 @@ pub fn commit_date_str() -> Option<&'static str> {
option_env!("CFG_VER_DATE")
}
pub fn build_date_str() -> Option<&'static str> {
option_env!("CFG_BUILD_DATE")
}
/// Prints version information and returns None on success or an error
/// message on panic.
pub fn version(binary: &str, matches: &getopts::Matches) {
@ -488,6 +492,7 @@ pub fn version(binary: &str, matches: &getopts::Matches) {
println!("binary: {}", binary);
println!("commit-hash: {}", unw(commit_hash_str()));
println!("commit-date: {}", unw(commit_date_str()));
println!("build-date: {}", unw(build_date_str()));
println!("host: {}", config::host_triple());
println!("release: {}", unw(release_str()));
}

View File

@ -24,7 +24,6 @@
#![feature(int_uint)]
#![feature(rustc_diagnostic_macros)]
#![feature(rustc_private)]
#![feature(slicing_syntax)]
#![feature(staged_api)]
#![feature(std_misc)]

View File

@ -37,7 +37,7 @@
#![feature(quote)]
#![feature(rustc_diagnostic_macros)]
#![feature(rustc_private)]
#![feature(slicing_syntax, unsafe_destructor)]
#![feature(unsafe_destructor)]
#![feature(staged_api)]
#![feature(std_misc)]
#![feature(unicode)]

View File

@ -2425,6 +2425,14 @@ fn finish_register_fn(ccx: &CrateContext, sp: Span, sym: String, node_id: ast::N
if is_entry_fn(ccx.sess(), node_id) {
// check for the #[rustc_error] annotation, which forces an
// error in trans. This is used to write compile-fail tests
// that actually test that compilation succeeds without
// reporting an error.
if ty::has_attr(ccx.tcx(), local_def(node_id), "rustc_error") {
ccx.tcx().sess.span_fatal(sp, "compilation successful");
}
create_entry_wrapper(ccx, sp, llfn);
}
}

View File

@ -83,7 +83,7 @@ This API is completely unstable and subject to change.
#![feature(quote)]
#![feature(rustc_diagnostic_macros)]
#![feature(rustc_private)]
#![feature(slicing_syntax, unsafe_destructor)]
#![feature(unsafe_destructor)]
#![feature(staged_api)]
#[macro_use] extern crate log;

View File

@ -412,7 +412,7 @@ struct ConstraintContext<'a, 'tcx: 'a> {
invariant_lang_items: [Option<ast::DefId>; 2],
covariant_lang_items: [Option<ast::DefId>; 2],
contravariant_lang_items: [Option<ast::DefId>; 2],
unsafe_lang_item: Option<ast::DefId>,
unsafe_cell_lang_item: Option<ast::DefId>,
// These are pointers to common `ConstantTerm` instances
covariant: VarianceTermPtr<'a>,
@ -453,7 +453,7 @@ fn add_constraints_from_crate<'a, 'tcx>(terms_cx: TermsContext<'a, 'tcx>,
invariant_lang_items[RegionParam as uint] =
terms_cx.tcx.lang_items.invariant_lifetime();
let unsafe_lang_item = terms_cx.tcx.lang_items.unsafe_type();
let unsafe_cell_lang_item = terms_cx.tcx.lang_items.unsafe_cell_type();
let covariant = terms_cx.arena.alloc(ConstantTerm(ty::Covariant));
let contravariant = terms_cx.arena.alloc(ConstantTerm(ty::Contravariant));
@ -465,7 +465,7 @@ fn add_constraints_from_crate<'a, 'tcx>(terms_cx: TermsContext<'a, 'tcx>,
invariant_lang_items: invariant_lang_items,
covariant_lang_items: covariant_lang_items,
contravariant_lang_items: contravariant_lang_items,
unsafe_lang_item: unsafe_lang_item,
unsafe_cell_lang_item: unsafe_cell_lang_item,
covariant: covariant,
contravariant: contravariant,
@ -654,7 +654,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
self.covariant
} else if self.contravariant_lang_items[kind as uint] == Some(item_def_id) {
self.contravariant
} else if kind == TypeParam && Some(item_def_id) == self.unsafe_lang_item {
} else if kind == TypeParam && Some(item_def_id) == self.unsafe_cell_lang_item {
self.invariant
} else if param_def_id.krate == ast::LOCAL_CRATE {
// Parameter on an item defined within current crate:

View File

@ -1849,6 +1849,7 @@ fn render_method(w: &mut fmt::Formatter, meth: &clean::Item) -> fmt::Result {
fn item_struct(w: &mut fmt::Formatter, it: &clean::Item,
s: &clean::Struct) -> fmt::Result {
try!(write!(w, "<pre class='rust struct'>"));
try!(render_attributes(w, it));
try!(render_struct(w,
it,
Some(&s.generics),
@ -1885,7 +1886,9 @@ fn item_struct(w: &mut fmt::Formatter, it: &clean::Item,
fn item_enum(w: &mut fmt::Formatter, it: &clean::Item,
e: &clean::Enum) -> fmt::Result {
try!(write!(w, "<pre class='rust enum'>{}enum {}{}{}",
try!(write!(w, "<pre class='rust enum'>"));
try!(render_attributes(w, it));
try!(write!(w, "{}enum {}{}{}",
VisSpace(it.visibility),
it.name.as_ref().unwrap(),
e.generics,
@ -1982,6 +1985,21 @@ fn item_enum(w: &mut fmt::Formatter, it: &clean::Item,
Ok(())
}
fn render_attributes(w: &mut fmt::Formatter, it: &clean::Item) -> fmt::Result {
for attr in &it.attrs {
match *attr {
clean::Word(ref s) if *s == "must_use" => {
try!(write!(w, "#[{}]\n", s));
}
clean::NameValue(ref k, ref v) if *k == "must_use" => {
try!(write!(w, "#[{} = \"{}\"]\n", k, v));
}
_ => ()
}
}
Ok(())
}
fn render_struct(w: &mut fmt::Formatter, it: &clean::Item,
g: Option<&clean::Generics>,
ty: doctree::StructType,

View File

@ -30,7 +30,6 @@
#![feature(os)]
#![feature(path)]
#![feature(rustc_private)]
#![feature(slicing_syntax)]
#![feature(staged_api)]
#![feature(std_misc)]
#![feature(test)]

View File

@ -33,7 +33,6 @@ Core encoding and decoding interfaces.
#![feature(path)]
#![feature(hash)]
#![feature(rustc_private)]
#![feature(slicing_syntax)]
#![feature(staged_api)]
#![feature(std_misc)]
#![feature(unicode)]

View File

@ -159,12 +159,12 @@ impl AsciiExt for u8 {
#[inline]
fn to_ascii_uppercase(&self) -> u8 {
ASCII_UPPERCASE_MAP[*self as uint]
ASCII_UPPERCASE_MAP[*self as usize]
}
#[inline]
fn to_ascii_lowercase(&self) -> u8 {
ASCII_LOWERCASE_MAP[*self as uint]
ASCII_LOWERCASE_MAP[*self as usize]
}
#[inline]

View File

@ -189,7 +189,7 @@ impl OsStr {
self.inner.to_string_lossy()
}
/// Copy the slice into an onwed `OsString`.
/// Copy the slice into an owned `OsString`.
pub fn to_os_string(&self) -> OsString {
OsString { inner: self.inner.to_owned() }
}

View File

@ -279,7 +279,7 @@ pub mod sync;
#[path = "sys/common/mod.rs"] mod sys_common;
pub mod rt;
mod failure;
mod panicking;
// Documentation for primitive types

View File

@ -30,6 +30,7 @@ use core::num;
pub use core::f32::{RADIX, MANTISSA_DIGITS, DIGITS, EPSILON, MIN_VALUE};
pub use core::f32::{MIN_POS_VALUE, MAX_VALUE, MIN_EXP, MAX_EXP, MIN_10_EXP};
pub use core::f32::{MAX_10_EXP, NAN, INFINITY, NEG_INFINITY};
pub use core::f32::{MIN, MIN_POSITIVE, MAX};
pub use core::f32::consts;
#[allow(dead_code)]
@ -369,7 +370,7 @@ impl Float for f32 {
#[unstable(feature = "std_misc", reason = "may be removed or relocated")]
pub fn to_string(num: f32) -> String {
let (r, _) = strconv::float_to_str_common(
num, 10u, true, SignNeg, DigAll, ExpNone, false);
num, 10, true, SignNeg, DigAll, ExpNone, false);
r
}
@ -382,7 +383,7 @@ pub fn to_string(num: f32) -> String {
#[unstable(feature = "std_misc", reason = "may be removed or relocated")]
pub fn to_str_hex(num: f32) -> String {
let (r, _) = strconv::float_to_str_common(
num, 16u, true, SignNeg, DigAll, ExpNone, false);
num, 16, true, SignNeg, DigAll, ExpNone, false);
r
}
@ -395,7 +396,7 @@ pub fn to_str_hex(num: f32) -> String {
/// * radix - The base to use
#[inline]
#[unstable(feature = "std_misc", reason = "may be removed or relocated")]
pub fn to_str_radix_special(num: f32, rdx: uint) -> (String, bool) {
pub fn to_str_radix_special(num: f32, rdx: u32) -> (String, bool) {
strconv::float_to_str_common(num, rdx, true, SignNeg, DigAll, ExpNone, false)
}
@ -410,7 +411,7 @@ pub fn to_str_radix_special(num: f32, rdx: uint) -> (String, bool) {
#[unstable(feature = "std_misc", reason = "may be removed or relocated")]
pub fn to_str_exact(num: f32, dig: uint) -> String {
let (r, _) = strconv::float_to_str_common(
num, 10u, true, SignNeg, DigExact(dig), ExpNone, false);
num, 10, true, SignNeg, DigExact(dig), ExpNone, false);
r
}
@ -425,7 +426,7 @@ pub fn to_str_exact(num: f32, dig: uint) -> String {
#[unstable(feature = "std_misc", reason = "may be removed or relocated")]
pub fn to_str_digits(num: f32, dig: uint) -> String {
let (r, _) = strconv::float_to_str_common(
num, 10u, true, SignNeg, DigMax(dig), ExpNone, false);
num, 10, true, SignNeg, DigMax(dig), ExpNone, false);
r
}
@ -441,7 +442,7 @@ pub fn to_str_digits(num: f32, dig: uint) -> String {
#[unstable(feature = "std_misc", reason = "may be removed or relocated")]
pub fn to_str_exp_exact(num: f32, dig: uint, upper: bool) -> String {
let (r, _) = strconv::float_to_str_common(
num, 10u, true, SignNeg, DigExact(dig), ExpDec, upper);
num, 10, true, SignNeg, DigExact(dig), ExpDec, upper);
r
}
@ -457,7 +458,7 @@ pub fn to_str_exp_exact(num: f32, dig: uint, upper: bool) -> String {
#[unstable(feature = "std_misc", reason = "may be removed or relocated")]
pub fn to_str_exp_digits(num: f32, dig: uint, upper: bool) -> String {
let (r, _) = strconv::float_to_str_common(
num, 10u, true, SignNeg, DigMax(dig), ExpDec, upper);
num, 10, true, SignNeg, DigMax(dig), ExpDec, upper);
r
}

View File

@ -29,6 +29,7 @@ use core::num;
pub use core::f64::{RADIX, MANTISSA_DIGITS, DIGITS, EPSILON, MIN_VALUE};
pub use core::f64::{MIN_POS_VALUE, MAX_VALUE, MIN_EXP, MAX_EXP, MIN_10_EXP};
pub use core::f64::{MAX_10_EXP, NAN, INFINITY, NEG_INFINITY};
pub use core::f64::{MIN, MIN_POSITIVE, MAX};
pub use core::f64::consts;
#[allow(dead_code)]
@ -378,7 +379,7 @@ impl Float for f64 {
#[unstable(feature = "std_misc", reason = "may be removed or relocated")]
pub fn to_string(num: f64) -> String {
let (r, _) = strconv::float_to_str_common(
num, 10u, true, SignNeg, DigAll, ExpNone, false);
num, 10, true, SignNeg, DigAll, ExpNone, false);
r
}
@ -391,7 +392,7 @@ pub fn to_string(num: f64) -> String {
#[unstable(feature = "std_misc", reason = "may be removed or relocated")]
pub fn to_str_hex(num: f64) -> String {
let (r, _) = strconv::float_to_str_common(
num, 16u, true, SignNeg, DigAll, ExpNone, false);
num, 16, true, SignNeg, DigAll, ExpNone, false);
r
}
@ -404,7 +405,7 @@ pub fn to_str_hex(num: f64) -> String {
/// * radix - The base to use
#[inline]
#[unstable(feature = "std_misc", reason = "may be removed or relocated")]
pub fn to_str_radix_special(num: f64, rdx: uint) -> (String, bool) {
pub fn to_str_radix_special(num: f64, rdx: u32) -> (String, bool) {
strconv::float_to_str_common(num, rdx, true, SignNeg, DigAll, ExpNone, false)
}
@ -419,7 +420,7 @@ pub fn to_str_radix_special(num: f64, rdx: uint) -> (String, bool) {
#[unstable(feature = "std_misc", reason = "may be removed or relocated")]
pub fn to_str_exact(num: f64, dig: uint) -> String {
let (r, _) = strconv::float_to_str_common(
num, 10u, true, SignNeg, DigExact(dig), ExpNone, false);
num, 10, true, SignNeg, DigExact(dig), ExpNone, false);
r
}
@ -434,7 +435,7 @@ pub fn to_str_exact(num: f64, dig: uint) -> String {
#[unstable(feature = "std_misc", reason = "may be removed or relocated")]
pub fn to_str_digits(num: f64, dig: uint) -> String {
let (r, _) = strconv::float_to_str_common(
num, 10u, true, SignNeg, DigMax(dig), ExpNone, false);
num, 10, true, SignNeg, DigMax(dig), ExpNone, false);
r
}
@ -450,7 +451,7 @@ pub fn to_str_digits(num: f64, dig: uint) -> String {
#[unstable(feature = "std_misc", reason = "may be removed or relocated")]
pub fn to_str_exp_exact(num: f64, dig: uint, upper: bool) -> String {
let (r, _) = strconv::float_to_str_common(
num, 10u, true, SignNeg, DigExact(dig), ExpDec, upper);
num, 10, true, SignNeg, DigExact(dig), ExpDec, upper);
r
}
@ -466,7 +467,7 @@ pub fn to_str_exp_exact(num: f64, dig: uint, upper: bool) -> String {
#[unstable(feature = "std_misc", reason = "may be removed or relocated")]
pub fn to_str_exp_digits(num: f64, dig: uint, upper: bool) -> String {
let (r, _) = strconv::float_to_str_common(
num, 10u, true, SignNeg, DigMax(dig), ExpDec, upper);
num, 10, true, SignNeg, DigMax(dig), ExpDec, upper);
r
}

View File

@ -182,7 +182,7 @@ fn int_to_str_bytes_common<T, F>(num: T, radix: uint, sign: SignFormat, mut f: F
/// - Panics if `radix` > 25 and `exp_format` is `ExpBin` due to conflict
/// between digit and exponent sign `'p'`.
pub fn float_to_str_bytes_common<T: Float>(
num: T, radix: uint, negative_zero: bool,
num: T, radix: u32, negative_zero: bool,
sign: SignFormat, digits: SignificantDigits, exp_format: ExponentFormat, exp_upper: bool
) -> (Vec<u8>, bool) {
assert!(2 <= radix && radix <= 36);
@ -253,7 +253,7 @@ pub fn float_to_str_bytes_common<T: Float>(
deccum = deccum / radix_gen;
deccum = deccum.trunc();
buf.push(char::from_digit(current_digit.to_int().unwrap() as uint, radix)
buf.push(char::from_digit(current_digit.to_int().unwrap() as u32, radix)
.unwrap() as u8);
// No more digits to calculate for the non-fractional part -> break
@ -310,7 +310,7 @@ pub fn float_to_str_bytes_common<T: Float>(
let current_digit = deccum.trunc().abs();
buf.push(char::from_digit(
current_digit.to_int().unwrap() as uint, radix).unwrap() as u8);
current_digit.to_int().unwrap() as u32, radix).unwrap() as u8);
// Decrease the deccumulator one fractional digit at a time
deccum = deccum.fract();
@ -324,7 +324,7 @@ pub fn float_to_str_bytes_common<T: Float>(
let ascii2value = |chr: u8| {
(chr as char).to_digit(radix).unwrap()
};
let value2ascii = |val: uint| {
let value2ascii = |val: u32| {
char::from_digit(val, radix).unwrap() as u8
};
@ -412,7 +412,7 @@ pub fn float_to_str_bytes_common<T: Float>(
/// `to_str_bytes_common()`, for details see there.
#[inline]
pub fn float_to_str_common<T: Float>(
num: T, radix: uint, negative_zero: bool,
num: T, radix: u32, negative_zero: bool,
sign: SignFormat, digits: SignificantDigits, exp_format: ExponentFormat, exp_capital: bool
) -> (String, bool) {
let (bytes, special) = float_to_str_bytes_common(num, radix,
@ -422,8 +422,8 @@ pub fn float_to_str_common<T: Float>(
// Some constants for from_str_bytes_common's input validation,
// they define minimum radix values for which the character is a valid digit.
static DIGIT_P_RADIX: uint = ('p' as uint) - ('a' as uint) + 11u;
static DIGIT_E_RADIX: uint = ('e' as uint) - ('a' as uint) + 11u;
static DIGIT_P_RADIX: u32 = ('p' as u32) - ('a' as u32) + 11;
static DIGIT_E_RADIX: u32 = ('e' as u32) - ('a' as u32) + 11;
#[cfg(test)]
mod tests {

View File

@ -32,7 +32,6 @@ use sys_common;
///
/// ```rust,no_run
/// # #![allow(unused_must_use)]
/// #![feature(slicing_syntax)]
///
/// use std::old_io::net::udp::UdpSocket;
/// use std::old_io::net::ip::{Ipv4Addr, SocketAddr};

View File

@ -30,7 +30,7 @@ use self::StdSource::*;
use boxed::Box;
use cell::RefCell;
use clone::Clone;
use failure::LOCAL_STDERR;
use panicking::LOCAL_STDERR;
use fmt;
use old_io::{Reader, Writer, IoResult, IoError, OtherIoError, Buffer,
standard_error, EndOfFile, LineBufferedWriter, BufferedReader};

View File

@ -33,7 +33,7 @@ impl Writer for Stdio {
}
}
pub fn on_fail(obj: &(Any+Send), file: &'static str, line: uint) {
pub fn on_panic(obj: &(Any+Send), file: &'static str, line: uint) {
let msg = match obj.downcast_ref::<&'static str>() {
Some(s) => *s,
None => match obj.downcast_ref::<String>() {

View File

@ -1033,6 +1033,7 @@ impl AsOsStr for PathBuf {
/// let parent_dir = path.parent();
/// ```
///
#[derive(Hash)]
pub struct Path {
inner: OsStr
}

View File

@ -62,7 +62,7 @@ use prelude::v1::*;
use any::Any;
use cell::Cell;
use cmp;
use failure;
use panicking;
use fmt;
use intrinsics;
use libc::c_void;
@ -534,10 +534,10 @@ pub fn begin_unwind<M: Any + Send>(msg: M, file_line: &(&'static str, uint)) ->
/// }` from ~1900/3700 (-O/no opts) to 180/590.
#[inline(never)] #[cold] // this is the slow path, please never inline this
fn begin_unwind_inner(msg: Box<Any + Send>, file_line: &(&'static str, uint)) -> ! {
// Make sure the default failure handler is registered before we look at the
// Make sure the default panic handler is registered before we look at the
// callbacks.
static INIT: Once = ONCE_INIT;
INIT.call_once(|| unsafe { register(failure::on_fail); });
INIT.call_once(|| unsafe { register(panicking::on_panic); });
// First, invoke call the user-defined callbacks triggered on thread panic.
//

View File

@ -1024,14 +1024,14 @@ impl fmt::Display for TryRecvError {
mod test {
use prelude::v1::*;
use os;
use std::env;
use super::*;
use thread::Thread;
pub fn stress_factor() -> uint {
match os::getenv("RUST_TEST_STRESS") {
Some(val) => val.parse().unwrap(),
None => 1,
match env::var("RUST_TEST_STRESS") {
Ok(val) => val.parse().unwrap(),
Err(..) => 1,
}
}
@ -1546,14 +1546,14 @@ mod test {
mod sync_tests {
use prelude::v1::*;
use os;
use std::env;
use thread::Thread;
use super::*;
pub fn stress_factor() -> uint {
match os::getenv("RUST_TEST_STRESS") {
Some(val) => val.parse().unwrap(),
None => 1,
match env::var("RUST_TEST_STRESS") {
Ok(val) => val.parse().unwrap(),
Err(..) => 1,
}
}

View File

@ -111,11 +111,18 @@ pub trait Packet {
}
impl Select {
/// Creates a new selection structure. This set is initially empty and
/// `wait` will panic!() if called.
/// Creates a new selection structure. This set is initially empty.
///
/// Usage of this struct directly can sometimes be burdensome, and usage is
/// rather much easier through the `select!` macro.
/// Usage of this struct directly can sometimes be burdensome, and usage is much easier through
/// the `select!` macro.
///
/// # Examples
///
/// ```
/// use std::sync::mpsc::Select;
///
/// let select = Select::new();
/// ```
pub fn new() -> Select {
Select {
head: ptr::null_mut(),

View File

@ -89,8 +89,7 @@ impl<'a> MacResult for ParserAnyMacro<'a> {
match parser.token {
token::Eof => break,
_ => {
let attrs = parser.parse_outer_attributes();
ret.push(parser.parse_method(attrs, ast::Inherited))
ret.push(parser.parse_method_with_outer_attributes());
}
}
}

View File

@ -79,7 +79,7 @@ static KNOWN_FEATURES: &'static [(&'static str, &'static str, Status)] = &[
("tuple_indexing", "1.0.0", Accepted),
("associated_types", "1.0.0", Accepted),
("visible_private_types", "1.0.0", Active),
("slicing_syntax", "1.0.0", Active),
("slicing_syntax", "1.0.0", Accepted),
("box_syntax", "1.0.0", Active),
("on_unimplemented", "1.0.0", Active),
("simd_ffi", "1.0.0", Active),
@ -134,6 +134,7 @@ static KNOWN_FEATURES: &'static [(&'static str, &'static str, Status)] = &[
// switch to Accepted; see RFC 320)
("unsafe_no_drop_flag", "1.0.0", Active),
];
// (changing above list without updating src/doc/reference.md makes @cmr sad)
enum Status {
/// Represents an active feature that is currently being implemented or

View File

@ -35,7 +35,6 @@
#![feature(path)]
#![feature(quote, unsafe_destructor)]
#![feature(rustc_private)]
#![feature(slicing_syntax)]
#![feature(staged_api)]
#![feature(std_misc)]
#![feature(unicode)]

View File

@ -645,7 +645,7 @@ impl<'a> StringReader<'a> {
/// Scan through any digits (base `radix`) or underscores, and return how
/// many digits there were.
fn scan_digits(&mut self, radix: usize) -> usize {
fn scan_digits(&mut self, radix: u32) -> usize {
let mut len = 0;
loop {
let c = self.curr;

View File

@ -4650,6 +4650,17 @@ impl<'a> Parser<'a> {
self.parse_method(attrs, visa)
}
fn complain_if_pub_macro(&mut self, visa: Visibility, span: Span) {
match visa {
Public => {
self.span_err(span, "can't qualify macro invocation with `pub`");
self.span_help(span, "try adjusting the macro to put `pub` inside \
the invocation");
}
Inherited => (),
}
}
/// Parse a method in a trait impl, starting with `attrs` attributes.
pub fn parse_method(&mut self,
attrs: Vec<Attribute>,
@ -4664,6 +4675,10 @@ impl<'a> Parser<'a> {
&& (self.look_ahead(2, |t| *t == token::OpenDelim(token::Paren))
|| self.look_ahead(2, |t| *t == token::OpenDelim(token::Brace))) {
// method macro.
let last_span = self.last_span;
self.complain_if_pub_macro(visa, last_span);
let pth = self.parse_path(NoTypesAllowed);
self.expect(&token::Not);
@ -5867,6 +5882,9 @@ impl<'a> Parser<'a> {
|| self.look_ahead(2, |t| *t == token::OpenDelim(token::Brace))) {
// MACRO INVOCATION ITEM
let last_span = self.last_span;
self.complain_if_pub_macro(visibility, last_span);
// item macro.
let pth = self.parse_path(NoTypesAllowed);
self.expect(&token::Not);

View File

@ -57,7 +57,6 @@
#![feature(io)]
#![feature(path)]
#![feature(rustc_private)]
#![feature(slicing_syntax)]
#![feature(staged_api)]
#![feature(std_misc)]
#![feature(unicode)]

View File

@ -297,7 +297,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
PushParam => {
// params are 1-indexed
stack.push(mparams[match cur.to_digit(10) {
Some(d) => d - 1,
Some(d) => d as usize - 1,
None => return Err("bad param number".to_string())
}].clone());
},

View File

@ -32,7 +32,7 @@
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/nightly/")]
#![feature(asm, slicing_syntax)]
#![feature(asm)]
#![feature(box_syntax)]
#![feature(collections)]
#![feature(core)]

View File

@ -31,8 +31,6 @@
html_playground_url = "http://play.rust-lang.org/")]
#![feature(no_std)]
#![no_std]
#![feature(slicing_syntax)]
#![feature(int_uint)]
#![feature(core)]
extern crate core;

View File

@ -14,7 +14,7 @@
/// The version of [Unicode](http://www.unicode.org/)
/// that the unicode parts of `CharExt` and `UnicodeStrPrelude` traits are based on.
pub const UNICODE_VERSION: (uint, uint, uint) = (7, 0, 0);
pub const UNICODE_VERSION: (u64, u64, u64) = (7, 0, 0);
fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool {
use core::cmp::Ordering::{Equal, Less, Greater};
@ -6977,7 +6977,7 @@ pub mod conversions {
}
}
fn bsearch_case_table(c: char, table: &'static [(char, char)]) -> Option<uint> {
fn bsearch_case_table(c: char, table: &'static [(char, char)]) -> Option<usize> {
match table.binary_search_by(|&(key, _)| {
if c == key { Equal }
else if key < c { Less }
@ -7613,13 +7613,13 @@ pub mod charwidth {
}
}
pub fn width(c: char, is_cjk: bool) -> Option<uint> {
match c as uint {
pub fn width(c: char, is_cjk: bool) -> Option<usize> {
match c as usize {
_c @ 0 => Some(0), // null is zero width
cu if cu < 0x20 => None, // control sequences have no width
cu if cu < 0x7F => Some(1), // ASCII
cu if cu < 0xA0 => None, // more control sequences
_ => Some(bsearch_range_value_table(c, is_cjk, charwidth_table) as uint)
_ => Some(bsearch_range_value_table(c, is_cjk, charwidth_table) as usize)
}
}

View File

@ -36,7 +36,7 @@ pub trait CharExt {
/// Panics if given a radix > 36.
#[unstable(feature = "unicode",
reason = "pending integer conventions")]
fn is_digit(self, radix: uint) -> bool;
fn is_digit(self, radix: u32) -> bool;
/// Converts a character to the corresponding digit.
///
@ -51,7 +51,7 @@ pub trait CharExt {
/// Panics if given a radix outside the range [0..36].
#[unstable(feature = "unicode",
reason = "pending integer conventions")]
fn to_digit(self, radix: uint) -> Option<uint>;
fn to_digit(self, radix: u32) -> Option<u32>;
/// Returns an iterator that yields the hexadecimal Unicode escape
/// of a character, as `char`s.
@ -80,12 +80,12 @@ pub trait CharExt {
/// Returns the amount of bytes this character would need if encoded in
/// UTF-8.
#[stable(feature = "rust1", since = "1.0.0")]
fn len_utf8(self) -> uint;
fn len_utf8(self) -> usize;
/// Returns the amount of bytes this character would need if encoded in
/// UTF-16.
#[stable(feature = "rust1", since = "1.0.0")]
fn len_utf16(self) -> uint;
fn len_utf16(self) -> usize;
/// Encodes this character as UTF-8 into the provided byte buffer,
/// and then returns the number of bytes written.
@ -94,7 +94,7 @@ pub trait CharExt {
/// and a `None` will be returned.
#[unstable(feature = "unicode",
reason = "pending decision about Iterator/Writer/Reader")]
fn encode_utf8(self, dst: &mut [u8]) -> Option<uint>;
fn encode_utf8(self, dst: &mut [u8]) -> Option<usize>;
/// Encodes this character as UTF-16 into the provided `u16` buffer,
/// and then returns the number of `u16`s written.
@ -103,7 +103,7 @@ pub trait CharExt {
/// and a `None` will be returned.
#[unstable(feature = "unicode",
reason = "pending decision about Iterator/Writer/Reader")]
fn encode_utf16(self, dst: &mut [u16]) -> Option<uint>;
fn encode_utf16(self, dst: &mut [u16]) -> Option<usize>;
/// Returns whether the specified character is considered a Unicode
/// alphabetic code point.
@ -216,31 +216,31 @@ pub trait CharExt {
/// `is_cjk` = `false`) if the context cannot be reliably determined.
#[unstable(feature = "unicode",
reason = "needs expert opinion. is_cjk flag stands out as ugly")]
fn width(self, is_cjk: bool) -> Option<uint>;
fn width(self, is_cjk: bool) -> Option<usize>;
}
#[stable(feature = "rust1", since = "1.0.0")]
impl CharExt for char {
#[unstable(feature = "unicode",
reason = "pending integer conventions")]
fn is_digit(self, radix: uint) -> bool { C::is_digit(self, radix) }
fn is_digit(self, radix: u32) -> bool { C::is_digit(self, radix) }
#[unstable(feature = "unicode",
reason = "pending integer conventions")]
fn to_digit(self, radix: uint) -> Option<uint> { C::to_digit(self, radix) }
fn to_digit(self, radix: u32) -> Option<u32> { C::to_digit(self, radix) }
#[stable(feature = "rust1", since = "1.0.0")]
fn escape_unicode(self) -> char::EscapeUnicode { C::escape_unicode(self) }
#[stable(feature = "rust1", since = "1.0.0")]
fn escape_default(self) -> char::EscapeDefault { C::escape_default(self) }
#[stable(feature = "rust1", since = "1.0.0")]
fn len_utf8(self) -> uint { C::len_utf8(self) }
fn len_utf8(self) -> usize { C::len_utf8(self) }
#[stable(feature = "rust1", since = "1.0.0")]
fn len_utf16(self) -> uint { C::len_utf16(self) }
fn len_utf16(self) -> usize { C::len_utf16(self) }
#[unstable(feature = "unicode",
reason = "pending decision about Iterator/Writer/Reader")]
fn encode_utf8(self, dst: &mut [u8]) -> Option<uint> { C::encode_utf8(self, dst) }
fn encode_utf8(self, dst: &mut [u8]) -> Option<usize> { C::encode_utf8(self, dst) }
#[unstable(feature = "unicode",
reason = "pending decision about Iterator/Writer/Reader")]
fn encode_utf16(self, dst: &mut [u16]) -> Option<uint> { C::encode_utf16(self, dst) }
fn encode_utf16(self, dst: &mut [u16]) -> Option<usize> { C::encode_utf16(self, dst) }
#[stable(feature = "rust1", since = "1.0.0")]
fn is_alphabetic(self) -> bool {
@ -313,5 +313,5 @@ impl CharExt for char {
#[unstable(feature = "unicode",
reason = "needs expert opinion. is_cjk flag stands out as ugly")]
fn width(self, is_cjk: bool) -> Option<uint> { charwidth::width(self, is_cjk) }
fn width(self, is_cjk: bool) -> Option<usize> { charwidth::width(self, is_cjk) }
}

View File

@ -43,7 +43,7 @@ pub trait UnicodeStr {
fn words<'a>(&'a self) -> Words<'a>;
fn is_whitespace(&self) -> bool;
fn is_alphanumeric(&self) -> bool;
fn width(&self, is_cjk: bool) -> uint;
fn width(&self, is_cjk: bool) -> usize;
fn trim<'a>(&'a self) -> &'a str;
fn trim_left<'a>(&'a self) -> &'a str;
fn trim_right<'a>(&'a self) -> &'a str;
@ -57,7 +57,7 @@ impl UnicodeStr for str {
#[inline]
fn grapheme_indices(&self, is_extended: bool) -> GraphemeIndices {
GraphemeIndices { start_offset: self.as_ptr() as uint, iter: self.graphemes(is_extended) }
GraphemeIndices { start_offset: self.as_ptr() as usize, iter: self.graphemes(is_extended) }
}
#[inline]
@ -78,7 +78,7 @@ impl UnicodeStr for str {
fn is_alphanumeric(&self) -> bool { self.chars().all(|c| c.is_alphanumeric()) }
#[inline]
fn width(&self, is_cjk: bool) -> uint {
fn width(&self, is_cjk: bool) -> usize {
self.chars().map(|c| c.width(is_cjk).unwrap_or(0)).sum()
}
@ -101,28 +101,28 @@ impl UnicodeStr for str {
/// External iterator for grapheme clusters and byte offsets.
#[derive(Clone)]
pub struct GraphemeIndices<'a> {
start_offset: uint,
start_offset: usize,
iter: Graphemes<'a>,
}
impl<'a> Iterator for GraphemeIndices<'a> {
type Item = (uint, &'a str);
type Item = (usize, &'a str);
#[inline]
fn next(&mut self) -> Option<(uint, &'a str)> {
self.iter.next().map(|s| (s.as_ptr() as uint - self.start_offset, s))
fn next(&mut self) -> Option<(usize, &'a str)> {
self.iter.next().map(|s| (s.as_ptr() as usize - self.start_offset, s))
}
#[inline]
fn size_hint(&self) -> (uint, Option<uint>) {
fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint()
}
}
impl<'a> DoubleEndedIterator for GraphemeIndices<'a> {
#[inline]
fn next_back(&mut self) -> Option<(uint, &'a str)> {
self.iter.next_back().map(|s| (s.as_ptr() as uint - self.start_offset, s))
fn next_back(&mut self) -> Option<(usize, &'a str)> {
self.iter.next_back().map(|s| (s.as_ptr() as usize - self.start_offset, s))
}
}
@ -151,7 +151,7 @@ impl<'a> Iterator for Graphemes<'a> {
type Item = &'a str;
#[inline]
fn size_hint(&self) -> (uint, Option<uint>) {
fn size_hint(&self) -> (usize, Option<usize>) {
let slen = self.string.len();
(cmp::min(slen, 1), Some(slen))
}
@ -378,8 +378,8 @@ static UTF8_CHAR_WIDTH: [u8; 256] = [
/// Given a first byte, determine how many bytes are in this UTF-8 character
#[inline]
pub fn utf8_char_width(b: u8) -> uint {
return UTF8_CHAR_WIDTH[b as uint] as uint;
pub fn utf8_char_width(b: u8) -> usize {
return UTF8_CHAR_WIDTH[b as usize] as usize;
}
/// Determines if a vector of `u16` contains valid UTF-16
@ -468,7 +468,7 @@ impl<'a> Iterator for Utf16Items<'a> {
}
#[inline]
fn size_hint(&self) -> (uint, Option<uint>) {
fn size_hint(&self) -> (usize, Option<usize>) {
let (low, high) = self.iter.size_hint();
// we could be entirely valid surrogates (2 elements per
// char), or entirely non-surrogates (1 element per char)
@ -534,7 +534,7 @@ impl<I> Iterator for Utf16Encoder<I> where I: Iterator<Item=char> {
}
#[inline]
fn size_hint(&self) -> (uint, Option<uint>) {
fn size_hint(&self) -> (usize, Option<usize>) {
let (low, high) = self.chars.size_hint();
// every char gets either one u16 or two u16,
// so this iterator is between 1 or 2 times as

@ -1 +1 @@
Subproject commit 32c27dda3ae2318b6897f00795009cd6f42ac4b3
Subproject commit 4891e6382e3e8aa89d530aa18427836428c47157

@ -1 +1 @@
Subproject commit e577c97b494be2815b215e3042207d6d4b7c5516
Subproject commit 60fd8abfcae50629a3fc664bd809238fed039617

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(slicing_syntax, box_syntax)]
#![feature(box_syntax)]
#![feature(collections)]
#![feature(core)]
#![feature(io)]

View File

@ -1,4 +1,4 @@
# If this file is modified, then llvm will be forcibly cleaned and then rebuilt.
# The actual contents of this file do not matter, but to trigger a change on the
# build bots then the contents should be changed so git updates the mtime.
2015-02-09
2015-02-12

View File

@ -17,6 +17,7 @@ use std::old_io::File;
use std::iter::repeat;
use std::mem::swap;
use std::os;
use std::env;
use std::rand::Rng;
use std::rand;
use std::str;
@ -46,7 +47,7 @@ fn main() {
fn maybe_run_test<F>(argv: &[String], name: String, test: F) where F: FnOnce() {
let mut run_test = false;
if os::getenv("RUST_BENCH").is_some() {
if env::var_os("RUST_BENCH").is_some() {
run_test = true
} else if argv.len() > 0 {
run_test = argv.iter().any(|x| x == &"all".to_string()) || argv.iter().any(|x| x == &name)

View File

@ -9,10 +9,11 @@
// except according to those terms.
use std::os;
use std::env;
fn main() {
let args = os::args();
let args = if os::getenv("RUST_BENCH").is_some() {
let args = if env::var_os("RUST_BENCH").is_some() {
vec!("".to_string(), "10000000".to_string())
} else if args.len() <= 1u {
vec!("".to_string(), "100000".to_string())

View File

@ -20,6 +20,7 @@
use std::sync::mpsc::{channel, Sender, Receiver};
use std::os;
use std::env;
use std::thread::Thread;
use std::time::Duration;
@ -94,7 +95,7 @@ fn run(args: &[String]) {
fn main() {
let args = os::args();
let args = if os::getenv("RUST_BENCH").is_some() {
let args = if env::var_os("RUST_BENCH").is_some() {
vec!("".to_string(), "1000000".to_string(), "10000".to_string())
} else if args.len() <= 1u {
vec!("".to_string(), "10000".to_string(), "4".to_string())

View File

@ -16,6 +16,7 @@
use std::sync::mpsc::{channel, Sender, Receiver};
use std::os;
use std::env;
use std::thread::Thread;
use std::time::Duration;
@ -101,7 +102,7 @@ fn run(args: &[String]) {
fn main() {
let args = os::args();
let args = if os::getenv("RUST_BENCH").is_some() {
let args = if env::var_os("RUST_BENCH").is_some() {
vec!("".to_string(), "1000000".to_string(), "8".to_string())
} else if args.len() <= 1u {
vec!("".to_string(), "10000".to_string(), "4".to_string())

View File

@ -19,6 +19,7 @@
// ignore-lexer-test FIXME #15679
use std::os;
use std::env;
use std::sync::{Arc, Future, Mutex, Condvar};
use std::time::Duration;
@ -64,7 +65,7 @@ fn thread_ring(i: uint, count: uint, num_chan: pipe, num_port: pipe) {
fn main() {
let args = os::args();
let args = if os::getenv("RUST_BENCH").is_some() {
let args = if env::var_os("RUST_BENCH").is_some() {
vec!("".to_string(), "100".to_string(), "10000".to_string())
} else if args.len() <= 1u {
vec!("".to_string(), "10".to_string(), "100".to_string())

View File

@ -9,6 +9,7 @@
// except according to those terms.
use std::os;
use std::env;
fn ack(m: int, n: int) -> int {
if m == 0 {
@ -24,7 +25,7 @@ fn ack(m: int, n: int) -> int {
fn main() {
let args = os::args();
let args = if os::getenv("RUST_BENCH").is_some() {
let args = if env::var_os("RUST_BENCH").is_some() {
vec!("".to_string(), "12".to_string())
} else if args.len() <= 1u {
vec!("".to_string(), "8".to_string())

View File

@ -86,7 +86,7 @@ fn inner(depth: i32, iterations: i32) -> String {
fn main() {
let args = std::os::args();
let args = args;
let n = if std::os::getenv("RUST_BENCH").is_some() {
let n = if std::env::var_os("RUST_BENCH").is_some() {
17
} else if args.len() <= 1u {
8

View File

@ -227,7 +227,7 @@ fn rendezvous(nn: uint, set: Vec<Color>) {
}
fn main() {
let nn = if std::os::getenv("RUST_BENCH").is_some() {
let nn = if std::env::var_os("RUST_BENCH").is_some() {
200000
} else {
std::os::args()

View File

@ -43,6 +43,7 @@ use std::old_io::{BufferedWriter, File};
use std::old_io;
use std::num::Float;
use std::os;
use std::env;
const LINE_LENGTH: uint = 60;
const IM: u32 = 139968;
@ -105,7 +106,7 @@ fn make_fasta<W: Writer, I: Iterator<Item=u8>>(
fn run<W: Writer>(writer: &mut W) -> std::old_io::IoResult<()> {
let args = os::args();
let args = args;
let n = if os::getenv("RUST_BENCH").is_some() {
let n = if env::var_os("RUST_BENCH").is_some() {
25000000
} else if args.len() <= 1u {
1000
@ -143,7 +144,7 @@ fn run<W: Writer>(writer: &mut W) -> std::old_io::IoResult<()> {
}
fn main() {
let res = if os::getenv("RUST_BENCH").is_some() {
let res = if env::var_os("RUST_BENCH").is_some() {
let mut file = BufferedWriter::new(File::create(&Path::new("./shootout-fasta.data")));
run(&mut file)
} else {

View File

@ -9,6 +9,7 @@
// except according to those terms.
use std::os;
use std::env;
fn fib(n: int) -> int {
if n < 2 {
@ -20,7 +21,7 @@ fn fib(n: int) -> int {
fn main() {
let args = os::args();
let args = if os::getenv("RUST_BENCH").is_some() {
let args = if env::var_os("RUST_BENCH").is_some() {
vec!("".to_string(), "40".to_string())
} else if args.len() <= 1u {
vec!("".to_string(), "30".to_string())

View File

@ -22,6 +22,7 @@ use std::mem::replace;
use std::num::Float;
use std::option;
use std::os;
use std::env;
use std::sync::mpsc::{channel, Sender, Receiver};
use std::thread::Thread;
@ -148,7 +149,7 @@ fn make_sequence_processor(sz: uint,
fn main() {
use std::old_io::{stdio, MemReader, BufferedReader};
let rdr = if os::getenv("RUST_BENCH").is_some() {
let rdr = if env::var_os("RUST_BENCH").is_some() {
let foo = include_bytes!("shootout-k-nucleotide.data");
box MemReader::new(foo.to_vec()) as Box<Reader>
} else {

View File

@ -291,7 +291,7 @@ fn get_sequence<R: Buffer>(r: &mut R, key: &str) -> Vec<u8> {
}
fn main() {
let input = if std::os::getenv("RUST_BENCH").is_some() {
let input = if std::env::var_os("RUST_BENCH").is_some() {
let fd = std::old_io::File::open(&Path::new("shootout-k-nucleotide.data"));
get_sequence(&mut std::old_io::BufferedReader::new(fd), ">THREE")
} else {

Some files were not shown because too many files have changed in this diff Show More