mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +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 libcpp 1 "build with llvm with libc++ instead of libstdc++ when using clang"
|
||||||
opt llvm-assertions 1 "build LLVM with assertions"
|
opt llvm-assertions 1 "build LLVM with assertions"
|
||||||
opt debug 1 "build with extra debug fun"
|
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 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 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"
|
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
|
JEMALLOC_ARGS_$(1) := --disable-tls
|
||||||
else ifeq ($(OSTYPE_$(1)), linux-androideabi)
|
else ifeq ($(OSTYPE_$(1)), linux-androideabi)
|
||||||
JEMALLOC_ARGS_$(1) := --disable-tls
|
JEMALLOC_ARGS_$(1) := --disable-tls
|
||||||
|
else ifeq ($(OSTYPE_$(1)), linux-android)
|
||||||
|
JEMALLOC_ARGS_$(1) := --disable-tls
|
||||||
endif
|
endif
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
|
@ -300,6 +300,7 @@ tidy:
|
|||||||
| grep '^$(S)src/libbacktrace' -v \
|
| grep '^$(S)src/libbacktrace' -v \
|
||||||
| grep '^$(S)src/rust-installer' -v \
|
| grep '^$(S)src/rust-installer' -v \
|
||||||
| xargs $(CFG_PYTHON) $(S)src/etc/check-binaries.py
|
| xargs $(CFG_PYTHON) $(S)src/etc/check-binaries.py
|
||||||
|
$(Q) $(CFG_PYTHON) $(S)src/etc/errorck.py $(S)src/
|
||||||
|
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
@ -13,7 +13,7 @@ use std::fmt;
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
#[derive(Clone, PartialEq)]
|
#[derive(Clone, PartialEq, Debug)]
|
||||||
pub enum Mode {
|
pub enum Mode {
|
||||||
CompileFail,
|
CompileFail,
|
||||||
RunFail,
|
RunFail,
|
||||||
@ -43,9 +43,9 @@ impl FromStr for Mode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::String for Mode {
|
impl fmt::Display for Mode {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
fmt::String::fmt(match *self {
|
fmt::Display::fmt(match *self {
|
||||||
CompileFail => "compile-fail",
|
CompileFail => "compile-fail",
|
||||||
RunFail => "run-fail",
|
RunFail => "run-fail",
|
||||||
RunPass => "run-pass",
|
RunPass => "run-pass",
|
||||||
@ -58,12 +58,6 @@ impl fmt::String for Mode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Show for Mode {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
fmt::String::fmt(self, f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
// The library paths required for running the compiler
|
// 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
|
// Write out a parseable log of tests that were run
|
||||||
pub logfile: Option<Path>,
|
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,
|
// A command line to prefix program execution with,
|
||||||
// for running under valgrind
|
// for running under valgrind
|
||||||
pub runtool: Option<String>,
|
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"),
|
optopt("", "target-rustcflags", "flags to pass to rustc for target", "FLAGS"),
|
||||||
optflag("", "verbose", "run tests verbosely, showing all output"),
|
optflag("", "verbose", "run tests verbosely, showing all output"),
|
||||||
optopt("", "logfile", "file to log test execution to", "FILE"),
|
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"),
|
optflag("", "jit", "run tests under the JIT"),
|
||||||
optopt("", "target", "the target to build for", "TARGET"),
|
optopt("", "target", "the target to build for", "TARGET"),
|
||||||
optopt("", "host", "the host to build for", "HOST"),
|
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-path", "path to the android debugger", "PATH"),
|
||||||
optopt("", "adb-test-dir", "path to tests for 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("", "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"));
|
optflag("h", "help", "show this message"));
|
||||||
|
|
||||||
assert!(!args.is_empty());
|
assert!(!args.is_empty());
|
||||||
@ -152,12 +147,6 @@ pub fn parse_config(args: Vec<String> ) -> Config {
|
|||||||
filter: filter,
|
filter: filter,
|
||||||
cfail_regex: Regex::new(errors::EXPECTED_PATTERN).unwrap(),
|
cfail_regex: Regex::new(errors::EXPECTED_PATTERN).unwrap(),
|
||||||
logfile: matches.opt_str("logfile").map(|s| Path::new(s)),
|
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"),
|
runtool: matches.opt_str("runtool"),
|
||||||
host_rustcflags: matches.opt_str("host-rustcflags"),
|
host_rustcflags: matches.opt_str("host-rustcflags"),
|
||||||
target_rustcflags: matches.opt_str("target-rustcflags"),
|
target_rustcflags: matches.opt_str("target-rustcflags"),
|
||||||
@ -176,7 +165,6 @@ pub fn parse_config(args: Vec<String> ) -> Config {
|
|||||||
opt_str2(matches.opt_str("adb-test-dir")).as_slice() &&
|
opt_str2(matches.opt_str("adb-test-dir")).as_slice() &&
|
||||||
!opt_str2(matches.opt_str("adb-test-dir")).is_empty(),
|
!opt_str2(matches.opt_str("adb-test-dir")).is_empty(),
|
||||||
lldb_python_dir: matches.opt_str("lldb-python-dir"),
|
lldb_python_dir: matches.opt_str("lldb-python-dir"),
|
||||||
test_shard: test::opt_shard(matches.opt_str("test-shard")),
|
|
||||||
verbose: matches.opt_present("verbose"),
|
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_test_dir: {:?}", config.adb_test_dir));
|
||||||
logv(c, format!("adb_device_status: {}",
|
logv(c, format!("adb_device_status: {}",
|
||||||
config.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!("verbose: {}", config.verbose));
|
||||||
logv(c, format!("\n"));
|
logv(c, format!("\n"));
|
||||||
}
|
}
|
||||||
@ -284,15 +268,8 @@ pub fn test_opts(config: &Config) -> test::TestOpts {
|
|||||||
logfile: config.logfile.clone(),
|
logfile: config.logfile.clone(),
|
||||||
run_tests: true,
|
run_tests: true,
|
||||||
run_benchmarks: 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,
|
nocapture: false,
|
||||||
color: test::AutoColor,
|
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);
|
let keycolon = format!("{}:", directive);
|
||||||
match line.find_str(keycolon.as_slice()) {
|
match line.find_str(keycolon.as_slice()) {
|
||||||
Some(colon) => {
|
Some(colon) => {
|
||||||
let value = line.slice(colon + keycolon.len(),
|
let value = line[(colon + keycolon.len()) .. line.len()].to_string();
|
||||||
line.len()).to_string();
|
|
||||||
debug!("{}: {}", directive, value);
|
debug!("{}: {}", directive, value);
|
||||||
Some(value)
|
Some(value)
|
||||||
}
|
}
|
||||||
|
@ -294,6 +294,7 @@ fn run_pretty_test(config: &Config, props: &TestProps, testfile: &Path) {
|
|||||||
let aux_dir = aux_output_dir_name(config, testfile);
|
let aux_dir = aux_output_dir_name(config, testfile);
|
||||||
// FIXME (#9639): This needs to handle non-utf8 paths
|
// FIXME (#9639): This needs to handle non-utf8 paths
|
||||||
let mut args = vec!("-".to_string(),
|
let mut args = vec!("-".to_string(),
|
||||||
|
"-Zunstable-options".to_string(),
|
||||||
"--pretty".to_string(),
|
"--pretty".to_string(),
|
||||||
pretty_type,
|
pretty_type,
|
||||||
format!("--target={}", config.target),
|
format!("--target={}", config.target),
|
||||||
@ -340,7 +341,7 @@ actual:\n\
|
|||||||
};
|
};
|
||||||
// FIXME (#9639): This needs to handle non-utf8 paths
|
// FIXME (#9639): This needs to handle non-utf8 paths
|
||||||
let mut args = vec!("-".to_string(),
|
let mut args = vec!("-".to_string(),
|
||||||
"--no-trans".to_string(),
|
"-Zno-trans".to_string(),
|
||||||
"--crate-type=lib".to_string(),
|
"--crate-type=lib".to_string(),
|
||||||
format!("--target={}", target),
|
format!("--target={}", target),
|
||||||
"-L".to_string(),
|
"-L".to_string(),
|
||||||
@ -547,7 +548,7 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
|
|||||||
|
|
||||||
// Add line breakpoints
|
// Add line breakpoints
|
||||||
for line in breakpoint_lines.iter() {
|
for line in breakpoint_lines.iter() {
|
||||||
script_str.push_str(&format!("break '{:?}':{}\n",
|
script_str.push_str(&format!("break '{}':{}\n",
|
||||||
testfile.filename_display(),
|
testfile.filename_display(),
|
||||||
*line)[]);
|
*line)[]);
|
||||||
}
|
}
|
||||||
@ -750,7 +751,7 @@ fn run_debuginfo_lldb_test(config: &Config, props: &TestProps, testfile: &Path)
|
|||||||
status: status,
|
status: status,
|
||||||
stdout: out,
|
stdout: out,
|
||||||
stderr: err,
|
stderr: err,
|
||||||
cmdline: format!("{}", cmd)
|
cmdline: format!("{:?}", cmd)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -862,7 +863,7 @@ fn check_debugger_output(debugger_run_result: &ProcRes, check_lines: &[String])
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Some(i) => {
|
Some(i) => {
|
||||||
rest = rest.slice_from(i + frag.len());
|
rest = &rest[(i + frag.len())..];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
first = false;
|
first = false;
|
||||||
@ -953,7 +954,7 @@ fn check_expected_errors(expected_errors: Vec<errors::ExpectedError> ,
|
|||||||
}
|
}
|
||||||
|
|
||||||
let prefixes = expected_errors.iter().map(|ee| {
|
let prefixes = expected_errors.iter().map(|ee| {
|
||||||
format!("{:?}:{}:", testfile.display(), ee.line)
|
format!("{}:{}:", testfile.display(), ee.line)
|
||||||
}).collect::<Vec<String> >();
|
}).collect::<Vec<String> >();
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
@ -1045,7 +1046,7 @@ fn scan_until_char(haystack: &str, needle: char, idx: &mut uint) -> bool {
|
|||||||
if *idx >= haystack.len() {
|
if *idx >= haystack.len() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let opt = haystack.slice_from(*idx).find(needle);
|
let opt = haystack[(*idx)..].find(needle);
|
||||||
if opt.is_none() {
|
if opt.is_none() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -480,14 +480,12 @@ use std::sync::{Arc,Mutex};
|
|||||||
fn main() {
|
fn main() {
|
||||||
let numbers = Arc::new(Mutex::new(vec![1is, 2, 3]));
|
let numbers = Arc::new(Mutex::new(vec![1is, 2, 3]));
|
||||||
|
|
||||||
for i in 0..3 {
|
for i in 0us..3 {
|
||||||
let number = numbers.clone();
|
let number = numbers.clone();
|
||||||
Thread::spawn(move || {
|
Thread::spawn(move || {
|
||||||
let mut array = number.lock().unwrap();
|
let mut array = number.lock().unwrap();
|
||||||
|
array[i] += 1;
|
||||||
(*array)[i] += 1;
|
println!("numbers[{}] is {}", i, array[i]);
|
||||||
|
|
||||||
println!("numbers[{}] is {}", i, (*array)[i]);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -803,8 +803,9 @@ Crates contain [items](#items), each of which may have some number of
|
|||||||
## Items
|
## Items
|
||||||
|
|
||||||
```{.ebnf .gram}
|
```{.ebnf .gram}
|
||||||
item : mod_item | fn_item | type_item | struct_item | enum_item
|
item : extern_crate_decl | use_decl | mod_item | fn_item | type_item
|
||||||
| static_item | trait_item | impl_item | extern_block ;
|
| 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
|
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:
|
There are several kinds of item:
|
||||||
|
|
||||||
|
* [`extern crate` declarations](#extern-crate-declarations)
|
||||||
|
* [`use` declarations](#use-declarations)
|
||||||
* [modules](#modules)
|
* [modules](#modules)
|
||||||
* [functions](#functions)
|
* [functions](#functions)
|
||||||
* [type definitions](#type-definitions)
|
* [type definitions](#type-definitions)
|
||||||
@ -854,13 +857,10 @@ no notion of type abstraction: there are no first-class "forall" types.
|
|||||||
|
|
||||||
```{.ebnf .gram}
|
```{.ebnf .gram}
|
||||||
mod_item : "mod" ident ( ';' | '{' mod '}' );
|
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
|
A module is a container for zero or more [items](#items).
|
||||||
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 item_ is a module, surrounded in braces, named, and prefixed with the
|
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
|
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
|
##### Extern crate declarations
|
||||||
|
|
||||||
```{.ebnf .gram}
|
```{.ebnf .gram}
|
||||||
@ -2377,10 +2364,6 @@ These types help drive the compiler's analysis
|
|||||||
: ___Needs filling in___
|
: ___Needs filling in___
|
||||||
* `no_copy_bound`
|
* `no_copy_bound`
|
||||||
: This type does not implement "copy", even if eligible.
|
: 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`
|
* `eh_personality`
|
||||||
: ___Needs filling in___
|
: ___Needs filling in___
|
||||||
* `exchange_free`
|
* `exchange_free`
|
||||||
@ -2891,13 +2874,12 @@ Point3d {y: 0, z: 10, .. base};
|
|||||||
### Block expressions
|
### Block expressions
|
||||||
|
|
||||||
```{.ebnf .gram}
|
```{.ebnf .gram}
|
||||||
block_expr : '{' [ view_item ] *
|
block_expr : '{' [ stmt ';' | item ] *
|
||||||
[ stmt ';' | item ] *
|
|
||||||
[ expr ] '}' ;
|
[ expr ] '}' ;
|
||||||
```
|
```
|
||||||
|
|
||||||
A _block expression_ is similar to a module in terms of the declarations that
|
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
|
items can bring new names into scopes and declared items are in scope for only
|
||||||
the block itself.
|
the block itself.
|
||||||
|
|
||||||
|
@ -257,7 +257,7 @@ fn goodbye() -> String {
|
|||||||
|
|
||||||
(This is "Sayōnara", if you're curious.)
|
(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.
|
another crate.
|
||||||
|
|
||||||
# Importing External Crates
|
# 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
|
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
|
`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:
|
iteration. This will only print the odd numbers:
|
||||||
|
|
||||||
```{rust}
|
```{rust}
|
||||||
for x in 0..10 {
|
for x in 0u32..10 {
|
||||||
if x % 2 == 0 { continue; }
|
if x % 2 == 0 { continue; }
|
||||||
|
|
||||||
println!("{}", x);
|
println!("{}", x);
|
||||||
|
@ -179,7 +179,7 @@ for init_val in 0 .. 3 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let result = rx.recv().unwrap() + rx.recv().unwrap() + rx.recv().unwrap();
|
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
|
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
|
// Wait on each port, accumulating the results
|
||||||
let result = rxs.iter().fold(0, |&:accum, rx| accum + rx.recv().unwrap() );
|
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
|
## Backgrounding computations: Futures
|
||||||
|
@ -707,7 +707,7 @@ Other features provided by lang items include:
|
|||||||
various kinds; lang items `send`, `sync` and `copy`.
|
various kinds; lang items `send`, `sync` and `copy`.
|
||||||
- the marker types and variance indicators found in
|
- the marker types and variance indicators found in
|
||||||
`std::marker`; lang items `covariant_type`,
|
`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
|
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`
|
`Box` then there is no need to define functions for `exchange_malloc`
|
||||||
|
@ -54,6 +54,11 @@
|
|||||||
:type 'integer
|
:type 'integer
|
||||||
:group 'rust-mode)
|
: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-paren-level () (nth 0 (syntax-ppss)))
|
||||||
(defun rust-in-str-or-cmnt () (nth 8 (syntax-ppss)))
|
(defun rust-in-str-or-cmnt () (nth 8 (syntax-ppss)))
|
||||||
(defun rust-rewind-past-str-cmnt () (goto-char (nth 8 (syntax-ppss))))
|
(defun rust-rewind-past-str-cmnt () (goto-char (nth 8 (syntax-ppss))))
|
||||||
@ -77,6 +82,15 @@
|
|||||||
(backward-word 1))
|
(backward-word 1))
|
||||||
(current-column))))
|
(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 ()
|
(defun rust-rewind-to-beginning-of-current-level-expr ()
|
||||||
(let ((current-level (rust-paren-level)))
|
(let ((current-level (rust-paren-level)))
|
||||||
(back-to-indentation)
|
(back-to-indentation)
|
||||||
@ -99,10 +113,13 @@
|
|||||||
;; the inside of it correctly relative to the outside.
|
;; the inside of it correctly relative to the outside.
|
||||||
(if (= 0 level)
|
(if (= 0 level)
|
||||||
0
|
0
|
||||||
|
(or
|
||||||
|
(when rust-indent-method-chain
|
||||||
|
(rust-align-to-method-chain))
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(backward-up-list)
|
(backward-up-list)
|
||||||
(rust-rewind-to-beginning-of-current-level-expr)
|
(rust-rewind-to-beginning-of-current-level-expr)
|
||||||
(+ (current-column) rust-indent-offset)))))
|
(+ (current-column) rust-indent-offset))))))
|
||||||
(cond
|
(cond
|
||||||
;; A function return type is indented to the corresponding function arguments
|
;; A function return type is indented to the corresponding function arguments
|
||||||
((looking-at "->")
|
((looking-at "->")
|
||||||
@ -114,6 +131,16 @@
|
|||||||
;; A closing brace is 1 level unindended
|
;; A closing brace is 1 level unindended
|
||||||
((looking-at "}") (- baseline rust-indent-offset))
|
((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
|
;; Doc comments in /** style with leading * indent to line up the *s
|
||||||
((and (nth 4 (syntax-ppss)) (looking-at "*"))
|
((and (nth 4 (syntax-ppss)) (looking-at "*"))
|
||||||
(+ 1 baseline))
|
(+ 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 \
|
|| mktemp -d -t 'rustup-tmp-install' 2>/dev/null \
|
||||||
|| create_tmp_dir)
|
|| create_tmp_dir)
|
||||||
|
|
||||||
# If we're saving nightlies and we didn't specify which one, grab todays.
|
# If we're saving nightlies and we didn't specify which one, grab the latest
|
||||||
# Otherwise we'll use the latest version.
|
# 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}" ];
|
if [ -n "${CFG_SAVE}" -a -z "${CFG_DATE}" ];
|
||||||
then
|
then
|
||||||
CFG_DATE=`date "+%Y-%m-%d"`
|
CFG_DATE=`TZ=Etc/UTC+9 date "+%Y-%m-%d"`
|
||||||
fi
|
fi
|
||||||
|
|
||||||
RUST_URL="https://static.rust-lang.org/dist"
|
RUST_URL="https://static.rust-lang.org/dist"
|
||||||
@ -453,16 +458,33 @@ then
|
|||||||
RUST_URL="${RUST_URL}/${CFG_DATE}"
|
RUST_URL="${RUST_URL}/${CFG_DATE}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
verify_hash() {
|
download_hash() {
|
||||||
remote_sha256="$1"
|
|
||||||
local_file="$2"
|
|
||||||
|
|
||||||
msg "Downloading ${remote_sha256}"
|
msg "Downloading ${remote_sha256}"
|
||||||
remote_sha256=`"${CFG_CURL}" -f "${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
|
if [ "$?" -ne 0 ]; then
|
||||||
rm -Rf "${CFG_TMP_DIR}"
|
rm -Rf "${CFG_TMP_DIR}"
|
||||||
err "Failed to download ${remote_url}"
|
err "Failed to download ${remote_url}"
|
||||||
fi
|
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"
|
msg "Verifying hash"
|
||||||
local_sha256=$(calculate_hash "${local_file}")
|
local_sha256=$(calculate_hash "${local_file}")
|
||||||
|
@ -72,7 +72,7 @@ use core::prelude::*;
|
|||||||
use core::atomic;
|
use core::atomic;
|
||||||
use core::atomic::Ordering::{Relaxed, Release, Acquire, SeqCst};
|
use core::atomic::Ordering::{Relaxed, Release, Acquire, SeqCst};
|
||||||
use core::borrow::BorrowFrom;
|
use core::borrow::BorrowFrom;
|
||||||
use core::fmt::{self, Show};
|
use core::fmt;
|
||||||
use core::cmp::{Ordering};
|
use core::cmp::{Ordering};
|
||||||
use core::default::Default;
|
use core::default::Default;
|
||||||
use core::mem::{min_align_of, size_of};
|
use core::mem::{min_align_of, size_of};
|
||||||
@ -578,16 +578,17 @@ impl<T: Ord> Ord for Arc<T> {
|
|||||||
#[stable]
|
#[stable]
|
||||||
impl<T: Eq> Eq for Arc<T> {}
|
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 {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "Arc({:?})", (**self))
|
fmt::Display::fmt(&**self, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable]
|
#[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 {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
fmt::String::fmt(&**self, f)
|
fmt::Debug::fmt(&**self, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -806,7 +807,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn show_arc() {
|
fn show_arc() {
|
||||||
let a = Arc::new(5u32);
|
let a = Arc::new(5u32);
|
||||||
assert!(format!("{:?}", a) == "Arc(5u32)")
|
assert_eq!(format!("{:?}", a), "5");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure deriving works with Arc<T>
|
// Make sure deriving works with Arc<T>
|
||||||
|
@ -16,16 +16,18 @@ use core::any::Any;
|
|||||||
use core::clone::Clone;
|
use core::clone::Clone;
|
||||||
use core::cmp::{PartialEq, PartialOrd, Eq, Ord, Ordering};
|
use core::cmp::{PartialEq, PartialOrd, Eq, Ord, Ordering};
|
||||||
use core::default::Default;
|
use core::default::Default;
|
||||||
|
use core::error::{Error, FromError};
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
use core::hash::{self, Hash};
|
use core::hash::{self, Hash};
|
||||||
|
use core::iter::Iterator;
|
||||||
use core::marker::Sized;
|
use core::marker::Sized;
|
||||||
use core::mem;
|
use core::mem;
|
||||||
|
use core::ops::{Deref, DerefMut};
|
||||||
use core::option::Option;
|
use core::option::Option;
|
||||||
use core::ptr::Unique;
|
use core::ptr::Unique;
|
||||||
use core::raw::TraitObject;
|
use core::raw::TraitObject;
|
||||||
use core::result::Result;
|
|
||||||
use core::result::Result::{Ok, Err};
|
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
|
/// A value that represents the global exchange heap. This is the default
|
||||||
/// place that the `box` keyword allocates into when no place is supplied.
|
/// place that the `box` keyword allocates into when no place is supplied.
|
||||||
@ -156,20 +158,22 @@ impl BoxAny for 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 {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "Box({:?})", &**self)
|
fmt::Display::fmt(&**self, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable]
|
#[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 {
|
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 {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
f.pad("Box<Any>")
|
f.pad("Box<Any>")
|
||||||
}
|
}
|
||||||
@ -187,56 +191,22 @@ impl<T: ?Sized> DerefMut for Box<T> {
|
|||||||
fn deref_mut(&mut self) -> &mut T { &mut **self }
|
fn deref_mut(&mut self) -> &mut T { &mut **self }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
// FIXME(#21363) remove `old_impl_check` when bug is fixed
|
||||||
mod test {
|
#[old_impl_check]
|
||||||
#[test]
|
impl<'a, T> Iterator for Box<Iterator<Item=T> + 'a> {
|
||||||
fn test_owned_clone() {
|
type Item = T;
|
||||||
let a = Box::new(5i);
|
|
||||||
let b: Box<int> = a.clone();
|
fn next(&mut self) -> Option<T> {
|
||||||
assert!(a == b);
|
(**self).next()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||||
fn any_move() {
|
(**self).size_hint()
|
||||||
let a = Box::new(8u) as Box<Any>;
|
}
|
||||||
let b = Box::new(Test) as Box<Any>;
|
}
|
||||||
|
|
||||||
match a.downcast::<uint>() {
|
impl<'a, E: Error + 'a> FromError<E> for Box<Error + 'a> {
|
||||||
Ok(a) => { assert!(a == Box::new(8u)); }
|
fn from_error(err: E) -> Box<Error + 'a> {
|
||||||
Err(..) => panic!()
|
Box::new(err)
|
||||||
}
|
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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 @@ mod imp {
|
|||||||
if align <= MIN_ALIGN {
|
if align <= MIN_ALIGN {
|
||||||
libc::malloc(size as libc::size_t) as *mut u8
|
libc::malloc(size as libc::size_t) as *mut u8
|
||||||
} else {
|
} else {
|
||||||
let mut out = 0 as *mut libc::c_void;
|
let mut out = ptr::null_mut();
|
||||||
let ret = posix_memalign(&mut out,
|
let ret = posix_memalign(&mut out,
|
||||||
align as libc::size_t,
|
align as libc::size_t,
|
||||||
size as libc::size_t);
|
size as libc::size_t);
|
||||||
|
@ -70,6 +70,8 @@
|
|||||||
#![feature(lang_items, unsafe_destructor)]
|
#![feature(lang_items, unsafe_destructor)]
|
||||||
#![feature(box_syntax)]
|
#![feature(box_syntax)]
|
||||||
#![feature(optin_builtin_traits)]
|
#![feature(optin_builtin_traits)]
|
||||||
|
// FIXME(#21363) remove `old_impl_check` when bug is fixed
|
||||||
|
#![feature(old_impl_check)]
|
||||||
#![allow(unknown_features)] #![feature(int_uint)]
|
#![allow(unknown_features)] #![feature(int_uint)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
@ -91,6 +93,8 @@ pub mod heap;
|
|||||||
|
|
||||||
#[cfg(not(test))]
|
#[cfg(not(test))]
|
||||||
pub mod boxed;
|
pub mod boxed;
|
||||||
|
#[cfg(test)]
|
||||||
|
mod boxed_test;
|
||||||
pub mod arc;
|
pub mod arc;
|
||||||
pub mod rc;
|
pub mod rc;
|
||||||
|
|
||||||
|
@ -174,61 +174,17 @@ struct RcBox<T> {
|
|||||||
/// See the [module level documentation](../index.html) for more details.
|
/// See the [module level documentation](../index.html) for more details.
|
||||||
#[unsafe_no_drop_flag]
|
#[unsafe_no_drop_flag]
|
||||||
#[stable]
|
#[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> {
|
pub struct Rc<T> {
|
||||||
// FIXME #12808: strange names to try to avoid interfering with field accesses of the contained
|
// FIXME #12808: strange names to try to avoid interfering with field accesses of the contained
|
||||||
// type via Deref
|
// type via Deref
|
||||||
_ptr: NonZero<*mut RcBox<T>>,
|
_ptr: NonZero<*mut RcBox<T>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
|
|
||||||
impl<T> !marker::Send for Rc<T> {}
|
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> !marker::Sync for Rc<T> {}
|
||||||
|
|
||||||
impl<T> 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>`.
|
/// Constructs a new `Rc<T>`.
|
||||||
///
|
///
|
||||||
@ -240,7 +196,6 @@ impl<T> Rc<T> {
|
|||||||
/// let five = Rc::new(5i);
|
/// let five = Rc::new(5i);
|
||||||
/// ```
|
/// ```
|
||||||
#[stable]
|
#[stable]
|
||||||
#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
|
|
||||||
pub fn new(value: T) -> Rc<T> {
|
pub fn new(value: T) -> Rc<T> {
|
||||||
unsafe {
|
unsafe {
|
||||||
Rc {
|
Rc {
|
||||||
@ -267,29 +222,6 @@ impl<T> Rc<T> {
|
|||||||
///
|
///
|
||||||
/// let weak_five = five.downgrade();
|
/// 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"]
|
#[unstable = "Weak pointers may not belong in this module"]
|
||||||
pub fn downgrade(&self) -> Weak<T> {
|
pub fn downgrade(&self) -> Weak<T> {
|
||||||
self.inc_weak();
|
self.inc_weak();
|
||||||
@ -483,25 +415,6 @@ impl<T> Drop for Rc<T> {
|
|||||||
|
|
||||||
#[stable]
|
#[stable]
|
||||||
impl<T> Clone for Rc<T> {
|
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>`.
|
/// Makes a clone of the `Rc<T>`.
|
||||||
///
|
///
|
||||||
@ -517,7 +430,6 @@ impl<T> Clone for Rc<T> {
|
|||||||
/// five.clone();
|
/// five.clone();
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
|
|
||||||
fn clone(&self) -> Rc<T> {
|
fn clone(&self) -> Rc<T> {
|
||||||
self.inc_strong();
|
self.inc_strong();
|
||||||
Rc { _ptr: self._ptr }
|
Rc { _ptr: self._ptr }
|
||||||
@ -693,17 +605,17 @@ impl<S: hash::Hasher, T: Hash<S>> Hash<S> for Rc<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable = "Show is experimental."]
|
#[stable]
|
||||||
impl<T: fmt::Show> fmt::Show for Rc<T> {
|
impl<T: fmt::Display> fmt::Display for Rc<T> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "Rc({:?})", **self)
|
fmt::Display::fmt(&**self, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable]
|
#[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 {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
fmt::String::fmt(&**self, f)
|
fmt::Debug::fmt(&**self, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -714,66 +626,21 @@ impl<T: fmt::String> fmt::String for Rc<T> {
|
|||||||
/// See the [module level documentation](../index.html) for more.
|
/// See the [module level documentation](../index.html) for more.
|
||||||
#[unsafe_no_drop_flag]
|
#[unsafe_no_drop_flag]
|
||||||
#[unstable = "Weak pointers may not belong in this module."]
|
#[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> {
|
pub struct Weak<T> {
|
||||||
// FIXME #12808: strange names to try to avoid interfering with
|
// FIXME #12808: strange names to try to avoid interfering with
|
||||||
// field accesses of the contained type via Deref
|
// field accesses of the contained type via Deref
|
||||||
_ptr: NonZero<*mut RcBox<T>>,
|
_ptr: NonZero<*mut RcBox<T>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
|
|
||||||
#[allow(unstable)]
|
#[allow(unstable)]
|
||||||
impl<T> !marker::Send for Weak<T> {}
|
impl<T> !marker::Send for Weak<T> {}
|
||||||
|
|
||||||
#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
|
|
||||||
#[allow(unstable)]
|
#[allow(unstable)]
|
||||||
impl<T> !marker::Sync for Weak<T> {}
|
impl<T> !marker::Sync for Weak<T> {}
|
||||||
|
|
||||||
|
|
||||||
#[unstable = "Weak pointers may not belong in this module."]
|
#[unstable = "Weak pointers may not belong in this module."]
|
||||||
impl<T> Weak<T> {
|
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.
|
/// Upgrades a weak reference to a strong reference.
|
||||||
///
|
///
|
||||||
@ -792,7 +659,6 @@ impl<T> Weak<T> {
|
|||||||
///
|
///
|
||||||
/// let strong_five: Option<Rc<_>> = weak_five.upgrade();
|
/// let strong_five: Option<Rc<_>> = weak_five.upgrade();
|
||||||
/// ```
|
/// ```
|
||||||
#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
|
|
||||||
pub fn upgrade(&self) -> Option<Rc<T>> {
|
pub fn upgrade(&self) -> Option<Rc<T>> {
|
||||||
if self.strong() == 0 {
|
if self.strong() == 0 {
|
||||||
None
|
None
|
||||||
@ -849,25 +715,6 @@ impl<T> Drop for Weak<T> {
|
|||||||
|
|
||||||
#[unstable = "Weak pointers may not belong in this module."]
|
#[unstable = "Weak pointers may not belong in this module."]
|
||||||
impl<T> Clone for Weak<T> {
|
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>`.
|
/// Makes a clone of the `Weak<T>`.
|
||||||
///
|
///
|
||||||
@ -883,15 +730,14 @@ impl<T> Clone for Weak<T> {
|
|||||||
/// weak_five.clone();
|
/// weak_five.clone();
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
|
|
||||||
fn clone(&self) -> Weak<T> {
|
fn clone(&self) -> Weak<T> {
|
||||||
self.inc_weak();
|
self.inc_weak();
|
||||||
Weak { _ptr: self._ptr }
|
Weak { _ptr: self._ptr }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable = "Show is experimental."]
|
#[stable]
|
||||||
impl<T: fmt::Show> fmt::Show for Weak<T> {
|
impl<T: fmt::Debug> fmt::Debug for Weak<T> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "(Weak)")
|
write!(f, "(Weak)")
|
||||||
}
|
}
|
||||||
@ -1134,7 +980,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_show() {
|
fn test_show() {
|
||||||
let foo = Rc::new(75u);
|
let foo = Rc::new(75u);
|
||||||
assert!(format!("{:?}", foo) == "Rc(75u)")
|
assert_eq!(format!("{:?}", foo), "75");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -330,7 +330,7 @@ impl Bitv {
|
|||||||
|
|
||||||
if extra_bytes > 0 {
|
if extra_bytes > 0 {
|
||||||
let mut last_word = 0u32;
|
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);
|
last_word |= (reverse_bits(byte) as u32) << (i * 8);
|
||||||
}
|
}
|
||||||
bitv.storage.push(last_word);
|
bitv.storage.push(last_word);
|
||||||
@ -972,7 +972,7 @@ impl Ord for Bitv {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[stable]
|
#[stable]
|
||||||
impl fmt::Show for Bitv {
|
impl fmt::Debug for Bitv {
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
for bit in self.iter() {
|
for bit in self.iter() {
|
||||||
try!(write!(fmt, "{}", if bit { 1u32 } else { 0u32 }));
|
try!(write!(fmt, "{}", if bit { 1u32 } else { 0u32 }));
|
||||||
@ -1727,7 +1727,7 @@ impl BitvSet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Show for BitvSet {
|
impl fmt::Debug for BitvSet {
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
try!(write!(fmt, "BitvSet {{"));
|
try!(write!(fmt, "BitvSet {{"));
|
||||||
let mut first = true;
|
let mut first = true;
|
||||||
@ -2622,7 +2622,7 @@ mod bitv_set_test {
|
|||||||
s.insert(10);
|
s.insert(10);
|
||||||
s.insert(50);
|
s.insert(50);
|
||||||
s.insert(2);
|
s.insert(2);
|
||||||
assert_eq!("BitvSet {1u, 2u, 10u, 50u}", format!("{:?}", s));
|
assert_eq!("BitvSet {1, 2, 10, 50}", format!("{:?}", s));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -22,7 +22,7 @@ use core::prelude::*;
|
|||||||
use core::borrow::BorrowFrom;
|
use core::borrow::BorrowFrom;
|
||||||
use core::cmp::Ordering;
|
use core::cmp::Ordering;
|
||||||
use core::default::Default;
|
use core::default::Default;
|
||||||
use core::fmt::Show;
|
use core::fmt::Debug;
|
||||||
use core::hash::{Hash, Hasher};
|
use core::hash::{Hash, Hasher};
|
||||||
use core::iter::{Map, FromIterator};
|
use core::iter::{Map, FromIterator};
|
||||||
use core::ops::{Index, IndexMut};
|
use core::ops::{Index, IndexMut};
|
||||||
@ -871,7 +871,7 @@ impl<K: Ord, V: Ord> Ord for BTreeMap<K, V> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[stable]
|
#[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 {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
try!(write!(f, "BTreeMap {{"));
|
try!(write!(f, "BTreeMap {{"));
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ use core::prelude::*;
|
|||||||
use core::borrow::BorrowFrom;
|
use core::borrow::BorrowFrom;
|
||||||
use core::cmp::Ordering::{Greater, Less, Equal};
|
use core::cmp::Ordering::{Greater, Less, Equal};
|
||||||
use core::iter::Zip;
|
use core::iter::Zip;
|
||||||
use core::ops::{Deref, DerefMut};
|
use core::ops::{Deref, DerefMut, Index, IndexMut};
|
||||||
use core::ptr::Unique;
|
use core::ptr::Unique;
|
||||||
use core::{slice, mem, ptr, cmp, num, raw};
|
use core::{slice, mem, ptr, cmp, num, raw};
|
||||||
use alloc::heap;
|
use alloc::heap;
|
||||||
@ -1487,7 +1487,7 @@ impl<K, V, E, Impl> AbsTraversal<Impl>
|
|||||||
|
|
||||||
macro_rules! node_slice_impl {
|
macro_rules! node_slice_impl {
|
||||||
($NodeSlice:ident, $Traversal:ident,
|
($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> {
|
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).
|
/// Performs linear search in a slice. Returns a tuple of (index, is_exact_match).
|
||||||
fn search_linear<Q: ?Sized>(&self, key: &Q) -> (uint, bool)
|
fn search_linear<Q: ?Sized>(&self, key: &Q) -> (uint, bool)
|
||||||
@ -1521,10 +1521,10 @@ macro_rules! node_slice_impl {
|
|||||||
edges: if !self.has_edges {
|
edges: if !self.has_edges {
|
||||||
self.edges
|
self.edges
|
||||||
} else {
|
} else {
|
||||||
self.edges.$slice_from(pos)
|
self.edges.$index(&(pos ..))
|
||||||
},
|
},
|
||||||
keys: self.keys.slice_from(pos),
|
keys: &self.keys[pos ..],
|
||||||
vals: self.vals.$slice_from(pos),
|
vals: self.vals.$index(&(pos ..)),
|
||||||
head_is_edge: !pos_is_kv,
|
head_is_edge: !pos_is_kv,
|
||||||
tail_is_edge: self.tail_is_edge,
|
tail_is_edge: self.tail_is_edge,
|
||||||
}
|
}
|
||||||
@ -1550,10 +1550,10 @@ macro_rules! node_slice_impl {
|
|||||||
edges: if !self.has_edges {
|
edges: if !self.has_edges {
|
||||||
self.edges
|
self.edges
|
||||||
} else {
|
} else {
|
||||||
self.edges.$slice_to(pos + 1)
|
self.edges.$index(&(.. (pos + 1)))
|
||||||
},
|
},
|
||||||
keys: self.keys.slice_to(pos),
|
keys: &self.keys[..pos],
|
||||||
vals: self.vals.$slice_to(pos),
|
vals: self.vals.$index(&(.. pos)),
|
||||||
head_is_edge: self.head_is_edge,
|
head_is_edge: self.head_is_edge,
|
||||||
tail_is_edge: !pos_is_kv,
|
tail_is_edge: !pos_is_kv,
|
||||||
}
|
}
|
||||||
@ -1583,6 +1583,5 @@ macro_rules! node_slice_impl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
node_slice_impl!(NodeSlice, Traversal, as_slices_internal, slice_from, slice_to, iter);
|
node_slice_impl!(NodeSlice, Traversal, as_slices_internal, index, iter);
|
||||||
node_slice_impl!(MutNodeSlice, MutTraversal, as_slices_internal_mut, slice_from_mut,
|
node_slice_impl!(MutNodeSlice, MutTraversal, as_slices_internal_mut, index_mut, iter_mut);
|
||||||
slice_to_mut, iter_mut);
|
|
||||||
|
@ -16,11 +16,8 @@ use core::prelude::*;
|
|||||||
use core::borrow::BorrowFrom;
|
use core::borrow::BorrowFrom;
|
||||||
use core::cmp::Ordering::{self, Less, Greater, Equal};
|
use core::cmp::Ordering::{self, Less, Greater, Equal};
|
||||||
use core::default::Default;
|
use core::default::Default;
|
||||||
use core::fmt::Show;
|
use core::fmt::Debug;
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
// NOTE(stage0) remove import after a snapshot
|
|
||||||
#[cfg(stage0)]
|
|
||||||
use core::hash::Hash;
|
|
||||||
use core::iter::{Peekable, Map, FromIterator};
|
use core::iter::{Peekable, Map, FromIterator};
|
||||||
use core::ops::{BitOr, BitAnd, BitXor, Sub};
|
use core::ops::{BitOr, BitAnd, BitXor, Sub};
|
||||||
|
|
||||||
@ -592,7 +589,7 @@ impl<'a, 'b, T: Ord + Clone> BitOr<&'b BTreeSet<T>> for &'a BTreeSet<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[stable]
|
#[stable]
|
||||||
impl<T: Show> Show for BTreeSet<T> {
|
impl<T: Debug> Debug for BTreeSet<T> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
try!(write!(f, "BTreeSet {{"));
|
try!(write!(f, "BTreeSet {{"));
|
||||||
|
|
||||||
@ -892,7 +889,7 @@ mod test {
|
|||||||
|
|
||||||
let set_str = format!("{:?}", set);
|
let set_str = format!("{:?}", set);
|
||||||
|
|
||||||
assert_eq!(set_str, "BTreeSet {1i, 2i}");
|
assert_eq!(set_str, "BTreeSet {1, 2}");
|
||||||
assert_eq!(format!("{:?}", empty), "BTreeSet {}");
|
assert_eq!(format!("{:?}", empty), "BTreeSet {}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -874,7 +874,7 @@ impl<A: Clone> Clone for DList<A> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[stable]
|
#[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 {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
try!(write!(f, "DList ["));
|
try!(write!(f, "DList ["));
|
||||||
|
|
||||||
@ -1333,7 +1333,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_show() {
|
fn test_show() {
|
||||||
let list: DList<int> = range(0i, 10).collect();
|
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()
|
let list: DList<&str> = vec!["just", "one", "test", "more"].iter()
|
||||||
.map(|&s| s)
|
.map(|&s| s)
|
||||||
|
@ -31,7 +31,7 @@ pub struct EnumSet<E> {
|
|||||||
|
|
||||||
impl<E> Copy for 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 {
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
try!(write!(fmt, "EnumSet {{"));
|
try!(write!(fmt, "EnumSet {{"));
|
||||||
let mut first = true;
|
let mut first = true;
|
||||||
|
@ -12,13 +12,13 @@
|
|||||||
#[macro_export]
|
#[macro_export]
|
||||||
#[stable]
|
#[stable]
|
||||||
macro_rules! vec {
|
macro_rules! vec {
|
||||||
($x:expr; $y:expr) => ({
|
($x:expr; $y:expr) => (
|
||||||
let xs: $crate::boxed::Box<[_]> = $crate::boxed::Box::new([$x; $y]);
|
<[_] as $crate::slice::SliceExt>::into_vec(
|
||||||
$crate::slice::SliceExt::into_vec(xs)
|
$crate::boxed::Box::new([$x; $y]))
|
||||||
});
|
);
|
||||||
($($x:expr),*) => ({
|
($($x:expr),*) => (
|
||||||
let xs: $crate::boxed::Box<[_]> = $crate::boxed::Box::new([$($x),*]);
|
<[_] as $crate::slice::SliceExt>::into_vec(
|
||||||
$crate::slice::SliceExt::into_vec(xs)
|
$crate::boxed::Box::new([$($x),*]))
|
||||||
});
|
);
|
||||||
($($x:expr,)*) => (vec![$($x),*])
|
($($x:expr,)*) => (vec![$($x),*])
|
||||||
}
|
}
|
||||||
|
@ -578,7 +578,7 @@ impl<T> RingBuf<T> {
|
|||||||
|
|
||||||
if contiguous {
|
if contiguous {
|
||||||
let (empty, buf) = buf.split_at_mut(0);
|
let (empty, buf) = buf.split_at_mut(0);
|
||||||
(buf.slice_mut(tail, head), empty)
|
(&mut buf[tail .. head], empty)
|
||||||
} else {
|
} else {
|
||||||
let (mid, right) = buf.split_at_mut(tail);
|
let (mid, right) = buf.split_at_mut(tail);
|
||||||
let (left, _) = mid.split_at_mut(head);
|
let (left, _) = mid.split_at_mut(head);
|
||||||
@ -1611,7 +1611,7 @@ impl<A> Extend<A> for RingBuf<A> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[stable]
|
#[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 {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
try!(write!(f, "RingBuf ["));
|
try!(write!(f, "RingBuf ["));
|
||||||
|
|
||||||
@ -1630,7 +1630,7 @@ mod tests {
|
|||||||
use self::Taggypar::*;
|
use self::Taggypar::*;
|
||||||
use prelude::*;
|
use prelude::*;
|
||||||
use core::iter;
|
use core::iter;
|
||||||
use std::fmt::Show;
|
use std::fmt::Debug;
|
||||||
use std::hash::{self, SipHasher};
|
use std::hash::{self, SipHasher};
|
||||||
use test::Bencher;
|
use test::Bencher;
|
||||||
use test;
|
use test;
|
||||||
@ -1678,7 +1678,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[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();
|
let mut deq = RingBuf::new();
|
||||||
assert_eq!(deq.len(), 0);
|
assert_eq!(deq.len(), 0);
|
||||||
deq.push_front(a.clone());
|
deq.push_front(a.clone());
|
||||||
@ -2302,7 +2302,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_show() {
|
fn test_show() {
|
||||||
let ringbuf: RingBuf<int> = range(0i, 10).collect();
|
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()
|
let ringbuf: RingBuf<&str> = vec!["just", "one", "test", "more"].iter()
|
||||||
.map(|&s| s)
|
.map(|&s| s)
|
||||||
|
@ -169,29 +169,16 @@ pub trait SliceExt {
|
|||||||
#[unstable = "uncertain about this API approach"]
|
#[unstable = "uncertain about this API approach"]
|
||||||
fn move_from(&mut self, src: Vec<Self::Item>, start: uint, end: uint) -> uint;
|
fn move_from(&mut self, src: Vec<Self::Item>, start: uint, end: uint) -> uint;
|
||||||
|
|
||||||
/// Returns a subslice spanning the interval [`start`, `end`).
|
/// Deprecated: use `&s[start .. end]` notation instead.
|
||||||
///
|
#[deprecated = "use &s[start .. end] instead"]
|
||||||
/// 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"]
|
|
||||||
fn slice(&self, start: uint, end: uint) -> &[Self::Item];
|
fn slice(&self, start: uint, end: uint) -> &[Self::Item];
|
||||||
|
|
||||||
/// Returns a subslice from `start` to the end of the slice.
|
/// Deprecated: use `&s[start..]` notation instead.
|
||||||
///
|
#[deprecated = "use &s[start..] isntead"]
|
||||||
/// 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"]
|
|
||||||
fn slice_from(&self, start: uint) -> &[Self::Item];
|
fn slice_from(&self, start: uint) -> &[Self::Item];
|
||||||
|
|
||||||
/// Returns a subslice from the start of the slice to `end`.
|
/// Deprecated: use `&s[..end]` notation instead.
|
||||||
///
|
#[deprecated = "use &s[..end] instead"]
|
||||||
/// 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"]
|
|
||||||
fn slice_to(&self, end: uint) -> &[Self::Item];
|
fn slice_to(&self, end: uint) -> &[Self::Item];
|
||||||
|
|
||||||
/// Divides one slice into two at an index.
|
/// Divides one slice into two at an index.
|
||||||
@ -378,29 +365,16 @@ pub trait SliceExt {
|
|||||||
#[stable]
|
#[stable]
|
||||||
fn as_mut_slice(&mut self) -> &mut [Self::Item];
|
fn as_mut_slice(&mut self) -> &mut [Self::Item];
|
||||||
|
|
||||||
/// Returns a mutable subslice spanning the interval [`start`, `end`).
|
/// Deprecated: use `&mut s[start .. end]` instead.
|
||||||
///
|
#[deprecated = "use &mut s[start .. end] instead"]
|
||||||
/// 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"]
|
|
||||||
fn slice_mut(&mut self, start: uint, end: uint) -> &mut [Self::Item];
|
fn slice_mut(&mut self, start: uint, end: uint) -> &mut [Self::Item];
|
||||||
|
|
||||||
/// Returns a mutable subslice from `start` to the end of the slice.
|
/// Deprecated: use `&mut s[start ..]` instead.
|
||||||
///
|
#[deprecated = "use &mut s[start ..] instead"]
|
||||||
/// 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"]
|
|
||||||
fn slice_from_mut(&mut self, start: uint) -> &mut [Self::Item];
|
fn slice_from_mut(&mut self, start: uint) -> &mut [Self::Item];
|
||||||
|
|
||||||
/// Returns a mutable subslice from the start of the slice to `end`.
|
/// Deprecated: use `&mut s[.. end]` instead.
|
||||||
///
|
#[deprecated = "use &mut s[.. end] instead"]
|
||||||
/// 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"]
|
|
||||||
fn slice_to_mut(&mut self, end: uint) -> &mut [Self::Item];
|
fn slice_to_mut(&mut self, end: uint) -> &mut [Self::Item];
|
||||||
|
|
||||||
/// Returns an iterator that allows modifying each value
|
/// Returns an iterator that allows modifying each value
|
||||||
@ -712,7 +686,7 @@ impl<T> SliceExt for [T] {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn move_from(&mut self, mut src: Vec<T>, start: uint, end: uint) -> uint {
|
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);
|
mem::swap(a, b);
|
||||||
}
|
}
|
||||||
cmp::min(self.len(), end-start)
|
cmp::min(self.len(), end-start)
|
||||||
@ -720,17 +694,17 @@ impl<T> SliceExt for [T] {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn slice<'a>(&'a self, start: uint, end: uint) -> &'a [T] {
|
fn slice<'a>(&'a self, start: uint, end: uint) -> &'a [T] {
|
||||||
core_slice::SliceExt::slice(self, start, end)
|
&self[start .. end]
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn slice_from<'a>(&'a self, start: uint) -> &'a [T] {
|
fn slice_from<'a>(&'a self, start: uint) -> &'a [T] {
|
||||||
core_slice::SliceExt::slice_from(self, start)
|
&self[start ..]
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn slice_to<'a>(&'a self, end: uint) -> &'a [T] {
|
fn slice_to<'a>(&'a self, end: uint) -> &'a [T] {
|
||||||
core_slice::SliceExt::slice_to(self, end)
|
&self[.. end]
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -834,17 +808,17 @@ impl<T> SliceExt for [T] {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn slice_mut<'a>(&'a mut self, start: uint, end: uint) -> &'a mut [T] {
|
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]
|
#[inline]
|
||||||
fn slice_from_mut<'a>(&'a mut self, start: uint) -> &'a mut [T] {
|
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]
|
#[inline]
|
||||||
fn slice_to_mut<'a>(&'a mut self, end: uint) -> &'a mut [T] {
|
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]
|
#[inline]
|
||||||
@ -2409,8 +2383,12 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_chunksator() {
|
fn test_chunksator() {
|
||||||
|
use core::iter::ExactSizeIterator;
|
||||||
|
|
||||||
let v = &[1i,2,3,4,5];
|
let v = &[1i,2,3,4,5];
|
||||||
|
|
||||||
|
assert_eq!(v.chunks(2).len(), 3);
|
||||||
|
|
||||||
let chunks: &[&[int]] = &[&[1i,2], &[3,4], &[5]];
|
let chunks: &[&[int]] = &[&[1i,2], &[3,4], &[5]];
|
||||||
assert_eq!(v.chunks(2).collect::<Vec<&[int]>>(), chunks);
|
assert_eq!(v.chunks(2).collect::<Vec<&[int]>>(), chunks);
|
||||||
let chunks: &[&[int]] = &[&[1i,2,3], &[4,5]];
|
let chunks: &[&[int]] = &[&[1i,2,3], &[4,5]];
|
||||||
@ -2476,19 +2454,19 @@ mod tests {
|
|||||||
}
|
}
|
||||||
let empty: Vec<int> = vec![];
|
let empty: Vec<int> = vec![];
|
||||||
test_show_vec!(empty, "[]");
|
test_show_vec!(empty, "[]");
|
||||||
test_show_vec!(vec![1i], "[1i]");
|
test_show_vec!(vec![1i], "[1]");
|
||||||
test_show_vec!(vec![1i, 2, 3], "[1i, 2i, 3i]");
|
test_show_vec!(vec![1i, 2, 3], "[1, 2, 3]");
|
||||||
test_show_vec!(vec![vec![], vec![1u], vec![1u, 1u]],
|
test_show_vec!(vec![vec![], vec![1u], vec![1u, 1u]],
|
||||||
"[[], [1u], [1u, 1u]]");
|
"[[], [1], [1, 1]]");
|
||||||
|
|
||||||
let empty_mut: &mut [int] = &mut[];
|
let empty_mut: &mut [int] = &mut[];
|
||||||
test_show_vec!(empty_mut, "[]");
|
test_show_vec!(empty_mut, "[]");
|
||||||
let v: &mut[int] = &mut[1];
|
let v: &mut[int] = &mut[1];
|
||||||
test_show_vec!(v, "[1i]");
|
test_show_vec!(v, "[1]");
|
||||||
let v: &mut[int] = &mut[1, 2, 3];
|
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]];
|
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]
|
#[test]
|
||||||
@ -2675,7 +2653,10 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_mut_chunks() {
|
fn test_mut_chunks() {
|
||||||
|
use core::iter::ExactSizeIterator;
|
||||||
|
|
||||||
let mut v = [0u8, 1, 2, 3, 4, 5, 6];
|
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 (i, chunk) in v.chunks_mut(3).enumerate() {
|
||||||
for x in chunk.iter_mut() {
|
for x in chunk.iter_mut() {
|
||||||
*x = i as u8;
|
*x = i as u8;
|
||||||
|
@ -750,67 +750,17 @@ pub trait StrExt: Index<FullRange, Output = str> {
|
|||||||
core_str::StrExt::lines_any(&self[])
|
core_str::StrExt::lines_any(&self[])
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a slice of the given string from the byte range
|
/// Deprecated: use `s[a .. b]` instead.
|
||||||
/// [`begin`..`end`).
|
#[deprecated = "use slice notation [a..b] instead"]
|
||||||
///
|
fn slice(&self, begin: uint, end: uint) -> &str;
|
||||||
/// 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)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns a slice of the string from `begin` to its end.
|
/// Deprecated: use `s[a..]` instead.
|
||||||
///
|
#[deprecated = "use slice notation [a..] instead"]
|
||||||
/// Equivalent to `self.slice(begin, self.len())`.
|
fn slice_from(&self, begin: uint) -> &str;
|
||||||
///
|
|
||||||
/// 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)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns a slice of the string from the beginning to byte
|
/// Deprecated: use `s[..a]` instead.
|
||||||
/// `end`.
|
#[deprecated = "use slice notation [..a] instead"]
|
||||||
///
|
fn slice_to(&self, end: uint) -> &str;
|
||||||
/// 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)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns a slice of the string from the character range
|
/// Returns a slice of the string from the character range
|
||||||
/// [`begin`..`end`).
|
/// [`begin`..`end`).
|
||||||
@ -1348,7 +1298,19 @@ pub trait StrExt: Index<FullRange, Output = str> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[stable]
|
#[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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
@ -18,6 +18,7 @@ use core::prelude::*;
|
|||||||
|
|
||||||
use core::borrow::{Cow, IntoCow};
|
use core::borrow::{Cow, IntoCow};
|
||||||
use core::default::Default;
|
use core::default::Default;
|
||||||
|
use core::error::Error;
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
use core::hash;
|
use core::hash;
|
||||||
use core::iter::FromIterator;
|
use core::iter::FromIterator;
|
||||||
@ -40,6 +41,7 @@ pub struct String {
|
|||||||
|
|
||||||
/// A possible error value from the `String::from_utf8` function.
|
/// A possible error value from the `String::from_utf8` function.
|
||||||
#[stable]
|
#[stable]
|
||||||
|
#[derive(Show)]
|
||||||
pub struct FromUtf8Error {
|
pub struct FromUtf8Error {
|
||||||
bytes: Vec<u8>,
|
bytes: Vec<u8>,
|
||||||
error: Utf8Error,
|
error: Utf8Error,
|
||||||
@ -48,6 +50,7 @@ pub struct FromUtf8Error {
|
|||||||
/// A possible error value from the `String::from_utf16` function.
|
/// A possible error value from the `String::from_utf16` function.
|
||||||
#[stable]
|
#[stable]
|
||||||
#[allow(missing_copy_implementations)]
|
#[allow(missing_copy_implementations)]
|
||||||
|
#[derive(Show)]
|
||||||
pub struct FromUtf16Error(());
|
pub struct FromUtf16Error(());
|
||||||
|
|
||||||
impl String {
|
impl String {
|
||||||
@ -680,30 +683,28 @@ impl FromUtf8Error {
|
|||||||
pub fn utf8_error(&self) -> Utf8Error { self.error }
|
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 {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
fmt::String::fmt(self, f)
|
fmt::Display::fmt(&self.error, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable]
|
#[stable]
|
||||||
impl fmt::String for FromUtf8Error {
|
impl Error for FromUtf8Error {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn description(&self) -> &str { "invalid utf-8" }
|
||||||
fmt::String::fmt(&self.error, f)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Show for FromUtf16Error {
|
#[stable]
|
||||||
|
impl fmt::Display for FromUtf16Error {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
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]
|
#[stable]
|
||||||
impl fmt::String for FromUtf16Error {
|
impl Error for FromUtf16Error {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn description(&self) -> &str { "invalid utf-16" }
|
||||||
fmt::String::fmt("invalid utf-16: lone surrogate found", f)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable]
|
#[stable]
|
||||||
@ -814,18 +815,18 @@ impl Default for String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[stable]
|
#[stable]
|
||||||
impl fmt::String for String {
|
impl fmt::Display for String {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
fmt::String::fmt(&**self, f)
|
fmt::Display::fmt(&**self, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable = "waiting on fmt stabilization"]
|
#[stable]
|
||||||
impl fmt::Show for String {
|
impl fmt::Debug for String {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
fmt::Show::fmt(&**self, f)
|
fmt::Debug::fmt(&**self, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -848,6 +849,7 @@ impl<'a> Add<&'a str> for String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[stable]
|
||||||
impl ops::Index<ops::Range<uint>> for String {
|
impl ops::Index<ops::Range<uint>> for String {
|
||||||
type Output = str;
|
type Output = str;
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -855,6 +857,7 @@ impl ops::Index<ops::Range<uint>> for String {
|
|||||||
&self[][*index]
|
&self[][*index]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[stable]
|
||||||
impl ops::Index<ops::RangeTo<uint>> for String {
|
impl ops::Index<ops::RangeTo<uint>> for String {
|
||||||
type Output = str;
|
type Output = str;
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -862,6 +865,7 @@ impl ops::Index<ops::RangeTo<uint>> for String {
|
|||||||
&self[][*index]
|
&self[][*index]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[stable]
|
||||||
impl ops::Index<ops::RangeFrom<uint>> for String {
|
impl ops::Index<ops::RangeFrom<uint>> for String {
|
||||||
type Output = str;
|
type Output = str;
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -869,6 +873,7 @@ impl ops::Index<ops::RangeFrom<uint>> for String {
|
|||||||
&self[][*index]
|
&self[][*index]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[stable]
|
||||||
impl ops::Index<ops::FullRange> for String {
|
impl ops::Index<ops::FullRange> for String {
|
||||||
type Output = str;
|
type Output = str;
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -934,7 +939,7 @@ pub trait ToString {
|
|||||||
fn to_string(&self) -> String;
|
fn to_string(&self) -> String;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: fmt::String + ?Sized> ToString for T {
|
impl<T: fmt::Display + ?Sized> ToString for T {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_string(&self) -> String {
|
fn to_string(&self) -> String {
|
||||||
use core::fmt::Writer;
|
use core::fmt::Writer;
|
||||||
@ -1295,10 +1300,10 @@ mod tests {
|
|||||||
fn test_vectors() {
|
fn test_vectors() {
|
||||||
let x: Vec<int> = vec![];
|
let x: Vec<int> = vec![];
|
||||||
assert_eq!(format!("{:?}", x), "[]");
|
assert_eq!(format!("{:?}", x), "[]");
|
||||||
assert_eq!(format!("{:?}", vec![1i]), "[1i]");
|
assert_eq!(format!("{:?}", vec![1i]), "[1]");
|
||||||
assert_eq!(format!("{:?}", vec![1i, 2, 3]), "[1i, 2i, 3i]");
|
assert_eq!(format!("{:?}", vec![1i, 2, 3]), "[1, 2, 3]");
|
||||||
assert!(format!("{:?}", vec![vec![], vec![1i], vec![1i, 1]]) ==
|
assert!(format!("{:?}", vec![vec![], vec![1i], vec![1i, 1]]) ==
|
||||||
"[[], [1i], [1i, 1i]]");
|
"[[], [1], [1, 1]]");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1229,7 +1229,7 @@ impl<S: hash::Writer + hash::Hasher, T: Hash<S>> Hash<S> for Vec<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable = "waiting on Index stability"]
|
#[stable]
|
||||||
impl<T> Index<uint> for Vec<T> {
|
impl<T> Index<uint> for Vec<T> {
|
||||||
type Output = T;
|
type Output = T;
|
||||||
|
|
||||||
@ -1239,6 +1239,7 @@ impl<T> Index<uint> for Vec<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[stable]
|
||||||
impl<T> IndexMut<uint> for Vec<T> {
|
impl<T> IndexMut<uint> for Vec<T> {
|
||||||
type Output = T;
|
type Output = T;
|
||||||
|
|
||||||
@ -1249,6 +1250,7 @@ impl<T> IndexMut<uint> for Vec<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[stable]
|
||||||
impl<T> ops::Index<ops::Range<uint>> for Vec<T> {
|
impl<T> ops::Index<ops::Range<uint>> for Vec<T> {
|
||||||
type Output = [T];
|
type Output = [T];
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -1256,6 +1258,7 @@ impl<T> ops::Index<ops::Range<uint>> for Vec<T> {
|
|||||||
self.as_slice().index(index)
|
self.as_slice().index(index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[stable]
|
||||||
impl<T> ops::Index<ops::RangeTo<uint>> for Vec<T> {
|
impl<T> ops::Index<ops::RangeTo<uint>> for Vec<T> {
|
||||||
type Output = [T];
|
type Output = [T];
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -1263,6 +1266,7 @@ impl<T> ops::Index<ops::RangeTo<uint>> for Vec<T> {
|
|||||||
self.as_slice().index(index)
|
self.as_slice().index(index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[stable]
|
||||||
impl<T> ops::Index<ops::RangeFrom<uint>> for Vec<T> {
|
impl<T> ops::Index<ops::RangeFrom<uint>> for Vec<T> {
|
||||||
type Output = [T];
|
type Output = [T];
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -1270,6 +1274,7 @@ impl<T> ops::Index<ops::RangeFrom<uint>> for Vec<T> {
|
|||||||
self.as_slice().index(index)
|
self.as_slice().index(index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[stable]
|
||||||
impl<T> ops::Index<ops::FullRange> for Vec<T> {
|
impl<T> ops::Index<ops::FullRange> for Vec<T> {
|
||||||
type Output = [T];
|
type Output = [T];
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -1278,6 +1283,7 @@ impl<T> ops::Index<ops::FullRange> for Vec<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[stable]
|
||||||
impl<T> ops::IndexMut<ops::Range<uint>> for Vec<T> {
|
impl<T> ops::IndexMut<ops::Range<uint>> for Vec<T> {
|
||||||
type Output = [T];
|
type Output = [T];
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -1285,6 +1291,7 @@ impl<T> ops::IndexMut<ops::Range<uint>> for Vec<T> {
|
|||||||
self.as_mut_slice().index_mut(index)
|
self.as_mut_slice().index_mut(index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[stable]
|
||||||
impl<T> ops::IndexMut<ops::RangeTo<uint>> for Vec<T> {
|
impl<T> ops::IndexMut<ops::RangeTo<uint>> for Vec<T> {
|
||||||
type Output = [T];
|
type Output = [T];
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -1292,6 +1299,7 @@ impl<T> ops::IndexMut<ops::RangeTo<uint>> for Vec<T> {
|
|||||||
self.as_mut_slice().index_mut(index)
|
self.as_mut_slice().index_mut(index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[stable]
|
||||||
impl<T> ops::IndexMut<ops::RangeFrom<uint>> for Vec<T> {
|
impl<T> ops::IndexMut<ops::RangeFrom<uint>> for Vec<T> {
|
||||||
type Output = [T];
|
type Output = [T];
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -1299,6 +1307,7 @@ impl<T> ops::IndexMut<ops::RangeFrom<uint>> for Vec<T> {
|
|||||||
self.as_mut_slice().index_mut(index)
|
self.as_mut_slice().index_mut(index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[stable]
|
||||||
impl<T> ops::IndexMut<ops::FullRange> for Vec<T> {
|
impl<T> ops::IndexMut<ops::FullRange> for Vec<T> {
|
||||||
type Output = [T];
|
type Output = [T];
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -1307,7 +1316,6 @@ impl<T> ops::IndexMut<ops::FullRange> for Vec<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[stable]
|
#[stable]
|
||||||
impl<T> ops::Deref for Vec<T> {
|
impl<T> ops::Deref for Vec<T> {
|
||||||
type Target = [T];
|
type Target = [T];
|
||||||
@ -1486,10 +1494,10 @@ impl<T> Default for Vec<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable = "waiting on Show stability"]
|
#[stable]
|
||||||
impl<T: fmt::Show> fmt::Show for Vec<T> {
|
impl<T: fmt::Debug> fmt::Debug for Vec<T> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
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 @@ mod tests {
|
|||||||
#[should_fail]
|
#[should_fail]
|
||||||
fn test_slice_out_of_bounds_1() {
|
fn test_slice_out_of_bounds_1() {
|
||||||
let x: Vec<int> = vec![1, 2, 3, 4, 5];
|
let x: Vec<int> = vec![1, 2, 3, 4, 5];
|
||||||
&x[(-1)..];
|
&x[-1..];
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -2172,7 +2180,7 @@ mod tests {
|
|||||||
#[should_fail]
|
#[should_fail]
|
||||||
fn test_slice_out_of_bounds_3() {
|
fn test_slice_out_of_bounds_3() {
|
||||||
let x: Vec<int> = vec![1, 2, 3, 4, 5];
|
let x: Vec<int> = vec![1, 2, 3, 4, 5];
|
||||||
&x[(-1)..4];
|
&x[-1..4];
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -513,7 +513,7 @@ impl<V: Ord> Ord for VecMap<V> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[stable]
|
#[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 {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
try!(write!(f, "VecMap {{"));
|
try!(write!(f, "VecMap {{"));
|
||||||
|
|
||||||
@ -990,7 +990,7 @@ mod test_map {
|
|||||||
map.insert(3, 4i);
|
map.insert(3, 4i);
|
||||||
|
|
||||||
let map_str = format!("{:?}", map);
|
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 {}");
|
assert_eq!(format!("{:?}", empty), "VecMap {}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,11 +34,11 @@
|
|||||||
//! use runtime reflection instead.
|
//! use runtime reflection instead.
|
||||||
//!
|
//!
|
||||||
//! ```rust
|
//! ```rust
|
||||||
//! use std::fmt::Show;
|
//! use std::fmt::Debug;
|
||||||
//! use std::any::Any;
|
//! use std::any::Any;
|
||||||
//!
|
//!
|
||||||
//! // Logger function for any type that implements Show.
|
//! // Logger function for any type that implements Debug.
|
||||||
//! fn log<T: Any+Show>(value: &T) {
|
//! fn log<T: Any + Debug>(value: &T) {
|
||||||
//! let value_any = value as &Any;
|
//! let value_any = value as &Any;
|
||||||
//!
|
//!
|
||||||
//! // try to convert our value to a String. If successful, we want to
|
//! // 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.
|
//! // 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);
|
//! log(value);
|
||||||
//! // ...do some other work
|
//! // ...do some other work
|
||||||
//! }
|
//! }
|
||||||
@ -75,7 +75,7 @@ use mem::transmute;
|
|||||||
use option::Option::{self, Some, None};
|
use option::Option::{self, Some, None};
|
||||||
use raw::TraitObject;
|
use raw::TraitObject;
|
||||||
use intrinsics;
|
use intrinsics;
|
||||||
#[cfg(not(stage0))] use marker::Sized;
|
use marker::Sized;
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// Any trait
|
// Any trait
|
||||||
@ -175,17 +175,10 @@ pub struct TypeId {
|
|||||||
impl TypeId {
|
impl TypeId {
|
||||||
/// Returns the `TypeId` of the type this generic function has been
|
/// Returns the `TypeId` of the type this generic function has been
|
||||||
/// instantiated with
|
/// instantiated with
|
||||||
#[cfg(not(stage0))]
|
|
||||||
#[unstable = "may grow a `Reflect` bound soon via marker traits"]
|
#[unstable = "may grow a `Reflect` bound soon via marker traits"]
|
||||||
pub fn of<T: ?Sized + 'static>() -> TypeId {
|
pub fn of<T: ?Sized + 'static>() -> TypeId {
|
||||||
TypeId {
|
TypeId {
|
||||||
t: unsafe { intrinsics::type_id::<T>() },
|
t: unsafe { intrinsics::type_id::<T>() },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// dox
|
|
||||||
#[cfg(stage0)]
|
|
||||||
pub fn of<T: 'static>() -> TypeId {
|
|
||||||
unsafe { intrinsics::type_id::<T>() }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -39,10 +39,10 @@ macro_rules! array_impls {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable = "waiting for Show to stabilize"]
|
#[stable]
|
||||||
impl<T:fmt::Show> fmt::Show for [T; $N] {
|
impl<T: fmt::Debug> fmt::Debug for [T; $N] {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
fmt::Show::fmt(&&self[], f)
|
fmt::Debug::fmt(&&self[], f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,7 +133,6 @@ impl<T> ToOwned<T> for T where T: Clone {
|
|||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Show)]
|
|
||||||
pub enum Cow<'a, T, B: ?Sized + 'a> where B: ToOwned<T> {
|
pub enum Cow<'a, T, B: ?Sized + 'a> where B: ToOwned<T> {
|
||||||
/// Borrowed data.
|
/// Borrowed data.
|
||||||
Borrowed(&'a B),
|
Borrowed(&'a B),
|
||||||
@ -239,14 +238,27 @@ impl<'a, T, B: ?Sized> PartialOrd for Cow<'a, T, B> where B: PartialOrd + ToOwne
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[stable]
|
#[stable]
|
||||||
impl<'a, T, B: ?Sized> fmt::String for Cow<'a, T, B> where
|
impl<'a, T, B: ?Sized> fmt::Debug for Cow<'a, T, B> where
|
||||||
B: fmt::String + ToOwned<T>,
|
B: fmt::Debug + ToOwned<T>,
|
||||||
T: fmt::String,
|
T: fmt::Debug,
|
||||||
{
|
{
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match *self {
|
match *self {
|
||||||
Borrowed(ref b) => fmt::String::fmt(b, f),
|
Borrowed(ref b) => fmt::Debug::fmt(b, f),
|
||||||
Owned(ref o) => fmt::String::fmt(o, 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,
|
//! `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
|
//! 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
|
//! a description, but they may optionally provide additional detail (via
|
||||||
//! chain information:
|
//! `Display`) and cause chain information:
|
||||||
//!
|
//!
|
||||||
//! ```
|
//! ```
|
||||||
//! trait Error {
|
//! use std::fmt::Display;
|
||||||
|
//!
|
||||||
|
//! trait Error: Display {
|
||||||
//! fn description(&self) -> &str;
|
//! fn description(&self) -> &str;
|
||||||
//!
|
//!
|
||||||
//! fn detail(&self) -> Option<String> { None }
|
|
||||||
//! fn cause(&self) -> Option<&Error> { None }
|
//! fn cause(&self) -> Option<&Error> { None }
|
||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
@ -80,20 +81,15 @@
|
|||||||
|
|
||||||
#![stable]
|
#![stable]
|
||||||
|
|
||||||
use prelude::v1::*;
|
use prelude::*;
|
||||||
|
use fmt::Display;
|
||||||
use str::Utf8Error;
|
|
||||||
use string::{FromUtf8Error, FromUtf16Error};
|
|
||||||
|
|
||||||
/// Base functionality for all errors in Rust.
|
/// Base functionality for all errors in Rust.
|
||||||
#[unstable = "the exact API of this trait may change"]
|
#[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.
|
/// A short description of the error; usually a static string.
|
||||||
fn description(&self) -> &str;
|
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.
|
/// The lower-level cause of this error, if any.
|
||||||
fn cause(&self) -> Option<&Error> { None }
|
fn cause(&self) -> Option<&Error> { None }
|
||||||
}
|
}
|
||||||
@ -112,26 +108,3 @@ impl<E> FromError<E> for E {
|
|||||||
err
|
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.
|
// Remember start of the fractional digits.
|
||||||
// Points one beyond end of buf if none get generated,
|
// Points one beyond end of buf if none get generated,
|
||||||
@ -316,7 +316,7 @@ pub fn float_to_str_bytes_common<T: Float, U, F>(
|
|||||||
|
|
||||||
impl<'a> fmt::Writer for Filler<'a> {
|
impl<'a> fmt::Writer for Filler<'a> {
|
||||||
fn write_str(&mut self, s: &str) -> fmt::Result {
|
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());
|
s.as_bytes());
|
||||||
*self.end += s.len();
|
*self.end += s.len();
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -26,12 +26,15 @@ use ops::{Deref, FnOnce};
|
|||||||
use result;
|
use result;
|
||||||
use slice::SliceExt;
|
use slice::SliceExt;
|
||||||
use slice;
|
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::Radix;
|
pub use self::num::Radix;
|
||||||
pub use self::num::RadixFmt;
|
pub use self::num::RadixFmt;
|
||||||
|
|
||||||
|
#[cfg(stage0)] pub use self::Debug as Show;
|
||||||
|
#[cfg(stage0)] pub use self::Display as String;
|
||||||
|
|
||||||
mod num;
|
mod num;
|
||||||
mod float;
|
mod float;
|
||||||
pub mod rt;
|
pub mod rt;
|
||||||
@ -46,7 +49,7 @@ pub type Result = result::Result<(), Error>;
|
|||||||
/// occurred. Any extra information must be arranged to be transmitted through
|
/// occurred. Any extra information must be arranged to be transmitted through
|
||||||
/// some other means.
|
/// some other means.
|
||||||
#[unstable = "core and I/O reconciliation may alter this definition"]
|
#[unstable = "core and I/O reconciliation may alter this definition"]
|
||||||
#[derive(Copy)]
|
#[derive(Copy, Show)]
|
||||||
pub struct Error;
|
pub struct Error;
|
||||||
|
|
||||||
/// A collection of methods that are required to format a message into a stream.
|
/// 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> {
|
impl<'a> Argument<'a> {
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
fn show_uint(x: &uint, f: &mut Formatter) -> Result {
|
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> {
|
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>],
|
args: &'a [Argument<'a>],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Show for Arguments<'a> {
|
#[stable]
|
||||||
|
impl<'a> Debug for Arguments<'a> {
|
||||||
fn fmt(&self, fmt: &mut Formatter) -> Result {
|
fn fmt(&self, fmt: &mut Formatter) -> Result {
|
||||||
String::fmt(self, fmt)
|
Display::fmt(self, fmt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable]
|
#[stable]
|
||||||
impl<'a> String for Arguments<'a> {
|
impl<'a> Display for Arguments<'a> {
|
||||||
fn fmt(&self, fmt: &mut Formatter) -> Result {
|
fn fmt(&self, fmt: &mut Formatter) -> Result {
|
||||||
write(fmt.buf, *self)
|
write(fmt.buf, *self)
|
||||||
}
|
}
|
||||||
@ -229,20 +233,49 @@ impl<'a> String for Arguments<'a> {
|
|||||||
|
|
||||||
/// Format trait for the `:?` format. Useful for debugging, most all types
|
/// Format trait for the `:?` format. Useful for debugging, most all types
|
||||||
/// should implement this.
|
/// should implement this.
|
||||||
#[unstable = "I/O and core have yet to be reconciled"]
|
#[deprecated = "renamed to Debug"]
|
||||||
|
#[cfg(not(stage0))]
|
||||||
pub trait Show {
|
pub trait Show {
|
||||||
/// Formats the value using the given formatter.
|
/// Formats the value using the given formatter.
|
||||||
fn fmt(&self, &mut Formatter) -> Result;
|
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
|
/// When a value can be semantically expressed as a String, this trait may be
|
||||||
/// used. It corresponds to the default format, `{}`.
|
/// used. It corresponds to the default format, `{}`.
|
||||||
#[unstable = "I/O and core have yet to be reconciled"]
|
#[unstable = "I/O and core have yet to be reconciled"]
|
||||||
pub trait String {
|
pub trait Display {
|
||||||
/// Formats the value using the given formatter.
|
/// Formats the value using the given formatter.
|
||||||
fn fmt(&self, &mut Formatter) -> Result;
|
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
|
/// Format trait for the `o` character
|
||||||
#[unstable = "I/O and core have yet to be reconciled"]
|
#[unstable = "I/O and core have yet to be reconciled"]
|
||||||
@ -583,9 +616,10 @@ impl<'a> Formatter<'a> {
|
|||||||
pub fn precision(&self) -> Option<uint> { self.precision }
|
pub fn precision(&self) -> Option<uint> { self.precision }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Show for Error {
|
#[stable]
|
||||||
|
impl Display for Error {
|
||||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
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 {
|
macro_rules! fmt_refs {
|
||||||
($($tr:ident),*) => {
|
($($tr:ident),*) => {
|
||||||
$(
|
$(
|
||||||
|
#[stable]
|
||||||
impl<'a, T: ?Sized + $tr> $tr for &'a T {
|
impl<'a, T: ?Sized + $tr> $tr for &'a T {
|
||||||
fn fmt(&self, f: &mut Formatter) -> Result { $tr::fmt(&**self, f) }
|
fn fmt(&self, f: &mut Formatter) -> Result { $tr::fmt(&**self, f) }
|
||||||
}
|
}
|
||||||
|
#[stable]
|
||||||
impl<'a, T: ?Sized + $tr> $tr for &'a mut T {
|
impl<'a, T: ?Sized + $tr> $tr for &'a mut T {
|
||||||
fn fmt(&self, f: &mut Formatter) -> Result { $tr::fmt(&**self, f) }
|
fn fmt(&self, f: &mut Formatter) -> Result { $tr::fmt(&**self, f) }
|
||||||
}
|
}
|
||||||
@ -621,22 +657,24 @@ macro_rules! fmt_refs {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||||
String::fmt(self, f)
|
Display::fmt(self, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable]
|
#[stable]
|
||||||
impl String for bool {
|
impl Display for bool {
|
||||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
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 {
|
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||||
try!(write!(f, "\""));
|
try!(write!(f, "\""));
|
||||||
for c in self.chars().flat_map(|c| c.escape_default()) {
|
for c in self.chars().flat_map(|c| c.escape_default()) {
|
||||||
@ -647,13 +685,14 @@ impl Show for str {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[stable]
|
#[stable]
|
||||||
impl String for str {
|
impl Display for str {
|
||||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||||
f.pad(self)
|
f.pad(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Show for char {
|
#[stable]
|
||||||
|
impl Debug for char {
|
||||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||||
use char::CharExt;
|
use char::CharExt;
|
||||||
try!(write!(f, "'"));
|
try!(write!(f, "'"));
|
||||||
@ -665,15 +704,16 @@ impl Show for char {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[stable]
|
#[stable]
|
||||||
impl String for char {
|
impl Display for char {
|
||||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||||
let mut utf8 = [0u8; 4];
|
let mut utf8 = [0u8; 4];
|
||||||
let amt = self.encode_utf8(&mut utf8).unwrap_or(0);
|
let amt = self.encode_utf8(&mut utf8).unwrap_or(0);
|
||||||
let s: &str = unsafe { mem::transmute(&utf8[..amt]) };
|
let s: &str = unsafe { mem::transmute(&utf8[..amt]) };
|
||||||
String::fmt(s, f)
|
Display::fmt(s, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[stable]
|
||||||
impl<T> Pointer for *const T {
|
impl<T> Pointer for *const T {
|
||||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||||
f.flags |= 1 << (rt::FlagAlternate as uint);
|
f.flags |= 1 << (rt::FlagAlternate as uint);
|
||||||
@ -683,18 +723,21 @@ impl<T> Pointer for *const T {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[stable]
|
||||||
impl<T> Pointer for *mut T {
|
impl<T> Pointer for *mut T {
|
||||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||||
Pointer::fmt(&(*self as *const T), f)
|
Pointer::fmt(&(*self as *const T), f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[stable]
|
||||||
impl<'a, T> Pointer for &'a T {
|
impl<'a, T> Pointer for &'a T {
|
||||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||||
Pointer::fmt(&(*self as *const T), f)
|
Pointer::fmt(&(*self as *const T), f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[stable]
|
||||||
impl<'a, T> Pointer for &'a mut T {
|
impl<'a, T> Pointer for &'a mut T {
|
||||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||||
Pointer::fmt(&(&**self as *const T), f)
|
Pointer::fmt(&(&**self as *const T), f)
|
||||||
@ -703,15 +746,15 @@ impl<'a, T> Pointer for &'a mut T {
|
|||||||
|
|
||||||
macro_rules! floating { ($ty:ident) => {
|
macro_rules! floating { ($ty:ident) => {
|
||||||
|
|
||||||
impl Show for $ty {
|
#[stable]
|
||||||
|
impl Debug for $ty {
|
||||||
fn fmt(&self, fmt: &mut Formatter) -> Result {
|
fn fmt(&self, fmt: &mut Formatter) -> Result {
|
||||||
try!(String::fmt(self, fmt));
|
Display::fmt(self, fmt)
|
||||||
fmt.write_str(stringify!($ty))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable]
|
#[stable]
|
||||||
impl String for $ty {
|
impl Display for $ty {
|
||||||
fn fmt(&self, fmt: &mut Formatter) -> Result {
|
fn fmt(&self, fmt: &mut Formatter) -> Result {
|
||||||
use num::Float;
|
use num::Float;
|
||||||
|
|
||||||
@ -732,6 +775,7 @@ macro_rules! floating { ($ty:ident) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[stable]
|
||||||
impl LowerExp for $ty {
|
impl LowerExp for $ty {
|
||||||
fn fmt(&self, fmt: &mut Formatter) -> Result {
|
fn fmt(&self, fmt: &mut Formatter) -> Result {
|
||||||
use num::Float;
|
use num::Float;
|
||||||
@ -753,6 +797,7 @@ macro_rules! floating { ($ty:ident) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[stable]
|
||||||
impl UpperExp for $ty {
|
impl UpperExp for $ty {
|
||||||
fn fmt(&self, fmt: &mut Formatter) -> Result {
|
fn fmt(&self, fmt: &mut Formatter) -> Result {
|
||||||
use num::Float;
|
use num::Float;
|
||||||
@ -777,12 +822,14 @@ macro_rules! floating { ($ty:ident) => {
|
|||||||
floating! { f32 }
|
floating! { f32 }
|
||||||
floating! { f64 }
|
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) }
|
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) }
|
fn fmt(&self, f: &mut Formatter) -> Result { Pointer::fmt(self, f) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -793,7 +840,8 @@ macro_rules! peel {
|
|||||||
macro_rules! tuple {
|
macro_rules! tuple {
|
||||||
() => ();
|
() => ();
|
||||||
( $($name:ident,)+ ) => (
|
( $($name:ident,)+ ) => (
|
||||||
impl<$($name:Show),*> Show for ($($name,)*) {
|
#[stable]
|
||||||
|
impl<$($name:Debug),*> Debug for ($($name,)*) {
|
||||||
#[allow(non_snake_case, unused_assignments)]
|
#[allow(non_snake_case, unused_assignments)]
|
||||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||||
try!(write!(f, "("));
|
try!(write!(f, "("));
|
||||||
@ -818,11 +866,13 @@ macro_rules! tuple {
|
|||||||
|
|
||||||
tuple! { T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, }
|
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") }
|
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 {
|
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||||
if f.flags & (1 << (rt::FlagAlternate as uint)) == 0 {
|
if f.flags & (1 << (rt::FlagAlternate as uint)) == 0 {
|
||||||
try!(write!(f, "["));
|
try!(write!(f, "["));
|
||||||
@ -843,20 +893,22 @@ impl<T: Show> Show for [T] {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Show for () {
|
#[stable]
|
||||||
|
impl Debug for () {
|
||||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||||
f.pad("()")
|
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 {
|
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||||
write!(f, "Cell {{ value: {:?} }}", self.get())
|
write!(f, "Cell {{ value: {:?} }}", self.get())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable]
|
#[stable]
|
||||||
impl<T: Show> Show for RefCell<T> {
|
impl<T: Debug> Debug for RefCell<T> {
|
||||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||||
match self.try_borrow() {
|
match self.try_borrow() {
|
||||||
Some(val) => write!(f, "RefCell {{ value: {:?} }}", val),
|
Some(val) => write!(f, "RefCell {{ value: {:?} }}", val),
|
||||||
@ -865,29 +917,17 @@ impl<T: Show> Show for RefCell<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||||
Show::fmt(&**self, f)
|
Debug::fmt(&**self, f)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'b, T: Show> Show for RefMut<'b, T> {
|
|
||||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
|
||||||
Show::fmt(&*(self.deref()), f)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable]
|
#[stable]
|
||||||
impl String for Utf8Error {
|
impl<'b, T: Debug> Debug for RefMut<'b, T> {
|
||||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||||
match *self {
|
Debug::fmt(&*(self.deref()), f)
|
||||||
Utf8Error::InvalidByte(n) => {
|
|
||||||
write!(f, "invalid utf-8: invalid byte at index {}", n)
|
|
||||||
}
|
|
||||||
Utf8Error::TooShort => {
|
|
||||||
write!(f, "invalid utf-8: byte slice too short")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,13 +154,14 @@ pub fn radix<T>(x: T, base: u8) -> RadixFmt<T, Radix> {
|
|||||||
|
|
||||||
macro_rules! radix_fmt {
|
macro_rules! radix_fmt {
|
||||||
($T:ty as $U:ty, $fmt:ident, $S:expr) => {
|
($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 {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
try!(fmt::String::fmt(self, f));
|
fmt::Display::fmt(self, f)
|
||||||
f.write_str($S)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl fmt::String for RadixFmt<$T, Radix> {
|
#[stable]
|
||||||
|
impl fmt::Display for RadixFmt<$T, Radix> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match *self { RadixFmt(ref x, radix) => radix.$fmt(*x as $U, f) }
|
match *self { RadixFmt(ref x, radix) => radix.$fmt(*x as $U, f) }
|
||||||
}
|
}
|
||||||
@ -169,6 +170,7 @@ macro_rules! radix_fmt {
|
|||||||
}
|
}
|
||||||
macro_rules! int_base {
|
macro_rules! int_base {
|
||||||
($Trait:ident for $T:ident as $U:ident -> $Radix:ident) => {
|
($Trait:ident for $T:ident as $U:ident -> $Radix:ident) => {
|
||||||
|
#[stable]
|
||||||
impl fmt::$Trait for $T {
|
impl fmt::$Trait for $T {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
$Radix.fmt_int(*self as $U, f)
|
$Radix.fmt_int(*self as $U, f)
|
||||||
@ -179,10 +181,10 @@ macro_rules! int_base {
|
|||||||
|
|
||||||
macro_rules! show {
|
macro_rules! show {
|
||||||
($T:ident with $S:expr) => {
|
($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 {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
try!(fmt::String::fmt(self, f));
|
fmt::Display::fmt(self, f)
|
||||||
f.write_str($S)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -192,7 +194,7 @@ macro_rules! integer {
|
|||||||
integer! { $Int, $Uint, stringify!($Int), stringify!($Uint) }
|
integer! { $Int, $Uint, stringify!($Int), stringify!($Uint) }
|
||||||
};
|
};
|
||||||
($Int:ident, $Uint:ident, $SI:expr, $SU:expr) => {
|
($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! { Binary for $Int as $Uint -> Binary }
|
||||||
int_base! { Octal for $Int as $Uint -> Octal }
|
int_base! { Octal for $Int as $Uint -> Octal }
|
||||||
int_base! { LowerHex for $Int as $Uint -> LowerHex }
|
int_base! { LowerHex for $Int as $Uint -> LowerHex }
|
||||||
@ -200,7 +202,7 @@ macro_rules! integer {
|
|||||||
radix_fmt! { $Int as $Int, fmt_int, $SI }
|
radix_fmt! { $Int as $Int, fmt_int, $SI }
|
||||||
show! { $Int with $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! { Binary for $Uint as $Uint -> Binary }
|
||||||
int_base! { Octal for $Uint as $Uint -> Octal }
|
int_base! { Octal for $Uint as $Uint -> Octal }
|
||||||
int_base! { LowerHex for $Uint as $Uint -> LowerHex }
|
int_base! { LowerHex for $Uint as $Uint -> LowerHex }
|
||||||
|
@ -44,8 +44,6 @@
|
|||||||
|
|
||||||
use marker::Sized;
|
use marker::Sized;
|
||||||
|
|
||||||
#[cfg(stage0)] use any::TypeId;
|
|
||||||
|
|
||||||
pub type GlueFn = extern "Rust" fn(*const i8);
|
pub type GlueFn = extern "Rust" fn(*const i8);
|
||||||
|
|
||||||
#[lang="ty_desc"]
|
#[lang="ty_desc"]
|
||||||
@ -208,12 +206,8 @@ extern "rust-intrinsic" {
|
|||||||
/// Gets an identifier which is globally unique to the specified type. This
|
/// Gets an identifier which is globally unique to the specified type. This
|
||||||
/// function will return the same value for a type regardless of whichever
|
/// function will return the same value for a type regardless of whichever
|
||||||
/// crate it is invoked in.
|
/// crate it is invoked in.
|
||||||
#[cfg(not(stage0))]
|
|
||||||
pub fn type_id<T: ?Sized + 'static>() -> u64;
|
pub fn type_id<T: ?Sized + 'static>() -> u64;
|
||||||
|
|
||||||
#[cfg(stage0)]
|
|
||||||
pub fn type_id<T: ?Sized + 'static>() -> TypeId;
|
|
||||||
|
|
||||||
/// Create a value initialized to zero.
|
/// Create a value initialized to zero.
|
||||||
///
|
///
|
||||||
/// `init` is unsafe because it returns a zeroed-out datum,
|
/// `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) }
|
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`
|
/// Conversion from an `Iterator`
|
||||||
#[stable]
|
#[stable]
|
||||||
#[rustc_on_unimplemented="a collection of type `{Self}` cannot be \
|
#[rustc_on_unimplemented="a collection of type `{Self}` cannot be \
|
||||||
@ -2701,63 +2715,93 @@ impl<A: Int> Iterator for RangeStepInclusive<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
|
#[inline]
|
||||||
/// directions. The `steps_between` function provides a way to
|
fn next(&mut self) -> Option<$t> {
|
||||||
/// compare two Step objects (it could be provided using `step()` and `Ord`,
|
if self.start < self.end {
|
||||||
/// but the implementation would be so inefficient as to be useless).
|
let result = self.start;
|
||||||
#[unstable = "design of range notation/iteration is in flux"]
|
self.start += 1;
|
||||||
pub trait Step: Ord {
|
return Some(result);
|
||||||
/// 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>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! step_impl {
|
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! range_impl_no_hint {
|
||||||
($($t:ty)*) => ($(
|
($($t:ty)*) => ($(
|
||||||
#[unstable = "Trait is unstable."]
|
#[stable]
|
||||||
impl Step for $t {
|
impl Iterator for ::ops::Range<$t> {
|
||||||
|
type Item = $t;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn step(&mut self) { *self += 1; }
|
fn next(&mut self) -> Option<$t> {
|
||||||
#[inline]
|
if self.start < self.end {
|
||||||
fn step_back(&mut self) { *self -= 1; }
|
let result = self.start;
|
||||||
#[inline]
|
self.start += 1;
|
||||||
fn steps_between(start: &$t, end: &$t) -> Option<uint> {
|
return Some(result);
|
||||||
debug_assert!(end >= start);
|
}
|
||||||
Some((*end - *start) as uint)
|
|
||||||
|
return None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)*)
|
)*)
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! step_impl_no_between {
|
macro_rules! range_other_impls {
|
||||||
($($t:ty)*) => ($(
|
($($t:ty)*) => ($(
|
||||||
#[unstable = "Trait is unstable."]
|
#[stable]
|
||||||
impl Step for $t {
|
impl DoubleEndedIterator for ::ops::Range<$t> {
|
||||||
#[inline]
|
#[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]
|
#[inline]
|
||||||
fn step_back(&mut self) { *self -= 1; }
|
fn next(&mut self) -> Option<$t> {
|
||||||
#[inline]
|
let result = self.start;
|
||||||
fn steps_between(_start: &$t, _end: &$t) -> Option<uint> {
|
self.start += 1;
|
||||||
None
|
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")]
|
#[cfg(target_pointer_width = "64")]
|
||||||
step_impl!(u64 i64);
|
range_impl!(u64 i64);
|
||||||
#[cfg(target_pointer_width = "32")]
|
#[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
|
/// An iterator that repeats an element endlessly
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -63,6 +63,8 @@
|
|||||||
#![feature(unboxed_closures)]
|
#![feature(unboxed_closures)]
|
||||||
#![allow(unknown_features)] #![feature(int_uint)]
|
#![allow(unknown_features)] #![feature(int_uint)]
|
||||||
#![feature(on_unimplemented)]
|
#![feature(on_unimplemented)]
|
||||||
|
// FIXME(#21363) remove `old_impl_check` when bug is fixed
|
||||||
|
#![feature(old_impl_check)]
|
||||||
#![deny(missing_docs)]
|
#![deny(missing_docs)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
@ -136,6 +138,7 @@ pub mod slice;
|
|||||||
pub mod str;
|
pub mod str;
|
||||||
pub mod hash;
|
pub mod hash;
|
||||||
pub mod fmt;
|
pub mod fmt;
|
||||||
|
pub mod error;
|
||||||
|
|
||||||
// note: does not need to be public
|
// note: does not need to be public
|
||||||
mod tuple;
|
mod tuple;
|
||||||
|
@ -376,16 +376,6 @@ pub struct ContravariantLifetime<'a>;
|
|||||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub struct InvariantLifetime<'a>;
|
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
|
/// A type which is considered "not POD", meaning that it is not
|
||||||
/// implicitly copyable. This is typically embedded in other types to
|
/// implicitly copyable. This is typically embedded in other types to
|
||||||
/// ensure that they are never copied, even if they lack a destructor.
|
/// ensure that they are never copied, even if they lack a destructor.
|
||||||
@ -395,15 +385,6 @@ pub struct NoSend;
|
|||||||
#[allow(missing_copy_implementations)]
|
#[allow(missing_copy_implementations)]
|
||||||
pub struct NoCopy;
|
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
|
/// A type which is considered managed by the GC. This is typically
|
||||||
/// embedded in other types.
|
/// embedded in other types.
|
||||||
#[unstable = "likely to change with new variance strategy"]
|
#[unstable = "likely to change with new variance strategy"]
|
||||||
|
@ -33,8 +33,6 @@
|
|||||||
//! demonstrates adding and subtracting two `Point`s.
|
//! demonstrates adding and subtracting two `Point`s.
|
||||||
//!
|
//!
|
||||||
//! ```rust
|
//! ```rust
|
||||||
//! #![feature(associated_types)]
|
|
||||||
//!
|
|
||||||
//! use std::ops::{Add, Sub};
|
//! use std::ops::{Add, Sub};
|
||||||
//!
|
//!
|
||||||
//! #[derive(Show)]
|
//! #[derive(Show)]
|
||||||
@ -69,10 +67,7 @@
|
|||||||
|
|
||||||
#![stable]
|
#![stable]
|
||||||
|
|
||||||
use clone::Clone;
|
|
||||||
use iter::{Step, Iterator,DoubleEndedIterator,ExactSizeIterator};
|
|
||||||
use marker::Sized;
|
use marker::Sized;
|
||||||
use option::Option::{self, Some, None};
|
|
||||||
use fmt;
|
use fmt;
|
||||||
|
|
||||||
/// The `Drop` trait is used to run some code when a value goes out of scope. This
|
/// The `Drop` trait is used to run some code when a value goes out of scope. This
|
||||||
@ -164,8 +159,6 @@ macro_rules! forward_ref_binop {
|
|||||||
/// calling `add`, and therefore, `main` prints `Adding!`.
|
/// calling `add`, and therefore, `main` prints `Adding!`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// #![feature(associated_types)]
|
|
||||||
///
|
|
||||||
/// use std::ops::Add;
|
/// use std::ops::Add;
|
||||||
///
|
///
|
||||||
/// #[derive(Copy)]
|
/// #[derive(Copy)]
|
||||||
@ -219,8 +212,6 @@ add_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 }
|
|||||||
/// calling `sub`, and therefore, `main` prints `Subtracting!`.
|
/// calling `sub`, and therefore, `main` prints `Subtracting!`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// #![feature(associated_types)]
|
|
||||||
///
|
|
||||||
/// use std::ops::Sub;
|
/// use std::ops::Sub;
|
||||||
///
|
///
|
||||||
/// #[derive(Copy)]
|
/// #[derive(Copy)]
|
||||||
@ -274,8 +265,6 @@ sub_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 }
|
|||||||
/// calling `mul`, and therefore, `main` prints `Multiplying!`.
|
/// calling `mul`, and therefore, `main` prints `Multiplying!`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// #![feature(associated_types)]
|
|
||||||
///
|
|
||||||
/// use std::ops::Mul;
|
/// use std::ops::Mul;
|
||||||
///
|
///
|
||||||
/// #[derive(Copy)]
|
/// #[derive(Copy)]
|
||||||
@ -329,8 +318,6 @@ mul_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 }
|
|||||||
/// calling `div`, and therefore, `main` prints `Dividing!`.
|
/// calling `div`, and therefore, `main` prints `Dividing!`.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(associated_types)]
|
|
||||||
///
|
|
||||||
/// use std::ops::Div;
|
/// use std::ops::Div;
|
||||||
///
|
///
|
||||||
/// #[derive(Copy)]
|
/// #[derive(Copy)]
|
||||||
@ -384,8 +371,6 @@ div_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 }
|
|||||||
/// calling `rem`, and therefore, `main` prints `Remainder-ing!`.
|
/// calling `rem`, and therefore, `main` prints `Remainder-ing!`.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(associated_types)]
|
|
||||||
///
|
|
||||||
/// use std::ops::Rem;
|
/// use std::ops::Rem;
|
||||||
///
|
///
|
||||||
/// #[derive(Copy)]
|
/// #[derive(Copy)]
|
||||||
@ -458,8 +443,6 @@ rem_float_impl! { f64, fmod }
|
|||||||
/// `neg`, and therefore, `main` prints `Negating!`.
|
/// `neg`, and therefore, `main` prints `Negating!`.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(associated_types)]
|
|
||||||
///
|
|
||||||
/// use std::ops::Neg;
|
/// use std::ops::Neg;
|
||||||
///
|
///
|
||||||
/// struct Foo;
|
/// struct Foo;
|
||||||
@ -537,8 +520,6 @@ neg_uint_impl! { u64, i64 }
|
|||||||
/// `not`, and therefore, `main` prints `Not-ing!`.
|
/// `not`, and therefore, `main` prints `Not-ing!`.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(associated_types)]
|
|
||||||
///
|
|
||||||
/// use std::ops::Not;
|
/// use std::ops::Not;
|
||||||
///
|
///
|
||||||
/// struct Foo;
|
/// struct Foo;
|
||||||
@ -593,8 +574,6 @@ not_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 }
|
|||||||
/// calling `bitand`, and therefore, `main` prints `Bitwise And-ing!`.
|
/// calling `bitand`, and therefore, `main` prints `Bitwise And-ing!`.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(associated_types)]
|
|
||||||
///
|
|
||||||
/// use std::ops::BitAnd;
|
/// use std::ops::BitAnd;
|
||||||
///
|
///
|
||||||
/// #[derive(Copy)]
|
/// #[derive(Copy)]
|
||||||
@ -648,8 +627,6 @@ bitand_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 }
|
|||||||
/// calling `bitor`, and therefore, `main` prints `Bitwise Or-ing!`.
|
/// calling `bitor`, and therefore, `main` prints `Bitwise Or-ing!`.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(associated_types)]
|
|
||||||
///
|
|
||||||
/// use std::ops::BitOr;
|
/// use std::ops::BitOr;
|
||||||
///
|
///
|
||||||
/// #[derive(Copy)]
|
/// #[derive(Copy)]
|
||||||
@ -703,8 +680,6 @@ bitor_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 }
|
|||||||
/// calling `bitxor`, and therefore, `main` prints `Bitwise Xor-ing!`.
|
/// calling `bitxor`, and therefore, `main` prints `Bitwise Xor-ing!`.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(associated_types)]
|
|
||||||
///
|
|
||||||
/// use std::ops::BitXor;
|
/// use std::ops::BitXor;
|
||||||
///
|
///
|
||||||
/// #[derive(Copy)]
|
/// #[derive(Copy)]
|
||||||
@ -758,8 +733,6 @@ bitxor_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 }
|
|||||||
/// calling `shl`, and therefore, `main` prints `Shifting left!`.
|
/// calling `shl`, and therefore, `main` prints `Shifting left!`.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(associated_types)]
|
|
||||||
///
|
|
||||||
/// use std::ops::Shl;
|
/// use std::ops::Shl;
|
||||||
///
|
///
|
||||||
/// #[derive(Copy)]
|
/// #[derive(Copy)]
|
||||||
@ -831,8 +804,6 @@ shl_impl_all! { u8 u16 u32 u64 usize i8 i16 i32 i64 isize }
|
|||||||
/// calling `shr`, and therefore, `main` prints `Shifting right!`.
|
/// calling `shr`, and therefore, `main` prints `Shifting right!`.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(associated_types)]
|
|
||||||
///
|
|
||||||
/// use std::ops::Shr;
|
/// use std::ops::Shr;
|
||||||
///
|
///
|
||||||
/// #[derive(Copy)]
|
/// #[derive(Copy)]
|
||||||
@ -924,10 +895,12 @@ shr_impl_all! { u8 u16 u32 u64 usize i8 i16 i32 i64 isize }
|
|||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[lang="index"]
|
#[lang="index"]
|
||||||
|
#[stable]
|
||||||
pub trait Index<Index: ?Sized> {
|
pub trait Index<Index: ?Sized> {
|
||||||
type Output: ?Sized;
|
type Output: ?Sized;
|
||||||
|
|
||||||
/// The method for the indexing (`Foo[Bar]`) operation
|
/// The method for the indexing (`Foo[Bar]`) operation
|
||||||
|
#[stable]
|
||||||
fn index<'a>(&'a self, index: &Index) -> &'a Self::Output;
|
fn index<'a>(&'a self, index: &Index) -> &'a Self::Output;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -960,30 +933,32 @@ pub trait Index<Index: ?Sized> {
|
|||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[lang="index_mut"]
|
#[lang="index_mut"]
|
||||||
|
#[stable]
|
||||||
pub trait IndexMut<Index: ?Sized> {
|
pub trait IndexMut<Index: ?Sized> {
|
||||||
type Output: ?Sized;
|
type Output: ?Sized;
|
||||||
|
|
||||||
/// The method for the indexing (`Foo[Bar]`) operation
|
/// The method for the indexing (`Foo[Bar]`) operation
|
||||||
|
#[stable]
|
||||||
fn index_mut<'a>(&'a mut self, index: &Index) -> &'a mut Self::Output;
|
fn index_mut<'a>(&'a mut self, index: &Index) -> &'a mut Self::Output;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An unbounded range.
|
/// An unbounded range.
|
||||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||||
#[lang="full_range"]
|
#[lang="full_range"]
|
||||||
#[unstable = "API still in development"]
|
#[unstable = "may be renamed to RangeFull"]
|
||||||
pub struct FullRange;
|
pub struct FullRange;
|
||||||
|
|
||||||
#[unstable = "API still in development"]
|
#[stable]
|
||||||
impl fmt::Show for FullRange {
|
impl fmt::Debug for FullRange {
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
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.
|
/// A (half-open) range which is bounded at both ends.
|
||||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||||
#[lang="range"]
|
#[lang="range"]
|
||||||
#[unstable = "API still in development"]
|
#[stable]
|
||||||
pub struct Range<Idx> {
|
pub struct Range<Idx> {
|
||||||
/// The lower bound of the range (inclusive).
|
/// The lower bound of the range (inclusive).
|
||||||
pub start: Idx,
|
pub start: Idx,
|
||||||
@ -991,49 +966,8 @@ pub struct Range<Idx> {
|
|||||||
pub end: Idx,
|
pub end: Idx,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable = "API still in development"]
|
#[stable]
|
||||||
impl<Idx: Clone + Step> Iterator for Range<Idx> {
|
impl<Idx: fmt::Debug> fmt::Debug 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> {
|
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(fmt, "{:?}..{:?}", self.start, self.end)
|
write!(fmt, "{:?}..{:?}", self.start, self.end)
|
||||||
}
|
}
|
||||||
@ -1042,27 +976,16 @@ impl<Idx: fmt::Show> fmt::Show for Range<Idx> {
|
|||||||
/// A range which is only bounded below.
|
/// A range which is only bounded below.
|
||||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||||
#[lang="range_from"]
|
#[lang="range_from"]
|
||||||
#[unstable = "API still in development"]
|
#[stable]
|
||||||
pub struct RangeFrom<Idx> {
|
pub struct RangeFrom<Idx> {
|
||||||
/// The lower bound of the range (inclusive).
|
/// The lower bound of the range (inclusive).
|
||||||
pub start: Idx,
|
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"]
|
#[stable]
|
||||||
impl<Idx: fmt::Show> fmt::Show for RangeFrom<Idx> {
|
impl<Idx: fmt::Debug> fmt::Debug for RangeFrom<Idx> {
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(fmt, "{:?}..", self.start)
|
write!(fmt, "{:?}..", self.start)
|
||||||
}
|
}
|
||||||
@ -1071,14 +994,14 @@ impl<Idx: fmt::Show> fmt::Show for RangeFrom<Idx> {
|
|||||||
/// A range which is only bounded above.
|
/// A range which is only bounded above.
|
||||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||||
#[lang="range_to"]
|
#[lang="range_to"]
|
||||||
#[unstable = "API still in development"]
|
#[stable]
|
||||||
pub struct RangeTo<Idx> {
|
pub struct RangeTo<Idx> {
|
||||||
/// The upper bound of the range (exclusive).
|
/// The upper bound of the range (exclusive).
|
||||||
pub end: Idx,
|
pub end: Idx,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable = "API still in development"]
|
#[stable]
|
||||||
impl<Idx: fmt::Show> fmt::Show for RangeTo<Idx> {
|
impl<Idx: fmt::Debug> fmt::Debug for RangeTo<Idx> {
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(fmt, "..{:?}", self.end)
|
write!(fmt, "..{:?}", self.end)
|
||||||
}
|
}
|
||||||
@ -1094,8 +1017,6 @@ impl<Idx: fmt::Show> fmt::Show for RangeTo<Idx> {
|
|||||||
/// struct.
|
/// struct.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(associated_types)]
|
|
||||||
///
|
|
||||||
/// use std::ops::Deref;
|
/// use std::ops::Deref;
|
||||||
///
|
///
|
||||||
/// struct DerefExample<T> {
|
/// struct DerefExample<T> {
|
||||||
@ -1149,8 +1070,6 @@ impl<'a, T: ?Sized> Deref for &'a mut T {
|
|||||||
/// struct.
|
/// struct.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(associated_types)]
|
|
||||||
///
|
|
||||||
/// use std::ops::{Deref, DerefMut};
|
/// use std::ops::{Deref, DerefMut};
|
||||||
///
|
///
|
||||||
/// struct DerefMutExample<T> {
|
/// struct DerefMutExample<T> {
|
||||||
|
@ -229,7 +229,7 @@
|
|||||||
use self::Result::{Ok, Err};
|
use self::Result::{Ok, Err};
|
||||||
|
|
||||||
use clone::Clone;
|
use clone::Clone;
|
||||||
use fmt::Show;
|
use fmt::Display;
|
||||||
use iter::{Iterator, IteratorExt, DoubleEndedIterator, FromIterator, ExactSizeIterator};
|
use iter::{Iterator, IteratorExt, DoubleEndedIterator, FromIterator, ExactSizeIterator};
|
||||||
use ops::{FnMut, FnOnce};
|
use ops::{FnMut, FnOnce};
|
||||||
use option::Option::{self, None, Some};
|
use option::Option::{self, None, Some};
|
||||||
@ -714,7 +714,7 @@ impl<T, E> Result<T, E> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[stable]
|
#[stable]
|
||||||
impl<T, E: Show> Result<T, E> {
|
impl<T, E: Display> Result<T, E> {
|
||||||
/// Unwraps a result, yielding the content of an `Ok`.
|
/// Unwraps a result, yielding the content of an `Ok`.
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
@ -739,13 +739,13 @@ impl<T, E: Show> Result<T, E> {
|
|||||||
match self {
|
match self {
|
||||||
Ok(t) => t,
|
Ok(t) => t,
|
||||||
Err(e) =>
|
Err(e) =>
|
||||||
panic!("called `Result::unwrap()` on an `Err` value: {:?}", e)
|
panic!("called `Result::unwrap()` on an `Err` value: {}", e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable]
|
#[stable]
|
||||||
impl<T: Show, E> Result<T, E> {
|
impl<T: Display, E> Result<T, E> {
|
||||||
/// Unwraps a result, yielding the content of an `Err`.
|
/// Unwraps a result, yielding the content of an `Err`.
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
@ -769,7 +769,7 @@ impl<T: Show, E> Result<T, E> {
|
|||||||
pub fn unwrap_err(self) -> E {
|
pub fn unwrap_err(self) -> E {
|
||||||
match self {
|
match self {
|
||||||
Ok(t) =>
|
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
|
Err(e) => e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,9 +67,6 @@ use raw::Slice as RawSlice;
|
|||||||
pub trait SliceExt {
|
pub trait SliceExt {
|
||||||
type Item;
|
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 split_at<'a>(&'a self, mid: uint) -> (&'a [Self::Item], &'a [Self::Item]);
|
||||||
fn iter<'a>(&'a self) -> Iter<'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>
|
fn split<'a, P>(&'a self, pred: P) -> Split<'a, Self::Item, P>
|
||||||
@ -93,9 +90,6 @@ pub trait SliceExt {
|
|||||||
fn is_empty(&self) -> bool { self.len() == 0 }
|
fn is_empty(&self) -> bool { self.len() == 0 }
|
||||||
fn get_mut<'a>(&'a mut self, index: uint) -> Option<&'a mut Self::Item>;
|
fn get_mut<'a>(&'a mut self, index: uint) -> Option<&'a mut Self::Item>;
|
||||||
fn as_mut_slice<'a>(&'a mut self) -> &'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 iter_mut<'a>(&'a mut self) -> IterMut<'a, Self::Item>;
|
||||||
fn first_mut<'a>(&'a mut self) -> Option<&'a mut 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];
|
fn tail_mut<'a>(&'a mut self) -> &'a mut [Self::Item];
|
||||||
@ -135,28 +129,6 @@ pub trait SliceExt {
|
|||||||
impl<T> SliceExt for [T] {
|
impl<T> SliceExt for [T] {
|
||||||
type Item = 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]
|
#[inline]
|
||||||
fn split_at(&self, mid: uint) -> (&[T], &[T]) {
|
fn split_at(&self, mid: uint) -> (&[T], &[T]) {
|
||||||
(&self[..mid], &self[mid..])
|
(&self[..mid], &self[mid..])
|
||||||
@ -240,7 +212,7 @@ impl<T> SliceExt for [T] {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn init(&self) -> &[T] {
|
fn init(&self) -> &[T] {
|
||||||
&self[..(self.len() - 1)]
|
&self[..self.len() - 1]
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -291,20 +263,6 @@ impl<T> SliceExt for [T] {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn as_mut_slice(&mut self) -> &mut [T] { self }
|
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]
|
#[inline]
|
||||||
fn split_at_mut(&mut self, mid: uint) -> (&mut [T], &mut [T]) {
|
fn split_at_mut(&mut self, mid: uint) -> (&mut [T], &mut [T]) {
|
||||||
unsafe {
|
unsafe {
|
||||||
@ -345,13 +303,13 @@ impl<T> SliceExt for [T] {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn tail_mut(&mut self) -> &mut [T] {
|
fn tail_mut(&mut self) -> &mut [T] {
|
||||||
self.slice_from_mut(1)
|
&mut self[1 ..]
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn init_mut(&mut self) -> &mut [T] {
|
fn init_mut(&mut self) -> &mut [T] {
|
||||||
let len = self.len();
|
let len = self.len();
|
||||||
self.slice_to_mut(len-1)
|
&mut self[.. (len - 1)]
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -449,7 +407,7 @@ impl<T> SliceExt for [T] {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn ends_with(&self, needle: &[T]) -> bool where T: PartialEq {
|
fn ends_with(&self, needle: &[T]) -> bool where T: PartialEq {
|
||||||
let (m, n) = (self.len(), needle.len());
|
let (m, n) = (self.len(), needle.len());
|
||||||
m >= n && needle == &self[(m-n)..]
|
m >= n && needle == &self[m-n..]
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable]
|
#[unstable]
|
||||||
@ -483,7 +441,7 @@ impl<T> SliceExt for [T] {
|
|||||||
self.swap(j, i-1);
|
self.swap(j, i-1);
|
||||||
|
|
||||||
// Step 4: Reverse the (previously) weakly decreasing part
|
// Step 4: Reverse the (previously) weakly decreasing part
|
||||||
self.slice_from_mut(i).reverse();
|
self[i..].reverse();
|
||||||
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
@ -505,7 +463,7 @@ impl<T> SliceExt for [T] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Step 2: Reverse the weakly increasing part
|
// 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)
|
// Step 3: Find the rightmost element equal to or bigger than the pivot (i-1)
|
||||||
let mut j = self.len() - 1;
|
let mut j = self.len() - 1;
|
||||||
@ -522,8 +480,8 @@ impl<T> SliceExt for [T] {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn clone_from_slice(&mut self, src: &[T]) -> uint where T: Clone {
|
fn clone_from_slice(&mut self, src: &[T]) -> uint where T: Clone {
|
||||||
let min = cmp::min(self.len(), src.len());
|
let min = cmp::min(self.len(), src.len());
|
||||||
let dst = self.slice_to_mut(min);
|
let dst = &mut self[.. min];
|
||||||
let src = src.slice_to(min);
|
let src = &src[.. min];
|
||||||
for i in range(0, min) {
|
for i in range(0, min) {
|
||||||
dst[i].clone_from(&src[i]);
|
dst[i].clone_from(&src[i]);
|
||||||
}
|
}
|
||||||
@ -531,6 +489,7 @@ impl<T> SliceExt for [T] {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[stable]
|
||||||
impl<T> ops::Index<uint> for [T] {
|
impl<T> ops::Index<uint> for [T] {
|
||||||
type Output = T;
|
type Output = T;
|
||||||
|
|
||||||
@ -541,6 +500,7 @@ impl<T> ops::Index<uint> for [T] {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[stable]
|
||||||
impl<T> ops::IndexMut<uint> for [T] {
|
impl<T> ops::IndexMut<uint> for [T] {
|
||||||
type Output = T;
|
type Output = T;
|
||||||
|
|
||||||
@ -551,6 +511,7 @@ impl<T> ops::IndexMut<uint> for [T] {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[stable]
|
||||||
impl<T> ops::Index<ops::Range<uint>> for [T] {
|
impl<T> ops::Index<ops::Range<uint>> for [T] {
|
||||||
type Output = [T];
|
type Output = [T];
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -565,6 +526,7 @@ impl<T> ops::Index<ops::Range<uint>> for [T] {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[stable]
|
||||||
impl<T> ops::Index<ops::RangeTo<uint>> for [T] {
|
impl<T> ops::Index<ops::RangeTo<uint>> for [T] {
|
||||||
type Output = [T];
|
type Output = [T];
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -572,6 +534,7 @@ impl<T> ops::Index<ops::RangeTo<uint>> for [T] {
|
|||||||
self.index(&ops::Range{ start: 0, end: index.end })
|
self.index(&ops::Range{ start: 0, end: index.end })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[stable]
|
||||||
impl<T> ops::Index<ops::RangeFrom<uint>> for [T] {
|
impl<T> ops::Index<ops::RangeFrom<uint>> for [T] {
|
||||||
type Output = [T];
|
type Output = [T];
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -579,6 +542,7 @@ impl<T> ops::Index<ops::RangeFrom<uint>> for [T] {
|
|||||||
self.index(&ops::Range{ start: index.start, end: self.len() })
|
self.index(&ops::Range{ start: index.start, end: self.len() })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[stable]
|
||||||
impl<T> ops::Index<ops::FullRange> for [T] {
|
impl<T> ops::Index<ops::FullRange> for [T] {
|
||||||
type Output = [T];
|
type Output = [T];
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -587,6 +551,7 @@ impl<T> ops::Index<ops::FullRange> for [T] {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[stable]
|
||||||
impl<T> ops::IndexMut<ops::Range<uint>> for [T] {
|
impl<T> ops::IndexMut<ops::Range<uint>> for [T] {
|
||||||
type Output = [T];
|
type Output = [T];
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -601,6 +566,7 @@ impl<T> ops::IndexMut<ops::Range<uint>> for [T] {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[stable]
|
||||||
impl<T> ops::IndexMut<ops::RangeTo<uint>> for [T] {
|
impl<T> ops::IndexMut<ops::RangeTo<uint>> for [T] {
|
||||||
type Output = [T];
|
type Output = [T];
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -608,6 +574,7 @@ impl<T> ops::IndexMut<ops::RangeTo<uint>> for [T] {
|
|||||||
self.index_mut(&ops::Range{ start: 0, end: index.end })
|
self.index_mut(&ops::Range{ start: 0, end: index.end })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[stable]
|
||||||
impl<T> ops::IndexMut<ops::RangeFrom<uint>> for [T] {
|
impl<T> ops::IndexMut<ops::RangeFrom<uint>> for [T] {
|
||||||
type Output = [T];
|
type Output = [T];
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -616,6 +583,7 @@ impl<T> ops::IndexMut<ops::RangeFrom<uint>> for [T] {
|
|||||||
self.index_mut(&ops::Range{ start: index.start, end: len })
|
self.index_mut(&ops::Range{ start: index.start, end: len })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[stable]
|
||||||
impl<T> ops::IndexMut<ops::FullRange> for [T] {
|
impl<T> ops::IndexMut<ops::FullRange> for [T] {
|
||||||
type Output = [T];
|
type Output = [T];
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -973,7 +941,7 @@ impl<'a, T, P> Iterator for Split<'a, T, P> where P: FnMut(&T) -> bool {
|
|||||||
None => self.finish(),
|
None => self.finish(),
|
||||||
Some(idx) => {
|
Some(idx) => {
|
||||||
let ret = Some(&self.v[..idx]);
|
let ret = Some(&self.v[..idx]);
|
||||||
self.v = &self.v[(idx + 1)..];
|
self.v = &self.v[idx + 1..];
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -998,7 +966,7 @@ impl<'a, T, P> DoubleEndedIterator for Split<'a, T, P> where P: FnMut(&T) -> boo
|
|||||||
match self.v.iter().rposition(|x| (self.pred)(x)) {
|
match self.v.iter().rposition(|x| (self.pred)(x)) {
|
||||||
None => self.finish(),
|
None => self.finish(),
|
||||||
Some(idx) => {
|
Some(idx) => {
|
||||||
let ret = Some(&self.v[(idx + 1)..]);
|
let ret = Some(&self.v[idx + 1..]);
|
||||||
self.v = &self.v[..idx];
|
self.v = &self.v[..idx];
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
@ -1051,7 +1019,7 @@ impl<'a, T, P> Iterator for SplitMut<'a, T, P> where P: FnMut(&T) -> bool {
|
|||||||
Some(idx) => {
|
Some(idx) => {
|
||||||
let tmp = mem::replace(&mut self.v, &mut []);
|
let tmp = mem::replace(&mut self.v, &mut []);
|
||||||
let (head, tail) = tmp.split_at_mut(idx);
|
let (head, tail) = tmp.split_at_mut(idx);
|
||||||
self.v = tail.slice_from_mut(1);
|
self.v = &mut tail[1..];
|
||||||
Some(head)
|
Some(head)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1087,7 +1055,7 @@ impl<'a, T, P> DoubleEndedIterator for SplitMut<'a, T, P> where
|
|||||||
let tmp = mem::replace(&mut self.v, &mut []);
|
let tmp = mem::replace(&mut self.v, &mut []);
|
||||||
let (head, tail) = tmp.split_at_mut(idx);
|
let (head, tail) = tmp.split_at_mut(idx);
|
||||||
self.v = head;
|
self.v = head;
|
||||||
Some(tail.slice_from_mut(1))
|
Some(&mut tail[1..])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1269,6 +1237,9 @@ impl<'a, T> DoubleEndedIterator for Chunks<'a, T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[stable]
|
||||||
|
impl<'a, T> ExactSizeIterator for Chunks<'a, T> {}
|
||||||
|
|
||||||
#[unstable = "trait is experimental"]
|
#[unstable = "trait is experimental"]
|
||||||
impl<'a, T> RandomAccessIterator for Chunks<'a, T> {
|
impl<'a, T> RandomAccessIterator for Chunks<'a, T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -1347,6 +1318,8 @@ impl<'a, T> DoubleEndedIterator for ChunksMut<'a, T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[stable]
|
||||||
|
impl<'a, T> ExactSizeIterator for ChunksMut<'a, T> {}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Free functions
|
// Free functions
|
||||||
|
@ -20,8 +20,10 @@ use self::Searcher::{Naive, TwoWay, TwoWayLong};
|
|||||||
|
|
||||||
use cmp::{self, Eq};
|
use cmp::{self, Eq};
|
||||||
use default::Default;
|
use default::Default;
|
||||||
use iter::range;
|
use error::Error;
|
||||||
|
use fmt;
|
||||||
use iter::ExactSizeIterator;
|
use iter::ExactSizeIterator;
|
||||||
|
use iter::range;
|
||||||
use iter::{Map, Iterator, IteratorExt, DoubleEndedIterator};
|
use iter::{Map, Iterator, IteratorExt, DoubleEndedIterator};
|
||||||
use marker::Sized;
|
use marker::Sized;
|
||||||
use mem;
|
use mem;
|
||||||
@ -242,6 +244,30 @@ impl<'a> CharEq for &'a [char] {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[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
|
Section: Iterators
|
||||||
*/
|
*/
|
||||||
@ -902,13 +928,13 @@ impl<'a> Iterator for SplitStr<'a> {
|
|||||||
|
|
||||||
match self.it.next() {
|
match self.it.next() {
|
||||||
Some((from, to)) => {
|
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;
|
self.last_end = to;
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
self.finished = true;
|
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 @@ mod traits {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 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 {
|
impl ops::Index<ops::Range<uint>> for str {
|
||||||
type Output = str;
|
type Output = str;
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index(&self, index: &ops::Range<uint>) -> &str {
|
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 {
|
impl ops::Index<ops::RangeTo<uint>> for str {
|
||||||
type Output = str;
|
type Output = str;
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index(&self, index: &ops::RangeTo<uint>) -> &str {
|
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 {
|
impl ops::Index<ops::RangeFrom<uint>> for str {
|
||||||
type Output = str;
|
type Output = str;
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index(&self, index: &ops::RangeFrom<uint>) -> &str {
|
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 {
|
impl ops::Index<ops::FullRange> for str {
|
||||||
type Output = str;
|
type Output = str;
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -1147,7 +1236,7 @@ mod traits {
|
|||||||
|
|
||||||
/// Any string that can be represented as a slice
|
/// Any string that can be represented as a slice
|
||||||
#[unstable = "Instead of taking this bound generically, this trait will be \
|
#[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"]
|
a more generic conversion trait"]
|
||||||
pub trait Str {
|
pub trait Str {
|
||||||
/// Work with `self` as a slice.
|
/// Work with `self` as a slice.
|
||||||
@ -1208,9 +1297,6 @@ pub trait StrExt {
|
|||||||
fn lines<'a>(&'a self) -> Lines<'a>;
|
fn lines<'a>(&'a self) -> Lines<'a>;
|
||||||
fn lines_any<'a>(&'a self) -> LinesAny<'a>;
|
fn lines_any<'a>(&'a self) -> LinesAny<'a>;
|
||||||
fn char_len(&self) -> uint;
|
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;
|
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;
|
unsafe fn slice_unchecked<'a>(&'a self, begin: uint, end: uint) -> &'a str;
|
||||||
fn starts_with(&self, pat: &str) -> bool;
|
fn starts_with(&self, pat: &str) -> bool;
|
||||||
@ -1332,7 +1418,7 @@ impl StrExt for str {
|
|||||||
fn lines_any(&self) -> LinesAny {
|
fn lines_any(&self) -> LinesAny {
|
||||||
fn f(line: &str) -> &str {
|
fn f(line: &str) -> &str {
|
||||||
let l = line.len();
|
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 }
|
else { line }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1343,38 +1429,6 @@ impl StrExt for str {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn char_len(&self) -> uint { self.chars().count() }
|
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 {
|
fn slice_chars(&self, begin: uint, end: uint) -> &str {
|
||||||
assert!(begin <= end);
|
assert!(begin <= end);
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
@ -1415,7 +1469,7 @@ impl StrExt for str {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn ends_with(&self, needle: &str) -> bool {
|
fn ends_with(&self, needle: &str) -> bool {
|
||||||
let (m, n) = (self.len(), needle.len());
|
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]
|
#[inline]
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
#![allow(deprecated)]
|
||||||
|
|
||||||
use core::finally::{try_finally, Finally};
|
use core::finally::{try_finally, Finally};
|
||||||
use std::thread::Thread;
|
use std::thread::Thread;
|
||||||
|
|
||||||
|
@ -26,11 +26,11 @@ fn test_format_int() {
|
|||||||
assert!(format!("{}", -1i16) == "-1");
|
assert!(format!("{}", -1i16) == "-1");
|
||||||
assert!(format!("{}", -1i32) == "-1");
|
assert!(format!("{}", -1i32) == "-1");
|
||||||
assert!(format!("{}", -1i64) == "-1");
|
assert!(format!("{}", -1i64) == "-1");
|
||||||
assert!(format!("{:?}", 1i) == "1i");
|
assert!(format!("{:?}", 1i) == "1");
|
||||||
assert!(format!("{:?}", 1i8) == "1i8");
|
assert!(format!("{:?}", 1i8) == "1");
|
||||||
assert!(format!("{:?}", 1i16) == "1i16");
|
assert!(format!("{:?}", 1i16) == "1");
|
||||||
assert!(format!("{:?}", 1i32) == "1i32");
|
assert!(format!("{:?}", 1i32) == "1");
|
||||||
assert!(format!("{:?}", 1i64) == "1i64");
|
assert!(format!("{:?}", 1i64) == "1");
|
||||||
assert!(format!("{:b}", 1i) == "1");
|
assert!(format!("{:b}", 1i) == "1");
|
||||||
assert!(format!("{:b}", 1i8) == "1");
|
assert!(format!("{:b}", 1i8) == "1");
|
||||||
assert!(format!("{:b}", 1i16) == "1");
|
assert!(format!("{:b}", 1i16) == "1");
|
||||||
@ -57,11 +57,11 @@ fn test_format_int() {
|
|||||||
assert!(format!("{}", 1u16) == "1");
|
assert!(format!("{}", 1u16) == "1");
|
||||||
assert!(format!("{}", 1u32) == "1");
|
assert!(format!("{}", 1u32) == "1");
|
||||||
assert!(format!("{}", 1u64) == "1");
|
assert!(format!("{}", 1u64) == "1");
|
||||||
assert!(format!("{:?}", 1u) == "1u");
|
assert!(format!("{:?}", 1u) == "1");
|
||||||
assert!(format!("{:?}", 1u8) == "1u8");
|
assert!(format!("{:?}", 1u8) == "1");
|
||||||
assert!(format!("{:?}", 1u16) == "1u16");
|
assert!(format!("{:?}", 1u16) == "1");
|
||||||
assert!(format!("{:?}", 1u32) == "1u32");
|
assert!(format!("{:?}", 1u32) == "1");
|
||||||
assert!(format!("{:?}", 1u64) == "1u64");
|
assert!(format!("{:?}", 1u64) == "1");
|
||||||
assert!(format!("{:b}", 1u) == "1");
|
assert!(format!("{:b}", 1u) == "1");
|
||||||
assert!(format!("{:b}", 1u8) == "1");
|
assert!(format!("{:b}", 1u8) == "1");
|
||||||
assert!(format!("{:b}", 1u16) == "1");
|
assert!(format!("{:b}", 1u16) == "1");
|
||||||
@ -94,14 +94,14 @@ fn test_format_int() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_format_int_zero() {
|
fn test_format_int_zero() {
|
||||||
assert!(format!("{}", 0i) == "0");
|
assert!(format!("{}", 0i) == "0");
|
||||||
assert!(format!("{:?}", 0i) == "0i");
|
assert!(format!("{:?}", 0i) == "0");
|
||||||
assert!(format!("{:b}", 0i) == "0");
|
assert!(format!("{:b}", 0i) == "0");
|
||||||
assert!(format!("{:o}", 0i) == "0");
|
assert!(format!("{:o}", 0i) == "0");
|
||||||
assert!(format!("{:x}", 0i) == "0");
|
assert!(format!("{:x}", 0i) == "0");
|
||||||
assert!(format!("{:X}", 0i) == "0");
|
assert!(format!("{:X}", 0i) == "0");
|
||||||
|
|
||||||
assert!(format!("{}", 0u) == "0");
|
assert!(format!("{}", 0u) == "0");
|
||||||
assert!(format!("{:?}", 0u) == "0u");
|
assert!(format!("{:?}", 0u) == "0");
|
||||||
assert!(format!("{:b}", 0u) == "0");
|
assert!(format!("{:b}", 0u) == "0");
|
||||||
assert!(format!("{:o}", 0u) == "0");
|
assert!(format!("{:o}", 0u) == "0");
|
||||||
assert!(format!("{:x}", 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() {
|
fn test_double_ended_flat_map() {
|
||||||
let u = [0u,1];
|
let u = [0u,1];
|
||||||
let v = [5u,6,7,8];
|
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_back().unwrap(), &8);
|
||||||
assert_eq!(it.next().unwrap(), &5);
|
assert_eq!(it.next().unwrap(), &5);
|
||||||
assert_eq!(it.next_back().unwrap(), &7);
|
assert_eq!(it.next_back().unwrap(), &7);
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
use core::cmp::PartialEq;
|
use core::cmp::PartialEq;
|
||||||
use core::fmt::Show;
|
use core::fmt::Debug;
|
||||||
use core::num::{NumCast, cast};
|
use core::num::{NumCast, cast};
|
||||||
use core::ops::{Add, Sub, Mul, Div, Rem};
|
use core::ops::{Add, Sub, Mul, Div, Rem};
|
||||||
use core::marker::Copy;
|
use core::marker::Copy;
|
||||||
@ -37,7 +37,7 @@ pub fn test_num<T>(ten: T, two: T) where
|
|||||||
T: PartialEq + NumCast
|
T: PartialEq + NumCast
|
||||||
+ Add<Output=T> + Sub<Output=T>
|
+ Add<Output=T> + Sub<Output=T>
|
||||||
+ Mul<Output=T> + Div<Output=T>
|
+ Mul<Output=T> + Div<Output=T>
|
||||||
+ Rem<Output=T> + Show
|
+ Rem<Output=T> + Debug
|
||||||
+ Copy
|
+ Copy
|
||||||
{
|
{
|
||||||
assert_eq!(ten.add(two), cast(12i).unwrap());
|
assert_eq!(ten.add(two), cast(12i).unwrap());
|
||||||
|
@ -14,11 +14,11 @@ pub fn op2() -> Result<int, &'static str> { Err("sadface") }
|
|||||||
#[test]
|
#[test]
|
||||||
pub fn test_and() {
|
pub fn test_and() {
|
||||||
assert_eq!(op1().and(Ok(667i)).unwrap(), 667);
|
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");
|
"bad");
|
||||||
|
|
||||||
assert_eq!(op2().and(Ok(667i)).unwrap_err(), "sadface");
|
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");
|
"sadface");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ pub fn test_fmt_default() {
|
|||||||
let err: Result<int, &'static str> = Err("Err");
|
let err: Result<int, &'static str> = Err("Err");
|
||||||
|
|
||||||
let s = format!("{:?}", ok);
|
let s = format!("{:?}", ok);
|
||||||
assert_eq!(s, "Ok(100i)");
|
assert_eq!(s, "Ok(100)");
|
||||||
let s = format!("{:?}", err);
|
let s = format!("{:?}", err);
|
||||||
assert_eq!(s, "Err(\"Err\")");
|
assert_eq!(s, "Err(\"Err\")");
|
||||||
}
|
}
|
||||||
|
@ -60,9 +60,9 @@ fn test_tuple_cmp() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_show() {
|
fn test_show() {
|
||||||
let s = format!("{:?}", (1i,));
|
let s = format!("{:?}", (1i,));
|
||||||
assert_eq!(s, "(1i,)");
|
assert_eq!(s, "(1,)");
|
||||||
let s = format!("{:?}", (1i, true));
|
let s = format!("{:?}", (1i, true));
|
||||||
assert_eq!(s, "(1i, true)");
|
assert_eq!(s, "(1, true)");
|
||||||
let s = format!("{:?}", (1i, "hi", true));
|
let s = format!("{:?}", (1i, "hi", true));
|
||||||
assert_eq!(s, "(1i, \"hi\", true)");
|
assert_eq!(s, "(1, \"hi\", true)");
|
||||||
}
|
}
|
||||||
|
@ -544,7 +544,7 @@ impl Fail {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::String for Fail {
|
impl fmt::Display for Fail {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match *self {
|
match *self {
|
||||||
ArgumentMissing(ref nm) => {
|
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, UnderLim) => { B }
|
||||||
(B, Cr, OverLim) if (i - last_start + 1) > lim
|
(B, Cr, OverLim) if (i - last_start + 1) > lim
|
||||||
=> panic!("word starting with {} longer than limit!",
|
=> panic!("word starting with {} longer than limit!",
|
||||||
&ss[last_start..(i + 1)]),
|
&ss[last_start..i + 1]),
|
||||||
(B, Cr, OverLim) => {
|
(B, Cr, OverLim) => {
|
||||||
*cont = it(&ss[slice_start..last_end]);
|
*cont = it(&ss[slice_start..last_end]);
|
||||||
slice_start = last_start;
|
slice_start = last_start;
|
||||||
|
@ -358,19 +358,19 @@ impl<'a> Id<'a> {
|
|||||||
///
|
///
|
||||||
/// Passing an invalid string (containing spaces, brackets,
|
/// Passing an invalid string (containing spaces, brackets,
|
||||||
/// quotes, ...) will return an empty `Err` value.
|
/// 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 name = name.into_cow();
|
||||||
{
|
{
|
||||||
let mut chars = name.chars();
|
let mut chars = name.chars();
|
||||||
match chars.next() {
|
match chars.next() {
|
||||||
Some(c) if is_letter_or_underscore(c) => { ; },
|
Some(c) if is_letter_or_underscore(c) => { ; },
|
||||||
_ => return Err(())
|
_ => return None
|
||||||
}
|
}
|
||||||
if !chars.all(is_constituent) {
|
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 {
|
fn is_letter_or_underscore(c: char) -> bool {
|
||||||
in_range('a', c, 'z') || in_range('A', c, 'Z') || c == '_'
|
in_range('a', c, 'z') || in_range('A', c, 'Z') || c == '_'
|
||||||
@ -874,8 +874,8 @@ r#"digraph syntax_tree {
|
|||||||
fn simple_id_construction() {
|
fn simple_id_construction() {
|
||||||
let id1 = Id::new("hello");
|
let id1 = Id::new("hello");
|
||||||
match id1 {
|
match id1 {
|
||||||
Ok(_) => {;},
|
Some(_) => {;},
|
||||||
Err(_) => panic!("'hello' is not a valid value for id anymore")
|
None => panic!("'hello' is not a valid value for id anymore")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -883,8 +883,8 @@ r#"digraph syntax_tree {
|
|||||||
fn badly_formatted_id() {
|
fn badly_formatted_id() {
|
||||||
let id2 = Id::new("Weird { struct : ure } !!!");
|
let id2 = Id::new("Weird { struct : ure } !!!");
|
||||||
match id2 {
|
match id2 {
|
||||||
Ok(_) => panic!("graphviz id suddenly allows spaces, brackets and stuff"),
|
Some(_) => panic!("graphviz id suddenly allows spaces, brackets and stuff"),
|
||||||
Err(_) => {;}
|
None => {;}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,7 @@ impl<'a,T> FromIterator<T> for 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 {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
self.as_slice().fmt(f)
|
self.as_slice().fmt(f)
|
||||||
}
|
}
|
||||||
|
@ -4648,13 +4648,13 @@ pub mod funcs {
|
|||||||
use types::os::arch::c95::c_int;
|
use types::os::arch::c95::c_int;
|
||||||
use types::os::common::posix01::sighandler_t;
|
use types::os::common::posix01::sighandler_t;
|
||||||
|
|
||||||
#[cfg(not(target_os = "android"))]
|
#[cfg(not(all(target_os = "android", target_arch = "arm")))]
|
||||||
extern {
|
extern {
|
||||||
pub fn signal(signum: c_int,
|
pub fn signal(signum: c_int,
|
||||||
handler: sighandler_t) -> sighandler_t;
|
handler: sighandler_t) -> sighandler_t;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(all(target_os = "android", target_arch = "arm"))]
|
||||||
extern {
|
extern {
|
||||||
#[link_name = "bsd_signal"]
|
#[link_name = "bsd_signal"]
|
||||||
pub fn signal(signum: c_int,
|
pub fn signal(signum: c_int,
|
||||||
|
@ -180,6 +180,7 @@ use std::io::LineBufferedWriter;
|
|||||||
use std::io;
|
use std::io;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::os;
|
use std::os;
|
||||||
|
use std::ptr;
|
||||||
use std::rt;
|
use std::rt;
|
||||||
use std::slice;
|
use std::slice;
|
||||||
use std::sync::{Once, ONCE_INIT};
|
use std::sync::{Once, ONCE_INIT};
|
||||||
@ -239,21 +240,15 @@ struct DefaultLogger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Wraps the log level with fmt implementations.
|
/// Wraps the log level with fmt implementations.
|
||||||
#[derive(Copy, PartialEq, PartialOrd)]
|
#[derive(Copy, PartialEq, PartialOrd, Show)]
|
||||||
pub struct LogLevel(pub u32);
|
pub struct LogLevel(pub u32);
|
||||||
|
|
||||||
impl fmt::Show for LogLevel {
|
impl fmt::Display for LogLevel {
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
fmt::String::fmt(self, fmt)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::String for LogLevel {
|
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
let LogLevel(level) = *self;
|
let LogLevel(level) = *self;
|
||||||
match LOG_LEVEL_NAMES.get(level as uint - 1) {
|
match LOG_LEVEL_NAMES.get(level as uint - 1) {
|
||||||
Some(ref name) => fmt::String::fmt(name, fmt),
|
Some(ref name) => fmt::Display::fmt(name, fmt),
|
||||||
None => fmt::String::fmt(&level, fmt)
|
None => fmt::Display::fmt(&level, fmt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -437,11 +432,11 @@ fn init() {
|
|||||||
assert!(!DIRECTIVES.is_null());
|
assert!(!DIRECTIVES.is_null());
|
||||||
let _directives: Box<Vec<directive::LogDirective>> =
|
let _directives: Box<Vec<directive::LogDirective>> =
|
||||||
mem::transmute(DIRECTIVES);
|
mem::transmute(DIRECTIVES);
|
||||||
DIRECTIVES = 0 as *const Vec<directive::LogDirective>;
|
DIRECTIVES = ptr::null();
|
||||||
|
|
||||||
if !FILTER.is_null() {
|
if !FILTER.is_null() {
|
||||||
let _filter: Box<Regex> = mem::transmute(FILTER);
|
let _filter: Box<Regex> = mem::transmute(FILTER);
|
||||||
FILTER = 0 as *const _;
|
FILTER = ptr::null();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -174,7 +174,7 @@ impl<'a> SeedableRng<&'a [u32]> for ChaChaRng {
|
|||||||
// reset state
|
// reset state
|
||||||
self.init(&[0u32; KEY_WORDS]);
|
self.init(&[0u32; KEY_WORDS]);
|
||||||
// set key in place
|
// 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()) {
|
for (k, s) in key.iter_mut().zip(seed.iter()) {
|
||||||
*k = *s;
|
*k = *s;
|
||||||
}
|
}
|
||||||
@ -292,4 +292,3 @@ mod test {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ impl Writer for SeekableMemWriter {
|
|||||||
|
|
||||||
// Do the necessary writes
|
// Do the necessary writes
|
||||||
if left.len() > 0 {
|
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 {
|
if right.len() > 0 {
|
||||||
self.buf.push_all(right);
|
self.buf.push_all(right);
|
||||||
|
@ -38,6 +38,7 @@ pub use self::EbmlEncoderTag::*;
|
|||||||
pub use self::Error::*;
|
pub use self::Error::*;
|
||||||
|
|
||||||
use std::str;
|
use std::str;
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
pub mod io;
|
pub mod io;
|
||||||
|
|
||||||
@ -113,6 +114,13 @@ pub enum Error {
|
|||||||
IoError(std::io::IoError),
|
IoError(std::io::IoError),
|
||||||
ApplicationError(String)
|
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 {
|
pub mod reader {
|
||||||
|
@ -30,6 +30,7 @@ static MAX_REPEAT: uint = 1000;
|
|||||||
///
|
///
|
||||||
/// (Once an expression is compiled, it is not possible to produce an error
|
/// (Once an expression is compiled, it is not possible to produce an error
|
||||||
/// via searching, splitting or replacing.)
|
/// via searching, splitting or replacing.)
|
||||||
|
#[derive(Show)]
|
||||||
pub struct Error {
|
pub struct Error {
|
||||||
/// The *approximate* character index of where the error occurred.
|
/// The *approximate* character index of where the error occurred.
|
||||||
pub pos: uint,
|
pub pos: uint,
|
||||||
@ -37,7 +38,7 @@ pub struct Error {
|
|||||||
pub msg: String,
|
pub msg: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Show for Error {
|
impl fmt::Display for Error {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "Regex syntax error near position {}: {:?}",
|
write!(f, "Regex syntax error near position {}: {:?}",
|
||||||
self.pos, self.msg)
|
self.pos, self.msg)
|
||||||
@ -518,7 +519,7 @@ impl<'a> Parser<'a> {
|
|||||||
};
|
};
|
||||||
self.chari = closer;
|
self.chari = closer;
|
||||||
let greed = try!(self.get_next_greedy());
|
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>();
|
.collect::<String>();
|
||||||
|
|
||||||
// Parse the min and max values from the regex.
|
// Parse the min and max values from the regex.
|
||||||
|
@ -90,10 +90,10 @@ impl Clone for ExNative {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::String for Regex {
|
impl fmt::Display for Regex {
|
||||||
/// Shows the original regular expression.
|
/// Shows the original regular expression.
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
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 @@ impl<'t> Captures<'t> {
|
|||||||
pub fn at(&self, i: uint) -> Option<&'t str> {
|
pub fn at(&self, i: uint) -> Option<&'t str> {
|
||||||
match self.pos(i) {
|
match self.pos(i) {
|
||||||
None => None,
|
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)]
|
#![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
|
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,
|
will never be reached as for all possible values of the expression being matched,
|
||||||
one of the preceeding patterns will match.
|
one of the preceeding patterns will match.
|
||||||
|
|
||||||
This means that perhaps some of the preceeding patterns are too general, this
|
This means that perhaps some of the preceeding patterns are too general, this
|
||||||
one is too specific or the ordering is incorrect.
|
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! {
|
register_diagnostics! {
|
||||||
E0002,
|
E0002,
|
||||||
E0003,
|
|
||||||
E0004,
|
|
||||||
E0005,
|
|
||||||
E0006,
|
|
||||||
E0007,
|
E0007,
|
||||||
E0008,
|
E0008,
|
||||||
E0009,
|
E0009,
|
||||||
E0010,
|
E0010,
|
||||||
E0011,
|
E0011,
|
||||||
E0012,
|
E0012,
|
||||||
E0013,
|
|
||||||
E0014,
|
E0014,
|
||||||
E0015,
|
E0015,
|
||||||
E0016,
|
E0016,
|
||||||
@ -49,24 +76,58 @@ register_diagnostics! {
|
|||||||
E0137,
|
E0137,
|
||||||
E0138,
|
E0138,
|
||||||
E0139,
|
E0139,
|
||||||
E0140,
|
|
||||||
E0152,
|
E0152,
|
||||||
E0153,
|
|
||||||
E0157,
|
|
||||||
E0158,
|
E0158,
|
||||||
E0161,
|
E0161,
|
||||||
E0162,
|
E0162,
|
||||||
E0165,
|
E0165,
|
||||||
E0166,
|
|
||||||
E0167,
|
|
||||||
E0168,
|
|
||||||
E0169,
|
|
||||||
E0170,
|
E0170,
|
||||||
E0171,
|
E0261, // use of undeclared lifetime name
|
||||||
E0172,
|
E0262, // illegal lifetime parameter name
|
||||||
E0173,
|
E0263, // lifetime name declared twice in same scope
|
||||||
E0174,
|
E0264, // unknown external lang item
|
||||||
E0177,
|
E0265, // recursive constant
|
||||||
E0178,
|
E0266, // expected item
|
||||||
E0179
|
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 @@ extern crate test;
|
|||||||
|
|
||||||
pub use rustc_llvm as llvm;
|
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 mod back {
|
||||||
pub use rustc_back::abi;
|
pub use rustc_back::abi;
|
||||||
@ -132,8 +134,6 @@ pub mod lib {
|
|||||||
pub use llvm;
|
pub use llvm;
|
||||||
}
|
}
|
||||||
|
|
||||||
__build_diagnostic_array! { DIAGNOSTICS }
|
|
||||||
|
|
||||||
// A private module so that macro-expanded idents like
|
// A private module so that macro-expanded idents like
|
||||||
// `::rustc::lint::Lint` will also work in `rustc` itself.
|
// `::rustc::lint::Lint` will also work in `rustc` itself.
|
||||||
//
|
//
|
||||||
|
@ -1202,17 +1202,17 @@ impl LintPass for UnusedImportBraces {
|
|||||||
lint_array!(UNUSED_IMPORT_BRACES)
|
lint_array!(UNUSED_IMPORT_BRACES)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_view_item(&mut self, cx: &Context, view_item: &ast::ViewItem) {
|
fn check_item(&mut self, cx: &Context, item: &ast::Item) {
|
||||||
match view_item.node {
|
match item.node {
|
||||||
ast::ViewItemUse(ref view_path) => {
|
ast::ItemUse(ref view_path) => {
|
||||||
match view_path.node {
|
match view_path.node {
|
||||||
ast::ViewPathList(_, ref items, _) => {
|
ast::ViewPathList(_, ref items) => {
|
||||||
if items.len() == 1 {
|
if items.len() == 1 {
|
||||||
match items[0].node {
|
match items[0].node {
|
||||||
ast::PathListIdent {ref name, ..} => {
|
ast::PathListIdent {ref name, ..} => {
|
||||||
let m = format!("braces around {} is unnecessary",
|
let m = format!("braces around {} is unnecessary",
|
||||||
token::get_ident(*name).get());
|
token::get_ident(*name).get());
|
||||||
cx.span_lint(UNUSED_IMPORT_BRACES, view_item.span,
|
cx.span_lint(UNUSED_IMPORT_BRACES, item.span,
|
||||||
&m[]);
|
&m[]);
|
||||||
},
|
},
|
||||||
_ => ()
|
_ => ()
|
||||||
@ -1329,7 +1329,7 @@ impl UnusedMut {
|
|||||||
let ident = path1.node;
|
let ident = path1.node;
|
||||||
if let ast::BindByValue(ast::MutMutable) = mode {
|
if let ast::BindByValue(ast::MutMutable) = mode {
|
||||||
if !token::get_ident(ident).get().starts_with("_") {
|
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]); },
|
Vacant(entry) => { entry.insert(vec![id]); },
|
||||||
Occupied(mut entry) => { entry.get_mut().push(id); },
|
Occupied(mut entry) => { entry.get_mut().push(id); },
|
||||||
}
|
}
|
||||||
@ -1709,22 +1709,6 @@ impl LintPass for Stability {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
|
||||||
if self.is_internal(cx, e.span) { return; }
|
if self.is_internal(cx, e.span) { return; }
|
||||||
|
|
||||||
@ -1776,6 +1760,17 @@ impl LintPass for Stability {
|
|||||||
if self.is_internal(cx, item.span) { return }
|
if self.is_internal(cx, item.span) { return }
|
||||||
|
|
||||||
match item.node {
|
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, _) => {
|
ast::ItemTrait(_, _, ref supertraits, _) => {
|
||||||
for t in supertraits.iter() {
|
for t in supertraits.iter() {
|
||||||
if let ast::TraitTyParamBound(ref t, _) = *t {
|
if let ast::TraitTyParamBound(ref t, _) = *t {
|
||||||
|
@ -231,30 +231,7 @@ impl LintStore {
|
|||||||
// We have one lint pass defined in this module.
|
// We have one lint pass defined in this module.
|
||||||
self.register_pass(sess, false, box GatherNodeLevels as LintPassObject);
|
self.register_pass(sess, false, box GatherNodeLevels as LintPassObject);
|
||||||
|
|
||||||
// Insert temporary renamings for a one-time deprecation (#16545)
|
// Insert temporary renamings for a one-time deprecation
|
||||||
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");
|
|
||||||
self.register_renamed("raw_pointer_deriving", "raw_pointer_derive");
|
self.register_renamed("raw_pointer_deriving", "raw_pointer_derive");
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -603,14 +580,6 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
fn visit_pat(&mut self, p: &ast::Pat) {
|
||||||
run_lints!(self, check_pat, p);
|
run_lints!(self, check_pat, p);
|
||||||
visit::walk_pat(self, p);
|
visit::walk_pat(self, p);
|
||||||
|
@ -128,7 +128,6 @@ pub trait LintPass {
|
|||||||
fn check_crate(&mut self, _: &Context, _: &ast::Crate) { }
|
fn check_crate(&mut self, _: &Context, _: &ast::Crate) { }
|
||||||
fn check_ident(&mut self, _: &Context, _: Span, _: ast::Ident) { }
|
fn check_ident(&mut self, _: &Context, _: Span, _: ast::Ident) { }
|
||||||
fn check_mod(&mut self, _: &Context, _: &ast::Mod, _: Span, _: ast::NodeId) { }
|
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_foreign_item(&mut self, _: &Context, _: &ast::ForeignItem) { }
|
||||||
fn check_item(&mut self, _: &Context, _: &ast::Item) { }
|
fn check_item(&mut self, _: &Context, _: &ast::Item) { }
|
||||||
fn check_local(&mut self, _: &Context, _: &ast::Local) { }
|
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> {
|
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) {
|
fn visit_item(&mut self, a: &ast::Item) {
|
||||||
self.process_item(a);
|
self.process_item(a);
|
||||||
visit::walk_item(self, 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")
|
!attr::contains_name(&i.attrs[], "no_link")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CrateInfo {
|
struct CrateInfo {
|
||||||
@ -181,7 +176,35 @@ impl<'a> CrateReader<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
if !should_link(i) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -199,35 +222,6 @@ impl<'a> CrateReader<'a> {
|
|||||||
None => ()
|
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) => {
|
ast::ItemForeignMod(ref fm) => {
|
||||||
if fm.abi == abi::Rust || fm.abi == abi::RustIntrinsic {
|
if fm.abi == abi::Rust || fm.abi == abi::RustIntrinsic {
|
||||||
return;
|
return;
|
||||||
@ -533,7 +527,7 @@ impl<'a> CrateReader<'a> {
|
|||||||
|
|
||||||
#[derive(Copy)]
|
#[derive(Copy)]
|
||||||
pub enum CrateOrString<'a> {
|
pub enum CrateOrString<'a> {
|
||||||
Krate(&'a ast::ViewItem),
|
Krate(&'a ast::Item),
|
||||||
Str(&'a str)
|
Str(&'a str)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,7 +242,7 @@ impl MetadataBlob {
|
|||||||
((slice[2] as u32) << 8) |
|
((slice[2] as u32) << 8) |
|
||||||
((slice[3] as u32) << 0)) as uint;
|
((slice[3] as u32) << 0)) as uint;
|
||||||
if len + 4 <= slice.len() {
|
if len + 4 <= slice.len() {
|
||||||
slice.slice(4, len + 4)
|
&slice[4.. len + 4]
|
||||||
} else {
|
} else {
|
||||||
&[] // corrupt or old metadata
|
&[] // 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;
|
let mut ret = None;
|
||||||
reader::tagged_docs(tagged_doc.doc, belt, |elt| {
|
reader::tagged_docs(tagged_doc.doc, belt, |elt| {
|
||||||
let pos = u64_from_be_bytes(elt.data, elt.start, 4) as uint;
|
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);
|
ret = Some(reader::doc_at(d.data, pos).unwrap().doc);
|
||||||
false
|
false
|
||||||
} else {
|
} else {
|
||||||
|
@ -1456,8 +1456,8 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
|||||||
rbml_w.end_tag();
|
rbml_w.end_tag();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ast::ItemMac(..) => {
|
ast::ItemExternCrate(_) | ast::ItemUse(_) |ast::ItemMac(..) => {
|
||||||
// macros are encoded separately
|
// these are encoded separately
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -392,11 +392,11 @@ impl<'a> Context<'a> {
|
|||||||
};
|
};
|
||||||
let (hash, rlib) = if file.starts_with(&rlib_prefix[]) &&
|
let (hash, rlib) = if file.starts_with(&rlib_prefix[]) &&
|
||||||
file.ends_with(".rlib") {
|
file.ends_with(".rlib") {
|
||||||
(file.slice(rlib_prefix.len(), file.len() - ".rlib".len()),
|
(&file[(rlib_prefix.len()) .. (file.len() - ".rlib".len())],
|
||||||
true)
|
true)
|
||||||
} else if file.starts_with(dylib_prefix.as_slice()) &&
|
} else if file.starts_with(dylib_prefix.as_slice()) &&
|
||||||
file.ends_with(dypair.1.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)
|
false)
|
||||||
} else {
|
} else {
|
||||||
return FileDoesntMatch
|
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>,
|
fn parse_vec_per_param_space<'a, 'tcx, T, F>(st: &mut PState<'a, 'tcx>,
|
||||||
mut f: F)
|
mut f: F)
|
||||||
-> VecPerParamSpace<T> where
|
-> 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>,
|
fn parse_closure_ty<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>,
|
||||||
mut conv: F) -> ty::ClosureTy<'tcx> where
|
mut conv: F) -> ty::ClosureTy<'tcx> where
|
||||||
F: FnMut(DefIdSource, ast::DefId) -> ast::DefId,
|
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,
|
F: FnMut(DefIdSource, ast::DefId) -> ast::DefId,
|
||||||
{
|
{
|
||||||
let unsafety = parse_unsafety(next(st));
|
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 sig = parse_sig_(st, conv);
|
||||||
let abi = parse_abi_set(st);
|
let abi = parse_abi_set(st);
|
||||||
ty::ClosureTy {
|
ty::ClosureTy {
|
||||||
unsafety: unsafety,
|
unsafety: unsafety,
|
||||||
onceness: onceness,
|
|
||||||
store: store,
|
|
||||||
bounds: bounds,
|
|
||||||
sig: sig,
|
sig: sig,
|
||||||
abi: abi,
|
abi: abi,
|
||||||
}
|
}
|
||||||
@ -734,7 +707,7 @@ pub fn parse_def_id(buf: &[u8]) -> ast::DefId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let crate_part = &buf[0u..colon_idx];
|
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>()) {
|
let crate_num = match str::from_utf8(crate_part).ok().and_then(|s| s.parse::<uint>()) {
|
||||||
Some(cn) => cn as ast::CrateNum,
|
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);
|
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) {
|
fn enc_unsafety(w: &mut SeekableMemWriter, p: ast::Unsafety) {
|
||||||
match p {
|
match p {
|
||||||
ast::Unsafety::Normal => mywrite!(w, "n"),
|
ast::Unsafety::Normal => mywrite!(w, "n"),
|
||||||
@ -329,13 +318,6 @@ fn enc_abi(w: &mut SeekableMemWriter, abi: Abi) {
|
|||||||
mywrite!(w, "]")
|
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>,
|
pub fn enc_bare_fn_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>,
|
||||||
ft: &ty::BareFnTy<'tcx>) {
|
ft: &ty::BareFnTy<'tcx>) {
|
||||||
enc_unsafety(w, ft.unsafety);
|
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>,
|
pub fn enc_closure_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>,
|
||||||
ft: &ty::ClosureTy<'tcx>) {
|
ft: &ty::ClosureTy<'tcx>) {
|
||||||
enc_unsafety(w, ft.unsafety);
|
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_fn_sig(w, cx, &ft.sig);
|
||||||
enc_abi(w, ft.abi);
|
enc_abi(w, ft.abi);
|
||||||
}
|
}
|
||||||
|
@ -332,8 +332,6 @@ impl Folder for NestedItemsDropper {
|
|||||||
}
|
}
|
||||||
}).collect();
|
}).collect();
|
||||||
let blk_sans_items = P(ast::Block {
|
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,
|
stmts: stmts_sans_items,
|
||||||
expr: expr,
|
expr: expr,
|
||||||
id: id,
|
id: id,
|
||||||
@ -515,17 +513,6 @@ impl tr for 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
|
// Encoding and decoding of freevar information
|
||||||
|
|
||||||
|
@ -424,7 +424,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ast::ExprMethodCall(_, _, ref args) => {
|
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) |
|
ast::ExprIndex(ref l, ref r) |
|
||||||
|
@ -73,12 +73,12 @@ impl<'a> CheckLoopVisitor<'a> {
|
|||||||
match self.cx {
|
match self.cx {
|
||||||
Loop => {}
|
Loop => {}
|
||||||
Closure => {
|
Closure => {
|
||||||
self.sess.span_err(span,
|
span_err!(self.sess, span, E0267,
|
||||||
&format!("`{}` inside of a closure", name)[]);
|
"`{}` inside of a closure", name);
|
||||||
}
|
}
|
||||||
Normal => {
|
Normal => {
|
||||||
self.sess.span_err(span,
|
span_err!(self.sess, span, E0268,
|
||||||
&format!("`{}` outside of loop", name)[]);
|
"`{}` outside of loop", name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ struct Matrix<'a>(Vec<Vec<&'a Pat>>);
|
|||||||
/// ++++++++++++++++++++++++++
|
/// ++++++++++++++++++++++++++
|
||||||
/// + _ + [_, _, ..tail] +
|
/// + _ + [_, _, ..tail] +
|
||||||
/// ++++++++++++++++++++++++++
|
/// ++++++++++++++++++++++++++
|
||||||
impl<'a> fmt::Show for Matrix<'a> {
|
impl<'a> fmt::Debug for Matrix<'a> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
try!(write!(f, "\n"));
|
try!(write!(f, "\n"));
|
||||||
|
|
||||||
@ -226,11 +226,10 @@ fn check_expr(cx: &mut MatchCheckCtxt, ex: &ast::Expr) {
|
|||||||
ast::ExprForLoop(ref pat, _, _, _) => {
|
ast::ExprForLoop(ref pat, _, _, _) => {
|
||||||
let mut static_inliner = StaticInliner::new(cx.tcx);
|
let mut static_inliner = StaticInliner::new(cx.tcx);
|
||||||
is_refutable(cx, &*static_inliner.fold_pat((*pat).clone()), |uncovered_pat| {
|
is_refutable(cx, &*static_inliner.fold_pat((*pat).clone()), |uncovered_pat| {
|
||||||
cx.tcx.sess.span_err(
|
span_err!(cx.tcx.sess, pat.span, E0297,
|
||||||
pat.span,
|
"refutable pattern in `for` loop binding: \
|
||||||
&format!("refutable pattern in `for` loop binding: \
|
|
||||||
`{}` not covered",
|
`{}` not covered",
|
||||||
pat_to_string(uncovered_pat))[]);
|
pat_to_string(uncovered_pat));
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check legality of move bindings.
|
// Check legality of move bindings.
|
||||||
@ -869,7 +868,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
|
|||||||
Some(true) => Some(vec![]),
|
Some(true) => Some(vec![]),
|
||||||
Some(false) => None,
|
Some(false) => None,
|
||||||
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
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -882,7 +881,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
|
|||||||
Some(true) => Some(vec![]),
|
Some(true) => Some(vec![]),
|
||||||
Some(false) => None,
|
Some(false) => None,
|
||||||
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
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -921,13 +920,13 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
|
|||||||
}
|
}
|
||||||
|
|
||||||
ast::PatMac(_) => {
|
ast::PatMac(_) => {
|
||||||
cx.tcx.sess.span_err(pat_span, "unexpanded macro");
|
span_err!(cx.tcx.sess, pat_span, E0300, "unexpanded macro");
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
head.map(|mut head| {
|
head.map(|mut head| {
|
||||||
head.push_all(&r[..col]);
|
head.push_all(&r[..col]);
|
||||||
head.push_all(&r[(col + 1)..]);
|
head.push_all(&r[col + 1..]);
|
||||||
head
|
head
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -1082,10 +1081,7 @@ impl<'a, 'tcx> Delegate<'tcx> for MutationChecker<'a, 'tcx> {
|
|||||||
_: LoanCause) {
|
_: LoanCause) {
|
||||||
match kind {
|
match kind {
|
||||||
MutBorrow => {
|
MutBorrow => {
|
||||||
self.cx
|
span_err!(self.cx.tcx.sess, span, E0301,
|
||||||
.tcx
|
|
||||||
.sess
|
|
||||||
.span_err(span,
|
|
||||||
"cannot mutably borrow in a pattern guard")
|
"cannot mutably borrow in a pattern guard")
|
||||||
}
|
}
|
||||||
ImmBorrow | UniqueImmBorrow => {}
|
ImmBorrow | UniqueImmBorrow => {}
|
||||||
@ -1095,10 +1091,7 @@ impl<'a, 'tcx> Delegate<'tcx> for MutationChecker<'a, 'tcx> {
|
|||||||
fn mutate(&mut self, _: NodeId, span: Span, _: cmt, mode: MutateMode) {
|
fn mutate(&mut self, _: NodeId, span: Span, _: cmt, mode: MutateMode) {
|
||||||
match mode {
|
match mode {
|
||||||
JustWrite | WriteAndRead => {
|
JustWrite | WriteAndRead => {
|
||||||
self.cx
|
span_err!(self.cx.tcx.sess, span, E0302, "cannot assign in a pattern guard")
|
||||||
.tcx
|
|
||||||
.sess
|
|
||||||
.span_err(span, "cannot assign in a pattern guard")
|
|
||||||
}
|
}
|
||||||
Init => {}
|
Init => {}
|
||||||
}
|
}
|
||||||
@ -1120,7 +1113,7 @@ struct AtBindingPatternVisitor<'a, 'b:'a, 'tcx:'b> {
|
|||||||
impl<'a, 'b, 'tcx, 'v> Visitor<'v> for AtBindingPatternVisitor<'a, 'b, 'tcx> {
|
impl<'a, 'b, 'tcx, 'v> Visitor<'v> for AtBindingPatternVisitor<'a, 'b, 'tcx> {
|
||||||
fn visit_pat(&mut self, pat: &Pat) {
|
fn visit_pat(&mut self, pat: &Pat) {
|
||||||
if !self.bindings_allowed && pat_is_binding(&self.cx.tcx.def_map, 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 \
|
"pattern bindings are not allowed \
|
||||||
after an `@`");
|
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> {
|
impl<'a, 'ast, 'v> Visitor<'v> for CheckItemRecursionVisitor<'a, 'ast> {
|
||||||
fn visit_item(&mut self, it: &ast::Item) {
|
fn visit_item(&mut self, it: &ast::Item) {
|
||||||
if self.idstack.iter().any(|x| x == &(it.id)) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
self.idstack.push(it.id);
|
self.idstack.push(it.id);
|
||||||
@ -103,9 +103,9 @@ impl<'a, 'ast, 'v> Visitor<'v> for CheckItemRecursionVisitor<'a, 'ast> {
|
|||||||
self.visit_item(item),
|
self.visit_item(item),
|
||||||
ast_map::NodeForeignItem(_) => {},
|
ast_map::NodeForeignItem(_) => {},
|
||||||
_ => {
|
_ => {
|
||||||
self.sess.span_err(e.span,
|
span_err!(self.sess, e.span, E0266,
|
||||||
&format!("expected item, found {}",
|
"expected item, found {}",
|
||||||
self.ast_map.node_to_string(def_id.node))[]);
|
self.ast_map.node_to_string(def_id.node));
|
||||||
return;
|
return;
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -118,17 +118,17 @@ impl<'a, 'tcx, O:DataFlowOperator> pprust::PpAnn for DataFlowContext<'a, 'tcx, O
|
|||||||
assert!(self.bits_per_id > 0);
|
assert!(self.bits_per_id > 0);
|
||||||
let cfgidx = to_cfgidx_or_die(id, &self.nodeid_to_index);
|
let cfgidx = to_cfgidx_or_die(id, &self.nodeid_to_index);
|
||||||
let (start, end) = self.compute_id_range(cfgidx);
|
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 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) {
|
let gens_str = if gens.iter().any(|&u| u != 0) {
|
||||||
format!(" gen: {}", bits_to_string(gens))
|
format!(" gen: {}", bits_to_string(gens))
|
||||||
} else {
|
} else {
|
||||||
"".to_string()
|
"".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) {
|
let kills_str = if kills.iter().any(|&u| u != 0) {
|
||||||
format!(" kill: {}", bits_to_string(kills))
|
format!(" kill: {}", bits_to_string(kills))
|
||||||
} else {
|
} else {
|
||||||
@ -232,7 +232,7 @@ impl<'a, 'tcx, O:DataFlowOperator> DataFlowContext<'a, 'tcx, O> {
|
|||||||
|
|
||||||
let cfgidx = to_cfgidx_or_die(id, &self.nodeid_to_index);
|
let cfgidx = to_cfgidx_or_die(id, &self.nodeid_to_index);
|
||||||
let (start, end) = self.compute_id_range(cfgidx);
|
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);
|
set_bit(gens, bit);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,7 +245,7 @@ impl<'a, 'tcx, O:DataFlowOperator> DataFlowContext<'a, 'tcx, O> {
|
|||||||
|
|
||||||
let cfgidx = to_cfgidx_or_die(id, &self.nodeid_to_index);
|
let cfgidx = to_cfgidx_or_die(id, &self.nodeid_to_index);
|
||||||
let (start, end) = self.compute_id_range(cfgidx);
|
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);
|
set_bit(kills, bit);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,9 +256,9 @@ impl<'a, 'tcx, O:DataFlowOperator> DataFlowContext<'a, 'tcx, O> {
|
|||||||
assert!(self.bits_per_id > 0);
|
assert!(self.bits_per_id > 0);
|
||||||
|
|
||||||
let (start, end) = self.compute_id_range(cfgidx);
|
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);
|
bitwise(bits, gens, &Union);
|
||||||
let kills = self.kills.slice(start, end);
|
let kills = &self.kills[start.. end];
|
||||||
bitwise(bits, kills, &Subtract);
|
bitwise(bits, kills, &Subtract);
|
||||||
|
|
||||||
debug!("{} apply_gen_kill(cfgidx={:?}, bits={}) [after]",
|
debug!("{} apply_gen_kill(cfgidx={:?}, bits={}) [after]",
|
||||||
@ -304,7 +304,7 @@ impl<'a, 'tcx, O:DataFlowOperator> DataFlowContext<'a, 'tcx, O> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let (start, end) = self.compute_id_range(cfgidx);
|
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 temp_bits;
|
||||||
let slice = match e {
|
let slice = match e {
|
||||||
Entry => on_entry,
|
Entry => on_entry,
|
||||||
@ -336,7 +336,7 @@ impl<'a, 'tcx, O:DataFlowOperator> DataFlowContext<'a, 'tcx, O> {
|
|||||||
|
|
||||||
let cfgidx = to_cfgidx_or_die(id, &self.nodeid_to_index);
|
let cfgidx = to_cfgidx_or_die(id, &self.nodeid_to_index);
|
||||||
let (start, end) = self.compute_id_range(cfgidx);
|
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={})",
|
debug!("{} each_gen_bit(id={}, gens={})",
|
||||||
self.analysis_name, id, bits_to_string(gens));
|
self.analysis_name, id, bits_to_string(gens));
|
||||||
self.each_bit(gens, f)
|
self.each_bit(gens, f)
|
||||||
@ -396,7 +396,7 @@ impl<'a, 'tcx, O:DataFlowOperator> DataFlowContext<'a, 'tcx, O> {
|
|||||||
cfg.graph.each_edge(|_edge_index, edge| {
|
cfg.graph.each_edge(|_edge_index, edge| {
|
||||||
let flow_exit = edge.source();
|
let flow_exit = edge.source();
|
||||||
let (start, end) = self.compute_id_range(flow_exit);
|
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;
|
let mut changed = false;
|
||||||
for &node_id in edge.data.exiting_scopes.iter() {
|
for &node_id in edge.data.exiting_scopes.iter() {
|
||||||
@ -404,7 +404,7 @@ impl<'a, 'tcx, O:DataFlowOperator> DataFlowContext<'a, 'tcx, O> {
|
|||||||
match opt_cfg_idx {
|
match opt_cfg_idx {
|
||||||
Some(cfg_idx) => {
|
Some(cfg_idx) => {
|
||||||
let (start, end) = self.compute_id_range(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) {
|
if bitwise(orig_kills.as_mut_slice(), kills, &Union) {
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
@ -418,7 +418,7 @@ impl<'a, 'tcx, O:DataFlowOperator> DataFlowContext<'a, 'tcx, O> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if changed {
|
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]",
|
debug!("{} add_kills_from_flow_exits flow_exit={:?} bits={} [before]",
|
||||||
self.analysis_name, flow_exit, mut_bits_to_string(bits));
|
self.analysis_name, flow_exit, mut_bits_to_string(bits));
|
||||||
bits.clone_from_slice(&orig_kills[]);
|
bits.clone_from_slice(&orig_kills[]);
|
||||||
@ -487,7 +487,7 @@ impl<'a, 'b, 'tcx, O:DataFlowOperator> PropagationContext<'a, 'b, 'tcx, O> {
|
|||||||
let (start, end) = self.dfcx.compute_id_range(node_index);
|
let (start, end) = self.dfcx.compute_id_range(node_index);
|
||||||
|
|
||||||
// Initialize local bitvector with state on-entry.
|
// 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
|
// Compute state on-exit by applying transfer function to
|
||||||
// state on-entry.
|
// state on-entry.
|
||||||
@ -528,13 +528,13 @@ impl<'a, 'b, 'tcx, O:DataFlowOperator> PropagationContext<'a, 'b, 'tcx, O> {
|
|||||||
let (start, end) = self.dfcx.compute_id_range(cfgidx);
|
let (start, end) = self.dfcx.compute_id_range(cfgidx);
|
||||||
let changed = {
|
let changed = {
|
||||||
// (scoping mutable borrow of self.dfcx.on_entry)
|
// (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)
|
bitwise(on_entry, pred_bits, &self.dfcx.oper)
|
||||||
};
|
};
|
||||||
if changed {
|
if changed {
|
||||||
debug!("{} changed entry set for {:?} to {}",
|
debug!("{} changed entry set for {:?} to {}",
|
||||||
self.dfcx.analysis_name, cfgidx,
|
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;
|
self.changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
|
|
||||||
#![allow(dead_code)] // still WIP
|
#![allow(dead_code)] // still WIP
|
||||||
|
|
||||||
use std::fmt::{Formatter, Error, Show};
|
use std::fmt::{Formatter, Error, Debug};
|
||||||
use std::uint;
|
use std::uint;
|
||||||
use std::collections::BitvSet;
|
use std::collections::BitvSet;
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ pub struct Edge<E> {
|
|||||||
pub data: 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> {
|
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
|
||||||
write!(f, "Edge {{ next_edge: [{:?}, {:?}], source: {:?}, target: {:?}, data: {:?} }}",
|
write!(f, "Edge {{ next_edge: [{:?}, {:?}], source: {:?}, target: {:?}, data: {:?} }}",
|
||||||
self.next_edge[0], self.next_edge[1], self.source,
|
self.next_edge[0], self.next_edge[1], self.source,
|
||||||
@ -353,7 +353,7 @@ impl<E> Edge<E> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use middle::graph::*;
|
use middle::graph::*;
|
||||||
use std::fmt::Show;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
type TestNode = Node<&'static str>;
|
type TestNode = Node<&'static str>;
|
||||||
type TestEdge = Edge<&'static str>;
|
type TestEdge = Edge<&'static str>;
|
||||||
@ -408,7 +408,7 @@ mod test {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
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_index: NodeIndex,
|
||||||
start_data: N,
|
start_data: N,
|
||||||
expected_incoming: &[(E,N)],
|
expected_incoming: &[(E,N)],
|
||||||
|
@ -202,39 +202,6 @@ pub trait Combine<'tcx> : Sized {
|
|||||||
sig: sig})
|
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>> {
|
fn fn_sigs(&self, a: &ty::FnSig<'tcx>, b: &ty::FnSig<'tcx>) -> cres<'tcx, ty::FnSig<'tcx>> {
|
||||||
if a.variadic != b.variadic {
|
if a.variadic != b.variadic {
|
||||||
return Err(ty::terr_variadic_mismatch(expected_found(self, a.variadic, b.variadic)));
|
return Err(ty::terr_variadic_mismatch(expected_found(self, a.variadic, b.variadic)));
|
||||||
@ -356,31 +323,6 @@ pub trait Combine<'tcx> : Sized {
|
|||||||
|
|
||||||
fn regions(&self, a: ty::Region, b: ty::Region) -> cres<'tcx, 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,
|
fn trait_refs(&self,
|
||||||
a: &ty::TraitRef<'tcx>,
|
a: &ty::TraitRef<'tcx>,
|
||||||
b: &ty::TraitRef<'tcx>)
|
b: &ty::TraitRef<'tcx>)
|
||||||
|
@ -371,12 +371,11 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
|
|||||||
infer::EquatePredicate(_) => "equality predicate not satisfied",
|
infer::EquatePredicate(_) => "equality predicate not satisfied",
|
||||||
};
|
};
|
||||||
|
|
||||||
self.tcx.sess.span_err(
|
span_err!(self.tcx.sess, trace.origin.span(), E0308,
|
||||||
trace.origin.span(),
|
"{}: {} ({})",
|
||||||
&format!("{}: {} ({})",
|
|
||||||
message_root_str,
|
message_root_str,
|
||||||
expected_found_str,
|
expected_found_str,
|
||||||
ty::type_err_to_str(self.tcx, terr))[]);
|
ty::type_err_to_str(self.tcx, terr));
|
||||||
|
|
||||||
match trace.origin {
|
match trace.origin {
|
||||||
infer::MatchExpressionArm(_, arm_span) =>
|
infer::MatchExpressionArm(_, arm_span) =>
|
||||||
@ -443,9 +442,8 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
|
|||||||
match sub {
|
match sub {
|
||||||
ty::ReFree(ty::FreeRegion {bound_region: ty::BrNamed(..), ..}) => {
|
ty::ReFree(ty::FreeRegion {bound_region: ty::BrNamed(..), ..}) => {
|
||||||
// Does the required lifetime have a nice name we can print?
|
// Does the required lifetime have a nice name we can print?
|
||||||
self.tcx.sess.span_err(
|
span_err!(self.tcx.sess, origin.span(), E0309,
|
||||||
origin.span(),
|
"{} may not live long enough", labeled_user_string);
|
||||||
&format!("{} may not live long enough", labeled_user_string)[]);
|
|
||||||
self.tcx.sess.span_help(
|
self.tcx.sess.span_help(
|
||||||
origin.span(),
|
origin.span(),
|
||||||
&format!(
|
&format!(
|
||||||
@ -456,9 +454,8 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
|
|||||||
|
|
||||||
ty::ReStatic => {
|
ty::ReStatic => {
|
||||||
// Does the required lifetime have a nice name we can print?
|
// Does the required lifetime have a nice name we can print?
|
||||||
self.tcx.sess.span_err(
|
span_err!(self.tcx.sess, origin.span(), E0310,
|
||||||
origin.span(),
|
"{} may not live long enough", labeled_user_string);
|
||||||
&format!("{} may not live long enough", labeled_user_string)[]);
|
|
||||||
self.tcx.sess.span_help(
|
self.tcx.sess.span_help(
|
||||||
origin.span(),
|
origin.span(),
|
||||||
&format!(
|
&format!(
|
||||||
@ -468,11 +465,9 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
|
|||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
// If not, be less specific.
|
// If not, be less specific.
|
||||||
self.tcx.sess.span_err(
|
span_err!(self.tcx.sess, origin.span(), E0311,
|
||||||
origin.span(),
|
|
||||||
&format!(
|
|
||||||
"{} may not live long enough",
|
"{} may not live long enough",
|
||||||
labeled_user_string)[]);
|
labeled_user_string);
|
||||||
self.tcx.sess.span_help(
|
self.tcx.sess.span_help(
|
||||||
origin.span(),
|
origin.span(),
|
||||||
&format!(
|
&format!(
|
||||||
@ -499,8 +494,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
|
|||||||
self.report_and_explain_type_error(trace, &terr);
|
self.report_and_explain_type_error(trace, &terr);
|
||||||
}
|
}
|
||||||
infer::Reborrow(span) => {
|
infer::Reborrow(span) => {
|
||||||
self.tcx.sess.span_err(
|
span_err!(self.tcx.sess, span, E0312,
|
||||||
span,
|
|
||||||
"lifetime of reference outlines \
|
"lifetime of reference outlines \
|
||||||
lifetime of borrowed content...");
|
lifetime of borrowed content...");
|
||||||
note_and_explain_region(
|
note_and_explain_region(
|
||||||
@ -515,14 +509,13 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
|
|||||||
"");
|
"");
|
||||||
}
|
}
|
||||||
infer::ReborrowUpvar(span, ref upvar_id) => {
|
infer::ReborrowUpvar(span, ref upvar_id) => {
|
||||||
self.tcx.sess.span_err(
|
span_err!(self.tcx.sess, span, E0313,
|
||||||
span,
|
"lifetime of borrowed pointer outlives \
|
||||||
&format!("lifetime of borrowed pointer outlives \
|
|
||||||
lifetime of captured variable `{}`...",
|
lifetime of captured variable `{}`...",
|
||||||
ty::local_var_name_str(self.tcx,
|
ty::local_var_name_str(self.tcx,
|
||||||
upvar_id.var_id)
|
upvar_id.var_id)
|
||||||
.get()
|
.get()
|
||||||
.to_string())[]);
|
.to_string());
|
||||||
note_and_explain_region(
|
note_and_explain_region(
|
||||||
self.tcx,
|
self.tcx,
|
||||||
"...the borrowed pointer is valid for ",
|
"...the borrowed pointer is valid for ",
|
||||||
@ -539,8 +532,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
|
|||||||
"");
|
"");
|
||||||
}
|
}
|
||||||
infer::InfStackClosure(span) => {
|
infer::InfStackClosure(span) => {
|
||||||
self.tcx.sess.span_err(
|
span_err!(self.tcx.sess, span, E0314,
|
||||||
span,
|
|
||||||
"closure outlives stack frame");
|
"closure outlives stack frame");
|
||||||
note_and_explain_region(
|
note_and_explain_region(
|
||||||
self.tcx,
|
self.tcx,
|
||||||
@ -554,8 +546,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
|
|||||||
"");
|
"");
|
||||||
}
|
}
|
||||||
infer::InvokeClosure(span) => {
|
infer::InvokeClosure(span) => {
|
||||||
self.tcx.sess.span_err(
|
span_err!(self.tcx.sess, span, E0315,
|
||||||
span,
|
|
||||||
"cannot invoke closure outside of its lifetime");
|
"cannot invoke closure outside of its lifetime");
|
||||||
note_and_explain_region(
|
note_and_explain_region(
|
||||||
self.tcx,
|
self.tcx,
|
||||||
|
@ -609,8 +609,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
|
|||||||
pub fn vars_created_since_snapshot(&self, mark: &RegionSnapshot)
|
pub fn vars_created_since_snapshot(&self, mark: &RegionSnapshot)
|
||||||
-> Vec<RegionVid>
|
-> Vec<RegionVid>
|
||||||
{
|
{
|
||||||
self.undo_log.borrow()
|
self.undo_log.borrow()[mark.length..]
|
||||||
.slice_from(mark.length)
|
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|&elt| match elt {
|
.filter_map(|&elt| match elt {
|
||||||
AddVar(vid) => Some(vid),
|
AddVar(vid) => Some(vid),
|
||||||
@ -637,7 +636,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
|
|||||||
debug!("result_index={}, r={:?}", result_index, r);
|
debug!("result_index={}, r={:?}", result_index, r);
|
||||||
|
|
||||||
for undo_entry in
|
for undo_entry in
|
||||||
self.undo_log.borrow().slice_from(mark.length).iter()
|
self.undo_log.borrow()[mark.length..].iter()
|
||||||
{
|
{
|
||||||
match undo_entry {
|
match undo_entry {
|
||||||
&AddConstraint(ConstrainVarSubVar(a, b)) => {
|
&AddConstraint(ConstrainVarSubVar(a, b)) => {
|
||||||
|
@ -17,7 +17,7 @@ use middle::ty::{self, Ty};
|
|||||||
use middle::infer::{uok, ures};
|
use middle::infer::{uok, ures};
|
||||||
use middle::infer::InferCtxt;
|
use middle::infer::InferCtxt;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::fmt::Show;
|
use std::fmt::Debug;
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use util::ppaux::Repr;
|
use util::ppaux::Repr;
|
||||||
use util::snapshot_vec as sv;
|
use util::snapshot_vec as sv;
|
||||||
@ -32,7 +32,7 @@ use util::snapshot_vec as sv;
|
|||||||
/// (possibly not yet known) sort of integer.
|
/// (possibly not yet known) sort of integer.
|
||||||
///
|
///
|
||||||
/// Implementations of this trait are at the end of this file.
|
/// 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 index(&self) -> uint;
|
||||||
|
|
||||||
fn from_index(u: uint) -> Self;
|
fn from_index(u: uint) -> Self;
|
||||||
|
@ -320,9 +320,7 @@ lets_do_this! {
|
|||||||
ContravariantLifetimeItem, "contravariant_lifetime", contravariant_lifetime;
|
ContravariantLifetimeItem, "contravariant_lifetime", contravariant_lifetime;
|
||||||
InvariantLifetimeItem, "invariant_lifetime", invariant_lifetime;
|
InvariantLifetimeItem, "invariant_lifetime", invariant_lifetime;
|
||||||
|
|
||||||
NoSendItem, "no_send_bound", no_send_bound;
|
|
||||||
NoCopyItem, "no_copy_bound", no_copy_bound;
|
NoCopyItem, "no_copy_bound", no_copy_bound;
|
||||||
NoSyncItem, "no_sync_bound", no_sync_bound;
|
|
||||||
ManagedItem, "managed_bound", managed_bound;
|
ManagedItem, "managed_bound", managed_bound;
|
||||||
|
|
||||||
NonZeroItem, "non_zero", non_zero;
|
NonZeroItem, "non_zero", non_zero;
|
||||||
|
@ -198,13 +198,13 @@ pub fn check_crate(tcx: &ty::ctxt) {
|
|||||||
tcx.sess.abort_if_errors();
|
tcx.sess.abort_if_errors();
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Show for LiveNode {
|
impl fmt::Debug for LiveNode {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "ln({})", self.get())
|
write!(f, "ln({})", self.get())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Show for Variable {
|
impl fmt::Debug for Variable {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "v({})", self.get())
|
write!(f, "v({})", self.get())
|
||||||
}
|
}
|
||||||
@ -1557,8 +1557,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
|||||||
},
|
},
|
||||||
_ => false
|
_ => false
|
||||||
};
|
};
|
||||||
self.ir.tcx.sess.span_err(
|
span_err!(self.ir.tcx.sess, sp, E0269, "not all control paths return a value");
|
||||||
sp, "not all control paths return a value");
|
|
||||||
if ends_with_stmt {
|
if ends_with_stmt {
|
||||||
let last_stmt = body.stmts.first().unwrap();
|
let last_stmt = body.stmts.first().unwrap();
|
||||||
let original_span = original_sp(self.ir.tcx.sess.codemap(),
|
let original_span = original_sp(self.ir.tcx.sess.codemap(),
|
||||||
@ -1575,7 +1574,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
ty::FnDiverging
|
ty::FnDiverging
|
||||||
if self.live_on_entry(entry_ln, self.s.clean_exit_var).is_some() => {
|
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");
|
"computation may converge in a function marked as diverging");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,6 +297,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
|
|||||||
// These are normal, nothing reachable about these
|
// These are normal, nothing reachable about these
|
||||||
// inherently and their children are already in the
|
// inherently and their children are already in the
|
||||||
// worklist, as determined by the privacy pass
|
// worklist, as determined by the privacy pass
|
||||||
|
ast::ItemExternCrate(_) | ast::ItemUse(_) |
|
||||||
ast::ItemTy(..) | ast::ItemStatic(_, _, _) |
|
ast::ItemTy(..) | ast::ItemStatic(_, _, _) |
|
||||||
ast::ItemMod(..) | ast::ItemForeignMod(..) |
|
ast::ItemMod(..) | ast::ItemForeignMod(..) |
|
||||||
ast::ItemImpl(..) | ast::ItemTrait(..) |
|
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\"]");
|
expected #![recursion_limit=\"N\"]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,9 +22,6 @@ use util::nodemap::{FnvHashMap, FnvHashSet, NodeMap};
|
|||||||
use util::common::can_reach;
|
use util::common::can_reach;
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
// NOTE(stage0) remove import after a snapshot
|
|
||||||
#[cfg(stage0)]
|
|
||||||
use std::hash::{Hash};
|
|
||||||
use syntax::codemap::Span;
|
use syntax::codemap::Span;
|
||||||
use syntax::{ast, visit};
|
use syntax::{ast, visit};
|
||||||
use syntax::ast::{Block, Item, FnDecl, NodeId, Arm, Pat, Stmt, Expr, Local};
|
use syntax::ast::{Block, Item, FnDecl, NodeId, Arm, Pat, Stmt, Expr, Local};
|
||||||
|
@ -94,6 +94,8 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
|
|||||||
// Fn lifetimes get added in visit_fn below:
|
// Fn lifetimes get added in visit_fn below:
|
||||||
visit::walk_item(this, item);
|
visit::walk_item(this, item);
|
||||||
}
|
}
|
||||||
|
ast::ItemExternCrate(_) |
|
||||||
|
ast::ItemUse(_) |
|
||||||
ast::ItemMod(..) |
|
ast::ItemMod(..) |
|
||||||
ast::ItemMac(..) |
|
ast::ItemMac(..) |
|
||||||
ast::ItemForeignMod(..) |
|
ast::ItemForeignMod(..) |
|
||||||
@ -396,10 +398,9 @@ impl<'a> LifetimeContext<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn unresolved_lifetime_ref(&self, lifetime_ref: &ast::Lifetime) {
|
fn unresolved_lifetime_ref(&self, lifetime_ref: &ast::Lifetime) {
|
||||||
self.sess.span_err(
|
span_err!(self.sess, lifetime_ref.span, E0261,
|
||||||
lifetime_ref.span,
|
"use of undeclared lifetime name `{}`",
|
||||||
&format!("use of undeclared lifetime name `{}`",
|
token::get_name(lifetime_ref.name));
|
||||||
token::get_name(lifetime_ref.name))[]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_lifetime_defs(&mut self, old_scope: Scope, lifetimes: &Vec<ast::LifetimeDef>) {
|
fn check_lifetime_defs(&mut self, old_scope: Scope, lifetimes: &Vec<ast::LifetimeDef>) {
|
||||||
@ -409,11 +410,9 @@ impl<'a> LifetimeContext<'a> {
|
|||||||
let special_idents = [special_idents::static_lifetime];
|
let special_idents = [special_idents::static_lifetime];
|
||||||
for lifetime in lifetimes.iter() {
|
for lifetime in lifetimes.iter() {
|
||||||
if special_idents.iter().any(|&i| i.name == lifetime.lifetime.name) {
|
if special_idents.iter().any(|&i| i.name == lifetime.lifetime.name) {
|
||||||
self.sess.span_err(
|
span_err!(self.sess, lifetime.lifetime.span, E0262,
|
||||||
lifetime.lifetime.span,
|
"illegal lifetime parameter name: `{}`",
|
||||||
&format!("illegal lifetime parameter name: `{}`",
|
token::get_name(lifetime.lifetime.name));
|
||||||
token::get_name(lifetime.lifetime.name))
|
|
||||||
[]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -422,12 +421,10 @@ impl<'a> LifetimeContext<'a> {
|
|||||||
let lifetime_j = &lifetimes[j];
|
let lifetime_j = &lifetimes[j];
|
||||||
|
|
||||||
if lifetime_i.lifetime.name == lifetime_j.lifetime.name {
|
if lifetime_i.lifetime.name == lifetime_j.lifetime.name {
|
||||||
self.sess.span_err(
|
span_err!(self.sess, lifetime_j.lifetime.span, E0263,
|
||||||
lifetime_j.lifetime.span,
|
"lifetime name `{}` declared twice in \
|
||||||
&format!("lifetime name `{}` declared twice in \
|
|
||||||
the same scope",
|
the same scope",
|
||||||
token::get_name(lifetime_j.lifetime.name))
|
token::get_name(lifetime_j.lifetime.name));
|
||||||
[]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -462,11 +459,11 @@ impl<'a> LifetimeContext<'a> {
|
|||||||
format!("lifetime name `{}` shadows another \
|
format!("lifetime name `{}` shadows another \
|
||||||
lifetime name that is already in scope",
|
lifetime name that is already in scope",
|
||||||
token::get_name(lifetime.name)).as_slice());
|
token::get_name(lifetime.name)).as_slice());
|
||||||
self.sess.span_help(
|
self.sess.span_note(
|
||||||
lifetime_def.span,
|
lifetime_def.span,
|
||||||
format!("shadowed lifetime `{}` declared here",
|
format!("shadowed lifetime `{}` declared here",
|
||||||
token::get_name(lifetime.name)).as_slice());
|
token::get_name(lifetime.name)).as_slice());
|
||||||
self.sess.span_help(
|
self.sess.span_note(
|
||||||
lifetime.span,
|
lifetime.span,
|
||||||
"shadowed lifetimes are deprecated \
|
"shadowed lifetimes are deprecated \
|
||||||
and will become a hard error before 1.0");
|
and will become a hard error before 1.0");
|
||||||
@ -602,7 +599,7 @@ fn early_bound_lifetime_names(generics: &ast::Generics) -> 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 {
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match *self {
|
match *self {
|
||||||
EarlyScope(space, defs, _) => write!(fmt, "EarlyScope({:?}, {:?})", space, defs),
|
EarlyScope(space, defs, _) => write!(fmt, "EarlyScope({:?}, {:?})", space, defs),
|
||||||
|
@ -238,7 +238,7 @@ pub struct SeparateVecsPerParamSpace<T> {
|
|||||||
pub fns: Vec<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 {
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
try!(write!(fmt, "VecPerParamSpace {{"));
|
try!(write!(fmt, "VecPerParamSpace {{"));
|
||||||
for space in ParamSpace::all().iter() {
|
for space in ParamSpace::all().iter() {
|
||||||
@ -373,12 +373,12 @@ impl<T> VecPerParamSpace<T> {
|
|||||||
|
|
||||||
pub fn get_slice<'a>(&'a self, space: ParamSpace) -> &'a [T] {
|
pub fn get_slice<'a>(&'a self, space: ParamSpace) -> &'a [T] {
|
||||||
let (start, limit) = self.limits(space);
|
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] {
|
pub fn get_mut_slice<'a>(&'a mut self, space: ParamSpace) -> &'a mut [T] {
|
||||||
let (start, limit) = self.limits(space);
|
let (start, limit) = self.limits(space);
|
||||||
self.content.slice_mut(start, limit)
|
&mut self.content[start.. limit]
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn opt_get<'a>(&'a self,
|
pub fn opt_get<'a>(&'a self,
|
||||||
|
@ -55,12 +55,10 @@ pub fn report_projection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
|
|||||||
let predicate =
|
let predicate =
|
||||||
infcx.resolve_type_vars_if_possible(&obligation.predicate);
|
infcx.resolve_type_vars_if_possible(&obligation.predicate);
|
||||||
if !predicate.references_error() {
|
if !predicate.references_error() {
|
||||||
infcx.tcx.sess.span_err(
|
span_err!(infcx.tcx.sess, obligation.cause.span, E0271,
|
||||||
obligation.cause.span,
|
|
||||||
format!(
|
|
||||||
"type mismatch resolving `{}`: {}",
|
"type mismatch resolving `{}`: {}",
|
||||||
predicate.user_string(infcx.tcx),
|
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);
|
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) {
|
Position::ArgumentNamed(s) => match generic_map.get(s) {
|
||||||
Some(val) => Some(val.as_slice()),
|
Some(val) => Some(val.as_slice()),
|
||||||
None => {
|
None => {
|
||||||
infcx.tcx.sess
|
span_err!(infcx.tcx.sess, err_sp, E0272,
|
||||||
.span_err(err_sp,
|
"the #[rustc_on_unimplemented] \
|
||||||
format!("the #[rustc_on_unimplemented] \
|
|
||||||
attribute on \
|
attribute on \
|
||||||
trait definition for {} refers to \
|
trait definition for {} refers to \
|
||||||
non-existent type parameter {}",
|
non-existent type parameter {}",
|
||||||
trait_str, s)
|
trait_str, s);
|
||||||
.as_slice());
|
|
||||||
errored = true;
|
errored = true;
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
infcx.tcx.sess
|
span_err!(infcx.tcx.sess, err_sp, E0273,
|
||||||
.span_err(err_sp,
|
"the #[rustc_on_unimplemented] \
|
||||||
format!("the #[rustc_on_unimplemented] \
|
|
||||||
attribute on \
|
attribute on \
|
||||||
trait definition for {} must have named \
|
trait definition for {} must have named \
|
||||||
format arguments, \
|
format arguments, \
|
||||||
eg `#[rustc_on_unimplemented = \
|
eg `#[rustc_on_unimplemented = \
|
||||||
\"foo {{T}}\"]`",
|
\"foo {{T}}\"]`",
|
||||||
trait_str).as_slice());
|
trait_str);
|
||||||
errored = true;
|
errored = true;
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
@ -130,11 +125,11 @@ fn report_on_unimplemented<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
|
|||||||
report = Some(err);
|
report = Some(err);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
infcx.tcx.sess.span_err(err_sp,
|
span_err!(infcx.tcx.sess, err_sp, E0274,
|
||||||
format!("the #[rustc_on_unimplemented] attribute on \
|
"the #[rustc_on_unimplemented] attribute on \
|
||||||
trait definition for {} must have a value, \
|
trait definition for {} must have a value, \
|
||||||
eg `#[rustc_on_unimplemented = \"foo\"]`",
|
eg `#[rustc_on_unimplemented = \"foo\"]`",
|
||||||
trait_str).as_slice());
|
trait_str);
|
||||||
}
|
}
|
||||||
break;
|
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.
|
// We could track the stack here more precisely if we wanted, I imagine.
|
||||||
let predicate =
|
let predicate =
|
||||||
infcx.resolve_type_vars_if_possible(&obligation.predicate);
|
infcx.resolve_type_vars_if_possible(&obligation.predicate);
|
||||||
infcx.tcx.sess.span_err(
|
span_err!(infcx.tcx.sess, obligation.cause.span, E0275,
|
||||||
obligation.cause.span,
|
|
||||||
format!(
|
|
||||||
"overflow evaluating the requirement `{}`",
|
"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);
|
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 => {
|
SelectionError::Unimplemented => {
|
||||||
match &obligation.cause.code {
|
match &obligation.cause.code {
|
||||||
&ObligationCauseCode::CompareImplMethodObligation => {
|
&ObligationCauseCode::CompareImplMethodObligation => {
|
||||||
infcx.tcx.sess.span_err(
|
span_err!(infcx.tcx.sess, obligation.cause.span, E0276,
|
||||||
obligation.cause.span,
|
|
||||||
format!(
|
|
||||||
"the requirement `{}` appears on the impl \
|
"the requirement `{}` appears on the impl \
|
||||||
method but not on the corresponding trait method",
|
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 {
|
match obligation.predicate {
|
||||||
@ -180,12 +171,10 @@ pub fn report_selection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
|
|||||||
|
|
||||||
if !trait_predicate.references_error() {
|
if !trait_predicate.references_error() {
|
||||||
let trait_ref = trait_predicate.to_poly_trait_ref();
|
let trait_ref = trait_predicate.to_poly_trait_ref();
|
||||||
infcx.tcx.sess.span_err(
|
span_err!(infcx.tcx.sess, obligation.cause.span, E0277,
|
||||||
obligation.cause.span,
|
|
||||||
format!(
|
|
||||||
"the trait `{}` is not implemented for the type `{}`",
|
"the trait `{}` is not implemented for the type `{}`",
|
||||||
trait_ref.user_string(infcx.tcx),
|
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]"
|
// Check if it has a custom "#[rustc_on_unimplemented]"
|
||||||
// error message, report with that message if it does
|
// error message, report with that message if it does
|
||||||
let custom_note = report_on_unimplemented(infcx, &*trait_ref.0,
|
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) => {
|
ty::Predicate::Equate(ref predicate) => {
|
||||||
let predicate = infcx.resolve_type_vars_if_possible(predicate);
|
let predicate = infcx.resolve_type_vars_if_possible(predicate);
|
||||||
let err = infcx.equality_predicate(obligation.cause.span,
|
let err = infcx.equality_predicate(obligation.cause.span,
|
||||||
&predicate).unwrap_err();
|
&predicate).err().unwrap();
|
||||||
infcx.tcx.sess.span_err(
|
span_err!(infcx.tcx.sess, obligation.cause.span, E0278,
|
||||||
obligation.cause.span,
|
|
||||||
format!(
|
|
||||||
"the requirement `{}` is not satisfied (`{}`)",
|
"the requirement `{}` is not satisfied (`{}`)",
|
||||||
predicate.user_string(infcx.tcx),
|
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) => {
|
ty::Predicate::RegionOutlives(ref predicate) => {
|
||||||
let predicate = infcx.resolve_type_vars_if_possible(predicate);
|
let predicate = infcx.resolve_type_vars_if_possible(predicate);
|
||||||
let err = infcx.region_outlives_predicate(obligation.cause.span,
|
let err = infcx.region_outlives_predicate(obligation.cause.span,
|
||||||
&predicate).unwrap_err();
|
&predicate).err().unwrap();
|
||||||
infcx.tcx.sess.span_err(
|
span_err!(infcx.tcx.sess, obligation.cause.span, E0279,
|
||||||
obligation.cause.span,
|
|
||||||
format!(
|
|
||||||
"the requirement `{}` is not satisfied (`{}`)",
|
"the requirement `{}` is not satisfied (`{}`)",
|
||||||
predicate.user_string(infcx.tcx),
|
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(..) => {
|
ty::Predicate::Projection(..) | ty::Predicate::TypeOutlives(..) => {
|
||||||
let predicate =
|
let predicate =
|
||||||
infcx.resolve_type_vars_if_possible(&obligation.predicate);
|
infcx.resolve_type_vars_if_possible(&obligation.predicate);
|
||||||
infcx.tcx.sess.span_err(
|
span_err!(infcx.tcx.sess, obligation.cause.span, E0280,
|
||||||
obligation.cause.span,
|
|
||||||
format!(
|
|
||||||
"the requirement `{}` is not satisfied",
|
"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 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);
|
let actual_trait_ref = infcx.resolve_type_vars_if_possible(&*actual_trait_ref);
|
||||||
if !ty::type_is_error(actual_trait_ref.self_ty()) {
|
if !ty::type_is_error(actual_trait_ref.self_ty()) {
|
||||||
infcx.tcx.sess.span_err(
|
span_err!(infcx.tcx.sess, obligation.cause.span, E0281,
|
||||||
obligation.cause.span,
|
|
||||||
format!(
|
|
||||||
"type mismatch: the type `{}` implements the trait `{}`, \
|
"type mismatch: the type `{}` implements the trait `{}`, \
|
||||||
but the trait `{}` is required ({})",
|
but the trait `{}` is required ({})",
|
||||||
expected_trait_ref.self_ty().user_string(infcx.tcx),
|
expected_trait_ref.self_ty().user_string(infcx.tcx),
|
||||||
expected_trait_ref.user_string(infcx.tcx),
|
expected_trait_ref.user_string(infcx.tcx),
|
||||||
actual_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);
|
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()
|
infcx.tcx.lang_items.sized_trait()
|
||||||
.map_or(false, |sized_id| sized_id == trait_ref.def_id())
|
.map_or(false, |sized_id| sized_id == trait_ref.def_id())
|
||||||
{
|
{
|
||||||
infcx.tcx.sess.span_err(
|
span_err!(infcx.tcx.sess, obligation.cause.span, E0282,
|
||||||
obligation.cause.span,
|
|
||||||
format!(
|
|
||||||
"unable to infer enough type information about `{}`; \
|
"unable to infer enough type information about `{}`; \
|
||||||
type annotations required",
|
type annotations required",
|
||||||
self_ty.user_string(infcx.tcx)).as_slice());
|
self_ty.user_string(infcx.tcx));
|
||||||
} else {
|
} else {
|
||||||
infcx.tcx.sess.span_err(
|
span_err!(infcx.tcx.sess, obligation.cause.span, E0283,
|
||||||
obligation.cause.span,
|
|
||||||
format!(
|
|
||||||
"type annotations required: cannot resolve `{}`",
|
"type annotations required: cannot resolve `{}`",
|
||||||
predicate.user_string(infcx.tcx)).as_slice());
|
predicate.user_string(infcx.tcx));;
|
||||||
note_obligation_cause(infcx, obligation);
|
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() {
|
if !infcx.tcx.sess.has_errors() {
|
||||||
infcx.tcx.sess.span_err(
|
span_err!(infcx.tcx.sess, obligation.cause.span, E0284,
|
||||||
obligation.cause.span,
|
|
||||||
format!(
|
|
||||||
"type annotations required: cannot resolve `{}`",
|
"type annotations required: cannot resolve `{}`",
|
||||||
predicate.user_string(infcx.tcx)).as_slice());
|
predicate.user_string(infcx.tcx));;
|
||||||
note_obligation_cause(infcx, obligation);
|
note_obligation_cause(infcx, obligation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,6 +84,7 @@ pub struct FulfillmentContext<'tcx> {
|
|||||||
region_obligations: NodeMap<Vec<RegionObligation<'tcx>>>,
|
region_obligations: NodeMap<Vec<RegionObligation<'tcx>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct RegionObligation<'tcx> {
|
pub struct RegionObligation<'tcx> {
|
||||||
pub sub_region: ty::Region,
|
pub sub_region: ty::Region,
|
||||||
pub sup_type: Ty<'tcx>,
|
pub sup_type: Ty<'tcx>,
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user