mirror of
https://github.com/rust-lang/rust
synced 2024-09-05 08:37:14 +00:00
Auto merge of #21473 - alexcrichton:rollup, r=alexcrichton
This commit is contained in:
commit
5d2056a7e3
1
configure
vendored
1
configure
vendored
|
@ -509,7 +509,6 @@ opt optimize-tests 1 "build tests with optimizations"
|
|||
opt libcpp 1 "build with llvm with libc++ instead of libstdc++ when using clang"
|
||||
opt llvm-assertions 1 "build LLVM with assertions"
|
||||
opt debug 1 "build with extra debug fun"
|
||||
opt ratchet-bench 0 "ratchet benchmarks"
|
||||
opt fast-make 0 "use .gitmodules as timestamp for submodule deps"
|
||||
opt ccache 0 "invoke gcc/clang via ccache to reuse object files between builds"
|
||||
opt local-rust 0 "use an installed rustc rather than downloading a snapshot"
|
||||
|
|
30
mk/cfg/aarch64-linux-android.mk
Normal file
30
mk/cfg/aarch64-linux-android.mk
Normal file
|
@ -0,0 +1,30 @@
|
|||
# aarch64-linux-android configuration
|
||||
# CROSS_PREFIX_aarch64-linux-android-
|
||||
CC_aarch64-linux-android=$(CFG_ANDROID_CROSS_PATH)/bin/aarch64-linux-android-gcc
|
||||
CXX_aarch64-linux-android=$(CFG_ANDROID_CROSS_PATH)/bin/aarch64-linux-android-g++
|
||||
CPP_aarch64-linux-android=$(CFG_ANDROID_CROSS_PATH)/bin/aarch64-linux-android-gcc -E
|
||||
AR_aarch64-linux-android=$(CFG_ANDROID_CROSS_PATH)/bin/aarch64-linux-android-ar
|
||||
CFG_LIB_NAME_aarch64-linux-android=lib$(1).so
|
||||
CFG_STATIC_LIB_NAME_aarch64-linux-android=lib$(1).a
|
||||
CFG_LIB_GLOB_aarch64-linux-android=lib$(1)-*.so
|
||||
CFG_LIB_DSYM_GLOB_aarch64-linux-android=lib$(1)-*.dylib.dSYM
|
||||
CFG_JEMALLOC_CFLAGS_aarch64-linux-android := -D__aarch64__ -DANDROID -D__ANDROID__ $(CFLAGS)
|
||||
CFG_GCCISH_CFLAGS_aarch64-linux-android := -Wall -g -fPIC -D__aarch64__ -DANDROID -D__ANDROID__ $(CFLAGS)
|
||||
CFG_GCCISH_CXXFLAGS_aarch64-linux-android := -fno-rtti $(CXXFLAGS)
|
||||
CFG_GCCISH_LINK_FLAGS_aarch64-linux-android := -shared -fPIC -ldl -g -lm -lsupc++
|
||||
CFG_GCCISH_DEF_FLAG_aarch64-linux-android := -Wl,--export-dynamic,--dynamic-list=
|
||||
CFG_GCCISH_PRE_LIB_FLAGS_aarch64-linux-android := -Wl,-whole-archive
|
||||
CFG_GCCISH_POST_LIB_FLAGS_aarch64-linux-android := -Wl,-no-whole-archive
|
||||
CFG_DEF_SUFFIX_aarch64-linux-android := .android.def
|
||||
CFG_LLC_FLAGS_aarch64-linux-android :=
|
||||
CFG_INSTALL_NAME_aarch64-linux-android =
|
||||
CFG_EXE_SUFFIX_aarch64-linux-android :=
|
||||
CFG_WINDOWSY_aarch64-linux-android :=
|
||||
CFG_UNIXY_aarch64-linux-android := 1
|
||||
CFG_PATH_MUNGE_aarch64-linux-android := true
|
||||
CFG_LDPATH_aarch64-linux-android :=
|
||||
CFG_RUN_aarch64-linux-android=
|
||||
CFG_RUN_TARG_aarch64-linux-android=
|
||||
RUSTC_FLAGS_aarch64-linux-android :=
|
||||
RUSTC_CROSS_FLAGS_aarch64-linux-android :=
|
||||
CFG_GNU_TRIPLE_aarch64-linux-android := aarch64-linux-android
|
2
mk/rt.mk
2
mk/rt.mk
|
@ -141,6 +141,8 @@ else ifeq ($(OSTYPE_$(1)), apple-ios)
|
|||
JEMALLOC_ARGS_$(1) := --disable-tls
|
||||
else ifeq ($(OSTYPE_$(1)), linux-androideabi)
|
||||
JEMALLOC_ARGS_$(1) := --disable-tls
|
||||
else ifeq ($(OSTYPE_$(1)), linux-android)
|
||||
JEMALLOC_ARGS_$(1) := --disable-tls
|
||||
endif
|
||||
|
||||
################################################################################
|
||||
|
|
|
@ -300,6 +300,7 @@ tidy:
|
|||
| grep '^$(S)src/libbacktrace' -v \
|
||||
| grep '^$(S)src/rust-installer' -v \
|
||||
| xargs $(CFG_PYTHON) $(S)src/etc/check-binaries.py
|
||||
$(Q) $(CFG_PYTHON) $(S)src/etc/errorck.py $(S)src/
|
||||
|
||||
|
||||
endif
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
use std::str::FromStr;
|
||||
use regex::Regex;
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
pub enum Mode {
|
||||
CompileFail,
|
||||
RunFail,
|
||||
|
@ -43,9 +43,9 @@ fn from_str(s: &str) -> Option<Mode> {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::String for Mode {
|
||||
impl fmt::Display for Mode {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::String::fmt(match *self {
|
||||
fmt::Display::fmt(match *self {
|
||||
CompileFail => "compile-fail",
|
||||
RunFail => "run-fail",
|
||||
RunPass => "run-pass",
|
||||
|
@ -58,12 +58,6 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Show for Mode {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::String::fmt(self, f)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Config {
|
||||
// The library paths required for running the compiler
|
||||
|
@ -115,20 +109,6 @@ pub struct Config {
|
|||
// Write out a parseable log of tests that were run
|
||||
pub logfile: Option<Path>,
|
||||
|
||||
// Write out a json file containing any metrics of the run
|
||||
pub save_metrics: Option<Path>,
|
||||
|
||||
// Write and ratchet a metrics file
|
||||
pub ratchet_metrics: Option<Path>,
|
||||
|
||||
// Percent change in metrics to consider noise
|
||||
pub ratchet_noise_percent: Option<f64>,
|
||||
|
||||
// "Shard" of the testsuite to pub run: this has the form of
|
||||
// two numbers (a,b), and causes only those tests with
|
||||
// positional order equal to a mod b to run.
|
||||
pub test_shard: Option<(uint,uint)>,
|
||||
|
||||
// A command line to prefix program execution with,
|
||||
// for running under valgrind
|
||||
pub runtool: Option<String>,
|
||||
|
|
|
@ -77,10 +77,6 @@ pub fn parse_config(args: Vec<String> ) -> Config {
|
|||
optopt("", "target-rustcflags", "flags to pass to rustc for target", "FLAGS"),
|
||||
optflag("", "verbose", "run tests verbosely, showing all output"),
|
||||
optopt("", "logfile", "file to log test execution to", "FILE"),
|
||||
optopt("", "save-metrics", "file to save metrics to", "FILE"),
|
||||
optopt("", "ratchet-metrics", "file to ratchet metrics against", "FILE"),
|
||||
optopt("", "ratchet-noise-percent",
|
||||
"percent change in metrics to consider noise", "N"),
|
||||
optflag("", "jit", "run tests under the JIT"),
|
||||
optopt("", "target", "the target to build for", "TARGET"),
|
||||
optopt("", "host", "the host to build for", "HOST"),
|
||||
|
@ -90,7 +86,6 @@ pub fn parse_config(args: Vec<String> ) -> Config {
|
|||
optopt("", "adb-path", "path to the android debugger", "PATH"),
|
||||
optopt("", "adb-test-dir", "path to tests for the android debugger", "PATH"),
|
||||
optopt("", "lldb-python-dir", "directory containing LLDB's python module", "PATH"),
|
||||
optopt("", "test-shard", "run shard A, of B shards, worth of the testsuite", "A.B"),
|
||||
optflag("h", "help", "show this message"));
|
||||
|
||||
assert!(!args.is_empty());
|
||||
|
@ -152,12 +147,6 @@ fn opt_path(m: &getopts::Matches, nm: &str) -> Path {
|
|||
filter: filter,
|
||||
cfail_regex: Regex::new(errors::EXPECTED_PATTERN).unwrap(),
|
||||
logfile: matches.opt_str("logfile").map(|s| Path::new(s)),
|
||||
save_metrics: matches.opt_str("save-metrics").map(|s| Path::new(s)),
|
||||
ratchet_metrics:
|
||||
matches.opt_str("ratchet-metrics").map(|s| Path::new(s)),
|
||||
ratchet_noise_percent:
|
||||
matches.opt_str("ratchet-noise-percent")
|
||||
.and_then(|s| s.as_slice().parse::<f64>()),
|
||||
runtool: matches.opt_str("runtool"),
|
||||
host_rustcflags: matches.opt_str("host-rustcflags"),
|
||||
target_rustcflags: matches.opt_str("target-rustcflags"),
|
||||
|
@ -176,7 +165,6 @@ fn opt_path(m: &getopts::Matches, nm: &str) -> Path {
|
|||
opt_str2(matches.opt_str("adb-test-dir")).as_slice() &&
|
||||
!opt_str2(matches.opt_str("adb-test-dir")).is_empty(),
|
||||
lldb_python_dir: matches.opt_str("lldb-python-dir"),
|
||||
test_shard: test::opt_shard(matches.opt_str("test-shard")),
|
||||
verbose: matches.opt_present("verbose"),
|
||||
}
|
||||
}
|
||||
|
@ -210,10 +198,6 @@ pub fn log_config(config: &Config) {
|
|||
logv(c, format!("adb_test_dir: {:?}", config.adb_test_dir));
|
||||
logv(c, format!("adb_device_status: {}",
|
||||
config.adb_device_status));
|
||||
match config.test_shard {
|
||||
None => logv(c, "test_shard: (all)".to_string()),
|
||||
Some((a,b)) => logv(c, format!("test_shard: {}.{}", a, b))
|
||||
}
|
||||
logv(c, format!("verbose: {}", config.verbose));
|
||||
logv(c, format!("\n"));
|
||||
}
|
||||
|
@ -284,15 +268,8 @@ pub fn test_opts(config: &Config) -> test::TestOpts {
|
|||
logfile: config.logfile.clone(),
|
||||
run_tests: true,
|
||||
run_benchmarks: true,
|
||||
ratchet_metrics: config.ratchet_metrics.clone(),
|
||||
ratchet_noise_percent: config.ratchet_noise_percent.clone(),
|
||||
save_metrics: config.save_metrics.clone(),
|
||||
test_shard: config.test_shard.clone(),
|
||||
nocapture: false,
|
||||
color: test::AutoColor,
|
||||
show_boxplot: false,
|
||||
boxplot_width: 50,
|
||||
show_all_stats: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -332,8 +332,7 @@ pub fn parse_name_value_directive(line: &str, directive: &str)
|
|||
let keycolon = format!("{}:", directive);
|
||||
match line.find_str(keycolon.as_slice()) {
|
||||
Some(colon) => {
|
||||
let value = line.slice(colon + keycolon.len(),
|
||||
line.len()).to_string();
|
||||
let value = line[(colon + keycolon.len()) .. line.len()].to_string();
|
||||
debug!("{}: {}", directive, value);
|
||||
Some(value)
|
||||
}
|
||||
|
|
|
@ -294,6 +294,7 @@ fn make_pp_args(config: &Config,
|
|||
let aux_dir = aux_output_dir_name(config, testfile);
|
||||
// FIXME (#9639): This needs to handle non-utf8 paths
|
||||
let mut args = vec!("-".to_string(),
|
||||
"-Zunstable-options".to_string(),
|
||||
"--pretty".to_string(),
|
||||
pretty_type,
|
||||
format!("--target={}", config.target),
|
||||
|
@ -340,7 +341,7 @@ fn make_typecheck_args(config: &Config, props: &TestProps, testfile: &Path) -> P
|
|||
};
|
||||
// FIXME (#9639): This needs to handle non-utf8 paths
|
||||
let mut args = vec!("-".to_string(),
|
||||
"--no-trans".to_string(),
|
||||
"-Zno-trans".to_string(),
|
||||
"--crate-type=lib".to_string(),
|
||||
format!("--target={}", target),
|
||||
"-L".to_string(),
|
||||
|
@ -547,7 +548,7 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
|
|||
|
||||
// Add line breakpoints
|
||||
for line in breakpoint_lines.iter() {
|
||||
script_str.push_str(&format!("break '{:?}':{}\n",
|
||||
script_str.push_str(&format!("break '{}':{}\n",
|
||||
testfile.filename_display(),
|
||||
*line)[]);
|
||||
}
|
||||
|
@ -750,7 +751,7 @@ fn run_lldb(config: &Config,
|
|||
status: status,
|
||||
stdout: out,
|
||||
stderr: err,
|
||||
cmdline: format!("{}", cmd)
|
||||
cmdline: format!("{:?}", cmd)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -862,7 +863,7 @@ fn check_debugger_output(debugger_run_result: &ProcRes, check_lines: &[String])
|
|||
break;
|
||||
}
|
||||
Some(i) => {
|
||||
rest = rest.slice_from(i + frag.len());
|
||||
rest = &rest[(i + frag.len())..];
|
||||
}
|
||||
}
|
||||
first = false;
|
||||
|
@ -953,7 +954,7 @@ fn check_expected_errors(expected_errors: Vec<errors::ExpectedError> ,
|
|||
}
|
||||
|
||||
let prefixes = expected_errors.iter().map(|ee| {
|
||||
format!("{:?}:{}:", testfile.display(), ee.line)
|
||||
format!("{}:{}:", testfile.display(), ee.line)
|
||||
}).collect::<Vec<String> >();
|
||||
|
||||
#[cfg(windows)]
|
||||
|
@ -1045,7 +1046,7 @@ fn scan_until_char(haystack: &str, needle: char, idx: &mut uint) -> bool {
|
|||
if *idx >= haystack.len() {
|
||||
return false;
|
||||
}
|
||||
let opt = haystack.slice_from(*idx).find(needle);
|
||||
let opt = haystack[(*idx)..].find(needle);
|
||||
if opt.is_none() {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -480,14 +480,12 @@ use std::sync::{Arc,Mutex};
|
|||
fn main() {
|
||||
let numbers = Arc::new(Mutex::new(vec![1is, 2, 3]));
|
||||
|
||||
for i in 0..3 {
|
||||
for i in 0us..3 {
|
||||
let number = numbers.clone();
|
||||
Thread::spawn(move || {
|
||||
let mut array = number.lock().unwrap();
|
||||
|
||||
(*array)[i] += 1;
|
||||
|
||||
println!("numbers[{}] is {}", i, (*array)[i]);
|
||||
array[i] += 1;
|
||||
println!("numbers[{}] is {}", i, array[i]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -803,8 +803,9 @@ Crates contain [items](#items), each of which may have some number of
|
|||
## Items
|
||||
|
||||
```{.ebnf .gram}
|
||||
item : mod_item | fn_item | type_item | struct_item | enum_item
|
||||
| static_item | trait_item | impl_item | extern_block ;
|
||||
item : extern_crate_decl | use_decl | mod_item | fn_item | type_item
|
||||
| struct_item | enum_item | static_item | trait_item | impl_item
|
||||
| extern_block ;
|
||||
```
|
||||
|
||||
An _item_ is a component of a crate; some module items can be defined in crate
|
||||
|
@ -818,6 +819,8 @@ execution, and may reside in read-only memory.
|
|||
|
||||
There are several kinds of item:
|
||||
|
||||
* [`extern crate` declarations](#extern-crate-declarations)
|
||||
* [`use` declarations](#use-declarations)
|
||||
* [modules](#modules)
|
||||
* [functions](#functions)
|
||||
* [type definitions](#type-definitions)
|
||||
|
@ -854,13 +857,10 @@ no notion of type abstraction: there are no first-class "forall" types.
|
|||
|
||||
```{.ebnf .gram}
|
||||
mod_item : "mod" ident ( ';' | '{' mod '}' );
|
||||
mod : [ view_item | item ] * ;
|
||||
mod : item * ;
|
||||
```
|
||||
|
||||
A module is a container for zero or more [view items](#view-items) and zero or
|
||||
more [items](#items). The view items manage the visibility of the items defined
|
||||
within the module, as well as the visibility of names from outside the module
|
||||
when referenced from inside the module.
|
||||
A module is a container for zero or more [items](#items).
|
||||
|
||||
A _module item_ is a module, surrounded in braces, named, and prefixed with the
|
||||
keyword `mod`. A module item introduces a new, named module into the tree of
|
||||
|
@ -918,19 +918,6 @@ mod thread {
|
|||
}
|
||||
```
|
||||
|
||||
#### View items
|
||||
|
||||
```{.ebnf .gram}
|
||||
view_item : extern_crate_decl | use_decl ;
|
||||
```
|
||||
|
||||
A view item manages the namespace of a module. View items do not define new
|
||||
items, but rather, simply change other items' visibility. There are two
|
||||
kinds of view items:
|
||||
|
||||
* [`extern crate` declarations](#extern-crate-declarations)
|
||||
* [`use` declarations](#use-declarations)
|
||||
|
||||
##### Extern crate declarations
|
||||
|
||||
```{.ebnf .gram}
|
||||
|
@ -2377,10 +2364,6 @@ These types help drive the compiler's analysis
|
|||
: ___Needs filling in___
|
||||
* `no_copy_bound`
|
||||
: This type does not implement "copy", even if eligible.
|
||||
* `no_send_bound`
|
||||
: This type does not implement "send", even if eligible.
|
||||
* `no_sync_bound`
|
||||
: This type does not implement "sync", even if eligible.
|
||||
* `eh_personality`
|
||||
: ___Needs filling in___
|
||||
* `exchange_free`
|
||||
|
@ -2891,13 +2874,12 @@ Point3d {y: 0, z: 10, .. base};
|
|||
### Block expressions
|
||||
|
||||
```{.ebnf .gram}
|
||||
block_expr : '{' [ view_item ] *
|
||||
[ stmt ';' | item ] *
|
||||
block_expr : '{' [ stmt ';' | item ] *
|
||||
[ expr ] '}' ;
|
||||
```
|
||||
|
||||
A _block expression_ is similar to a module in terms of the declarations that
|
||||
are possible. Each block conceptually introduces a new namespace scope. View
|
||||
are possible. Each block conceptually introduces a new namespace scope. Use
|
||||
items can bring new names into scopes and declared items are in scope for only
|
||||
the block itself.
|
||||
|
||||
|
|
|
@ -257,7 +257,7 @@ fn goodbye() -> String {
|
|||
|
||||
(This is "Sayōnara", if you're curious.)
|
||||
|
||||
Now that we have our some functionality in our crate, let's try to use it from
|
||||
Now that we have some functionality in our crate, let's try to use it from
|
||||
another crate.
|
||||
|
||||
# Importing External Crates
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
% `if`
|
||||
% If
|
||||
|
||||
Rust's take on `if` is not particularly complex, but it's much more like the
|
||||
`if` you'll find in a dynamically typed language than in a more traditional
|
||||
|
|
|
@ -123,7 +123,7 @@ We now loop forever with `loop` and use `break` to break out early.
|
|||
iteration. This will only print the odd numbers:
|
||||
|
||||
```{rust}
|
||||
for x in 0..10 {
|
||||
for x in 0u32..10 {
|
||||
if x % 2 == 0 { continue; }
|
||||
|
||||
println!("{}", x);
|
||||
|
|
|
@ -179,7 +179,7 @@ for init_val in 0 .. 3 {
|
|||
}
|
||||
|
||||
let result = rx.recv().unwrap() + rx.recv().unwrap() + rx.recv().unwrap();
|
||||
# fn some_expensive_computation(_i: u32) -> u32 { 42 }
|
||||
# fn some_expensive_computation(_i: i32) -> i32 { 42 }
|
||||
```
|
||||
|
||||
Cloning a `Sender` produces a new handle to the same channel, allowing multiple
|
||||
|
@ -207,7 +207,7 @@ let rxs = (0 .. 3).map(|&:init_val| {
|
|||
|
||||
// Wait on each port, accumulating the results
|
||||
let result = rxs.iter().fold(0, |&:accum, rx| accum + rx.recv().unwrap() );
|
||||
# fn some_expensive_computation(_i: u32) -> u32 { 42 }
|
||||
# fn some_expensive_computation(_i: i32) -> i32 { 42 }
|
||||
```
|
||||
|
||||
## Backgrounding computations: Futures
|
||||
|
|
|
@ -707,7 +707,7 @@ Other features provided by lang items include:
|
|||
various kinds; lang items `send`, `sync` and `copy`.
|
||||
- the marker types and variance indicators found in
|
||||
`std::marker`; lang items `covariant_type`,
|
||||
`contravariant_lifetime`, `no_sync_bound`, etc.
|
||||
`contravariant_lifetime`, etc.
|
||||
|
||||
Lang items are loaded lazily by the compiler; e.g. if one never uses
|
||||
`Box` then there is no need to define functions for `exchange_malloc`
|
||||
|
|
|
@ -54,6 +54,11 @@
|
|||
:type 'integer
|
||||
:group 'rust-mode)
|
||||
|
||||
(defcustom rust-indent-method-chain nil
|
||||
"Indent Rust method chains, aligned by the '.' operators"
|
||||
:type 'boolean
|
||||
:group 'rust-mode)
|
||||
|
||||
(defun rust-paren-level () (nth 0 (syntax-ppss)))
|
||||
(defun rust-in-str-or-cmnt () (nth 8 (syntax-ppss)))
|
||||
(defun rust-rewind-past-str-cmnt () (goto-char (nth 8 (syntax-ppss))))
|
||||
|
@ -77,6 +82,15 @@
|
|||
(backward-word 1))
|
||||
(current-column))))
|
||||
|
||||
(defun rust-align-to-method-chain ()
|
||||
(save-excursion
|
||||
(previous-line)
|
||||
(end-of-line)
|
||||
(backward-word 1)
|
||||
(backward-char)
|
||||
(when (looking-at "\\..+\(.*\)\n")
|
||||
(- (current-column) rust-indent-offset))))
|
||||
|
||||
(defun rust-rewind-to-beginning-of-current-level-expr ()
|
||||
(let ((current-level (rust-paren-level)))
|
||||
(back-to-indentation)
|
||||
|
@ -99,10 +113,13 @@
|
|||
;; the inside of it correctly relative to the outside.
|
||||
(if (= 0 level)
|
||||
0
|
||||
(or
|
||||
(when rust-indent-method-chain
|
||||
(rust-align-to-method-chain))
|
||||
(save-excursion
|
||||
(backward-up-list)
|
||||
(rust-rewind-to-beginning-of-current-level-expr)
|
||||
(+ (current-column) rust-indent-offset)))))
|
||||
(+ (current-column) rust-indent-offset))))))
|
||||
(cond
|
||||
;; A function return type is indented to the corresponding function arguments
|
||||
((looking-at "->")
|
||||
|
@ -114,6 +131,16 @@
|
|||
;; A closing brace is 1 level unindended
|
||||
((looking-at "}") (- baseline rust-indent-offset))
|
||||
|
||||
;;Line up method chains by their .'s
|
||||
((when (and rust-indent-method-chain
|
||||
(looking-at "\..+\(.*\);?\n"))
|
||||
(or
|
||||
(let ((method-indent (rust-align-to-method-chain)))
|
||||
(when method-indent
|
||||
(+ method-indent rust-indent-offset)))
|
||||
(+ baseline rust-indent-offset))))
|
||||
|
||||
|
||||
;; Doc comments in /** style with leading * indent to line up the *s
|
||||
((and (nth 4 (syntax-ppss)) (looking-at "*"))
|
||||
(+ 1 baseline))
|
||||
|
|
70
src/etc/errorck.py
Normal file
70
src/etc/errorck.py
Normal file
|
@ -0,0 +1,70 @@
|
|||
# Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
||||
# file at the top-level directory of this distribution and at
|
||||
# http://rust-lang.org/COPYRIGHT.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
# option. This file may not be copied, modified, or distributed
|
||||
# except according to those terms.
|
||||
|
||||
# Digs error codes out of files named 'diagnostics.rs' across
|
||||
# the tree, and ensures thare are no duplicates.
|
||||
|
||||
import sys, os, re
|
||||
|
||||
src_dir = sys.argv[1]
|
||||
|
||||
errcode_map = { }
|
||||
|
||||
for (dirpath, dirnames, filenames) in os.walk(src_dir):
|
||||
|
||||
if "src/test" in dirpath or "src/llvm" in dirpath:
|
||||
# Short circuit for fast
|
||||
continue
|
||||
|
||||
for filename in filenames:
|
||||
if filename != "diagnostics.rs":
|
||||
continue
|
||||
|
||||
path = os.path.join(dirpath, filename)
|
||||
line_num = 1
|
||||
with open(path, 'r') as f:
|
||||
for line in f:
|
||||
|
||||
p = re.compile("(E\d\d\d\d)")
|
||||
m = p.search(line)
|
||||
if not m is None:
|
||||
errcode = m.group(1)
|
||||
|
||||
new_record = [(errcode, path, line_num, line)]
|
||||
existing = errcode_map.get(errcode)
|
||||
if existing is not None:
|
||||
# This is a dupe
|
||||
errcode_map[errcode] = existing + new_record
|
||||
else:
|
||||
errcode_map[errcode] = new_record
|
||||
|
||||
line_num += 1
|
||||
|
||||
errors = False
|
||||
all_errors = []
|
||||
for errcode in errcode_map:
|
||||
entries = errcode_map[errcode]
|
||||
all_errors += [entries[0][0]]
|
||||
if len(entries) > 1:
|
||||
print "error: duplicate error code " + errcode
|
||||
for entry in entries:
|
||||
print entry[1] + ": " + str(entry[2])
|
||||
print entry[3]
|
||||
errors = True
|
||||
|
||||
print str(len(errcode_map)) + " error codes"
|
||||
|
||||
all_errors.sort()
|
||||
all_errors.reverse()
|
||||
|
||||
print "highest error code: " + all_errors[0]
|
||||
|
||||
if errors:
|
||||
sys.exit(1)
|
|
@ -433,11 +433,16 @@ CFG_TMP_DIR=$(mktemp -d 2>/dev/null \
|
|||
|| mktemp -d -t 'rustup-tmp-install' 2>/dev/null \
|
||||
|| create_tmp_dir)
|
||||
|
||||
# If we're saving nightlies and we didn't specify which one, grab todays.
|
||||
# Otherwise we'll use the latest version.
|
||||
# If we're saving nightlies and we didn't specify which one, grab the latest
|
||||
# verison from the perspective of the server. Buildbot has typically finished
|
||||
# building and uploading by ~8UTC, but we want to include a little buffer.
|
||||
#
|
||||
# FIXME It would be better to use the known most recent nightly that has been
|
||||
# built. This is waiting on a change to have buildbot publish metadata that
|
||||
# can be queried.
|
||||
if [ -n "${CFG_SAVE}" -a -z "${CFG_DATE}" ];
|
||||
then
|
||||
CFG_DATE=`date "+%Y-%m-%d"`
|
||||
CFG_DATE=`TZ=Etc/UTC+9 date "+%Y-%m-%d"`
|
||||
fi
|
||||
|
||||
RUST_URL="https://static.rust-lang.org/dist"
|
||||
|
@ -453,16 +458,33 @@ then
|
|||
RUST_URL="${RUST_URL}/${CFG_DATE}"
|
||||
fi
|
||||
|
||||
verify_hash() {
|
||||
remote_sha256="$1"
|
||||
local_file="$2"
|
||||
|
||||
download_hash() {
|
||||
msg "Downloading ${remote_sha256}"
|
||||
remote_sha256=`"${CFG_CURL}" -f "${remote_sha256}"`
|
||||
if [ -n "${CFG_SAVE}" ]; then
|
||||
echo "${remote_sha256}" > "${local_sha_file}"
|
||||
fi
|
||||
if [ "$?" -ne 0 ]; then
|
||||
rm -Rf "${CFG_TMP_DIR}"
|
||||
err "Failed to download ${remote_url}"
|
||||
fi
|
||||
}
|
||||
|
||||
verify_hash() {
|
||||
remote_sha256="$1"
|
||||
local_file="$2"
|
||||
local_sha_file="${local_file}.sha256"
|
||||
|
||||
if [ -n "${CFG_SAVE}" ]; then
|
||||
if [ -f "${local_sha_file}" ]; then
|
||||
msg "Local ${local_sha_file} exists, treating as remote hash"
|
||||
remote_sha256=`cat "${local_sha_file}"`
|
||||
else
|
||||
download_hash
|
||||
fi
|
||||
else
|
||||
download_hash
|
||||
fi
|
||||
|
||||
msg "Verifying hash"
|
||||
local_sha256=$(calculate_hash "${local_file}")
|
||||
|
|
|
@ -72,7 +72,7 @@
|
|||
use core::atomic;
|
||||
use core::atomic::Ordering::{Relaxed, Release, Acquire, SeqCst};
|
||||
use core::borrow::BorrowFrom;
|
||||
use core::fmt::{self, Show};
|
||||
use core::fmt;
|
||||
use core::cmp::{Ordering};
|
||||
use core::default::Default;
|
||||
use core::mem::{min_align_of, size_of};
|
||||
|
@ -578,16 +578,17 @@ fn cmp(&self, other: &Arc<T>) -> Ordering { (**self).cmp(&**other) }
|
|||
#[stable]
|
||||
impl<T: Eq> Eq for Arc<T> {}
|
||||
|
||||
impl<T: fmt::Show> fmt::Show for Arc<T> {
|
||||
#[stable]
|
||||
impl<T: fmt::Display> fmt::Display for Arc<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "Arc({:?})", (**self))
|
||||
fmt::Display::fmt(&**self, f)
|
||||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl<T: fmt::String> fmt::String for Arc<T> {
|
||||
impl<T: fmt::Debug> fmt::Debug for Arc<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::String::fmt(&**self, f)
|
||||
fmt::Debug::fmt(&**self, f)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -806,7 +807,7 @@ fn test_weak_count() {
|
|||
#[test]
|
||||
fn show_arc() {
|
||||
let a = Arc::new(5u32);
|
||||
assert!(format!("{:?}", a) == "Arc(5u32)")
|
||||
assert_eq!(format!("{:?}", a), "5");
|
||||
}
|
||||
|
||||
// Make sure deriving works with Arc<T>
|
||||
|
|
|
@ -16,16 +16,18 @@
|
|||
use core::clone::Clone;
|
||||
use core::cmp::{PartialEq, PartialOrd, Eq, Ord, Ordering};
|
||||
use core::default::Default;
|
||||
use core::error::{Error, FromError};
|
||||
use core::fmt;
|
||||
use core::hash::{self, Hash};
|
||||
use core::iter::Iterator;
|
||||
use core::marker::Sized;
|
||||
use core::mem;
|
||||
use core::ops::{Deref, DerefMut};
|
||||
use core::option::Option;
|
||||
use core::ptr::Unique;
|
||||
use core::raw::TraitObject;
|
||||
use core::result::Result;
|
||||
use core::result::Result::{Ok, Err};
|
||||
use core::ops::{Deref, DerefMut};
|
||||
use core::result::Result;
|
||||
|
||||
/// A value that represents the global exchange heap. This is the default
|
||||
/// place that the `box` keyword allocates into when no place is supplied.
|
||||
|
@ -156,20 +158,22 @@ fn downcast<T: 'static>(self) -> Result<Box<T>, Box<Any>> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: ?Sized + fmt::Show> fmt::Show for Box<T> {
|
||||
#[stable]
|
||||
impl<T: fmt::Display + ?Sized> fmt::Display for Box<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "Box({:?})", &**self)
|
||||
fmt::Display::fmt(&**self, f)
|
||||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl<T: ?Sized + fmt::String> fmt::String for Box<T> {
|
||||
impl<T: fmt::Debug + ?Sized> fmt::Debug for Box<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::String::fmt(&**self, f)
|
||||
fmt::Debug::fmt(&**self, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Show for Box<Any> {
|
||||
#[stable]
|
||||
impl fmt::Debug for Box<Any> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.pad("Box<Any>")
|
||||
}
|
||||
|
@ -187,56 +191,22 @@ impl<T: ?Sized> DerefMut for Box<T> {
|
|||
fn deref_mut(&mut self) -> &mut T { &mut **self }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
#[test]
|
||||
fn test_owned_clone() {
|
||||
let a = Box::new(5i);
|
||||
let b: Box<int> = a.clone();
|
||||
assert!(a == b);
|
||||
// FIXME(#21363) remove `old_impl_check` when bug is fixed
|
||||
#[old_impl_check]
|
||||
impl<'a, T> Iterator for Box<Iterator<Item=T> + 'a> {
|
||||
type Item = T;
|
||||
|
||||
fn next(&mut self) -> Option<T> {
|
||||
(**self).next()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn any_move() {
|
||||
let a = Box::new(8u) as Box<Any>;
|
||||
let b = Box::new(Test) as Box<Any>;
|
||||
|
||||
match a.downcast::<uint>() {
|
||||
Ok(a) => { assert!(a == Box::new(8u)); }
|
||||
Err(..) => panic!()
|
||||
}
|
||||
match b.downcast::<Test>() {
|
||||
Ok(a) => { assert!(a == Box::new(Test)); }
|
||||
Err(..) => panic!()
|
||||
}
|
||||
|
||||
let a = Box::new(8u) as Box<Any>;
|
||||
let b = Box::new(Test) as Box<Any>;
|
||||
|
||||
assert!(a.downcast::<Box<Test>>().is_err());
|
||||
assert!(b.downcast::<Box<uint>>().is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_show() {
|
||||
let a = Box::new(8u) as Box<Any>;
|
||||
let b = Box::new(Test) as Box<Any>;
|
||||
let a_str = a.to_str();
|
||||
let b_str = b.to_str();
|
||||
assert_eq!(a_str, "Box<Any>");
|
||||
assert_eq!(b_str, "Box<Any>");
|
||||
|
||||
let a = &8u as &Any;
|
||||
let b = &Test as &Any;
|
||||
let s = format!("{}", a);
|
||||
assert_eq!(s, "&Any");
|
||||
let s = format!("{}", b);
|
||||
assert_eq!(s, "&Any");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deref() {
|
||||
fn homura<T: Deref<Target=i32>>(_: T) { }
|
||||
homura(Box::new(765i32));
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
(**self).size_hint()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, E: Error + 'a> FromError<E> for Box<Error + 'a> {
|
||||
fn from_error(err: E) -> Box<Error + 'a> {
|
||||
Box::new(err)
|
||||
}
|
||||
}
|
||||
|
|
75
src/liballoc/boxed_test.rs
Normal file
75
src/liballoc/boxed_test.rs
Normal file
|
@ -0,0 +1,75 @@
|
|||
// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
//! Test for `boxed` mod.
|
||||
|
||||
use core::any::Any;
|
||||
use core::ops::Deref;
|
||||
use core::result::Result::{Ok, Err};
|
||||
use core::clone::Clone;
|
||||
|
||||
use std::boxed::Box;
|
||||
use std::boxed::BoxAny;
|
||||
|
||||
#[test]
|
||||
fn test_owned_clone() {
|
||||
let a = Box::new(5i);
|
||||
let b: Box<int> = a.clone();
|
||||
assert!(a == b);
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
struct Test;
|
||||
|
||||
#[test]
|
||||
fn any_move() {
|
||||
let a = Box::new(8u) as Box<Any>;
|
||||
let b = Box::new(Test) as Box<Any>;
|
||||
|
||||
match a.downcast::<uint>() {
|
||||
Ok(a) => { assert!(a == Box::new(8u)); }
|
||||
Err(..) => panic!()
|
||||
}
|
||||
match b.downcast::<Test>() {
|
||||
Ok(a) => { assert!(a == Box::new(Test)); }
|
||||
Err(..) => panic!()
|
||||
}
|
||||
|
||||
let a = Box::new(8u) as Box<Any>;
|
||||
let b = Box::new(Test) as Box<Any>;
|
||||
|
||||
assert!(a.downcast::<Box<Test>>().is_err());
|
||||
assert!(b.downcast::<Box<uint>>().is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_show() {
|
||||
let a = Box::new(8u) as Box<Any>;
|
||||
let b = Box::new(Test) as Box<Any>;
|
||||
let a_str = format!("{:?}", a);
|
||||
let b_str = format!("{:?}", b);
|
||||
assert_eq!(a_str, "Box<Any>");
|
||||
assert_eq!(b_str, "Box<Any>");
|
||||
|
||||
static EIGHT: usize = 8us;
|
||||
static TEST: Test = Test;
|
||||
let a = &EIGHT as &Any;
|
||||
let b = &TEST as &Any;
|
||||
let s = format!("{:?}", a);
|
||||
assert_eq!(s, "&Any");
|
||||
let s = format!("{:?}", b);
|
||||
assert_eq!(s, "&Any");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deref() {
|
||||
fn homura<T: Deref<Target=i32>>(_: T) { }
|
||||
homura(Box::new(765i32));
|
||||
}
|
|
@ -280,7 +280,7 @@ pub unsafe fn allocate(size: uint, align: uint) -> *mut u8 {
|
|||
if align <= MIN_ALIGN {
|
||||
libc::malloc(size as libc::size_t) as *mut u8
|
||||
} else {
|
||||
let mut out = 0 as *mut libc::c_void;
|
||||
let mut out = ptr::null_mut();
|
||||
let ret = posix_memalign(&mut out,
|
||||
align as libc::size_t,
|
||||
size as libc::size_t);
|
||||
|
|
|
@ -70,6 +70,8 @@
|
|||
#![feature(lang_items, unsafe_destructor)]
|
||||
#![feature(box_syntax)]
|
||||
#![feature(optin_builtin_traits)]
|
||||
// FIXME(#21363) remove `old_impl_check` when bug is fixed
|
||||
#![feature(old_impl_check)]
|
||||
#![allow(unknown_features)] #![feature(int_uint)]
|
||||
|
||||
#[macro_use]
|
||||
|
@ -91,6 +93,8 @@
|
|||
|
||||
#[cfg(not(test))]
|
||||
pub mod boxed;
|
||||
#[cfg(test)]
|
||||
mod boxed_test;
|
||||
pub mod arc;
|
||||
pub mod rc;
|
||||
|
||||
|
|
|
@ -174,61 +174,17 @@ struct RcBox<T> {
|
|||
/// See the [module level documentation](../index.html) for more details.
|
||||
#[unsafe_no_drop_flag]
|
||||
#[stable]
|
||||
#[cfg(stage0)] // NOTE remove impl after next snapshot
|
||||
pub struct Rc<T> {
|
||||
// FIXME #12808: strange names to try to avoid interfering with field accesses of the contained
|
||||
// type via Deref
|
||||
_ptr: NonZero<*mut RcBox<T>>,
|
||||
_nosend: marker::NoSend,
|
||||
_noshare: marker::NoSync
|
||||
}
|
||||
|
||||
/// An immutable reference-counted pointer type.
|
||||
///
|
||||
/// See the [module level documentation](../index.html) for more details.
|
||||
#[unsafe_no_drop_flag]
|
||||
#[stable]
|
||||
#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
|
||||
pub struct Rc<T> {
|
||||
// FIXME #12808: strange names to try to avoid interfering with field accesses of the contained
|
||||
// type via Deref
|
||||
_ptr: NonZero<*mut RcBox<T>>,
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
|
||||
impl<T> !marker::Send for Rc<T> {}
|
||||
|
||||
#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
|
||||
impl<T> !marker::Sync for Rc<T> {}
|
||||
|
||||
impl<T> Rc<T> {
|
||||
/// Constructs a new `Rc<T>`.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use std::rc::Rc;
|
||||
///
|
||||
/// let five = Rc::new(5i);
|
||||
/// ```
|
||||
#[stable]
|
||||
#[cfg(stage0)] // NOTE remove after next snapshot
|
||||
pub fn new(value: T) -> Rc<T> {
|
||||
unsafe {
|
||||
Rc {
|
||||
// there is an implicit weak pointer owned by all the strong pointers, which
|
||||
// ensures that the weak destructor never frees the allocation while the strong
|
||||
// destructor is running, even if the weak pointer is stored inside the strong one.
|
||||
_ptr: NonZero::new(transmute(box RcBox {
|
||||
value: value,
|
||||
strong: Cell::new(1),
|
||||
weak: Cell::new(1)
|
||||
})),
|
||||
_nosend: marker::NoSend,
|
||||
_noshare: marker::NoSync
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Constructs a new `Rc<T>`.
|
||||
///
|
||||
|
@ -240,7 +196,6 @@ pub fn new(value: T) -> Rc<T> {
|
|||
/// let five = Rc::new(5i);
|
||||
/// ```
|
||||
#[stable]
|
||||
#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
|
||||
pub fn new(value: T) -> Rc<T> {
|
||||
unsafe {
|
||||
Rc {
|
||||
|
@ -267,29 +222,6 @@ pub fn new(value: T) -> Rc<T> {
|
|||
///
|
||||
/// let weak_five = five.downgrade();
|
||||
/// ```
|
||||
#[cfg(stage0)] // NOTE remove after next snapshot
|
||||
#[unstable = "Weak pointers may not belong in this module"]
|
||||
pub fn downgrade(&self) -> Weak<T> {
|
||||
self.inc_weak();
|
||||
Weak {
|
||||
_ptr: self._ptr,
|
||||
_nosend: marker::NoSend,
|
||||
_noshare: marker::NoSync
|
||||
}
|
||||
}
|
||||
|
||||
/// Downgrades the `Rc<T>` to a `Weak<T>` reference.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use std::rc::Rc;
|
||||
///
|
||||
/// let five = Rc::new(5i);
|
||||
///
|
||||
/// let weak_five = five.downgrade();
|
||||
/// ```
|
||||
#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
|
||||
#[unstable = "Weak pointers may not belong in this module"]
|
||||
pub fn downgrade(&self) -> Weak<T> {
|
||||
self.inc_weak();
|
||||
|
@ -483,25 +415,6 @@ fn drop(&mut self) {
|
|||
|
||||
#[stable]
|
||||
impl<T> Clone for Rc<T> {
|
||||
/// Makes a clone of the `Rc<T>`.
|
||||
///
|
||||
/// This increases the strong reference count.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use std::rc::Rc;
|
||||
///
|
||||
/// let five = Rc::new(5i);
|
||||
///
|
||||
/// five.clone();
|
||||
/// ```
|
||||
#[inline]
|
||||
#[cfg(stage0)] // NOTE remove after next snapshot
|
||||
fn clone(&self) -> Rc<T> {
|
||||
self.inc_strong();
|
||||
Rc { _ptr: self._ptr, _nosend: marker::NoSend, _noshare: marker::NoSync }
|
||||
}
|
||||
|
||||
/// Makes a clone of the `Rc<T>`.
|
||||
///
|
||||
|
@ -517,7 +430,6 @@ fn clone(&self) -> Rc<T> {
|
|||
/// five.clone();
|
||||
/// ```
|
||||
#[inline]
|
||||
#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
|
||||
fn clone(&self) -> Rc<T> {
|
||||
self.inc_strong();
|
||||
Rc { _ptr: self._ptr }
|
||||
|
@ -693,17 +605,17 @@ fn hash(&self, state: &mut S) {
|
|||
}
|
||||
}
|
||||
|
||||
#[unstable = "Show is experimental."]
|
||||
impl<T: fmt::Show> fmt::Show for Rc<T> {
|
||||
#[stable]
|
||||
impl<T: fmt::Display> fmt::Display for Rc<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "Rc({:?})", **self)
|
||||
fmt::Display::fmt(&**self, f)
|
||||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl<T: fmt::String> fmt::String for Rc<T> {
|
||||
impl<T: fmt::Debug> fmt::Debug for Rc<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::String::fmt(&**self, f)
|
||||
fmt::Debug::fmt(&**self, f)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -714,66 +626,21 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|||
/// See the [module level documentation](../index.html) for more.
|
||||
#[unsafe_no_drop_flag]
|
||||
#[unstable = "Weak pointers may not belong in this module."]
|
||||
#[cfg(stage0)] // NOTE remove impl after next snapshot
|
||||
pub struct Weak<T> {
|
||||
// FIXME #12808: strange names to try to avoid interfering with
|
||||
// field accesses of the contained type via Deref
|
||||
_ptr: NonZero<*mut RcBox<T>>,
|
||||
_nosend: marker::NoSend,
|
||||
_noshare: marker::NoSync
|
||||
}
|
||||
|
||||
/// A weak version of `Rc<T>`.
|
||||
///
|
||||
/// Weak references do not count when determining if the inner value should be dropped.
|
||||
///
|
||||
/// See the [module level documentation](../index.html) for more.
|
||||
#[unsafe_no_drop_flag]
|
||||
#[unstable = "Weak pointers may not belong in this module."]
|
||||
#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
|
||||
pub struct Weak<T> {
|
||||
// FIXME #12808: strange names to try to avoid interfering with
|
||||
// field accesses of the contained type via Deref
|
||||
_ptr: NonZero<*mut RcBox<T>>,
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
|
||||
#[allow(unstable)]
|
||||
impl<T> !marker::Send for Weak<T> {}
|
||||
|
||||
#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
|
||||
#[allow(unstable)]
|
||||
impl<T> !marker::Sync for Weak<T> {}
|
||||
|
||||
|
||||
#[unstable = "Weak pointers may not belong in this module."]
|
||||
impl<T> Weak<T> {
|
||||
/// Upgrades a weak reference to a strong reference.
|
||||
///
|
||||
/// Upgrades the `Weak<T>` reference to an `Rc<T>`, if possible.
|
||||
///
|
||||
/// Returns `None` if there were no strong references and the data was destroyed.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use std::rc::Rc;
|
||||
///
|
||||
/// let five = Rc::new(5i);
|
||||
///
|
||||
/// let weak_five = five.downgrade();
|
||||
///
|
||||
/// let strong_five: Option<Rc<_>> = weak_five.upgrade();
|
||||
/// ```
|
||||
#[cfg(stage0)] // NOTE remove after next snapshot
|
||||
pub fn upgrade(&self) -> Option<Rc<T>> {
|
||||
if self.strong() == 0 {
|
||||
None
|
||||
} else {
|
||||
self.inc_strong();
|
||||
Some(Rc { _ptr: self._ptr, _nosend: marker::NoSend, _noshare: marker::NoSync })
|
||||
}
|
||||
}
|
||||
|
||||
/// Upgrades a weak reference to a strong reference.
|
||||
///
|
||||
|
@ -792,7 +659,6 @@ pub fn upgrade(&self) -> Option<Rc<T>> {
|
|||
///
|
||||
/// let strong_five: Option<Rc<_>> = weak_five.upgrade();
|
||||
/// ```
|
||||
#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
|
||||
pub fn upgrade(&self) -> Option<Rc<T>> {
|
||||
if self.strong() == 0 {
|
||||
None
|
||||
|
@ -849,25 +715,6 @@ fn drop(&mut self) {
|
|||
|
||||
#[unstable = "Weak pointers may not belong in this module."]
|
||||
impl<T> Clone for Weak<T> {
|
||||
/// Makes a clone of the `Weak<T>`.
|
||||
///
|
||||
/// This increases the weak reference count.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use std::rc::Rc;
|
||||
///
|
||||
/// let weak_five = Rc::new(5i).downgrade();
|
||||
///
|
||||
/// weak_five.clone();
|
||||
/// ```
|
||||
#[inline]
|
||||
#[cfg(stage0)] // NOTE remove after next snapshot
|
||||
fn clone(&self) -> Weak<T> {
|
||||
self.inc_weak();
|
||||
Weak { _ptr: self._ptr, _nosend: marker::NoSend, _noshare: marker::NoSync }
|
||||
}
|
||||
|
||||
/// Makes a clone of the `Weak<T>`.
|
||||
///
|
||||
|
@ -883,15 +730,14 @@ fn clone(&self) -> Weak<T> {
|
|||
/// weak_five.clone();
|
||||
/// ```
|
||||
#[inline]
|
||||
#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
|
||||
fn clone(&self) -> Weak<T> {
|
||||
self.inc_weak();
|
||||
Weak { _ptr: self._ptr }
|
||||
}
|
||||
}
|
||||
|
||||
#[unstable = "Show is experimental."]
|
||||
impl<T: fmt::Show> fmt::Show for Weak<T> {
|
||||
#[stable]
|
||||
impl<T: fmt::Debug> fmt::Debug for Weak<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "(Weak)")
|
||||
}
|
||||
|
@ -1134,7 +980,7 @@ fn test_cowrc_clone_weak() {
|
|||
#[test]
|
||||
fn test_show() {
|
||||
let foo = Rc::new(75u);
|
||||
assert!(format!("{:?}", foo) == "Rc(75u)")
|
||||
assert_eq!(format!("{:?}", foo), "75");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -330,7 +330,7 @@ pub fn from_bytes(bytes: &[u8]) -> Bitv {
|
|||
|
||||
if extra_bytes > 0 {
|
||||
let mut last_word = 0u32;
|
||||
for (i, &byte) in bytes[(complete_words*4)..].iter().enumerate() {
|
||||
for (i, &byte) in bytes[complete_words*4..].iter().enumerate() {
|
||||
last_word |= (reverse_bits(byte) as u32) << (i * 8);
|
||||
}
|
||||
bitv.storage.push(last_word);
|
||||
|
@ -972,7 +972,7 @@ fn cmp(&self, other: &Bitv) -> Ordering {
|
|||
}
|
||||
|
||||
#[stable]
|
||||
impl fmt::Show for Bitv {
|
||||
impl fmt::Debug for Bitv {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
for bit in self.iter() {
|
||||
try!(write!(fmt, "{}", if bit { 1u32 } else { 0u32 }));
|
||||
|
@ -1727,7 +1727,7 @@ pub fn remove(&mut self, value: &uint) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Show for BitvSet {
|
||||
impl fmt::Debug for BitvSet {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
try!(write!(fmt, "BitvSet {{"));
|
||||
let mut first = true;
|
||||
|
@ -2622,7 +2622,7 @@ fn test_bitv_set_show() {
|
|||
s.insert(10);
|
||||
s.insert(50);
|
||||
s.insert(2);
|
||||
assert_eq!("BitvSet {1u, 2u, 10u, 50u}", format!("{:?}", s));
|
||||
assert_eq!("BitvSet {1, 2, 10, 50}", format!("{:?}", s));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
use core::borrow::BorrowFrom;
|
||||
use core::cmp::Ordering;
|
||||
use core::default::Default;
|
||||
use core::fmt::Show;
|
||||
use core::fmt::Debug;
|
||||
use core::hash::{Hash, Hasher};
|
||||
use core::iter::{Map, FromIterator};
|
||||
use core::ops::{Index, IndexMut};
|
||||
|
@ -871,7 +871,7 @@ fn cmp(&self, other: &BTreeMap<K, V>) -> Ordering {
|
|||
}
|
||||
|
||||
#[stable]
|
||||
impl<K: Show, V: Show> Show for BTreeMap<K, V> {
|
||||
impl<K: Debug, V: Debug> Debug for BTreeMap<K, V> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
try!(write!(f, "BTreeMap {{"));
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
use core::borrow::BorrowFrom;
|
||||
use core::cmp::Ordering::{Greater, Less, Equal};
|
||||
use core::iter::Zip;
|
||||
use core::ops::{Deref, DerefMut};
|
||||
use core::ops::{Deref, DerefMut, Index, IndexMut};
|
||||
use core::ptr::Unique;
|
||||
use core::{slice, mem, ptr, cmp, num, raw};
|
||||
use alloc::heap;
|
||||
|
@ -1487,7 +1487,7 @@ pub fn next_kv_item_back(&mut self) -> Option<(K, V)> {
|
|||
|
||||
macro_rules! node_slice_impl {
|
||||
($NodeSlice:ident, $Traversal:ident,
|
||||
$as_slices_internal:ident, $slice_from:ident, $slice_to:ident, $iter:ident) => {
|
||||
$as_slices_internal:ident, $index:ident, $iter:ident) => {
|
||||
impl<'a, K: Ord + 'a, V: 'a> $NodeSlice<'a, K, V> {
|
||||
/// Performs linear search in a slice. Returns a tuple of (index, is_exact_match).
|
||||
fn search_linear<Q: ?Sized>(&self, key: &Q) -> (uint, bool)
|
||||
|
@ -1521,10 +1521,10 @@ pub fn slice_from(self, min_key: &K) -> $NodeSlice<'a, K, V> {
|
|||
edges: if !self.has_edges {
|
||||
self.edges
|
||||
} else {
|
||||
self.edges.$slice_from(pos)
|
||||
self.edges.$index(&(pos ..))
|
||||
},
|
||||
keys: self.keys.slice_from(pos),
|
||||
vals: self.vals.$slice_from(pos),
|
||||
keys: &self.keys[pos ..],
|
||||
vals: self.vals.$index(&(pos ..)),
|
||||
head_is_edge: !pos_is_kv,
|
||||
tail_is_edge: self.tail_is_edge,
|
||||
}
|
||||
|
@ -1550,10 +1550,10 @@ pub fn slice_to(self, max_key: &K) -> $NodeSlice<'a, K, V> {
|
|||
edges: if !self.has_edges {
|
||||
self.edges
|
||||
} else {
|
||||
self.edges.$slice_to(pos + 1)
|
||||
self.edges.$index(&(.. (pos + 1)))
|
||||
},
|
||||
keys: self.keys.slice_to(pos),
|
||||
vals: self.vals.$slice_to(pos),
|
||||
keys: &self.keys[..pos],
|
||||
vals: self.vals.$index(&(.. pos)),
|
||||
head_is_edge: self.head_is_edge,
|
||||
tail_is_edge: !pos_is_kv,
|
||||
}
|
||||
|
@ -1583,6 +1583,5 @@ pub fn $iter(self) -> $Traversal<'a, K, V> {
|
|||
}
|
||||
}
|
||||
|
||||
node_slice_impl!(NodeSlice, Traversal, as_slices_internal, slice_from, slice_to, iter);
|
||||
node_slice_impl!(MutNodeSlice, MutTraversal, as_slices_internal_mut, slice_from_mut,
|
||||
slice_to_mut, iter_mut);
|
||||
node_slice_impl!(NodeSlice, Traversal, as_slices_internal, index, iter);
|
||||
node_slice_impl!(MutNodeSlice, MutTraversal, as_slices_internal_mut, index_mut, iter_mut);
|
||||
|
|
|
@ -16,11 +16,8 @@
|
|||
use core::borrow::BorrowFrom;
|
||||
use core::cmp::Ordering::{self, Less, Greater, Equal};
|
||||
use core::default::Default;
|
||||
use core::fmt::Show;
|
||||
use core::fmt::Debug;
|
||||
use core::fmt;
|
||||
// NOTE(stage0) remove import after a snapshot
|
||||
#[cfg(stage0)]
|
||||
use core::hash::Hash;
|
||||
use core::iter::{Peekable, Map, FromIterator};
|
||||
use core::ops::{BitOr, BitAnd, BitXor, Sub};
|
||||
|
||||
|
@ -592,7 +589,7 @@ fn bitor(self, rhs: &BTreeSet<T>) -> BTreeSet<T> {
|
|||
}
|
||||
|
||||
#[stable]
|
||||
impl<T: Show> Show for BTreeSet<T> {
|
||||
impl<T: Debug> Debug for BTreeSet<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
try!(write!(f, "BTreeSet {{"));
|
||||
|
||||
|
@ -892,7 +889,7 @@ fn test_show() {
|
|||
|
||||
let set_str = format!("{:?}", set);
|
||||
|
||||
assert_eq!(set_str, "BTreeSet {1i, 2i}");
|
||||
assert_eq!(set_str, "BTreeSet {1, 2}");
|
||||
assert_eq!(format!("{:?}", empty), "BTreeSet {}");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -874,7 +874,7 @@ fn clone(&self) -> DList<A> {
|
|||
}
|
||||
|
||||
#[stable]
|
||||
impl<A: fmt::Show> fmt::Show for DList<A> {
|
||||
impl<A: fmt::Debug> fmt::Debug for DList<A> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
try!(write!(f, "DList ["));
|
||||
|
||||
|
@ -1333,7 +1333,7 @@ fn test_fuzz() {
|
|||
#[test]
|
||||
fn test_show() {
|
||||
let list: DList<int> = range(0i, 10).collect();
|
||||
assert_eq!(format!("{:?}", list), "DList [0i, 1i, 2i, 3i, 4i, 5i, 6i, 7i, 8i, 9i]");
|
||||
assert_eq!(format!("{:?}", list), "DList [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]");
|
||||
|
||||
let list: DList<&str> = vec!["just", "one", "test", "more"].iter()
|
||||
.map(|&s| s)
|
||||
|
|
|
@ -31,7 +31,7 @@ pub struct EnumSet<E> {
|
|||
|
||||
impl<E> Copy for EnumSet<E> {}
|
||||
|
||||
impl<E:CLike+fmt::Show> fmt::Show for EnumSet<E> {
|
||||
impl<E:CLike + fmt::Debug> fmt::Debug for EnumSet<E> {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
try!(write!(fmt, "EnumSet {{"));
|
||||
let mut first = true;
|
||||
|
|
|
@ -12,13 +12,13 @@
|
|||
#[macro_export]
|
||||
#[stable]
|
||||
macro_rules! vec {
|
||||
($x:expr; $y:expr) => ({
|
||||
let xs: $crate::boxed::Box<[_]> = $crate::boxed::Box::new([$x; $y]);
|
||||
$crate::slice::SliceExt::into_vec(xs)
|
||||
});
|
||||
($($x:expr),*) => ({
|
||||
let xs: $crate::boxed::Box<[_]> = $crate::boxed::Box::new([$($x),*]);
|
||||
$crate::slice::SliceExt::into_vec(xs)
|
||||
});
|
||||
($x:expr; $y:expr) => (
|
||||
<[_] as $crate::slice::SliceExt>::into_vec(
|
||||
$crate::boxed::Box::new([$x; $y]))
|
||||
);
|
||||
($($x:expr),*) => (
|
||||
<[_] as $crate::slice::SliceExt>::into_vec(
|
||||
$crate::boxed::Box::new([$($x),*]))
|
||||
);
|
||||
($($x:expr,)*) => (vec![$($x),*])
|
||||
}
|
||||
|
|
|
@ -578,7 +578,7 @@ pub fn as_mut_slices<'a>(&'a mut self) -> (&'a mut [T], &'a mut [T]) {
|
|||
|
||||
if contiguous {
|
||||
let (empty, buf) = buf.split_at_mut(0);
|
||||
(buf.slice_mut(tail, head), empty)
|
||||
(&mut buf[tail .. head], empty)
|
||||
} else {
|
||||
let (mid, right) = buf.split_at_mut(tail);
|
||||
let (left, _) = mid.split_at_mut(head);
|
||||
|
@ -1611,7 +1611,7 @@ fn extend<T: Iterator<Item=A>>(&mut self, mut iterator: T) {
|
|||
}
|
||||
|
||||
#[stable]
|
||||
impl<T: fmt::Show> fmt::Show for RingBuf<T> {
|
||||
impl<T: fmt::Debug> fmt::Debug for RingBuf<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
try!(write!(f, "RingBuf ["));
|
||||
|
||||
|
@ -1630,7 +1630,7 @@ mod tests {
|
|||
use self::Taggypar::*;
|
||||
use prelude::*;
|
||||
use core::iter;
|
||||
use std::fmt::Show;
|
||||
use std::fmt::Debug;
|
||||
use std::hash::{self, SipHasher};
|
||||
use test::Bencher;
|
||||
use test;
|
||||
|
@ -1678,7 +1678,7 @@ fn test_simple() {
|
|||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn test_parameterized<T:Clone + PartialEq + Show>(a: T, b: T, c: T, d: T) {
|
||||
fn test_parameterized<T:Clone + PartialEq + Debug>(a: T, b: T, c: T, d: T) {
|
||||
let mut deq = RingBuf::new();
|
||||
assert_eq!(deq.len(), 0);
|
||||
deq.push_front(a.clone());
|
||||
|
@ -2302,7 +2302,7 @@ fn test_ord() {
|
|||
#[test]
|
||||
fn test_show() {
|
||||
let ringbuf: RingBuf<int> = range(0i, 10).collect();
|
||||
assert_eq!(format!("{:?}", ringbuf), "RingBuf [0i, 1i, 2i, 3i, 4i, 5i, 6i, 7i, 8i, 9i]");
|
||||
assert_eq!(format!("{:?}", ringbuf), "RingBuf [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]");
|
||||
|
||||
let ringbuf: RingBuf<&str> = vec!["just", "one", "test", "more"].iter()
|
||||
.map(|&s| s)
|
||||
|
|
|
@ -169,29 +169,16 @@ pub trait SliceExt {
|
|||
#[unstable = "uncertain about this API approach"]
|
||||
fn move_from(&mut self, src: Vec<Self::Item>, start: uint, end: uint) -> uint;
|
||||
|
||||
/// Returns a subslice spanning the interval [`start`, `end`).
|
||||
///
|
||||
/// Panics when the end of the new slice lies beyond the end of the
|
||||
/// original slice (i.e. when `end > self.len()`) or when `start > end`.
|
||||
///
|
||||
/// Slicing with `start` equal to `end` yields an empty slice.
|
||||
#[unstable = "will be replaced by slice syntax"]
|
||||
/// Deprecated: use `&s[start .. end]` notation instead.
|
||||
#[deprecated = "use &s[start .. end] instead"]
|
||||
fn slice(&self, start: uint, end: uint) -> &[Self::Item];
|
||||
|
||||
/// Returns a subslice from `start` to the end of the slice.
|
||||
///
|
||||
/// Panics when `start` is strictly greater than the length of the original slice.
|
||||
///
|
||||
/// Slicing from `self.len()` yields an empty slice.
|
||||
#[unstable = "will be replaced by slice syntax"]
|
||||
/// Deprecated: use `&s[start..]` notation instead.
|
||||
#[deprecated = "use &s[start..] isntead"]
|
||||
fn slice_from(&self, start: uint) -> &[Self::Item];
|
||||
|
||||
/// Returns a subslice from the start of the slice to `end`.
|
||||
///
|
||||
/// Panics when `end` is strictly greater than the length of the original slice.
|
||||
///
|
||||
/// Slicing to `0` yields an empty slice.
|
||||
#[unstable = "will be replaced by slice syntax"]
|
||||
/// Deprecated: use `&s[..end]` notation instead.
|
||||
#[deprecated = "use &s[..end] instead"]
|
||||
fn slice_to(&self, end: uint) -> &[Self::Item];
|
||||
|
||||
/// Divides one slice into two at an index.
|
||||
|
@ -378,29 +365,16 @@ fn is_empty(&self) -> bool { self.len() == 0 }
|
|||
#[stable]
|
||||
fn as_mut_slice(&mut self) -> &mut [Self::Item];
|
||||
|
||||
/// Returns a mutable subslice spanning the interval [`start`, `end`).
|
||||
///
|
||||
/// Panics when the end of the new slice lies beyond the end of the
|
||||
/// original slice (i.e. when `end > self.len()`) or when `start > end`.
|
||||
///
|
||||
/// Slicing with `start` equal to `end` yields an empty slice.
|
||||
#[unstable = "will be replaced by slice syntax"]
|
||||
/// Deprecated: use `&mut s[start .. end]` instead.
|
||||
#[deprecated = "use &mut s[start .. end] instead"]
|
||||
fn slice_mut(&mut self, start: uint, end: uint) -> &mut [Self::Item];
|
||||
|
||||
/// Returns a mutable subslice from `start` to the end of the slice.
|
||||
///
|
||||
/// Panics when `start` is strictly greater than the length of the original slice.
|
||||
///
|
||||
/// Slicing from `self.len()` yields an empty slice.
|
||||
#[unstable = "will be replaced by slice syntax"]
|
||||
/// Deprecated: use `&mut s[start ..]` instead.
|
||||
#[deprecated = "use &mut s[start ..] instead"]
|
||||
fn slice_from_mut(&mut self, start: uint) -> &mut [Self::Item];
|
||||
|
||||
/// Returns a mutable subslice from the start of the slice to `end`.
|
||||
///
|
||||
/// Panics when `end` is strictly greater than the length of the original slice.
|
||||
///
|
||||
/// Slicing to `0` yields an empty slice.
|
||||
#[unstable = "will be replaced by slice syntax"]
|
||||
/// Deprecated: use `&mut s[.. end]` instead.
|
||||
#[deprecated = "use &mut s[.. end] instead"]
|
||||
fn slice_to_mut(&mut self, end: uint) -> &mut [Self::Item];
|
||||
|
||||
/// Returns an iterator that allows modifying each value
|
||||
|
@ -712,7 +686,7 @@ fn sort_by<F>(&mut self, compare: F) where F: FnMut(&T, &T) -> Ordering {
|
|||
|
||||
#[inline]
|
||||
fn move_from(&mut self, mut src: Vec<T>, start: uint, end: uint) -> uint {
|
||||
for (a, b) in self.iter_mut().zip(src.slice_mut(start, end).iter_mut()) {
|
||||
for (a, b) in self.iter_mut().zip(src[start .. end].iter_mut()) {
|
||||
mem::swap(a, b);
|
||||
}
|
||||
cmp::min(self.len(), end-start)
|
||||
|
@ -720,17 +694,17 @@ fn move_from(&mut self, mut src: Vec<T>, start: uint, end: uint) -> uint {
|
|||
|
||||
#[inline]
|
||||
fn slice<'a>(&'a self, start: uint, end: uint) -> &'a [T] {
|
||||
core_slice::SliceExt::slice(self, start, end)
|
||||
&self[start .. end]
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn slice_from<'a>(&'a self, start: uint) -> &'a [T] {
|
||||
core_slice::SliceExt::slice_from(self, start)
|
||||
&self[start ..]
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn slice_to<'a>(&'a self, end: uint) -> &'a [T] {
|
||||
core_slice::SliceExt::slice_to(self, end)
|
||||
&self[.. end]
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -834,17 +808,17 @@ fn as_mut_slice<'a>(&'a mut self) -> &'a mut [T] {
|
|||
|
||||
#[inline]
|
||||
fn slice_mut<'a>(&'a mut self, start: uint, end: uint) -> &'a mut [T] {
|
||||
core_slice::SliceExt::slice_mut(self, start, end)
|
||||
&mut self[start .. end]
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn slice_from_mut<'a>(&'a mut self, start: uint) -> &'a mut [T] {
|
||||
core_slice::SliceExt::slice_from_mut(self, start)
|
||||
&mut self[start ..]
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn slice_to_mut<'a>(&'a mut self, end: uint) -> &'a mut [T] {
|
||||
core_slice::SliceExt::slice_to_mut(self, end)
|
||||
&mut self[.. end]
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -2409,8 +2383,12 @@ fn test_windowsator_0() {
|
|||
|
||||
#[test]
|
||||
fn test_chunksator() {
|
||||
use core::iter::ExactSizeIterator;
|
||||
|
||||
let v = &[1i,2,3,4,5];
|
||||
|
||||
assert_eq!(v.chunks(2).len(), 3);
|
||||
|
||||
let chunks: &[&[int]] = &[&[1i,2], &[3,4], &[5]];
|
||||
assert_eq!(v.chunks(2).collect::<Vec<&[int]>>(), chunks);
|
||||
let chunks: &[&[int]] = &[&[1i,2,3], &[4,5]];
|
||||
|
@ -2476,19 +2454,19 @@ macro_rules! test_show_vec {
|
|||
}
|
||||
let empty: Vec<int> = vec![];
|
||||
test_show_vec!(empty, "[]");
|
||||
test_show_vec!(vec![1i], "[1i]");
|
||||
test_show_vec!(vec![1i, 2, 3], "[1i, 2i, 3i]");
|
||||
test_show_vec!(vec![1i], "[1]");
|
||||
test_show_vec!(vec![1i, 2, 3], "[1, 2, 3]");
|
||||
test_show_vec!(vec![vec![], vec![1u], vec![1u, 1u]],
|
||||
"[[], [1u], [1u, 1u]]");
|
||||
"[[], [1], [1, 1]]");
|
||||
|
||||
let empty_mut: &mut [int] = &mut[];
|
||||
test_show_vec!(empty_mut, "[]");
|
||||
let v: &mut[int] = &mut[1];
|
||||
test_show_vec!(v, "[1i]");
|
||||
test_show_vec!(v, "[1]");
|
||||
let v: &mut[int] = &mut[1, 2, 3];
|
||||
test_show_vec!(v, "[1i, 2i, 3i]");
|
||||
test_show_vec!(v, "[1, 2, 3]");
|
||||
let v: &mut [&mut[uint]] = &mut[&mut[], &mut[1u], &mut[1u, 1u]];
|
||||
test_show_vec!(v, "[[], [1u], [1u, 1u]]");
|
||||
test_show_vec!(v, "[[], [1], [1, 1]]");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -2675,7 +2653,10 @@ fn test_get_mut() {
|
|||
|
||||
#[test]
|
||||
fn test_mut_chunks() {
|
||||
use core::iter::ExactSizeIterator;
|
||||
|
||||
let mut v = [0u8, 1, 2, 3, 4, 5, 6];
|
||||
assert_eq!(v.chunks_mut(2).len(), 4);
|
||||
for (i, chunk) in v.chunks_mut(3).enumerate() {
|
||||
for x in chunk.iter_mut() {
|
||||
*x = i as u8;
|
||||
|
|
|
@ -750,67 +750,17 @@ fn lines_any(&self) -> LinesAny {
|
|||
core_str::StrExt::lines_any(&self[])
|
||||
}
|
||||
|
||||
/// Returns a slice of the given string from the byte range
|
||||
/// [`begin`..`end`).
|
||||
///
|
||||
/// This operation is `O(1)`.
|
||||
///
|
||||
/// Panics when `begin` and `end` do not point to valid characters
|
||||
/// or point beyond the last character of the string.
|
||||
///
|
||||
/// See also `slice_to` and `slice_from` for slicing prefixes and
|
||||
/// suffixes of strings, and `slice_chars` for slicing based on
|
||||
/// code point counts.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// let s = "Löwe 老虎 Léopard";
|
||||
/// assert_eq!(s.slice(0, 1), "L");
|
||||
///
|
||||
/// assert_eq!(s.slice(1, 9), "öwe 老");
|
||||
///
|
||||
/// // these will panic:
|
||||
/// // byte 2 lies within `ö`:
|
||||
/// // s.slice(2, 3);
|
||||
///
|
||||
/// // byte 8 lies within `老`
|
||||
/// // s.slice(1, 8);
|
||||
///
|
||||
/// // byte 100 is outside the string
|
||||
/// // s.slice(3, 100);
|
||||
/// ```
|
||||
#[unstable = "use slice notation [a..b] instead"]
|
||||
fn slice(&self, begin: uint, end: uint) -> &str {
|
||||
core_str::StrExt::slice(&self[], begin, end)
|
||||
}
|
||||
/// Deprecated: use `s[a .. b]` instead.
|
||||
#[deprecated = "use slice notation [a..b] instead"]
|
||||
fn slice(&self, begin: uint, end: uint) -> &str;
|
||||
|
||||
/// Returns a slice of the string from `begin` to its end.
|
||||
///
|
||||
/// Equivalent to `self.slice(begin, self.len())`.
|
||||
///
|
||||
/// Panics when `begin` does not point to a valid character, or is
|
||||
/// out of bounds.
|
||||
///
|
||||
/// See also `slice`, `slice_to` and `slice_chars`.
|
||||
#[unstable = "use slice notation [a..] instead"]
|
||||
fn slice_from(&self, begin: uint) -> &str {
|
||||
core_str::StrExt::slice_from(&self[], begin)
|
||||
}
|
||||
/// Deprecated: use `s[a..]` instead.
|
||||
#[deprecated = "use slice notation [a..] instead"]
|
||||
fn slice_from(&self, begin: uint) -> &str;
|
||||
|
||||
/// Returns a slice of the string from the beginning to byte
|
||||
/// `end`.
|
||||
///
|
||||
/// Equivalent to `self.slice(0, end)`.
|
||||
///
|
||||
/// Panics when `end` does not point to a valid character, or is
|
||||
/// out of bounds.
|
||||
///
|
||||
/// See also `slice`, `slice_from` and `slice_chars`.
|
||||
#[unstable = "use slice notation [..a] instead"]
|
||||
fn slice_to(&self, end: uint) -> &str {
|
||||
core_str::StrExt::slice_to(&self[], end)
|
||||
}
|
||||
/// Deprecated: use `s[..a]` instead.
|
||||
#[deprecated = "use slice notation [..a] instead"]
|
||||
fn slice_to(&self, end: uint) -> &str;
|
||||
|
||||
/// Returns a slice of the string from the character range
|
||||
/// [`begin`..`end`).
|
||||
|
@ -1348,7 +1298,19 @@ fn trim_right(&self) -> &str {
|
|||
}
|
||||
|
||||
#[stable]
|
||||
impl StrExt for str {}
|
||||
impl StrExt for str {
|
||||
fn slice(&self, begin: uint, end: uint) -> &str {
|
||||
&self[begin..end]
|
||||
}
|
||||
|
||||
fn slice_from(&self, begin: uint) -> &str {
|
||||
&self[begin..]
|
||||
}
|
||||
|
||||
fn slice_to(&self, end: uint) -> &str {
|
||||
&self[..end]
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
use core::borrow::{Cow, IntoCow};
|
||||
use core::default::Default;
|
||||
use core::error::Error;
|
||||
use core::fmt;
|
||||
use core::hash;
|
||||
use core::iter::FromIterator;
|
||||
|
@ -40,6 +41,7 @@ pub struct String {
|
|||
|
||||
/// A possible error value from the `String::from_utf8` function.
|
||||
#[stable]
|
||||
#[derive(Show)]
|
||||
pub struct FromUtf8Error {
|
||||
bytes: Vec<u8>,
|
||||
error: Utf8Error,
|
||||
|
@ -48,6 +50,7 @@ pub struct FromUtf8Error {
|
|||
/// A possible error value from the `String::from_utf16` function.
|
||||
#[stable]
|
||||
#[allow(missing_copy_implementations)]
|
||||
#[derive(Show)]
|
||||
pub struct FromUtf16Error(());
|
||||
|
||||
impl String {
|
||||
|
@ -680,30 +683,28 @@ pub fn into_bytes(self) -> Vec<u8> { self.bytes }
|
|||
pub fn utf8_error(&self) -> Utf8Error { self.error }
|
||||
}
|
||||
|
||||
impl fmt::Show for FromUtf8Error {
|
||||
#[stable]
|
||||
impl fmt::Display for FromUtf8Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::String::fmt(self, f)
|
||||
fmt::Display::fmt(&self.error, f)
|
||||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl fmt::String for FromUtf8Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::String::fmt(&self.error, f)
|
||||
}
|
||||
impl Error for FromUtf8Error {
|
||||
fn description(&self) -> &str { "invalid utf-8" }
|
||||
}
|
||||
|
||||
impl fmt::Show for FromUtf16Error {
|
||||
#[stable]
|
||||
impl fmt::Display for FromUtf16Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::String::fmt(self, f)
|
||||
fmt::Display::fmt("invalid utf-16: lone surrogate found", f)
|
||||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl fmt::String for FromUtf16Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::String::fmt("invalid utf-16: lone surrogate found", f)
|
||||
}
|
||||
impl Error for FromUtf16Error {
|
||||
fn description(&self) -> &str { "invalid utf-16" }
|
||||
}
|
||||
|
||||
#[stable]
|
||||
|
@ -814,18 +815,18 @@ fn default() -> String {
|
|||
}
|
||||
|
||||
#[stable]
|
||||
impl fmt::String for String {
|
||||
impl fmt::Display for String {
|
||||
#[inline]
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::String::fmt(&**self, f)
|
||||
fmt::Display::fmt(&**self, f)
|
||||
}
|
||||
}
|
||||
|
||||
#[unstable = "waiting on fmt stabilization"]
|
||||
impl fmt::Show for String {
|
||||
#[stable]
|
||||
impl fmt::Debug for String {
|
||||
#[inline]
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::Show::fmt(&**self, f)
|
||||
fmt::Debug::fmt(&**self, f)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -848,6 +849,7 @@ fn add(mut self, other: &str) -> String {
|
|||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl ops::Index<ops::Range<uint>> for String {
|
||||
type Output = str;
|
||||
#[inline]
|
||||
|
@ -855,6 +857,7 @@ fn index(&self, index: &ops::Range<uint>) -> &str {
|
|||
&self[][*index]
|
||||
}
|
||||
}
|
||||
#[stable]
|
||||
impl ops::Index<ops::RangeTo<uint>> for String {
|
||||
type Output = str;
|
||||
#[inline]
|
||||
|
@ -862,6 +865,7 @@ fn index(&self, index: &ops::RangeTo<uint>) -> &str {
|
|||
&self[][*index]
|
||||
}
|
||||
}
|
||||
#[stable]
|
||||
impl ops::Index<ops::RangeFrom<uint>> for String {
|
||||
type Output = str;
|
||||
#[inline]
|
||||
|
@ -869,6 +873,7 @@ fn index(&self, index: &ops::RangeFrom<uint>) -> &str {
|
|||
&self[][*index]
|
||||
}
|
||||
}
|
||||
#[stable]
|
||||
impl ops::Index<ops::FullRange> for String {
|
||||
type Output = str;
|
||||
#[inline]
|
||||
|
@ -934,7 +939,7 @@ pub trait ToString {
|
|||
fn to_string(&self) -> String;
|
||||
}
|
||||
|
||||
impl<T: fmt::String + ?Sized> ToString for T {
|
||||
impl<T: fmt::Display + ?Sized> ToString for T {
|
||||
#[inline]
|
||||
fn to_string(&self) -> String {
|
||||
use core::fmt::Writer;
|
||||
|
@ -1295,10 +1300,10 @@ fn test_simple_types() {
|
|||
fn test_vectors() {
|
||||
let x: Vec<int> = vec![];
|
||||
assert_eq!(format!("{:?}", x), "[]");
|
||||
assert_eq!(format!("{:?}", vec![1i]), "[1i]");
|
||||
assert_eq!(format!("{:?}", vec![1i, 2, 3]), "[1i, 2i, 3i]");
|
||||
assert_eq!(format!("{:?}", vec![1i]), "[1]");
|
||||
assert_eq!(format!("{:?}", vec![1i, 2, 3]), "[1, 2, 3]");
|
||||
assert!(format!("{:?}", vec![vec![], vec![1i], vec![1i, 1]]) ==
|
||||
"[[], [1i], [1i, 1i]]");
|
||||
"[[], [1], [1, 1]]");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -1229,7 +1229,7 @@ fn hash(&self, state: &mut S) {
|
|||
}
|
||||
}
|
||||
|
||||
#[unstable = "waiting on Index stability"]
|
||||
#[stable]
|
||||
impl<T> Index<uint> for Vec<T> {
|
||||
type Output = T;
|
||||
|
||||
|
@ -1239,6 +1239,7 @@ fn index<'a>(&'a self, index: &uint) -> &'a T {
|
|||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl<T> IndexMut<uint> for Vec<T> {
|
||||
type Output = T;
|
||||
|
||||
|
@ -1249,6 +1250,7 @@ fn index_mut<'a>(&'a mut self, index: &uint) -> &'a mut T {
|
|||
}
|
||||
|
||||
|
||||
#[stable]
|
||||
impl<T> ops::Index<ops::Range<uint>> for Vec<T> {
|
||||
type Output = [T];
|
||||
#[inline]
|
||||
|
@ -1256,6 +1258,7 @@ fn index(&self, index: &ops::Range<uint>) -> &[T] {
|
|||
self.as_slice().index(index)
|
||||
}
|
||||
}
|
||||
#[stable]
|
||||
impl<T> ops::Index<ops::RangeTo<uint>> for Vec<T> {
|
||||
type Output = [T];
|
||||
#[inline]
|
||||
|
@ -1263,6 +1266,7 @@ fn index(&self, index: &ops::RangeTo<uint>) -> &[T] {
|
|||
self.as_slice().index(index)
|
||||
}
|
||||
}
|
||||
#[stable]
|
||||
impl<T> ops::Index<ops::RangeFrom<uint>> for Vec<T> {
|
||||
type Output = [T];
|
||||
#[inline]
|
||||
|
@ -1270,6 +1274,7 @@ fn index(&self, index: &ops::RangeFrom<uint>) -> &[T] {
|
|||
self.as_slice().index(index)
|
||||
}
|
||||
}
|
||||
#[stable]
|
||||
impl<T> ops::Index<ops::FullRange> for Vec<T> {
|
||||
type Output = [T];
|
||||
#[inline]
|
||||
|
@ -1278,6 +1283,7 @@ fn index(&self, _index: &ops::FullRange) -> &[T] {
|
|||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl<T> ops::IndexMut<ops::Range<uint>> for Vec<T> {
|
||||
type Output = [T];
|
||||
#[inline]
|
||||
|
@ -1285,6 +1291,7 @@ fn index_mut(&mut self, index: &ops::Range<uint>) -> &mut [T] {
|
|||
self.as_mut_slice().index_mut(index)
|
||||
}
|
||||
}
|
||||
#[stable]
|
||||
impl<T> ops::IndexMut<ops::RangeTo<uint>> for Vec<T> {
|
||||
type Output = [T];
|
||||
#[inline]
|
||||
|
@ -1292,6 +1299,7 @@ fn index_mut(&mut self, index: &ops::RangeTo<uint>) -> &mut [T] {
|
|||
self.as_mut_slice().index_mut(index)
|
||||
}
|
||||
}
|
||||
#[stable]
|
||||
impl<T> ops::IndexMut<ops::RangeFrom<uint>> for Vec<T> {
|
||||
type Output = [T];
|
||||
#[inline]
|
||||
|
@ -1299,6 +1307,7 @@ fn index_mut(&mut self, index: &ops::RangeFrom<uint>) -> &mut [T] {
|
|||
self.as_mut_slice().index_mut(index)
|
||||
}
|
||||
}
|
||||
#[stable]
|
||||
impl<T> ops::IndexMut<ops::FullRange> for Vec<T> {
|
||||
type Output = [T];
|
||||
#[inline]
|
||||
|
@ -1307,7 +1316,6 @@ fn index_mut(&mut self, _index: &ops::FullRange) -> &mut [T] {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
#[stable]
|
||||
impl<T> ops::Deref for Vec<T> {
|
||||
type Target = [T];
|
||||
|
@ -1486,10 +1494,10 @@ fn default() -> Vec<T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[unstable = "waiting on Show stability"]
|
||||
impl<T: fmt::Show> fmt::Show for Vec<T> {
|
||||
#[stable]
|
||||
impl<T: fmt::Debug> fmt::Debug for Vec<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::Show::fmt(self.as_slice(), f)
|
||||
fmt::Debug::fmt(self.as_slice(), f)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2158,7 +2166,7 @@ fn test_index_out_of_bounds() {
|
|||
#[should_fail]
|
||||
fn test_slice_out_of_bounds_1() {
|
||||
let x: Vec<int> = vec![1, 2, 3, 4, 5];
|
||||
&x[(-1)..];
|
||||
&x[-1..];
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -2172,7 +2180,7 @@ fn test_slice_out_of_bounds_2() {
|
|||
#[should_fail]
|
||||
fn test_slice_out_of_bounds_3() {
|
||||
let x: Vec<int> = vec![1, 2, 3, 4, 5];
|
||||
&x[(-1)..4];
|
||||
&x[-1..4];
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -513,7 +513,7 @@ fn cmp(&self, other: &VecMap<V>) -> Ordering {
|
|||
}
|
||||
|
||||
#[stable]
|
||||
impl<V: fmt::Show> fmt::Show for VecMap<V> {
|
||||
impl<V: fmt::Debug> fmt::Debug for VecMap<V> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
try!(write!(f, "VecMap {{"));
|
||||
|
||||
|
@ -990,7 +990,7 @@ fn test_show() {
|
|||
map.insert(3, 4i);
|
||||
|
||||
let map_str = format!("{:?}", map);
|
||||
assert!(map_str == "VecMap {1: 2i, 3: 4i}" || map_str == "{3: 4i, 1: 2i}");
|
||||
assert!(map_str == "VecMap {1: 2, 3: 4}" || map_str == "{3: 4, 1: 2}");
|
||||
assert_eq!(format!("{:?}", empty), "VecMap {}");
|
||||
}
|
||||
|
||||
|
|
|
@ -34,11 +34,11 @@
|
|||
//! use runtime reflection instead.
|
||||
//!
|
||||
//! ```rust
|
||||
//! use std::fmt::Show;
|
||||
//! use std::fmt::Debug;
|
||||
//! use std::any::Any;
|
||||
//!
|
||||
//! // Logger function for any type that implements Show.
|
||||
//! fn log<T: Any+Show>(value: &T) {
|
||||
//! // Logger function for any type that implements Debug.
|
||||
//! fn log<T: Any + Debug>(value: &T) {
|
||||
//! let value_any = value as &Any;
|
||||
//!
|
||||
//! // try to convert our value to a String. If successful, we want to
|
||||
|
@ -55,7 +55,7 @@
|
|||
//! }
|
||||
//!
|
||||
//! // This function wants to log its parameter out prior to doing work with it.
|
||||
//! fn do_work<T: Show+'static>(value: &T) {
|
||||
//! fn do_work<T: Debug + 'static>(value: &T) {
|
||||
//! log(value);
|
||||
//! // ...do some other work
|
||||
//! }
|
||||
|
@ -75,7 +75,7 @@
|
|||
use option::Option::{self, Some, None};
|
||||
use raw::TraitObject;
|
||||
use intrinsics;
|
||||
#[cfg(not(stage0))] use marker::Sized;
|
||||
use marker::Sized;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Any trait
|
||||
|
@ -175,17 +175,10 @@ pub struct TypeId {
|
|||
impl TypeId {
|
||||
/// Returns the `TypeId` of the type this generic function has been
|
||||
/// instantiated with
|
||||
#[cfg(not(stage0))]
|
||||
#[unstable = "may grow a `Reflect` bound soon via marker traits"]
|
||||
pub fn of<T: ?Sized + 'static>() -> TypeId {
|
||||
TypeId {
|
||||
t: unsafe { intrinsics::type_id::<T>() },
|
||||
}
|
||||
}
|
||||
|
||||
/// dox
|
||||
#[cfg(stage0)]
|
||||
pub fn of<T: 'static>() -> TypeId {
|
||||
unsafe { intrinsics::type_id::<T>() }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,10 +39,10 @@ fn hash(&self, state: &mut S) {
|
|||
}
|
||||
}
|
||||
|
||||
#[unstable = "waiting for Show to stabilize"]
|
||||
impl<T:fmt::Show> fmt::Show for [T; $N] {
|
||||
#[stable]
|
||||
impl<T: fmt::Debug> fmt::Debug for [T; $N] {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::Show::fmt(&&self[], f)
|
||||
fmt::Debug::fmt(&&self[], f)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -133,7 +133,6 @@ fn to_owned(&self) -> T { self.clone() }
|
|||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
#[derive(Show)]
|
||||
pub enum Cow<'a, T, B: ?Sized + 'a> where B: ToOwned<T> {
|
||||
/// Borrowed data.
|
||||
Borrowed(&'a B),
|
||||
|
@ -239,14 +238,27 @@ fn partial_cmp(&self, other: &Cow<'a, T, B>) -> Option<Ordering> {
|
|||
}
|
||||
|
||||
#[stable]
|
||||
impl<'a, T, B: ?Sized> fmt::String for Cow<'a, T, B> where
|
||||
B: fmt::String + ToOwned<T>,
|
||||
T: fmt::String,
|
||||
impl<'a, T, B: ?Sized> fmt::Debug for Cow<'a, T, B> where
|
||||
B: fmt::Debug + ToOwned<T>,
|
||||
T: fmt::Debug,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
Borrowed(ref b) => fmt::String::fmt(b, f),
|
||||
Owned(ref o) => fmt::String::fmt(o, f),
|
||||
Borrowed(ref b) => fmt::Debug::fmt(b, f),
|
||||
Owned(ref o) => fmt::Debug::fmt(o, f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl<'a, T, B: ?Sized> fmt::Display for Cow<'a, T, B> where
|
||||
B: fmt::Display + ToOwned<T>,
|
||||
T: fmt::Display,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
Borrowed(ref b) => fmt::Display::fmt(b, f),
|
||||
Owned(ref o) => fmt::Display::fmt(o, f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,14 +14,15 @@
|
|||
//!
|
||||
//! `Error` is a trait representing the basic expectations for error values,
|
||||
//! i.e. values of type `E` in `Result<T, E>`. At a minimum, errors must provide
|
||||
//! a description, but they may optionally provide additional detail and cause
|
||||
//! chain information:
|
||||
//! a description, but they may optionally provide additional detail (via
|
||||
//! `Display`) and cause chain information:
|
||||
//!
|
||||
//! ```
|
||||
//! trait Error {
|
||||
//! use std::fmt::Display;
|
||||
//!
|
||||
//! trait Error: Display {
|
||||
//! fn description(&self) -> &str;
|
||||
//!
|
||||
//! fn detail(&self) -> Option<String> { None }
|
||||
//! fn cause(&self) -> Option<&Error> { None }
|
||||
//! }
|
||||
//! ```
|
||||
|
@ -80,20 +81,15 @@
|
|||
|
||||
#![stable]
|
||||
|
||||
use prelude::v1::*;
|
||||
|
||||
use str::Utf8Error;
|
||||
use string::{FromUtf8Error, FromUtf16Error};
|
||||
use prelude::*;
|
||||
use fmt::Display;
|
||||
|
||||
/// Base functionality for all errors in Rust.
|
||||
#[unstable = "the exact API of this trait may change"]
|
||||
pub trait Error {
|
||||
pub trait Error: Display {
|
||||
/// A short description of the error; usually a static string.
|
||||
fn description(&self) -> &str;
|
||||
|
||||
/// A detailed description of the error, usually including dynamic information.
|
||||
fn detail(&self) -> Option<String> { None }
|
||||
|
||||
/// The lower-level cause of this error, if any.
|
||||
fn cause(&self) -> Option<&Error> { None }
|
||||
}
|
||||
|
@ -112,26 +108,3 @@ fn from_error(err: E) -> E {
|
|||
err
|
||||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl Error for Utf8Error {
|
||||
fn description(&self) -> &str {
|
||||
match *self {
|
||||
Utf8Error::TooShort => "invalid utf-8: not enough bytes",
|
||||
Utf8Error::InvalidByte(..) => "invalid utf-8: corrupt contents",
|
||||
}
|
||||
}
|
||||
|
||||
fn detail(&self) -> Option<String> { Some(self.to_string()) }
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl Error for FromUtf8Error {
|
||||
fn description(&self) -> &str { "invalid utf-8" }
|
||||
fn detail(&self) -> Option<String> { Some(self.to_string()) }
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl Error for FromUtf16Error {
|
||||
fn description(&self) -> &str { "invalid utf-16" }
|
||||
}
|
|
@ -179,7 +179,7 @@ pub fn float_to_str_bytes_common<T: Float, U, F>(
|
|||
_ => ()
|
||||
}
|
||||
|
||||
buf.slice_to_mut(end).reverse();
|
||||
buf[..end].reverse();
|
||||
|
||||
// Remember start of the fractional digits.
|
||||
// Points one beyond end of buf if none get generated,
|
||||
|
@ -316,7 +316,7 @@ struct Filler<'a> {
|
|||
|
||||
impl<'a> fmt::Writer for Filler<'a> {
|
||||
fn write_str(&mut self, s: &str) -> fmt::Result {
|
||||
slice::bytes::copy_memory(self.buf.slice_from_mut(*self.end),
|
||||
slice::bytes::copy_memory(&mut self.buf[(*self.end)..],
|
||||
s.as_bytes());
|
||||
*self.end += s.len();
|
||||
Ok(())
|
||||
|
|
|
@ -26,12 +26,15 @@
|
|||
use result;
|
||||
use slice::SliceExt;
|
||||
use slice;
|
||||
use str::{self, StrExt, Utf8Error};
|
||||
use str::{self, StrExt};
|
||||
|
||||
pub use self::num::radix;
|
||||
pub use self::num::Radix;
|
||||
pub use self::num::RadixFmt;
|
||||
|
||||
#[cfg(stage0)] pub use self::Debug as Show;
|
||||
#[cfg(stage0)] pub use self::Display as String;
|
||||
|
||||
mod num;
|
||||
mod float;
|
||||
pub mod rt;
|
||||
|
@ -46,7 +49,7 @@
|
|||
/// occurred. Any extra information must be arranged to be transmitted through
|
||||
/// some other means.
|
||||
#[unstable = "core and I/O reconciliation may alter this definition"]
|
||||
#[derive(Copy)]
|
||||
#[derive(Copy, Show)]
|
||||
pub struct Error;
|
||||
|
||||
/// A collection of methods that are required to format a message into a stream.
|
||||
|
@ -133,7 +136,7 @@ pub struct Argument<'a> {
|
|||
impl<'a> Argument<'a> {
|
||||
#[inline(never)]
|
||||
fn show_uint(x: &uint, f: &mut Formatter) -> Result {
|
||||
Show::fmt(x, f)
|
||||
Display::fmt(x, f)
|
||||
}
|
||||
|
||||
fn new<'b, T>(x: &'b T, f: fn(&T, &mut Formatter) -> Result) -> Argument<'b> {
|
||||
|
@ -214,14 +217,15 @@ pub struct Arguments<'a> {
|
|||
args: &'a [Argument<'a>],
|
||||
}
|
||||
|
||||
impl<'a> Show for Arguments<'a> {
|
||||
#[stable]
|
||||
impl<'a> Debug for Arguments<'a> {
|
||||
fn fmt(&self, fmt: &mut Formatter) -> Result {
|
||||
String::fmt(self, fmt)
|
||||
Display::fmt(self, fmt)
|
||||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl<'a> String for Arguments<'a> {
|
||||
impl<'a> Display for Arguments<'a> {
|
||||
fn fmt(&self, fmt: &mut Formatter) -> Result {
|
||||
write(fmt.buf, *self)
|
||||
}
|
||||
|
@ -229,20 +233,49 @@ fn fmt(&self, fmt: &mut Formatter) -> Result {
|
|||
|
||||
/// Format trait for the `:?` format. Useful for debugging, most all types
|
||||
/// should implement this.
|
||||
#[unstable = "I/O and core have yet to be reconciled"]
|
||||
#[deprecated = "renamed to Debug"]
|
||||
#[cfg(not(stage0))]
|
||||
pub trait Show {
|
||||
/// Formats the value using the given formatter.
|
||||
fn fmt(&self, &mut Formatter) -> Result;
|
||||
}
|
||||
|
||||
/// Format trait for the `:?` format. Useful for debugging, most all types
|
||||
/// should implement this.
|
||||
#[unstable = "I/O and core have yet to be reconciled"]
|
||||
pub trait Debug {
|
||||
/// Formats the value using the given formatter.
|
||||
fn fmt(&self, &mut Formatter) -> Result;
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
impl<T: Show + ?Sized> Debug for T {
|
||||
#[allow(deprecated)]
|
||||
fn fmt(&self, f: &mut Formatter) -> Result { Show::fmt(self, f) }
|
||||
}
|
||||
|
||||
/// When a value can be semantically expressed as a String, this trait may be
|
||||
/// used. It corresponds to the default format, `{}`.
|
||||
#[deprecated = "renamed to Display"]
|
||||
#[cfg(not(stage0))]
|
||||
pub trait String {
|
||||
/// Formats the value using the given formatter.
|
||||
fn fmt(&self, &mut Formatter) -> Result;
|
||||
}
|
||||
|
||||
/// When a value can be semantically expressed as a String, this trait may be
|
||||
/// used. It corresponds to the default format, `{}`.
|
||||
#[unstable = "I/O and core have yet to be reconciled"]
|
||||
pub trait String {
|
||||
pub trait Display {
|
||||
/// Formats the value using the given formatter.
|
||||
fn fmt(&self, &mut Formatter) -> Result;
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
impl<T: String + ?Sized> Display for T {
|
||||
#[allow(deprecated)]
|
||||
fn fmt(&self, f: &mut Formatter) -> Result { String::fmt(self, f) }
|
||||
}
|
||||
|
||||
/// Format trait for the `o` character
|
||||
#[unstable = "I/O and core have yet to be reconciled"]
|
||||
|
@ -583,9 +616,10 @@ pub fn width(&self) -> Option<uint> { self.width }
|
|||
pub fn precision(&self) -> Option<uint> { self.precision }
|
||||
}
|
||||
|
||||
impl Show for Error {
|
||||
#[stable]
|
||||
impl Display for Error {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
String::fmt("an error occurred when formatting an argument", f)
|
||||
Display::fmt("an error occurred when formatting an argument", f)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -611,9 +645,11 @@ pub fn argumentuint<'a>(s: &'a uint) -> Argument<'a> {
|
|||
macro_rules! fmt_refs {
|
||||
($($tr:ident),*) => {
|
||||
$(
|
||||
#[stable]
|
||||
impl<'a, T: ?Sized + $tr> $tr for &'a T {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result { $tr::fmt(&**self, f) }
|
||||
}
|
||||
#[stable]
|
||||
impl<'a, T: ?Sized + $tr> $tr for &'a mut T {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result { $tr::fmt(&**self, f) }
|
||||
}
|
||||
|
@ -621,22 +657,24 @@ fn fmt(&self, f: &mut Formatter) -> Result { $tr::fmt(&**self, f) }
|
|||
}
|
||||
}
|
||||
|
||||
fmt_refs! { Show, String, Octal, Binary, LowerHex, UpperHex, LowerExp, UpperExp }
|
||||
fmt_refs! { Debug, Display, Octal, Binary, LowerHex, UpperHex, LowerExp, UpperExp }
|
||||
|
||||
impl Show for bool {
|
||||
#[stable]
|
||||
impl Debug for bool {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
String::fmt(self, f)
|
||||
Display::fmt(self, f)
|
||||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl String for bool {
|
||||
impl Display for bool {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
String::fmt(if *self { "true" } else { "false" }, f)
|
||||
Display::fmt(if *self { "true" } else { "false" }, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl Show for str {
|
||||
#[stable]
|
||||
impl Debug for str {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
try!(write!(f, "\""));
|
||||
for c in self.chars().flat_map(|c| c.escape_default()) {
|
||||
|
@ -647,13 +685,14 @@ fn fmt(&self, f: &mut Formatter) -> Result {
|
|||
}
|
||||
|
||||
#[stable]
|
||||
impl String for str {
|
||||
impl Display for str {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
f.pad(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl Show for char {
|
||||
#[stable]
|
||||
impl Debug for char {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
use char::CharExt;
|
||||
try!(write!(f, "'"));
|
||||
|
@ -665,15 +704,16 @@ fn fmt(&self, f: &mut Formatter) -> Result {
|
|||
}
|
||||
|
||||
#[stable]
|
||||
impl String for char {
|
||||
impl Display for char {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
let mut utf8 = [0u8; 4];
|
||||
let amt = self.encode_utf8(&mut utf8).unwrap_or(0);
|
||||
let s: &str = unsafe { mem::transmute(&utf8[..amt]) };
|
||||
String::fmt(s, f)
|
||||
Display::fmt(s, f)
|
||||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl<T> Pointer for *const T {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
f.flags |= 1 << (rt::FlagAlternate as uint);
|
||||
|
@ -683,18 +723,21 @@ fn fmt(&self, f: &mut Formatter) -> Result {
|
|||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl<T> Pointer for *mut T {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
Pointer::fmt(&(*self as *const T), f)
|
||||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl<'a, T> Pointer for &'a T {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
Pointer::fmt(&(*self as *const T), f)
|
||||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl<'a, T> Pointer for &'a mut T {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
Pointer::fmt(&(&**self as *const T), f)
|
||||
|
@ -703,15 +746,15 @@ fn fmt(&self, f: &mut Formatter) -> Result {
|
|||
|
||||
macro_rules! floating { ($ty:ident) => {
|
||||
|
||||
impl Show for $ty {
|
||||
#[stable]
|
||||
impl Debug for $ty {
|
||||
fn fmt(&self, fmt: &mut Formatter) -> Result {
|
||||
try!(String::fmt(self, fmt));
|
||||
fmt.write_str(stringify!($ty))
|
||||
Display::fmt(self, fmt)
|
||||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl String for $ty {
|
||||
impl Display for $ty {
|
||||
fn fmt(&self, fmt: &mut Formatter) -> Result {
|
||||
use num::Float;
|
||||
|
||||
|
@ -732,6 +775,7 @@ fn fmt(&self, fmt: &mut Formatter) -> Result {
|
|||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl LowerExp for $ty {
|
||||
fn fmt(&self, fmt: &mut Formatter) -> Result {
|
||||
use num::Float;
|
||||
|
@ -753,6 +797,7 @@ fn fmt(&self, fmt: &mut Formatter) -> Result {
|
|||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl UpperExp for $ty {
|
||||
fn fmt(&self, fmt: &mut Formatter) -> Result {
|
||||
use num::Float;
|
||||
|
@ -777,12 +822,14 @@ fn fmt(&self, fmt: &mut Formatter) -> Result {
|
|||
floating! { f32 }
|
||||
floating! { f64 }
|
||||
|
||||
// Implementation of Show for various core types
|
||||
// Implementation of Display/Debug for various core types
|
||||
|
||||
impl<T> Show for *const T {
|
||||
#[stable]
|
||||
impl<T> Debug for *const T {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result { Pointer::fmt(self, f) }
|
||||
}
|
||||
impl<T> Show for *mut T {
|
||||
#[stable]
|
||||
impl<T> Debug for *mut T {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result { Pointer::fmt(self, f) }
|
||||
}
|
||||
|
||||
|
@ -793,7 +840,8 @@ macro_rules! peel {
|
|||
macro_rules! tuple {
|
||||
() => ();
|
||||
( $($name:ident,)+ ) => (
|
||||
impl<$($name:Show),*> Show for ($($name,)*) {
|
||||
#[stable]
|
||||
impl<$($name:Debug),*> Debug for ($($name,)*) {
|
||||
#[allow(non_snake_case, unused_assignments)]
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
try!(write!(f, "("));
|
||||
|
@ -818,11 +866,13 @@ fn fmt(&self, f: &mut Formatter) -> Result {
|
|||
|
||||
tuple! { T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, }
|
||||
|
||||
impl<'a> Show for &'a (any::Any+'a) {
|
||||
#[stable]
|
||||
impl<'a> Debug for &'a (any::Any+'a) {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result { f.pad("&Any") }
|
||||
}
|
||||
|
||||
impl<T: Show> Show for [T] {
|
||||
#[stable]
|
||||
impl<T: Debug> Debug for [T] {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
if f.flags & (1 << (rt::FlagAlternate as uint)) == 0 {
|
||||
try!(write!(f, "["));
|
||||
|
@ -843,20 +893,22 @@ fn fmt(&self, f: &mut Formatter) -> Result {
|
|||
}
|
||||
}
|
||||
|
||||
impl Show for () {
|
||||
#[stable]
|
||||
impl Debug for () {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
f.pad("()")
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Copy + Show> Show for Cell<T> {
|
||||
#[stable]
|
||||
impl<T: Copy + Debug> Debug for Cell<T> {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
write!(f, "Cell {{ value: {:?} }}", self.get())
|
||||
}
|
||||
}
|
||||
|
||||
#[unstable]
|
||||
impl<T: Show> Show for RefCell<T> {
|
||||
#[stable]
|
||||
impl<T: Debug> Debug for RefCell<T> {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
match self.try_borrow() {
|
||||
Some(val) => write!(f, "RefCell {{ value: {:?} }}", val),
|
||||
|
@ -865,29 +917,17 @@ fn fmt(&self, f: &mut Formatter) -> Result {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'b, T: Show> Show for Ref<'b, T> {
|
||||
#[stable]
|
||||
impl<'b, T: Debug> Debug for Ref<'b, T> {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
Show::fmt(&**self, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'b, T: Show> Show for RefMut<'b, T> {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
Show::fmt(&*(self.deref()), f)
|
||||
Debug::fmt(&**self, f)
|
||||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl String for Utf8Error {
|
||||
impl<'b, T: Debug> Debug for RefMut<'b, T> {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
match *self {
|
||||
Utf8Error::InvalidByte(n) => {
|
||||
write!(f, "invalid utf-8: invalid byte at index {}", n)
|
||||
}
|
||||
Utf8Error::TooShort => {
|
||||
write!(f, "invalid utf-8: byte slice too short")
|
||||
}
|
||||
}
|
||||
Debug::fmt(&*(self.deref()), f)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -154,13 +154,14 @@ pub fn radix<T>(x: T, base: u8) -> RadixFmt<T, Radix> {
|
|||
|
||||
macro_rules! radix_fmt {
|
||||
($T:ty as $U:ty, $fmt:ident, $S:expr) => {
|
||||
impl fmt::Show for RadixFmt<$T, Radix> {
|
||||
#[stable]
|
||||
impl fmt::Debug for RadixFmt<$T, Radix> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
try!(fmt::String::fmt(self, f));
|
||||
f.write_str($S)
|
||||
fmt::Display::fmt(self, f)
|
||||
}
|
||||
}
|
||||
impl fmt::String for RadixFmt<$T, Radix> {
|
||||
#[stable]
|
||||
impl fmt::Display for RadixFmt<$T, Radix> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self { RadixFmt(ref x, radix) => radix.$fmt(*x as $U, f) }
|
||||
}
|
||||
|
@ -169,6 +170,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|||
}
|
||||
macro_rules! int_base {
|
||||
($Trait:ident for $T:ident as $U:ident -> $Radix:ident) => {
|
||||
#[stable]
|
||||
impl fmt::$Trait for $T {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
$Radix.fmt_int(*self as $U, f)
|
||||
|
@ -179,10 +181,10 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|||
|
||||
macro_rules! show {
|
||||
($T:ident with $S:expr) => {
|
||||
impl fmt::Show for $T {
|
||||
#[stable]
|
||||
impl fmt::Debug for $T {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
try!(fmt::String::fmt(self, f));
|
||||
f.write_str($S)
|
||||
fmt::Display::fmt(self, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -192,7 +194,7 @@ macro_rules! integer {
|
|||
integer! { $Int, $Uint, stringify!($Int), stringify!($Uint) }
|
||||
};
|
||||
($Int:ident, $Uint:ident, $SI:expr, $SU:expr) => {
|
||||
int_base! { String for $Int as $Int -> Decimal }
|
||||
int_base! { Display for $Int as $Int -> Decimal }
|
||||
int_base! { Binary for $Int as $Uint -> Binary }
|
||||
int_base! { Octal for $Int as $Uint -> Octal }
|
||||
int_base! { LowerHex for $Int as $Uint -> LowerHex }
|
||||
|
@ -200,7 +202,7 @@ macro_rules! integer {
|
|||
radix_fmt! { $Int as $Int, fmt_int, $SI }
|
||||
show! { $Int with $SI }
|
||||
|
||||
int_base! { String for $Uint as $Uint -> Decimal }
|
||||
int_base! { Display for $Uint as $Uint -> Decimal }
|
||||
int_base! { Binary for $Uint as $Uint -> Binary }
|
||||
int_base! { Octal for $Uint as $Uint -> Octal }
|
||||
int_base! { LowerHex for $Uint as $Uint -> LowerHex }
|
||||
|
|
|
@ -44,8 +44,6 @@
|
|||
|
||||
use marker::Sized;
|
||||
|
||||
#[cfg(stage0)] use any::TypeId;
|
||||
|
||||
pub type GlueFn = extern "Rust" fn(*const i8);
|
||||
|
||||
#[lang="ty_desc"]
|
||||
|
@ -208,12 +206,8 @@ pub struct TyDesc {
|
|||
/// Gets an identifier which is globally unique to the specified type. This
|
||||
/// function will return the same value for a type regardless of whichever
|
||||
/// crate it is invoked in.
|
||||
#[cfg(not(stage0))]
|
||||
pub fn type_id<T: ?Sized + 'static>() -> u64;
|
||||
|
||||
#[cfg(stage0)]
|
||||
pub fn type_id<T: ?Sized + 'static>() -> TypeId;
|
||||
|
||||
/// Create a value initialized to zero.
|
||||
///
|
||||
/// `init` is unsafe because it returns a zeroed-out datum,
|
||||
|
|
|
@ -99,6 +99,20 @@ pub trait Iterator {
|
|||
fn size_hint(&self) -> (uint, Option<uint>) { (0, None) }
|
||||
}
|
||||
|
||||
// FIXME(#21363) remove `old_impl_check` when bug is fixed
|
||||
#[old_impl_check]
|
||||
impl<'a, T> Iterator for &'a mut (Iterator<Item=T> + 'a) {
|
||||
type Item = T;
|
||||
|
||||
fn next(&mut self) -> Option<T> {
|
||||
(**self).next()
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
(**self).size_hint()
|
||||
}
|
||||
}
|
||||
|
||||
/// Conversion from an `Iterator`
|
||||
#[stable]
|
||||
#[rustc_on_unimplemented="a collection of type `{Self}` cannot be \
|
||||
|
@ -2701,63 +2715,93 @@ fn next(&mut self) -> Option<A> {
|
|||
}
|
||||
}
|
||||
|
||||
macro_rules! range_impl {
|
||||
($($t:ty)*) => ($(
|
||||
#[stable]
|
||||
impl Iterator for ::ops::Range<$t> {
|
||||
type Item = $t;
|
||||
|
||||
/// The `Step` trait identifies objects which can be stepped over in both
|
||||
/// directions. The `steps_between` function provides a way to
|
||||
/// compare two Step objects (it could be provided using `step()` and `Ord`,
|
||||
/// but the implementation would be so inefficient as to be useless).
|
||||
#[unstable = "design of range notation/iteration is in flux"]
|
||||
pub trait Step: Ord {
|
||||
/// Change self to the next object.
|
||||
fn step(&mut self);
|
||||
/// Change self to the previous object.
|
||||
fn step_back(&mut self);
|
||||
/// The steps_between two step objects.
|
||||
/// start should always be less than end, so the result should never be negative.
|
||||
/// Return None if it is not possible to calculate steps_between without
|
||||
/// overflow.
|
||||
fn steps_between(start: &Self, end: &Self) -> Option<uint>;
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<$t> {
|
||||
if self.start < self.end {
|
||||
let result = self.start;
|
||||
self.start += 1;
|
||||
return Some(result);
|
||||
}
|
||||
|
||||
return None;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn size_hint(&self) -> (uint, Option<uint>) {
|
||||
debug_assert!(self.end >= self.start);
|
||||
let hint = (self.end - self.start) as uint;
|
||||
(hint, Some(hint))
|
||||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl ExactSizeIterator for ::ops::Range<$t> {}
|
||||
)*)
|
||||
}
|
||||
|
||||
macro_rules! step_impl {
|
||||
macro_rules! range_impl_no_hint {
|
||||
($($t:ty)*) => ($(
|
||||
#[unstable = "Trait is unstable."]
|
||||
impl Step for $t {
|
||||
#[stable]
|
||||
impl Iterator for ::ops::Range<$t> {
|
||||
type Item = $t;
|
||||
|
||||
#[inline]
|
||||
fn step(&mut self) { *self += 1; }
|
||||
#[inline]
|
||||
fn step_back(&mut self) { *self -= 1; }
|
||||
#[inline]
|
||||
fn steps_between(start: &$t, end: &$t) -> Option<uint> {
|
||||
debug_assert!(end >= start);
|
||||
Some((*end - *start) as uint)
|
||||
fn next(&mut self) -> Option<$t> {
|
||||
if self.start < self.end {
|
||||
let result = self.start;
|
||||
self.start += 1;
|
||||
return Some(result);
|
||||
}
|
||||
|
||||
return None;
|
||||
}
|
||||
}
|
||||
)*)
|
||||
}
|
||||
|
||||
macro_rules! step_impl_no_between {
|
||||
macro_rules! range_other_impls {
|
||||
($($t:ty)*) => ($(
|
||||
#[unstable = "Trait is unstable."]
|
||||
impl Step for $t {
|
||||
#[stable]
|
||||
impl DoubleEndedIterator for ::ops::Range<$t> {
|
||||
#[inline]
|
||||
fn step(&mut self) { *self += 1; }
|
||||
fn next_back(&mut self) -> Option<$t> {
|
||||
if self.start < self.end {
|
||||
self.end -= 1;
|
||||
return Some(self.end);
|
||||
}
|
||||
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl Iterator for ::ops::RangeFrom<$t> {
|
||||
type Item = $t;
|
||||
|
||||
#[inline]
|
||||
fn step_back(&mut self) { *self -= 1; }
|
||||
#[inline]
|
||||
fn steps_between(_start: &$t, _end: &$t) -> Option<uint> {
|
||||
None
|
||||
fn next(&mut self) -> Option<$t> {
|
||||
let result = self.start;
|
||||
self.start += 1;
|
||||
debug_assert!(result < self.start);
|
||||
return Some(result);
|
||||
}
|
||||
}
|
||||
)*)
|
||||
}
|
||||
|
||||
step_impl!(uint u8 u16 u32 int i8 i16 i32);
|
||||
range_impl!(uint u8 u16 u32 int i8 i16 i32);
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
step_impl!(u64 i64);
|
||||
range_impl!(u64 i64);
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
step_impl_no_between!(u64 i64);
|
||||
range_impl_no_hint!(u64 i64);
|
||||
|
||||
range_other_impls!(uint u8 u16 u32 u64 int i8 i16 i32 i64);
|
||||
|
||||
/// An iterator that repeats an element endlessly
|
||||
#[derive(Clone)]
|
||||
|
|
|
@ -63,6 +63,8 @@
|
|||
#![feature(unboxed_closures)]
|
||||
#![allow(unknown_features)] #![feature(int_uint)]
|
||||
#![feature(on_unimplemented)]
|
||||
// FIXME(#21363) remove `old_impl_check` when bug is fixed
|
||||
#![feature(old_impl_check)]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
#[macro_use]
|
||||
|
@ -136,6 +138,7 @@
|
|||
pub mod str;
|
||||
pub mod hash;
|
||||
pub mod fmt;
|
||||
pub mod error;
|
||||
|
||||
// note: does not need to be public
|
||||
mod tuple;
|
||||
|
|
|
@ -376,16 +376,6 @@ fn clone(&self) -> InvariantType<T> { *self }
|
|||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct InvariantLifetime<'a>;
|
||||
|
||||
/// A type which is considered "not sendable", meaning that it cannot
|
||||
/// be safely sent between tasks, even if it is owned. This is
|
||||
/// typically embedded in other types, such as `Gc`, to ensure that
|
||||
/// their instances remain thread-local.
|
||||
#[unstable = "likely to change with new variance strategy"]
|
||||
#[lang="no_send_bound"]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[cfg(stage0)] // NOTE remove impl after next snapshot
|
||||
pub struct NoSend;
|
||||
|
||||
/// A type which is considered "not POD", meaning that it is not
|
||||
/// implicitly copyable. This is typically embedded in other types to
|
||||
/// ensure that they are never copied, even if they lack a destructor.
|
||||
|
@ -395,15 +385,6 @@ fn clone(&self) -> InvariantType<T> { *self }
|
|||
#[allow(missing_copy_implementations)]
|
||||
pub struct NoCopy;
|
||||
|
||||
/// A type which is considered "not sync", meaning that
|
||||
/// its contents are not threadsafe, hence they cannot be
|
||||
/// shared between tasks.
|
||||
#[unstable = "likely to change with new variance strategy"]
|
||||
#[lang="no_sync_bound"]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[cfg(stage0)] // NOTE remove impl after next snapshot
|
||||
pub struct NoSync;
|
||||
|
||||
/// A type which is considered managed by the GC. This is typically
|
||||
/// embedded in other types.
|
||||
#[unstable = "likely to change with new variance strategy"]
|
||||
|
|
|
@ -33,8 +33,6 @@
|
|||
//! demonstrates adding and subtracting two `Point`s.
|
||||
//!
|
||||
//! ```rust
|
||||
//! #![feature(associated_types)]
|
||||
//!
|
||||
//! use std::ops::{Add, Sub};
|
||||
//!
|
||||
//! #[derive(Show)]
|
||||
|
@ -69,10 +67,7 @@
|
|||
|
||||
#![stable]
|
||||
|
||||
use clone::Clone;
|
||||
use iter::{Step, Iterator,DoubleEndedIterator,ExactSizeIterator};
|
||||
use marker::Sized;
|
||||
use option::Option::{self, Some, None};
|
||||
use fmt;
|
||||
|
||||
/// The `Drop` trait is used to run some code when a value goes out of scope. This
|
||||
|
@ -164,8 +159,6 @@ fn $method(self, other: &'a $u) -> <$t as $imp<$u>>::Output {
|
|||
/// calling `add`, and therefore, `main` prints `Adding!`.
|
||||
///
|
||||
/// ```rust
|
||||
/// #![feature(associated_types)]
|
||||
///
|
||||
/// use std::ops::Add;
|
||||
///
|
||||
/// #[derive(Copy)]
|
||||
|
@ -219,8 +212,6 @@ fn add(self, other: $t) -> $t { self + other }
|
|||
/// calling `sub`, and therefore, `main` prints `Subtracting!`.
|
||||
///
|
||||
/// ```rust
|
||||
/// #![feature(associated_types)]
|
||||
///
|
||||
/// use std::ops::Sub;
|
||||
///
|
||||
/// #[derive(Copy)]
|
||||
|
@ -274,8 +265,6 @@ fn sub(self, other: $t) -> $t { self - other }
|
|||
/// calling `mul`, and therefore, `main` prints `Multiplying!`.
|
||||
///
|
||||
/// ```rust
|
||||
/// #![feature(associated_types)]
|
||||
///
|
||||
/// use std::ops::Mul;
|
||||
///
|
||||
/// #[derive(Copy)]
|
||||
|
@ -329,8 +318,6 @@ fn mul(self, other: $t) -> $t { self * other }
|
|||
/// calling `div`, and therefore, `main` prints `Dividing!`.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(associated_types)]
|
||||
///
|
||||
/// use std::ops::Div;
|
||||
///
|
||||
/// #[derive(Copy)]
|
||||
|
@ -384,8 +371,6 @@ fn div(self, other: $t) -> $t { self / other }
|
|||
/// calling `rem`, and therefore, `main` prints `Remainder-ing!`.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(associated_types)]
|
||||
///
|
||||
/// use std::ops::Rem;
|
||||
///
|
||||
/// #[derive(Copy)]
|
||||
|
@ -458,8 +443,6 @@ fn rem(self, other: $t) -> $t {
|
|||
/// `neg`, and therefore, `main` prints `Negating!`.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(associated_types)]
|
||||
///
|
||||
/// use std::ops::Neg;
|
||||
///
|
||||
/// struct Foo;
|
||||
|
@ -537,8 +520,6 @@ fn neg(self) -> $t { -(self as $t_signed) as $t }
|
|||
/// `not`, and therefore, `main` prints `Not-ing!`.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(associated_types)]
|
||||
///
|
||||
/// use std::ops::Not;
|
||||
///
|
||||
/// struct Foo;
|
||||
|
@ -593,8 +574,6 @@ fn not(self) -> $t { !self }
|
|||
/// calling `bitand`, and therefore, `main` prints `Bitwise And-ing!`.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(associated_types)]
|
||||
///
|
||||
/// use std::ops::BitAnd;
|
||||
///
|
||||
/// #[derive(Copy)]
|
||||
|
@ -648,8 +627,6 @@ fn bitand(self, rhs: $t) -> $t { self & rhs }
|
|||
/// calling `bitor`, and therefore, `main` prints `Bitwise Or-ing!`.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(associated_types)]
|
||||
///
|
||||
/// use std::ops::BitOr;
|
||||
///
|
||||
/// #[derive(Copy)]
|
||||
|
@ -703,8 +680,6 @@ fn bitor(self, rhs: $t) -> $t { self | rhs }
|
|||
/// calling `bitxor`, and therefore, `main` prints `Bitwise Xor-ing!`.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(associated_types)]
|
||||
///
|
||||
/// use std::ops::BitXor;
|
||||
///
|
||||
/// #[derive(Copy)]
|
||||
|
@ -758,8 +733,6 @@ fn bitxor(self, other: $t) -> $t { self ^ other }
|
|||
/// calling `shl`, and therefore, `main` prints `Shifting left!`.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(associated_types)]
|
||||
///
|
||||
/// use std::ops::Shl;
|
||||
///
|
||||
/// #[derive(Copy)]
|
||||
|
@ -831,8 +804,6 @@ macro_rules! shl_impl_all {
|
|||
/// calling `shr`, and therefore, `main` prints `Shifting right!`.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(associated_types)]
|
||||
///
|
||||
/// use std::ops::Shr;
|
||||
///
|
||||
/// #[derive(Copy)]
|
||||
|
@ -924,10 +895,12 @@ macro_rules! shr_impl_all {
|
|||
/// }
|
||||
/// ```
|
||||
#[lang="index"]
|
||||
#[stable]
|
||||
pub trait Index<Index: ?Sized> {
|
||||
type Output: ?Sized;
|
||||
|
||||
/// The method for the indexing (`Foo[Bar]`) operation
|
||||
#[stable]
|
||||
fn index<'a>(&'a self, index: &Index) -> &'a Self::Output;
|
||||
}
|
||||
|
||||
|
@ -960,30 +933,32 @@ pub trait Index<Index: ?Sized> {
|
|||
/// }
|
||||
/// ```
|
||||
#[lang="index_mut"]
|
||||
#[stable]
|
||||
pub trait IndexMut<Index: ?Sized> {
|
||||
type Output: ?Sized;
|
||||
|
||||
/// The method for the indexing (`Foo[Bar]`) operation
|
||||
#[stable]
|
||||
fn index_mut<'a>(&'a mut self, index: &Index) -> &'a mut Self::Output;
|
||||
}
|
||||
|
||||
/// An unbounded range.
|
||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||
#[lang="full_range"]
|
||||
#[unstable = "API still in development"]
|
||||
#[unstable = "may be renamed to RangeFull"]
|
||||
pub struct FullRange;
|
||||
|
||||
#[unstable = "API still in development"]
|
||||
impl fmt::Show for FullRange {
|
||||
#[stable]
|
||||
impl fmt::Debug for FullRange {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::Show::fmt("..", fmt)
|
||||
fmt::Debug::fmt("..", fmt)
|
||||
}
|
||||
}
|
||||
|
||||
/// A (half-open) range which is bounded at both ends.
|
||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||
#[lang="range"]
|
||||
#[unstable = "API still in development"]
|
||||
#[stable]
|
||||
pub struct Range<Idx> {
|
||||
/// The lower bound of the range (inclusive).
|
||||
pub start: Idx,
|
||||
|
@ -991,49 +966,8 @@ pub struct Range<Idx> {
|
|||
pub end: Idx,
|
||||
}
|
||||
|
||||
#[unstable = "API still in development"]
|
||||
impl<Idx: Clone + Step> Iterator for Range<Idx> {
|
||||
type Item = Idx;
|
||||
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<Idx> {
|
||||
if self.start < self.end {
|
||||
let result = self.start.clone();
|
||||
self.start.step();
|
||||
return Some(result);
|
||||
}
|
||||
|
||||
return None;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn size_hint(&self) -> (uint, Option<uint>) {
|
||||
if let Some(hint) = Step::steps_between(&self.start, &self.end) {
|
||||
(hint, Some(hint))
|
||||
} else {
|
||||
(0, None)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[unstable = "API still in development"]
|
||||
impl<Idx: Clone + Step> DoubleEndedIterator for Range<Idx> {
|
||||
#[inline]
|
||||
fn next_back(&mut self) -> Option<Idx> {
|
||||
if self.start < self.end {
|
||||
self.end.step_back();
|
||||
return Some(self.end.clone());
|
||||
}
|
||||
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
||||
#[unstable = "API still in development"]
|
||||
impl<Idx: Clone + Step> ExactSizeIterator for Range<Idx> {}
|
||||
|
||||
#[unstable = "API still in development"]
|
||||
impl<Idx: fmt::Show> fmt::Show for Range<Idx> {
|
||||
#[stable]
|
||||
impl<Idx: fmt::Debug> fmt::Debug for Range<Idx> {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(fmt, "{:?}..{:?}", self.start, self.end)
|
||||
}
|
||||
|
@ -1042,27 +976,16 @@ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
|||
/// A range which is only bounded below.
|
||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||
#[lang="range_from"]
|
||||
#[unstable = "API still in development"]
|
||||
#[stable]
|
||||
pub struct RangeFrom<Idx> {
|
||||
/// The lower bound of the range (inclusive).
|
||||
pub start: Idx,
|
||||
}
|
||||
|
||||
#[unstable = "API still in development"]
|
||||
impl<Idx: Clone + Step> Iterator for RangeFrom<Idx> {
|
||||
type Item = Idx;
|
||||
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<Idx> {
|
||||
// Deliberately overflow so we loop forever.
|
||||
let result = self.start.clone();
|
||||
self.start.step();
|
||||
return Some(result);
|
||||
}
|
||||
}
|
||||
|
||||
#[unstable = "API still in development"]
|
||||
impl<Idx: fmt::Show> fmt::Show for RangeFrom<Idx> {
|
||||
#[stable]
|
||||
impl<Idx: fmt::Debug> fmt::Debug for RangeFrom<Idx> {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(fmt, "{:?}..", self.start)
|
||||
}
|
||||
|
@ -1071,14 +994,14 @@ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
|||
/// A range which is only bounded above.
|
||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||
#[lang="range_to"]
|
||||
#[unstable = "API still in development"]
|
||||
#[stable]
|
||||
pub struct RangeTo<Idx> {
|
||||
/// The upper bound of the range (exclusive).
|
||||
pub end: Idx,
|
||||
}
|
||||
|
||||
#[unstable = "API still in development"]
|
||||
impl<Idx: fmt::Show> fmt::Show for RangeTo<Idx> {
|
||||
#[stable]
|
||||
impl<Idx: fmt::Debug> fmt::Debug for RangeTo<Idx> {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(fmt, "..{:?}", self.end)
|
||||
}
|
||||
|
@ -1094,8 +1017,6 @@ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
|||
/// struct.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(associated_types)]
|
||||
///
|
||||
/// use std::ops::Deref;
|
||||
///
|
||||
/// struct DerefExample<T> {
|
||||
|
@ -1149,8 +1070,6 @@ fn deref(&self) -> &T { *self }
|
|||
/// struct.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(associated_types)]
|
||||
///
|
||||
/// use std::ops::{Deref, DerefMut};
|
||||
///
|
||||
/// struct DerefMutExample<T> {
|
||||
|
|
|
@ -229,7 +229,7 @@
|
|||
use self::Result::{Ok, Err};
|
||||
|
||||
use clone::Clone;
|
||||
use fmt::Show;
|
||||
use fmt::Display;
|
||||
use iter::{Iterator, IteratorExt, DoubleEndedIterator, FromIterator, ExactSizeIterator};
|
||||
use ops::{FnMut, FnOnce};
|
||||
use option::Option::{self, None, Some};
|
||||
|
@ -714,7 +714,7 @@ pub fn unwrap_or_else<F: FnOnce(E) -> T>(self, op: F) -> T {
|
|||
}
|
||||
|
||||
#[stable]
|
||||
impl<T, E: Show> Result<T, E> {
|
||||
impl<T, E: Display> Result<T, E> {
|
||||
/// Unwraps a result, yielding the content of an `Ok`.
|
||||
///
|
||||
/// # Panics
|
||||
|
@ -739,13 +739,13 @@ pub fn unwrap(self) -> T {
|
|||
match self {
|
||||
Ok(t) => t,
|
||||
Err(e) =>
|
||||
panic!("called `Result::unwrap()` on an `Err` value: {:?}", e)
|
||||
panic!("called `Result::unwrap()` on an `Err` value: {}", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl<T: Show, E> Result<T, E> {
|
||||
impl<T: Display, E> Result<T, E> {
|
||||
/// Unwraps a result, yielding the content of an `Err`.
|
||||
///
|
||||
/// # Panics
|
||||
|
@ -769,7 +769,7 @@ impl<T: Show, E> Result<T, E> {
|
|||
pub fn unwrap_err(self) -> E {
|
||||
match self {
|
||||
Ok(t) =>
|
||||
panic!("called `Result::unwrap_err()` on an `Ok` value: {:?}", t),
|
||||
panic!("called `Result::unwrap_err()` on an `Ok` value: {}", t),
|
||||
Err(e) => e
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,9 +67,6 @@
|
|||
pub trait SliceExt {
|
||||
type Item;
|
||||
|
||||
fn slice<'a>(&'a self, start: uint, end: uint) -> &'a [Self::Item];
|
||||
fn slice_from<'a>(&'a self, start: uint) -> &'a [Self::Item];
|
||||
fn slice_to<'a>(&'a self, end: uint) -> &'a [Self::Item];
|
||||
fn split_at<'a>(&'a self, mid: uint) -> (&'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>
|
||||
|
@ -93,9 +90,6 @@ fn binary_search_by<F>(&self, f: F) -> Result<uint, uint> where
|
|||
fn is_empty(&self) -> bool { self.len() == 0 }
|
||||
fn get_mut<'a>(&'a mut self, index: uint) -> Option<&'a mut Self::Item>;
|
||||
fn as_mut_slice<'a>(&'a mut self) -> &'a mut [Self::Item];
|
||||
fn slice_mut<'a>(&'a mut self, start: uint, end: uint) -> &'a mut [Self::Item];
|
||||
fn slice_from_mut<'a>(&'a mut self, start: uint) -> &'a mut [Self::Item];
|
||||
fn slice_to_mut<'a>(&'a mut self, end: uint) -> &'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>;
|
||||
fn tail_mut<'a>(&'a mut self) -> &'a mut [Self::Item];
|
||||
|
@ -135,28 +129,6 @@ fn rsplitn_mut<P>(&mut self, n: uint, pred: P) -> RSplitNMut<Self::Item, P>
|
|||
impl<T> SliceExt for [T] {
|
||||
type Item = T;
|
||||
|
||||
#[inline]
|
||||
fn slice(&self, start: uint, end: uint) -> &[T] {
|
||||
assert!(start <= end);
|
||||
assert!(end <= self.len());
|
||||
unsafe {
|
||||
transmute(RawSlice {
|
||||
data: self.as_ptr().offset(start as int),
|
||||
len: (end - start)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn slice_from(&self, start: uint) -> &[T] {
|
||||
self.slice(start, self.len())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn slice_to(&self, end: uint) -> &[T] {
|
||||
self.slice(0, end)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn split_at(&self, mid: uint) -> (&[T], &[T]) {
|
||||
(&self[..mid], &self[mid..])
|
||||
|
@ -240,7 +212,7 @@ fn tail(&self) -> &[T] { &self[1..] }
|
|||
|
||||
#[inline]
|
||||
fn init(&self) -> &[T] {
|
||||
&self[..(self.len() - 1)]
|
||||
&self[..self.len() - 1]
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -291,20 +263,6 @@ fn get_mut(&mut self, index: uint) -> Option<&mut T> {
|
|||
#[inline]
|
||||
fn as_mut_slice(&mut self) -> &mut [T] { self }
|
||||
|
||||
fn slice_mut(&mut self, start: uint, end: uint) -> &mut [T] {
|
||||
ops::IndexMut::index_mut(self, &ops::Range { start: start, end: end } )
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn slice_from_mut(&mut self, start: uint) -> &mut [T] {
|
||||
ops::IndexMut::index_mut(self, &ops::RangeFrom { start: start } )
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn slice_to_mut(&mut self, end: uint) -> &mut [T] {
|
||||
ops::IndexMut::index_mut(self, &ops::RangeTo { end: end } )
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn split_at_mut(&mut self, mid: uint) -> (&mut [T], &mut [T]) {
|
||||
unsafe {
|
||||
|
@ -345,13 +303,13 @@ fn first_mut(&mut self) -> Option<&mut T> {
|
|||
|
||||
#[inline]
|
||||
fn tail_mut(&mut self) -> &mut [T] {
|
||||
self.slice_from_mut(1)
|
||||
&mut self[1 ..]
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn init_mut(&mut self) -> &mut [T] {
|
||||
let len = self.len();
|
||||
self.slice_to_mut(len-1)
|
||||
&mut self[.. (len - 1)]
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -449,7 +407,7 @@ fn starts_with(&self, needle: &[T]) -> bool where T: PartialEq {
|
|||
#[inline]
|
||||
fn ends_with(&self, needle: &[T]) -> bool where T: PartialEq {
|
||||
let (m, n) = (self.len(), needle.len());
|
||||
m >= n && needle == &self[(m-n)..]
|
||||
m >= n && needle == &self[m-n..]
|
||||
}
|
||||
|
||||
#[unstable]
|
||||
|
@ -483,7 +441,7 @@ fn next_permutation(&mut self) -> bool where T: Ord {
|
|||
self.swap(j, i-1);
|
||||
|
||||
// Step 4: Reverse the (previously) weakly decreasing part
|
||||
self.slice_from_mut(i).reverse();
|
||||
self[i..].reverse();
|
||||
|
||||
true
|
||||
}
|
||||
|
@ -505,7 +463,7 @@ fn prev_permutation(&mut self) -> bool where T: Ord {
|
|||
}
|
||||
|
||||
// Step 2: Reverse the weakly increasing part
|
||||
self.slice_from_mut(i).reverse();
|
||||
self[i..].reverse();
|
||||
|
||||
// Step 3: Find the rightmost element equal to or bigger than the pivot (i-1)
|
||||
let mut j = self.len() - 1;
|
||||
|
@ -522,8 +480,8 @@ fn prev_permutation(&mut self) -> bool where T: Ord {
|
|||
#[inline]
|
||||
fn clone_from_slice(&mut self, src: &[T]) -> uint where T: Clone {
|
||||
let min = cmp::min(self.len(), src.len());
|
||||
let dst = self.slice_to_mut(min);
|
||||
let src = src.slice_to(min);
|
||||
let dst = &mut self[.. min];
|
||||
let src = &src[.. min];
|
||||
for i in range(0, min) {
|
||||
dst[i].clone_from(&src[i]);
|
||||
}
|
||||
|
@ -531,6 +489,7 @@ fn clone_from_slice(&mut self, src: &[T]) -> uint where T: Clone {
|
|||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl<T> ops::Index<uint> for [T] {
|
||||
type Output = T;
|
||||
|
||||
|
@ -541,6 +500,7 @@ fn index(&self, &index: &uint) -> &T {
|
|||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl<T> ops::IndexMut<uint> for [T] {
|
||||
type Output = T;
|
||||
|
||||
|
@ -551,6 +511,7 @@ fn index_mut(&mut self, &index: &uint) -> &mut T {
|
|||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl<T> ops::Index<ops::Range<uint>> for [T] {
|
||||
type Output = [T];
|
||||
#[inline]
|
||||
|
@ -565,6 +526,7 @@ fn index(&self, index: &ops::Range<uint>) -> &[T] {
|
|||
}
|
||||
}
|
||||
}
|
||||
#[stable]
|
||||
impl<T> ops::Index<ops::RangeTo<uint>> for [T] {
|
||||
type Output = [T];
|
||||
#[inline]
|
||||
|
@ -572,6 +534,7 @@ fn index(&self, index: &ops::RangeTo<uint>) -> &[T] {
|
|||
self.index(&ops::Range{ start: 0, end: index.end })
|
||||
}
|
||||
}
|
||||
#[stable]
|
||||
impl<T> ops::Index<ops::RangeFrom<uint>> for [T] {
|
||||
type Output = [T];
|
||||
#[inline]
|
||||
|
@ -579,6 +542,7 @@ fn index(&self, index: &ops::RangeFrom<uint>) -> &[T] {
|
|||
self.index(&ops::Range{ start: index.start, end: self.len() })
|
||||
}
|
||||
}
|
||||
#[stable]
|
||||
impl<T> ops::Index<ops::FullRange> for [T] {
|
||||
type Output = [T];
|
||||
#[inline]
|
||||
|
@ -587,6 +551,7 @@ fn index(&self, _index: &ops::FullRange) -> &[T] {
|
|||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl<T> ops::IndexMut<ops::Range<uint>> for [T] {
|
||||
type Output = [T];
|
||||
#[inline]
|
||||
|
@ -601,6 +566,7 @@ fn index_mut(&mut self, index: &ops::Range<uint>) -> &mut [T] {
|
|||
}
|
||||
}
|
||||
}
|
||||
#[stable]
|
||||
impl<T> ops::IndexMut<ops::RangeTo<uint>> for [T] {
|
||||
type Output = [T];
|
||||
#[inline]
|
||||
|
@ -608,6 +574,7 @@ fn index_mut(&mut self, index: &ops::RangeTo<uint>) -> &mut [T] {
|
|||
self.index_mut(&ops::Range{ start: 0, end: index.end })
|
||||
}
|
||||
}
|
||||
#[stable]
|
||||
impl<T> ops::IndexMut<ops::RangeFrom<uint>> for [T] {
|
||||
type Output = [T];
|
||||
#[inline]
|
||||
|
@ -616,6 +583,7 @@ fn index_mut(&mut self, index: &ops::RangeFrom<uint>) -> &mut [T] {
|
|||
self.index_mut(&ops::Range{ start: index.start, end: len })
|
||||
}
|
||||
}
|
||||
#[stable]
|
||||
impl<T> ops::IndexMut<ops::FullRange> for [T] {
|
||||
type Output = [T];
|
||||
#[inline]
|
||||
|
@ -973,7 +941,7 @@ fn next(&mut self) -> Option<&'a [T]> {
|
|||
None => self.finish(),
|
||||
Some(idx) => {
|
||||
let ret = Some(&self.v[..idx]);
|
||||
self.v = &self.v[(idx + 1)..];
|
||||
self.v = &self.v[idx + 1..];
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
@ -998,7 +966,7 @@ fn next_back(&mut self) -> Option<&'a [T]> {
|
|||
match self.v.iter().rposition(|x| (self.pred)(x)) {
|
||||
None => self.finish(),
|
||||
Some(idx) => {
|
||||
let ret = Some(&self.v[(idx + 1)..]);
|
||||
let ret = Some(&self.v[idx + 1..]);
|
||||
self.v = &self.v[..idx];
|
||||
ret
|
||||
}
|
||||
|
@ -1051,7 +1019,7 @@ fn next(&mut self) -> Option<&'a mut [T]> {
|
|||
Some(idx) => {
|
||||
let tmp = mem::replace(&mut self.v, &mut []);
|
||||
let (head, tail) = tmp.split_at_mut(idx);
|
||||
self.v = tail.slice_from_mut(1);
|
||||
self.v = &mut tail[1..];
|
||||
Some(head)
|
||||
}
|
||||
}
|
||||
|
@ -1087,7 +1055,7 @@ fn next_back(&mut self) -> Option<&'a mut [T]> {
|
|||
let tmp = mem::replace(&mut self.v, &mut []);
|
||||
let (head, tail) = tmp.split_at_mut(idx);
|
||||
self.v = head;
|
||||
Some(tail.slice_from_mut(1))
|
||||
Some(&mut tail[1..])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1269,6 +1237,9 @@ fn next_back(&mut self) -> Option<&'a [T]> {
|
|||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl<'a, T> ExactSizeIterator for Chunks<'a, T> {}
|
||||
|
||||
#[unstable = "trait is experimental"]
|
||||
impl<'a, T> RandomAccessIterator for Chunks<'a, T> {
|
||||
#[inline]
|
||||
|
@ -1347,6 +1318,8 @@ fn next_back(&mut self) -> Option<&'a mut [T]> {
|
|||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl<'a, T> ExactSizeIterator for ChunksMut<'a, T> {}
|
||||
|
||||
//
|
||||
// Free functions
|
||||
|
|
|
@ -20,8 +20,10 @@
|
|||
|
||||
use cmp::{self, Eq};
|
||||
use default::Default;
|
||||
use iter::range;
|
||||
use error::Error;
|
||||
use fmt;
|
||||
use iter::ExactSizeIterator;
|
||||
use iter::range;
|
||||
use iter::{Map, Iterator, IteratorExt, DoubleEndedIterator};
|
||||
use marker::Sized;
|
||||
use mem;
|
||||
|
@ -242,6 +244,30 @@ fn only_ascii(&self) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl Error for Utf8Error {
|
||||
fn description(&self) -> &str {
|
||||
match *self {
|
||||
Utf8Error::TooShort => "invalid utf-8: not enough bytes",
|
||||
Utf8Error::InvalidByte(..) => "invalid utf-8: corrupt contents",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl fmt::Display for Utf8Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
Utf8Error::InvalidByte(n) => {
|
||||
write!(f, "invalid utf-8: invalid byte at index {}", n)
|
||||
}
|
||||
Utf8Error::TooShort => {
|
||||
write!(f, "invalid utf-8: byte slice too short")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Section: Iterators
|
||||
*/
|
||||
|
@ -902,13 +928,13 @@ fn next(&mut self) -> Option<&'a str> {
|
|||
|
||||
match self.it.next() {
|
||||
Some((from, to)) => {
|
||||
let ret = Some(self.it.haystack.slice(self.last_end, from));
|
||||
let ret = Some(&self.it.haystack[self.last_end .. from]);
|
||||
self.last_end = to;
|
||||
ret
|
||||
}
|
||||
None => {
|
||||
self.finished = true;
|
||||
Some(self.it.haystack.slice(self.last_end, self.it.haystack.len()))
|
||||
Some(&self.it.haystack[self.last_end .. self.it.haystack.len()])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1115,27 +1141,90 @@ fn partial_cmp(&self, other: &str) -> Option<Ordering> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns a slice of the given string from the byte range
|
||||
/// [`begin`..`end`).
|
||||
///
|
||||
/// This operation is `O(1)`.
|
||||
///
|
||||
/// Panics when `begin` and `end` do not point to valid characters
|
||||
/// or point beyond the last character of the string.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// let s = "Löwe 老虎 Léopard";
|
||||
/// assert_eq!(&s[0 .. 1], "L");
|
||||
///
|
||||
/// assert_eq!(&s[1 .. 9], "öwe 老");
|
||||
///
|
||||
/// // these will panic:
|
||||
/// // byte 2 lies within `ö`:
|
||||
/// // &s[2 ..3];
|
||||
///
|
||||
/// // byte 8 lies within `老`
|
||||
/// // &s[1 .. 8];
|
||||
///
|
||||
/// // byte 100 is outside the string
|
||||
/// // &s[3 .. 100];
|
||||
/// ```
|
||||
#[stable]
|
||||
impl ops::Index<ops::Range<uint>> for str {
|
||||
type Output = str;
|
||||
#[inline]
|
||||
fn index(&self, index: &ops::Range<uint>) -> &str {
|
||||
self.slice(index.start, index.end)
|
||||
// is_char_boundary checks that the index is in [0, .len()]
|
||||
if index.start <= index.end &&
|
||||
self.is_char_boundary(index.start) &&
|
||||
self.is_char_boundary(index.end) {
|
||||
unsafe { self.slice_unchecked(index.start, index.end) }
|
||||
} else {
|
||||
super::slice_error_fail(self, index.start, index.end)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a slice of the string from the beginning to byte
|
||||
/// `end`.
|
||||
///
|
||||
/// Equivalent to `self[0 .. end]`.
|
||||
///
|
||||
/// Panics when `end` does not point to a valid character, or is
|
||||
/// out of bounds.
|
||||
#[stable]
|
||||
impl ops::Index<ops::RangeTo<uint>> for str {
|
||||
type Output = str;
|
||||
#[inline]
|
||||
fn index(&self, index: &ops::RangeTo<uint>) -> &str {
|
||||
self.slice_to(index.end)
|
||||
// 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) }
|
||||
} else {
|
||||
super::slice_error_fail(self, 0, index.end)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a slice of the string from `begin` to its end.
|
||||
///
|
||||
/// Equivalent to `self[begin .. self.len()]`.
|
||||
///
|
||||
/// Panics when `begin` does not point to a valid character, or is
|
||||
/// out of bounds.
|
||||
#[stable]
|
||||
impl ops::Index<ops::RangeFrom<uint>> for str {
|
||||
type Output = str;
|
||||
#[inline]
|
||||
fn index(&self, index: &ops::RangeFrom<uint>) -> &str {
|
||||
self.slice_from(index.start)
|
||||
// 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()) }
|
||||
} else {
|
||||
super::slice_error_fail(self, index.start, self.len())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl ops::Index<ops::FullRange> for str {
|
||||
type Output = str;
|
||||
#[inline]
|
||||
|
@ -1147,7 +1236,7 @@ fn index(&self, _index: &ops::FullRange) -> &str {
|
|||
|
||||
/// Any string that can be represented as a slice
|
||||
#[unstable = "Instead of taking this bound generically, this trait will be \
|
||||
replaced with one of slicing syntax, deref coercions, or \
|
||||
replaced with one of slicing syntax (&foo[]), deref coercions, or \
|
||||
a more generic conversion trait"]
|
||||
pub trait Str {
|
||||
/// Work with `self` as a slice.
|
||||
|
@ -1208,9 +1297,6 @@ pub trait StrExt {
|
|||
fn lines<'a>(&'a self) -> Lines<'a>;
|
||||
fn lines_any<'a>(&'a self) -> LinesAny<'a>;
|
||||
fn char_len(&self) -> uint;
|
||||
fn slice<'a>(&'a self, begin: uint, end: uint) -> &'a str;
|
||||
fn slice_from<'a>(&'a self, begin: uint) -> &'a str;
|
||||
fn slice_to<'a>(&'a self, end: uint) -> &'a str;
|
||||
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 starts_with(&self, pat: &str) -> bool;
|
||||
|
@ -1332,7 +1418,7 @@ fn lines(&self) -> Lines {
|
|||
fn lines_any(&self) -> LinesAny {
|
||||
fn f(line: &str) -> &str {
|
||||
let l = line.len();
|
||||
if l > 0 && line.as_bytes()[l - 1] == b'\r' { line.slice(0, l - 1) }
|
||||
if l > 0 && line.as_bytes()[l - 1] == b'\r' { &line[0 .. l - 1] }
|
||||
else { line }
|
||||
}
|
||||
|
||||
|
@ -1343,38 +1429,6 @@ fn f(line: &str) -> &str {
|
|||
#[inline]
|
||||
fn char_len(&self) -> uint { self.chars().count() }
|
||||
|
||||
#[inline]
|
||||
fn slice(&self, begin: uint, end: uint) -> &str {
|
||||
// is_char_boundary checks that the index is in [0, .len()]
|
||||
if begin <= end &&
|
||||
self.is_char_boundary(begin) &&
|
||||
self.is_char_boundary(end) {
|
||||
unsafe { self.slice_unchecked(begin, end) }
|
||||
} else {
|
||||
slice_error_fail(self, begin, end)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn slice_from(&self, begin: uint) -> &str {
|
||||
// is_char_boundary checks that the index is in [0, .len()]
|
||||
if self.is_char_boundary(begin) {
|
||||
unsafe { self.slice_unchecked(begin, self.len()) }
|
||||
} else {
|
||||
slice_error_fail(self, begin, self.len())
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn slice_to(&self, end: uint) -> &str {
|
||||
// is_char_boundary checks that the index is in [0, .len()]
|
||||
if self.is_char_boundary(end) {
|
||||
unsafe { self.slice_unchecked(0, end) }
|
||||
} else {
|
||||
slice_error_fail(self, 0, end)
|
||||
}
|
||||
}
|
||||
|
||||
fn slice_chars(&self, begin: uint, end: uint) -> &str {
|
||||
assert!(begin <= end);
|
||||
let mut count = 0;
|
||||
|
@ -1415,7 +1469,7 @@ fn starts_with(&self, needle: &str) -> bool {
|
|||
#[inline]
|
||||
fn ends_with(&self, needle: &str) -> bool {
|
||||
let (m, n) = (self.len(), needle.len());
|
||||
m >= n && needle.as_bytes() == &self.as_bytes()[(m-n)..]
|
||||
m >= n && needle.as_bytes() == &self.as_bytes()[m-n..]
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![allow(deprecated)]
|
||||
|
||||
use core::finally::{try_finally, Finally};
|
||||
use std::thread::Thread;
|
||||
|
||||
|
|
|
@ -26,11 +26,11 @@ fn test_format_int() {
|
|||
assert!(format!("{}", -1i16) == "-1");
|
||||
assert!(format!("{}", -1i32) == "-1");
|
||||
assert!(format!("{}", -1i64) == "-1");
|
||||
assert!(format!("{:?}", 1i) == "1i");
|
||||
assert!(format!("{:?}", 1i8) == "1i8");
|
||||
assert!(format!("{:?}", 1i16) == "1i16");
|
||||
assert!(format!("{:?}", 1i32) == "1i32");
|
||||
assert!(format!("{:?}", 1i64) == "1i64");
|
||||
assert!(format!("{:?}", 1i) == "1");
|
||||
assert!(format!("{:?}", 1i8) == "1");
|
||||
assert!(format!("{:?}", 1i16) == "1");
|
||||
assert!(format!("{:?}", 1i32) == "1");
|
||||
assert!(format!("{:?}", 1i64) == "1");
|
||||
assert!(format!("{:b}", 1i) == "1");
|
||||
assert!(format!("{:b}", 1i8) == "1");
|
||||
assert!(format!("{:b}", 1i16) == "1");
|
||||
|
@ -57,11 +57,11 @@ fn test_format_int() {
|
|||
assert!(format!("{}", 1u16) == "1");
|
||||
assert!(format!("{}", 1u32) == "1");
|
||||
assert!(format!("{}", 1u64) == "1");
|
||||
assert!(format!("{:?}", 1u) == "1u");
|
||||
assert!(format!("{:?}", 1u8) == "1u8");
|
||||
assert!(format!("{:?}", 1u16) == "1u16");
|
||||
assert!(format!("{:?}", 1u32) == "1u32");
|
||||
assert!(format!("{:?}", 1u64) == "1u64");
|
||||
assert!(format!("{:?}", 1u) == "1");
|
||||
assert!(format!("{:?}", 1u8) == "1");
|
||||
assert!(format!("{:?}", 1u16) == "1");
|
||||
assert!(format!("{:?}", 1u32) == "1");
|
||||
assert!(format!("{:?}", 1u64) == "1");
|
||||
assert!(format!("{:b}", 1u) == "1");
|
||||
assert!(format!("{:b}", 1u8) == "1");
|
||||
assert!(format!("{:b}", 1u16) == "1");
|
||||
|
@ -94,14 +94,14 @@ fn test_format_int() {
|
|||
#[test]
|
||||
fn test_format_int_zero() {
|
||||
assert!(format!("{}", 0i) == "0");
|
||||
assert!(format!("{:?}", 0i) == "0i");
|
||||
assert!(format!("{:?}", 0i) == "0");
|
||||
assert!(format!("{:b}", 0i) == "0");
|
||||
assert!(format!("{:o}", 0i) == "0");
|
||||
assert!(format!("{:x}", 0i) == "0");
|
||||
assert!(format!("{:X}", 0i) == "0");
|
||||
|
||||
assert!(format!("{}", 0u) == "0");
|
||||
assert!(format!("{:?}", 0u) == "0u");
|
||||
assert!(format!("{:?}", 0u) == "0");
|
||||
assert!(format!("{:b}", 0u) == "0");
|
||||
assert!(format!("{:o}", 0u) == "0");
|
||||
assert!(format!("{:x}", 0u) == "0");
|
||||
|
|
|
@ -585,7 +585,7 @@ fn check_randacc_iter<A, T>(a: T, len: uint) where
|
|||
fn test_double_ended_flat_map() {
|
||||
let u = [0u,1];
|
||||
let v = [5u,6,7,8];
|
||||
let mut it = u.iter().flat_map(|x| v[(*x)..v.len()].iter());
|
||||
let mut it = u.iter().flat_map(|x| v[*x..v.len()].iter());
|
||||
assert_eq!(it.next_back().unwrap(), &8);
|
||||
assert_eq!(it.next().unwrap(), &5);
|
||||
assert_eq!(it.next_back().unwrap(), &7);
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
// except according to those terms.
|
||||
|
||||
use core::cmp::PartialEq;
|
||||
use core::fmt::Show;
|
||||
use core::fmt::Debug;
|
||||
use core::num::{NumCast, cast};
|
||||
use core::ops::{Add, Sub, Mul, Div, Rem};
|
||||
use core::marker::Copy;
|
||||
|
@ -37,7 +37,7 @@ pub fn test_num<T>(ten: T, two: T) where
|
|||
T: PartialEq + NumCast
|
||||
+ Add<Output=T> + Sub<Output=T>
|
||||
+ Mul<Output=T> + Div<Output=T>
|
||||
+ Rem<Output=T> + Show
|
||||
+ Rem<Output=T> + Debug
|
||||
+ Copy
|
||||
{
|
||||
assert_eq!(ten.add(two), cast(12i).unwrap());
|
||||
|
|
|
@ -14,11 +14,11 @@ pub fn op2() -> Result<int, &'static str> { Err("sadface") }
|
|||
#[test]
|
||||
pub fn test_and() {
|
||||
assert_eq!(op1().and(Ok(667i)).unwrap(), 667);
|
||||
assert_eq!(op1().and(Err::<(), &'static str>("bad")).unwrap_err(),
|
||||
assert_eq!(op1().and(Err::<i32, &'static str>("bad")).unwrap_err(),
|
||||
"bad");
|
||||
|
||||
assert_eq!(op2().and(Ok(667i)).unwrap_err(), "sadface");
|
||||
assert_eq!(op2().and(Err::<(),&'static str>("bad")).unwrap_err(),
|
||||
assert_eq!(op2().and(Err::<i32,&'static str>("bad")).unwrap_err(),
|
||||
"sadface");
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ pub fn test_fmt_default() {
|
|||
let err: Result<int, &'static str> = Err("Err");
|
||||
|
||||
let s = format!("{:?}", ok);
|
||||
assert_eq!(s, "Ok(100i)");
|
||||
assert_eq!(s, "Ok(100)");
|
||||
let s = format!("{:?}", err);
|
||||
assert_eq!(s, "Err(\"Err\")");
|
||||
}
|
||||
|
|
|
@ -60,9 +60,9 @@ fn test_tuple_cmp() {
|
|||
#[test]
|
||||
fn test_show() {
|
||||
let s = format!("{:?}", (1i,));
|
||||
assert_eq!(s, "(1i,)");
|
||||
assert_eq!(s, "(1,)");
|
||||
let s = format!("{:?}", (1i, true));
|
||||
assert_eq!(s, "(1i, true)");
|
||||
assert_eq!(s, "(1, true)");
|
||||
let s = format!("{:?}", (1i, "hi", true));
|
||||
assert_eq!(s, "(1i, \"hi\", true)");
|
||||
assert_eq!(s, "(1, \"hi\", true)");
|
||||
}
|
||||
|
|
|
@ -544,7 +544,7 @@ pub fn to_err_msg(self) -> String {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::String for Fail {
|
||||
impl fmt::Display for Fail {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
ArgumentMissing(ref nm) => {
|
||||
|
@ -893,7 +893,7 @@ fn each_split_within<F>(ss: &str, lim: uint, mut it: F) -> bool where
|
|||
(B, Cr, UnderLim) => { B }
|
||||
(B, Cr, OverLim) if (i - last_start + 1) > lim
|
||||
=> panic!("word starting with {} longer than limit!",
|
||||
&ss[last_start..(i + 1)]),
|
||||
&ss[last_start..i + 1]),
|
||||
(B, Cr, OverLim) => {
|
||||
*cont = it(&ss[slice_start..last_end]);
|
||||
slice_start = last_start;
|
||||
|
|
|
@ -358,19 +358,19 @@ impl<'a> Id<'a> {
|
|||
///
|
||||
/// Passing an invalid string (containing spaces, brackets,
|
||||
/// quotes, ...) will return an empty `Err` value.
|
||||
pub fn new<Name: IntoCow<'a, String, str>>(name: Name) -> Result<Id<'a>, ()> {
|
||||
pub fn new<Name: IntoCow<'a, String, str>>(name: Name) -> Option<Id<'a>> {
|
||||
let name = name.into_cow();
|
||||
{
|
||||
let mut chars = name.chars();
|
||||
match chars.next() {
|
||||
Some(c) if is_letter_or_underscore(c) => { ; },
|
||||
_ => return Err(())
|
||||
_ => return None
|
||||
}
|
||||
if !chars.all(is_constituent) {
|
||||
return Err(());
|
||||
return None
|
||||
}
|
||||
}
|
||||
return Ok(Id{ name: name });
|
||||
return Some(Id{ name: name });
|
||||
|
||||
fn is_letter_or_underscore(c: char) -> bool {
|
||||
in_range('a', c, 'z') || in_range('A', c, 'Z') || c == '_'
|
||||
|
@ -874,8 +874,8 @@ fn left_aligned_text() {
|
|||
fn simple_id_construction() {
|
||||
let id1 = Id::new("hello");
|
||||
match id1 {
|
||||
Ok(_) => {;},
|
||||
Err(_) => panic!("'hello' is not a valid value for id anymore")
|
||||
Some(_) => {;},
|
||||
None => panic!("'hello' is not a valid value for id anymore")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -883,8 +883,8 @@ fn simple_id_construction() {
|
|||
fn badly_formatted_id() {
|
||||
let id2 = Id::new("Weird { struct : ure } !!!");
|
||||
match id2 {
|
||||
Ok(_) => panic!("graphviz id suddenly allows spaces, brackets and stuff"),
|
||||
Err(_) => {;}
|
||||
Some(_) => panic!("graphviz id suddenly allows spaces, brackets and stuff"),
|
||||
None => {;}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -124,7 +124,7 @@ fn from_iter<I:Iterator<Item=T>>(iterator: I) -> MaybeOwnedVector<'a,T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a,T:fmt::Show> fmt::Show for MaybeOwnedVector<'a,T> {
|
||||
impl<'a,T:fmt::Debug> fmt::Debug for MaybeOwnedVector<'a,T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.as_slice().fmt(f)
|
||||
}
|
||||
|
|
|
@ -4648,13 +4648,13 @@ pub mod signal {
|
|||
use types::os::arch::c95::c_int;
|
||||
use types::os::common::posix01::sighandler_t;
|
||||
|
||||
#[cfg(not(target_os = "android"))]
|
||||
#[cfg(not(all(target_os = "android", target_arch = "arm")))]
|
||||
extern {
|
||||
pub fn signal(signum: c_int,
|
||||
handler: sighandler_t) -> sighandler_t;
|
||||
}
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
#[cfg(all(target_os = "android", target_arch = "arm"))]
|
||||
extern {
|
||||
#[link_name = "bsd_signal"]
|
||||
pub fn signal(signum: c_int,
|
||||
|
|
|
@ -180,6 +180,7 @@
|
|||
use std::io;
|
||||
use std::mem;
|
||||
use std::os;
|
||||
use std::ptr;
|
||||
use std::rt;
|
||||
use std::slice;
|
||||
use std::sync::{Once, ONCE_INIT};
|
||||
|
@ -239,21 +240,15 @@ struct DefaultLogger {
|
|||
}
|
||||
|
||||
/// Wraps the log level with fmt implementations.
|
||||
#[derive(Copy, PartialEq, PartialOrd)]
|
||||
#[derive(Copy, PartialEq, PartialOrd, Show)]
|
||||
pub struct LogLevel(pub u32);
|
||||
|
||||
impl fmt::Show for LogLevel {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::String::fmt(self, fmt)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::String for LogLevel {
|
||||
impl fmt::Display for LogLevel {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
let LogLevel(level) = *self;
|
||||
match LOG_LEVEL_NAMES.get(level as uint - 1) {
|
||||
Some(ref name) => fmt::String::fmt(name, fmt),
|
||||
None => fmt::String::fmt(&level, fmt)
|
||||
Some(ref name) => fmt::Display::fmt(name, fmt),
|
||||
None => fmt::Display::fmt(&level, fmt)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -437,11 +432,11 @@ fn init() {
|
|||
assert!(!DIRECTIVES.is_null());
|
||||
let _directives: Box<Vec<directive::LogDirective>> =
|
||||
mem::transmute(DIRECTIVES);
|
||||
DIRECTIVES = 0 as *const Vec<directive::LogDirective>;
|
||||
DIRECTIVES = ptr::null();
|
||||
|
||||
if !FILTER.is_null() {
|
||||
let _filter: Box<Regex> = mem::transmute(FILTER);
|
||||
FILTER = 0 as *const _;
|
||||
FILTER = ptr::null();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -174,7 +174,7 @@ fn reseed(&mut self, seed: &'a [u32]) {
|
|||
// reset state
|
||||
self.init(&[0u32; KEY_WORDS]);
|
||||
// set key in place
|
||||
let key = self.state.slice_mut(4, 4+KEY_WORDS);
|
||||
let key = &mut self.state[4 .. 4+KEY_WORDS];
|
||||
for (k, s) in key.iter_mut().zip(seed.iter()) {
|
||||
*k = *s;
|
||||
}
|
||||
|
@ -292,4 +292,3 @@ fn test_rng_clone() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -103,7 +103,7 @@ fn write(&mut self, buf: &[u8]) -> IoResult<()> {
|
|||
|
||||
// Do the necessary writes
|
||||
if left.len() > 0 {
|
||||
slice::bytes::copy_memory(self.buf.slice_from_mut(self.pos), left);
|
||||
slice::bytes::copy_memory(&mut self.buf[self.pos..], left);
|
||||
}
|
||||
if right.len() > 0 {
|
||||
self.buf.push_all(right);
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
pub use self::Error::*;
|
||||
|
||||
use std::str;
|
||||
use std::fmt;
|
||||
|
||||
pub mod io;
|
||||
|
||||
|
@ -113,6 +114,13 @@ pub enum Error {
|
|||
IoError(std::io::IoError),
|
||||
ApplicationError(String)
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
// FIXME: this should be a more useful display form
|
||||
fmt::Debug::fmt(self, f)
|
||||
}
|
||||
}
|
||||
// --------------------------------------
|
||||
|
||||
pub mod reader {
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
///
|
||||
/// (Once an expression is compiled, it is not possible to produce an error
|
||||
/// via searching, splitting or replacing.)
|
||||
#[derive(Show)]
|
||||
pub struct Error {
|
||||
/// The *approximate* character index of where the error occurred.
|
||||
pub pos: uint,
|
||||
|
@ -37,7 +38,7 @@ pub struct Error {
|
|||
pub msg: String,
|
||||
}
|
||||
|
||||
impl fmt::Show for Error {
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "Regex syntax error near position {}: {:?}",
|
||||
self.pos, self.msg)
|
||||
|
@ -518,7 +519,7 @@ fn parse_counted(&mut self) -> Result<(), Error> {
|
|||
};
|
||||
self.chari = closer;
|
||||
let greed = try!(self.get_next_greedy());
|
||||
let inner = self.chars[(start+1)..closer].iter().cloned()
|
||||
let inner = self.chars[start+1..closer].iter().cloned()
|
||||
.collect::<String>();
|
||||
|
||||
// Parse the min and max values from the regex.
|
||||
|
|
|
@ -90,10 +90,10 @@ fn clone(&self) -> ExNative {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::String for Regex {
|
||||
impl fmt::Display for Regex {
|
||||
/// Shows the original regular expression.
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::String::fmt(self.as_str(), f)
|
||||
fmt::Display::fmt(self.as_str(), f)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -459,7 +459,7 @@ pub fn pos(&self, i: uint) -> Option<(uint, uint)> {
|
|||
pub fn at(&self, i: uint) -> Option<&'t str> {
|
||||
match self.pos(i) {
|
||||
None => None,
|
||||
Some((s, e)) => Some(self.text.slice(s, e))
|
||||
Some((s, e)) => Some(&self.text[s.. e])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,28 +10,55 @@
|
|||
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
register_diagnostic! { E0001, r##"
|
||||
register_long_diagnostics! {
|
||||
E0001: r##"
|
||||
This error suggests that the expression arm corresponding to the noted pattern
|
||||
will never be reached as for all possible values of the expression being matched,
|
||||
one of the preceeding patterns will match.
|
||||
|
||||
This means that perhaps some of the preceeding patterns are too general, this
|
||||
one is too specific or the ordering is incorrect.
|
||||
"## }
|
||||
"##,
|
||||
|
||||
E0003: r##"
|
||||
Not-a-Number (NaN) values can not be compared for equality and hence can never match
|
||||
the input to a match expression. To match against NaN values, you should instead use
|
||||
the `is_nan` method in a guard, as in: x if x.is_nan() => ...
|
||||
"##,
|
||||
|
||||
E0004: r##"
|
||||
This error indicates that the compiler can not guarantee a matching pattern for one
|
||||
or more possible inputs to a match expression. Guaranteed matches are required in order
|
||||
to assign values to match expressions, or alternatively, determine the flow of execution.
|
||||
|
||||
If you encounter this error you must alter your patterns so that every possible value of
|
||||
the input type is matched. For types with a small number of variants (like enums) you
|
||||
should probably cover all cases explicitly. Alternatively, the underscore `_` wildcard
|
||||
pattern can be added after all other patterns to match "anything else".
|
||||
"##,
|
||||
|
||||
// FIXME: Remove duplication here?
|
||||
E0005: r##"
|
||||
Patterns used to bind names must be irrefutable, that is, they must guarantee that a
|
||||
name will be extracted in all cases. If you encounter this error you probably need
|
||||
to use a `match` or `if let` to deal with the possibility of failure.
|
||||
"##,
|
||||
|
||||
E0006: r##"
|
||||
Patterns used to bind names must be irrefutable, that is, they must guarantee that a
|
||||
name will be extracted in all cases. If you encounter this error you probably need
|
||||
to use a `match` or `if let` to deal with the possibility of failure.
|
||||
"##
|
||||
}
|
||||
|
||||
register_diagnostics! {
|
||||
E0002,
|
||||
E0003,
|
||||
E0004,
|
||||
E0005,
|
||||
E0006,
|
||||
E0007,
|
||||
E0008,
|
||||
E0009,
|
||||
E0010,
|
||||
E0011,
|
||||
E0012,
|
||||
E0013,
|
||||
E0014,
|
||||
E0015,
|
||||
E0016,
|
||||
|
@ -49,24 +76,58 @@
|
|||
E0137,
|
||||
E0138,
|
||||
E0139,
|
||||
E0140,
|
||||
E0152,
|
||||
E0153,
|
||||
E0157,
|
||||
E0158,
|
||||
E0161,
|
||||
E0162,
|
||||
E0165,
|
||||
E0166,
|
||||
E0167,
|
||||
E0168,
|
||||
E0169,
|
||||
E0170,
|
||||
E0171,
|
||||
E0172,
|
||||
E0173,
|
||||
E0174,
|
||||
E0177,
|
||||
E0178,
|
||||
E0179
|
||||
E0261, // use of undeclared lifetime name
|
||||
E0262, // illegal lifetime parameter name
|
||||
E0263, // lifetime name declared twice in same scope
|
||||
E0264, // unknown external lang item
|
||||
E0265, // recursive constant
|
||||
E0266, // expected item
|
||||
E0267, // thing inside of a closure
|
||||
E0268, // thing outside of a loop
|
||||
E0269, // not all control paths return a value
|
||||
E0270, // computation may converge in a function marked as diverging
|
||||
E0271, // type mismatch resolving
|
||||
E0272, // rustc_on_unimplemented attribute refers to non-existent type parameter
|
||||
E0273, // rustc_on_unimplemented must have named format arguments
|
||||
E0274, // rustc_on_unimplemented must have a value
|
||||
E0275, // overflow evaluating requirement
|
||||
E0276, // requirement appears on impl method but not on corresponding trait method
|
||||
E0277, // trait is not implemented for type
|
||||
E0278, // requirement is not satisfied
|
||||
E0279, // requirement is not satisfied
|
||||
E0280, // requirement is not satisfied
|
||||
E0281, // type implements trait but other trait is required
|
||||
E0282, // unable to infer enough type information about
|
||||
E0283, // cannot resolve type
|
||||
E0284, // cannot resolve type
|
||||
E0285, // overflow evaluation builtin bounds
|
||||
E0296, // malformed recursion limit attribute
|
||||
E0297, // refutable pattern in for loop binding
|
||||
E0298, // mismatched types between arms
|
||||
E0299, // mismatched types between arms
|
||||
E0300, // unexpanded macro
|
||||
E0301, // cannot mutable borrow in a pattern guard
|
||||
E0302, // cannot assign in a pattern guard
|
||||
E0303, // pattern bindings are not allowed after an `@`
|
||||
E0304, // expected signed integer constant
|
||||
E0305, // expected constant
|
||||
E0306, // expected positive integer for repeat count
|
||||
E0307, // expected constant integer for repeat count
|
||||
E0308,
|
||||
E0309, // thing may not live long enough
|
||||
E0310, // thing may not live long enough
|
||||
E0311, // thing may not live long enough
|
||||
E0312, // lifetime of reference outlives lifetime of borrowed content
|
||||
E0313, // lifetime of borrowed pointer outlives lifetime of captured variable
|
||||
E0314, // closure outlives stack frame
|
||||
E0315 // cannot invoke closure outside of its lifetime
|
||||
}
|
||||
|
||||
__build_diagnostic_array! { DIAGNOSTICS }
|
||||
|
||||
|
|
|
@ -54,7 +54,9 @@
|
|||
|
||||
pub use rustc_llvm as llvm;
|
||||
|
||||
mod diagnostics;
|
||||
// NB: This module needs to be declared first so diagnostics are
|
||||
// registered before they are used.
|
||||
pub mod diagnostics;
|
||||
|
||||
pub mod back {
|
||||
pub use rustc_back::abi;
|
||||
|
@ -132,8 +134,6 @@ pub mod lib {
|
|||
pub use llvm;
|
||||
}
|
||||
|
||||
__build_diagnostic_array! { DIAGNOSTICS }
|
||||
|
||||
// A private module so that macro-expanded idents like
|
||||
// `::rustc::lint::Lint` will also work in `rustc` itself.
|
||||
//
|
||||
|
|
|
@ -1202,17 +1202,17 @@ fn get_lints(&self) -> LintArray {
|
|||
lint_array!(UNUSED_IMPORT_BRACES)
|
||||
}
|
||||
|
||||
fn check_view_item(&mut self, cx: &Context, view_item: &ast::ViewItem) {
|
||||
match view_item.node {
|
||||
ast::ViewItemUse(ref view_path) => {
|
||||
fn check_item(&mut self, cx: &Context, item: &ast::Item) {
|
||||
match item.node {
|
||||
ast::ItemUse(ref view_path) => {
|
||||
match view_path.node {
|
||||
ast::ViewPathList(_, ref items, _) => {
|
||||
ast::ViewPathList(_, ref items) => {
|
||||
if items.len() == 1 {
|
||||
match items[0].node {
|
||||
ast::PathListIdent {ref name, ..} => {
|
||||
let m = format!("braces around {} is unnecessary",
|
||||
token::get_ident(*name).get());
|
||||
cx.span_lint(UNUSED_IMPORT_BRACES, view_item.span,
|
||||
cx.span_lint(UNUSED_IMPORT_BRACES, item.span,
|
||||
&m[]);
|
||||
},
|
||||
_ => ()
|
||||
|
@ -1329,7 +1329,7 @@ fn check_unused_mut_pat(&self, cx: &Context, pats: &[P<ast::Pat>]) {
|
|||
let ident = path1.node;
|
||||
if let ast::BindByValue(ast::MutMutable) = mode {
|
||||
if !token::get_ident(ident).get().starts_with("_") {
|
||||
match mutables.entry(ident.name.uint()) {
|
||||
match mutables.entry(ident.name.usize()) {
|
||||
Vacant(entry) => { entry.insert(vec![id]); },
|
||||
Occupied(mut entry) => { entry.get_mut().push(id); },
|
||||
}
|
||||
|
@ -1709,22 +1709,6 @@ fn check_crate(&mut self, _: &Context, c: &ast::Crate) {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_view_item(&mut self, cx: &Context, item: &ast::ViewItem) {
|
||||
// compiler-generated `extern crate` statements have a dummy span.
|
||||
if item.span == DUMMY_SP { return }
|
||||
|
||||
let id = match item.node {
|
||||
ast::ViewItemExternCrate(_, _, id) => id,
|
||||
ast::ViewItemUse(..) => return,
|
||||
};
|
||||
let cnum = match cx.tcx.sess.cstore.find_extern_mod_stmt_cnum(id) {
|
||||
Some(cnum) => cnum,
|
||||
None => return,
|
||||
};
|
||||
let id = ast::DefId { krate: cnum, node: ast::CRATE_NODE_ID };
|
||||
self.lint(cx, id, item.span);
|
||||
}
|
||||
|
||||
fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
|
||||
if self.is_internal(cx, e.span) { return; }
|
||||
|
||||
|
@ -1776,6 +1760,17 @@ fn check_item(&mut self, cx: &Context, item: &ast::Item) {
|
|||
if self.is_internal(cx, item.span) { return }
|
||||
|
||||
match item.node {
|
||||
ast::ItemExternCrate(_) => {
|
||||
// compiler-generated `extern crate` items have a dummy span.
|
||||
if item.span == DUMMY_SP { return }
|
||||
|
||||
let cnum = match cx.tcx.sess.cstore.find_extern_mod_stmt_cnum(item.id) {
|
||||
Some(cnum) => cnum,
|
||||
None => return,
|
||||
};
|
||||
let id = ast::DefId { krate: cnum, node: ast::CRATE_NODE_ID };
|
||||
self.lint(cx, id, item.span);
|
||||
}
|
||||
ast::ItemTrait(_, _, ref supertraits, _) => {
|
||||
for t in supertraits.iter() {
|
||||
if let ast::TraitTyParamBound(ref t, _) = *t {
|
||||
|
|
|
@ -231,30 +231,7 @@ macro_rules! add_lint_group {
|
|||
// We have one lint pass defined in this module.
|
||||
self.register_pass(sess, false, box GatherNodeLevels as LintPassObject);
|
||||
|
||||
// Insert temporary renamings for a one-time deprecation (#16545)
|
||||
self.register_renamed("unnecessary_typecast", "unused_typecasts");
|
||||
self.register_renamed("unsigned_negate", "unsigned_negation");
|
||||
self.register_renamed("type_limits", "unused_comparisons");
|
||||
self.register_renamed("type_overflow", "overflowing_literals");
|
||||
self.register_renamed("ctypes", "improper_ctypes");
|
||||
self.register_renamed("owned_heap_memory", "box_pointers");
|
||||
self.register_renamed("unused_attribute", "unused_attributes");
|
||||
self.register_renamed("path_statement", "path_statements");
|
||||
self.register_renamed("unused_result", "unused_results");
|
||||
self.register_renamed("non_uppercase_statics", "non_upper_case_globals");
|
||||
self.register_renamed("unnecessary_parens", "unused_parens");
|
||||
self.register_renamed("unnecessary_import_braces", "unused_import_braces");
|
||||
self.register_renamed("unsafe_block", "unsafe_blocks");
|
||||
self.register_renamed("unnecessary_allocation", "unused_allocation");
|
||||
self.register_renamed("missing_doc", "missing_docs");
|
||||
self.register_renamed("unused_extern_crate", "unused_extern_crates");
|
||||
self.register_renamed("unnecessary_qualification", "unused_qualifications");
|
||||
self.register_renamed("unrecognized_lint", "unknown_lints");
|
||||
self.register_renamed("unused_variable", "unused_variables");
|
||||
self.register_renamed("dead_assignment", "unused_assignments");
|
||||
self.register_renamed("unknown_crate_type", "unknown_crate_types");
|
||||
self.register_renamed("variant_size_difference", "variant_size_differences");
|
||||
self.register_renamed("transmute_fat_ptr", "fat_ptr_transmutes");
|
||||
// Insert temporary renamings for a one-time deprecation
|
||||
self.register_renamed("raw_pointer_deriving", "raw_pointer_derive");
|
||||
|
||||
}
|
||||
|
@ -603,14 +580,6 @@ fn visit_foreign_item(&mut self, it: &ast::ForeignItem) {
|
|||
})
|
||||
}
|
||||
|
||||
fn visit_view_item(&mut self, i: &ast::ViewItem) {
|
||||
self.with_lint_attrs(&i.attrs[], |cx| {
|
||||
run_lints!(cx, check_view_item, i);
|
||||
cx.visit_ids(|v| v.visit_view_item(i));
|
||||
visit::walk_view_item(cx, i);
|
||||
})
|
||||
}
|
||||
|
||||
fn visit_pat(&mut self, p: &ast::Pat) {
|
||||
run_lints!(self, check_pat, p);
|
||||
visit::walk_pat(self, p);
|
||||
|
|
|
@ -128,7 +128,6 @@ pub trait LintPass {
|
|||
fn check_crate(&mut self, _: &Context, _: &ast::Crate) { }
|
||||
fn check_ident(&mut self, _: &Context, _: Span, _: ast::Ident) { }
|
||||
fn check_mod(&mut self, _: &Context, _: &ast::Mod, _: Span, _: ast::NodeId) { }
|
||||
fn check_view_item(&mut self, _: &Context, _: &ast::ViewItem) { }
|
||||
fn check_foreign_item(&mut self, _: &Context, _: &ast::ForeignItem) { }
|
||||
fn check_item(&mut self, _: &Context, _: &ast::Item) { }
|
||||
fn check_local(&mut self, _: &Context, _: &ast::Local) { }
|
||||
|
|
|
@ -40,10 +40,6 @@ pub struct CrateReader<'a> {
|
|||
}
|
||||
|
||||
impl<'a, 'v> visit::Visitor<'v> for CrateReader<'a> {
|
||||
fn visit_view_item(&mut self, a: &ast::ViewItem) {
|
||||
self.process_view_item(a);
|
||||
visit::walk_view_item(self, a);
|
||||
}
|
||||
fn visit_item(&mut self, a: &ast::Item) {
|
||||
self.process_item(a);
|
||||
visit::walk_item(self, a);
|
||||
|
@ -64,9 +60,8 @@ fn dump_crates(cstore: &CStore) {
|
|||
})
|
||||
}
|
||||
|
||||
fn should_link(i: &ast::ViewItem) -> bool {
|
||||
fn should_link(i: &ast::Item) -> bool {
|
||||
!attr::contains_name(&i.attrs[], "no_link")
|
||||
|
||||
}
|
||||
|
||||
struct CrateInfo {
|
||||
|
@ -181,7 +176,35 @@ fn process_crate(&self, c: &ast::Crate) {
|
|||
}
|
||||
}
|
||||
|
||||
fn process_view_item(&mut self, i: &ast::ViewItem) {
|
||||
fn extract_crate_info(&self, i: &ast::Item) -> Option<CrateInfo> {
|
||||
match i.node {
|
||||
ast::ItemExternCrate(ref path_opt) => {
|
||||
let ident = token::get_ident(i.ident);
|
||||
debug!("resolving extern crate stmt. ident: {} path_opt: {:?}",
|
||||
ident, path_opt);
|
||||
let name = match *path_opt {
|
||||
Some((ref path_str, _)) => {
|
||||
let name = path_str.get().to_string();
|
||||
validate_crate_name(Some(self.sess), &name[],
|
||||
Some(i.span));
|
||||
name
|
||||
}
|
||||
None => ident.get().to_string(),
|
||||
};
|
||||
Some(CrateInfo {
|
||||
ident: ident.get().to_string(),
|
||||
name: name,
|
||||
id: i.id,
|
||||
should_link: should_link(i),
|
||||
})
|
||||
}
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
|
||||
fn process_item(&mut self, i: &ast::Item) {
|
||||
match i.node {
|
||||
ast::ItemExternCrate(_) => {
|
||||
if !should_link(i) {
|
||||
return;
|
||||
}
|
||||
|
@ -199,35 +222,6 @@ fn process_view_item(&mut self, i: &ast::ViewItem) {
|
|||
None => ()
|
||||
}
|
||||
}
|
||||
|
||||
fn extract_crate_info(&self, i: &ast::ViewItem) -> Option<CrateInfo> {
|
||||
match i.node {
|
||||
ast::ViewItemExternCrate(ident, ref path_opt, id) => {
|
||||
let ident = token::get_ident(ident);
|
||||
debug!("resolving extern crate stmt. ident: {} path_opt: {:?}",
|
||||
ident, path_opt);
|
||||
let name = match *path_opt {
|
||||
Some((ref path_str, _)) => {
|
||||
let name = path_str.get().to_string();
|
||||
validate_crate_name(Some(self.sess), &name[],
|
||||
Some(i.span));
|
||||
name
|
||||
}
|
||||
None => ident.get().to_string(),
|
||||
};
|
||||
Some(CrateInfo {
|
||||
ident: ident.get().to_string(),
|
||||
name: name,
|
||||
id: id,
|
||||
should_link: should_link(i),
|
||||
})
|
||||
}
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
|
||||
fn process_item(&self, i: &ast::Item) {
|
||||
match i.node {
|
||||
ast::ItemForeignMod(ref fm) => {
|
||||
if fm.abi == abi::Rust || fm.abi == abi::RustIntrinsic {
|
||||
return;
|
||||
|
@ -533,7 +527,7 @@ pub fn read_plugin_metadata<'b>(&'b mut self,
|
|||
|
||||
#[derive(Copy)]
|
||||
pub enum CrateOrString<'a> {
|
||||
Krate(&'a ast::ViewItem),
|
||||
Krate(&'a ast::Item),
|
||||
Str(&'a str)
|
||||
}
|
||||
|
||||
|
|
|
@ -242,7 +242,7 @@ pub fn as_slice<'a>(&'a self) -> &'a [u8] {
|
|||
((slice[2] as u32) << 8) |
|
||||
((slice[3] as u32) << 0)) as uint;
|
||||
if len + 4 <= slice.len() {
|
||||
slice.slice(4, len + 4)
|
||||
&slice[4.. len + 4]
|
||||
} else {
|
||||
&[] // corrupt or old metadata
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ fn lookup_hash<'a, F>(d: rbml::Doc<'a>, mut eq_fn: F, hash: u64) -> Option<rbml:
|
|||
let mut ret = None;
|
||||
reader::tagged_docs(tagged_doc.doc, belt, |elt| {
|
||||
let pos = u64_from_be_bytes(elt.data, elt.start, 4) as uint;
|
||||
if eq_fn(&elt.data[(elt.start + 4) .. elt.end]) {
|
||||
if eq_fn(&elt.data[elt.start + 4 .. elt.end]) {
|
||||
ret = Some(reader::doc_at(d.data, pos).unwrap().doc);
|
||||
false
|
||||
} else {
|
||||
|
|
|
@ -1456,8 +1456,8 @@ fn add_to_index(item: &ast::Item, rbml_w: &Encoder,
|
|||
rbml_w.end_tag();
|
||||
}
|
||||
}
|
||||
ast::ItemMac(..) => {
|
||||
// macros are encoded separately
|
||||
ast::ItemExternCrate(_) | ast::ItemUse(_) |ast::ItemMac(..) => {
|
||||
// these are encoded separately
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -392,11 +392,11 @@ fn find_library_crate(&mut self) -> Option<Library> {
|
|||
};
|
||||
let (hash, rlib) = if file.starts_with(&rlib_prefix[]) &&
|
||||
file.ends_with(".rlib") {
|
||||
(file.slice(rlib_prefix.len(), file.len() - ".rlib".len()),
|
||||
(&file[(rlib_prefix.len()) .. (file.len() - ".rlib".len())],
|
||||
true)
|
||||
} else if file.starts_with(dylib_prefix.as_slice()) &&
|
||||
file.ends_with(dypair.1.as_slice()) {
|
||||
(file.slice(dylib_prefix.len(), file.len() - dypair.1.len()),
|
||||
(&file[(dylib_prefix.len()) .. (file.len() - dypair.1.len())],
|
||||
false)
|
||||
} else {
|
||||
return FileDoesntMatch
|
||||
|
|
|
@ -243,19 +243,6 @@ fn parse_size(st: &mut PState) -> Option<uint> {
|
|||
}
|
||||
}
|
||||
|
||||
fn parse_trait_store_<F>(st: &mut PState, conv: &mut F) -> ty::TraitStore where
|
||||
F: FnMut(DefIdSource, ast::DefId) -> ast::DefId,
|
||||
{
|
||||
match next(st) {
|
||||
'~' => ty::UniqTraitStore,
|
||||
'&' => ty::RegionTraitStore(parse_region_(st, conv), parse_mutability(st)),
|
||||
c => {
|
||||
st.tcx.sess.bug(&format!("parse_trait_store(): bad input '{}'",
|
||||
c)[])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_vec_per_param_space<'a, 'tcx, T, F>(st: &mut PState<'a, 'tcx>,
|
||||
mut f: F)
|
||||
-> VecPerParamSpace<T> where
|
||||
|
@ -641,14 +628,6 @@ fn parse_abi_set(st: &mut PState) -> abi::Abi {
|
|||
})
|
||||
}
|
||||
|
||||
fn parse_onceness(c: char) -> ast::Onceness {
|
||||
match c {
|
||||
'o' => ast::Once,
|
||||
'm' => ast::Many,
|
||||
_ => panic!("parse_onceness: bad onceness")
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_closure_ty<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>,
|
||||
mut conv: F) -> ty::ClosureTy<'tcx> where
|
||||
F: FnMut(DefIdSource, ast::DefId) -> ast::DefId,
|
||||
|
@ -661,16 +640,10 @@ fn parse_closure_ty_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>,
|
|||
F: FnMut(DefIdSource, ast::DefId) -> ast::DefId,
|
||||
{
|
||||
let unsafety = parse_unsafety(next(st));
|
||||
let onceness = parse_onceness(next(st));
|
||||
let store = parse_trait_store_(st, conv);
|
||||
let bounds = parse_existential_bounds_(st, conv);
|
||||
let sig = parse_sig_(st, conv);
|
||||
let abi = parse_abi_set(st);
|
||||
ty::ClosureTy {
|
||||
unsafety: unsafety,
|
||||
onceness: onceness,
|
||||
store: store,
|
||||
bounds: bounds,
|
||||
sig: sig,
|
||||
abi: abi,
|
||||
}
|
||||
|
@ -734,7 +707,7 @@ pub fn parse_def_id(buf: &[u8]) -> ast::DefId {
|
|||
}
|
||||
|
||||
let crate_part = &buf[0u..colon_idx];
|
||||
let def_part = &buf[(colon_idx + 1u)..len];
|
||||
let def_part = &buf[colon_idx + 1u..len];
|
||||
|
||||
let crate_num = match str::from_utf8(crate_part).ok().and_then(|s| s.parse::<uint>()) {
|
||||
Some(cn) => cn as ast::CrateNum,
|
||||
|
|
|
@ -305,17 +305,6 @@ pub fn enc_trait_ref<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>,
|
|||
enc_substs(w, cx, s.substs);
|
||||
}
|
||||
|
||||
pub fn enc_trait_store(w: &mut SeekableMemWriter, cx: &ctxt, s: ty::TraitStore) {
|
||||
match s {
|
||||
ty::UniqTraitStore => mywrite!(w, "~"),
|
||||
ty::RegionTraitStore(re, m) => {
|
||||
mywrite!(w, "&");
|
||||
enc_region(w, cx, re);
|
||||
enc_mutability(w, m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn enc_unsafety(w: &mut SeekableMemWriter, p: ast::Unsafety) {
|
||||
match p {
|
||||
ast::Unsafety::Normal => mywrite!(w, "n"),
|
||||
|
@ -329,13 +318,6 @@ fn enc_abi(w: &mut SeekableMemWriter, abi: Abi) {
|
|||
mywrite!(w, "]")
|
||||
}
|
||||
|
||||
fn enc_onceness(w: &mut SeekableMemWriter, o: ast::Onceness) {
|
||||
match o {
|
||||
ast::Once => mywrite!(w, "o"),
|
||||
ast::Many => mywrite!(w, "m")
|
||||
}
|
||||
}
|
||||
|
||||
pub fn enc_bare_fn_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>,
|
||||
ft: &ty::BareFnTy<'tcx>) {
|
||||
enc_unsafety(w, ft.unsafety);
|
||||
|
@ -346,9 +328,6 @@ pub fn enc_bare_fn_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>,
|
|||
pub fn enc_closure_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>,
|
||||
ft: &ty::ClosureTy<'tcx>) {
|
||||
enc_unsafety(w, ft.unsafety);
|
||||
enc_onceness(w, ft.onceness);
|
||||
enc_trait_store(w, cx, ft.store);
|
||||
enc_existential_bounds(w, cx, &ft.bounds);
|
||||
enc_fn_sig(w, cx, &ft.sig);
|
||||
enc_abi(w, ft.abi);
|
||||
}
|
||||
|
|
|
@ -332,8 +332,6 @@ fn fold_block(&mut self, blk: P<ast::Block>) -> P<ast::Block> {
|
|||
}
|
||||
}).collect();
|
||||
let blk_sans_items = P(ast::Block {
|
||||
view_items: Vec::new(), // I don't know if we need the view_items
|
||||
// here, but it doesn't break tests!
|
||||
stmts: stmts_sans_items,
|
||||
expr: expr,
|
||||
id: id,
|
||||
|
@ -515,17 +513,6 @@ fn tr(&self, dcx: &DecodeContext) -> ty::BoundRegion {
|
|||
}
|
||||
}
|
||||
|
||||
impl tr for ty::TraitStore {
|
||||
fn tr(&self, dcx: &DecodeContext) -> ty::TraitStore {
|
||||
match *self {
|
||||
ty::RegionTraitStore(r, m) => {
|
||||
ty::RegionTraitStore(r.tr(dcx), m)
|
||||
}
|
||||
ty::UniqTraitStore => ty::UniqTraitStore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ______________________________________________________________________
|
||||
// Encoding and decoding of freevar information
|
||||
|
||||
|
|
|
@ -424,7 +424,7 @@ fn expr(&mut self, expr: &ast::Expr, pred: CFGIndex) -> CFGIndex {
|
|||
}
|
||||
|
||||
ast::ExprMethodCall(_, _, ref args) => {
|
||||
self.call(expr, pred, &*args[0], args.slice_from(1).iter().map(|e| &**e))
|
||||
self.call(expr, pred, &*args[0], args[1..].iter().map(|e| &**e))
|
||||
}
|
||||
|
||||
ast::ExprIndex(ref l, ref r) |
|
||||
|
|
|
@ -73,12 +73,12 @@ fn require_loop(&self, name: &str, span: Span) {
|
|||
match self.cx {
|
||||
Loop => {}
|
||||
Closure => {
|
||||
self.sess.span_err(span,
|
||||
&format!("`{}` inside of a closure", name)[]);
|
||||
span_err!(self.sess, span, E0267,
|
||||
"`{}` inside of a closure", name);
|
||||
}
|
||||
Normal => {
|
||||
self.sess.span_err(span,
|
||||
&format!("`{}` outside of loop", name)[]);
|
||||
span_err!(self.sess, span, E0268,
|
||||
"`{}` outside of loop", name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@
|
|||
/// ++++++++++++++++++++++++++
|
||||
/// + _ + [_, _, ..tail] +
|
||||
/// ++++++++++++++++++++++++++
|
||||
impl<'a> fmt::Show for Matrix<'a> {
|
||||
impl<'a> fmt::Debug for Matrix<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
try!(write!(f, "\n"));
|
||||
|
||||
|
@ -226,11 +226,10 @@ fn check_expr(cx: &mut MatchCheckCtxt, ex: &ast::Expr) {
|
|||
ast::ExprForLoop(ref pat, _, _, _) => {
|
||||
let mut static_inliner = StaticInliner::new(cx.tcx);
|
||||
is_refutable(cx, &*static_inliner.fold_pat((*pat).clone()), |uncovered_pat| {
|
||||
cx.tcx.sess.span_err(
|
||||
pat.span,
|
||||
&format!("refutable pattern in `for` loop binding: \
|
||||
span_err!(cx.tcx.sess, pat.span, E0297,
|
||||
"refutable pattern in `for` loop binding: \
|
||||
`{}` not covered",
|
||||
pat_to_string(uncovered_pat))[]);
|
||||
pat_to_string(uncovered_pat));
|
||||
});
|
||||
|
||||
// Check legality of move bindings.
|
||||
|
@ -869,7 +868,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
|
|||
Some(true) => Some(vec![]),
|
||||
Some(false) => None,
|
||||
None => {
|
||||
cx.tcx.sess.span_err(pat_span, "mismatched types between arms");
|
||||
span_err!(cx.tcx.sess, pat_span, E0298, "mismatched types between arms");
|
||||
None
|
||||
}
|
||||
}
|
||||
|
@ -882,7 +881,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
|
|||
Some(true) => Some(vec![]),
|
||||
Some(false) => None,
|
||||
None => {
|
||||
cx.tcx.sess.span_err(pat_span, "mismatched types between arms");
|
||||
span_err!(cx.tcx.sess, pat_span, E0299, "mismatched types between arms");
|
||||
None
|
||||
}
|
||||
}
|
||||
|
@ -921,13 +920,13 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
|
|||
}
|
||||
|
||||
ast::PatMac(_) => {
|
||||
cx.tcx.sess.span_err(pat_span, "unexpanded macro");
|
||||
span_err!(cx.tcx.sess, pat_span, E0300, "unexpanded macro");
|
||||
None
|
||||
}
|
||||
};
|
||||
head.map(|mut head| {
|
||||
head.push_all(&r[..col]);
|
||||
head.push_all(&r[(col + 1)..]);
|
||||
head.push_all(&r[col + 1..]);
|
||||
head
|
||||
})
|
||||
}
|
||||
|
@ -1082,10 +1081,7 @@ fn borrow(&mut self,
|
|||
_: LoanCause) {
|
||||
match kind {
|
||||
MutBorrow => {
|
||||
self.cx
|
||||
.tcx
|
||||
.sess
|
||||
.span_err(span,
|
||||
span_err!(self.cx.tcx.sess, span, E0301,
|
||||
"cannot mutably borrow in a pattern guard")
|
||||
}
|
||||
ImmBorrow | UniqueImmBorrow => {}
|
||||
|
@ -1095,10 +1091,7 @@ fn decl_without_init(&mut self, _: NodeId, _: Span) {}
|
|||
fn mutate(&mut self, _: NodeId, span: Span, _: cmt, mode: MutateMode) {
|
||||
match mode {
|
||||
JustWrite | WriteAndRead => {
|
||||
self.cx
|
||||
.tcx
|
||||
.sess
|
||||
.span_err(span, "cannot assign in a pattern guard")
|
||||
span_err!(self.cx.tcx.sess, span, E0302, "cannot assign in a pattern guard")
|
||||
}
|
||||
Init => {}
|
||||
}
|
||||
|
@ -1120,7 +1113,7 @@ struct AtBindingPatternVisitor<'a, 'b:'a, 'tcx:'b> {
|
|||
impl<'a, 'b, 'tcx, 'v> Visitor<'v> for AtBindingPatternVisitor<'a, 'b, 'tcx> {
|
||||
fn visit_pat(&mut self, pat: &Pat) {
|
||||
if !self.bindings_allowed && pat_is_binding(&self.cx.tcx.def_map, pat) {
|
||||
self.cx.tcx.sess.span_err(pat.span,
|
||||
span_err!(self.cx.tcx.sess, pat.span, E0303,
|
||||
"pattern bindings are not allowed \
|
||||
after an `@`");
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ pub fn check_item_recursion<'a>(sess: &'a Session,
|
|||
impl<'a, 'ast, 'v> Visitor<'v> for CheckItemRecursionVisitor<'a, 'ast> {
|
||||
fn visit_item(&mut self, it: &ast::Item) {
|
||||
if self.idstack.iter().any(|x| x == &(it.id)) {
|
||||
self.sess.span_err(self.root_it.span, "recursive constant");
|
||||
span_err!(self.sess, self.root_it.span, E0265, "recursive constant");
|
||||
return;
|
||||
}
|
||||
self.idstack.push(it.id);
|
||||
|
@ -103,9 +103,9 @@ fn visit_expr(&mut self, e: &ast::Expr) {
|
|||
self.visit_item(item),
|
||||
ast_map::NodeForeignItem(_) => {},
|
||||
_ => {
|
||||
self.sess.span_err(e.span,
|
||||
&format!("expected item, found {}",
|
||||
self.ast_map.node_to_string(def_id.node))[]);
|
||||
span_err!(self.sess, e.span, E0266,
|
||||
"expected item, found {}",
|
||||
self.ast_map.node_to_string(def_id.node));
|
||||
return;
|
||||
},
|
||||
}
|
||||
|
|
|
@ -118,17 +118,17 @@ fn pre(&self,
|
|||
assert!(self.bits_per_id > 0);
|
||||
let cfgidx = to_cfgidx_or_die(id, &self.nodeid_to_index);
|
||||
let (start, end) = self.compute_id_range(cfgidx);
|
||||
let on_entry = self.on_entry.slice(start, end);
|
||||
let on_entry = &self.on_entry[start.. end];
|
||||
let entry_str = bits_to_string(on_entry);
|
||||
|
||||
let gens = self.gens.slice(start, end);
|
||||
let gens = &self.gens[start.. end];
|
||||
let gens_str = if gens.iter().any(|&u| u != 0) {
|
||||
format!(" gen: {}", bits_to_string(gens))
|
||||
} else {
|
||||
"".to_string()
|
||||
};
|
||||
|
||||
let kills = self.kills.slice(start, end);
|
||||
let kills = &self.kills[start .. end];
|
||||
let kills_str = if kills.iter().any(|&u| u != 0) {
|
||||
format!(" kill: {}", bits_to_string(kills))
|
||||
} else {
|
||||
|
@ -232,7 +232,7 @@ pub fn add_gen(&mut self, id: ast::NodeId, bit: uint) {
|
|||
|
||||
let cfgidx = to_cfgidx_or_die(id, &self.nodeid_to_index);
|
||||
let (start, end) = self.compute_id_range(cfgidx);
|
||||
let gens = self.gens.slice_mut(start, end);
|
||||
let gens = &mut self.gens[start.. end];
|
||||
set_bit(gens, bit);
|
||||
}
|
||||
|
||||
|
@ -245,7 +245,7 @@ pub fn add_kill(&mut self, id: ast::NodeId, bit: uint) {
|
|||
|
||||
let cfgidx = to_cfgidx_or_die(id, &self.nodeid_to_index);
|
||||
let (start, end) = self.compute_id_range(cfgidx);
|
||||
let kills = self.kills.slice_mut(start, end);
|
||||
let kills = &mut self.kills[start.. end];
|
||||
set_bit(kills, bit);
|
||||
}
|
||||
|
||||
|
@ -256,9 +256,9 @@ fn apply_gen_kill(&self, cfgidx: CFGIndex, bits: &mut [uint]) {
|
|||
assert!(self.bits_per_id > 0);
|
||||
|
||||
let (start, end) = self.compute_id_range(cfgidx);
|
||||
let gens = self.gens.slice(start, end);
|
||||
let gens = &self.gens[start.. end];
|
||||
bitwise(bits, gens, &Union);
|
||||
let kills = self.kills.slice(start, end);
|
||||
let kills = &self.kills[start.. end];
|
||||
bitwise(bits, kills, &Subtract);
|
||||
|
||||
debug!("{} apply_gen_kill(cfgidx={:?}, bits={}) [after]",
|
||||
|
@ -304,7 +304,7 @@ pub fn each_bit_for_node<F>(&self, e: EntryOrExit, cfgidx: CFGIndex, f: F) -> bo
|
|||
}
|
||||
|
||||
let (start, end) = self.compute_id_range(cfgidx);
|
||||
let on_entry = self.on_entry.slice(start, end);
|
||||
let on_entry = &self.on_entry[start.. end];
|
||||
let temp_bits;
|
||||
let slice = match e {
|
||||
Entry => on_entry,
|
||||
|
@ -336,7 +336,7 @@ pub fn each_gen_bit<F>(&self, id: ast::NodeId, f: F) -> bool where
|
|||
|
||||
let cfgidx = to_cfgidx_or_die(id, &self.nodeid_to_index);
|
||||
let (start, end) = self.compute_id_range(cfgidx);
|
||||
let gens = self.gens.slice(start, end);
|
||||
let gens = &self.gens[start.. end];
|
||||
debug!("{} each_gen_bit(id={}, gens={})",
|
||||
self.analysis_name, id, bits_to_string(gens));
|
||||
self.each_bit(gens, f)
|
||||
|
@ -396,7 +396,7 @@ pub fn add_kills_from_flow_exits(&mut self, cfg: &cfg::CFG) {
|
|||
cfg.graph.each_edge(|_edge_index, edge| {
|
||||
let flow_exit = edge.source();
|
||||
let (start, end) = self.compute_id_range(flow_exit);
|
||||
let mut orig_kills = self.kills.slice(start, end).to_vec();
|
||||
let mut orig_kills = self.kills[start.. end].to_vec();
|
||||
|
||||
let mut changed = false;
|
||||
for &node_id in edge.data.exiting_scopes.iter() {
|
||||
|
@ -404,7 +404,7 @@ pub fn add_kills_from_flow_exits(&mut self, cfg: &cfg::CFG) {
|
|||
match opt_cfg_idx {
|
||||
Some(cfg_idx) => {
|
||||
let (start, end) = self.compute_id_range(cfg_idx);
|
||||
let kills = self.kills.slice(start, end);
|
||||
let kills = &self.kills[start.. end];
|
||||
if bitwise(orig_kills.as_mut_slice(), kills, &Union) {
|
||||
changed = true;
|
||||
}
|
||||
|
@ -418,7 +418,7 @@ pub fn add_kills_from_flow_exits(&mut self, cfg: &cfg::CFG) {
|
|||
}
|
||||
|
||||
if changed {
|
||||
let bits = self.kills.slice_mut(start, end);
|
||||
let bits = &mut self.kills[start.. end];
|
||||
debug!("{} add_kills_from_flow_exits flow_exit={:?} bits={} [before]",
|
||||
self.analysis_name, flow_exit, mut_bits_to_string(bits));
|
||||
bits.clone_from_slice(&orig_kills[]);
|
||||
|
@ -487,7 +487,7 @@ fn walk_cfg(&mut self,
|
|||
let (start, end) = self.dfcx.compute_id_range(node_index);
|
||||
|
||||
// Initialize local bitvector with state on-entry.
|
||||
in_out.clone_from_slice(self.dfcx.on_entry.slice(start, end));
|
||||
in_out.clone_from_slice(&self.dfcx.on_entry[start.. end]);
|
||||
|
||||
// Compute state on-exit by applying transfer function to
|
||||
// state on-entry.
|
||||
|
@ -528,13 +528,13 @@ fn propagate_bits_into_entry_set_for(&mut self,
|
|||
let (start, end) = self.dfcx.compute_id_range(cfgidx);
|
||||
let changed = {
|
||||
// (scoping mutable borrow of self.dfcx.on_entry)
|
||||
let on_entry = self.dfcx.on_entry.slice_mut(start, end);
|
||||
let on_entry = &mut self.dfcx.on_entry[start.. end];
|
||||
bitwise(on_entry, pred_bits, &self.dfcx.oper)
|
||||
};
|
||||
if changed {
|
||||
debug!("{} changed entry set for {:?} to {}",
|
||||
self.dfcx.analysis_name, cfgidx,
|
||||
bits_to_string(self.dfcx.on_entry.slice(start, end)));
|
||||
bits_to_string(&self.dfcx.on_entry[start.. end]));
|
||||
self.changed = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
|
||||
#![allow(dead_code)] // still WIP
|
||||
|
||||
use std::fmt::{Formatter, Error, Show};
|
||||
use std::fmt::{Formatter, Error, Debug};
|
||||
use std::uint;
|
||||
use std::collections::BitvSet;
|
||||
|
||||
|
@ -53,7 +53,7 @@ pub struct Edge<E> {
|
|||
pub data: E,
|
||||
}
|
||||
|
||||
impl<E: Show> Show for Edge<E> {
|
||||
impl<E: Debug> Debug for Edge<E> {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
|
||||
write!(f, "Edge {{ next_edge: [{:?}, {:?}], source: {:?}, target: {:?}, data: {:?} }}",
|
||||
self.next_edge[0], self.next_edge[1], self.source,
|
||||
|
@ -353,7 +353,7 @@ pub fn target(&self) -> NodeIndex {
|
|||
#[cfg(test)]
|
||||
mod test {
|
||||
use middle::graph::*;
|
||||
use std::fmt::Show;
|
||||
use std::fmt::Debug;
|
||||
|
||||
type TestNode = Node<&'static str>;
|
||||
type TestEdge = Edge<&'static str>;
|
||||
|
@ -408,7 +408,7 @@ fn each_edge() {
|
|||
});
|
||||
}
|
||||
|
||||
fn test_adjacent_edges<N:PartialEq+Show,E:PartialEq+Show>(graph: &Graph<N,E>,
|
||||
fn test_adjacent_edges<N:PartialEq+Debug,E:PartialEq+Debug>(graph: &Graph<N,E>,
|
||||
start_index: NodeIndex,
|
||||
start_data: N,
|
||||
expected_incoming: &[(E,N)],
|
||||
|
|
|
@ -202,39 +202,6 @@ fn bare_fn_tys(&self, a: &ty::BareFnTy<'tcx>,
|
|||
sig: sig})
|
||||
}
|
||||
|
||||
fn closure_tys(&self, a: &ty::ClosureTy<'tcx>,
|
||||
b: &ty::ClosureTy<'tcx>) -> cres<'tcx, ty::ClosureTy<'tcx>> {
|
||||
|
||||
let store = match (a.store, b.store) {
|
||||
(ty::RegionTraitStore(a_r, a_m),
|
||||
ty::RegionTraitStore(b_r, b_m)) if a_m == b_m => {
|
||||
let r = try!(self.contraregions(a_r, b_r));
|
||||
ty::RegionTraitStore(r, a_m)
|
||||
}
|
||||
|
||||
_ if a.store == b.store => {
|
||||
a.store
|
||||
}
|
||||
|
||||
_ => {
|
||||
return Err(ty::terr_sigil_mismatch(expected_found(self, a.store, b.store)))
|
||||
}
|
||||
};
|
||||
let unsafety = try!(self.unsafeties(a.unsafety, b.unsafety));
|
||||
let onceness = try!(self.oncenesses(a.onceness, b.onceness));
|
||||
let bounds = try!(self.existential_bounds(&a.bounds, &b.bounds));
|
||||
let sig = try!(self.binders(&a.sig, &b.sig));
|
||||
let abi = try!(self.abi(a.abi, b.abi));
|
||||
Ok(ty::ClosureTy {
|
||||
unsafety: unsafety,
|
||||
onceness: onceness,
|
||||
store: store,
|
||||
bounds: bounds,
|
||||
sig: sig,
|
||||
abi: abi,
|
||||
})
|
||||
}
|
||||
|
||||
fn fn_sigs(&self, a: &ty::FnSig<'tcx>, b: &ty::FnSig<'tcx>) -> cres<'tcx, ty::FnSig<'tcx>> {
|
||||
if a.variadic != b.variadic {
|
||||
return Err(ty::terr_variadic_mismatch(expected_found(self, a.variadic, b.variadic)));
|
||||
|
@ -356,31 +323,6 @@ fn contraregions(&self, a: ty::Region, b: ty::Region)
|
|||
|
||||
fn regions(&self, a: ty::Region, b: ty::Region) -> cres<'tcx, ty::Region>;
|
||||
|
||||
fn trait_stores(&self,
|
||||
vk: ty::terr_vstore_kind,
|
||||
a: ty::TraitStore,
|
||||
b: ty::TraitStore)
|
||||
-> cres<'tcx, ty::TraitStore> {
|
||||
debug!("{}.trait_stores(a={:?}, b={:?})", self.tag(), a, b);
|
||||
|
||||
match (a, b) {
|
||||
(ty::RegionTraitStore(a_r, a_m),
|
||||
ty::RegionTraitStore(b_r, b_m)) if a_m == b_m => {
|
||||
self.contraregions(a_r, b_r).and_then(|r| {
|
||||
Ok(ty::RegionTraitStore(r, a_m))
|
||||
})
|
||||
}
|
||||
|
||||
_ if a == b => {
|
||||
Ok(a)
|
||||
}
|
||||
|
||||
_ => {
|
||||
Err(ty::terr_trait_stores_differ(vk, expected_found(self, a, b)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn trait_refs(&self,
|
||||
a: &ty::TraitRef<'tcx>,
|
||||
b: &ty::TraitRef<'tcx>)
|
||||
|
|
|
@ -371,12 +371,11 @@ fn report_type_error(&self, trace: TypeTrace<'tcx>, terr: &ty::type_err<'tcx>) {
|
|||
infer::EquatePredicate(_) => "equality predicate not satisfied",
|
||||
};
|
||||
|
||||
self.tcx.sess.span_err(
|
||||
trace.origin.span(),
|
||||
&format!("{}: {} ({})",
|
||||
span_err!(self.tcx.sess, trace.origin.span(), E0308,
|
||||
"{}: {} ({})",
|
||||
message_root_str,
|
||||
expected_found_str,
|
||||
ty::type_err_to_str(self.tcx, terr))[]);
|
||||
ty::type_err_to_str(self.tcx, terr));
|
||||
|
||||
match trace.origin {
|
||||
infer::MatchExpressionArm(_, arm_span) =>
|
||||
|
@ -443,9 +442,8 @@ fn report_generic_bound_failure(&self,
|
|||
match sub {
|
||||
ty::ReFree(ty::FreeRegion {bound_region: ty::BrNamed(..), ..}) => {
|
||||
// Does the required lifetime have a nice name we can print?
|
||||
self.tcx.sess.span_err(
|
||||
origin.span(),
|
||||
&format!("{} may not live long enough", labeled_user_string)[]);
|
||||
span_err!(self.tcx.sess, origin.span(), E0309,
|
||||
"{} may not live long enough", labeled_user_string);
|
||||
self.tcx.sess.span_help(
|
||||
origin.span(),
|
||||
&format!(
|
||||
|
@ -456,9 +454,8 @@ fn report_generic_bound_failure(&self,
|
|||
|
||||
ty::ReStatic => {
|
||||
// Does the required lifetime have a nice name we can print?
|
||||
self.tcx.sess.span_err(
|
||||
origin.span(),
|
||||
&format!("{} may not live long enough", labeled_user_string)[]);
|
||||
span_err!(self.tcx.sess, origin.span(), E0310,
|
||||
"{} may not live long enough", labeled_user_string);
|
||||
self.tcx.sess.span_help(
|
||||
origin.span(),
|
||||
&format!(
|
||||
|
@ -468,11 +465,9 @@ fn report_generic_bound_failure(&self,
|
|||
|
||||
_ => {
|
||||
// If not, be less specific.
|
||||
self.tcx.sess.span_err(
|
||||
origin.span(),
|
||||
&format!(
|
||||
span_err!(self.tcx.sess, origin.span(), E0311,
|
||||
"{} may not live long enough",
|
||||
labeled_user_string)[]);
|
||||
labeled_user_string);
|
||||
self.tcx.sess.span_help(
|
||||
origin.span(),
|
||||
&format!(
|
||||
|
@ -499,8 +494,7 @@ fn report_concrete_failure(&self,
|
|||
self.report_and_explain_type_error(trace, &terr);
|
||||
}
|
||||
infer::Reborrow(span) => {
|
||||
self.tcx.sess.span_err(
|
||||
span,
|
||||
span_err!(self.tcx.sess, span, E0312,
|
||||
"lifetime of reference outlines \
|
||||
lifetime of borrowed content...");
|
||||
note_and_explain_region(
|
||||
|
@ -515,14 +509,13 @@ fn report_concrete_failure(&self,
|
|||
"");
|
||||
}
|
||||
infer::ReborrowUpvar(span, ref upvar_id) => {
|
||||
self.tcx.sess.span_err(
|
||||
span,
|
||||
&format!("lifetime of borrowed pointer outlives \
|
||||
span_err!(self.tcx.sess, span, E0313,
|
||||
"lifetime of borrowed pointer outlives \
|
||||
lifetime of captured variable `{}`...",
|
||||
ty::local_var_name_str(self.tcx,
|
||||
upvar_id.var_id)
|
||||
.get()
|
||||
.to_string())[]);
|
||||
.to_string());
|
||||
note_and_explain_region(
|
||||
self.tcx,
|
||||
"...the borrowed pointer is valid for ",
|
||||
|
@ -539,8 +532,7 @@ fn report_concrete_failure(&self,
|
|||
"");
|
||||
}
|
||||
infer::InfStackClosure(span) => {
|
||||
self.tcx.sess.span_err(
|
||||
span,
|
||||
span_err!(self.tcx.sess, span, E0314,
|
||||
"closure outlives stack frame");
|
||||
note_and_explain_region(
|
||||
self.tcx,
|
||||
|
@ -554,8 +546,7 @@ fn report_concrete_failure(&self,
|
|||
"");
|
||||
}
|
||||
infer::InvokeClosure(span) => {
|
||||
self.tcx.sess.span_err(
|
||||
span,
|
||||
span_err!(self.tcx.sess, span, E0315,
|
||||
"cannot invoke closure outside of its lifetime");
|
||||
note_and_explain_region(
|
||||
self.tcx,
|
||||
|
|
|
@ -609,8 +609,7 @@ pub fn combine_vars<F>(&self,
|
|||
pub fn vars_created_since_snapshot(&self, mark: &RegionSnapshot)
|
||||
-> Vec<RegionVid>
|
||||
{
|
||||
self.undo_log.borrow()
|
||||
.slice_from(mark.length)
|
||||
self.undo_log.borrow()[mark.length..]
|
||||
.iter()
|
||||
.filter_map(|&elt| match elt {
|
||||
AddVar(vid) => Some(vid),
|
||||
|
@ -637,7 +636,7 @@ pub fn tainted(&self, mark: &RegionSnapshot, r0: Region) -> Vec<Region> {
|
|||
debug!("result_index={}, r={:?}", result_index, r);
|
||||
|
||||
for undo_entry in
|
||||
self.undo_log.borrow().slice_from(mark.length).iter()
|
||||
self.undo_log.borrow()[mark.length..].iter()
|
||||
{
|
||||
match undo_entry {
|
||||
&AddConstraint(ConstrainVarSubVar(a, b)) => {
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
use middle::infer::{uok, ures};
|
||||
use middle::infer::InferCtxt;
|
||||
use std::cell::RefCell;
|
||||
use std::fmt::Show;
|
||||
use std::fmt::Debug;
|
||||
use syntax::ast;
|
||||
use util::ppaux::Repr;
|
||||
use util::snapshot_vec as sv;
|
||||
|
@ -32,7 +32,7 @@
|
|||
/// (possibly not yet known) sort of integer.
|
||||
///
|
||||
/// Implementations of this trait are at the end of this file.
|
||||
pub trait UnifyKey<'tcx, V> : Clone + Show + PartialEq + Repr<'tcx> {
|
||||
pub trait UnifyKey<'tcx, V> : Clone + Debug + PartialEq + Repr<'tcx> {
|
||||
fn index(&self) -> uint;
|
||||
|
||||
fn from_index(u: uint) -> Self;
|
||||
|
|
|
@ -320,9 +320,7 @@ pub fn collect_language_items(krate: &ast::Crate,
|
|||
ContravariantLifetimeItem, "contravariant_lifetime", contravariant_lifetime;
|
||||
InvariantLifetimeItem, "invariant_lifetime", invariant_lifetime;
|
||||
|
||||
NoSendItem, "no_send_bound", no_send_bound;
|
||||
NoCopyItem, "no_copy_bound", no_copy_bound;
|
||||
NoSyncItem, "no_sync_bound", no_sync_bound;
|
||||
ManagedItem, "managed_bound", managed_bound;
|
||||
|
||||
NonZeroItem, "non_zero", non_zero;
|
||||
|
|
|
@ -198,13 +198,13 @@ pub fn check_crate(tcx: &ty::ctxt) {
|
|||
tcx.sess.abort_if_errors();
|
||||
}
|
||||
|
||||
impl fmt::Show for LiveNode {
|
||||
impl fmt::Debug for LiveNode {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "ln({})", self.get())
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Show for Variable {
|
||||
impl fmt::Debug for Variable {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "v({})", self.get())
|
||||
}
|
||||
|
@ -1557,8 +1557,7 @@ fn check_ret(&self,
|
|||
},
|
||||
_ => false
|
||||
};
|
||||
self.ir.tcx.sess.span_err(
|
||||
sp, "not all control paths return a value");
|
||||
span_err!(self.ir.tcx.sess, sp, E0269, "not all control paths return a value");
|
||||
if ends_with_stmt {
|
||||
let last_stmt = body.stmts.first().unwrap();
|
||||
let original_span = original_sp(self.ir.tcx.sess.codemap(),
|
||||
|
@ -1575,7 +1574,7 @@ fn check_ret(&self,
|
|||
}
|
||||
ty::FnDiverging
|
||||
if self.live_on_entry(entry_ln, self.s.clean_exit_var).is_some() => {
|
||||
self.ir.tcx.sess.span_err(sp,
|
||||
span_err!(self.ir.tcx.sess, sp, E0270,
|
||||
"computation may converge in a function marked as diverging");
|
||||
}
|
||||
|
||||
|
|
|
@ -297,6 +297,7 @@ fn propagate_node(&mut self, node: &ast_map::Node,
|
|||
// These are normal, nothing reachable about these
|
||||
// inherently and their children are already in the
|
||||
// worklist, as determined by the privacy pass
|
||||
ast::ItemExternCrate(_) | ast::ItemUse(_) |
|
||||
ast::ItemTy(..) | ast::ItemStatic(_, _, _) |
|
||||
ast::ItemMod(..) | ast::ItemForeignMod(..) |
|
||||
ast::ItemImpl(..) | ast::ItemTrait(..) |
|
||||
|
|
|
@ -33,7 +33,7 @@ pub fn update_recursion_limit(sess: &Session, krate: &ast::Crate) {
|
|||
}
|
||||
}
|
||||
|
||||
sess.span_err(attr.span, "malformed recursion limit attribute, \
|
||||
span_err!(sess, attr.span, E0296, "malformed recursion limit attribute, \
|
||||
expected #![recursion_limit=\"N\"]");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,9 +22,6 @@
|
|||
use util::common::can_reach;
|
||||
|
||||
use std::cell::RefCell;
|
||||
// NOTE(stage0) remove import after a snapshot
|
||||
#[cfg(stage0)]
|
||||
use std::hash::{Hash};
|
||||
use syntax::codemap::Span;
|
||||
use syntax::{ast, visit};
|
||||
use syntax::ast::{Block, Item, FnDecl, NodeId, Arm, Pat, Stmt, Expr, Local};
|
||||
|
|
|
@ -94,6 +94,8 @@ fn visit_item(&mut self, item: &ast::Item) {
|
|||
// Fn lifetimes get added in visit_fn below:
|
||||
visit::walk_item(this, item);
|
||||
}
|
||||
ast::ItemExternCrate(_) |
|
||||
ast::ItemUse(_) |
|
||||
ast::ItemMod(..) |
|
||||
ast::ItemMac(..) |
|
||||
ast::ItemForeignMod(..) |
|
||||
|
@ -396,10 +398,9 @@ fn resolve_free_lifetime_ref(&mut self,
|
|||
}
|
||||
|
||||
fn unresolved_lifetime_ref(&self, lifetime_ref: &ast::Lifetime) {
|
||||
self.sess.span_err(
|
||||
lifetime_ref.span,
|
||||
&format!("use of undeclared lifetime name `{}`",
|
||||
token::get_name(lifetime_ref.name))[]);
|
||||
span_err!(self.sess, lifetime_ref.span, E0261,
|
||||
"use of undeclared lifetime name `{}`",
|
||||
token::get_name(lifetime_ref.name));
|
||||
}
|
||||
|
||||
fn check_lifetime_defs(&mut self, old_scope: Scope, lifetimes: &Vec<ast::LifetimeDef>) {
|
||||
|
@ -409,11 +410,9 @@ fn check_lifetime_defs(&mut self, old_scope: Scope, lifetimes: &Vec<ast::Lifetim
|
|||
let special_idents = [special_idents::static_lifetime];
|
||||
for lifetime in lifetimes.iter() {
|
||||
if special_idents.iter().any(|&i| i.name == lifetime.lifetime.name) {
|
||||
self.sess.span_err(
|
||||
lifetime.lifetime.span,
|
||||
&format!("illegal lifetime parameter name: `{}`",
|
||||
token::get_name(lifetime.lifetime.name))
|
||||
[]);
|
||||
span_err!(self.sess, lifetime.lifetime.span, E0262,
|
||||
"illegal lifetime parameter name: `{}`",
|
||||
token::get_name(lifetime.lifetime.name));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -422,12 +421,10 @@ fn check_lifetime_defs(&mut self, old_scope: Scope, lifetimes: &Vec<ast::Lifetim
|
|||
let lifetime_j = &lifetimes[j];
|
||||
|
||||
if lifetime_i.lifetime.name == lifetime_j.lifetime.name {
|
||||
self.sess.span_err(
|
||||
lifetime_j.lifetime.span,
|
||||
&format!("lifetime name `{}` declared twice in \
|
||||
span_err!(self.sess, lifetime_j.lifetime.span, E0263,
|
||||
"lifetime name `{}` declared twice in \
|
||||
the same scope",
|
||||
token::get_name(lifetime_j.lifetime.name))
|
||||
[]);
|
||||
token::get_name(lifetime_j.lifetime.name));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -462,11 +459,11 @@ fn check_lifetime_def_for_shadowing(&self,
|
|||
format!("lifetime name `{}` shadows another \
|
||||
lifetime name that is already in scope",
|
||||
token::get_name(lifetime.name)).as_slice());
|
||||
self.sess.span_help(
|
||||
self.sess.span_note(
|
||||
lifetime_def.span,
|
||||
format!("shadowed lifetime `{}` declared here",
|
||||
token::get_name(lifetime.name)).as_slice());
|
||||
self.sess.span_help(
|
||||
self.sess.span_note(
|
||||
lifetime.span,
|
||||
"shadowed lifetimes are deprecated \
|
||||
and will become a hard error before 1.0");
|
||||
|
@ -602,7 +599,7 @@ fn shuffle(early_bound: &mut Vec<ast::Name>,
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Show for ScopeChain<'a> {
|
||||
impl<'a> fmt::Debug for ScopeChain<'a> {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
EarlyScope(space, defs, _) => write!(fmt, "EarlyScope({:?}, {:?})", space, defs),
|
||||
|
|
|
@ -238,7 +238,7 @@ pub struct SeparateVecsPerParamSpace<T> {
|
|||
pub fns: Vec<T>,
|
||||
}
|
||||
|
||||
impl<T:fmt::Show> fmt::Show for VecPerParamSpace<T> {
|
||||
impl<T: fmt::Debug> fmt::Debug for VecPerParamSpace<T> {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
try!(write!(fmt, "VecPerParamSpace {{"));
|
||||
for space in ParamSpace::all().iter() {
|
||||
|
@ -373,12 +373,12 @@ pub fn is_empty_in(&self, space: ParamSpace) -> bool {
|
|||
|
||||
pub fn get_slice<'a>(&'a self, space: ParamSpace) -> &'a [T] {
|
||||
let (start, limit) = self.limits(space);
|
||||
self.content.slice(start, limit)
|
||||
&self.content[start.. limit]
|
||||
}
|
||||
|
||||
pub fn get_mut_slice<'a>(&'a mut self, space: ParamSpace) -> &'a mut [T] {
|
||||
let (start, limit) = self.limits(space);
|
||||
self.content.slice_mut(start, limit)
|
||||
&mut self.content[start.. limit]
|
||||
}
|
||||
|
||||
pub fn opt_get<'a>(&'a self,
|
||||
|
|
|
@ -55,12 +55,10 @@ pub fn report_projection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
|
|||
let predicate =
|
||||
infcx.resolve_type_vars_if_possible(&obligation.predicate);
|
||||
if !predicate.references_error() {
|
||||
infcx.tcx.sess.span_err(
|
||||
obligation.cause.span,
|
||||
format!(
|
||||
span_err!(infcx.tcx.sess, obligation.cause.span, E0271,
|
||||
"type mismatch resolving `{}`: {}",
|
||||
predicate.user_string(infcx.tcx),
|
||||
ty::type_err_to_str(infcx.tcx, &error.err)).as_slice());
|
||||
ty::type_err_to_str(infcx.tcx, &error.err));
|
||||
note_obligation_cause(infcx, obligation);
|
||||
}
|
||||
}
|
||||
|
@ -97,28 +95,25 @@ fn report_on_unimplemented<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
|
|||
Position::ArgumentNamed(s) => match generic_map.get(s) {
|
||||
Some(val) => Some(val.as_slice()),
|
||||
None => {
|
||||
infcx.tcx.sess
|
||||
.span_err(err_sp,
|
||||
format!("the #[rustc_on_unimplemented] \
|
||||
span_err!(infcx.tcx.sess, err_sp, E0272,
|
||||
"the #[rustc_on_unimplemented] \
|
||||
attribute on \
|
||||
trait definition for {} refers to \
|
||||
non-existent type parameter {}",
|
||||
trait_str, s)
|
||||
.as_slice());
|
||||
trait_str, s);
|
||||
errored = true;
|
||||
None
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
infcx.tcx.sess
|
||||
.span_err(err_sp,
|
||||
format!("the #[rustc_on_unimplemented] \
|
||||
span_err!(infcx.tcx.sess, err_sp, E0273,
|
||||
"the #[rustc_on_unimplemented] \
|
||||
attribute on \
|
||||
trait definition for {} must have named \
|
||||
format arguments, \
|
||||
eg `#[rustc_on_unimplemented = \
|
||||
\"foo {{T}}\"]`",
|
||||
trait_str).as_slice());
|
||||
trait_str);
|
||||
errored = true;
|
||||
None
|
||||
}
|
||||
|
@ -130,11 +125,11 @@ trait definition for {} must have named \
|
|||
report = Some(err);
|
||||
}
|
||||
} else {
|
||||
infcx.tcx.sess.span_err(err_sp,
|
||||
format!("the #[rustc_on_unimplemented] attribute on \
|
||||
span_err!(infcx.tcx.sess, err_sp, E0274,
|
||||
"the #[rustc_on_unimplemented] attribute on \
|
||||
trait definition for {} must have a value, \
|
||||
eg `#[rustc_on_unimplemented = \"foo\"]`",
|
||||
trait_str).as_slice());
|
||||
trait_str);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -151,11 +146,9 @@ pub fn report_selection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
|
|||
// We could track the stack here more precisely if we wanted, I imagine.
|
||||
let predicate =
|
||||
infcx.resolve_type_vars_if_possible(&obligation.predicate);
|
||||
infcx.tcx.sess.span_err(
|
||||
obligation.cause.span,
|
||||
format!(
|
||||
span_err!(infcx.tcx.sess, obligation.cause.span, E0275,
|
||||
"overflow evaluating the requirement `{}`",
|
||||
predicate.user_string(infcx.tcx)).as_slice());
|
||||
predicate.user_string(infcx.tcx));
|
||||
|
||||
suggest_new_overflow_limit(infcx.tcx, obligation.cause.span);
|
||||
|
||||
|
@ -165,12 +158,10 @@ pub fn report_selection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
|
|||
SelectionError::Unimplemented => {
|
||||
match &obligation.cause.code {
|
||||
&ObligationCauseCode::CompareImplMethodObligation => {
|
||||
infcx.tcx.sess.span_err(
|
||||
obligation.cause.span,
|
||||
format!(
|
||||
span_err!(infcx.tcx.sess, obligation.cause.span, E0276,
|
||||
"the requirement `{}` appears on the impl \
|
||||
method but not on the corresponding trait method",
|
||||
obligation.predicate.user_string(infcx.tcx)).as_slice());
|
||||
obligation.predicate.user_string(infcx.tcx));;
|
||||
}
|
||||
_ => {
|
||||
match obligation.predicate {
|
||||
|
@ -180,12 +171,10 @@ pub fn report_selection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
|
|||
|
||||
if !trait_predicate.references_error() {
|
||||
let trait_ref = trait_predicate.to_poly_trait_ref();
|
||||
infcx.tcx.sess.span_err(
|
||||
obligation.cause.span,
|
||||
format!(
|
||||
span_err!(infcx.tcx.sess, obligation.cause.span, E0277,
|
||||
"the trait `{}` is not implemented for the type `{}`",
|
||||
trait_ref.user_string(infcx.tcx),
|
||||
trait_ref.self_ty().user_string(infcx.tcx)).as_slice());
|
||||
trait_ref.self_ty().user_string(infcx.tcx));
|
||||
// Check if it has a custom "#[rustc_on_unimplemented]"
|
||||
// error message, report with that message if it does
|
||||
let custom_note = report_on_unimplemented(infcx, &*trait_ref.0,
|
||||
|
@ -200,35 +189,29 @@ pub fn report_selection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
|
|||
ty::Predicate::Equate(ref predicate) => {
|
||||
let predicate = infcx.resolve_type_vars_if_possible(predicate);
|
||||
let err = infcx.equality_predicate(obligation.cause.span,
|
||||
&predicate).unwrap_err();
|
||||
infcx.tcx.sess.span_err(
|
||||
obligation.cause.span,
|
||||
format!(
|
||||
&predicate).err().unwrap();
|
||||
span_err!(infcx.tcx.sess, obligation.cause.span, E0278,
|
||||
"the requirement `{}` is not satisfied (`{}`)",
|
||||
predicate.user_string(infcx.tcx),
|
||||
ty::type_err_to_str(infcx.tcx, &err)).as_slice());
|
||||
ty::type_err_to_str(infcx.tcx, &err));
|
||||
}
|
||||
|
||||
ty::Predicate::RegionOutlives(ref predicate) => {
|
||||
let predicate = infcx.resolve_type_vars_if_possible(predicate);
|
||||
let err = infcx.region_outlives_predicate(obligation.cause.span,
|
||||
&predicate).unwrap_err();
|
||||
infcx.tcx.sess.span_err(
|
||||
obligation.cause.span,
|
||||
format!(
|
||||
&predicate).err().unwrap();
|
||||
span_err!(infcx.tcx.sess, obligation.cause.span, E0279,
|
||||
"the requirement `{}` is not satisfied (`{}`)",
|
||||
predicate.user_string(infcx.tcx),
|
||||
ty::type_err_to_str(infcx.tcx, &err)).as_slice());
|
||||
ty::type_err_to_str(infcx.tcx, &err));
|
||||
}
|
||||
|
||||
ty::Predicate::Projection(..) | ty::Predicate::TypeOutlives(..) => {
|
||||
let predicate =
|
||||
infcx.resolve_type_vars_if_possible(&obligation.predicate);
|
||||
infcx.tcx.sess.span_err(
|
||||
obligation.cause.span,
|
||||
format!(
|
||||
span_err!(infcx.tcx.sess, obligation.cause.span, E0280,
|
||||
"the requirement `{}` is not satisfied",
|
||||
predicate.user_string(infcx.tcx)).as_slice());
|
||||
predicate.user_string(infcx.tcx));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -239,15 +222,13 @@ pub fn report_selection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
|
|||
let expected_trait_ref = infcx.resolve_type_vars_if_possible(&*expected_trait_ref);
|
||||
let actual_trait_ref = infcx.resolve_type_vars_if_possible(&*actual_trait_ref);
|
||||
if !ty::type_is_error(actual_trait_ref.self_ty()) {
|
||||
infcx.tcx.sess.span_err(
|
||||
obligation.cause.span,
|
||||
format!(
|
||||
span_err!(infcx.tcx.sess, obligation.cause.span, E0281,
|
||||
"type mismatch: the type `{}` implements the trait `{}`, \
|
||||
but the trait `{}` is required ({})",
|
||||
expected_trait_ref.self_ty().user_string(infcx.tcx),
|
||||
expected_trait_ref.user_string(infcx.tcx),
|
||||
actual_trait_ref.user_string(infcx.tcx),
|
||||
ty::type_err_to_str(infcx.tcx, e)).as_slice());
|
||||
ty::type_err_to_str(infcx.tcx, e));
|
||||
note_obligation_cause(infcx, obligation);
|
||||
}
|
||||
}
|
||||
|
@ -293,18 +274,14 @@ pub fn maybe_report_ambiguity<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
|
|||
infcx.tcx.lang_items.sized_trait()
|
||||
.map_or(false, |sized_id| sized_id == trait_ref.def_id())
|
||||
{
|
||||
infcx.tcx.sess.span_err(
|
||||
obligation.cause.span,
|
||||
format!(
|
||||
span_err!(infcx.tcx.sess, obligation.cause.span, E0282,
|
||||
"unable to infer enough type information about `{}`; \
|
||||
type annotations required",
|
||||
self_ty.user_string(infcx.tcx)).as_slice());
|
||||
self_ty.user_string(infcx.tcx));
|
||||
} else {
|
||||
infcx.tcx.sess.span_err(
|
||||
obligation.cause.span,
|
||||
format!(
|
||||
span_err!(infcx.tcx.sess, obligation.cause.span, E0283,
|
||||
"type annotations required: cannot resolve `{}`",
|
||||
predicate.user_string(infcx.tcx)).as_slice());
|
||||
predicate.user_string(infcx.tcx));;
|
||||
note_obligation_cause(infcx, obligation);
|
||||
}
|
||||
}
|
||||
|
@ -323,11 +300,9 @@ pub fn maybe_report_ambiguity<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
|
|||
|
||||
_ => {
|
||||
if !infcx.tcx.sess.has_errors() {
|
||||
infcx.tcx.sess.span_err(
|
||||
obligation.cause.span,
|
||||
format!(
|
||||
span_err!(infcx.tcx.sess, obligation.cause.span, E0284,
|
||||
"type annotations required: cannot resolve `{}`",
|
||||
predicate.user_string(infcx.tcx)).as_slice());
|
||||
predicate.user_string(infcx.tcx));;
|
||||
note_obligation_cause(infcx, obligation);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,6 +84,7 @@ pub struct FulfillmentContext<'tcx> {
|
|||
region_obligations: NodeMap<Vec<RegionObligation<'tcx>>>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct RegionObligation<'tcx> {
|
||||
pub sub_region: ty::Region,
|
||||
pub sup_type: Ty<'tcx>,
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue