auto merge of #18719 : alexcrichton/rust/rollup, r=alexcrichton
This commit is contained in:
commit
45cbdec417
201 changed files with 3508 additions and 2441 deletions
|
|
@ -51,7 +51,7 @@
|
|||
|
||||
TARGET_CRATES := libc std green native flate arena term \
|
||||
serialize sync getopts collections test time rand \
|
||||
log regex graphviz core rbml rlibc alloc rustrt \
|
||||
log regex graphviz core rbml alloc rustrt \
|
||||
unicode
|
||||
HOST_CRATES := syntax rustc rustdoc regex_macros fmt_macros \
|
||||
rustc_llvm rustc_back
|
||||
|
|
@ -60,7 +60,6 @@ TOOLS := compiletest rustdoc rustc
|
|||
|
||||
DEPS_core :=
|
||||
DEPS_libc := core
|
||||
DEPS_rlibc := core
|
||||
DEPS_unicode := core
|
||||
DEPS_alloc := core libc native:jemalloc
|
||||
DEPS_rustrt := alloc core libc collections native:rustrt_native
|
||||
|
|
@ -104,7 +103,6 @@ TOOL_SOURCE_rustc := $(S)src/driver/driver.rs
|
|||
|
||||
ONLY_RLIB_core := 1
|
||||
ONLY_RLIB_libc := 1
|
||||
ONLY_RLIB_rlibc := 1
|
||||
ONLY_RLIB_alloc := 1
|
||||
ONLY_RLIB_rand := 1
|
||||
ONLY_RLIB_collections := 1
|
||||
|
|
|
|||
|
|
@ -155,6 +155,7 @@ endif
|
|||
RUSTFLAGS_STAGE0 += -C prefer-dynamic
|
||||
RUSTFLAGS_STAGE1 += -C prefer-dynamic
|
||||
RUST_LIB_FLAGS_ST2 += -C prefer-dynamic
|
||||
RUST_LIB_FLAGS_ST3 += -C prefer-dynamic
|
||||
|
||||
# Landing pads require a lot of codegen. We can get through bootstrapping faster
|
||||
# by not emitting them.
|
||||
|
|
|
|||
|
|
@ -677,7 +677,9 @@ CTEST_DEPS_cfail_$(1)-T-$(2)-H-$(3) = $$(CFAIL_TESTS)
|
|||
CTEST_DEPS_bench_$(1)-T-$(2)-H-$(3) = $$(BENCH_TESTS)
|
||||
CTEST_DEPS_perf_$(1)-T-$(2)-H-$(3) = $$(PERF_TESTS)
|
||||
CTEST_DEPS_debuginfo-gdb_$(1)-T-$(2)-H-$(3) = $$(DEBUGINFO_GDB_TESTS)
|
||||
CTEST_DEPS_debuginfo-lldb_$(1)-T-$(2)-H-$(3) = $$(DEBUGINFO_LLDB_TESTS)
|
||||
CTEST_DEPS_debuginfo-lldb_$(1)-T-$(2)-H-$(3) = $$(DEBUGINFO_LLDB_TESTS) \
|
||||
$(S)src/etc/lldb_batchmode.py \
|
||||
$(S)src/etc/lldb_rust_formatters.py
|
||||
CTEST_DEPS_codegen_$(1)-T-$(2)-H-$(3) = $$(CODEGEN_TESTS)
|
||||
|
||||
endef
|
||||
|
|
|
|||
|
|
@ -1149,7 +1149,7 @@ enum StringResult {
|
|||
}
|
||||
```
|
||||
Where a `StringResult` is either an `StringOK`, with the result of a computation, or an
|
||||
`ErrorReason` with a `String` explaining what caused the computation to fail. This kind of
|
||||
`ErrorReason` with a `String` explaining what caused the computation to fail. These kinds of
|
||||
`enum`s are actually very useful and are even part of the standard library.
|
||||
|
||||
As you can see `enum`s with values are quite a powerful tool for data representation,
|
||||
|
|
@ -1901,8 +1901,8 @@ result is a link to
|
|||
click on that result, we'll be taken to its documentation page.
|
||||
|
||||
This page shows us a few things: the type signature of the function, some
|
||||
explanatory text, and then an example. Let's modify our code to add in the
|
||||
`random` function:
|
||||
explanatory text, and then an example. Let's try to modify our code to add in the
|
||||
`random` function and see what happens:
|
||||
|
||||
```{rust,ignore}
|
||||
use std::io;
|
||||
|
|
|
|||
|
|
@ -1961,8 +1961,10 @@ On an `extern` block, the following attributes are interpreted:
|
|||
name and type. This is feature gated and the exact behavior is
|
||||
implementation-defined (due to variety of linker invocation syntax).
|
||||
- `link` - indicate that a native library should be linked to for the
|
||||
declarations in this block to be linked correctly. See [external
|
||||
blocks](#external-blocks)
|
||||
declarations in this block to be linked correctly. `link` supports an optional `kind`
|
||||
key with three possible values: `dylib`, `static`, and `framework`. See [external blocks](#external-blocks) for more about external blocks. Two
|
||||
examples: `#[link(name = "readline")]` and
|
||||
`#[link(name = "CoreFoundation", kind = "framework")]`.
|
||||
|
||||
On declarations inside an `extern` block, the following attributes are
|
||||
interpreted:
|
||||
|
|
|
|||
|
|
@ -28,8 +28,10 @@ import lldb
|
|||
import os
|
||||
import sys
|
||||
import threading
|
||||
import thread
|
||||
import re
|
||||
import atexit
|
||||
import time
|
||||
|
||||
# Set this to True for additional output
|
||||
DEBUG_OUTPUT = False
|
||||
|
|
@ -130,6 +132,22 @@ def start_breakpoint_listener(target):
|
|||
target.GetBroadcaster().AddListener(listener, lldb.SBTarget.eBroadcastBitBreakpointChanged)
|
||||
|
||||
|
||||
def start_watchdog():
|
||||
"Starts a watchdog thread that will terminate the process after a certain period of time"
|
||||
watchdog_start_time = time.clock()
|
||||
watchdog_max_time = watchdog_start_time + 30
|
||||
|
||||
def watchdog():
|
||||
while time.clock() < watchdog_max_time:
|
||||
time.sleep(1)
|
||||
print("TIMEOUT: lldb_batchmode.py has been running for too long. Aborting!")
|
||||
thread.interrupt_main()
|
||||
|
||||
# Start the listener and let it run as a daemon
|
||||
watchdog_thread = threading.Thread(target = watchdog)
|
||||
watchdog_thread.daemon = True
|
||||
watchdog_thread.start()
|
||||
|
||||
####################################################################################################
|
||||
# ~main
|
||||
####################################################################################################
|
||||
|
|
@ -147,6 +165,9 @@ print("Debugger commands script is '%s'." % script_path)
|
|||
print("Target executable is '%s'." % target_path)
|
||||
print("Current working directory is '%s'" % os.getcwd())
|
||||
|
||||
# Start the timeout watchdog
|
||||
start_watchdog()
|
||||
|
||||
# Create a new debugger instance
|
||||
debugger = lldb.SBDebugger.Create()
|
||||
|
||||
|
|
@ -175,6 +196,10 @@ try:
|
|||
|
||||
for line in script_file:
|
||||
command = line.strip()
|
||||
if command == "run" or command == "r" or re.match("^process\s+launch.*", command):
|
||||
# Before starting to run the program, let the thread sleep a bit, so all
|
||||
# breakpoint added events can be processed
|
||||
time.sleep(0.5)
|
||||
if command != '':
|
||||
execute_command(command_interpreter, command)
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ preamble = '''// Copyright 2012-2014 The Rust Project Developers. See the COPYRI
|
|||
|
||||
// NOTE: The following code was generated by "src/etc/unicode.py", do not edit directly
|
||||
|
||||
#![allow(missing_docs, non_uppercase_statics, non_snake_case)]
|
||||
#![allow(missing_docs, non_upper_case_globals, non_snake_case)]
|
||||
'''
|
||||
|
||||
# Mapping taken from Table 12 from:
|
||||
|
|
|
|||
|
|
@ -48,6 +48,10 @@ impl<T: Default> Default for Box<T> {
|
|||
fn default() -> Box<T> { box Default::default() }
|
||||
}
|
||||
|
||||
impl<T> Default for Box<[T]> {
|
||||
fn default() -> Box<[T]> { box [] }
|
||||
}
|
||||
|
||||
#[unstable]
|
||||
impl<T: Clone> Clone for Box<T> {
|
||||
/// Returns a copy of the owned box.
|
||||
|
|
|
|||
|
|
@ -162,6 +162,8 @@ use core::ptr;
|
|||
use slice;
|
||||
use vec::Vec;
|
||||
|
||||
// FIXME(conventions): implement into_iter
|
||||
|
||||
/// A priority queue implemented with a binary heap.
|
||||
///
|
||||
/// This will be a max-heap.
|
||||
|
|
@ -184,6 +186,7 @@ impl<T: Ord> BinaryHeap<T> {
|
|||
/// use std::collections::BinaryHeap;
|
||||
/// let pq: BinaryHeap<uint> = BinaryHeap::new();
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn new() -> BinaryHeap<T> { BinaryHeap{data: vec!(),} }
|
||||
|
||||
/// Creates an empty `BinaryHeap` with a specific capacity.
|
||||
|
|
@ -197,6 +200,7 @@ impl<T: Ord> BinaryHeap<T> {
|
|||
/// use std::collections::BinaryHeap;
|
||||
/// let pq: BinaryHeap<uint> = BinaryHeap::with_capacity(10u);
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn with_capacity(capacity: uint) -> BinaryHeap<T> {
|
||||
BinaryHeap { data: Vec::with_capacity(capacity) }
|
||||
}
|
||||
|
|
@ -234,6 +238,7 @@ impl<T: Ord> BinaryHeap<T> {
|
|||
/// println!("{}", x);
|
||||
/// }
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn iter<'a>(&'a self) -> Items<'a, T> {
|
||||
Items { iter: self.data.iter() }
|
||||
}
|
||||
|
|
@ -268,10 +273,19 @@ impl<T: Ord> BinaryHeap<T> {
|
|||
/// let pq: BinaryHeap<uint> = BinaryHeap::with_capacity(100u);
|
||||
/// assert!(pq.capacity() >= 100u);
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn capacity(&self) -> uint { self.data.capacity() }
|
||||
|
||||
/// Reserves capacity for exactly `n` elements in the `BinaryHeap`.
|
||||
/// Do nothing if the capacity is already sufficient.
|
||||
/// Reserves the minimum capacity for exactly `additional` more elements to be inserted in the
|
||||
/// given `BinaryHeap`. Does nothing if the capacity is already sufficient.
|
||||
///
|
||||
/// Note that the allocator may give the collection more space than it requests. Therefore
|
||||
/// capacity can not be relied upon to be precisely minimal. Prefer `reserve` if future
|
||||
/// insertions are expected.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if the new capacity overflows `uint`.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
|
|
@ -280,12 +294,17 @@ impl<T: Ord> BinaryHeap<T> {
|
|||
///
|
||||
/// let mut pq: BinaryHeap<uint> = BinaryHeap::new();
|
||||
/// pq.reserve_exact(100u);
|
||||
/// assert!(pq.capacity() == 100u);
|
||||
/// assert!(pq.capacity() >= 100u);
|
||||
/// ```
|
||||
pub fn reserve_exact(&mut self, n: uint) { self.data.reserve_exact(n) }
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn reserve_exact(&mut self, additional: uint) { self.data.reserve_exact(additional) }
|
||||
|
||||
/// Reserves capacity for at least `n` elements in the `BinaryHeap`.
|
||||
/// Do nothing if the capacity is already sufficient.
|
||||
/// Reserves capacity for at least `additional` more elements to be inserted in the
|
||||
/// `BinaryHeap`. The collection may reserve more space to avoid frequent reallocations.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if the new capacity overflows `uint`.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
|
|
@ -296,8 +315,15 @@ impl<T: Ord> BinaryHeap<T> {
|
|||
/// pq.reserve(100u);
|
||||
/// assert!(pq.capacity() >= 100u);
|
||||
/// ```
|
||||
pub fn reserve(&mut self, n: uint) {
|
||||
self.data.reserve(n)
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn reserve(&mut self, additional: uint) {
|
||||
self.data.reserve(additional)
|
||||
}
|
||||
|
||||
/// Discards as much additional capacity as possible.
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn shrink_to_fit(&mut self) {
|
||||
self.data.shrink_to_fit()
|
||||
}
|
||||
|
||||
/// Removes the greatest item from a queue and returns it, or `None` if it
|
||||
|
|
@ -314,6 +340,7 @@ impl<T: Ord> BinaryHeap<T> {
|
|||
/// assert_eq!(pq.pop(), Some(1i));
|
||||
/// assert_eq!(pq.pop(), None);
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn pop(&mut self) -> Option<T> {
|
||||
match self.data.pop() {
|
||||
None => { None }
|
||||
|
|
@ -342,6 +369,7 @@ impl<T: Ord> BinaryHeap<T> {
|
|||
/// assert_eq!(pq.len(), 3);
|
||||
/// assert_eq!(pq.top(), Some(&5i));
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn push(&mut self, item: T) {
|
||||
self.data.push(item);
|
||||
let new_len = self.len() - 1;
|
||||
|
|
@ -495,12 +523,15 @@ impl<T: Ord> BinaryHeap<T> {
|
|||
}
|
||||
|
||||
/// Returns the length of the queue.
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn len(&self) -> uint { self.data.len() }
|
||||
|
||||
/// Returns true if the queue contains no elements
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn is_empty(&self) -> bool { self.len() == 0 }
|
||||
|
||||
/// Drops all items from the queue.
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn clear(&mut self) { self.data.truncate(0) }
|
||||
}
|
||||
|
||||
|
|
@ -528,8 +559,7 @@ impl<T: Ord> Extendable<T> for BinaryHeap<T> {
|
|||
fn extend<Iter: Iterator<T>>(&mut self, mut iter: Iter) {
|
||||
let (lower, _) = iter.size_hint();
|
||||
|
||||
let len = self.capacity();
|
||||
self.reserve(len + lower);
|
||||
self.reserve(lower);
|
||||
|
||||
for elem in iter {
|
||||
self.push(elem);
|
||||
|
|
|
|||
|
|
@ -75,6 +75,8 @@ use std::hash;
|
|||
|
||||
use vec::Vec;
|
||||
|
||||
// FIXME(conventions): look, we just need to refactor this whole thing. Inside and out.
|
||||
|
||||
type MatchWords<'a> = Chain<MaskWords<'a>, Skip<Take<Enumerate<Repeat<u32>>>>>;
|
||||
// Take two BitV's, and return iterators of their words, where the shorter one
|
||||
// has been padded with 0's
|
||||
|
|
@ -216,6 +218,7 @@ impl Bitv {
|
|||
/// use std::collections::Bitv;
|
||||
/// let mut bv = Bitv::new();
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn new() -> Bitv {
|
||||
Bitv { storage: Vec::new(), nbits: 0 }
|
||||
}
|
||||
|
|
@ -613,6 +616,7 @@ impl Bitv {
|
|||
/// bv.truncate(2);
|
||||
/// assert!(bv.eq_vec([false, true]));
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn truncate(&mut self, len: uint) {
|
||||
if len < self.len() {
|
||||
self.nbits = len;
|
||||
|
|
@ -760,14 +764,17 @@ impl Bitv {
|
|||
|
||||
/// Return the total number of bits in this vector
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn len(&self) -> uint { self.nbits }
|
||||
|
||||
/// Returns true if there are no bits in this vector
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn is_empty(&self) -> bool { self.len() == 0 }
|
||||
|
||||
/// Clears all bits in this vector.
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn clear(&mut self) {
|
||||
for w in self.storage.iter_mut() { *w = 0u32; }
|
||||
}
|
||||
|
|
@ -849,8 +856,7 @@ impl Clone for Bitv {
|
|||
#[inline]
|
||||
fn clone_from(&mut self, source: &Bitv) {
|
||||
self.nbits = source.nbits;
|
||||
self.storage.reserve(source.storage.len());
|
||||
for (i, w) in self.storage.iter_mut().enumerate() { *w = source.storage[i]; }
|
||||
self.storage.clone_from(&source.storage);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1052,6 +1058,7 @@ impl BitvSet {
|
|||
/// let mut s = BitvSet::new();
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn new() -> BitvSet {
|
||||
BitvSet(Bitv::new())
|
||||
}
|
||||
|
|
@ -1067,6 +1074,7 @@ impl BitvSet {
|
|||
/// assert!(s.capacity() >= 100);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn with_capacity(nbits: uint) -> BitvSet {
|
||||
let bitv = Bitv::with_capacity(nbits, false);
|
||||
BitvSet::from_bitv(bitv)
|
||||
|
|
@ -1106,6 +1114,7 @@ impl BitvSet {
|
|||
/// assert!(s.capacity() >= 100);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn capacity(&self) -> uint {
|
||||
let &BitvSet(ref bitv) = self;
|
||||
bitv.capacity()
|
||||
|
|
@ -1212,6 +1221,7 @@ impl BitvSet {
|
|||
/// println!("new capacity: {}", s.capacity());
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn shrink_to_fit(&mut self) {
|
||||
let &BitvSet(ref mut bitv) = self;
|
||||
// Obtain original length
|
||||
|
|
@ -1240,6 +1250,7 @@ impl BitvSet {
|
|||
/// }
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn iter<'a>(&'a self) -> BitPositions<'a> {
|
||||
BitPositions {set: self, next_idx: 0u}
|
||||
}
|
||||
|
|
@ -1262,6 +1273,7 @@ impl BitvSet {
|
|||
/// }
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn union<'a>(&'a self, other: &'a BitvSet) -> TwoBitPositions<'a> {
|
||||
TwoBitPositions {
|
||||
set: self,
|
||||
|
|
@ -1290,6 +1302,7 @@ impl BitvSet {
|
|||
/// }
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn intersection<'a>(&'a self, other: &'a BitvSet) -> Take<TwoBitPositions<'a>> {
|
||||
let min = cmp::min(self.capacity(), other.capacity());
|
||||
TwoBitPositions {
|
||||
|
|
@ -1326,6 +1339,7 @@ impl BitvSet {
|
|||
/// }
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn difference<'a>(&'a self, other: &'a BitvSet) -> TwoBitPositions<'a> {
|
||||
TwoBitPositions {
|
||||
set: self,
|
||||
|
|
@ -1355,6 +1369,7 @@ impl BitvSet {
|
|||
/// }
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn symmetric_difference<'a>(&'a self, other: &'a BitvSet) -> TwoBitPositions<'a> {
|
||||
TwoBitPositions {
|
||||
set: self,
|
||||
|
|
@ -1473,6 +1488,7 @@ impl BitvSet {
|
|||
|
||||
/// Return the number of set bits in this set.
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn len(&self) -> uint {
|
||||
let &BitvSet(ref bitv) = self;
|
||||
bitv.storage.iter().fold(0, |acc, &n| acc + n.count_ones())
|
||||
|
|
@ -1480,6 +1496,7 @@ impl BitvSet {
|
|||
|
||||
/// Returns whether there are no bits set in this set
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn is_empty(&self) -> bool {
|
||||
let &BitvSet(ref bitv) = self;
|
||||
bitv.storage.iter().all(|&n| n == 0)
|
||||
|
|
@ -1487,6 +1504,7 @@ impl BitvSet {
|
|||
|
||||
/// Clears all bits in this set
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn clear(&mut self) {
|
||||
let &BitvSet(ref mut bitv) = self;
|
||||
bitv.clear();
|
||||
|
|
@ -1494,6 +1512,7 @@ impl BitvSet {
|
|||
|
||||
/// Returns `true` if this set contains the specified integer.
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn contains(&self, value: &uint) -> bool {
|
||||
let &BitvSet(ref bitv) = self;
|
||||
*value < bitv.nbits && bitv.get(*value)
|
||||
|
|
@ -1502,12 +1521,14 @@ impl BitvSet {
|
|||
/// Returns `true` if the set has no elements in common with `other`.
|
||||
/// This is equivalent to checking for an empty intersection.
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn is_disjoint(&self, other: &BitvSet) -> bool {
|
||||
self.intersection(other).next().is_none()
|
||||
}
|
||||
|
||||
/// Returns `true` if the set is a subset of another.
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn is_subset(&self, other: &BitvSet) -> bool {
|
||||
let &BitvSet(ref self_bitv) = self;
|
||||
let &BitvSet(ref other_bitv) = other;
|
||||
|
|
@ -1521,12 +1542,14 @@ impl BitvSet {
|
|||
|
||||
/// Returns `true` if the set is a superset of another.
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn is_superset(&self, other: &BitvSet) -> bool {
|
||||
other.is_subset(self)
|
||||
}
|
||||
|
||||
/// Adds a value to the set. Returns `true` if the value was not already
|
||||
/// present in the set.
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn insert(&mut self, value: uint) -> bool {
|
||||
if self.contains(&value) {
|
||||
return false;
|
||||
|
|
@ -1545,6 +1568,7 @@ impl BitvSet {
|
|||
|
||||
/// Removes a value from the set. Returns `true` if the value was
|
||||
/// present in the set.
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn remove(&mut self, value: &uint) -> bool {
|
||||
if !self.contains(value) {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ use core::fmt::Show;
|
|||
|
||||
use ring_buf::RingBuf;
|
||||
|
||||
// FIXME(conventions): implement bounded iterators
|
||||
|
||||
/// A map based on a B-Tree.
|
||||
///
|
||||
/// B-Trees represent a fundamental compromise between cache-efficiency and actually minimizing
|
||||
|
|
@ -125,6 +127,7 @@ pub struct OccupiedEntry<'a, K:'a, V:'a> {
|
|||
|
||||
impl<K: Ord, V> BTreeMap<K, V> {
|
||||
/// Makes a new empty BTreeMap with a reasonable choice for B.
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn new() -> BTreeMap<K, V> {
|
||||
//FIXME(Gankro): Tune this as a function of size_of<K/V>?
|
||||
BTreeMap::with_b(6)
|
||||
|
|
@ -155,12 +158,19 @@ impl<K: Ord, V> BTreeMap<K, V> {
|
|||
/// a.clear();
|
||||
/// assert!(a.is_empty());
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn clear(&mut self) {
|
||||
let b = self.b;
|
||||
// avoid recursive destructors by manually traversing the tree
|
||||
for _ in mem::replace(self, BTreeMap::with_b(b)).into_iter() {};
|
||||
}
|
||||
|
||||
/// Deprecated: renamed to `get`.
|
||||
#[deprecated = "renamed to `get`"]
|
||||
pub fn find(&self, key: &K) -> Option<&V> {
|
||||
self.get(key)
|
||||
}
|
||||
|
||||
// Searching in a B-Tree is pretty straightforward.
|
||||
//
|
||||
// Start at the root. Try to find the key in the current node. If we find it, return it.
|
||||
|
|
@ -178,10 +188,11 @@ impl<K: Ord, V> BTreeMap<K, V> {
|
|||
///
|
||||
/// let mut map = BTreeMap::new();
|
||||
/// map.insert(1u, "a");
|
||||
/// assert_eq!(map.find(&1), Some(&"a"));
|
||||
/// assert_eq!(map.find(&2), None);
|
||||
/// assert_eq!(map.get(&1), Some(&"a"));
|
||||
/// assert_eq!(map.get(&2), None);
|
||||
/// ```
|
||||
pub fn find(&self, key: &K) -> Option<&V> {
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn get(&self, key: &K) -> Option<&V> {
|
||||
let mut cur_node = &self.root;
|
||||
loop {
|
||||
match cur_node.search(key) {
|
||||
|
|
@ -209,9 +220,15 @@ impl<K: Ord, V> BTreeMap<K, V> {
|
|||
/// assert_eq!(map.contains_key(&1), true);
|
||||
/// assert_eq!(map.contains_key(&2), false);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn contains_key(&self, key: &K) -> bool {
|
||||
self.find(key).is_some()
|
||||
self.get(key).is_some()
|
||||
}
|
||||
|
||||
/// Deprecated: renamed to `get_mut`.
|
||||
#[deprecated = "renamed to `get_mut`"]
|
||||
pub fn find_mut(&mut self, key: &K) -> Option<&mut V> {
|
||||
self.get_mut(key)
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to the value corresponding to the key.
|
||||
|
|
@ -223,14 +240,15 @@ impl<K: Ord, V> BTreeMap<K, V> {
|
|||
///
|
||||
/// let mut map = BTreeMap::new();
|
||||
/// map.insert(1u, "a");
|
||||
/// match map.find_mut(&1) {
|
||||
/// match map.get_mut(&1) {
|
||||
/// Some(x) => *x = "b",
|
||||
/// None => (),
|
||||
/// }
|
||||
/// assert_eq!(map[1], "b");
|
||||
/// ```
|
||||
// See `find` for implementation notes, this is basically a copy-paste with mut's added
|
||||
pub fn find_mut(&mut self, key: &K) -> Option<&mut V> {
|
||||
// See `get` for implementation notes, this is basically a copy-paste with mut's added
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn get_mut(&mut self, key: &K) -> Option<&mut V> {
|
||||
// temp_node is a Borrowck hack for having a mutable value outlive a loop iteration
|
||||
let mut temp_node = &mut self.root;
|
||||
loop {
|
||||
|
|
@ -248,6 +266,12 @@ impl<K: Ord, V> BTreeMap<K, V> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Deprecated: renamed to `insert`.
|
||||
#[deprecated = "renamed to `insert`"]
|
||||
pub fn swap(&mut self, key: K, value: V) -> Option<V> {
|
||||
self.insert(key, value)
|
||||
}
|
||||
|
||||
// Insertion in a B-Tree is a bit complicated.
|
||||
//
|
||||
// First we do the same kind of search described in `find`. But we need to maintain a stack of
|
||||
|
|
@ -283,14 +307,15 @@ impl<K: Ord, V> BTreeMap<K, V> {
|
|||
/// use std::collections::BTreeMap;
|
||||
///
|
||||
/// let mut map = BTreeMap::new();
|
||||
/// assert_eq!(map.swap(37u, "a"), None);
|
||||
/// assert_eq!(map.insert(37u, "a"), None);
|
||||
/// assert_eq!(map.is_empty(), false);
|
||||
///
|
||||
/// map.insert(37, "b");
|
||||
/// assert_eq!(map.swap(37, "c"), Some("b"));
|
||||
/// assert_eq!(map.insert(37, "c"), Some("b"));
|
||||
/// assert_eq!(map[37], "c");
|
||||
/// ```
|
||||
pub fn swap(&mut self, key: K, mut value: V) -> Option<V> {
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn insert(&mut self, key: K, mut value: V) -> Option<V> {
|
||||
// This is a stack of rawptrs to nodes paired with indices, respectively
|
||||
// representing the nodes and edges of our search path. We have to store rawptrs
|
||||
// because as far as Rust is concerned, we can mutate aliased data with such a
|
||||
|
|
@ -338,25 +363,6 @@ impl<K: Ord, V> BTreeMap<K, V> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Inserts a key-value pair into the map. An existing value for a
|
||||
/// key is replaced by the new value. Returns `true` if the key did
|
||||
/// not already exist in the map.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use std::collections::BTreeMap;
|
||||
///
|
||||
/// let mut map = BTreeMap::new();
|
||||
/// assert_eq!(map.insert(2u, "value"), true);
|
||||
/// assert_eq!(map.insert(2, "value2"), false);
|
||||
/// assert_eq!(map[2], "value2");
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn insert(&mut self, key: K, value: V) -> bool {
|
||||
self.swap(key, value).is_none()
|
||||
}
|
||||
|
||||
// Deletion is the most complicated operation for a B-Tree.
|
||||
//
|
||||
// First we do the same kind of search described in
|
||||
|
|
@ -392,6 +398,12 @@ impl<K: Ord, V> BTreeMap<K, V> {
|
|||
// the underflow handling process on the parent. If merging merges the last two children
|
||||
// of the root, then we replace the root with the merged node.
|
||||
|
||||
/// Deprecated: renamed to `remove`.
|
||||
#[deprecated = "renamed to `remove`"]
|
||||
pub fn pop(&mut self, key: &K) -> Option<V> {
|
||||
self.remove(key)
|
||||
}
|
||||
|
||||
/// Removes a key from the map, returning the value at the key if the key
|
||||
/// was previously in the map.
|
||||
///
|
||||
|
|
@ -402,10 +414,11 @@ impl<K: Ord, V> BTreeMap<K, V> {
|
|||
///
|
||||
/// let mut map = BTreeMap::new();
|
||||
/// map.insert(1u, "a");
|
||||
/// assert_eq!(map.pop(&1), Some("a"));
|
||||
/// assert_eq!(map.pop(&1), None);
|
||||
/// assert_eq!(map.remove(&1), Some("a"));
|
||||
/// assert_eq!(map.remove(&1), None);
|
||||
/// ```
|
||||
pub fn pop(&mut self, key: &K) -> Option<V> {
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn remove(&mut self, key: &K) -> Option<V> {
|
||||
// See `swap` for a more thorough description of the stuff going on in here
|
||||
let mut stack = stack::PartialSearchStack::new(self);
|
||||
loop {
|
||||
|
|
@ -426,24 +439,6 @@ impl<K: Ord, V> BTreeMap<K, V> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Removes a key-value pair from the map. Returns `true` if the key
|
||||
/// was present in the map.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use std::collections::BTreeMap;
|
||||
///
|
||||
/// let mut map = BTreeMap::new();
|
||||
/// assert_eq!(map.remove(&1u), false);
|
||||
/// map.insert(1, "a");
|
||||
/// assert_eq!(map.remove(&1), true);
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn remove(&mut self, key: &K) -> bool {
|
||||
self.pop(key).is_some()
|
||||
}
|
||||
}
|
||||
|
||||
/// The stack module provides a safe interface for constructing and manipulating a stack of ptrs
|
||||
|
|
@ -793,13 +788,13 @@ impl<K: Show, V: Show> Show for BTreeMap<K, V> {
|
|||
|
||||
impl<K: Ord, V> Index<K, V> for BTreeMap<K, V> {
|
||||
fn index(&self, key: &K) -> &V {
|
||||
self.find(key).expect("no entry found for key")
|
||||
self.get(key).expect("no entry found for key")
|
||||
}
|
||||
}
|
||||
|
||||
impl<K: Ord, V> IndexMut<K, V> for BTreeMap<K, V> {
|
||||
fn index_mut(&mut self, key: &K) -> &mut V {
|
||||
self.find_mut(key).expect("no entry found for key")
|
||||
self.get_mut(key).expect("no entry found for key")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -891,8 +886,8 @@ impl<K, V, E, T: Traverse<E> + DoubleEndedIterator<TraversalItem<K, V, E>>>
|
|||
|
||||
// Handle any operation on the left stack as necessary
|
||||
match op {
|
||||
Push(item) => { self.left.push(item); },
|
||||
Pop => { self.left.pop(); },
|
||||
Push(item) => { self.left.push_back(item); },
|
||||
Pop => { self.left.pop_back(); },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -933,8 +928,8 @@ impl<K, V, E, T: Traverse<E> + DoubleEndedIterator<TraversalItem<K, V, E>>>
|
|||
};
|
||||
|
||||
match op {
|
||||
Push(item) => { self.right.push(item); },
|
||||
Pop => { self.right.pop(); }
|
||||
Push(item) => { self.right.push_back(item); },
|
||||
Pop => { self.right.pop_back(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1010,6 +1005,7 @@ impl<'a, K: Ord, V> OccupiedEntry<'a, K, V> {
|
|||
|
||||
impl<K, V> BTreeMap<K, V> {
|
||||
/// Gets an iterator over the entries of the map.
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn iter<'a>(&'a self) -> Entries<'a, K, V> {
|
||||
let len = self.len();
|
||||
Entries {
|
||||
|
|
@ -1023,6 +1019,7 @@ impl<K, V> BTreeMap<K, V> {
|
|||
}
|
||||
|
||||
/// Gets a mutable iterator over the entries of the map.
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn iter_mut<'a>(&'a mut self) -> MutEntries<'a, K, V> {
|
||||
let len = self.len();
|
||||
MutEntries {
|
||||
|
|
@ -1036,6 +1033,7 @@ impl<K, V> BTreeMap<K, V> {
|
|||
}
|
||||
|
||||
/// Gets an owning iterator over the entries of the map.
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn into_iter(self) -> MoveEntries<K, V> {
|
||||
let len = self.len();
|
||||
MoveEntries {
|
||||
|
|
@ -1049,11 +1047,13 @@ impl<K, V> BTreeMap<K, V> {
|
|||
}
|
||||
|
||||
/// Gets an iterator over the keys of the map.
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn keys<'a>(&'a self) -> Keys<'a, K, V> {
|
||||
self.iter().map(|(k, _)| k)
|
||||
}
|
||||
|
||||
/// Gets an iterator over the values of the map.
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn values<'a>(&'a self) -> Values<'a, K, V> {
|
||||
self.iter().map(|(_, v)| v)
|
||||
}
|
||||
|
|
@ -1070,6 +1070,7 @@ impl<K, V> BTreeMap<K, V> {
|
|||
/// a.insert(1u, "a");
|
||||
/// assert_eq!(a.len(), 1);
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn len(&self) -> uint { self.length }
|
||||
|
||||
/// Return true if the map contains no elements.
|
||||
|
|
@ -1084,6 +1085,7 @@ impl<K, V> BTreeMap<K, V> {
|
|||
/// a.insert(1u, "a");
|
||||
/// assert!(!a.is_empty());
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn is_empty(&self) -> bool { self.len() == 0 }
|
||||
}
|
||||
|
||||
|
|
@ -1137,40 +1139,40 @@ mod test {
|
|||
assert_eq!(map.len(), 0);
|
||||
|
||||
for i in range(0, size) {
|
||||
assert_eq!(map.swap(i, 10*i), None);
|
||||
assert_eq!(map.insert(i, 10*i), None);
|
||||
assert_eq!(map.len(), i + 1);
|
||||
}
|
||||
|
||||
for i in range(0, size) {
|
||||
assert_eq!(map.find(&i).unwrap(), &(i*10));
|
||||
assert_eq!(map.get(&i).unwrap(), &(i*10));
|
||||
}
|
||||
|
||||
for i in range(size, size*2) {
|
||||
assert_eq!(map.find(&i), None);
|
||||
assert_eq!(map.get(&i), None);
|
||||
}
|
||||
|
||||
for i in range(0, size) {
|
||||
assert_eq!(map.swap(i, 100*i), Some(10*i));
|
||||
assert_eq!(map.insert(i, 100*i), Some(10*i));
|
||||
assert_eq!(map.len(), size);
|
||||
}
|
||||
|
||||
for i in range(0, size) {
|
||||
assert_eq!(map.find(&i).unwrap(), &(i*100));
|
||||
assert_eq!(map.get(&i).unwrap(), &(i*100));
|
||||
}
|
||||
|
||||
for i in range(0, size/2) {
|
||||
assert_eq!(map.pop(&(i*2)), Some(i*200));
|
||||
assert_eq!(map.remove(&(i*2)), Some(i*200));
|
||||
assert_eq!(map.len(), size - i - 1);
|
||||
}
|
||||
|
||||
for i in range(0, size/2) {
|
||||
assert_eq!(map.find(&(2*i)), None);
|
||||
assert_eq!(map.find(&(2*i+1)).unwrap(), &(i*200 + 100));
|
||||
assert_eq!(map.get(&(2*i)), None);
|
||||
assert_eq!(map.get(&(2*i+1)).unwrap(), &(i*200 + 100));
|
||||
}
|
||||
|
||||
for i in range(0, size/2) {
|
||||
assert_eq!(map.pop(&(2*i)), None);
|
||||
assert_eq!(map.pop(&(2*i+1)), Some(i*200 + 100));
|
||||
assert_eq!(map.remove(&(2*i)), None);
|
||||
assert_eq!(map.remove(&(2*i+1)), Some(i*200 + 100));
|
||||
assert_eq!(map.len(), size/2 - i - 1);
|
||||
}
|
||||
}
|
||||
|
|
@ -1178,17 +1180,17 @@ mod test {
|
|||
#[test]
|
||||
fn test_basic_small() {
|
||||
let mut map = BTreeMap::new();
|
||||
assert_eq!(map.pop(&1), None);
|
||||
assert_eq!(map.find(&1), None);
|
||||
assert_eq!(map.swap(1u, 1u), None);
|
||||
assert_eq!(map.find(&1), Some(&1));
|
||||
assert_eq!(map.swap(1, 2), Some(1));
|
||||
assert_eq!(map.find(&1), Some(&2));
|
||||
assert_eq!(map.swap(2, 4), None);
|
||||
assert_eq!(map.find(&2), Some(&4));
|
||||
assert_eq!(map.pop(&1), Some(2));
|
||||
assert_eq!(map.pop(&2), Some(4));
|
||||
assert_eq!(map.pop(&1), None);
|
||||
assert_eq!(map.remove(&1), None);
|
||||
assert_eq!(map.get(&1), None);
|
||||
assert_eq!(map.insert(1u, 1u), None);
|
||||
assert_eq!(map.get(&1), Some(&1));
|
||||
assert_eq!(map.insert(1, 2), Some(1));
|
||||
assert_eq!(map.get(&1), Some(&2));
|
||||
assert_eq!(map.insert(2, 4), None);
|
||||
assert_eq!(map.get(&2), Some(&4));
|
||||
assert_eq!(map.remove(&1), Some(2));
|
||||
assert_eq!(map.remove(&2), Some(4));
|
||||
assert_eq!(map.remove(&1), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -1283,7 +1285,7 @@ mod test {
|
|||
assert_eq!(view.set(100), 10);
|
||||
}
|
||||
}
|
||||
assert_eq!(map.find(&1).unwrap(), &100);
|
||||
assert_eq!(map.get(&1).unwrap(), &100);
|
||||
assert_eq!(map.len(), 6);
|
||||
|
||||
|
||||
|
|
@ -1295,7 +1297,7 @@ mod test {
|
|||
*v *= 10;
|
||||
}
|
||||
}
|
||||
assert_eq!(map.find(&2).unwrap(), &200);
|
||||
assert_eq!(map.get(&2).unwrap(), &200);
|
||||
assert_eq!(map.len(), 6);
|
||||
|
||||
// Existing key (take)
|
||||
|
|
@ -1305,7 +1307,7 @@ mod test {
|
|||
assert_eq!(view.take(), 30);
|
||||
}
|
||||
}
|
||||
assert_eq!(map.find(&3), None);
|
||||
assert_eq!(map.get(&3), None);
|
||||
assert_eq!(map.len(), 5);
|
||||
|
||||
|
||||
|
|
@ -1316,7 +1318,7 @@ mod test {
|
|||
assert_eq!(*view.set(1000), 1000);
|
||||
}
|
||||
}
|
||||
assert_eq!(map.find(&10).unwrap(), &1000);
|
||||
assert_eq!(map.get(&10).unwrap(), &1000);
|
||||
assert_eq!(map.len(), 6);
|
||||
}
|
||||
}
|
||||
|
|
@ -1374,7 +1376,7 @@ mod bench {
|
|||
let mut m : BTreeMap<uint,uint> = BTreeMap::new();
|
||||
find_rand_n(100, &mut m, b,
|
||||
|m, i| { m.insert(i, 1); },
|
||||
|m, i| { m.find(&i); });
|
||||
|m, i| { m.get(&i); });
|
||||
}
|
||||
|
||||
#[bench]
|
||||
|
|
@ -1382,7 +1384,7 @@ mod bench {
|
|||
let mut m : BTreeMap<uint,uint> = BTreeMap::new();
|
||||
find_rand_n(10_000, &mut m, b,
|
||||
|m, i| { m.insert(i, 1); },
|
||||
|m, i| { m.find(&i); });
|
||||
|m, i| { m.get(&i); });
|
||||
}
|
||||
|
||||
// Find seq
|
||||
|
|
@ -1391,7 +1393,7 @@ mod bench {
|
|||
let mut m : BTreeMap<uint,uint> = BTreeMap::new();
|
||||
find_seq_n(100, &mut m, b,
|
||||
|m, i| { m.insert(i, 1); },
|
||||
|m, i| { m.find(&i); });
|
||||
|m, i| { m.get(&i); });
|
||||
}
|
||||
|
||||
#[bench]
|
||||
|
|
@ -1399,7 +1401,7 @@ mod bench {
|
|||
let mut m : BTreeMap<uint,uint> = BTreeMap::new();
|
||||
find_seq_n(10_000, &mut m, b,
|
||||
|m, i| { m.insert(i, 1); },
|
||||
|m, i| { m.find(&i); });
|
||||
|m, i| { m.get(&i); });
|
||||
}
|
||||
|
||||
fn bench_iter(b: &mut Bencher, size: uint) {
|
||||
|
|
@ -1407,7 +1409,7 @@ mod bench {
|
|||
let mut rng = weak_rng();
|
||||
|
||||
for _ in range(0, size) {
|
||||
map.swap(rng.gen(), rng.gen());
|
||||
map.insert(rng.gen(), rng.gen());
|
||||
}
|
||||
|
||||
b.iter(|| {
|
||||
|
|
|
|||
|
|
@ -20,6 +20,9 @@ use core::{iter, fmt};
|
|||
use core::iter::Peekable;
|
||||
use core::fmt::Show;
|
||||
|
||||
// FIXME(conventions): implement bounded iterators
|
||||
// FIXME(conventions): implement BitOr, BitAnd, BitXor, and Sub
|
||||
|
||||
/// A set based on a B-Tree.
|
||||
///
|
||||
/// See BTreeMap's documentation for a detailed discussion of this collection's performance
|
||||
|
|
@ -61,6 +64,7 @@ pub struct UnionItems<'a, T:'a> {
|
|||
|
||||
impl<T: Ord> BTreeSet<T> {
|
||||
/// Makes a new BTreeSet with a reasonable choice of B.
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn new() -> BTreeSet<T> {
|
||||
BTreeSet { map: BTreeMap::new() }
|
||||
}
|
||||
|
|
@ -75,11 +79,13 @@ impl<T: Ord> BTreeSet<T> {
|
|||
|
||||
impl<T> BTreeSet<T> {
|
||||
/// Gets an iterator over the BTreeSet's contents.
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn iter<'a>(&'a self) -> Items<'a, T> {
|
||||
self.map.keys()
|
||||
}
|
||||
|
||||
/// Gets an iterator for moving out the BtreeSet's contents.
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn into_iter(self) -> MoveItems<T> {
|
||||
self.map.into_iter().map(|(k, _)| k)
|
||||
}
|
||||
|
|
@ -87,23 +93,27 @@ impl<T> BTreeSet<T> {
|
|||
|
||||
impl<T: Ord> BTreeSet<T> {
|
||||
/// Visits the values representing the difference, in ascending order.
|
||||
#[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()}
|
||||
}
|
||||
|
||||
/// Visits the values representing the symmetric difference, in ascending order.
|
||||
#[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()}
|
||||
}
|
||||
|
||||
/// Visits the values representing the intersection, in ascending order.
|
||||
#[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()}
|
||||
}
|
||||
|
||||
/// Visits the values representing the union, in ascending order.
|
||||
#[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()}
|
||||
}
|
||||
|
|
@ -120,6 +130,7 @@ impl<T: Ord> BTreeSet<T> {
|
|||
/// v.insert(1i);
|
||||
/// assert_eq!(v.len(), 1);
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn len(&self) -> uint { self.map.len() }
|
||||
|
||||
/// Returns true if the set contains no elements
|
||||
|
|
@ -134,6 +145,7 @@ impl<T: Ord> BTreeSet<T> {
|
|||
/// v.insert(1i);
|
||||
/// assert!(!v.is_empty());
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn is_empty(&self) -> bool { self.len() == 0 }
|
||||
|
||||
/// Clears the set, removing all values.
|
||||
|
|
@ -148,6 +160,7 @@ impl<T: Ord> BTreeSet<T> {
|
|||
/// v.clear();
|
||||
/// assert!(v.is_empty());
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn clear(&mut self) {
|
||||
self.map.clear()
|
||||
}
|
||||
|
|
@ -163,8 +176,9 @@ impl<T: Ord> BTreeSet<T> {
|
|||
/// assert_eq!(set.contains(&1), true);
|
||||
/// assert_eq!(set.contains(&4), false);
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn contains(&self, value: &T) -> bool {
|
||||
self.map.find(value).is_some()
|
||||
self.map.contains_key(value)
|
||||
}
|
||||
|
||||
/// Returns `true` if the set has no elements in common with `other`.
|
||||
|
|
@ -184,6 +198,7 @@ impl<T: Ord> BTreeSet<T> {
|
|||
/// b.insert(1);
|
||||
/// assert_eq!(a.is_disjoint(&b), false);
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn is_disjoint(&self, other: &BTreeSet<T>) -> bool {
|
||||
self.intersection(other).next().is_none()
|
||||
}
|
||||
|
|
@ -204,6 +219,7 @@ impl<T: Ord> BTreeSet<T> {
|
|||
/// set.insert(4);
|
||||
/// assert_eq!(set.is_subset(&sup), false);
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn is_subset(&self, other: &BTreeSet<T>) -> bool {
|
||||
// Stolen from TreeMap
|
||||
let mut x = self.iter();
|
||||
|
|
@ -248,6 +264,7 @@ impl<T: Ord> BTreeSet<T> {
|
|||
/// set.insert(2);
|
||||
/// assert_eq!(set.is_superset(&sub), true);
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn is_superset(&self, other: &BTreeSet<T>) -> bool {
|
||||
other.is_subset(self)
|
||||
}
|
||||
|
|
@ -266,8 +283,9 @@ impl<T: Ord> BTreeSet<T> {
|
|||
/// assert_eq!(set.insert(2i), false);
|
||||
/// assert_eq!(set.len(), 1);
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn insert(&mut self, value: T) -> bool {
|
||||
self.map.insert(value, ())
|
||||
self.map.insert(value, ()).is_none()
|
||||
}
|
||||
|
||||
/// Removes a value from the set. Returns `true` if the value was
|
||||
|
|
@ -284,8 +302,9 @@ impl<T: Ord> BTreeSet<T> {
|
|||
/// assert_eq!(set.remove(&2), true);
|
||||
/// assert_eq!(set.remove(&2), false);
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn remove(&mut self, value: &T) -> bool {
|
||||
self.map.remove(value)
|
||||
self.map.remove(value).is_some()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -195,6 +195,7 @@ impl<T> Default for DList<T> {
|
|||
impl<T> DList<T> {
|
||||
/// Creates an empty `DList`.
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn new() -> DList<T> {
|
||||
DList{list_head: None, list_tail: Rawlink::none(), length: 0}
|
||||
}
|
||||
|
|
@ -209,9 +210,9 @@ impl<T> DList<T> {
|
|||
/// use std::collections::DList;
|
||||
///
|
||||
/// let mut dl = DList::new();
|
||||
/// dl.push(1i);
|
||||
/// dl.push(2);
|
||||
/// dl.push(3);
|
||||
/// dl.push_back(1i);
|
||||
/// dl.push_back(2);
|
||||
/// dl.push_back(3);
|
||||
///
|
||||
/// dl.rotate_forward();
|
||||
///
|
||||
|
|
@ -236,9 +237,9 @@ impl<T> DList<T> {
|
|||
/// use std::collections::DList;
|
||||
///
|
||||
/// let mut dl = DList::new();
|
||||
/// dl.push(1i);
|
||||
/// dl.push(2);
|
||||
/// dl.push(3);
|
||||
/// dl.push_back(1i);
|
||||
/// dl.push_back(2);
|
||||
/// dl.push_back(3);
|
||||
///
|
||||
/// dl.rotate_backward();
|
||||
///
|
||||
|
|
@ -264,10 +265,10 @@ impl<T> DList<T> {
|
|||
///
|
||||
/// let mut a = DList::new();
|
||||
/// let mut b = DList::new();
|
||||
/// a.push(1i);
|
||||
/// a.push(2);
|
||||
/// b.push(3i);
|
||||
/// b.push(4);
|
||||
/// a.push_back(1i);
|
||||
/// a.push_back(2);
|
||||
/// b.push_back(3i);
|
||||
/// b.push_back(4);
|
||||
///
|
||||
/// a.append(b);
|
||||
///
|
||||
|
|
@ -305,10 +306,10 @@ impl<T> DList<T> {
|
|||
///
|
||||
/// let mut a = DList::new();
|
||||
/// let mut b = DList::new();
|
||||
/// a.push(1i);
|
||||
/// a.push(2);
|
||||
/// b.push(3i);
|
||||
/// b.push(4);
|
||||
/// a.push_back(1i);
|
||||
/// a.push_back(2);
|
||||
/// b.push_back(3i);
|
||||
/// b.push_back(4);
|
||||
///
|
||||
/// a.prepend(b);
|
||||
///
|
||||
|
|
@ -333,10 +334,10 @@ impl<T> DList<T> {
|
|||
/// use std::collections::DList;
|
||||
///
|
||||
/// let mut a: DList<int> = DList::new();
|
||||
/// a.push(2i);
|
||||
/// a.push(4);
|
||||
/// a.push(7);
|
||||
/// a.push(8);
|
||||
/// a.push_back(2i);
|
||||
/// a.push_back(4);
|
||||
/// a.push_back(7);
|
||||
/// a.push_back(8);
|
||||
///
|
||||
/// // insert 11 before the first odd number in the list
|
||||
/// a.insert_when(11, |&e, _| e % 2 == 1);
|
||||
|
|
@ -387,12 +388,14 @@ 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}
|
||||
}
|
||||
|
||||
/// 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> {
|
||||
let head_raw = match self.list_head {
|
||||
Some(ref mut h) => Rawlink::some(&mut **h),
|
||||
|
|
@ -408,6 +411,7 @@ 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}
|
||||
}
|
||||
|
|
@ -416,6 +420,7 @@ impl<T> DList<T> {
|
|||
///
|
||||
/// This operation should compute in O(1) time.
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.list_head.is_none()
|
||||
}
|
||||
|
|
@ -424,6 +429,7 @@ impl<T> DList<T> {
|
|||
///
|
||||
/// This operation should compute in O(1) time.
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn len(&self) -> uint {
|
||||
self.length
|
||||
}
|
||||
|
|
@ -432,6 +438,7 @@ impl<T> DList<T> {
|
|||
///
|
||||
/// This operation should compute in O(n) time.
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn clear(&mut self) {
|
||||
*self = DList::new()
|
||||
}
|
||||
|
|
@ -439,34 +446,39 @@ impl<T> DList<T> {
|
|||
/// Provides a reference to the front element, or `None` if the list is
|
||||
/// empty.
|
||||
#[inline]
|
||||
pub fn front<'a>(&'a self) -> Option<&'a T> {
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn front(&self) -> Option<&T> {
|
||||
self.list_head.as_ref().map(|head| &head.value)
|
||||
}
|
||||
|
||||
/// Provides a mutable reference to the front element, or `None` if the list
|
||||
/// is empty.
|
||||
#[inline]
|
||||
pub fn front_mut<'a>(&'a mut self) -> Option<&'a mut T> {
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn front_mut(&mut self) -> Option<&mut T> {
|
||||
self.list_head.as_mut().map(|head| &mut head.value)
|
||||
}
|
||||
|
||||
/// Provides a reference to the back element, or `None` if the list is
|
||||
/// empty.
|
||||
#[inline]
|
||||
pub fn back<'a>(&'a self) -> Option<&'a T> {
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn back(&self) -> Option<&T> {
|
||||
self.list_tail.resolve_immut().as_ref().map(|tail| &tail.value)
|
||||
}
|
||||
|
||||
/// Provides a mutable reference to the back element, or `None` if the list
|
||||
/// is empty.
|
||||
#[inline]
|
||||
pub fn back_mut<'a>(&'a mut self) -> Option<&'a mut T> {
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn back_mut(&mut self) -> Option<&mut T> {
|
||||
self.list_tail.resolve().map(|tail| &mut tail.value)
|
||||
}
|
||||
|
||||
/// Adds an element first in the list.
|
||||
///
|
||||
/// This operation should compute in O(1) time.
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn push_front(&mut self, elt: T) {
|
||||
self.push_front_node(box Node::new(elt))
|
||||
}
|
||||
|
|
@ -475,10 +487,17 @@ impl<T> DList<T> {
|
|||
/// empty.
|
||||
///
|
||||
/// This operation should compute in O(1) time.
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn pop_front(&mut self) -> Option<T> {
|
||||
self.pop_front_node().map(|box Node{value, ..}| value)
|
||||
}
|
||||
|
||||
/// Deprecated: Renamed to `push_back`.
|
||||
#[deprecated = "Renamed to `push_back`"]
|
||||
pub fn push(&mut self, elt: T) {
|
||||
self.push_back(elt)
|
||||
}
|
||||
|
||||
/// Appends an element to the back of a list
|
||||
///
|
||||
/// # Example
|
||||
|
|
@ -487,14 +506,21 @@ impl<T> DList<T> {
|
|||
/// use std::collections::DList;
|
||||
///
|
||||
/// let mut d = DList::new();
|
||||
/// d.push(1i);
|
||||
/// d.push(3);
|
||||
/// d.push_back(1i);
|
||||
/// d.push_back(3);
|
||||
/// assert_eq!(3, *d.back().unwrap());
|
||||
/// ```
|
||||
pub fn push(&mut self, elt: T) {
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn push_back(&mut self, elt: T) {
|
||||
self.push_back_node(box Node::new(elt))
|
||||
}
|
||||
|
||||
/// Deprecated: Renamed to `pop_back`.
|
||||
#[deprecated = "Renamed to `pop_back`"]
|
||||
pub fn pop(&mut self) -> Option<T> {
|
||||
self.pop_back()
|
||||
}
|
||||
|
||||
/// Removes the last element from a list and returns it, or `None` if
|
||||
/// it is empty.
|
||||
///
|
||||
|
|
@ -504,12 +530,13 @@ impl<T> DList<T> {
|
|||
/// use std::collections::DList;
|
||||
///
|
||||
/// let mut d = DList::new();
|
||||
/// assert_eq!(d.pop(), None);
|
||||
/// d.push(1i);
|
||||
/// d.push(3);
|
||||
/// assert_eq!(d.pop(), Some(3));
|
||||
/// assert_eq!(d.pop_back(), None);
|
||||
/// d.push_back(1i);
|
||||
/// d.push_back(3);
|
||||
/// assert_eq!(d.pop_back(), Some(3));
|
||||
/// ```
|
||||
pub fn pop(&mut self) -> Option<T> {
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn pop_back(&mut self) -> Option<T> {
|
||||
self.pop_back_node().map(|box Node{value, ..}| value)
|
||||
}
|
||||
}
|
||||
|
|
@ -682,7 +709,7 @@ impl<A> Iterator<A> for MoveItems<A> {
|
|||
|
||||
impl<A> DoubleEndedIterator<A> for MoveItems<A> {
|
||||
#[inline]
|
||||
fn next_back(&mut self) -> Option<A> { self.list.pop() }
|
||||
fn next_back(&mut self) -> Option<A> { self.list.pop_back() }
|
||||
}
|
||||
|
||||
impl<A> FromIterator<A> for DList<A> {
|
||||
|
|
@ -695,7 +722,7 @@ impl<A> FromIterator<A> for DList<A> {
|
|||
|
||||
impl<A> Extendable<A> for DList<A> {
|
||||
fn extend<T: Iterator<A>>(&mut self, mut iterator: T) {
|
||||
for elt in iterator { self.push(elt); }
|
||||
for elt in iterator { self.push_back(elt); }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -801,21 +828,21 @@ mod tests {
|
|||
fn test_basic() {
|
||||
let mut m: DList<Box<int>> = DList::new();
|
||||
assert_eq!(m.pop_front(), None);
|
||||
assert_eq!(m.pop(), None);
|
||||
assert_eq!(m.pop_back(), None);
|
||||
assert_eq!(m.pop_front(), None);
|
||||
m.push_front(box 1);
|
||||
assert_eq!(m.pop_front(), Some(box 1));
|
||||
m.push(box 2);
|
||||
m.push(box 3);
|
||||
m.push_back(box 2);
|
||||
m.push_back(box 3);
|
||||
assert_eq!(m.len(), 2);
|
||||
assert_eq!(m.pop_front(), Some(box 2));
|
||||
assert_eq!(m.pop_front(), Some(box 3));
|
||||
assert_eq!(m.len(), 0);
|
||||
assert_eq!(m.pop_front(), None);
|
||||
m.push(box 1);
|
||||
m.push(box 3);
|
||||
m.push(box 5);
|
||||
m.push(box 7);
|
||||
m.push_back(box 1);
|
||||
m.push_back(box 3);
|
||||
m.push_back(box 5);
|
||||
m.push_back(box 7);
|
||||
assert_eq!(m.pop_front(), Some(box 1));
|
||||
|
||||
let mut n = DList::new();
|
||||
|
|
@ -853,19 +880,19 @@ mod tests {
|
|||
{
|
||||
let mut m = DList::new();
|
||||
let mut n = DList::new();
|
||||
n.push(2i);
|
||||
n.push_back(2i);
|
||||
m.append(n);
|
||||
assert_eq!(m.len(), 1);
|
||||
assert_eq!(m.pop(), Some(2));
|
||||
assert_eq!(m.pop_back(), Some(2));
|
||||
check_links(&m);
|
||||
}
|
||||
{
|
||||
let mut m = DList::new();
|
||||
let n = DList::new();
|
||||
m.push(2i);
|
||||
m.push_back(2i);
|
||||
m.append(n);
|
||||
assert_eq!(m.len(), 1);
|
||||
assert_eq!(m.pop(), Some(2));
|
||||
assert_eq!(m.pop_back(), Some(2));
|
||||
check_links(&m);
|
||||
}
|
||||
|
||||
|
|
@ -887,10 +914,10 @@ mod tests {
|
|||
{
|
||||
let mut m = DList::new();
|
||||
let mut n = DList::new();
|
||||
n.push(2i);
|
||||
n.push_back(2i);
|
||||
m.prepend(n);
|
||||
assert_eq!(m.len(), 1);
|
||||
assert_eq!(m.pop(), Some(2));
|
||||
assert_eq!(m.pop_back(), Some(2));
|
||||
check_links(&m);
|
||||
}
|
||||
|
||||
|
|
@ -948,9 +975,9 @@ mod tests {
|
|||
#[test]
|
||||
fn test_iterator_clone() {
|
||||
let mut n = DList::new();
|
||||
n.push(2i);
|
||||
n.push(3);
|
||||
n.push(4);
|
||||
n.push_back(2i);
|
||||
n.push_back(3);
|
||||
n.push_back(4);
|
||||
let mut it = n.iter();
|
||||
it.next();
|
||||
let mut jt = it.clone();
|
||||
|
|
@ -1005,7 +1032,7 @@ mod tests {
|
|||
let mut n = DList::new();
|
||||
assert!(n.iter_mut().next().is_none());
|
||||
n.push_front(4i);
|
||||
n.push(5);
|
||||
n.push_back(5);
|
||||
let mut it = n.iter_mut();
|
||||
assert_eq!(it.size_hint(), (2, Some(2)));
|
||||
assert!(it.next().is_some());
|
||||
|
|
@ -1079,8 +1106,8 @@ mod tests {
|
|||
assert_eq!(n.pop_front(), Some(1));
|
||||
|
||||
let mut m = DList::new();
|
||||
m.push(2i);
|
||||
m.push(4);
|
||||
m.push_back(2i);
|
||||
m.push_back(4);
|
||||
m.insert_ordered(3);
|
||||
check_links(&m);
|
||||
assert_eq!(vec![2,3,4], m.into_iter().collect::<Vec<int>>());
|
||||
|
|
@ -1117,7 +1144,7 @@ mod tests {
|
|||
assert!(n == m);
|
||||
n.push_front(1);
|
||||
assert!(n != m);
|
||||
m.push(1);
|
||||
m.push_back(1);
|
||||
assert!(n == m);
|
||||
|
||||
let n = list_from([2i,3,4]);
|
||||
|
|
@ -1132,9 +1159,9 @@ mod tests {
|
|||
|
||||
assert!(hash::hash(&x) == hash::hash(&y));
|
||||
|
||||
x.push(1i);
|
||||
x.push(2);
|
||||
x.push(3);
|
||||
x.push_back(1i);
|
||||
x.push_back(2);
|
||||
x.push_back(3);
|
||||
|
||||
y.push_front(3i);
|
||||
y.push_front(2);
|
||||
|
|
@ -1214,7 +1241,7 @@ mod tests {
|
|||
let r: u8 = rand::random();
|
||||
match r % 6 {
|
||||
0 => {
|
||||
m.pop();
|
||||
m.pop_back();
|
||||
v.pop();
|
||||
}
|
||||
1 => {
|
||||
|
|
@ -1226,7 +1253,7 @@ mod tests {
|
|||
v.insert(0, -i);
|
||||
}
|
||||
3 | 5 | _ => {
|
||||
m.push(i);
|
||||
m.push_back(i);
|
||||
v.push(i);
|
||||
}
|
||||
}
|
||||
|
|
@ -1262,7 +1289,7 @@ mod tests {
|
|||
fn bench_push_back(b: &mut test::Bencher) {
|
||||
let mut m: DList<int> = DList::new();
|
||||
b.iter(|| {
|
||||
m.push(0);
|
||||
m.push_back(0);
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -1270,8 +1297,8 @@ mod tests {
|
|||
fn bench_push_back_pop_back(b: &mut test::Bencher) {
|
||||
let mut m: DList<int> = DList::new();
|
||||
b.iter(|| {
|
||||
m.push(0);
|
||||
m.pop();
|
||||
m.push_back(0);
|
||||
m.pop_back();
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,10 @@
|
|||
use core::prelude::*;
|
||||
use core::fmt;
|
||||
|
||||
// FIXME(conventions): implement BitXor
|
||||
// FIXME(contentions): implement union family of methods? (general design may be wrong here)
|
||||
// FIXME(conventions): implement len
|
||||
|
||||
#[deriving(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
/// A specialized `Set` implementation to use enum types.
|
||||
pub struct EnumSet<E> {
|
||||
|
|
@ -47,34 +51,56 @@ pub trait CLike {
|
|||
fn from_uint(uint) -> Self;
|
||||
}
|
||||
|
||||
fn bit<E:CLike>(e: E) -> uint {
|
||||
fn bit<E:CLike>(e: &E) -> uint {
|
||||
1 << e.to_uint()
|
||||
}
|
||||
|
||||
impl<E:CLike> EnumSet<E> {
|
||||
/// Returns an empty `EnumSet`.
|
||||
/// Deprecated: Renamed to `new`.
|
||||
#[deprecated = "Renamed to `new`"]
|
||||
pub fn empty() -> EnumSet<E> {
|
||||
EnumSet::new()
|
||||
}
|
||||
|
||||
/// Returns an empty `EnumSet`.
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn new() -> EnumSet<E> {
|
||||
EnumSet {bits: 0}
|
||||
}
|
||||
|
||||
/// Returns true if the `EnumSet` is empty.
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.bits == 0
|
||||
}
|
||||
|
||||
pub fn clear(&mut self) {
|
||||
self.bits = 0;
|
||||
}
|
||||
|
||||
/// Returns `true` if the `EnumSet` contains any enum of the given `EnumSet`.
|
||||
/// Deprecated: Use `is_disjoint`.
|
||||
#[deprecated = "Use `is_disjoint`"]
|
||||
pub fn intersects(&self, e: EnumSet<E>) -> bool {
|
||||
(self.bits & e.bits) != 0
|
||||
!self.is_disjoint(&e)
|
||||
}
|
||||
|
||||
/// Returns the intersection of both `EnumSets`.
|
||||
pub fn intersection(&self, e: EnumSet<E>) -> EnumSet<E> {
|
||||
EnumSet {bits: self.bits & e.bits}
|
||||
/// Returns `false` if the `EnumSet` contains any enum of the given `EnumSet`.
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn is_disjoint(&self, other: &EnumSet<E>) -> bool {
|
||||
(self.bits & other.bits) == 0
|
||||
}
|
||||
|
||||
/// Returns `true` if a given `EnumSet` is included in an `EnumSet`.
|
||||
pub fn contains(&self, e: EnumSet<E>) -> bool {
|
||||
(self.bits & e.bits) == e.bits
|
||||
/// Returns `true` if a given `EnumSet` is included in this `EnumSet`.
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn is_superset(&self, other: &EnumSet<E>) -> bool {
|
||||
(self.bits & other.bits) == other.bits
|
||||
}
|
||||
|
||||
/// Returns `true` if this `EnumSet` is included in the given `EnumSet`.
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn is_subset(&self, other: &EnumSet<E>) -> bool {
|
||||
other.is_superset(self)
|
||||
}
|
||||
|
||||
/// Returns the union of both `EnumSets`.
|
||||
|
|
@ -82,17 +108,47 @@ impl<E:CLike> EnumSet<E> {
|
|||
EnumSet {bits: self.bits | e.bits}
|
||||
}
|
||||
|
||||
/// Adds an enum to an `EnumSet`.
|
||||
/// Returns the intersection of both `EnumSets`.
|
||||
pub fn intersection(&self, e: EnumSet<E>) -> EnumSet<E> {
|
||||
EnumSet {bits: self.bits & e.bits}
|
||||
}
|
||||
|
||||
/// Deprecated: Use `insert`.
|
||||
#[deprecated = "Use `insert`"]
|
||||
pub fn add(&mut self, e: E) {
|
||||
self.bits |= bit(e);
|
||||
self.insert(e);
|
||||
}
|
||||
|
||||
/// Adds an enum to the `EnumSet`, and returns `true` if it wasn't there before
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn insert(&mut self, e: E) -> bool {
|
||||
let result = !self.contains(&e);
|
||||
self.bits |= bit(&e);
|
||||
result
|
||||
}
|
||||
|
||||
/// Removes an enum from the EnumSet
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn remove(&mut self, e: &E) -> bool {
|
||||
let result = self.contains(e);
|
||||
self.bits &= !bit(e);
|
||||
result
|
||||
}
|
||||
|
||||
/// Deprecated: use `contains`.
|
||||
#[deprecated = "use `contains"]
|
||||
pub fn contains_elem(&self, e: E) -> bool {
|
||||
self.contains(&e)
|
||||
}
|
||||
|
||||
/// Returns `true` if an `EnumSet` contains a given enum.
|
||||
pub fn contains_elem(&self, e: E) -> bool {
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn contains(&self, e: &E) -> bool {
|
||||
(self.bits & bit(e)) != 0
|
||||
}
|
||||
|
||||
/// 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)
|
||||
}
|
||||
|
|
@ -174,18 +230,18 @@ mod test {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_empty() {
|
||||
let e: EnumSet<Foo> = EnumSet::empty();
|
||||
fn test_new() {
|
||||
let e: EnumSet<Foo> = EnumSet::new();
|
||||
assert!(e.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_show() {
|
||||
let mut e = EnumSet::empty();
|
||||
let mut e = EnumSet::new();
|
||||
assert_eq!("{}", e.to_string().as_slice());
|
||||
e.add(A);
|
||||
e.insert(A);
|
||||
assert_eq!("{A}", e.to_string().as_slice());
|
||||
e.add(C);
|
||||
e.insert(C);
|
||||
assert_eq!("{A, C}", e.to_string().as_slice());
|
||||
}
|
||||
|
||||
|
|
@ -194,75 +250,80 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_two_empties_do_not_intersect() {
|
||||
let e1: EnumSet<Foo> = EnumSet::empty();
|
||||
let e2: EnumSet<Foo> = EnumSet::empty();
|
||||
assert!(!e1.intersects(e2));
|
||||
let e1: EnumSet<Foo> = EnumSet::new();
|
||||
let e2: EnumSet<Foo> = EnumSet::new();
|
||||
assert!(e1.is_disjoint(&e2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_empty_does_not_intersect_with_full() {
|
||||
let e1: EnumSet<Foo> = EnumSet::empty();
|
||||
let e1: EnumSet<Foo> = EnumSet::new();
|
||||
|
||||
let mut e2: EnumSet<Foo> = EnumSet::empty();
|
||||
e2.add(A);
|
||||
e2.add(B);
|
||||
e2.add(C);
|
||||
let mut e2: EnumSet<Foo> = EnumSet::new();
|
||||
e2.insert(A);
|
||||
e2.insert(B);
|
||||
e2.insert(C);
|
||||
|
||||
assert!(!e1.intersects(e2));
|
||||
assert!(e1.is_disjoint(&e2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_disjoint_intersects() {
|
||||
let mut e1: EnumSet<Foo> = EnumSet::empty();
|
||||
e1.add(A);
|
||||
let mut e1: EnumSet<Foo> = EnumSet::new();
|
||||
e1.insert(A);
|
||||
|
||||
let mut e2: EnumSet<Foo> = EnumSet::empty();
|
||||
e2.add(B);
|
||||
let mut e2: EnumSet<Foo> = EnumSet::new();
|
||||
e2.insert(B);
|
||||
|
||||
assert!(!e1.intersects(e2));
|
||||
assert!(e1.is_disjoint(&e2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_overlapping_intersects() {
|
||||
let mut e1: EnumSet<Foo> = EnumSet::empty();
|
||||
e1.add(A);
|
||||
let mut e1: EnumSet<Foo> = EnumSet::new();
|
||||
e1.insert(A);
|
||||
|
||||
let mut e2: EnumSet<Foo> = EnumSet::empty();
|
||||
e2.add(A);
|
||||
e2.add(B);
|
||||
let mut e2: EnumSet<Foo> = EnumSet::new();
|
||||
e2.insert(A);
|
||||
e2.insert(B);
|
||||
|
||||
assert!(e1.intersects(e2));
|
||||
assert!(!e1.is_disjoint(&e2));
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// contains and contains_elem
|
||||
|
||||
#[test]
|
||||
fn test_contains() {
|
||||
let mut e1: EnumSet<Foo> = EnumSet::empty();
|
||||
e1.add(A);
|
||||
fn test_superset() {
|
||||
let mut e1: EnumSet<Foo> = EnumSet::new();
|
||||
e1.insert(A);
|
||||
|
||||
let mut e2: EnumSet<Foo> = EnumSet::empty();
|
||||
e2.add(A);
|
||||
e2.add(B);
|
||||
let mut e2: EnumSet<Foo> = EnumSet::new();
|
||||
e2.insert(A);
|
||||
e2.insert(B);
|
||||
|
||||
assert!(!e1.contains(e2));
|
||||
assert!(e2.contains(e1));
|
||||
let mut e3: EnumSet<Foo> = EnumSet::new();
|
||||
e3.insert(C);
|
||||
|
||||
assert!(e1.is_subset(&e2));
|
||||
assert!(e2.is_superset(&e1));
|
||||
assert!(!e3.is_superset(&e2))
|
||||
assert!(!e2.is_superset(&e3))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_contains_elem() {
|
||||
let mut e1: EnumSet<Foo> = EnumSet::empty();
|
||||
e1.add(A);
|
||||
assert!(e1.contains_elem(A));
|
||||
assert!(!e1.contains_elem(B));
|
||||
assert!(!e1.contains_elem(C));
|
||||
fn test_contains() {
|
||||
let mut e1: EnumSet<Foo> = EnumSet::new();
|
||||
e1.insert(A);
|
||||
assert!(e1.contains(&A));
|
||||
assert!(!e1.contains(&B));
|
||||
assert!(!e1.contains(&C));
|
||||
|
||||
e1.add(A);
|
||||
e1.add(B);
|
||||
assert!(e1.contains_elem(A));
|
||||
assert!(e1.contains_elem(B));
|
||||
assert!(!e1.contains_elem(C));
|
||||
e1.insert(A);
|
||||
e1.insert(B);
|
||||
assert!(e1.contains(&A));
|
||||
assert!(e1.contains(&B));
|
||||
assert!(!e1.contains(&C));
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -270,24 +331,24 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_iterator() {
|
||||
let mut e1: EnumSet<Foo> = EnumSet::empty();
|
||||
let mut e1: EnumSet<Foo> = EnumSet::new();
|
||||
|
||||
let elems: Vec<Foo> = e1.iter().collect();
|
||||
assert!(elems.is_empty())
|
||||
|
||||
e1.add(A);
|
||||
e1.insert(A);
|
||||
let elems = e1.iter().collect();
|
||||
assert_eq!(vec![A], elems)
|
||||
|
||||
e1.add(C);
|
||||
e1.insert(C);
|
||||
let elems = e1.iter().collect();
|
||||
assert_eq!(vec![A,C], elems)
|
||||
|
||||
e1.add(C);
|
||||
e1.insert(C);
|
||||
let elems = e1.iter().collect();
|
||||
assert_eq!(vec![A,C], elems)
|
||||
|
||||
e1.add(B);
|
||||
e1.insert(B);
|
||||
let elems = e1.iter().collect();
|
||||
assert_eq!(vec![A,B,C], elems)
|
||||
}
|
||||
|
|
@ -297,13 +358,13 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_operators() {
|
||||
let mut e1: EnumSet<Foo> = EnumSet::empty();
|
||||
e1.add(A);
|
||||
e1.add(C);
|
||||
let mut e1: EnumSet<Foo> = EnumSet::new();
|
||||
e1.insert(A);
|
||||
e1.insert(C);
|
||||
|
||||
let mut e2: EnumSet<Foo> = EnumSet::empty();
|
||||
e2.add(B);
|
||||
e2.add(C);
|
||||
let mut e2: EnumSet<Foo> = EnumSet::new();
|
||||
e2.insert(B);
|
||||
e2.insert(C);
|
||||
|
||||
let e_union = e1 | e2;
|
||||
let elems = e_union.iter().collect();
|
||||
|
|
|
|||
|
|
@ -27,6 +27,11 @@ use vec::Vec;
|
|||
static INITIAL_CAPACITY: uint = 8u; // 2^3
|
||||
static MINIMUM_CAPACITY: uint = 2u;
|
||||
|
||||
// FIXME(conventions): implement shrink_to_fit. Awkward with the current design, but it should
|
||||
// be scrapped anyway. Defer to rewrite?
|
||||
// FIXME(conventions): implement into_iter
|
||||
|
||||
|
||||
/// `RingBuf` is a circular buffer that implements `Deque`.
|
||||
#[deriving(Clone)]
|
||||
pub struct RingBuf<T> {
|
||||
|
|
@ -42,11 +47,13 @@ impl<T> Default for RingBuf<T> {
|
|||
|
||||
impl<T> RingBuf<T> {
|
||||
/// Creates an empty `RingBuf`.
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn new() -> RingBuf<T> {
|
||||
RingBuf::with_capacity(INITIAL_CAPACITY)
|
||||
}
|
||||
|
||||
/// Creates an empty `RingBuf` with space for at least `n` elements.
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn with_capacity(n: uint) -> RingBuf<T> {
|
||||
RingBuf{nelts: 0, lo: 0,
|
||||
elts: Vec::from_fn(cmp::max(MINIMUM_CAPACITY, n), |_| None)}
|
||||
|
|
@ -54,24 +61,51 @@ impl<T> RingBuf<T> {
|
|||
|
||||
/// Retrieves an element in the `RingBuf` by index.
|
||||
///
|
||||
/// Fails if there is no element with the given index.
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// use std::collections::RingBuf;
|
||||
///
|
||||
/// let mut buf = RingBuf::new();
|
||||
/// buf.push_back(3i);
|
||||
/// buf.push_back(4);
|
||||
/// buf.push_back(5);
|
||||
/// assert_eq!(buf.get(1).unwrap(), &4);
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn get(&self, i: uint) -> Option<&T> {
|
||||
match self.elts.get(i) {
|
||||
None => None,
|
||||
Some(opt) => opt.as_ref(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Retrieves an element in the `RingBuf` mutably by index.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// # #![allow(deprecated)]
|
||||
/// use std::collections::RingBuf;
|
||||
///
|
||||
/// let mut buf = RingBuf::new();
|
||||
/// buf.push(3i);
|
||||
/// buf.push(4);
|
||||
/// buf.push(5);
|
||||
/// *buf.get_mut(1) = 7;
|
||||
/// buf.push_back(3i);
|
||||
/// buf.push_back(4);
|
||||
/// buf.push_back(5);
|
||||
/// match buf.get_mut(1) {
|
||||
/// None => {}
|
||||
/// Some(elem) => {
|
||||
/// *elem = 7;
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// assert_eq!(buf[1], 7);
|
||||
/// ```
|
||||
#[deprecated = "use indexing instead: `buf[index] = value`"]
|
||||
pub fn get_mut(&mut self, i: uint) -> &mut T {
|
||||
&mut self[i]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn get_mut(&mut self, i: uint) -> Option<&mut T> {
|
||||
match self.elts.get_mut(i) {
|
||||
None => None,
|
||||
Some(opt) => opt.as_mut(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Swaps elements at indices `i` and `j`.
|
||||
|
|
@ -86,9 +120,9 @@ impl<T> RingBuf<T> {
|
|||
/// use std::collections::RingBuf;
|
||||
///
|
||||
/// let mut buf = RingBuf::new();
|
||||
/// buf.push(3i);
|
||||
/// buf.push(4);
|
||||
/// buf.push(5);
|
||||
/// buf.push_back(3i);
|
||||
/// buf.push_back(4);
|
||||
/// buf.push_back(5);
|
||||
/// buf.swap(0, 2);
|
||||
/// assert_eq!(buf[0], 5);
|
||||
/// assert_eq!(buf[2], 3);
|
||||
|
|
@ -107,21 +141,70 @@ impl<T> RingBuf<T> {
|
|||
raw_index(self.lo, self.elts.len(), idx)
|
||||
}
|
||||
|
||||
/// Reserves capacity for exactly `n` elements in the given `RingBuf`,
|
||||
/// doing nothing if `self`'s capacity is already equal to or greater
|
||||
/// than the requested capacity.
|
||||
pub fn reserve_exact(&mut self, n: uint) {
|
||||
self.elts.reserve_exact(n);
|
||||
/// Returns the number of elements the `RingBuf` can hold without
|
||||
/// reallocating.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use std::collections::RingBuf;
|
||||
///
|
||||
/// let buf: RingBuf<int> = RingBuf::with_capacity(10);
|
||||
/// assert_eq!(buf.capacity(), 10);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn capacity(&self) -> uint {
|
||||
// FXIME(Gankro): not the actual usable capacity if you use reserve/reserve_exact
|
||||
self.elts.capacity()
|
||||
}
|
||||
|
||||
/// Reserves capacity for at least `n` elements in the given `RingBuf`,
|
||||
/// over-allocating in case the caller needs to reserve additional
|
||||
/// space.
|
||||
/// Reserves the minimum capacity for exactly `additional` more elements to be inserted in the
|
||||
/// given `RingBuf`. Does nothing if the capacity is already sufficient.
|
||||
///
|
||||
/// Do nothing if `self`'s capacity is already equal to or greater
|
||||
/// than the requested capacity.
|
||||
pub fn reserve(&mut self, n: uint) {
|
||||
self.elts.reserve(n);
|
||||
/// Note that the allocator may give the collection more space than it requests. Therefore
|
||||
/// capacity can not be relied upon to be precisely minimal. Prefer `reserve` if future
|
||||
/// insertions are expected.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if the new capacity overflows `uint`.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use std::collections::RingBuf;
|
||||
///
|
||||
/// let mut buf: RingBuf<int> = vec![1].into_iter().collect();
|
||||
/// buf.reserve_exact(10);
|
||||
/// assert!(buf.capacity() >= 11);
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn reserve_exact(&mut self, additional: uint) {
|
||||
// FIXME(Gankro): this is just wrong. The ringbuf won't actually use this space
|
||||
self.elts.reserve_exact(additional);
|
||||
}
|
||||
|
||||
/// Reserves capacity for at least `additional` more elements to be inserted in the given
|
||||
/// `Ringbuf`. The collection may reserve more space to avoid frequent reallocations.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if the new capacity overflows `uint`.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use std::collections::RingBuf;
|
||||
///
|
||||
/// let mut buf: RingBuf<int> = vec![1].into_iter().collect();
|
||||
/// buf.reserve(10);
|
||||
/// assert!(buf.capacity() >= 11);
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn reserve(&mut self, additional: uint) {
|
||||
// FIXME(Gankro): this is just wrong. The ringbuf won't actually use this space
|
||||
self.elts.reserve(additional);
|
||||
}
|
||||
|
||||
/// Returns a front-to-back iterator.
|
||||
|
|
@ -132,12 +215,13 @@ impl<T> RingBuf<T> {
|
|||
/// use std::collections::RingBuf;
|
||||
///
|
||||
/// let mut buf = RingBuf::new();
|
||||
/// buf.push(5i);
|
||||
/// buf.push(3);
|
||||
/// buf.push(4);
|
||||
/// buf.push_back(5i);
|
||||
/// buf.push_back(3);
|
||||
/// buf.push_back(4);
|
||||
/// let b: &[_] = &[&5, &3, &4];
|
||||
/// 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{index: 0, rindex: self.nelts, lo: self.lo, elts: self.elts.as_slice()}
|
||||
}
|
||||
|
|
@ -150,15 +234,16 @@ impl<T> RingBuf<T> {
|
|||
/// use std::collections::RingBuf;
|
||||
///
|
||||
/// let mut buf = RingBuf::new();
|
||||
/// buf.push(5i);
|
||||
/// buf.push(3);
|
||||
/// buf.push(4);
|
||||
/// buf.push_back(5i);
|
||||
/// buf.push_back(3);
|
||||
/// buf.push_back(4);
|
||||
/// for num in buf.iter_mut() {
|
||||
/// *num = *num - 2;
|
||||
/// }
|
||||
/// let b: &[_] = &[&mut 3, &mut 1, &mut 2];
|
||||
/// assert_eq!(buf.iter_mut().collect::<Vec<&mut int>>()[], b);
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn iter_mut(&mut self) -> MutItems<T> {
|
||||
let start_index = raw_index(self.lo, self.elts.len(), 0);
|
||||
let end_index = raw_index(self.lo, self.elts.len(), self.nelts);
|
||||
|
|
@ -197,9 +282,10 @@ impl<T> RingBuf<T> {
|
|||
///
|
||||
/// let mut v = RingBuf::new();
|
||||
/// assert_eq!(v.len(), 0);
|
||||
/// v.push(1i);
|
||||
/// v.push_back(1i);
|
||||
/// assert_eq!(v.len(), 1);
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn len(&self) -> uint { self.nelts }
|
||||
|
||||
/// Returns true if the buffer contains no elements
|
||||
|
|
@ -214,6 +300,7 @@ impl<T> RingBuf<T> {
|
|||
/// v.push_front(1i);
|
||||
/// assert!(!v.is_empty());
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn is_empty(&self) -> bool { self.len() == 0 }
|
||||
|
||||
/// Clears the buffer, removing all values.
|
||||
|
|
@ -224,10 +311,11 @@ impl<T> RingBuf<T> {
|
|||
/// use std::collections::RingBuf;
|
||||
///
|
||||
/// let mut v = RingBuf::new();
|
||||
/// v.push(1i);
|
||||
/// v.push_back(1i);
|
||||
/// v.clear();
|
||||
/// assert!(v.is_empty());
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn clear(&mut self) {
|
||||
for x in self.elts.iter_mut() { *x = None }
|
||||
self.nelts = 0;
|
||||
|
|
@ -245,10 +333,11 @@ impl<T> RingBuf<T> {
|
|||
/// let mut d = RingBuf::new();
|
||||
/// assert_eq!(d.front(), None);
|
||||
///
|
||||
/// d.push(1i);
|
||||
/// d.push(2i);
|
||||
/// d.push_back(1i);
|
||||
/// d.push_back(2i);
|
||||
/// assert_eq!(d.front(), Some(&1i));
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn front(&self) -> Option<&T> {
|
||||
if self.nelts > 0 { Some(&self[0]) } else { None }
|
||||
}
|
||||
|
|
@ -264,14 +353,15 @@ impl<T> RingBuf<T> {
|
|||
/// let mut d = RingBuf::new();
|
||||
/// assert_eq!(d.front_mut(), None);
|
||||
///
|
||||
/// d.push(1i);
|
||||
/// d.push(2i);
|
||||
/// d.push_back(1i);
|
||||
/// d.push_back(2i);
|
||||
/// match d.front_mut() {
|
||||
/// Some(x) => *x = 9i,
|
||||
/// None => (),
|
||||
/// }
|
||||
/// assert_eq!(d.front(), Some(&9i));
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn front_mut(&mut self) -> Option<&mut T> {
|
||||
if self.nelts > 0 { Some(&mut self[0]) } else { None }
|
||||
}
|
||||
|
|
@ -287,10 +377,11 @@ impl<T> RingBuf<T> {
|
|||
/// let mut d = RingBuf::new();
|
||||
/// assert_eq!(d.back(), None);
|
||||
///
|
||||
/// d.push(1i);
|
||||
/// d.push(2i);
|
||||
/// d.push_back(1i);
|
||||
/// d.push_back(2i);
|
||||
/// assert_eq!(d.back(), Some(&2i));
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn back(&self) -> Option<&T> {
|
||||
if self.nelts > 0 { Some(&self[self.nelts - 1]) } else { None }
|
||||
}
|
||||
|
|
@ -306,14 +397,15 @@ impl<T> RingBuf<T> {
|
|||
/// let mut d = RingBuf::new();
|
||||
/// assert_eq!(d.back(), None);
|
||||
///
|
||||
/// d.push(1i);
|
||||
/// d.push(2i);
|
||||
/// d.push_back(1i);
|
||||
/// d.push_back(2i);
|
||||
/// match d.back_mut() {
|
||||
/// Some(x) => *x = 9i,
|
||||
/// None => (),
|
||||
/// }
|
||||
/// assert_eq!(d.back(), Some(&9i));
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn back_mut(&mut self) -> Option<&mut T> {
|
||||
let nelts = self.nelts;
|
||||
if nelts > 0 { Some(&mut self[nelts - 1]) } else { None }
|
||||
|
|
@ -328,13 +420,14 @@ impl<T> RingBuf<T> {
|
|||
/// use std::collections::RingBuf;
|
||||
///
|
||||
/// let mut d = RingBuf::new();
|
||||
/// d.push(1i);
|
||||
/// d.push(2i);
|
||||
/// d.push_back(1i);
|
||||
/// d.push_back(2i);
|
||||
///
|
||||
/// assert_eq!(d.pop_front(), Some(1i));
|
||||
/// assert_eq!(d.pop_front(), Some(2i));
|
||||
/// assert_eq!(d.pop_front(), None);
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn pop_front(&mut self) -> Option<T> {
|
||||
let result = self.elts[self.lo].take();
|
||||
if result.is_some() {
|
||||
|
|
@ -356,6 +449,7 @@ impl<T> RingBuf<T> {
|
|||
/// d.push_front(2i);
|
||||
/// assert_eq!(d.front(), Some(&2i));
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn push_front(&mut self, t: T) {
|
||||
if self.nelts == self.elts.len() {
|
||||
grow(self.nelts, &mut self.lo, &mut self.elts);
|
||||
|
|
@ -367,6 +461,12 @@ impl<T> RingBuf<T> {
|
|||
self.nelts += 1u;
|
||||
}
|
||||
|
||||
/// Deprecated: Renamed to `push_back`.
|
||||
#[deprecated = "Renamed to `push_back`"]
|
||||
pub fn push(&mut self, t: T) {
|
||||
self.push_back(t)
|
||||
}
|
||||
|
||||
/// Appends an element to the back of a buffer
|
||||
///
|
||||
/// # Example
|
||||
|
|
@ -375,11 +475,12 @@ impl<T> RingBuf<T> {
|
|||
/// use std::collections::RingBuf;
|
||||
///
|
||||
/// let mut buf = RingBuf::new();
|
||||
/// buf.push(1i);
|
||||
/// buf.push(3);
|
||||
/// buf.push_back(1i);
|
||||
/// buf.push_back(3);
|
||||
/// assert_eq!(3, *buf.back().unwrap());
|
||||
/// ```
|
||||
pub fn push(&mut self, t: T) {
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn push_back(&mut self, t: T) {
|
||||
if self.nelts == self.elts.len() {
|
||||
grow(self.nelts, &mut self.lo, &mut self.elts);
|
||||
}
|
||||
|
|
@ -388,6 +489,12 @@ impl<T> RingBuf<T> {
|
|||
self.nelts += 1u;
|
||||
}
|
||||
|
||||
/// Deprecated: Renamed to `pop_back`.
|
||||
#[deprecated = "Renamed to `pop_back`"]
|
||||
pub fn pop(&mut self) -> Option<T> {
|
||||
self.pop_back()
|
||||
}
|
||||
|
||||
/// Removes the last element from a buffer and returns it, or `None` if
|
||||
/// it is empty.
|
||||
///
|
||||
|
|
@ -397,12 +504,13 @@ impl<T> RingBuf<T> {
|
|||
/// use std::collections::RingBuf;
|
||||
///
|
||||
/// let mut buf = RingBuf::new();
|
||||
/// assert_eq!(buf.pop(), None);
|
||||
/// buf.push(1i);
|
||||
/// buf.push(3);
|
||||
/// assert_eq!(buf.pop(), Some(3));
|
||||
/// assert_eq!(buf.pop_back(), None);
|
||||
/// buf.push_back(1i);
|
||||
/// buf.push_back(3);
|
||||
/// assert_eq!(buf.pop_back(), Some(3));
|
||||
/// ```
|
||||
pub fn pop(&mut self) -> Option<T> {
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn pop_back(&mut self) -> Option<T> {
|
||||
if self.nelts > 0 {
|
||||
self.nelts -= 1;
|
||||
let hi = self.raw_index(self.nelts);
|
||||
|
|
@ -523,7 +631,7 @@ impl<'a, T> ExactSize<&'a mut T> for MutItems<'a, T> {}
|
|||
fn grow<T>(nelts: uint, loptr: &mut uint, elts: &mut Vec<Option<T>>) {
|
||||
assert_eq!(nelts, elts.len());
|
||||
let lo = *loptr;
|
||||
elts.reserve(nelts * 2);
|
||||
elts.reserve_exact(nelts);
|
||||
let newlen = elts.capacity();
|
||||
|
||||
/* fill with None */
|
||||
|
|
@ -630,7 +738,7 @@ impl<A> FromIterator<A> for RingBuf<A> {
|
|||
impl<A> Extendable<A> for RingBuf<A> {
|
||||
fn extend<T: Iterator<A>>(&mut self, mut iterator: T) {
|
||||
for elt in iterator {
|
||||
self.push(elt);
|
||||
self.push_back(elt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -666,9 +774,9 @@ mod tests {
|
|||
assert_eq!(d.len(), 0u);
|
||||
d.push_front(17i);
|
||||
d.push_front(42i);
|
||||
d.push(137);
|
||||
d.push_back(137);
|
||||
assert_eq!(d.len(), 3u);
|
||||
d.push(137);
|
||||
d.push_back(137);
|
||||
assert_eq!(d.len(), 4u);
|
||||
debug!("{}", d.front());
|
||||
assert_eq!(*d.front().unwrap(), 42);
|
||||
|
|
@ -677,21 +785,21 @@ mod tests {
|
|||
let mut i = d.pop_front();
|
||||
debug!("{}", i);
|
||||
assert_eq!(i, Some(42));
|
||||
i = d.pop();
|
||||
i = d.pop_back();
|
||||
debug!("{}", i);
|
||||
assert_eq!(i, Some(137));
|
||||
i = d.pop();
|
||||
i = d.pop_back();
|
||||
debug!("{}", i);
|
||||
assert_eq!(i, Some(137));
|
||||
i = d.pop();
|
||||
i = d.pop_back();
|
||||
debug!("{}", i);
|
||||
assert_eq!(i, Some(17));
|
||||
assert_eq!(d.len(), 0u);
|
||||
d.push(3);
|
||||
d.push_back(3);
|
||||
assert_eq!(d.len(), 1u);
|
||||
d.push_front(2);
|
||||
assert_eq!(d.len(), 2u);
|
||||
d.push(4);
|
||||
d.push_back(4);
|
||||
assert_eq!(d.len(), 3u);
|
||||
d.push_front(1);
|
||||
assert_eq!(d.len(), 4u);
|
||||
|
|
@ -711,22 +819,22 @@ mod tests {
|
|||
assert_eq!(deq.len(), 0);
|
||||
deq.push_front(a.clone());
|
||||
deq.push_front(b.clone());
|
||||
deq.push(c.clone());
|
||||
deq.push_back(c.clone());
|
||||
assert_eq!(deq.len(), 3);
|
||||
deq.push(d.clone());
|
||||
deq.push_back(d.clone());
|
||||
assert_eq!(deq.len(), 4);
|
||||
assert_eq!((*deq.front().unwrap()).clone(), b.clone());
|
||||
assert_eq!((*deq.back().unwrap()).clone(), d.clone());
|
||||
assert_eq!(deq.pop_front().unwrap(), b.clone());
|
||||
assert_eq!(deq.pop().unwrap(), d.clone());
|
||||
assert_eq!(deq.pop().unwrap(), c.clone());
|
||||
assert_eq!(deq.pop().unwrap(), a.clone());
|
||||
assert_eq!(deq.pop_back().unwrap(), d.clone());
|
||||
assert_eq!(deq.pop_back().unwrap(), c.clone());
|
||||
assert_eq!(deq.pop_back().unwrap(), a.clone());
|
||||
assert_eq!(deq.len(), 0);
|
||||
deq.push(c.clone());
|
||||
deq.push_back(c.clone());
|
||||
assert_eq!(deq.len(), 1);
|
||||
deq.push_front(b.clone());
|
||||
assert_eq!(deq.len(), 2);
|
||||
deq.push(d.clone());
|
||||
deq.push_back(d.clone());
|
||||
assert_eq!(deq.len(), 3);
|
||||
deq.push_front(a.clone());
|
||||
assert_eq!(deq.len(), 4);
|
||||
|
|
@ -750,7 +858,7 @@ mod tests {
|
|||
|
||||
let mut deq = RingBuf::new();
|
||||
for i in range(0u, 66) {
|
||||
deq.push(i);
|
||||
deq.push_back(i);
|
||||
}
|
||||
|
||||
for i in range(0u, 66) {
|
||||
|
|
@ -788,7 +896,7 @@ mod tests {
|
|||
fn bench_push_back(b: &mut test::Bencher) {
|
||||
let mut deq = RingBuf::new();
|
||||
b.iter(|| {
|
||||
deq.push(0i);
|
||||
deq.push_back(0i);
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -861,17 +969,17 @@ mod tests {
|
|||
#[test]
|
||||
fn test_with_capacity() {
|
||||
let mut d = RingBuf::with_capacity(0);
|
||||
d.push(1i);
|
||||
d.push_back(1i);
|
||||
assert_eq!(d.len(), 1);
|
||||
let mut d = RingBuf::with_capacity(50);
|
||||
d.push(1i);
|
||||
d.push_back(1i);
|
||||
assert_eq!(d.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_with_capacity_non_power_two() {
|
||||
let mut d3 = RingBuf::with_capacity(3);
|
||||
d3.push(1i);
|
||||
d3.push_back(1i);
|
||||
|
||||
// X = None, | = lo
|
||||
// [|1, X, X]
|
||||
|
|
@ -880,20 +988,20 @@ mod tests {
|
|||
assert_eq!(d3.front(), None);
|
||||
|
||||
// [X, |3, X]
|
||||
d3.push(3);
|
||||
d3.push_back(3);
|
||||
// [X, |3, 6]
|
||||
d3.push(6);
|
||||
d3.push_back(6);
|
||||
// [X, X, |6]
|
||||
assert_eq!(d3.pop_front(), Some(3));
|
||||
|
||||
// Pushing the lo past half way point to trigger
|
||||
// the 'B' scenario for growth
|
||||
// [9, X, |6]
|
||||
d3.push(9);
|
||||
d3.push_back(9);
|
||||
// [9, 12, |6]
|
||||
d3.push(12);
|
||||
d3.push_back(12);
|
||||
|
||||
d3.push(15);
|
||||
d3.push_back(15);
|
||||
// There used to be a bug here about how the
|
||||
// RingBuf made growth assumptions about the
|
||||
// underlying Vec which didn't hold and lead
|
||||
|
|
@ -912,25 +1020,25 @@ mod tests {
|
|||
#[test]
|
||||
fn test_reserve_exact() {
|
||||
let mut d = RingBuf::new();
|
||||
d.push(0u64);
|
||||
d.push_back(0u64);
|
||||
d.reserve_exact(50);
|
||||
assert_eq!(d.elts.capacity(), 50);
|
||||
assert!(d.capacity() >= 51);
|
||||
let mut d = RingBuf::new();
|
||||
d.push(0u32);
|
||||
d.push_back(0u32);
|
||||
d.reserve_exact(50);
|
||||
assert_eq!(d.elts.capacity(), 50);
|
||||
assert!(d.capacity() >= 51);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_reserve() {
|
||||
let mut d = RingBuf::new();
|
||||
d.push(0u64);
|
||||
d.push_back(0u64);
|
||||
d.reserve(50);
|
||||
assert_eq!(d.elts.capacity(), 64);
|
||||
assert!(d.capacity() >= 64);
|
||||
let mut d = RingBuf::new();
|
||||
d.push(0u32);
|
||||
d.push_back(0u32);
|
||||
d.reserve(50);
|
||||
assert_eq!(d.elts.capacity(), 64);
|
||||
assert!(d.capacity() >= 64);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -948,7 +1056,7 @@ mod tests {
|
|||
assert_eq!(d.iter().size_hint(), (0, Some(0)));
|
||||
|
||||
for i in range(0i, 5) {
|
||||
d.push(i);
|
||||
d.push_back(i);
|
||||
}
|
||||
{
|
||||
let b: &[_] = &[&0,&1,&2,&3,&4];
|
||||
|
|
@ -979,7 +1087,7 @@ mod tests {
|
|||
assert_eq!(d.iter().rev().next(), None);
|
||||
|
||||
for i in range(0i, 5) {
|
||||
d.push(i);
|
||||
d.push_back(i);
|
||||
}
|
||||
{
|
||||
let b: &[_] = &[&4,&3,&2,&1,&0];
|
||||
|
|
@ -998,11 +1106,11 @@ mod tests {
|
|||
let mut d = RingBuf::with_capacity(3);
|
||||
assert!(d.iter_mut().rev().next().is_none());
|
||||
|
||||
d.push(1i);
|
||||
d.push(2);
|
||||
d.push(3);
|
||||
d.push_back(1i);
|
||||
d.push_back(2);
|
||||
d.push_back(3);
|
||||
assert_eq!(d.pop_front(), Some(1));
|
||||
d.push(4);
|
||||
d.push_back(4);
|
||||
|
||||
assert_eq!(d.iter_mut().rev().map(|x| *x).collect::<Vec<int>>(),
|
||||
vec!(4, 3, 2));
|
||||
|
|
@ -1075,13 +1183,13 @@ mod tests {
|
|||
let mut d = RingBuf::new();
|
||||
d.push_front(17i);
|
||||
d.push_front(42);
|
||||
d.push(137);
|
||||
d.push(137);
|
||||
d.push_back(137);
|
||||
d.push_back(137);
|
||||
assert_eq!(d.len(), 4u);
|
||||
let mut e = d.clone();
|
||||
assert_eq!(e.len(), 4u);
|
||||
while !d.is_empty() {
|
||||
assert_eq!(d.pop(), e.pop());
|
||||
assert_eq!(d.pop_back(), e.pop_back());
|
||||
}
|
||||
assert_eq!(d.len(), 0u);
|
||||
assert_eq!(e.len(), 0u);
|
||||
|
|
@ -1094,15 +1202,15 @@ mod tests {
|
|||
d.push_front(137i);
|
||||
d.push_front(17);
|
||||
d.push_front(42);
|
||||
d.push(137);
|
||||
d.push_back(137);
|
||||
let mut e = RingBuf::with_capacity(0);
|
||||
e.push(42);
|
||||
e.push(17);
|
||||
e.push(137);
|
||||
e.push(137);
|
||||
e.push_back(42);
|
||||
e.push_back(17);
|
||||
e.push_back(137);
|
||||
e.push_back(137);
|
||||
assert!(&e == &d);
|
||||
e.pop();
|
||||
e.push(0);
|
||||
e.pop_back();
|
||||
e.push_back(0);
|
||||
assert!(e != d);
|
||||
e.clear();
|
||||
assert!(e == RingBuf::new());
|
||||
|
|
@ -1113,15 +1221,15 @@ mod tests {
|
|||
let mut x = RingBuf::new();
|
||||
let mut y = RingBuf::new();
|
||||
|
||||
x.push(1i);
|
||||
x.push(2);
|
||||
x.push(3);
|
||||
x.push_back(1i);
|
||||
x.push_back(2);
|
||||
x.push_back(3);
|
||||
|
||||
y.push(0i);
|
||||
y.push(1i);
|
||||
y.push_back(0i);
|
||||
y.push_back(1i);
|
||||
y.pop_front();
|
||||
y.push(2);
|
||||
y.push(3);
|
||||
y.push_back(2);
|
||||
y.push_back(3);
|
||||
|
||||
assert!(hash::hash(&x) == hash::hash(&y));
|
||||
}
|
||||
|
|
@ -1130,9 +1238,9 @@ mod tests {
|
|||
fn test_ord() {
|
||||
let x = RingBuf::new();
|
||||
let mut y = RingBuf::new();
|
||||
y.push(1i);
|
||||
y.push(2);
|
||||
y.push(3);
|
||||
y.push_back(1i);
|
||||
y.push_back(2);
|
||||
y.push_back(3);
|
||||
assert!(x < y);
|
||||
assert!(y > x);
|
||||
assert!(x <= x);
|
||||
|
|
|
|||
|
|
@ -1425,10 +1425,10 @@ mod tests {
|
|||
fn test_capacity() {
|
||||
let mut v = vec![0u64];
|
||||
v.reserve_exact(10u);
|
||||
assert_eq!(v.capacity(), 10u);
|
||||
assert!(v.capacity() >= 11u);
|
||||
let mut v = vec![0u32];
|
||||
v.reserve_exact(10u);
|
||||
assert_eq!(v.capacity(), 10u);
|
||||
assert!(v.capacity() >= 11u);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -2220,7 +2220,7 @@ mod bench {
|
|||
v.set_len(1024);
|
||||
}
|
||||
for i in range(0u, 1024) {
|
||||
*v.get_mut(i) = 0;
|
||||
v[i] = 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,6 +76,8 @@ pub use core::str::{truncate_utf16_at_nul, utf8_char_width, CharRange};
|
|||
pub use core::str::{Str, StrPrelude};
|
||||
pub use unicode::str::{UnicodeStrPrelude, Words, Graphemes, GraphemeIndices};
|
||||
|
||||
// FIXME(conventions): ensure bit/char conventions are followed by str's API
|
||||
|
||||
/*
|
||||
Section: Creating a string
|
||||
*/
|
||||
|
|
@ -308,7 +310,7 @@ impl<'a> Iterator<char> for Recompositions<'a> {
|
|||
self.composee = Some(ch);
|
||||
return Some(k);
|
||||
}
|
||||
self.buffer.push(ch);
|
||||
self.buffer.push_back(ch);
|
||||
self.last_ccc = Some(ch_class);
|
||||
}
|
||||
}
|
||||
|
|
@ -322,7 +324,7 @@ impl<'a> Iterator<char> for Recompositions<'a> {
|
|||
self.state = Purging;
|
||||
return Some(k);
|
||||
}
|
||||
self.buffer.push(ch);
|
||||
self.buffer.push_back(ch);
|
||||
self.last_ccc = Some(ch_class);
|
||||
continue;
|
||||
}
|
||||
|
|
@ -332,7 +334,7 @@ impl<'a> Iterator<char> for Recompositions<'a> {
|
|||
continue;
|
||||
}
|
||||
None => {
|
||||
self.buffer.push(ch);
|
||||
self.buffer.push_back(ch);
|
||||
self.last_ccc = Some(ch_class);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -330,8 +330,8 @@ impl String {
|
|||
|
||||
let mut buf = String::new();
|
||||
buf.push(ch);
|
||||
let size = buf.len() * length;
|
||||
buf.reserve(size);
|
||||
let size = buf.len() * (length - 1);
|
||||
buf.reserve_exact(size);
|
||||
for _ in range(1, length) {
|
||||
buf.push(ch)
|
||||
}
|
||||
|
|
@ -379,27 +379,23 @@ impl String {
|
|||
/// assert!(s.capacity() >= 10);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "just implemented, needs to prove itself"]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn capacity(&self) -> uint {
|
||||
self.vec.capacity()
|
||||
}
|
||||
|
||||
/// Reserves capacity for at least `extra` additional bytes in this string buffer.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// let mut s = String::with_capacity(10);
|
||||
/// let before = s.capacity();
|
||||
/// s.reserve_additional(100);
|
||||
/// assert!(s.capacity() - before >= 100);
|
||||
/// ```
|
||||
#[inline]
|
||||
/// Deprecated: Renamed to `reserve`.
|
||||
#[deprecated = "Renamed to `reserve`"]
|
||||
pub fn reserve_additional(&mut self, extra: uint) {
|
||||
self.vec.reserve_additional(extra)
|
||||
self.vec.reserve(extra)
|
||||
}
|
||||
|
||||
/// Reserves capacity for at least `capacity` bytes in this string buffer.
|
||||
/// Reserves capacity for at least `additional` more bytes to be inserted in the given
|
||||
/// `String`. The collection may reserve more space to avoid frequent reallocations.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if the new capacity overflows `uint`.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
|
|
@ -409,22 +405,33 @@ impl String {
|
|||
/// assert!(s.capacity() >= 10);
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn reserve(&mut self, capacity: uint) {
|
||||
self.vec.reserve(capacity)
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn reserve(&mut self, additional: uint) {
|
||||
self.vec.reserve(additional)
|
||||
}
|
||||
|
||||
/// Reserves capacity for exactly `capacity` bytes in this string buffer.
|
||||
/// Reserves the minimum capacity for exactly `additional` more bytes to be inserted in the
|
||||
/// given `String`. Does nothing if the capacity is already sufficient.
|
||||
///
|
||||
/// Note that the allocator may give the collection more space than it requests. Therefore
|
||||
/// capacity can not be relied upon to be precisely minimal. Prefer `reserve` if future
|
||||
/// insertions are expected.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if the new capacity overflows `uint`.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// let mut s = String::new();
|
||||
/// s.reserve_exact(10);
|
||||
/// assert_eq!(s.capacity(), 10);
|
||||
/// s.reserve(10);
|
||||
/// assert!(s.capacity() >= 10);
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn reserve_exact(&mut self, capacity: uint) {
|
||||
self.vec.reserve_exact(capacity)
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn reserve_exact(&mut self, additional: uint) {
|
||||
self.vec.reserve_exact(additional)
|
||||
}
|
||||
|
||||
/// Shrinks the capacity of this string buffer to match its length.
|
||||
|
|
@ -439,6 +446,7 @@ impl String {
|
|||
/// assert_eq!(s.capacity(), 3);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn shrink_to_fit(&mut self) {
|
||||
self.vec.shrink_to_fit()
|
||||
}
|
||||
|
|
@ -459,7 +467,7 @@ impl String {
|
|||
pub fn push(&mut self, ch: char) {
|
||||
let cur_len = self.len();
|
||||
// This may use up to 4 bytes.
|
||||
self.vec.reserve_additional(4);
|
||||
self.vec.reserve(4);
|
||||
|
||||
unsafe {
|
||||
// Attempt to not use an intermediate buffer by just pushing bytes
|
||||
|
|
@ -590,7 +598,7 @@ impl String {
|
|||
let len = self.len();
|
||||
assert!(idx <= len);
|
||||
assert!(self.as_slice().is_char_boundary(idx));
|
||||
self.vec.reserve_additional(4);
|
||||
self.vec.reserve(4);
|
||||
let mut bits = [0, ..4];
|
||||
let amt = ch.encode_utf8(bits).unwrap();
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,9 @@ use std::hash::{Writer, Hash};
|
|||
|
||||
use vec::Vec;
|
||||
|
||||
// FIXME(conventions): implement bounded iterators
|
||||
// FIXME(conventions): replace rev_iter(_mut) by making iter(_mut) DoubleEnded
|
||||
|
||||
/// This is implemented as an AA tree, which is a simplified variation of
|
||||
/// a red-black tree where red (horizontal) nodes can only be added
|
||||
/// as a right child. The time complexity is the same, and re-balancing
|
||||
|
|
@ -60,7 +63,7 @@ use vec::Vec;
|
|||
/// }
|
||||
///
|
||||
/// for key in range(0, 4) {
|
||||
/// match map.find(&key) {
|
||||
/// match map.get(&key) {
|
||||
/// Some(val) => println!("{} has a value: {}", key, val),
|
||||
/// None => println!("{} not in map", key),
|
||||
/// }
|
||||
|
|
@ -188,14 +191,14 @@ impl<K: Ord, V> Default for TreeMap<K,V> {
|
|||
impl<K: Ord, V> Index<K, V> for TreeMap<K, V> {
|
||||
#[inline]
|
||||
fn index<'a>(&'a self, i: &K) -> &'a V {
|
||||
self.find(i).expect("no entry found for key")
|
||||
self.get(i).expect("no entry found for key")
|
||||
}
|
||||
}
|
||||
|
||||
impl<K: Ord, V> IndexMut<K, V> for TreeMap<K, V> {
|
||||
#[inline]
|
||||
fn index_mut<'a>(&'a mut self, i: &K) -> &'a mut V {
|
||||
self.find_mut(i).expect("no entry found for key")
|
||||
self.get_mut(i).expect("no entry found for key")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -208,6 +211,7 @@ impl<K: Ord, V> TreeMap<K, V> {
|
|||
/// use std::collections::TreeMap;
|
||||
/// let mut map: TreeMap<&str, int> = TreeMap::new();
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn new() -> TreeMap<K, V> { TreeMap{root: None, length: 0} }
|
||||
|
||||
/// Gets a lazy iterator over the keys in the map, in ascending order.
|
||||
|
|
@ -226,6 +230,7 @@ impl<K: Ord, V> TreeMap<K, V> {
|
|||
/// println!("{}", x);
|
||||
/// }
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn keys<'a>(&'a self) -> Keys<'a, K, V> {
|
||||
self.iter().map(|(k, _v)| k)
|
||||
}
|
||||
|
|
@ -247,6 +252,7 @@ impl<K: Ord, V> TreeMap<K, V> {
|
|||
/// println!("{}", x);
|
||||
/// }
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn values<'a>(&'a self) -> Values<'a, K, V> {
|
||||
self.iter().map(|(_k, v)| v)
|
||||
}
|
||||
|
|
@ -267,6 +273,7 @@ impl<K: Ord, V> TreeMap<K, V> {
|
|||
/// println!("{}: {}", key, value);
|
||||
/// }
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn iter<'a>(&'a self) -> Entries<'a, K, V> {
|
||||
Entries {
|
||||
stack: vec!(),
|
||||
|
|
@ -314,10 +321,11 @@ impl<K: Ord, V> TreeMap<K, V> {
|
|||
/// if key == &"b" { break }
|
||||
/// }
|
||||
///
|
||||
/// assert_eq!(map.find(&"a"), Some(&11));
|
||||
/// assert_eq!(map.find(&"b"), Some(&12));
|
||||
/// assert_eq!(map.find(&"c"), Some(&3));
|
||||
/// assert_eq!(map.get(&"a"), Some(&11));
|
||||
/// assert_eq!(map.get(&"b"), Some(&12));
|
||||
/// assert_eq!(map.get(&"c"), Some(&3));
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn iter_mut<'a>(&'a mut self) -> MutEntries<'a, K, V> {
|
||||
MutEntries {
|
||||
stack: vec!(),
|
||||
|
|
@ -345,15 +353,15 @@ impl<K: Ord, V> TreeMap<K, V> {
|
|||
/// if key == &"b" { break }
|
||||
/// }
|
||||
///
|
||||
/// assert_eq!(map.find(&"a"), Some(&1));
|
||||
/// assert_eq!(map.find(&"b"), Some(&12));
|
||||
/// assert_eq!(map.find(&"c"), Some(&13));
|
||||
/// assert_eq!(map.get(&"a"), Some(&1));
|
||||
/// assert_eq!(map.get(&"b"), Some(&12));
|
||||
/// assert_eq!(map.get(&"c"), Some(&13));
|
||||
/// ```
|
||||
pub fn rev_iter_mut<'a>(&'a mut self) -> RevMutEntries<'a, K, V> {
|
||||
RevMutEntries{iter: self.iter_mut()}
|
||||
}
|
||||
|
||||
/// Gets a lazy iterator that consumes the TreeMap.
|
||||
/// Gets a lazy iterator that consumes the treemap.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
|
|
@ -368,6 +376,7 @@ impl<K: Ord, V> TreeMap<K, V> {
|
|||
/// let vec: Vec<(&str, int)> = map.into_iter().collect();
|
||||
/// assert_eq!(vec, vec![("a", 1), ("b", 2), ("c", 3)]);
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn into_iter(self) -> MoveEntries<K, V> {
|
||||
let TreeMap { root, length } = self;
|
||||
let stk = match root {
|
||||
|
|
@ -392,6 +401,7 @@ impl<K: Ord, V> TreeMap<K, V> {
|
|||
/// a.insert(1u, "a");
|
||||
/// assert_eq!(a.len(), 1);
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn len(&self) -> uint { self.length }
|
||||
|
||||
/// Return true if the map contains no elements.
|
||||
|
|
@ -406,6 +416,7 @@ impl<K: Ord, V> TreeMap<K, V> {
|
|||
/// a.insert(1u, "a");
|
||||
/// assert!(!a.is_empty());
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
#[inline]
|
||||
pub fn is_empty(&self) -> bool { self.len() == 0 }
|
||||
|
||||
|
|
@ -421,11 +432,18 @@ impl<K: Ord, V> TreeMap<K, V> {
|
|||
/// a.clear();
|
||||
/// assert!(a.is_empty());
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn clear(&mut self) {
|
||||
self.root = None;
|
||||
self.length = 0
|
||||
}
|
||||
|
||||
/// Deprecated: Renamed to `get`.
|
||||
#[deprecated = "Renamed to `get`"]
|
||||
pub fn find(&self, key: &K) -> Option<&V> {
|
||||
self.get(key)
|
||||
}
|
||||
|
||||
/// Returns a reference to the value corresponding to the key.
|
||||
///
|
||||
/// # Example
|
||||
|
|
@ -435,11 +453,12 @@ impl<K: Ord, V> TreeMap<K, V> {
|
|||
///
|
||||
/// let mut map = TreeMap::new();
|
||||
/// map.insert(1u, "a");
|
||||
/// assert_eq!(map.find(&1), Some(&"a"));
|
||||
/// assert_eq!(map.find(&2), None);
|
||||
/// assert_eq!(map.get(&1), Some(&"a"));
|
||||
/// assert_eq!(map.get(&2), None);
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn find<'a>(&'a self, key: &K) -> Option<&'a V> {
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn get(&self, key: &K) -> Option<&V> {
|
||||
tree_find_with(&self.root, |k2| key.cmp(k2))
|
||||
}
|
||||
|
||||
|
|
@ -456,8 +475,15 @@ impl<K: Ord, V> TreeMap<K, V> {
|
|||
/// assert_eq!(map.contains_key(&2), false);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn contains_key(&self, key: &K) -> bool {
|
||||
self.find(key).is_some()
|
||||
self.get(key).is_some()
|
||||
}
|
||||
|
||||
/// Deprecated: Renamed to `get_mut`.
|
||||
#[deprecated = "Renamed to `get_mut`"]
|
||||
pub fn find_mut(&mut self, key: &K) -> Option<&mut V> {
|
||||
self.get_mut(key)
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to the value corresponding to the key.
|
||||
|
|
@ -469,52 +495,22 @@ impl<K: Ord, V> TreeMap<K, V> {
|
|||
///
|
||||
/// let mut map = TreeMap::new();
|
||||
/// map.insert(1u, "a");
|
||||
/// match map.find_mut(&1) {
|
||||
/// match map.get_mut(&1) {
|
||||
/// Some(x) => *x = "b",
|
||||
/// None => (),
|
||||
/// }
|
||||
/// assert_eq!(map[1], "b");
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn find_mut<'a>(&'a mut self, key: &K) -> Option<&'a mut V> {
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn get_mut(&mut self, key: &K) -> Option<&mut V> {
|
||||
tree_find_with_mut(&mut self.root, |x| key.cmp(x))
|
||||
}
|
||||
|
||||
/// Inserts a key-value pair into the map. An existing value for a
|
||||
/// key is replaced by the new value. Returns `true` if the key did
|
||||
/// not already exist in the map.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use std::collections::TreeMap;
|
||||
///
|
||||
/// let mut map = TreeMap::new();
|
||||
/// assert_eq!(map.insert(2u, "value"), true);
|
||||
/// assert_eq!(map.insert(2, "value2"), false);
|
||||
/// assert_eq!(map[2], "value2");
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn insert(&mut self, key: K, value: V) -> bool {
|
||||
self.swap(key, value).is_none()
|
||||
}
|
||||
|
||||
/// Removes a key-value pair from the map. Returns `true` if the key
|
||||
/// was present in the map.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use std::collections::TreeMap;
|
||||
///
|
||||
/// let mut map = TreeMap::new();
|
||||
/// assert_eq!(map.remove(&1u), false);
|
||||
/// map.insert(1, "a");
|
||||
/// assert_eq!(map.remove(&1), true);
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn remove(&mut self, key: &K) -> bool {
|
||||
self.pop(key).is_some()
|
||||
/// Deprecated: Renamed to `insert`.
|
||||
#[deprecated = "Renamed to `insert`"]
|
||||
pub fn swap(&mut self, key: K, value: V) -> Option<V> {
|
||||
self.insert(key, value)
|
||||
}
|
||||
|
||||
/// Inserts a key-value pair from the map. If the key already had a value
|
||||
|
|
@ -526,19 +522,26 @@ impl<K: Ord, V> TreeMap<K, V> {
|
|||
/// use std::collections::TreeMap;
|
||||
///
|
||||
/// let mut map = TreeMap::new();
|
||||
/// assert_eq!(map.swap(37u, "a"), None);
|
||||
/// assert_eq!(map.insert(37u, "a"), None);
|
||||
/// assert_eq!(map.is_empty(), false);
|
||||
///
|
||||
/// map.insert(37, "b");
|
||||
/// assert_eq!(map.swap(37, "c"), Some("b"));
|
||||
/// assert_eq!(map.insert(37, "c"), Some("b"));
|
||||
/// assert_eq!(map[37], "c");
|
||||
/// ```
|
||||
pub fn swap(&mut self, key: K, value: V) -> Option<V> {
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn insert(&mut self, key: K, value: V) -> Option<V> {
|
||||
let ret = insert(&mut self.root, key, value);
|
||||
if ret.is_none() { self.length += 1 }
|
||||
ret
|
||||
}
|
||||
|
||||
/// Deprecated: Renamed to `remove`.
|
||||
#[deprecated = "Renamed to `remove`"]
|
||||
pub fn pop(&mut self, key: &K) -> Option<V> {
|
||||
self.remove(key)
|
||||
}
|
||||
|
||||
/// Removes a key from the map, returning the value at the key if the key
|
||||
/// was previously in the map.
|
||||
///
|
||||
|
|
@ -549,10 +552,11 @@ impl<K: Ord, V> TreeMap<K, V> {
|
|||
///
|
||||
/// let mut map = TreeMap::new();
|
||||
/// map.insert(1u, "a");
|
||||
/// assert_eq!(map.pop(&1), Some("a"));
|
||||
/// assert_eq!(map.pop(&1), None);
|
||||
/// assert_eq!(map.remove(&1), Some("a"));
|
||||
/// assert_eq!(map.remove(&1), None);
|
||||
/// ```
|
||||
pub fn pop(&mut self, key: &K) -> Option<V> {
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn remove(&mut self, key: &K) -> Option<V> {
|
||||
let ret = remove(&mut self.root, key);
|
||||
if ret.is_some() { self.length -= 1 }
|
||||
ret
|
||||
|
|
@ -567,7 +571,7 @@ impl<K, V> TreeMap<K, V> {
|
|||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use std::collections::TreeMap;
|
||||
/// use collections::tree_map::TreeMap;
|
||||
///
|
||||
/// fn get_headers() -> TreeMap<String, String> {
|
||||
/// let mut result = TreeMap::new();
|
||||
|
|
@ -585,7 +589,7 @@ impl<K, V> TreeMap<K, V> {
|
|||
/// assert_eq!((*ua.unwrap()).as_slice(), "Curl-Rust/0.1");
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn find_with<'a>(&'a self, f:|&K| -> Ordering) -> Option<&'a V> {
|
||||
pub fn find_with(&self, f:|&K| -> Ordering) -> Option<&V> {
|
||||
tree_find_with(&self.root, f)
|
||||
}
|
||||
|
||||
|
|
@ -596,9 +600,7 @@ impl<K, V> TreeMap<K, V> {
|
|||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use std::collections::TreeMap;
|
||||
///
|
||||
/// let mut t = TreeMap::new();
|
||||
/// let mut t = collections::tree_map::TreeMap::new();
|
||||
/// t.insert("Content-Type", "application/xml");
|
||||
/// t.insert("User-Agent", "Curl-Rust/0.1");
|
||||
///
|
||||
|
|
@ -608,7 +610,7 @@ impl<K, V> TreeMap<K, V> {
|
|||
/// None => panic!(),
|
||||
/// }
|
||||
///
|
||||
/// assert_eq!(t.find(&"User-Agent"), Some(&new_ua));
|
||||
/// assert_eq!(t.get(&"User-Agent"), Some(&new_ua));
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn find_with_mut<'a>(&'a mut self, f:|&K| -> Ordering) -> Option<&'a mut V> {
|
||||
|
|
@ -742,10 +744,10 @@ impl<K: Ord, V> TreeMap<K, V> {
|
|||
/// *value = "changed";
|
||||
/// }
|
||||
///
|
||||
/// assert_eq!(map.find(&2), Some(&"a"));
|
||||
/// assert_eq!(map.find(&4), Some(&"changed"));
|
||||
/// assert_eq!(map.find(&6), Some(&"changed"));
|
||||
/// assert_eq!(map.find(&8), Some(&"changed"));
|
||||
/// assert_eq!(map.get(&2), Some(&"a"));
|
||||
/// assert_eq!(map.get(&4), Some(&"changed"));
|
||||
/// assert_eq!(map.get(&6), Some(&"changed"));
|
||||
/// assert_eq!(map.get(&8), Some(&"changed"));
|
||||
/// ```
|
||||
pub fn lower_bound_mut<'a>(&'a mut self, k: &K) -> MutEntries<'a, K, V> {
|
||||
bound_setup!(self.iter_mut_for_traversal(), k, true)
|
||||
|
|
@ -776,10 +778,10 @@ impl<K: Ord, V> TreeMap<K, V> {
|
|||
/// *value = "changed";
|
||||
/// }
|
||||
///
|
||||
/// assert_eq!(map.find(&2), Some(&"a"));
|
||||
/// assert_eq!(map.find(&4), Some(&"b"));
|
||||
/// assert_eq!(map.find(&6), Some(&"changed"));
|
||||
/// assert_eq!(map.find(&8), Some(&"changed"));
|
||||
/// assert_eq!(map.get(&2), Some(&"a"));
|
||||
/// assert_eq!(map.get(&4), Some(&"b"));
|
||||
/// assert_eq!(map.get(&6), Some(&"changed"));
|
||||
/// assert_eq!(map.get(&8), Some(&"changed"));
|
||||
/// ```
|
||||
pub fn upper_bound_mut<'a>(&'a mut self, k: &K) -> MutEntries<'a, K, V> {
|
||||
bound_setup!(self.iter_mut_for_traversal(), k, false)
|
||||
|
|
@ -1287,16 +1289,16 @@ mod test_treemap {
|
|||
#[test]
|
||||
fn find_empty() {
|
||||
let m: TreeMap<int,int> = TreeMap::new();
|
||||
assert!(m.find(&5) == None);
|
||||
assert!(m.get(&5) == None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn find_not_found() {
|
||||
let mut m = TreeMap::new();
|
||||
assert!(m.insert(1i, 2i));
|
||||
assert!(m.insert(5i, 3i));
|
||||
assert!(m.insert(9i, 3i));
|
||||
assert_eq!(m.find(&2), None);
|
||||
assert!(m.insert(1i, 2i).is_none());
|
||||
assert!(m.insert(5i, 3i).is_none());
|
||||
assert!(m.insert(9i, 3i).is_none());
|
||||
assert_eq!(m.get(&2), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -1308,41 +1310,42 @@ mod test_treemap {
|
|||
#[test]
|
||||
fn find_with_not_found() {
|
||||
let mut m = TreeMap::new();
|
||||
assert!(m.insert("test1", 2i));
|
||||
assert!(m.insert("test2", 3i));
|
||||
assert!(m.insert("test3", 3i));
|
||||
assert!(m.insert("test1", 2i).is_none());
|
||||
assert!(m.insert("test2", 3i).is_none());
|
||||
assert!(m.insert("test3", 3i).is_none());
|
||||
assert_eq!(m.find_with(|&k| "test4".cmp(k)), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn find_with_found() {
|
||||
let mut m = TreeMap::new();
|
||||
assert!(m.insert("test1", 2i));
|
||||
assert!(m.insert("test2", 3i));
|
||||
assert!(m.insert("test3", 4i));
|
||||
assert!(m.insert("test1", 2i).is_none());
|
||||
assert!(m.insert("test2", 3i).is_none());
|
||||
assert!(m.insert("test3", 4i).is_none());
|
||||
assert_eq!(m.find_with(|&k| "test2".cmp(k)), Some(&3i));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_find_mut() {
|
||||
let mut m = TreeMap::new();
|
||||
assert!(m.insert(1i, 12i));
|
||||
assert!(m.insert(2, 8));
|
||||
assert!(m.insert(5, 14));
|
||||
assert!(m.insert(1i, 12i).is_none());
|
||||
assert!(m.insert(2, 8).is_none());
|
||||
assert!(m.insert(5, 14).is_none());
|
||||
let new = 100;
|
||||
match m.find_mut(&5) {
|
||||
match m.get_mut(&5) {
|
||||
None => panic!(), Some(x) => *x = new
|
||||
}
|
||||
assert_eq!(m.find(&5), Some(&new));
|
||||
assert_eq!(m.get(&5), Some(&new));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_find_with_mut() {
|
||||
let mut m = TreeMap::new();
|
||||
assert!(m.insert("t1", 12i));
|
||||
assert!(m.insert("t2", 8));
|
||||
assert!(m.insert("t5", 14));
|
||||
assert!(m.insert("t1", 12i).is_none());
|
||||
assert!(m.insert("t2", 8).is_none());
|
||||
assert!(m.insert("t5", 14).is_none());
|
||||
let new = 100;
|
||||
|
||||
match m.find_with_mut(|&k| "t5".cmp(k)) {
|
||||
None => panic!(), Some(x) => *x = new
|
||||
}
|
||||
|
|
@ -1352,23 +1355,23 @@ mod test_treemap {
|
|||
#[test]
|
||||
fn insert_replace() {
|
||||
let mut m = TreeMap::new();
|
||||
assert!(m.insert(5i, 2i));
|
||||
assert!(m.insert(2, 9));
|
||||
assert!(!m.insert(2, 11));
|
||||
assert_eq!(m.find(&2).unwrap(), &11);
|
||||
assert!(m.insert(5i, 2i).is_none());
|
||||
assert!(m.insert(2, 9).is_none());
|
||||
assert!(!m.insert(2, 11).is_none());
|
||||
assert_eq!(m.get(&2).unwrap(), &11);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_clear() {
|
||||
let mut m = TreeMap::new();
|
||||
m.clear();
|
||||
assert!(m.insert(5i, 11i));
|
||||
assert!(m.insert(12, -3));
|
||||
assert!(m.insert(19, 2));
|
||||
assert!(m.insert(5i, 11i).is_none());
|
||||
assert!(m.insert(12, -3).is_none());
|
||||
assert!(m.insert(19, 2).is_none());
|
||||
m.clear();
|
||||
assert!(m.find(&5).is_none());
|
||||
assert!(m.find(&12).is_none());
|
||||
assert!(m.find(&19).is_none());
|
||||
assert!(m.get(&5).is_none());
|
||||
assert!(m.get(&12).is_none());
|
||||
assert!(m.get(&19).is_none());
|
||||
assert!(m.is_empty());
|
||||
}
|
||||
|
||||
|
|
@ -1384,8 +1387,8 @@ mod test_treemap {
|
|||
m.insert(k1.clone(), v1.clone());
|
||||
m.insert(k2.clone(), v2.clone());
|
||||
|
||||
assert_eq!(m.find(&k2), Some(&v2));
|
||||
assert_eq!(m.find(&k1), Some(&v1));
|
||||
assert_eq!(m.get(&k2), Some(&v2));
|
||||
assert_eq!(m.get(&k1), Some(&v1));
|
||||
}
|
||||
|
||||
fn check_equal<K: PartialEq + Ord, V: PartialEq>(ctrl: &[(K, V)],
|
||||
|
|
@ -1393,7 +1396,7 @@ mod test_treemap {
|
|||
assert_eq!(ctrl.is_empty(), map.is_empty());
|
||||
for x in ctrl.iter() {
|
||||
let &(ref k, ref v) = x;
|
||||
assert!(map.find(k).unwrap() == v)
|
||||
assert!(map.get(k).unwrap() == v)
|
||||
}
|
||||
for (map_k, map_v) in map.iter() {
|
||||
let mut found = false;
|
||||
|
|
@ -1455,7 +1458,7 @@ mod test_treemap {
|
|||
let mut ctrl = vec![];
|
||||
|
||||
check_equal(ctrl.as_slice(), &map);
|
||||
assert!(map.find(&5).is_none());
|
||||
assert!(map.get(&5).is_none());
|
||||
|
||||
let seed: &[_] = &[42];
|
||||
let mut rng: rand::IsaacRng = rand::SeedableRng::from_seed(seed);
|
||||
|
|
@ -1465,7 +1468,7 @@ mod test_treemap {
|
|||
let k = rng.gen();
|
||||
let v = rng.gen();
|
||||
if !ctrl.iter().any(|x| x == &(k, v)) {
|
||||
assert!(map.insert(k, v));
|
||||
assert!(map.insert(k, v).is_none());
|
||||
ctrl.push((k, v));
|
||||
check_structure(&map);
|
||||
check_equal(ctrl.as_slice(), &map);
|
||||
|
|
@ -1475,7 +1478,7 @@ mod test_treemap {
|
|||
for _ in range(0u, 30) {
|
||||
let r = rng.gen_range(0, ctrl.len());
|
||||
let (key, _) = ctrl.remove(r).unwrap();
|
||||
assert!(map.remove(&key));
|
||||
assert!(map.remove(&key).is_some());
|
||||
check_structure(&map);
|
||||
check_equal(ctrl.as_slice(), &map);
|
||||
}
|
||||
|
|
@ -1485,19 +1488,19 @@ mod test_treemap {
|
|||
#[test]
|
||||
fn test_len() {
|
||||
let mut m = TreeMap::new();
|
||||
assert!(m.insert(3i, 6i));
|
||||
assert!(m.insert(3i, 6i).is_none());
|
||||
assert_eq!(m.len(), 1);
|
||||
assert!(m.insert(0, 0));
|
||||
assert!(m.insert(0, 0).is_none());
|
||||
assert_eq!(m.len(), 2);
|
||||
assert!(m.insert(4, 8));
|
||||
assert!(m.insert(4, 8).is_none());
|
||||
assert_eq!(m.len(), 3);
|
||||
assert!(m.remove(&3));
|
||||
assert!(m.remove(&3).is_some());
|
||||
assert_eq!(m.len(), 2);
|
||||
assert!(!m.remove(&5));
|
||||
assert!(!m.remove(&5).is_some());
|
||||
assert_eq!(m.len(), 2);
|
||||
assert!(m.insert(2, 4));
|
||||
assert!(m.insert(2, 4).is_none());
|
||||
assert_eq!(m.len(), 3);
|
||||
assert!(m.insert(1, 2));
|
||||
assert!(m.insert(1, 2).is_none());
|
||||
assert_eq!(m.len(), 4);
|
||||
}
|
||||
|
||||
|
|
@ -1505,11 +1508,11 @@ mod test_treemap {
|
|||
fn test_iterator() {
|
||||
let mut m = TreeMap::new();
|
||||
|
||||
assert!(m.insert(3i, 6i));
|
||||
assert!(m.insert(0, 0));
|
||||
assert!(m.insert(4, 8));
|
||||
assert!(m.insert(2, 4));
|
||||
assert!(m.insert(1, 2));
|
||||
assert!(m.insert(3i, 6i).is_none());
|
||||
assert!(m.insert(0, 0).is_none());
|
||||
assert!(m.insert(4, 8).is_none());
|
||||
assert!(m.insert(2, 4).is_none());
|
||||
assert!(m.insert(1, 2).is_none());
|
||||
|
||||
let mut n = 0;
|
||||
for (k, v) in m.iter() {
|
||||
|
|
@ -1524,7 +1527,7 @@ mod test_treemap {
|
|||
fn test_interval_iteration() {
|
||||
let mut m = TreeMap::new();
|
||||
for i in range(1i, 100i) {
|
||||
assert!(m.insert(i * 2, i * 4));
|
||||
assert!(m.insert(i * 2, i * 4).is_none());
|
||||
}
|
||||
|
||||
for i in range(1i, 198i) {
|
||||
|
|
@ -1548,11 +1551,11 @@ mod test_treemap {
|
|||
fn test_rev_iter() {
|
||||
let mut m = TreeMap::new();
|
||||
|
||||
assert!(m.insert(3i, 6i));
|
||||
assert!(m.insert(0, 0));
|
||||
assert!(m.insert(4, 8));
|
||||
assert!(m.insert(2, 4));
|
||||
assert!(m.insert(1, 2));
|
||||
assert!(m.insert(3i, 6i).is_none());
|
||||
assert!(m.insert(0, 0).is_none());
|
||||
assert!(m.insert(4, 8).is_none());
|
||||
assert!(m.insert(2, 4).is_none());
|
||||
assert!(m.insert(1, 2).is_none());
|
||||
|
||||
let mut n = 4;
|
||||
for (k, v) in m.rev_iter() {
|
||||
|
|
@ -1566,7 +1569,7 @@ mod test_treemap {
|
|||
fn test_mut_iter() {
|
||||
let mut m = TreeMap::new();
|
||||
for i in range(0u, 10) {
|
||||
assert!(m.insert(i, 100 * i));
|
||||
assert!(m.insert(i, 100 * i).is_none());
|
||||
}
|
||||
|
||||
for (i, (&k, v)) in m.iter_mut().enumerate() {
|
||||
|
|
@ -1581,7 +1584,7 @@ mod test_treemap {
|
|||
fn test_mut_rev_iter() {
|
||||
let mut m = TreeMap::new();
|
||||
for i in range(0u, 10) {
|
||||
assert!(m.insert(i, 100 * i));
|
||||
assert!(m.insert(i, 100 * i).is_none());
|
||||
}
|
||||
|
||||
for (i, (&k, v)) in m.rev_iter_mut().enumerate() {
|
||||
|
|
@ -1598,8 +1601,8 @@ mod test_treemap {
|
|||
let mut m_lower = TreeMap::new();
|
||||
let mut m_upper = TreeMap::new();
|
||||
for i in range(1i, 100i) {
|
||||
assert!(m_lower.insert(i * 2, i * 4));
|
||||
assert!(m_upper.insert(i * 2, i * 4));
|
||||
assert!(m_lower.insert(i * 2, i * 4).is_none());
|
||||
assert!(m_upper.insert(i * 2, i * 4).is_none());
|
||||
}
|
||||
|
||||
for i in range(1i, 199) {
|
||||
|
|
@ -1653,15 +1656,15 @@ mod test_treemap {
|
|||
let mut b = TreeMap::new();
|
||||
|
||||
assert!(a == b);
|
||||
assert!(a.insert(0i, 5i));
|
||||
assert!(a.insert(0i, 5i).is_none());
|
||||
assert!(a != b);
|
||||
assert!(b.insert(0, 4));
|
||||
assert!(b.insert(0, 4).is_none());
|
||||
assert!(a != b);
|
||||
assert!(a.insert(5, 19));
|
||||
assert!(a.insert(5, 19).is_none());
|
||||
assert!(a != b);
|
||||
assert!(!b.insert(0, 5));
|
||||
assert!(!b.insert(0, 5).is_none());
|
||||
assert!(a != b);
|
||||
assert!(b.insert(5, 19));
|
||||
assert!(b.insert(5, 19).is_none());
|
||||
assert!(a == b);
|
||||
}
|
||||
|
||||
|
|
@ -1671,15 +1674,15 @@ mod test_treemap {
|
|||
let mut b = TreeMap::new();
|
||||
|
||||
assert!(!(a < b) && !(b < a));
|
||||
assert!(b.insert(0i, 5i));
|
||||
assert!(b.insert(0i, 5i).is_none());
|
||||
assert!(a < b);
|
||||
assert!(a.insert(0, 7));
|
||||
assert!(a.insert(0, 7).is_none());
|
||||
assert!(!(a < b) && b < a);
|
||||
assert!(b.insert(-2, 0));
|
||||
assert!(b.insert(-2, 0).is_none());
|
||||
assert!(b < a);
|
||||
assert!(a.insert(-5, 2));
|
||||
assert!(a.insert(-5, 2).is_none());
|
||||
assert!(a < b);
|
||||
assert!(a.insert(6, 2));
|
||||
assert!(a.insert(6, 2).is_none());
|
||||
assert!(a < b && !(b < a));
|
||||
}
|
||||
|
||||
|
|
@ -1689,10 +1692,10 @@ mod test_treemap {
|
|||
let mut b = TreeMap::new();
|
||||
|
||||
assert!(a <= b && a >= b);
|
||||
assert!(a.insert(1i, 1i));
|
||||
assert!(a.insert(1i, 1i).is_none());
|
||||
assert!(a > b && a >= b);
|
||||
assert!(b < a && b <= a);
|
||||
assert!(b.insert(2, 2));
|
||||
assert!(b.insert(2, 2).is_none());
|
||||
assert!(b > a && b >= a);
|
||||
assert!(a < b && a <= b);
|
||||
}
|
||||
|
|
@ -1720,11 +1723,11 @@ mod test_treemap {
|
|||
let (x4, y4) = (29, 5);
|
||||
let (x5, y5) = (103, 3);
|
||||
|
||||
assert!(m.insert(x1, y1));
|
||||
assert!(m.insert(x2, y2));
|
||||
assert!(m.insert(x3, y3));
|
||||
assert!(m.insert(x4, y4));
|
||||
assert!(m.insert(x5, y5));
|
||||
assert!(m.insert(x1, y1).is_none());
|
||||
assert!(m.insert(x2, y2).is_none());
|
||||
assert!(m.insert(x3, y3).is_none());
|
||||
assert!(m.insert(x4, y4).is_none());
|
||||
assert!(m.insert(x5, y5).is_none());
|
||||
|
||||
let m = m;
|
||||
let mut a = m.iter();
|
||||
|
|
@ -1765,7 +1768,7 @@ mod test_treemap {
|
|||
let map: TreeMap<int, int> = xs.iter().map(|&x| x).collect();
|
||||
|
||||
for &(k, v) in xs.iter() {
|
||||
assert_eq!(map.find(&k), Some(&v));
|
||||
assert_eq!(map.get(&k), Some(&v));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1795,17 +1798,17 @@ mod test_treemap {
|
|||
#[test]
|
||||
fn test_swap() {
|
||||
let mut m = TreeMap::new();
|
||||
assert_eq!(m.swap(1u, 2i), None);
|
||||
assert_eq!(m.swap(1u, 3i), Some(2));
|
||||
assert_eq!(m.swap(1u, 4i), Some(3));
|
||||
assert_eq!(m.insert(1u, 2i), None);
|
||||
assert_eq!(m.insert(1u, 3i), Some(2));
|
||||
assert_eq!(m.insert(1u, 4i), Some(3));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_pop() {
|
||||
let mut m = TreeMap::new();
|
||||
m.insert(1u, 2i);
|
||||
assert_eq!(m.pop(&1), Some(2));
|
||||
assert_eq!(m.pop(&1), None);
|
||||
assert_eq!(m.remove(&1), Some(2));
|
||||
assert_eq!(m.remove(&1), None);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1857,7 +1860,7 @@ mod bench {
|
|||
let mut m : TreeMap<uint,uint> = TreeMap::new();
|
||||
find_rand_n(100, &mut m, b,
|
||||
|m, i| { m.insert(i, 1); },
|
||||
|m, i| { m.find(&i); });
|
||||
|m, i| { m.get(&i); });
|
||||
}
|
||||
|
||||
#[bench]
|
||||
|
|
@ -1865,7 +1868,7 @@ mod bench {
|
|||
let mut m : TreeMap<uint,uint> = TreeMap::new();
|
||||
find_rand_n(10_000, &mut m, b,
|
||||
|m, i| { m.insert(i, 1); },
|
||||
|m, i| { m.find(&i); });
|
||||
|m, i| { m.get(&i); });
|
||||
}
|
||||
|
||||
// Find seq
|
||||
|
|
@ -1874,7 +1877,7 @@ mod bench {
|
|||
let mut m : TreeMap<uint,uint> = TreeMap::new();
|
||||
find_seq_n(100, &mut m, b,
|
||||
|m, i| { m.insert(i, 1); },
|
||||
|m, i| { m.find(&i); });
|
||||
|m, i| { m.get(&i); });
|
||||
}
|
||||
|
||||
#[bench]
|
||||
|
|
@ -1882,7 +1885,7 @@ mod bench {
|
|||
let mut m : TreeMap<uint,uint> = TreeMap::new();
|
||||
find_seq_n(10_000, &mut m, b,
|
||||
|m, i| { m.insert(i, 1); },
|
||||
|m, i| { m.find(&i); });
|
||||
|m, i| { m.get(&i); });
|
||||
}
|
||||
|
||||
fn bench_iter(b: &mut Bencher, size: uint) {
|
||||
|
|
@ -1890,7 +1893,7 @@ mod bench {
|
|||
let mut rng = weak_rng();
|
||||
|
||||
for _ in range(0, size) {
|
||||
map.swap(rng.gen(), rng.gen());
|
||||
map.insert(rng.gen(), rng.gen());
|
||||
}
|
||||
|
||||
b.iter(|| {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,10 @@ use std::hash::{Writer, Hash};
|
|||
|
||||
use tree_map::{TreeMap, Entries, RevEntries, MoveEntries};
|
||||
|
||||
// FIXME(conventions): implement bounded iterators
|
||||
// FIXME(conventions): implement BitOr, BitAnd, BitXor, and Sub
|
||||
// FIXME(conventions): replace rev_iter(_mut) by making iter(_mut) DoubleEnded
|
||||
|
||||
/// An implementation of the `Set` trait on top of the `TreeMap` container. The
|
||||
/// only requirement is that the type of the elements contained ascribes to the
|
||||
/// `Ord` trait.
|
||||
|
|
@ -145,6 +149,7 @@ impl<T: Ord> TreeSet<T> {
|
|||
/// let mut set: TreeSet<int> = TreeSet::new();
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn new() -> TreeSet<T> { TreeSet{map: TreeMap::new()} }
|
||||
|
||||
/// Gets a lazy iterator over the values in the set, in ascending order.
|
||||
|
|
@ -161,6 +166,7 @@ impl<T: Ord> TreeSet<T> {
|
|||
/// }
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn iter<'a>(&'a self) -> SetItems<'a, T> {
|
||||
SetItems{iter: self.map.iter()}
|
||||
}
|
||||
|
|
@ -197,6 +203,7 @@ impl<T: Ord> TreeSet<T> {
|
|||
/// assert_eq!(v, vec![1, 2, 3, 4, 5]);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn into_iter(self) -> MoveSetItems<T> {
|
||||
self.map.into_iter().map(|(value, _)| value)
|
||||
}
|
||||
|
|
@ -261,6 +268,7 @@ impl<T: Ord> TreeSet<T> {
|
|||
/// let diff: TreeSet<int> = b.difference(&a).map(|&x| x).collect();
|
||||
/// assert_eq!(diff, [4, 5].iter().map(|&x| x).collect());
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn difference<'a>(&'a self, other: &'a TreeSet<T>) -> DifferenceItems<'a, T> {
|
||||
DifferenceItems{a: self.iter().peekable(), b: other.iter().peekable()}
|
||||
}
|
||||
|
|
@ -286,6 +294,7 @@ impl<T: Ord> TreeSet<T> {
|
|||
/// assert_eq!(diff1, diff2);
|
||||
/// assert_eq!(diff1, [1, 2, 4, 5].iter().map(|&x| x).collect());
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn symmetric_difference<'a>(&'a self, other: &'a TreeSet<T>)
|
||||
-> SymDifferenceItems<'a, T> {
|
||||
SymDifferenceItems{a: self.iter().peekable(), b: other.iter().peekable()}
|
||||
|
|
@ -309,6 +318,7 @@ impl<T: Ord> TreeSet<T> {
|
|||
/// let diff: TreeSet<int> = a.intersection(&b).map(|&x| x).collect();
|
||||
/// assert_eq!(diff, [2, 3].iter().map(|&x| x).collect());
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn intersection<'a>(&'a self, other: &'a TreeSet<T>)
|
||||
-> IntersectionItems<'a, T> {
|
||||
IntersectionItems{a: self.iter().peekable(), b: other.iter().peekable()}
|
||||
|
|
@ -332,6 +342,7 @@ impl<T: Ord> TreeSet<T> {
|
|||
/// let diff: TreeSet<int> = a.union(&b).map(|&x| x).collect();
|
||||
/// assert_eq!(diff, [1, 2, 3, 4, 5].iter().map(|&x| x).collect());
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn union<'a>(&'a self, other: &'a TreeSet<T>) -> UnionItems<'a, T> {
|
||||
UnionItems{a: self.iter().peekable(), b: other.iter().peekable()}
|
||||
}
|
||||
|
|
@ -349,6 +360,7 @@ impl<T: Ord> TreeSet<T> {
|
|||
/// assert_eq!(v.len(), 1);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn len(&self) -> uint { self.map.len() }
|
||||
|
||||
/// Returns true if the set contains no elements
|
||||
|
|
@ -363,6 +375,7 @@ impl<T: Ord> TreeSet<T> {
|
|||
/// v.insert(1i);
|
||||
/// assert!(!v.is_empty());
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn is_empty(&self) -> bool { self.len() == 0 }
|
||||
|
||||
/// Clears the set, removing all values.
|
||||
|
|
@ -378,6 +391,7 @@ impl<T: Ord> TreeSet<T> {
|
|||
/// assert!(v.is_empty());
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn clear(&mut self) { self.map.clear() }
|
||||
|
||||
/// Returns `true` if the set contains a value.
|
||||
|
|
@ -392,6 +406,7 @@ impl<T: Ord> TreeSet<T> {
|
|||
/// assert_eq!(set.contains(&4), false);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn contains(&self, value: &T) -> bool {
|
||||
self.map.contains_key(value)
|
||||
}
|
||||
|
|
@ -413,6 +428,7 @@ impl<T: Ord> TreeSet<T> {
|
|||
/// b.insert(1);
|
||||
/// assert_eq!(a.is_disjoint(&b), false);
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn is_disjoint(&self, other: &TreeSet<T>) -> bool {
|
||||
self.intersection(other).next().is_none()
|
||||
}
|
||||
|
|
@ -433,6 +449,7 @@ impl<T: Ord> TreeSet<T> {
|
|||
/// set.insert(4);
|
||||
/// assert_eq!(set.is_subset(&sup), false);
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn is_subset(&self, other: &TreeSet<T>) -> bool {
|
||||
let mut x = self.iter();
|
||||
let mut y = other.iter();
|
||||
|
|
@ -476,6 +493,7 @@ impl<T: Ord> TreeSet<T> {
|
|||
/// set.insert(2);
|
||||
/// assert_eq!(set.is_superset(&sub), true);
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn is_superset(&self, other: &TreeSet<T>) -> bool {
|
||||
other.is_subset(self)
|
||||
}
|
||||
|
|
@ -495,7 +513,8 @@ impl<T: Ord> TreeSet<T> {
|
|||
/// assert_eq!(set.len(), 1);
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn insert(&mut self, value: T) -> bool { self.map.insert(value, ()) }
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn insert(&mut self, value: T) -> bool { self.map.insert(value, ()).is_none() }
|
||||
|
||||
/// Removes a value from the set. Returns `true` if the value was
|
||||
/// present in the set.
|
||||
|
|
@ -512,7 +531,8 @@ impl<T: Ord> TreeSet<T> {
|
|||
/// assert_eq!(set.remove(&2), false);
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn remove(&mut self, value: &T) -> bool { self.map.remove(value) }
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn remove(&mut self, value: &T) -> bool { self.map.remove(value).is_some() }
|
||||
}
|
||||
|
||||
/// A lazy forward iterator over a set.
|
||||
|
|
|
|||
|
|
@ -32,6 +32,10 @@ use std::hash::{Writer, Hash};
|
|||
use slice::{Items, MutItems};
|
||||
use slice;
|
||||
|
||||
// FIXME(conventions): implement bounded iterators
|
||||
// FIXME(conventions): implement into_iter
|
||||
// FIXME(conventions): replace each_reverse by making iter DoubleEnded
|
||||
|
||||
// FIXME: #5244: need to manually update the TrieNode constructor
|
||||
const SHIFT: uint = 4;
|
||||
const SIZE: uint = 1 << SHIFT;
|
||||
|
|
@ -59,14 +63,14 @@ enum Child<T> {
|
|||
/// map.insert(1, "Martin");
|
||||
///
|
||||
/// assert_eq!(map.len(), 3);
|
||||
/// assert_eq!(map.find(&1), Some(&"Martin"));
|
||||
/// assert_eq!(map.get(&1), Some(&"Martin"));
|
||||
///
|
||||
/// if !map.contains_key(&90) {
|
||||
/// println!("Nobody is keyed 90");
|
||||
/// }
|
||||
///
|
||||
/// // Update a key
|
||||
/// match map.find_mut(&1) {
|
||||
/// match map.get_mut(&1) {
|
||||
/// Some(value) => *value = "Olga",
|
||||
/// None => (),
|
||||
/// }
|
||||
|
|
@ -140,6 +144,7 @@ impl<T> TrieMap<T> {
|
|||
/// let mut map: TrieMap<&str> = TrieMap::new();
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn new() -> TrieMap<T> {
|
||||
TrieMap{root: TrieNode::new(), length: 0}
|
||||
}
|
||||
|
|
@ -169,12 +174,14 @@ impl<T> TrieMap<T> {
|
|||
|
||||
/// Gets an iterator visiting all keys in ascending order by the keys.
|
||||
/// The iterator's element type is `uint`.
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn keys<'r>(&'r self) -> Keys<'r, T> {
|
||||
self.iter().map(|(k, _v)| k)
|
||||
}
|
||||
|
||||
/// Gets an iterator visiting all values in ascending order by the keys.
|
||||
/// The iterator's element type is `&'r T`.
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn values<'r>(&'r self) -> Values<'r, T> {
|
||||
self.iter().map(|(_k, v)| v)
|
||||
}
|
||||
|
|
@ -191,6 +198,7 @@ impl<T> TrieMap<T> {
|
|||
/// println!("{}: {}", key, value);
|
||||
/// }
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn iter<'a>(&'a self) -> Entries<'a, T> {
|
||||
let mut iter = unsafe {Entries::new()};
|
||||
iter.stack[0] = self.root.children.iter();
|
||||
|
|
@ -214,10 +222,11 @@ impl<T> TrieMap<T> {
|
|||
/// *value = -(key as int);
|
||||
/// }
|
||||
///
|
||||
/// assert_eq!(map.find(&1), Some(&-1));
|
||||
/// assert_eq!(map.find(&2), Some(&-2));
|
||||
/// assert_eq!(map.find(&3), Some(&-3));
|
||||
/// assert_eq!(map.get(&1), Some(&-1));
|
||||
/// assert_eq!(map.get(&2), Some(&-2));
|
||||
/// assert_eq!(map.get(&3), Some(&-3));
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn iter_mut<'a>(&'a mut self) -> MutEntries<'a, T> {
|
||||
let mut iter = unsafe {MutEntries::new()};
|
||||
iter.stack[0] = self.root.children.iter_mut();
|
||||
|
|
@ -241,6 +250,7 @@ impl<T> TrieMap<T> {
|
|||
/// assert_eq!(a.len(), 1);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn len(&self) -> uint { self.length }
|
||||
|
||||
/// Return true if the map contains no elements.
|
||||
|
|
@ -256,6 +266,7 @@ impl<T> TrieMap<T> {
|
|||
/// assert!(!a.is_empty());
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn is_empty(&self) -> bool { self.len() == 0 }
|
||||
|
||||
/// Clears the map, removing all values.
|
||||
|
|
@ -271,11 +282,18 @@ impl<T> TrieMap<T> {
|
|||
/// assert!(a.is_empty());
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn clear(&mut self) {
|
||||
self.root = TrieNode::new();
|
||||
self.length = 0;
|
||||
}
|
||||
|
||||
/// Deprecated: renamed to `get`.
|
||||
#[deprecated = "renamed to `get`"]
|
||||
pub fn find(&self, key: &uint) -> Option<&T> {
|
||||
self.get(key)
|
||||
}
|
||||
|
||||
/// Returns a reference to the value corresponding to the key.
|
||||
///
|
||||
/// # Example
|
||||
|
|
@ -285,12 +303,13 @@ impl<T> TrieMap<T> {
|
|||
///
|
||||
/// let mut map = TrieMap::new();
|
||||
/// map.insert(1, "a");
|
||||
/// assert_eq!(map.find(&1), Some(&"a"));
|
||||
/// assert_eq!(map.find(&2), None);
|
||||
/// assert_eq!(map.get(&1), Some(&"a"));
|
||||
/// assert_eq!(map.get(&2), None);
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn find<'a>(&'a self, key: &uint) -> Option<&'a T> {
|
||||
let mut node: &'a TrieNode<T> = &self.root;
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn get(&self, key: &uint) -> Option<&T> {
|
||||
let mut node = &self.root;
|
||||
let mut idx = 0;
|
||||
loop {
|
||||
match node.children[chunk(*key, idx)] {
|
||||
|
|
@ -321,8 +340,15 @@ impl<T> TrieMap<T> {
|
|||
/// assert_eq!(map.contains_key(&2), false);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn contains_key(&self, key: &uint) -> bool {
|
||||
self.find(key).is_some()
|
||||
self.get(key).is_some()
|
||||
}
|
||||
|
||||
/// Deprecated: renamed to `get_mut`.
|
||||
#[deprecated = "renamed to `get_mut`"]
|
||||
pub fn find_mut(&mut self, key: &uint) -> Option<&mut T> {
|
||||
self.get_mut(key)
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to the value corresponding to the key.
|
||||
|
|
@ -334,52 +360,22 @@ impl<T> TrieMap<T> {
|
|||
///
|
||||
/// let mut map = TrieMap::new();
|
||||
/// map.insert(1, "a");
|
||||
/// match map.find_mut(&1) {
|
||||
/// match map.get_mut(&1) {
|
||||
/// Some(x) => *x = "b",
|
||||
/// None => (),
|
||||
/// }
|
||||
/// assert_eq!(map[1], "b");
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn find_mut<'a>(&'a mut self, key: &uint) -> Option<&'a mut T> {
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn get_mut<'a>(&'a mut self, key: &uint) -> Option<&'a mut T> {
|
||||
find_mut(&mut self.root.children[chunk(*key, 0)], *key, 1)
|
||||
}
|
||||
|
||||
/// Inserts a key-value pair into the map. An existing value for a
|
||||
/// key is replaced by the new value. Returns `true` if the key did
|
||||
/// not already exist in the map.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use std::collections::TrieMap;
|
||||
///
|
||||
/// let mut map = TrieMap::new();
|
||||
/// assert_eq!(map.insert(2, "value"), true);
|
||||
/// assert_eq!(map.insert(2, "value2"), false);
|
||||
/// assert_eq!(map[2], "value2");
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn insert(&mut self, key: uint, value: T) -> bool {
|
||||
self.swap(key, value).is_none()
|
||||
}
|
||||
|
||||
/// Removes a key-value pair from the map. Returns `true` if the key
|
||||
/// was present in the map.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use std::collections::TrieMap;
|
||||
///
|
||||
/// let mut map = TrieMap::new();
|
||||
/// assert_eq!(map.remove(&1), false);
|
||||
/// map.insert(1, "a");
|
||||
/// assert_eq!(map.remove(&1), true);
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn remove(&mut self, key: &uint) -> bool {
|
||||
self.pop(key).is_some()
|
||||
/// Deprecated: Renamed to `insert`.
|
||||
#[deprecated = "Renamed to `insert`"]
|
||||
pub fn swap(&mut self, key: uint, value: T) -> Option<T> {
|
||||
self.insert(key, value)
|
||||
}
|
||||
|
||||
/// Inserts a key-value pair from the map. If the key already had a value
|
||||
|
|
@ -391,14 +387,15 @@ impl<T> TrieMap<T> {
|
|||
/// use std::collections::TrieMap;
|
||||
///
|
||||
/// let mut map = TrieMap::new();
|
||||
/// assert_eq!(map.swap(37, "a"), None);
|
||||
/// assert_eq!(map.insert(37, "a"), None);
|
||||
/// assert_eq!(map.is_empty(), false);
|
||||
///
|
||||
/// map.insert(37, "b");
|
||||
/// assert_eq!(map.swap(37, "c"), Some("b"));
|
||||
/// assert_eq!(map.insert(37, "c"), Some("b"));
|
||||
/// assert_eq!(map[37], "c");
|
||||
/// ```
|
||||
pub fn swap(&mut self, key: uint, value: T) -> Option<T> {
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn insert(&mut self, key: uint, value: T) -> Option<T> {
|
||||
let ret = insert(&mut self.root.count,
|
||||
&mut self.root.children[chunk(key, 0)],
|
||||
key, value, 1);
|
||||
|
|
@ -406,6 +403,12 @@ impl<T> TrieMap<T> {
|
|||
ret
|
||||
}
|
||||
|
||||
/// Deprecated: Renamed to `remove`.
|
||||
#[deprecated = "Renamed to `remove`"]
|
||||
pub fn pop(&mut self, key: &uint) -> Option<T> {
|
||||
self.remove(key)
|
||||
}
|
||||
|
||||
/// Removes a key from the map, returning the value at the key if the key
|
||||
/// was previously in the map.
|
||||
///
|
||||
|
|
@ -416,10 +419,11 @@ impl<T> TrieMap<T> {
|
|||
///
|
||||
/// let mut map = TrieMap::new();
|
||||
/// map.insert(1, "a");
|
||||
/// assert_eq!(map.pop(&1), Some("a"));
|
||||
/// assert_eq!(map.pop(&1), None);
|
||||
/// assert_eq!(map.remove(&1), Some("a"));
|
||||
/// assert_eq!(map.remove(&1), None);
|
||||
/// ```
|
||||
pub fn pop(&mut self, key: &uint) -> Option<T> {
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn remove(&mut self, key: &uint) -> Option<T> {
|
||||
let ret = remove(&mut self.root.count,
|
||||
&mut self.root.children[chunk(*key, 0)],
|
||||
*key, 1);
|
||||
|
|
@ -582,9 +586,9 @@ impl<T> TrieMap<T> {
|
|||
/// *value = "changed";
|
||||
/// }
|
||||
///
|
||||
/// assert_eq!(map.find(&2), Some(&"a"));
|
||||
/// assert_eq!(map.find(&4), Some(&"changed"));
|
||||
/// assert_eq!(map.find(&6), Some(&"changed"));
|
||||
/// assert_eq!(map.get(&2), Some(&"a"));
|
||||
/// assert_eq!(map.get(&4), Some(&"changed"));
|
||||
/// assert_eq!(map.get(&6), Some(&"changed"));
|
||||
/// ```
|
||||
pub fn lower_bound_mut<'a>(&'a mut self, key: uint) -> MutEntries<'a, T> {
|
||||
self.bound_mut(key, false)
|
||||
|
|
@ -607,9 +611,9 @@ impl<T> TrieMap<T> {
|
|||
/// *value = "changed";
|
||||
/// }
|
||||
///
|
||||
/// assert_eq!(map.find(&2), Some(&"a"));
|
||||
/// assert_eq!(map.find(&4), Some(&"b"));
|
||||
/// assert_eq!(map.find(&6), Some(&"changed"));
|
||||
/// assert_eq!(map.get(&2), Some(&"a"));
|
||||
/// assert_eq!(map.get(&4), Some(&"b"));
|
||||
/// assert_eq!(map.get(&6), Some(&"changed"));
|
||||
/// ```
|
||||
pub fn upper_bound_mut<'a>(&'a mut self, key: uint) -> MutEntries<'a, T> {
|
||||
self.bound_mut(key, true)
|
||||
|
|
@ -643,14 +647,14 @@ impl<S: Writer, T: Hash<S>> Hash<S> for TrieMap<T> {
|
|||
impl<T> Index<uint, T> for TrieMap<T> {
|
||||
#[inline]
|
||||
fn index<'a>(&'a self, i: &uint) -> &'a T {
|
||||
self.find(i).expect("key not present")
|
||||
self.get(i).expect("key not present")
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> IndexMut<uint, T> for TrieMap<T> {
|
||||
#[inline]
|
||||
fn index_mut<'a>(&'a mut self, i: &uint) -> &'a mut T {
|
||||
self.find_mut(i).expect("key not present")
|
||||
self.get_mut(i).expect("key not present")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -957,24 +961,24 @@ mod test {
|
|||
#[test]
|
||||
fn test_find_mut() {
|
||||
let mut m = TrieMap::new();
|
||||
assert!(m.insert(1u, 12i));
|
||||
assert!(m.insert(2u, 8i));
|
||||
assert!(m.insert(5u, 14i));
|
||||
assert!(m.insert(1u, 12i).is_none());
|
||||
assert!(m.insert(2u, 8i).is_none());
|
||||
assert!(m.insert(5u, 14i).is_none());
|
||||
let new = 100;
|
||||
match m.find_mut(&5) {
|
||||
match m.get_mut(&5) {
|
||||
None => panic!(), Some(x) => *x = new
|
||||
}
|
||||
assert_eq!(m.find(&5), Some(&new));
|
||||
assert_eq!(m.get(&5), Some(&new));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_find_mut_missing() {
|
||||
let mut m = TrieMap::new();
|
||||
assert!(m.find_mut(&0).is_none());
|
||||
assert!(m.insert(1u, 12i));
|
||||
assert!(m.find_mut(&0).is_none());
|
||||
assert!(m.insert(2, 8));
|
||||
assert!(m.find_mut(&0).is_none());
|
||||
assert!(m.get_mut(&0).is_none());
|
||||
assert!(m.insert(1u, 12i).is_none());
|
||||
assert!(m.get_mut(&0).is_none());
|
||||
assert!(m.insert(2, 8).is_none());
|
||||
assert!(m.get_mut(&0).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -983,32 +987,32 @@ mod test {
|
|||
let n = 300u;
|
||||
|
||||
for x in range_step(1u, n, 2) {
|
||||
assert!(trie.insert(x, x + 1));
|
||||
assert!(trie.insert(x, x + 1).is_none());
|
||||
assert!(trie.contains_key(&x));
|
||||
check_integrity(&trie.root);
|
||||
}
|
||||
|
||||
for x in range_step(0u, n, 2) {
|
||||
assert!(!trie.contains_key(&x));
|
||||
assert!(trie.insert(x, x + 1));
|
||||
assert!(trie.insert(x, x + 1).is_none());
|
||||
check_integrity(&trie.root);
|
||||
}
|
||||
|
||||
for x in range(0u, n) {
|
||||
assert!(trie.contains_key(&x));
|
||||
assert!(!trie.insert(x, x + 1));
|
||||
assert!(!trie.insert(x, x + 1).is_none());
|
||||
check_integrity(&trie.root);
|
||||
}
|
||||
|
||||
for x in range_step(1u, n, 2) {
|
||||
assert!(trie.remove(&x));
|
||||
assert!(trie.remove(&x).is_some());
|
||||
assert!(!trie.contains_key(&x));
|
||||
check_integrity(&trie.root);
|
||||
}
|
||||
|
||||
for x in range_step(0u, n, 2) {
|
||||
assert!(trie.contains_key(&x));
|
||||
assert!(!trie.insert(x, x + 1));
|
||||
assert!(!trie.insert(x, x + 1).is_none());
|
||||
check_integrity(&trie.root);
|
||||
}
|
||||
}
|
||||
|
|
@ -1017,11 +1021,11 @@ mod test {
|
|||
fn test_each_reverse() {
|
||||
let mut m = TrieMap::new();
|
||||
|
||||
assert!(m.insert(3, 6));
|
||||
assert!(m.insert(0, 0));
|
||||
assert!(m.insert(4, 8));
|
||||
assert!(m.insert(2, 4));
|
||||
assert!(m.insert(1, 2));
|
||||
assert!(m.insert(3, 6).is_none());
|
||||
assert!(m.insert(0, 0).is_none());
|
||||
assert!(m.insert(4, 8).is_none());
|
||||
assert!(m.insert(2, 4).is_none());
|
||||
assert!(m.insert(1, 2).is_none());
|
||||
|
||||
let mut n = 4;
|
||||
m.each_reverse(|k, v| {
|
||||
|
|
@ -1054,19 +1058,19 @@ mod test {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_swap() {
|
||||
fn test_insert() {
|
||||
let mut m = TrieMap::new();
|
||||
assert_eq!(m.swap(1u, 2i), None);
|
||||
assert_eq!(m.swap(1u, 3i), Some(2));
|
||||
assert_eq!(m.swap(1u, 4i), Some(3));
|
||||
assert_eq!(m.insert(1u, 2i), None);
|
||||
assert_eq!(m.insert(1u, 3i), Some(2));
|
||||
assert_eq!(m.insert(1u, 4i), Some(3));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_pop() {
|
||||
fn test_remove() {
|
||||
let mut m = TrieMap::new();
|
||||
m.insert(1u, 2i);
|
||||
assert_eq!(m.pop(&1), Some(2));
|
||||
assert_eq!(m.pop(&1), None);
|
||||
assert_eq!(m.remove(&1), Some(2));
|
||||
assert_eq!(m.remove(&1), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -1076,7 +1080,7 @@ mod test {
|
|||
let map: TrieMap<int> = xs.iter().map(|&x| x).collect();
|
||||
|
||||
for &(k, v) in xs.iter() {
|
||||
assert_eq!(map.find(&k), Some(&v));
|
||||
assert_eq!(map.get(&k), Some(&v));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1243,15 +1247,15 @@ mod test {
|
|||
let mut b = TrieMap::new();
|
||||
|
||||
assert!(a == b);
|
||||
assert!(a.insert(0, 5i));
|
||||
assert!(a.insert(0, 5i).is_none());
|
||||
assert!(a != b);
|
||||
assert!(b.insert(0, 4i));
|
||||
assert!(b.insert(0, 4i).is_none());
|
||||
assert!(a != b);
|
||||
assert!(a.insert(5, 19));
|
||||
assert!(a.insert(5, 19).is_none());
|
||||
assert!(a != b);
|
||||
assert!(!b.insert(0, 5));
|
||||
assert!(!b.insert(0, 5).is_none());
|
||||
assert!(a != b);
|
||||
assert!(b.insert(5, 19));
|
||||
assert!(b.insert(5, 19).is_none());
|
||||
assert!(a == b);
|
||||
}
|
||||
|
||||
|
|
@ -1261,15 +1265,15 @@ mod test {
|
|||
let mut b = TrieMap::new();
|
||||
|
||||
assert!(!(a < b) && !(b < a));
|
||||
assert!(b.insert(2u, 5i));
|
||||
assert!(b.insert(2u, 5i).is_none());
|
||||
assert!(a < b);
|
||||
assert!(a.insert(2, 7));
|
||||
assert!(a.insert(2, 7).is_none());
|
||||
assert!(!(a < b) && b < a);
|
||||
assert!(b.insert(1, 0));
|
||||
assert!(b.insert(1, 0).is_none());
|
||||
assert!(b < a);
|
||||
assert!(a.insert(0, 6));
|
||||
assert!(a.insert(0, 6).is_none());
|
||||
assert!(a < b);
|
||||
assert!(a.insert(6, 2));
|
||||
assert!(a.insert(6, 2).is_none());
|
||||
assert!(a < b && !(b < a));
|
||||
}
|
||||
|
||||
|
|
@ -1279,10 +1283,10 @@ mod test {
|
|||
let mut b = TrieMap::new();
|
||||
|
||||
assert!(a <= b && a >= b);
|
||||
assert!(a.insert(1u, 1i));
|
||||
assert!(a.insert(1u, 1i).is_none());
|
||||
assert!(a > b && a >= b);
|
||||
assert!(b < a && b <= a);
|
||||
assert!(b.insert(2, 2));
|
||||
assert!(b.insert(2, 2).is_none());
|
||||
assert!(b > a && b >= a);
|
||||
assert!(a < b && a <= b);
|
||||
}
|
||||
|
|
@ -1355,7 +1359,7 @@ mod bench {
|
|||
let mut rng = weak_rng();
|
||||
|
||||
for _ in range(0, size) {
|
||||
map.swap(rng.gen(), rng.gen());
|
||||
map.insert(rng.gen(), rng.gen());
|
||||
}
|
||||
|
||||
b.iter(|| {
|
||||
|
|
|
|||
|
|
@ -8,6 +8,12 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// FIXME(conventions): implement bounded iterators
|
||||
// FIXME(conventions): implement union family of fns
|
||||
// FIXME(conventions): implement BitOr, BitAnd, BitXor, and Sub
|
||||
// FIXME(conventions): replace each_reverse by making iter DoubleEnded
|
||||
// FIXME(conventions): implement iter_mut and into_iter
|
||||
|
||||
use core::prelude::*;
|
||||
|
||||
use core::default::Default;
|
||||
|
|
@ -79,6 +85,7 @@ impl TrieSet {
|
|||
/// let mut set = TrieSet::new();
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn new() -> TrieSet {
|
||||
TrieSet{map: TrieMap::new()}
|
||||
}
|
||||
|
|
@ -126,6 +133,7 @@ impl TrieSet {
|
|||
/// }
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn iter<'a>(&'a self) -> SetItems<'a> {
|
||||
SetItems{iter: self.map.iter()}
|
||||
}
|
||||
|
|
@ -177,6 +185,7 @@ impl TrieSet {
|
|||
/// assert_eq!(v.len(), 1);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn len(&self) -> uint { self.map.len() }
|
||||
|
||||
/// Returns true if the set contains no elements
|
||||
|
|
@ -191,6 +200,7 @@ impl TrieSet {
|
|||
/// v.insert(1);
|
||||
/// assert!(!v.is_empty());
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn is_empty(&self) -> bool { self.len() == 0 }
|
||||
|
||||
/// Clears the set, removing all values.
|
||||
|
|
@ -206,6 +216,7 @@ impl TrieSet {
|
|||
/// assert!(v.is_empty());
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn clear(&mut self) { self.map.clear() }
|
||||
|
||||
/// Returns `true` if the set contains a value.
|
||||
|
|
@ -220,6 +231,7 @@ impl TrieSet {
|
|||
/// assert_eq!(set.contains(&4), false);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn contains(&self, value: &uint) -> bool {
|
||||
self.map.contains_key(value)
|
||||
}
|
||||
|
|
@ -242,6 +254,7 @@ impl TrieSet {
|
|||
/// assert_eq!(a.is_disjoint(&b), false);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn is_disjoint(&self, other: &TrieSet) -> bool {
|
||||
self.iter().all(|v| !other.contains(&v))
|
||||
}
|
||||
|
|
@ -263,6 +276,7 @@ impl TrieSet {
|
|||
/// assert_eq!(set.is_subset(&sup), false);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn is_subset(&self, other: &TrieSet) -> bool {
|
||||
self.iter().all(|v| other.contains(&v))
|
||||
}
|
||||
|
|
@ -287,6 +301,7 @@ impl TrieSet {
|
|||
/// assert_eq!(set.is_superset(&sub), true);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn is_superset(&self, other: &TrieSet) -> bool {
|
||||
other.is_subset(self)
|
||||
}
|
||||
|
|
@ -306,8 +321,9 @@ impl TrieSet {
|
|||
/// assert_eq!(set.len(), 1);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn insert(&mut self, value: uint) -> bool {
|
||||
self.map.insert(value, ())
|
||||
self.map.insert(value, ()).is_none()
|
||||
}
|
||||
|
||||
/// Removes a value from the set. Returns `true` if the value was
|
||||
|
|
@ -325,8 +341,9 @@ impl TrieSet {
|
|||
/// assert_eq!(set.remove(&2), false);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn remove(&mut self, value: &uint) -> bool {
|
||||
self.map.remove(value)
|
||||
self.map.remove(value).is_some()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -312,7 +312,7 @@ impl<T: Clone> Vec<T> {
|
|||
#[inline]
|
||||
#[experimental]
|
||||
pub fn push_all(&mut self, other: &[T]) {
|
||||
self.reserve_additional(other.len());
|
||||
self.reserve(other.len());
|
||||
|
||||
for i in range(0, other.len()) {
|
||||
let len = self.len();
|
||||
|
|
@ -342,7 +342,7 @@ impl<T: Clone> Vec<T> {
|
|||
/// ```
|
||||
#[stable]
|
||||
pub fn grow(&mut self, n: uint, value: T) {
|
||||
self.reserve_additional(n);
|
||||
self.reserve(n);
|
||||
let mut i: uint = 0u;
|
||||
|
||||
while i < n {
|
||||
|
|
@ -489,7 +489,7 @@ impl<T> Extendable<T> for Vec<T> {
|
|||
#[inline]
|
||||
fn extend<I: Iterator<T>>(&mut self, mut iterator: I) {
|
||||
let (lower, _) = iterator.size_hint();
|
||||
self.reserve_additional(lower);
|
||||
self.reserve(lower);
|
||||
for element in iterator {
|
||||
self.push(element)
|
||||
}
|
||||
|
|
@ -578,74 +578,70 @@ impl<T> Vec<T> {
|
|||
self.cap
|
||||
}
|
||||
|
||||
/// Reserves capacity for at least `n` additional elements in the given
|
||||
/// vector.
|
||||
///
|
||||
/// # Failure
|
||||
///
|
||||
/// Fails if the new capacity overflows `uint`.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// let mut vec: Vec<int> = vec![1i];
|
||||
/// vec.reserve_additional(10);
|
||||
/// assert!(vec.capacity() >= 11);
|
||||
/// ```
|
||||
/// Deprecated: Renamed to `reserve`.
|
||||
#[deprecated = "Renamed to `reserve`"]
|
||||
pub fn reserve_additional(&mut self, extra: uint) {
|
||||
if self.cap - self.len < extra {
|
||||
match self.len.checked_add(&extra) {
|
||||
None => panic!("Vec::reserve_additional: `uint` overflow"),
|
||||
Some(new_cap) => self.reserve(new_cap)
|
||||
}
|
||||
}
|
||||
self.reserve(extra)
|
||||
}
|
||||
|
||||
/// Reserves capacity for at least `n` elements in the given vector.
|
||||
/// Reserves capacity for at least `additional` more elements to be inserted in the given
|
||||
/// `Vec`. The collection may reserve more space to avoid frequent reallocations.
|
||||
///
|
||||
/// This function will over-allocate in order to amortize the allocation
|
||||
/// costs in scenarios where the caller may need to repeatedly reserve
|
||||
/// additional space.
|
||||
/// # Panics
|
||||
///
|
||||
/// If the capacity for `self` is already equal to or greater than the
|
||||
/// requested capacity, then no action is taken.
|
||||
/// Panics if the new capacity overflows `uint`.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// let mut vec = vec![1i, 2, 3];
|
||||
/// let mut vec: Vec<int> = vec![1];
|
||||
/// vec.reserve(10);
|
||||
/// assert!(vec.capacity() >= 10);
|
||||
/// assert!(vec.capacity() >= 11);
|
||||
/// ```
|
||||
pub fn reserve(&mut self, capacity: uint) {
|
||||
if capacity > self.cap {
|
||||
self.reserve_exact(num::next_power_of_two(capacity))
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn reserve(&mut self, additional: uint) {
|
||||
if self.cap - self.len < additional {
|
||||
match self.len.checked_add(&additional) {
|
||||
None => panic!("Vec::reserve: `uint` overflow"),
|
||||
// if the checked_add
|
||||
Some(new_cap) => {
|
||||
let amort_cap = num::next_power_of_two(new_cap);
|
||||
// next_power_of_two will overflow to exactly 0 for really big capacities
|
||||
if amort_cap == 0 {
|
||||
self.grow_capacity(new_cap);
|
||||
} else {
|
||||
self.grow_capacity(amort_cap);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Reserves capacity for exactly `capacity` elements in the given vector.
|
||||
/// Reserves the minimum capacity for exactly `additional` more elements to be inserted in the
|
||||
/// given `Vec`. Does nothing if the capacity is already sufficient.
|
||||
///
|
||||
/// If the capacity for `self` is already equal to or greater than the
|
||||
/// requested capacity, then no action is taken.
|
||||
/// Note that the allocator may give the collection more space than it requests. Therefore
|
||||
/// capacity can not be relied upon to be precisely minimal. Prefer `reserve` if future
|
||||
/// insertions are expected.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if the new capacity overflows `uint`.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// let mut vec: Vec<int> = Vec::with_capacity(10);
|
||||
/// vec.reserve_exact(11);
|
||||
/// assert_eq!(vec.capacity(), 11);
|
||||
/// let mut vec: Vec<int> = vec![1];
|
||||
/// vec.reserve_exact(10);
|
||||
/// assert!(vec.capacity() >= 11);
|
||||
/// ```
|
||||
pub fn reserve_exact(&mut self, capacity: uint) {
|
||||
if mem::size_of::<T>() == 0 { return }
|
||||
|
||||
if capacity > self.cap {
|
||||
let size = capacity.checked_mul(&mem::size_of::<T>())
|
||||
.expect("capacity overflow");
|
||||
unsafe {
|
||||
self.ptr = alloc_or_realloc(self.ptr, self.cap * mem::size_of::<T>(), size);
|
||||
if self.ptr.is_null() { ::alloc::oom() }
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn reserve_exact(&mut self, additional: uint) {
|
||||
if self.cap - self.len < additional {
|
||||
match self.len.checked_add(&additional) {
|
||||
None => panic!("Vec::reserve: `uint` overflow"),
|
||||
Some(new_cap) => self.grow_capacity(new_cap)
|
||||
}
|
||||
self.cap = capacity;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -663,6 +659,7 @@ impl<T> Vec<T> {
|
|||
/// assert!(vec.capacity() >= 3);
|
||||
/// ```
|
||||
#[stable]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn shrink_to_fit(&mut self) {
|
||||
if mem::size_of::<T>() == 0 { return }
|
||||
|
||||
|
|
@ -713,7 +710,7 @@ impl<T> Vec<T> {
|
|||
/// vec.truncate(2);
|
||||
/// assert_eq!(vec, vec![1, 2]);
|
||||
/// ```
|
||||
#[unstable = "waiting on panic semantics"]
|
||||
#[unstable = "matches collection reform specification; waiting on panic semantics"]
|
||||
pub fn truncate(&mut self, len: uint) {
|
||||
unsafe {
|
||||
// drop any extra elements
|
||||
|
|
@ -761,6 +758,7 @@ impl<T> Vec<T> {
|
|||
/// }
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn into_iter(self) -> MoveItems<T> {
|
||||
unsafe {
|
||||
let ptr = self.ptr;
|
||||
|
|
@ -796,26 +794,6 @@ impl<T> Vec<T> {
|
|||
self.len = len;
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to the value at index `index`.
|
||||
///
|
||||
/// # Failure
|
||||
///
|
||||
/// Fails if `index` is out of bounds
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// # #![allow(deprecated)]
|
||||
/// let mut vec = vec![1i, 2, 3];
|
||||
/// *vec.get_mut(1) = 4;
|
||||
/// assert_eq!(vec, vec![1i, 4, 3]);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[deprecated = "use `foo[index] = bar` instead"]
|
||||
pub fn get_mut<'a>(&'a mut self, index: uint) -> &'a mut T {
|
||||
&mut self.as_mut_slice()[index]
|
||||
}
|
||||
|
||||
/// Removes an element from anywhere in the vector and return it, replacing
|
||||
/// it with the last element. This does not preserve ordering, but is O(1).
|
||||
///
|
||||
|
|
@ -868,7 +846,7 @@ impl<T> Vec<T> {
|
|||
let len = self.len();
|
||||
assert!(index <= len);
|
||||
// space for the new element
|
||||
self.reserve(len + 1);
|
||||
self.reserve(1);
|
||||
|
||||
unsafe { // infallible
|
||||
// The spot to put the new value
|
||||
|
|
@ -970,7 +948,7 @@ impl<T> Vec<T> {
|
|||
/// ```
|
||||
#[unstable = "this function may be renamed or change to unboxed closures"]
|
||||
pub fn grow_fn(&mut self, n: uint, f: |uint| -> T) {
|
||||
self.reserve_additional(n);
|
||||
self.reserve(n);
|
||||
for i in range(0u, n) {
|
||||
self.push(f(i));
|
||||
}
|
||||
|
|
@ -1076,7 +1054,26 @@ impl<T> Vec<T> {
|
|||
/// v.push(1i);
|
||||
/// assert!(!v.is_empty());
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn is_empty(&self) -> bool { self.len() == 0 }
|
||||
|
||||
/// Reserves capacity for exactly `capacity` elements in the given vector.
|
||||
///
|
||||
/// If the capacity for `self` is already equal to or greater than the
|
||||
/// requested capacity, then no action is taken.
|
||||
fn grow_capacity(&mut self, capacity: uint) {
|
||||
if mem::size_of::<T>() == 0 { return }
|
||||
|
||||
if capacity > self.cap {
|
||||
let size = capacity.checked_mul(&mem::size_of::<T>())
|
||||
.expect("capacity overflow");
|
||||
unsafe {
|
||||
self.ptr = alloc_or_realloc(self.ptr, self.cap * mem::size_of::<T>(), size);
|
||||
if self.ptr.is_null() { ::alloc::oom() }
|
||||
}
|
||||
self.cap = capacity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: PartialEq> Vec<T> {
|
||||
|
|
@ -1742,11 +1739,11 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_reserve_additional() {
|
||||
fn test_reserve() {
|
||||
let mut v = Vec::new();
|
||||
assert_eq!(v.capacity(), 0);
|
||||
|
||||
v.reserve_additional(2);
|
||||
v.reserve(2);
|
||||
assert!(v.capacity() >= 2);
|
||||
|
||||
for i in range(0i, 16) {
|
||||
|
|
@ -1754,12 +1751,12 @@ mod tests {
|
|||
}
|
||||
|
||||
assert!(v.capacity() >= 16);
|
||||
v.reserve_additional(16);
|
||||
v.reserve(16);
|
||||
assert!(v.capacity() >= 32);
|
||||
|
||||
v.push(16);
|
||||
|
||||
v.reserve_additional(16);
|
||||
v.reserve(16);
|
||||
assert!(v.capacity() >= 33)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ use vec::Vec;
|
|||
use hash;
|
||||
use hash::Hash;
|
||||
|
||||
// FIXME(conventions): capacity management???
|
||||
|
||||
/// A map optimized for small integer keys.
|
||||
///
|
||||
/// # Example
|
||||
|
|
@ -42,14 +44,14 @@ use hash::Hash;
|
|||
/// println!("The end is near!");
|
||||
/// }
|
||||
///
|
||||
/// assert_eq!(months.find(&1), Some(&"Jan"));
|
||||
/// assert_eq!(months.get(&1), Some(&"Jan"));
|
||||
///
|
||||
/// match months.find_mut(&3) {
|
||||
/// match months.get_mut(&3) {
|
||||
/// Some(value) => *value = "Venus",
|
||||
/// None => (),
|
||||
/// }
|
||||
///
|
||||
/// assert_eq!(months.find(&3), Some(&"Venus"));
|
||||
/// assert_eq!(months.get(&3), Some(&"Venus"));
|
||||
///
|
||||
/// // Print out all months
|
||||
/// for (key, value) in months.iter() {
|
||||
|
|
@ -77,10 +79,7 @@ impl<V:Clone> Clone for VecMap<V> {
|
|||
|
||||
#[inline]
|
||||
fn clone_from(&mut self, source: &VecMap<V>) {
|
||||
self.v.reserve(source.v.len());
|
||||
for (i, w) in self.v.iter_mut().enumerate() {
|
||||
*w = source.v[i].clone();
|
||||
}
|
||||
self.v.clone_from(&source.v);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -99,6 +98,7 @@ impl<V> VecMap<V> {
|
|||
/// use std::collections::VecMap;
|
||||
/// let mut map: VecMap<&str> = VecMap::new();
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn new() -> VecMap<V> { VecMap{v: vec!()} }
|
||||
|
||||
/// Creates an empty `VecMap` with space for at least `capacity`
|
||||
|
|
@ -110,18 +110,21 @@ impl<V> VecMap<V> {
|
|||
/// use std::collections::VecMap;
|
||||
/// let mut map: VecMap<&str> = VecMap::with_capacity(10);
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn with_capacity(capacity: uint) -> VecMap<V> {
|
||||
VecMap { v: Vec::with_capacity(capacity) }
|
||||
}
|
||||
|
||||
/// Returns an iterator visiting all keys in ascending order by the keys.
|
||||
/// The iterator's element type is `uint`.
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn keys<'r>(&'r self) -> Keys<'r, V> {
|
||||
self.iter().map(|(k, _v)| k)
|
||||
}
|
||||
|
||||
/// Returns an iterator visiting all values in ascending order by the keys.
|
||||
/// The iterator's element type is `&'r V`.
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn values<'r>(&'r self) -> Values<'r, V> {
|
||||
self.iter().map(|(_k, v)| v)
|
||||
}
|
||||
|
|
@ -144,6 +147,7 @@ impl<V> VecMap<V> {
|
|||
/// println!("{}: {}", key, value);
|
||||
/// }
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn iter<'r>(&'r self) -> Entries<'r, V> {
|
||||
Entries {
|
||||
front: 0,
|
||||
|
|
@ -174,6 +178,7 @@ impl<V> VecMap<V> {
|
|||
/// assert_eq!(value, &"x");
|
||||
/// }
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn iter_mut<'r>(&'r mut self) -> MutEntries<'r, V> {
|
||||
MutEntries {
|
||||
front: 0,
|
||||
|
|
@ -201,6 +206,7 @@ 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)
|
||||
-> FilterMap<(uint, Option<V>), (uint, V),
|
||||
Enumerate<vec::MoveItems<Option<V>>>>
|
||||
|
|
@ -223,6 +229,7 @@ impl<V> VecMap<V> {
|
|||
/// a.insert(1, "a");
|
||||
/// assert_eq!(a.len(), 1);
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn len(&self) -> uint {
|
||||
self.v.iter().filter(|elt| elt.is_some()).count()
|
||||
}
|
||||
|
|
@ -239,6 +246,7 @@ impl<V> VecMap<V> {
|
|||
/// a.insert(1, "a");
|
||||
/// assert!(!a.is_empty());
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.v.iter().all(|elt| elt.is_none())
|
||||
}
|
||||
|
|
@ -255,8 +263,15 @@ impl<V> VecMap<V> {
|
|||
/// a.clear();
|
||||
/// assert!(a.is_empty());
|
||||
/// ```
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn clear(&mut self) { self.v.clear() }
|
||||
|
||||
/// Deprecated: Renamed to `get`.
|
||||
#[deprecated = "Renamed to `get`"]
|
||||
pub fn find(&self, key: &uint) -> Option<&V> {
|
||||
self.get(key)
|
||||
}
|
||||
|
||||
/// Returns a reference to the value corresponding to the key.
|
||||
///
|
||||
/// # Example
|
||||
|
|
@ -266,10 +281,11 @@ impl<V> VecMap<V> {
|
|||
///
|
||||
/// let mut map = VecMap::new();
|
||||
/// map.insert(1, "a");
|
||||
/// assert_eq!(map.find(&1), Some(&"a"));
|
||||
/// assert_eq!(map.find(&2), None);
|
||||
/// assert_eq!(map.get(&1), Some(&"a"));
|
||||
/// assert_eq!(map.get(&2), None);
|
||||
/// ```
|
||||
pub fn find<'a>(&'a self, key: &uint) -> Option<&'a V> {
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn get(&self, key: &uint) -> Option<&V> {
|
||||
if *key < self.v.len() {
|
||||
match self.v[*key] {
|
||||
Some(ref value) => Some(value),
|
||||
|
|
@ -293,8 +309,15 @@ impl<V> VecMap<V> {
|
|||
/// assert_eq!(map.contains_key(&2), false);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn contains_key(&self, key: &uint) -> bool {
|
||||
self.find(key).is_some()
|
||||
self.get(key).is_some()
|
||||
}
|
||||
|
||||
/// Deprecated: Renamed to `get_mut`.
|
||||
#[deprecated = "Renamed to `get_mut`"]
|
||||
pub fn find_mut(&mut self, key: &uint) -> Option<&mut V> {
|
||||
self.get_mut(key)
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to the value corresponding to the key.
|
||||
|
|
@ -306,13 +329,14 @@ impl<V> VecMap<V> {
|
|||
///
|
||||
/// let mut map = VecMap::new();
|
||||
/// map.insert(1, "a");
|
||||
/// match map.find_mut(&1) {
|
||||
/// match map.get_mut(&1) {
|
||||
/// Some(x) => *x = "b",
|
||||
/// None => (),
|
||||
/// }
|
||||
/// assert_eq!(map[1], "b");
|
||||
/// ```
|
||||
pub fn find_mut<'a>(&'a mut self, key: &uint) -> Option<&'a mut V> {
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn get_mut(&mut self, key: &uint) -> Option<&mut V> {
|
||||
if *key < self.v.len() {
|
||||
match *(&mut self.v[*key]) {
|
||||
Some(ref mut value) => Some(value),
|
||||
|
|
@ -323,45 +347,10 @@ impl<V> VecMap<V> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Inserts a key-value pair into the map. An existing value for a
|
||||
/// key is replaced by the new value. Returns `true` if the key did
|
||||
/// not already exist in the map.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use std::collections::VecMap;
|
||||
///
|
||||
/// let mut map = VecMap::new();
|
||||
/// assert_eq!(map.insert(2, "value"), true);
|
||||
/// assert_eq!(map.insert(2, "value2"), false);
|
||||
/// assert_eq!(map[2], "value2");
|
||||
/// ```
|
||||
pub fn insert(&mut self, key: uint, value: V) -> bool {
|
||||
let exists = self.contains_key(&key);
|
||||
let len = self.v.len();
|
||||
if len <= key {
|
||||
self.v.grow_fn(key - len + 1, |_| None);
|
||||
}
|
||||
self.v[key] = Some(value);
|
||||
!exists
|
||||
}
|
||||
|
||||
/// Removes a key-value pair from the map. Returns `true` if the key
|
||||
/// was present in the map.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use std::collections::VecMap;
|
||||
///
|
||||
/// let mut map = VecMap::new();
|
||||
/// assert_eq!(map.remove(&1), false);
|
||||
/// map.insert(1, "a");
|
||||
/// assert_eq!(map.remove(&1), true);
|
||||
/// ```
|
||||
pub fn remove(&mut self, key: &uint) -> bool {
|
||||
self.pop(key).is_some()
|
||||
/// Deprecated: Renamed to `insert`.
|
||||
#[deprecated = "Renamed to `insert`"]
|
||||
pub fn swap(&mut self, key: uint, value: V) -> Option<V> {
|
||||
self.insert(key, value)
|
||||
}
|
||||
|
||||
/// Inserts a key-value pair from the map. If the key already had a value
|
||||
|
|
@ -373,20 +362,26 @@ impl<V> VecMap<V> {
|
|||
/// use std::collections::VecMap;
|
||||
///
|
||||
/// let mut map = VecMap::new();
|
||||
/// assert_eq!(map.swap(37, "a"), None);
|
||||
/// assert_eq!(map.insert(37, "a"), None);
|
||||
/// assert_eq!(map.is_empty(), false);
|
||||
///
|
||||
/// map.insert(37, "b");
|
||||
/// assert_eq!(map.swap(37, "c"), Some("b"));
|
||||
/// assert_eq!(map.insert(37, "c"), Some("b"));
|
||||
/// assert_eq!(map[37], "c");
|
||||
/// ```
|
||||
pub fn swap(&mut self, key: uint, value: V) -> Option<V> {
|
||||
match self.find_mut(&key) {
|
||||
Some(loc) => { return Some(replace(loc, value)); }
|
||||
None => ()
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn insert(&mut self, key: uint, value: V) -> Option<V> {
|
||||
let len = self.v.len();
|
||||
if len <= key {
|
||||
self.v.grow_fn(key - len + 1, |_| None);
|
||||
}
|
||||
self.insert(key, value);
|
||||
return None;
|
||||
replace(&mut self.v[key], Some(value))
|
||||
}
|
||||
|
||||
/// Deprecated: Renamed to `remove`.
|
||||
#[deprecated = "Renamed to `remove`"]
|
||||
pub fn pop(&mut self, key: &uint) -> Option<V> {
|
||||
self.remove(key)
|
||||
}
|
||||
|
||||
/// Removes a key from the map, returning the value at the key if the key
|
||||
|
|
@ -399,10 +394,11 @@ impl<V> VecMap<V> {
|
|||
///
|
||||
/// let mut map = VecMap::new();
|
||||
/// map.insert(1, "a");
|
||||
/// assert_eq!(map.pop(&1), Some("a"));
|
||||
/// assert_eq!(map.pop(&1), None);
|
||||
/// assert_eq!(map.remove(&1), Some("a"));
|
||||
/// assert_eq!(map.remove(&1), None);
|
||||
/// ```
|
||||
pub fn pop(&mut self, key: &uint) -> Option<V> {
|
||||
#[unstable = "matches collection reform specification, waiting for dust to settle"]
|
||||
pub fn remove(&mut self, key: &uint) -> Option<V> {
|
||||
if *key >= self.v.len() {
|
||||
return None;
|
||||
}
|
||||
|
|
@ -460,11 +456,11 @@ impl<V:Clone> VecMap<V> {
|
|||
val: V,
|
||||
ff: |uint, V, V| -> V)
|
||||
-> bool {
|
||||
let new_val = match self.find(&key) {
|
||||
let new_val = match self.get(&key) {
|
||||
None => val,
|
||||
Some(orig) => ff(key, (*orig).clone(), val)
|
||||
};
|
||||
self.insert(key, new_val)
|
||||
self.insert(key, new_val).is_none()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -514,14 +510,14 @@ impl<V> Extendable<(uint, V)> for VecMap<V> {
|
|||
impl<V> Index<uint, V> for VecMap<V> {
|
||||
#[inline]
|
||||
fn index<'a>(&'a self, i: &uint) -> &'a V {
|
||||
self.find(i).expect("key not present")
|
||||
self.get(i).expect("key not present")
|
||||
}
|
||||
}
|
||||
|
||||
impl<V> IndexMut<uint, V> for VecMap<V> {
|
||||
#[inline]
|
||||
fn index_mut<'a>(&'a mut self, i: &uint) -> &'a mut V {
|
||||
self.find_mut(i).expect("key not present")
|
||||
self.get_mut(i).expect("key not present")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -615,16 +611,16 @@ mod test_map {
|
|||
use super::VecMap;
|
||||
|
||||
#[test]
|
||||
fn test_find_mut() {
|
||||
fn test_get_mut() {
|
||||
let mut m = VecMap::new();
|
||||
assert!(m.insert(1, 12i));
|
||||
assert!(m.insert(2, 8));
|
||||
assert!(m.insert(5, 14));
|
||||
assert!(m.insert(1, 12i).is_none());
|
||||
assert!(m.insert(2, 8).is_none());
|
||||
assert!(m.insert(5, 14).is_none());
|
||||
let new = 100;
|
||||
match m.find_mut(&5) {
|
||||
match m.get_mut(&5) {
|
||||
None => panic!(), Some(x) => *x = new
|
||||
}
|
||||
assert_eq!(m.find(&5), Some(&new));
|
||||
assert_eq!(m.get(&5), Some(&new));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -632,13 +628,13 @@ mod test_map {
|
|||
let mut map = VecMap::new();
|
||||
assert_eq!(map.len(), 0);
|
||||
assert!(map.is_empty());
|
||||
assert!(map.insert(5, 20i));
|
||||
assert!(map.insert(5, 20i).is_none());
|
||||
assert_eq!(map.len(), 1);
|
||||
assert!(!map.is_empty());
|
||||
assert!(map.insert(11, 12));
|
||||
assert!(map.insert(11, 12).is_none());
|
||||
assert_eq!(map.len(), 2);
|
||||
assert!(!map.is_empty());
|
||||
assert!(map.insert(14, 22));
|
||||
assert!(map.insert(14, 22).is_none());
|
||||
assert_eq!(map.len(), 3);
|
||||
assert!(!map.is_empty());
|
||||
}
|
||||
|
|
@ -646,14 +642,14 @@ mod test_map {
|
|||
#[test]
|
||||
fn test_clear() {
|
||||
let mut map = VecMap::new();
|
||||
assert!(map.insert(5, 20i));
|
||||
assert!(map.insert(11, 12));
|
||||
assert!(map.insert(14, 22));
|
||||
assert!(map.insert(5, 20i).is_none());
|
||||
assert!(map.insert(11, 12).is_none());
|
||||
assert!(map.insert(14, 22).is_none());
|
||||
map.clear();
|
||||
assert!(map.is_empty());
|
||||
assert!(map.find(&5).is_none());
|
||||
assert!(map.find(&11).is_none());
|
||||
assert!(map.find(&14).is_none());
|
||||
assert!(map.get(&5).is_none());
|
||||
assert!(map.get(&11).is_none());
|
||||
assert!(map.get(&14).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -678,28 +674,28 @@ mod test_map {
|
|||
map.update_with_key(3, 2, add_more_to_count);
|
||||
|
||||
// check the total counts
|
||||
assert_eq!(map.find(&3).unwrap(), &10);
|
||||
assert_eq!(map.find(&5).unwrap(), &3);
|
||||
assert_eq!(map.find(&9).unwrap(), &1);
|
||||
assert_eq!(map.get(&3).unwrap(), &10);
|
||||
assert_eq!(map.get(&5).unwrap(), &3);
|
||||
assert_eq!(map.get(&9).unwrap(), &1);
|
||||
|
||||
// sadly, no sevens were counted
|
||||
assert!(map.find(&7).is_none());
|
||||
assert!(map.get(&7).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_swap() {
|
||||
fn test_insert() {
|
||||
let mut m = VecMap::new();
|
||||
assert_eq!(m.swap(1, 2i), None);
|
||||
assert_eq!(m.swap(1, 3i), Some(2));
|
||||
assert_eq!(m.swap(1, 4i), Some(3));
|
||||
assert_eq!(m.insert(1, 2i), None);
|
||||
assert_eq!(m.insert(1, 3i), Some(2));
|
||||
assert_eq!(m.insert(1, 4i), Some(3));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_pop() {
|
||||
fn test_remove() {
|
||||
let mut m = VecMap::new();
|
||||
m.insert(1, 2i);
|
||||
assert_eq!(m.pop(&1), Some(2));
|
||||
assert_eq!(m.pop(&1), None);
|
||||
assert_eq!(m.remove(&1), Some(2));
|
||||
assert_eq!(m.remove(&1), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -732,11 +728,11 @@ mod test_map {
|
|||
fn test_iterator() {
|
||||
let mut m = VecMap::new();
|
||||
|
||||
assert!(m.insert(0, 1i));
|
||||
assert!(m.insert(1, 2));
|
||||
assert!(m.insert(3, 5));
|
||||
assert!(m.insert(6, 10));
|
||||
assert!(m.insert(10, 11));
|
||||
assert!(m.insert(0, 1i).is_none());
|
||||
assert!(m.insert(1, 2).is_none());
|
||||
assert!(m.insert(3, 5).is_none());
|
||||
assert!(m.insert(6, 10).is_none());
|
||||
assert!(m.insert(10, 11).is_none());
|
||||
|
||||
let mut it = m.iter();
|
||||
assert_eq!(it.size_hint(), (0, Some(11)));
|
||||
|
|
@ -757,11 +753,11 @@ mod test_map {
|
|||
fn test_iterator_size_hints() {
|
||||
let mut m = VecMap::new();
|
||||
|
||||
assert!(m.insert(0, 1i));
|
||||
assert!(m.insert(1, 2));
|
||||
assert!(m.insert(3, 5));
|
||||
assert!(m.insert(6, 10));
|
||||
assert!(m.insert(10, 11));
|
||||
assert!(m.insert(0, 1i).is_none());
|
||||
assert!(m.insert(1, 2).is_none());
|
||||
assert!(m.insert(3, 5).is_none());
|
||||
assert!(m.insert(6, 10).is_none());
|
||||
assert!(m.insert(10, 11).is_none());
|
||||
|
||||
assert_eq!(m.iter().size_hint(), (0, Some(11)));
|
||||
assert_eq!(m.iter().rev().size_hint(), (0, Some(11)));
|
||||
|
|
@ -773,11 +769,11 @@ mod test_map {
|
|||
fn test_mut_iterator() {
|
||||
let mut m = VecMap::new();
|
||||
|
||||
assert!(m.insert(0, 1i));
|
||||
assert!(m.insert(1, 2));
|
||||
assert!(m.insert(3, 5));
|
||||
assert!(m.insert(6, 10));
|
||||
assert!(m.insert(10, 11));
|
||||
assert!(m.insert(0, 1i).is_none());
|
||||
assert!(m.insert(1, 2).is_none());
|
||||
assert!(m.insert(3, 5).is_none());
|
||||
assert!(m.insert(6, 10).is_none());
|
||||
assert!(m.insert(10, 11).is_none());
|
||||
|
||||
for (k, v) in m.iter_mut() {
|
||||
*v += k as int;
|
||||
|
|
@ -796,11 +792,11 @@ mod test_map {
|
|||
fn test_rev_iterator() {
|
||||
let mut m = VecMap::new();
|
||||
|
||||
assert!(m.insert(0, 1i));
|
||||
assert!(m.insert(1, 2));
|
||||
assert!(m.insert(3, 5));
|
||||
assert!(m.insert(6, 10));
|
||||
assert!(m.insert(10, 11));
|
||||
assert!(m.insert(0, 1i).is_none());
|
||||
assert!(m.insert(1, 2).is_none());
|
||||
assert!(m.insert(3, 5).is_none());
|
||||
assert!(m.insert(6, 10).is_none());
|
||||
assert!(m.insert(10, 11).is_none());
|
||||
|
||||
let mut it = m.iter().rev();
|
||||
assert_eq!(it.next().unwrap(), (10, &11));
|
||||
|
|
@ -815,11 +811,11 @@ mod test_map {
|
|||
fn test_mut_rev_iterator() {
|
||||
let mut m = VecMap::new();
|
||||
|
||||
assert!(m.insert(0, 1i));
|
||||
assert!(m.insert(1, 2));
|
||||
assert!(m.insert(3, 5));
|
||||
assert!(m.insert(6, 10));
|
||||
assert!(m.insert(10, 11));
|
||||
assert!(m.insert(0, 1i).is_none());
|
||||
assert!(m.insert(1, 2).is_none());
|
||||
assert!(m.insert(3, 5).is_none());
|
||||
assert!(m.insert(6, 10).is_none());
|
||||
assert!(m.insert(10, 11).is_none());
|
||||
|
||||
for (k, v) in m.iter_mut().rev() {
|
||||
*v += k as int;
|
||||
|
|
@ -880,15 +876,15 @@ mod test_map {
|
|||
let mut b = VecMap::new();
|
||||
|
||||
assert!(a == b);
|
||||
assert!(a.insert(0, 5i));
|
||||
assert!(a.insert(0, 5i).is_none());
|
||||
assert!(a != b);
|
||||
assert!(b.insert(0, 4i));
|
||||
assert!(b.insert(0, 4i).is_none());
|
||||
assert!(a != b);
|
||||
assert!(a.insert(5, 19));
|
||||
assert!(a.insert(5, 19).is_none());
|
||||
assert!(a != b);
|
||||
assert!(!b.insert(0, 5));
|
||||
assert!(!b.insert(0, 5).is_none());
|
||||
assert!(a != b);
|
||||
assert!(b.insert(5, 19));
|
||||
assert!(b.insert(5, 19).is_none());
|
||||
assert!(a == b);
|
||||
}
|
||||
|
||||
|
|
@ -898,15 +894,15 @@ mod test_map {
|
|||
let mut b = VecMap::new();
|
||||
|
||||
assert!(!(a < b) && !(b < a));
|
||||
assert!(b.insert(2u, 5i));
|
||||
assert!(b.insert(2u, 5i).is_none());
|
||||
assert!(a < b);
|
||||
assert!(a.insert(2, 7));
|
||||
assert!(a.insert(2, 7).is_none());
|
||||
assert!(!(a < b) && b < a);
|
||||
assert!(b.insert(1, 0));
|
||||
assert!(b.insert(1, 0).is_none());
|
||||
assert!(b < a);
|
||||
assert!(a.insert(0, 6));
|
||||
assert!(a.insert(0, 6).is_none());
|
||||
assert!(a < b);
|
||||
assert!(a.insert(6, 2));
|
||||
assert!(a.insert(6, 2).is_none());
|
||||
assert!(a < b && !(b < a));
|
||||
}
|
||||
|
||||
|
|
@ -916,10 +912,10 @@ mod test_map {
|
|||
let mut b = VecMap::new();
|
||||
|
||||
assert!(a <= b && a >= b);
|
||||
assert!(a.insert(1u, 1i));
|
||||
assert!(a.insert(1u, 1i).is_none());
|
||||
assert!(a > b && a >= b);
|
||||
assert!(b < a && b <= a);
|
||||
assert!(b.insert(2, 2));
|
||||
assert!(b.insert(2, 2).is_none());
|
||||
assert!(b > a && b >= a);
|
||||
assert!(a < b && a <= b);
|
||||
}
|
||||
|
|
@ -948,7 +944,7 @@ mod test_map {
|
|||
let map: VecMap<char> = xs.iter().map(|&x| x).collect();
|
||||
|
||||
for &(k, v) in xs.iter() {
|
||||
assert_eq!(map.find(&k), Some(&v));
|
||||
assert_eq!(map.get(&k), Some(&v));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1022,7 +1018,7 @@ mod bench {
|
|||
let mut m : VecMap<uint> = VecMap::new();
|
||||
find_rand_n(100, &mut m, b,
|
||||
|m, i| { m.insert(i, 1); },
|
||||
|m, i| { m.find(&i); });
|
||||
|m, i| { m.get(&i); });
|
||||
}
|
||||
|
||||
#[bench]
|
||||
|
|
@ -1030,7 +1026,7 @@ mod bench {
|
|||
let mut m : VecMap<uint> = VecMap::new();
|
||||
find_rand_n(10_000, &mut m, b,
|
||||
|m, i| { m.insert(i, 1); },
|
||||
|m, i| { m.find(&i); });
|
||||
|m, i| { m.get(&i); });
|
||||
}
|
||||
|
||||
// Find seq
|
||||
|
|
@ -1039,7 +1035,7 @@ mod bench {
|
|||
let mut m : VecMap<uint> = VecMap::new();
|
||||
find_seq_n(100, &mut m, b,
|
||||
|m, i| { m.insert(i, 1); },
|
||||
|m, i| { m.find(&i); });
|
||||
|m, i| { m.get(&i); });
|
||||
}
|
||||
|
||||
#[bench]
|
||||
|
|
@ -1047,6 +1043,6 @@ mod bench {
|
|||
let mut m : VecMap<uint> = VecMap::new();
|
||||
find_seq_n(10_000, &mut m, b,
|
||||
|m, i| { m.insert(i, 1); },
|
||||
|m, i| { m.find(&i); });
|
||||
|m, i| { m.get(&i); });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -417,7 +417,7 @@ impl SchedPool {
|
|||
}
|
||||
|
||||
// Jettison the task away!
|
||||
self.handles.get_mut(idx).send(TaskFromFriend(task));
|
||||
self.handles[idx].send(TaskFromFriend(task));
|
||||
}
|
||||
|
||||
/// Spawns a new scheduler into this M:N pool. A handle is returned to the
|
||||
|
|
|
|||
|
|
@ -502,7 +502,7 @@ impl Scheduler {
|
|||
let len = work_queues.len();
|
||||
let start_index = self.rng.gen_range(0, len);
|
||||
for index in range(0, len).map(|i| (i + start_index) % len) {
|
||||
match work_queues.get_mut(index).steal() {
|
||||
match work_queues[index].steal() {
|
||||
deque::Data(task) => {
|
||||
rtdebug!("found task by stealing");
|
||||
return Some(task)
|
||||
|
|
|
|||
|
|
@ -41,7 +41,8 @@
|
|||
//! it to match anywhere in the text. Anchors can be used to ensure that the
|
||||
//! full text matches an expression.
|
||||
//!
|
||||
//! This example also demonstrates the utility of raw strings in Rust, which
|
||||
//! This example also demonstrates the utility of [raw
|
||||
//! strings](../reference.html#character-and-string-literals) in Rust, which
|
||||
//! are just like regular strings except they are prefixed with an `r` and do
|
||||
//! not process any escape sequences. For example, `"\\d"` is the same
|
||||
//! expression as `r"\d"`.
|
||||
|
|
|
|||
|
|
@ -1,202 +0,0 @@
|
|||
// Copyright 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.
|
||||
|
||||
//! A bare-metal library supplying functions rustc may lower code to
|
||||
//!
|
||||
//! This library is not intended for general use, and is superseded by a system
|
||||
//! libc if one is available. In a freestanding context, however, common
|
||||
//! functions such as memset, memcpy, etc are not implemented. This library
|
||||
//! provides an implementation of these functions which are either required by
|
||||
//! libcore or called by rustc implicitly.
|
||||
//!
|
||||
//! This library is never included by default, and must be manually included if
|
||||
//! necessary. It is an error to include this library when also linking with
|
||||
//! the system libc library.
|
||||
|
||||
#![crate_name = "rlibc"]
|
||||
#![experimental]
|
||||
#![license = "MIT/ASL2"]
|
||||
#![crate_type = "rlib"]
|
||||
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
|
||||
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
|
||||
html_root_url = "http://doc.rust-lang.org/nightly/")]
|
||||
|
||||
#![feature(import_shadowing, intrinsics, phase)]
|
||||
#![no_std]
|
||||
|
||||
// This library defines the builtin functions, so it would be a shame for
|
||||
// LLVM to optimize these function calls to themselves!
|
||||
#![no_builtins]
|
||||
|
||||
#[phase(plugin, link)] extern crate core;
|
||||
|
||||
#[cfg(test)] extern crate native;
|
||||
#[cfg(test)] extern crate test;
|
||||
|
||||
#[cfg(test)] #[phase(plugin, link)] extern crate std;
|
||||
|
||||
// Require the offset intrinsics for LLVM to properly optimize the
|
||||
// implementations below. If pointer arithmetic is done through integers the
|
||||
// optimizations start to break down.
|
||||
extern "rust-intrinsic" {
|
||||
fn offset<T>(dst: *const T, offset: int) -> *const T;
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn memcpy(dest: *mut u8, src: *const u8,
|
||||
n: uint) -> *mut u8 {
|
||||
let mut i = 0;
|
||||
while i < n {
|
||||
*(offset(dest as *const u8, i as int) as *mut u8) =
|
||||
*offset(src, i as int);
|
||||
i += 1;
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn memmove(dest: *mut u8, src: *const u8,
|
||||
n: uint) -> *mut u8 {
|
||||
if src < dest as *const u8 { // copy from end
|
||||
let mut i = n;
|
||||
while i != 0 {
|
||||
i -= 1;
|
||||
*(offset(dest as *const u8, i as int) as *mut u8) =
|
||||
*offset(src, i as int);
|
||||
}
|
||||
} else { // copy from beginning
|
||||
let mut i = 0;
|
||||
while i < n {
|
||||
*(offset(dest as *const u8, i as int) as *mut u8) =
|
||||
*offset(src, i as int);
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn memset(s: *mut u8, c: i32, n: uint) -> *mut u8 {
|
||||
let mut i = 0;
|
||||
while i < n {
|
||||
*(offset(s as *const u8, i as int) as *mut u8) = c as u8;
|
||||
i += 1;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn memcmp(s1: *const u8, s2: *const u8, n: uint) -> i32 {
|
||||
let mut i = 0;
|
||||
while i < n {
|
||||
let a = *offset(s1, i as int);
|
||||
let b = *offset(s2, i as int);
|
||||
if a != b {
|
||||
return a as i32 - b as i32
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use core::str::StrPrelude;
|
||||
use core::slice::{SlicePrelude};
|
||||
|
||||
use super::{memcmp, memset, memcpy, memmove};
|
||||
|
||||
#[test]
|
||||
fn memcmp_single_byte_pointers() {
|
||||
unsafe {
|
||||
assert_eq!(memcmp(&0xFAu8, &0xFAu8, 1), 0x00);
|
||||
assert!(memcmp(&0xEFu8, &0xFEu8, 1) < 0x00);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn memcmp_strings() {
|
||||
{
|
||||
let (x, z) = ("Hello!", "Good Bye.");
|
||||
let l = x.len();
|
||||
unsafe {
|
||||
assert_eq!(memcmp(x.as_ptr(), x.as_ptr(), l), 0);
|
||||
assert!(memcmp(x.as_ptr(), z.as_ptr(), l) > 0);
|
||||
assert!(memcmp(z.as_ptr(), x.as_ptr(), l) < 0);
|
||||
}
|
||||
}
|
||||
{
|
||||
let (x, z) = ("hey!", "hey.");
|
||||
let l = x.len();
|
||||
unsafe {
|
||||
assert!(memcmp(x.as_ptr(), z.as_ptr(), l) < 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn memset_single_byte_pointers() {
|
||||
let mut x: u8 = 0xFF;
|
||||
unsafe {
|
||||
memset(&mut x, 0xAA, 1);
|
||||
assert_eq!(x, 0xAA);
|
||||
memset(&mut x, 0x00, 1);
|
||||
assert_eq!(x, 0x00);
|
||||
x = 0x01;
|
||||
memset(&mut x, 0x12, 0);
|
||||
assert_eq!(x, 0x01);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn memset_array() {
|
||||
let mut buffer = [b'X', .. 100];
|
||||
unsafe {
|
||||
memset(buffer.as_mut_ptr(), b'#' as i32, buffer.len());
|
||||
}
|
||||
for byte in buffer.iter() { assert_eq!(*byte, b'#'); }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn memcpy_and_memcmp_arrays() {
|
||||
let (src, mut dst) = ([b'X', .. 100], [b'Y', .. 100]);
|
||||
unsafe {
|
||||
assert!(memcmp(src.as_ptr(), dst.as_ptr(), 100) != 0);
|
||||
let _ = memcpy(dst.as_mut_ptr(), src.as_ptr(), 100);
|
||||
assert_eq!(memcmp(src.as_ptr(), dst.as_ptr(), 100), 0);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn memmove_overlapping() {
|
||||
{
|
||||
let mut buffer = [ b'0', b'1', b'2', b'3', b'4', b'5', b'6', b'7', b'8', b'9' ];
|
||||
unsafe {
|
||||
memmove(&mut buffer[4], &buffer[0], 6);
|
||||
let mut i = 0;
|
||||
for byte in b"0123012345".iter() {
|
||||
assert_eq!(buffer[i], *byte);
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
let mut buffer = [ b'0', b'1', b'2', b'3', b'4', b'5', b'6', b'7', b'8', b'9' ];
|
||||
unsafe {
|
||||
memmove(&mut buffer[0], &buffer[4], 6);
|
||||
let mut i = 0;
|
||||
for byte in b"4567896789".iter() {
|
||||
assert_eq!(buffer[i], *byte);
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -220,7 +220,7 @@ fn symbol_hash(tcx: &ty::ctxt,
|
|||
}
|
||||
|
||||
fn get_symbol_hash(ccx: &CrateContext, t: ty::t) -> String {
|
||||
match ccx.type_hashcodes().borrow().find(&t) {
|
||||
match ccx.type_hashcodes().borrow().get(&t) {
|
||||
Some(h) => return h.to_string(),
|
||||
None => {}
|
||||
}
|
||||
|
|
@ -920,7 +920,7 @@ fn link_args(cmd: &mut Command,
|
|||
|
||||
let used_link_args = sess.cstore.get_used_link_args().borrow();
|
||||
|
||||
if t.options.position_independant_executables {
|
||||
if t.options.position_independent_executables {
|
||||
let empty_vec = Vec::new();
|
||||
let empty_str = String::new();
|
||||
let args = sess.opts.cg.link_args.as_ref().unwrap_or(&empty_vec);
|
||||
|
|
|
|||
|
|
@ -57,7 +57,6 @@ register_diagnostics!(
|
|||
E0044,
|
||||
E0045,
|
||||
E0046,
|
||||
E0047,
|
||||
E0049,
|
||||
E0050,
|
||||
E0051,
|
||||
|
|
@ -111,7 +110,6 @@ register_diagnostics!(
|
|||
E0108,
|
||||
E0109,
|
||||
E0110,
|
||||
E0113,
|
||||
E0116,
|
||||
E0117,
|
||||
E0118,
|
||||
|
|
@ -145,5 +143,6 @@ register_diagnostics!(
|
|||
E0163,
|
||||
E0164,
|
||||
E0165,
|
||||
E0166
|
||||
E0166,
|
||||
E0167
|
||||
)
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ impl Session {
|
|||
msg: String) {
|
||||
let lint_id = lint::LintId::of(lint);
|
||||
let mut lints = self.lints.borrow_mut();
|
||||
match lints.find_mut(&id) {
|
||||
match lints.get_mut(&id) {
|
||||
Some(arr) => { arr.push((lint_id, sp, msg)); return; }
|
||||
None => {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -403,7 +403,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
|
|||
libc::c_uint or libc::c_ulong should be used");
|
||||
}
|
||||
def::DefTy(..) => {
|
||||
let tty = match self.cx.tcx.ast_ty_to_ty_cache.borrow().find(&ty_id) {
|
||||
let tty = match self.cx.tcx.ast_ty_to_ty_cache.borrow().get(&ty_id) {
|
||||
Some(&ty::atttce_resolved(t)) => t,
|
||||
_ => panic!("ast_ty_to_ty_cache was incomplete after typeck!")
|
||||
};
|
||||
|
|
@ -994,7 +994,7 @@ impl LintPass for NonSnakeCase {
|
|||
fn check_pat(&mut self, cx: &Context, p: &ast::Pat) {
|
||||
match &p.node {
|
||||
&ast::PatIdent(_, ref path1, _) => {
|
||||
match cx.tcx.def_map.borrow().find(&p.id) {
|
||||
match cx.tcx.def_map.borrow().get(&p.id) {
|
||||
Some(&def::DefLocal(_)) => {
|
||||
self.check_snake_case(cx, "variable", path1.node, p.span);
|
||||
}
|
||||
|
|
@ -1051,7 +1051,7 @@ impl LintPass for NonUpperCaseGlobals {
|
|||
|
||||
fn check_pat(&mut self, cx: &Context, p: &ast::Pat) {
|
||||
// Lint for constants that look like binding identifiers (#7526)
|
||||
match (&p.node, cx.tcx.def_map.borrow().find(&p.id)) {
|
||||
match (&p.node, cx.tcx.def_map.borrow().get(&p.id)) {
|
||||
(&ast::PatIdent(_, ref path1, _), Some(&def::DefConst(..))) => {
|
||||
let s = token::get_ident(path1.node);
|
||||
if s.get().chars().any(|c| c.is_lowercase()) {
|
||||
|
|
@ -1211,7 +1211,7 @@ impl LintPass for NonShorthandFieldPatterns {
|
|||
ast::PatStruct(_, ref v, _) => {
|
||||
for fieldpat in v.iter()
|
||||
.filter(|fieldpat| !fieldpat.node.is_shorthand)
|
||||
.filter(|fieldpat| def_map.find(&fieldpat.node.pat.id)
|
||||
.filter(|fieldpat| def_map.get(&fieldpat.node.pat.id)
|
||||
== Some(&def::DefLocal(fieldpat.node.pat.id))) {
|
||||
match fieldpat.node.pat.node {
|
||||
ast::PatIdent(_, ident, None) if ident.node.as_str()
|
||||
|
|
@ -1368,7 +1368,7 @@ impl LintPass for UnusedAllocation {
|
|||
_ => return
|
||||
}
|
||||
|
||||
match cx.tcx.adjustments.borrow().find(&e.id) {
|
||||
match cx.tcx.adjustments.borrow().get(&e.id) {
|
||||
Some(adjustment) => {
|
||||
match *adjustment {
|
||||
ty::AdjustDerefRef(ty::AutoDerefRef { ref autoref, .. }) => {
|
||||
|
|
@ -1581,6 +1581,36 @@ impl Stability {
|
|||
|
||||
cx.span_lint(lint, span, msg.as_slice());
|
||||
}
|
||||
|
||||
fn is_internal(&self, cx: &Context, span: Span) -> bool {
|
||||
// first, check if the given expression was generated by a macro or not
|
||||
// we need to go back the expn_info tree to check only the arguments
|
||||
// of the initial macro call, not the nested ones.
|
||||
let mut expnid = span.expn_id;
|
||||
let mut is_internal = false;
|
||||
while cx.tcx.sess.codemap().with_expn_info(expnid, |expninfo| {
|
||||
match expninfo {
|
||||
Some(ref info) => {
|
||||
// save the parent expn_id for next loop iteration
|
||||
expnid = info.call_site.expn_id;
|
||||
if info.callee.span.is_none() {
|
||||
// it's a compiler built-in, we *really* don't want to mess with it
|
||||
// so we skip it, unless it was called by a regular macro, in which case
|
||||
// we will handle the caller macro next turn
|
||||
is_internal = true;
|
||||
true // continue looping
|
||||
} else {
|
||||
// was this expression from the current macro arguments ?
|
||||
is_internal = !( span.lo > info.call_site.lo &&
|
||||
span.hi < info.call_site.hi );
|
||||
true // continue looping
|
||||
}
|
||||
},
|
||||
_ => false // stop looping
|
||||
}
|
||||
}) { /* empty while loop body */ }
|
||||
return is_internal;
|
||||
}
|
||||
}
|
||||
|
||||
impl LintPass for Stability {
|
||||
|
|
@ -1605,39 +1635,13 @@ impl LintPass for Stability {
|
|||
}
|
||||
|
||||
fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
|
||||
// first, check if the given expression was generated by a macro or not
|
||||
// we need to go back the expn_info tree to check only the arguments
|
||||
// of the initial macro call, not the nested ones.
|
||||
let mut expnid = e.span.expn_id;
|
||||
let mut is_internal = false;
|
||||
while cx.tcx.sess.codemap().with_expn_info(expnid, |expninfo| {
|
||||
match expninfo {
|
||||
Some(ref info) => {
|
||||
// save the parent expn_id for next loop iteration
|
||||
expnid = info.call_site.expn_id;
|
||||
if info.callee.span.is_none() {
|
||||
// it's a compiler built-in, we *really* don't want to mess with it
|
||||
// so we skip it, unless it was called by a regular macro, in which case
|
||||
// we will handle the caller macro next turn
|
||||
is_internal = true;
|
||||
true // continue looping
|
||||
} else {
|
||||
// was this expression from the current macro arguments ?
|
||||
is_internal = !( e.span.lo > info.call_site.lo &&
|
||||
e.span.hi < info.call_site.hi );
|
||||
true // continue looping
|
||||
}
|
||||
},
|
||||
_ => false // stop looping
|
||||
}
|
||||
}) { /* empty while loop body */ }
|
||||
if is_internal { return; }
|
||||
if self.is_internal(cx, e.span) { return; }
|
||||
|
||||
let mut span = e.span;
|
||||
|
||||
let id = match e.node {
|
||||
ast::ExprPath(..) | ast::ExprStruct(..) => {
|
||||
match cx.tcx.def_map.borrow().find(&e.id) {
|
||||
match cx.tcx.def_map.borrow().get(&e.id) {
|
||||
Some(&def) => def.def_id(),
|
||||
None => return
|
||||
}
|
||||
|
|
@ -1645,7 +1649,7 @@ impl LintPass for Stability {
|
|||
ast::ExprMethodCall(i, _, _) => {
|
||||
span = i.span;
|
||||
let method_call = typeck::MethodCall::expr(e.id);
|
||||
match cx.tcx.method_map.borrow().find(&method_call) {
|
||||
match cx.tcx.method_map.borrow().get(&method_call) {
|
||||
Some(method) => {
|
||||
match method.origin {
|
||||
typeck::MethodStatic(def_id) => {
|
||||
|
|
@ -1677,6 +1681,29 @@ impl LintPass for Stability {
|
|||
};
|
||||
self.lint(cx, id, span);
|
||||
}
|
||||
|
||||
fn check_item(&mut self, cx: &Context, item: &ast::Item) {
|
||||
if self.is_internal(cx, item.span) { return }
|
||||
|
||||
match item.node {
|
||||
ast::ItemTrait(_, _, ref supertraits, _) => {
|
||||
for t in supertraits.iter() {
|
||||
match *t {
|
||||
ast::TraitTyParamBound(ref t) => {
|
||||
let id = ty::trait_ref_to_def_id(cx.tcx, t);
|
||||
self.lint(cx, id, t.path.span);
|
||||
}
|
||||
_ => (/* pass */)
|
||||
}
|
||||
}
|
||||
}
|
||||
ast::ItemImpl(_, Some(ref t), _, _) => {
|
||||
let id = ty::trait_ref_to_def_id(cx.tcx, t);
|
||||
self.lint(cx, id, t.path.span);
|
||||
}
|
||||
_ => (/* pass */)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
declare_lint!(pub UNUSED_IMPORTS, Warn,
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ enum TargetLint {
|
|||
|
||||
impl LintStore {
|
||||
fn get_level_source(&self, lint: LintId) -> LevelSource {
|
||||
match self.levels.find(&lint) {
|
||||
match self.levels.get(&lint) {
|
||||
Some(&s) => s,
|
||||
None => (Allow, Default),
|
||||
}
|
||||
|
|
@ -124,7 +124,7 @@ impl LintStore {
|
|||
self.lints.push((*lint, from_plugin));
|
||||
|
||||
let id = LintId::of(*lint);
|
||||
if !self.by_name.insert(lint.name_lower(), Id(id)) {
|
||||
if self.by_name.insert(lint.name_lower(), Id(id)).is_some() {
|
||||
let msg = format!("duplicate specification of lint {}", lint.name_lower());
|
||||
match (sess, from_plugin) {
|
||||
// We load builtin lints first, so a duplicate is a compiler bug.
|
||||
|
|
@ -147,7 +147,7 @@ impl LintStore {
|
|||
pub fn register_group(&mut self, sess: Option<&Session>,
|
||||
from_plugin: bool, name: &'static str,
|
||||
to: Vec<LintId>) {
|
||||
let new = self.lint_groups.insert(name, (to, from_plugin));
|
||||
let new = self.lint_groups.insert(name, (to, from_plugin)).is_none();
|
||||
|
||||
if !new {
|
||||
let msg = format!("duplicate specification of lint group {}", name);
|
||||
|
|
@ -437,11 +437,11 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
|
|||
/// Get the level of `lint` at the current position of the lint
|
||||
/// traversal.
|
||||
pub fn current_level(&self, lint: &'static Lint) -> Level {
|
||||
self.lints.levels.find(&LintId::of(lint)).map_or(Allow, |&(lvl, _)| lvl)
|
||||
self.lints.levels.get(&LintId::of(lint)).map_or(Allow, |&(lvl, _)| lvl)
|
||||
}
|
||||
|
||||
fn lookup_and_emit(&self, lint: &'static Lint, span: Option<Span>, msg: &str) {
|
||||
let (level, src) = match self.lints.levels.find(&LintId::of(lint)) {
|
||||
let (level, src) = match self.lints.levels.get(&LintId::of(lint)) {
|
||||
None => return,
|
||||
Some(&(Warn, src)) => {
|
||||
let lint_id = LintId::of(builtin::WARNINGS);
|
||||
|
|
@ -750,7 +750,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> {
|
|||
// Output any lints that were previously added to the session.
|
||||
impl<'a, 'tcx> IdVisitingOperation for Context<'a, 'tcx> {
|
||||
fn visit_id(&mut self, id: ast::NodeId) {
|
||||
match self.tcx.sess.lints.borrow_mut().pop(&id) {
|
||||
match self.tcx.sess.lints.borrow_mut().remove(&id) {
|
||||
None => {}
|
||||
Some(lints) => {
|
||||
for (lint_id, span, msg) in lints.into_iter() {
|
||||
|
|
|
|||
|
|
@ -213,7 +213,7 @@ impl CStore {
|
|||
|
||||
pub fn find_extern_mod_stmt_cnum(&self, emod_id: ast::NodeId)
|
||||
-> Option<ast::CrateNum> {
|
||||
self.extern_mod_crate_map.borrow().find(&emod_id).map(|x| *x)
|
||||
self.extern_mod_crate_map.borrow().get(&emod_id).map(|x| *x)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1209,7 +1209,7 @@ pub fn translate_def_id(cdata: Cmd, did: ast::DefId) -> ast::DefId {
|
|||
return ast::DefId { krate: cdata.cnum, node: did.node };
|
||||
}
|
||||
|
||||
match cdata.cnum_map.find(&did.krate) {
|
||||
match cdata.cnum_map.get(&did.krate) {
|
||||
Some(&n) => {
|
||||
ast::DefId {
|
||||
krate: n,
|
||||
|
|
@ -1321,7 +1321,7 @@ pub fn get_dylib_dependency_formats(cdata: Cmd)
|
|||
let cnum = spec.split(':').nth(0).unwrap();
|
||||
let link = spec.split(':').nth(1).unwrap();
|
||||
let cnum = from_str(cnum).unwrap();
|
||||
let cnum = match cdata.cnum_map.find(&cnum) {
|
||||
let cnum = match cdata.cnum_map.get(&cnum) {
|
||||
Some(&n) => n,
|
||||
None => panic!("didn't find a crate in the cnum_map")
|
||||
};
|
||||
|
|
|
|||
|
|
@ -253,7 +253,7 @@ fn encode_symbol(ecx: &EncodeContext,
|
|||
rbml_w: &mut Encoder,
|
||||
id: NodeId) {
|
||||
rbml_w.start_tag(tag_items_data_item_symbol);
|
||||
match ecx.item_symbols.borrow().find(&id) {
|
||||
match ecx.item_symbols.borrow().get(&id) {
|
||||
Some(x) => {
|
||||
debug!("encode_symbol(id={}, str={})", id, *x);
|
||||
rbml_w.writer.write(x.as_bytes());
|
||||
|
|
@ -397,7 +397,7 @@ fn encode_reexported_static_base_methods(ecx: &EncodeContext,
|
|||
exp: &middle::resolve::Export2)
|
||||
-> bool {
|
||||
let impl_items = ecx.tcx.impl_items.borrow();
|
||||
match ecx.tcx.inherent_impls.borrow().find(&exp.def_id) {
|
||||
match ecx.tcx.inherent_impls.borrow().get(&exp.def_id) {
|
||||
Some(implementations) => {
|
||||
for base_impl_did in implementations.iter() {
|
||||
for &method_did in (*impl_items)[*base_impl_did].iter() {
|
||||
|
|
@ -426,7 +426,7 @@ fn encode_reexported_static_trait_methods(ecx: &EncodeContext,
|
|||
rbml_w: &mut Encoder,
|
||||
exp: &middle::resolve::Export2)
|
||||
-> bool {
|
||||
match ecx.tcx.trait_items_cache.borrow().find(&exp.def_id) {
|
||||
match ecx.tcx.trait_items_cache.borrow().get(&exp.def_id) {
|
||||
Some(trait_items) => {
|
||||
for trait_item in trait_items.iter() {
|
||||
match *trait_item {
|
||||
|
|
@ -531,7 +531,7 @@ fn encode_reexports(ecx: &EncodeContext,
|
|||
id: NodeId,
|
||||
path: PathElems) {
|
||||
debug!("(encoding info for module) encoding reexports for {}", id);
|
||||
match ecx.reexports2.find(&id) {
|
||||
match ecx.reexports2.get(&id) {
|
||||
Some(ref exports) => {
|
||||
debug!("(encoding info for module) found reexports for {}", id);
|
||||
for exp in exports.iter() {
|
||||
|
|
@ -978,7 +978,7 @@ fn should_inline(attrs: &[Attribute]) -> bool {
|
|||
fn encode_inherent_implementations(ecx: &EncodeContext,
|
||||
rbml_w: &mut Encoder,
|
||||
def_id: DefId) {
|
||||
match ecx.tcx.inherent_impls.borrow().find(&def_id) {
|
||||
match ecx.tcx.inherent_impls.borrow().get(&def_id) {
|
||||
None => {}
|
||||
Some(implementations) => {
|
||||
for &impl_def_id in implementations.iter() {
|
||||
|
|
@ -994,7 +994,7 @@ fn encode_inherent_implementations(ecx: &EncodeContext,
|
|||
fn encode_extension_implementations(ecx: &EncodeContext,
|
||||
rbml_w: &mut Encoder,
|
||||
trait_def_id: DefId) {
|
||||
match ecx.tcx.trait_impls.borrow().find(&trait_def_id) {
|
||||
match ecx.tcx.trait_impls.borrow().get(&trait_def_id) {
|
||||
None => {}
|
||||
Some(implementations) => {
|
||||
for &impl_def_id in implementations.borrow().iter() {
|
||||
|
|
@ -1987,7 +1987,7 @@ fn encode_crate_triple(rbml_w: &mut Encoder, triple: &str) {
|
|||
|
||||
fn encode_dylib_dependency_formats(rbml_w: &mut Encoder, ecx: &EncodeContext) {
|
||||
rbml_w.start_tag(tag_dylib_dependency_formats);
|
||||
match ecx.tcx.dependency_formats.borrow().find(&config::CrateTypeDylib) {
|
||||
match ecx.tcx.dependency_formats.borrow().get(&config::CrateTypeDylib) {
|
||||
Some(arr) => {
|
||||
let s = arr.iter().enumerate().filter_map(|(i, slot)| {
|
||||
slot.map(|kind| (format!("{}:{}", i + 1, match kind {
|
||||
|
|
|
|||
|
|
@ -675,16 +675,16 @@ fn parse_builtin_bounds(st: &mut PState, _conv: conv_did) -> ty::BuiltinBounds {
|
|||
loop {
|
||||
match next(st) {
|
||||
'S' => {
|
||||
builtin_bounds.add(ty::BoundSend);
|
||||
builtin_bounds.insert(ty::BoundSend);
|
||||
}
|
||||
'Z' => {
|
||||
builtin_bounds.add(ty::BoundSized);
|
||||
builtin_bounds.insert(ty::BoundSized);
|
||||
}
|
||||
'P' => {
|
||||
builtin_bounds.add(ty::BoundCopy);
|
||||
builtin_bounds.insert(ty::BoundCopy);
|
||||
}
|
||||
'T' => {
|
||||
builtin_bounds.add(ty::BoundSync);
|
||||
builtin_bounds.insert(ty::BoundSync);
|
||||
}
|
||||
'.' => {
|
||||
return builtin_bounds;
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ pub struct ty_abbrev {
|
|||
pub type abbrev_map = RefCell<HashMap<ty::t, ty_abbrev>>;
|
||||
|
||||
pub fn enc_ty(w: &mut SeekableMemWriter, cx: &ctxt, t: ty::t) {
|
||||
match cx.abbrevs.borrow_mut().find(&t) {
|
||||
match cx.abbrevs.borrow_mut().get(&t) {
|
||||
Some(a) => { w.write(a.s.as_bytes()); return; }
|
||||
None => {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1151,14 +1151,14 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
|
|||
|
||||
debug!("Encoding side tables for id {}", id);
|
||||
|
||||
for def in tcx.def_map.borrow().find(&id).iter() {
|
||||
for def in tcx.def_map.borrow().get(&id).iter() {
|
||||
rbml_w.tag(c::tag_table_def, |rbml_w| {
|
||||
rbml_w.id(id);
|
||||
rbml_w.tag(c::tag_table_val, |rbml_w| (*def).encode(rbml_w).unwrap());
|
||||
})
|
||||
}
|
||||
|
||||
for &ty in tcx.node_types.borrow().find(&(id as uint)).iter() {
|
||||
for &ty in tcx.node_types.borrow().get(&(id as uint)).iter() {
|
||||
rbml_w.tag(c::tag_table_node_type, |rbml_w| {
|
||||
rbml_w.id(id);
|
||||
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
||||
|
|
@ -1167,7 +1167,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
|
|||
})
|
||||
}
|
||||
|
||||
for &item_substs in tcx.item_substs.borrow().find(&id).iter() {
|
||||
for &item_substs in tcx.item_substs.borrow().get(&id).iter() {
|
||||
rbml_w.tag(c::tag_table_item_subst, |rbml_w| {
|
||||
rbml_w.id(id);
|
||||
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
||||
|
|
@ -1176,7 +1176,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
|
|||
})
|
||||
}
|
||||
|
||||
for &fv in tcx.freevars.borrow().find(&id).iter() {
|
||||
for &fv in tcx.freevars.borrow().get(&id).iter() {
|
||||
rbml_w.tag(c::tag_table_freevars, |rbml_w| {
|
||||
rbml_w.id(id);
|
||||
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
||||
|
|
@ -1209,7 +1209,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
|
|||
}
|
||||
}
|
||||
|
||||
for &cm in tcx.capture_modes.borrow().find(&id).iter() {
|
||||
for &cm in tcx.capture_modes.borrow().get(&id).iter() {
|
||||
rbml_w.tag(c::tag_table_capture_modes, |rbml_w| {
|
||||
rbml_w.id(id);
|
||||
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
||||
|
|
@ -1219,7 +1219,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
|
|||
}
|
||||
|
||||
let lid = ast::DefId { krate: ast::LOCAL_CRATE, node: id };
|
||||
for &pty in tcx.tcache.borrow().find(&lid).iter() {
|
||||
for &pty in tcx.tcache.borrow().get(&lid).iter() {
|
||||
rbml_w.tag(c::tag_table_tcache, |rbml_w| {
|
||||
rbml_w.id(id);
|
||||
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
||||
|
|
@ -1228,7 +1228,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
|
|||
})
|
||||
}
|
||||
|
||||
for &type_param_def in tcx.ty_param_defs.borrow().find(&id).iter() {
|
||||
for &type_param_def in tcx.ty_param_defs.borrow().get(&id).iter() {
|
||||
rbml_w.tag(c::tag_table_param_defs, |rbml_w| {
|
||||
rbml_w.id(id);
|
||||
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
||||
|
|
@ -1238,7 +1238,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
|
|||
}
|
||||
|
||||
let method_call = MethodCall::expr(id);
|
||||
for &method in tcx.method_map.borrow().find(&method_call).iter() {
|
||||
for &method in tcx.method_map.borrow().get(&method_call).iter() {
|
||||
rbml_w.tag(c::tag_table_method_map, |rbml_w| {
|
||||
rbml_w.id(id);
|
||||
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
||||
|
|
@ -1247,7 +1247,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
|
|||
})
|
||||
}
|
||||
|
||||
for &trait_ref in tcx.object_cast_map.borrow().find(&id).iter() {
|
||||
for &trait_ref in tcx.object_cast_map.borrow().get(&id).iter() {
|
||||
rbml_w.tag(c::tag_table_object_cast_map, |rbml_w| {
|
||||
rbml_w.id(id);
|
||||
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
||||
|
|
@ -1256,11 +1256,11 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
|
|||
})
|
||||
}
|
||||
|
||||
for &adjustment in tcx.adjustments.borrow().find(&id).iter() {
|
||||
for &adjustment in tcx.adjustments.borrow().get(&id).iter() {
|
||||
match *adjustment {
|
||||
_ if ty::adjust_is_object(adjustment) => {
|
||||
let method_call = MethodCall::autoobject(id);
|
||||
for &method in tcx.method_map.borrow().find(&method_call).iter() {
|
||||
for &method in tcx.method_map.borrow().get(&method_call).iter() {
|
||||
rbml_w.tag(c::tag_table_method_map, |rbml_w| {
|
||||
rbml_w.id(id);
|
||||
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
||||
|
|
@ -1273,7 +1273,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
|
|||
assert!(!ty::adjust_is_object(adjustment));
|
||||
for autoderef in range(0, adj.autoderefs) {
|
||||
let method_call = MethodCall::autoderef(id, autoderef);
|
||||
for &method in tcx.method_map.borrow().find(&method_call).iter() {
|
||||
for &method in tcx.method_map.borrow().get(&method_call).iter() {
|
||||
rbml_w.tag(c::tag_table_method_map, |rbml_w| {
|
||||
rbml_w.id(id);
|
||||
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
||||
|
|
@ -1299,7 +1299,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
|
|||
|
||||
for unboxed_closure in tcx.unboxed_closures
|
||||
.borrow()
|
||||
.find(&ast_util::local_def(id))
|
||||
.get(&ast_util::local_def(id))
|
||||
.iter() {
|
||||
rbml_w.tag(c::tag_table_unboxed_closures, |rbml_w| {
|
||||
rbml_w.id(id);
|
||||
|
|
|
|||
|
|
@ -242,7 +242,7 @@ impl MoveData {
|
|||
* base paths that do not yet have an index.
|
||||
*/
|
||||
|
||||
match self.path_map.borrow().find(&lp) {
|
||||
match self.path_map.borrow().get(&lp) {
|
||||
Some(&index) => {
|
||||
return index;
|
||||
}
|
||||
|
|
@ -577,7 +577,7 @@ impl<'a, 'tcx> FlowedMoveData<'a, 'tcx> {
|
|||
//! Returns the kind of a move of `loan_path` by `id`, if one exists.
|
||||
|
||||
let mut ret = None;
|
||||
for loan_path_index in self.move_data.path_map.borrow().find(&*loan_path).iter() {
|
||||
for loan_path_index in self.move_data.path_map.borrow().get(&*loan_path).iter() {
|
||||
self.dfcx_moves.each_gen_bit(id, |move_index| {
|
||||
let the_move = self.move_data.moves.borrow();
|
||||
let the_move = (*the_move)[move_index];
|
||||
|
|
|
|||
|
|
@ -512,7 +512,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
|
|||
func_or_rcvr: &ast::Expr,
|
||||
args: I) -> CFGIndex {
|
||||
let method_call = typeck::MethodCall::expr(call_expr.id);
|
||||
let return_ty = ty::ty_fn_ret(match self.tcx.method_map.borrow().find(&method_call) {
|
||||
let return_ty = ty::ty_fn_ret(match self.tcx.method_map.borrow().get(&method_call) {
|
||||
Some(method) => method.ty,
|
||||
None => ty::expr_ty(self.tcx, func_or_rcvr)
|
||||
});
|
||||
|
|
@ -610,7 +610,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
|
|||
}
|
||||
|
||||
Some(_) => {
|
||||
match self.tcx.def_map.borrow().find(&expr.id) {
|
||||
match self.tcx.def_map.borrow().get(&expr.id) {
|
||||
Some(&def::DefLabel(loop_id)) => {
|
||||
for l in self.loop_scopes.iter() {
|
||||
if l.loop_id == loop_id {
|
||||
|
|
|
|||
|
|
@ -138,12 +138,12 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr) -> bool {
|
|||
// to handle on-demand instantiation of functions via
|
||||
// foo::<bar> in a const. Currently that is only done on
|
||||
// a path in trans::callee that only works in block contexts.
|
||||
if !pth.segments.iter().all(|segment| segment.types.is_empty()) {
|
||||
if !pth.segments.iter().all(|segment| segment.parameters.is_empty()) {
|
||||
span_err!(v.tcx.sess, e.span, E0013,
|
||||
"paths in constants may only refer to items without \
|
||||
type parameters");
|
||||
}
|
||||
match v.tcx.def_map.borrow().find(&e.id) {
|
||||
match v.tcx.def_map.borrow().get(&e.id) {
|
||||
Some(&DefStatic(..)) |
|
||||
Some(&DefConst(..)) |
|
||||
Some(&DefFn(..)) |
|
||||
|
|
@ -162,7 +162,7 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr) -> bool {
|
|||
}
|
||||
}
|
||||
ExprCall(ref callee, _) => {
|
||||
match v.tcx.def_map.borrow().find(&callee.id) {
|
||||
match v.tcx.def_map.borrow().get(&callee.id) {
|
||||
Some(&DefStruct(..)) |
|
||||
Some(&DefVariant(..)) => {} // OK.
|
||||
|
||||
|
|
|
|||
|
|
@ -639,7 +639,7 @@ fn pat_constructors(cx: &MatchCheckCtxt, p: &Pat,
|
|||
let pat = raw_pat(p);
|
||||
match pat.node {
|
||||
PatIdent(..) =>
|
||||
match cx.tcx.def_map.borrow().find(&pat.id) {
|
||||
match cx.tcx.def_map.borrow().get(&pat.id) {
|
||||
Some(&DefConst(..)) =>
|
||||
cx.tcx.sess.span_bug(pat.span, "const pattern should've \
|
||||
been rewritten"),
|
||||
|
|
@ -648,7 +648,7 @@ fn pat_constructors(cx: &MatchCheckCtxt, p: &Pat,
|
|||
_ => vec!()
|
||||
},
|
||||
PatEnum(..) =>
|
||||
match cx.tcx.def_map.borrow().find(&pat.id) {
|
||||
match cx.tcx.def_map.borrow().get(&pat.id) {
|
||||
Some(&DefConst(..)) =>
|
||||
cx.tcx.sess.span_bug(pat.span, "const pattern should've \
|
||||
been rewritten"),
|
||||
|
|
@ -656,7 +656,7 @@ fn pat_constructors(cx: &MatchCheckCtxt, p: &Pat,
|
|||
_ => vec!(Single)
|
||||
},
|
||||
PatStruct(..) =>
|
||||
match cx.tcx.def_map.borrow().find(&pat.id) {
|
||||
match cx.tcx.def_map.borrow().get(&pat.id) {
|
||||
Some(&DefConst(..)) =>
|
||||
cx.tcx.sess.span_bug(pat.span, "const pattern should've \
|
||||
been rewritten"),
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ impl<'a, 'ast, 'v> Visitor<'v> for CheckItemRecursionVisitor<'a, 'ast> {
|
|||
fn visit_expr(&mut self, e: &ast::Expr) {
|
||||
match e.node {
|
||||
ast::ExprPath(..) => {
|
||||
match self.def_map.borrow().find(&e.id) {
|
||||
match self.def_map.borrow().get(&e.id) {
|
||||
Some(&DefStatic(def_id, _)) |
|
||||
Some(&DefConst(def_id)) if
|
||||
ast_util::is_local(def_id) => {
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ fn lookup_variant_by_id<'a>(tcx: &'a ty::ctxt,
|
|||
Some(_) => None
|
||||
}
|
||||
} else {
|
||||
match tcx.extern_const_variants.borrow().find(&variant_def) {
|
||||
match tcx.extern_const_variants.borrow().get(&variant_def) {
|
||||
Some(&ast::DUMMY_NODE_ID) => return None,
|
||||
Some(&expr_id) => {
|
||||
return Some(tcx.map.expect_expr(expr_id));
|
||||
|
|
@ -163,7 +163,7 @@ pub fn lookup_const_by_id<'a>(tcx: &'a ty::ctxt, def_id: ast::DefId)
|
|||
Some(_) => None
|
||||
}
|
||||
} else {
|
||||
match tcx.extern_const_statics.borrow().find(&def_id) {
|
||||
match tcx.extern_const_statics.borrow().get(&def_id) {
|
||||
Some(&ast::DUMMY_NODE_ID) => return None,
|
||||
Some(&expr_id) => {
|
||||
return Some(tcx.map.expect_expr(expr_id));
|
||||
|
|
@ -192,7 +192,7 @@ struct ConstEvalVisitor<'a, 'tcx: 'a> {
|
|||
impl<'a, 'tcx> ConstEvalVisitor<'a, 'tcx> {
|
||||
fn classify(&mut self, e: &Expr) -> constness {
|
||||
let did = ast_util::local_def(e.id);
|
||||
match self.ccache.find(&did) {
|
||||
match self.ccache.get(&did) {
|
||||
Some(&x) => return x,
|
||||
None => {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ struct PropagationContext<'a, 'b: 'a, 'tcx: 'b, O: 'a> {
|
|||
}
|
||||
|
||||
fn to_cfgidx_or_die(id: ast::NodeId, index: &NodeMap<CFGIndex>) -> CFGIndex {
|
||||
let opt_cfgindex = index.find(&id).map(|&i|i);
|
||||
let opt_cfgindex = index.get(&id).map(|&i|i);
|
||||
opt_cfgindex.unwrap_or_else(|| {
|
||||
panic!("nodeid_to_index does not have entry for NodeId {}", id);
|
||||
})
|
||||
|
|
@ -397,7 +397,7 @@ impl<'a, 'tcx, O:DataFlowOperator> DataFlowContext<'a, 'tcx, O> {
|
|||
|
||||
let mut changed = false;
|
||||
for &node_id in edge.data.exiting_scopes.iter() {
|
||||
let opt_cfg_idx = self.nodeid_to_index.find(&node_id).map(|&i|i);
|
||||
let opt_cfg_idx = self.nodeid_to_index.get(&node_id).map(|&i|i);
|
||||
match opt_cfg_idx {
|
||||
Some(cfg_idx) => {
|
||||
let (start, end) = self.compute_id_range(cfg_idx);
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
fn lookup_and_handle_definition(&mut self, id: &ast::NodeId) {
|
||||
self.tcx.def_map.borrow().find(id).map(|def| {
|
||||
self.tcx.def_map.borrow().get(id).map(|def| {
|
||||
match def {
|
||||
&def::DefConst(_) => {
|
||||
self.check_def_id(def.def_id())
|
||||
|
|
@ -95,7 +95,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
|
|||
fn lookup_and_handle_method(&mut self, id: ast::NodeId,
|
||||
span: codemap::Span) {
|
||||
let method_call = typeck::MethodCall::expr(id);
|
||||
match self.tcx.method_map.borrow().find(&method_call) {
|
||||
match self.tcx.method_map.borrow().get(&method_call) {
|
||||
Some(method) => {
|
||||
match method.origin {
|
||||
typeck::MethodStatic(def_id) => {
|
||||
|
|
@ -493,7 +493,7 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
|
|||
// method of a private type is used, but the type itself is never
|
||||
// called directly.
|
||||
let impl_items = self.tcx.impl_items.borrow();
|
||||
match self.tcx.inherent_impls.borrow().find(&local_def(id)) {
|
||||
match self.tcx.inherent_impls.borrow().get(&local_def(id)) {
|
||||
None => (),
|
||||
Some(impl_list) => {
|
||||
for impl_did in impl_list.iter() {
|
||||
|
|
|
|||
|
|
@ -158,7 +158,7 @@ fn calculate_type(sess: &session::Session,
|
|||
|
||||
// Collect what we've got so far in the return vector.
|
||||
let mut ret = range(1, sess.cstore.next_crate_num()).map(|i| {
|
||||
match formats.find(&i).map(|v| *v) {
|
||||
match formats.get(&i).map(|v| *v) {
|
||||
v @ Some(cstore::RequireDynamic) => v,
|
||||
_ => None,
|
||||
}
|
||||
|
|
@ -209,7 +209,7 @@ fn add_library(sess: &session::Session,
|
|||
cnum: ast::CrateNum,
|
||||
link: cstore::LinkagePreference,
|
||||
m: &mut HashMap<ast::CrateNum, cstore::LinkagePreference>) {
|
||||
match m.find(&cnum) {
|
||||
match m.get(&cnum) {
|
||||
Some(&link2) => {
|
||||
// If the linkages differ, then we'd have two copies of the library
|
||||
// if we continued linking. If the linkages are both static, then we
|
||||
|
|
|
|||
|
|
@ -162,7 +162,7 @@ impl OverloadedCallType {
|
|||
let trait_did =
|
||||
tcx.unboxed_closures
|
||||
.borrow()
|
||||
.find(&closure_did)
|
||||
.get(&closure_did)
|
||||
.expect("OverloadedCallType::from_unboxed_closure: didn't \
|
||||
find closure id")
|
||||
.kind
|
||||
|
|
@ -535,7 +535,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,TYPER> {
|
|||
match self.tcx()
|
||||
.method_map
|
||||
.borrow()
|
||||
.find(&MethodCall::expr(call.id)) {
|
||||
.get(&MethodCall::expr(call.id)) {
|
||||
Some(ref method_callee) => {
|
||||
OverloadedCallType::from_method_origin(
|
||||
self.tcx(),
|
||||
|
|
@ -686,7 +686,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,TYPER> {
|
|||
// process.
|
||||
fn walk_adjustment(&mut self, expr: &ast::Expr) {
|
||||
let typer = self.typer;
|
||||
match typer.adjustments().borrow().find(&expr.id) {
|
||||
match typer.adjustments().borrow().get(&expr.id) {
|
||||
None => { }
|
||||
Some(adjustment) => {
|
||||
match *adjustment {
|
||||
|
|
|
|||
|
|
@ -173,7 +173,7 @@ impl<'a> LanguageItemCollector<'a> {
|
|||
}
|
||||
|
||||
// Matched.
|
||||
*self.items.items.get_mut(item_index) = Some(item_def_id);
|
||||
self.items.items[item_index] = Some(item_def_id);
|
||||
}
|
||||
|
||||
pub fn collect_local_language_items(&mut self, krate: &ast::Crate) {
|
||||
|
|
|
|||
|
|
@ -322,7 +322,7 @@ impl<'a, 'tcx> IrMaps<'a, 'tcx> {
|
|||
}
|
||||
|
||||
fn variable(&self, node_id: NodeId, span: Span) -> Variable {
|
||||
match self.variable_map.find(&node_id) {
|
||||
match self.variable_map.get(&node_id) {
|
||||
Some(&var) => var,
|
||||
None => {
|
||||
self.tcx
|
||||
|
|
@ -591,7 +591,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
|||
}
|
||||
|
||||
fn live_node(&self, node_id: NodeId, span: Span) -> LiveNode {
|
||||
match self.ir.live_node_map.find(&node_id) {
|
||||
match self.ir.live_node_map.get(&node_id) {
|
||||
Some(&ln) => ln,
|
||||
None => {
|
||||
// This must be a mismatch between the ir_map construction
|
||||
|
|
@ -719,7 +719,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
|||
Some(_) => {
|
||||
// Refers to a labeled loop. Use the results of resolve
|
||||
// to find with one
|
||||
match self.ir.tcx.def_map.borrow().find(&id) {
|
||||
match self.ir.tcx.def_map.borrow().get(&id) {
|
||||
Some(&DefLabel(loop_id)) => loop_id,
|
||||
_ => self.ir.tcx.sess.span_bug(sp, "label on break/loop \
|
||||
doesn't refer to a loop")
|
||||
|
|
@ -988,7 +988,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
|||
|
||||
// the construction of a closure itself is not important,
|
||||
// but we have to consider the closed over variables.
|
||||
let caps = match this.ir.capture_info_map.find(&expr.id) {
|
||||
let caps = match this.ir.capture_info_map.get(&expr.id) {
|
||||
Some(caps) => caps.clone(),
|
||||
None => {
|
||||
this.ir.tcx.sess.span_bug(expr.span, "no registered caps");
|
||||
|
|
@ -1096,7 +1096,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
|||
// Now that we know the label we're going to,
|
||||
// look it up in the break loop nodes table
|
||||
|
||||
match self.break_ln.find(&sc) {
|
||||
match self.break_ln.get(&sc) {
|
||||
Some(&b) => b,
|
||||
None => self.ir.tcx.sess.span_bug(expr.span,
|
||||
"break to unknown label")
|
||||
|
|
@ -1110,7 +1110,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
|||
// Now that we know the label we're going to,
|
||||
// look it up in the continue loop nodes table
|
||||
|
||||
match self.cont_ln.find(&sc) {
|
||||
match self.cont_ln.get(&sc) {
|
||||
Some(&b) => b,
|
||||
None => self.ir.tcx.sess.span_bug(expr.span,
|
||||
"loop to unknown label")
|
||||
|
|
@ -1167,7 +1167,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
|||
|
||||
ExprMethodCall(_, _, ref args) => {
|
||||
let method_call = typeck::MethodCall::expr(expr.id);
|
||||
let method_ty = self.ir.tcx.method_map.borrow().find(&method_call).unwrap().ty;
|
||||
let method_ty = self.ir.tcx.method_map.borrow().get(&method_call).unwrap().ty;
|
||||
let diverges = ty::ty_fn_ret(method_ty) == ty::FnDiverging;
|
||||
let succ = if diverges {
|
||||
self.s.exit_ln
|
||||
|
|
@ -1520,7 +1520,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
|||
ty::ty_unboxed_closure(closure_def_id, _, _) =>
|
||||
self.ir.tcx.unboxed_closures()
|
||||
.borrow()
|
||||
.find(&closure_def_id)
|
||||
.get(&closure_def_id)
|
||||
.unwrap()
|
||||
.closure_type
|
||||
.sig
|
||||
|
|
|
|||
|
|
@ -389,7 +389,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
|
|||
fn expr_ty_adjusted(&self, expr: &ast::Expr) -> McResult<ty::t> {
|
||||
let unadjusted_ty = if_ok!(self.expr_ty(expr));
|
||||
Ok(ty::adjust_ty(self.tcx(), expr.span, expr.id, unadjusted_ty,
|
||||
self.typer.adjustments().borrow().find(&expr.id),
|
||||
self.typer.adjustments().borrow().get(&expr.id),
|
||||
|method_call| self.typer.node_method_ty(method_call)))
|
||||
}
|
||||
|
||||
|
|
@ -402,7 +402,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
|
|||
}
|
||||
|
||||
pub fn cat_expr(&self, expr: &ast::Expr) -> McResult<cmt> {
|
||||
match self.typer.adjustments().borrow().find(&expr.id) {
|
||||
match self.typer.adjustments().borrow().get(&expr.id) {
|
||||
None => {
|
||||
// No adjustments.
|
||||
self.cat_expr_unadjusted(expr)
|
||||
|
|
@ -861,7 +861,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
|
|||
deref_cnt: uint,
|
||||
implicit: bool)
|
||||
-> cmt {
|
||||
let adjustment = match self.typer.adjustments().borrow().find(&node.id()) {
|
||||
let adjustment = match self.typer.adjustments().borrow().get(&node.id()) {
|
||||
Some(adj) if ty::adjust_is_object(adj) => typeck::AutoObject,
|
||||
_ if deref_cnt != 0 => typeck::AutoDeref(deref_cnt),
|
||||
_ => typeck::NoAdjustment
|
||||
|
|
@ -1170,7 +1170,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
|
|||
// variant(..)
|
||||
}
|
||||
ast::PatEnum(_, Some(ref subpats)) => {
|
||||
match self.tcx().def_map.borrow().find(&pat.id) {
|
||||
match self.tcx().def_map.borrow().get(&pat.id) {
|
||||
Some(&def::DefVariant(enum_did, _, _)) => {
|
||||
// variant(x, y, z)
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ use std::collections::HashMap;
|
|||
use syntax::ast::*;
|
||||
use syntax::ast_util::{walk_pat};
|
||||
use syntax::codemap::{Span, DUMMY_SP};
|
||||
use syntax::owned_slice::OwnedSlice;
|
||||
|
||||
pub type PatIdMap = HashMap<Ident, NodeId>;
|
||||
|
||||
|
|
@ -34,7 +33,7 @@ pub fn pat_is_refutable(dm: &resolve::DefMap, pat: &Pat) -> bool {
|
|||
match pat.node {
|
||||
PatLit(_) | PatRange(_, _) => true,
|
||||
PatEnum(_, _) | PatIdent(_, _, None) | PatStruct(..) => {
|
||||
match dm.borrow().find(&pat.id) {
|
||||
match dm.borrow().get(&pat.id) {
|
||||
Some(&DefVariant(..)) => true,
|
||||
_ => false
|
||||
}
|
||||
|
|
@ -47,7 +46,7 @@ pub fn pat_is_refutable(dm: &resolve::DefMap, pat: &Pat) -> bool {
|
|||
pub fn pat_is_variant_or_struct(dm: &resolve::DefMap, pat: &Pat) -> bool {
|
||||
match pat.node {
|
||||
PatEnum(_, _) | PatIdent(_, _, None) | PatStruct(..) => {
|
||||
match dm.borrow().find(&pat.id) {
|
||||
match dm.borrow().get(&pat.id) {
|
||||
Some(&DefVariant(..)) | Some(&DefStruct(..)) => true,
|
||||
_ => false
|
||||
}
|
||||
|
|
@ -59,7 +58,7 @@ pub fn pat_is_variant_or_struct(dm: &resolve::DefMap, pat: &Pat) -> bool {
|
|||
pub fn pat_is_const(dm: &resolve::DefMap, pat: &Pat) -> bool {
|
||||
match pat.node {
|
||||
PatIdent(_, _, None) | PatEnum(..) => {
|
||||
match dm.borrow().find(&pat.id) {
|
||||
match dm.borrow().get(&pat.id) {
|
||||
Some(&DefConst(..)) => true,
|
||||
_ => false
|
||||
}
|
||||
|
|
@ -133,8 +132,7 @@ pub fn def_to_path(tcx: &ty::ctxt, id: DefId) -> Path {
|
|||
global: false,
|
||||
segments: path.last().map(|elem| PathSegment {
|
||||
identifier: Ident::new(elem.name()),
|
||||
lifetimes: vec!(),
|
||||
types: OwnedSlice::empty()
|
||||
parameters: PathParameters::none(),
|
||||
}).into_iter().collect(),
|
||||
span: DUMMY_SP,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ use syntax::ast_map;
|
|||
use syntax::ast_util::{is_local, local_def, PostExpansionMethod};
|
||||
use syntax::codemap::Span;
|
||||
use syntax::parse::token;
|
||||
use syntax::owned_slice::OwnedSlice;
|
||||
use syntax::visit;
|
||||
use syntax::visit::Visitor;
|
||||
|
||||
|
|
@ -399,7 +398,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
|
|||
}
|
||||
debug!("privacy - is {} a public method", did);
|
||||
|
||||
return match self.tcx.impl_or_trait_items.borrow().find(&did) {
|
||||
return match self.tcx.impl_or_trait_items.borrow().get(&did) {
|
||||
Some(&ty::MethodTraitItem(ref meth)) => {
|
||||
debug!("privacy - well at least it's a method: {}",
|
||||
*meth);
|
||||
|
|
@ -462,7 +461,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
|
|||
debug!("privacy - local {} not public all the way down",
|
||||
self.tcx.map.node_to_string(did.node));
|
||||
// return quickly for things in the same module
|
||||
if self.parents.find(&did.node) == self.parents.find(&self.curitem) {
|
||||
if self.parents.get(&did.node) == self.parents.get(&self.curitem) {
|
||||
debug!("privacy - same parent, we're done here");
|
||||
return Allowable;
|
||||
}
|
||||
|
|
@ -855,7 +854,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
|
|||
}
|
||||
ast::ExprMethodCall(ident, _, _) => {
|
||||
let method_call = MethodCall::expr(expr.id);
|
||||
match self.tcx.method_map.borrow().find(&method_call) {
|
||||
match self.tcx.method_map.borrow().get(&method_call) {
|
||||
None => {
|
||||
self.tcx.sess.span_bug(expr.span,
|
||||
"method call not in \
|
||||
|
|
@ -909,7 +908,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
|
|||
with private fields");
|
||||
}
|
||||
};
|
||||
match self.tcx.def_map.borrow().find(&expr.id) {
|
||||
match self.tcx.def_map.borrow().get(&expr.id) {
|
||||
Some(&def::DefStruct(did)) => {
|
||||
guard(if is_local(did) {
|
||||
local_def(self.tcx.map.get_parent(did.node))
|
||||
|
|
@ -945,8 +944,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
|
|||
debug!("privacy - ident item {}", id);
|
||||
let seg = ast::PathSegment {
|
||||
identifier: name,
|
||||
lifetimes: Vec::new(),
|
||||
types: OwnedSlice::empty(),
|
||||
parameters: ast::PathParameters::none(),
|
||||
};
|
||||
let segs = vec![seg];
|
||||
let path = ast::Path {
|
||||
|
|
@ -986,7 +984,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
ty::ty_enum(_, _) => {
|
||||
match self.tcx.def_map.borrow().find(&pattern.id) {
|
||||
match self.tcx.def_map.borrow().get(&pattern.id) {
|
||||
Some(&def::DefVariant(_, variant_id, _)) => {
|
||||
for field in fields.iter() {
|
||||
self.check_field(pattern.span, variant_id,
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for ReachableContext<'a, 'tcx> {
|
|||
|
||||
match expr.node {
|
||||
ast::ExprPath(_) => {
|
||||
let def = match self.tcx.def_map.borrow().find(&expr.id) {
|
||||
let def = match self.tcx.def_map.borrow().get(&expr.id) {
|
||||
Some(&def) => def,
|
||||
None => {
|
||||
self.tcx.sess.span_bug(expr.span,
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ struct RegionResolutionVisitor<'a> {
|
|||
|
||||
impl RegionMaps {
|
||||
pub fn relate_free_regions(&self, sub: FreeRegion, sup: FreeRegion) {
|
||||
match self.free_region_map.borrow_mut().find_mut(&sub) {
|
||||
match self.free_region_map.borrow_mut().get_mut(&sub) {
|
||||
Some(sups) => {
|
||||
if !sups.iter().any(|x| x == &sup) {
|
||||
sups.push(sup);
|
||||
|
|
@ -149,13 +149,13 @@ impl RegionMaps {
|
|||
|
||||
pub fn opt_encl_scope(&self, id: ast::NodeId) -> Option<ast::NodeId> {
|
||||
//! Returns the narrowest scope that encloses `id`, if any.
|
||||
self.scope_map.borrow().find(&id).map(|x| *x)
|
||||
self.scope_map.borrow().get(&id).map(|x| *x)
|
||||
}
|
||||
|
||||
#[allow(dead_code)] // used in middle::cfg
|
||||
pub fn encl_scope(&self, id: ast::NodeId) -> ast::NodeId {
|
||||
//! Returns the narrowest scope that encloses `id`, if any.
|
||||
match self.scope_map.borrow().find(&id) {
|
||||
match self.scope_map.borrow().get(&id) {
|
||||
Some(&r) => r,
|
||||
None => { panic!("no enclosing scope for id {}", id); }
|
||||
}
|
||||
|
|
@ -165,7 +165,7 @@ impl RegionMaps {
|
|||
/*!
|
||||
* Returns the lifetime of the local variable `var_id`
|
||||
*/
|
||||
match self.var_map.borrow().find(&var_id) {
|
||||
match self.var_map.borrow().get(&var_id) {
|
||||
Some(&r) => r,
|
||||
None => { panic!("no enclosing scope for id {}", var_id); }
|
||||
}
|
||||
|
|
@ -175,7 +175,7 @@ impl RegionMaps {
|
|||
//! Returns the scope when temp created by expr_id will be cleaned up
|
||||
|
||||
// check for a designated rvalue scope
|
||||
match self.rvalue_scopes.borrow().find(&expr_id) {
|
||||
match self.rvalue_scopes.borrow().get(&expr_id) {
|
||||
Some(&s) => {
|
||||
debug!("temporary_scope({}) = {} [custom]", expr_id, s);
|
||||
return Some(s);
|
||||
|
|
@ -232,7 +232,7 @@ impl RegionMaps {
|
|||
|
||||
let mut s = subscope;
|
||||
while superscope != s {
|
||||
match self.scope_map.borrow().find(&s) {
|
||||
match self.scope_map.borrow().get(&s) {
|
||||
None => {
|
||||
debug!("is_subscope_of({}, {}, s={})=false",
|
||||
subscope, superscope, s);
|
||||
|
|
@ -356,7 +356,7 @@ impl RegionMaps {
|
|||
let mut result = vec!(scope);
|
||||
let mut scope = scope;
|
||||
loop {
|
||||
match this.scope_map.borrow().find(&scope) {
|
||||
match this.scope_map.borrow().get(&scope) {
|
||||
None => return result,
|
||||
Some(&superscope) => {
|
||||
result.push(superscope);
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ use syntax::ast::{TupleVariantKind, Ty, TyBool, TyChar, TyClosure, TyF32};
|
|||
use syntax::ast::{TyF64, TyFloat, TyI, TyI8, TyI16, TyI32, TyI64, TyInt};
|
||||
use syntax::ast::{TyParam, TyParamBound, TyPath, TyPtr, TyProc, TyQPath};
|
||||
use syntax::ast::{TyRptr, TyStr, TyU, TyU8, TyU16, TyU32, TyU64, TyUint};
|
||||
use syntax::ast::{TypeImplItem, UnboxedFnTyParamBound, UnnamedField};
|
||||
use syntax::ast::{TypeImplItem, UnnamedField};
|
||||
use syntax::ast::{Variant, ViewItem, ViewItemExternCrate};
|
||||
use syntax::ast::{ViewItemUse, ViewPathGlob, ViewPathList, ViewPathSimple};
|
||||
use syntax::ast::{Visibility};
|
||||
|
|
@ -2234,7 +2234,7 @@ impl<'a> Resolver<'a> {
|
|||
|
||||
let mut import_resolutions = module_.import_resolutions
|
||||
.borrow_mut();
|
||||
match import_resolutions.find_mut(&target) {
|
||||
match import_resolutions.get_mut(&target) {
|
||||
Some(resolution) => {
|
||||
debug!("(building import directive) bumping \
|
||||
reference");
|
||||
|
|
@ -2552,7 +2552,7 @@ impl<'a> Resolver<'a> {
|
|||
// Search for direct children of the containing module.
|
||||
self.populate_module_if_necessary(&containing_module);
|
||||
|
||||
match containing_module.children.borrow().find(&source) {
|
||||
match containing_module.children.borrow().get(&source) {
|
||||
None => {
|
||||
// Continue.
|
||||
}
|
||||
|
|
@ -2588,7 +2588,7 @@ impl<'a> Resolver<'a> {
|
|||
}
|
||||
|
||||
// Now search the exported imports within the containing module.
|
||||
match containing_module.import_resolutions.borrow().find(&source) {
|
||||
match containing_module.import_resolutions.borrow().get(&source) {
|
||||
None => {
|
||||
debug!("(resolving single import) no import");
|
||||
// The containing module definitely doesn't have an
|
||||
|
|
@ -2853,7 +2853,7 @@ impl<'a> Resolver<'a> {
|
|||
|
||||
// Here we merge two import resolutions.
|
||||
let mut import_resolutions = module_.import_resolutions.borrow_mut();
|
||||
match import_resolutions.find_mut(ident) {
|
||||
match import_resolutions.get_mut(ident) {
|
||||
Some(dest_import_resolution) => {
|
||||
// Merge the two import resolutions at a finer-grained
|
||||
// level.
|
||||
|
|
@ -3046,7 +3046,7 @@ impl<'a> Resolver<'a> {
|
|||
|
||||
// Check for item conflicts.
|
||||
let children = module.children.borrow();
|
||||
let name_bindings = match children.find(&name) {
|
||||
let name_bindings = match children.get(&name) {
|
||||
None => {
|
||||
// There can't be any conflicts.
|
||||
return
|
||||
|
|
@ -3432,7 +3432,7 @@ impl<'a> Resolver<'a> {
|
|||
// its immediate children.
|
||||
self.populate_module_if_necessary(&module_);
|
||||
|
||||
match module_.children.borrow().find(&name) {
|
||||
match module_.children.borrow().get(&name) {
|
||||
Some(name_bindings)
|
||||
if name_bindings.defined_in_namespace(namespace) => {
|
||||
debug!("top name bindings succeeded");
|
||||
|
|
@ -3448,7 +3448,7 @@ impl<'a> Resolver<'a> {
|
|||
// all its imports in the usual way; this is because chains of
|
||||
// adjacent import statements are processed as though they mutated the
|
||||
// current scope.
|
||||
match module_.import_resolutions.borrow().find(&name) {
|
||||
match module_.import_resolutions.borrow().get(&name) {
|
||||
None => {
|
||||
// Not found; continue.
|
||||
}
|
||||
|
|
@ -3705,7 +3705,7 @@ impl<'a> Resolver<'a> {
|
|||
// First, check the direct children of the module.
|
||||
self.populate_module_if_necessary(&module_);
|
||||
|
||||
match module_.children.borrow().find(&name) {
|
||||
match module_.children.borrow().get(&name) {
|
||||
Some(name_bindings)
|
||||
if name_bindings.defined_in_namespace(namespace) => {
|
||||
debug!("(resolving name in module) found node as child");
|
||||
|
|
@ -3728,7 +3728,7 @@ impl<'a> Resolver<'a> {
|
|||
}
|
||||
|
||||
// Check the list of resolved imports.
|
||||
match module_.import_resolutions.borrow().find(&name) {
|
||||
match module_.import_resolutions.borrow().get(&name) {
|
||||
Some(import_resolution) if allow_private_imports ||
|
||||
import_resolution.is_public => {
|
||||
|
||||
|
|
@ -3967,7 +3967,7 @@ impl<'a> Resolver<'a> {
|
|||
Some(name) => {
|
||||
self.populate_module_if_necessary(&orig_module);
|
||||
|
||||
match orig_module.children.borrow().find(&name) {
|
||||
match orig_module.children.borrow().get(&name) {
|
||||
None => {
|
||||
debug!("!!! (with scope) didn't find `{}` in `{}`",
|
||||
token::get_name(name),
|
||||
|
|
@ -4523,41 +4523,6 @@ impl<'a> Resolver<'a> {
|
|||
TraitTyParamBound(ref tref) => {
|
||||
self.resolve_trait_reference(id, tref, reference_type)
|
||||
}
|
||||
UnboxedFnTyParamBound(ref unboxed_function) => {
|
||||
match self.resolve_path(unboxed_function.ref_id,
|
||||
&unboxed_function.path,
|
||||
TypeNS,
|
||||
true) {
|
||||
None => {
|
||||
let path_str = self.path_names_to_string(
|
||||
&unboxed_function.path);
|
||||
self.resolve_error(unboxed_function.path.span,
|
||||
format!("unresolved trait `{}`",
|
||||
path_str).as_slice())
|
||||
}
|
||||
Some(def) => {
|
||||
match def {
|
||||
(DefTrait(_), _) => {
|
||||
self.record_def(unboxed_function.ref_id, def);
|
||||
}
|
||||
_ => {
|
||||
let msg =
|
||||
format!("`{}` is not a trait",
|
||||
self.path_names_to_string(
|
||||
&unboxed_function.path));
|
||||
self.resolve_error(unboxed_function.path.span,
|
||||
msg.as_slice());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for argument in unboxed_function.decl.inputs.iter() {
|
||||
self.resolve_type(&*argument.ty);
|
||||
}
|
||||
|
||||
self.resolve_type(&*unboxed_function.decl.output);
|
||||
}
|
||||
RegionTyParamBound(..) => {}
|
||||
}
|
||||
}
|
||||
|
|
@ -4691,7 +4656,7 @@ impl<'a> Resolver<'a> {
|
|||
Some(ref trait_ref) => {
|
||||
self.resolve_trait_reference(id, trait_ref, TraitImplementation);
|
||||
|
||||
match self.def_map.borrow().find(&trait_ref.ref_id) {
|
||||
match self.def_map.borrow().get(&trait_ref.ref_id) {
|
||||
Some(def) => {
|
||||
let did = def.def_id();
|
||||
Some((did, trait_ref.clone()))
|
||||
|
|
@ -4767,7 +4732,7 @@ impl<'a> Resolver<'a> {
|
|||
// a type (shadowing any imported modules or types with this name), leading
|
||||
// to weird user-visible bugs. So we ward this off here. See #15060.
|
||||
TyPath(ref path, _, path_id) => {
|
||||
match self.def_map.borrow().find(&path_id) {
|
||||
match self.def_map.borrow().get(&path_id) {
|
||||
// FIXME: should we catch other options and give more precise errors?
|
||||
Some(&DefMod(_)) => {
|
||||
self.resolve_error(path.span, "inherent implementations are not \
|
||||
|
|
@ -4785,7 +4750,7 @@ impl<'a> Resolver<'a> {
|
|||
fn check_trait_item(&self, name: Name, span: Span) {
|
||||
// If there is a TraitRef in scope for an impl, then the method must be in the trait.
|
||||
for &(did, ref trait_ref) in self.current_trait_ref.iter() {
|
||||
if self.trait_item_map.find(&(name, did)).is_none() {
|
||||
if self.trait_item_map.get(&(name, did)).is_none() {
|
||||
let path_str = self.path_names_to_string(&trait_ref.path);
|
||||
self.resolve_error(span,
|
||||
format!("method `{}` is not a member of trait `{}`",
|
||||
|
|
@ -4849,7 +4814,7 @@ impl<'a> Resolver<'a> {
|
|||
let map_i = self.binding_mode_map(&**p);
|
||||
|
||||
for (&key, &binding_0) in map_0.iter() {
|
||||
match map_i.find(&key) {
|
||||
match map_i.get(&key) {
|
||||
None => {
|
||||
self.resolve_error(
|
||||
p.span,
|
||||
|
|
@ -4908,7 +4873,7 @@ impl<'a> Resolver<'a> {
|
|||
|
||||
// Move down in the graph, if there's an anonymous module rooted here.
|
||||
let orig_module = self.current_module.clone();
|
||||
match orig_module.anonymous_children.borrow().find(&block.id) {
|
||||
match orig_module.anonymous_children.borrow().get(&block.id) {
|
||||
None => { /* Nothing to do. */ }
|
||||
Some(anonymous_module) => {
|
||||
debug!("(resolving block) found anonymous module, moving \
|
||||
|
|
@ -4943,7 +4908,7 @@ impl<'a> Resolver<'a> {
|
|||
|
||||
match self.primitive_type_table
|
||||
.primitive_types
|
||||
.find(&id.name) {
|
||||
.get(&id.name) {
|
||||
|
||||
Some(&primitive_type) => {
|
||||
result_def =
|
||||
|
|
@ -4951,12 +4916,12 @@ impl<'a> Resolver<'a> {
|
|||
|
||||
if path.segments
|
||||
.iter()
|
||||
.any(|s| !s.lifetimes.is_empty()) {
|
||||
.any(|s| s.parameters.has_lifetimes()) {
|
||||
span_err!(self.session, path.span, E0157,
|
||||
"lifetime parameters are not allowed on this type");
|
||||
} else if path.segments
|
||||
.iter()
|
||||
.any(|s| s.types.len() > 0) {
|
||||
.any(|s| !s.parameters.is_empty()) {
|
||||
span_err!(self.session, path.span, E0153,
|
||||
"type parameters are not allowed on this type");
|
||||
}
|
||||
|
|
@ -5181,7 +5146,7 @@ impl<'a> Resolver<'a> {
|
|||
token::get_ident(
|
||||
ident))
|
||||
.as_slice())
|
||||
} else if bindings_list.find(&renamed) ==
|
||||
} else if bindings_list.get(&renamed) ==
|
||||
Some(&pat_id) {
|
||||
// Then this is a duplicate variable in the
|
||||
// same disjunction, which is an error.
|
||||
|
|
@ -5234,7 +5199,7 @@ impl<'a> Resolver<'a> {
|
|||
// Check the types in the path pattern.
|
||||
for ty in path.segments
|
||||
.iter()
|
||||
.flat_map(|s| s.types.iter()) {
|
||||
.flat_map(|s| s.parameters.types().into_iter()) {
|
||||
self.resolve_type(&**ty);
|
||||
}
|
||||
}
|
||||
|
|
@ -5340,7 +5305,7 @@ impl<'a> Resolver<'a> {
|
|||
namespace: Namespace,
|
||||
check_ribs: bool) -> Option<(Def, LastPrivate)> {
|
||||
// First, resolve the types.
|
||||
for ty in path.segments.iter().flat_map(|s| s.types.iter()) {
|
||||
for ty in path.segments.iter().flat_map(|s| s.parameters.types().into_iter()) {
|
||||
self.resolve_type(&**ty);
|
||||
}
|
||||
|
||||
|
|
@ -5407,7 +5372,7 @@ impl<'a> Resolver<'a> {
|
|||
// First, search children.
|
||||
self.populate_module_if_necessary(&containing_module);
|
||||
|
||||
match containing_module.children.borrow().find(&name) {
|
||||
match containing_module.children.borrow().get(&name) {
|
||||
Some(child_name_bindings) => {
|
||||
match child_name_bindings.def_for_namespace(namespace) {
|
||||
Some(def) => {
|
||||
|
|
@ -5426,7 +5391,7 @@ impl<'a> Resolver<'a> {
|
|||
}
|
||||
|
||||
// Next, search import resolutions.
|
||||
match containing_module.import_resolutions.borrow().find(&name) {
|
||||
match containing_module.import_resolutions.borrow().get(&name) {
|
||||
Some(import_resolution) if import_resolution.is_public => {
|
||||
match (*import_resolution).target_for_namespace(namespace) {
|
||||
Some(target) => {
|
||||
|
|
@ -5715,10 +5680,10 @@ impl<'a> Resolver<'a> {
|
|||
let last_name = name_path.last().unwrap();
|
||||
|
||||
if name_path.len() == 1 {
|
||||
match this.primitive_type_table.primitive_types.find(last_name) {
|
||||
match this.primitive_type_table.primitive_types.get(last_name) {
|
||||
Some(_) => None,
|
||||
None => {
|
||||
match this.current_module.children.borrow().find(last_name) {
|
||||
match this.current_module.children.borrow().get(last_name) {
|
||||
Some(child) => child.get_module_if_available(),
|
||||
None => None
|
||||
}
|
||||
|
|
@ -5746,10 +5711,10 @@ impl<'a> Resolver<'a> {
|
|||
|
||||
if allowed == Everything {
|
||||
// Look for a field with the same name in the current self_type.
|
||||
match self.def_map.borrow().find(&node_id) {
|
||||
match self.def_map.borrow().get(&node_id) {
|
||||
Some(&DefTy(did, _))
|
||||
| Some(&DefStruct(did))
|
||||
| Some(&DefVariant(_, did, _)) => match self.structs.find(&did) {
|
||||
| Some(&DefVariant(_, did, _)) => match self.structs.get(&did) {
|
||||
None => {}
|
||||
Some(fields) => {
|
||||
if fields.iter().any(|&field_name| name == field_name) {
|
||||
|
|
@ -5765,7 +5730,7 @@ impl<'a> Resolver<'a> {
|
|||
|
||||
// Look for a method in the current self type's impl module.
|
||||
match get_module(self, path.span, name_path.as_slice()) {
|
||||
Some(module) => match module.children.borrow().find(&name) {
|
||||
Some(module) => match module.children.borrow().get(&name) {
|
||||
Some(binding) => {
|
||||
let p_str = self.path_names_to_string(&path);
|
||||
match binding.def_for_namespace(ValueNS) {
|
||||
|
|
@ -5790,7 +5755,7 @@ impl<'a> Resolver<'a> {
|
|||
Some((did, ref trait_ref)) => {
|
||||
let path_str = self.path_names_to_string(&trait_ref.path);
|
||||
|
||||
match self.trait_item_map.find(&(name, did)) {
|
||||
match self.trait_item_map.get(&(name, did)) {
|
||||
Some(&StaticMethodTraitItemKind) => {
|
||||
return TraitMethod(path_str)
|
||||
}
|
||||
|
|
@ -6270,7 +6235,7 @@ impl<'a> Resolver<'a> {
|
|||
"unused import".to_string());
|
||||
}
|
||||
|
||||
let (v_priv, t_priv) = match self.last_private.find(&id) {
|
||||
let (v_priv, t_priv) = match self.last_private.get(&id) {
|
||||
Some(&LastImport {
|
||||
value_priv: v,
|
||||
value_used: _,
|
||||
|
|
|
|||
|
|
@ -204,9 +204,6 @@ impl<'a> LifetimeContext<'a> {
|
|||
ast::TraitTyParamBound(ref trait_ref) => {
|
||||
self.visit_trait_ref(trait_ref);
|
||||
}
|
||||
ast::UnboxedFnTyParamBound(ref fn_decl) => {
|
||||
self.visit_unboxed_fn_ty_param_bound(&**fn_decl);
|
||||
}
|
||||
ast::RegionTyParamBound(ref lifetime) => {
|
||||
self.visit_lifetime_ref(lifetime);
|
||||
}
|
||||
|
|
@ -226,18 +223,6 @@ impl<'a> LifetimeContext<'a> {
|
|||
})
|
||||
}
|
||||
|
||||
fn visit_unboxed_fn_ty_param_bound(&mut self,
|
||||
bound: &ast::UnboxedFnBound) {
|
||||
self.with(|scope, f| {
|
||||
f(LateScope(bound.ref_id, &bound.lifetimes, scope))
|
||||
}, |v| {
|
||||
for argument in bound.decl.inputs.iter() {
|
||||
v.visit_ty(&*argument.ty);
|
||||
}
|
||||
v.visit_ty(&*bound.decl.output);
|
||||
})
|
||||
}
|
||||
|
||||
/// Visits self by adding a scope and handling recursive walk over the contents with `walk`.
|
||||
fn visit_fn_decl(&mut self,
|
||||
n: ast::NodeId,
|
||||
|
|
|
|||
|
|
@ -705,7 +705,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
|
|||
ast::TraitTyParamBound(ref trait_ref) => {
|
||||
trait_ref
|
||||
}
|
||||
ast::UnboxedFnTyParamBound(..) | ast::RegionTyParamBound(..) => {
|
||||
ast::RegionTyParamBound(..) => {
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -906,7 +906,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
{
|
||||
let cache = self.pick_candidate_cache(&cache_skol_trait_ref);
|
||||
let hashmap = cache.hashmap.borrow();
|
||||
hashmap.find(&cache_skol_trait_ref).map(|c| (*c).clone())
|
||||
hashmap.get(&cache_skol_trait_ref).map(|c| (*c).clone())
|
||||
}
|
||||
|
||||
fn insert_candidate_cache(&mut self,
|
||||
|
|
@ -1032,7 +1032,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
self_ty.repr(self.tcx()),
|
||||
obligation.repr(self.tcx()));
|
||||
|
||||
let closure_kind = match self.typer.unboxed_closures().borrow().find(&closure_def_id) {
|
||||
let closure_kind = match self.typer.unboxed_closures().borrow().get(&closure_def_id) {
|
||||
Some(closure) => closure.kind,
|
||||
None => {
|
||||
self.tcx().sess.span_bug(
|
||||
|
|
@ -1282,7 +1282,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
|
||||
ty::BoundSync |
|
||||
ty::BoundSend => {
|
||||
if c.bounds.builtin_bounds.contains_elem(bound) {
|
||||
if c.bounds.builtin_bounds.contains(&bound) {
|
||||
Ok(If(Vec::new()))
|
||||
} else {
|
||||
Err(Unimplemented)
|
||||
|
|
@ -1306,7 +1306,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
|
||||
ty::BoundSync |
|
||||
ty::BoundSend => {
|
||||
if c.bounds.builtin_bounds.contains_elem(bound) {
|
||||
if c.bounds.builtin_bounds.contains(&bound) {
|
||||
Ok(If(Vec::new()))
|
||||
} else {
|
||||
Err(Unimplemented)
|
||||
|
|
@ -1323,7 +1323,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
Err(Unimplemented)
|
||||
}
|
||||
ty::BoundCopy | ty::BoundSync | ty::BoundSend => {
|
||||
if bounds.builtin_bounds.contains_elem(bound) {
|
||||
if bounds.builtin_bounds.contains(&bound) {
|
||||
Ok(If(Vec::new()))
|
||||
} else {
|
||||
Err(Unimplemented)
|
||||
|
|
@ -1428,7 +1428,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
// is reserve judgement and then intertwine this
|
||||
// analysis with closure inference.
|
||||
assert_eq!(def_id.krate, ast::LOCAL_CRATE);
|
||||
match self.tcx().freevars.borrow().find(&def_id.node) {
|
||||
match self.tcx().freevars.borrow().get(&def_id.node) {
|
||||
None => {
|
||||
// No upvars.
|
||||
Ok(If(Vec::new()))
|
||||
|
|
@ -1690,7 +1690,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
closure_def_id.repr(self.tcx()),
|
||||
substs.repr(self.tcx()));
|
||||
|
||||
let closure_type = match self.typer.unboxed_closures().borrow().find(&closure_def_id) {
|
||||
let closure_type = match self.typer.unboxed_closures().borrow().get(&closure_def_id) {
|
||||
Some(closure) => closure.closure_type.clone(),
|
||||
None => {
|
||||
self.tcx().sess.span_bug(
|
||||
|
|
@ -1973,7 +1973,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
|
||||
ty::populate_implementations_for_trait_if_necessary(self.tcx(),
|
||||
trait_def_id);
|
||||
match self.tcx().trait_impls.borrow().find(&trait_def_id) {
|
||||
match self.tcx().trait_impls.borrow().get(&trait_def_id) {
|
||||
None => Vec::new(),
|
||||
Some(impls) => impls.borrow().clone()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -696,13 +696,13 @@ fn any_irrefutable_adt_pat(tcx: &ty::ctxt, m: &[Match], col: uint) -> bool {
|
|||
match pat.node {
|
||||
ast::PatTup(_) => true,
|
||||
ast::PatStruct(..) => {
|
||||
match tcx.def_map.borrow().find(&pat.id) {
|
||||
match tcx.def_map.borrow().get(&pat.id) {
|
||||
Some(&def::DefVariant(..)) => false,
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
ast::PatEnum(..) | ast::PatIdent(_, _, None) => {
|
||||
match tcx.def_map.borrow().find(&pat.id) {
|
||||
match tcx.def_map.borrow().get(&pat.id) {
|
||||
Some(&def::DefStruct(..)) => true,
|
||||
_ => false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ use std::num::Int;
|
|||
use std::rc::Rc;
|
||||
|
||||
use llvm::{ValueRef, True, IntEQ, IntNE};
|
||||
use back::abi::slice_elt_base;
|
||||
use middle::subst;
|
||||
use middle::subst::Subst;
|
||||
use middle::trans::_match;
|
||||
|
|
@ -147,7 +148,7 @@ pub fn represent_node(bcx: Block, node: ast::NodeId) -> Rc<Repr> {
|
|||
/// Decides how to represent a given type.
|
||||
pub fn represent_type(cx: &CrateContext, t: ty::t) -> Rc<Repr> {
|
||||
debug!("Representing: {}", ty_to_string(cx.tcx(), t));
|
||||
match cx.adt_reprs().borrow().find(&t) {
|
||||
match cx.adt_reprs().borrow().get(&t) {
|
||||
Some(repr) => return repr.clone(),
|
||||
None => {}
|
||||
}
|
||||
|
|
@ -235,7 +236,7 @@ fn represent_type_uncached(cx: &CrateContext, t: ty::t) -> Repr {
|
|||
if cases[1 - discr].is_zerolen(cx, t) {
|
||||
let st = mk_struct(cx, cases[discr].tys.as_slice(),
|
||||
false, t);
|
||||
match cases[discr].find_ptr() {
|
||||
match cases[discr].find_ptr(cx) {
|
||||
Some(ThinPointer(_)) if st.fields.len() == 1 => {
|
||||
return RawNullablePointer {
|
||||
nndiscr: discr as Disr,
|
||||
|
|
@ -290,7 +291,7 @@ struct Case {
|
|||
#[deriving(Eq, PartialEq, Show)]
|
||||
pub enum PointerField {
|
||||
ThinPointer(uint),
|
||||
FatPointer(uint, uint)
|
||||
FatPointer(uint)
|
||||
}
|
||||
|
||||
impl Case {
|
||||
|
|
@ -298,31 +299,22 @@ impl Case {
|
|||
mk_struct(cx, self.tys.as_slice(), false, scapegoat).size == 0
|
||||
}
|
||||
|
||||
fn find_ptr(&self) -> Option<PointerField> {
|
||||
use back::abi::{fn_field_code, slice_elt_base, trt_field_box};
|
||||
|
||||
fn find_ptr(&self, cx: &CrateContext) -> Option<PointerField> {
|
||||
for (i, &ty) in self.tys.iter().enumerate() {
|
||||
match ty::get(ty).sty {
|
||||
// &T/&mut T could either be a thin or fat pointer depending on T
|
||||
ty::ty_rptr(_, ty::mt { ty, .. }) => match ty::get(ty).sty {
|
||||
// &T/&mut T/Box<T> could either be a thin or fat pointer depending on T
|
||||
ty::ty_rptr(_, ty::mt { ty, .. }) | ty::ty_uniq(ty) => match ty::get(ty).sty {
|
||||
// &[T] and &str are a pointer and length pair
|
||||
ty::ty_vec(_, None) | ty::ty_str => return Some(FatPointer(i, slice_elt_base)),
|
||||
ty::ty_vec(_, None) | ty::ty_str => return Some(FatPointer(i)),
|
||||
|
||||
// &Trait/&mut Trait are a pair of pointers: the actual object and a vtable
|
||||
ty::ty_trait(..) => return Some(FatPointer(i, trt_field_box)),
|
||||
// &Trait is a pair of pointers: the actual object and a vtable
|
||||
ty::ty_trait(..) => return Some(FatPointer(i)),
|
||||
|
||||
// Any other &T/&mut T is just a pointer
|
||||
_ => return Some(ThinPointer(i))
|
||||
},
|
||||
ty::ty_struct(..) if !ty::type_is_sized(cx.tcx(), ty) => {
|
||||
return Some(FatPointer(i))
|
||||
}
|
||||
|
||||
// Box<T> could either be a thin or fat pointer depending on T
|
||||
ty::ty_uniq(t) => match ty::get(t).sty {
|
||||
ty::ty_vec(_, None) => return Some(FatPointer(i, slice_elt_base)),
|
||||
|
||||
// Box<Trait> is a pair of pointers: the actual object and a vtable
|
||||
ty::ty_trait(..) => return Some(FatPointer(i, trt_field_box)),
|
||||
|
||||
// Any other Box<T> is just a pointer
|
||||
// Any other &T is just a pointer
|
||||
_ => return Some(ThinPointer(i))
|
||||
},
|
||||
|
||||
|
|
@ -330,7 +322,7 @@ impl Case {
|
|||
ty::ty_bare_fn(..) => return Some(ThinPointer(i)),
|
||||
|
||||
// Closures are a pair of pointers: the code and environment
|
||||
ty::ty_closure(..) => return Some(FatPointer(i, fn_field_code)),
|
||||
ty::ty_closure(..) => return Some(FatPointer(i)),
|
||||
|
||||
// Anything else is not a pointer
|
||||
_ => continue
|
||||
|
|
@ -636,6 +628,7 @@ pub fn trans_get_discr(bcx: Block, r: &Repr, scrutinee: ValueRef, cast_to: Optio
|
|||
-> ValueRef {
|
||||
let signed;
|
||||
let val;
|
||||
debug!("trans_get_discr r: {}", r);
|
||||
match *r {
|
||||
CEnum(ity, min, max) => {
|
||||
val = load_discr(bcx, ity, scrutinee, min, max);
|
||||
|
|
@ -671,7 +664,7 @@ fn struct_wrapped_nullable_bitdiscr(bcx: Block, nndiscr: Disr, ptrfield: Pointer
|
|||
scrutinee: ValueRef) -> ValueRef {
|
||||
let llptrptr = match ptrfield {
|
||||
ThinPointer(field) => GEPi(bcx, scrutinee, [0, field]),
|
||||
FatPointer(field, pair) => GEPi(bcx, scrutinee, [0, field, pair])
|
||||
FatPointer(field) => GEPi(bcx, scrutinee, [0, field, slice_elt_base])
|
||||
};
|
||||
let llptr = Load(bcx, llptrptr);
|
||||
let cmp = if nndiscr == 0 { IntEQ } else { IntNE };
|
||||
|
|
@ -767,8 +760,8 @@ pub fn trans_set_discr(bcx: Block, r: &Repr, val: ValueRef, discr: Disr) {
|
|||
ThinPointer(field) =>
|
||||
(GEPi(bcx, val, [0, field]),
|
||||
type_of::type_of(bcx.ccx(), nonnull.fields[field])),
|
||||
FatPointer(field, pair) => {
|
||||
let v = GEPi(bcx, val, [0, field, pair]);
|
||||
FatPointer(field) => {
|
||||
let v = GEPi(bcx, val, [0, field, slice_elt_base]);
|
||||
(v, val_ty(v).element_type())
|
||||
}
|
||||
};
|
||||
|
|
@ -1102,7 +1095,7 @@ pub fn const_get_discrim(ccx: &CrateContext, r: &Repr, val: ValueRef)
|
|||
StructWrappedNullablePointer { nndiscr, ptrfield, .. } => {
|
||||
let (idx, sub_idx) = match ptrfield {
|
||||
ThinPointer(field) => (field, None),
|
||||
FatPointer(field, pair) => (field, Some(pair))
|
||||
FatPointer(field) => (field, Some(slice_elt_base))
|
||||
};
|
||||
if is_null(const_struct_field(ccx, val, idx, sub_idx)) {
|
||||
/* subtraction as uint is ok because nndiscr is either 0 or 1 */
|
||||
|
|
|
|||
|
|
@ -316,7 +316,7 @@ pub fn get_extern_const(ccx: &CrateContext, did: ast::DefId,
|
|||
t: ty::t) -> ValueRef {
|
||||
let name = csearch::get_symbol(&ccx.sess().cstore, did);
|
||||
let ty = type_of(ccx, t);
|
||||
match ccx.externs().borrow_mut().find(&name) {
|
||||
match ccx.externs().borrow_mut().get(&name) {
|
||||
Some(n) => return *n,
|
||||
None => ()
|
||||
}
|
||||
|
|
@ -409,7 +409,7 @@ pub fn malloc_raw_dyn_proc<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, t: ty::t) -> Resu
|
|||
// Type descriptor and type glue stuff
|
||||
|
||||
pub fn get_tydesc(ccx: &CrateContext, t: ty::t) -> Rc<tydesc_info> {
|
||||
match ccx.tydescs().borrow().find(&t) {
|
||||
match ccx.tydescs().borrow().get(&t) {
|
||||
Some(inf) => return inf.clone(),
|
||||
_ => { }
|
||||
}
|
||||
|
|
@ -1836,11 +1836,7 @@ pub fn trans_closure(ccx: &CrateContext,
|
|||
NotUnboxedClosure => monomorphized_arg_types,
|
||||
|
||||
// Tuple up closure argument types for the "rust-call" ABI.
|
||||
IsUnboxedClosure => vec![if monomorphized_arg_types.is_empty() {
|
||||
ty::mk_nil()
|
||||
} else {
|
||||
ty::mk_tup(ccx.tcx(), monomorphized_arg_types)
|
||||
}]
|
||||
IsUnboxedClosure => vec![ty::mk_tup_or_nil(ccx.tcx(), monomorphized_arg_types)]
|
||||
};
|
||||
for monomorphized_arg_type in monomorphized_arg_types.iter() {
|
||||
debug!("trans_closure: monomorphized_arg_type: {}",
|
||||
|
|
@ -2100,7 +2096,7 @@ fn enum_variant_size_lint(ccx: &CrateContext, enum_def: &ast::EnumDef, sp: Span,
|
|||
|
||||
let levels = ccx.tcx().node_lint_levels.borrow();
|
||||
let lint_id = lint::LintId::of(lint::builtin::VARIANT_SIZE_DIFFERENCES);
|
||||
let lvlsrc = match levels.find(&(id, lint_id)) {
|
||||
let lvlsrc = match levels.get(&(id, lint_id)) {
|
||||
None | Some(&(lint::Allow, _)) => return,
|
||||
Some(&lvlsrc) => lvlsrc,
|
||||
};
|
||||
|
|
@ -2645,7 +2641,7 @@ pub fn create_entry_wrapper(ccx: &CrateContext,
|
|||
|
||||
fn exported_name(ccx: &CrateContext, id: ast::NodeId,
|
||||
ty: ty::t, attrs: &[ast::Attribute]) -> String {
|
||||
match ccx.external_srcs().borrow().find(&id) {
|
||||
match ccx.external_srcs().borrow().get(&id) {
|
||||
Some(&did) => {
|
||||
let sym = csearch::get_symbol(&ccx.sess().cstore, did);
|
||||
debug!("found item {} in other crate...", sym);
|
||||
|
|
@ -3123,7 +3119,7 @@ pub fn trans_crate<'tcx>(analysis: CrateAnalysis<'tcx>)
|
|||
.collect();
|
||||
|
||||
let mut reachable: Vec<String> = shared_ccx.reachable().iter().filter_map(|id| {
|
||||
shared_ccx.item_symbols().borrow().find(id).map(|s| s.to_string())
|
||||
shared_ccx.item_symbols().borrow().get(id).map(|s| s.to_string())
|
||||
}).collect();
|
||||
|
||||
// For the purposes of LTO, we add to the reachable set all of the upstream
|
||||
|
|
|
|||
|
|
@ -655,7 +655,7 @@ pub fn _UndefReturn(cx: Block, fn_: ValueRef) -> ValueRef {
|
|||
unsafe {
|
||||
let ccx = cx.fcx.ccx;
|
||||
let ty = val_ty(fn_);
|
||||
let retty = if ty.kind() == llvm::Integer {
|
||||
let retty = if ty.kind() == llvm::Function {
|
||||
ty.return_type()
|
||||
} else {
|
||||
ccx.int_type()
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
s.push('/');
|
||||
s.push_str(category);
|
||||
|
||||
let n = match h.find(&s) {
|
||||
let n = match h.get(&s) {
|
||||
Some(&n) => n,
|
||||
_ => 0u
|
||||
};
|
||||
|
|
|
|||
|
|
@ -438,7 +438,7 @@ pub fn get_or_create_declaration_if_unboxed_closure<'blk, 'tcx>(bcx: Block<'blk,
|
|||
params: params
|
||||
};
|
||||
|
||||
match ccx.unboxed_closure_vals().borrow().find(&mono_id) {
|
||||
match ccx.unboxed_closure_vals().borrow().get(&mono_id) {
|
||||
Some(llfn) => {
|
||||
debug!("get_or_create_declaration_if_unboxed_closure(): found \
|
||||
closure");
|
||||
|
|
@ -564,7 +564,7 @@ pub fn get_wrapper_for_bare_fn(ccx: &CrateContext,
|
|||
}
|
||||
};
|
||||
|
||||
match ccx.closure_bare_wrapper_cache().borrow().find(&fn_ptr) {
|
||||
match ccx.closure_bare_wrapper_cache().borrow().get(&fn_ptr) {
|
||||
Some(&llval) => return llval,
|
||||
None => {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -466,7 +466,7 @@ impl<'blk, 'tcx> BlockS<'blk, 'tcx> {
|
|||
}
|
||||
|
||||
pub fn def(&self, nid: ast::NodeId) -> def::Def {
|
||||
match self.tcx().def_map.borrow().find(&nid) {
|
||||
match self.tcx().def_map.borrow().get(&nid) {
|
||||
Some(v) => v.clone(),
|
||||
None => {
|
||||
self.tcx().sess.bug(format!(
|
||||
|
|
@ -505,7 +505,7 @@ impl<'blk, 'tcx> mc::Typer<'tcx> for BlockS<'blk, 'tcx> {
|
|||
self.tcx()
|
||||
.method_map
|
||||
.borrow()
|
||||
.find(&method_call)
|
||||
.get(&method_call)
|
||||
.map(|method| monomorphize_type(self, method.ty))
|
||||
}
|
||||
|
||||
|
|
@ -647,7 +647,7 @@ pub fn C_u8(ccx: &CrateContext, i: uint) -> ValueRef {
|
|||
// our boxed-and-length-annotated strings.
|
||||
pub fn C_cstr(cx: &CrateContext, s: InternedString, null_terminated: bool) -> ValueRef {
|
||||
unsafe {
|
||||
match cx.const_cstr_cache().borrow().find(&s) {
|
||||
match cx.const_cstr_cache().borrow().get(&s) {
|
||||
Some(&llval) => return llval,
|
||||
None => ()
|
||||
}
|
||||
|
|
@ -813,7 +813,7 @@ pub fn fulfill_obligation(ccx: &CrateContext,
|
|||
let trait_ref = ty_fold::erase_regions(tcx, trait_ref);
|
||||
|
||||
// First check the cache.
|
||||
match ccx.trait_cache().borrow().find(&trait_ref) {
|
||||
match ccx.trait_cache().borrow().get(&trait_ref) {
|
||||
Some(vtable) => {
|
||||
info!("Cache hit: {}", trait_ref.repr(ccx.tcx()));
|
||||
return (*vtable).clone();
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ pub fn const_lit(cx: &CrateContext, e: &ast::Expr, lit: &ast::Lit)
|
|||
pub fn const_ptrcast(cx: &CrateContext, a: ValueRef, t: Type) -> ValueRef {
|
||||
unsafe {
|
||||
let b = llvm::LLVMConstPointerCast(a, t.ptr_to().to_ref());
|
||||
assert!(cx.const_globals().borrow_mut().insert(b as int, a));
|
||||
assert!(cx.const_globals().borrow_mut().insert(b as int, a).is_none());
|
||||
b
|
||||
}
|
||||
}
|
||||
|
|
@ -125,7 +125,7 @@ pub fn const_addr_of(cx: &CrateContext, cv: ValueRef, mutbl: ast::Mutability) ->
|
|||
}
|
||||
|
||||
fn const_deref_ptr(cx: &CrateContext, v: ValueRef) -> ValueRef {
|
||||
let v = match cx.const_globals().borrow().find(&(v as int)) {
|
||||
let v = match cx.const_globals().borrow().get(&(v as int)) {
|
||||
Some(&v) => v,
|
||||
None => v
|
||||
};
|
||||
|
|
@ -625,7 +625,7 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr) -> ValueRef {
|
|||
}
|
||||
ast::ExprPath(ref pth) => {
|
||||
// Assert that there are no type parameters in this path.
|
||||
assert!(pth.segments.iter().all(|seg| seg.types.is_empty()));
|
||||
assert!(pth.segments.iter().all(|seg| !seg.parameters.has_types()));
|
||||
|
||||
let opt_def = cx.tcx().def_map.borrow().find_copy(&e.id);
|
||||
match opt_def {
|
||||
|
|
|
|||
|
|
@ -421,7 +421,7 @@ pub fn trans_break_cont<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
let loop_id = match opt_label {
|
||||
None => fcx.top_loop_scope(),
|
||||
Some(_) => {
|
||||
match bcx.tcx().def_map.borrow().find(&expr_id) {
|
||||
match bcx.tcx().def_map.borrow().get(&expr_id) {
|
||||
Some(&def::DefLabel(loop_id)) => loop_id,
|
||||
ref r => {
|
||||
bcx.tcx().sess.bug(format!("{} in def-map for label",
|
||||
|
|
|
|||
|
|
@ -282,7 +282,7 @@ impl TypeMap {
|
|||
cx: &CrateContext,
|
||||
type_: ty::t,
|
||||
metadata: DIType) {
|
||||
if !self.type_to_metadata.insert(ty::type_id(type_), metadata) {
|
||||
if self.type_to_metadata.insert(ty::type_id(type_), metadata).is_some() {
|
||||
cx.sess().bug(format!("Type metadata for ty::t '{}' is already in the TypeMap!",
|
||||
ppaux::ty_to_string(cx.tcx(), type_)).as_slice());
|
||||
}
|
||||
|
|
@ -294,7 +294,7 @@ impl TypeMap {
|
|||
cx: &CrateContext,
|
||||
unique_type_id: UniqueTypeId,
|
||||
metadata: DIType) {
|
||||
if !self.unique_id_to_metadata.insert(unique_type_id, metadata) {
|
||||
if self.unique_id_to_metadata.insert(unique_type_id, metadata).is_some() {
|
||||
let unique_type_id_str = self.get_unique_type_id_as_string(unique_type_id);
|
||||
cx.sess().bug(format!("Type metadata for unique id '{}' is already in the TypeMap!",
|
||||
unique_type_id_str.as_slice()).as_slice());
|
||||
|
|
@ -468,7 +468,7 @@ impl TypeMap {
|
|||
},
|
||||
ty::ty_unboxed_closure(ref def_id, _, ref substs) => {
|
||||
let closure_ty = cx.tcx().unboxed_closures.borrow()
|
||||
.find(def_id).unwrap().closure_type.subst(cx.tcx(), substs);
|
||||
.get(def_id).unwrap().closure_type.subst(cx.tcx(), substs);
|
||||
self.get_unique_type_id_of_closure_type(cx,
|
||||
closure_ty,
|
||||
&mut unique_type_id);
|
||||
|
|
@ -2255,7 +2255,7 @@ impl EnumMemberDescriptionFactory {
|
|||
let null_variant_name = token::get_name((*self.variants)[null_variant_index].name);
|
||||
let discrfield = match ptrfield {
|
||||
adt::ThinPointer(field) => format!("{}", field),
|
||||
adt::FatPointer(field, pair) => format!("{}${}", field, pair)
|
||||
adt::FatPointer(field) => format!("{}", field)
|
||||
};
|
||||
let union_member_name = format!("RUST$ENCODED$ENUM${}${}",
|
||||
discrfield,
|
||||
|
|
@ -2939,7 +2939,7 @@ fn type_metadata(cx: &CrateContext,
|
|||
}
|
||||
ty::ty_unboxed_closure(ref def_id, _, ref substs) => {
|
||||
let sig = cx.tcx().unboxed_closures.borrow()
|
||||
.find(def_id).unwrap().closure_type.sig.subst(cx.tcx(), substs);
|
||||
.get(def_id).unwrap().closure_type.sig.subst(cx.tcx(), substs);
|
||||
subroutine_type_metadata(cx, unique_type_id, &sig, usage_site_span)
|
||||
}
|
||||
ty::ty_struct(def_id, ref substs) => {
|
||||
|
|
|
|||
|
|
@ -212,7 +212,7 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
// Don't skip a conversion from Box<T> to &T, etc.
|
||||
ty::ty_rptr(..) => {
|
||||
let method_call = MethodCall::autoderef(expr.id, adj.autoderefs-1);
|
||||
let method = bcx.tcx().method_map.borrow().find(&method_call).is_some();
|
||||
let method = bcx.tcx().method_map.borrow().get(&method_call).is_some();
|
||||
if method {
|
||||
// Don't skip an overloaded deref.
|
||||
(adj.autoderefs, true)
|
||||
|
|
@ -601,7 +601,7 @@ fn trans_datum_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
let method_ty = ccx.tcx()
|
||||
.method_map
|
||||
.borrow()
|
||||
.find(&method_call)
|
||||
.get(&method_call)
|
||||
.map(|method| method.ty);
|
||||
let base_datum = unpack_datum!(bcx, trans(bcx, &**base));
|
||||
|
||||
|
|
@ -736,7 +736,7 @@ fn trans_index<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
let method_ty = ccx.tcx()
|
||||
.method_map
|
||||
.borrow()
|
||||
.find(&method_call)
|
||||
.get(&method_call)
|
||||
.map(|method| method.ty);
|
||||
let elt_datum = match method_ty {
|
||||
Some(method_ty) => {
|
||||
|
|
@ -1114,7 +1114,7 @@ fn trans_rvalue_dps_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
if ty::type_is_trait(node_id_type(bcx, expr.id)) {
|
||||
let trait_ref =
|
||||
bcx.tcx().object_cast_map.borrow()
|
||||
.find(&expr.id)
|
||||
.get(&expr.id)
|
||||
.map(|t| (*t).clone())
|
||||
.unwrap();
|
||||
let trait_ref =
|
||||
|
|
@ -1232,7 +1232,7 @@ pub fn trans_local_var<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
def::DefUpvar(nid, _, _) => {
|
||||
// Can't move upvars, so this is never a ZeroMemLastUse.
|
||||
let local_ty = node_id_type(bcx, nid);
|
||||
match bcx.fcx.llupvars.borrow().find(&nid) {
|
||||
match bcx.fcx.llupvars.borrow().get(&nid) {
|
||||
Some(&val) => Datum::new(val, local_ty, Lvalue),
|
||||
None => {
|
||||
bcx.sess().bug(format!(
|
||||
|
|
@ -1242,7 +1242,7 @@ pub fn trans_local_var<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
}
|
||||
}
|
||||
def::DefLocal(nid) => {
|
||||
let datum = match bcx.fcx.lllocals.borrow().find(&nid) {
|
||||
let datum = match bcx.fcx.lllocals.borrow().get(&nid) {
|
||||
Some(&v) => v,
|
||||
None => {
|
||||
bcx.sess().bug(format!(
|
||||
|
|
@ -1461,14 +1461,35 @@ pub fn trans_adt<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
|
|||
None => {}
|
||||
};
|
||||
|
||||
// Now, we just overwrite the fields we've explicitly specified
|
||||
for &(i, ref e) in fields.iter() {
|
||||
let dest = adt::trans_field_ptr(bcx, &*repr, addr, discr, i);
|
||||
let e_ty = expr_ty_adjusted(bcx, &**e);
|
||||
bcx = trans_into(bcx, &**e, SaveIn(dest));
|
||||
let scope = cleanup::CustomScope(custom_cleanup_scope);
|
||||
fcx.schedule_lifetime_end(scope, dest);
|
||||
fcx.schedule_drop_mem(scope, dest, e_ty);
|
||||
if ty::type_is_simd(bcx.tcx(), ty) {
|
||||
// This is the constructor of a SIMD type, such types are
|
||||
// always primitive machine types and so do not have a
|
||||
// destructor or require any clean-up.
|
||||
let llty = type_of::type_of(bcx.ccx(), ty);
|
||||
|
||||
// keep a vector as a register, and running through the field
|
||||
// `insertelement`ing them directly into that register
|
||||
// (i.e. avoid GEPi and `store`s to an alloca) .
|
||||
let mut vec_val = C_undef(llty);
|
||||
|
||||
for &(i, ref e) in fields.iter() {
|
||||
let block_datum = trans(bcx, &**e);
|
||||
bcx = block_datum.bcx;
|
||||
let position = C_uint(bcx.ccx(), i);
|
||||
let value = block_datum.datum.to_llscalarish(bcx);
|
||||
vec_val = InsertElement(bcx, vec_val, value, position);
|
||||
}
|
||||
Store(bcx, vec_val, addr);
|
||||
} else {
|
||||
// Now, we just overwrite the fields we've explicitly specified
|
||||
for &(i, ref e) in fields.iter() {
|
||||
let dest = adt::trans_field_ptr(bcx, &*repr, addr, discr, i);
|
||||
let e_ty = expr_ty_adjusted(bcx, &**e);
|
||||
bcx = trans_into(bcx, &**e, SaveIn(dest));
|
||||
let scope = cleanup::CustomScope(custom_cleanup_scope);
|
||||
fcx.schedule_lifetime_end(scope, dest);
|
||||
fcx.schedule_drop_mem(scope, dest, e_ty);
|
||||
}
|
||||
}
|
||||
|
||||
adt::trans_set_discr(bcx, &*repr, addr, discr);
|
||||
|
|
@ -2089,7 +2110,7 @@ fn deref_once<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
|
||||
// Check for overloaded deref.
|
||||
let method_ty = ccx.tcx().method_map.borrow()
|
||||
.find(&method_call).map(|method| method.ty);
|
||||
.get(&method_call).map(|method| method.ty);
|
||||
let datum = match method_ty {
|
||||
Some(method_ty) => {
|
||||
// Overloaded. Evaluate `trans_overloaded_op`, which will
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ pub fn get_drop_glue(ccx: &CrateContext, t: ty::t) -> ValueRef {
|
|||
debug!("make drop glue for {}", ppaux::ty_to_string(ccx.tcx(), t));
|
||||
let t = get_drop_glue_type(ccx, t);
|
||||
debug!("drop glue type {}", ppaux::ty_to_string(ccx.tcx(), t));
|
||||
match ccx.drop_glues().borrow().find(&t) {
|
||||
match ccx.drop_glues().borrow().get(&t) {
|
||||
Some(&glue) => return glue,
|
||||
_ => { }
|
||||
}
|
||||
|
|
@ -157,7 +157,7 @@ pub fn get_drop_glue(ccx: &CrateContext, t: ty::t) -> ValueRef {
|
|||
|
||||
let llfnty = Type::glue_fn(ccx, llty);
|
||||
|
||||
let (glue, new_sym) = match ccx.available_drop_glues().borrow().find(&t) {
|
||||
let (glue, new_sym) = match ccx.available_drop_glues().borrow().get(&t) {
|
||||
Some(old_sym) => {
|
||||
let glue = decl_cdecl_fn(ccx, old_sym.as_slice(), llfnty, ty::mk_nil());
|
||||
(glue, None)
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ use syntax::ast_util::{local_def, PostExpansionMethod};
|
|||
fn instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId)
|
||||
-> Option<ast::DefId> {
|
||||
let _icx = push_ctxt("maybe_instantiate_inline");
|
||||
match ccx.external().borrow().find(&fn_id) {
|
||||
match ccx.external().borrow().get(&fn_id) {
|
||||
Some(&Some(node_id)) => {
|
||||
// Already inline
|
||||
debug!("maybe_instantiate_inline({}): already inline as node id {}",
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ pub fn trans_method_callee<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
let (origin, method_ty) =
|
||||
bcx.tcx().method_map
|
||||
.borrow()
|
||||
.find(&method_call)
|
||||
.get(&method_call)
|
||||
.map(|method| (method.origin.clone(), method.ty))
|
||||
.unwrap();
|
||||
|
||||
|
|
@ -308,7 +308,7 @@ fn method_with_name(ccx: &CrateContext, impl_id: ast::DefId, name: ast::Name)
|
|||
|
||||
let impl_items = ccx.tcx().impl_items.borrow();
|
||||
let impl_items =
|
||||
impl_items.find(&impl_id)
|
||||
impl_items.get(&impl_id)
|
||||
.expect("could not find impl while translating");
|
||||
let meth_did = impl_items.iter()
|
||||
.find(|&did| {
|
||||
|
|
@ -559,7 +559,7 @@ pub fn get_vtable(bcx: Block,
|
|||
|
||||
// Check the cache.
|
||||
let cache_key = (box_ty, trait_ref.clone());
|
||||
match ccx.vtables().borrow().find(&cache_key) {
|
||||
match ccx.vtables().borrow().get(&cache_key) {
|
||||
Some(&val) => { return val }
|
||||
None => { }
|
||||
}
|
||||
|
|
@ -599,7 +599,7 @@ pub fn get_vtable(bcx: Block,
|
|||
.unboxed_closures
|
||||
.borrow();
|
||||
let closure_info =
|
||||
unboxed_closures.find(&closure_def_id)
|
||||
unboxed_closures.get(&closure_def_id)
|
||||
.expect("get_vtable(): didn't find \
|
||||
unboxed closure");
|
||||
if closure_info.kind == ty::FnOnceUnboxedClosureKind {
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,
|
|||
params: real_substs.types.clone()
|
||||
};
|
||||
|
||||
match ccx.monomorphized().borrow().find(&hash_id) {
|
||||
match ccx.monomorphized().borrow().get(&hash_id) {
|
||||
Some(&val) => {
|
||||
debug!("leaving monomorphic fn {}",
|
||||
ty::item_path_str(ccx.tcx(), fn_id));
|
||||
|
|
@ -106,7 +106,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,
|
|||
let depth;
|
||||
{
|
||||
let mut monomorphizing = ccx.monomorphizing().borrow_mut();
|
||||
depth = match monomorphizing.find(&fn_id) {
|
||||
depth = match monomorphizing.get(&fn_id) {
|
||||
Some(&d) => d, None => 0
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -332,7 +332,7 @@ impl TypeNames {
|
|||
|
||||
pub fn associate_type(&self, s: &str, t: &Type) {
|
||||
assert!(self.named_types.borrow_mut().insert(s.to_string(),
|
||||
t.to_ref()));
|
||||
t.to_ref()).is_none());
|
||||
}
|
||||
|
||||
pub fn find_type(&self, s: &str) -> Option<Type> {
|
||||
|
|
|
|||
|
|
@ -272,7 +272,7 @@ pub fn type_of(cx: &CrateContext, t: ty::t) -> Type {
|
|||
}
|
||||
|
||||
// Check the cache.
|
||||
match cx.lltypes().borrow().find(&t) {
|
||||
match cx.lltypes().borrow().get(&t) {
|
||||
Some(&llty) => return llty,
|
||||
None => ()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1080,14 +1080,14 @@ pub enum BuiltinBound {
|
|||
}
|
||||
|
||||
pub fn empty_builtin_bounds() -> BuiltinBounds {
|
||||
EnumSet::empty()
|
||||
EnumSet::new()
|
||||
}
|
||||
|
||||
pub fn all_builtin_bounds() -> BuiltinBounds {
|
||||
let mut set = EnumSet::empty();
|
||||
set.add(BoundSend);
|
||||
set.add(BoundSized);
|
||||
set.add(BoundSync);
|
||||
let mut set = EnumSet::new();
|
||||
set.insert(BoundSend);
|
||||
set.insert(BoundSized);
|
||||
set.insert(BoundSync);
|
||||
set
|
||||
}
|
||||
|
||||
|
|
@ -1584,7 +1584,7 @@ pub fn mk_t(cx: &ctxt, st: sty) -> t {
|
|||
|
||||
let key = intern_key { sty: &st };
|
||||
|
||||
match cx.interner.borrow().find(&key) {
|
||||
match cx.interner.borrow().get(&key) {
|
||||
Some(t) => unsafe { return mem::transmute(&t.sty); },
|
||||
_ => ()
|
||||
}
|
||||
|
|
@ -1838,6 +1838,14 @@ pub fn mk_slice(cx: &ctxt, r: Region, tm: mt) -> t {
|
|||
|
||||
pub fn mk_tup(cx: &ctxt, ts: Vec<t>) -> t { mk_t(cx, ty_tup(ts)) }
|
||||
|
||||
pub fn mk_tup_or_nil(cx: &ctxt, ts: Vec<t>) -> t {
|
||||
if ts.len() == 0 {
|
||||
ty::mk_nil()
|
||||
} else {
|
||||
mk_t(cx, ty_tup(ts))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mk_closure(cx: &ctxt, fty: ClosureTy) -> t {
|
||||
mk_t(cx, ty_closure(box fty))
|
||||
}
|
||||
|
|
@ -2418,11 +2426,11 @@ pub fn type_contents(cx: &ctxt, ty: t) -> TypeContents {
|
|||
// value for the type contents of list. The correct value is
|
||||
// TC::OwnsOwned. This manifested as issue #4821.
|
||||
let ty_id = type_id(ty);
|
||||
match cache.find(&ty_id) {
|
||||
match cache.get(&ty_id) {
|
||||
Some(tc) => { return *tc; }
|
||||
None => {}
|
||||
}
|
||||
match cx.tc_cache.borrow().find(&ty_id) { // Must check both caches!
|
||||
match cx.tc_cache.borrow().get(&ty_id) { // Must check both caches!
|
||||
Some(tc) => { return *tc; }
|
||||
None => {}
|
||||
}
|
||||
|
|
@ -3192,7 +3200,7 @@ pub fn array_element_ty(t: t) -> Option<t> {
|
|||
}
|
||||
|
||||
pub fn node_id_to_trait_ref(cx: &ctxt, id: ast::NodeId) -> Rc<ty::TraitRef> {
|
||||
match cx.trait_refs.borrow().find(&id) {
|
||||
match cx.trait_refs.borrow().get(&id) {
|
||||
Some(t) => t.clone(),
|
||||
None => cx.sess.bug(
|
||||
format!("node_id_to_trait_ref: no trait ref for node `{}`",
|
||||
|
|
@ -3214,14 +3222,14 @@ pub fn node_id_to_type(cx: &ctxt, id: ast::NodeId) -> t {
|
|||
}
|
||||
|
||||
pub fn node_id_to_type_opt(cx: &ctxt, id: ast::NodeId) -> Option<t> {
|
||||
match cx.node_types.borrow().find(&(id as uint)) {
|
||||
match cx.node_types.borrow().get(&(id as uint)) {
|
||||
Some(&t) => Some(t),
|
||||
None => None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn node_id_item_substs(cx: &ctxt, id: ast::NodeId) -> ItemSubsts {
|
||||
match cx.item_substs.borrow().find(&id) {
|
||||
match cx.item_substs.borrow().get(&id) {
|
||||
None => ItemSubsts::empty(),
|
||||
Some(ts) => ts.clone(),
|
||||
}
|
||||
|
|
@ -3361,8 +3369,8 @@ pub fn expr_ty_adjusted(cx: &ctxt, expr: &ast::Expr) -> t {
|
|||
*/
|
||||
|
||||
adjust_ty(cx, expr.span, expr.id, expr_ty(cx, expr),
|
||||
cx.adjustments.borrow().find(&expr.id),
|
||||
|method_call| cx.method_map.borrow().find(&method_call).map(|method| method.ty))
|
||||
cx.adjustments.borrow().get(&expr.id),
|
||||
|method_call| cx.method_map.borrow().get(&method_call).map(|method| method.ty))
|
||||
}
|
||||
|
||||
pub fn expr_span(cx: &ctxt, id: NodeId) -> Span {
|
||||
|
|
@ -3553,7 +3561,7 @@ pub fn unsize_ty(cx: &ctxt,
|
|||
}
|
||||
|
||||
pub fn resolve_expr(tcx: &ctxt, expr: &ast::Expr) -> def::Def {
|
||||
match tcx.def_map.borrow().find(&expr.id) {
|
||||
match tcx.def_map.borrow().get(&expr.id) {
|
||||
Some(&def) => def,
|
||||
None => {
|
||||
tcx.sess.span_bug(expr.span, format!(
|
||||
|
|
@ -3690,7 +3698,7 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind {
|
|||
}
|
||||
|
||||
ast::ExprCast(..) => {
|
||||
match tcx.node_types.borrow().find(&(expr.id as uint)) {
|
||||
match tcx.node_types.borrow().get(&(expr.id as uint)) {
|
||||
Some(&t) => {
|
||||
if type_is_trait(t) {
|
||||
RvalueDpsExpr
|
||||
|
|
@ -3736,7 +3744,7 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind {
|
|||
|
||||
ast::ExprBox(ref place, _) => {
|
||||
// Special case `Box<T>` for now:
|
||||
let definition = match tcx.def_map.borrow().find(&place.id) {
|
||||
let definition = match tcx.def_map.borrow().get(&place.id) {
|
||||
Some(&def) => def,
|
||||
None => panic!("no def for place"),
|
||||
};
|
||||
|
|
@ -4003,7 +4011,7 @@ pub fn note_and_explain_type_err(cx: &ctxt, err: &type_err) {
|
|||
}
|
||||
|
||||
pub fn provided_source(cx: &ctxt, id: ast::DefId) -> Option<ast::DefId> {
|
||||
cx.provided_method_sources.borrow().find(&id).map(|x| *x)
|
||||
cx.provided_method_sources.borrow().get(&id).map(|x| *x)
|
||||
}
|
||||
|
||||
pub fn provided_trait_methods(cx: &ctxt, id: ast::DefId) -> Vec<Rc<Method>> {
|
||||
|
|
@ -4113,7 +4121,7 @@ pub fn impl_or_trait_item(cx: &ctxt, id: ast::DefId) -> ImplOrTraitItem {
|
|||
pub fn is_associated_type(cx: &ctxt, id: ast::DefId) -> bool {
|
||||
memoized(&cx.associated_types, id, |id: ast::DefId| {
|
||||
if id.krate == ast::LOCAL_CRATE {
|
||||
match cx.impl_or_trait_items.borrow().find(&id) {
|
||||
match cx.impl_or_trait_items.borrow().get(&id) {
|
||||
Some(ref item) => {
|
||||
match **item {
|
||||
TypeTraitItem(_) => true,
|
||||
|
|
@ -4198,7 +4206,7 @@ pub fn impl_trait_ref(cx: &ctxt, id: ast::DefId) -> Option<Rc<TraitRef>> {
|
|||
|
||||
pub fn trait_ref_to_def_id(tcx: &ctxt, tr: &ast::TraitRef) -> ast::DefId {
|
||||
let def = *tcx.def_map.borrow()
|
||||
.find(&tr.ref_id)
|
||||
.get(&tr.ref_id)
|
||||
.expect("no def-map entry for trait");
|
||||
def.def_id()
|
||||
}
|
||||
|
|
@ -4215,7 +4223,7 @@ pub fn try_add_builtin_trait(
|
|||
//! is a builtin trait.
|
||||
|
||||
match tcx.lang_items.to_builtin_kind(trait_def_id) {
|
||||
Some(bound) => { builtin_bounds.add(bound); true }
|
||||
Some(bound) => { builtin_bounds.insert(bound); true }
|
||||
None => false
|
||||
}
|
||||
}
|
||||
|
|
@ -4346,7 +4354,7 @@ impl DtorKind {
|
|||
/* If struct_id names a struct with a dtor, return Some(the dtor's id).
|
||||
Otherwise return none. */
|
||||
pub fn ty_dtor(cx: &ctxt, struct_id: DefId) -> DtorKind {
|
||||
match cx.destructor_for_type.borrow().find(&struct_id) {
|
||||
match cx.destructor_for_type.borrow().get(&struct_id) {
|
||||
Some(&method_def_id) => {
|
||||
let flag = !has_attr(cx, struct_id, "unsafe_no_drop_flag");
|
||||
|
||||
|
|
@ -4569,7 +4577,7 @@ pub fn lookup_field_type(tcx: &ctxt,
|
|||
pub fn lookup_struct_fields(cx: &ctxt, did: ast::DefId) -> Vec<field_ty> {
|
||||
if did.krate == ast::LOCAL_CRATE {
|
||||
let struct_fields = cx.struct_fields.borrow();
|
||||
match struct_fields.find(&did) {
|
||||
match struct_fields.get(&did) {
|
||||
Some(fields) => (**fields).clone(),
|
||||
_ => {
|
||||
cx.sess.bug(
|
||||
|
|
@ -4632,7 +4640,7 @@ pub fn unboxed_closure_upvars(tcx: &ctxt, closure_id: ast::DefId, substs: &Subst
|
|||
// implemented.
|
||||
assert!(closure_id.krate == ast::LOCAL_CRATE);
|
||||
let capture_mode = tcx.capture_modes.borrow().get_copy(&closure_id.node);
|
||||
match tcx.freevars.borrow().find(&closure_id.node) {
|
||||
match tcx.freevars.borrow().get(&closure_id.node) {
|
||||
None => vec![],
|
||||
Some(ref freevars) => {
|
||||
freevars.iter().map(|freevar| {
|
||||
|
|
@ -4898,7 +4906,7 @@ pub fn required_region_bounds(tcx: &ctxt,
|
|||
all_bounds: &mut Vec<ty::Region>) {
|
||||
all_bounds.push_all(region_bounds.as_slice());
|
||||
|
||||
if builtin_bounds.contains_elem(ty::BoundSend) {
|
||||
if builtin_bounds.contains(&ty::BoundSend) {
|
||||
all_bounds.push(ty::ReStatic);
|
||||
}
|
||||
}
|
||||
|
|
@ -4921,7 +4929,7 @@ pub fn item_variances(tcx: &ctxt, item_id: ast::DefId) -> Rc<ItemVariances> {
|
|||
pub fn record_trait_implementation(tcx: &ctxt,
|
||||
trait_def_id: DefId,
|
||||
impl_def_id: DefId) {
|
||||
match tcx.trait_impls.borrow().find(&trait_def_id) {
|
||||
match tcx.trait_impls.borrow().get(&trait_def_id) {
|
||||
Some(impls_for_trait) => {
|
||||
impls_for_trait.borrow_mut().push(impl_def_id);
|
||||
return;
|
||||
|
|
@ -5094,7 +5102,7 @@ pub fn trait_of_item(tcx: &ctxt, def_id: ast::DefId) -> Option<ast::DefId> {
|
|||
/// Otherwise, return `None`.
|
||||
pub fn trait_item_of_item(tcx: &ctxt, def_id: ast::DefId)
|
||||
-> Option<ImplOrTraitItemId> {
|
||||
let impl_item = match tcx.impl_or_trait_items.borrow().find(&def_id) {
|
||||
let impl_item = match tcx.impl_or_trait_items.borrow().get(&def_id) {
|
||||
Some(m) => m.clone(),
|
||||
None => return None,
|
||||
};
|
||||
|
|
@ -5449,7 +5457,7 @@ impl<'tcx> mc::Typer<'tcx> for ty::ctxt<'tcx> {
|
|||
}
|
||||
|
||||
fn node_method_ty(&self, method_call: typeck::MethodCall) -> Option<ty::t> {
|
||||
self.method_map.borrow().find(&method_call).map(|method| method.ty)
|
||||
self.method_map.borrow().get(&method_call).map(|method| method.ty)
|
||||
}
|
||||
|
||||
fn adjustments<'a>(&'a self) -> &'a RefCell<NodeMap<ty::AutoAdjustment>> {
|
||||
|
|
@ -5561,7 +5569,7 @@ pub type FreevarMap = NodeMap<Vec<Freevar>>;
|
|||
pub type CaptureModeMap = NodeMap<ast::CaptureClause>;
|
||||
|
||||
pub fn with_freevars<T>(tcx: &ty::ctxt, fid: ast::NodeId, f: |&[Freevar]| -> T) -> T {
|
||||
match tcx.freevars.borrow().find(&fid) {
|
||||
match tcx.freevars.borrow().get(&fid) {
|
||||
None => f(&[]),
|
||||
Some(d) => f(d.as_slice())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ use middle::subst::{VecPerParamSpace};
|
|||
use middle::ty;
|
||||
use middle::typeck::lookup_def_tcx;
|
||||
use middle::typeck::infer;
|
||||
use middle::typeck::rscope::{UnelidableRscope, RegionScope, SpecificRscope};
|
||||
use middle::typeck::rscope::{UnelidableRscope, RegionScope, SpecificRscope, BindingRscope};
|
||||
use middle::typeck::rscope;
|
||||
use middle::typeck::TypeAndSubsts;
|
||||
use middle::typeck;
|
||||
|
|
@ -99,7 +99,7 @@ pub trait AstConv<'tcx> {
|
|||
|
||||
pub fn ast_region_to_region(tcx: &ty::ctxt, lifetime: &ast::Lifetime)
|
||||
-> ty::Region {
|
||||
let r = match tcx.named_region_map.find(&lifetime.id) {
|
||||
let r = match tcx.named_region_map.get(&lifetime.id) {
|
||||
None => {
|
||||
// should have been recorded by the `resolve_lifetime` pass
|
||||
tcx.sess.span_bug(lifetime.span, "unresolved lifetime");
|
||||
|
|
@ -207,15 +207,16 @@ pub fn opt_ast_region_to_region<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
|
|||
}
|
||||
|
||||
fn ast_path_substs<'tcx,AC,RS>(
|
||||
this: &AC,
|
||||
rscope: &RS,
|
||||
decl_def_id: ast::DefId,
|
||||
decl_generics: &ty::Generics,
|
||||
self_ty: Option<ty::t>,
|
||||
associated_ty: Option<ty::t>,
|
||||
path: &ast::Path)
|
||||
-> Substs
|
||||
where AC: AstConv<'tcx>, RS: RegionScope
|
||||
this: &AC,
|
||||
rscope: &RS,
|
||||
decl_def_id: ast::DefId,
|
||||
decl_generics: &ty::Generics,
|
||||
self_ty: Option<ty::t>,
|
||||
associated_ty: Option<ty::t>,
|
||||
path: &ast::Path,
|
||||
binder_id: ast::NodeId)
|
||||
-> Substs
|
||||
where AC: AstConv<'tcx>, RS: RegionScope
|
||||
{
|
||||
/*!
|
||||
* Given a path `path` that refers to an item `I` with the
|
||||
|
|
@ -236,45 +237,51 @@ fn ast_path_substs<'tcx,AC,RS>(
|
|||
assert!(decl_generics.regions.all(|d| d.space == TypeSpace));
|
||||
assert!(decl_generics.types.all(|d| d.space != FnSpace));
|
||||
|
||||
let (regions, types) = match path.segments.last().unwrap().parameters {
|
||||
ast::AngleBracketedParameters(ref data) =>
|
||||
angle_bracketed_parameters(this, rscope, data),
|
||||
ast::ParenthesizedParameters(ref data) =>
|
||||
parenthesized_parameters(this, binder_id, data),
|
||||
};
|
||||
|
||||
// If the type is parameterized by the this region, then replace this
|
||||
// region with the current anon region binding (in other words,
|
||||
// whatever & would get replaced with).
|
||||
let expected_num_region_params = decl_generics.regions.len(TypeSpace);
|
||||
let supplied_num_region_params = path.segments.last().unwrap().lifetimes.len();
|
||||
let supplied_num_region_params = regions.len();
|
||||
let regions = if expected_num_region_params == supplied_num_region_params {
|
||||
path.segments.last().unwrap().lifetimes.iter().map(
|
||||
|l| ast_region_to_region(this.tcx(), l)).collect::<Vec<_>>()
|
||||
regions
|
||||
} else {
|
||||
let anon_regions =
|
||||
rscope.anon_regions(path.span, expected_num_region_params);
|
||||
|
||||
if supplied_num_region_params != 0 || anon_regions.is_err() {
|
||||
span_err!(tcx.sess, path.span, E0107,
|
||||
"wrong number of lifetime parameters: expected {}, found {}",
|
||||
expected_num_region_params, supplied_num_region_params);
|
||||
"wrong number of lifetime parameters: expected {}, found {}",
|
||||
expected_num_region_params, supplied_num_region_params);
|
||||
}
|
||||
|
||||
match anon_regions {
|
||||
Ok(v) => v.into_iter().collect(),
|
||||
Err(_) => Vec::from_fn(expected_num_region_params,
|
||||
|_| ty::ReStatic) // hokey
|
||||
|_| ty::ReStatic) // hokey
|
||||
}
|
||||
};
|
||||
|
||||
// Convert the type parameters supplied by the user.
|
||||
let ty_param_defs = decl_generics.types.get_slice(TypeSpace);
|
||||
let supplied_ty_param_count = path.segments.iter().flat_map(|s| s.types.iter()).count();
|
||||
let supplied_ty_param_count = types.len();
|
||||
let formal_ty_param_count =
|
||||
ty_param_defs.iter()
|
||||
.take_while(|x| !ty::is_associated_type(tcx, x.def_id))
|
||||
.count();
|
||||
.take_while(|x| !ty::is_associated_type(tcx, x.def_id))
|
||||
.count();
|
||||
let required_ty_param_count =
|
||||
ty_param_defs.iter()
|
||||
.take_while(|x| {
|
||||
x.default.is_none() &&
|
||||
!ty::is_associated_type(tcx, x.def_id)
|
||||
})
|
||||
.count();
|
||||
.take_while(|x| {
|
||||
x.default.is_none() &&
|
||||
!ty::is_associated_type(tcx, x.def_id)
|
||||
})
|
||||
.count();
|
||||
if supplied_ty_param_count < required_ty_param_count {
|
||||
let expected = if required_ty_param_count < formal_ty_param_count {
|
||||
"expected at least"
|
||||
|
|
@ -282,10 +289,10 @@ fn ast_path_substs<'tcx,AC,RS>(
|
|||
"expected"
|
||||
};
|
||||
this.tcx().sess.span_fatal(path.span,
|
||||
format!("wrong number of type arguments: {} {}, found {}",
|
||||
expected,
|
||||
required_ty_param_count,
|
||||
supplied_ty_param_count).as_slice());
|
||||
format!("wrong number of type arguments: {} {}, found {}",
|
||||
expected,
|
||||
required_ty_param_count,
|
||||
supplied_ty_param_count).as_slice());
|
||||
} else if supplied_ty_param_count > formal_ty_param_count {
|
||||
let expected = if required_ty_param_count < formal_ty_param_count {
|
||||
"expected at most"
|
||||
|
|
@ -293,10 +300,10 @@ fn ast_path_substs<'tcx,AC,RS>(
|
|||
"expected"
|
||||
};
|
||||
this.tcx().sess.span_fatal(path.span,
|
||||
format!("wrong number of type arguments: {} {}, found {}",
|
||||
expected,
|
||||
formal_ty_param_count,
|
||||
supplied_ty_param_count).as_slice());
|
||||
format!("wrong number of type arguments: {} {}, found {}",
|
||||
expected,
|
||||
formal_ty_param_count,
|
||||
supplied_ty_param_count).as_slice());
|
||||
}
|
||||
|
||||
if supplied_ty_param_count > required_ty_param_count
|
||||
|
|
@ -307,13 +314,7 @@ fn ast_path_substs<'tcx,AC,RS>(
|
|||
"add #![feature(default_type_params)] to the crate attributes to enable");
|
||||
}
|
||||
|
||||
let tps = path.segments
|
||||
.iter()
|
||||
.flat_map(|s| s.types.iter())
|
||||
.map(|a_t| ast_ty_to_ty(this, rscope, &**a_t))
|
||||
.collect();
|
||||
|
||||
let mut substs = Substs::new_type(tps, regions);
|
||||
let mut substs = Substs::new_type(types, regions);
|
||||
|
||||
match self_ty {
|
||||
None => {
|
||||
|
|
@ -354,7 +355,47 @@ fn ast_path_substs<'tcx,AC,RS>(
|
|||
param.def_id))
|
||||
}
|
||||
|
||||
substs
|
||||
return substs;
|
||||
|
||||
fn angle_bracketed_parameters<'tcx, AC, RS>(this: &AC,
|
||||
rscope: &RS,
|
||||
data: &ast::AngleBracketedParameterData)
|
||||
-> (Vec<ty::Region>, Vec<ty::t>)
|
||||
where AC: AstConv<'tcx>, RS: RegionScope
|
||||
{
|
||||
let regions: Vec<_> =
|
||||
data.lifetimes.iter()
|
||||
.map(|l| ast_region_to_region(this.tcx(), l))
|
||||
.collect();
|
||||
|
||||
let types: Vec<_> =
|
||||
data.types.iter()
|
||||
.map(|t| ast_ty_to_ty(this, rscope, &**t))
|
||||
.collect();
|
||||
|
||||
(regions, types)
|
||||
}
|
||||
|
||||
fn parenthesized_parameters<'tcx,AC>(this: &AC,
|
||||
binder_id: ast::NodeId,
|
||||
data: &ast::ParenthesizedParameterData)
|
||||
-> (Vec<ty::Region>, Vec<ty::t>)
|
||||
where AC: AstConv<'tcx>
|
||||
{
|
||||
let binding_rscope = BindingRscope::new(binder_id);
|
||||
|
||||
let inputs = data.inputs.iter()
|
||||
.map(|a_t| ast_ty_to_ty(this, &binding_rscope, &**a_t))
|
||||
.collect();
|
||||
let input_ty = ty::mk_tup_or_nil(this.tcx(), inputs);
|
||||
|
||||
let output = match data.output {
|
||||
Some(ref output_ty) => ast_ty_to_ty(this, &binding_rscope, &**output_ty),
|
||||
None => ty::mk_nil()
|
||||
};
|
||||
|
||||
(Vec::new(), vec![input_ty, output])
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ast_path_to_trait_ref<'tcx,AC,RS>(this: &AC,
|
||||
|
|
@ -362,7 +403,8 @@ pub fn ast_path_to_trait_ref<'tcx,AC,RS>(this: &AC,
|
|||
trait_def_id: ast::DefId,
|
||||
self_ty: Option<ty::t>,
|
||||
associated_type: Option<ty::t>,
|
||||
path: &ast::Path)
|
||||
path: &ast::Path,
|
||||
binder_id: ast::NodeId)
|
||||
-> Rc<ty::TraitRef>
|
||||
where AC: AstConv<'tcx>,
|
||||
RS: RegionScope {
|
||||
|
|
@ -375,7 +417,8 @@ pub fn ast_path_to_trait_ref<'tcx,AC,RS>(this: &AC,
|
|||
&trait_def.generics,
|
||||
self_ty,
|
||||
associated_type,
|
||||
path)
|
||||
path,
|
||||
binder_id)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -383,8 +426,10 @@ pub fn ast_path_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
|
|||
this: &AC,
|
||||
rscope: &RS,
|
||||
did: ast::DefId,
|
||||
path: &ast::Path)
|
||||
-> TypeAndSubsts {
|
||||
path: &ast::Path,
|
||||
binder_id: ast::NodeId)
|
||||
-> TypeAndSubsts
|
||||
{
|
||||
let tcx = this.tcx();
|
||||
let ty::Polytype {
|
||||
generics,
|
||||
|
|
@ -397,7 +442,8 @@ pub fn ast_path_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
|
|||
&generics,
|
||||
None,
|
||||
None,
|
||||
path);
|
||||
path,
|
||||
binder_id);
|
||||
let ty = decl_ty.subst(tcx, &substs);
|
||||
TypeAndSubsts { substs: substs, ty: ty }
|
||||
}
|
||||
|
|
@ -407,24 +453,29 @@ pub fn ast_path_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
|
|||
/// and/or region variables are substituted.
|
||||
///
|
||||
/// This is used when checking the constructor in struct literals.
|
||||
pub fn ast_path_to_ty_relaxed<'tcx, AC: AstConv<'tcx>,
|
||||
RS:RegionScope>(
|
||||
this: &AC,
|
||||
rscope: &RS,
|
||||
did: ast::DefId,
|
||||
path: &ast::Path)
|
||||
-> TypeAndSubsts {
|
||||
pub fn ast_path_to_ty_relaxed<'tcx,AC,RS>(
|
||||
this: &AC,
|
||||
rscope: &RS,
|
||||
did: ast::DefId,
|
||||
path: &ast::Path,
|
||||
binder_id: ast::NodeId)
|
||||
-> TypeAndSubsts
|
||||
where AC : AstConv<'tcx>, RS : RegionScope
|
||||
{
|
||||
let tcx = this.tcx();
|
||||
let ty::Polytype {
|
||||
generics,
|
||||
ty: decl_ty
|
||||
} = this.get_item_ty(did);
|
||||
|
||||
let substs = if (generics.has_type_params(TypeSpace) ||
|
||||
generics.has_region_params(TypeSpace)) &&
|
||||
path.segments.iter().all(|s| {
|
||||
s.lifetimes.len() == 0 && s.types.len() == 0
|
||||
}) {
|
||||
let wants_params =
|
||||
generics.has_type_params(TypeSpace) || generics.has_region_params(TypeSpace);
|
||||
|
||||
let needs_defaults =
|
||||
wants_params &&
|
||||
path.segments.iter().all(|s| s.parameters.is_empty());
|
||||
|
||||
let substs = if needs_defaults {
|
||||
let type_params = Vec::from_fn(generics.types.len(TypeSpace),
|
||||
|_| this.ty_infer(path.span));
|
||||
let region_params =
|
||||
|
|
@ -433,7 +484,7 @@ pub fn ast_path_to_ty_relaxed<'tcx, AC: AstConv<'tcx>,
|
|||
Substs::new(VecPerParamSpace::params_from_type(type_params),
|
||||
VecPerParamSpace::params_from_type(region_params))
|
||||
} else {
|
||||
ast_path_substs(this, rscope, did, &generics, None, None, path)
|
||||
ast_path_substs(this, rscope, did, &generics, None, None, path, binder_id)
|
||||
};
|
||||
|
||||
let ty = decl_ty.subst(tcx, &substs);
|
||||
|
|
@ -450,14 +501,14 @@ fn check_path_args(tcx: &ty::ctxt,
|
|||
path: &ast::Path,
|
||||
flags: uint) {
|
||||
if (flags & NO_TPS) != 0u {
|
||||
if !path.segments.iter().all(|s| s.types.is_empty()) {
|
||||
if path.segments.iter().any(|s| s.parameters.has_types()) {
|
||||
span_err!(tcx.sess, path.span, E0109,
|
||||
"type parameters are not allowed on this type");
|
||||
}
|
||||
}
|
||||
|
||||
if (flags & NO_REGIONS) != 0u {
|
||||
if !path.segments.last().unwrap().lifetimes.is_empty() {
|
||||
if path.segments.iter().any(|s| s.parameters.has_lifetimes()) {
|
||||
span_err!(tcx.sess, path.span, E0110,
|
||||
"region parameters are not allowed on this type");
|
||||
}
|
||||
|
|
@ -467,7 +518,7 @@ fn check_path_args(tcx: &ty::ctxt,
|
|||
pub fn ast_ty_to_prim_ty(tcx: &ty::ctxt, ast_ty: &ast::Ty) -> Option<ty::t> {
|
||||
match ast_ty.node {
|
||||
ast::TyPath(ref path, _, id) => {
|
||||
let a_def = match tcx.def_map.borrow().find(&id) {
|
||||
let a_def = match tcx.def_map.borrow().get(&id) {
|
||||
None => {
|
||||
tcx.sess.span_bug(ast_ty.span,
|
||||
format!("unbound path {}",
|
||||
|
|
@ -524,7 +575,7 @@ pub fn ast_ty_to_builtin_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
|
|||
|
||||
match ast_ty.node {
|
||||
ast::TyPath(ref path, _, id) => {
|
||||
let a_def = match this.tcx().def_map.borrow().find(&id) {
|
||||
let a_def = match this.tcx().def_map.borrow().get(&id) {
|
||||
None => {
|
||||
this.tcx()
|
||||
.sess
|
||||
|
|
@ -538,29 +589,23 @@ pub fn ast_ty_to_builtin_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
|
|||
// FIXME(#12938): This is a hack until we have full support for
|
||||
// DST.
|
||||
match a_def {
|
||||
def::DefTy(did, _) | def::DefStruct(did)
|
||||
if Some(did) == this.tcx().lang_items.owned_box() => {
|
||||
if path.segments
|
||||
.iter()
|
||||
.flat_map(|s| s.types.iter())
|
||||
.count() > 1 {
|
||||
span_err!(this.tcx().sess, path.span, E0047,
|
||||
"`Box` has only one type parameter");
|
||||
def::DefTy(did, _) |
|
||||
def::DefStruct(did) if Some(did) == this.tcx().lang_items.owned_box() => {
|
||||
let ty = ast_path_to_ty(this, rscope, did, path, id).ty;
|
||||
match ty::get(ty).sty {
|
||||
ty::ty_struct(struct_def_id, ref substs) => {
|
||||
assert_eq!(struct_def_id, did);
|
||||
assert_eq!(substs.types.len(TypeSpace), 1);
|
||||
let referent_ty = *substs.types.get(TypeSpace, 0);
|
||||
Some(ty::mk_uniq(this.tcx(), referent_ty))
|
||||
}
|
||||
_ => {
|
||||
this.tcx().sess.span_bug(
|
||||
path.span,
|
||||
format!("converting `Box` to `{}`",
|
||||
ty.repr(this.tcx()))[]);
|
||||
}
|
||||
}
|
||||
|
||||
for inner_ast_type in path.segments
|
||||
.iter()
|
||||
.flat_map(|s| s.types.iter()) {
|
||||
return Some(mk_pointer(this,
|
||||
rscope,
|
||||
ast::MutImmutable,
|
||||
&**inner_ast_type,
|
||||
Uniq,
|
||||
|typ| ty::mk_uniq(this.tcx(), typ)));
|
||||
}
|
||||
span_err!(this.tcx().sess, path.span, E0113,
|
||||
"not enough type parameters supplied to `Box<T>`");
|
||||
Some(ty::mk_err())
|
||||
}
|
||||
_ => None
|
||||
}
|
||||
|
|
@ -575,15 +620,6 @@ enum PointerTy {
|
|||
Uniq
|
||||
}
|
||||
|
||||
impl PointerTy {
|
||||
fn default_region(&self) -> ty::Region {
|
||||
match *self {
|
||||
Uniq => ty::ReStatic,
|
||||
RPtr(r) => r,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn trait_ref_for_unboxed_function<'tcx, AC: AstConv<'tcx>,
|
||||
RS:RegionScope>(
|
||||
this: &AC,
|
||||
|
|
@ -603,11 +639,7 @@ pub fn trait_ref_for_unboxed_function<'tcx, AC: AstConv<'tcx>,
|
|||
.map(|input| {
|
||||
ast_ty_to_ty(this, rscope, &*input.ty)
|
||||
}).collect::<Vec<_>>();
|
||||
let input_tuple = if input_types.len() == 0 {
|
||||
ty::mk_nil()
|
||||
} else {
|
||||
ty::mk_tup(this.tcx(), input_types)
|
||||
};
|
||||
let input_tuple = ty::mk_tup_or_nil(this.tcx(), input_types);
|
||||
let output_type = ast_ty_to_ty(this, rscope, &*decl.output);
|
||||
let mut substs = Substs::new_type(vec!(input_tuple, output_type),
|
||||
Vec::new());
|
||||
|
|
@ -646,36 +678,11 @@ fn mk_pointer<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
|
|||
let ty = ast_ty_to_ty(this, rscope, &**ty);
|
||||
return constr(ty::mk_vec(tcx, ty, None));
|
||||
}
|
||||
ast::TyUnboxedFn(ref unboxed_function) => {
|
||||
let ty::TraitRef {
|
||||
def_id,
|
||||
substs
|
||||
} = trait_ref_for_unboxed_function(this,
|
||||
rscope,
|
||||
unboxed_function.kind,
|
||||
&*unboxed_function.decl,
|
||||
None);
|
||||
let r = ptr_ty.default_region();
|
||||
let tr = ty::mk_trait(this.tcx(),
|
||||
def_id,
|
||||
substs,
|
||||
ty::region_existential_bound(r));
|
||||
match ptr_ty {
|
||||
Uniq => {
|
||||
return ty::mk_uniq(this.tcx(), tr);
|
||||
}
|
||||
RPtr(r) => {
|
||||
return ty::mk_rptr(this.tcx(),
|
||||
r,
|
||||
ty::mt {mutbl: a_seq_mutbl, ty: tr});
|
||||
}
|
||||
}
|
||||
}
|
||||
ast::TyPath(ref path, ref opt_bounds, id) => {
|
||||
// Note that the "bounds must be empty if path is not a trait"
|
||||
// restriction is enforced in the below case for ty_path, which
|
||||
// will run after this as long as the path isn't a trait.
|
||||
match tcx.def_map.borrow().find(&id) {
|
||||
match tcx.def_map.borrow().get(&id) {
|
||||
Some(&def::DefPrimTy(ast::TyStr)) => {
|
||||
check_path_args(tcx, path, NO_TPS | NO_REGIONS);
|
||||
match ptr_ty {
|
||||
|
|
@ -693,7 +700,8 @@ fn mk_pointer<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
|
|||
trait_def_id,
|
||||
None,
|
||||
None,
|
||||
path);
|
||||
path,
|
||||
id);
|
||||
let bounds = match *opt_bounds {
|
||||
None => {
|
||||
conv_existential_bounds(this,
|
||||
|
|
@ -771,7 +779,12 @@ fn associated_ty_to_ty<'tcx,AC,RS>(this: &AC,
|
|||
trait_did,
|
||||
None,
|
||||
Some(for_type),
|
||||
trait_path);
|
||||
trait_path,
|
||||
ast::DUMMY_NODE_ID); // *see below
|
||||
|
||||
// * The trait in a qualified path cannot be "higher-ranked" and
|
||||
// hence cannot use the parenthetical sugar, so the binder-id is
|
||||
// irrelevant.
|
||||
|
||||
debug!("associated_ty_to_ty(trait_ref={})",
|
||||
trait_ref.repr(this.tcx()));
|
||||
|
|
@ -802,7 +815,7 @@ pub fn ast_ty_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
|
|||
let tcx = this.tcx();
|
||||
|
||||
let mut ast_ty_to_ty_cache = tcx.ast_ty_to_ty_cache.borrow_mut();
|
||||
match ast_ty_to_ty_cache.find(&ast_ty.id) {
|
||||
match ast_ty_to_ty_cache.get(&ast_ty.id) {
|
||||
Some(&ty::atttce_resolved(ty)) => return ty,
|
||||
Some(&ty::atttce_unresolved) => {
|
||||
tcx.sess.span_fatal(ast_ty.span,
|
||||
|
|
@ -894,13 +907,8 @@ pub fn ast_ty_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
|
|||
|
||||
ty::mk_closure(tcx, fn_decl)
|
||||
}
|
||||
ast::TyUnboxedFn(..) => {
|
||||
tcx.sess.span_err(ast_ty.span,
|
||||
"cannot use unboxed functions here");
|
||||
ty::mk_err()
|
||||
}
|
||||
ast::TyPath(ref path, ref bounds, id) => {
|
||||
let a_def = match tcx.def_map.borrow().find(&id) {
|
||||
let a_def = match tcx.def_map.borrow().get(&id) {
|
||||
None => {
|
||||
tcx.sess
|
||||
.span_bug(ast_ty.span,
|
||||
|
|
@ -925,7 +933,8 @@ pub fn ast_ty_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
|
|||
trait_def_id,
|
||||
None,
|
||||
None,
|
||||
path);
|
||||
path,
|
||||
id);
|
||||
let empty_bounds: &[ast::TyParamBound] = &[];
|
||||
let ast_bounds = match *bounds {
|
||||
Some(ref b) => b.as_slice(),
|
||||
|
|
@ -942,7 +951,7 @@ pub fn ast_ty_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
|
|||
bounds)
|
||||
}
|
||||
def::DefTy(did, _) | def::DefStruct(did) => {
|
||||
ast_path_to_ty(this, rscope, did, path).ty
|
||||
ast_path_to_ty(this, rscope, did, path, id).ty
|
||||
}
|
||||
def::DefTyParam(space, id, n) => {
|
||||
check_path_args(tcx, path, NO_TPS | NO_REGIONS);
|
||||
|
|
@ -990,7 +999,7 @@ pub fn ast_ty_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
|
|||
}
|
||||
}
|
||||
ast::TyQPath(ref qpath) => {
|
||||
match tcx.def_map.borrow().find(&ast_ty.id) {
|
||||
match tcx.def_map.borrow().get(&ast_ty.id) {
|
||||
None => {
|
||||
tcx.sess.span_bug(ast_ty.span,
|
||||
"unbound qualified path")
|
||||
|
|
@ -1377,8 +1386,7 @@ pub fn conv_existential_bounds<'tcx, AC: AstConv<'tcx>, RS:RegionScope>(
|
|||
|
||||
let PartitionedBounds { builtin_bounds,
|
||||
trait_bounds,
|
||||
region_bounds,
|
||||
unboxed_fn_ty_bounds } =
|
||||
region_bounds } =
|
||||
partition_bounds(this.tcx(), span, ast_bound_refs.as_slice());
|
||||
|
||||
if !trait_bounds.is_empty() {
|
||||
|
|
@ -1389,13 +1397,6 @@ pub fn conv_existential_bounds<'tcx, AC: AstConv<'tcx>, RS:RegionScope>(
|
|||
as closure or object bounds").as_slice());
|
||||
}
|
||||
|
||||
if !unboxed_fn_ty_bounds.is_empty() {
|
||||
this.tcx().sess.span_err(
|
||||
span,
|
||||
format!("only the builtin traits can be used \
|
||||
as closure or object bounds").as_slice());
|
||||
}
|
||||
|
||||
// The "main trait refs", rather annoyingly, have no type
|
||||
// specified for the `Self` parameter of the trait. The reason for
|
||||
// this is that they are, after all, *existential* types, and
|
||||
|
|
@ -1524,7 +1525,6 @@ fn compute_region_bound<'tcx, AC: AstConv<'tcx>, RS:RegionScope>(
|
|||
pub struct PartitionedBounds<'a> {
|
||||
pub builtin_bounds: ty::BuiltinBounds,
|
||||
pub trait_bounds: Vec<&'a ast::TraitRef>,
|
||||
pub unboxed_fn_ty_bounds: Vec<&'a ast::UnboxedFnBound>,
|
||||
pub region_bounds: Vec<&'a ast::Lifetime>,
|
||||
}
|
||||
|
||||
|
|
@ -1542,14 +1542,13 @@ pub fn partition_bounds<'a>(tcx: &ty::ctxt,
|
|||
let mut builtin_bounds = ty::empty_builtin_bounds();
|
||||
let mut region_bounds = Vec::new();
|
||||
let mut trait_bounds = Vec::new();
|
||||
let mut unboxed_fn_ty_bounds = Vec::new();
|
||||
let mut trait_def_ids = HashMap::new();
|
||||
for &ast_bound in ast_bounds.iter() {
|
||||
match *ast_bound {
|
||||
ast::TraitTyParamBound(ref b) => {
|
||||
match lookup_def_tcx(tcx, b.path.span, b.ref_id) {
|
||||
def::DefTrait(trait_did) => {
|
||||
match trait_def_ids.find(&trait_did) {
|
||||
match trait_def_ids.get(&trait_did) {
|
||||
// Already seen this trait. We forbid
|
||||
// duplicates in the list (for some
|
||||
// reason).
|
||||
|
|
@ -1587,9 +1586,6 @@ pub fn partition_bounds<'a>(tcx: &ty::ctxt,
|
|||
ast::RegionTyParamBound(ref l) => {
|
||||
region_bounds.push(l);
|
||||
}
|
||||
ast::UnboxedFnTyParamBound(ref unboxed_function) => {
|
||||
unboxed_fn_ty_bounds.push(&**unboxed_function);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1597,7 +1593,6 @@ pub fn partition_bounds<'a>(tcx: &ty::ctxt,
|
|||
builtin_bounds: builtin_bounds,
|
||||
trait_bounds: trait_bounds,
|
||||
region_bounds: region_bounds,
|
||||
unboxed_fn_ty_bounds: unboxed_fn_ty_bounds
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -324,7 +324,7 @@ pub fn check_pat_struct(pcx: &pat_ctxt, pat: &ast::Pat,
|
|||
|
||||
let item_substs = fcx
|
||||
.item_substs()
|
||||
.find(&pat.id)
|
||||
.get(&pat.id)
|
||||
.map(|substs| substs.substs.clone())
|
||||
.unwrap_or_else(|| Substs::empty());
|
||||
|
||||
|
|
|
|||
|
|
@ -678,7 +678,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
|
|||
debug!("push_extension_candidates(expr_id={})", expr_id);
|
||||
|
||||
let mut duplicates = HashSet::new();
|
||||
let opt_applicable_traits = self.fcx.ccx.trait_map.find(&expr_id);
|
||||
let opt_applicable_traits = self.fcx.ccx.trait_map.get(&expr_id);
|
||||
for applicable_traits in opt_applicable_traits.into_iter() {
|
||||
for &trait_did in applicable_traits.iter() {
|
||||
if duplicates.insert(trait_did) {
|
||||
|
|
@ -912,7 +912,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
|
|||
// metadata if necessary.
|
||||
ty::populate_implementations_for_type_if_necessary(self.tcx(), did);
|
||||
|
||||
for impl_infos in self.tcx().inherent_impls.borrow().find(&did).iter() {
|
||||
for impl_infos in self.tcx().inherent_impls.borrow().get(&did).iter() {
|
||||
for impl_did in impl_infos.iter() {
|
||||
self.push_candidates_from_inherent_impl(*impl_did);
|
||||
}
|
||||
|
|
@ -1627,7 +1627,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
|
|||
.inh
|
||||
.adjustments
|
||||
.borrow()
|
||||
.find(&expr.id) {
|
||||
.get(&expr.id) {
|
||||
Some(&ty::AdjustDerefRef(ty::AutoDerefRef {
|
||||
autoderefs: autoderef_count,
|
||||
autoref: _
|
||||
|
|
@ -1658,7 +1658,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
|
|||
match expr.node {
|
||||
ast::ExprIndex(ref base_expr, _) => {
|
||||
let mut base_adjustment =
|
||||
match self.fcx.inh.adjustments.borrow().find(&base_expr.id) {
|
||||
match self.fcx.inh.adjustments.borrow().get(&base_expr.id) {
|
||||
Some(&ty::AdjustDerefRef(ref adr)) => (*adr).clone(),
|
||||
None => ty::AutoDerefRef { autoderefs: 0, autoref: None },
|
||||
Some(_) => {
|
||||
|
|
@ -1839,7 +1839,7 @@ fn impl_method(tcx: &ty::ctxt,
|
|||
-> Option<Rc<ty::Method>>
|
||||
{
|
||||
let impl_items = tcx.impl_items.borrow();
|
||||
let impl_items = impl_items.find(&impl_def_id).unwrap();
|
||||
let impl_items = impl_items.get(&impl_def_id).unwrap();
|
||||
impl_items
|
||||
.iter()
|
||||
.map(|&did| ty::impl_or_trait_item(tcx, did.def_id()))
|
||||
|
|
|
|||
|
|
@ -298,7 +298,7 @@ impl<'a, 'tcx> mem_categorization::Typer<'tcx> for FnCtxt<'a, 'tcx> {
|
|||
}
|
||||
fn node_method_ty(&self, method_call: typeck::MethodCall)
|
||||
-> Option<ty::t> {
|
||||
self.inh.method_map.borrow().find(&method_call).map(|m| m.ty)
|
||||
self.inh.method_map.borrow().get(&method_call).map(|m| m.ty)
|
||||
}
|
||||
fn adjustments<'a>(&'a self) -> &'a RefCell<NodeMap<ty::AutoAdjustment>> {
|
||||
&self.inh.adjustments
|
||||
|
|
@ -1556,7 +1556,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
}
|
||||
|
||||
pub fn local_ty(&self, span: Span, nid: ast::NodeId) -> ty::t {
|
||||
match self.inh.locals.borrow().find(&nid) {
|
||||
match self.inh.locals.borrow().get(&nid) {
|
||||
Some(&t) => t,
|
||||
None => {
|
||||
self.tcx().sess.span_bug(
|
||||
|
|
@ -1808,7 +1808,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
}
|
||||
|
||||
pub fn expr_ty(&self, ex: &ast::Expr) -> ty::t {
|
||||
match self.inh.node_types.borrow().find(&ex.id) {
|
||||
match self.inh.node_types.borrow().get(&ex.id) {
|
||||
Some(&t) => t,
|
||||
None => {
|
||||
self.tcx().sess.bug(format!("no type for expr in fcx {}",
|
||||
|
|
@ -1824,7 +1824,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
*/
|
||||
|
||||
let adjustments = self.inh.adjustments.borrow();
|
||||
let adjustment = adjustments.find(&expr.id);
|
||||
let adjustment = adjustments.get(&expr.id);
|
||||
self.adjust_expr_ty(expr, adjustment)
|
||||
}
|
||||
|
||||
|
|
@ -1845,12 +1845,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
raw_ty,
|
||||
adjustment,
|
||||
|method_call| self.inh.method_map.borrow()
|
||||
.find(&method_call)
|
||||
.get(&method_call)
|
||||
.map(|method| method.ty))
|
||||
}
|
||||
|
||||
pub fn node_ty(&self, id: ast::NodeId) -> ty::t {
|
||||
match self.inh.node_types.borrow().find(&id) {
|
||||
match self.inh.node_types.borrow().get(&id) {
|
||||
Some(&t) => t,
|
||||
None => {
|
||||
self.tcx().sess.bug(
|
||||
|
|
@ -1868,7 +1868,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
pub fn opt_node_ty_substs(&self,
|
||||
id: ast::NodeId,
|
||||
f: |&ty::ItemSubsts|) {
|
||||
match self.inh.item_substs.borrow().find(&id) {
|
||||
match self.inh.item_substs.borrow().get(&id) {
|
||||
Some(s) => { f(s) }
|
||||
None => { }
|
||||
}
|
||||
|
|
@ -3481,11 +3481,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
|
|||
|
||||
// Tuple up the arguments and insert the resulting function type into
|
||||
// the `unboxed_closures` table.
|
||||
fn_ty.sig.inputs = if fn_ty.sig.inputs.len() == 0 {
|
||||
vec![ty::mk_nil()]
|
||||
} else {
|
||||
vec![ty::mk_tup(fcx.tcx(), fn_ty.sig.inputs)]
|
||||
};
|
||||
fn_ty.sig.inputs = vec![ty::mk_tup_or_nil(fcx.tcx(), fn_ty.sig.inputs)];
|
||||
|
||||
let kind = match kind {
|
||||
ast::FnUnboxedClosureKind => ty::FnUnboxedClosureKind,
|
||||
|
|
@ -3554,7 +3550,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
|
|||
let (bounds, onceness) = match expr.node {
|
||||
ast::ExprProc(..) => {
|
||||
let mut bounds = ty::region_existential_bound(ty::ReStatic);
|
||||
bounds.builtin_bounds.add(ty::BoundSend); // FIXME
|
||||
bounds.builtin_bounds.insert(ty::BoundSend); // FIXME
|
||||
(bounds, ast::Once)
|
||||
}
|
||||
_ => {
|
||||
|
|
@ -3763,7 +3759,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
|
|||
for field in ast_fields.iter() {
|
||||
let mut expected_field_type = ty::mk_err();
|
||||
|
||||
let pair = class_field_map.find(&field.ident.node.name).map(|x| *x);
|
||||
let pair = class_field_map.get(&field.ident.node.name).map(|x| *x);
|
||||
match pair {
|
||||
None => {
|
||||
fcx.type_error_message(
|
||||
|
|
@ -4422,7 +4418,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
|
|||
}
|
||||
ast::ExprStruct(ref path, ref fields, ref base_expr) => {
|
||||
// Resolve the path.
|
||||
let def = tcx.def_map.borrow().find(&id).map(|i| *i);
|
||||
let def = tcx.def_map.borrow().get(&id).map(|i| *i);
|
||||
let struct_id = match def {
|
||||
Some(def::DefVariant(enum_id, variant_id, true)) => {
|
||||
check_struct_enum_variant(fcx, id, expr.span, enum_id,
|
||||
|
|
@ -4478,7 +4474,8 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
|
|||
let type_and_substs = astconv::ast_path_to_ty_relaxed(fcx,
|
||||
fcx.infcx(),
|
||||
struct_id,
|
||||
path);
|
||||
path,
|
||||
expr.id);
|
||||
match fcx.mk_subty(false,
|
||||
infer::Misc(path.span),
|
||||
actual_structure_type,
|
||||
|
|
@ -5339,6 +5336,7 @@ pub fn instantiate_path(fcx: &FnCtxt,
|
|||
Some(space) => {
|
||||
push_explicit_parameters_from_segment_to_substs(fcx,
|
||||
space,
|
||||
path.span,
|
||||
type_defs,
|
||||
region_defs,
|
||||
segment,
|
||||
|
|
@ -5374,13 +5372,13 @@ pub fn instantiate_path(fcx: &FnCtxt,
|
|||
fcx: &FnCtxt,
|
||||
segment: &ast::PathSegment)
|
||||
{
|
||||
for typ in segment.types.iter() {
|
||||
for typ in segment.parameters.types().iter() {
|
||||
span_err!(fcx.tcx().sess, typ.span, E0085,
|
||||
"type parameters may not appear here");
|
||||
break;
|
||||
}
|
||||
|
||||
for lifetime in segment.lifetimes.iter() {
|
||||
for lifetime in segment.parameters.lifetimes().iter() {
|
||||
span_err!(fcx.tcx().sess, lifetime.span, E0086,
|
||||
"lifetime parameters may not appear here");
|
||||
break;
|
||||
|
|
@ -5390,6 +5388,7 @@ pub fn instantiate_path(fcx: &FnCtxt,
|
|||
fn push_explicit_parameters_from_segment_to_substs(
|
||||
fcx: &FnCtxt,
|
||||
space: subst::ParamSpace,
|
||||
span: Span,
|
||||
type_defs: &VecPerParamSpace<ty::TypeParameterDef>,
|
||||
region_defs: &VecPerParamSpace<ty::RegionParameterDef>,
|
||||
segment: &ast::PathSegment,
|
||||
|
|
@ -5412,10 +5411,31 @@ pub fn instantiate_path(fcx: &FnCtxt,
|
|||
* span of the N+1'th parameter.
|
||||
*/
|
||||
|
||||
match segment.parameters {
|
||||
ast::AngleBracketedParameters(ref data) => {
|
||||
push_explicit_angle_bracketed_parameters_from_segment_to_substs(
|
||||
fcx, space, type_defs, region_defs, data, substs);
|
||||
}
|
||||
|
||||
ast::ParenthesizedParameters(ref data) => {
|
||||
push_explicit_parenthesized_parameters_from_segment_to_substs(
|
||||
fcx, space, span, type_defs, data, substs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn push_explicit_angle_bracketed_parameters_from_segment_to_substs(
|
||||
fcx: &FnCtxt,
|
||||
space: subst::ParamSpace,
|
||||
type_defs: &VecPerParamSpace<ty::TypeParameterDef>,
|
||||
region_defs: &VecPerParamSpace<ty::RegionParameterDef>,
|
||||
data: &ast::AngleBracketedParameterData,
|
||||
substs: &mut Substs)
|
||||
{
|
||||
{
|
||||
let type_count = type_defs.len(space);
|
||||
assert_eq!(substs.types.len(space), 0);
|
||||
for (i, typ) in segment.types.iter().enumerate() {
|
||||
for (i, typ) in data.types.iter().enumerate() {
|
||||
let t = fcx.to_ty(&**typ);
|
||||
if i < type_count {
|
||||
substs.types.push(space, t);
|
||||
|
|
@ -5424,7 +5444,7 @@ pub fn instantiate_path(fcx: &FnCtxt,
|
|||
"too many type parameters provided: \
|
||||
expected at most {} parameter(s), \
|
||||
found {} parameter(s)",
|
||||
type_count, segment.types.len());
|
||||
type_count, data.types.len());
|
||||
substs.types.truncate(space, 0);
|
||||
}
|
||||
}
|
||||
|
|
@ -5433,7 +5453,7 @@ pub fn instantiate_path(fcx: &FnCtxt,
|
|||
{
|
||||
let region_count = region_defs.len(space);
|
||||
assert_eq!(substs.regions().len(space), 0);
|
||||
for (i, lifetime) in segment.lifetimes.iter().enumerate() {
|
||||
for (i, lifetime) in data.lifetimes.iter().enumerate() {
|
||||
let r = ast_region_to_region(fcx.tcx(), lifetime);
|
||||
if i < region_count {
|
||||
substs.mut_regions().push(space, r);
|
||||
|
|
@ -5442,13 +5462,59 @@ pub fn instantiate_path(fcx: &FnCtxt,
|
|||
"too many lifetime parameters provided: \
|
||||
expected {} parameter(s), found {} parameter(s)",
|
||||
region_count,
|
||||
segment.lifetimes.len());
|
||||
data.lifetimes.len());
|
||||
substs.mut_regions().truncate(space, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn push_explicit_parenthesized_parameters_from_segment_to_substs(
|
||||
fcx: &FnCtxt,
|
||||
space: subst::ParamSpace,
|
||||
span: Span,
|
||||
type_defs: &VecPerParamSpace<ty::TypeParameterDef>,
|
||||
data: &ast::ParenthesizedParameterData,
|
||||
substs: &mut Substs)
|
||||
{
|
||||
/*!
|
||||
* As with
|
||||
* `push_explicit_angle_bracketed_parameters_from_segment_to_substs`,
|
||||
* but intended for `Foo(A,B) -> C` form. This expands to
|
||||
* roughly the same thing as `Foo<(A,B),C>`. One important
|
||||
* difference has to do with the treatment of anonymous
|
||||
* regions, which are translated into bound regions (NYI).
|
||||
*/
|
||||
|
||||
let type_count = type_defs.len(space);
|
||||
if type_count < 2 {
|
||||
span_err!(fcx.tcx().sess, span, E0167,
|
||||
"parenthesized form always supplies 2 type parameters, \
|
||||
but only {} parameter(s) were expected",
|
||||
type_count);
|
||||
}
|
||||
|
||||
let input_tys: Vec<ty::t> =
|
||||
data.inputs.iter().map(|ty| fcx.to_ty(&**ty)).collect();
|
||||
|
||||
let tuple_ty =
|
||||
ty::mk_tup_or_nil(fcx.tcx(), input_tys);
|
||||
|
||||
if type_count >= 1 {
|
||||
substs.types.push(space, tuple_ty);
|
||||
}
|
||||
|
||||
let output_ty: Option<ty::t> =
|
||||
data.output.as_ref().map(|ty| fcx.to_ty(&**ty));
|
||||
|
||||
let output_ty =
|
||||
output_ty.unwrap_or(ty::mk_nil());
|
||||
|
||||
if type_count >= 2 {
|
||||
substs.types.push(space, output_ty);
|
||||
}
|
||||
}
|
||||
|
||||
fn adjust_type_parameters(
|
||||
fcx: &FnCtxt,
|
||||
span: Span,
|
||||
|
|
@ -5603,7 +5669,7 @@ pub fn may_break(cx: &ty::ctxt, id: ast::NodeId, b: &ast::Block) -> bool {
|
|||
(block_query(b, |e| {
|
||||
match e.node {
|
||||
ast::ExprBreak(Some(_)) => {
|
||||
match cx.def_map.borrow().find(&e.id) {
|
||||
match cx.def_map.borrow().get(&e.id) {
|
||||
Some(&def::DefLabel(loop_id)) if id == loop_id => true,
|
||||
_ => false,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -327,7 +327,7 @@ impl<'a, 'tcx> Rcx<'a, 'tcx> {
|
|||
|
||||
fn resolve_method_type(&self, method_call: MethodCall) -> Option<ty::t> {
|
||||
let method_ty = self.fcx.inh.method_map.borrow()
|
||||
.find(&method_call).map(|method| method.ty);
|
||||
.get(&method_call).map(|method| method.ty);
|
||||
method_ty.map(|method_ty| self.resolve_type(method_ty))
|
||||
}
|
||||
|
||||
|
|
@ -339,7 +339,7 @@ impl<'a, 'tcx> Rcx<'a, 'tcx> {
|
|||
} else {
|
||||
let tcx = self.fcx.tcx();
|
||||
ty::adjust_ty(tcx, expr.span, expr.id, ty_unadjusted,
|
||||
self.fcx.inh.adjustments.borrow().find(&expr.id),
|
||||
self.fcx.inh.adjustments.borrow().get(&expr.id),
|
||||
|method_call| self.resolve_method_type(method_call))
|
||||
}
|
||||
}
|
||||
|
|
@ -351,7 +351,7 @@ impl<'a, 'tcx> Rcx<'a, 'tcx> {
|
|||
// When we enter a function, we can derive
|
||||
|
||||
let fn_sig_map = self.fcx.inh.fn_sig_map.borrow();
|
||||
let fn_sig = match fn_sig_map.find(&id) {
|
||||
let fn_sig = match fn_sig_map.get(&id) {
|
||||
Some(f) => f,
|
||||
None => {
|
||||
self.tcx().sess.bug(
|
||||
|
|
@ -370,7 +370,7 @@ impl<'a, 'tcx> Rcx<'a, 'tcx> {
|
|||
{
|
||||
debug!("visit_region_obligations: node_id={}", node_id);
|
||||
let region_obligations = self.fcx.inh.region_obligations.borrow();
|
||||
match region_obligations.find(&node_id) {
|
||||
match region_obligations.get(&node_id) {
|
||||
None => { }
|
||||
Some(vec) => {
|
||||
for r_o in vec.iter() {
|
||||
|
|
@ -594,7 +594,7 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) {
|
|||
let has_method_map = rcx.fcx.inh.method_map.borrow().contains_key(&method_call);
|
||||
|
||||
// Check any autoderefs or autorefs that appear.
|
||||
for &adjustment in rcx.fcx.inh.adjustments.borrow().find(&expr.id).iter() {
|
||||
for &adjustment in rcx.fcx.inh.adjustments.borrow().get(&expr.id).iter() {
|
||||
debug!("adjustment={}", adjustment);
|
||||
match *adjustment {
|
||||
ty::AdjustDerefRef(ty::AutoDerefRef {autoderefs, autoref: ref opt_autoref}) => {
|
||||
|
|
@ -686,7 +686,7 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) {
|
|||
ast::ExprUnary(ast::UnDeref, ref base) => {
|
||||
// For *a, the lifetime of a must enclose the deref
|
||||
let method_call = MethodCall::expr(expr.id);
|
||||
let base_ty = match rcx.fcx.inh.method_map.borrow().find(&method_call) {
|
||||
let base_ty = match rcx.fcx.inh.method_map.borrow().get(&method_call) {
|
||||
Some(method) => {
|
||||
constrain_call(rcx, expr, Some(&**base),
|
||||
None::<ast::Expr>.iter(), true);
|
||||
|
|
@ -950,7 +950,7 @@ fn check_expr_fn_block(rcx: &mut Rcx,
|
|||
let raw_var_ty = rcx.resolve_node_type(var_node_id);
|
||||
let upvar_id = ty::UpvarId { var_id: var_node_id,
|
||||
closure_expr_id: expr.id };
|
||||
let var_ty = match rcx.fcx.inh.upvar_borrow_map.borrow().find(&upvar_id) {
|
||||
let var_ty = match rcx.fcx.inh.upvar_borrow_map.borrow().get(&upvar_id) {
|
||||
Some(upvar_borrow) => {
|
||||
ty::mk_rptr(rcx.tcx(),
|
||||
upvar_borrow.region,
|
||||
|
|
@ -1195,7 +1195,7 @@ fn constrain_autoderefs(rcx: &mut Rcx,
|
|||
i, derefs);
|
||||
|
||||
let method_call = MethodCall::autoderef(deref_expr.id, i);
|
||||
derefd_ty = match rcx.fcx.inh.method_map.borrow().find(&method_call) {
|
||||
derefd_ty = match rcx.fcx.inh.method_map.borrow().get(&method_call) {
|
||||
Some(method) => {
|
||||
// Treat overloaded autoderefs as if an AutoRef adjustment
|
||||
// was applied on the base type, as that is always the case.
|
||||
|
|
@ -1301,7 +1301,7 @@ fn type_of_node_must_outlive(
|
|||
// report errors later on in the writeback phase.
|
||||
let ty0 = rcx.resolve_node_type(id);
|
||||
let ty = ty::adjust_ty(tcx, origin.span(), id, ty0,
|
||||
rcx.fcx.inh.adjustments.borrow().find(&id),
|
||||
rcx.fcx.inh.adjustments.borrow().get(&id),
|
||||
|method_call| rcx.resolve_method_type(method_call));
|
||||
debug!("constrain_regions_in_type_of_node(\
|
||||
ty={}, ty0={}, id={}, minimum_lifetime={})",
|
||||
|
|
@ -1582,7 +1582,7 @@ fn link_reborrowed_region(rcx: &Rcx,
|
|||
mc::NoteUpvarRef(ref upvar_id) => {
|
||||
let mut upvar_borrow_map =
|
||||
rcx.fcx.inh.upvar_borrow_map.borrow_mut();
|
||||
match upvar_borrow_map.find_mut(upvar_id) {
|
||||
match upvar_borrow_map.get_mut(upvar_id) {
|
||||
Some(upvar_borrow) => {
|
||||
// Adjust mutability that we infer for the upvar
|
||||
// so it can accommodate being borrowed with
|
||||
|
|
@ -1845,7 +1845,7 @@ fn link_upvar_borrow_kind_for_nested_closures(rcx: &mut Rcx,
|
|||
|
||||
let mut upvar_borrow_map = rcx.fcx.inh.upvar_borrow_map.borrow_mut();
|
||||
let inner_borrow = upvar_borrow_map.get_copy(&inner_upvar_id);
|
||||
match upvar_borrow_map.find_mut(&outer_upvar_id) {
|
||||
match upvar_borrow_map.get_mut(&outer_upvar_id) {
|
||||
Some(outer_borrow) => {
|
||||
adjust_upvar_borrow_kind(rcx, outer_upvar_id, outer_borrow, inner_borrow.kind);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -263,7 +263,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
|||
}
|
||||
|
||||
fn visit_adjustments(&self, reason: ResolveReason, id: ast::NodeId) {
|
||||
match self.fcx.inh.adjustments.borrow_mut().pop(&id) {
|
||||
match self.fcx.inh.adjustments.borrow_mut().remove(&id) {
|
||||
None => {
|
||||
debug!("No adjustments for node {}", id);
|
||||
}
|
||||
|
|
@ -275,7 +275,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
|||
// FIXME(eddyb) #2190 Allow only statically resolved
|
||||
// bare functions to coerce to a closure to avoid
|
||||
// constructing (slower) indirect call wrappers.
|
||||
match self.tcx().def_map.borrow().find(&id) {
|
||||
match self.tcx().def_map.borrow().get(&id) {
|
||||
Some(&def::DefFn(..)) |
|
||||
Some(&def::DefStaticMethod(..)) |
|
||||
Some(&def::DefVariant(..)) |
|
||||
|
|
@ -320,7 +320,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
|||
reason: ResolveReason,
|
||||
method_call: MethodCall) {
|
||||
// Resolve any method map entry
|
||||
match self.fcx.inh.method_map.borrow_mut().pop(&method_call) {
|
||||
match self.fcx.inh.method_map.borrow_mut().remove(&method_call) {
|
||||
Some(method) => {
|
||||
debug!("writeback::resolve_method_map_entry(call={}, entry={})",
|
||||
method_call,
|
||||
|
|
|
|||
|
|
@ -294,7 +294,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
|
|||
}
|
||||
|
||||
fn add_inherent_impl(&self, base_def_id: DefId, impl_def_id: DefId) {
|
||||
match self.inherent_impls.borrow().find(&base_def_id) {
|
||||
match self.inherent_impls.borrow().get(&base_def_id) {
|
||||
Some(implementation_list) => {
|
||||
implementation_list.borrow_mut().push(impl_def_id);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ impl<'cx, 'tcx> OverlapChecker<'cx, 'tcx> {
|
|||
fn push_impls_of_trait(&self,
|
||||
trait_def_id: ast::DefId,
|
||||
out: &mut Vec<ast::DefId>) {
|
||||
match self.tcx.trait_impls.borrow().find(&trait_def_id) {
|
||||
match self.tcx.trait_impls.borrow().get(&trait_def_id) {
|
||||
Some(impls) => { out.push_all(impls.borrow().as_slice()); }
|
||||
None => { /* no impls */ }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -638,7 +638,7 @@ pub fn ensure_no_ty_param_bounds(ccx: &CrateCtxt,
|
|||
let mut bounds = bounds.chain(ty_param.unbound.iter());
|
||||
for bound in bounds {
|
||||
match *bound {
|
||||
ast::TraitTyParamBound(..) | ast::UnboxedFnTyParamBound(..) => {
|
||||
ast::TraitTyParamBound(..) => {
|
||||
// According to accepted RFC #XXX, we should
|
||||
// eventually accept these, but it will not be
|
||||
// part of this PR. Still, convert to warning to
|
||||
|
|
@ -1243,7 +1243,7 @@ pub fn convert_struct(ccx: &CrateCtxt,
|
|||
let result = convert_field(ccx, &pty.generics, f, local_def(id));
|
||||
|
||||
if result.name != special_idents::unnamed_field.name {
|
||||
let dup = match seen_fields.find(&result.name) {
|
||||
let dup = match seen_fields.get(&result.name) {
|
||||
Some(prev_span) => {
|
||||
span_err!(tcx.sess, f.span, E0124,
|
||||
"field `{}` is already declared",
|
||||
|
|
@ -1340,7 +1340,8 @@ pub fn instantiate_trait_ref<'tcx,AC>(this: &AC,
|
|||
trait_did,
|
||||
Some(self_ty),
|
||||
associated_type,
|
||||
&ast_trait_ref.path);
|
||||
&ast_trait_ref.path,
|
||||
ast_trait_ref.ref_id);
|
||||
|
||||
this.tcx().trait_refs.borrow_mut().insert(ast_trait_ref.ref_id,
|
||||
trait_ref.clone());
|
||||
|
|
@ -1355,20 +1356,6 @@ pub fn instantiate_trait_ref<'tcx,AC>(this: &AC,
|
|||
}
|
||||
}
|
||||
|
||||
pub fn instantiate_unboxed_fn_ty<'tcx,AC>(this: &AC,
|
||||
unboxed_function: &ast::UnboxedFnTy,
|
||||
param_ty: ty::ParamTy)
|
||||
-> Rc<ty::TraitRef>
|
||||
where AC: AstConv<'tcx> {
|
||||
let rscope = ExplicitRscope;
|
||||
let param_ty = param_ty.to_ty(this.tcx());
|
||||
Rc::new(astconv::trait_ref_for_unboxed_function(this,
|
||||
&rscope,
|
||||
unboxed_function.kind,
|
||||
&*unboxed_function.decl,
|
||||
Some(param_ty)))
|
||||
}
|
||||
|
||||
fn get_trait_def(ccx: &CrateCtxt, trait_id: ast::DefId) -> Rc<ty::TraitDef> {
|
||||
if trait_id.krate != ast::LOCAL_CRATE {
|
||||
return ty::lookup_trait_def(ccx.tcx, trait_id)
|
||||
|
|
@ -1386,7 +1373,7 @@ fn get_trait_def(ccx: &CrateCtxt, trait_id: ast::DefId) -> Rc<ty::TraitDef> {
|
|||
pub fn trait_def_of_item(ccx: &CrateCtxt, it: &ast::Item) -> Rc<ty::TraitDef> {
|
||||
let def_id = local_def(it.id);
|
||||
let tcx = ccx.tcx;
|
||||
match tcx.trait_defs.borrow().find(&def_id) {
|
||||
match tcx.trait_defs.borrow().get(&def_id) {
|
||||
Some(def) => return def.clone(),
|
||||
_ => {}
|
||||
}
|
||||
|
|
@ -1486,7 +1473,7 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::Item)
|
|||
-> ty::Polytype {
|
||||
let def_id = local_def(it.id);
|
||||
let tcx = ccx.tcx;
|
||||
match tcx.tcache.borrow().find(&def_id) {
|
||||
match tcx.tcache.borrow().get(&def_id) {
|
||||
Some(pty) => return pty.clone(),
|
||||
_ => {}
|
||||
}
|
||||
|
|
@ -1528,7 +1515,7 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::Item)
|
|||
return pty;
|
||||
}
|
||||
ast::ItemTy(ref t, ref generics) => {
|
||||
match tcx.tcache.borrow_mut().find(&local_def(it.id)) {
|
||||
match tcx.tcache.borrow_mut().get(&local_def(it.id)) {
|
||||
Some(pty) => return pty.clone(),
|
||||
None => { }
|
||||
}
|
||||
|
|
@ -1878,7 +1865,6 @@ fn ty_generics<'tcx,AC>(this: &AC,
|
|||
// In the above example, `ast_trait_ref` is `Iterator`.
|
||||
let ast_trait_ref = match *bound {
|
||||
ast::TraitTyParamBound(ref r) => r,
|
||||
ast::UnboxedFnTyParamBound(..) => { continue; }
|
||||
ast::RegionTyParamBound(..) => { continue; }
|
||||
};
|
||||
|
||||
|
|
@ -1933,7 +1919,7 @@ fn get_or_create_type_parameter_def<'tcx,AC>(this: &AC,
|
|||
-> ty::TypeParameterDef
|
||||
where AC: AstConv<'tcx>
|
||||
{
|
||||
match this.tcx().ty_param_defs.borrow().find(¶m.id) {
|
||||
match this.tcx().ty_param_defs.borrow().get(¶m.id) {
|
||||
Some(d) => { return (*d).clone(); }
|
||||
None => { }
|
||||
}
|
||||
|
|
@ -2027,13 +2013,13 @@ fn check_bounds_compatible(tcx: &ty::ctxt,
|
|||
span: Span) {
|
||||
// Currently the only bound which is incompatible with other bounds is
|
||||
// Sized/Unsized.
|
||||
if !param_bounds.builtin_bounds.contains_elem(ty::BoundSized) {
|
||||
if !param_bounds.builtin_bounds.contains(&ty::BoundSized) {
|
||||
ty::each_bound_trait_and_supertraits(
|
||||
tcx,
|
||||
param_bounds.trait_bounds.as_slice(),
|
||||
|trait_ref| {
|
||||
let trait_def = ty::lookup_trait_def(tcx, trait_ref.def_id);
|
||||
if trait_def.bounds.builtin_bounds.contains_elem(ty::BoundSized) {
|
||||
if trait_def.bounds.builtin_bounds.contains(&ty::BoundSized) {
|
||||
span_err!(tcx.sess, span, E0129,
|
||||
"incompatible bounds on type parameter `{}`, \
|
||||
bound `{}` does not allow unsized type",
|
||||
|
|
@ -2056,45 +2042,8 @@ fn conv_param_bounds<'tcx,AC>(this: &AC,
|
|||
merge_param_bounds(this.tcx(), param_ty, ast_bounds, where_clause);
|
||||
let astconv::PartitionedBounds { builtin_bounds,
|
||||
trait_bounds,
|
||||
region_bounds,
|
||||
unboxed_fn_ty_bounds } =
|
||||
region_bounds } =
|
||||
astconv::partition_bounds(this.tcx(), span, all_bounds.as_slice());
|
||||
|
||||
let unboxed_fn_ty_bounds = unboxed_fn_ty_bounds.into_iter().map(|b| {
|
||||
let trait_id = (*this.tcx().def_map.borrow())[b.ref_id].def_id();
|
||||
let mut kind = None;
|
||||
for &(lang_item, this_kind) in [
|
||||
(this.tcx().lang_items.fn_trait(), ast::FnUnboxedClosureKind),
|
||||
(this.tcx().lang_items.fn_mut_trait(),
|
||||
ast::FnMutUnboxedClosureKind),
|
||||
(this.tcx().lang_items.fn_once_trait(),
|
||||
ast::FnOnceUnboxedClosureKind)
|
||||
].iter() {
|
||||
if Some(trait_id) == lang_item {
|
||||
kind = Some(this_kind);
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
let kind = match kind {
|
||||
Some(kind) => kind,
|
||||
None => {
|
||||
this.tcx().sess.span_err(b.path.span,
|
||||
"unboxed function trait must be one \
|
||||
of `Fn`, `FnMut`, or `FnOnce`");
|
||||
ast::FnMutUnboxedClosureKind
|
||||
}
|
||||
};
|
||||
|
||||
let rscope = ExplicitRscope;
|
||||
let param_ty = param_ty.to_ty(this.tcx());
|
||||
Rc::new(astconv::trait_ref_for_unboxed_function(this,
|
||||
&rscope,
|
||||
kind,
|
||||
&*b.decl,
|
||||
Some(param_ty)))
|
||||
});
|
||||
|
||||
let trait_bounds: Vec<Rc<ty::TraitRef>> =
|
||||
trait_bounds.into_iter()
|
||||
.map(|b| {
|
||||
|
|
@ -2103,7 +2052,6 @@ fn conv_param_bounds<'tcx,AC>(this: &AC,
|
|||
param_ty.to_ty(this.tcx()),
|
||||
Some(param_ty.to_ty(this.tcx())))
|
||||
})
|
||||
.chain(unboxed_fn_ty_bounds)
|
||||
.collect();
|
||||
let region_bounds: Vec<ty::Region> =
|
||||
region_bounds.into_iter()
|
||||
|
|
@ -2136,7 +2084,7 @@ fn merge_param_bounds<'a>(tcx: &ty::ctxt,
|
|||
let predicate_param_id =
|
||||
tcx.def_map
|
||||
.borrow()
|
||||
.find(&predicate.id)
|
||||
.get(&predicate.id)
|
||||
.expect("compute_bounds(): resolve didn't resolve the type \
|
||||
parameter identifier in a `where` clause")
|
||||
.def_id();
|
||||
|
|
|
|||
|
|
@ -1102,13 +1102,11 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
|
|||
// be passing down a map.
|
||||
ast::RegionTyParamBound(lt)
|
||||
}
|
||||
&ast::UnboxedFnTyParamBound(ref unboxed_function_type) => {
|
||||
ast::UnboxedFnTyParamBound((*unboxed_function_type).clone())
|
||||
}
|
||||
&ast::TraitTyParamBound(ref tr) => {
|
||||
let last_seg = tr.path.segments.last().unwrap();
|
||||
let mut insert = Vec::new();
|
||||
for (i, lt) in last_seg.lifetimes.iter().enumerate() {
|
||||
let lifetimes = last_seg.parameters.lifetimes();
|
||||
for (i, lt) in lifetimes.iter().enumerate() {
|
||||
if region_names.contains(<.name) {
|
||||
insert.push(i);
|
||||
}
|
||||
|
|
@ -1116,7 +1114,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
|
|||
let rebuild_info = RebuildPathInfo {
|
||||
path: &tr.path,
|
||||
indexes: insert,
|
||||
expected: last_seg.lifetimes.len(),
|
||||
expected: lifetimes.len(),
|
||||
anon_nums: &HashSet::new(),
|
||||
region_names: region_names
|
||||
};
|
||||
|
|
@ -1240,7 +1238,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
|
|||
ty_queue.push(&*mut_ty.ty);
|
||||
}
|
||||
ast::TyPath(ref path, ref bounds, id) => {
|
||||
let a_def = match self.tcx.def_map.borrow().find(&id) {
|
||||
let a_def = match self.tcx.def_map.borrow().get(&id) {
|
||||
None => {
|
||||
self.tcx
|
||||
.sess
|
||||
|
|
@ -1257,7 +1255,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
|
|||
let expected =
|
||||
generics.regions.len(subst::TypeSpace);
|
||||
let lifetimes =
|
||||
&path.segments.last().unwrap().lifetimes;
|
||||
path.segments.last().unwrap().parameters.lifetimes();
|
||||
let mut insert = Vec::new();
|
||||
if lifetimes.len() == 0 {
|
||||
let anon = self.cur_anon.get();
|
||||
|
|
@ -1357,7 +1355,8 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
|
|||
fn rebuild_path(&self,
|
||||
rebuild_info: RebuildPathInfo,
|
||||
lifetime: ast::Lifetime)
|
||||
-> ast::Path {
|
||||
-> ast::Path
|
||||
{
|
||||
let RebuildPathInfo {
|
||||
path,
|
||||
indexes,
|
||||
|
|
@ -1367,37 +1366,48 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
|
|||
} = rebuild_info;
|
||||
|
||||
let last_seg = path.segments.last().unwrap();
|
||||
let mut new_lts = Vec::new();
|
||||
if last_seg.lifetimes.len() == 0 {
|
||||
// traverse once to see if there's a need to insert lifetime
|
||||
let need_insert = range(0, expected).any(|i| {
|
||||
indexes.contains(&i)
|
||||
});
|
||||
if need_insert {
|
||||
for i in range(0, expected) {
|
||||
if indexes.contains(&i) {
|
||||
new_lts.push(lifetime);
|
||||
} else {
|
||||
new_lts.push(self.life_giver.give_lifetime());
|
||||
let new_parameters = match last_seg.parameters {
|
||||
ast::ParenthesizedParameters(..) => {
|
||||
last_seg.parameters.clone()
|
||||
}
|
||||
|
||||
ast::AngleBracketedParameters(ref data) => {
|
||||
let mut new_lts = Vec::new();
|
||||
if data.lifetimes.len() == 0 {
|
||||
// traverse once to see if there's a need to insert lifetime
|
||||
let need_insert = range(0, expected).any(|i| {
|
||||
indexes.contains(&i)
|
||||
});
|
||||
if need_insert {
|
||||
for i in range(0, expected) {
|
||||
if indexes.contains(&i) {
|
||||
new_lts.push(lifetime);
|
||||
} else {
|
||||
new_lts.push(self.life_giver.give_lifetime());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (i, lt) in data.lifetimes.iter().enumerate() {
|
||||
if indexes.contains(&i) {
|
||||
new_lts.push(lifetime);
|
||||
} else {
|
||||
new_lts.push(*lt);
|
||||
}
|
||||
}
|
||||
}
|
||||
let new_types = data.types.map(|t| {
|
||||
self.rebuild_arg_ty_or_output(&**t, lifetime, anon_nums, region_names)
|
||||
});
|
||||
ast::AngleBracketedParameters(ast::AngleBracketedParameterData {
|
||||
lifetimes: new_lts,
|
||||
types: new_types
|
||||
})
|
||||
}
|
||||
} else {
|
||||
for (i, lt) in last_seg.lifetimes.iter().enumerate() {
|
||||
if indexes.contains(&i) {
|
||||
new_lts.push(lifetime);
|
||||
} else {
|
||||
new_lts.push(*lt);
|
||||
}
|
||||
}
|
||||
}
|
||||
let new_types = last_seg.types.map(|t| {
|
||||
self.rebuild_arg_ty_or_output(&**t, lifetime, anon_nums, region_names)
|
||||
});
|
||||
};
|
||||
let new_seg = ast::PathSegment {
|
||||
identifier: last_seg.identifier,
|
||||
lifetimes: new_lts,
|
||||
types: new_types,
|
||||
parameters: new_parameters
|
||||
};
|
||||
let mut new_segs = Vec::new();
|
||||
new_segs.push_all(path.segments.init());
|
||||
|
|
|
|||
|
|
@ -367,7 +367,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
|
|||
debug!("RegionVarBindings: add_constraint({})",
|
||||
constraint.repr(self.tcx));
|
||||
|
||||
if self.constraints.borrow_mut().insert(constraint, origin) {
|
||||
if self.constraints.borrow_mut().insert(constraint, origin).is_none() {
|
||||
if self.in_snapshot() {
|
||||
self.undo_log.borrow_mut().push(AddConstraint(constraint));
|
||||
}
|
||||
|
|
@ -559,7 +559,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
|
|||
new_r: Region|)
|
||||
-> Region {
|
||||
let vars = TwoRegions { a: a, b: b };
|
||||
match self.combine_map(t).borrow().find(&vars) {
|
||||
match self.combine_map(t).borrow().get(&vars) {
|
||||
Some(&c) => {
|
||||
return ReInfer(ReVar(c));
|
||||
}
|
||||
|
|
@ -991,7 +991,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
|
|||
debug!("expansion: constraint={} origin={}",
|
||||
constraint.repr(self.tcx),
|
||||
self.constraints.borrow()
|
||||
.find(constraint)
|
||||
.get(constraint)
|
||||
.unwrap()
|
||||
.repr(self.tcx));
|
||||
match *constraint {
|
||||
|
|
@ -1075,7 +1075,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
|
|||
debug!("contraction: constraint={} origin={}",
|
||||
constraint.repr(self.tcx),
|
||||
self.constraints.borrow()
|
||||
.find(constraint)
|
||||
.get(constraint)
|
||||
.unwrap()
|
||||
.repr(self.tcx));
|
||||
match *constraint {
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ impl<'f, 'tcx> Combine<'tcx> for Sub<'f, 'tcx> {
|
|||
// e.g., fn:Copy() <: fn(), because the former is a function
|
||||
// that only closes over copyable things, but the latter is
|
||||
// any function at all.
|
||||
if a.contains(b) {
|
||||
if a.is_superset(&b) {
|
||||
Ok(a)
|
||||
} else {
|
||||
Err(ty::terr_builtin_bounds(expected_found(self, a, b)))
|
||||
|
|
|
|||
|
|
@ -301,7 +301,7 @@ pub fn write_substs_to_tcx(tcx: &ty::ctxt,
|
|||
}
|
||||
}
|
||||
pub fn lookup_def_tcx(tcx:&ty::ctxt, sp: Span, id: ast::NodeId) -> def::Def {
|
||||
match tcx.def_map.borrow().find(&id) {
|
||||
match tcx.def_map.borrow().get(&id) {
|
||||
Some(x) => x.clone(),
|
||||
_ => {
|
||||
tcx.sess.span_fatal(sp, "internal error looking up a definition")
|
||||
|
|
|
|||
|
|
@ -322,7 +322,7 @@ impl<'a, 'tcx> TermsContext<'a, 'tcx> {
|
|||
index: index,
|
||||
param_id: param_id,
|
||||
term: term });
|
||||
let newly_added = self.inferred_map.insert(param_id, inf_index);
|
||||
let newly_added = self.inferred_map.insert(param_id, inf_index).is_none();
|
||||
assert!(newly_added);
|
||||
|
||||
debug!("add_inferred(item_id={}, \
|
||||
|
|
@ -376,7 +376,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for TermsContext<'a, 'tcx> {
|
|||
if self.num_inferred() == inferreds_on_entry {
|
||||
let newly_added = self.tcx.item_variance_map.borrow_mut().insert(
|
||||
ast_util::local_def(item.id),
|
||||
self.empty_variances.clone());
|
||||
self.empty_variances.clone()).is_none();
|
||||
assert!(newly_added);
|
||||
}
|
||||
|
||||
|
|
@ -556,7 +556,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
|
|||
}
|
||||
|
||||
fn inferred_index(&self, param_id: ast::NodeId) -> InferredIndex {
|
||||
match self.terms_cx.inferred_map.find(¶m_id) {
|
||||
match self.terms_cx.inferred_map.get(¶m_id) {
|
||||
Some(&index) => index,
|
||||
None => {
|
||||
self.tcx().sess.bug(format!(
|
||||
|
|
@ -569,7 +569,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
|
|||
fn find_binding_for_lifetime(&self, param_id: ast::NodeId) -> ast::NodeId {
|
||||
let tcx = self.terms_cx.tcx;
|
||||
assert!(is_lifetime(&tcx.map, param_id));
|
||||
match tcx.named_region_map.find(¶m_id) {
|
||||
match tcx.named_region_map.get(¶m_id) {
|
||||
Some(&rl::DefEarlyBoundRegion(_, _, lifetime_decl_id))
|
||||
=> lifetime_decl_id,
|
||||
Some(_) => panic!("should not encounter non early-bound cases"),
|
||||
|
|
@ -810,7 +810,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
|
|||
|
||||
ty::ty_param(ty::ParamTy { ref def_id, .. }) => {
|
||||
assert_eq!(def_id.krate, ast::LOCAL_CRATE);
|
||||
match self.terms_cx.inferred_map.find(&def_id.node) {
|
||||
match self.terms_cx.inferred_map.get(&def_id.node) {
|
||||
Some(&index) => {
|
||||
self.add_constraint(index, variance);
|
||||
}
|
||||
|
|
@ -1060,7 +1060,7 @@ impl<'a, 'tcx> SolveContext<'a, 'tcx> {
|
|||
}
|
||||
|
||||
let newly_added = tcx.item_variance_map.borrow_mut()
|
||||
.insert(item_def_id, Rc::new(item_variances));
|
||||
.insert(item_def_id, Rc::new(item_variances)).is_none();
|
||||
assert!(newly_added);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ pub fn can_reach<S,H:Hasher<S>,T:Eq+Clone+Hash<S>>(
|
|||
let mut queue = vec!(source);
|
||||
let mut i = 0;
|
||||
while i < queue.len() {
|
||||
match edges_map.find(&queue[i]) {
|
||||
match edges_map.get(&queue[i]) {
|
||||
Some(edges) => {
|
||||
for target in edges.iter() {
|
||||
if *target == destination {
|
||||
|
|
@ -200,7 +200,7 @@ pub fn memoized_with_key<T, K: Hash<S> + Eq, U: Clone, S, H: Hasher<S>>(
|
|||
k: |&T| -> K
|
||||
) -> U {
|
||||
let key = k(&arg);
|
||||
let result = cache.borrow().find(&key).map(|result| result.clone());
|
||||
let result = cache.borrow().get(&key).map(|result| result.clone());
|
||||
match result {
|
||||
Some(result) => result,
|
||||
None => {
|
||||
|
|
|
|||
|
|
@ -451,7 +451,7 @@ pub fn ty_to_string(cx: &ctxt, typ: t) -> String {
|
|||
ty_str => "str".to_string(),
|
||||
ty_unboxed_closure(ref did, _, ref substs) => {
|
||||
let unboxed_closures = cx.unboxed_closures.borrow();
|
||||
unboxed_closures.find(did).map(|cl| {
|
||||
unboxed_closures.get(did).map(|cl| {
|
||||
closure_to_string(cx, &cl.closure_type.subst(cx, substs))
|
||||
}).unwrap_or_else(|| "closure".to_string())
|
||||
}
|
||||
|
|
@ -1108,7 +1108,7 @@ impl UserString for ty::ParamBounds {
|
|||
|
||||
impl UserString for ty::ExistentialBounds {
|
||||
fn user_string(&self, tcx: &ctxt) -> String {
|
||||
if self.builtin_bounds.contains_elem(ty::BoundSend) &&
|
||||
if self.builtin_bounds.contains(&ty::BoundSend) &&
|
||||
self.region_bound == ty::ReStatic
|
||||
{ // Region bound is implied by builtin bounds:
|
||||
return self.builtin_bounds.repr(tcx);
|
||||
|
|
@ -1277,7 +1277,7 @@ impl UserString for ParamTy {
|
|||
fn user_string(&self, tcx: &ctxt) -> String {
|
||||
let id = self.idx;
|
||||
let did = self.def_id;
|
||||
let ident = match tcx.ty_param_defs.borrow().find(&did.node) {
|
||||
let ident = match tcx.ty_param_defs.borrow().get(&did.node) {
|
||||
Some(def) => token::get_name(def.name).get().to_string(),
|
||||
|
||||
// This can only happen when a type mismatch error happens and
|
||||
|
|
|
|||
|
|
@ -14,6 +14,9 @@ pub const box_field_refcnt: uint = 0u;
|
|||
pub const box_field_drop_glue: uint = 1u;
|
||||
pub const box_field_body: uint = 4u;
|
||||
|
||||
// FIXME(18590) although we have three different layouts here, the compiler relies on
|
||||
// them being the same. We should replace them with one set of constants.
|
||||
|
||||
// The two halves of a closure: code and environment.
|
||||
pub const fn_field_code: uint = 0u;
|
||||
pub const fn_field_box: uint = 1u;
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ pub fn target() -> Target {
|
|||
// linker doesn't like that by default.
|
||||
base.pre_link_args.push("-Wl,--allow-multiple-definition".to_string());
|
||||
// FIXME #17437 (and #17448): Android doesn't support position dependant executables anymore.
|
||||
base.position_independant_executables = false;
|
||||
base.position_independent_executables = false;
|
||||
|
||||
Target {
|
||||
data_layout: "e-p:32:32:32\
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ pub fn target() -> Target {
|
|||
-f32:32:32-f64:64:64\
|
||||
-v64:64:64-v128:64:128\
|
||||
-a0:0:64-n32".to_string(),
|
||||
llvm_target: "arm-unknown-linux-gnueabi".to_string(),
|
||||
llvm_target: "arm-unknown-linux-gnueabihf".to_string(),
|
||||
target_endian: "little".to_string(),
|
||||
target_word_size: "32".to_string(),
|
||||
arch: "arm".to_string(),
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
use target::Target;
|
||||
|
||||
pub fn target() -> Target {
|
||||
let mut base = super::draginfly_base::opts();
|
||||
let mut base = super::dragonfly_base::opts();
|
||||
base.pre_link_args.push("-m32".to_string());
|
||||
|
||||
Target {
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ pub fn opts() -> TargetOptions {
|
|||
// follow this flag. Thus, use it before specifying libraries to link to.
|
||||
"-Wl,--as-needed".to_string(),
|
||||
),
|
||||
position_independant_executables: true,
|
||||
position_independent_executables: true,
|
||||
.. Default::default()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ mod arm_unknown_linux_gnueabihf;
|
|||
mod i686_apple_darwin;
|
||||
mod i386_apple_ios;
|
||||
mod i686_pc_windows_gnu;
|
||||
mod i686_unknown_dragonfly;
|
||||
mod i686_unknown_linux_gnu;
|
||||
mod mips_unknown_linux_gnu;
|
||||
mod mipsel_unknown_linux_gnu;
|
||||
|
|
@ -158,7 +159,7 @@ pub struct TargetOptions {
|
|||
/// relocation model of position independent code is not changed. This is a requirement to take
|
||||
/// advantage of ASLR, as otherwise the functions in the executable are not randomized and can
|
||||
/// be used during an exploit of a vulnerability in any code.
|
||||
pub position_independant_executables: bool,
|
||||
pub position_independent_executables: bool,
|
||||
}
|
||||
|
||||
impl Default for TargetOptions {
|
||||
|
|
@ -189,7 +190,7 @@ impl Default for TargetOptions {
|
|||
linker_is_gnu: false,
|
||||
has_rpath: false,
|
||||
no_compiler_rt: false,
|
||||
position_independant_executables: false,
|
||||
position_independent_executables: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -338,6 +339,7 @@ impl Target {
|
|||
|
||||
x86_64_unknown_freebsd,
|
||||
|
||||
i686_unknown_dragonfly,
|
||||
x86_64_unknown_dragonfly,
|
||||
|
||||
x86_64_apple_darwin,
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue