mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-26 05:44:26 +00:00
auto merge of #20145 : alexcrichton/rust/rollup, r=alexcrichton
This commit is contained in:
commit
62fb41c32b
@ -498,6 +498,7 @@ Robert Irelan <rirelan@gmail.com>
|
||||
Robert Knight <robertknight@gmail.com>
|
||||
Robert Millar <robert.millar@cantab.net>
|
||||
Roland Tanglao <roland@rolandtanglao.com>
|
||||
Rolf Timmermans <r.w.timmermans@gmail.com>
|
||||
Ron Dahlgren <ronald.dahlgren@gmail.com>
|
||||
Roy Frostig <rfrostig@mozilla.com>
|
||||
Russell <rpjohnst@gmail.com>
|
||||
|
131
man/rustc.1
131
man/rustc.1
@ -12,75 +12,54 @@ This program is a compiler for the Rust language, available at
|
||||
.SH OPTIONS
|
||||
|
||||
.TP
|
||||
\fB\-\-crate-name NAME\fR
|
||||
Specify the name of the crate being built
|
||||
.TP
|
||||
\fB\-\-crate-type=[bin|lib|dylib|rlib|staticlib]\fR
|
||||
Configure the flavor of rust crate that is generated (default `bin`)
|
||||
\fB\-h\fR, \fB\-\-help\fR
|
||||
Display the help message
|
||||
.TP
|
||||
\fB\-\-cfg\fR SPEC
|
||||
Configure the compilation environment
|
||||
.TP
|
||||
\fB\-\-emit=[asm,ir,bc,obj,link]\fR
|
||||
Configure the output that rustc will produce
|
||||
.TP
|
||||
\fB\-h\fR, \fB\-\-help\fR
|
||||
Display this message
|
||||
.TP
|
||||
\fB\-L\fR PATH
|
||||
Add a directory to the library search path
|
||||
.TP
|
||||
\fB\-\-no\-trans\fR
|
||||
Run all passes except translation; no output
|
||||
\fB\-l\fR NAME[:KIND]
|
||||
Link the generated crate(s) to the specified native library NAME. The optional
|
||||
KIND can be one of, static, dylib, or framework. If omitted, dylib is assumed.
|
||||
.TP
|
||||
\fB\-\-no\-analysis\fR
|
||||
Parse and expand the source, but run no analysis and produce no output
|
||||
\fB\-\-crate-type\fR [bin|lib|rlib|dylib|staticlib]
|
||||
Comma separated list of types of crates for the compiler to emit
|
||||
.TP
|
||||
\fB\-\-crate-name NAME\fR
|
||||
Specify the name of the crate being built
|
||||
.TP
|
||||
\fB\-\-emit\fR [asm|llvm-bc|llvm-ir|obj|link|dep-info]
|
||||
Configure the output that rustc will produce
|
||||
.TP
|
||||
\fB\-\-print\fR [crate-name|output-file-names|sysroot]
|
||||
Comma separated list of compiler information to print on stdout
|
||||
.TP
|
||||
\fB\-g\fR
|
||||
Emit DWARF debug information into object files generated.
|
||||
.TP
|
||||
\fB\-\-debuginfo\fR LEVEL
|
||||
Emit DWARF debug info to the objects created: 0 = no debug info, 1 =
|
||||
line-tables only (for stacktraces and breakpoints), 2 = full debug
|
||||
info with variable and type information (same as -g).
|
||||
Equivalent to \fI\-C\fR debuginfo=2
|
||||
.TP
|
||||
\fB\-O\fR
|
||||
Equivalent to \fI\-\-opt\-level=2\fR
|
||||
Equivalent to \fI\-C\fR opt-level=2
|
||||
.TP
|
||||
\fB\-o\fR FILENAME
|
||||
Write output to <filename>. Ignored if more than one --emit is specified.
|
||||
.TP
|
||||
\fB\-\-opt\-level\fR LEVEL
|
||||
Optimize with possible levels 0-3
|
||||
Write output to <filename>. Ignored if multiple \fI\-\-emit\fR outputs are
|
||||
specified.
|
||||
.TP
|
||||
\fB\-\-out\-dir\fR DIR
|
||||
Write output to compiler-chosen filename in <dir>. Ignored if -o is specified.
|
||||
(default the current directory)
|
||||
Write output to compiler-chosen filename in <dir>. Ignored if \fI\-o\fR is
|
||||
specified. Defaults to the current directory.
|
||||
.TP
|
||||
\fB\-\-parse\-only\fR
|
||||
Parse only; do not compile, assemble, or link
|
||||
.TP
|
||||
\fB\-\-pretty\fR [TYPE]
|
||||
Pretty-print the input instead of compiling; valid types are: normal
|
||||
(un-annotated source), expanded (crates expanded), typed (crates
|
||||
expanded, with type annotations), identified (fully parenthesized,
|
||||
AST nodes and blocks with IDs), or flowgraph=<nodeid> (graphviz
|
||||
formatted flowgraph for node)
|
||||
.TP
|
||||
\fB\-\-dep-info\fR [FILENAME]
|
||||
Output dependency info to <filename> after compiling, in a format suitable
|
||||
for use by Makefiles.
|
||||
.TP
|
||||
\fB\-\-sysroot\fR PATH
|
||||
Override the system root
|
||||
\fB\-\-explain\fR OPT
|
||||
Provide a detailed explanation of an error message
|
||||
.TP
|
||||
\fB\-\-test\fR
|
||||
Build a test harness
|
||||
.TP
|
||||
\fB\-\-target\fR TRIPLE
|
||||
Target triple cpu-manufacturer-kernel[-os] to compile for (see
|
||||
http://sources.redhat.com/autobook/autobook/autobook_17.html
|
||||
for details)
|
||||
Target triple cpu-manufacturer-kernel[-os] to compile for (see chapter 3.4 of
|
||||
http://www.sourceware.org/autobook/ for details)
|
||||
.TP
|
||||
\fB\-W\fR help
|
||||
Print 'lint' options and default settings
|
||||
@ -97,15 +76,30 @@ Set lint denied
|
||||
\fB\-F\fR OPT, \fB\-\-forbid\fR OPT
|
||||
Set lint forbidden
|
||||
.TP
|
||||
\fB\-Z\fR FLAG
|
||||
Set internal debugging options. Use "-Z help" to print available options.
|
||||
.TP
|
||||
\fB\-C\fR FLAG[=VAL], \fB\-\-codegen\fR FLAG[=VAL]
|
||||
Set a codegen-related flag to the value specified. Use "-C help" to print
|
||||
available flags. See CODEGEN OPTIONS below
|
||||
.TP
|
||||
\fB\-v\fR, \fB\-\-version\fR
|
||||
\fB\-V\fR, \fB\-\-version\fR
|
||||
Print version info and exit
|
||||
.TP
|
||||
\fB\-v\fR, \fB\-\-verbose\fR
|
||||
Use verbose output
|
||||
.TP
|
||||
\fB\-\-extern\fR NAME=PATH
|
||||
Specify where an external rust library is located
|
||||
.TP
|
||||
\fB\-\-sysroot\fR PATH
|
||||
Override the system root
|
||||
.TP
|
||||
\fB\-Z\fR FLAG
|
||||
Set internal debugging options. Use "-Z help" to print available options.
|
||||
.TP
|
||||
\fB\-\-color\fR auto|always|never
|
||||
Configure coloring of output:
|
||||
auto = colorize, if output goes to a tty (default);
|
||||
always = always colorize output;
|
||||
never = never colorize output
|
||||
|
||||
.SH CODEGEN OPTIONS
|
||||
|
||||
@ -121,6 +115,9 @@ objects.
|
||||
A space-separated list of extra arguments to pass to the linker when the linker
|
||||
is invoked.
|
||||
.TP
|
||||
\fBlto\fR
|
||||
Perform LLVM link-time optimizations.
|
||||
.TP
|
||||
\fBtarget-cpu\fR=help
|
||||
Selects a target processor. If the value is 'help', then a list of available
|
||||
CPUs is printed.
|
||||
@ -167,8 +164,38 @@ Prefers dynamic linking to static linking.
|
||||
\fBno-integrated-as\fR
|
||||
Force usage of an external assembler rather than LLVM's integrated one.
|
||||
.TP
|
||||
\fBno-redzone\fR
|
||||
Disable the use of the redzone.
|
||||
.TP
|
||||
\fBrelocation-model\fR=[pic,static,dynamic-no-pic]
|
||||
The relocation model to use. (default: pic)
|
||||
The relocation model to use. (Default: pic)
|
||||
.TP
|
||||
\fBcode-model\fR=[small,kernel,medium,large]
|
||||
Choose the code model to use.
|
||||
.TP
|
||||
\fBmetadata\fR=val
|
||||
Metadata to mangle symbol names with.
|
||||
.TP
|
||||
\fBextra-filename\fR=val
|
||||
Extra data to put in each output filename.
|
||||
.TP
|
||||
\fBcodegen-units\fR=val
|
||||
Divide crate into N units to optimize in parallel.
|
||||
.TP
|
||||
\fBremark\fR=val
|
||||
Print remarks for these optimization passes (space separated, or "all").
|
||||
.TP
|
||||
\fBno-stack-check\fR
|
||||
Disable checks for stack exhaustion (a memory-safety hazard!).
|
||||
.TP
|
||||
\fBdebuginfo\fR=val
|
||||
Debug info emission level:
|
||||
0 = no debug info;
|
||||
1 = line-tables only (for stacktraces and breakpoints);
|
||||
2 = full debug info with variable and type information.
|
||||
.TP
|
||||
\fBopt-level\fR=val
|
||||
Optimize with possible levels 0-3
|
||||
|
||||
.SH "EXAMPLES"
|
||||
To build an executable from a source file with a main function:
|
||||
|
5
mk/rt.mk
5
mk/rt.mk
@ -35,7 +35,7 @@
|
||||
# that's per-target so you're allowed to conditionally add files based on the
|
||||
# target.
|
||||
################################################################################
|
||||
NATIVE_LIBS := rust_builtin hoedown morestack miniz context_switch \
|
||||
NATIVE_LIBS := rust_builtin hoedown morestack miniz \
|
||||
rustrt_native rust_test_helpers
|
||||
|
||||
# $(1) is the target triple
|
||||
@ -58,8 +58,7 @@ NATIVE_DEPS_rustrt_native_$(1) := \
|
||||
arch/$$(HOST_$(1))/record_sp.S
|
||||
NATIVE_DEPS_rust_test_helpers_$(1) := rust_test_helpers.c
|
||||
NATIVE_DEPS_morestack_$(1) := arch/$$(HOST_$(1))/morestack.S
|
||||
NATIVE_DEPS_context_switch_$(1) := \
|
||||
arch/$$(HOST_$(1))/_context.S
|
||||
|
||||
|
||||
################################################################################
|
||||
# You shouldn't find it that necessary to edit anything below this line.
|
||||
|
@ -152,7 +152,7 @@ pub fn parse_config(args: Vec<String> ) -> Config {
|
||||
matches.opt_str("ratchet-metrics").map(|s| Path::new(s)),
|
||||
ratchet_noise_percent:
|
||||
matches.opt_str("ratchet-noise-percent")
|
||||
.and_then(|s| from_str::<f64>(s.as_slice())),
|
||||
.and_then(|s| s.as_slice().parse::<f64>()),
|
||||
runtool: matches.opt_str("runtool"),
|
||||
host_rustcflags: matches.opt_str("host-rustcflags"),
|
||||
target_rustcflags: matches.opt_str("target-rustcflags"),
|
||||
@ -190,9 +190,7 @@ pub fn log_config(config: &Config) {
|
||||
logv(c, format!("filter: {}",
|
||||
opt_str(&config.filter
|
||||
.as_ref()
|
||||
.map(|re| {
|
||||
re.to_string().into_string()
|
||||
}))));
|
||||
.map(|re| re.to_string()))));
|
||||
logv(c, format!("runtool: {}", opt_str(&config.runtool)));
|
||||
logv(c, format!("host-rustcflags: {}",
|
||||
opt_str(&config.host_rustcflags)));
|
||||
|
@ -351,8 +351,8 @@ pub fn gdb_version_to_int(version_string: &str) -> int {
|
||||
panic!("{}", error_string);
|
||||
}
|
||||
|
||||
let major: int = from_str(components[0]).expect(error_string);
|
||||
let minor: int = from_str(components[1]).expect(error_string);
|
||||
let major: int = components[0].parse().expect(error_string);
|
||||
let minor: int = components[1].parse().expect(error_string);
|
||||
|
||||
return major * 1000 + minor;
|
||||
}
|
||||
@ -362,6 +362,6 @@ pub fn lldb_version_to_int(version_string: &str) -> int {
|
||||
"Encountered LLDB version string with unexpected format: {}",
|
||||
version_string);
|
||||
let error_string = error_string.as_slice();
|
||||
let major: int = from_str(version_string).expect(error_string);
|
||||
let major: int = version_string.parse().expect(error_string);
|
||||
return major;
|
||||
}
|
||||
|
@ -1361,7 +1361,7 @@ fn split_maybe_args(argstr: &Option<String>) -> Vec<String> {
|
||||
s.as_slice()
|
||||
.split(' ')
|
||||
.filter_map(|s| {
|
||||
if s.is_whitespace() {
|
||||
if s.chars().all(|c| c.is_whitespace()) {
|
||||
None
|
||||
} else {
|
||||
Some(s.to_string())
|
||||
|
@ -1010,8 +1010,8 @@ in the original declaration.
|
||||
Finally, because fields have names, we can access the field through dot
|
||||
notation: `origin.x`.
|
||||
|
||||
The values in structs are immutable, like other bindings in Rust. However, you
|
||||
can use `mut` to make them mutable:
|
||||
The values in structs are immutable by default, like other bindings in Rust.
|
||||
Use `mut` to make them mutable:
|
||||
|
||||
```{rust}
|
||||
struct Point {
|
||||
@ -2257,10 +2257,10 @@ a function for that:
|
||||
let input = io::stdin().read_line()
|
||||
.ok()
|
||||
.expect("Failed to read line");
|
||||
let input_num: Option<uint> = from_str(input.as_slice());
|
||||
let input_num: Option<uint> = input.parse();
|
||||
```
|
||||
|
||||
The `from_str` function takes in a `&str` value and converts it into something.
|
||||
The `parse` function takes in a `&str` value and converts it into something.
|
||||
We tell it what kind of something with a type hint. Remember our type hint with
|
||||
`random()`? It looked like this:
|
||||
|
||||
@ -2279,8 +2279,8 @@ In this case, we say `x` is a `uint` explicitly, so Rust is able to properly
|
||||
tell `random()` what to generate. In a similar fashion, both of these work:
|
||||
|
||||
```{rust,ignore}
|
||||
let input_num = from_str::<uint>("5"); // input_num: Option<uint>
|
||||
let input_num: Option<uint> = from_str("5"); // input_num: Option<uint>
|
||||
let input_num = "5".parse::<uint>(); // input_num: Option<uint>
|
||||
let input_num: Option<uint> = "5".parse(); // input_num: Option<uint>
|
||||
```
|
||||
|
||||
Anyway, with us now converting our input to a number, our code looks like this:
|
||||
@ -2301,7 +2301,7 @@ fn main() {
|
||||
let input = io::stdin().read_line()
|
||||
.ok()
|
||||
.expect("Failed to read line");
|
||||
let input_num: Option<uint> = from_str(input.as_slice());
|
||||
let input_num: Option<uint> = input.parse();
|
||||
|
||||
println!("You guessed: {}", input_num);
|
||||
|
||||
@ -2350,7 +2350,7 @@ fn main() {
|
||||
let input = io::stdin().read_line()
|
||||
.ok()
|
||||
.expect("Failed to read line");
|
||||
let input_num: Option<uint> = from_str(input.as_slice());
|
||||
let input_num: Option<uint> = input.parse();
|
||||
|
||||
let num = match input_num {
|
||||
Some(num) => num,
|
||||
@ -2395,7 +2395,7 @@ Uh, what? But we did!
|
||||
|
||||
... actually, we didn't. See, when you get a line of input from `stdin()`,
|
||||
you get all the input. Including the `\n` character from you pressing Enter.
|
||||
Therefore, `from_str()` sees the string `"5\n"` and says "nope, that's not a
|
||||
Therefore, `parse()` sees the string `"5\n"` and says "nope, that's not a
|
||||
number; there's non-number stuff in there!" Luckily for us, `&str`s have an easy
|
||||
method we can use defined on them: `trim()`. One small modification, and our
|
||||
code looks like this:
|
||||
@ -2416,7 +2416,7 @@ fn main() {
|
||||
let input = io::stdin().read_line()
|
||||
.ok()
|
||||
.expect("Failed to read line");
|
||||
let input_num: Option<uint> = from_str(input.as_slice().trim());
|
||||
let input_num: Option<uint> = input.trim().parse();
|
||||
|
||||
let num = match input_num {
|
||||
Some(num) => num,
|
||||
@ -2491,7 +2491,7 @@ fn main() {
|
||||
let input = io::stdin().read_line()
|
||||
.ok()
|
||||
.expect("Failed to read line");
|
||||
let input_num: Option<uint> = from_str(input.as_slice().trim());
|
||||
let input_num: Option<uint> = input.trim().parse();
|
||||
|
||||
let num = match input_num {
|
||||
Some(num) => num,
|
||||
@ -2566,7 +2566,7 @@ fn main() {
|
||||
let input = io::stdin().read_line()
|
||||
.ok()
|
||||
.expect("Failed to read line");
|
||||
let input_num: Option<uint> = from_str(input.as_slice().trim());
|
||||
let input_num: Option<uint> = input.trim().parse();
|
||||
|
||||
let num = match input_num {
|
||||
Some(num) => num,
|
||||
@ -2621,7 +2621,7 @@ fn main() {
|
||||
let input = io::stdin().read_line()
|
||||
.ok()
|
||||
.expect("Failed to read line");
|
||||
let input_num: Option<uint> = from_str(input.as_slice().trim());
|
||||
let input_num: Option<uint> = input.trim().parse();
|
||||
|
||||
let num = match input_num {
|
||||
Some(num) => num,
|
||||
@ -2697,7 +2697,7 @@ fn main() {
|
||||
let input = io::stdin().read_line()
|
||||
.ok()
|
||||
.expect("Failed to read line");
|
||||
let input_num: Option<uint> = from_str(input.as_slice().trim());
|
||||
let input_num: Option<uint> = input.trim().parse();
|
||||
|
||||
let num = match input_num {
|
||||
Some(num) => num,
|
||||
|
@ -3177,7 +3177,7 @@ Some examples of call expressions:
|
||||
# fn add(x: int, y: int) -> int { 0 }
|
||||
|
||||
let x: int = add(1, 2);
|
||||
let pi: Option<f32> = from_str("3.14");
|
||||
let pi: Option<f32> = "3.14".parse();
|
||||
```
|
||||
|
||||
### Lambda expressions
|
||||
|
@ -239,8 +239,8 @@ impl<T: Ord> BinaryHeap<T> {
|
||||
/// }
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn iter(&self) -> Items<T> {
|
||||
Items { iter: self.data.iter() }
|
||||
pub fn iter(&self) -> Iter<T> {
|
||||
Iter { iter: self.data.iter() }
|
||||
}
|
||||
|
||||
/// Creates a consuming iterator, that is, one that moves each value out of
|
||||
@ -260,8 +260,8 @@ impl<T: Ord> BinaryHeap<T> {
|
||||
/// }
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn into_iter(self) -> MoveItems<T> {
|
||||
MoveItems { iter: self.data.into_iter() }
|
||||
pub fn into_iter(self) -> IntoIter<T> {
|
||||
IntoIter { iter: self.data.into_iter() }
|
||||
}
|
||||
|
||||
/// Returns the greatest item in a queue, or `None` if it is empty.
|
||||
@ -272,15 +272,16 @@ impl<T: Ord> BinaryHeap<T> {
|
||||
/// use std::collections::BinaryHeap;
|
||||
///
|
||||
/// let mut heap = BinaryHeap::new();
|
||||
/// assert_eq!(heap.top(), None);
|
||||
/// assert_eq!(heap.peek(), None);
|
||||
///
|
||||
/// heap.push(1i);
|
||||
/// heap.push(5i);
|
||||
/// heap.push(2i);
|
||||
/// assert_eq!(heap.top(), Some(&5i));
|
||||
/// assert_eq!(heap.peek(), Some(&5i));
|
||||
///
|
||||
/// ```
|
||||
pub fn top(&self) -> Option<&T> {
|
||||
#[stable]
|
||||
pub fn peek(&self) -> Option<&T> {
|
||||
self.data.get(0)
|
||||
}
|
||||
|
||||
@ -388,7 +389,7 @@ impl<T: Ord> BinaryHeap<T> {
|
||||
/// heap.push(1i);
|
||||
///
|
||||
/// assert_eq!(heap.len(), 3);
|
||||
/// assert_eq!(heap.top(), Some(&5i));
|
||||
/// assert_eq!(heap.peek(), Some(&5i));
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn push(&mut self, item: T) {
|
||||
@ -412,7 +413,7 @@ impl<T: Ord> BinaryHeap<T> {
|
||||
/// assert_eq!(heap.push_pop(3i), 5);
|
||||
/// assert_eq!(heap.push_pop(9i), 9);
|
||||
/// assert_eq!(heap.len(), 2);
|
||||
/// assert_eq!(heap.top(), Some(&3i));
|
||||
/// assert_eq!(heap.peek(), Some(&3i));
|
||||
/// ```
|
||||
pub fn push_pop(&mut self, mut item: T) -> T {
|
||||
match self.data.get_mut(0) {
|
||||
@ -442,7 +443,7 @@ impl<T: Ord> BinaryHeap<T> {
|
||||
/// assert_eq!(heap.replace(1i), None);
|
||||
/// assert_eq!(heap.replace(3i), Some(1i));
|
||||
/// assert_eq!(heap.len(), 1);
|
||||
/// assert_eq!(heap.top(), Some(&3i));
|
||||
/// assert_eq!(heap.peek(), Some(&3i));
|
||||
/// ```
|
||||
pub fn replace(&mut self, mut item: T) -> Option<T> {
|
||||
if !self.is_empty() {
|
||||
@ -571,11 +572,11 @@ impl<T: Ord> BinaryHeap<T> {
|
||||
}
|
||||
|
||||
/// `BinaryHeap` iterator.
|
||||
pub struct Items<'a, T: 'a> {
|
||||
iter: slice::Items<'a, T>,
|
||||
pub struct Iter <'a, T: 'a> {
|
||||
iter: slice::Iter<'a, T>,
|
||||
}
|
||||
|
||||
impl<'a, T> Iterator<&'a T> for Items<'a, T> {
|
||||
impl<'a, T> Iterator<&'a T> for Iter<'a, T> {
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<&'a T> { self.iter.next() }
|
||||
|
||||
@ -583,19 +584,19 @@ impl<'a, T> Iterator<&'a T> for Items<'a, T> {
|
||||
fn size_hint(&self) -> (uint, Option<uint>) { self.iter.size_hint() }
|
||||
}
|
||||
|
||||
impl<'a, T> DoubleEndedIterator<&'a T> for Items<'a, T> {
|
||||
impl<'a, T> DoubleEndedIterator<&'a T> for Iter<'a, T> {
|
||||
#[inline]
|
||||
fn next_back(&mut self) -> Option<&'a T> { self.iter.next_back() }
|
||||
}
|
||||
|
||||
impl<'a, T> ExactSizeIterator<&'a T> for Items<'a, T> {}
|
||||
impl<'a, T> ExactSizeIterator<&'a T> for Iter<'a, T> {}
|
||||
|
||||
/// An iterator that moves out of a `BinaryHeap`.
|
||||
pub struct MoveItems<T> {
|
||||
iter: vec::MoveItems<T>,
|
||||
pub struct IntoIter<T> {
|
||||
iter: vec::IntoIter<T>,
|
||||
}
|
||||
|
||||
impl<T> Iterator<T> for MoveItems<T> {
|
||||
impl<T> Iterator<T> for IntoIter<T> {
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<T> { self.iter.next() }
|
||||
|
||||
@ -603,12 +604,12 @@ impl<T> Iterator<T> for MoveItems<T> {
|
||||
fn size_hint(&self) -> (uint, Option<uint>) { self.iter.size_hint() }
|
||||
}
|
||||
|
||||
impl<T> DoubleEndedIterator<T> for MoveItems<T> {
|
||||
impl<T> DoubleEndedIterator<T> for IntoIter<T> {
|
||||
#[inline]
|
||||
fn next_back(&mut self) -> Option<T> { self.iter.next_back() }
|
||||
}
|
||||
|
||||
impl<T> ExactSizeIterator<T> for MoveItems<T> {}
|
||||
impl<T> ExactSizeIterator<T> for IntoIter<T> {}
|
||||
|
||||
/// An iterator that drains a `BinaryHeap`.
|
||||
pub struct Drain<'a, T: 'a> {
|
||||
@ -714,13 +715,13 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_top_and_pop() {
|
||||
fn test_peek_and_pop() {
|
||||
let data = vec!(2u, 4, 6, 2, 1, 8, 10, 3, 5, 7, 0, 9, 1);
|
||||
let mut sorted = data.clone();
|
||||
sorted.sort();
|
||||
let mut heap = BinaryHeap::from_vec(data);
|
||||
while !heap.is_empty() {
|
||||
assert_eq!(heap.top().unwrap(), sorted.last().unwrap());
|
||||
assert_eq!(heap.peek().unwrap(), sorted.last().unwrap());
|
||||
assert_eq!(heap.pop().unwrap(), sorted.pop().unwrap());
|
||||
}
|
||||
}
|
||||
@ -729,44 +730,44 @@ mod tests {
|
||||
fn test_push() {
|
||||
let mut heap = BinaryHeap::from_vec(vec!(2i, 4, 9));
|
||||
assert_eq!(heap.len(), 3);
|
||||
assert!(*heap.top().unwrap() == 9);
|
||||
assert!(*heap.peek().unwrap() == 9);
|
||||
heap.push(11);
|
||||
assert_eq!(heap.len(), 4);
|
||||
assert!(*heap.top().unwrap() == 11);
|
||||
assert!(*heap.peek().unwrap() == 11);
|
||||
heap.push(5);
|
||||
assert_eq!(heap.len(), 5);
|
||||
assert!(*heap.top().unwrap() == 11);
|
||||
assert!(*heap.peek().unwrap() == 11);
|
||||
heap.push(27);
|
||||
assert_eq!(heap.len(), 6);
|
||||
assert!(*heap.top().unwrap() == 27);
|
||||
assert!(*heap.peek().unwrap() == 27);
|
||||
heap.push(3);
|
||||
assert_eq!(heap.len(), 7);
|
||||
assert!(*heap.top().unwrap() == 27);
|
||||
assert!(*heap.peek().unwrap() == 27);
|
||||
heap.push(103);
|
||||
assert_eq!(heap.len(), 8);
|
||||
assert!(*heap.top().unwrap() == 103);
|
||||
assert!(*heap.peek().unwrap() == 103);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_push_unique() {
|
||||
let mut heap = BinaryHeap::from_vec(vec!(box 2i, box 4, box 9));
|
||||
assert_eq!(heap.len(), 3);
|
||||
assert!(*heap.top().unwrap() == box 9);
|
||||
assert!(*heap.peek().unwrap() == box 9);
|
||||
heap.push(box 11);
|
||||
assert_eq!(heap.len(), 4);
|
||||
assert!(*heap.top().unwrap() == box 11);
|
||||
assert!(*heap.peek().unwrap() == box 11);
|
||||
heap.push(box 5);
|
||||
assert_eq!(heap.len(), 5);
|
||||
assert!(*heap.top().unwrap() == box 11);
|
||||
assert!(*heap.peek().unwrap() == box 11);
|
||||
heap.push(box 27);
|
||||
assert_eq!(heap.len(), 6);
|
||||
assert!(*heap.top().unwrap() == box 27);
|
||||
assert!(*heap.peek().unwrap() == box 27);
|
||||
heap.push(box 3);
|
||||
assert_eq!(heap.len(), 7);
|
||||
assert!(*heap.top().unwrap() == box 27);
|
||||
assert!(*heap.peek().unwrap() == box 27);
|
||||
heap.push(box 103);
|
||||
assert_eq!(heap.len(), 8);
|
||||
assert!(*heap.top().unwrap() == box 103);
|
||||
assert!(*heap.peek().unwrap() == box 103);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -831,9 +832,9 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_empty_top() {
|
||||
fn test_empty_peek() {
|
||||
let empty = BinaryHeap::<int>::new();
|
||||
assert!(empty.top().is_none());
|
||||
assert!(empty.peek().is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -88,7 +88,7 @@ pub struct BTreeMap<K, V> {
|
||||
}
|
||||
|
||||
/// An abstract base over-which all other BTree iterators are built.
|
||||
struct AbsEntries<T> {
|
||||
struct AbsIter<T> {
|
||||
lca: T,
|
||||
left: RingBuf<T>,
|
||||
right: RingBuf<T>,
|
||||
@ -96,28 +96,28 @@ struct AbsEntries<T> {
|
||||
}
|
||||
|
||||
/// An iterator over a BTreeMap's entries.
|
||||
pub struct Entries<'a, K: 'a, V: 'a> {
|
||||
inner: AbsEntries<Traversal<'a, K, V>>
|
||||
pub struct Iter<'a, K: 'a, V: 'a> {
|
||||
inner: AbsIter<Traversal<'a, K, V>>
|
||||
}
|
||||
|
||||
/// A mutable iterator over a BTreeMap's entries.
|
||||
pub struct MutEntries<'a, K: 'a, V: 'a> {
|
||||
inner: AbsEntries<MutTraversal<'a, K, V>>
|
||||
pub struct IterMut<'a, K: 'a, V: 'a> {
|
||||
inner: AbsIter<MutTraversal<'a, K, V>>
|
||||
}
|
||||
|
||||
/// An owning iterator over a BTreeMap's entries.
|
||||
pub struct MoveEntries<K, V> {
|
||||
inner: AbsEntries<MoveTraversal<K, V>>
|
||||
pub struct IntoIter<K, V> {
|
||||
inner: AbsIter<MoveTraversal<K, V>>
|
||||
}
|
||||
|
||||
/// An iterator over a BTreeMap's keys.
|
||||
pub struct Keys<'a, K: 'a, V: 'a> {
|
||||
inner: Map<(&'a K, &'a V), &'a K, Entries<'a, K, V>, fn((&'a K, &'a V)) -> &'a K>
|
||||
inner: Map<(&'a K, &'a V), &'a K, Iter<'a, K, V>, fn((&'a K, &'a V)) -> &'a K>
|
||||
}
|
||||
|
||||
/// An iterator over a BTreeMap's values.
|
||||
pub struct Values<'a, K: 'a, V: 'a> {
|
||||
inner: Map<(&'a K, &'a V), &'a V, Entries<'a, K, V>, fn((&'a K, &'a V)) -> &'a V>
|
||||
inner: Map<(&'a K, &'a V), &'a V, Iter<'a, K, V>, fn((&'a K, &'a V)) -> &'a V>
|
||||
}
|
||||
|
||||
/// A view into a single entry in a map, which may either be vacant or occupied.
|
||||
@ -929,7 +929,7 @@ enum StackOp<T> {
|
||||
}
|
||||
|
||||
impl<K, V, E, T: Traverse<E> + DoubleEndedIterator<TraversalItem<K, V, E>>>
|
||||
Iterator<(K, V)> for AbsEntries<T> {
|
||||
Iterator<(K, V)> for AbsIter<T> {
|
||||
// This function is pretty long, but only because there's a lot of cases to consider.
|
||||
// Our iterator represents two search paths, left and right, to the smallest and largest
|
||||
// elements we have yet to yield. lca represents the least common ancestor of these two paths,
|
||||
@ -995,7 +995,7 @@ impl<K, V, E, T: Traverse<E> + DoubleEndedIterator<TraversalItem<K, V, E>>>
|
||||
}
|
||||
|
||||
impl<K, V, E, T: Traverse<E> + DoubleEndedIterator<TraversalItem<K, V, E>>>
|
||||
DoubleEndedIterator<(K, V)> for AbsEntries<T> {
|
||||
DoubleEndedIterator<(K, V)> for AbsIter<T> {
|
||||
// next_back is totally symmetric to next
|
||||
fn next_back(&mut self) -> Option<(K, V)> {
|
||||
loop {
|
||||
@ -1032,34 +1032,34 @@ impl<K, V, E, T: Traverse<E> + DoubleEndedIterator<TraversalItem<K, V, E>>>
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, K, V> Iterator<(&'a K, &'a V)> for Entries<'a, K, V> {
|
||||
impl<'a, K, V> Iterator<(&'a K, &'a V)> for Iter<'a, K, V> {
|
||||
fn next(&mut self) -> Option<(&'a K, &'a V)> { self.inner.next() }
|
||||
fn size_hint(&self) -> (uint, Option<uint>) { self.inner.size_hint() }
|
||||
}
|
||||
impl<'a, K, V> DoubleEndedIterator<(&'a K, &'a V)> for Entries<'a, K, V> {
|
||||
impl<'a, K, V> DoubleEndedIterator<(&'a K, &'a V)> for Iter<'a, K, V> {
|
||||
fn next_back(&mut self) -> Option<(&'a K, &'a V)> { self.inner.next_back() }
|
||||
}
|
||||
impl<'a, K, V> ExactSizeIterator<(&'a K, &'a V)> for Entries<'a, K, V> {}
|
||||
impl<'a, K, V> ExactSizeIterator<(&'a K, &'a V)> for Iter<'a, K, V> {}
|
||||
|
||||
|
||||
impl<'a, K, V> Iterator<(&'a K, &'a mut V)> for MutEntries<'a, K, V> {
|
||||
impl<'a, K, V> Iterator<(&'a K, &'a mut V)> for IterMut<'a, K, V> {
|
||||
fn next(&mut self) -> Option<(&'a K, &'a mut V)> { self.inner.next() }
|
||||
fn size_hint(&self) -> (uint, Option<uint>) { self.inner.size_hint() }
|
||||
}
|
||||
impl<'a, K, V> DoubleEndedIterator<(&'a K, &'a mut V)> for MutEntries<'a, K, V> {
|
||||
impl<'a, K, V> DoubleEndedIterator<(&'a K, &'a mut V)> for IterMut<'a, K, V> {
|
||||
fn next_back(&mut self) -> Option<(&'a K, &'a mut V)> { self.inner.next_back() }
|
||||
}
|
||||
impl<'a, K, V> ExactSizeIterator<(&'a K, &'a mut V)> for MutEntries<'a, K, V> {}
|
||||
impl<'a, K, V> ExactSizeIterator<(&'a K, &'a mut V)> for IterMut<'a, K, V> {}
|
||||
|
||||
|
||||
impl<K, V> Iterator<(K, V)> for MoveEntries<K, V> {
|
||||
impl<K, V> Iterator<(K, V)> for IntoIter<K, V> {
|
||||
fn next(&mut self) -> Option<(K, V)> { self.inner.next() }
|
||||
fn size_hint(&self) -> (uint, Option<uint>) { self.inner.size_hint() }
|
||||
}
|
||||
impl<K, V> DoubleEndedIterator<(K, V)> for MoveEntries<K, V> {
|
||||
impl<K, V> DoubleEndedIterator<(K, V)> for IntoIter<K, V> {
|
||||
fn next_back(&mut self) -> Option<(K, V)> { self.inner.next_back() }
|
||||
}
|
||||
impl<K, V> ExactSizeIterator<(K, V)> for MoveEntries<K, V> {}
|
||||
impl<K, V> ExactSizeIterator<(K, V)> for IntoIter<K, V> {}
|
||||
|
||||
|
||||
impl<'a, K, V> Iterator<&'a K> for Keys<'a, K, V> {
|
||||
@ -1140,10 +1140,10 @@ impl<K, V> BTreeMap<K, V> {
|
||||
/// assert_eq!((*first_key, *first_value), (1u, "a"));
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn iter<'a>(&'a self) -> Entries<'a, K, V> {
|
||||
pub fn iter<'a>(&'a self) -> Iter<'a, K, V> {
|
||||
let len = self.len();
|
||||
Entries {
|
||||
inner: AbsEntries {
|
||||
Iter {
|
||||
inner: AbsIter {
|
||||
lca: Traverse::traverse(&self.root),
|
||||
left: RingBuf::new(),
|
||||
right: RingBuf::new(),
|
||||
@ -1172,10 +1172,10 @@ impl<K, V> BTreeMap<K, V> {
|
||||
/// }
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn iter_mut<'a>(&'a mut self) -> MutEntries<'a, K, V> {
|
||||
pub fn iter_mut<'a>(&'a mut self) -> IterMut<'a, K, V> {
|
||||
let len = self.len();
|
||||
MutEntries {
|
||||
inner: AbsEntries {
|
||||
IterMut {
|
||||
inner: AbsIter {
|
||||
lca: Traverse::traverse(&mut self.root),
|
||||
left: RingBuf::new(),
|
||||
right: RingBuf::new(),
|
||||
@ -1201,10 +1201,10 @@ impl<K, V> BTreeMap<K, V> {
|
||||
/// }
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn into_iter(self) -> MoveEntries<K, V> {
|
||||
pub fn into_iter(self) -> IntoIter<K, V> {
|
||||
let len = self.len();
|
||||
MoveEntries {
|
||||
inner: AbsEntries {
|
||||
IntoIter {
|
||||
inner: AbsIter {
|
||||
lca: Traverse::traverse(self.root),
|
||||
left: RingBuf::new(),
|
||||
right: RingBuf::new(),
|
||||
@ -1230,6 +1230,7 @@ impl<K, V> BTreeMap<K, V> {
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn keys<'a>(&'a self) -> Keys<'a, K, V> {
|
||||
fn first<A, B>((a, _): (A, B)) -> A { a }
|
||||
let first: fn((&'a K, &'a V)) -> &'a K = first; // coerce to fn pointer
|
||||
|
||||
Keys { inner: self.iter().map(first) }
|
||||
}
|
||||
@ -1251,6 +1252,7 @@ impl<K, V> BTreeMap<K, V> {
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn values<'a>(&'a self) -> Values<'a, K, V> {
|
||||
fn second<A, B>((_, b): (A, B)) -> B { b }
|
||||
let second: fn((&'a K, &'a V)) -> &'a V = second; // coerce to fn pointer
|
||||
|
||||
Values { inner: self.iter().map(second) }
|
||||
}
|
||||
@ -1288,6 +1290,30 @@ impl<K, V> BTreeMap<K, V> {
|
||||
|
||||
impl<K: Ord, V> BTreeMap<K, V> {
|
||||
/// Gets the given key's corresponding entry in the map for in-place manipulation.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use std::collections::BTreeMap;
|
||||
/// use std::collections::btree_map::Entry;
|
||||
///
|
||||
/// let mut count: BTreeMap<&str, uint> = BTreeMap::new();
|
||||
///
|
||||
/// // count the number of occurrences of letters in the vec
|
||||
/// for x in vec!["a","b","a","c","a","b"].iter() {
|
||||
/// match count.entry(*x) {
|
||||
/// Entry::Vacant(view) => {
|
||||
/// view.set(1);
|
||||
/// },
|
||||
/// Entry::Occupied(mut view) => {
|
||||
/// let v = view.get_mut();
|
||||
/// *v += 1;
|
||||
/// },
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// assert_eq!(count["a"], 3u);
|
||||
/// ```
|
||||
pub fn entry<'a>(&'a mut self, mut key: K) -> Entry<'a, K, V> {
|
||||
// same basic logic of `swap` and `pop`, blended together
|
||||
let mut stack = stack::PartialSearchStack::new(self);
|
||||
|
@ -1382,14 +1382,14 @@ pub enum TraversalItem<K, V, E> {
|
||||
}
|
||||
|
||||
/// A traversal over a node's entries and edges
|
||||
pub type Traversal<'a, K, V> = AbsTraversal<ElemsAndEdges<Zip<slice::Items<'a, K>,
|
||||
slice::Items<'a, V>>,
|
||||
slice::Items<'a, Node<K, V>>>>;
|
||||
pub type Traversal<'a, K, V> = AbsTraversal<ElemsAndEdges<Zip<slice::Iter<'a, K>,
|
||||
slice::Iter<'a, V>>,
|
||||
slice::Iter<'a, Node<K, V>>>>;
|
||||
|
||||
/// A mutable traversal over a node's entries and edges
|
||||
pub type MutTraversal<'a, K, V> = AbsTraversal<ElemsAndEdges<Zip<slice::Items<'a, K>,
|
||||
slice::MutItems<'a, V>>,
|
||||
slice::MutItems<'a, Node<K, V>>>>;
|
||||
pub type MutTraversal<'a, K, V> = AbsTraversal<ElemsAndEdges<Zip<slice::Iter<'a, K>,
|
||||
slice::IterMut<'a, V>>,
|
||||
slice::IterMut<'a, Node<K, V>>>>;
|
||||
|
||||
/// An owning traversal over a node's entries and edges
|
||||
pub type MoveTraversal<K, V> = AbsTraversal<MoveTraversalImpl<K, V>>;
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
use core::prelude::*;
|
||||
|
||||
use btree_map::{BTreeMap, Keys, MoveEntries};
|
||||
use btree_map::{BTreeMap, Keys};
|
||||
use std::hash::Hash;
|
||||
use core::borrow::BorrowFrom;
|
||||
use core::default::Default;
|
||||
@ -33,37 +33,37 @@ pub struct BTreeSet<T>{
|
||||
}
|
||||
|
||||
/// An iterator over a BTreeSet's items.
|
||||
pub struct Items<'a, T: 'a> {
|
||||
pub struct Iter<'a, T: 'a> {
|
||||
iter: Keys<'a, T, ()>
|
||||
}
|
||||
|
||||
/// An owning iterator over a BTreeSet's items.
|
||||
pub struct MoveItems<T> {
|
||||
iter: Map<(T, ()), T, MoveEntries<T, ()>, fn((T, ())) -> T>
|
||||
pub struct IntoIter<T> {
|
||||
iter: Map<(T, ()), T, ::btree_map::IntoIter<T, ()>, fn((T, ())) -> T>
|
||||
}
|
||||
|
||||
/// A lazy iterator producing elements in the set difference (in-order).
|
||||
pub struct DifferenceItems<'a, T:'a> {
|
||||
a: Peekable<&'a T, Items<'a, T>>,
|
||||
b: Peekable<&'a T, Items<'a, T>>,
|
||||
pub struct Difference<'a, T:'a> {
|
||||
a: Peekable<&'a T, Iter<'a, T>>,
|
||||
b: Peekable<&'a T, Iter<'a, T>>,
|
||||
}
|
||||
|
||||
/// A lazy iterator producing elements in the set symmetric difference (in-order).
|
||||
pub struct SymDifferenceItems<'a, T:'a> {
|
||||
a: Peekable<&'a T, Items<'a, T>>,
|
||||
b: Peekable<&'a T, Items<'a, T>>,
|
||||
pub struct SymmetricDifference<'a, T:'a> {
|
||||
a: Peekable<&'a T, Iter<'a, T>>,
|
||||
b: Peekable<&'a T, Iter<'a, T>>,
|
||||
}
|
||||
|
||||
/// A lazy iterator producing elements in the set intersection (in-order).
|
||||
pub struct IntersectionItems<'a, T:'a> {
|
||||
a: Peekable<&'a T, Items<'a, T>>,
|
||||
b: Peekable<&'a T, Items<'a, T>>,
|
||||
pub struct Intersection<'a, T:'a> {
|
||||
a: Peekable<&'a T, Iter<'a, T>>,
|
||||
b: Peekable<&'a T, Iter<'a, T>>,
|
||||
}
|
||||
|
||||
/// A lazy iterator producing elements in the set union (in-order).
|
||||
pub struct UnionItems<'a, T:'a> {
|
||||
a: Peekable<&'a T, Items<'a, T>>,
|
||||
b: Peekable<&'a T, Items<'a, T>>,
|
||||
pub struct Union<'a, T:'a> {
|
||||
a: Peekable<&'a T, Iter<'a, T>>,
|
||||
b: Peekable<&'a T, Iter<'a, T>>,
|
||||
}
|
||||
|
||||
impl<T: Ord> BTreeSet<T> {
|
||||
@ -107,8 +107,8 @@ impl<T> BTreeSet<T> {
|
||||
/// assert_eq!(v, vec![1u,2,3,4]);
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn iter<'a>(&'a self) -> Items<'a, T> {
|
||||
Items { iter: self.map.keys() }
|
||||
pub fn iter<'a>(&'a self) -> Iter<'a, T> {
|
||||
Iter { iter: self.map.keys() }
|
||||
}
|
||||
|
||||
/// Gets an iterator for moving out the BtreeSet's contents.
|
||||
@ -124,10 +124,11 @@ impl<T> BTreeSet<T> {
|
||||
/// assert_eq!(v, vec![1u,2,3,4]);
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn into_iter(self) -> MoveItems<T> {
|
||||
pub fn into_iter(self) -> IntoIter<T> {
|
||||
fn first<A, B>((a, _): (A, B)) -> A { a }
|
||||
let first: fn((T, ())) -> T = first; // coerce to fn pointer
|
||||
|
||||
MoveItems { iter: self.map.into_iter().map(first) }
|
||||
IntoIter { iter: self.map.into_iter().map(first) }
|
||||
}
|
||||
}
|
||||
|
||||
@ -151,8 +152,8 @@ impl<T: Ord> BTreeSet<T> {
|
||||
/// assert_eq!(diff, vec![1u]);
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn difference<'a>(&'a self, other: &'a BTreeSet<T>) -> DifferenceItems<'a, T> {
|
||||
DifferenceItems{a: self.iter().peekable(), b: other.iter().peekable()}
|
||||
pub fn difference<'a>(&'a self, other: &'a BTreeSet<T>) -> Difference<'a, T> {
|
||||
Difference{a: self.iter().peekable(), b: other.iter().peekable()}
|
||||
}
|
||||
|
||||
/// Visits the values representing the symmetric difference, in ascending order.
|
||||
@ -175,8 +176,8 @@ impl<T: Ord> BTreeSet<T> {
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn symmetric_difference<'a>(&'a self, other: &'a BTreeSet<T>)
|
||||
-> SymDifferenceItems<'a, T> {
|
||||
SymDifferenceItems{a: self.iter().peekable(), b: other.iter().peekable()}
|
||||
-> SymmetricDifference<'a, T> {
|
||||
SymmetricDifference{a: self.iter().peekable(), b: other.iter().peekable()}
|
||||
}
|
||||
|
||||
/// Visits the values representing the intersection, in ascending order.
|
||||
@ -199,8 +200,8 @@ impl<T: Ord> BTreeSet<T> {
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn intersection<'a>(&'a self, other: &'a BTreeSet<T>)
|
||||
-> IntersectionItems<'a, T> {
|
||||
IntersectionItems{a: self.iter().peekable(), b: other.iter().peekable()}
|
||||
-> Intersection<'a, T> {
|
||||
Intersection{a: self.iter().peekable(), b: other.iter().peekable()}
|
||||
}
|
||||
|
||||
/// Visits the values representing the union, in ascending order.
|
||||
@ -220,8 +221,8 @@ impl<T: Ord> BTreeSet<T> {
|
||||
/// assert_eq!(union, vec![1u,2]);
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn union<'a>(&'a self, other: &'a BTreeSet<T>) -> UnionItems<'a, T> {
|
||||
UnionItems{a: self.iter().peekable(), b: other.iter().peekable()}
|
||||
pub fn union<'a>(&'a self, other: &'a BTreeSet<T>) -> Union<'a, T> {
|
||||
Union{a: self.iter().peekable(), b: other.iter().peekable()}
|
||||
}
|
||||
|
||||
/// Return the number of elements in the set
|
||||
@ -544,24 +545,24 @@ impl<T: Show> Show for BTreeSet<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T> Iterator<&'a T> for Items<'a, T> {
|
||||
impl<'a, T> Iterator<&'a T> for Iter<'a, T> {
|
||||
fn next(&mut self) -> Option<&'a T> { self.iter.next() }
|
||||
fn size_hint(&self) -> (uint, Option<uint>) { self.iter.size_hint() }
|
||||
}
|
||||
impl<'a, T> DoubleEndedIterator<&'a T> for Items<'a, T> {
|
||||
impl<'a, T> DoubleEndedIterator<&'a T> for Iter<'a, T> {
|
||||
fn next_back(&mut self) -> Option<&'a T> { self.iter.next_back() }
|
||||
}
|
||||
impl<'a, T> ExactSizeIterator<&'a T> for Items<'a, T> {}
|
||||
impl<'a, T> ExactSizeIterator<&'a T> for Iter<'a, T> {}
|
||||
|
||||
|
||||
impl<T> Iterator<T> for MoveItems<T> {
|
||||
impl<T> Iterator<T> for IntoIter<T> {
|
||||
fn next(&mut self) -> Option<T> { self.iter.next() }
|
||||
fn size_hint(&self) -> (uint, Option<uint>) { self.iter.size_hint() }
|
||||
}
|
||||
impl<T> DoubleEndedIterator<T> for MoveItems<T> {
|
||||
impl<T> DoubleEndedIterator<T> for IntoIter<T> {
|
||||
fn next_back(&mut self) -> Option<T> { self.iter.next_back() }
|
||||
}
|
||||
impl<T> ExactSizeIterator<T> for MoveItems<T> {}
|
||||
impl<T> ExactSizeIterator<T> for IntoIter<T> {}
|
||||
|
||||
/// Compare `x` and `y`, but return `short` if x is None and `long` if y is None
|
||||
fn cmp_opt<T: Ord>(x: Option<&T>, y: Option<&T>,
|
||||
@ -573,7 +574,7 @@ fn cmp_opt<T: Ord>(x: Option<&T>, y: Option<&T>,
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: Ord> Iterator<&'a T> for DifferenceItems<'a, T> {
|
||||
impl<'a, T: Ord> Iterator<&'a T> for Difference<'a, T> {
|
||||
fn next(&mut self) -> Option<&'a T> {
|
||||
loop {
|
||||
match cmp_opt(self.a.peek(), self.b.peek(), Less, Less) {
|
||||
@ -585,7 +586,7 @@ impl<'a, T: Ord> Iterator<&'a T> for DifferenceItems<'a, T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: Ord> Iterator<&'a T> for SymDifferenceItems<'a, T> {
|
||||
impl<'a, T: Ord> Iterator<&'a T> for SymmetricDifference<'a, T> {
|
||||
fn next(&mut self) -> Option<&'a T> {
|
||||
loop {
|
||||
match cmp_opt(self.a.peek(), self.b.peek(), Greater, Less) {
|
||||
@ -597,7 +598,7 @@ impl<'a, T: Ord> Iterator<&'a T> for SymDifferenceItems<'a, T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: Ord> Iterator<&'a T> for IntersectionItems<'a, T> {
|
||||
impl<'a, T: Ord> Iterator<&'a T> for Intersection<'a, T> {
|
||||
fn next(&mut self) -> Option<&'a T> {
|
||||
loop {
|
||||
let o_cmp = match (self.a.peek(), self.b.peek()) {
|
||||
@ -615,7 +616,7 @@ impl<'a, T: Ord> Iterator<&'a T> for IntersectionItems<'a, T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: Ord> Iterator<&'a T> for UnionItems<'a, T> {
|
||||
impl<'a, T: Ord> Iterator<&'a T> for Union<'a, T> {
|
||||
fn next(&mut self) -> Option<&'a T> {
|
||||
loop {
|
||||
match cmp_opt(self.a.peek(), self.b.peek(), Greater, Less) {
|
||||
|
@ -51,21 +51,21 @@ struct Node<T> {
|
||||
}
|
||||
|
||||
/// An iterator over references to the items of a `DList`.
|
||||
pub struct Items<'a, T:'a> {
|
||||
pub struct Iter<'a, T:'a> {
|
||||
head: &'a Link<T>,
|
||||
tail: Rawlink<Node<T>>,
|
||||
nelem: uint,
|
||||
}
|
||||
|
||||
// FIXME #11820: the &'a Option<> of the Link stops clone working.
|
||||
impl<'a, T> Clone for Items<'a, T> {
|
||||
fn clone(&self) -> Items<'a, T> { *self }
|
||||
impl<'a, T> Clone for Iter<'a, T> {
|
||||
fn clone(&self) -> Iter<'a, T> { *self }
|
||||
}
|
||||
|
||||
impl<'a,T> Copy for Items<'a,T> {}
|
||||
impl<'a,T> Copy for Iter<'a,T> {}
|
||||
|
||||
/// An iterator over mutable references to the items of a `DList`.
|
||||
pub struct MutItems<'a, T:'a> {
|
||||
pub struct IterMut<'a, T:'a> {
|
||||
list: &'a mut DList<T>,
|
||||
head: Rawlink<Node<T>>,
|
||||
tail: Rawlink<Node<T>>,
|
||||
@ -74,7 +74,7 @@ pub struct MutItems<'a, T:'a> {
|
||||
|
||||
/// An iterator over mutable references to the items of a `DList`.
|
||||
#[deriving(Clone)]
|
||||
pub struct MoveItems<T> {
|
||||
pub struct IntoIter<T> {
|
||||
list: DList<T>
|
||||
}
|
||||
|
||||
@ -394,19 +394,19 @@ impl<T> DList<T> {
|
||||
/// Provides a forward iterator.
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn iter<'a>(&'a self) -> Items<'a, T> {
|
||||
Items{nelem: self.len(), head: &self.list_head, tail: self.list_tail}
|
||||
pub fn iter<'a>(&'a self) -> Iter<'a, T> {
|
||||
Iter{nelem: self.len(), head: &self.list_head, tail: self.list_tail}
|
||||
}
|
||||
|
||||
/// Provides a forward iterator with mutable references.
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn iter_mut<'a>(&'a mut self) -> MutItems<'a, T> {
|
||||
pub fn iter_mut<'a>(&'a mut self) -> IterMut<'a, T> {
|
||||
let head_raw = match self.list_head {
|
||||
Some(ref mut h) => Rawlink::some(&mut **h),
|
||||
None => Rawlink::none(),
|
||||
};
|
||||
MutItems{
|
||||
IterMut{
|
||||
nelem: self.len(),
|
||||
head: head_raw,
|
||||
tail: self.list_tail,
|
||||
@ -417,8 +417,8 @@ impl<T> DList<T> {
|
||||
/// Consumes the list into an iterator yielding elements by value.
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn into_iter(self) -> MoveItems<T> {
|
||||
MoveItems{list: self}
|
||||
pub fn into_iter(self) -> IntoIter<T> {
|
||||
IntoIter{list: self}
|
||||
}
|
||||
|
||||
/// Returns `true` if the `DList` is empty.
|
||||
@ -451,7 +451,7 @@ impl<T> DList<T> {
|
||||
/// Provides a reference to the front element, or `None` if the list is
|
||||
/// empty.
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
#[stable]
|
||||
pub fn front(&self) -> Option<&T> {
|
||||
self.list_head.as_ref().map(|head| &head.value)
|
||||
}
|
||||
@ -459,7 +459,7 @@ impl<T> DList<T> {
|
||||
/// Provides a mutable reference to the front element, or `None` if the list
|
||||
/// is empty.
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
#[stable]
|
||||
pub fn front_mut(&mut self) -> Option<&mut T> {
|
||||
self.list_head.as_mut().map(|head| &mut head.value)
|
||||
}
|
||||
@ -467,7 +467,7 @@ impl<T> DList<T> {
|
||||
/// Provides a reference to the back element, or `None` if the list is
|
||||
/// empty.
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
#[stable]
|
||||
pub fn back(&self) -> Option<&T> {
|
||||
self.list_tail.resolve_immut().as_ref().map(|tail| &tail.value)
|
||||
}
|
||||
@ -475,7 +475,7 @@ impl<T> DList<T> {
|
||||
/// Provides a mutable reference to the back element, or `None` if the list
|
||||
/// is empty.
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
#[stable]
|
||||
pub fn back_mut(&mut self) -> Option<&mut T> {
|
||||
self.list_tail.resolve().map(|tail| &mut tail.value)
|
||||
}
|
||||
@ -579,7 +579,7 @@ impl<T> Drop for DList<T> {
|
||||
}
|
||||
|
||||
|
||||
impl<'a, A> Iterator<&'a A> for Items<'a, A> {
|
||||
impl<'a, A> Iterator<&'a A> for Iter<'a, A> {
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<&'a A> {
|
||||
if self.nelem == 0 {
|
||||
@ -598,7 +598,7 @@ impl<'a, A> Iterator<&'a A> for Items<'a, A> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, A> DoubleEndedIterator<&'a A> for Items<'a, A> {
|
||||
impl<'a, A> DoubleEndedIterator<&'a A> for Iter<'a, A> {
|
||||
#[inline]
|
||||
fn next_back(&mut self) -> Option<&'a A> {
|
||||
if self.nelem == 0 {
|
||||
@ -612,9 +612,9 @@ impl<'a, A> DoubleEndedIterator<&'a A> for Items<'a, A> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, A> ExactSizeIterator<&'a A> for Items<'a, A> {}
|
||||
impl<'a, A> ExactSizeIterator<&'a A> for Iter<'a, A> {}
|
||||
|
||||
impl<'a, A> Iterator<&'a mut A> for MutItems<'a, A> {
|
||||
impl<'a, A> Iterator<&'a mut A> for IterMut<'a, A> {
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<&'a mut A> {
|
||||
if self.nelem == 0 {
|
||||
@ -636,7 +636,7 @@ impl<'a, A> Iterator<&'a mut A> for MutItems<'a, A> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, A> DoubleEndedIterator<&'a mut A> for MutItems<'a, A> {
|
||||
impl<'a, A> DoubleEndedIterator<&'a mut A> for IterMut<'a, A> {
|
||||
#[inline]
|
||||
fn next_back(&mut self) -> Option<&'a mut A> {
|
||||
if self.nelem == 0 {
|
||||
@ -650,7 +650,7 @@ impl<'a, A> DoubleEndedIterator<&'a mut A> for MutItems<'a, A> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, A> ExactSizeIterator<&'a mut A> for MutItems<'a, A> {}
|
||||
impl<'a, A> ExactSizeIterator<&'a mut A> for IterMut<'a, A> {}
|
||||
|
||||
/// Allows mutating a `DList` while iterating.
|
||||
pub trait ListInsertion<A> {
|
||||
@ -664,8 +664,8 @@ pub trait ListInsertion<A> {
|
||||
fn peek_next<'a>(&'a mut self) -> Option<&'a mut A>;
|
||||
}
|
||||
|
||||
// private methods for MutItems
|
||||
impl<'a, A> MutItems<'a, A> {
|
||||
// private methods for IterMut
|
||||
impl<'a, A> IterMut<'a, A> {
|
||||
fn insert_next_node(&mut self, mut ins_node: Box<Node<A>>) {
|
||||
// Insert before `self.head` so that it is between the
|
||||
// previously yielded element and self.head.
|
||||
@ -687,7 +687,7 @@ impl<'a, A> MutItems<'a, A> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, A> ListInsertion<A> for MutItems<'a, A> {
|
||||
impl<'a, A> ListInsertion<A> for IterMut<'a, A> {
|
||||
#[inline]
|
||||
fn insert_next(&mut self, elt: A) {
|
||||
self.insert_next_node(box Node::new(elt))
|
||||
@ -702,7 +702,7 @@ impl<'a, A> ListInsertion<A> for MutItems<'a, A> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<A> Iterator<A> for MoveItems<A> {
|
||||
impl<A> Iterator<A> for IntoIter<A> {
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<A> { self.list.pop_front() }
|
||||
|
||||
@ -712,7 +712,7 @@ impl<A> Iterator<A> for MoveItems<A> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<A> DoubleEndedIterator<A> for MoveItems<A> {
|
||||
impl<A> DoubleEndedIterator<A> for IntoIter<A> {
|
||||
#[inline]
|
||||
fn next_back(&mut self) -> Option<A> { self.list.pop_back() }
|
||||
}
|
||||
|
@ -178,8 +178,8 @@ impl<E:CLike> EnumSet<E> {
|
||||
|
||||
/// Returns an iterator over an `EnumSet`.
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn iter(&self) -> Items<E> {
|
||||
Items::new(self.bits)
|
||||
pub fn iter(&self) -> Iter<E> {
|
||||
Iter::new(self.bits)
|
||||
}
|
||||
}
|
||||
|
||||
@ -208,18 +208,18 @@ impl<E:CLike> BitXor<EnumSet<E>, EnumSet<E>> for EnumSet<E> {
|
||||
}
|
||||
|
||||
/// An iterator over an EnumSet
|
||||
pub struct Items<E> {
|
||||
pub struct Iter<E> {
|
||||
index: uint,
|
||||
bits: uint,
|
||||
}
|
||||
|
||||
impl<E:CLike> Items<E> {
|
||||
fn new(bits: uint) -> Items<E> {
|
||||
Items { index: 0, bits: bits }
|
||||
impl<E:CLike> Iter<E> {
|
||||
fn new(bits: uint) -> Iter<E> {
|
||||
Iter { index: 0, bits: bits }
|
||||
}
|
||||
}
|
||||
|
||||
impl<E:CLike> Iterator<E> for Items<E> {
|
||||
impl<E:CLike> Iterator<E> for Iter<E> {
|
||||
fn next(&mut self) -> Option<E> {
|
||||
if self.bits == 0 {
|
||||
return None;
|
||||
|
@ -121,7 +121,7 @@ mod prelude {
|
||||
// in core and collections (may differ).
|
||||
pub use slice::{PartialEqSliceExt, OrdSliceExt};
|
||||
pub use slice::{AsSlice, SliceExt};
|
||||
pub use str::{from_str, Str, StrPrelude};
|
||||
pub use str::{from_str, Str};
|
||||
|
||||
// from other crates.
|
||||
pub use alloc::boxed::Box;
|
||||
@ -129,7 +129,7 @@ mod prelude {
|
||||
|
||||
// from collections.
|
||||
pub use slice::{CloneSliceExt, VectorVector};
|
||||
pub use str::{IntoMaybeOwned, UnicodeStrPrelude, StrAllocating, StrVector};
|
||||
pub use str::{IntoMaybeOwned, StrVector};
|
||||
pub use string::{String, ToString};
|
||||
pub use vec::Vec;
|
||||
}
|
||||
|
@ -228,6 +228,7 @@ impl<T> RingBuf<T> {
|
||||
/// assert_eq!(buf[0], 5);
|
||||
/// assert_eq!(buf[2], 3);
|
||||
/// ```
|
||||
#[stable]
|
||||
pub fn swap(&mut self, i: uint, j: uint) {
|
||||
assert!(i < self.len());
|
||||
assert!(j < self.len());
|
||||
@ -376,8 +377,8 @@ impl<T> RingBuf<T> {
|
||||
/// assert_eq!(buf.iter().collect::<Vec<&int>>().as_slice(), b);
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn iter(&self) -> Items<T> {
|
||||
Items {
|
||||
pub fn iter(&self) -> Iter<T> {
|
||||
Iter {
|
||||
tail: self.tail,
|
||||
head: self.head,
|
||||
ring: unsafe { self.buffer_as_slice() }
|
||||
@ -402,8 +403,8 @@ impl<T> RingBuf<T> {
|
||||
/// assert_eq!(buf.iter_mut().collect::<Vec<&mut int>>()[], b);
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn iter_mut<'a>(&'a mut self) -> MutItems<'a, T> {
|
||||
MutItems {
|
||||
pub fn iter_mut<'a>(&'a mut self) -> IterMut<'a, T> {
|
||||
IterMut {
|
||||
tail: self.tail,
|
||||
head: self.head,
|
||||
cap: self.cap,
|
||||
@ -414,8 +415,8 @@ impl<T> RingBuf<T> {
|
||||
|
||||
/// Consumes the list into an iterator yielding elements by value.
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn into_iter(self) -> MoveItems<T> {
|
||||
MoveItems {
|
||||
pub fn into_iter(self) -> IntoIter<T> {
|
||||
IntoIter {
|
||||
inner: self,
|
||||
}
|
||||
}
|
||||
@ -546,7 +547,7 @@ impl<T> RingBuf<T> {
|
||||
/// d.push_back(2i);
|
||||
/// assert_eq!(d.front(), Some(&1i));
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
#[stable]
|
||||
pub fn front(&self) -> Option<&T> {
|
||||
if !self.is_empty() { Some(&self[0]) } else { None }
|
||||
}
|
||||
@ -570,7 +571,7 @@ impl<T> RingBuf<T> {
|
||||
/// }
|
||||
/// assert_eq!(d.front(), Some(&9i));
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
#[stable]
|
||||
pub fn front_mut(&mut self) -> Option<&mut T> {
|
||||
if !self.is_empty() { Some(&mut self[0]) } else { None }
|
||||
}
|
||||
@ -590,7 +591,7 @@ impl<T> RingBuf<T> {
|
||||
/// d.push_back(2i);
|
||||
/// assert_eq!(d.back(), Some(&2i));
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
#[stable]
|
||||
pub fn back(&self) -> Option<&T> {
|
||||
if !self.is_empty() { Some(&self[self.len() - 1]) } else { None }
|
||||
}
|
||||
@ -614,7 +615,7 @@ impl<T> RingBuf<T> {
|
||||
/// }
|
||||
/// assert_eq!(d.back(), Some(&9i));
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
#[stable]
|
||||
pub fn back_mut(&mut self) -> Option<&mut T> {
|
||||
let len = self.len();
|
||||
if !self.is_empty() { Some(&mut self[len - 1]) } else { None }
|
||||
@ -1122,13 +1123,13 @@ fn count(tail: uint, head: uint, size: uint) -> uint {
|
||||
}
|
||||
|
||||
/// `RingBuf` iterator.
|
||||
pub struct Items<'a, T:'a> {
|
||||
pub struct Iter<'a, T:'a> {
|
||||
ring: &'a [T],
|
||||
tail: uint,
|
||||
head: uint
|
||||
}
|
||||
|
||||
impl<'a, T> Iterator<&'a T> for Items<'a, T> {
|
||||
impl<'a, T> Iterator<&'a T> for Iter<'a, T> {
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<&'a T> {
|
||||
if self.tail == self.head {
|
||||
@ -1146,7 +1147,7 @@ impl<'a, T> Iterator<&'a T> for Items<'a, T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T> DoubleEndedIterator<&'a T> for Items<'a, T> {
|
||||
impl<'a, T> DoubleEndedIterator<&'a T> for Iter<'a, T> {
|
||||
#[inline]
|
||||
fn next_back(&mut self) -> Option<&'a T> {
|
||||
if self.tail == self.head {
|
||||
@ -1157,9 +1158,9 @@ impl<'a, T> DoubleEndedIterator<&'a T> for Items<'a, T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T> ExactSizeIterator<&'a T> for Items<'a, T> {}
|
||||
impl<'a, T> ExactSizeIterator<&'a T> for Iter<'a, T> {}
|
||||
|
||||
impl<'a, T> RandomAccessIterator<&'a T> for Items<'a, T> {
|
||||
impl<'a, T> RandomAccessIterator<&'a T> for Iter<'a, T> {
|
||||
#[inline]
|
||||
fn indexable(&self) -> uint {
|
||||
let (len, _) = self.size_hint();
|
||||
@ -1177,11 +1178,11 @@ impl<'a, T> RandomAccessIterator<&'a T> for Items<'a, T> {
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME This was implemented differently from Items because of a problem
|
||||
// FIXME This was implemented differently from Iter because of a problem
|
||||
// with returning the mutable reference. I couldn't find a way to
|
||||
// make the lifetime checker happy so, but there should be a way.
|
||||
/// `RingBuf` mutable iterator.
|
||||
pub struct MutItems<'a, T:'a> {
|
||||
pub struct IterMut<'a, T:'a> {
|
||||
ptr: *mut T,
|
||||
tail: uint,
|
||||
head: uint,
|
||||
@ -1189,7 +1190,7 @@ pub struct MutItems<'a, T:'a> {
|
||||
marker: marker::ContravariantLifetime<'a>,
|
||||
}
|
||||
|
||||
impl<'a, T> Iterator<&'a mut T> for MutItems<'a, T> {
|
||||
impl<'a, T> Iterator<&'a mut T> for IterMut<'a, T> {
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<&'a mut T> {
|
||||
if self.tail == self.head {
|
||||
@ -1210,7 +1211,7 @@ impl<'a, T> Iterator<&'a mut T> for MutItems<'a, T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T> DoubleEndedIterator<&'a mut T> for MutItems<'a, T> {
|
||||
impl<'a, T> DoubleEndedIterator<&'a mut T> for IterMut<'a, T> {
|
||||
#[inline]
|
||||
fn next_back(&mut self) -> Option<&'a mut T> {
|
||||
if self.tail == self.head {
|
||||
@ -1224,14 +1225,14 @@ impl<'a, T> DoubleEndedIterator<&'a mut T> for MutItems<'a, T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T> ExactSizeIterator<&'a mut T> for MutItems<'a, T> {}
|
||||
impl<'a, T> ExactSizeIterator<&'a mut T> for IterMut<'a, T> {}
|
||||
|
||||
// A by-value RingBuf iterator
|
||||
pub struct MoveItems<T> {
|
||||
pub struct IntoIter<T> {
|
||||
inner: RingBuf<T>,
|
||||
}
|
||||
|
||||
impl<T> Iterator<T> for MoveItems<T> {
|
||||
impl<T> Iterator<T> for IntoIter<T> {
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<T> {
|
||||
self.inner.pop_front()
|
||||
@ -1244,14 +1245,14 @@ impl<T> Iterator<T> for MoveItems<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> DoubleEndedIterator<T> for MoveItems<T> {
|
||||
impl<T> DoubleEndedIterator<T> for IntoIter<T> {
|
||||
#[inline]
|
||||
fn next_back(&mut self) -> Option<T> {
|
||||
self.inner.pop_back()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ExactSizeIterator<T> for MoveItems<T> {}
|
||||
impl<T> ExactSizeIterator<T> for IntoIter<T> {}
|
||||
|
||||
/// A draining RingBuf iterator
|
||||
pub struct Drain<'a, T: 'a> {
|
||||
|
@ -37,7 +37,7 @@
|
||||
//!
|
||||
//! ## Structs
|
||||
//!
|
||||
//! There are several structs that are useful for slices, such as `Items`, which
|
||||
//! There are several structs that are useful for slices, such as `Iter`, which
|
||||
//! represents iteration over a slice.
|
||||
//!
|
||||
//! ## Traits
|
||||
@ -104,7 +104,7 @@ use self::Direction::*;
|
||||
use vec::Vec;
|
||||
|
||||
pub use core::slice::{Chunks, AsSlice, SplitsN, Windows};
|
||||
pub use core::slice::{Items, MutItems, PartialEqSliceExt};
|
||||
pub use core::slice::{Iter, IterMut, PartialEqSliceExt};
|
||||
pub use core::slice::{ImmutableIntSlice, MutableIntSlice};
|
||||
pub use core::slice::{MutSplits, MutChunks, Splits};
|
||||
pub use core::slice::{bytes, mut_ref_slice, ref_slice};
|
||||
@ -771,7 +771,7 @@ pub trait SliceExt<T> for Sized? {
|
||||
|
||||
/// Returns an iterator over the slice
|
||||
#[unstable = "iterator type may change"]
|
||||
fn iter(&self) -> Items<T>;
|
||||
fn iter(&self) -> Iter<T>;
|
||||
|
||||
/// Returns an iterator over subslices separated by elements that match
|
||||
/// `pred`. The matched element is not contained in the subslices.
|
||||
@ -970,7 +970,7 @@ pub trait SliceExt<T> for Sized? {
|
||||
|
||||
/// Returns an iterator that allows modifying each value
|
||||
#[unstable = "waiting on iterator type name conventions"]
|
||||
fn iter_mut(&mut self) -> MutItems<T>;
|
||||
fn iter_mut(&mut self) -> IterMut<T>;
|
||||
|
||||
/// Returns a mutable pointer to the first element of a slice, or `None` if it is empty
|
||||
#[unstable = "name may change"]
|
||||
@ -1137,7 +1137,7 @@ impl<T> SliceExt<T> for [T] {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn iter<'a>(&'a self) -> Items<'a, T> {
|
||||
fn iter<'a>(&'a self) -> Iter<'a, T> {
|
||||
core_slice::SliceExt::iter(self)
|
||||
}
|
||||
|
||||
@ -1246,7 +1246,7 @@ impl<T> SliceExt<T> for [T] {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn iter_mut<'a>(&'a mut self) -> MutItems<'a, T> {
|
||||
fn iter_mut<'a>(&'a mut self) -> IterMut<'a, T> {
|
||||
core_slice::SliceExt::iter_mut(self)
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -21,13 +21,12 @@ use core::hash;
|
||||
use core::mem;
|
||||
use core::ptr;
|
||||
use core::ops;
|
||||
// FIXME: ICE's abound if you import the `Slice` type while importing `Slice` trait
|
||||
use core::raw::Slice as RawSlice;
|
||||
use unicode::str as unicode_str;
|
||||
use unicode::str::Utf16Item;
|
||||
|
||||
use slice::CloneSliceExt;
|
||||
use str;
|
||||
use str::{CharRange, CowString, FromStr, StrAllocating};
|
||||
use str::MaybeOwned::Owned;
|
||||
use str::{mod, CharRange, FromStr, Utf8Error};
|
||||
use vec::{DerefVec, Vec, as_vec};
|
||||
|
||||
/// A growable string stored as a UTF-8 encoded buffer.
|
||||
@ -87,27 +86,31 @@ impl String {
|
||||
/// Returns the vector as a string buffer, if possible, taking care not to
|
||||
/// copy it.
|
||||
///
|
||||
/// Returns `Err` with the original vector if the vector contains invalid
|
||||
/// UTF-8.
|
||||
/// # Failure
|
||||
///
|
||||
/// If the given vector is not valid UTF-8, then the original vector and the
|
||||
/// corresponding error is returned.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// # #![allow(deprecated)]
|
||||
/// use std::str::Utf8Error;
|
||||
///
|
||||
/// let hello_vec = vec![104, 101, 108, 108, 111];
|
||||
/// let s = String::from_utf8(hello_vec);
|
||||
/// assert_eq!(s, Ok("hello".to_string()));
|
||||
///
|
||||
/// let invalid_vec = vec![240, 144, 128];
|
||||
/// let s = String::from_utf8(invalid_vec);
|
||||
/// assert_eq!(s, Err(vec![240, 144, 128]));
|
||||
/// assert_eq!(s, Err((vec![240, 144, 128], Utf8Error::TooShort)));
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "error type may change"]
|
||||
pub fn from_utf8(vec: Vec<u8>) -> Result<String, Vec<u8>> {
|
||||
if str::is_utf8(vec.as_slice()) {
|
||||
Ok(String { vec: vec })
|
||||
} else {
|
||||
Err(vec)
|
||||
pub fn from_utf8(vec: Vec<u8>) -> Result<String, (Vec<u8>, Utf8Error)> {
|
||||
match str::from_utf8(vec.as_slice()) {
|
||||
Ok(..) => Ok(String { vec: vec }),
|
||||
Err(e) => Err((vec, e))
|
||||
}
|
||||
}
|
||||
|
||||
@ -123,8 +126,9 @@ impl String {
|
||||
/// ```
|
||||
#[unstable = "return type may change"]
|
||||
pub fn from_utf8_lossy<'a>(v: &'a [u8]) -> CowString<'a> {
|
||||
if str::is_utf8(v) {
|
||||
return Cow::Borrowed(unsafe { mem::transmute(v) })
|
||||
match str::from_utf8(v) {
|
||||
Ok(s) => return Cow::Borrowed(s),
|
||||
Err(..) => {}
|
||||
}
|
||||
|
||||
static TAG_CONT_U8: u8 = 128u8;
|
||||
@ -173,7 +177,7 @@ impl String {
|
||||
if byte < 128u8 {
|
||||
// subseqidx handles this
|
||||
} else {
|
||||
let w = str::utf8_char_width(byte);
|
||||
let w = unicode_str::utf8_char_width(byte);
|
||||
|
||||
match w {
|
||||
2 => {
|
||||
@ -235,7 +239,7 @@ impl String {
|
||||
res.as_mut_vec().push_all(v[subseqidx..total])
|
||||
};
|
||||
}
|
||||
Cow::Owned(res.into_string())
|
||||
Cow::Owned(res)
|
||||
}
|
||||
|
||||
/// Decode a UTF-16 encoded vector `v` into a `String`, returning `None`
|
||||
@ -256,10 +260,10 @@ impl String {
|
||||
#[unstable = "error value in return may change"]
|
||||
pub fn from_utf16(v: &[u16]) -> Option<String> {
|
||||
let mut s = String::with_capacity(v.len());
|
||||
for c in str::utf16_items(v) {
|
||||
for c in unicode_str::utf16_items(v) {
|
||||
match c {
|
||||
str::ScalarValue(c) => s.push(c),
|
||||
str::LoneSurrogate(_) => return None
|
||||
Utf16Item::ScalarValue(c) => s.push(c),
|
||||
Utf16Item::LoneSurrogate(_) => return None
|
||||
}
|
||||
}
|
||||
Some(s)
|
||||
@ -281,7 +285,7 @@ impl String {
|
||||
/// ```
|
||||
#[stable]
|
||||
pub fn from_utf16_lossy(v: &[u16]) -> String {
|
||||
str::utf16_items(v).map(|c| c.to_char_lossy()).collect()
|
||||
unicode_str::utf16_items(v).map(|c| c.to_char_lossy()).collect()
|
||||
}
|
||||
|
||||
/// Convert a vector of `char`s to a `String`.
|
||||
@ -812,21 +816,12 @@ impl<'a, 'b> PartialEq<CowString<'a>> for &'b str {
|
||||
}
|
||||
|
||||
#[experimental = "waiting on Str stabilization"]
|
||||
#[allow(deprecated)]
|
||||
impl Str for String {
|
||||
#[inline]
|
||||
#[stable]
|
||||
fn as_slice<'a>(&'a self) -> &'a str {
|
||||
unsafe {
|
||||
mem::transmute(self.vec.as_slice())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[experimental = "waiting on StrAllocating stabilization"]
|
||||
impl StrAllocating for String {
|
||||
#[inline]
|
||||
fn into_string(self) -> String {
|
||||
self
|
||||
unsafe { mem::transmute(self.vec.as_slice()) }
|
||||
}
|
||||
}
|
||||
|
||||
@ -841,7 +836,7 @@ impl Default for String {
|
||||
#[experimental = "waiting on Show stabilization"]
|
||||
impl fmt::Show for String {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.as_slice().fmt(f)
|
||||
(**self).fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
@ -849,7 +844,7 @@ impl fmt::Show for String {
|
||||
impl<H: hash::Writer> hash::Hash<H> for String {
|
||||
#[inline]
|
||||
fn hash(&self, hasher: &mut H) {
|
||||
self.as_slice().hash(hasher)
|
||||
(**self).hash(hasher)
|
||||
}
|
||||
}
|
||||
|
||||
@ -873,7 +868,7 @@ impl<'a> Add<&'a str, String> for String {
|
||||
impl ops::Slice<uint, str> for String {
|
||||
#[inline]
|
||||
fn as_slice_<'a>(&'a self) -> &'a str {
|
||||
self.as_slice()
|
||||
unsafe { mem::transmute(self.vec.as_slice()) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -894,7 +889,9 @@ impl ops::Slice<uint, str> for String {
|
||||
|
||||
#[experimental = "waiting on Deref stabilization"]
|
||||
impl ops::Deref<str> for String {
|
||||
fn deref<'a>(&'a self) -> &'a str { self.as_slice() }
|
||||
fn deref<'a>(&'a self) -> &'a str {
|
||||
unsafe { mem::transmute(self.vec[]) }
|
||||
}
|
||||
}
|
||||
|
||||
/// Wrapper type providing a `&String` reference via `Deref`.
|
||||
@ -1015,11 +1012,24 @@ pub mod raw {
|
||||
}
|
||||
}
|
||||
|
||||
/// A clone-on-write string
|
||||
#[stable]
|
||||
pub type CowString<'a> = Cow<'a, String, str>;
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl<'a> Str for CowString<'a> {
|
||||
#[inline]
|
||||
fn as_slice<'b>(&'b self) -> &'b str {
|
||||
(**self).as_slice()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use prelude::*;
|
||||
use test::Bencher;
|
||||
|
||||
use str::{StrExt, Utf8Error};
|
||||
use str;
|
||||
use super::as_string;
|
||||
|
||||
@ -1038,14 +1048,16 @@ mod tests {
|
||||
#[test]
|
||||
fn test_from_utf8() {
|
||||
let xs = b"hello".to_vec();
|
||||
assert_eq!(String::from_utf8(xs), Ok(String::from_str("hello")));
|
||||
assert_eq!(String::from_utf8(xs),
|
||||
Ok(String::from_str("hello")));
|
||||
|
||||
let xs = "ศไทย中华Việt Nam".as_bytes().to_vec();
|
||||
assert_eq!(String::from_utf8(xs), Ok(String::from_str("ศไทย中华Việt Nam")));
|
||||
assert_eq!(String::from_utf8(xs),
|
||||
Ok(String::from_str("ศไทย中华Việt Nam")));
|
||||
|
||||
let xs = b"hello\xFF".to_vec();
|
||||
assert_eq!(String::from_utf8(xs),
|
||||
Err(b"hello\xFF".to_vec()));
|
||||
Err((b"hello\xFF".to_vec(), Utf8Error::TooShort)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -1135,7 +1147,7 @@ mod tests {
|
||||
let s_as_utf16 = s.utf16_units().collect::<Vec<u16>>();
|
||||
let u_as_string = String::from_utf16(u.as_slice()).unwrap();
|
||||
|
||||
assert!(str::is_utf16(u.as_slice()));
|
||||
assert!(::unicode::str::is_utf16(u.as_slice()));
|
||||
assert_eq!(s_as_utf16, u);
|
||||
|
||||
assert_eq!(u_as_string, s);
|
||||
|
@ -888,7 +888,7 @@ impl<T> Vec<T> {
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn into_iter(self) -> MoveItems<T> {
|
||||
pub fn into_iter(self) -> IntoIter<T> {
|
||||
unsafe {
|
||||
let ptr = self.ptr;
|
||||
let cap = self.cap;
|
||||
@ -899,7 +899,7 @@ impl<T> Vec<T> {
|
||||
ptr.offset(self.len() as int) as *const T
|
||||
};
|
||||
mem::forget(self);
|
||||
MoveItems { allocation: ptr, cap: cap, ptr: begin, end: end }
|
||||
IntoIter { allocation: ptr, cap: cap, ptr: begin, end: end }
|
||||
}
|
||||
}
|
||||
|
||||
@ -1402,21 +1402,21 @@ impl<T:fmt::Show> fmt::Show for Vec<T> {
|
||||
}
|
||||
|
||||
/// An iterator that moves out of a vector.
|
||||
pub struct MoveItems<T> {
|
||||
pub struct IntoIter<T> {
|
||||
allocation: *mut T, // the block of memory allocated for the vector
|
||||
cap: uint, // the capacity of the vector
|
||||
ptr: *const T,
|
||||
end: *const T
|
||||
}
|
||||
|
||||
impl<T> MoveItems<T> {
|
||||
impl<T> IntoIter<T> {
|
||||
/// Drops all items that have not yet been moved and returns the empty vector.
|
||||
#[inline]
|
||||
#[unstable]
|
||||
pub fn into_inner(mut self) -> Vec<T> {
|
||||
unsafe {
|
||||
for _x in self { }
|
||||
let MoveItems { allocation, cap, ptr: _ptr, end: _end } = self;
|
||||
let IntoIter { allocation, cap, ptr: _ptr, end: _end } = self;
|
||||
mem::forget(self);
|
||||
Vec { ptr: allocation, cap: cap, len: 0 }
|
||||
}
|
||||
@ -1427,7 +1427,7 @@ impl<T> MoveItems<T> {
|
||||
pub fn unwrap(self) -> Vec<T> { self.into_inner() }
|
||||
}
|
||||
|
||||
impl<T> Iterator<T> for MoveItems<T> {
|
||||
impl<T> Iterator<T> for IntoIter<T> {
|
||||
#[inline]
|
||||
fn next<'a>(&'a mut self) -> Option<T> {
|
||||
unsafe {
|
||||
@ -1461,7 +1461,7 @@ impl<T> Iterator<T> for MoveItems<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> DoubleEndedIterator<T> for MoveItems<T> {
|
||||
impl<T> DoubleEndedIterator<T> for IntoIter<T> {
|
||||
#[inline]
|
||||
fn next_back<'a>(&'a mut self) -> Option<T> {
|
||||
unsafe {
|
||||
@ -1484,10 +1484,10 @@ impl<T> DoubleEndedIterator<T> for MoveItems<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ExactSizeIterator<T> for MoveItems<T> {}
|
||||
impl<T> ExactSizeIterator<T> for IntoIter<T> {}
|
||||
|
||||
#[unsafe_destructor]
|
||||
impl<T> Drop for MoveItems<T> {
|
||||
impl<T> Drop for IntoIter<T> {
|
||||
fn drop(&mut self) {
|
||||
// destroy the remaining elements
|
||||
if self.cap != 0 {
|
||||
|
@ -144,6 +144,7 @@ impl<V> VecMap<V> {
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn keys<'r>(&'r self) -> Keys<'r, V> {
|
||||
fn first<A, B>((a, _): (A, B)) -> A { a }
|
||||
let first: fn((uint, &'r V)) -> uint = first; // coerce to fn pointer
|
||||
|
||||
Keys { iter: self.iter().map(first) }
|
||||
}
|
||||
@ -153,6 +154,7 @@ impl<V> VecMap<V> {
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn values<'r>(&'r self) -> Values<'r, V> {
|
||||
fn second<A, B>((_, b): (A, B)) -> B { b }
|
||||
let second: fn((uint, &'r V)) -> &'r V = second; // coerce to fn pointer
|
||||
|
||||
Values { iter: self.iter().map(second) }
|
||||
}
|
||||
@ -176,8 +178,8 @@ impl<V> VecMap<V> {
|
||||
/// }
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn iter<'r>(&'r self) -> Entries<'r, V> {
|
||||
Entries {
|
||||
pub fn iter<'r>(&'r self) -> Iter<'r, V> {
|
||||
Iter {
|
||||
front: 0,
|
||||
back: self.v.len(),
|
||||
iter: self.v.iter()
|
||||
@ -207,8 +209,8 @@ impl<V> VecMap<V> {
|
||||
/// }
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn iter_mut<'r>(&'r mut self) -> MutEntries<'r, V> {
|
||||
MutEntries {
|
||||
pub fn iter_mut<'r>(&'r mut self) -> IterMut<'r, V> {
|
||||
IterMut {
|
||||
front: 0,
|
||||
back: self.v.len(),
|
||||
iter: self.v.iter_mut()
|
||||
@ -235,13 +237,14 @@ impl<V> VecMap<V> {
|
||||
/// assert_eq!(vec, vec![(1, "a"), (2, "b"), (3, "c")]);
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn into_iter(&mut self) -> MoveItems<V> {
|
||||
pub fn into_iter(&mut self) -> IntoIter<V> {
|
||||
fn filter<A>((i, v): (uint, Option<A>)) -> Option<(uint, A)> {
|
||||
v.map(|v| (i, v))
|
||||
}
|
||||
let filter: fn((uint, Option<V>)) -> Option<(uint, V)> = filter; // coerce to fn ptr
|
||||
|
||||
let values = replace(&mut self.v, vec!());
|
||||
MoveItems { iter: values.into_iter().enumerate().filter_map(filter) }
|
||||
IntoIter { iter: values.into_iter().enumerate().filter_map(filter) }
|
||||
}
|
||||
|
||||
/// Return the number of elements in the map.
|
||||
@ -605,42 +608,42 @@ macro_rules! double_ended_iterator {
|
||||
}
|
||||
|
||||
/// An iterator over the key-value pairs of a map.
|
||||
pub struct Entries<'a, V:'a> {
|
||||
pub struct Iter<'a, V:'a> {
|
||||
front: uint,
|
||||
back: uint,
|
||||
iter: slice::Items<'a, Option<V>>
|
||||
iter: slice::Iter<'a, Option<V>>
|
||||
}
|
||||
|
||||
iterator! { impl Entries -> (uint, &'a V), as_ref }
|
||||
double_ended_iterator! { impl Entries -> (uint, &'a V), as_ref }
|
||||
iterator! { impl Iter -> (uint, &'a V), as_ref }
|
||||
double_ended_iterator! { impl Iter -> (uint, &'a V), as_ref }
|
||||
|
||||
/// An iterator over the key-value pairs of a map, with the
|
||||
/// values being mutable.
|
||||
pub struct MutEntries<'a, V:'a> {
|
||||
pub struct IterMut<'a, V:'a> {
|
||||
front: uint,
|
||||
back: uint,
|
||||
iter: slice::MutItems<'a, Option<V>>
|
||||
iter: slice::IterMut<'a, Option<V>>
|
||||
}
|
||||
|
||||
iterator! { impl MutEntries -> (uint, &'a mut V), as_mut }
|
||||
double_ended_iterator! { impl MutEntries -> (uint, &'a mut V), as_mut }
|
||||
iterator! { impl IterMut -> (uint, &'a mut V), as_mut }
|
||||
double_ended_iterator! { impl IterMut -> (uint, &'a mut V), as_mut }
|
||||
|
||||
/// An iterator over the keys of a map.
|
||||
pub struct Keys<'a, V: 'a> {
|
||||
iter: Map<(uint, &'a V), uint, Entries<'a, V>, fn((uint, &'a V)) -> uint>
|
||||
iter: Map<(uint, &'a V), uint, Iter<'a, V>, fn((uint, &'a V)) -> uint>
|
||||
}
|
||||
|
||||
/// An iterator over the values of a map.
|
||||
pub struct Values<'a, V: 'a> {
|
||||
iter: Map<(uint, &'a V), &'a V, Entries<'a, V>, fn((uint, &'a V)) -> &'a V>
|
||||
iter: Map<(uint, &'a V), &'a V, Iter<'a, V>, fn((uint, &'a V)) -> &'a V>
|
||||
}
|
||||
|
||||
/// A consuming iterator over the key-value pairs of a map.
|
||||
pub struct MoveItems<V> {
|
||||
pub struct IntoIter<V> {
|
||||
iter: FilterMap<
|
||||
(uint, Option<V>),
|
||||
(uint, V),
|
||||
Enumerate<vec::MoveItems<Option<V>>>,
|
||||
Enumerate<vec::IntoIter<Option<V>>>,
|
||||
fn((uint, Option<V>)) -> Option<(uint, V)>>
|
||||
}
|
||||
|
||||
@ -662,11 +665,11 @@ impl<'a, V> DoubleEndedIterator<&'a V> for Values<'a, V> {
|
||||
}
|
||||
|
||||
|
||||
impl<V> Iterator<(uint, V)> for MoveItems<V> {
|
||||
impl<V> Iterator<(uint, V)> for IntoIter<V> {
|
||||
fn next(&mut self) -> Option<(uint, V)> { self.iter.next() }
|
||||
fn size_hint(&self) -> (uint, Option<uint>) { self.iter.size_hint() }
|
||||
}
|
||||
impl<V> DoubleEndedIterator<(uint, V)> for MoveItems<V> {
|
||||
impl<V> DoubleEndedIterator<(uint, V)> for IntoIter<V> {
|
||||
fn next_back(&mut self) -> Option<(uint, V)> { self.iter.next_back() }
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@
|
||||
|
||||
#![stable]
|
||||
|
||||
pub use self::Ordering::*;
|
||||
use self::Ordering::*;
|
||||
|
||||
use kinds::Sized;
|
||||
use option::Option::{mod, Some, None};
|
||||
|
@ -23,7 +23,7 @@ use num::cast;
|
||||
use ops::FnOnce;
|
||||
use result::Result::Ok;
|
||||
use slice::{mod, SliceExt};
|
||||
use str::StrPrelude;
|
||||
use str::StrExt;
|
||||
|
||||
/// A flag that specifies whether to use exponential (scientific) notation.
|
||||
pub enum ExponentFormat {
|
||||
|
@ -24,7 +24,7 @@ use result::Result::{Ok, Err};
|
||||
use result;
|
||||
use slice::SliceExt;
|
||||
use slice;
|
||||
use str::StrPrelude;
|
||||
use str::{StrExt, Utf8Error};
|
||||
|
||||
pub use self::num::radix;
|
||||
pub use self::num::Radix;
|
||||
@ -89,7 +89,7 @@ pub struct Formatter<'a> {
|
||||
precision: Option<uint>,
|
||||
|
||||
buf: &'a mut (FormatWriter+'a),
|
||||
curarg: slice::Items<'a, Argument<'a>>,
|
||||
curarg: slice::Iter<'a, Argument<'a>>,
|
||||
args: &'a [Argument<'a>],
|
||||
}
|
||||
|
||||
@ -795,5 +795,18 @@ impl<'b, T: Show> Show for RefMut<'b, T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl Show for Utf8Error {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
match *self {
|
||||
Utf8Error::InvalidByte(n) => {
|
||||
write!(f, "invalid utf-8: invalid byte at index {}", n)
|
||||
}
|
||||
Utf8Error::TooShort => {
|
||||
write!(f, "invalid utf-8: byte slice too short")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If you expected tests to be here, look instead at the run-pass/ifmt.rs test,
|
||||
// it's a lot easier than creating all of the rt::Piece structures here.
|
||||
|
@ -2612,6 +2612,9 @@ pub fn iterate<T, F>(seed: T, f: F) -> Iterate<T, F> where
|
||||
val.clone()
|
||||
}
|
||||
|
||||
// coerce to a fn pointer
|
||||
let next: fn(&mut IterateState<T,F>) -> Option<T> = next;
|
||||
|
||||
Unfold::new((f, Some(seed), true), next)
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ use ops::{Add, Sub, Mul, Div, Rem, Neg};
|
||||
use ops::{Not, BitAnd, BitOr, BitXor, Shl, Shr};
|
||||
use option::Option;
|
||||
use option::Option::{Some, None};
|
||||
use str::{FromStr, from_str, StrPrelude};
|
||||
use str::{FromStr, from_str, StrExt};
|
||||
|
||||
/// Simultaneous division and remainder
|
||||
#[inline]
|
||||
|
@ -718,15 +718,15 @@ impl<T: Default> Option<T> {
|
||||
/// # Example
|
||||
///
|
||||
/// Convert a string to an integer, turning poorly-formed strings
|
||||
/// into 0 (the default value for integers). `from_str` converts
|
||||
/// into 0 (the default value for integers). `parse` converts
|
||||
/// a string to any other type that implements `FromStr`, returning
|
||||
/// `None` on error.
|
||||
///
|
||||
/// ```
|
||||
/// let good_year_from_input = "1909";
|
||||
/// let bad_year_from_input = "190blarg";
|
||||
/// let good_year = from_str(good_year_from_input).unwrap_or_default();
|
||||
/// let bad_year = from_str(bad_year_from_input).unwrap_or_default();
|
||||
/// let good_year = good_year_from_input.parse().unwrap_or_default();
|
||||
/// let bad_year = bad_year_from_input.parse().unwrap_or_default();
|
||||
///
|
||||
/// assert_eq!(1909i, good_year);
|
||||
/// assert_eq!(0i, bad_year);
|
||||
|
@ -60,7 +60,7 @@ pub use option::Option::{Some, None};
|
||||
pub use ptr::RawPtr;
|
||||
pub use result::Result;
|
||||
pub use result::Result::{Ok, Err};
|
||||
pub use str::{Str, StrPrelude};
|
||||
pub use str::{Str, StrExt};
|
||||
pub use tuple::{Tuple1, Tuple2, Tuple3, Tuple4};
|
||||
pub use tuple::{Tuple5, Tuple6, Tuple7, Tuple8};
|
||||
pub use tuple::{Tuple9, Tuple10, Tuple11, Tuple12};
|
||||
|
@ -458,7 +458,7 @@ impl<T, E> Result<T, E> {
|
||||
/// let line: IoResult<String> = buffer.read_line();
|
||||
/// // Convert the string line to a number using `map` and `from_str`
|
||||
/// let val: IoResult<int> = line.map(|line| {
|
||||
/// from_str::<int>(line.as_slice().trim_right()).unwrap_or(0)
|
||||
/// line.as_slice().trim_right().parse::<int>().unwrap_or(0)
|
||||
/// });
|
||||
/// // Add the value if there were no errors, otherwise add 0
|
||||
/// sum += val.ok().unwrap_or(0);
|
||||
|
@ -67,7 +67,7 @@ pub trait SliceExt<T> for Sized? {
|
||||
fn slice_from<'a>(&'a self, start: uint) -> &'a [T];
|
||||
fn slice_to<'a>(&'a self, end: uint) -> &'a [T];
|
||||
fn split_at<'a>(&'a self, mid: uint) -> (&'a [T], &'a [T]);
|
||||
fn iter<'a>(&'a self) -> Items<'a, T>;
|
||||
fn iter<'a>(&'a self) -> Iter<'a, T>;
|
||||
fn split<'a, P>(&'a self, pred: P) -> Splits<'a, T, P>
|
||||
where P: FnMut(&T) -> bool;
|
||||
fn splitn<'a, P>(&'a self, n: uint, pred: P) -> SplitsN<Splits<'a, T, P>>
|
||||
@ -92,7 +92,7 @@ pub trait SliceExt<T> for Sized? {
|
||||
fn slice_mut<'a>(&'a mut self, start: uint, end: uint) -> &'a mut [T];
|
||||
fn slice_from_mut<'a>(&'a mut self, start: uint) -> &'a mut [T];
|
||||
fn slice_to_mut<'a>(&'a mut self, end: uint) -> &'a mut [T];
|
||||
fn iter_mut<'a>(&'a mut self) -> MutItems<'a, T>;
|
||||
fn iter_mut<'a>(&'a mut self) -> IterMut<'a, T>;
|
||||
fn head_mut<'a>(&'a mut self) -> Option<&'a mut T>;
|
||||
fn tail_mut<'a>(&'a mut self) -> &'a mut [T];
|
||||
fn init_mut<'a>(&'a mut self) -> &'a mut [T];
|
||||
@ -141,15 +141,15 @@ impl<T> SliceExt<T> for [T] {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn iter<'a>(&'a self) -> Items<'a, T> {
|
||||
fn iter<'a>(&'a self) -> Iter<'a, T> {
|
||||
unsafe {
|
||||
let p = self.as_ptr();
|
||||
if mem::size_of::<T>() == 0 {
|
||||
Items{ptr: p,
|
||||
Iter{ptr: p,
|
||||
end: (p as uint + self.len()) as *const T,
|
||||
marker: marker::ContravariantLifetime::<'a>}
|
||||
} else {
|
||||
Items{ptr: p,
|
||||
Iter{ptr: p,
|
||||
end: p.offset(self.len() as int),
|
||||
marker: marker::ContravariantLifetime::<'a>}
|
||||
}
|
||||
@ -286,15 +286,15 @@ impl<T> SliceExt<T> for [T] {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn iter_mut<'a>(&'a mut self) -> MutItems<'a, T> {
|
||||
fn iter_mut<'a>(&'a mut self) -> IterMut<'a, T> {
|
||||
unsafe {
|
||||
let p = self.as_mut_ptr();
|
||||
if mem::size_of::<T>() == 0 {
|
||||
MutItems{ptr: p,
|
||||
IterMut{ptr: p,
|
||||
end: (p as uint + self.len()) as *mut T,
|
||||
marker: marker::ContravariantLifetime::<'a>}
|
||||
} else {
|
||||
MutItems{ptr: p,
|
||||
IterMut{ptr: p,
|
||||
end: p.offset(self.len() as int),
|
||||
marker: marker::ContravariantLifetime::<'a>}
|
||||
}
|
||||
@ -655,7 +655,7 @@ impl<'a, T> Default for &'a [T] {
|
||||
// Iterators
|
||||
//
|
||||
|
||||
// The shared definition of the `Item` and `MutItems` iterators
|
||||
// The shared definition of the `Item` and `IterMut` iterators
|
||||
macro_rules! iterator {
|
||||
(struct $name:ident -> $ptr:ty, $elem:ty) => {
|
||||
#[experimental = "needs review"]
|
||||
@ -738,14 +738,14 @@ macro_rules! make_slice {
|
||||
|
||||
/// Immutable slice iterator
|
||||
#[experimental = "needs review"]
|
||||
pub struct Items<'a, T: 'a> {
|
||||
pub struct Iter<'a, T: 'a> {
|
||||
ptr: *const T,
|
||||
end: *const T,
|
||||
marker: marker::ContravariantLifetime<'a>
|
||||
}
|
||||
|
||||
#[experimental]
|
||||
impl<'a, T> ops::Slice<uint, [T]> for Items<'a, T> {
|
||||
impl<'a, T> ops::Slice<uint, [T]> for Iter<'a, T> {
|
||||
fn as_slice_(&self) -> &[T] {
|
||||
self.as_slice()
|
||||
}
|
||||
@ -763,7 +763,7 @@ impl<'a, T> ops::Slice<uint, [T]> for Items<'a, T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T> Items<'a, T> {
|
||||
impl<'a, T> Iter<'a, T> {
|
||||
/// View the underlying data as a subslice of the original data.
|
||||
///
|
||||
/// This has the same lifetime as the original slice, and so the
|
||||
@ -774,20 +774,20 @@ impl<'a, T> Items<'a, T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a,T> Copy for Items<'a,T> {}
|
||||
impl<'a,T> Copy for Iter<'a,T> {}
|
||||
|
||||
iterator!{struct Items -> *const T, &'a T}
|
||||
iterator!{struct Iter -> *const T, &'a T}
|
||||
|
||||
#[experimental = "needs review"]
|
||||
impl<'a, T> ExactSizeIterator<&'a T> for Items<'a, T> {}
|
||||
impl<'a, T> ExactSizeIterator<&'a T> for Iter<'a, T> {}
|
||||
|
||||
#[stable]
|
||||
impl<'a, T> Clone for Items<'a, T> {
|
||||
fn clone(&self) -> Items<'a, T> { *self }
|
||||
impl<'a, T> Clone for Iter<'a, T> {
|
||||
fn clone(&self) -> Iter<'a, T> { *self }
|
||||
}
|
||||
|
||||
#[experimental = "needs review"]
|
||||
impl<'a, T> RandomAccessIterator<&'a T> for Items<'a, T> {
|
||||
impl<'a, T> RandomAccessIterator<&'a T> for Iter<'a, T> {
|
||||
#[inline]
|
||||
fn indexable(&self) -> uint {
|
||||
let (exact, _) = self.size_hint();
|
||||
@ -813,14 +813,14 @@ impl<'a, T> RandomAccessIterator<&'a T> for Items<'a, T> {
|
||||
|
||||
/// Mutable slice iterator.
|
||||
#[experimental = "needs review"]
|
||||
pub struct MutItems<'a, T: 'a> {
|
||||
pub struct IterMut<'a, T: 'a> {
|
||||
ptr: *mut T,
|
||||
end: *mut T,
|
||||
marker: marker::ContravariantLifetime<'a>,
|
||||
}
|
||||
|
||||
#[experimental]
|
||||
impl<'a, T> ops::Slice<uint, [T]> for MutItems<'a, T> {
|
||||
impl<'a, T> ops::Slice<uint, [T]> for IterMut<'a, T> {
|
||||
fn as_slice_<'b>(&'b self) -> &'b [T] {
|
||||
make_slice!(T -> &'b [T]: self.ptr, self.end)
|
||||
}
|
||||
@ -839,7 +839,7 @@ impl<'a, T> ops::Slice<uint, [T]> for MutItems<'a, T> {
|
||||
}
|
||||
|
||||
#[experimental]
|
||||
impl<'a, T> ops::SliceMut<uint, [T]> for MutItems<'a, T> {
|
||||
impl<'a, T> ops::SliceMut<uint, [T]> for IterMut<'a, T> {
|
||||
fn as_mut_slice_<'b>(&'b mut self) -> &'b mut [T] {
|
||||
make_slice!(T -> &'b mut [T]: self.ptr, self.end)
|
||||
}
|
||||
@ -857,7 +857,7 @@ impl<'a, T> ops::SliceMut<uint, [T]> for MutItems<'a, T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T> MutItems<'a, T> {
|
||||
impl<'a, T> IterMut<'a, T> {
|
||||
/// View the underlying data as a subslice of the original data.
|
||||
///
|
||||
/// To avoid creating `&mut` references that alias, this is forced
|
||||
@ -870,10 +870,10 @@ impl<'a, T> MutItems<'a, T> {
|
||||
}
|
||||
}
|
||||
|
||||
iterator!{struct MutItems -> *mut T, &'a mut T}
|
||||
iterator!{struct IterMut -> *mut T, &'a mut T}
|
||||
|
||||
#[experimental = "needs review"]
|
||||
impl<'a, T> ExactSizeIterator<&'a mut T> for MutItems<'a, T> {}
|
||||
impl<'a, T> ExactSizeIterator<&'a mut T> for IterMut<'a, T> {}
|
||||
|
||||
/// An abstraction over the splitting iterators, so that splitn, splitn_mut etc
|
||||
/// can be implemented once.
|
||||
|
1042
src/libcore/str.rs
1042
src/libcore/str.rs
File diff suppressed because it is too large
Load Diff
@ -69,6 +69,7 @@
|
||||
|
||||
use clone::Clone;
|
||||
use cmp::*;
|
||||
use cmp::Ordering::*;
|
||||
use default::Default;
|
||||
use option::Option;
|
||||
use option::Option::Some;
|
||||
|
@ -13,6 +13,7 @@
|
||||
extern crate core;
|
||||
extern crate test;
|
||||
extern crate libc;
|
||||
extern crate unicode;
|
||||
|
||||
mod any;
|
||||
mod atomic;
|
||||
|
@ -117,7 +117,7 @@ fn test_rev_split_char_iterator_no_trailing() {
|
||||
|
||||
#[test]
|
||||
fn test_utf16_code_units() {
|
||||
use core::str::Utf16Encoder;
|
||||
use unicode::str::Utf16Encoder;
|
||||
assert_eq!(Utf16Encoder::new(vec!['é', '\U0001F4A9'].into_iter()).collect::<Vec<u16>>(),
|
||||
vec![0xE9, 0xD83D, 0xDCA9])
|
||||
}
|
||||
|
@ -23,7 +23,8 @@
|
||||
html_root_url = "http://doc.rust-lang.org/nightly/",
|
||||
html_playground_url = "http://play.rust-lang.org/")]
|
||||
|
||||
#![feature(macro_rules, globs)]
|
||||
#![feature(macro_rules, globs, slicing_syntax)]
|
||||
|
||||
pub use self::Piece::*;
|
||||
pub use self::Position::*;
|
||||
pub use self::Alignment::*;
|
||||
@ -136,7 +137,7 @@ pub enum Count<'a> {
|
||||
/// necessary there's probably lots of room for improvement performance-wise.
|
||||
pub struct Parser<'a> {
|
||||
input: &'a str,
|
||||
cur: str::CharOffsets<'a>,
|
||||
cur: str::CharIndices<'a>,
|
||||
/// Error messages accumulated during parsing
|
||||
pub errors: Vec<string::String>,
|
||||
}
|
||||
@ -208,13 +209,11 @@ impl<'a> Parser<'a> {
|
||||
self.cur.next();
|
||||
}
|
||||
Some((_, other)) => {
|
||||
self.err(format!("expected `{}`, found `{}`",
|
||||
c,
|
||||
other).as_slice());
|
||||
self.err(format!("expected `{}`, found `{}`", c, other)[]);
|
||||
}
|
||||
None => {
|
||||
self.err(format!("expected `{}` but string was terminated",
|
||||
c).as_slice());
|
||||
c)[]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -237,12 +236,12 @@ impl<'a> Parser<'a> {
|
||||
// we may not consume the character, so clone the iterator
|
||||
match self.cur.clone().next() {
|
||||
Some((pos, '}')) | Some((pos, '{')) => {
|
||||
return self.input.slice(start, pos);
|
||||
return self.input[start..pos];
|
||||
}
|
||||
Some(..) => { self.cur.next(); }
|
||||
None => {
|
||||
self.cur.next();
|
||||
return self.input.slice(start, self.input.len());
|
||||
return self.input[start..self.input.len()];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -282,7 +281,7 @@ impl<'a> Parser<'a> {
|
||||
flags: 0,
|
||||
precision: CountImplied,
|
||||
width: CountImplied,
|
||||
ty: self.input.slice(0, 0),
|
||||
ty: self.input[0..0],
|
||||
};
|
||||
if !self.consume(':') { return spec }
|
||||
|
||||
@ -391,7 +390,7 @@ impl<'a> Parser<'a> {
|
||||
self.cur.next();
|
||||
pos
|
||||
}
|
||||
Some(..) | None => { return self.input.slice(0, 0); }
|
||||
Some(..) | None => { return self.input[0..0]; }
|
||||
};
|
||||
let mut end;
|
||||
loop {
|
||||
@ -403,7 +402,7 @@ impl<'a> Parser<'a> {
|
||||
None => { end = self.input.len(); break }
|
||||
}
|
||||
}
|
||||
self.input.slice(start, end)
|
||||
self.input[start..end]
|
||||
}
|
||||
|
||||
/// Optionally parses an integer at the current position. This doesn't deal
|
||||
|
@ -85,7 +85,7 @@
|
||||
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
|
||||
html_root_url = "http://doc.rust-lang.org/nightly/",
|
||||
html_playground_url = "http://play.rust-lang.org/")]
|
||||
#![feature(globs, phase)]
|
||||
#![feature(globs, phase, slicing_syntax)]
|
||||
#![feature(unboxed_closures)]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
@ -101,9 +101,8 @@ use self::Whitespace::*;
|
||||
use self::LengthLimit::*;
|
||||
|
||||
use std::fmt;
|
||||
use std::result::Result::{Err, Ok};
|
||||
use std::iter::repeat;
|
||||
use std::result;
|
||||
use std::string::String;
|
||||
|
||||
/// Name of an option. Either a string or a single char.
|
||||
#[deriving(Clone, PartialEq, Eq)]
|
||||
@ -282,7 +281,7 @@ impl OptGroup {
|
||||
|
||||
impl Matches {
|
||||
fn opt_vals(&self, nm: &str) -> Vec<Optval> {
|
||||
match find_opt(self.opts.as_slice(), Name::from_str(nm)) {
|
||||
match find_opt(self.opts[], Name::from_str(nm)) {
|
||||
Some(id) => self.vals[id].clone(),
|
||||
None => panic!("No option '{}' defined", nm)
|
||||
}
|
||||
@ -310,8 +309,7 @@ impl Matches {
|
||||
/// Returns true if any of several options were matched.
|
||||
pub fn opts_present(&self, names: &[String]) -> bool {
|
||||
for nm in names.iter() {
|
||||
match find_opt(self.opts.as_slice(),
|
||||
Name::from_str(nm.as_slice())) {
|
||||
match find_opt(self.opts.as_slice(), Name::from_str(nm[])) {
|
||||
Some(id) if !self.vals[id].is_empty() => return true,
|
||||
_ => (),
|
||||
};
|
||||
@ -322,7 +320,7 @@ impl Matches {
|
||||
/// Returns the string argument supplied to one of several matching options or `None`.
|
||||
pub fn opts_str(&self, names: &[String]) -> Option<String> {
|
||||
for nm in names.iter() {
|
||||
match self.opt_val(nm.as_slice()) {
|
||||
match self.opt_val(nm[]) {
|
||||
Some(Val(ref s)) => return Some(s.clone()),
|
||||
_ => ()
|
||||
}
|
||||
@ -587,7 +585,7 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
|
||||
while i < l {
|
||||
let cur = args[i].clone();
|
||||
let curlen = cur.len();
|
||||
if !is_arg(cur.as_slice()) {
|
||||
if !is_arg(cur[]) {
|
||||
free.push(cur);
|
||||
} else if cur == "--" {
|
||||
let mut j = i + 1;
|
||||
@ -597,7 +595,7 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
|
||||
let mut names;
|
||||
let mut i_arg = None;
|
||||
if cur.as_bytes()[1] == b'-' {
|
||||
let tail = cur.slice(2, curlen);
|
||||
let tail = cur[2..curlen];
|
||||
let tail_eq: Vec<&str> = tail.split('=').collect();
|
||||
if tail_eq.len() <= 1 {
|
||||
names = vec!(Long(tail.to_string()));
|
||||
@ -633,7 +631,7 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
|
||||
};
|
||||
|
||||
if arg_follows && range.next < curlen {
|
||||
i_arg = Some(cur.slice(range.next, curlen).to_string());
|
||||
i_arg = Some(cur[range.next..curlen].to_string());
|
||||
break;
|
||||
}
|
||||
|
||||
@ -660,7 +658,7 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
|
||||
.push(Val((i_arg.clone())
|
||||
.unwrap()));
|
||||
} else if name_pos < names.len() || i + 1 == l ||
|
||||
is_arg(args[i + 1].as_slice()) {
|
||||
is_arg(args[i + 1][]) {
|
||||
vals[optid].push(Given);
|
||||
} else {
|
||||
i += 1;
|
||||
@ -702,7 +700,7 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
|
||||
/// Derive a usage message from a set of long options.
|
||||
pub fn usage(brief: &str, opts: &[OptGroup]) -> String {
|
||||
|
||||
let desc_sep = format!("\n{}", " ".repeat(24));
|
||||
let desc_sep = format!("\n{}", repeat(" ").take(24).collect::<String>());
|
||||
|
||||
let rows = opts.iter().map(|optref| {
|
||||
let OptGroup{short_name,
|
||||
@ -712,14 +710,14 @@ pub fn usage(brief: &str, opts: &[OptGroup]) -> String {
|
||||
hasarg,
|
||||
..} = (*optref).clone();
|
||||
|
||||
let mut row = " ".repeat(4);
|
||||
let mut row = repeat(" ").take(4).collect::<String>();
|
||||
|
||||
// short option
|
||||
match short_name.len() {
|
||||
0 => {}
|
||||
1 => {
|
||||
row.push('-');
|
||||
row.push_str(short_name.as_slice());
|
||||
row.push_str(short_name[]);
|
||||
row.push(' ');
|
||||
}
|
||||
_ => panic!("the short name should only be 1 ascii char long"),
|
||||
@ -730,7 +728,7 @@ pub fn usage(brief: &str, opts: &[OptGroup]) -> String {
|
||||
0 => {}
|
||||
_ => {
|
||||
row.push_str("--");
|
||||
row.push_str(long_name.as_slice());
|
||||
row.push_str(long_name[]);
|
||||
row.push(' ');
|
||||
}
|
||||
}
|
||||
@ -738,23 +736,23 @@ pub fn usage(brief: &str, opts: &[OptGroup]) -> String {
|
||||
// arg
|
||||
match hasarg {
|
||||
No => {}
|
||||
Yes => row.push_str(hint.as_slice()),
|
||||
Yes => row.push_str(hint[]),
|
||||
Maybe => {
|
||||
row.push('[');
|
||||
row.push_str(hint.as_slice());
|
||||
row.push_str(hint[]);
|
||||
row.push(']');
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: #5516 should be graphemes not codepoints
|
||||
// here we just need to indent the start of the description
|
||||
let rowlen = row.char_len();
|
||||
let rowlen = row.chars().count();
|
||||
if rowlen < 24 {
|
||||
for _ in range(0, 24 - rowlen) {
|
||||
row.push(' ');
|
||||
}
|
||||
} else {
|
||||
row.push_str(desc_sep.as_slice())
|
||||
row.push_str(desc_sep[]);
|
||||
}
|
||||
|
||||
// Normalize desc to contain words separated by one space character
|
||||
@ -766,16 +764,14 @@ pub fn usage(brief: &str, opts: &[OptGroup]) -> String {
|
||||
|
||||
// FIXME: #5516 should be graphemes not codepoints
|
||||
let mut desc_rows = Vec::new();
|
||||
each_split_within(desc_normalized_whitespace.as_slice(),
|
||||
54,
|
||||
|substr| {
|
||||
each_split_within(desc_normalized_whitespace[], 54, |substr| {
|
||||
desc_rows.push(substr.to_string());
|
||||
true
|
||||
});
|
||||
|
||||
// FIXME: #5516 should be graphemes not codepoints
|
||||
// wrapped description
|
||||
row.push_str(desc_rows.connect(desc_sep.as_slice()).as_slice());
|
||||
row.push_str(desc_rows.connect(desc_sep[])[]);
|
||||
|
||||
row
|
||||
});
|
||||
@ -794,10 +790,10 @@ fn format_option(opt: &OptGroup) -> String {
|
||||
// Use short_name is possible, but fallback to long_name.
|
||||
if opt.short_name.len() > 0 {
|
||||
line.push('-');
|
||||
line.push_str(opt.short_name.as_slice());
|
||||
line.push_str(opt.short_name[]);
|
||||
} else {
|
||||
line.push_str("--");
|
||||
line.push_str(opt.long_name.as_slice());
|
||||
line.push_str(opt.long_name[]);
|
||||
}
|
||||
|
||||
if opt.hasarg != No {
|
||||
@ -805,7 +801,7 @@ fn format_option(opt: &OptGroup) -> String {
|
||||
if opt.hasarg == Maybe {
|
||||
line.push('[');
|
||||
}
|
||||
line.push_str(opt.hint.as_slice());
|
||||
line.push_str(opt.hint[]);
|
||||
if opt.hasarg == Maybe {
|
||||
line.push(']');
|
||||
}
|
||||
@ -827,8 +823,7 @@ pub fn short_usage(program_name: &str, opts: &[OptGroup]) -> String {
|
||||
line.push_str(opts.iter()
|
||||
.map(format_option)
|
||||
.collect::<Vec<String>>()
|
||||
.connect(" ")
|
||||
.as_slice());
|
||||
.connect(" ")[]);
|
||||
line
|
||||
}
|
||||
|
||||
@ -891,9 +886,9 @@ fn each_split_within<F>(ss: &str, lim: uint, mut it: F) -> bool where
|
||||
(B, Cr, UnderLim) => { B }
|
||||
(B, Cr, OverLim) if (i - last_start + 1) > lim
|
||||
=> panic!("word starting with {} longer than limit!",
|
||||
ss.slice(last_start, i + 1)),
|
||||
ss[last_start..i + 1]),
|
||||
(B, Cr, OverLim) => {
|
||||
*cont = it(ss.slice(slice_start, last_end));
|
||||
*cont = it(ss[slice_start..last_end]);
|
||||
slice_start = last_start;
|
||||
B
|
||||
}
|
||||
@ -903,7 +898,7 @@ fn each_split_within<F>(ss: &str, lim: uint, mut it: F) -> bool where
|
||||
}
|
||||
(B, Ws, OverLim) => {
|
||||
last_end = i;
|
||||
*cont = it(ss.slice(slice_start, last_end));
|
||||
*cont = it(ss[slice_start..last_end]);
|
||||
A
|
||||
}
|
||||
|
||||
@ -912,14 +907,14 @@ fn each_split_within<F>(ss: &str, lim: uint, mut it: F) -> bool where
|
||||
B
|
||||
}
|
||||
(C, Cr, OverLim) => {
|
||||
*cont = it(ss.slice(slice_start, last_end));
|
||||
*cont = it(ss[slice_start..last_end]);
|
||||
slice_start = i;
|
||||
last_start = i;
|
||||
last_end = i;
|
||||
B
|
||||
}
|
||||
(C, Ws, OverLim) => {
|
||||
*cont = it(ss.slice(slice_start, last_end));
|
||||
*cont = it(ss[slice_start..last_end]);
|
||||
A
|
||||
}
|
||||
(C, Ws, UnderLim) => {
|
||||
|
@ -448,8 +448,8 @@ impl<'a> LabelText<'a> {
|
||||
/// Renders text as string suitable for a label in a .dot file.
|
||||
pub fn escape(&self) -> String {
|
||||
match self {
|
||||
&LabelStr(ref s) => (&**s).escape_default(),
|
||||
&EscStr(ref s) => LabelText::escape_str(s.as_slice()),
|
||||
&LabelStr(ref s) => s.escape_default(),
|
||||
&EscStr(ref s) => LabelText::escape_str(s[]),
|
||||
}
|
||||
}
|
||||
|
||||
@ -475,10 +475,10 @@ impl<'a> LabelText<'a> {
|
||||
|
||||
/// Puts `suffix` on a line below this label, with a blank line separator.
|
||||
pub fn suffix_line(self, suffix: LabelText) -> LabelText<'static> {
|
||||
let mut prefix = self.pre_escaped_content().into_string();
|
||||
let mut prefix = self.pre_escaped_content().into_owned();
|
||||
let suffix = suffix.pre_escaped_content();
|
||||
prefix.push_str(r"\n\n");
|
||||
prefix.push_str(suffix.as_slice());
|
||||
prefix.push_str(suffix[]);
|
||||
EscStr(prefix.into_cow())
|
||||
}
|
||||
}
|
||||
@ -671,7 +671,7 @@ mod tests {
|
||||
|
||||
impl<'a> Labeller<'a, Node, &'a Edge> for LabelledGraph {
|
||||
fn graph_id(&'a self) -> Id<'a> {
|
||||
Id::new(self.name.as_slice()).unwrap()
|
||||
Id::new(self.name[]).unwrap()
|
||||
}
|
||||
fn node_id(&'a self, n: &Node) -> Id<'a> {
|
||||
id_name(n)
|
||||
@ -735,7 +735,7 @@ mod tests {
|
||||
fn test_input(g: LabelledGraph) -> IoResult<String> {
|
||||
let mut writer = Vec::new();
|
||||
render(&g, &mut writer).unwrap();
|
||||
(&mut writer.as_slice()).read_to_string()
|
||||
(&mut writer[]).read_to_string()
|
||||
}
|
||||
|
||||
// All of the tests use raw-strings as the format for the expected outputs,
|
||||
@ -847,7 +847,7 @@ r#"digraph hasse_diagram {
|
||||
edge(1, 3, ";"), edge(2, 3, ";" )));
|
||||
|
||||
render(&g, &mut writer).unwrap();
|
||||
let r = (&mut writer.as_slice()).read_to_string();
|
||||
let r = (&mut writer[]).read_to_string();
|
||||
|
||||
assert_eq!(r.unwrap(),
|
||||
r#"digraph syntax_tree {
|
||||
|
@ -63,7 +63,7 @@ impl<'a,T> IntoMaybeOwnedVector<'a,T> for &'a [T] {
|
||||
}
|
||||
|
||||
impl<'a,T> MaybeOwnedVector<'a,T> {
|
||||
pub fn iter(&'a self) -> slice::Items<'a,T> {
|
||||
pub fn iter(&'a self) -> slice::Iter<'a,T> {
|
||||
match self {
|
||||
&Growable(ref v) => v.as_slice().iter(),
|
||||
&Borrowed(ref v) => v.iter(),
|
||||
|
@ -23,7 +23,7 @@ pub static LOG_LEVEL_NAMES: [&'static str, ..4] = ["ERROR", "WARN", "INFO",
|
||||
|
||||
/// Parse an individual log level that is either a number or a symbolic log level
|
||||
fn parse_log_level(level: &str) -> Option<u32> {
|
||||
from_str::<u32>(level).or_else(|| {
|
||||
level.parse::<u32>().or_else(|| {
|
||||
let pos = LOG_LEVEL_NAMES.iter().position(|&name| name.eq_ignore_ascii_case(level));
|
||||
pos.map(|p| p as u32 + 1)
|
||||
}).map(|p| cmp::min(p, ::MAX_LOG_LEVEL))
|
||||
|
@ -164,7 +164,7 @@
|
||||
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
|
||||
html_root_url = "http://doc.rust-lang.org/nightly/",
|
||||
html_playground_url = "http://play.rust-lang.org/")]
|
||||
#![feature(macro_rules, unboxed_closures)]
|
||||
#![feature(macro_rules, unboxed_closures, slicing_syntax)]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
extern crate regex;
|
||||
@ -280,7 +280,7 @@ pub fn log(level: u32, loc: &'static LogLocation, args: &fmt::Arguments) {
|
||||
// Test the literal string from args against the current filter, if there
|
||||
// is one.
|
||||
match unsafe { FILTER.as_ref() } {
|
||||
Some(filter) if !filter.is_match(args.to_string().as_slice()) => return,
|
||||
Some(filter) if !filter.is_match(args.to_string()[]) => return,
|
||||
_ => {}
|
||||
}
|
||||
|
||||
@ -370,12 +370,12 @@ pub fn mod_enabled(level: u32, module: &str) -> bool {
|
||||
|
||||
fn enabled(level: u32,
|
||||
module: &str,
|
||||
iter: slice::Items<directive::LogDirective>)
|
||||
iter: slice::Iter<directive::LogDirective>)
|
||||
-> bool {
|
||||
// Search for the longest match, the vector is assumed to be pre-sorted.
|
||||
for directive in iter.rev() {
|
||||
match directive.name {
|
||||
Some(ref name) if !module.starts_with(name.as_slice()) => {},
|
||||
Some(ref name) if !module.starts_with(name[]) => {},
|
||||
Some(..) | None => {
|
||||
return level <= directive.level
|
||||
}
|
||||
@ -390,7 +390,7 @@ fn enabled(level: u32,
|
||||
/// `Once` primitive (and this function is called from that primitive).
|
||||
fn init() {
|
||||
let (mut directives, filter) = match os::getenv("RUST_LOG") {
|
||||
Some(spec) => directive::parse_logging_spec(spec.as_slice()),
|
||||
Some(spec) => directive::parse_logging_spec(spec[]),
|
||||
None => (Vec::new(), None),
|
||||
};
|
||||
|
||||
|
@ -286,7 +286,7 @@ impl<'a> Parser<'a> {
|
||||
true => Ok(()),
|
||||
false => {
|
||||
self.err(format!("Expected {} but got EOF.",
|
||||
expected).as_slice())
|
||||
expected)[])
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -295,10 +295,10 @@ impl<'a> Parser<'a> {
|
||||
match self.next_char() {
|
||||
true if self.cur() == expected => Ok(()),
|
||||
true => self.err(format!("Expected '{}' but got '{}'.",
|
||||
expected, self.cur()).as_slice()),
|
||||
expected, self.cur())[]),
|
||||
false => {
|
||||
self.err(format!("Expected '{}' but got EOF.",
|
||||
expected).as_slice())
|
||||
expected)[])
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -443,14 +443,14 @@ impl<'a> Parser<'a> {
|
||||
Literal(c3, _) => c2 = c3, // allow literal escapes below
|
||||
ast =>
|
||||
return self.err(format!("Expected a literal, but got {}.",
|
||||
ast).as_slice()),
|
||||
ast)[]),
|
||||
}
|
||||
}
|
||||
if c2 < c {
|
||||
return self.err(format!("Invalid character class \
|
||||
range '{}-{}'",
|
||||
c,
|
||||
c2).as_slice())
|
||||
c2)[])
|
||||
}
|
||||
ranges.push((c, self.cur()))
|
||||
} else {
|
||||
@ -488,7 +488,7 @@ impl<'a> Parser<'a> {
|
||||
FLAG_EMPTY
|
||||
};
|
||||
let name = self.slice(name_start, closer - 1);
|
||||
match find_class(ASCII_CLASSES, name.as_slice()) {
|
||||
match find_class(ASCII_CLASSES, name[]) {
|
||||
None => None,
|
||||
Some(ranges) => {
|
||||
self.chari = closer;
|
||||
@ -513,7 +513,7 @@ impl<'a> Parser<'a> {
|
||||
return self.err(format!("No closing brace for counted \
|
||||
repetition starting at position \
|
||||
{}.",
|
||||
start).as_slice())
|
||||
start)[])
|
||||
}
|
||||
};
|
||||
self.chari = closer;
|
||||
@ -524,7 +524,7 @@ impl<'a> Parser<'a> {
|
||||
// Parse the min and max values from the regex.
|
||||
let (mut min, mut max): (uint, Option<uint>);
|
||||
if !inner.contains(",") {
|
||||
min = try!(self.parse_uint(inner.as_slice()));
|
||||
min = try!(self.parse_uint(inner[]));
|
||||
max = Some(min);
|
||||
} else {
|
||||
let pieces: Vec<&str> = inner.splitn(1, ',').collect();
|
||||
@ -546,19 +546,19 @@ impl<'a> Parser<'a> {
|
||||
if min > MAX_REPEAT {
|
||||
return self.err(format!(
|
||||
"{} exceeds maximum allowed repetitions ({})",
|
||||
min, MAX_REPEAT).as_slice());
|
||||
min, MAX_REPEAT)[]);
|
||||
}
|
||||
if max.is_some() {
|
||||
let m = max.unwrap();
|
||||
if m > MAX_REPEAT {
|
||||
return self.err(format!(
|
||||
"{} exceeds maximum allowed repetitions ({})",
|
||||
m, MAX_REPEAT).as_slice());
|
||||
m, MAX_REPEAT)[]);
|
||||
}
|
||||
if m < min {
|
||||
return self.err(format!(
|
||||
"Max repetitions ({}) cannot be smaller than min \
|
||||
repetitions ({}).", m, min).as_slice());
|
||||
repetitions ({}).", m, min)[]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -622,8 +622,7 @@ impl<'a> Parser<'a> {
|
||||
Ok(AstClass(ranges, flags))
|
||||
}
|
||||
_ => {
|
||||
self.err(format!("Invalid escape sequence '\\\\{}'",
|
||||
c).as_slice())
|
||||
self.err(format!("Invalid escape sequence '\\\\{}'", c)[])
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -643,7 +642,7 @@ impl<'a> Parser<'a> {
|
||||
Some(i) => i,
|
||||
None => return self.err(format!(
|
||||
"Missing '}}' for unclosed '{{' at position {}",
|
||||
self.chari).as_slice()),
|
||||
self.chari)[]),
|
||||
};
|
||||
if closer - self.chari + 1 == 0 {
|
||||
return self.err("No Unicode class name found.")
|
||||
@ -657,10 +656,10 @@ impl<'a> Parser<'a> {
|
||||
name = self.slice(self.chari + 1, self.chari + 2);
|
||||
self.chari += 1;
|
||||
}
|
||||
match find_class(UNICODE_CLASSES, name.as_slice()) {
|
||||
match find_class(UNICODE_CLASSES, name[]) {
|
||||
None => {
|
||||
return self.err(format!("Could not find Unicode class '{}'",
|
||||
name).as_slice())
|
||||
name)[])
|
||||
}
|
||||
Some(ranges) => {
|
||||
Ok(AstClass(ranges, negated | (self.flags & FLAG_NOCASE)))
|
||||
@ -683,11 +682,11 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
}
|
||||
let s = self.slice(start, end);
|
||||
match num::from_str_radix::<u32>(s.as_slice(), 8) {
|
||||
match num::from_str_radix::<u32>(s[], 8) {
|
||||
Some(n) => Ok(Literal(try!(self.char_from_u32(n)), FLAG_EMPTY)),
|
||||
None => {
|
||||
self.err(format!("Could not parse '{}' as octal number.",
|
||||
s).as_slice())
|
||||
s)[])
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -705,12 +704,12 @@ impl<'a> Parser<'a> {
|
||||
None => {
|
||||
return self.err(format!("Missing '}}' for unclosed \
|
||||
'{{' at position {}",
|
||||
start).as_slice())
|
||||
start)[])
|
||||
}
|
||||
Some(i) => i,
|
||||
};
|
||||
self.chari = closer;
|
||||
self.parse_hex_digits(self.slice(start, closer).as_slice())
|
||||
self.parse_hex_digits(self.slice(start, closer)[])
|
||||
}
|
||||
|
||||
// Parses a two-digit hex number.
|
||||
@ -730,8 +729,7 @@ impl<'a> Parser<'a> {
|
||||
match num::from_str_radix::<u32>(s, 16) {
|
||||
Some(n) => Ok(Literal(try!(self.char_from_u32(n)), FLAG_EMPTY)),
|
||||
None => {
|
||||
self.err(format!("Could not parse '{}' as hex number.",
|
||||
s).as_slice())
|
||||
self.err(format!("Could not parse '{}' as hex number.", s)[])
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -757,7 +755,7 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
if self.names.contains(&name) {
|
||||
return self.err(format!("Duplicate capture group name '{}'.",
|
||||
name).as_slice())
|
||||
name)[])
|
||||
}
|
||||
self.names.push(name.clone());
|
||||
self.chari = closer;
|
||||
@ -791,7 +789,7 @@ impl<'a> Parser<'a> {
|
||||
if sign < 0 {
|
||||
return self.err(format!(
|
||||
"Cannot negate flags twice in '{}'.",
|
||||
self.slice(start, self.chari + 1)).as_slice())
|
||||
self.slice(start, self.chari + 1))[])
|
||||
}
|
||||
sign = -1;
|
||||
saw_flag = false;
|
||||
@ -802,7 +800,7 @@ impl<'a> Parser<'a> {
|
||||
if !saw_flag {
|
||||
return self.err(format!(
|
||||
"A valid flag does not follow negation in '{}'",
|
||||
self.slice(start, self.chari + 1)).as_slice())
|
||||
self.slice(start, self.chari + 1))[])
|
||||
}
|
||||
flags = flags ^ flags;
|
||||
}
|
||||
@ -814,7 +812,7 @@ impl<'a> Parser<'a> {
|
||||
return Ok(())
|
||||
}
|
||||
_ => return self.err(format!(
|
||||
"Unrecognized flag '{}'.", self.cur()).as_slice()),
|
||||
"Unrecognized flag '{}'.", self.cur())[]),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -908,11 +906,11 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
|
||||
fn parse_uint(&self, s: &str) -> Result<uint, Error> {
|
||||
match from_str::<uint>(s) {
|
||||
match s.parse::<uint>() {
|
||||
Some(i) => Ok(i),
|
||||
None => {
|
||||
self.err(format!("Expected an unsigned integer but got '{}'.",
|
||||
s).as_slice())
|
||||
s)[])
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -922,8 +920,7 @@ impl<'a> Parser<'a> {
|
||||
Some(c) => Ok(c),
|
||||
None => {
|
||||
self.err(format!("Could not decode '{}' to unicode \
|
||||
character.",
|
||||
n).as_slice())
|
||||
character.", n)[])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -417,7 +417,7 @@ impl Regex {
|
||||
/// # extern crate regex; #[phase(plugin)] extern crate regex_macros;
|
||||
/// # fn main() {
|
||||
/// let re = regex!("[^01]+");
|
||||
/// assert_eq!(re.replace("1078910", "").as_slice(), "1010");
|
||||
/// assert_eq!(re.replace("1078910", ""), "1010");
|
||||
/// # }
|
||||
/// ```
|
||||
///
|
||||
@ -435,7 +435,7 @@ impl Regex {
|
||||
/// let result = re.replace("Springsteen, Bruce", |&: caps: &Captures| {
|
||||
/// format!("{} {}", caps.at(2).unwrap_or(""), caps.at(1).unwrap_or(""))
|
||||
/// });
|
||||
/// assert_eq!(result.as_slice(), "Bruce Springsteen");
|
||||
/// assert_eq!(result, "Bruce Springsteen");
|
||||
/// # }
|
||||
/// ```
|
||||
///
|
||||
@ -450,7 +450,7 @@ impl Regex {
|
||||
/// # fn main() {
|
||||
/// let re = regex!(r"(?P<last>[^,\s]+),\s+(?P<first>\S+)");
|
||||
/// let result = re.replace("Springsteen, Bruce", "$first $last");
|
||||
/// assert_eq!(result.as_slice(), "Bruce Springsteen");
|
||||
/// assert_eq!(result, "Bruce Springsteen");
|
||||
/// # }
|
||||
/// ```
|
||||
///
|
||||
@ -469,7 +469,7 @@ impl Regex {
|
||||
///
|
||||
/// let re = regex!(r"(?P<last>[^,\s]+),\s+(\S+)");
|
||||
/// let result = re.replace("Springsteen, Bruce", NoExpand("$2 $last"));
|
||||
/// assert_eq!(result.as_slice(), "$2 $last");
|
||||
/// assert_eq!(result, "$2 $last");
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn replace<R: Replacer>(&self, text: &str, rep: R) -> String {
|
||||
@ -505,19 +505,19 @@ impl Regex {
|
||||
}
|
||||
|
||||
let (s, e) = cap.pos(0).unwrap(); // captures only reports matches
|
||||
new.push_str(text.slice(last_match, s));
|
||||
new.push_str(rep.reg_replace(&cap).as_slice());
|
||||
new.push_str(text[last_match..s]);
|
||||
new.push_str(rep.reg_replace(&cap)[]);
|
||||
last_match = e;
|
||||
}
|
||||
new.push_str(text.slice(last_match, text.len()));
|
||||
new.push_str(text[last_match..text.len()]);
|
||||
return new;
|
||||
}
|
||||
|
||||
/// Returns the original string of this regex.
|
||||
pub fn as_str<'a>(&'a self) -> &'a str {
|
||||
match *self {
|
||||
Dynamic(ExDynamic { ref original, .. }) => original.as_slice(),
|
||||
Native(ExNative { ref original, .. }) => original.as_slice(),
|
||||
Dynamic(ExDynamic { ref original, .. }) => original[],
|
||||
Native(ExNative { ref original, .. }) => original[],
|
||||
}
|
||||
}
|
||||
|
||||
@ -540,8 +540,8 @@ impl Regex {
|
||||
}
|
||||
|
||||
pub enum NamesIter<'a> {
|
||||
NamesIterNative(::std::slice::Items<'a, Option<&'static str>>),
|
||||
NamesIterDynamic(::std::slice::Items<'a, Option<String>>)
|
||||
NamesIterNative(::std::slice::Iter<'a, Option<&'static str>>),
|
||||
NamesIterDynamic(::std::slice::Iter<'a, Option<String>>)
|
||||
}
|
||||
|
||||
impl<'a> Iterator<Option<String>> for NamesIter<'a> {
|
||||
@ -608,13 +608,13 @@ impl<'r, 't> Iterator<&'t str> for RegexSplits<'r, 't> {
|
||||
if self.last >= text.len() {
|
||||
None
|
||||
} else {
|
||||
let s = text.slice(self.last, text.len());
|
||||
let s = text[self.last..text.len()];
|
||||
self.last = text.len();
|
||||
Some(s)
|
||||
}
|
||||
}
|
||||
Some((s, e)) => {
|
||||
let matched = text.slice(self.last, s);
|
||||
let matched = text[self.last..s];
|
||||
self.last = e;
|
||||
Some(matched)
|
||||
}
|
||||
@ -642,7 +642,7 @@ impl<'r, 't> Iterator<&'t str> for RegexSplitsN<'r, 't> {
|
||||
} else {
|
||||
self.cur += 1;
|
||||
if self.cur >= self.limit {
|
||||
Some(text.slice(self.splits.last, text.len()))
|
||||
Some(text[self.splits.last..text.len()])
|
||||
} else {
|
||||
self.splits.next()
|
||||
}
|
||||
@ -769,13 +769,13 @@ impl<'t> Captures<'t> {
|
||||
let pre = refs.at(1).unwrap_or("");
|
||||
let name = refs.at(2).unwrap_or("");
|
||||
format!("{}{}", pre,
|
||||
match from_str::<uint>(name.as_slice()) {
|
||||
match name.parse::<uint>() {
|
||||
None => self.name(name).unwrap_or("").to_string(),
|
||||
Some(i) => self.at(i).unwrap_or("").to_string(),
|
||||
})
|
||||
});
|
||||
let re = Regex::new(r"\$\$").unwrap();
|
||||
re.replace_all(text.as_slice(), NoExpand("$"))
|
||||
re.replace_all(text[], NoExpand("$"))
|
||||
}
|
||||
|
||||
/// Returns the number of captured groups.
|
||||
|
@ -40,6 +40,8 @@ extern crate collections;
|
||||
#[phase(plugin, link)] extern crate log;
|
||||
#[phase(plugin, link)] extern crate syntax;
|
||||
|
||||
extern crate "serialize" as rustc_serialize; // used by deriving
|
||||
|
||||
#[cfg(test)]
|
||||
extern crate test;
|
||||
|
||||
@ -115,6 +117,7 @@ pub mod util {
|
||||
pub mod ppaux;
|
||||
pub mod nodemap;
|
||||
pub mod snapshot_vec;
|
||||
pub mod lev_distance;
|
||||
}
|
||||
|
||||
pub mod lib {
|
||||
|
@ -250,10 +250,12 @@ impl LintPass for TypeLimits {
|
||||
let (min, max) = float_ty_range(t);
|
||||
let lit_val: f64 = match lit.node {
|
||||
ast::LitFloat(ref v, _) |
|
||||
ast::LitFloatUnsuffixed(ref v) => match from_str(v.get()) {
|
||||
Some(f) => f,
|
||||
None => return
|
||||
},
|
||||
ast::LitFloatUnsuffixed(ref v) => {
|
||||
match v.parse() {
|
||||
Some(f) => f,
|
||||
None => return
|
||||
}
|
||||
}
|
||||
_ => panic!()
|
||||
};
|
||||
if lit_val < min || lit_val > max {
|
||||
@ -507,7 +509,7 @@ impl BoxPointers {
|
||||
if n_uniq > 0 {
|
||||
let s = ty_to_string(cx.tcx, ty);
|
||||
let m = format!("type uses owned (Box type) pointers: {}", s);
|
||||
cx.span_lint(BOX_POINTERS, span, m.as_slice());
|
||||
cx.span_lint(BOX_POINTERS, span, m[]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -587,7 +589,7 @@ impl LintPass for RawPointerDeriving {
|
||||
}
|
||||
|
||||
fn check_item(&mut self, cx: &Context, item: &ast::Item) {
|
||||
if !attr::contains_name(item.attrs.as_slice(), "automatically_derived") {
|
||||
if !attr::contains_name(item.attrs[], "automatically_derived") {
|
||||
return
|
||||
}
|
||||
let did = match item.node {
|
||||
@ -766,11 +768,11 @@ impl LintPass for UnusedResults {
|
||||
ty::ty_enum(did, _) => {
|
||||
if ast_util::is_local(did) {
|
||||
if let ast_map::NodeItem(it) = cx.tcx.map.get(did.node) {
|
||||
warned |= check_must_use(cx, it.attrs.as_slice(), s.span);
|
||||
warned |= check_must_use(cx, it.attrs[], s.span);
|
||||
}
|
||||
} else {
|
||||
csearch::get_item_attrs(&cx.sess().cstore, did, |attrs| {
|
||||
warned |= check_must_use(cx, attrs.as_slice(), s.span);
|
||||
warned |= check_must_use(cx, attrs[], s.span);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -792,7 +794,7 @@ impl LintPass for UnusedResults {
|
||||
msg.push_str(s.get());
|
||||
}
|
||||
}
|
||||
cx.span_lint(UNUSED_MUST_USE, sp, msg.as_slice());
|
||||
cx.span_lint(UNUSED_MUST_USE, sp, msg[]);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -838,7 +840,7 @@ impl NonCamelCaseTypes {
|
||||
} else {
|
||||
format!("{} `{}` should have a camel case name such as `{}`", sort, s, c)
|
||||
};
|
||||
cx.span_lint(NON_CAMEL_CASE_TYPES, span, m.as_slice());
|
||||
cx.span_lint(NON_CAMEL_CASE_TYPES, span, m[]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -978,7 +980,7 @@ impl NonSnakeCase {
|
||||
if !is_snake_case(ident) {
|
||||
cx.span_lint(NON_SNAKE_CASE, span,
|
||||
format!("{} `{}` should have a snake case name such as `{}`",
|
||||
sort, s, to_snake_case(s.get())).as_slice());
|
||||
sort, s, to_snake_case(s.get()))[]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1065,7 +1067,7 @@ impl LintPass for NonUpperCaseGlobals {
|
||||
format!("static constant `{}` should have an uppercase name \
|
||||
such as `{}`",
|
||||
s.get(), s.get().chars().map(|c| c.to_uppercase())
|
||||
.collect::<String>().as_slice()).as_slice());
|
||||
.collect::<String>()[])[]);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
@ -1082,7 +1084,7 @@ impl LintPass for NonUpperCaseGlobals {
|
||||
format!("static constant in pattern `{}` should have an uppercase \
|
||||
name such as `{}`",
|
||||
s.get(), s.get().chars().map(|c| c.to_uppercase())
|
||||
.collect::<String>().as_slice()).as_slice());
|
||||
.collect::<String>()[])[]);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
@ -1107,7 +1109,7 @@ impl UnusedParens {
|
||||
if !necessary {
|
||||
cx.span_lint(UNUSED_PARENS, value.span,
|
||||
format!("unnecessary parentheses around {}",
|
||||
msg).as_slice())
|
||||
msg)[])
|
||||
}
|
||||
}
|
||||
|
||||
@ -1209,7 +1211,7 @@ impl LintPass for UnusedImportBraces {
|
||||
let m = format!("braces around {} is unnecessary",
|
||||
token::get_ident(*name).get());
|
||||
cx.span_lint(UNUSED_IMPORT_BRACES, view_item.span,
|
||||
m.as_slice());
|
||||
m[]);
|
||||
},
|
||||
_ => ()
|
||||
}
|
||||
@ -1248,7 +1250,7 @@ impl LintPass for NonShorthandFieldPatterns {
|
||||
if ident.node.as_str() == fieldpat.node.ident.as_str() {
|
||||
cx.span_lint(NON_SHORTHAND_FIELD_PATTERNS, fieldpat.span,
|
||||
format!("the `{}:` in this pattern is redundant and can \
|
||||
be removed", ident.node.as_str()).as_slice())
|
||||
be removed", ident.node.as_str())[])
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1352,7 +1354,7 @@ impl LintPass for UnusedMut {
|
||||
fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
|
||||
if let ast::ExprMatch(_, ref arms, _) = e.node {
|
||||
for a in arms.iter() {
|
||||
self.check_unused_mut_pat(cx, a.pats.as_slice())
|
||||
self.check_unused_mut_pat(cx, a.pats[])
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1473,7 +1475,7 @@ impl MissingDoc {
|
||||
});
|
||||
if !has_doc {
|
||||
cx.span_lint(MISSING_DOCS, sp,
|
||||
format!("missing documentation for {}", desc).as_slice());
|
||||
format!("missing documentation for {}", desc)[]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1487,7 +1489,7 @@ impl LintPass for MissingDoc {
|
||||
let doc_hidden = self.doc_hidden() || attrs.iter().any(|attr| {
|
||||
attr.check_name("doc") && match attr.meta_item_list() {
|
||||
None => false,
|
||||
Some(l) => attr::contains_name(l.as_slice(), "hidden"),
|
||||
Some(l) => attr::contains_name(l[], "hidden"),
|
||||
}
|
||||
});
|
||||
self.doc_hidden_stack.push(doc_hidden);
|
||||
@ -1509,7 +1511,7 @@ impl LintPass for MissingDoc {
|
||||
}
|
||||
|
||||
fn check_crate(&mut self, cx: &Context, krate: &ast::Crate) {
|
||||
self.check_missing_docs_attrs(cx, None, krate.attrs.as_slice(),
|
||||
self.check_missing_docs_attrs(cx, None, krate.attrs[],
|
||||
krate.span, "crate");
|
||||
}
|
||||
|
||||
@ -1523,7 +1525,7 @@ impl LintPass for MissingDoc {
|
||||
ast::ItemTy(..) => "a type alias",
|
||||
_ => return
|
||||
};
|
||||
self.check_missing_docs_attrs(cx, Some(it.id), it.attrs.as_slice(),
|
||||
self.check_missing_docs_attrs(cx, Some(it.id), it.attrs[],
|
||||
it.span, desc);
|
||||
}
|
||||
|
||||
@ -1536,13 +1538,13 @@ impl LintPass for MissingDoc {
|
||||
|
||||
// Otherwise, doc according to privacy. This will also check
|
||||
// doc for default methods defined on traits.
|
||||
self.check_missing_docs_attrs(cx, Some(m.id), m.attrs.as_slice(),
|
||||
self.check_missing_docs_attrs(cx, Some(m.id), m.attrs[],
|
||||
m.span, "a method");
|
||||
}
|
||||
}
|
||||
|
||||
fn check_ty_method(&mut self, cx: &Context, tm: &ast::TypeMethod) {
|
||||
self.check_missing_docs_attrs(cx, Some(tm.id), tm.attrs.as_slice(),
|
||||
self.check_missing_docs_attrs(cx, Some(tm.id), tm.attrs[],
|
||||
tm.span, "a type method");
|
||||
}
|
||||
|
||||
@ -1552,14 +1554,14 @@ impl LintPass for MissingDoc {
|
||||
let cur_struct_def = *self.struct_def_stack.last()
|
||||
.expect("empty struct_def_stack");
|
||||
self.check_missing_docs_attrs(cx, Some(cur_struct_def),
|
||||
sf.node.attrs.as_slice(), sf.span,
|
||||
sf.node.attrs[], sf.span,
|
||||
"a struct field")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn check_variant(&mut self, cx: &Context, v: &ast::Variant, _: &ast::Generics) {
|
||||
self.check_missing_docs_attrs(cx, Some(v.node.id), v.node.attrs.as_slice(),
|
||||
self.check_missing_docs_attrs(cx, Some(v.node.id), v.node.attrs[],
|
||||
v.span, "a variant");
|
||||
assert!(!self.in_variant);
|
||||
self.in_variant = true;
|
||||
@ -1675,7 +1677,7 @@ impl Stability {
|
||||
_ => format!("use of {} item", label)
|
||||
};
|
||||
|
||||
cx.span_lint(lint, span, msg.as_slice());
|
||||
cx.span_lint(lint, span, msg[]);
|
||||
}
|
||||
|
||||
fn is_internal(&self, cx: &Context, span: Span) -> bool {
|
||||
|
@ -104,7 +104,7 @@ impl LintStore {
|
||||
}
|
||||
|
||||
pub fn get_lints<'t>(&'t self) -> &'t [(&'static Lint, bool)] {
|
||||
self.lints.as_slice()
|
||||
self.lints[]
|
||||
}
|
||||
|
||||
pub fn get_lint_groups<'t>(&'t self) -> Vec<(&'static str, Vec<LintId>, bool)> {
|
||||
@ -124,11 +124,11 @@ impl LintStore {
|
||||
match (sess, from_plugin) {
|
||||
// We load builtin lints first, so a duplicate is a compiler bug.
|
||||
// Use early_error when handling -W help with no crate.
|
||||
(None, _) => early_error(msg.as_slice()),
|
||||
(Some(sess), false) => sess.bug(msg.as_slice()),
|
||||
(None, _) => early_error(msg[]),
|
||||
(Some(sess), false) => sess.bug(msg[]),
|
||||
|
||||
// A duplicate name from a plugin is a user error.
|
||||
(Some(sess), true) => sess.err(msg.as_slice()),
|
||||
(Some(sess), true) => sess.err(msg[]),
|
||||
}
|
||||
}
|
||||
|
||||
@ -149,11 +149,11 @@ impl LintStore {
|
||||
match (sess, from_plugin) {
|
||||
// We load builtin lints first, so a duplicate is a compiler bug.
|
||||
// Use early_error when handling -W help with no crate.
|
||||
(None, _) => early_error(msg.as_slice()),
|
||||
(Some(sess), false) => sess.bug(msg.as_slice()),
|
||||
(None, _) => early_error(msg[]),
|
||||
(Some(sess), false) => sess.bug(msg[]),
|
||||
|
||||
// A duplicate name from a plugin is a user error.
|
||||
(Some(sess), true) => sess.err(msg.as_slice()),
|
||||
(Some(sess), true) => sess.err(msg[]),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -260,8 +260,8 @@ impl LintStore {
|
||||
let warning = format!("lint {} has been renamed to {}",
|
||||
lint_name, new_name);
|
||||
match span {
|
||||
Some(span) => sess.span_warn(span, warning.as_slice()),
|
||||
None => sess.warn(warning.as_slice()),
|
||||
Some(span) => sess.span_warn(span, warning[]),
|
||||
None => sess.warn(warning[]),
|
||||
};
|
||||
Some(lint_id)
|
||||
}
|
||||
@ -271,13 +271,13 @@ impl LintStore {
|
||||
|
||||
pub fn process_command_line(&mut self, sess: &Session) {
|
||||
for &(ref lint_name, level) in sess.opts.lint_opts.iter() {
|
||||
match self.find_lint(lint_name.as_slice(), sess, None) {
|
||||
match self.find_lint(lint_name[], sess, None) {
|
||||
Some(lint_id) => self.set_level(lint_id, (level, CommandLine)),
|
||||
None => {
|
||||
match self.lint_groups.iter().map(|(&x, pair)| (x, pair.0.clone()))
|
||||
.collect::<FnvHashMap<&'static str,
|
||||
Vec<LintId>>>()
|
||||
.get(lint_name.as_slice()) {
|
||||
.get(lint_name[]) {
|
||||
Some(v) => {
|
||||
v.iter()
|
||||
.map(|lint_id: &LintId|
|
||||
@ -285,7 +285,7 @@ impl LintStore {
|
||||
.collect::<Vec<()>>();
|
||||
}
|
||||
None => sess.err(format!("unknown {} flag: {}",
|
||||
level.as_str(), lint_name).as_slice()),
|
||||
level.as_str(), lint_name)[]),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -396,10 +396,10 @@ pub fn raw_emit_lint(sess: &Session, lint: &'static Lint,
|
||||
if level == Forbid { level = Deny; }
|
||||
|
||||
match (level, span) {
|
||||
(Warn, Some(sp)) => sess.span_warn(sp, msg.as_slice()),
|
||||
(Warn, None) => sess.warn(msg.as_slice()),
|
||||
(Deny, Some(sp)) => sess.span_err(sp, msg.as_slice()),
|
||||
(Deny, None) => sess.err(msg.as_slice()),
|
||||
(Warn, Some(sp)) => sess.span_warn(sp, msg[]),
|
||||
(Warn, None) => sess.warn(msg[]),
|
||||
(Deny, Some(sp)) => sess.span_err(sp, msg[]),
|
||||
(Deny, None) => sess.err(msg[]),
|
||||
_ => sess.bug("impossible level in raw_emit_lint"),
|
||||
}
|
||||
|
||||
@ -492,7 +492,7 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
|
||||
None => {
|
||||
self.span_lint(builtin::UNKNOWN_LINTS, span,
|
||||
format!("unknown `{}` attribute: `{}`",
|
||||
level.as_str(), lint_name).as_slice());
|
||||
level.as_str(), lint_name)[]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@ -508,7 +508,7 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
|
||||
self.tcx.sess.span_err(span,
|
||||
format!("{}({}) overruled by outer forbid({})",
|
||||
level.as_str(), lint_name,
|
||||
lint_name).as_slice());
|
||||
lint_name)[]);
|
||||
} else if now != level {
|
||||
let src = self.lints.get_level_source(lint_id).1;
|
||||
self.level_stack.push((lint_id, (now, src)));
|
||||
@ -543,7 +543,7 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
|
||||
|
||||
impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> {
|
||||
fn visit_item(&mut self, it: &ast::Item) {
|
||||
self.with_lint_attrs(it.attrs.as_slice(), |cx| {
|
||||
self.with_lint_attrs(it.attrs[], |cx| {
|
||||
run_lints!(cx, check_item, it);
|
||||
cx.visit_ids(|v| v.visit_item(it));
|
||||
visit::walk_item(cx, it);
|
||||
@ -551,14 +551,14 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> {
|
||||
}
|
||||
|
||||
fn visit_foreign_item(&mut self, it: &ast::ForeignItem) {
|
||||
self.with_lint_attrs(it.attrs.as_slice(), |cx| {
|
||||
self.with_lint_attrs(it.attrs[], |cx| {
|
||||
run_lints!(cx, check_foreign_item, it);
|
||||
visit::walk_foreign_item(cx, it);
|
||||
})
|
||||
}
|
||||
|
||||
fn visit_view_item(&mut self, i: &ast::ViewItem) {
|
||||
self.with_lint_attrs(i.attrs.as_slice(), |cx| {
|
||||
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);
|
||||
@ -584,7 +584,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> {
|
||||
body: &'v ast::Block, span: Span, id: ast::NodeId) {
|
||||
match fk {
|
||||
visit::FkMethod(_, _, m) => {
|
||||
self.with_lint_attrs(m.attrs.as_slice(), |cx| {
|
||||
self.with_lint_attrs(m.attrs[], |cx| {
|
||||
run_lints!(cx, check_fn, fk, decl, body, span, id);
|
||||
cx.visit_ids(|v| {
|
||||
v.visit_fn(fk, decl, body, span, id);
|
||||
@ -600,7 +600,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> {
|
||||
}
|
||||
|
||||
fn visit_ty_method(&mut self, t: &ast::TypeMethod) {
|
||||
self.with_lint_attrs(t.attrs.as_slice(), |cx| {
|
||||
self.with_lint_attrs(t.attrs[], |cx| {
|
||||
run_lints!(cx, check_ty_method, t);
|
||||
visit::walk_ty_method(cx, t);
|
||||
})
|
||||
@ -617,14 +617,14 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> {
|
||||
}
|
||||
|
||||
fn visit_struct_field(&mut self, s: &ast::StructField) {
|
||||
self.with_lint_attrs(s.node.attrs.as_slice(), |cx| {
|
||||
self.with_lint_attrs(s.node.attrs[], |cx| {
|
||||
run_lints!(cx, check_struct_field, s);
|
||||
visit::walk_struct_field(cx, s);
|
||||
})
|
||||
}
|
||||
|
||||
fn visit_variant(&mut self, v: &ast::Variant, g: &ast::Generics) {
|
||||
self.with_lint_attrs(v.node.attrs.as_slice(), |cx| {
|
||||
self.with_lint_attrs(v.node.attrs[], |cx| {
|
||||
run_lints!(cx, check_variant, v, g);
|
||||
visit::walk_variant(cx, v, g);
|
||||
run_lints!(cx, check_variant_post, v, g);
|
||||
@ -718,7 +718,7 @@ impl<'a, 'tcx> IdVisitingOperation for Context<'a, 'tcx> {
|
||||
None => {}
|
||||
Some(lints) => {
|
||||
for (lint_id, span, msg) in lints.into_iter() {
|
||||
self.span_lint(lint_id.lint, span, msg.as_slice())
|
||||
self.span_lint(lint_id.lint, span, msg[])
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -764,7 +764,7 @@ pub fn check_crate(tcx: &ty::ctxt,
|
||||
let mut cx = Context::new(tcx, krate, exported_items);
|
||||
|
||||
// Visit the whole crate.
|
||||
cx.with_lint_attrs(krate.attrs.as_slice(), |cx| {
|
||||
cx.with_lint_attrs(krate.attrs[], |cx| {
|
||||
cx.visit_id(ast::CRATE_NODE_ID);
|
||||
cx.visit_ids(|v| {
|
||||
v.visited_outermost = true;
|
||||
@ -784,7 +784,7 @@ pub fn check_crate(tcx: &ty::ctxt,
|
||||
for &(lint, span, ref msg) in v.iter() {
|
||||
tcx.sess.span_bug(span,
|
||||
format!("unprocessed lint {} at {}: {}",
|
||||
lint.as_str(), tcx.map.node_to_string(*id), *msg).as_slice())
|
||||
lint.as_str(), tcx.map.node_to_string(*id), *msg)[])
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,11 +95,11 @@ fn warn_if_multiple_versions(diag: &SpanHandler, cstore: &CStore) {
|
||||
for (name, dupes) in map.into_iter() {
|
||||
if dupes.len() == 1 { continue }
|
||||
diag.handler().warn(
|
||||
format!("using multiple versions of crate `{}`", name).as_slice());
|
||||
format!("using multiple versions of crate `{}`", name)[]);
|
||||
for dupe in dupes.into_iter() {
|
||||
let data = cstore.get_crate_data(dupe);
|
||||
diag.span_note(data.span, "used here");
|
||||
loader::note_crate_name(diag, data.name().as_slice());
|
||||
loader::note_crate_name(diag, data.name()[]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -117,7 +117,7 @@ fn should_link(i: &ast::ViewItem) -> bool {
|
||||
i.attrs.iter().all(|attr| {
|
||||
attr.name().get() != "phase" ||
|
||||
attr.meta_item_list().map_or(false, |phases| {
|
||||
attr::contains_name(phases.as_slice(), "link")
|
||||
attr::contains_name(phases[], "link")
|
||||
})
|
||||
})
|
||||
}
|
||||
@ -131,8 +131,8 @@ fn visit_view_item(e: &mut Env, i: &ast::ViewItem) {
|
||||
Some(info) => {
|
||||
let (cnum, _, _) = resolve_crate(e,
|
||||
&None,
|
||||
info.ident.as_slice(),
|
||||
info.name.as_slice(),
|
||||
info.ident[],
|
||||
info.name[],
|
||||
None,
|
||||
i.span);
|
||||
e.sess.cstore.add_extern_mod_stmt_cnum(info.id, cnum);
|
||||
@ -157,7 +157,7 @@ fn extract_crate_info(e: &Env, i: &ast::ViewItem) -> Option<CrateInfo> {
|
||||
let name = match *path_opt {
|
||||
Some((ref path_str, _)) => {
|
||||
let name = path_str.get().to_string();
|
||||
validate_crate_name(Some(e.sess), name.as_slice(),
|
||||
validate_crate_name(Some(e.sess), name[],
|
||||
Some(i.span));
|
||||
name
|
||||
}
|
||||
@ -188,7 +188,7 @@ pub fn validate_crate_name(sess: Option<&Session>, s: &str, sp: Option<Span>) {
|
||||
for c in s.chars() {
|
||||
if c.is_alphanumeric() { continue }
|
||||
if c == '_' || c == '-' { continue }
|
||||
err(format!("invalid character `{}` in crate name: `{}`", c, s).as_slice());
|
||||
err(format!("invalid character `{}` in crate name: `{}`", c, s)[]);
|
||||
}
|
||||
match sess {
|
||||
Some(sess) => sess.abort_if_errors(),
|
||||
@ -246,7 +246,7 @@ fn visit_item(e: &Env, i: &ast::Item) {
|
||||
} else {
|
||||
e.sess.span_err(m.span,
|
||||
format!("unknown kind: `{}`",
|
||||
k).as_slice());
|
||||
k)[]);
|
||||
cstore::NativeUnknown
|
||||
}
|
||||
}
|
||||
@ -327,7 +327,7 @@ fn existing_match(e: &Env, name: &str,
|
||||
match e.sess.opts.externs.get(name) {
|
||||
Some(locs) => {
|
||||
let found = locs.iter().any(|l| {
|
||||
let l = fs::realpath(&Path::new(l.as_slice())).ok();
|
||||
let l = fs::realpath(&Path::new(l[])).ok();
|
||||
l == source.dylib || l == source.rlib
|
||||
});
|
||||
if found {
|
||||
@ -405,7 +405,7 @@ fn resolve_crate<'a>(e: &mut Env,
|
||||
crate_name: name,
|
||||
hash: hash.map(|a| &*a),
|
||||
filesearch: e.sess.target_filesearch(),
|
||||
triple: e.sess.opts.target_triple.as_slice(),
|
||||
triple: e.sess.opts.target_triple[],
|
||||
root: root,
|
||||
rejected_via_hash: vec!(),
|
||||
rejected_via_triple: vec!(),
|
||||
@ -431,8 +431,8 @@ fn resolve_crate_deps(e: &mut Env,
|
||||
decoder::get_crate_deps(cdata).iter().map(|dep| {
|
||||
debug!("resolving dep crate {} hash: `{}`", dep.name, dep.hash);
|
||||
let (local_cnum, _, _) = resolve_crate(e, root,
|
||||
dep.name.as_slice(),
|
||||
dep.name.as_slice(),
|
||||
dep.name[],
|
||||
dep.name[],
|
||||
Some(&dep.hash),
|
||||
span);
|
||||
(dep.cnum, local_cnum)
|
||||
@ -455,14 +455,14 @@ impl<'a> PluginMetadataReader<'a> {
|
||||
|
||||
pub fn read_plugin_metadata(&mut self, krate: &ast::ViewItem) -> PluginMetadata {
|
||||
let info = extract_crate_info(&self.env, krate).unwrap();
|
||||
let target_triple = self.env.sess.opts.target_triple.as_slice();
|
||||
let target_triple = self.env.sess.opts.target_triple[];
|
||||
let is_cross = target_triple != config::host_triple();
|
||||
let mut should_link = info.should_link && !is_cross;
|
||||
let mut load_ctxt = loader::Context {
|
||||
sess: self.env.sess,
|
||||
span: krate.span,
|
||||
ident: info.ident.as_slice(),
|
||||
crate_name: info.name.as_slice(),
|
||||
ident: info.ident[],
|
||||
crate_name: info.name[],
|
||||
hash: None,
|
||||
filesearch: self.env.sess.host_filesearch(),
|
||||
triple: config::host_triple(),
|
||||
@ -483,7 +483,7 @@ impl<'a> PluginMetadataReader<'a> {
|
||||
let message = format!("crate `{}` contains a plugin_registrar fn but \
|
||||
only a version for triple `{}` could be found (need {})",
|
||||
info.ident, target_triple, config::host_triple());
|
||||
self.env.sess.span_err(krate.span, message.as_slice());
|
||||
self.env.sess.span_err(krate.span, message[]);
|
||||
// need to abort now because the syntax expansion
|
||||
// code will shortly attempt to load and execute
|
||||
// code from the found library.
|
||||
@ -502,7 +502,7 @@ impl<'a> PluginMetadataReader<'a> {
|
||||
let message = format!("plugin crate `{}` only found in rlib format, \
|
||||
but must be available in dylib format",
|
||||
info.ident);
|
||||
self.env.sess.span_err(krate.span, message.as_slice());
|
||||
self.env.sess.span_err(krate.span, message[]);
|
||||
// No need to abort because the loading code will just ignore this
|
||||
// empty dylib.
|
||||
}
|
||||
@ -511,11 +511,11 @@ impl<'a> PluginMetadataReader<'a> {
|
||||
macros: macros,
|
||||
registrar_symbol: registrar,
|
||||
};
|
||||
if should_link && existing_match(&self.env, info.name.as_slice(),
|
||||
if should_link && existing_match(&self.env, info.name[],
|
||||
None).is_none() {
|
||||
// register crate now to avoid double-reading metadata
|
||||
register_crate(&mut self.env, &None, info.ident.as_slice(),
|
||||
info.name.as_slice(), krate.span, library);
|
||||
register_crate(&mut self.env, &None, info.ident[],
|
||||
info.name[], krate.span, library);
|
||||
}
|
||||
pc
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ pub fn get_item_path(tcx: &ty::ctxt, def: ast::DefId) -> Vec<ast_map::PathElem>
|
||||
|
||||
// FIXME #1920: This path is not always correct if the crate is not linked
|
||||
// into the root namespace.
|
||||
let mut r = vec![ast_map::PathMod(token::intern(cdata.name.as_slice()))];
|
||||
let mut r = vec![ast_map::PathMod(token::intern(cdata.name[]))];
|
||||
r.push_all(path.as_slice());
|
||||
r
|
||||
}
|
||||
|
@ -221,7 +221,7 @@ fn each_reexport<F>(d: rbml::Doc, f: F) -> bool where
|
||||
fn variant_disr_val(d: rbml::Doc) -> Option<ty::Disr> {
|
||||
reader::maybe_get_doc(d, tag_disr_val).and_then(|val_doc| {
|
||||
reader::with_doc_data(val_doc, |data| {
|
||||
str::from_utf8(data).and_then(from_str)
|
||||
str::from_utf8(data).ok().and_then(|s| s.parse())
|
||||
})
|
||||
})
|
||||
}
|
||||
@ -700,7 +700,7 @@ pub fn get_enum_variants<'tcx>(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::Nod
|
||||
item, tcx, cdata);
|
||||
let name = item_name(&*intr, item);
|
||||
let (ctor_ty, arg_tys, arg_names) = match ctor_ty.sty {
|
||||
ty::ty_bare_fn(ref f) =>
|
||||
ty::ty_bare_fn(_, ref f) =>
|
||||
(Some(ctor_ty), f.sig.0.inputs.clone(), None),
|
||||
_ => { // Nullary or struct enum variant.
|
||||
let mut arg_names = Vec::new();
|
||||
@ -1160,7 +1160,7 @@ pub fn get_crate_deps(data: &[u8]) -> Vec<CrateDep> {
|
||||
}
|
||||
reader::tagged_docs(depsdoc, tag_crate_dep, |depdoc| {
|
||||
let name = docstr(depdoc, tag_crate_dep_crate_name);
|
||||
let hash = Svh::new(docstr(depdoc, tag_crate_dep_hash).as_slice());
|
||||
let hash = Svh::new(docstr(depdoc, tag_crate_dep_hash)[]);
|
||||
deps.push(CrateDep {
|
||||
cnum: crate_num,
|
||||
name: name,
|
||||
@ -1345,7 +1345,7 @@ pub fn get_dylib_dependency_formats(cdata: Cmd)
|
||||
if spec.len() == 0 { continue }
|
||||
let cnum = spec.split(':').nth(0).unwrap();
|
||||
let link = spec.split(':').nth(1).unwrap();
|
||||
let cnum = from_str(cnum).unwrap();
|
||||
let cnum = cnum.parse().unwrap();
|
||||
let cnum = match cdata.cnum_map.get(&cnum) {
|
||||
Some(&n) => n,
|
||||
None => panic!("didn't find a crate in the cnum_map")
|
||||
|
@ -95,7 +95,7 @@ fn encode_impl_type_basename(rbml_w: &mut Encoder, name: ast::Ident) {
|
||||
}
|
||||
|
||||
pub fn encode_def_id(rbml_w: &mut Encoder, id: DefId) {
|
||||
rbml_w.wr_tagged_str(tag_def_id, def_to_string(id).as_slice());
|
||||
rbml_w.wr_tagged_str(tag_def_id, def_to_string(id)[]);
|
||||
}
|
||||
|
||||
#[deriving(Clone)]
|
||||
@ -154,7 +154,7 @@ fn encode_variant_id(rbml_w: &mut Encoder, vid: DefId) {
|
||||
rbml_w.end_tag();
|
||||
|
||||
rbml_w.start_tag(tag_mod_child);
|
||||
rbml_w.wr_str(s.as_slice());
|
||||
rbml_w.wr_str(s[]);
|
||||
rbml_w.end_tag();
|
||||
}
|
||||
|
||||
@ -264,7 +264,7 @@ fn encode_symbol(ecx: &EncodeContext,
|
||||
}
|
||||
None => {
|
||||
ecx.diag.handler().bug(
|
||||
format!("encode_symbol: id not found {}", id).as_slice());
|
||||
format!("encode_symbol: id not found {}", id)[]);
|
||||
}
|
||||
}
|
||||
rbml_w.end_tag();
|
||||
@ -332,8 +332,8 @@ fn encode_enum_variant_info(ecx: &EncodeContext,
|
||||
encode_name(rbml_w, variant.node.name.name);
|
||||
encode_parent_item(rbml_w, local_def(id));
|
||||
encode_visibility(rbml_w, variant.node.vis);
|
||||
encode_attributes(rbml_w, variant.node.attrs.as_slice());
|
||||
encode_repr_attrs(rbml_w, ecx, variant.node.attrs.as_slice());
|
||||
encode_attributes(rbml_w, variant.node.attrs[]);
|
||||
encode_repr_attrs(rbml_w, ecx, variant.node.attrs[]);
|
||||
|
||||
let stab = stability::lookup(ecx.tcx, ast_util::local_def(variant.node.id));
|
||||
encode_stability(rbml_w, stab);
|
||||
@ -344,9 +344,9 @@ fn encode_enum_variant_info(ecx: &EncodeContext,
|
||||
let fields = ty::lookup_struct_fields(ecx.tcx, def_id);
|
||||
let idx = encode_info_for_struct(ecx,
|
||||
rbml_w,
|
||||
fields.as_slice(),
|
||||
fields[],
|
||||
index);
|
||||
encode_struct_fields(rbml_w, fields.as_slice(), def_id);
|
||||
encode_struct_fields(rbml_w, fields[], def_id);
|
||||
encode_index(rbml_w, idx, write_i64);
|
||||
}
|
||||
}
|
||||
@ -386,12 +386,12 @@ fn encode_reexported_static_method(rbml_w: &mut Encoder,
|
||||
exp.name, token::get_name(method_name));
|
||||
rbml_w.start_tag(tag_items_data_item_reexport);
|
||||
rbml_w.start_tag(tag_items_data_item_reexport_def_id);
|
||||
rbml_w.wr_str(def_to_string(method_def_id).as_slice());
|
||||
rbml_w.wr_str(def_to_string(method_def_id)[]);
|
||||
rbml_w.end_tag();
|
||||
rbml_w.start_tag(tag_items_data_item_reexport_name);
|
||||
rbml_w.wr_str(format!("{}::{}",
|
||||
exp.name,
|
||||
token::get_name(method_name)).as_slice());
|
||||
token::get_name(method_name))[]);
|
||||
rbml_w.end_tag();
|
||||
rbml_w.end_tag();
|
||||
}
|
||||
@ -529,7 +529,7 @@ fn encode_reexports(ecx: &EncodeContext,
|
||||
id);
|
||||
rbml_w.start_tag(tag_items_data_item_reexport);
|
||||
rbml_w.start_tag(tag_items_data_item_reexport_def_id);
|
||||
rbml_w.wr_str(def_to_string(exp.def_id).as_slice());
|
||||
rbml_w.wr_str(def_to_string(exp.def_id)[]);
|
||||
rbml_w.end_tag();
|
||||
rbml_w.start_tag(tag_items_data_item_reexport_name);
|
||||
rbml_w.wr_str(exp.name.as_str());
|
||||
@ -562,13 +562,13 @@ fn encode_info_for_mod(ecx: &EncodeContext,
|
||||
// Encode info about all the module children.
|
||||
for item in md.items.iter() {
|
||||
rbml_w.start_tag(tag_mod_child);
|
||||
rbml_w.wr_str(def_to_string(local_def(item.id)).as_slice());
|
||||
rbml_w.wr_str(def_to_string(local_def(item.id))[]);
|
||||
rbml_w.end_tag();
|
||||
|
||||
each_auxiliary_node_id(&**item, |auxiliary_node_id| {
|
||||
rbml_w.start_tag(tag_mod_child);
|
||||
rbml_w.wr_str(def_to_string(local_def(
|
||||
auxiliary_node_id)).as_slice());
|
||||
auxiliary_node_id))[]);
|
||||
rbml_w.end_tag();
|
||||
true
|
||||
});
|
||||
@ -580,7 +580,7 @@ fn encode_info_for_mod(ecx: &EncodeContext,
|
||||
did, ecx.tcx.map.node_to_string(did));
|
||||
|
||||
rbml_w.start_tag(tag_mod_impl);
|
||||
rbml_w.wr_str(def_to_string(local_def(did)).as_slice());
|
||||
rbml_w.wr_str(def_to_string(local_def(did))[]);
|
||||
rbml_w.end_tag();
|
||||
}
|
||||
}
|
||||
@ -615,7 +615,7 @@ fn encode_visibility(rbml_w: &mut Encoder, visibility: ast::Visibility) {
|
||||
ast::Public => 'y',
|
||||
ast::Inherited => 'i',
|
||||
};
|
||||
rbml_w.wr_str(ch.to_string().as_slice());
|
||||
rbml_w.wr_str(ch.to_string()[]);
|
||||
rbml_w.end_tag();
|
||||
}
|
||||
|
||||
@ -627,7 +627,7 @@ fn encode_unboxed_closure_kind(rbml_w: &mut Encoder,
|
||||
ty::FnMutUnboxedClosureKind => 'm',
|
||||
ty::FnOnceUnboxedClosureKind => 'o',
|
||||
};
|
||||
rbml_w.wr_str(ch.to_string().as_slice());
|
||||
rbml_w.wr_str(ch.to_string()[]);
|
||||
rbml_w.end_tag();
|
||||
}
|
||||
|
||||
@ -788,7 +788,7 @@ fn encode_generics<'a, 'tcx>(rbml_w: &mut Encoder,
|
||||
rbml_w.end_tag();
|
||||
|
||||
rbml_w.wr_tagged_str(tag_region_param_def_def_id,
|
||||
def_to_string(param.def_id).as_slice());
|
||||
def_to_string(param.def_id)[]);
|
||||
|
||||
rbml_w.wr_tagged_u64(tag_region_param_def_space,
|
||||
param.space.to_uint() as u64);
|
||||
@ -864,9 +864,9 @@ fn encode_info_for_method<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
|
||||
encode_path(rbml_w, impl_path.chain(Some(elem).into_iter()));
|
||||
match ast_item_opt {
|
||||
Some(&ast::MethodImplItem(ref ast_method)) => {
|
||||
encode_attributes(rbml_w, ast_method.attrs.as_slice());
|
||||
encode_attributes(rbml_w, ast_method.attrs[]);
|
||||
let any_types = !pty.generics.types.is_empty();
|
||||
if any_types || is_default_impl || should_inline(ast_method.attrs.as_slice()) {
|
||||
if any_types || is_default_impl || should_inline(ast_method.attrs[]) {
|
||||
encode_inlined_item(ecx, rbml_w, IIImplItemRef(local_def(parent_id),
|
||||
ast_item_opt.unwrap()));
|
||||
}
|
||||
@ -909,7 +909,7 @@ fn encode_info_for_associated_type(ecx: &EncodeContext,
|
||||
match typedef_opt {
|
||||
None => {}
|
||||
Some(typedef) => {
|
||||
encode_attributes(rbml_w, typedef.attrs.as_slice());
|
||||
encode_attributes(rbml_w, typedef.attrs[]);
|
||||
encode_type(ecx, rbml_w, ty::node_id_to_type(ecx.tcx,
|
||||
typedef.id));
|
||||
}
|
||||
@ -1043,7 +1043,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
||||
encode_path(rbml_w, path);
|
||||
encode_visibility(rbml_w, vis);
|
||||
encode_stability(rbml_w, stab);
|
||||
encode_attributes(rbml_w, item.attrs.as_slice());
|
||||
encode_attributes(rbml_w, item.attrs[]);
|
||||
rbml_w.end_tag();
|
||||
}
|
||||
ast::ItemConst(_, _) => {
|
||||
@ -1069,8 +1069,8 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
||||
encode_bounds_and_type(rbml_w, ecx, &lookup_item_type(tcx, def_id));
|
||||
encode_name(rbml_w, item.ident.name);
|
||||
encode_path(rbml_w, path);
|
||||
encode_attributes(rbml_w, item.attrs.as_slice());
|
||||
if tps_len > 0u || should_inline(item.attrs.as_slice()) {
|
||||
encode_attributes(rbml_w, item.attrs[]);
|
||||
if tps_len > 0u || should_inline(item.attrs[]) {
|
||||
encode_inlined_item(ecx, rbml_w, IIItemRef(item));
|
||||
}
|
||||
if tps_len == 0 {
|
||||
@ -1086,7 +1086,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
||||
encode_info_for_mod(ecx,
|
||||
rbml_w,
|
||||
m,
|
||||
item.attrs.as_slice(),
|
||||
item.attrs[],
|
||||
item.id,
|
||||
path,
|
||||
item.ident,
|
||||
@ -1103,7 +1103,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
||||
// Encode all the items in this module.
|
||||
for foreign_item in fm.items.iter() {
|
||||
rbml_w.start_tag(tag_mod_child);
|
||||
rbml_w.wr_str(def_to_string(local_def(foreign_item.id)).as_slice());
|
||||
rbml_w.wr_str(def_to_string(local_def(foreign_item.id))[]);
|
||||
rbml_w.end_tag();
|
||||
}
|
||||
encode_visibility(rbml_w, vis);
|
||||
@ -1131,8 +1131,8 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
||||
encode_item_variances(rbml_w, ecx, item.id);
|
||||
encode_bounds_and_type(rbml_w, ecx, &lookup_item_type(tcx, def_id));
|
||||
encode_name(rbml_w, item.ident.name);
|
||||
encode_attributes(rbml_w, item.attrs.as_slice());
|
||||
encode_repr_attrs(rbml_w, ecx, item.attrs.as_slice());
|
||||
encode_attributes(rbml_w, item.attrs[]);
|
||||
encode_repr_attrs(rbml_w, ecx, item.attrs[]);
|
||||
for v in (*enum_definition).variants.iter() {
|
||||
encode_variant_id(rbml_w, local_def(v.node.id));
|
||||
}
|
||||
@ -1149,7 +1149,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
||||
encode_enum_variant_info(ecx,
|
||||
rbml_w,
|
||||
item.id,
|
||||
(*enum_definition).variants.as_slice(),
|
||||
(*enum_definition).variants[],
|
||||
index);
|
||||
}
|
||||
ast::ItemStruct(ref struct_def, _) => {
|
||||
@ -1161,7 +1161,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
||||
class itself */
|
||||
let idx = encode_info_for_struct(ecx,
|
||||
rbml_w,
|
||||
fields.as_slice(),
|
||||
fields[],
|
||||
index);
|
||||
|
||||
/* Index the class*/
|
||||
@ -1175,16 +1175,16 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
||||
|
||||
encode_item_variances(rbml_w, ecx, item.id);
|
||||
encode_name(rbml_w, item.ident.name);
|
||||
encode_attributes(rbml_w, item.attrs.as_slice());
|
||||
encode_attributes(rbml_w, item.attrs[]);
|
||||
encode_path(rbml_w, path.clone());
|
||||
encode_stability(rbml_w, stab);
|
||||
encode_visibility(rbml_w, vis);
|
||||
encode_repr_attrs(rbml_w, ecx, item.attrs.as_slice());
|
||||
encode_repr_attrs(rbml_w, ecx, item.attrs[]);
|
||||
|
||||
/* Encode def_ids for each field and method
|
||||
for methods, write all the stuff get_trait_method
|
||||
needs to know*/
|
||||
encode_struct_fields(rbml_w, fields.as_slice(), def_id);
|
||||
encode_struct_fields(rbml_w, fields[], def_id);
|
||||
|
||||
encode_inlined_item(ecx, rbml_w, IIItemRef(item));
|
||||
|
||||
@ -1216,7 +1216,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
||||
encode_family(rbml_w, 'i');
|
||||
encode_bounds_and_type(rbml_w, ecx, &lookup_item_type(tcx, def_id));
|
||||
encode_name(rbml_w, item.ident.name);
|
||||
encode_attributes(rbml_w, item.attrs.as_slice());
|
||||
encode_attributes(rbml_w, item.attrs[]);
|
||||
encode_unsafety(rbml_w, unsafety);
|
||||
match ty.node {
|
||||
ast::TyPath(ref path, _) if path.segments
|
||||
@ -1319,7 +1319,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
||||
encode_generics(rbml_w, ecx, &trait_def.generics, tag_item_generics);
|
||||
encode_trait_ref(rbml_w, ecx, &*trait_def.trait_ref, tag_item_trait_ref);
|
||||
encode_name(rbml_w, item.ident.name);
|
||||
encode_attributes(rbml_w, item.attrs.as_slice());
|
||||
encode_attributes(rbml_w, item.attrs[]);
|
||||
encode_visibility(rbml_w, vis);
|
||||
encode_stability(rbml_w, stab);
|
||||
for &method_def_id in ty::trait_item_def_ids(tcx, def_id).iter() {
|
||||
@ -1337,7 +1337,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
||||
rbml_w.end_tag();
|
||||
|
||||
rbml_w.start_tag(tag_mod_child);
|
||||
rbml_w.wr_str(def_to_string(method_def_id.def_id()).as_slice());
|
||||
rbml_w.wr_str(def_to_string(method_def_id.def_id())[]);
|
||||
rbml_w.end_tag();
|
||||
}
|
||||
encode_path(rbml_w, path.clone());
|
||||
@ -1422,14 +1422,14 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
||||
};
|
||||
match trait_item {
|
||||
&ast::RequiredMethod(ref m) => {
|
||||
encode_attributes(rbml_w, m.attrs.as_slice());
|
||||
encode_attributes(rbml_w, m.attrs[]);
|
||||
encode_trait_item(rbml_w);
|
||||
encode_item_sort(rbml_w, 'r');
|
||||
encode_method_argument_names(rbml_w, &*m.decl);
|
||||
}
|
||||
|
||||
&ast::ProvidedMethod(ref m) => {
|
||||
encode_attributes(rbml_w, m.attrs.as_slice());
|
||||
encode_attributes(rbml_w, m.attrs[]);
|
||||
encode_trait_item(rbml_w);
|
||||
encode_item_sort(rbml_w, 'p');
|
||||
encode_inlined_item(ecx, rbml_w, IITraitItemRef(def_id, trait_item));
|
||||
@ -1438,7 +1438,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
||||
|
||||
&ast::TypeTraitItem(ref associated_type) => {
|
||||
encode_attributes(rbml_w,
|
||||
associated_type.attrs.as_slice());
|
||||
associated_type.attrs[]);
|
||||
encode_item_sort(rbml_w, 't');
|
||||
}
|
||||
}
|
||||
@ -1802,7 +1802,7 @@ fn encode_macro_def(ecx: &EncodeContext,
|
||||
let def = ecx.tcx.sess.codemap().span_to_snippet(*span)
|
||||
.expect("Unable to find source for macro");
|
||||
rbml_w.start_tag(tag_macro_def);
|
||||
rbml_w.wr_str(def.as_slice());
|
||||
rbml_w.wr_str(def[]);
|
||||
rbml_w.end_tag();
|
||||
}
|
||||
|
||||
@ -1849,7 +1849,7 @@ fn encode_struct_field_attrs(rbml_w: &mut Encoder, krate: &ast::Crate) {
|
||||
fn visit_struct_field(&mut self, field: &ast::StructField) {
|
||||
self.rbml_w.start_tag(tag_struct_field);
|
||||
self.rbml_w.wr_tagged_u32(tag_struct_field_id, field.node.id);
|
||||
encode_attributes(self.rbml_w, field.node.attrs.as_slice());
|
||||
encode_attributes(self.rbml_w, field.node.attrs[]);
|
||||
self.rbml_w.end_tag();
|
||||
}
|
||||
}
|
||||
@ -1921,13 +1921,13 @@ fn encode_misc_info(ecx: &EncodeContext,
|
||||
rbml_w.start_tag(tag_misc_info_crate_items);
|
||||
for item in krate.module.items.iter() {
|
||||
rbml_w.start_tag(tag_mod_child);
|
||||
rbml_w.wr_str(def_to_string(local_def(item.id)).as_slice());
|
||||
rbml_w.wr_str(def_to_string(local_def(item.id))[]);
|
||||
rbml_w.end_tag();
|
||||
|
||||
each_auxiliary_node_id(&**item, |auxiliary_node_id| {
|
||||
rbml_w.start_tag(tag_mod_child);
|
||||
rbml_w.wr_str(def_to_string(local_def(
|
||||
auxiliary_node_id)).as_slice());
|
||||
auxiliary_node_id))[]);
|
||||
rbml_w.end_tag();
|
||||
true
|
||||
});
|
||||
@ -2096,17 +2096,17 @@ fn encode_metadata_inner(wr: &mut SeekableMemWriter,
|
||||
|
||||
let mut rbml_w = writer::Encoder::new(wr);
|
||||
|
||||
encode_crate_name(&mut rbml_w, ecx.link_meta.crate_name.as_slice());
|
||||
encode_crate_name(&mut rbml_w, ecx.link_meta.crate_name[]);
|
||||
encode_crate_triple(&mut rbml_w,
|
||||
tcx.sess
|
||||
.opts
|
||||
.target_triple
|
||||
.as_slice());
|
||||
[]);
|
||||
encode_hash(&mut rbml_w, &ecx.link_meta.crate_hash);
|
||||
encode_dylib_dependency_formats(&mut rbml_w, &ecx);
|
||||
|
||||
let mut i = rbml_w.writer.tell().unwrap();
|
||||
encode_attributes(&mut rbml_w, krate.attrs.as_slice());
|
||||
encode_attributes(&mut rbml_w, krate.attrs[]);
|
||||
stats.attr_bytes = rbml_w.writer.tell().unwrap() - i;
|
||||
|
||||
i = rbml_w.writer.tell().unwrap();
|
||||
|
@ -316,14 +316,14 @@ impl<'a> Context<'a> {
|
||||
&Some(ref r) => format!("{} which `{}` depends on",
|
||||
message, r.ident)
|
||||
};
|
||||
self.sess.span_err(self.span, message.as_slice());
|
||||
self.sess.span_err(self.span, message[]);
|
||||
|
||||
if self.rejected_via_triple.len() > 0 {
|
||||
let mismatches = self.rejected_via_triple.iter();
|
||||
for (i, &CrateMismatch{ ref path, ref got }) in mismatches.enumerate() {
|
||||
self.sess.fileline_note(self.span,
|
||||
format!("crate `{}`, path #{}, triple {}: {}",
|
||||
self.ident, i+1, got, path.display()).as_slice());
|
||||
self.ident, i+1, got, path.display())[]);
|
||||
}
|
||||
}
|
||||
if self.rejected_via_hash.len() > 0 {
|
||||
@ -333,7 +333,7 @@ impl<'a> Context<'a> {
|
||||
for (i, &CrateMismatch{ ref path, .. }) in mismatches.enumerate() {
|
||||
self.sess.fileline_note(self.span,
|
||||
format!("crate `{}` path {}{}: {}",
|
||||
self.ident, "#", i+1, path.display()).as_slice());
|
||||
self.ident, "#", i+1, path.display())[]);
|
||||
}
|
||||
match self.root {
|
||||
&None => {}
|
||||
@ -341,7 +341,7 @@ impl<'a> Context<'a> {
|
||||
for (i, path) in r.paths().iter().enumerate() {
|
||||
self.sess.fileline_note(self.span,
|
||||
format!("crate `{}` path #{}: {}",
|
||||
r.ident, i+1, path.display()).as_slice());
|
||||
r.ident, i+1, path.display())[]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -387,7 +387,7 @@ impl<'a> Context<'a> {
|
||||
None => return FileDoesntMatch,
|
||||
Some(file) => file,
|
||||
};
|
||||
let (hash, rlib) = if file.starts_with(rlib_prefix.as_slice()) &&
|
||||
let (hash, rlib) = if file.starts_with(rlib_prefix[]) &&
|
||||
file.ends_with(".rlib") {
|
||||
(file.slice(rlib_prefix.len(), file.len() - ".rlib".len()),
|
||||
true)
|
||||
@ -448,26 +448,26 @@ impl<'a> Context<'a> {
|
||||
_ => {
|
||||
self.sess.span_err(self.span,
|
||||
format!("multiple matching crates for `{}`",
|
||||
self.crate_name).as_slice());
|
||||
self.crate_name)[]);
|
||||
self.sess.note("candidates:");
|
||||
for lib in libraries.iter() {
|
||||
match lib.dylib {
|
||||
Some(ref p) => {
|
||||
self.sess.note(format!("path: {}",
|
||||
p.display()).as_slice());
|
||||
p.display())[]);
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
match lib.rlib {
|
||||
Some(ref p) => {
|
||||
self.sess.note(format!("path: {}",
|
||||
p.display()).as_slice());
|
||||
p.display())[]);
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
let data = lib.metadata.as_slice();
|
||||
let name = decoder::get_crate_name(data);
|
||||
note_crate_name(self.sess.diagnostic(), name.as_slice());
|
||||
note_crate_name(self.sess.diagnostic(), name[]);
|
||||
}
|
||||
None
|
||||
}
|
||||
@ -521,11 +521,11 @@ impl<'a> Context<'a> {
|
||||
format!("multiple {} candidates for `{}` \
|
||||
found",
|
||||
flavor,
|
||||
self.crate_name).as_slice());
|
||||
self.crate_name)[]);
|
||||
self.sess.span_note(self.span,
|
||||
format!(r"candidate #1: {}",
|
||||
ret.as_ref().unwrap()
|
||||
.display()).as_slice());
|
||||
.display())[]);
|
||||
error = 1;
|
||||
ret = None;
|
||||
}
|
||||
@ -533,7 +533,7 @@ impl<'a> Context<'a> {
|
||||
error += 1;
|
||||
self.sess.span_note(self.span,
|
||||
format!(r"candidate #{}: {}", error,
|
||||
lib.display()).as_slice());
|
||||
lib.display())[]);
|
||||
continue
|
||||
}
|
||||
*slot = Some(metadata);
|
||||
@ -608,17 +608,17 @@ impl<'a> Context<'a> {
|
||||
let mut rlibs = HashSet::new();
|
||||
let mut dylibs = HashSet::new();
|
||||
{
|
||||
let mut locs = locs.iter().map(|l| Path::new(l.as_slice())).filter(|loc| {
|
||||
let mut locs = locs.iter().map(|l| Path::new(l[])).filter(|loc| {
|
||||
if !loc.exists() {
|
||||
sess.err(format!("extern location for {} does not exist: {}",
|
||||
self.crate_name, loc.display()).as_slice());
|
||||
self.crate_name, loc.display())[]);
|
||||
return false;
|
||||
}
|
||||
let file = match loc.filename_str() {
|
||||
Some(file) => file,
|
||||
None => {
|
||||
sess.err(format!("extern location for {} is not a file: {}",
|
||||
self.crate_name, loc.display()).as_slice());
|
||||
self.crate_name, loc.display())[]);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
@ -626,12 +626,12 @@ impl<'a> Context<'a> {
|
||||
return true
|
||||
} else {
|
||||
let (ref prefix, ref suffix) = dylibname;
|
||||
if file.starts_with(prefix.as_slice()) && file.ends_with(suffix.as_slice()) {
|
||||
if file.starts_with(prefix[]) && file.ends_with(suffix[]) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
sess.err(format!("extern location for {} is of an unknown type: {}",
|
||||
self.crate_name, loc.display()).as_slice());
|
||||
self.crate_name, loc.display())[]);
|
||||
false
|
||||
});
|
||||
|
||||
@ -664,7 +664,7 @@ impl<'a> Context<'a> {
|
||||
}
|
||||
|
||||
pub fn note_crate_name(diag: &SpanHandler, name: &str) {
|
||||
diag.handler().note(format!("crate name: {}", name).as_slice());
|
||||
diag.handler().note(format!("crate name: {}", name)[]);
|
||||
}
|
||||
|
||||
impl ArchiveMetadata {
|
||||
|
@ -233,7 +233,7 @@ fn parse_trait_store(st: &mut PState, conv: conv_did) -> ty::TraitStore {
|
||||
'&' => ty::RegionTraitStore(parse_region(st, conv), parse_mutability(st)),
|
||||
c => {
|
||||
st.tcx.sess.bug(format!("parse_trait_store(): bad input '{}'",
|
||||
c).as_slice())
|
||||
c)[])
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -287,7 +287,7 @@ fn parse_bound_region(st: &mut PState, conv: conv_did) -> ty::BoundRegion {
|
||||
}
|
||||
'[' => {
|
||||
let def = parse_def(st, RegionParameter, |x,y| conv(x,y));
|
||||
let ident = token::str_to_ident(parse_str(st, ']').as_slice());
|
||||
let ident = token::str_to_ident(parse_str(st, ']')[]);
|
||||
ty::BrNamed(def, ident.name)
|
||||
}
|
||||
'f' => {
|
||||
@ -318,7 +318,7 @@ fn parse_region(st: &mut PState, conv: conv_did) -> ty::Region {
|
||||
assert_eq!(next(st), '|');
|
||||
let index = parse_uint(st);
|
||||
assert_eq!(next(st), '|');
|
||||
let nm = token::str_to_ident(parse_str(st, ']').as_slice());
|
||||
let nm = token::str_to_ident(parse_str(st, ']')[]);
|
||||
ty::ReEarlyBound(node_id, space, index, nm.name)
|
||||
}
|
||||
'f' => {
|
||||
@ -453,7 +453,11 @@ fn parse_ty<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) -> Ty<'tcx> {
|
||||
return ty::mk_closure(st.tcx, parse_closure_ty(st, |x,y| conv(x,y)));
|
||||
}
|
||||
'F' => {
|
||||
return ty::mk_bare_fn(st.tcx, parse_bare_fn_ty(st, |x,y| conv(x,y)));
|
||||
let def_id = parse_def(st, NominalType, |x,y| conv(x,y));
|
||||
return ty::mk_bare_fn(st.tcx, Some(def_id), parse_bare_fn_ty(st, |x,y| conv(x,y)));
|
||||
}
|
||||
'G' => {
|
||||
return ty::mk_bare_fn(st.tcx, None, parse_bare_fn_ty(st, |x,y| conv(x,y)));
|
||||
}
|
||||
'#' => {
|
||||
let pos = parse_hex(st);
|
||||
@ -560,7 +564,7 @@ fn parse_abi_set(st: &mut PState) -> abi::Abi {
|
||||
assert_eq!(next(st), '[');
|
||||
scan(st, |c| c == ']', |bytes| {
|
||||
let abi_str = str::from_utf8(bytes).unwrap();
|
||||
abi::lookup(abi_str.as_slice()).expect(abi_str)
|
||||
abi::lookup(abi_str[]).expect(abi_str)
|
||||
})
|
||||
}
|
||||
|
||||
@ -639,12 +643,12 @@ pub fn parse_def_id(buf: &[u8]) -> ast::DefId {
|
||||
let crate_part = buf[0u..colon_idx];
|
||||
let def_part = buf[colon_idx + 1u..len];
|
||||
|
||||
let crate_num = match str::from_utf8(crate_part).and_then(from_str::<uint>) {
|
||||
let crate_num = match str::from_utf8(crate_part).ok().and_then(|s| s.parse::<uint>()) {
|
||||
Some(cn) => cn as ast::CrateNum,
|
||||
None => panic!("internal error: parse_def_id: crate number expected, found {}",
|
||||
crate_part)
|
||||
};
|
||||
let def_num = match str::from_utf8(def_part).and_then(from_str::<uint>) {
|
||||
let def_num = match str::from_utf8(def_part).ok().and_then(|s| s.parse::<uint>()) {
|
||||
Some(dn) => dn as ast::NodeId,
|
||||
None => panic!("internal error: parse_def_id: id expected, found {}",
|
||||
def_part)
|
||||
|
@ -123,8 +123,13 @@ pub fn enc_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>, t: Ty<'t
|
||||
mywrite!(w, "f");
|
||||
enc_closure_ty(w, cx, &**f);
|
||||
}
|
||||
ty::ty_bare_fn(ref f) => {
|
||||
ty::ty_bare_fn(Some(def_id), ref f) => {
|
||||
mywrite!(w, "F");
|
||||
mywrite!(w, "{}|", (cx.ds)(def_id));
|
||||
enc_bare_fn_ty(w, cx, f);
|
||||
}
|
||||
ty::ty_bare_fn(None, ref f) => {
|
||||
mywrite!(w, "G");
|
||||
enc_bare_fn_ty(w, cx, f);
|
||||
}
|
||||
ty::ty_infer(_) => {
|
||||
|
@ -48,7 +48,7 @@ pub fn ast_ty_to_prim_ty<'tcx>(tcx: &ty::ctxt<'tcx>, ast_ty: &ast::Ty)
|
||||
None => {
|
||||
tcx.sess.span_bug(ast_ty.span,
|
||||
format!("unbound path {}",
|
||||
path.repr(tcx)).as_slice())
|
||||
path.repr(tcx))[])
|
||||
}
|
||||
Some(&d) => d
|
||||
};
|
||||
|
@ -132,7 +132,7 @@ pub fn decode_inlined_item<'tcx>(cdata: &cstore::crate_metadata,
|
||||
// Do an Option dance to use the path after it is moved below.
|
||||
let s = ast_map::path_to_string(ast_map::Values(path.iter()));
|
||||
path_as_str = Some(s);
|
||||
path_as_str.as_ref().map(|x| x.as_slice())
|
||||
path_as_str.as_ref().map(|x| x[])
|
||||
});
|
||||
let mut ast_dsr = reader::Decoder::new(ast_doc);
|
||||
let from_id_range = Decodable::decode(&mut ast_dsr).unwrap();
|
||||
@ -1007,14 +1007,21 @@ impl<'a, 'tcx> rbml_writer_helpers<'tcx> for Encoder<'a> {
|
||||
|
||||
self.emit_enum("AutoAdjustment", |this| {
|
||||
match *adj {
|
||||
ty::AdjustAddEnv(store) => {
|
||||
this.emit_enum_variant("AutoAddEnv", 0, 1, |this| {
|
||||
this.emit_enum_variant_arg(0, |this| store.encode(this))
|
||||
ty::AdjustAddEnv(def_id, store) => {
|
||||
this.emit_enum_variant("AdjustAddEnv", 0, 2, |this| {
|
||||
this.emit_enum_variant_arg(0, |this| def_id.encode(this));
|
||||
this.emit_enum_variant_arg(1, |this| store.encode(this))
|
||||
})
|
||||
}
|
||||
|
||||
ty::AdjustReifyFnPointer(def_id) => {
|
||||
this.emit_enum_variant("AdjustReifyFnPointer", 1, 2, |this| {
|
||||
this.emit_enum_variant_arg(0, |this| def_id.encode(this))
|
||||
})
|
||||
}
|
||||
|
||||
ty::AdjustDerefRef(ref auto_deref_ref) => {
|
||||
this.emit_enum_variant("AutoDerefRef", 1, 1, |this| {
|
||||
this.emit_enum_variant("AdjustDerefRef", 2, 2, |this| {
|
||||
this.emit_enum_variant_arg(0,
|
||||
|this| Ok(this.emit_auto_deref_ref(ecx, auto_deref_ref)))
|
||||
})
|
||||
@ -1648,12 +1655,20 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
|
||||
this.read_enum_variant(&variants, |this, i| {
|
||||
Ok(match i {
|
||||
0 => {
|
||||
let def_id: ast::DefId =
|
||||
this.read_def_id(dcx);
|
||||
let store: ty::TraitStore =
|
||||
this.read_enum_variant_arg(0, |this| Decodable::decode(this)).unwrap();
|
||||
|
||||
ty::AdjustAddEnv(store.tr(dcx))
|
||||
ty::AdjustAddEnv(def_id, store.tr(dcx))
|
||||
}
|
||||
1 => {
|
||||
let def_id: ast::DefId =
|
||||
this.read_def_id(dcx);
|
||||
|
||||
ty::AdjustReifyFnPointer(def_id)
|
||||
}
|
||||
2 => {
|
||||
let auto_deref_ref: ty::AutoDerefRef =
|
||||
this.read_enum_variant_arg(0,
|
||||
|this| Ok(this.read_auto_deref_ref(dcx))).unwrap();
|
||||
@ -1876,7 +1891,7 @@ fn decode_side_tables(dcx: &DecodeContext,
|
||||
None => {
|
||||
dcx.tcx.sess.bug(
|
||||
format!("unknown tag found in side tables: {:x}",
|
||||
tag).as_slice());
|
||||
tag)[]);
|
||||
}
|
||||
Some(value) => {
|
||||
let val_doc = entry_doc.get(c::tag_table_val as uint);
|
||||
@ -1961,7 +1976,7 @@ fn decode_side_tables(dcx: &DecodeContext,
|
||||
_ => {
|
||||
dcx.tcx.sess.bug(
|
||||
format!("unknown tag found in side tables: {:x}",
|
||||
tag).as_slice());
|
||||
tag)[]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -362,7 +362,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
|
||||
let mut cond_exit = discr_exit;
|
||||
for arm in arms.iter() {
|
||||
cond_exit = self.add_dummy_node(&[cond_exit]); // 2
|
||||
let pats_exit = self.pats_any(arm.pats.as_slice(),
|
||||
let pats_exit = self.pats_any(arm.pats[],
|
||||
cond_exit); // 3
|
||||
let guard_exit = self.opt_expr(&arm.guard,
|
||||
pats_exit); // 4
|
||||
@ -617,14 +617,14 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
|
||||
self.tcx.sess.span_bug(
|
||||
expr.span,
|
||||
format!("no loop scope for id {}",
|
||||
loop_id).as_slice());
|
||||
loop_id)[]);
|
||||
}
|
||||
|
||||
r => {
|
||||
self.tcx.sess.span_bug(
|
||||
expr.span,
|
||||
format!("bad entry `{}` in def_map for label",
|
||||
r).as_slice());
|
||||
r)[]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ fn replace_newline_with_backslash_l(s: String) -> String {
|
||||
}
|
||||
|
||||
impl<'a, 'ast> dot::Labeller<'a, Node<'a>, Edge<'a>> for LabelledCFG<'a, 'ast> {
|
||||
fn graph_id(&'a self) -> dot::Id<'a> { dot::Id::new(self.name.as_slice()).unwrap() }
|
||||
fn graph_id(&'a self) -> dot::Id<'a> { dot::Id::new(self.name[]).unwrap() }
|
||||
|
||||
fn node_id(&'a self, &(i,_): &Node<'a>) -> dot::Id<'a> {
|
||||
dot::Id::new(format!("N{}", i.node_id())).unwrap()
|
||||
@ -83,8 +83,7 @@ impl<'a, 'ast> dot::Labeller<'a, Node<'a>, Edge<'a>> for LabelledCFG<'a, 'ast> {
|
||||
let s = self.ast_map.node_to_string(node_id);
|
||||
// left-aligns the lines
|
||||
let s = replace_newline_with_backslash_l(s);
|
||||
label.push_str(format!("exiting scope_{} {}", i,
|
||||
s.as_slice()).as_slice());
|
||||
label.push_str(format!("exiting scope_{} {}", i, s[])[]);
|
||||
}
|
||||
dot::EscStr(label.into_cow())
|
||||
}
|
||||
|
@ -127,7 +127,11 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &ast::Expr) -> bool {
|
||||
ast::ExprCast(ref from, _) => {
|
||||
let toty = ty::expr_ty(v.tcx, e);
|
||||
let fromty = ty::expr_ty(v.tcx, &**from);
|
||||
if !ty::type_is_numeric(toty) && !ty::type_is_unsafe_ptr(toty) {
|
||||
let is_legal_cast =
|
||||
ty::type_is_numeric(toty) ||
|
||||
ty::type_is_unsafe_ptr(toty) ||
|
||||
(ty::type_is_bare_fn(toty) && ty::type_is_bare_fn_item(fromty));
|
||||
if !is_legal_cast {
|
||||
span_err!(v.tcx.sess, e.span, E0012,
|
||||
"can not cast to `{}` in a constant expression",
|
||||
ppaux::ty_to_string(v.tcx, toty));
|
||||
|
@ -74,13 +74,11 @@ impl<'a> CheckLoopVisitor<'a> {
|
||||
Loop => {}
|
||||
Closure => {
|
||||
self.sess.span_err(span,
|
||||
format!("`{}` inside of a closure",
|
||||
name).as_slice());
|
||||
format!("`{}` inside of a closure", name)[]);
|
||||
}
|
||||
Normal => {
|
||||
self.sess.span_err(span,
|
||||
format!("`{}` outside of loop",
|
||||
name).as_slice());
|
||||
format!("`{}` outside of loop", name)[]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ fn check_expr(cx: &mut MatchCheckCtxt, ex: &ast::Expr) {
|
||||
// First, check legality of move bindings.
|
||||
check_legality_of_move_bindings(cx,
|
||||
arm.guard.is_some(),
|
||||
arm.pats.as_slice());
|
||||
arm.pats[]);
|
||||
|
||||
// Second, if there is a guard on each arm, make sure it isn't
|
||||
// assigning or borrowing anything mutably.
|
||||
@ -199,7 +199,7 @@ fn check_expr(cx: &mut MatchCheckCtxt, ex: &ast::Expr) {
|
||||
}
|
||||
|
||||
// Fourth, check for unreachable arms.
|
||||
check_arms(cx, inlined_arms.as_slice(), source);
|
||||
check_arms(cx, inlined_arms[], source);
|
||||
|
||||
// Finally, check if the whole match expression is exhaustive.
|
||||
// Check for empty enum, because is_useful only works on inhabited types.
|
||||
@ -231,7 +231,7 @@ fn check_expr(cx: &mut MatchCheckCtxt, ex: &ast::Expr) {
|
||||
pat.span,
|
||||
format!("refutable pattern in `for` loop binding: \
|
||||
`{}` not covered",
|
||||
pat_to_string(uncovered_pat)).as_slice());
|
||||
pat_to_string(uncovered_pat))[]);
|
||||
});
|
||||
|
||||
// Check legality of move bindings.
|
||||
@ -304,7 +304,7 @@ fn check_arms(cx: &MatchCheckCtxt,
|
||||
for pat in pats.iter() {
|
||||
let v = vec![&**pat];
|
||||
|
||||
match is_useful(cx, &seen, v.as_slice(), LeaveOutWitness) {
|
||||
match is_useful(cx, &seen, v[], LeaveOutWitness) {
|
||||
NotUseful => {
|
||||
match source {
|
||||
ast::MatchSource::IfLetDesugar { .. } => {
|
||||
@ -356,7 +356,7 @@ fn raw_pat<'a>(p: &'a Pat) -> &'a Pat {
|
||||
fn check_exhaustive(cx: &MatchCheckCtxt, sp: Span, matrix: &Matrix) {
|
||||
match is_useful(cx, matrix, &[DUMMY_WILD_PAT], ConstructWitness) {
|
||||
UsefulWithWitness(pats) => {
|
||||
let witness = match pats.as_slice() {
|
||||
let witness = match pats[] {
|
||||
[ref witness] => &**witness,
|
||||
[] => DUMMY_WILD_PAT,
|
||||
_ => unreachable!()
|
||||
@ -610,7 +610,7 @@ fn is_useful(cx: &MatchCheckCtxt,
|
||||
UsefulWithWitness(pats) => UsefulWithWitness({
|
||||
let arity = constructor_arity(cx, &c, left_ty);
|
||||
let mut result = {
|
||||
let pat_slice = pats.as_slice();
|
||||
let pat_slice = pats[];
|
||||
let subpats = Vec::from_fn(arity, |i| {
|
||||
pat_slice.get(i).map_or(DUMMY_WILD_PAT, |p| &**p)
|
||||
});
|
||||
@ -657,10 +657,10 @@ fn is_useful_specialized(cx: &MatchCheckCtxt, &Matrix(ref m): &Matrix,
|
||||
witness: WitnessPreference) -> Usefulness {
|
||||
let arity = constructor_arity(cx, &ctor, lty);
|
||||
let matrix = Matrix(m.iter().filter_map(|r| {
|
||||
specialize(cx, r.as_slice(), &ctor, 0u, arity)
|
||||
specialize(cx, r[], &ctor, 0u, arity)
|
||||
}).collect());
|
||||
match specialize(cx, v, &ctor, 0u, arity) {
|
||||
Some(v) => is_useful(cx, &matrix, v.as_slice(), witness),
|
||||
Some(v) => is_useful(cx, &matrix, v[], witness),
|
||||
None => NotUseful
|
||||
}
|
||||
}
|
||||
@ -1047,7 +1047,7 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt,
|
||||
format!("binding pattern {} is not an \
|
||||
identifier: {}",
|
||||
p.id,
|
||||
p.node).as_slice());
|
||||
p.node)[]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ impl<'a, 'tcx> CheckStaticVisitor<'a, 'tcx> {
|
||||
};
|
||||
|
||||
self.tcx.sess.span_err(e.span, format!("mutable statics are not allowed \
|
||||
to have {}", suffix).as_slice());
|
||||
to have {}", suffix)[]);
|
||||
}
|
||||
|
||||
fn check_static_type(&self, e: &ast::Expr) {
|
||||
@ -168,7 +168,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckStaticVisitor<'a, 'tcx> {
|
||||
ty::ty_enum(did, _) if ty::has_dtor(self.tcx, did) => {
|
||||
self.tcx.sess.span_err(e.span,
|
||||
format!("{} are not allowed to have \
|
||||
destructors", self.msg()).as_slice())
|
||||
destructors", self.msg())[])
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
@ -232,7 +232,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckStaticVisitor<'a, 'tcx> {
|
||||
let msg = "constants cannot refer to other statics, \
|
||||
insert an intermediate constant \
|
||||
instead";
|
||||
self.tcx.sess.span_err(e.span, msg.as_slice());
|
||||
self.tcx.sess.span_err(e.span, msg[]);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ impl<'a, 'ast, 'v> Visitor<'v> for CheckItemRecursionVisitor<'a, 'ast> {
|
||||
_ => {
|
||||
self.sess.span_err(e.span,
|
||||
format!("expected item, found {}",
|
||||
self.ast_map.node_to_string(def_id.node)).as_slice());
|
||||
self.ast_map.node_to_string(def_id.node))[]);
|
||||
return;
|
||||
},
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ fn lookup_variant_by_id<'a>(tcx: &'a ty::ctxt,
|
||||
None => None,
|
||||
Some(ast_map::NodeItem(it)) => match it.node {
|
||||
ast::ItemEnum(ast::EnumDef { ref variants }, _) => {
|
||||
variant_expr(variants.as_slice(), variant_def.node)
|
||||
variant_expr(variants[], variant_def.node)
|
||||
}
|
||||
_ => None
|
||||
},
|
||||
@ -138,7 +138,7 @@ fn lookup_variant_by_id<'a>(tcx: &'a ty::ctxt,
|
||||
// NOTE this doesn't do the right thing, it compares inlined
|
||||
// NodeId's to the original variant_def's NodeId, but they
|
||||
// come from different crates, so they will likely never match.
|
||||
variant_expr(variants.as_slice(), variant_def.node).map(|e| e.id)
|
||||
variant_expr(variants[], variant_def.node).map(|e| e.id)
|
||||
}
|
||||
_ => None
|
||||
},
|
||||
@ -364,7 +364,7 @@ pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr) -> P<ast::Pat> {
|
||||
pub fn eval_const_expr(tcx: &ty::ctxt, e: &Expr) -> const_val {
|
||||
match eval_const_expr_partial(tcx, e) {
|
||||
Ok(r) => r,
|
||||
Err(s) => tcx.sess.span_fatal(e.span, s.as_slice())
|
||||
Err(s) => tcx.sess.span_fatal(e.span, s[])
|
||||
}
|
||||
}
|
||||
|
||||
@ -603,7 +603,7 @@ pub fn lit_to_const(lit: &ast::Lit) -> const_val {
|
||||
ast::LitInt(n, ast::UnsignedIntLit(_)) => const_uint(n),
|
||||
ast::LitFloat(ref n, _) |
|
||||
ast::LitFloatUnsuffixed(ref n) => {
|
||||
const_float(from_str::<f64>(n.get()).unwrap() as f64)
|
||||
const_float(n.get().parse::<f64>().unwrap() as f64)
|
||||
}
|
||||
ast::LitBool(b) => const_bool(b)
|
||||
}
|
||||
|
@ -311,7 +311,7 @@ impl<'a, 'tcx, O:DataFlowOperator> DataFlowContext<'a, 'tcx, O> {
|
||||
let mut t = on_entry.to_vec();
|
||||
self.apply_gen_kill(cfgidx, t.as_mut_slice());
|
||||
temp_bits = t;
|
||||
temp_bits.as_slice()
|
||||
temp_bits[]
|
||||
}
|
||||
};
|
||||
debug!("{} each_bit_for_node({}, cfgidx={}) bits={}",
|
||||
@ -420,7 +420,7 @@ impl<'a, 'tcx, O:DataFlowOperator> DataFlowContext<'a, 'tcx, O> {
|
||||
let bits = self.kills.slice_mut(start, end);
|
||||
debug!("{} add_kills_from_flow_exits flow_exit={} bits={} [before]",
|
||||
self.analysis_name, flow_exit, mut_bits_to_string(bits));
|
||||
bits.clone_from_slice(orig_kills.as_slice());
|
||||
bits.clone_from_slice(orig_kills[]);
|
||||
debug!("{} add_kills_from_flow_exits flow_exit={} bits={} [after]",
|
||||
self.analysis_name, flow_exit, mut_bits_to_string(bits));
|
||||
}
|
||||
@ -553,7 +553,7 @@ fn bits_to_string(words: &[uint]) -> String {
|
||||
let mut v = word;
|
||||
for _ in range(0u, uint::BYTES) {
|
||||
result.push(sep);
|
||||
result.push_str(format!("{:02x}", v & 0xFF).as_slice());
|
||||
result.push_str(format!("{:02x}", v & 0xFF)[]);
|
||||
v >>= 8;
|
||||
sep = '-';
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ use syntax::ast_util::local_def;
|
||||
|
||||
use std::cell::RefCell;
|
||||
|
||||
#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
|
||||
#[deriving(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
|
||||
pub enum Def {
|
||||
DefFn(ast::DefId, bool /* is_ctor */),
|
||||
DefStaticMethod(/* method */ ast::DefId, MethodProvenance),
|
||||
@ -73,13 +73,13 @@ pub struct Export {
|
||||
pub def_id: ast::DefId, // The definition of the target.
|
||||
}
|
||||
|
||||
#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
|
||||
#[deriving(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
|
||||
pub enum MethodProvenance {
|
||||
FromTrait(ast::DefId),
|
||||
FromImpl(ast::DefId),
|
||||
}
|
||||
|
||||
#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
|
||||
#[deriving(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
|
||||
pub enum TyParamProvenance {
|
||||
FromSelf(ast::DefId),
|
||||
FromParam(ast::DefId),
|
||||
|
@ -118,7 +118,7 @@ fn calculate_type(sess: &session::Session,
|
||||
let src = sess.cstore.get_used_crate_source(cnum).unwrap();
|
||||
if src.rlib.is_some() { return }
|
||||
sess.err(format!("dependency `{}` not found in rlib format",
|
||||
data.name).as_slice());
|
||||
data.name)[]);
|
||||
});
|
||||
return Vec::new();
|
||||
}
|
||||
@ -197,7 +197,7 @@ fn calculate_type(sess: &session::Session,
|
||||
match kind {
|
||||
cstore::RequireStatic => "rlib",
|
||||
cstore::RequireDynamic => "dylib",
|
||||
}).as_slice());
|
||||
})[]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -222,7 +222,7 @@ fn add_library(sess: &session::Session,
|
||||
let data = sess.cstore.get_crate_data(cnum);
|
||||
sess.err(format!("cannot satisfy dependencies so `{}` only \
|
||||
shows up once",
|
||||
data.name).as_slice());
|
||||
data.name)[]);
|
||||
sess.help("having upstream crates all available in one format \
|
||||
will likely make this go away");
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ enum UnsafeContext {
|
||||
|
||||
fn type_is_unsafe_function(ty: Ty) -> bool {
|
||||
match ty.sty {
|
||||
ty::ty_bare_fn(ref f) => f.unsafety == ast::Unsafety::Unsafe,
|
||||
ty::ty_bare_fn(_, ref f) => f.unsafety == ast::Unsafety::Unsafe,
|
||||
ty::ty_closure(ref f) => f.unsafety == ast::Unsafety::Unsafe,
|
||||
_ => false,
|
||||
}
|
||||
|
@ -678,7 +678,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
|
||||
self.tcx().sess.span_bug(
|
||||
callee.span,
|
||||
format!("unexpected callee type {}",
|
||||
callee_ty.repr(self.tcx())).as_slice())
|
||||
callee_ty.repr(self.tcx()))[])
|
||||
}
|
||||
};
|
||||
match overloaded_call_type {
|
||||
@ -824,10 +824,12 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
|
||||
None => { }
|
||||
Some(adjustment) => {
|
||||
match *adjustment {
|
||||
ty::AdjustAddEnv(..) => {
|
||||
// Creating a closure consumes the input and stores it
|
||||
// into the resulting rvalue.
|
||||
debug!("walk_adjustment(AutoAddEnv)");
|
||||
ty::AdjustAddEnv(..) |
|
||||
ty::AdjustReifyFnPointer(..) => {
|
||||
// Creating a closure/fn-pointer consumes the
|
||||
// input and stores it into the resulting
|
||||
// rvalue.
|
||||
debug!("walk_adjustment(AutoAddEnv|AdjustReifyFnPointer)");
|
||||
let cmt_unadjusted =
|
||||
return_if_err!(self.mc.cat_expr_unadjusted(expr));
|
||||
self.delegate_consume(expr.id, expr.span, cmt_unadjusted);
|
||||
@ -869,7 +871,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
|
||||
ty::ty_rptr(r, ref m) => (m.mutbl, r),
|
||||
_ => self.tcx().sess.span_bug(expr.span,
|
||||
format!("bad overloaded deref type {}",
|
||||
method_ty.repr(self.tcx())).as_slice())
|
||||
method_ty.repr(self.tcx()))[])
|
||||
};
|
||||
let bk = ty::BorrowKind::from_mutbl(m);
|
||||
self.delegate.borrow(expr.id, expr.span, cmt,
|
||||
@ -1186,7 +1188,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
|
||||
// pattern.
|
||||
|
||||
let msg = format!("Pattern has unexpected type: {}", def);
|
||||
tcx.sess.span_bug(pat.span, msg.as_slice())
|
||||
tcx.sess.span_bug(pat.span, msg[])
|
||||
}
|
||||
|
||||
Some(def) => {
|
||||
@ -1195,7 +1197,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
|
||||
// should not resolve.
|
||||
|
||||
let msg = format!("Pattern has unexpected def: {}", def);
|
||||
tcx.sess.span_bug(pat.span, msg.as_slice())
|
||||
tcx.sess.span_bug(pat.span, msg[])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ pub fn simplify_type(tcx: &ty::ctxt,
|
||||
ty::ty_closure(ref f) => {
|
||||
Some(FunctionSimplifiedType(f.sig.0.inputs.len()))
|
||||
}
|
||||
ty::ty_bare_fn(ref f) => {
|
||||
ty::ty_bare_fn(_, ref f) => {
|
||||
Some(FunctionSimplifiedType(f.sig.0.inputs.len()))
|
||||
}
|
||||
ty::ty_param(_) => {
|
||||
|
@ -84,10 +84,14 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
||||
let Coerce(ref v) = *self; v
|
||||
}
|
||||
|
||||
fn tcx(&self) -> &ty::ctxt<'tcx> {
|
||||
self.get_ref().infcx.tcx
|
||||
}
|
||||
|
||||
pub fn tys(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> CoerceResult<'tcx> {
|
||||
debug!("Coerce.tys({} => {})",
|
||||
a.repr(self.get_ref().infcx.tcx),
|
||||
b.repr(self.get_ref().infcx.tcx));
|
||||
a.repr(self.tcx()),
|
||||
b.repr(self.tcx()));
|
||||
|
||||
// Consider coercing the subtype to a DST
|
||||
let unsize = self.unpack_actual_value(a, |a| {
|
||||
@ -170,13 +174,11 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
||||
|
||||
self.unpack_actual_value(a, |a| {
|
||||
match a.sty {
|
||||
ty::ty_bare_fn(ref a_f) => {
|
||||
// Bare functions are coercible to any closure type.
|
||||
//
|
||||
// FIXME(#3320) this should go away and be
|
||||
// replaced with proper inference, got a patch
|
||||
// underway - ndm
|
||||
self.coerce_from_bare_fn(a, a_f, b)
|
||||
ty::ty_bare_fn(Some(a_def_id), ref a_f) => {
|
||||
// Function items are coercible to any closure
|
||||
// type; function pointers are not (that would
|
||||
// require double indirection).
|
||||
self.coerce_from_fn_item(a, a_def_id, a_f, b)
|
||||
}
|
||||
_ => {
|
||||
// Otherwise, just use subtyping rules.
|
||||
@ -206,8 +208,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
||||
mutbl_b: ast::Mutability)
|
||||
-> CoerceResult<'tcx> {
|
||||
debug!("coerce_borrowed_pointer(a={}, b={})",
|
||||
a.repr(self.get_ref().infcx.tcx),
|
||||
b.repr(self.get_ref().infcx.tcx));
|
||||
a.repr(self.tcx()),
|
||||
b.repr(self.tcx()));
|
||||
|
||||
// If we have a parameter of type `&M T_a` and the value
|
||||
// provided is `expr`, we will be adding an implicit borrow,
|
||||
@ -227,7 +229,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
||||
}
|
||||
};
|
||||
|
||||
let a_borrowed = ty::mk_rptr(self.get_ref().infcx.tcx,
|
||||
let a_borrowed = ty::mk_rptr(self.tcx(),
|
||||
r_borrow,
|
||||
mt {ty: inner_ty, mutbl: mutbl_b});
|
||||
try!(sub.tys(a_borrowed, b));
|
||||
@ -247,8 +249,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
||||
b: Ty<'tcx>)
|
||||
-> CoerceResult<'tcx> {
|
||||
debug!("coerce_unsized(a={}, b={})",
|
||||
a.repr(self.get_ref().infcx.tcx),
|
||||
b.repr(self.get_ref().infcx.tcx));
|
||||
a.repr(self.tcx()),
|
||||
b.repr(self.tcx()));
|
||||
|
||||
// Note, we want to avoid unnecessary unsizing. We don't want to coerce to
|
||||
// a DST unless we have to. This currently comes out in the wash since
|
||||
@ -268,7 +270,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
||||
|
||||
let coercion = Coercion(self.get_ref().trace.clone());
|
||||
let r_borrow = self.get_ref().infcx.next_region_var(coercion);
|
||||
let ty = ty::mk_rptr(self.get_ref().infcx.tcx,
|
||||
let ty = ty::mk_rptr(self.tcx(),
|
||||
r_borrow,
|
||||
ty::mt{ty: ty, mutbl: mt_b.mutbl});
|
||||
try!(self.get_ref().infcx.try(|_| sub.tys(ty, b)));
|
||||
@ -292,7 +294,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
||||
return Err(ty::terr_mutability);
|
||||
}
|
||||
|
||||
let ty = ty::mk_ptr(self.get_ref().infcx.tcx,
|
||||
let ty = ty::mk_ptr(self.tcx(),
|
||||
ty::mt{ty: ty, mutbl: mt_b.mutbl});
|
||||
try!(self.get_ref().infcx.try(|_| sub.tys(ty, b)));
|
||||
debug!("Success, coerced with AutoDerefRef(1, \
|
||||
@ -311,7 +313,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
||||
self.unpack_actual_value(t_a, |a| {
|
||||
match self.unsize_ty(t_a, a, t_b) {
|
||||
Some((ty, kind)) => {
|
||||
let ty = ty::mk_uniq(self.get_ref().infcx.tcx, ty);
|
||||
let ty = ty::mk_uniq(self.tcx(), ty);
|
||||
try!(self.get_ref().infcx.try(|_| sub.tys(ty, b)));
|
||||
debug!("Success, coerced with AutoDerefRef(1, \
|
||||
AutoUnsizeUniq({}))", kind);
|
||||
@ -336,9 +338,9 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
||||
a: Ty<'tcx>,
|
||||
ty_b: Ty<'tcx>)
|
||||
-> Option<(Ty<'tcx>, ty::UnsizeKind<'tcx>)> {
|
||||
debug!("unsize_ty(a={}, ty_b={})", a, ty_b.repr(self.get_ref().infcx.tcx));
|
||||
debug!("unsize_ty(a={}, ty_b={})", a, ty_b.repr(self.tcx()));
|
||||
|
||||
let tcx = self.get_ref().infcx.tcx;
|
||||
let tcx = self.tcx();
|
||||
|
||||
self.unpack_actual_value(ty_b, |b|
|
||||
match (&a.sty, &b.sty) {
|
||||
@ -412,7 +414,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
||||
b: Ty<'tcx>,
|
||||
b_mutbl: ast::Mutability) -> CoerceResult<'tcx>
|
||||
{
|
||||
let tcx = self.get_ref().infcx.tcx;
|
||||
let tcx = self.tcx();
|
||||
|
||||
debug!("coerce_borrowed_object(a={}, b={}, b_mutbl={})",
|
||||
a.repr(tcx),
|
||||
@ -431,7 +433,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
||||
b: Ty<'tcx>,
|
||||
b_mutbl: ast::Mutability) -> CoerceResult<'tcx>
|
||||
{
|
||||
let tcx = self.get_ref().infcx.tcx;
|
||||
let tcx = self.tcx();
|
||||
|
||||
debug!("coerce_unsafe_object(a={}, b={}, b_mutbl={})",
|
||||
a.repr(tcx),
|
||||
@ -451,7 +453,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
||||
F: FnOnce(Ty<'tcx>) -> Ty<'tcx>,
|
||||
G: FnOnce() -> ty::AutoRef<'tcx>,
|
||||
{
|
||||
let tcx = self.get_ref().infcx.tcx;
|
||||
let tcx = self.tcx();
|
||||
|
||||
match a.sty {
|
||||
ty::ty_rptr(_, ty::mt{ty, mutbl}) => match ty.sty {
|
||||
@ -480,12 +482,12 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
||||
b: Ty<'tcx>)
|
||||
-> CoerceResult<'tcx> {
|
||||
debug!("coerce_borrowed_fn(a={}, b={})",
|
||||
a.repr(self.get_ref().infcx.tcx),
|
||||
b.repr(self.get_ref().infcx.tcx));
|
||||
a.repr(self.tcx()),
|
||||
b.repr(self.tcx()));
|
||||
|
||||
match a.sty {
|
||||
ty::ty_bare_fn(ref f) => {
|
||||
self.coerce_from_bare_fn(a, f, b)
|
||||
ty::ty_bare_fn(Some(a_def_id), ref f) => {
|
||||
self.coerce_from_fn_item(a, a_def_id, f, b)
|
||||
}
|
||||
_ => {
|
||||
self.subtype(a, b)
|
||||
@ -493,32 +495,46 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Attempts to coerce from a bare Rust function (`extern "Rust" fn`) into a closure or a
|
||||
/// `proc`.
|
||||
fn coerce_from_bare_fn(&self, a: Ty<'tcx>, fn_ty_a: &ty::BareFnTy<'tcx>, b: Ty<'tcx>)
|
||||
fn coerce_from_fn_item(&self,
|
||||
a: Ty<'tcx>,
|
||||
fn_def_id_a: ast::DefId,
|
||||
fn_ty_a: &ty::BareFnTy<'tcx>,
|
||||
b: Ty<'tcx>)
|
||||
-> CoerceResult<'tcx> {
|
||||
/*!
|
||||
* Attempts to coerce from the type of a Rust function item
|
||||
* into a closure or a `proc`.
|
||||
*/
|
||||
|
||||
self.unpack_actual_value(b, |b| {
|
||||
debug!("coerce_from_fn_item(a={}, b={})",
|
||||
a.repr(self.tcx()), b.repr(self.tcx()));
|
||||
|
||||
debug!("coerce_from_bare_fn(a={}, b={})",
|
||||
a.repr(self.get_ref().infcx.tcx), b.repr(self.get_ref().infcx.tcx));
|
||||
match b.sty {
|
||||
ty::ty_closure(ref f) => {
|
||||
if fn_ty_a.abi != abi::Rust || fn_ty_a.unsafety != ast::Unsafety::Normal {
|
||||
return self.subtype(a, b);
|
||||
}
|
||||
|
||||
if fn_ty_a.abi != abi::Rust || fn_ty_a.unsafety != ast::Unsafety::Normal {
|
||||
return self.subtype(a, b);
|
||||
let fn_ty_b = (*f).clone();
|
||||
let adj = ty::AdjustAddEnv(fn_def_id_a, fn_ty_b.store);
|
||||
let a_closure = ty::mk_closure(self.tcx(),
|
||||
ty::ClosureTy {
|
||||
sig: fn_ty_a.sig.clone(),
|
||||
.. *fn_ty_b
|
||||
});
|
||||
try!(self.subtype(a_closure, b));
|
||||
Ok(Some(adj))
|
||||
}
|
||||
ty::ty_bare_fn(None, _) => {
|
||||
let a_fn_pointer = ty::mk_bare_fn(self.tcx(), None, (*fn_ty_a).clone());
|
||||
try!(self.subtype(a_fn_pointer, b));
|
||||
Ok(Some(ty::AdjustReifyFnPointer(fn_def_id_a)))
|
||||
}
|
||||
_ => {
|
||||
return self.subtype(a, b)
|
||||
}
|
||||
}
|
||||
|
||||
let fn_ty_b = match b.sty {
|
||||
ty::ty_closure(ref f) => (*f).clone(),
|
||||
_ => return self.subtype(a, b)
|
||||
};
|
||||
|
||||
let adj = ty::AdjustAddEnv(fn_ty_b.store);
|
||||
let a_closure = ty::mk_closure(self.get_ref().infcx.tcx,
|
||||
ty::ClosureTy {
|
||||
sig: fn_ty_a.sig.clone(),
|
||||
.. *fn_ty_b
|
||||
});
|
||||
try!(self.subtype(a_closure, b));
|
||||
Ok(Some(adj))
|
||||
})
|
||||
}
|
||||
|
||||
@ -528,8 +544,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
||||
mutbl_b: ast::Mutability)
|
||||
-> CoerceResult<'tcx> {
|
||||
debug!("coerce_unsafe_ptr(a={}, b={})",
|
||||
a.repr(self.get_ref().infcx.tcx),
|
||||
b.repr(self.get_ref().infcx.tcx));
|
||||
a.repr(self.tcx()),
|
||||
b.repr(self.tcx()));
|
||||
|
||||
let mt_a = match a.sty {
|
||||
ty::ty_rptr(_, mt) | ty::ty_ptr(mt) => mt,
|
||||
@ -539,7 +555,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
||||
};
|
||||
|
||||
// Check that the types which they point at are compatible.
|
||||
let a_unsafe = ty::mk_ptr(self.get_ref().infcx.tcx, ty::mt{ mutbl: mutbl_b, ty: mt_a.ty });
|
||||
let a_unsafe = ty::mk_ptr(self.tcx(), ty::mt{ mutbl: mutbl_b, ty: mt_a.ty });
|
||||
try!(self.subtype(a_unsafe, b));
|
||||
if !can_coerce_mutbls(mt_a.mutbl, mutbl_b) {
|
||||
return Err(ty::terr_mutability);
|
||||
|
@ -141,7 +141,7 @@ pub trait Combine<'tcx> {
|
||||
for _ in a_regions.iter() {
|
||||
invariance.push(ty::Invariant);
|
||||
}
|
||||
invariance.as_slice()
|
||||
invariance[]
|
||||
}
|
||||
};
|
||||
|
||||
@ -411,7 +411,7 @@ pub fn super_tys<'tcx, C: Combine<'tcx>>(this: &C,
|
||||
format!("{}: bot and var types should have been handled ({},{})",
|
||||
this.tag(),
|
||||
a.repr(this.infcx().tcx),
|
||||
b.repr(this.infcx().tcx)).as_slice());
|
||||
b.repr(this.infcx().tcx))[]);
|
||||
}
|
||||
|
||||
(&ty::ty_err, _) | (_, &ty::ty_err) => {
|
||||
@ -568,11 +568,12 @@ pub fn super_tys<'tcx, C: Combine<'tcx>>(this: &C,
|
||||
}
|
||||
}
|
||||
|
||||
(&ty::ty_bare_fn(ref a_fty), &ty::ty_bare_fn(ref b_fty)) => {
|
||||
this.bare_fn_tys(a_fty, b_fty).and_then(|fty| {
|
||||
Ok(ty::mk_bare_fn(tcx, fty))
|
||||
})
|
||||
}
|
||||
(&ty::ty_bare_fn(a_opt_def_id, ref a_fty), &ty::ty_bare_fn(b_opt_def_id, ref b_fty))
|
||||
if a_opt_def_id == b_opt_def_id =>
|
||||
{
|
||||
let fty = try!(this.bare_fn_tys(a_fty, b_fty));
|
||||
Ok(ty::mk_bare_fn(tcx, a_opt_def_id, fty))
|
||||
}
|
||||
|
||||
(&ty::ty_closure(ref a_fty), &ty::ty_closure(ref b_fty)) => {
|
||||
this.closure_tys(&**a_fty, &**b_fty).and_then(|fty| {
|
||||
|
@ -199,9 +199,9 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
ref trace_origins,
|
||||
ref same_regions) => {
|
||||
if !same_regions.is_empty() {
|
||||
self.report_processed_errors(var_origins.as_slice(),
|
||||
trace_origins.as_slice(),
|
||||
same_regions.as_slice());
|
||||
self.report_processed_errors(var_origins[],
|
||||
trace_origins[],
|
||||
same_regions[]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -374,7 +374,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
format!("{}: {} ({})",
|
||||
message_root_str,
|
||||
expected_found_str,
|
||||
ty::type_err_to_str(self.tcx, terr)).as_slice());
|
||||
ty::type_err_to_str(self.tcx, terr))[]);
|
||||
|
||||
match trace.origin {
|
||||
infer::MatchExpressionArm(_, arm_span) =>
|
||||
@ -438,13 +438,13 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
origin.span(),
|
||||
format!(
|
||||
"the parameter type `{}` may not live long enough",
|
||||
param_ty.user_string(self.tcx)).as_slice());
|
||||
param_ty.user_string(self.tcx))[]);
|
||||
self.tcx.sess.span_help(
|
||||
origin.span(),
|
||||
format!(
|
||||
"consider adding an explicit lifetime bound `{}: {}`...",
|
||||
param_ty.user_string(self.tcx),
|
||||
sub.user_string(self.tcx)).as_slice());
|
||||
sub.user_string(self.tcx))[]);
|
||||
}
|
||||
|
||||
ty::ReStatic => {
|
||||
@ -453,12 +453,12 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
origin.span(),
|
||||
format!(
|
||||
"the parameter type `{}` may not live long enough",
|
||||
param_ty.user_string(self.tcx)).as_slice());
|
||||
param_ty.user_string(self.tcx))[]);
|
||||
self.tcx.sess.span_help(
|
||||
origin.span(),
|
||||
format!(
|
||||
"consider adding an explicit lifetime bound `{}: 'static`...",
|
||||
param_ty.user_string(self.tcx)).as_slice());
|
||||
param_ty.user_string(self.tcx))[]);
|
||||
}
|
||||
|
||||
_ => {
|
||||
@ -467,16 +467,16 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
origin.span(),
|
||||
format!(
|
||||
"the parameter type `{}` may not live long enough",
|
||||
param_ty.user_string(self.tcx)).as_slice());
|
||||
param_ty.user_string(self.tcx))[]);
|
||||
self.tcx.sess.span_help(
|
||||
origin.span(),
|
||||
format!(
|
||||
"consider adding an explicit lifetime bound to `{}`",
|
||||
param_ty.user_string(self.tcx)).as_slice());
|
||||
param_ty.user_string(self.tcx))[]);
|
||||
note_and_explain_region(
|
||||
self.tcx,
|
||||
format!("the parameter type `{}` must be valid for ",
|
||||
param_ty.user_string(self.tcx)).as_slice(),
|
||||
param_ty.user_string(self.tcx))[],
|
||||
sub,
|
||||
"...");
|
||||
}
|
||||
@ -518,7 +518,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
ty::local_var_name_str(self.tcx,
|
||||
upvar_id.var_id)
|
||||
.get()
|
||||
.to_string()).as_slice());
|
||||
.to_string())[]);
|
||||
note_and_explain_region(
|
||||
self.tcx,
|
||||
"...the borrowed pointer is valid for ",
|
||||
@ -530,7 +530,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
ty::local_var_name_str(self.tcx,
|
||||
upvar_id.var_id)
|
||||
.get()
|
||||
.to_string()).as_slice(),
|
||||
.to_string())[],
|
||||
sup,
|
||||
"");
|
||||
}
|
||||
@ -576,7 +576,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
outlive the enclosing closure",
|
||||
ty::local_var_name_str(self.tcx,
|
||||
id).get()
|
||||
.to_string()).as_slice());
|
||||
.to_string())[]);
|
||||
note_and_explain_region(
|
||||
self.tcx,
|
||||
"captured variable is valid for ",
|
||||
@ -618,7 +618,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
span,
|
||||
format!("the type `{}` does not fulfill the \
|
||||
required lifetime",
|
||||
self.ty_to_string(ty)).as_slice());
|
||||
self.ty_to_string(ty))[]);
|
||||
note_and_explain_region(self.tcx,
|
||||
"type must outlive ",
|
||||
sub,
|
||||
@ -644,7 +644,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
span,
|
||||
format!("the type `{}` (provided as the value of \
|
||||
a type parameter) is not valid at this point",
|
||||
self.ty_to_string(ty)).as_slice());
|
||||
self.ty_to_string(ty))[]);
|
||||
note_and_explain_region(self.tcx,
|
||||
"type must outlive ",
|
||||
sub,
|
||||
@ -710,7 +710,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
span,
|
||||
format!("type of expression contains references \
|
||||
that are not valid during the expression: `{}`",
|
||||
self.ty_to_string(t)).as_slice());
|
||||
self.ty_to_string(t))[]);
|
||||
note_and_explain_region(
|
||||
self.tcx,
|
||||
"type is only valid for ",
|
||||
@ -732,7 +732,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
span,
|
||||
format!("in type `{}`, reference has a longer lifetime \
|
||||
than the data it references",
|
||||
self.ty_to_string(ty)).as_slice());
|
||||
self.ty_to_string(ty))[]);
|
||||
note_and_explain_region(
|
||||
self.tcx,
|
||||
"the pointer is valid for ",
|
||||
@ -857,7 +857,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
let (fn_decl, generics, unsafety, ident, expl_self, span)
|
||||
= node_inner.expect("expect item fn");
|
||||
let taken = lifetimes_in_scope(self.tcx, scope_id);
|
||||
let life_giver = LifeGiver::with_taken(taken.as_slice());
|
||||
let life_giver = LifeGiver::with_taken(taken[]);
|
||||
let rebuilder = Rebuilder::new(self.tcx, fn_decl, expl_self,
|
||||
generics, same_regions, &life_giver);
|
||||
let (fn_decl, expl_self, generics) = rebuilder.rebuild();
|
||||
@ -933,7 +933,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
|
||||
}
|
||||
expl_self_opt = self.rebuild_expl_self(expl_self_opt, lifetime,
|
||||
&anon_nums, ®ion_names);
|
||||
inputs = self.rebuild_args_ty(inputs.as_slice(), lifetime,
|
||||
inputs = self.rebuild_args_ty(inputs[], lifetime,
|
||||
&anon_nums, ®ion_names);
|
||||
output = self.rebuild_output(&output, lifetime, &anon_nums, ®ion_names);
|
||||
ty_params = self.rebuild_ty_params(ty_params, lifetime,
|
||||
@ -968,7 +968,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
|
||||
names.push(lt_name);
|
||||
}
|
||||
names.sort();
|
||||
let name = token::str_to_ident(names[0].as_slice()).name;
|
||||
let name = token::str_to_ident(names[0][]).name;
|
||||
return (name_to_dummy_lifetime(name), Kept);
|
||||
}
|
||||
return (self.life_giver.give_lifetime(), Fresh);
|
||||
@ -1219,7 +1219,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
|
||||
.sess
|
||||
.fatal(format!(
|
||||
"unbound path {}",
|
||||
pprust::path_to_string(path)).as_slice())
|
||||
pprust::path_to_string(path))[])
|
||||
}
|
||||
Some(&d) => d
|
||||
};
|
||||
@ -1417,7 +1417,7 @@ impl<'a, 'tcx> ErrorReportingHelpers<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
opt_explicit_self, generics);
|
||||
let msg = format!("consider using an explicit lifetime \
|
||||
parameter as shown: {}", suggested_fn);
|
||||
self.tcx.sess.span_help(span, msg.as_slice());
|
||||
self.tcx.sess.span_help(span, msg[]);
|
||||
}
|
||||
|
||||
fn report_inference_failure(&self,
|
||||
@ -1455,7 +1455,7 @@ impl<'a, 'tcx> ErrorReportingHelpers<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
var_origin.span(),
|
||||
format!("cannot infer an appropriate lifetime{} \
|
||||
due to conflicting requirements",
|
||||
var_description).as_slice());
|
||||
var_description)[]);
|
||||
}
|
||||
|
||||
fn note_region_origin(&self, origin: &SubregionOrigin<'tcx>) {
|
||||
@ -1500,7 +1500,7 @@ impl<'a, 'tcx> ErrorReportingHelpers<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
self.tcx.sess.span_note(
|
||||
trace.origin.span(),
|
||||
format!("...so that {} ({})",
|
||||
desc, values_str).as_slice());
|
||||
desc, values_str)[]);
|
||||
}
|
||||
None => {
|
||||
// Really should avoid printing this error at
|
||||
@ -1509,7 +1509,7 @@ impl<'a, 'tcx> ErrorReportingHelpers<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
// doing right now. - nmatsakis
|
||||
self.tcx.sess.span_note(
|
||||
trace.origin.span(),
|
||||
format!("...so that {}", desc).as_slice());
|
||||
format!("...so that {}", desc)[]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1526,7 +1526,7 @@ impl<'a, 'tcx> ErrorReportingHelpers<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
"...so that closure can access `{}`",
|
||||
ty::local_var_name_str(self.tcx, upvar_id.var_id)
|
||||
.get()
|
||||
.to_string()).as_slice())
|
||||
.to_string())[])
|
||||
}
|
||||
infer::InfStackClosure(span) => {
|
||||
self.tcx.sess.span_note(
|
||||
@ -1551,7 +1551,7 @@ impl<'a, 'tcx> ErrorReportingHelpers<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
does not outlive the enclosing closure",
|
||||
ty::local_var_name_str(
|
||||
self.tcx,
|
||||
id).get().to_string()).as_slice());
|
||||
id).get().to_string())[]);
|
||||
}
|
||||
infer::IndexSlice(span) => {
|
||||
self.tcx.sess.span_note(
|
||||
@ -1595,7 +1595,7 @@ impl<'a, 'tcx> ErrorReportingHelpers<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
span,
|
||||
format!("...so type `{}` of expression is valid during the \
|
||||
expression",
|
||||
self.ty_to_string(t)).as_slice());
|
||||
self.ty_to_string(t))[]);
|
||||
}
|
||||
infer::BindingTypeIsNotValidAtDecl(span) => {
|
||||
self.tcx.sess.span_note(
|
||||
@ -1607,14 +1607,14 @@ impl<'a, 'tcx> ErrorReportingHelpers<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
span,
|
||||
format!("...so that the reference type `{}` \
|
||||
does not outlive the data it points at",
|
||||
self.ty_to_string(ty)).as_slice());
|
||||
self.ty_to_string(ty))[]);
|
||||
}
|
||||
infer::RelateParamBound(span, t) => {
|
||||
self.tcx.sess.span_note(
|
||||
span,
|
||||
format!("...so that the type `{}` \
|
||||
will meet the declared lifetime bounds",
|
||||
self.ty_to_string(t)).as_slice());
|
||||
self.ty_to_string(t))[]);
|
||||
}
|
||||
infer::RelateDefaultParamBound(span, t) => {
|
||||
self.tcx.sess.span_note(
|
||||
@ -1622,13 +1622,13 @@ impl<'a, 'tcx> ErrorReportingHelpers<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
format!("...so that type parameter \
|
||||
instantiated with `{}`, \
|
||||
will meet its declared lifetime bounds",
|
||||
self.ty_to_string(t)).as_slice());
|
||||
self.ty_to_string(t))[]);
|
||||
}
|
||||
infer::RelateRegionParamBound(span) => {
|
||||
self.tcx.sess.span_note(
|
||||
span,
|
||||
format!("...so that the declared lifetime parameter bounds \
|
||||
are satisfied").as_slice());
|
||||
are satisfied")[]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1677,7 +1677,7 @@ fn lifetimes_in_scope(tcx: &ty::ctxt,
|
||||
Some(node) => match node {
|
||||
ast_map::NodeItem(item) => match item.node {
|
||||
ast::ItemFn(_, _, _, ref gen, _) => {
|
||||
taken.push_all(gen.lifetimes.as_slice());
|
||||
taken.push_all(gen.lifetimes[]);
|
||||
None
|
||||
},
|
||||
_ => None
|
||||
@ -1685,7 +1685,7 @@ fn lifetimes_in_scope(tcx: &ty::ctxt,
|
||||
ast_map::NodeImplItem(ii) => {
|
||||
match *ii {
|
||||
ast::MethodImplItem(ref m) => {
|
||||
taken.push_all(m.pe_generics().lifetimes.as_slice());
|
||||
taken.push_all(m.pe_generics().lifetimes[]);
|
||||
Some(m.id)
|
||||
}
|
||||
ast::TypeImplItem(_) => None,
|
||||
@ -1744,10 +1744,10 @@ impl LifeGiver {
|
||||
let mut lifetime;
|
||||
loop {
|
||||
let mut s = String::from_str("'");
|
||||
s.push_str(num_to_string(self.counter.get()).as_slice());
|
||||
s.push_str(num_to_string(self.counter.get())[]);
|
||||
if !self.taken.contains(&s) {
|
||||
lifetime = name_to_dummy_lifetime(
|
||||
token::str_to_ident(s.as_slice()).name);
|
||||
token::str_to_ident(s[]).name);
|
||||
self.generated.borrow_mut().push(lifetime);
|
||||
break;
|
||||
}
|
||||
|
@ -189,7 +189,7 @@ impl<'tcx,C> HigherRankedRelations<'tcx> for C
|
||||
span,
|
||||
format!("region {} is not associated with \
|
||||
any bound region from A!",
|
||||
r0).as_slice())
|
||||
r0)[])
|
||||
}
|
||||
}
|
||||
|
||||
@ -339,7 +339,7 @@ fn var_ids<'tcx, T: Combine<'tcx>>(combiner: &T,
|
||||
r => {
|
||||
combiner.infcx().tcx.sess.span_bug(
|
||||
combiner.trace().origin.span(),
|
||||
format!("found non-region-vid: {}", r).as_slice());
|
||||
format!("found non-region-vid: {}", r)[]);
|
||||
}
|
||||
}).collect()
|
||||
}
|
||||
|
@ -992,7 +992,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
|
||||
self.tcx.sess.span_err(sp, format!("{}{}",
|
||||
mk_msg(resolved_expected.map(|t| self.ty_to_string(t)), actual_ty),
|
||||
error_str).as_slice());
|
||||
error_str)[]);
|
||||
|
||||
for err in err.iter() {
|
||||
ty::note_and_explain_type_err(self.tcx, *err)
|
||||
|
@ -60,7 +60,7 @@ pub fn maybe_print_constraints_for<'a, 'tcx>(region_vars: &RegionVarBindings<'a,
|
||||
}
|
||||
|
||||
let requested_node : Option<ast::NodeId> =
|
||||
os::getenv("RUST_REGION_GRAPH_NODE").and_then(|s|from_str(s.as_slice()));
|
||||
os::getenv("RUST_REGION_GRAPH_NODE").and_then(|s| s.parse());
|
||||
|
||||
if requested_node.is_some() && requested_node != Some(subject_node) {
|
||||
return;
|
||||
|
@ -464,7 +464,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
|
||||
origin.span(),
|
||||
format!("cannot relate bound region: {} <= {}",
|
||||
sub.repr(self.tcx),
|
||||
sup.repr(self.tcx)).as_slice());
|
||||
sup.repr(self.tcx))[]);
|
||||
}
|
||||
(_, ReStatic) => {
|
||||
// all regions are subregions of static, so we can ignore this
|
||||
@ -724,7 +724,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
|
||||
self.tcx.sess.bug(
|
||||
format!("cannot relate bound region: LUB({}, {})",
|
||||
a.repr(self.tcx),
|
||||
b.repr(self.tcx)).as_slice());
|
||||
b.repr(self.tcx))[]);
|
||||
}
|
||||
|
||||
(ReStatic, _) | (_, ReStatic) => {
|
||||
@ -741,7 +741,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
|
||||
format!("lub_concrete_regions invoked with \
|
||||
non-concrete regions: {}, {}",
|
||||
a,
|
||||
b).as_slice());
|
||||
b)[]);
|
||||
}
|
||||
|
||||
(ReFree(ref fr), ReScope(s_id)) |
|
||||
@ -824,7 +824,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
|
||||
self.tcx.sess.bug(
|
||||
format!("cannot relate bound region: GLB({}, {})",
|
||||
a.repr(self.tcx),
|
||||
b.repr(self.tcx)).as_slice());
|
||||
b.repr(self.tcx))[]);
|
||||
}
|
||||
|
||||
(ReStatic, r) | (r, ReStatic) => {
|
||||
@ -844,7 +844,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
|
||||
format!("glb_concrete_regions invoked with \
|
||||
non-concrete regions: {}, {}",
|
||||
a,
|
||||
b).as_slice());
|
||||
b)[]);
|
||||
}
|
||||
|
||||
(ReFree(ref fr), ReScope(s_id)) |
|
||||
@ -965,7 +965,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
|
||||
self.expansion(var_data.as_mut_slice());
|
||||
self.contraction(var_data.as_mut_slice());
|
||||
let values =
|
||||
self.extract_values_and_collect_conflicts(var_data.as_slice(),
|
||||
self.extract_values_and_collect_conflicts(var_data[],
|
||||
errors);
|
||||
self.collect_concrete_region_errors(&values, errors);
|
||||
values
|
||||
@ -1403,7 +1403,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
|
||||
for var {}, lower_bounds={}, upper_bounds={}",
|
||||
node_idx,
|
||||
lower_bounds.repr(self.tcx),
|
||||
upper_bounds.repr(self.tcx)).as_slice());
|
||||
upper_bounds.repr(self.tcx))[]);
|
||||
}
|
||||
|
||||
fn collect_error_for_contracting_node(
|
||||
@ -1447,7 +1447,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
|
||||
format!("collect_error_for_contracting_node() could not find error \
|
||||
for var {}, upper_bounds={}",
|
||||
node_idx,
|
||||
upper_bounds.repr(self.tcx)).as_slice());
|
||||
upper_bounds.repr(self.tcx))[]);
|
||||
}
|
||||
|
||||
fn collect_concrete_regions(&self,
|
||||
|
@ -74,7 +74,7 @@ struct IntrinsicCheckingVisitor<'a, 'tcx: 'a> {
|
||||
impl<'a, 'tcx> IntrinsicCheckingVisitor<'a, 'tcx> {
|
||||
fn def_id_is_transmute(&self, def_id: DefId) -> bool {
|
||||
let intrinsic = match ty::lookup_item_type(self.tcx, def_id).ty.sty {
|
||||
ty::ty_bare_fn(ref bfty) => bfty.abi == RustIntrinsic,
|
||||
ty::ty_bare_fn(_, ref bfty) => bfty.abi == RustIntrinsic,
|
||||
_ => return false
|
||||
};
|
||||
if def_id.krate == ast::LOCAL_CRATE {
|
||||
@ -123,7 +123,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for IntrinsicCheckingVisitor<'a, 'tcx> {
|
||||
DefFn(did, _) if self.def_id_is_transmute(did) => {
|
||||
let typ = ty::node_id_to_type(self.tcx, expr.id);
|
||||
match typ.sty {
|
||||
ty_bare_fn(ref bare_fn_ty) if bare_fn_ty.abi == RustIntrinsic => {
|
||||
ty_bare_fn(_, ref bare_fn_ty) if bare_fn_ty.abi == RustIntrinsic => {
|
||||
if let ty::FnConverging(to) = bare_fn_ty.sig.0.output {
|
||||
let from = bare_fn_ty.sig.0.inputs[0];
|
||||
self.check_transmute(expr.span, from, to, expr.id);
|
||||
|
@ -65,7 +65,7 @@ impl LanguageItems {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn items<'a>(&'a self) -> Enumerate<slice::Items<'a, Option<ast::DefId>>> {
|
||||
pub fn items<'a>(&'a self) -> Enumerate<slice::Iter<'a, Option<ast::DefId>>> {
|
||||
self.items.iter().enumerate()
|
||||
}
|
||||
|
||||
|
@ -323,7 +323,7 @@ impl<'a, 'tcx> IrMaps<'a, 'tcx> {
|
||||
self.tcx
|
||||
.sess
|
||||
.span_bug(span, format!("no variable registered for id {}",
|
||||
node_id).as_slice());
|
||||
node_id)[]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -594,7 +594,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
||||
self.ir.tcx.sess.span_bug(
|
||||
span,
|
||||
format!("no live node registered for node {}",
|
||||
node_id).as_slice());
|
||||
node_id)[]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1129,7 +1129,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
||||
// Uninteresting cases: just propagate in rev exec order
|
||||
|
||||
ast::ExprVec(ref exprs) => {
|
||||
self.propagate_through_exprs(exprs.as_slice(), succ)
|
||||
self.propagate_through_exprs(exprs[], succ)
|
||||
}
|
||||
|
||||
ast::ExprRepeat(ref element, ref count) => {
|
||||
@ -1154,7 +1154,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
||||
} else {
|
||||
succ
|
||||
};
|
||||
let succ = self.propagate_through_exprs(args.as_slice(), succ);
|
||||
let succ = self.propagate_through_exprs(args[], succ);
|
||||
self.propagate_through_expr(&**f, succ)
|
||||
}
|
||||
|
||||
@ -1167,11 +1167,11 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
||||
} else {
|
||||
succ
|
||||
};
|
||||
self.propagate_through_exprs(args.as_slice(), succ)
|
||||
self.propagate_through_exprs(args[], succ)
|
||||
}
|
||||
|
||||
ast::ExprTup(ref exprs) => {
|
||||
self.propagate_through_exprs(exprs.as_slice(), succ)
|
||||
self.propagate_through_exprs(exprs[], succ)
|
||||
}
|
||||
|
||||
ast::ExprBinary(op, ref l, ref r) if ast_util::lazy_binop(op) => {
|
||||
|
@ -238,7 +238,7 @@ pub fn deref_kind<'tcx>(tcx: &ty::ctxt<'tcx>, t: Ty<'tcx>) -> deref_kind {
|
||||
None => {
|
||||
tcx.sess.bug(
|
||||
format!("deref_kind() invoked on non-derefable type {}",
|
||||
ty_to_string(tcx, t)).as_slice());
|
||||
ty_to_string(tcx, t))[]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -441,8 +441,8 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
|
||||
|
||||
Some(adjustment) => {
|
||||
match *adjustment {
|
||||
ty::AdjustAddEnv(..) => {
|
||||
debug!("cat_expr(AdjustAddEnv): {}",
|
||||
ty::AdjustAddEnv(..) | ty::AdjustReifyFnPointer(..) => {
|
||||
debug!("cat_expr(AdjustAddEnv|AdjustReifyFnPointer): {}",
|
||||
expr.repr(self.tcx()));
|
||||
// Convert a bare fn to a closure by adding NULL env.
|
||||
// Result is an rvalue.
|
||||
@ -635,7 +635,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
|
||||
span,
|
||||
format!("Upvar of non-closure {} - {}",
|
||||
fn_node_id,
|
||||
ty.repr(self.tcx())).as_slice());
|
||||
ty.repr(self.tcx()))[]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -917,7 +917,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
|
||||
self.tcx().sess.span_bug(
|
||||
node.span(),
|
||||
format!("Explicit deref of non-derefable type: {}",
|
||||
base_cmt.ty.repr(self.tcx())).as_slice());
|
||||
base_cmt.ty.repr(self.tcx()))[]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -996,7 +996,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
|
||||
self.tcx().sess.span_bug(
|
||||
elt.span(),
|
||||
format!("Explicit index of non-index type `{}`",
|
||||
base_cmt.ty.repr(self.tcx())).as_slice());
|
||||
base_cmt.ty.repr(self.tcx()))[]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -615,10 +615,10 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
|
||||
match result {
|
||||
None => true,
|
||||
Some((span, msg, note)) => {
|
||||
self.tcx.sess.span_err(span, msg.as_slice());
|
||||
self.tcx.sess.span_err(span, msg[]);
|
||||
match note {
|
||||
Some((span, msg)) => {
|
||||
self.tcx.sess.span_note(span, msg.as_slice())
|
||||
self.tcx.sess.span_note(span, msg[])
|
||||
}
|
||||
None => {},
|
||||
}
|
||||
@ -720,7 +720,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
|
||||
UnnamedField(idx) => format!("field #{} of {} is private",
|
||||
idx + 1, struct_desc),
|
||||
};
|
||||
self.tcx.sess.span_err(span, msg.as_slice());
|
||||
self.tcx.sess.span_err(span, msg[]);
|
||||
}
|
||||
|
||||
// Given the ID of a method, checks to ensure it's in scope.
|
||||
@ -742,7 +742,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
|
||||
method_id,
|
||||
None,
|
||||
format!("method `{}`",
|
||||
string).as_slice()));
|
||||
string)[]));
|
||||
}
|
||||
|
||||
// Checks that a path is in scope.
|
||||
@ -759,9 +759,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
|
||||
self.ensure_public(span,
|
||||
def,
|
||||
Some(origdid),
|
||||
format!("{} `{}`",
|
||||
tyname,
|
||||
name).as_slice())
|
||||
format!("{} `{}`", tyname, name)[])
|
||||
};
|
||||
|
||||
match self.last_private_map[path_id] {
|
||||
|
@ -50,7 +50,7 @@ fn generics_require_inlining(generics: &ast::Generics) -> bool {
|
||||
// monomorphized or it was marked with `#[inline]`. This will only return
|
||||
// true for functions.
|
||||
fn item_might_be_inlined(item: &ast::Item) -> bool {
|
||||
if attributes_specify_inlining(item.attrs.as_slice()) {
|
||||
if attributes_specify_inlining(item.attrs[]) {
|
||||
return true
|
||||
}
|
||||
|
||||
@ -65,7 +65,7 @@ fn item_might_be_inlined(item: &ast::Item) -> bool {
|
||||
|
||||
fn method_might_be_inlined(tcx: &ty::ctxt, method: &ast::Method,
|
||||
impl_src: ast::DefId) -> bool {
|
||||
if attributes_specify_inlining(method.attrs.as_slice()) ||
|
||||
if attributes_specify_inlining(method.attrs[]) ||
|
||||
generics_require_inlining(method.pe_generics()) {
|
||||
return true
|
||||
}
|
||||
@ -202,7 +202,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
|
||||
ast::MethodImplItem(ref method) => {
|
||||
if generics_require_inlining(method.pe_generics()) ||
|
||||
attributes_specify_inlining(
|
||||
method.attrs.as_slice()) {
|
||||
method.attrs[]) {
|
||||
true
|
||||
} else {
|
||||
let impl_did = self.tcx
|
||||
@ -249,7 +249,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
|
||||
None => {
|
||||
self.tcx.sess.bug(format!("found unmapped ID in worklist: \
|
||||
{}",
|
||||
search_item).as_slice())
|
||||
search_item)[])
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -341,7 +341,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
|
||||
.bug(format!("found unexpected thingy in worklist: {}",
|
||||
self.tcx
|
||||
.map
|
||||
.node_to_string(search_item)).as_slice())
|
||||
.node_to_string(search_item))[])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,8 @@ use syntax::visit::{Visitor, FnKind};
|
||||
/// placate the same deriving in `ty::FreeRegion`, but we may want to
|
||||
/// actually attach a more meaningful ordering to scopes than the one
|
||||
/// generated via deriving here.
|
||||
#[deriving(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash, Encodable, Decodable, Show)]
|
||||
#[deriving(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, RustcEncodable,
|
||||
RustcDecodable, Show, Copy)]
|
||||
pub enum CodeExtent {
|
||||
Misc(ast::NodeId)
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ use syntax::visit;
|
||||
use syntax::visit::Visitor;
|
||||
use util::nodemap::NodeMap;
|
||||
|
||||
#[deriving(Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, Show)]
|
||||
#[deriving(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Show)]
|
||||
pub enum DefRegion {
|
||||
DefStaticRegion,
|
||||
DefEarlyBoundRegion(/* space */ subst::ParamSpace,
|
||||
@ -409,7 +409,7 @@ impl<'a> LifetimeContext<'a> {
|
||||
self.sess.span_err(
|
||||
lifetime_ref.span,
|
||||
format!("use of undeclared lifetime name `{}`",
|
||||
token::get_name(lifetime_ref.name)).as_slice());
|
||||
token::get_name(lifetime_ref.name))[]);
|
||||
}
|
||||
|
||||
fn check_lifetime_defs(&mut self, old_scope: Scope, lifetimes: &Vec<ast::LifetimeDef>) {
|
||||
@ -423,7 +423,7 @@ impl<'a> LifetimeContext<'a> {
|
||||
lifetime.lifetime.span,
|
||||
format!("illegal lifetime parameter name: `{}`",
|
||||
token::get_name(lifetime.lifetime.name))
|
||||
.as_slice());
|
||||
[]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -437,7 +437,7 @@ impl<'a> LifetimeContext<'a> {
|
||||
format!("lifetime name `{}` declared twice in \
|
||||
the same scope",
|
||||
token::get_name(lifetime_j.lifetime.name))
|
||||
.as_slice());
|
||||
[]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ use middle::ty_fold::{mod, TypeFoldable, TypeFolder};
|
||||
use util::ppaux::Repr;
|
||||
|
||||
use std::fmt;
|
||||
use std::slice::Items;
|
||||
use std::slice::Iter;
|
||||
use std::vec::Vec;
|
||||
use syntax::codemap::{Span, DUMMY_SP};
|
||||
|
||||
@ -187,8 +187,8 @@ impl RegionSubsts {
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// ParamSpace
|
||||
|
||||
#[deriving(Copy, PartialOrd, Ord, PartialEq, Eq,
|
||||
Clone, Hash, Encodable, Decodable, Show)]
|
||||
#[deriving(PartialOrd, Ord, PartialEq, Eq, Copy,
|
||||
Clone, Hash, RustcEncodable, RustcDecodable, Show)]
|
||||
pub enum ParamSpace {
|
||||
TypeSpace, // Type parameters attached to a type definition, trait, or impl
|
||||
SelfSpace, // Self parameter on a trait
|
||||
@ -224,7 +224,7 @@ impl ParamSpace {
|
||||
/// Vector of things sorted by param space. Used to keep
|
||||
/// the set of things declared on the type, self, or method
|
||||
/// distinct.
|
||||
#[deriving(PartialEq, Eq, Clone, Hash, Encodable, Decodable)]
|
||||
#[deriving(PartialEq, Eq, Clone, Hash, RustcEncodable, RustcDecodable)]
|
||||
pub struct VecPerParamSpace<T> {
|
||||
// This was originally represented as a tuple with one Vec<T> for
|
||||
// each variant of ParamSpace, and that remains the abstraction
|
||||
@ -400,7 +400,7 @@ impl<T> VecPerParamSpace<T> {
|
||||
&self.get_slice(space)[index]
|
||||
}
|
||||
|
||||
pub fn iter<'a>(&'a self) -> Items<'a,T> {
|
||||
pub fn iter<'a>(&'a self) -> Iter<'a,T> {
|
||||
self.content.iter()
|
||||
}
|
||||
|
||||
@ -620,7 +620,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> {
|
||||
(space={}, index={})",
|
||||
region_name.as_str(),
|
||||
self.root_ty.repr(self.tcx()),
|
||||
space, i).as_slice());
|
||||
space, i)[]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -677,7 +677,7 @@ impl<'a,'tcx> SubstFolder<'a,'tcx> {
|
||||
p.space,
|
||||
p.idx,
|
||||
self.root_ty.repr(self.tcx()),
|
||||
self.substs.repr(self.tcx())).as_slice());
|
||||
self.substs.repr(self.tcx()))[]);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -154,7 +154,7 @@ pub fn ty_is_local<'tcx>(tcx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> bool {
|
||||
ty::ty_err => {
|
||||
tcx.sess.bug(
|
||||
format!("ty_is_local invoked on unexpected type: {}",
|
||||
ty.repr(tcx)).as_slice())
|
||||
ty.repr(tcx))[])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ use middle::subst;
|
||||
use middle::ty::{mod, Ty};
|
||||
use middle::infer::InferCtxt;
|
||||
use std::rc::Rc;
|
||||
use std::slice::Items;
|
||||
use std::slice::Iter;
|
||||
use syntax::ast;
|
||||
use syntax::codemap::{Span, DUMMY_SP};
|
||||
|
||||
@ -304,7 +304,7 @@ impl<'tcx> ObligationCause<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx, N> Vtable<'tcx, N> {
|
||||
pub fn iter_nested(&self) -> Items<N> {
|
||||
pub fn iter_nested(&self) -> Iter<N> {
|
||||
match *self {
|
||||
VtableImpl(ref i) => i.iter_nested(),
|
||||
VtableFnPointer(..) => (&[]).iter(),
|
||||
@ -338,7 +338,7 @@ impl<'tcx, N> Vtable<'tcx, N> {
|
||||
}
|
||||
|
||||
impl<'tcx, N> VtableImplData<'tcx, N> {
|
||||
pub fn iter_nested(&self) -> Items<N> {
|
||||
pub fn iter_nested(&self) -> Iter<N> {
|
||||
self.nested.iter()
|
||||
}
|
||||
|
||||
@ -365,7 +365,7 @@ impl<'tcx, N> VtableImplData<'tcx, N> {
|
||||
}
|
||||
|
||||
impl<N> VtableBuiltinData<N> {
|
||||
pub fn iter_nested(&self) -> Items<N> {
|
||||
pub fn iter_nested(&self) -> Iter<N> {
|
||||
self.nested.iter()
|
||||
}
|
||||
|
||||
|
@ -709,7 +709,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
|
||||
let all_bounds =
|
||||
util::transitive_bounds(
|
||||
self.tcx(), caller_trait_refs.as_slice());
|
||||
self.tcx(), caller_trait_refs[]);
|
||||
|
||||
let matching_bounds =
|
||||
all_bounds.filter(
|
||||
@ -762,7 +762,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
self.tcx().sess.span_bug(
|
||||
obligation.cause.span,
|
||||
format!("No entry for unboxed closure: {}",
|
||||
closure_def_id.repr(self.tcx())).as_slice());
|
||||
closure_def_id.repr(self.tcx()))[]);
|
||||
}
|
||||
};
|
||||
|
||||
@ -795,7 +795,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
}
|
||||
|
||||
// provide an impl, but only for suitable `fn` pointers
|
||||
ty::ty_bare_fn(ty::BareFnTy {
|
||||
ty::ty_bare_fn(_, ty::BareFnTy {
|
||||
unsafety: ast::Unsafety::Normal,
|
||||
abi: abi::Rust,
|
||||
sig: ty::Binder(ty::FnSig {
|
||||
@ -984,7 +984,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
ty::ty_int(_) |
|
||||
ty::ty_bool |
|
||||
ty::ty_float(_) |
|
||||
ty::ty_bare_fn(_) |
|
||||
ty::ty_bare_fn(..) |
|
||||
ty::ty_char => {
|
||||
// safe for everything
|
||||
Ok(If(Vec::new()))
|
||||
@ -1281,7 +1281,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
self.tcx().sess.bug(
|
||||
format!(
|
||||
"asked to assemble builtin bounds of unexpected type: {}",
|
||||
self_ty.repr(self.tcx())).as_slice());
|
||||
self_ty.repr(self.tcx()))[]);
|
||||
}
|
||||
};
|
||||
|
||||
@ -1436,7 +1436,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
self.tcx().sess.span_bug(
|
||||
obligation.cause.span,
|
||||
format!("builtin bound for {} was ambig",
|
||||
obligation.repr(self.tcx())).as_slice());
|
||||
obligation.repr(self.tcx()))[]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1543,7 +1543,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
|
||||
let self_ty = self.infcx.shallow_resolve(obligation.self_ty());
|
||||
let sig = match self_ty.sty {
|
||||
ty::ty_bare_fn(ty::BareFnTy {
|
||||
ty::ty_bare_fn(_, ty::BareFnTy {
|
||||
unsafety: ast::Unsafety::Normal,
|
||||
abi: abi::Rust,
|
||||
ref sig
|
||||
@ -1554,7 +1554,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
self.tcx().sess.span_bug(
|
||||
obligation.cause.span,
|
||||
format!("Fn pointer candidate for inappropriate self type: {}",
|
||||
self_ty.repr(self.tcx())).as_slice());
|
||||
self_ty.repr(self.tcx()))[]);
|
||||
}
|
||||
};
|
||||
|
||||
@ -1595,7 +1595,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
self.tcx().sess.span_bug(
|
||||
obligation.cause.span,
|
||||
format!("No entry for unboxed closure: {}",
|
||||
closure_def_id.repr(self.tcx())).as_slice());
|
||||
closure_def_id.repr(self.tcx()))[]);
|
||||
}
|
||||
};
|
||||
|
||||
@ -1692,8 +1692,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
self.tcx().sess.bug(
|
||||
format!("Impl {} was matchable against {} but now is not",
|
||||
impl_def_id.repr(self.tcx()),
|
||||
obligation.repr(self.tcx()))
|
||||
.as_slice());
|
||||
obligation.repr(self.tcx()))[]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -246,7 +246,7 @@ pub struct mt<'tcx> {
|
||||
pub mutbl: ast::Mutability,
|
||||
}
|
||||
|
||||
#[deriving(Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, Show)]
|
||||
#[deriving(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Show)]
|
||||
pub enum TraitStore {
|
||||
/// Box<Trait>
|
||||
UniqTraitStore,
|
||||
@ -277,13 +277,13 @@ pub enum ast_ty_to_ty_cache_entry<'tcx> {
|
||||
atttce_resolved(Ty<'tcx>) /* resolved to a type, irrespective of region */
|
||||
}
|
||||
|
||||
#[deriving(Clone, PartialEq, Decodable, Encodable)]
|
||||
#[deriving(Clone, PartialEq, RustcDecodable, RustcEncodable)]
|
||||
pub struct ItemVariances {
|
||||
pub types: VecPerParamSpace<Variance>,
|
||||
pub regions: VecPerParamSpace<Variance>,
|
||||
}
|
||||
|
||||
#[deriving(Clone, Copy, PartialEq, Decodable, Encodable, Show)]
|
||||
#[deriving(Clone, PartialEq, RustcDecodable, RustcEncodable, Show, Copy)]
|
||||
pub enum Variance {
|
||||
Covariant, // T<A> <: T<B> iff A <: B -- e.g., function return type
|
||||
Invariant, // T<A> <: T<B> iff B == A -- e.g., type of mutable cell
|
||||
@ -293,7 +293,8 @@ pub enum Variance {
|
||||
|
||||
#[deriving(Clone, Show)]
|
||||
pub enum AutoAdjustment<'tcx> {
|
||||
AdjustAddEnv(ty::TraitStore),
|
||||
AdjustAddEnv(ast::DefId, ty::TraitStore),
|
||||
AdjustReifyFnPointer(ast::DefId), // go from a fn-item type to a fn-pointer type
|
||||
AdjustDerefRef(AutoDerefRef<'tcx>)
|
||||
}
|
||||
|
||||
@ -430,7 +431,7 @@ pub fn type_of_adjust<'tcx>(cx: &ctxt<'tcx>, adj: &AutoAdjustment<'tcx>) -> Opti
|
||||
}
|
||||
}
|
||||
|
||||
#[deriving(Clone, Copy, Encodable, Decodable, PartialEq, PartialOrd, Show)]
|
||||
#[deriving(Clone, Copy, RustcEncodable, RustcDecodable, PartialEq, PartialOrd, Show)]
|
||||
pub struct param_index {
|
||||
pub space: subst::ParamSpace,
|
||||
pub index: uint
|
||||
@ -510,7 +511,7 @@ pub struct MethodCall {
|
||||
pub adjustment: ExprAdjustment
|
||||
}
|
||||
|
||||
#[deriving(Clone, Copy, PartialEq, Eq, Hash, Show, Encodable, Decodable)]
|
||||
#[deriving(Clone, PartialEq, Eq, Hash, Show, RustcEncodable, RustcDecodable, Copy)]
|
||||
pub enum ExprAdjustment {
|
||||
NoAdjustment,
|
||||
AutoDeref(uint),
|
||||
@ -973,7 +974,7 @@ pub struct ParamTy {
|
||||
/// is the outer fn.
|
||||
///
|
||||
/// [dbi]: http://en.wikipedia.org/wiki/De_Bruijn_index
|
||||
#[deriving(Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, Show)]
|
||||
#[deriving(Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Show, Copy)]
|
||||
pub struct DebruijnIndex {
|
||||
// We maintain the invariant that this is never 0. So 1 indicates
|
||||
// the innermost binder. To ensure this, create with `DebruijnIndex::new`.
|
||||
@ -981,7 +982,7 @@ pub struct DebruijnIndex {
|
||||
}
|
||||
|
||||
/// Representation of regions:
|
||||
#[deriving(Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, Show)]
|
||||
#[deriving(Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Show, Copy)]
|
||||
pub enum Region {
|
||||
// Region bound in a type or fn declaration which will be
|
||||
// substituted 'early' -- that is, at the same time when type
|
||||
@ -1028,7 +1029,7 @@ pub struct UpvarId {
|
||||
pub closure_expr_id: ast::NodeId,
|
||||
}
|
||||
|
||||
#[deriving(Clone, Copy, PartialEq, Eq, Hash, Show, Encodable, Decodable)]
|
||||
#[deriving(Clone, PartialEq, Eq, Hash, Show, RustcEncodable, RustcDecodable, Copy)]
|
||||
pub enum BorrowKind {
|
||||
/// Data must be immutable and is aliasable.
|
||||
ImmBorrow,
|
||||
@ -1121,7 +1122,7 @@ pub enum BorrowKind {
|
||||
/// - Through mutation, the borrowed upvars can actually escape
|
||||
/// the closure, so sometimes it is necessary for them to be larger
|
||||
/// than the closure lifetime itself.
|
||||
#[deriving(Copy, PartialEq, Clone, Encodable, Decodable, Show)]
|
||||
#[deriving(PartialEq, Clone, RustcEncodable, RustcDecodable, Show, Copy)]
|
||||
pub struct UpvarBorrow {
|
||||
pub kind: BorrowKind,
|
||||
pub region: ty::Region,
|
||||
@ -1146,7 +1147,8 @@ impl Region {
|
||||
}
|
||||
}
|
||||
|
||||
#[deriving(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash, Encodable, Decodable, Show)]
|
||||
#[deriving(Clone, PartialEq, PartialOrd, Eq, Ord, Hash,
|
||||
RustcEncodable, RustcDecodable, Show, Copy)]
|
||||
/// A "free" region `fr` can be interpreted as "some region
|
||||
/// at least as big as the scope `fr.scope`".
|
||||
pub struct FreeRegion {
|
||||
@ -1154,7 +1156,8 @@ pub struct FreeRegion {
|
||||
pub bound_region: BoundRegion
|
||||
}
|
||||
|
||||
#[deriving(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash, Encodable, Decodable, Show)]
|
||||
#[deriving(Clone, PartialEq, PartialOrd, Eq, Ord, Hash,
|
||||
RustcEncodable, RustcDecodable, Show, Copy)]
|
||||
pub enum BoundRegion {
|
||||
/// An anonymous region parameter for a given fn (&T)
|
||||
BrAnon(uint),
|
||||
@ -1243,11 +1246,17 @@ pub enum sty<'tcx> {
|
||||
ty_vec(Ty<'tcx>, Option<uint>), // Second field is length.
|
||||
ty_ptr(mt<'tcx>),
|
||||
ty_rptr(Region, mt<'tcx>),
|
||||
ty_bare_fn(BareFnTy<'tcx>),
|
||||
|
||||
// If the def-id is Some(_), then this is the type of a specific
|
||||
// fn item. Otherwise, if None(_), it a fn pointer type.
|
||||
ty_bare_fn(Option<DefId>, BareFnTy<'tcx>),
|
||||
|
||||
ty_closure(Box<ClosureTy<'tcx>>),
|
||||
ty_trait(Box<TyTrait<'tcx>>),
|
||||
ty_struct(DefId, Substs<'tcx>),
|
||||
|
||||
ty_unboxed_closure(DefId, Region, Substs<'tcx>),
|
||||
|
||||
ty_tup(Vec<Ty<'tcx>>),
|
||||
|
||||
ty_param(ParamTy), // type parameter
|
||||
@ -1412,7 +1421,8 @@ pub struct ExistentialBounds {
|
||||
|
||||
pub type BuiltinBounds = EnumSet<BuiltinBound>;
|
||||
|
||||
#[deriving(Copy, Clone, Encodable, PartialEq, Eq, Decodable, Hash, Show)]
|
||||
#[deriving(Clone, RustcEncodable, PartialEq, Eq, RustcDecodable, Hash,
|
||||
Show, Copy)]
|
||||
#[repr(uint)]
|
||||
pub enum BuiltinBound {
|
||||
BoundSend,
|
||||
@ -1463,7 +1473,7 @@ pub struct FloatVid {
|
||||
pub index: uint
|
||||
}
|
||||
|
||||
#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash)]
|
||||
#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
|
||||
pub struct RegionVid {
|
||||
pub index: uint
|
||||
}
|
||||
@ -1485,7 +1495,7 @@ pub enum InferTy {
|
||||
FreshIntTy(uint),
|
||||
}
|
||||
|
||||
#[deriving(Clone, Copy, Encodable, Decodable, Eq, Hash, Show)]
|
||||
#[deriving(Clone, RustcEncodable, RustcDecodable, Eq, Hash, Show, Copy)]
|
||||
pub enum InferRegion {
|
||||
ReVar(RegionVid),
|
||||
ReSkolemized(uint, BoundRegion)
|
||||
@ -1571,7 +1581,7 @@ pub struct TypeParameterDef<'tcx> {
|
||||
pub default: Option<Ty<'tcx>>,
|
||||
}
|
||||
|
||||
#[deriving(Encodable, Decodable, Clone, Show)]
|
||||
#[deriving(RustcEncodable, RustcDecodable, Clone, Show)]
|
||||
pub struct RegionParameterDef {
|
||||
pub name: ast::Name,
|
||||
pub def_id: ast::DefId,
|
||||
@ -1891,7 +1901,7 @@ impl<'tcx> ParameterEnvironment<'tcx> {
|
||||
_ => {
|
||||
cx.sess.bug(format!("ParameterEnvironment::from_item(): \
|
||||
`{}` is not an item",
|
||||
cx.map.node_to_string(id)).as_slice())
|
||||
cx.map.node_to_string(id))[])
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1960,7 +1970,7 @@ impl UnboxedClosureKind {
|
||||
};
|
||||
match result {
|
||||
Ok(trait_did) => trait_did,
|
||||
Err(err) => cx.sess.fatal(err.as_slice()),
|
||||
Err(err) => cx.sess.fatal(err[]),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2178,7 +2188,7 @@ impl FlagComputation {
|
||||
self.add_tys(ts[]);
|
||||
}
|
||||
|
||||
&ty_bare_fn(ref f) => {
|
||||
&ty_bare_fn(_, ref f) => {
|
||||
self.add_fn_sig(&f.sig);
|
||||
}
|
||||
|
||||
@ -2339,15 +2349,19 @@ pub fn mk_closure<'tcx>(cx: &ctxt<'tcx>, fty: ClosureTy<'tcx>) -> Ty<'tcx> {
|
||||
mk_t(cx, ty_closure(box fty))
|
||||
}
|
||||
|
||||
pub fn mk_bare_fn<'tcx>(cx: &ctxt<'tcx>, fty: BareFnTy<'tcx>) -> Ty<'tcx> {
|
||||
mk_t(cx, ty_bare_fn(fty))
|
||||
pub fn mk_bare_fn<'tcx>(cx: &ctxt<'tcx>,
|
||||
opt_def_id: Option<ast::DefId>,
|
||||
fty: BareFnTy<'tcx>) -> Ty<'tcx> {
|
||||
mk_t(cx, ty_bare_fn(opt_def_id, fty))
|
||||
}
|
||||
|
||||
pub fn mk_ctor_fn<'tcx>(cx: &ctxt<'tcx>,
|
||||
def_id: ast::DefId,
|
||||
input_tys: &[Ty<'tcx>],
|
||||
output: Ty<'tcx>) -> Ty<'tcx> {
|
||||
let input_args = input_tys.iter().map(|ty| *ty).collect();
|
||||
mk_bare_fn(cx,
|
||||
Some(def_id),
|
||||
BareFnTy {
|
||||
unsafety: ast::Unsafety::Normal,
|
||||
abi: abi::Rust,
|
||||
@ -2446,7 +2460,7 @@ pub fn maybe_walk_ty<'tcx>(ty: Ty<'tcx>, f: |Ty<'tcx>| -> bool) {
|
||||
}
|
||||
}
|
||||
ty_tup(ref ts) => { for tt in ts.iter() { maybe_walk_ty(*tt, |x| f(x)); } }
|
||||
ty_bare_fn(ref ft) => {
|
||||
ty_bare_fn(_, ref ft) => {
|
||||
for a in ft.sig.0.inputs.iter() { maybe_walk_ty(*a, |x| f(x)); }
|
||||
if let ty::FnConverging(output) = ft.sig.0.output {
|
||||
maybe_walk_ty(output, f);
|
||||
@ -2596,7 +2610,7 @@ pub fn sequence_element_type<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
|
||||
ty_str => mk_mach_uint(ast::TyU8),
|
||||
ty_open(ty) => sequence_element_type(cx, ty),
|
||||
_ => cx.sess.bug(format!("sequence_element_type called on non-sequence value: {}",
|
||||
ty_to_string(cx, ty)).as_slice()),
|
||||
ty_to_string(cx, ty))[]),
|
||||
}
|
||||
}
|
||||
|
||||
@ -2929,7 +2943,7 @@ pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents {
|
||||
// Scalar and unique types are sendable, and durable
|
||||
ty_infer(ty::FreshIntTy(_)) |
|
||||
ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) |
|
||||
ty_bare_fn(_) | ty::ty_char => {
|
||||
ty_bare_fn(..) | ty::ty_char => {
|
||||
TC::None
|
||||
}
|
||||
|
||||
@ -2972,7 +2986,7 @@ pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents {
|
||||
ty_struct(did, ref substs) => {
|
||||
let flds = struct_fields(cx, did, substs);
|
||||
let mut res =
|
||||
TypeContents::union(flds.as_slice(),
|
||||
TypeContents::union(flds[],
|
||||
|f| tc_mt(cx, f.mt, cache));
|
||||
|
||||
if !lookup_repr_hints(cx, did).contains(&attr::ReprExtern) {
|
||||
@ -2989,21 +3003,21 @@ pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents {
|
||||
// FIXME(#14449): `borrowed_contents` below assumes `&mut`
|
||||
// unboxed closure.
|
||||
let upvars = unboxed_closure_upvars(cx, did, substs);
|
||||
TypeContents::union(upvars.as_slice(),
|
||||
TypeContents::union(upvars[],
|
||||
|f| tc_ty(cx, f.ty, cache)) |
|
||||
borrowed_contents(r, MutMutable)
|
||||
}
|
||||
|
||||
ty_tup(ref tys) => {
|
||||
TypeContents::union(tys.as_slice(),
|
||||
TypeContents::union(tys[],
|
||||
|ty| tc_ty(cx, *ty, cache))
|
||||
}
|
||||
|
||||
ty_enum(did, ref substs) => {
|
||||
let variants = substd_enum_variants(cx, did, substs);
|
||||
let mut res =
|
||||
TypeContents::union(variants.as_slice(), |variant| {
|
||||
TypeContents::union(variant.args.as_slice(),
|
||||
TypeContents::union(variants[], |variant| {
|
||||
TypeContents::union(variant.args[],
|
||||
|arg_ty| {
|
||||
tc_ty(cx, *arg_ty, cache)
|
||||
})
|
||||
@ -3068,7 +3082,7 @@ pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents {
|
||||
kind_bounds_to_contents(
|
||||
cx,
|
||||
tp_def.bounds.builtin_bounds,
|
||||
tp_def.bounds.trait_bounds.as_slice())
|
||||
tp_def.bounds.trait_bounds[])
|
||||
}
|
||||
|
||||
ty_infer(_) => {
|
||||
@ -3264,7 +3278,7 @@ pub fn is_instantiable<'tcx>(cx: &ctxt<'tcx>, r_ty: Ty<'tcx>) -> bool {
|
||||
ty_uint(_) |
|
||||
ty_float(_) |
|
||||
ty_str |
|
||||
ty_bare_fn(_) |
|
||||
ty_bare_fn(..) |
|
||||
ty_closure(_) |
|
||||
ty_infer(_) |
|
||||
ty_err |
|
||||
@ -3560,6 +3574,13 @@ pub fn type_is_bare_fn(ty: Ty) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn type_is_bare_fn_item(ty: Ty) -> bool {
|
||||
match ty.sty {
|
||||
ty_bare_fn(Some(_), _) => true,
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
||||
pub fn type_is_fp(ty: Ty) -> bool {
|
||||
match ty.sty {
|
||||
ty_infer(FloatVar(_)) | ty_float(_) => true,
|
||||
@ -3658,7 +3679,7 @@ pub fn close_type<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
|
||||
match ty.sty {
|
||||
ty_open(ty) => mk_rptr(cx, ReStatic, mt {ty: ty, mutbl:ast::MutImmutable}),
|
||||
_ => cx.sess.bug(format!("Trying to close a non-open type {}",
|
||||
ty_to_string(cx, ty)).as_slice())
|
||||
ty_to_string(cx, ty))[])
|
||||
}
|
||||
}
|
||||
|
||||
@ -3759,7 +3780,7 @@ pub fn node_id_to_trait_ref<'tcx>(cx: &ctxt<'tcx>, id: ast::NodeId)
|
||||
Some(ty) => ty.clone(),
|
||||
None => cx.sess.bug(
|
||||
format!("node_id_to_trait_ref: no trait ref for node `{}`",
|
||||
cx.map.node_to_string(id)).as_slice())
|
||||
cx.map.node_to_string(id))[])
|
||||
}
|
||||
}
|
||||
|
||||
@ -3772,7 +3793,7 @@ pub fn node_id_to_type<'tcx>(cx: &ctxt<'tcx>, id: ast::NodeId) -> Ty<'tcx> {
|
||||
Some(ty) => ty,
|
||||
None => cx.sess.bug(
|
||||
format!("node_id_to_type: no type for node `{}`",
|
||||
cx.map.node_to_string(id)).as_slice())
|
||||
cx.map.node_to_string(id))[])
|
||||
}
|
||||
}
|
||||
|
||||
@ -3792,7 +3813,7 @@ pub fn node_id_item_substs<'tcx>(cx: &ctxt<'tcx>, id: ast::NodeId) -> ItemSubsts
|
||||
|
||||
pub fn fn_is_variadic(fty: Ty) -> bool {
|
||||
match fty.sty {
|
||||
ty_bare_fn(ref f) => f.sig.0.variadic,
|
||||
ty_bare_fn(_, ref f) => f.sig.0.variadic,
|
||||
ty_closure(ref f) => f.sig.0.variadic,
|
||||
ref s => {
|
||||
panic!("fn_is_variadic() called on non-fn type: {}", s)
|
||||
@ -3802,7 +3823,7 @@ pub fn fn_is_variadic(fty: Ty) -> bool {
|
||||
|
||||
pub fn ty_fn_sig<'tcx>(fty: Ty<'tcx>) -> &'tcx PolyFnSig<'tcx> {
|
||||
match fty.sty {
|
||||
ty_bare_fn(ref f) => &f.sig,
|
||||
ty_bare_fn(_, ref f) => &f.sig,
|
||||
ty_closure(ref f) => &f.sig,
|
||||
ref s => {
|
||||
panic!("ty_fn_sig() called on non-fn type: {}", s)
|
||||
@ -3813,7 +3834,7 @@ pub fn ty_fn_sig<'tcx>(fty: Ty<'tcx>) -> &'tcx PolyFnSig<'tcx> {
|
||||
/// Returns the ABI of the given function.
|
||||
pub fn ty_fn_abi(fty: Ty) -> abi::Abi {
|
||||
match fty.sty {
|
||||
ty_bare_fn(ref f) => f.abi,
|
||||
ty_bare_fn(_, ref f) => f.abi,
|
||||
ty_closure(ref f) => f.abi,
|
||||
_ => panic!("ty_fn_abi() called on non-fn type"),
|
||||
}
|
||||
@ -3840,7 +3861,7 @@ pub fn ty_closure_store(fty: Ty) -> TraitStore {
|
||||
|
||||
pub fn ty_fn_ret<'tcx>(fty: Ty<'tcx>) -> FnOutput<'tcx> {
|
||||
match fty.sty {
|
||||
ty_bare_fn(ref f) => f.sig.0.output,
|
||||
ty_bare_fn(_, ref f) => f.sig.0.output,
|
||||
ty_closure(ref f) => f.sig.0.output,
|
||||
ref s => {
|
||||
panic!("ty_fn_ret() called on non-fn type: {}", s)
|
||||
@ -3850,7 +3871,7 @@ pub fn ty_fn_ret<'tcx>(fty: Ty<'tcx>) -> FnOutput<'tcx> {
|
||||
|
||||
pub fn is_fn_ty(fty: Ty) -> bool {
|
||||
match fty.sty {
|
||||
ty_bare_fn(_) => true,
|
||||
ty_bare_fn(..) => true,
|
||||
ty_closure(_) => true,
|
||||
_ => false
|
||||
}
|
||||
@ -3865,7 +3886,7 @@ pub fn ty_region(tcx: &ctxt,
|
||||
tcx.sess.span_bug(
|
||||
span,
|
||||
format!("ty_region() invoked on an inappropriate ty: {}",
|
||||
s).as_slice());
|
||||
s)[]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3926,11 +3947,11 @@ pub fn expr_span(cx: &ctxt, id: NodeId) -> Span {
|
||||
Some(f) => {
|
||||
cx.sess.bug(format!("Node id {} is not an expr: {}",
|
||||
id,
|
||||
f).as_slice());
|
||||
f)[]);
|
||||
}
|
||||
None => {
|
||||
cx.sess.bug(format!("Node id {} is not present \
|
||||
in the node map", id).as_slice());
|
||||
in the node map", id)[]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3946,14 +3967,14 @@ pub fn local_var_name_str(cx: &ctxt, id: NodeId) -> InternedString {
|
||||
cx.sess.bug(
|
||||
format!("Variable id {} maps to {}, not local",
|
||||
id,
|
||||
pat).as_slice());
|
||||
pat)[]);
|
||||
}
|
||||
}
|
||||
}
|
||||
r => {
|
||||
cx.sess.bug(format!("Variable id {} maps to {}, not local",
|
||||
id,
|
||||
r).as_slice());
|
||||
r)[]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3975,9 +3996,9 @@ pub fn adjust_ty<'tcx, F>(cx: &ctxt<'tcx>,
|
||||
return match adjustment {
|
||||
Some(adjustment) => {
|
||||
match *adjustment {
|
||||
AdjustAddEnv(store) => {
|
||||
AdjustAddEnv(_, store) => {
|
||||
match unadjusted_ty.sty {
|
||||
ty::ty_bare_fn(ref b) => {
|
||||
ty::ty_bare_fn(Some(_), ref b) => {
|
||||
let bounds = ty::ExistentialBounds {
|
||||
region_bound: ReStatic,
|
||||
builtin_bounds: all_builtin_bounds(),
|
||||
@ -3994,13 +4015,27 @@ pub fn adjust_ty<'tcx, F>(cx: &ctxt<'tcx>,
|
||||
}
|
||||
ref b => {
|
||||
cx.sess.bug(
|
||||
format!("add_env adjustment on non-bare-fn: \
|
||||
format!("add_env adjustment on non-fn-item: \
|
||||
{}",
|
||||
b).as_slice());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AdjustReifyFnPointer(_) => {
|
||||
match unadjusted_ty.sty {
|
||||
ty::ty_bare_fn(Some(_), ref b) => {
|
||||
ty::mk_bare_fn(cx, None, (*b).clone())
|
||||
}
|
||||
ref b => {
|
||||
cx.sess.bug(
|
||||
format!("AdjustReifyFnPointer adjustment on non-fn-item: \
|
||||
{}",
|
||||
b)[]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AdjustDerefRef(ref adj) => {
|
||||
let mut adjusted_ty = unadjusted_ty;
|
||||
|
||||
@ -4024,7 +4059,7 @@ pub fn adjust_ty<'tcx, F>(cx: &ctxt<'tcx>,
|
||||
{}",
|
||||
i,
|
||||
ty_to_string(cx, adjusted_ty))
|
||||
.as_slice());
|
||||
[]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4087,7 +4122,7 @@ pub fn unsize_ty<'tcx>(cx: &ctxt<'tcx>,
|
||||
}
|
||||
_ => cx.sess.span_bug(span,
|
||||
format!("UnsizeLength with bad sty: {}",
|
||||
ty_to_string(cx, ty)).as_slice())
|
||||
ty_to_string(cx, ty))[])
|
||||
},
|
||||
&UnsizeStruct(box ref k, tp_index) => match ty.sty {
|
||||
ty_struct(did, ref substs) => {
|
||||
@ -4099,7 +4134,7 @@ pub fn unsize_ty<'tcx>(cx: &ctxt<'tcx>,
|
||||
}
|
||||
_ => cx.sess.span_bug(span,
|
||||
format!("UnsizeStruct with bad sty: {}",
|
||||
ty_to_string(cx, ty)).as_slice())
|
||||
ty_to_string(cx, ty))[])
|
||||
},
|
||||
&UnsizeVtable(TyTrait { ref principal, bounds }, _) => {
|
||||
mk_trait(cx, (*principal).clone(), bounds)
|
||||
@ -4112,7 +4147,7 @@ pub fn resolve_expr(tcx: &ctxt, expr: &ast::Expr) -> def::Def {
|
||||
Some(&def) => def,
|
||||
None => {
|
||||
tcx.sess.span_bug(expr.span, format!(
|
||||
"no def-map entry for expr {}", expr.id).as_slice());
|
||||
"no def-map entry for expr {}", expr.id)[]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4206,7 +4241,7 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind {
|
||||
expr.span,
|
||||
format!("uncategorized def for expr {}: {}",
|
||||
expr.id,
|
||||
def).as_slice());
|
||||
def)[]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4331,7 +4366,7 @@ pub fn field_idx_strict(tcx: &ctxt, name: ast::Name, fields: &[field])
|
||||
token::get_name(name),
|
||||
fields.iter()
|
||||
.map(|f| token::get_name(f.name).get().to_string())
|
||||
.collect::<Vec<String>>()).as_slice());
|
||||
.collect::<Vec<String>>())[]);
|
||||
}
|
||||
|
||||
pub fn impl_or_trait_item_idx(id: ast::Name, trait_items: &[ImplOrTraitItem])
|
||||
@ -4353,7 +4388,8 @@ pub fn ty_sort_string<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> String {
|
||||
ty_vec(_, None) => "slice".to_string(),
|
||||
ty_ptr(_) => "*-ptr".to_string(),
|
||||
ty_rptr(_, _) => "&-ptr".to_string(),
|
||||
ty_bare_fn(_) => "extern fn".to_string(),
|
||||
ty_bare_fn(Some(_), _) => format!("fn item"),
|
||||
ty_bare_fn(None, _) => "fn pointer".to_string(),
|
||||
ty_closure(_) => "fn".to_string(),
|
||||
ty_trait(ref inner) => {
|
||||
format!("trait {}", item_path_str(cx, inner.principal.def_id()))
|
||||
@ -4544,6 +4580,10 @@ pub fn note_and_explain_type_err(cx: &ctxt, err: &type_err) {
|
||||
"concrete lifetime that was found is ",
|
||||
conc_region, "");
|
||||
}
|
||||
terr_regions_overly_polymorphic(_, ty::ReInfer(ty::ReVar(_))) => {
|
||||
// don't bother to print out the message below for
|
||||
// inference variables, it's not very illuminating.
|
||||
}
|
||||
terr_regions_overly_polymorphic(_, conc_region) => {
|
||||
note_and_explain_region(cx,
|
||||
"expected concrete lifetime is ",
|
||||
@ -4565,7 +4605,7 @@ pub fn provided_trait_methods<'tcx>(cx: &ctxt<'tcx>, id: ast::DefId)
|
||||
match item.node {
|
||||
ItemTrait(_, _, _, _, ref ms) => {
|
||||
let (_, p) =
|
||||
ast_util::split_trait_methods(ms.as_slice());
|
||||
ast_util::split_trait_methods(ms[]);
|
||||
p.iter()
|
||||
.map(|m| {
|
||||
match impl_or_trait_item(
|
||||
@ -4584,14 +4624,14 @@ pub fn provided_trait_methods<'tcx>(cx: &ctxt<'tcx>, id: ast::DefId)
|
||||
_ => {
|
||||
cx.sess.bug(format!("provided_trait_methods: `{}` is \
|
||||
not a trait",
|
||||
id).as_slice())
|
||||
id)[])
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
cx.sess.bug(format!("provided_trait_methods: `{}` is not a \
|
||||
trait",
|
||||
id).as_slice())
|
||||
id)[])
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -4827,7 +4867,7 @@ impl<'tcx> VariantInfo<'tcx> {
|
||||
},
|
||||
ast::StructVariantKind(ref struct_def) => {
|
||||
|
||||
let fields: &[StructField] = struct_def.fields.as_slice();
|
||||
let fields: &[StructField] = struct_def.fields[];
|
||||
|
||||
assert!(fields.len() > 0);
|
||||
|
||||
@ -4978,7 +5018,7 @@ pub fn enum_variants<'tcx>(cx: &ctxt<'tcx>, id: ast::DefId)
|
||||
cx.sess
|
||||
.span_err(e.span,
|
||||
format!("expected constant: {}",
|
||||
*err).as_slice());
|
||||
*err)[]);
|
||||
}
|
||||
},
|
||||
None => {}
|
||||
@ -5258,7 +5298,7 @@ pub fn lookup_struct_fields(cx: &ctxt, did: ast::DefId) -> Vec<field_ty> {
|
||||
_ => {
|
||||
cx.sess.bug(
|
||||
format!("ID not mapped to struct fields: {}",
|
||||
cx.map.node_to_string(did.node)).as_slice());
|
||||
cx.map.node_to_string(did.node))[]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -5291,7 +5331,7 @@ pub fn struct_fields<'tcx>(cx: &ctxt<'tcx>, did: ast::DefId, substs: &Substs<'tc
|
||||
pub fn tup_fields<'tcx>(v: &[Ty<'tcx>]) -> Vec<field<'tcx>> {
|
||||
v.iter().enumerate().map(|(i, &f)| {
|
||||
field {
|
||||
name: token::intern(i.to_string().as_slice()),
|
||||
name: token::intern(i.to_string()[]),
|
||||
mt: mt {
|
||||
ty: f,
|
||||
mutbl: MutImmutable
|
||||
@ -5470,7 +5510,7 @@ pub fn eval_repeat_count(tcx: &ctxt, count_expr: &ast::Expr) -> uint {
|
||||
};
|
||||
tcx.sess.span_err(count_expr.span, format!(
|
||||
"expected positive integer for repeat count, found {}",
|
||||
found).as_slice());
|
||||
found)[]);
|
||||
}
|
||||
Err(_) => {
|
||||
let found = match count_expr.node {
|
||||
@ -5485,7 +5525,7 @@ pub fn eval_repeat_count(tcx: &ctxt, count_expr: &ast::Expr) -> uint {
|
||||
};
|
||||
tcx.sess.span_err(count_expr.span, format!(
|
||||
"expected constant integer for repeat count, found {}",
|
||||
found).as_slice());
|
||||
found)[]);
|
||||
}
|
||||
}
|
||||
0
|
||||
@ -5884,8 +5924,9 @@ pub fn hash_crate_independent<'tcx>(tcx: &ctxt<'tcx>, ty: Ty<'tcx>, svh: &Svh) -
|
||||
region(state, r);
|
||||
mt(state, m);
|
||||
}
|
||||
ty_bare_fn(ref b) => {
|
||||
ty_bare_fn(opt_def_id, ref b) => {
|
||||
byte!(14);
|
||||
hash!(opt_def_id);
|
||||
hash!(b.unsafety);
|
||||
hash!(b.abi);
|
||||
fn_sig(state, &b.sig);
|
||||
@ -6200,7 +6241,7 @@ pub fn accumulate_lifetimes_in_type(accumulator: &mut Vec<ty::Region>,
|
||||
ty_str |
|
||||
ty_vec(_, _) |
|
||||
ty_ptr(_) |
|
||||
ty_bare_fn(_) |
|
||||
ty_bare_fn(..) |
|
||||
ty_tup(_) |
|
||||
ty_param(_) |
|
||||
ty_infer(_) |
|
||||
@ -6223,7 +6264,7 @@ pub fn accumulate_lifetimes_in_type(accumulator: &mut Vec<ty::Region>,
|
||||
}
|
||||
|
||||
/// A free variable referred to in a function.
|
||||
#[deriving(Copy, Encodable, Decodable)]
|
||||
#[deriving(Copy, RustcEncodable, RustcDecodable)]
|
||||
pub struct Freevar {
|
||||
/// The variable being accessed free.
|
||||
pub def: def::Def,
|
||||
@ -6244,7 +6285,7 @@ pub fn with_freevars<T, F>(tcx: &ty::ctxt, fid: ast::NodeId, f: F) -> T where
|
||||
{
|
||||
match tcx.freevars.borrow().get(&fid) {
|
||||
None => f(&[]),
|
||||
Some(d) => f(d.as_slice())
|
||||
Some(d) => f(d[])
|
||||
}
|
||||
}
|
||||
|
||||
@ -6252,6 +6293,7 @@ impl<'tcx> AutoAdjustment<'tcx> {
|
||||
pub fn is_identity(&self) -> bool {
|
||||
match *self {
|
||||
AdjustAddEnv(..) => false,
|
||||
AdjustReifyFnPointer(..) => false,
|
||||
AdjustDerefRef(ref r) => r.is_identity(),
|
||||
}
|
||||
}
|
||||
@ -6367,8 +6409,11 @@ impl DebruijnIndex {
|
||||
impl<'tcx> Repr<'tcx> for AutoAdjustment<'tcx> {
|
||||
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
|
||||
match *self {
|
||||
AdjustAddEnv(ref trait_store) => {
|
||||
format!("AdjustAddEnv({})", trait_store)
|
||||
AdjustAddEnv(def_id, ref trait_store) => {
|
||||
format!("AdjustAddEnv({},{})", def_id.repr(tcx), trait_store)
|
||||
}
|
||||
AdjustReifyFnPointer(def_id) => {
|
||||
format!("AdjustAddEnv({})", def_id.repr(tcx))
|
||||
}
|
||||
AdjustDerefRef(ref data) => {
|
||||
data.repr(tcx)
|
||||
|
@ -538,8 +538,8 @@ pub fn super_fold_ty<'tcx, T: TypeFolder<'tcx>>(this: &mut T,
|
||||
ty::ty_tup(ref ts) => {
|
||||
ty::ty_tup(ts.fold_with(this))
|
||||
}
|
||||
ty::ty_bare_fn(ref f) => {
|
||||
ty::ty_bare_fn(f.fold_with(this))
|
||||
ty::ty_bare_fn(opt_def_id, ref f) => {
|
||||
ty::ty_bare_fn(opt_def_id, f.fold_with(this))
|
||||
}
|
||||
ty::ty_closure(ref f) => {
|
||||
ty::ty_closure(box f.fold_with(this))
|
||||
|
@ -141,17 +141,17 @@ impl<'a> PluginLoader<'a> {
|
||||
// this is fatal: there are almost certainly macros we need
|
||||
// inside this crate, so continue would spew "macro undefined"
|
||||
// errors
|
||||
Err(err) => self.sess.span_fatal(vi.span, err.as_slice())
|
||||
Err(err) => self.sess.span_fatal(vi.span, err[])
|
||||
};
|
||||
|
||||
unsafe {
|
||||
let registrar =
|
||||
match lib.symbol(symbol.as_slice()) {
|
||||
match lib.symbol(symbol[]) {
|
||||
Ok(registrar) => {
|
||||
mem::transmute::<*mut u8,PluginRegistrarFun>(registrar)
|
||||
}
|
||||
// again fatal if we can't register macros
|
||||
Err(err) => self.sess.span_fatal(vi.span, err.as_slice())
|
||||
Err(err) => self.sess.span_fatal(vi.span, err[])
|
||||
};
|
||||
|
||||
self.plugins.registrars.push(registrar);
|
||||
|
@ -34,7 +34,6 @@ use syntax::parse::token::InternedString;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::collections::hash_map::Entry::{Occupied, Vacant};
|
||||
use getopts::{optopt, optmulti, optflag, optflagopt};
|
||||
use getopts;
|
||||
use std::cell::{RefCell};
|
||||
use std::fmt;
|
||||
@ -278,7 +277,8 @@ debugging_opts! {
|
||||
PRINT_REGION_GRAPH,
|
||||
PARSE_ONLY,
|
||||
NO_TRANS,
|
||||
NO_ANALYSIS
|
||||
NO_ANALYSIS,
|
||||
UNSTABLE_OPTIONS
|
||||
]
|
||||
0
|
||||
}
|
||||
@ -330,7 +330,8 @@ pub fn debugging_opts_map() -> Vec<(&'static str, &'static str, u64)> {
|
||||
("no-trans", "Run all passes except translation; no output", NO_TRANS),
|
||||
("no-analysis", "Parse and expand the source, but run no analysis and",
|
||||
NO_TRANS),
|
||||
]
|
||||
("unstable-options", "Adds unstable command line options to rustc interface",
|
||||
UNSTABLE_OPTIONS)]
|
||||
}
|
||||
|
||||
#[deriving(Clone)]
|
||||
@ -555,17 +556,17 @@ pub fn build_codegen_options(matches: &getopts::Matches) -> CodegenOptions
|
||||
match (value, opt_type_desc) {
|
||||
(Some(..), None) => {
|
||||
early_error(format!("codegen option `{}` takes no \
|
||||
value", key).as_slice())
|
||||
value", key)[])
|
||||
}
|
||||
(None, Some(type_desc)) => {
|
||||
early_error(format!("codegen option `{0}` requires \
|
||||
{1} (-C {0}=<value>)",
|
||||
key, type_desc).as_slice())
|
||||
key, type_desc)[])
|
||||
}
|
||||
(Some(value), Some(type_desc)) => {
|
||||
early_error(format!("incorrect value `{}` for codegen \
|
||||
option `{}` - {} was expected",
|
||||
value, key, type_desc).as_slice())
|
||||
value, key, type_desc)[])
|
||||
}
|
||||
(None, None) => unreachable!()
|
||||
}
|
||||
@ -575,7 +576,7 @@ pub fn build_codegen_options(matches: &getopts::Matches) -> CodegenOptions
|
||||
}
|
||||
if !found {
|
||||
early_error(format!("unknown codegen option: `{}`",
|
||||
key).as_slice());
|
||||
key)[]);
|
||||
}
|
||||
}
|
||||
return cg;
|
||||
@ -588,10 +589,10 @@ pub fn default_lib_output() -> CrateType {
|
||||
pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
|
||||
use syntax::parse::token::intern_and_get_ident as intern;
|
||||
|
||||
let end = sess.target.target.target_endian.as_slice();
|
||||
let arch = sess.target.target.arch.as_slice();
|
||||
let wordsz = sess.target.target.target_word_size.as_slice();
|
||||
let os = sess.target.target.target_os.as_slice();
|
||||
let end = sess.target.target.target_endian[];
|
||||
let arch = sess.target.target.arch[];
|
||||
let wordsz = sess.target.target.target_word_size[];
|
||||
let os = sess.target.target.target_os[];
|
||||
|
||||
let fam = match sess.target.target.options.is_like_windows {
|
||||
true => InternedString::new("windows"),
|
||||
@ -627,23 +628,23 @@ pub fn build_configuration(sess: &Session) -> ast::CrateConfig {
|
||||
append_configuration(&mut user_cfg, InternedString::new("test"))
|
||||
}
|
||||
let mut v = user_cfg.into_iter().collect::<Vec<_>>();
|
||||
v.push_all(default_cfg.as_slice());
|
||||
v.push_all(default_cfg[]);
|
||||
v
|
||||
}
|
||||
|
||||
pub fn build_target_config(opts: &Options, sp: &SpanHandler) -> Config {
|
||||
let target = match Target::search(opts.target_triple.as_slice()) {
|
||||
let target = match Target::search(opts.target_triple[]) {
|
||||
Ok(t) => t,
|
||||
Err(e) => {
|
||||
sp.handler().fatal((format!("Error loading target specification: {}", e)).as_slice());
|
||||
sp.handler().fatal((format!("Error loading target specification: {}", e))[]);
|
||||
}
|
||||
};
|
||||
|
||||
let (int_type, uint_type) = match target.target_word_size.as_slice() {
|
||||
let (int_type, uint_type) = match target.target_word_size[] {
|
||||
"32" => (ast::TyI32, ast::TyU32),
|
||||
"64" => (ast::TyI64, ast::TyU64),
|
||||
w => sp.handler().fatal((format!("target specification was invalid: unrecognized \
|
||||
target-word-size {}", w)).as_slice())
|
||||
target-word-size {}", w))[])
|
||||
};
|
||||
|
||||
Config {
|
||||
@ -653,95 +654,179 @@ pub fn build_target_config(opts: &Options, sp: &SpanHandler) -> Config {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the "short" subset of the stable rustc command line options.
|
||||
pub fn short_optgroups() -> Vec<getopts::OptGroup> {
|
||||
rustc_short_optgroups().into_iter()
|
||||
.filter(|g|g.is_stable())
|
||||
.map(|g|g.opt_group)
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Returns all of the stable rustc command line options.
|
||||
pub fn optgroups() -> Vec<getopts::OptGroup> {
|
||||
rustc_optgroups().into_iter()
|
||||
.filter(|g|g.is_stable())
|
||||
.map(|g|g.opt_group)
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[deriving(Copy, Clone, PartialEq, Eq, Show)]
|
||||
pub enum OptionStability { Stable, Unstable }
|
||||
|
||||
#[deriving(Clone, PartialEq, Eq)]
|
||||
pub struct RustcOptGroup {
|
||||
pub opt_group: getopts::OptGroup,
|
||||
pub stability: OptionStability,
|
||||
}
|
||||
|
||||
impl RustcOptGroup {
|
||||
pub fn is_stable(&self) -> bool {
|
||||
self.stability == OptionStability::Stable
|
||||
}
|
||||
|
||||
fn stable(g: getopts::OptGroup) -> RustcOptGroup {
|
||||
RustcOptGroup { opt_group: g, stability: OptionStability::Stable }
|
||||
}
|
||||
|
||||
fn unstable(g: getopts::OptGroup) -> RustcOptGroup {
|
||||
RustcOptGroup { opt_group: g, stability: OptionStability::Unstable }
|
||||
}
|
||||
}
|
||||
|
||||
// The `opt` local module holds wrappers around the `getopts` API that
|
||||
// adds extra rustc-specific metadata to each option; such metadata
|
||||
// is exposed by . The public
|
||||
// functions below ending with `_u` are the functions that return
|
||||
// *unstable* options, i.e. options that are only enabled when the
|
||||
// user also passes the `-Z unstable-options` debugging flag.
|
||||
mod opt {
|
||||
// The `fn opt_u` etc below are written so that we can use them
|
||||
// in the future; do not warn about them not being used right now.
|
||||
#![allow(dead_code)]
|
||||
|
||||
use getopts;
|
||||
use super::RustcOptGroup;
|
||||
|
||||
type R = RustcOptGroup;
|
||||
type S<'a> = &'a str;
|
||||
|
||||
fn stable(g: getopts::OptGroup) -> R { RustcOptGroup::stable(g) }
|
||||
fn unstable(g: getopts::OptGroup) -> R { RustcOptGroup::unstable(g) }
|
||||
|
||||
// FIXME (pnkfelix): We default to stable since the current set of
|
||||
// options is defacto stable. However, it would be good to revise the
|
||||
// code so that a stable option is the thing that takes extra effort
|
||||
// to encode.
|
||||
|
||||
pub fn opt(a: S, b: S, c: S, d: S) -> R { stable(getopts::optopt(a, b, c, d)) }
|
||||
pub fn multi(a: S, b: S, c: S, d: S) -> R { stable(getopts::optmulti(a, b, c, d)) }
|
||||
pub fn flag(a: S, b: S, c: S) -> R { stable(getopts::optflag(a, b, c)) }
|
||||
pub fn flagopt(a: S, b: S, c: S, d: S) -> R { stable(getopts::optflagopt(a, b, c, d)) }
|
||||
|
||||
pub fn opt_u(a: S, b: S, c: S, d: S) -> R { unstable(getopts::optopt(a, b, c, d)) }
|
||||
pub fn multi_u(a: S, b: S, c: S, d: S) -> R { unstable(getopts::optmulti(a, b, c, d)) }
|
||||
pub fn flag_u(a: S, b: S, c: S) -> R { unstable(getopts::optflag(a, b, c)) }
|
||||
pub fn flagopt_u(a: S, b: S, c: S, d: S) -> R { unstable(getopts::optflagopt(a, b, c, d)) }
|
||||
}
|
||||
|
||||
/// Returns the "short" subset of the rustc command line options,
|
||||
/// including metadata for each option, such as whether the option is
|
||||
/// part of the stable long-term interface for rustc.
|
||||
pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
|
||||
vec![
|
||||
optflag("h", "help", "Display this message"),
|
||||
optmulti("", "cfg", "Configure the compilation environment", "SPEC"),
|
||||
optmulti("L", "", "Add a directory to the library search path", "PATH"),
|
||||
optmulti("l", "", "Link the generated crate(s) to the specified native
|
||||
opt::flag("h", "help", "Display this message"),
|
||||
opt::multi("", "cfg", "Configure the compilation environment", "SPEC"),
|
||||
opt::multi("L", "", "Add a directory to the library search path", "PATH"),
|
||||
opt::multi("l", "", "Link the generated crate(s) to the specified native
|
||||
library NAME. The optional KIND can be one of,
|
||||
static, dylib, or framework. If omitted, dylib is
|
||||
assumed.", "NAME[:KIND]"),
|
||||
optmulti("", "crate-type", "Comma separated list of types of crates
|
||||
opt::multi("", "crate-type", "Comma separated list of types of crates
|
||||
for the compiler to emit",
|
||||
"[bin|lib|rlib|dylib|staticlib|dep-info]"),
|
||||
optopt("", "crate-name", "Specify the name of the crate being built",
|
||||
"[bin|lib|rlib|dylib|staticlib]"),
|
||||
opt::opt("", "crate-name", "Specify the name of the crate being built",
|
||||
"NAME"),
|
||||
optmulti("", "emit", "Comma separated list of types of output for \
|
||||
opt::multi("", "emit", "Comma separated list of types of output for \
|
||||
the compiler to emit",
|
||||
"[asm|llvm-bc|llvm-ir|obj|link]"),
|
||||
optmulti("", "print", "Comma separated list of compiler information to \
|
||||
"[asm|llvm-bc|llvm-ir|obj|link|dep-info]"),
|
||||
opt::multi("", "print", "Comma separated list of compiler information to \
|
||||
print on stdout",
|
||||
"[crate-name|output-file-names|sysroot]"),
|
||||
optflag("g", "", "Equivalent to --debuginfo=2"),
|
||||
optflag("O", "", "Equivalent to --opt-level=2"),
|
||||
optopt("o", "", "Write output to <filename>", "FILENAME"),
|
||||
optopt("", "out-dir", "Write output to compiler-chosen filename \
|
||||
opt::flag("g", "", "Equivalent to -C debuginfo=2"),
|
||||
opt::flag("O", "", "Equivalent to -C opt-level=2"),
|
||||
opt::opt("o", "", "Write output to <filename>", "FILENAME"),
|
||||
opt::opt("", "out-dir", "Write output to compiler-chosen filename \
|
||||
in <dir>", "DIR"),
|
||||
optopt("", "explain", "Provide a detailed explanation of an error \
|
||||
opt::opt("", "explain", "Provide a detailed explanation of an error \
|
||||
message", "OPT"),
|
||||
optflag("", "test", "Build a test harness"),
|
||||
optopt("", "target", "Target triple cpu-manufacturer-kernel[-os] \
|
||||
opt::flag("", "test", "Build a test harness"),
|
||||
opt::opt("", "target", "Target triple cpu-manufacturer-kernel[-os] \
|
||||
to compile for (see chapter 3.4 of \
|
||||
http://www.sourceware.org/autobook/
|
||||
for details)",
|
||||
"TRIPLE"),
|
||||
optmulti("W", "warn", "Set lint warnings", "OPT"),
|
||||
optmulti("A", "allow", "Set lint allowed", "OPT"),
|
||||
optmulti("D", "deny", "Set lint denied", "OPT"),
|
||||
optmulti("F", "forbid", "Set lint forbidden", "OPT"),
|
||||
optmulti("C", "codegen", "Set a codegen option", "OPT[=VALUE]"),
|
||||
optflag("V", "version", "Print version info and exit"),
|
||||
optflag("v", "verbose", "Use verbose output"),
|
||||
opt::multi("W", "warn", "Set lint warnings", "OPT"),
|
||||
opt::multi("A", "allow", "Set lint allowed", "OPT"),
|
||||
opt::multi("D", "deny", "Set lint denied", "OPT"),
|
||||
opt::multi("F", "forbid", "Set lint forbidden", "OPT"),
|
||||
opt::multi("C", "codegen", "Set a codegen option", "OPT[=VALUE]"),
|
||||
opt::flag("V", "version", "Print version info and exit"),
|
||||
opt::flag("v", "verbose", "Use verbose output"),
|
||||
]
|
||||
}
|
||||
|
||||
// rustc command line options
|
||||
pub fn optgroups() -> Vec<getopts::OptGroup> {
|
||||
let mut opts = short_optgroups();
|
||||
/// Returns all rustc command line options, including metadata for
|
||||
/// each option, such as whether the option is part of the stable
|
||||
/// long-term interface for rustc.
|
||||
pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
|
||||
let mut opts = rustc_short_optgroups();
|
||||
opts.push_all(&[
|
||||
optmulti("", "extern", "Specify where an external rust library is \
|
||||
opt::multi("", "extern", "Specify where an external rust library is \
|
||||
located",
|
||||
"NAME=PATH"),
|
||||
optopt("", "opt-level", "Optimize with possible levels 0-3", "LEVEL"),
|
||||
optopt("", "sysroot", "Override the system root", "PATH"),
|
||||
optmulti("Z", "", "Set internal debugging options", "FLAG"),
|
||||
optopt("", "color", "Configure coloring of output:
|
||||
opt::opt("", "opt-level", "Optimize with possible levels 0-3", "LEVEL"),
|
||||
opt::opt("", "sysroot", "Override the system root", "PATH"),
|
||||
opt::multi("Z", "", "Set internal debugging options", "FLAG"),
|
||||
opt::opt("", "color", "Configure coloring of output:
|
||||
auto = colorize, if output goes to a tty (default);
|
||||
always = always colorize output;
|
||||
never = never colorize output", "auto|always|never"),
|
||||
|
||||
// DEPRECATED
|
||||
optflag("", "print-crate-name", "Output the crate name and exit"),
|
||||
optflag("", "print-file-name", "Output the file(s) that would be \
|
||||
opt::flag("", "print-crate-name", "Output the crate name and exit"),
|
||||
opt::flag("", "print-file-name", "Output the file(s) that would be \
|
||||
written if compilation \
|
||||
continued and exit"),
|
||||
optopt("", "debuginfo", "Emit DWARF debug info to the objects created:
|
||||
opt::opt("", "debuginfo", "Emit DWARF debug info to the objects created:
|
||||
0 = no debug info,
|
||||
1 = line-tables only (for stacktraces and breakpoints),
|
||||
2 = full debug info with variable and type information \
|
||||
(same as -g)", "LEVEL"),
|
||||
optflag("", "no-trans", "Run all passes except translation; no output"),
|
||||
optflag("", "no-analysis", "Parse and expand the source, but run no \
|
||||
opt::flag("", "no-trans", "Run all passes except translation; no output"),
|
||||
opt::flag("", "no-analysis", "Parse and expand the source, but run no \
|
||||
analysis and produce no output"),
|
||||
optflag("", "parse-only", "Parse only; do not compile, assemble, \
|
||||
opt::flag("", "parse-only", "Parse only; do not compile, assemble, \
|
||||
or link"),
|
||||
optflagopt("", "pretty",
|
||||
opt::flagopt("", "pretty",
|
||||
"Pretty-print the input instead of compiling;
|
||||
valid types are: `normal` (un-annotated source),
|
||||
`expanded` (crates expanded),
|
||||
`typed` (crates expanded, with type annotations),
|
||||
`expanded,identified` (fully parenthesized, AST nodes with IDs), or
|
||||
`flowgraph=<nodeid>` (graphviz formatted flowgraph for node)",
|
||||
`typed` (crates expanded, with type annotations), or
|
||||
`expanded,identified` (fully parenthesized, AST nodes with IDs).",
|
||||
"TYPE"),
|
||||
optflagopt("", "dep-info",
|
||||
opt::flagopt_u("", "xpretty",
|
||||
"Pretty-print the input instead of compiling, unstable variants;
|
||||
valid types are any of the types for `--pretty`, as well as:
|
||||
`flowgraph=<nodeid>` (graphviz formatted flowgraph for node), or
|
||||
`everybody_loops` (all function bodies replaced with `loop {}`).",
|
||||
"TYPE"),
|
||||
opt::flagopt("", "dep-info",
|
||||
"Output dependency info to <filename> after compiling, \
|
||||
in a format suitable for use by Makefiles", "FILENAME"),
|
||||
]);
|
||||
opts
|
||||
}
|
||||
|
||||
|
||||
// Convert strings provided as --cfg [cfgspec] into a crate_cfg
|
||||
pub fn parse_cfgspecs(cfgspecs: Vec<String> ) -> ast::CrateConfig {
|
||||
cfgspecs.into_iter().map(|s| {
|
||||
@ -756,7 +841,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
|
||||
|
||||
let unparsed_crate_types = matches.opt_strs("crate-type");
|
||||
let crate_types = parse_crate_types_from_list(unparsed_crate_types)
|
||||
.unwrap_or_else(|e| early_error(e.as_slice()));
|
||||
.unwrap_or_else(|e| early_error(e[]));
|
||||
|
||||
let mut lint_opts = vec!();
|
||||
let mut describe_lints = false;
|
||||
@ -766,7 +851,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
|
||||
if lint_name == "help" {
|
||||
describe_lints = true;
|
||||
} else {
|
||||
lint_opts.push((lint_name.replace("-", "_").into_string(), level));
|
||||
lint_opts.push((lint_name.replace("-", "_"), level));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -784,7 +869,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
|
||||
}
|
||||
if this_bit == 0 {
|
||||
early_error(format!("unknown debug flag: {}",
|
||||
*debug_flag).as_slice())
|
||||
*debug_flag)[])
|
||||
}
|
||||
debugging_opts |= this_bit;
|
||||
}
|
||||
@ -829,7 +914,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
|
||||
"dep-info" => OutputTypeDepInfo,
|
||||
_ => {
|
||||
early_error(format!("unknown emission type: `{}`",
|
||||
part).as_slice())
|
||||
part)[])
|
||||
}
|
||||
};
|
||||
output_types.push(output_type)
|
||||
@ -868,7 +953,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
|
||||
Some(arg) => {
|
||||
early_error(format!("optimization level needs to be \
|
||||
between 0-3 (instead was `{}`)",
|
||||
arg).as_slice());
|
||||
arg)[]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -906,7 +991,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
|
||||
Some(arg) => {
|
||||
early_error(format!("debug info level needs to be between \
|
||||
0-2 (instead was `{}`)",
|
||||
arg).as_slice());
|
||||
arg)[]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -923,7 +1008,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
|
||||
};
|
||||
|
||||
let addl_lib_search_paths = matches.opt_strs("L").iter().map(|s| {
|
||||
Path::new(s.as_slice())
|
||||
Path::new(s[])
|
||||
}).collect();
|
||||
|
||||
let libs = matches.opt_strs("l").into_iter().map(|s| {
|
||||
@ -937,7 +1022,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
|
||||
(_, s) => {
|
||||
early_error(format!("unknown library kind `{}`, expected \
|
||||
one of dylib, framework, or static",
|
||||
s).as_slice());
|
||||
s)[]);
|
||||
}
|
||||
};
|
||||
(name.to_string(), kind)
|
||||
@ -982,7 +1067,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
|
||||
// --debuginfo");
|
||||
}
|
||||
|
||||
let color = match matches.opt_str("color").as_ref().map(|s| s.as_slice()) {
|
||||
let color = match matches.opt_str("color").as_ref().map(|s| s[]) {
|
||||
Some("auto") => Auto,
|
||||
Some("always") => Always,
|
||||
Some("never") => Never,
|
||||
@ -992,7 +1077,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
|
||||
Some(arg) => {
|
||||
early_error(format!("argument for --color must be auto, always \
|
||||
or never (instead was `{}`)",
|
||||
arg).as_slice())
|
||||
arg)[])
|
||||
}
|
||||
};
|
||||
|
||||
@ -1093,7 +1178,7 @@ mod test {
|
||||
#[test]
|
||||
fn test_switch_implies_cfg_test() {
|
||||
let matches =
|
||||
&match getopts(&["--test".to_string()], optgroups().as_slice()) {
|
||||
&match getopts(&["--test".to_string()], optgroups()[]) {
|
||||
Ok(m) => m,
|
||||
Err(f) => panic!("test_switch_implies_cfg_test: {}", f)
|
||||
};
|
||||
@ -1101,7 +1186,7 @@ mod test {
|
||||
let sessopts = build_session_options(matches);
|
||||
let sess = build_session(sessopts, None, registry);
|
||||
let cfg = build_configuration(&sess);
|
||||
assert!((attr::contains_name(cfg.as_slice(), "test")));
|
||||
assert!((attr::contains_name(cfg[], "test")));
|
||||
}
|
||||
|
||||
// When the user supplies --test and --cfg test, don't implicitly add
|
||||
@ -1110,7 +1195,7 @@ mod test {
|
||||
fn test_switch_implies_cfg_test_unless_cfg_test() {
|
||||
let matches =
|
||||
&match getopts(&["--test".to_string(), "--cfg=test".to_string()],
|
||||
optgroups().as_slice()) {
|
||||
optgroups()[]) {
|
||||
Ok(m) => m,
|
||||
Err(f) => {
|
||||
panic!("test_switch_implies_cfg_test_unless_cfg_test: {}", f)
|
||||
@ -1130,7 +1215,7 @@ mod test {
|
||||
{
|
||||
let matches = getopts(&[
|
||||
"-Awarnings".to_string()
|
||||
], optgroups().as_slice()).unwrap();
|
||||
], optgroups()[]).unwrap();
|
||||
let registry = diagnostics::registry::Registry::new(&[]);
|
||||
let sessopts = build_session_options(&matches);
|
||||
let sess = build_session(sessopts, None, registry);
|
||||
@ -1141,7 +1226,7 @@ mod test {
|
||||
let matches = getopts(&[
|
||||
"-Awarnings".to_string(),
|
||||
"-Dwarnings".to_string()
|
||||
], optgroups().as_slice()).unwrap();
|
||||
], optgroups()[]).unwrap();
|
||||
let registry = diagnostics::registry::Registry::new(&[]);
|
||||
let sessopts = build_session_options(&matches);
|
||||
let sess = build_session(sessopts, None, registry);
|
||||
@ -1151,7 +1236,7 @@ mod test {
|
||||
{
|
||||
let matches = getopts(&[
|
||||
"-Adead_code".to_string()
|
||||
], optgroups().as_slice()).unwrap();
|
||||
], optgroups()[]).unwrap();
|
||||
let registry = diagnostics::registry::Registry::new(&[]);
|
||||
let sessopts = build_session_options(&matches);
|
||||
let sess = build_session(sessopts, None, registry);
|
||||
|
@ -172,7 +172,7 @@ impl Session {
|
||||
// cases later on
|
||||
pub fn impossible_case(&self, sp: Span, msg: &str) -> ! {
|
||||
self.span_bug(sp,
|
||||
format!("impossible case reached: {}", msg).as_slice());
|
||||
format!("impossible case reached: {}", msg)[]);
|
||||
}
|
||||
pub fn verbose(&self) -> bool { self.debugging_opt(config::VERBOSE) }
|
||||
pub fn time_passes(&self) -> bool { self.debugging_opt(config::TIME_PASSES) }
|
||||
@ -211,7 +211,7 @@ impl Session {
|
||||
}
|
||||
pub fn target_filesearch<'a>(&'a self) -> filesearch::FileSearch<'a> {
|
||||
filesearch::FileSearch::new(self.sysroot(),
|
||||
self.opts.target_triple.as_slice(),
|
||||
self.opts.target_triple[],
|
||||
&self.opts.addl_lib_search_paths)
|
||||
}
|
||||
pub fn host_filesearch<'a>(&'a self) -> filesearch::FileSearch<'a> {
|
||||
|
@ -14,6 +14,7 @@ use std::cell::{RefCell, Cell};
|
||||
use std::collections::HashMap;
|
||||
use std::fmt::Show;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::iter::repeat;
|
||||
use std::time::Duration;
|
||||
|
||||
use syntax::ast;
|
||||
@ -48,7 +49,7 @@ pub fn time<T, U, F>(do_it: bool, what: &str, u: U, f: F) -> T where
|
||||
};
|
||||
let rv = rv.unwrap();
|
||||
|
||||
println!("{}time: {}.{:03} \t{}", " ".repeat(old),
|
||||
println!("{}time: {}.{:03} \t{}", repeat(" ").take(old).collect::<String>(),
|
||||
dur.num_seconds(), dur.num_milliseconds() % 1000, what);
|
||||
DEPTH.with(|slot| slot.set(old));
|
||||
|
||||
|
63
src/librustc/util/lev_distance.rs
Normal file
63
src/librustc/util/lev_distance.rs
Normal file
@ -0,0 +1,63 @@
|
||||
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::cmp;
|
||||
|
||||
pub fn lev_distance(me: &str, t: &str) -> uint {
|
||||
if me.is_empty() { return t.chars().count(); }
|
||||
if t.is_empty() { return me.chars().count(); }
|
||||
|
||||
let mut dcol = Vec::from_fn(t.len() + 1, |x| x);
|
||||
let mut t_last = 0;
|
||||
|
||||
for (i, sc) in me.chars().enumerate() {
|
||||
|
||||
let mut current = i;
|
||||
dcol[0] = current + 1;
|
||||
|
||||
for (j, tc) in t.chars().enumerate() {
|
||||
|
||||
let next = dcol[j + 1];
|
||||
|
||||
if sc == tc {
|
||||
dcol[j + 1] = current;
|
||||
} else {
|
||||
dcol[j + 1] = cmp::min(current, next);
|
||||
dcol[j + 1] = cmp::min(dcol[j + 1], dcol[j]) + 1;
|
||||
}
|
||||
|
||||
current = next;
|
||||
t_last = j;
|
||||
}
|
||||
}
|
||||
|
||||
dcol[t_last + 1]
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_lev_distance() {
|
||||
use std::char::{ from_u32, MAX };
|
||||
// Test bytelength agnosticity
|
||||
for c in range(0u32, MAX as u32)
|
||||
.filter_map(|i| from_u32(i))
|
||||
.map(|i| String::from_char(1, i)) {
|
||||
assert_eq!(lev_distance(c[], c[]), 0);
|
||||
}
|
||||
|
||||
let a = "\nMäry häd ä little lämb\n\nLittle lämb\n";
|
||||
let b = "\nMary häd ä little lämb\n\nLittle lämb\n";
|
||||
let c = "Mary häd ä little lämb\n\nLittle lämb\n";
|
||||
assert_eq!(lev_distance(a, b), 1);
|
||||
assert_eq!(lev_distance(b, a), 1);
|
||||
assert_eq!(lev_distance(a, c), 2);
|
||||
assert_eq!(lev_distance(c, a), 2);
|
||||
assert_eq!(lev_distance(b, c), 1);
|
||||
assert_eq!(lev_distance(c, b), 1);
|
||||
}
|
@ -55,12 +55,12 @@ pub fn note_and_explain_region(cx: &ctxt,
|
||||
(ref str, Some(span)) => {
|
||||
cx.sess.span_note(
|
||||
span,
|
||||
format!("{}{}{}", prefix, *str, suffix).as_slice());
|
||||
format!("{}{}{}", prefix, *str, suffix)[]);
|
||||
Some(span)
|
||||
}
|
||||
(ref str, None) => {
|
||||
cx.sess.note(
|
||||
format!("{}{}{}", prefix, *str, suffix).as_slice());
|
||||
format!("{}{}{}", prefix, *str, suffix)[]);
|
||||
None
|
||||
}
|
||||
}
|
||||
@ -254,12 +254,14 @@ pub fn vec_map_to_string<T, F>(ts: &[T], f: F) -> String where
|
||||
|
||||
pub fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String {
|
||||
fn bare_fn_to_string<'tcx>(cx: &ctxt<'tcx>,
|
||||
opt_def_id: Option<ast::DefId>,
|
||||
unsafety: ast::Unsafety,
|
||||
abi: abi::Abi,
|
||||
ident: Option<ast::Ident>,
|
||||
sig: &ty::PolyFnSig<'tcx>)
|
||||
-> String {
|
||||
let mut s = String::new();
|
||||
|
||||
match unsafety {
|
||||
ast::Unsafety::Normal => {}
|
||||
ast::Unsafety::Unsafe => {
|
||||
@ -269,7 +271,7 @@ pub fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String {
|
||||
};
|
||||
|
||||
if abi != abi::Rust {
|
||||
s.push_str(format!("extern {} ", abi.to_string()).as_slice());
|
||||
s.push_str(format!("extern {} ", abi.to_string())[]);
|
||||
};
|
||||
|
||||
s.push_str("fn");
|
||||
@ -284,6 +286,16 @@ pub fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String {
|
||||
|
||||
push_sig_to_string(cx, &mut s, '(', ')', sig, "");
|
||||
|
||||
match opt_def_id {
|
||||
Some(def_id) => {
|
||||
s.push_str(" {");
|
||||
let path_str = ty::item_path_str(cx, def_id);
|
||||
s.push_str(path_str[]);
|
||||
s.push_str("}");
|
||||
}
|
||||
None => { }
|
||||
}
|
||||
|
||||
s
|
||||
}
|
||||
|
||||
@ -293,7 +305,7 @@ pub fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String {
|
||||
match cty.store {
|
||||
ty::UniqTraitStore => {}
|
||||
ty::RegionTraitStore(region, _) => {
|
||||
s.push_str(region_to_string(cx, "", true, region).as_slice());
|
||||
s.push_str(region_to_string(cx, "", true, region)[]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -312,7 +324,7 @@ pub fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String {
|
||||
assert_eq!(cty.onceness, ast::Once);
|
||||
s.push_str("proc");
|
||||
push_sig_to_string(cx, &mut s, '(', ')', &cty.sig,
|
||||
bounds_str.as_slice());
|
||||
bounds_str[]);
|
||||
}
|
||||
ty::RegionTraitStore(..) => {
|
||||
match cty.onceness {
|
||||
@ -320,7 +332,7 @@ pub fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String {
|
||||
ast::Once => s.push_str("once ")
|
||||
}
|
||||
push_sig_to_string(cx, &mut s, '|', '|', &cty.sig,
|
||||
bounds_str.as_slice());
|
||||
bounds_str[]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -353,7 +365,7 @@ pub fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String {
|
||||
ty::FnConverging(t) => {
|
||||
if !ty::type_is_nil(t) {
|
||||
s.push_str(" -> ");
|
||||
s.push_str(ty_to_string(cx, t).as_slice());
|
||||
s.push_str(ty_to_string(cx, t)[]);
|
||||
}
|
||||
}
|
||||
ty::FnDiverging => {
|
||||
@ -390,7 +402,7 @@ pub fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String {
|
||||
}
|
||||
ty_rptr(r, ref tm) => {
|
||||
let mut buf = region_ptr_to_string(cx, r);
|
||||
buf.push_str(mt_to_string(cx, tm).as_slice());
|
||||
buf.push_str(mt_to_string(cx, tm)[]);
|
||||
buf
|
||||
}
|
||||
ty_open(typ) =>
|
||||
@ -400,7 +412,7 @@ pub fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String {
|
||||
.iter()
|
||||
.map(|elem| ty_to_string(cx, *elem))
|
||||
.collect::<Vec<_>>();
|
||||
match strs.as_slice() {
|
||||
match strs[] {
|
||||
[ref string] => format!("({},)", string),
|
||||
strs => format!("({})", strs.connect(", "))
|
||||
}
|
||||
@ -408,8 +420,8 @@ pub fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String {
|
||||
ty_closure(ref f) => {
|
||||
closure_to_string(cx, &**f)
|
||||
}
|
||||
ty_bare_fn(ref f) => {
|
||||
bare_fn_to_string(cx, f.unsafety, f.abi, None, &f.sig)
|
||||
ty_bare_fn(opt_def_id, ref f) => {
|
||||
bare_fn_to_string(cx, opt_def_id, f.unsafety, f.abi, None, &f.sig)
|
||||
}
|
||||
ty_infer(infer_ty) => infer_ty_to_string(cx, infer_ty),
|
||||
ty_err => "[type error]".to_string(),
|
||||
@ -551,7 +563,7 @@ pub fn parameterized<'tcx>(cx: &ctxt<'tcx>,
|
||||
pub fn ty_to_short_str<'tcx>(cx: &ctxt<'tcx>, typ: Ty<'tcx>) -> String {
|
||||
let mut s = typ.repr(cx).to_string();
|
||||
if s.len() >= 32u {
|
||||
s = s.slice(0u, 32u).to_string();
|
||||
s = s[0u..32u].to_string();
|
||||
}
|
||||
return s;
|
||||
}
|
||||
@ -616,7 +628,7 @@ impl<'tcx, T:Repr<'tcx>> Repr<'tcx> for [T] {
|
||||
|
||||
impl<'tcx, T:Repr<'tcx>> Repr<'tcx> for OwnedSlice<T> {
|
||||
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
|
||||
repr_vec(tcx, self.as_slice())
|
||||
repr_vec(tcx, self[])
|
||||
}
|
||||
}
|
||||
|
||||
@ -624,7 +636,7 @@ impl<'tcx, T:Repr<'tcx>> Repr<'tcx> for OwnedSlice<T> {
|
||||
// autoderef cannot convert the &[T] handler
|
||||
impl<'tcx, T:Repr<'tcx>> Repr<'tcx> for Vec<T> {
|
||||
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
|
||||
repr_vec(tcx, self.as_slice())
|
||||
repr_vec(tcx, self[])
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ fn run_ar(handler: &ErrorHandler, maybe_ar_prog: &Option<String>,
|
||||
args: &str, cwd: Option<&Path>,
|
||||
paths: &[&Path]) -> ProcessOutput {
|
||||
let ar = match *maybe_ar_prog {
|
||||
Some(ref ar) => ar.as_slice(),
|
||||
Some(ref ar) => ar[],
|
||||
None => "ar"
|
||||
};
|
||||
let mut cmd = Command::new(ar);
|
||||
@ -75,22 +75,22 @@ fn run_ar(handler: &ErrorHandler, maybe_ar_prog: &Option<String>,
|
||||
if !o.status.success() {
|
||||
handler.err(format!("{} failed with: {}",
|
||||
cmd,
|
||||
o.status).as_slice());
|
||||
o.status)[]);
|
||||
handler.note(format!("stdout ---\n{}",
|
||||
str::from_utf8(o.output
|
||||
.as_slice()).unwrap())
|
||||
.as_slice());
|
||||
[]).unwrap())
|
||||
[]);
|
||||
handler.note(format!("stderr ---\n{}",
|
||||
str::from_utf8(o.error
|
||||
.as_slice()).unwrap())
|
||||
.as_slice());
|
||||
[]).unwrap())
|
||||
[]);
|
||||
handler.abort_if_errors();
|
||||
}
|
||||
o
|
||||
},
|
||||
Err(e) => {
|
||||
handler.err(format!("could not exec `{}`: {}", ar.as_slice(),
|
||||
e).as_slice());
|
||||
handler.err(format!("could not exec `{}`: {}", ar[],
|
||||
e)[]);
|
||||
handler.abort_if_errors();
|
||||
panic!("rustc::back::archive::run_ar() should not reach this point");
|
||||
}
|
||||
@ -106,16 +106,16 @@ pub fn find_library(name: &str, osprefix: &str, ossuffix: &str,
|
||||
|
||||
for path in search_paths.iter() {
|
||||
debug!("looking for {} inside {}", name, path.display());
|
||||
let test = path.join(oslibname.as_slice());
|
||||
let test = path.join(oslibname[]);
|
||||
if test.exists() { return test }
|
||||
if oslibname != unixlibname {
|
||||
let test = path.join(unixlibname.as_slice());
|
||||
let test = path.join(unixlibname[]);
|
||||
if test.exists() { return test }
|
||||
}
|
||||
}
|
||||
handler.fatal(format!("could not find native static library `{}`, \
|
||||
perhaps an -L flag is missing?",
|
||||
name).as_slice());
|
||||
name)[]);
|
||||
}
|
||||
|
||||
impl<'a> Archive<'a> {
|
||||
@ -147,7 +147,7 @@ impl<'a> Archive<'a> {
|
||||
/// Lists all files in an archive
|
||||
pub fn files(&self) -> Vec<String> {
|
||||
let output = run_ar(self.handler, &self.maybe_ar_prog, "t", None, &[&self.dst]);
|
||||
let output = str::from_utf8(output.output.as_slice()).unwrap();
|
||||
let output = str::from_utf8(output.output[]).unwrap();
|
||||
// use lines_any because windows delimits output with `\r\n` instead of
|
||||
// just `\n`
|
||||
output.lines_any().map(|s| s.to_string()).collect()
|
||||
@ -179,9 +179,9 @@ impl<'a> ArchiveBuilder<'a> {
|
||||
/// search in the relevant locations for a library named `name`.
|
||||
pub fn add_native_library(&mut self, name: &str) -> io::IoResult<()> {
|
||||
let location = find_library(name,
|
||||
self.archive.slib_prefix.as_slice(),
|
||||
self.archive.slib_suffix.as_slice(),
|
||||
self.archive.lib_search_paths.as_slice(),
|
||||
self.archive.slib_prefix[],
|
||||
self.archive.slib_suffix[],
|
||||
self.archive.lib_search_paths[],
|
||||
self.archive.handler);
|
||||
self.add_archive(&location, name, |_| false)
|
||||
}
|
||||
@ -197,12 +197,12 @@ impl<'a> ArchiveBuilder<'a> {
|
||||
// as simple comparison is not enough - there
|
||||
// might be also an extra name suffix
|
||||
let obj_start = format!("{}", name);
|
||||
let obj_start = obj_start.as_slice();
|
||||
let obj_start = obj_start[];
|
||||
// Ignoring all bytecode files, no matter of
|
||||
// name
|
||||
let bc_ext = ".bytecode.deflate";
|
||||
|
||||
self.add_archive(rlib, name.as_slice(), |fname: &str| {
|
||||
self.add_archive(rlib, name[], |fname: &str| {
|
||||
let skip_obj = lto && fname.starts_with(obj_start)
|
||||
&& fname.ends_with(".o");
|
||||
skip_obj || fname.ends_with(bc_ext) || fname == METADATA_FILENAME
|
||||
@ -239,7 +239,7 @@ impl<'a> ArchiveBuilder<'a> {
|
||||
// allow running `ar s file.a` to update symbols only.
|
||||
if self.should_update_symbols {
|
||||
run_ar(self.archive.handler, &self.archive.maybe_ar_prog,
|
||||
"s", Some(self.work_dir.path()), args.as_slice());
|
||||
"s", Some(self.work_dir.path()), args[]);
|
||||
}
|
||||
return self.archive;
|
||||
}
|
||||
@ -259,7 +259,7 @@ impl<'a> ArchiveBuilder<'a> {
|
||||
// Add the archive members seen so far, without updating the
|
||||
// symbol table (`S`).
|
||||
run_ar(self.archive.handler, &self.archive.maybe_ar_prog,
|
||||
"cruS", Some(self.work_dir.path()), args.as_slice());
|
||||
"cruS", Some(self.work_dir.path()), args[]);
|
||||
|
||||
args.clear();
|
||||
args.push(&abs_dst);
|
||||
@ -274,7 +274,7 @@ impl<'a> ArchiveBuilder<'a> {
|
||||
// necessary.
|
||||
let flags = if self.should_update_symbols { "crus" } else { "cruS" };
|
||||
run_ar(self.archive.handler, &self.archive.maybe_ar_prog,
|
||||
flags, Some(self.work_dir.path()), args.as_slice());
|
||||
flags, Some(self.work_dir.path()), args[]);
|
||||
|
||||
self.archive
|
||||
}
|
||||
@ -316,7 +316,7 @@ impl<'a> ArchiveBuilder<'a> {
|
||||
} else {
|
||||
filename
|
||||
};
|
||||
let new_filename = self.work_dir.path().join(filename.as_slice());
|
||||
let new_filename = self.work_dir.path().join(filename[]);
|
||||
try!(fs::rename(file, &new_filename));
|
||||
self.members.push(Path::new(filename));
|
||||
}
|
||||
|
@ -44,15 +44,15 @@ pub fn get_rpath_flags<F, G>(config: RPathConfig<F, G>) -> Vec<String> where
|
||||
l.map(|p| p.clone())
|
||||
}).collect::<Vec<_>>();
|
||||
|
||||
let rpaths = get_rpaths(config, libs.as_slice());
|
||||
flags.push_all(rpaths_to_flags(rpaths.as_slice()).as_slice());
|
||||
let rpaths = get_rpaths(config, libs[]);
|
||||
flags.push_all(rpaths_to_flags(rpaths[])[]);
|
||||
flags
|
||||
}
|
||||
|
||||
fn rpaths_to_flags(rpaths: &[String]) -> Vec<String> {
|
||||
let mut ret = Vec::new();
|
||||
for rpath in rpaths.iter() {
|
||||
ret.push(format!("-Wl,-rpath,{}", (*rpath).as_slice()));
|
||||
ret.push(format!("-Wl,-rpath,{}", (*rpath)[]));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -82,14 +82,14 @@ fn get_rpaths<F, G>(mut config: RPathConfig<F, G>, libs: &[Path]) -> Vec<String>
|
||||
}
|
||||
}
|
||||
|
||||
log_rpaths("relative", rel_rpaths.as_slice());
|
||||
log_rpaths("fallback", fallback_rpaths.as_slice());
|
||||
log_rpaths("relative", rel_rpaths[]);
|
||||
log_rpaths("fallback", fallback_rpaths[]);
|
||||
|
||||
let mut rpaths = rel_rpaths;
|
||||
rpaths.push_all(fallback_rpaths.as_slice());
|
||||
rpaths.push_all(fallback_rpaths[]);
|
||||
|
||||
// Remove duplicates
|
||||
let rpaths = minimize_rpaths(rpaths.as_slice());
|
||||
let rpaths = minimize_rpaths(rpaths[]);
|
||||
return rpaths;
|
||||
}
|
||||
|
||||
@ -140,7 +140,7 @@ fn minimize_rpaths(rpaths: &[String]) -> Vec<String> {
|
||||
let mut set = HashSet::new();
|
||||
let mut minimized = Vec::new();
|
||||
for rpath in rpaths.iter() {
|
||||
if set.insert(rpath.as_slice()) {
|
||||
if set.insert(rpath[]) {
|
||||
minimized.push(rpath.clone());
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ impl Svh {
|
||||
}
|
||||
|
||||
pub fn as_str<'a>(&'a self) -> &'a str {
|
||||
self.hash.as_slice()
|
||||
self.hash[]
|
||||
}
|
||||
|
||||
pub fn calculate(metadata: &Vec<String>, krate: &ast::Crate) -> Svh {
|
||||
@ -358,7 +358,7 @@ mod svh_visitor {
|
||||
fn macro_name(macro: &Mac) -> token::InternedString {
|
||||
match ¯o.node {
|
||||
&MacInvocTT(ref path, ref _tts, ref _stx_ctxt) => {
|
||||
let s = path.segments.as_slice();
|
||||
let s = path.segments[];
|
||||
assert_eq!(s.len(), 1);
|
||||
content(s[0].identifier)
|
||||
}
|
||||
|
@ -224,7 +224,7 @@ impl Target {
|
||||
Some(val) => val,
|
||||
None =>
|
||||
handler.fatal((format!("Field {} in target specification is required", name))
|
||||
.as_slice())
|
||||
[])
|
||||
}
|
||||
};
|
||||
|
||||
@ -365,7 +365,7 @@ impl Target {
|
||||
|
||||
let target_path = os::getenv("RUST_TARGET_PATH").unwrap_or(String::new());
|
||||
|
||||
let paths = os::split_paths(target_path.as_slice());
|
||||
let paths = os::split_paths(target_path[]);
|
||||
// FIXME 16351: add a sane default search path?
|
||||
|
||||
for dir in paths.iter() {
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user