Merge remote-tracking branch 'origin/master' into rollup

Conflicts:
	src/libcollections/slice.rs
	src/libcore/nonzero.rs
	src/libcore/ops.rs
This commit is contained in:
Manish Goregaokar 2015-01-28 23:03:36 +05:30
commit c709ed2faf
340 changed files with 5765 additions and 3761 deletions

View File

@ -301,6 +301,7 @@ tidy:
| grep '^$(S)src/rust-installer' -v \
| xargs $(CFG_PYTHON) $(S)src/etc/check-binaries.py
$(Q) $(CFG_PYTHON) $(S)src/etc/errorck.py $(S)src/
$(Q) $(CFG_PYTHON) $(S)src/etc/featureck.py $(S)src/
endif

View File

@ -13,7 +13,15 @@
#![feature(slicing_syntax, unboxed_closures)]
#![feature(box_syntax)]
#![feature(int_uint)]
#![allow(unstable)]
#![feature(test)]
#![feature(rustc_private)]
#![feature(std_misc)]
#![feature(path)]
#![feature(io)]
#![feature(core)]
#![feature(collections)]
#![feature(os)]
#![feature(unicode)]
#![deny(warnings)]

View File

@ -2359,77 +2359,6 @@ Supported traits for `derive` are:
* `Show`, to format a value using the `{}` formatter.
* `Zero`, to create a zero instance of a numeric data type.
### Stability
One can indicate the stability of an API using the following attributes:
* `deprecated`: This item should no longer be used, e.g. it has been
replaced. No guarantee of backwards-compatibility.
* `experimental`: This item was only recently introduced or is
otherwise in a state of flux. It may change significantly, or even
be removed. No guarantee of backwards-compatibility.
* `unstable`: This item is still under development, but requires more
testing to be considered stable. No guarantee of backwards-compatibility.
* `stable`: This item is considered stable, and will not change
significantly. Guarantee of backwards-compatibility.
* `frozen`: This item is very stable, and is unlikely to
change. Guarantee of backwards-compatibility.
* `locked`: This item will never change unless a serious bug is
found. Guarantee of backwards-compatibility.
These levels are directly inspired by
[Node.js' "stability index"](http://nodejs.org/api/documentation.html).
Stability levels are inherited, so an item's stability attribute is the default
stability for everything nested underneath it.
There are lints for disallowing items marked with certain levels: `deprecated`,
`experimental` and `unstable`. For now, only `deprecated` warns by default, but
this will change once the standard library has been stabilized. Stability
levels are meant to be promises at the crate level, so these lints only apply
when referencing items from an _external_ crate, not to items defined within
the current crate. Items with no stability level are considered to be unstable
for the purposes of the lint. One can give an optional string that will be
displayed when the lint flags the use of an item.
For example, if we define one crate called `stability_levels`:
```{.ignore}
#[deprecated="replaced by `best`"]
pub fn bad() {
// delete everything
}
pub fn better() {
// delete fewer things
}
#[stable]
pub fn best() {
// delete nothing
}
```
then the lints will work as follows for a client crate:
```{.ignore}
#![warn(unstable)]
extern crate stability_levels;
use stability_levels::{bad, better, best};
fn main() {
bad(); // "warning: use of deprecated item: replaced by `best`"
better(); // "warning: use of unmarked item"
best(); // no warning
}
```
> **Note:** Currently these are only checked when applied to individual
> functions, structs, methods and enum variants, *not* to entire modules,
> traits, impls or enums themselves.
### Compiler Features
Certain aspects of Rust may be implemented in the compiler, but they're not

View File

@ -8,7 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![allow(unstable)]
#![allow(unknown_features)]
#![cfg_attr(rustc, feature(rustc_private))]
#![cfg_attr(rustdoc, feature(rustdoc))]
#[cfg(rustdoc)]
extern crate "rustdoc" as this;

243
src/etc/featureck.py Normal file
View File

@ -0,0 +1,243 @@
# Copyright 2015 The Rust Project Developers. See the COPYRIGHT
# file at the top-level directory of this distribution and at
# http://rust-lang.org/COPYRIGHT.
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.
# This script does a tree-wide sanity checks against stability
# attributes, currently:
# * For all feature_name/level pairs the 'since' field is the same
# * That no features are both stable and unstable.
# * That lib features don't have the same name as lang features
# unless they are on the 'joint_features' whitelist
# * That features that exist in both lang and lib and are stable
# since the same version
# * Prints information about features
import sys, os, re
src_dir = sys.argv[1]
# Features that are allowed to exist in both the language and the library
joint_features = [ ]
# Grab the list of language features from the compiler
language_gate_statuses = [ "Active", "Deprecated", "Removed", "Accepted" ]
feature_gate_source = os.path.join(src_dir, "libsyntax", "feature_gate.rs")
language_features = []
language_feature_names = []
with open(feature_gate_source, 'r') as f:
for line in f:
original_line = line
line = line.strip()
is_feature_line = False
for status in language_gate_statuses:
if status in line and line.startswith("("):
is_feature_line = True
if is_feature_line:
line = line.replace("(", "").replace("),", "").replace(")", "")
parts = line.split(",")
if len(parts) != 3:
print "error: unexpected number of components in line: " + original_line
sys.exit(1)
feature_name = parts[0].strip().replace('"', "")
since = parts[1].strip().replace('"', "")
status = parts[2].strip()
assert len(feature_name) > 0
assert len(since) > 0
assert len(status) > 0
language_feature_names += [feature_name]
language_features += [(feature_name, since, status)]
assert len(language_features) > 0
errors = False
lib_features = { }
lib_features_and_level = { }
for (dirpath, dirnames, filenames) in os.walk(src_dir):
# Don't look for feature names in tests
if "src/test" in dirpath:
continue
# Takes a long time to traverse LLVM
if "src/llvm" in dirpath:
continue
for filename in filenames:
if not filename.endswith(".rs"):
continue
path = os.path.join(dirpath, filename)
with open(path, 'r') as f:
line_num = 0
for line in f:
line_num += 1
level = None
if "[unstable(" in line:
level = "unstable"
elif "[stable(" in line:
level = "stable"
else:
continue
# This is a stability attribute. For the purposes of this
# script we expect both the 'feature' and 'since' attributes on
# the same line, e.g.
# `#[unstable(feature = "foo", since = "1.0.0")]`
p = re.compile('(unstable|stable).*feature *= *"(\w*)"')
m = p.search(line)
if not m is None:
feature_name = m.group(2)
since = None
if re.compile("\[ *stable").search(line) is not None:
pp = re.compile('since *= *"([\w\.]*)"')
mm = pp.search(line)
if not mm is None:
since = mm.group(1)
else:
print "error: misformed stability attribute"
print "line " + str(line_num) + " of " + path + ":"
print line
errors = True
lib_features[feature_name] = feature_name
if lib_features_and_level.get((feature_name, level)) is None:
# Add it to the observed features
lib_features_and_level[(feature_name, level)] = \
(since, path, line_num, line)
else:
# Verify that for this combination of feature_name and level the 'since'
# attribute matches.
(expected_since, source_path, source_line_num, source_line) = \
lib_features_and_level.get((feature_name, level))
if since != expected_since:
print "error: mismatch in " + level + " feature '" + feature_name + "'"
print "line " + str(source_line_num) + " of " + source_path + ":"
print source_line
print "line " + str(line_num) + " of " + path + ":"
print line
errors = True
# Verify that this lib feature doesn't duplicate a lang feature
if feature_name in language_feature_names:
print "error: lib feature '" + feature_name + "' duplicates a lang feature"
print "line " + str(line_num) + " of " + path + ":"
print line
errors = True
else:
print "error: misformed stability attribute"
print "line " + str(line_num) + " of " + path + ":"
print line
errors = True
# Merge data about both lists
# name, lang, lib, status, stable since
language_feature_stats = {}
for f in language_features:
name = f[0]
lang = True
lib = False
status = "unstable"
stable_since = None
if f[2] == "Accepted":
status = "stable"
if status == "stable":
stable_since = f[1]
language_feature_stats[name] = (name, lang, lib, status, stable_since)
lib_feature_stats = {}
for f in lib_features:
name = f
lang = False
lib = True
status = "unstable"
stable_since = None
is_stable = lib_features_and_level.get((name, "stable")) is not None
is_unstable = lib_features_and_level.get((name, "unstable")) is not None
if is_stable and is_unstable:
print "error: feature '" + name + "' is both stable and unstable"
errors = True
if is_stable:
status = "stable"
stable_since = lib_features_and_level[(name, "stable")][0]
elif is_unstable:
status = "unstable"
lib_feature_stats[name] = (name, lang, lib, status, stable_since)
# Check for overlap in two sets
merged_stats = { }
for name in lib_feature_stats:
if language_feature_stats.get(name) is not None:
if not name in joint_features:
print "error: feature '" + name + "' is both a lang and lib feature but not whitelisted"
errors = True
lang_status = lang_feature_stats[name][3]
lib_status = lib_feature_stats[name][3]
lang_stable_since = lang_feature_stats[name][4]
lib_stable_since = lib_feature_stats[name][4]
if lang_status != lib_status and lib_status != "deprecated":
print "error: feature '" + name + "' has lang status " + lang_status + \
" but lib status " + lib_status
errors = True
if lang_stable_since != lib_stable_since:
print "error: feature '" + name + "' has lang stable since " + lang_stable_since + \
" but lib stable since " + lib_stable_since
errors = True
merged_stats[name] = (name, True, True, lang_status, lang_stable_since)
del language_feature_stats[name]
del lib_feature_stats[name]
if errors:
sys.exit(1)
# Finally, display the stats
stats = {}
stats.update(language_feature_stats)
stats.update(lib_feature_stats)
stats.update(merged_stats)
lines = []
for s in stats:
s = stats[s]
type_ = "lang"
if s[1] and s[2]:
type_ = "lang/lib"
elif s[2]:
type_ = "lib"
line = "{: <32}".format(s[0]) + \
"{: <8}".format(type_) + \
"{: <12}".format(s[3]) + \
"{: <8}".format(str(s[4]))
lines += [line]
lines.sort()
print
print "Rust feature summary:"
print
for line in lines:
print line
print

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![stable]
#![stable(feature = "rust1", since = "1.0.0")]
//! Threadsafe reference-counted boxes (the `Arc<T>` type).
//!
@ -110,7 +110,7 @@ use heap::deallocate;
/// }
/// ```
#[unsafe_no_drop_flag]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Arc<T> {
// FIXME #12808: strange name to try to avoid interfering with
// field accesses of the contained type via Deref
@ -126,7 +126,8 @@ unsafe impl<T: Sync + Send> Sync for Arc<T> { }
/// Weak pointers will not keep the data inside of the `Arc` alive, and can be used to break cycles
/// between `Arc` pointers.
#[unsafe_no_drop_flag]
#[unstable = "Weak pointers may not belong in this module."]
#[unstable(feature = "alloc",
reason = "Weak pointers may not belong in this module.")]
pub struct Weak<T> {
// FIXME #12808: strange name to try to avoid interfering with
// field accesses of the contained type via Deref
@ -156,7 +157,7 @@ impl<T> Arc<T> {
/// let five = Arc::new(5i);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new(data: T) -> Arc<T> {
// Start the weak pointer count as 1 which is the weak pointer that's
// held by all the strong pointers (kinda), see std/rc.rs for more info
@ -179,7 +180,8 @@ impl<T> Arc<T> {
///
/// let weak_five = five.downgrade();
/// ```
#[unstable = "Weak pointers may not belong in this module."]
#[unstable(feature = "alloc",
reason = "Weak pointers may not belong in this module.")]
pub fn downgrade(&self) -> Weak<T> {
// See the clone() impl for why this is relaxed
self.inner().weak.fetch_add(1, Relaxed);
@ -200,15 +202,15 @@ impl<T> Arc<T> {
/// Get the number of weak references to this value.
#[inline]
#[unstable]
#[unstable(feature = "alloc")]
pub fn weak_count<T>(this: &Arc<T>) -> uint { this.inner().weak.load(SeqCst) - 1 }
/// Get the number of strong references to this value.
#[inline]
#[unstable]
#[unstable(feature = "alloc")]
pub fn strong_count<T>(this: &Arc<T>) -> uint { this.inner().strong.load(SeqCst) }
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Clone for Arc<T> {
/// Makes a clone of the `Arc<T>`.
///
@ -245,7 +247,7 @@ impl<T> BorrowFrom<Arc<T>> for T {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Deref for Arc<T> {
type Target = T;
@ -271,7 +273,7 @@ impl<T: Send + Sync + Clone> Arc<T> {
/// let mut_five = five.make_unique();
/// ```
#[inline]
#[unstable]
#[unstable(feature = "alloc")]
pub fn make_unique(&mut self) -> &mut T {
// Note that we hold a strong reference, which also counts as a weak reference, so we only
// clone if there is an additional reference of either kind.
@ -289,7 +291,7 @@ impl<T: Send + Sync + Clone> Arc<T> {
}
#[unsafe_destructor]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Sync + Send> Drop for Arc<T> {
/// Drops the `Arc<T>`.
///
@ -355,7 +357,8 @@ impl<T: Sync + Send> Drop for Arc<T> {
}
}
#[unstable = "Weak pointers may not belong in this module."]
#[unstable(feature = "alloc",
reason = "Weak pointers may not belong in this module.")]
impl<T: Sync + Send> Weak<T> {
/// Upgrades a weak reference to a strong reference.
///
@ -393,7 +396,8 @@ impl<T: Sync + Send> Weak<T> {
}
}
#[unstable = "Weak pointers may not belong in this module."]
#[unstable(feature = "alloc",
reason = "Weak pointers may not belong in this module.")]
impl<T: Sync + Send> Clone for Weak<T> {
/// Makes a clone of the `Weak<T>`.
///
@ -417,7 +421,7 @@ impl<T: Sync + Send> Clone for Weak<T> {
}
#[unsafe_destructor]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Sync + Send> Drop for Weak<T> {
/// Drops the `Weak<T>`.
///
@ -460,7 +464,7 @@ impl<T: Sync + Send> Drop for Weak<T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: PartialEq> PartialEq for Arc<T> {
/// Equality for two `Arc<T>`s.
///
@ -492,7 +496,7 @@ impl<T: PartialEq> PartialEq for Arc<T> {
/// ```
fn ne(&self, other: &Arc<T>) -> bool { *(*self) != *(*other) }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: PartialOrd> PartialOrd for Arc<T> {
/// Partial comparison for two `Arc<T>`s.
///
@ -571,30 +575,30 @@ impl<T: PartialOrd> PartialOrd for Arc<T> {
/// ```
fn ge(&self, other: &Arc<T>) -> bool { *(*self) >= *(*other) }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Ord> Ord for Arc<T> {
fn cmp(&self, other: &Arc<T>) -> Ordering { (**self).cmp(&**other) }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Eq> Eq for Arc<T> {}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: fmt::Display> fmt::Display for Arc<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(&**self, f)
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: fmt::Debug> fmt::Debug for Arc<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Debug::fmt(&**self, f)
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Default + Sync + Send> Default for Arc<T> {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn default() -> Arc<T> { Arc::new(Default::default()) }
}
@ -605,7 +609,6 @@ impl<H: Hasher, T: Hash<H>> Hash<H> for Arc<T> {
}
#[cfg(test)]
#[allow(unstable)]
mod tests {
use std::clone::Clone;
use std::sync::mpsc::channel;

View File

@ -43,7 +43,7 @@
//!
//! This will print `Cons(1i32, Box(Cons(2i32, Box(Nil))))`.
#![stable]
#![stable(feature = "rust1", since = "1.0.0")]
use core::any::Any;
use core::clone::Clone;
@ -77,14 +77,15 @@ use core::result::Result;
/// }
/// ```
#[lang = "exchange_heap"]
#[unstable = "may be renamed; uncertain about custom allocator design"]
#[unstable(feature = "alloc",
reason = "may be renamed; uncertain about custom allocator design")]
pub static HEAP: () = ();
/// A pointer type for heap allocation.
///
/// See the [module-level documentation](../../std/boxed/index.html) for more.
#[lang = "owned_box"]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Box<T>(Unique<T>);
impl<T> Box<T> {
@ -95,25 +96,25 @@ impl<T> Box<T> {
/// ```
/// let x = Box::new(5);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new(x: T) -> Box<T> {
box x
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Default> Default for Box<T> {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn default() -> Box<T> { box Default::default() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Default for Box<[T]> {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn default() -> Box<[T]> { box [] }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Clone> Clone for Box<T> {
/// Returns a new box with a `clone()` of this box's contents.
///
@ -144,14 +145,14 @@ impl<T: Clone> Clone for Box<T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized + PartialEq> PartialEq for Box<T> {
#[inline]
fn eq(&self, other: &Box<T>) -> bool { PartialEq::eq(&**self, &**other) }
#[inline]
fn ne(&self, other: &Box<T>) -> bool { PartialEq::ne(&**self, &**other) }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized + PartialOrd> PartialOrd for Box<T> {
#[inline]
fn partial_cmp(&self, other: &Box<T>) -> Option<Ordering> {
@ -166,14 +167,14 @@ impl<T: ?Sized + PartialOrd> PartialOrd for Box<T> {
#[inline]
fn gt(&self, other: &Box<T>) -> bool { PartialOrd::gt(&**self, &**other) }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized + Ord> Ord for Box<T> {
#[inline]
fn cmp(&self, other: &Box<T>) -> Ordering {
Ord::cmp(&**self, &**other)
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized + Eq> Eq for Box<T> {}
impl<S: hash::Hasher, T: ?Sized + Hash<S>> Hash<S> for Box<T> {
@ -184,19 +185,20 @@ impl<S: hash::Hasher, T: ?Sized + Hash<S>> Hash<S> for Box<T> {
}
/// Extension methods for an owning `Any` trait object.
#[unstable = "this trait will likely disappear once compiler bugs blocking \
a direct impl on `Box<Any>` have been fixed "]
#[unstable(feature = "alloc",
reason = "this trait will likely disappear once compiler bugs blocking \
a direct impl on `Box<Any>` have been fixed ")]
// FIXME(#18737): this should be a direct impl on `Box<Any>`. If you're
// removing this please make sure that you can downcase on
// `Box<Any + Send>` as well as `Box<Any>`
pub trait BoxAny {
/// Returns the boxed value if it is of type `T`, or
/// `Err(Self)` if it isn't.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn downcast<T: 'static>(self) -> Result<Box<T>, Self>;
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl BoxAny for Box<Any> {
#[inline]
fn downcast<T: 'static>(self) -> Result<Box<T>, Box<Any>> {
@ -215,35 +217,35 @@ impl BoxAny for Box<Any> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: fmt::Display + ?Sized> fmt::Display for Box<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(&**self, f)
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: fmt::Debug + ?Sized> fmt::Debug for Box<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Debug::fmt(&**self, f)
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl fmt::Debug for Box<Any> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("Box<Any>")
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized> Deref for Box<T> {
type Target = T;
fn deref(&self) -> &T { &**self }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized> DerefMut for Box<T> {
fn deref_mut(&mut self) -> &mut T { &mut **self }
}

View File

@ -80,7 +80,7 @@ pub fn usable_size(size: uint, align: uint) -> uint {
///
/// These statistics may be inconsistent if other threads use the allocator
/// during the call.
#[unstable]
#[unstable(feature = "alloc")]
pub fn stats_print() {
imp::stats_print();
}

View File

@ -57,7 +57,8 @@
//! default global allocator. It is not compatible with the libc allocator API.
#![crate_name = "alloc"]
#![unstable]
#![unstable(feature = "alloc")]
#![feature(staged_api)]
#![staged_api]
#![crate_type = "rlib"]
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
@ -66,13 +67,15 @@
#![no_std]
#![allow(unknown_features)]
#![allow(unstable)]
#![feature(lang_items, unsafe_destructor)]
#![feature(box_syntax)]
#![feature(optin_builtin_traits)]
// FIXME(#21363) remove `old_impl_check` when bug is fixed
#![feature(old_impl_check)]
#![allow(unknown_features)] #![feature(int_uint)]
#![feature(core)]
#![feature(hash)]
#![feature(libc)]
#[macro_use]
extern crate core;

View File

@ -142,7 +142,7 @@
//! }
//! ```
#![stable]
#![stable(feature = "rust1", since = "1.0.0")]
use core::borrow::BorrowFrom;
use core::cell::Cell;
@ -173,7 +173,7 @@ struct RcBox<T> {
///
/// See the [module level documentation](../index.html) for more details.
#[unsafe_no_drop_flag]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Rc<T> {
// FIXME #12808: strange names to try to avoid interfering with field accesses of the contained
// type via Deref
@ -185,7 +185,6 @@ impl<T> !marker::Send for Rc<T> {}
impl<T> !marker::Sync for Rc<T> {}
impl<T> Rc<T> {
/// Constructs a new `Rc<T>`.
///
/// # Examples
@ -195,7 +194,7 @@ impl<T> Rc<T> {
///
/// let five = Rc::new(5i);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new(value: T) -> Rc<T> {
unsafe {
Rc {
@ -222,7 +221,8 @@ impl<T> Rc<T> {
///
/// let weak_five = five.downgrade();
/// ```
#[unstable = "Weak pointers may not belong in this module"]
#[unstable(feature = "alloc",
reason = "Weak pointers may not belong in this module")]
pub fn downgrade(&self) -> Weak<T> {
self.inc_weak();
Weak { _ptr: self._ptr }
@ -231,12 +231,12 @@ impl<T> Rc<T> {
/// Get the number of weak references to this value.
#[inline]
#[unstable]
#[unstable(feature = "alloc")]
pub fn weak_count<T>(this: &Rc<T>) -> uint { this.weak() - 1 }
/// Get the number of strong references to this value.
#[inline]
#[unstable]
#[unstable(feature = "alloc")]
pub fn strong_count<T>(this: &Rc<T>) -> uint { this.strong() }
/// Returns true if there are no other `Rc` or `Weak<T>` values that share the same inner value.
@ -252,7 +252,7 @@ pub fn strong_count<T>(this: &Rc<T>) -> uint { this.strong() }
/// rc::is_unique(&five);
/// ```
#[inline]
#[unstable]
#[unstable(feature = "alloc")]
pub fn is_unique<T>(rc: &Rc<T>) -> bool {
weak_count(rc) == 0 && strong_count(rc) == 1
}
@ -274,7 +274,7 @@ pub fn is_unique<T>(rc: &Rc<T>) -> bool {
/// assert_eq!(rc::try_unwrap(x), Err(Rc::new(4u)));
/// ```
#[inline]
#[unstable]
#[unstable(feature = "alloc")]
pub fn try_unwrap<T>(rc: Rc<T>) -> Result<T, Rc<T>> {
if is_unique(&rc) {
unsafe {
@ -308,7 +308,7 @@ pub fn try_unwrap<T>(rc: Rc<T>) -> Result<T, Rc<T>> {
/// assert!(rc::get_mut(&mut x).is_none());
/// ```
#[inline]
#[unstable]
#[unstable(feature = "alloc")]
pub fn get_mut<'a, T>(rc: &'a mut Rc<T>) -> Option<&'a mut T> {
if is_unique(rc) {
let inner = unsafe { &mut **rc._ptr };
@ -334,7 +334,7 @@ impl<T: Clone> Rc<T> {
/// let mut_five = five.make_unique();
/// ```
#[inline]
#[unstable]
#[unstable(feature = "alloc")]
pub fn make_unique(&mut self) -> &mut T {
if !is_unique(self) {
*self = Rc::new((**self).clone())
@ -354,7 +354,7 @@ impl<T> BorrowFrom<Rc<T>> for T {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Deref for Rc<T> {
type Target = T;
@ -365,7 +365,7 @@ impl<T> Deref for Rc<T> {
}
#[unsafe_destructor]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Drop for Rc<T> {
/// Drops the `Rc<T>`.
///
@ -413,7 +413,7 @@ impl<T> Drop for Rc<T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Clone for Rc<T> {
/// Makes a clone of the `Rc<T>`.
@ -436,7 +436,7 @@ impl<T> Clone for Rc<T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Default> Default for Rc<T> {
/// Creates a new `Rc<T>`, with the `Default` value for `T`.
///
@ -449,13 +449,13 @@ impl<T: Default> Default for Rc<T> {
/// let x: Rc<int> = Default::default();
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn default() -> Rc<T> {
Rc::new(Default::default())
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: PartialEq> PartialEq for Rc<T> {
/// Equality for two `Rc<T>`s.
///
@ -490,10 +490,10 @@ impl<T: PartialEq> PartialEq for Rc<T> {
fn ne(&self, other: &Rc<T>) -> bool { **self != **other }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Eq> Eq for Rc<T> {}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: PartialOrd> PartialOrd for Rc<T> {
/// Partial comparison for two `Rc<T>`s.
///
@ -578,7 +578,7 @@ impl<T: PartialOrd> PartialOrd for Rc<T> {
fn ge(&self, other: &Rc<T>) -> bool { **self >= **other }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Ord> Ord for Rc<T> {
/// Comparison for two `Rc<T>`s.
///
@ -605,14 +605,14 @@ impl<S: hash::Hasher, T: Hash<S>> Hash<S> for Rc<T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: fmt::Display> fmt::Display for Rc<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(&**self, f)
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: fmt::Debug> fmt::Debug for Rc<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Debug::fmt(&**self, f)
@ -625,21 +625,21 @@ impl<T: fmt::Debug> fmt::Debug for Rc<T> {
///
/// See the [module level documentation](../index.html) for more.
#[unsafe_no_drop_flag]
#[unstable = "Weak pointers may not belong in this module."]
#[unstable(feature = "alloc",
reason = "Weak pointers may not belong in this module.")]
pub struct Weak<T> {
// FIXME #12808: strange names to try to avoid interfering with
// field accesses of the contained type via Deref
_ptr: NonZero<*mut RcBox<T>>,
}
#[allow(unstable)]
impl<T> !marker::Send for Weak<T> {}
#[allow(unstable)]
impl<T> !marker::Sync for Weak<T> {}
#[unstable = "Weak pointers may not belong in this module."]
#[unstable(feature = "alloc",
reason = "Weak pointers may not belong in this module.")]
impl<T> Weak<T> {
/// Upgrades a weak reference to a strong reference.
@ -670,7 +670,7 @@ impl<T> Weak<T> {
}
#[unsafe_destructor]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Drop for Weak<T> {
/// Drops the `Weak<T>`.
///
@ -713,7 +713,8 @@ impl<T> Drop for Weak<T> {
}
}
#[unstable = "Weak pointers may not belong in this module."]
#[unstable(feature = "alloc",
reason = "Weak pointers may not belong in this module.")]
impl<T> Clone for Weak<T> {
/// Makes a clone of the `Weak<T>`.
@ -736,7 +737,7 @@ impl<T> Clone for Weak<T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: fmt::Debug> fmt::Debug for Weak<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "(Weak)")
@ -777,7 +778,6 @@ impl<T> RcBoxPtr<T> for Weak<T> {
}
#[cfg(test)]
#[allow(unstable)]
mod tests {
use super::{Rc, Weak, weak_count, strong_count};
use std::cell::RefCell;

View File

@ -20,7 +20,8 @@
//! more complex, slower arena which can hold objects of any type.
#![crate_name = "arena"]
#![unstable]
#![unstable(feature = "rustc_private")]
#![feature(staged_api)]
#![staged_api]
#![crate_type = "rlib"]
#![crate_type = "dylib"]
@ -34,7 +35,10 @@
#![feature(box_syntax)]
#![allow(unknown_features)] #![feature(int_uint)]
#![allow(missing_docs)]
#![allow(unstable)]
#![feature(alloc)]
#![feature(core)]
#![cfg_attr(test, feature(test))]
#![cfg_attr(test, feature(collections))]
extern crate alloc;

View File

@ -148,7 +148,7 @@
//! ```
#![allow(missing_docs)]
#![stable]
#![stable(feature = "rust1", since = "1.0.0")]
use core::prelude::*;
@ -164,12 +164,12 @@ use vec::{self, Vec};
///
/// This will be a max-heap.
#[derive(Clone)]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct BinaryHeap<T> {
data: Vec<T>,
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Ord> Default for BinaryHeap<T> {
#[inline]
fn default() -> BinaryHeap<T> { BinaryHeap::new() }
@ -185,7 +185,7 @@ impl<T: Ord> BinaryHeap<T> {
/// let mut heap = BinaryHeap::new();
/// heap.push(4u);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new() -> BinaryHeap<T> { BinaryHeap { data: vec![] } }
/// Creates an empty `BinaryHeap` with a specific capacity.
@ -200,7 +200,7 @@ impl<T: Ord> BinaryHeap<T> {
/// let mut heap = BinaryHeap::with_capacity(10);
/// heap.push(4u);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn with_capacity(capacity: uint) -> BinaryHeap<T> {
BinaryHeap { data: Vec::with_capacity(capacity) }
}
@ -238,7 +238,7 @@ impl<T: Ord> BinaryHeap<T> {
/// println!("{}", x);
/// }
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn iter(&self) -> Iter<T> {
Iter { iter: self.data.iter() }
}
@ -259,7 +259,7 @@ impl<T: Ord> BinaryHeap<T> {
/// println!("{}", x);
/// }
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn into_iter(self) -> IntoIter<T> {
IntoIter { iter: self.data.into_iter() }
}
@ -279,7 +279,7 @@ impl<T: Ord> BinaryHeap<T> {
/// assert_eq!(heap.peek(), Some(&5));
///
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn peek(&self) -> Option<&T> {
self.data.get(0)
}
@ -294,7 +294,7 @@ impl<T: Ord> BinaryHeap<T> {
/// assert!(heap.capacity() >= 100);
/// heap.push(4u);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn capacity(&self) -> uint { self.data.capacity() }
/// Reserves the minimum capacity for exactly `additional` more elements to be inserted in the
@ -317,7 +317,7 @@ impl<T: Ord> BinaryHeap<T> {
/// assert!(heap.capacity() >= 100);
/// heap.push(4u);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn reserve_exact(&mut self, additional: uint) {
self.data.reserve_exact(additional);
}
@ -338,13 +338,13 @@ impl<T: Ord> BinaryHeap<T> {
/// assert!(heap.capacity() >= 100);
/// heap.push(4u);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn reserve(&mut self, additional: uint) {
self.data.reserve(additional);
}
/// Discards as much additional capacity as possible.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn shrink_to_fit(&mut self) {
self.data.shrink_to_fit();
}
@ -362,7 +362,7 @@ impl<T: Ord> BinaryHeap<T> {
/// assert_eq!(heap.pop(), Some(1));
/// assert_eq!(heap.pop(), None);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn pop(&mut self) -> Option<T> {
self.data.pop().map(|mut item| {
if !self.is_empty() {
@ -387,7 +387,7 @@ impl<T: Ord> BinaryHeap<T> {
/// assert_eq!(heap.len(), 3);
/// assert_eq!(heap.peek(), Some(&5));
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn push(&mut self, item: T) {
let old_len = self.len();
self.data.push(item);
@ -542,40 +542,41 @@ impl<T: Ord> BinaryHeap<T> {
}
/// Returns the length of the binary heap.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn len(&self) -> uint { self.data.len() }
/// Checks if the binary heap is empty.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_empty(&self) -> bool { self.len() == 0 }
/// Clears the binary heap, returning an iterator over the removed elements.
#[inline]
#[unstable = "matches collection reform specification, waiting for dust to settle"]
#[unstable(feature = "collections",
reason = "matches collection reform specification, waiting for dust to settle")]
pub fn drain(&mut self) -> Drain<T> {
Drain { iter: self.data.drain() }
}
/// Drops all items from the binary heap.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn clear(&mut self) { self.drain(); }
}
/// `BinaryHeap` iterator.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Iter <'a, T: 'a> {
iter: slice::Iter<'a, T>,
}
// FIXME(#19839) Remove in favor of `#[derive(Clone)]`
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> Clone for Iter<'a, T> {
fn clone(&self) -> Iter<'a, T> {
Iter { iter: self.iter.clone() }
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> Iterator for Iter<'a, T> {
type Item = &'a T;
@ -586,22 +587,22 @@ impl<'a, T> Iterator for Iter<'a, T> {
fn size_hint(&self) -> (uint, Option<uint>) { self.iter.size_hint() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> DoubleEndedIterator for Iter<'a, T> {
#[inline]
fn next_back(&mut self) -> Option<&'a T> { self.iter.next_back() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> ExactSizeIterator for Iter<'a, T> {}
/// An iterator that moves out of a `BinaryHeap`.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct IntoIter<T> {
iter: vec::IntoIter<T>,
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Iterator for IntoIter<T> {
type Item = T;
@ -612,22 +613,22 @@ impl<T> Iterator for IntoIter<T> {
fn size_hint(&self) -> (uint, Option<uint>) { self.iter.size_hint() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> DoubleEndedIterator for IntoIter<T> {
#[inline]
fn next_back(&mut self) -> Option<T> { self.iter.next_back() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ExactSizeIterator for IntoIter<T> {}
/// An iterator that drains a `BinaryHeap`.
#[unstable = "recent addition"]
#[unstable(feature = "collections", reason = "recent addition")]
pub struct Drain<'a, T: 'a> {
iter: vec::Drain<'a, T>,
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: 'a> Iterator for Drain<'a, T> {
type Item = T;
@ -638,23 +639,23 @@ impl<'a, T: 'a> Iterator for Drain<'a, T> {
fn size_hint(&self) -> (uint, Option<uint>) { self.iter.size_hint() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: 'a> DoubleEndedIterator for Drain<'a, T> {
#[inline]
fn next_back(&mut self) -> Option<T> { self.iter.next_back() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: 'a> ExactSizeIterator for Drain<'a, T> {}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Ord> FromIterator<T> for BinaryHeap<T> {
fn from_iter<Iter: Iterator<Item=T>>(iter: Iter) -> BinaryHeap<T> {
BinaryHeap::from_vec(iter.collect())
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Ord> Extend<T> for BinaryHeap<T> {
fn extend<Iter: Iterator<Item=T>>(&mut self, mut iter: Iter) {
let (lower, _) = iter.size_hint();

View File

@ -156,7 +156,8 @@ static FALSE: bool = false;
/// println!("{:?}", bv);
/// println!("total bits set to true: {}", bv.iter().filter(|x| *x).count());
/// ```
#[unstable = "RFC 509"]
#[unstable(feature = "collections",
reason = "RFC 509")]
pub struct Bitv {
/// Internal representation of the bit vector
storage: Vec<u32>,
@ -252,7 +253,7 @@ impl Bitv {
/// use std::collections::Bitv;
/// let mut bv = Bitv::new();
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new() -> Bitv {
Bitv { storage: Vec::new(), nbits: 0 }
}
@ -288,7 +289,7 @@ impl Bitv {
///
/// It is important to note that this function does not specify the
/// *length* of the returned bitvector, but only the *capacity*.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn with_capacity(nbits: uint) -> Bitv {
Bitv {
storage: Vec::with_capacity(blocks_for_bits(nbits)),
@ -374,7 +375,7 @@ impl Bitv {
/// assert_eq!(bv[1], true);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn get(&self, i: uint) -> Option<bool> {
if i >= self.nbits {
return None;
@ -402,7 +403,8 @@ impl Bitv {
/// assert_eq!(bv[3], true);
/// ```
#[inline]
#[unstable = "panic semantics are likely to change in the future"]
#[unstable(feature = "collections",
reason = "panic semantics are likely to change in the future")]
pub fn set(&mut self, i: uint, x: bool) {
assert!(i < self.nbits);
let w = i / u32::BITS;
@ -585,7 +587,7 @@ impl Bitv {
/// assert_eq!(bv.iter().filter(|x| *x).count(), 7);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn iter(&self) -> Iter {
Iter { bitv: self, next_idx: 0, end_idx: self.nbits }
}
@ -706,7 +708,7 @@ impl Bitv {
/// bv.truncate(2);
/// assert!(bv.eq_vec(&[false, true]));
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn truncate(&mut self, len: uint) {
if len < self.len() {
self.nbits = len;
@ -733,7 +735,7 @@ impl Bitv {
/// assert_eq!(bv.len(), 3);
/// assert!(bv.capacity() >= 13);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn reserve(&mut self, additional: uint) {
let desired_cap = self.len().checked_add(additional).expect("capacity overflow");
let storage_len = self.storage.len();
@ -763,7 +765,7 @@ impl Bitv {
/// assert_eq!(bv.len(), 3);
/// assert!(bv.capacity() >= 13);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn reserve_exact(&mut self, additional: uint) {
let desired_cap = self.len().checked_add(additional).expect("capacity overflow");
let storage_len = self.storage.len();
@ -785,7 +787,7 @@ impl Bitv {
/// assert!(bv.capacity() >= 10);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn capacity(&self) -> uint {
self.storage.capacity().checked_mul(u32::BITS).unwrap_or(uint::MAX)
}
@ -856,7 +858,7 @@ impl Bitv {
/// assert_eq!(bv.pop(), Some(false));
/// assert_eq!(bv.len(), 6);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn pop(&mut self) -> Option<bool> {
if self.is_empty() {
None
@ -886,7 +888,7 @@ impl Bitv {
/// bv.push(false);
/// assert!(bv.eq_vec(&[true, false]));
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn push(&mut self, elem: bool) {
if self.nbits % u32::BITS == 0 {
self.storage.push(0);
@ -898,29 +900,29 @@ impl Bitv {
/// Return the total number of bits in this vector
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn len(&self) -> uint { self.nbits }
/// Returns true if there are no bits in this vector
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_empty(&self) -> bool { self.len() == 0 }
/// Clears all bits in this vector.
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn clear(&mut self) {
for w in self.storage.iter_mut() { *w = 0u32; }
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Default for Bitv {
#[inline]
fn default() -> Bitv { Bitv::new() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl FromIterator<bool> for Bitv {
fn from_iter<I:Iterator<Item=bool>>(iterator: I) -> Bitv {
let mut ret = Bitv::new();
@ -929,7 +931,7 @@ impl FromIterator<bool> for Bitv {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Extend<bool> for Bitv {
#[inline]
fn extend<I: Iterator<Item=bool>>(&mut self, mut iterator: I) {
@ -941,7 +943,7 @@ impl Extend<bool> for Bitv {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Clone for Bitv {
#[inline]
fn clone(&self) -> Bitv {
@ -955,7 +957,7 @@ impl Clone for Bitv {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl PartialOrd for Bitv {
#[inline]
fn partial_cmp(&self, other: &Bitv) -> Option<Ordering> {
@ -963,7 +965,7 @@ impl PartialOrd for Bitv {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Ord for Bitv {
#[inline]
fn cmp(&self, other: &Bitv) -> Ordering {
@ -971,7 +973,7 @@ impl Ord for Bitv {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl fmt::Debug for Bitv {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
for bit in self.iter() {
@ -981,7 +983,7 @@ impl fmt::Debug for Bitv {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<S: hash::Writer + hash::Hasher> hash::Hash<S> for Bitv {
fn hash(&self, state: &mut S) {
self.nbits.hash(state);
@ -991,7 +993,7 @@ impl<S: hash::Writer + hash::Hasher> hash::Hash<S> for Bitv {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl cmp::PartialEq for Bitv {
#[inline]
fn eq(&self, other: &Bitv) -> bool {
@ -1002,11 +1004,11 @@ impl cmp::PartialEq for Bitv {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl cmp::Eq for Bitv {}
/// An iterator for `Bitv`.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
#[derive(Clone)]
pub struct Iter<'a> {
bitv: &'a Bitv,
@ -1014,7 +1016,7 @@ pub struct Iter<'a> {
end_idx: uint,
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> Iterator for Iter<'a> {
type Item = bool;
@ -1035,7 +1037,7 @@ impl<'a> Iterator for Iter<'a> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> DoubleEndedIterator for Iter<'a> {
#[inline]
fn next_back(&mut self) -> Option<bool> {
@ -1048,10 +1050,10 @@ impl<'a> DoubleEndedIterator for Iter<'a> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> ExactSizeIterator for Iter<'a> {}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> RandomAccessIterator for Iter<'a> {
#[inline]
fn indexable(&self) -> uint {
@ -1107,18 +1109,19 @@ impl<'a> RandomAccessIterator for Iter<'a> {
/// assert!(bv[3]);
/// ```
#[derive(Clone)]
#[unstable = "RFC 509"]
#[unstable(feature = "collections",
reason = "RFC 509")]
pub struct BitvSet {
bitv: Bitv,
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Default for BitvSet {
#[inline]
fn default() -> BitvSet { BitvSet::new() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl FromIterator<uint> for BitvSet {
fn from_iter<I:Iterator<Item=uint>>(iterator: I) -> BitvSet {
let mut ret = BitvSet::new();
@ -1127,7 +1130,7 @@ impl FromIterator<uint> for BitvSet {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Extend<uint> for BitvSet {
#[inline]
fn extend<I: Iterator<Item=uint>>(&mut self, mut iterator: I) {
@ -1137,7 +1140,7 @@ impl Extend<uint> for BitvSet {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl PartialOrd for BitvSet {
#[inline]
fn partial_cmp(&self, other: &BitvSet) -> Option<Ordering> {
@ -1146,7 +1149,7 @@ impl PartialOrd for BitvSet {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Ord for BitvSet {
#[inline]
fn cmp(&self, other: &BitvSet) -> Ordering {
@ -1155,7 +1158,7 @@ impl Ord for BitvSet {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl cmp::PartialEq for BitvSet {
#[inline]
fn eq(&self, other: &BitvSet) -> bool {
@ -1164,7 +1167,7 @@ impl cmp::PartialEq for BitvSet {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl cmp::Eq for BitvSet {}
impl BitvSet {
@ -1178,7 +1181,7 @@ impl BitvSet {
/// let mut s = BitvSet::new();
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new() -> BitvSet {
BitvSet { bitv: Bitv::new() }
}
@ -1195,7 +1198,7 @@ impl BitvSet {
/// assert!(s.capacity() >= 100);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn with_capacity(nbits: uint) -> BitvSet {
let bitv = Bitv::from_elem(nbits, false);
BitvSet::from_bitv(bitv)
@ -1233,7 +1236,7 @@ impl BitvSet {
/// assert!(s.capacity() >= 100);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn capacity(&self) -> uint {
self.bitv.capacity()
}
@ -1254,7 +1257,7 @@ impl BitvSet {
/// s.reserve_len(10);
/// assert!(s.capacity() >= 10);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn reserve_len(&mut self, len: uint) {
let cur_len = self.bitv.len();
if len >= cur_len {
@ -1280,7 +1283,7 @@ impl BitvSet {
/// s.reserve_len_exact(10);
/// assert!(s.capacity() >= 10);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn reserve_len_exact(&mut self, len: uint) {
let cur_len = self.bitv.len();
if len >= cur_len {
@ -1374,7 +1377,7 @@ impl BitvSet {
/// println!("new capacity: {}", s.capacity());
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn shrink_to_fit(&mut self) {
let bitv = &mut self.bitv;
// Obtain original length
@ -1402,7 +1405,7 @@ impl BitvSet {
/// }
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn iter(&self) -> bitv_set::Iter {
SetIter {set: self, next_idx: 0u}
}
@ -1424,7 +1427,7 @@ impl BitvSet {
/// }
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn union<'a>(&'a self, other: &'a BitvSet) -> Union<'a> {
fn or(w1: u32, w2: u32) -> u32 { w1 | w2 }
@ -1454,7 +1457,7 @@ impl BitvSet {
/// }
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn intersection<'a>(&'a self, other: &'a BitvSet) -> Intersection<'a> {
fn bitand(w1: u32, w2: u32) -> u32 { w1 & w2 }
let min = cmp::min(self.bitv.len(), other.bitv.len());
@ -1491,7 +1494,7 @@ impl BitvSet {
/// }
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn difference<'a>(&'a self, other: &'a BitvSet) -> Difference<'a> {
fn diff(w1: u32, w2: u32) -> u32 { w1 & !w2 }
@ -1522,7 +1525,7 @@ impl BitvSet {
/// }
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn symmetric_difference<'a>(&'a self, other: &'a BitvSet) -> SymmetricDifference<'a> {
fn bitxor(w1: u32, w2: u32) -> u32 { w1 ^ w2 }
@ -1639,28 +1642,28 @@ impl BitvSet {
/// Return the number of set bits in this set.
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn len(&self) -> uint {
self.bitv.blocks().fold(0, |acc, n| acc + n.count_ones())
}
/// Returns whether there are no bits set in this set
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_empty(&self) -> bool {
self.bitv.none()
}
/// Clears all bits in this set
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn clear(&mut self) {
self.bitv.clear();
}
/// Returns `true` if this set contains the specified integer.
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn contains(&self, value: &uint) -> bool {
let bitv = &self.bitv;
*value < bitv.nbits && bitv[*value]
@ -1669,14 +1672,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]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
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]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_subset(&self, other: &BitvSet) -> bool {
let self_bitv = &self.bitv;
let other_bitv = &other.bitv;
@ -1690,14 +1693,14 @@ impl BitvSet {
/// Returns `true` if the set is a superset of another.
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
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.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn insert(&mut self, value: uint) -> bool {
if self.contains(&value) {
return false;
@ -1715,7 +1718,7 @@ impl BitvSet {
/// Removes a value from the set. Returns `true` if the value was
/// present in the set.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn remove(&mut self, value: &uint) -> bool {
if !self.contains(value) {
return false;
@ -1752,7 +1755,7 @@ impl<S: hash::Writer + hash::Hasher> hash::Hash<S> for BitvSet {
/// An iterator for `BitvSet`.
#[derive(Clone)]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct SetIter<'a> {
set: &'a BitvSet,
next_idx: uint
@ -1768,16 +1771,16 @@ struct TwoBitPositions<'a> {
next_idx: uint
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Union<'a>(TwoBitPositions<'a>);
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Intersection<'a>(Take<TwoBitPositions<'a>>);
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Difference<'a>(TwoBitPositions<'a>);
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct SymmetricDifference<'a>(TwoBitPositions<'a>);
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> Iterator for SetIter<'a> {
type Item = uint;
@ -1800,7 +1803,7 @@ impl<'a> Iterator for SetIter<'a> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> Iterator for TwoBitPositions<'a> {
type Item = uint;
@ -1838,7 +1841,7 @@ impl<'a> Iterator for TwoBitPositions<'a> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> Iterator for Union<'a> {
type Item = uint;
@ -1846,7 +1849,7 @@ impl<'a> Iterator for Union<'a> {
#[inline] fn size_hint(&self) -> (uint, Option<uint>) { self.0.size_hint() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> Iterator for Intersection<'a> {
type Item = uint;
@ -1854,7 +1857,7 @@ impl<'a> Iterator for Intersection<'a> {
#[inline] fn size_hint(&self) -> (uint, Option<uint>) { self.0.size_hint() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> Iterator for Difference<'a> {
type Item = uint;
@ -1862,7 +1865,7 @@ impl<'a> Iterator for Difference<'a> {
#[inline] fn size_hint(&self) -> (uint, Option<uint>) { self.0.size_hint() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> Iterator for SymmetricDifference<'a> {
type Item = uint;

View File

@ -81,7 +81,7 @@ use super::node::{self, Node, Found, GoDown};
/// done on each operation isn't *catastrophic*, and *is* still bounded by O(B log<sub>B</sub>n),
/// it is certainly much slower when it does.
#[derive(Clone)]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct BTreeMap<K, V> {
root: Node<K, V>,
length: uint,
@ -96,31 +96,31 @@ struct AbsIter<T> {
}
/// An iterator over a BTreeMap's entries.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Iter<'a, K: 'a, V: 'a> {
inner: AbsIter<Traversal<'a, K, V>>
}
/// A mutable iterator over a BTreeMap's entries.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct IterMut<'a, K: 'a, V: 'a> {
inner: AbsIter<MutTraversal<'a, K, V>>
}
/// An owning iterator over a BTreeMap's entries.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct IntoIter<K, V> {
inner: AbsIter<MoveTraversal<K, V>>
}
/// An iterator over a BTreeMap's keys.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Keys<'a, K: 'a, V: 'a> {
inner: Map<(&'a K, &'a V), &'a K, Iter<'a, K, V>, fn((&'a K, &'a V)) -> &'a K>
}
/// An iterator over a BTreeMap's values.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Values<'a, K: 'a, V: 'a> {
inner: Map<(&'a K, &'a V), &'a V, Iter<'a, K, V>, fn((&'a K, &'a V)) -> &'a V>
}
@ -136,7 +136,8 @@ pub struct RangeMut<'a, K: 'a, V: 'a> {
}
/// A view into a single entry in a map, which may either be vacant or occupied.
#[unstable = "precise API still under development"]
#[unstable(feature = "collections",
reason = "precise API still under development")]
pub enum Entry<'a, K:'a, V:'a> {
/// A vacant Entry
Vacant(VacantEntry<'a, K, V>),
@ -145,21 +146,23 @@ pub enum Entry<'a, K:'a, V:'a> {
}
/// A vacant Entry.
#[unstable = "precise API still under development"]
#[unstable(feature = "collections",
reason = "precise API still under development")]
pub struct VacantEntry<'a, K:'a, V:'a> {
key: K,
stack: stack::SearchStack<'a, K, V, node::handle::Edge, node::handle::Leaf>,
}
/// An occupied Entry.
#[unstable = "precise API still under development"]
#[unstable(feature = "collections",
reason = "precise API still under development")]
pub struct OccupiedEntry<'a, K:'a, V:'a> {
stack: stack::SearchStack<'a, K, V, node::handle::KV, node::handle::LeafOrInternal>,
}
impl<K: Ord, V> BTreeMap<K, V> {
/// Makes a new empty BTreeMap with a reasonable choice for B.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new() -> BTreeMap<K, V> {
//FIXME(Gankro): Tune this as a function of size_of<K/V>?
BTreeMap::with_b(6)
@ -190,7 +193,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
/// a.clear();
/// assert!(a.is_empty());
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn clear(&mut self) {
let b = self.b;
// avoid recursive destructors by manually traversing the tree
@ -220,7 +223,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
/// assert_eq!(map.get(&1), Some(&"a"));
/// assert_eq!(map.get(&2), None);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn get<Q: ?Sized>(&self, key: &Q) -> Option<&V> where Q: BorrowFrom<K> + Ord {
let mut cur_node = &self.root;
loop {
@ -252,7 +255,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
/// assert_eq!(map.contains_key(&1), true);
/// assert_eq!(map.contains_key(&2), false);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn contains_key<Q: ?Sized>(&self, key: &Q) -> bool where Q: BorrowFrom<K> + Ord {
self.get(key).is_some()
}
@ -276,7 +279,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
/// assert_eq!(map[1], "b");
/// ```
// See `get` for implementation notes, this is basically a copy-paste with mut's added
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn get_mut<Q: ?Sized>(&mut self, key: &Q) -> Option<&mut V> where Q: BorrowFrom<K> + Ord {
// temp_node is a Borrowck hack for having a mutable value outlive a loop iteration
let mut temp_node = &mut self.root;
@ -337,7 +340,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
/// assert_eq!(map.insert(37, "c"), Some("b"));
/// assert_eq!(map[37], "c");
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn insert(&mut self, mut 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
@ -446,7 +449,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
/// assert_eq!(map.remove(&1), Some("a"));
/// assert_eq!(map.remove(&1), None);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn remove<Q: ?Sized>(&mut self, key: &Q) -> Option<V> where Q: BorrowFrom<K> + Ord {
// See `swap` for a more thorough description of the stuff going on in here
let mut stack = stack::PartialSearchStack::new(self);
@ -807,7 +810,7 @@ mod stack {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<K: Ord, V> FromIterator<(K, V)> for BTreeMap<K, V> {
fn from_iter<T: Iterator<Item=(K, V)>>(iter: T) -> BTreeMap<K, V> {
let mut map = BTreeMap::new();
@ -816,7 +819,7 @@ impl<K: Ord, V> FromIterator<(K, V)> for BTreeMap<K, V> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<K: Ord, V> Extend<(K, V)> for BTreeMap<K, V> {
#[inline]
fn extend<T: Iterator<Item=(K, V)>>(&mut self, mut iter: T) {
@ -826,7 +829,7 @@ impl<K: Ord, V> Extend<(K, V)> for BTreeMap<K, V> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<S: Hasher, K: Hash<S>, V: Hash<S>> Hash<S> for BTreeMap<K, V> {
fn hash(&self, state: &mut S) {
for elt in self.iter() {
@ -835,15 +838,15 @@ impl<S: Hasher, K: Hash<S>, V: Hash<S>> Hash<S> for BTreeMap<K, V> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<K: Ord, V> Default for BTreeMap<K, V> {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn default() -> BTreeMap<K, V> {
BTreeMap::new()
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<K: PartialEq, V: PartialEq> PartialEq for BTreeMap<K, V> {
fn eq(&self, other: &BTreeMap<K, V>) -> bool {
self.len() == other.len() &&
@ -851,10 +854,10 @@ impl<K: PartialEq, V: PartialEq> PartialEq for BTreeMap<K, V> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<K: Eq, V: Eq> Eq for BTreeMap<K, V> {}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<K: PartialOrd, V: PartialOrd> PartialOrd for BTreeMap<K, V> {
#[inline]
fn partial_cmp(&self, other: &BTreeMap<K, V>) -> Option<Ordering> {
@ -862,7 +865,7 @@ impl<K: PartialOrd, V: PartialOrd> PartialOrd for BTreeMap<K, V> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<K: Ord, V: Ord> Ord for BTreeMap<K, V> {
#[inline]
fn cmp(&self, other: &BTreeMap<K, V>) -> Ordering {
@ -870,7 +873,7 @@ impl<K: Ord, V: Ord> Ord for BTreeMap<K, V> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<K: Debug, V: Debug> Debug for BTreeMap<K, V> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(write!(f, "BTreeMap {{"));
@ -884,7 +887,7 @@ impl<K: Debug, V: Debug> Debug for BTreeMap<K, V> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<K: Ord, Q: ?Sized, V> Index<Q> for BTreeMap<K, V>
where Q: BorrowFrom<K> + Ord
{
@ -895,7 +898,7 @@ impl<K: Ord, Q: ?Sized, V> Index<Q> for BTreeMap<K, V>
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<K: Ord, Q: ?Sized, V> IndexMut<Q> for BTreeMap<K, V>
where Q: BorrowFrom<K> + Ord
{
@ -1006,75 +1009,75 @@ impl<K, V, E, T> DoubleEndedIterator for AbsIter<T> where
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, K, V> Iterator for Iter<'a, K, V> {
type Item = (&'a K, &'a V);
fn next(&mut self) -> Option<(&'a K, &'a V)> { self.inner.next() }
fn size_hint(&self) -> (uint, Option<uint>) { self.inner.size_hint() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, K, V> DoubleEndedIterator for Iter<'a, K, V> {
fn next_back(&mut self) -> Option<(&'a K, &'a V)> { self.inner.next_back() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, K, V> ExactSizeIterator for Iter<'a, K, V> {}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, K, V> Iterator for IterMut<'a, K, V> {
type Item = (&'a K, &'a mut V);
fn next(&mut self) -> Option<(&'a K, &'a mut V)> { self.inner.next() }
fn size_hint(&self) -> (uint, Option<uint>) { self.inner.size_hint() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, K, V> DoubleEndedIterator for IterMut<'a, K, V> {
fn next_back(&mut self) -> Option<(&'a K, &'a mut V)> { self.inner.next_back() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, K, V> ExactSizeIterator for IterMut<'a, K, V> {}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<K, V> Iterator for IntoIter<K, V> {
type Item = (K, V);
fn next(&mut self) -> Option<(K, V)> { self.inner.next() }
fn size_hint(&self) -> (uint, Option<uint>) { self.inner.size_hint() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<K, V> DoubleEndedIterator for IntoIter<K, V> {
fn next_back(&mut self) -> Option<(K, V)> { self.inner.next_back() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<K, V> ExactSizeIterator for IntoIter<K, V> {}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, K, V> Iterator for Keys<'a, K, V> {
type Item = &'a K;
fn next(&mut self) -> Option<(&'a K)> { self.inner.next() }
fn size_hint(&self) -> (uint, Option<uint>) { self.inner.size_hint() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, K, V> DoubleEndedIterator for Keys<'a, K, V> {
fn next_back(&mut self) -> Option<(&'a K)> { self.inner.next_back() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, K, V> ExactSizeIterator for Keys<'a, K, V> {}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, K, V> Iterator for Values<'a, K, V> {
type Item = &'a V;
fn next(&mut self) -> Option<(&'a V)> { self.inner.next() }
fn size_hint(&self) -> (uint, Option<uint>) { self.inner.size_hint() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, K, V> DoubleEndedIterator for Values<'a, K, V> {
fn next_back(&mut self) -> Option<(&'a V)> { self.inner.next_back() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, K, V> ExactSizeIterator for Values<'a, K, V> {}
impl<'a, K, V> Iterator for Range<'a, K, V> {
@ -1096,7 +1099,8 @@ impl<'a, K, V> DoubleEndedIterator for RangeMut<'a, K, V> {
}
impl<'a, K: Ord, V> Entry<'a, K, V> {
#[unstable = "matches collection reform v2 specification, waiting for dust to settle"]
#[unstable(feature = "collections",
reason = "matches collection reform v2 specification, waiting for dust to settle")]
/// Returns a mutable reference to the entry if occupied, or the VacantEntry if vacant
pub fn get(self) -> Result<&'a mut V, VacantEntry<'a, K, V>> {
match self {
@ -1109,7 +1113,8 @@ impl<'a, K: Ord, V> Entry<'a, K, V> {
impl<'a, K: Ord, V> VacantEntry<'a, K, V> {
/// Sets the value of the entry with the VacantEntry's key,
/// and returns a mutable reference to it.
#[unstable = "matches collection reform v2 specification, waiting for dust to settle"]
#[unstable(feature = "collections",
reason = "matches collection reform v2 specification, waiting for dust to settle")]
pub fn insert(self, value: V) -> &'a mut V {
self.stack.insert(self.key, value)
}
@ -1117,33 +1122,38 @@ impl<'a, K: Ord, V> VacantEntry<'a, K, V> {
impl<'a, K: Ord, V> OccupiedEntry<'a, K, V> {
/// Gets a reference to the value in the entry.
#[unstable = "matches collection reform v2 specification, waiting for dust to settle"]
#[unstable(feature = "collections",
reason = "matches collection reform v2 specification, waiting for dust to settle")]
pub fn get(&self) -> &V {
self.stack.peek()
}
/// Gets a mutable reference to the value in the entry.
#[unstable = "matches collection reform v2 specification, waiting for dust to settle"]
#[unstable(feature = "collections",
reason = "matches collection reform v2 specification, waiting for dust to settle")]
pub fn get_mut(&mut self) -> &mut V {
self.stack.peek_mut()
}
/// Converts the entry into a mutable reference to its value.
#[unstable = "matches collection reform v2 specification, waiting for dust to settle"]
#[unstable(feature = "collections",
reason = "matches collection reform v2 specification, waiting for dust to settle")]
pub fn into_mut(self) -> &'a mut V {
self.stack.into_top()
}
/// Sets the value of the entry with the OccupiedEntry's key,
/// and returns the entry's old value.
#[unstable = "matches collection reform v2 specification, waiting for dust to settle"]
#[unstable(feature = "collections",
reason = "matches collection reform v2 specification, waiting for dust to settle")]
pub fn insert(&mut self, mut value: V) -> V {
mem::swap(self.stack.peek_mut(), &mut value);
value
}
/// Takes the value of the entry out of the map, and returns it.
#[unstable = "matches collection reform v2 specification, waiting for dust to settle"]
#[unstable(feature = "collections",
reason = "matches collection reform v2 specification, waiting for dust to settle")]
pub fn remove(self) -> V {
self.stack.remove()
}
@ -1169,7 +1179,7 @@ impl<K, V> BTreeMap<K, V> {
/// let (first_key, first_value) = map.iter().next().unwrap();
/// assert_eq!((*first_key, *first_value), (1u, "a"));
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn iter(&self) -> Iter<K, V> {
let len = self.len();
// NB. The initial capacity for ringbuf is large enough to avoid reallocs in many cases.
@ -1202,7 +1212,7 @@ impl<K, V> BTreeMap<K, V> {
/// }
/// }
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn iter_mut(&mut self) -> IterMut<K, V> {
let len = self.len();
let mut lca = RingBuf::new();
@ -1231,7 +1241,7 @@ impl<K, V> BTreeMap<K, V> {
/// println!("{}: {}", key, value);
/// }
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn into_iter(self) -> IntoIter<K, V> {
let len = self.len();
let mut lca = RingBuf::new();
@ -1258,7 +1268,7 @@ impl<K, V> BTreeMap<K, V> {
/// let keys: Vec<uint> = a.keys().cloned().collect();
/// assert_eq!(keys, vec![1u,2,]);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn keys<'a>(&'a self) -> Keys<'a, K, V> {
fn first<A, B>((a, _): (A, B)) -> A { a }
let first: fn((&'a K, &'a V)) -> &'a K = first; // coerce to fn pointer
@ -1280,7 +1290,7 @@ impl<K, V> BTreeMap<K, V> {
/// let values: Vec<&str> = a.values().cloned().collect();
/// assert_eq!(values, vec!["a","b"]);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn values<'a>(&'a self) -> Values<'a, K, V> {
fn second<A, B>((_, b): (A, B)) -> B { b }
let second: fn((&'a K, &'a V)) -> &'a V = second; // coerce to fn pointer
@ -1300,7 +1310,7 @@ impl<K, V> BTreeMap<K, V> {
/// a.insert(1u, "a");
/// assert_eq!(a.len(), 1);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn len(&self) -> uint { self.length }
/// Return true if the map contains no elements.
@ -1315,7 +1325,7 @@ impl<K, V> BTreeMap<K, V> {
/// a.insert(1u, "a");
/// assert!(!a.is_empty());
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_empty(&self) -> bool { self.len() == 0 }
}
@ -1470,7 +1480,8 @@ impl<K: Ord, V> BTreeMap<K, V> {
/// }
/// assert_eq!(Some((&5u, &"b")), map.range(Included(&4), Unbounded).next());
/// ```
#[unstable = "matches collection reform specification, waiting for dust to settle"]
#[unstable(feature = "collections",
reason = "matches collection reform specification, waiting for dust to settle")]
pub fn range<'a>(&'a self, min: Bound<&K>, max: Bound<&K>) -> Range<'a, K, V> {
range_impl!(&self.root, min, max, as_slices_internal, iter, Range, edges, [])
}
@ -1496,7 +1507,8 @@ impl<K: Ord, V> BTreeMap<K, V> {
/// println!("{} => {}", name, balance);
/// }
/// ```
#[unstable = "matches collection reform specification, waiting for dust to settle"]
#[unstable(feature = "collections",
reason = "matches collection reform specification, waiting for dust to settle")]
pub fn range_mut<'a>(&'a mut self, min: Bound<&K>, max: Bound<&K>) -> RangeMut<'a, K, V> {
range_impl!(&mut self.root, min, max, as_slices_internal_mut, iter_mut, RangeMut,
edges_mut, [mut])
@ -1528,7 +1540,8 @@ impl<K: Ord, V> BTreeMap<K, V> {
/// assert_eq!(count["a"], 3u);
/// ```
/// The key must have the same ordering before or after `.to_owned()` is called.
#[unstable = "precise API still under development"]
#[unstable(feature = "collections",
reason = "precise API still under development")]
pub fn entry<'a>(&'a mut self, mut key: K) -> Entry<'a, K, V> {
// same basic logic of `swap` and `pop`, blended together
let mut stack = stack::PartialSearchStack::new(self);

View File

@ -420,7 +420,7 @@ impl<K, V> Node<K, V> {
}
// FIXME(gereeter) Write an efficient clone_from
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<K: Clone, V: Clone> Clone for Node<K, V> {
fn clone(&self) -> Node<K, V> {
let mut ret = if self.is_leaf() {

View File

@ -31,19 +31,19 @@ use Bound;
/// See BTreeMap's documentation for a detailed discussion of this collection's performance
/// benefits and drawbacks.
#[derive(Clone, Hash, PartialEq, Eq, Ord, PartialOrd)]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct BTreeSet<T>{
map: BTreeMap<T, ()>,
}
/// An iterator over a BTreeSet's items.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Iter<'a, T: 'a> {
iter: Keys<'a, T, ()>
}
/// An owning iterator over a BTreeSet's items.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct IntoIter<T> {
iter: Map<(T, ()), T, ::btree_map::IntoIter<T, ()>, fn((T, ())) -> T>
}
@ -54,28 +54,28 @@ pub struct Range<'a, T: 'a> {
}
/// A lazy iterator producing elements in the set difference (in-order).
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Difference<'a, T:'a> {
a: Peekable<&'a T, Iter<'a, T>>,
b: Peekable<&'a T, Iter<'a, T>>,
}
/// A lazy iterator producing elements in the set symmetric difference (in-order).
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct SymmetricDifference<'a, T:'a> {
a: Peekable<&'a T, Iter<'a, T>>,
b: Peekable<&'a T, Iter<'a, T>>,
}
/// A lazy iterator producing elements in the set intersection (in-order).
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Intersection<'a, T:'a> {
a: Peekable<&'a T, Iter<'a, T>>,
b: Peekable<&'a T, Iter<'a, T>>,
}
/// A lazy iterator producing elements in the set union (in-order).
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Union<'a, T:'a> {
a: Peekable<&'a T, Iter<'a, T>>,
b: Peekable<&'a T, Iter<'a, T>>,
@ -91,7 +91,7 @@ impl<T: Ord> BTreeSet<T> {
///
/// let mut set: BTreeSet<int> = BTreeSet::new();
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new() -> BTreeSet<T> {
BTreeSet { map: BTreeMap::new() }
}
@ -99,7 +99,8 @@ impl<T: Ord> BTreeSet<T> {
/// Makes a new BTreeSet with the given B.
///
/// B cannot be less than 2.
#[unstable = "probably want this to be on the type, eventually"]
#[unstable(feature = "collections",
reason = "probably want this to be on the type, eventually")]
pub fn with_b(b: uint) -> BTreeSet<T> {
BTreeSet { map: BTreeMap::with_b(b) }
}
@ -122,7 +123,7 @@ impl<T> BTreeSet<T> {
/// let v: Vec<uint> = set.iter().map(|&x| x).collect();
/// assert_eq!(v, vec![1u,2,3,4]);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn iter(&self) -> Iter<T> {
Iter { iter: self.map.keys() }
}
@ -139,7 +140,7 @@ impl<T> BTreeSet<T> {
/// let v: Vec<uint> = set.into_iter().collect();
/// assert_eq!(v, vec![1u,2,3,4]);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn into_iter(self) -> IntoIter<T> {
fn first<A, B>((a, _): (A, B)) -> A { a }
let first: fn((T, ())) -> T = first; // coerce to fn pointer
@ -169,7 +170,8 @@ impl<T: Ord> BTreeSet<T> {
/// }
/// assert_eq!(Some(&5u), set.range(Included(&4), Unbounded).next());
/// ```
#[unstable = "matches collection reform specification, waiting for dust to settle"]
#[unstable(feature = "collections",
reason = "matches collection reform specification, waiting for dust to settle")]
pub fn range<'a>(&'a self, min: Bound<&T>, max: Bound<&T>) -> Range<'a, T> {
fn first<A, B>((a, _): (A, B)) -> A { a }
let first: fn((&'a T, &'a ())) -> &'a T = first; // coerce to fn pointer
@ -197,7 +199,7 @@ impl<T: Ord> BTreeSet<T> {
/// let diff: Vec<uint> = a.difference(&b).cloned().collect();
/// assert_eq!(diff, vec![1u]);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn difference<'a>(&'a self, other: &'a BTreeSet<T>) -> Difference<'a, T> {
Difference{a: self.iter().peekable(), b: other.iter().peekable()}
}
@ -220,7 +222,7 @@ impl<T: Ord> BTreeSet<T> {
/// let sym_diff: Vec<uint> = a.symmetric_difference(&b).cloned().collect();
/// assert_eq!(sym_diff, vec![1u,3]);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn symmetric_difference<'a>(&'a self, other: &'a BTreeSet<T>)
-> SymmetricDifference<'a, T> {
SymmetricDifference{a: self.iter().peekable(), b: other.iter().peekable()}
@ -244,7 +246,7 @@ impl<T: Ord> BTreeSet<T> {
/// let intersection: Vec<uint> = a.intersection(&b).cloned().collect();
/// assert_eq!(intersection, vec![2u]);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn intersection<'a>(&'a self, other: &'a BTreeSet<T>)
-> Intersection<'a, T> {
Intersection{a: self.iter().peekable(), b: other.iter().peekable()}
@ -266,7 +268,7 @@ impl<T: Ord> BTreeSet<T> {
/// let union: Vec<uint> = a.union(&b).cloned().collect();
/// assert_eq!(union, vec![1u,2]);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn union<'a>(&'a self, other: &'a BTreeSet<T>) -> Union<'a, T> {
Union{a: self.iter().peekable(), b: other.iter().peekable()}
}
@ -283,7 +285,7 @@ impl<T: Ord> BTreeSet<T> {
/// v.insert(1i);
/// assert_eq!(v.len(), 1);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn len(&self) -> uint { self.map.len() }
/// Returns true if the set contains no elements
@ -298,7 +300,7 @@ impl<T: Ord> BTreeSet<T> {
/// v.insert(1i);
/// assert!(!v.is_empty());
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_empty(&self) -> bool { self.len() == 0 }
/// Clears the set, removing all values.
@ -313,7 +315,7 @@ impl<T: Ord> BTreeSet<T> {
/// v.clear();
/// assert!(v.is_empty());
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn clear(&mut self) {
self.map.clear()
}
@ -333,7 +335,7 @@ impl<T: Ord> BTreeSet<T> {
/// assert_eq!(set.contains(&1), true);
/// assert_eq!(set.contains(&4), false);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn contains<Q: ?Sized>(&self, value: &Q) -> bool where Q: BorrowFrom<T> + Ord {
self.map.contains_key(value)
}
@ -355,7 +357,7 @@ impl<T: Ord> BTreeSet<T> {
/// b.insert(1);
/// assert_eq!(a.is_disjoint(&b), false);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_disjoint(&self, other: &BTreeSet<T>) -> bool {
self.intersection(other).next().is_none()
}
@ -376,7 +378,7 @@ impl<T: Ord> BTreeSet<T> {
/// set.insert(4);
/// assert_eq!(set.is_subset(&sup), false);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_subset(&self, other: &BTreeSet<T>) -> bool {
// Stolen from TreeMap
let mut x = self.iter();
@ -421,7 +423,7 @@ impl<T: Ord> BTreeSet<T> {
/// set.insert(2);
/// assert_eq!(set.is_superset(&sub), true);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_superset(&self, other: &BTreeSet<T>) -> bool {
other.is_subset(self)
}
@ -440,7 +442,7 @@ impl<T: Ord> BTreeSet<T> {
/// assert_eq!(set.insert(2i), false);
/// assert_eq!(set.len(), 1);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn insert(&mut self, value: T) -> bool {
self.map.insert(value, ()).is_none()
}
@ -463,13 +465,13 @@ impl<T: Ord> BTreeSet<T> {
/// assert_eq!(set.remove(&2), true);
/// assert_eq!(set.remove(&2), false);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn remove<Q: ?Sized>(&mut self, value: &Q) -> bool where Q: BorrowFrom<T> + Ord {
self.map.remove(value).is_some()
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Ord> FromIterator<T> for BTreeSet<T> {
fn from_iter<Iter: Iterator<Item=T>>(iter: Iter) -> BTreeSet<T> {
let mut set = BTreeSet::new();
@ -478,7 +480,7 @@ impl<T: Ord> FromIterator<T> for BTreeSet<T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Ord> Extend<T> for BTreeSet<T> {
#[inline]
fn extend<Iter: Iterator<Item=T>>(&mut self, mut iter: Iter) {
@ -488,15 +490,15 @@ impl<T: Ord> Extend<T> for BTreeSet<T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Ord> Default for BTreeSet<T> {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn default() -> BTreeSet<T> {
BTreeSet::new()
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, 'b, T: Ord + Clone> Sub<&'b BTreeSet<T>> for &'a BTreeSet<T> {
type Output = BTreeSet<T>;
@ -519,7 +521,7 @@ impl<'a, 'b, T: Ord + Clone> Sub<&'b BTreeSet<T>> for &'a BTreeSet<T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, 'b, T: Ord + Clone> BitXor<&'b BTreeSet<T>> for &'a BTreeSet<T> {
type Output = BTreeSet<T>;
@ -542,7 +544,7 @@ impl<'a, 'b, T: Ord + Clone> BitXor<&'b BTreeSet<T>> for &'a BTreeSet<T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, 'b, T: Ord + Clone> BitAnd<&'b BTreeSet<T>> for &'a BTreeSet<T> {
type Output = BTreeSet<T>;
@ -565,7 +567,7 @@ impl<'a, 'b, T: Ord + Clone> BitAnd<&'b BTreeSet<T>> for &'a BTreeSet<T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, 'b, T: Ord + Clone> BitOr<&'b BTreeSet<T>> for &'a BTreeSet<T> {
type Output = BTreeSet<T>;
@ -588,7 +590,7 @@ impl<'a, 'b, T: Ord + Clone> BitOr<&'b BTreeSet<T>> for &'a BTreeSet<T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Debug> Debug for BTreeSet<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(write!(f, "BTreeSet {{"));
@ -602,33 +604,33 @@ impl<T: Debug> Debug for BTreeSet<T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> Iterator for Iter<'a, T> {
type Item = &'a T;
fn next(&mut self) -> Option<&'a T> { self.iter.next() }
fn size_hint(&self) -> (uint, Option<uint>) { self.iter.size_hint() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> DoubleEndedIterator for Iter<'a, T> {
fn next_back(&mut self) -> Option<&'a T> { self.iter.next_back() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> ExactSizeIterator for Iter<'a, T> {}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Iterator for IntoIter<T> {
type Item = T;
fn next(&mut self) -> Option<T> { self.iter.next() }
fn size_hint(&self) -> (uint, Option<uint>) { self.iter.size_hint() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> DoubleEndedIterator for IntoIter<T> {
fn next_back(&mut self) -> Option<T> { self.iter.next_back() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ExactSizeIterator for IntoIter<T> {}
@ -651,7 +653,7 @@ fn cmp_opt<T: Ord>(x: Option<&T>, y: Option<&T>,
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: Ord> Iterator for Difference<'a, T> {
type Item = &'a T;
@ -666,7 +668,7 @@ impl<'a, T: Ord> Iterator for Difference<'a, T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: Ord> Iterator for SymmetricDifference<'a, T> {
type Item = &'a T;
@ -681,7 +683,7 @@ impl<'a, T: Ord> Iterator for SymmetricDifference<'a, T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: Ord> Iterator for Intersection<'a, T> {
type Item = &'a T;
@ -702,7 +704,7 @@ impl<'a, T: Ord> Iterator for Intersection<'a, T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: Ord> Iterator for Union<'a, T> {
type Item = &'a T;
@ -756,7 +758,9 @@ mod test {
expected: &'b [int],
}
impl<'a, 'b, 'c> FnMut(&'c int) -> bool for Counter<'a, 'b> {
impl<'a, 'b, 'c> FnMut<(&'c int,)> for Counter<'a, 'b> {
type Output = bool;
extern "rust-call" fn call_mut(&mut self, (&x,): (&'c int,)) -> bool {
assert_eq!(x, self.expected[*self.i]);
*self.i += 1;

View File

@ -19,7 +19,7 @@
// Backlinks over DList::prev are raw pointers that form a full chain in
// the reverse direction.
#![stable]
#![stable(feature = "rust1", since = "1.0.0")]
use core::prelude::*;
@ -33,7 +33,7 @@ use core::mem;
use core::ptr;
/// A doubly-linked list.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct DList<T> {
length: uint,
list_head: Link<T>,
@ -57,7 +57,7 @@ struct Node<T> {
}
/// An iterator over references to the items of a `DList`.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Iter<'a, T:'a> {
head: &'a Link<T>,
tail: Rawlink<Node<T>>,
@ -65,7 +65,7 @@ pub struct Iter<'a, T:'a> {
}
// FIXME #19839: deriving is too aggressive on the bounds (T doesn't need to be Clone).
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> Clone for Iter<'a, T> {
fn clone(&self) -> Iter<'a, T> {
Iter {
@ -77,7 +77,7 @@ impl<'a, T> Clone for Iter<'a, T> {
}
/// An iterator over mutable references to the items of a `DList`.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct IterMut<'a, T:'a> {
list: &'a mut DList<T>,
head: Rawlink<Node<T>>,
@ -87,7 +87,7 @@ pub struct IterMut<'a, T:'a> {
/// An iterator over mutable references to the items of a `DList`.
#[derive(Clone)]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct IntoIter<T> {
list: DList<T>
}
@ -206,17 +206,17 @@ impl<T> DList<T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Default for DList<T> {
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn default() -> DList<T> { DList::new() }
}
impl<T> DList<T> {
/// Creates an empty `DList`.
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new() -> DList<T> {
DList{list_head: None, list_tail: Rawlink::none(), length: 0}
}
@ -273,14 +273,14 @@ impl<T> DList<T> {
/// Provides a forward iterator.
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn iter(&self) -> Iter<T> {
Iter{nelem: self.len(), head: &self.list_head, tail: self.list_tail}
}
/// Provides a forward iterator with mutable references.
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn iter_mut(&mut self) -> IterMut<T> {
let head_raw = match self.list_head {
Some(ref mut h) => Rawlink::some(&mut **h),
@ -296,7 +296,7 @@ impl<T> DList<T> {
/// Consumes the list into an iterator yielding elements by value.
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn into_iter(self) -> IntoIter<T> {
IntoIter{list: self}
}
@ -317,7 +317,7 @@ impl<T> DList<T> {
/// assert!(!dl.is_empty());
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_empty(&self) -> bool {
self.list_head.is_none()
}
@ -344,7 +344,7 @@ impl<T> DList<T> {
///
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn len(&self) -> uint {
self.length
}
@ -371,7 +371,7 @@ impl<T> DList<T> {
///
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn clear(&mut self) {
*self = DList::new()
}
@ -392,7 +392,7 @@ impl<T> DList<T> {
///
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn front(&self) -> Option<&T> {
self.list_head.as_ref().map(|head| &head.value)
}
@ -419,7 +419,7 @@ impl<T> DList<T> {
///
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn front_mut(&mut self) -> Option<&mut T> {
self.list_head.as_mut().map(|head| &mut head.value)
}
@ -440,7 +440,7 @@ impl<T> DList<T> {
///
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn back(&self) -> Option<&T> {
self.list_tail.resolve_immut().as_ref().map(|tail| &tail.value)
}
@ -467,7 +467,7 @@ impl<T> DList<T> {
///
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn back_mut(&mut self) -> Option<&mut T> {
self.list_tail.resolve().map(|tail| &mut tail.value)
}
@ -490,7 +490,7 @@ impl<T> DList<T> {
/// assert_eq!(dl.front().unwrap(), &1);
///
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn push_front(&mut self, elt: T) {
self.push_front_node(box Node::new(elt))
}
@ -516,7 +516,7 @@ impl<T> DList<T> {
///
/// ```
///
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn pop_front(&mut self) -> Option<T> {
self.pop_front_node().map(|box Node{value, ..}| value)
}
@ -533,7 +533,7 @@ impl<T> DList<T> {
/// d.push_back(3);
/// assert_eq!(3, *d.back().unwrap());
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn push_back(&mut self, elt: T) {
self.push_back_node(box Node::new(elt))
}
@ -552,7 +552,7 @@ impl<T> DList<T> {
/// d.push_back(3);
/// assert_eq!(d.pop_back(), Some(3));
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn pop_back(&mut self) -> Option<T> {
self.pop_back_node().map(|box Node{value, ..}| value)
}
@ -577,7 +577,7 @@ impl<T> DList<T> {
/// assert_eq!(splitted.pop_front(), Some(1));
/// assert_eq!(splitted.pop_front(), None);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn split_off(&mut self, at: uint) -> DList<T> {
let len = self.len();
assert!(at < len, "Cannot split off at a nonexistent index");
@ -620,7 +620,7 @@ impl<T> DList<T> {
}
#[unsafe_destructor]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Drop for DList<T> {
fn drop(&mut self) {
// Dissolve the dlist in backwards direction
@ -642,7 +642,7 @@ impl<T> Drop for DList<T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, A> Iterator for Iter<'a, A> {
type Item = &'a A;
@ -664,7 +664,7 @@ impl<'a, A> Iterator for Iter<'a, A> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, A> DoubleEndedIterator for Iter<'a, A> {
#[inline]
fn next_back(&mut self) -> Option<&'a A> {
@ -679,10 +679,10 @@ impl<'a, A> DoubleEndedIterator for Iter<'a, A> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, A> ExactSizeIterator for Iter<'a, A> {}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, A> Iterator for IterMut<'a, A> {
type Item = &'a mut A;
#[inline]
@ -706,7 +706,7 @@ impl<'a, A> Iterator for IterMut<'a, A> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, A> DoubleEndedIterator for IterMut<'a, A> {
#[inline]
fn next_back(&mut self) -> Option<&'a mut A> {
@ -721,7 +721,7 @@ impl<'a, A> DoubleEndedIterator for IterMut<'a, A> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, A> ExactSizeIterator for IterMut<'a, A> {}
// private methods for IterMut
@ -770,7 +770,8 @@ impl<'a, A> IterMut<'a, A> {
/// }
/// ```
#[inline]
#[unstable = "this is probably better handled by a cursor type -- we'll see"]
#[unstable(feature = "collections",
reason = "this is probably better handled by a cursor type -- we'll see")]
pub fn insert_next(&mut self, elt: A) {
self.insert_next_node(box Node::new(elt))
}
@ -791,7 +792,8 @@ impl<'a, A> IterMut<'a, A> {
/// assert_eq!(it.next().unwrap(), &2);
/// ```
#[inline]
#[unstable = "this is probably better handled by a cursor type -- we'll see"]
#[unstable(feature = "collections",
reason = "this is probably better handled by a cursor type -- we'll see")]
pub fn peek_next(&mut self) -> Option<&mut A> {
if self.nelem == 0 {
return None
@ -800,7 +802,7 @@ impl<'a, A> IterMut<'a, A> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<A> Iterator for IntoIter<A> {
type Item = A;
@ -813,13 +815,13 @@ impl<A> Iterator for IntoIter<A> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<A> DoubleEndedIterator for IntoIter<A> {
#[inline]
fn next_back(&mut self) -> Option<A> { self.list.pop_back() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<A> FromIterator<A> for DList<A> {
fn from_iter<T: Iterator<Item=A>>(iterator: T) -> DList<A> {
let mut ret = DList::new();
@ -828,14 +830,14 @@ impl<A> FromIterator<A> for DList<A> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<A> Extend<A> for DList<A> {
fn extend<T: Iterator<Item=A>>(&mut self, mut iterator: T) {
for elt in iterator { self.push_back(elt); }
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<A: PartialEq> PartialEq for DList<A> {
fn eq(&self, other: &DList<A>) -> bool {
self.len() == other.len() &&
@ -848,17 +850,17 @@ impl<A: PartialEq> PartialEq for DList<A> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<A: Eq> Eq for DList<A> {}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<A: PartialOrd> PartialOrd for DList<A> {
fn partial_cmp(&self, other: &DList<A>) -> Option<Ordering> {
iter::order::partial_cmp(self.iter(), other.iter())
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<A: Ord> Ord for DList<A> {
#[inline]
fn cmp(&self, other: &DList<A>) -> Ordering {
@ -866,14 +868,14 @@ impl<A: Ord> Ord for DList<A> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<A: Clone> Clone for DList<A> {
fn clone(&self) -> DList<A> {
self.iter().map(|x| x.clone()).collect()
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<A: fmt::Debug> fmt::Debug for DList<A> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(write!(f, "DList ["));
@ -887,7 +889,7 @@ impl<A: fmt::Debug> fmt::Debug for DList<A> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<S: Writer + Hasher, A: Hash<S>> Hash<S> for DList<A> {
fn hash(&self, state: &mut S) {
self.len().hash(state);

View File

@ -82,19 +82,22 @@ fn bit<E:CLike>(e: &E) -> uint {
impl<E:CLike> EnumSet<E> {
/// Returns an empty `EnumSet`.
#[unstable = "matches collection reform specification, waiting for dust to settle"]
#[unstable(feature = "collections",
reason = "matches collection reform specification, waiting for dust to settle")]
pub fn new() -> EnumSet<E> {
EnumSet {bits: 0}
}
/// Returns the number of elements in the given `EnumSet`.
#[unstable = "matches collection reform specification, waiting for dust to settle"]
#[unstable(feature = "collections",
reason = "matches collection reform specification, waiting for dust to settle")]
pub fn len(&self) -> uint {
self.bits.count_ones()
}
/// Returns true if the `EnumSet` is empty.
#[unstable = "matches collection reform specification, waiting for dust to settle"]
#[unstable(feature = "collections",
reason = "matches collection reform specification, waiting for dust to settle")]
pub fn is_empty(&self) -> bool {
self.bits == 0
}
@ -104,19 +107,22 @@ impl<E:CLike> EnumSet<E> {
}
/// Returns `false` if the `EnumSet` contains any enum of the given `EnumSet`.
#[unstable = "matches collection reform specification, waiting for dust to settle"]
#[unstable(feature = "collections",
reason = "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 this `EnumSet`.
#[unstable = "matches collection reform specification, waiting for dust to settle"]
#[unstable(feature = "collections",
reason = "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"]
#[unstable(feature = "collections",
reason = "matches collection reform specification, waiting for dust to settle")]
pub fn is_subset(&self, other: &EnumSet<E>) -> bool {
other.is_superset(self)
}
@ -132,7 +138,8 @@ impl<E:CLike> EnumSet<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"]
#[unstable(feature = "collections",
reason = "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);
@ -140,7 +147,8 @@ impl<E:CLike> EnumSet<E> {
}
/// Removes an enum from the EnumSet
#[unstable = "matches collection reform specification, waiting for dust to settle"]
#[unstable(feature = "collections",
reason = "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);
@ -148,13 +156,15 @@ impl<E:CLike> EnumSet<E> {
}
/// Returns `true` if an `EnumSet` contains a given enum.
#[unstable = "matches collection reform specification, waiting for dust to settle"]
#[unstable(feature = "collections",
reason = "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"]
#[unstable(feature = "collections",
reason = "matches collection reform specification, waiting for dust to settle")]
pub fn iter(&self) -> Iter<E> {
Iter::new(self.bits)
}

View File

@ -14,7 +14,8 @@
#![crate_name = "collections"]
#![unstable]
#![unstable(feature = "collections")]
#![feature(staged_api)]
#![staged_api]
#![crate_type = "rlib"]
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
@ -27,8 +28,12 @@
#![feature(box_syntax)]
#![feature(unboxed_closures)]
#![allow(unknown_features)] #![feature(int_uint)]
#![allow(unstable)]
#![no_std]
#![feature(core)]
#![feature(alloc)]
#![feature(unicode)]
#![feature(hash)]
#![cfg_attr(test, feature(test))]
#[macro_use]
extern crate core;
@ -70,23 +75,25 @@ pub mod string;
pub mod vec;
pub mod vec_map;
#[unstable = "RFC 509"]
#[unstable(feature = "collections",
reason = "RFC 509")]
pub mod bitv {
pub use bit::{Bitv, Iter};
}
#[unstable = "RFC 509"]
#[unstable(feature = "collections",
reason = "RFC 509")]
pub mod bitv_set {
pub use bit::{BitvSet, Union, Intersection, Difference, SymmetricDifference};
pub use bit::SetIter as Iter;
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub mod btree_map {
pub use btree::map::*;
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub mod btree_set {
pub use btree::set::*;
}

View File

@ -10,7 +10,7 @@
/// Creates a `Vec` containing the arguments.
#[macro_export]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
macro_rules! vec {
($x:expr; $y:expr) => (
<[_] as $crate::slice::SliceExt>::into_vec(

View File

@ -12,7 +12,7 @@
//! ends of the container. It also has `O(1)` indexing like a vector. The contained elements are
//! not required to be copyable, and the queue will be sendable if the contained type is sendable.
#![stable]
#![stable(feature = "rust1", since = "1.0.0")]
use core::prelude::*;
@ -36,7 +36,7 @@ static INITIAL_CAPACITY: uint = 7u; // 2^3 - 1
static MINIMUM_CAPACITY: uint = 1u; // 2 - 1
/// `RingBuf` is a circular buffer, which can be used as a double-ended queue efficiently.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct RingBuf<T> {
// tail and head are pointers into the buffer. Tail always points
// to the first element that could be read, Head always points
@ -50,13 +50,13 @@ pub struct RingBuf<T> {
ptr: *mut T
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
unsafe impl<T: Send> Send for RingBuf<T> {}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
unsafe impl<T: Sync> Sync for RingBuf<T> {}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Clone> Clone for RingBuf<T> {
fn clone(&self) -> RingBuf<T> {
self.iter().map(|t| t.clone()).collect()
@ -64,7 +64,7 @@ impl<T: Clone> Clone for RingBuf<T> {
}
#[unsafe_destructor]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Drop for RingBuf<T> {
fn drop(&mut self) {
self.clear();
@ -78,7 +78,7 @@ impl<T> Drop for RingBuf<T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Default for RingBuf<T> {
#[inline]
fn default() -> RingBuf<T> { RingBuf::new() }
@ -146,13 +146,13 @@ impl<T> RingBuf<T> {
impl<T> RingBuf<T> {
/// Creates an empty `RingBuf`.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new() -> RingBuf<T> {
RingBuf::with_capacity(INITIAL_CAPACITY)
}
/// Creates an empty `RingBuf` with space for at least `n` elements.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn with_capacity(n: uint) -> RingBuf<T> {
// +1 since the ringbuffer always leaves one space empty
let cap = cmp::max(n + 1, MINIMUM_CAPACITY + 1).next_power_of_two();
@ -191,7 +191,7 @@ impl<T> RingBuf<T> {
/// buf.push_back(5);
/// assert_eq!(buf.get(1).unwrap(), &4);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn get(&self, i: uint) -> Option<&T> {
if i < self.len() {
let idx = self.wrap_index(self.tail + i);
@ -221,7 +221,7 @@ impl<T> RingBuf<T> {
///
/// assert_eq!(buf[1], 7);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn get_mut(&mut self, i: uint) -> Option<&mut T> {
if i < self.len() {
let idx = self.wrap_index(self.tail + i);
@ -250,7 +250,7 @@ impl<T> RingBuf<T> {
/// assert_eq!(buf[0], 5);
/// assert_eq!(buf[2], 3);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn swap(&mut self, i: uint, j: uint) {
assert!(i < self.len());
assert!(j < self.len());
@ -273,7 +273,7 @@ impl<T> RingBuf<T> {
/// assert!(buf.capacity() >= 10);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn capacity(&self) -> uint { self.cap - 1 }
/// Reserves the minimum capacity for exactly `additional` more elements to be inserted in the
@ -296,7 +296,7 @@ impl<T> RingBuf<T> {
/// buf.reserve_exact(10);
/// assert!(buf.capacity() >= 11);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn reserve_exact(&mut self, additional: uint) {
self.reserve(additional);
}
@ -317,7 +317,7 @@ impl<T> RingBuf<T> {
/// buf.reserve(10);
/// assert!(buf.capacity() >= 11);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn reserve(&mut self, additional: uint) {
let new_len = self.len() + additional;
assert!(new_len + 1 > self.len(), "capacity overflow");
@ -480,7 +480,8 @@ impl<T> RingBuf<T> {
/// assert_eq!(buf.len(), 1);
/// assert_eq!(Some(&5), buf.get(0));
/// ```
#[unstable = "matches collection reform specification; waiting on panic semantics"]
#[unstable(feature = "collections",
reason = "matches collection reform specification; waiting on panic semantics")]
pub fn truncate(&mut self, len: uint) {
for _ in range(len, self.len()) {
self.pop_back();
@ -501,7 +502,7 @@ impl<T> RingBuf<T> {
/// let b: &[_] = &[&5, &3, &4];
/// assert_eq!(buf.iter().collect::<Vec<&int>>().as_slice(), b);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn iter(&self) -> Iter<T> {
Iter {
tail: self.tail,
@ -527,7 +528,7 @@ impl<T> RingBuf<T> {
/// let b: &[_] = &[&mut 3, &mut 1, &mut 2];
/// assert_eq!(&buf.iter_mut().collect::<Vec<&mut int>>()[], b);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn iter_mut<'a>(&'a mut self) -> IterMut<'a, T> {
IterMut {
tail: self.tail,
@ -539,7 +540,7 @@ impl<T> RingBuf<T> {
}
/// Consumes the list into an iterator yielding elements by value.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn into_iter(self) -> IntoIter<T> {
IntoIter {
inner: self,
@ -549,7 +550,8 @@ impl<T> RingBuf<T> {
/// Returns a pair of slices which contain, in order, the contents of the
/// `RingBuf`.
#[inline]
#[unstable = "matches collection reform specification, waiting for dust to settle"]
#[unstable(feature = "collections",
reason = "matches collection reform specification, waiting for dust to settle")]
pub fn as_slices<'a>(&'a self) -> (&'a [T], &'a [T]) {
unsafe {
let contiguous = self.is_contiguous();
@ -568,7 +570,8 @@ impl<T> RingBuf<T> {
/// Returns a pair of slices which contain, in order, the contents of the
/// `RingBuf`.
#[inline]
#[unstable = "matches collection reform specification, waiting for dust to settle"]
#[unstable(feature = "collections",
reason = "matches collection reform specification, waiting for dust to settle")]
pub fn as_mut_slices<'a>(&'a mut self) -> (&'a mut [T], &'a mut [T]) {
unsafe {
let contiguous = self.is_contiguous();
@ -600,7 +603,7 @@ impl<T> RingBuf<T> {
/// v.push_back(1i);
/// assert_eq!(v.len(), 1);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn len(&self) -> uint { count(self.tail, self.head, self.cap) }
/// Returns true if the buffer contains no elements
@ -615,7 +618,7 @@ impl<T> RingBuf<T> {
/// v.push_front(1i);
/// assert!(!v.is_empty());
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_empty(&self) -> bool { self.len() == 0 }
/// Creates a draining iterator that clears the `RingBuf` and iterates over
@ -632,7 +635,8 @@ impl<T> RingBuf<T> {
/// assert!(v.is_empty());
/// ```
#[inline]
#[unstable = "matches collection reform specification, waiting for dust to settle"]
#[unstable(feature = "collections",
reason = "matches collection reform specification, waiting for dust to settle")]
pub fn drain(&mut self) -> Drain<T> {
Drain {
inner: self,
@ -651,7 +655,7 @@ impl<T> RingBuf<T> {
/// v.clear();
/// assert!(v.is_empty());
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn clear(&mut self) {
self.drain();
@ -672,7 +676,7 @@ impl<T> RingBuf<T> {
/// d.push_back(2i);
/// assert_eq!(d.front(), Some(&1i));
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn front(&self) -> Option<&T> {
if !self.is_empty() { Some(&self[0]) } else { None }
}
@ -696,7 +700,7 @@ impl<T> RingBuf<T> {
/// }
/// assert_eq!(d.front(), Some(&9i));
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn front_mut(&mut self) -> Option<&mut T> {
if !self.is_empty() { Some(&mut self[0]) } else { None }
}
@ -716,7 +720,7 @@ impl<T> RingBuf<T> {
/// d.push_back(2i);
/// assert_eq!(d.back(), Some(&2i));
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn back(&self) -> Option<&T> {
if !self.is_empty() { Some(&self[self.len() - 1]) } else { None }
}
@ -740,7 +744,7 @@ impl<T> RingBuf<T> {
/// }
/// assert_eq!(d.back(), Some(&9i));
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn back_mut(&mut self) -> Option<&mut T> {
let len = self.len();
if !self.is_empty() { Some(&mut self[len - 1]) } else { None }
@ -762,7 +766,7 @@ impl<T> RingBuf<T> {
/// assert_eq!(d.pop_front(), Some(2i));
/// assert_eq!(d.pop_front(), None);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn pop_front(&mut self) -> Option<T> {
if self.is_empty() {
None
@ -785,7 +789,7 @@ impl<T> RingBuf<T> {
/// d.push_front(2i);
/// assert_eq!(d.front(), Some(&2i));
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn push_front(&mut self, t: T) {
if self.is_full() {
self.reserve(1);
@ -809,7 +813,7 @@ impl<T> RingBuf<T> {
/// buf.push_back(3);
/// assert_eq!(3, *buf.back().unwrap());
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn push_back(&mut self, t: T) {
if self.is_full() {
self.reserve(1);
@ -835,7 +839,7 @@ impl<T> RingBuf<T> {
/// buf.push_back(3);
/// assert_eq!(buf.pop_back(), Some(3));
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn pop_back(&mut self) -> Option<T> {
if self.is_empty() {
None
@ -872,7 +876,8 @@ impl<T> RingBuf<T> {
/// buf.push_back(10);
/// assert_eq!(buf.swap_back_remove(1), Some(99));
/// ```
#[unstable = "the naming of this function may be altered"]
#[unstable(feature = "collections",
reason = "the naming of this function may be altered")]
pub fn swap_back_remove(&mut self, index: uint) -> Option<T> {
let length = self.len();
if length > 0 && index < length - 1 {
@ -904,7 +909,8 @@ impl<T> RingBuf<T> {
/// buf.push_back(20i);
/// assert_eq!(buf.swap_front_remove(3), Some(99));
/// ```
#[unstable = "the naming of this function may be altered"]
#[unstable(feature = "collections",
reason = "the naming of this function may be altered")]
pub fn swap_front_remove(&mut self, index: uint) -> Option<T> {
let length = self.len();
if length > 0 && index < length && index != 0 {
@ -1137,7 +1143,7 @@ impl<T> RingBuf<T> {
/// buf.remove(2);
/// assert_eq!(Some(&15), buf.get(2));
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn remove(&mut self, i: uint) -> Option<T> {
if self.is_empty() || self.len() <= i {
return None;
@ -1304,7 +1310,8 @@ impl<T: Clone> RingBuf<T> {
/// assert_eq!(a, b);
/// }
/// ```
#[unstable = "matches collection reform specification; waiting on panic semantics"]
#[unstable(feature = "collections",
reason = "matches collection reform specification; waiting on panic semantics")]
pub fn resize(&mut self, new_len: uint, value: T) {
let len = self.len();
@ -1331,7 +1338,7 @@ fn count(tail: uint, head: uint, size: uint) -> uint {
}
/// `RingBuf` iterator.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Iter<'a, T:'a> {
ring: &'a [T],
tail: uint,
@ -1349,7 +1356,7 @@ impl<'a, T> Clone for Iter<'a, T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> Iterator for Iter<'a, T> {
type Item = &'a T;
@ -1370,7 +1377,7 @@ impl<'a, T> Iterator for Iter<'a, T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> DoubleEndedIterator for Iter<'a, T> {
#[inline]
fn next_back(&mut self) -> Option<&'a T> {
@ -1382,10 +1389,10 @@ impl<'a, T> DoubleEndedIterator for Iter<'a, T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> ExactSizeIterator for Iter<'a, T> {}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> RandomAccessIterator for Iter<'a, T> {
#[inline]
fn indexable(&self) -> uint {
@ -1408,7 +1415,7 @@ impl<'a, T> RandomAccessIterator for Iter<'a, T> {
// with returning the mutable reference. I couldn't find a way to
// make the lifetime checker happy so, but there should be a way.
/// `RingBuf` mutable iterator.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct IterMut<'a, T:'a> {
ptr: *mut T,
tail: uint,
@ -1417,7 +1424,7 @@ pub struct IterMut<'a, T:'a> {
marker: marker::ContravariantLifetime<'a>,
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> Iterator for IterMut<'a, T> {
type Item = &'a mut T;
@ -1441,7 +1448,7 @@ impl<'a, T> Iterator for IterMut<'a, T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> DoubleEndedIterator for IterMut<'a, T> {
#[inline]
fn next_back(&mut self) -> Option<&'a mut T> {
@ -1456,16 +1463,16 @@ impl<'a, T> DoubleEndedIterator for IterMut<'a, T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> ExactSizeIterator for IterMut<'a, T> {}
/// A by-value RingBuf iterator
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct IntoIter<T> {
inner: RingBuf<T>,
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Iterator for IntoIter<T> {
type Item = T;
@ -1481,7 +1488,7 @@ impl<T> Iterator for IntoIter<T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> DoubleEndedIterator for IntoIter<T> {
#[inline]
fn next_back(&mut self) -> Option<T> {
@ -1489,17 +1496,18 @@ impl<T> DoubleEndedIterator for IntoIter<T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ExactSizeIterator for IntoIter<T> {}
/// A draining RingBuf iterator
#[unstable = "matches collection reform specification, waiting for dust to settle"]
#[unstable(feature = "collections",
reason = "matches collection reform specification, waiting for dust to settle")]
pub struct Drain<'a, T: 'a> {
inner: &'a mut RingBuf<T>,
}
#[unsafe_destructor]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: 'a> Drop for Drain<'a, T> {
fn drop(&mut self) {
for _ in *self {}
@ -1508,7 +1516,7 @@ impl<'a, T: 'a> Drop for Drain<'a, T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: 'a> Iterator for Drain<'a, T> {
type Item = T;
@ -1524,7 +1532,7 @@ impl<'a, T: 'a> Iterator for Drain<'a, T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: 'a> DoubleEndedIterator for Drain<'a, T> {
#[inline]
fn next_back(&mut self) -> Option<T> {
@ -1532,10 +1540,10 @@ impl<'a, T: 'a> DoubleEndedIterator for Drain<'a, T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: 'a> ExactSizeIterator for Drain<'a, T> {}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<A: PartialEq> PartialEq for RingBuf<A> {
fn eq(&self, other: &RingBuf<A>) -> bool {
self.len() == other.len() &&
@ -1543,17 +1551,17 @@ impl<A: PartialEq> PartialEq for RingBuf<A> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<A: Eq> Eq for RingBuf<A> {}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<A: PartialOrd> PartialOrd for RingBuf<A> {
fn partial_cmp(&self, other: &RingBuf<A>) -> Option<Ordering> {
iter::order::partial_cmp(self.iter(), other.iter())
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<A: Ord> Ord for RingBuf<A> {
#[inline]
fn cmp(&self, other: &RingBuf<A>) -> Ordering {
@ -1561,7 +1569,7 @@ impl<A: Ord> Ord for RingBuf<A> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<S: Writer + Hasher, A: Hash<S>> Hash<S> for RingBuf<A> {
fn hash(&self, state: &mut S) {
self.len().hash(state);
@ -1571,7 +1579,7 @@ impl<S: Writer + Hasher, A: Hash<S>> Hash<S> for RingBuf<A> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<A> Index<uint> for RingBuf<A> {
type Output = A;
@ -1581,7 +1589,7 @@ impl<A> Index<uint> for RingBuf<A> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<A> IndexMut<uint> for RingBuf<A> {
type Output = A;
@ -1591,7 +1599,7 @@ impl<A> IndexMut<uint> for RingBuf<A> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<A> FromIterator<A> for RingBuf<A> {
fn from_iter<T: Iterator<Item=A>>(iterator: T) -> RingBuf<A> {
let (lower, _) = iterator.size_hint();
@ -1601,7 +1609,7 @@ impl<A> FromIterator<A> for RingBuf<A> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<A> Extend<A> for RingBuf<A> {
fn extend<T: Iterator<Item=A>>(&mut self, mut iterator: T) {
for elt in iterator {
@ -1610,7 +1618,7 @@ impl<A> Extend<A> for RingBuf<A> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: fmt::Debug> fmt::Debug for RingBuf<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(write!(f, "RingBuf ["));

View File

@ -86,7 +86,7 @@
//! * Further iterators exist that split, chunk or permute the slice.
#![doc(primitive = "slice")]
#![stable]
#![stable(feature = "rust1", since = "1.0.0")]
use alloc::boxed::Box;
use core::borrow::{BorrowFrom, BorrowFromMut, ToOwned};
@ -120,9 +120,9 @@ pub use core::slice::{from_raw_buf, from_raw_mut_buf};
////////////////////////////////////////////////////////////////////////////////
/// Allocating extension methods for slices.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait SliceExt {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
type Item;
/// Sorts the slice, in place, using `compare` to compare
@ -142,7 +142,7 @@ pub trait SliceExt {
/// v.sort_by(|a, b| b.cmp(a));
/// assert!(v == [5, 4, 3, 2, 1]);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn sort_by<F>(&mut self, compare: F) where F: FnMut(&Self::Item, &Self::Item) -> Ordering;
/// Consumes `src` and moves as many elements as it can into `self`
@ -166,19 +166,26 @@ pub trait SliceExt {
/// assert_eq!(num_moved, 3);
/// assert!(a == [6i, 7, 8, 4, 5]);
/// ```
#[unstable = "uncertain about this API approach"]
#[unstable(feature = "collections",
reason = "uncertain about this API approach")]
fn move_from(&mut self, src: Vec<Self::Item>, start: uint, end: uint) -> uint;
/// Deprecated: use `&s[start .. end]` notation instead.
#[deprecated = "use &s[start .. end] instead"]
#[unstable(feature = "collections",
reason = "will be replaced by slice syntax")]
#[deprecated(since = "1.0.0", reason = "use &s[start .. end] instead")]
fn slice(&self, start: uint, end: uint) -> &[Self::Item];
/// Deprecated: use `&s[start..]` notation instead.
#[deprecated = "use &s[start..] instead"]
#[unstable(feature = "collections",
reason = "will be replaced by slice syntax")]
#[deprecated(since = "1.0.0", reason = "use &s[start..] instead")]
fn slice_from(&self, start: uint) -> &[Self::Item];
/// Deprecated: use `&s[..end]` notation instead.
#[deprecated = "use &s[..end] instead"]
#[unstable(feature = "collections",
reason = "will be replaced by slice syntax")]
#[deprecated(since = "1.0.0", reason = "use &s[..end] instead")]
fn slice_to(&self, end: uint) -> &[Self::Item];
/// Divides one slice into two at an index.
@ -197,11 +204,11 @@ pub trait SliceExt {
/// assert_eq!([10, 40], v1);
/// assert_eq!([30, 20, 50], v2);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn split_at(&self, mid: uint) -> (&[Self::Item], &[Self::Item]);
/// Returns an iterator over the slice.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn iter(&self) -> Iter<Self::Item>;
/// Returns an iterator over subslices separated by elements that match
@ -218,7 +225,7 @@ pub trait SliceExt {
/// println!("{:?}", group);
/// }
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn split<F>(&self, pred: F) -> Split<Self::Item, F>
where F: FnMut(&Self::Item) -> bool;
@ -237,7 +244,7 @@ pub trait SliceExt {
/// println!("{:?}", group);
/// }
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn splitn<F>(&self, n: uint, pred: F) -> SplitN<Self::Item, F>
where F: FnMut(&Self::Item) -> bool;
@ -257,7 +264,7 @@ pub trait SliceExt {
/// println!("{:?}", group);
/// }
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn rsplitn<F>(&self, n: uint, pred: F) -> RSplitN<Self::Item, F>
where F: FnMut(&Self::Item) -> bool;
@ -280,7 +287,7 @@ pub trait SliceExt {
/// println!("{:?}", win);
/// }
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn windows(&self, size: uint) -> Windows<Self::Item>;
/// Returns an iterator over `size` elements of the slice at a
@ -303,7 +310,7 @@ pub trait SliceExt {
/// println!("{:?}", win);
/// }
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn chunks(&self, size: uint) -> Chunks<Self::Item>;
/// Returns the element of a slice at the given index, or `None` if the
@ -316,7 +323,7 @@ pub trait SliceExt {
/// assert_eq!(Some(&40), v.get(1));
/// assert_eq!(None, v.get(3));
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn get(&self, index: uint) -> Option<&Self::Item>;
/// Returns the first element of a slice, or `None` if it is empty.
@ -330,15 +337,15 @@ pub trait SliceExt {
/// let w: &[i32] = &[];
/// assert_eq!(None, w.first());
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn first(&self) -> Option<&Self::Item>;
/// Returns all but the first element of a slice.
#[unstable = "likely to be renamed"]
#[unstable(feature = "collections", reason = "likely to be renamed")]
fn tail(&self) -> &[Self::Item];
/// Returns all but the last element of a slice.
#[unstable = "likely to be renamed"]
#[unstable(feature = "collections", reason = "likely to be renamed")]
fn init(&self) -> &[Self::Item];
/// Returns the last element of a slice, or `None` if it is empty.
@ -352,12 +359,12 @@ pub trait SliceExt {
/// let w: &[i32] = &[];
/// assert_eq!(None, w.last());
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn last(&self) -> Option<&Self::Item>;
/// Returns a pointer to the element at the given index, without doing
/// bounds checking.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
unsafe fn get_unchecked(&self, index: uint) -> &Self::Item;
/// Returns an unsafe pointer to the slice's buffer
@ -367,7 +374,7 @@ pub trait SliceExt {
///
/// Modifying the slice may cause its buffer to be reallocated, which
/// would also make any pointers to it invalid.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn as_ptr(&self) -> *const Self::Item;
/// Binary search a sorted slice with a comparator function.
@ -402,7 +409,7 @@ pub trait SliceExt {
/// let r = s.binary_search_by(|probe| probe.cmp(&seek));
/// assert!(match r { Ok(1...4) => true, _ => false, });
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn binary_search_by<F>(&self, f: F) -> Result<uint, uint> where
F: FnMut(&Self::Item) -> Ordering;
@ -414,7 +421,7 @@ pub trait SliceExt {
/// let a = [1i, 2, 3];
/// assert_eq!(a.len(), 3);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn len(&self) -> uint;
/// Returns true if the slice has a length of 0
@ -426,60 +433,68 @@ pub trait SliceExt {
/// assert!(!a.is_empty());
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn is_empty(&self) -> bool { self.len() == 0 }
/// Returns a mutable reference to the element at the given index,
/// or `None` if the index is out of bounds
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn get_mut(&mut self, index: uint) -> Option<&mut Self::Item>;
/// Work with `self` as a mut slice.
/// Primarily intended for getting a &mut [T] from a [T; N].
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn as_mut_slice(&mut self) -> &mut [Self::Item];
/// Deprecated: use `&mut s[start .. end]` instead.
#[deprecated = "use &mut s[start .. end] instead"]
#[unstable(feature = "collections",
reason = "will be replaced by slice syntax")]
#[deprecated(since = "1.0.0", reason = "use &mut s[start .. end] instead")]
fn slice_mut(&mut self, start: uint, end: uint) -> &mut [Self::Item];
/// Deprecated: use `&mut s[start ..]` instead.
#[deprecated = "use &mut s[start ..] instead"]
#[unstable(feature = "collections",
reason = "will be replaced by slice syntax")]
#[deprecated(since = "1.0.0", reason = "use &mut s[start ..] instead")]
fn slice_from_mut(&mut self, start: uint) -> &mut [Self::Item];
/// Deprecated: use `&mut s[.. end]` instead.
#[deprecated = "use &mut s[.. end] instead"]
#[unstable(feature = "collections",
reason = "will be replaced by slice syntax")]
#[deprecated(since = "1.0.0", reason = "use &mut s[.. end] instead")]
fn slice_to_mut(&mut self, end: uint) -> &mut [Self::Item];
/// Returns an iterator that allows modifying each value
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn iter_mut(&mut self) -> IterMut<Self::Item>;
/// Returns a mutable pointer to the first element of a slice, or `None` if it is empty
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn first_mut(&mut self) -> Option<&mut Self::Item>;
/// Returns all but the first element of a mutable slice
#[unstable = "likely to be renamed or removed"]
#[unstable(feature = "collections",
reason = "likely to be renamed or removed")]
fn tail_mut(&mut self) -> &mut [Self::Item];
/// Returns all but the last element of a mutable slice
#[unstable = "likely to be renamed or removed"]
#[unstable(feature = "collections",
reason = "likely to be renamed or removed")]
fn init_mut(&mut self) -> &mut [Self::Item];
/// Returns a mutable pointer to the last item in the slice.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn last_mut(&mut self) -> Option<&mut Self::Item>;
/// Returns an iterator over mutable subslices separated by elements that
/// match `pred`. The matched element is not contained in the subslices.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn split_mut<F>(&mut self, pred: F) -> SplitMut<Self::Item, F>
where F: FnMut(&Self::Item) -> bool;
/// Returns an iterator over subslices separated by elements that match
/// `pred`, limited to splitting at most `n` times. The matched element is
/// not contained in the subslices.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn splitn_mut<F>(&mut self, n: uint, pred: F) -> SplitNMut<Self::Item, F>
where F: FnMut(&Self::Item) -> bool;
@ -487,7 +502,7 @@ pub trait SliceExt {
/// `pred` limited to splitting at most `n` times. This starts at the end of
/// the slice and works backwards. The matched element is not contained in
/// the subslices.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn rsplitn_mut<F>(&mut self, n: uint, pred: F) -> RSplitNMut<Self::Item, F>
where F: FnMut(&Self::Item) -> bool;
@ -499,7 +514,7 @@ pub trait SliceExt {
/// # Panics
///
/// Panics if `chunk_size` is 0.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn chunks_mut(&mut self, chunk_size: uint) -> ChunksMut<Self::Item>;
/// Swaps two elements in a slice.
@ -520,7 +535,7 @@ pub trait SliceExt {
/// v.swap(1, 3);
/// assert!(v == ["a", "d", "c", "b"]);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn swap(&mut self, a: uint, b: uint);
/// Divides one `&mut` into two at an index.
@ -557,7 +572,7 @@ pub trait SliceExt {
/// assert!(right == []);
/// }
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn split_at_mut(&mut self, mid: uint) -> (&mut [Self::Item], &mut [Self::Item]);
/// Reverse the order of elements in a slice, in place.
@ -569,11 +584,11 @@ pub trait SliceExt {
/// v.reverse();
/// assert!(v == [3i, 2, 1]);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn reverse(&mut self);
/// Returns an unsafe mutable pointer to the element in index
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
unsafe fn get_unchecked_mut(&mut self, index: uint) -> &mut Self::Item;
/// Return an unsafe mutable pointer to the slice's buffer.
@ -584,11 +599,11 @@ pub trait SliceExt {
/// Modifying the slice may cause its buffer to be reallocated, which
/// would also make any pointers to it invalid.
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn as_mut_ptr(&mut self) -> *mut Self::Item;
/// Copies `self` into a new `Vec`.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn to_vec(&self) -> Vec<Self::Item> where Self::Item: Clone;
/// Creates an iterator that yields every possible permutation of the
@ -615,7 +630,7 @@ pub trait SliceExt {
/// assert_eq!(Some(vec![1i, 3, 2]), perms.next());
/// assert_eq!(Some(vec![3i, 1, 2]), perms.next());
/// ```
#[unstable]
#[unstable(feature = "collections")]
fn permutations(&self) -> Permutations<Self::Item> where Self::Item: Clone;
/// Copies as many elements from `src` as it can into `self` (the
@ -635,7 +650,7 @@ pub trait SliceExt {
/// assert!(dst.clone_from_slice(&src2) == 3);
/// assert!(dst == [3i, 4, 5]);
/// ```
#[unstable]
#[unstable(feature = "collections")]
fn clone_from_slice(&mut self, &[Self::Item]) -> uint where Self::Item: Clone;
/// Sorts the slice, in place.
@ -650,7 +665,7 @@ pub trait SliceExt {
/// v.sort();
/// assert!(v == [-5i, -3, 1, 2, 4]);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn sort(&mut self) where Self::Item: Ord;
/// Binary search a sorted slice for a given element.
@ -676,11 +691,12 @@ pub trait SliceExt {
/// let r = s.binary_search(&1);
/// assert!(match r { Ok(1...4) => true, _ => false, });
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn binary_search(&self, x: &Self::Item) -> Result<uint, uint> where Self::Item: Ord;
/// Deprecated: use `binary_search` instead.
#[deprecated = "use binary_search instead"]
#[unstable(feature = "collections")]
#[deprecated(since = "1.0.0", reason = "use binary_search instead")]
fn binary_search_elem(&self, x: &Self::Item) -> Result<uint, uint> where Self::Item: Ord {
self.binary_search(x)
}
@ -701,7 +717,8 @@ pub trait SliceExt {
/// let b: &mut [_] = &mut [1i, 0, 2];
/// assert!(v == b);
/// ```
#[unstable = "uncertain if this merits inclusion in std"]
#[unstable(feature = "collections",
reason = "uncertain if this merits inclusion in std")]
fn next_permutation(&mut self) -> bool where Self::Item: Ord;
/// Mutates the slice to the previous lexicographic permutation.
@ -720,15 +737,16 @@ pub trait SliceExt {
/// let b: &mut [_] = &mut [0i, 1, 2];
/// assert!(v == b);
/// ```
#[unstable = "uncertain if this merits inclusion in std"]
#[unstable(feature = "collections",
reason = "uncertain if this merits inclusion in std")]
fn prev_permutation(&mut self) -> bool where Self::Item: Ord;
/// Find the first index containing a matching value.
#[unstable]
#[unstable(feature = "collections")]
fn position_elem(&self, t: &Self::Item) -> Option<uint> where Self::Item: PartialEq;
/// Find the last index containing a matching value.
#[unstable]
#[unstable(feature = "collections")]
fn rposition_elem(&self, t: &Self::Item) -> Option<uint> where Self::Item: PartialEq;
/// Returns true if the slice contains an element with the given value.
@ -740,7 +758,7 @@ pub trait SliceExt {
/// assert!(v.contains(&30));
/// assert!(!v.contains(&50));
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn contains(&self, x: &Self::Item) -> bool where Self::Item: PartialEq;
/// Returns true if `needle` is a prefix of the slice.
@ -754,7 +772,7 @@ pub trait SliceExt {
/// assert!(!v.starts_with(&[50]));
/// assert!(!v.starts_with(&[10, 50]));
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn starts_with(&self, needle: &[Self::Item]) -> bool where Self::Item: PartialEq;
/// Returns true if `needle` is a suffix of the slice.
@ -768,15 +786,15 @@ pub trait SliceExt {
/// assert!(!v.ends_with(&[50]));
/// assert!(!v.ends_with(&[50, 30]));
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn ends_with(&self, needle: &[Self::Item]) -> bool where Self::Item: PartialEq;
/// Convert `self` into a vector without clones or allocation.
#[unstable]
#[unstable(feature = "collections")]
fn into_vec(self: Box<Self>) -> Vec<Self::Item>;
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> SliceExt for [T] {
type Item = T;
@ -1064,7 +1082,7 @@ impl<T> SliceExt for [T] {
////////////////////////////////////////////////////////////////////////////////
// Extension traits for slices over specific kinds of data
////////////////////////////////////////////////////////////////////////////////
#[unstable = "U should be an associated type"]
#[unstable(feature = "collections", reason = "U should be an associated type")]
/// An extension trait for concatenating slices
pub trait SliceConcatExt<T: ?Sized, U> {
/// Flattens a slice of `T` into a single value `U`.
@ -1078,7 +1096,7 @@ pub trait SliceConcatExt<T: ?Sized, U> {
///
/// println!("{}", s); // prints "helloworld"
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn concat(&self) -> U;
/// Flattens a slice of `T` into a single value `U`, placing a given separator between each.
@ -1092,7 +1110,7 @@ pub trait SliceConcatExt<T: ?Sized, U> {
///
/// println!("{}", s); // prints "hello world"
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn connect(&self, sep: &T) -> U;
}
@ -1128,7 +1146,7 @@ impl<T: Clone, V: AsSlice<T>> SliceConcatExt<T, Vec<T>> for [V] {
///
/// The last generated swap is always (0, 1), and it returns the
/// sequence to its initial order.
#[unstable]
#[unstable(feature = "collections")]
#[derive(Clone)]
pub struct ElementSwaps {
sdir: Vec<SizeDirection>,
@ -1140,7 +1158,7 @@ pub struct ElementSwaps {
impl ElementSwaps {
/// Creates an `ElementSwaps` iterator for a sequence of `length` elements.
#[unstable]
#[unstable(feature = "collections")]
pub fn new(length: uint) -> ElementSwaps {
// Initialize `sdir` with a direction that position should move in
// (all negative at the beginning) and the `size` of the
@ -1157,17 +1175,17 @@ impl ElementSwaps {
// Standard trait implementations for slices
////////////////////////////////////////////////////////////////////////////////
#[unstable = "trait is unstable"]
#[unstable(feature = "collections", reason = "trait is unstable")]
impl<T> BorrowFrom<Vec<T>> for [T] {
fn borrow_from(owned: &Vec<T>) -> &[T] { &owned[] }
}
#[unstable = "trait is unstable"]
#[unstable(feature = "collections", reason = "trait is unstable")]
impl<T> BorrowFromMut<Vec<T>> for [T] {
fn borrow_from_mut(owned: &mut Vec<T>) -> &mut [T] { &mut owned[] }
}
#[unstable = "trait is unstable"]
#[unstable(feature = "collections", reason = "trait is unstable")]
impl<T: Clone> ToOwned<Vec<T>> for [T] {
fn to_owned(&self) -> Vec<T> { self.to_vec() }
}
@ -1186,7 +1204,7 @@ struct SizeDirection {
dir: Direction,
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Iterator for ElementSwaps {
type Item = (uint, uint);
@ -1249,13 +1267,13 @@ impl Iterator for ElementSwaps {
/// swap applied.
///
/// Generates even and odd permutations alternately.
#[unstable]
#[unstable(feature = "collections")]
pub struct Permutations<T> {
swaps: ElementSwaps,
v: Vec<T>,
}
#[unstable = "trait is unstable"]
#[unstable(feature = "collections", reason = "trait is unstable")]
impl<T: Clone> Iterator for Permutations<T> {
type Item = Vec<T>;

View File

@ -50,7 +50,7 @@
//! is the same as `&[u8]`.
#![doc(primitive = "str")]
#![stable]
#![stable(feature = "rust1", since = "1.0.0")]
use self::RecompositionState::*;
use self::DecompositionType::*;
@ -165,7 +165,7 @@ enum DecompositionType {
/// External iterator for a string's decomposition's characters.
/// Use with the `std::iter` module.
#[derive(Clone)]
#[unstable]
#[unstable(feature = "collections")]
pub struct Decompositions<'a> {
kind: DecompositionType,
iter: Chars<'a>,
@ -173,7 +173,7 @@ pub struct Decompositions<'a> {
sorted: bool
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> Iterator for Decompositions<'a> {
type Item = char;
@ -255,7 +255,7 @@ enum RecompositionState {
/// External iterator for a string's recomposition's characters.
/// Use with the `std::iter` module.
#[derive(Clone)]
#[unstable]
#[unstable(feature = "collections")]
pub struct Recompositions<'a> {
iter: Decompositions<'a>,
state: RecompositionState,
@ -264,7 +264,7 @@ pub struct Recompositions<'a> {
last_ccc: Option<u8>
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> Iterator for Recompositions<'a> {
type Item = char;
@ -352,12 +352,12 @@ impl<'a> Iterator for Recompositions<'a> {
/// External iterator for a string's UTF16 codeunits.
/// Use with the `std::iter` module.
#[derive(Clone)]
#[unstable]
#[unstable(feature = "collections")]
pub struct Utf16Units<'a> {
encoder: Utf16Encoder<Chars<'a>>
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> Iterator for Utf16Units<'a> {
type Item = u16;
@ -384,12 +384,12 @@ macro_rules! utf8_acc_cont_byte {
($ch:expr, $byte:expr) => (($ch << 6) | ($byte & 63u8) as u32)
}
#[unstable = "trait is unstable"]
#[unstable(feature = "collections", reason = "trait is unstable")]
impl BorrowFrom<String> for str {
fn borrow_from(owned: &String) -> &str { &owned[] }
}
#[unstable = "trait is unstable"]
#[unstable(feature = "collections", reason = "trait is unstable")]
impl ToOwned<String> for str {
fn to_owned(&self) -> String {
unsafe {
@ -407,16 +407,18 @@ Section: Trait implementations
*/
/// Any string that can be represented as a slice.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait StrExt: Index<FullRange, Output = str> {
/// Escapes each char in `s` with `char::escape_default`.
#[unstable = "return type may change to be an iterator"]
#[unstable(feature = "collections",
reason = "return type may change to be an iterator")]
fn escape_default(&self) -> String {
self.chars().flat_map(|c| c.escape_default()).collect()
}
/// Escapes each char in `s` with `char::escape_unicode`.
#[unstable = "return type may change to be an iterator"]
#[unstable(feature = "collections",
reason = "return type may change to be an iterator")]
fn escape_unicode(&self) -> String {
self.chars().flat_map(|c| c.escape_unicode()).collect()
}
@ -445,7 +447,7 @@ pub trait StrExt: Index<FullRange, Output = str> {
/// // not found, so no change.
/// assert_eq!(s.replace("cookie monster", "little lamb"), s);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn replace(&self, from: &str, to: &str) -> String {
let mut result = String::new();
let mut last_end = 0;
@ -461,7 +463,8 @@ pub trait StrExt: Index<FullRange, Output = str> {
/// Returns an iterator over the string in Unicode Normalization Form D
/// (canonical decomposition).
#[inline]
#[unstable = "this functionality may be moved to libunicode"]
#[unstable(feature = "collections",
reason = "this functionality may be moved to libunicode")]
fn nfd_chars<'a>(&'a self) -> Decompositions<'a> {
Decompositions {
iter: self[].chars(),
@ -474,7 +477,8 @@ pub trait StrExt: Index<FullRange, Output = str> {
/// Returns an iterator over the string in Unicode Normalization Form KD
/// (compatibility decomposition).
#[inline]
#[unstable = "this functionality may be moved to libunicode"]
#[unstable(feature = "collections",
reason = "this functionality may be moved to libunicode")]
fn nfkd_chars<'a>(&'a self) -> Decompositions<'a> {
Decompositions {
iter: self[].chars(),
@ -487,7 +491,8 @@ pub trait StrExt: Index<FullRange, Output = str> {
/// An Iterator over the string in Unicode Normalization Form C
/// (canonical decomposition followed by canonical composition).
#[inline]
#[unstable = "this functionality may be moved to libunicode"]
#[unstable(feature = "collections",
reason = "this functionality may be moved to libunicode")]
fn nfc_chars<'a>(&'a self) -> Recompositions<'a> {
Recompositions {
iter: self.nfd_chars(),
@ -501,7 +506,8 @@ pub trait StrExt: Index<FullRange, Output = str> {
/// An Iterator over the string in Unicode Normalization Form KC
/// (compatibility decomposition followed by canonical composition).
#[inline]
#[unstable = "this functionality may be moved to libunicode"]
#[unstable(feature = "collections",
reason = "this functionality may be moved to libunicode")]
fn nfkc_chars<'a>(&'a self) -> Recompositions<'a> {
Recompositions {
iter: self.nfkd_chars(),
@ -523,7 +529,7 @@ pub trait StrExt: Index<FullRange, Output = str> {
/// ```rust
/// assert!("bananas".contains("nana"));
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn contains(&self, pat: &str) -> bool {
core_str::StrExt::contains(&self[], pat)
}
@ -539,7 +545,8 @@ pub trait StrExt: Index<FullRange, Output = str> {
/// ```rust
/// assert!("hello".contains_char('e'));
/// ```
#[unstable = "might get removed in favour of a more generic contains()"]
#[unstable(feature = "collections",
reason = "might get removed in favour of a more generic contains()")]
fn contains_char<P: CharEq>(&self, pat: P) -> bool {
core_str::StrExt::contains_char(&self[], pat)
}
@ -553,7 +560,7 @@ pub trait StrExt: Index<FullRange, Output = str> {
/// let v: Vec<char> = "abc åäö".chars().collect();
/// assert_eq!(v, vec!['a', 'b', 'c', ' ', 'å', 'ä', 'ö']);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn chars(&self) -> Chars {
core_str::StrExt::chars(&self[])
}
@ -566,13 +573,13 @@ pub trait StrExt: Index<FullRange, Output = str> {
/// let v: Vec<u8> = "bors".bytes().collect();
/// assert_eq!(v, b"bors".to_vec());
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn bytes(&self) -> Bytes {
core_str::StrExt::bytes(&self[])
}
/// An iterator over the characters of `self` and their byte offsets.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn char_indices(&self) -> CharIndices {
core_str::StrExt::char_indices(&self[])
}
@ -595,7 +602,7 @@ pub trait StrExt: Index<FullRange, Output = str> {
/// let v: Vec<&str> = "".split('X').collect();
/// assert_eq!(v, vec![""]);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn split<P: CharEq>(&self, pat: P) -> Split<P> {
core_str::StrExt::split(&self[], pat)
}
@ -622,7 +629,7 @@ pub trait StrExt: Index<FullRange, Output = str> {
/// let v: Vec<&str> = "".splitn(1, 'X').collect();
/// assert_eq!(v, vec![""]);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn splitn<P: CharEq>(&self, count: uint, pat: P) -> SplitN<P> {
core_str::StrExt::splitn(&self[], count, pat)
}
@ -651,7 +658,7 @@ pub trait StrExt: Index<FullRange, Output = str> {
/// let v: Vec<&str> = "lionXXtigerXleopard".split('X').rev().collect();
/// assert_eq!(v, vec!["leopard", "tiger", "", "lion"]);
/// ```
#[unstable = "might get removed"]
#[unstable(feature = "collections", reason = "might get removed")]
fn split_terminator<P: CharEq>(&self, pat: P) -> SplitTerminator<P> {
core_str::StrExt::split_terminator(&self[], pat)
}
@ -672,7 +679,7 @@ pub trait StrExt: Index<FullRange, Output = str> {
/// let v: Vec<&str> = "lionXXtigerXleopard".rsplitn(2, 'X').collect();
/// assert_eq!(v, vec!["leopard", "tiger", "lionX"]);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn rsplitn<P: CharEq>(&self, count: uint, pat: P) -> RSplitN<P> {
core_str::StrExt::rsplitn(&self[], count, pat)
}
@ -697,7 +704,8 @@ pub trait StrExt: Index<FullRange, Output = str> {
/// let v: Vec<(uint, uint)> = "ababa".match_indices("aba").collect();
/// assert_eq!(v, vec![(0, 3)]); // only the first `aba`
/// ```
#[unstable = "might have its iterator type changed"]
#[unstable(feature = "collections",
reason = "might have its iterator type changed")]
fn match_indices<'a>(&'a self, pat: &'a str) -> MatchIndices<'a> {
core_str::StrExt::match_indices(&self[], pat)
}
@ -713,7 +721,8 @@ pub trait StrExt: Index<FullRange, Output = str> {
/// let v: Vec<&str> = "1abcabc2".split_str("abc").collect();
/// assert_eq!(v, vec!["1", "", "2"]);
/// ```
#[unstable = "might get removed in the future in favor of a more generic split()"]
#[unstable(feature = "collections",
reason = "might get removed in the future in favor of a more generic split()")]
fn split_str<'a>(&'a self, pat: &'a str) -> SplitStr<'a> {
core_str::StrExt::split_str(&self[], pat)
}
@ -729,7 +738,7 @@ pub trait StrExt: Index<FullRange, Output = str> {
/// let v: Vec<&str> = four_lines.lines().collect();
/// assert_eq!(v, vec!["foo", "bar", "", "baz"]);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn lines(&self) -> Lines {
core_str::StrExt::lines(&self[])
}
@ -745,21 +754,27 @@ pub trait StrExt: Index<FullRange, Output = str> {
/// let v: Vec<&str> = four_lines.lines_any().collect();
/// assert_eq!(v, vec!["foo", "bar", "", "baz"]);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn lines_any(&self) -> LinesAny {
core_str::StrExt::lines_any(&self[])
}
/// Deprecated: use `s[a .. b]` instead.
#[deprecated = "use slice notation [a..b] instead"]
#[unstable(feature = "collections",
reason = "use slice notation [a..b] instead")]
#[deprecated(since = "1.0.0", reason = "use slice notation [a..b] instead")]
fn slice(&self, begin: uint, end: uint) -> &str;
/// Deprecated: use `s[a..]` instead.
#[deprecated = "use slice notation [a..] instead"]
#[unstable(feature = "collections",
reason = "use slice notation [a..b] instead")]
#[deprecated(since = "1.0.0", reason = "use slice notation [a..] instead")]
fn slice_from(&self, begin: uint) -> &str;
/// Deprecated: use `s[..a]` instead.
#[deprecated = "use slice notation [..a] instead"]
#[unstable(feature = "collections",
reason = "use slice notation [a..b] instead")]
#[deprecated(since = "1.0.0", reason = "use slice notation [..a] instead")]
fn slice_to(&self, end: uint) -> &str;
/// Returns a slice of the string from the character range
@ -785,7 +800,8 @@ pub trait StrExt: Index<FullRange, Output = str> {
/// assert_eq!(s.slice_chars(0, 4), "Löwe");
/// assert_eq!(s.slice_chars(5, 7), "老虎");
/// ```
#[unstable = "may have yet to prove its worth"]
#[unstable(feature = "collections",
reason = "may have yet to prove its worth")]
fn slice_chars(&self, begin: uint, end: uint) -> &str {
core_str::StrExt::slice_chars(&self[], begin, end)
}
@ -796,7 +812,7 @@ pub trait StrExt: Index<FullRange, Output = str> {
///
/// Caller must check both UTF-8 character boundaries and the boundaries of
/// the entire slice as well.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
unsafe fn slice_unchecked(&self, begin: uint, end: uint) -> &str {
core_str::StrExt::slice_unchecked(&self[], begin, end)
}
@ -808,7 +824,7 @@ pub trait StrExt: Index<FullRange, Output = str> {
/// ```rust
/// assert!("banana".starts_with("ba"));
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn starts_with(&self, pat: &str) -> bool {
core_str::StrExt::starts_with(&self[], pat)
}
@ -820,7 +836,7 @@ pub trait StrExt: Index<FullRange, Output = str> {
/// ```rust
/// assert!("banana".ends_with("nana"));
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn ends_with(&self, pat: &str) -> bool {
core_str::StrExt::ends_with(&self[], pat)
}
@ -840,7 +856,7 @@ pub trait StrExt: Index<FullRange, Output = str> {
/// assert_eq!("12foo1bar12".trim_matches(x), "foo1bar");
/// assert_eq!("123foo1bar123".trim_matches(|&: c: char| c.is_numeric()), "foo1bar");
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn trim_matches<P: CharEq>(&self, pat: P) -> &str {
core_str::StrExt::trim_matches(&self[], pat)
}
@ -860,7 +876,7 @@ pub trait StrExt: Index<FullRange, Output = str> {
/// assert_eq!("12foo1bar12".trim_left_matches(x), "foo1bar12");
/// assert_eq!("123foo1bar123".trim_left_matches(|&: c: char| c.is_numeric()), "foo1bar123");
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn trim_left_matches<P: CharEq>(&self, pat: P) -> &str {
core_str::StrExt::trim_left_matches(&self[], pat)
}
@ -880,7 +896,7 @@ pub trait StrExt: Index<FullRange, Output = str> {
/// assert_eq!("12foo1bar12".trim_right_matches(x), "12foo1bar");
/// assert_eq!("123foo1bar123".trim_right_matches(|&: c: char| c.is_numeric()), "123foo1bar");
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn trim_right_matches<P: CharEq>(&self, pat: P) -> &str {
core_str::StrExt::trim_right_matches(&self[], pat)
}
@ -908,7 +924,8 @@ pub trait StrExt: Index<FullRange, Output = str> {
/// // third byte of `老`
/// assert!(!s.is_char_boundary(8));
/// ```
#[unstable = "naming is uncertain with container conventions"]
#[unstable(feature = "collections",
reason = "naming is uncertain with container conventions")]
fn is_char_boundary(&self, index: uint) -> bool {
core_str::StrExt::is_char_boundary(&self[], index)
}
@ -966,7 +983,8 @@ pub trait StrExt: Index<FullRange, Output = str> {
///
/// If `i` is greater than or equal to the length of the string.
/// If `i` is not the index of the beginning of a valid UTF-8 character.
#[unstable = "naming is uncertain with container conventions"]
#[unstable(feature = "collections",
reason = "naming is uncertain with container conventions")]
fn char_range_at(&self, start: uint) -> CharRange {
core_str::StrExt::char_range_at(&self[], start)
}
@ -981,7 +999,8 @@ pub trait StrExt: Index<FullRange, Output = str> {
///
/// If `i` is greater than the length of the string.
/// If `i` is not an index following a valid UTF-8 character.
#[unstable = "naming is uncertain with container conventions"]
#[unstable(feature = "collections",
reason = "naming is uncertain with container conventions")]
fn char_range_at_reverse(&self, start: uint) -> CharRange {
core_str::StrExt::char_range_at_reverse(&self[], start)
}
@ -1001,7 +1020,8 @@ pub trait StrExt: Index<FullRange, Output = str> {
///
/// If `i` is greater than or equal to the length of the string.
/// If `i` is not the index of the beginning of a valid UTF-8 character.
#[unstable = "naming is uncertain with container conventions"]
#[unstable(feature = "collections",
reason = "naming is uncertain with container conventions")]
fn char_at(&self, i: uint) -> char {
core_str::StrExt::char_at(&self[], i)
}
@ -1012,7 +1032,8 @@ pub trait StrExt: Index<FullRange, Output = str> {
///
/// If `i` is greater than the length of the string.
/// If `i` is not an index following a valid UTF-8 character.
#[unstable = "naming is uncertain with container conventions"]
#[unstable(feature = "collections",
reason = "naming is uncertain with container conventions")]
fn char_at_reverse(&self, i: uint) -> char {
core_str::StrExt::char_at_reverse(&self[], i)
}
@ -1024,7 +1045,7 @@ pub trait StrExt: Index<FullRange, Output = str> {
/// ```rust
/// assert_eq!("bors".as_bytes(), b"bors");
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn as_bytes(&self) -> &[u8] {
core_str::StrExt::as_bytes(&self[])
}
@ -1052,7 +1073,7 @@ pub trait StrExt: Index<FullRange, Output = str> {
/// let x: &[_] = &['1', '2'];
/// assert_eq!(s.find(x), None);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn find<P: CharEq>(&self, pat: P) -> Option<uint> {
core_str::StrExt::find(&self[], pat)
}
@ -1080,7 +1101,7 @@ pub trait StrExt: Index<FullRange, Output = str> {
/// let x: &[_] = &['1', '2'];
/// assert_eq!(s.rfind(x), None);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn rfind<P: CharEq>(&self, pat: P) -> Option<uint> {
core_str::StrExt::rfind(&self[], pat)
}
@ -1104,7 +1125,8 @@ pub trait StrExt: Index<FullRange, Output = str> {
/// assert_eq!(s.find_str("老虎 L"), Some(6));
/// assert_eq!(s.find_str("muffin man"), None);
/// ```
#[unstable = "might get removed in favor of a more generic find in the future"]
#[unstable(feature = "collections",
reason = "might get removed in favor of a more generic find in the future")]
fn find_str(&self, needle: &str) -> Option<uint> {
core_str::StrExt::find_str(&self[], needle)
}
@ -1127,7 +1149,8 @@ pub trait StrExt: Index<FullRange, Output = str> {
/// assert_eq!(c, 'ö');
/// assert_eq!(s2, "we 老虎 Léopard");
/// ```
#[unstable = "awaiting conventions about shifting and slices"]
#[unstable(feature = "collections",
reason = "awaiting conventions about shifting and slices")]
fn slice_shift_char(&self) -> Option<(char, &str)> {
core_str::StrExt::slice_shift_char(&self[])
}
@ -1146,7 +1169,8 @@ pub trait StrExt: Index<FullRange, Output = str> {
/// assert!(string.subslice_offset(lines[1]) == 2); // &"b"
/// assert!(string.subslice_offset(lines[2]) == 4); // &"c"
/// ```
#[unstable = "awaiting convention about comparability of arbitrary slices"]
#[unstable(feature = "collections",
reason = "awaiting convention about comparability of arbitrary slices")]
fn subslice_offset(&self, inner: &str) -> uint {
core_str::StrExt::subslice_offset(&self[], inner)
}
@ -1156,14 +1180,15 @@ pub trait StrExt: Index<FullRange, Output = str> {
/// The caller must ensure that the string outlives this pointer,
/// and that it is not reallocated (e.g. by pushing to the
/// string).
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
fn as_ptr(&self) -> *const u8 {
core_str::StrExt::as_ptr(&self[])
}
/// Return an iterator of `u16` over the string encoded as UTF-16.
#[unstable = "this functionality may only be provided by libunicode"]
#[unstable(feature = "collections",
reason = "this functionality may only be provided by libunicode")]
fn utf16_units(&self) -> Utf16Units {
Utf16Units { encoder: Utf16Encoder::new(self[].chars()) }
}
@ -1176,7 +1201,7 @@ pub trait StrExt: Index<FullRange, Output = str> {
/// assert_eq!("foo".len(), 3);
/// assert_eq!("ƒoo".len(), 4);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
fn len(&self) -> uint {
core_str::StrExt::len(&self[])
@ -1190,7 +1215,7 @@ pub trait StrExt: Index<FullRange, Output = str> {
/// assert!("".is_empty());
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn is_empty(&self) -> bool {
core_str::StrExt::is_empty(&self[])
}
@ -1204,7 +1229,8 @@ pub trait StrExt: Index<FullRange, Output = str> {
/// assert_eq!("j".parse::<u32>(), None);
/// ```
#[inline]
#[unstable = "this method was just created"]
#[unstable(feature = "collections",
reason = "this method was just created")]
fn parse<F: FromStr>(&self) -> Option<F> {
core_str::StrExt::parse(&self[])
}
@ -1228,7 +1254,8 @@ pub trait StrExt: Index<FullRange, Output = str> {
/// let b: &[_] = &["a", "\r\n", "b", "🇷🇺🇸🇹"];
/// assert_eq!(gr2.as_slice(), b);
/// ```
#[unstable = "this functionality may only be provided by libunicode"]
#[unstable(feature = "collections",
reason = "this functionality may only be provided by libunicode")]
fn graphemes(&self, is_extended: bool) -> Graphemes {
UnicodeStr::graphemes(&self[], is_extended)
}
@ -1243,7 +1270,8 @@ pub trait StrExt: Index<FullRange, Output = str> {
/// let b: &[_] = &[(0u, "a̐"), (3, "é"), (6, "ö̲"), (11, "\r\n")];
/// assert_eq!(gr_inds.as_slice(), b);
/// ```
#[unstable = "this functionality may only be provided by libunicode"]
#[unstable(feature = "collections",
reason = "this functionality may only be provided by libunicode")]
fn grapheme_indices(&self, is_extended: bool) -> GraphemeIndices {
UnicodeStr::grapheme_indices(&self[], is_extended)
}
@ -1259,7 +1287,7 @@ pub trait StrExt: Index<FullRange, Output = str> {
/// let v: Vec<&str> = some_words.words().collect();
/// assert_eq!(v, vec!["Mary", "had", "a", "little", "lamb"]);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn words(&self) -> Words {
UnicodeStr::words(&self[])
}
@ -1273,31 +1301,32 @@ pub trait StrExt: Index<FullRange, Output = str> {
/// [Unicode Standard Annex #11](http://www.unicode.org/reports/tr11/)
/// recommends that these characters be treated as 1 column (i.e.,
/// `is_cjk` = `false`) if the locale is unknown.
#[unstable = "this functionality may only be provided by libunicode"]
#[unstable(feature = "collections",
reason = "this functionality may only be provided by libunicode")]
fn width(&self, is_cjk: bool) -> uint {
UnicodeStr::width(&self[], is_cjk)
}
/// Returns a string with leading and trailing whitespace removed.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn trim(&self) -> &str {
UnicodeStr::trim(&self[])
}
/// Returns a string with leading whitespace removed.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn trim_left(&self) -> &str {
UnicodeStr::trim_left(&self[])
}
/// Returns a string with trailing whitespace removed.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn trim_right(&self) -> &str {
UnicodeStr::trim_right(&self[])
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl StrExt for str {
fn slice(&self, begin: uint, end: uint) -> &str {
&self[begin..end]

View File

@ -12,7 +12,7 @@
//! An owned, growable string that enforces that its contents are valid UTF-8.
#![stable]
#![stable(feature = "rust1", since = "1.0.0")]
use core::prelude::*;
@ -34,13 +34,13 @@ use vec::{DerefVec, Vec, as_vec};
/// A growable string stored as a UTF-8 encoded buffer.
#[derive(Clone, PartialOrd, Eq, Ord)]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct String {
vec: Vec<u8>,
}
/// A possible error value from the `String::from_utf8` function.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
#[derive(Show)]
pub struct FromUtf8Error {
bytes: Vec<u8>,
@ -48,7 +48,7 @@ pub struct FromUtf8Error {
}
/// A possible error value from the `String::from_utf16` function.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
#[allow(missing_copy_implementations)]
#[derive(Show)]
pub struct FromUtf16Error(());
@ -62,7 +62,7 @@ impl String {
/// let mut s = String::new();
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new() -> String {
String {
vec: Vec::new(),
@ -79,7 +79,7 @@ impl String {
/// let mut s = String::with_capacity(10);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn with_capacity(capacity: uint) -> String {
String {
vec: Vec::with_capacity(capacity),
@ -95,7 +95,8 @@ impl String {
/// assert_eq!(s.as_slice(), "hello");
/// ```
#[inline]
#[unstable = "needs investigation to see if to_string() can match perf"]
#[unstable(feature = "collections",
reason = "needs investigation to see if to_string() can match perf")]
pub fn from_str(string: &str) -> String {
String { vec: ::slice::SliceExt::to_vec(string.as_bytes()) }
}
@ -123,7 +124,7 @@ impl String {
/// assert_eq!(s.into_bytes(), vec![240, 144, 128]);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn from_utf8(vec: Vec<u8>) -> Result<String, FromUtf8Error> {
match str::from_utf8(vec.as_slice()) {
Ok(..) => Ok(String { vec: vec }),
@ -141,7 +142,7 @@ impl String {
/// let output = String::from_utf8_lossy(input);
/// assert_eq!(output.as_slice(), "Hello \u{FFFD}World");
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn from_utf8_lossy<'a>(v: &'a [u8]) -> CowString<'a> {
let mut i = 0;
match str::from_utf8(v) {
@ -279,7 +280,7 @@ impl String {
/// v[4] = 0xD800;
/// assert!(String::from_utf16(v).is_err());
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn from_utf16(v: &[u16]) -> Result<String, FromUtf16Error> {
let mut s = String::with_capacity(v.len());
for c in unicode_str::utf16_items(v) {
@ -306,7 +307,7 @@ impl String {
/// "𝄞mus\u{FFFD}ic\u{FFFD}".to_string());
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn from_utf16_lossy(v: &[u16]) -> String {
unicode_str::utf16_items(v).map(|c| c.to_char_lossy()).collect()
}
@ -317,7 +318,7 @@ impl String {
/// * We call `Vec::from_raw_parts` to get a `Vec<u8>`;
/// * We assume that the `Vec` contains valid UTF-8.
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub unsafe fn from_raw_parts(buf: *mut u8, length: uint, capacity: uint) -> String {
String {
vec: Vec::from_raw_parts(buf, length, capacity),
@ -328,7 +329,7 @@ impl String {
/// it contains valid UTF-8. This is unsafe because it assumes that
/// the UTF-8-ness of the vector has already been validated.
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub unsafe fn from_utf8_unchecked(bytes: Vec<u8>) -> String {
String { vec: bytes }
}
@ -343,7 +344,7 @@ impl String {
/// assert_eq!(bytes, vec![104, 101, 108, 108, 111]);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn into_bytes(self) -> Vec<u8> {
self.vec
}
@ -358,7 +359,7 @@ impl String {
/// assert_eq!(s.as_slice(), "foobar");
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn push_str(&mut self, string: &str) {
self.vec.push_all(string.as_bytes())
}
@ -373,7 +374,7 @@ impl String {
/// assert!(s.capacity() >= 10);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn capacity(&self) -> uint {
self.vec.capacity()
}
@ -394,7 +395,7 @@ impl String {
/// assert!(s.capacity() >= 10);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn reserve(&mut self, additional: uint) {
self.vec.reserve(additional)
}
@ -419,7 +420,7 @@ impl String {
/// assert!(s.capacity() >= 10);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn reserve_exact(&mut self, additional: uint) {
self.vec.reserve_exact(additional)
}
@ -436,7 +437,7 @@ impl String {
/// assert_eq!(s.capacity(), 3);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn shrink_to_fit(&mut self) {
self.vec.shrink_to_fit()
}
@ -453,7 +454,7 @@ impl String {
/// assert_eq!(s.as_slice(), "abc123");
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn push(&mut self, ch: char) {
if (ch as u32) < 0x80 {
self.vec.push(ch as u8);
@ -486,7 +487,7 @@ impl String {
/// assert_eq!(s.as_bytes(), b);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn as_bytes<'a>(&'a self) -> &'a [u8] {
self.vec.as_slice()
}
@ -506,7 +507,7 @@ impl String {
/// assert_eq!(s.as_slice(), "he");
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn truncate(&mut self, new_len: uint) {
assert!(self.is_char_boundary(new_len));
self.vec.truncate(new_len)
@ -525,7 +526,7 @@ impl String {
/// assert_eq!(s.pop(), None);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn pop(&mut self) -> Option<char> {
let len = self.len();
if len == 0 {
@ -561,7 +562,7 @@ impl String {
/// assert_eq!(s.remove(0), 'o');
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn remove(&mut self, idx: uint) -> char {
let len = self.len();
assert!(idx <= len);
@ -588,7 +589,7 @@ impl String {
/// If `idx` does not lie on a character boundary or is out of bounds, then
/// this function will panic.
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn insert(&mut self, idx: uint, ch: char) {
let len = self.len();
assert!(idx <= len);
@ -625,7 +626,7 @@ impl String {
/// assert_eq!(s.as_slice(), "olleh");
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub unsafe fn as_mut_vec<'a>(&'a mut self) -> &'a mut Vec<u8> {
&mut self.vec
}
@ -639,7 +640,7 @@ impl String {
/// assert_eq!(a.len(), 3);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn len(&self) -> uint { self.vec.len() }
/// Returns true if the string contains no bytes
@ -653,7 +654,7 @@ impl String {
/// assert!(!v.is_empty());
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_empty(&self) -> bool { self.len() == 0 }
/// Truncates the string, returning it to 0 length.
@ -666,7 +667,7 @@ impl String {
/// assert!(s.is_empty());
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn clear(&mut self) {
self.vec.clear()
}
@ -675,39 +676,39 @@ impl String {
impl FromUtf8Error {
/// Consume this error, returning the bytes that were attempted to make a
/// `String` with.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn into_bytes(self) -> Vec<u8> { self.bytes }
/// Access the underlying UTF8-error that was the cause of this error.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn utf8_error(&self) -> Utf8Error { self.error }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl fmt::Display for FromUtf8Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(&self.error, f)
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Error for FromUtf8Error {
fn description(&self) -> &str { "invalid utf-8" }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl fmt::Display for FromUtf16Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt("invalid utf-16: lone surrogate found", f)
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Error for FromUtf16Error {
fn description(&self) -> &str { "invalid utf-16" }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl FromIterator<char> for String {
fn from_iter<I:Iterator<Item=char>>(iterator: I) -> String {
let mut buf = String::new();
@ -716,7 +717,7 @@ impl FromIterator<char> for String {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> FromIterator<&'a str> for String {
fn from_iter<I:Iterator<Item=&'a str>>(iterator: I) -> String {
let mut buf = String::new();
@ -725,7 +726,8 @@ impl<'a> FromIterator<&'a str> for String {
}
}
#[unstable = "waiting on Extend stabilization"]
#[unstable(feature = "collections",
reason = "waiting on Extend stabilization")]
impl Extend<char> for String {
fn extend<I:Iterator<Item=char>>(&mut self, mut iterator: I) {
let (lower_bound, _) = iterator.size_hint();
@ -736,7 +738,8 @@ impl Extend<char> for String {
}
}
#[unstable = "waiting on Extend stabilization"]
#[unstable(feature = "collections",
reason = "waiting on Extend stabilization")]
impl<'a> Extend<&'a str> for String {
fn extend<I: Iterator<Item=&'a str>>(&mut self, mut iterator: I) {
// A guess that at least one byte per iterator element will be needed.
@ -748,7 +751,7 @@ impl<'a> Extend<&'a str> for String {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl PartialEq for String {
#[inline]
fn eq(&self, other: &String) -> bool { PartialEq::eq(&**self, &**other) }
@ -758,7 +761,7 @@ impl PartialEq for String {
macro_rules! impl_eq {
($lhs:ty, $rhs: ty) => {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> PartialEq<$rhs> for $lhs {
#[inline]
fn eq(&self, other: &$rhs) -> bool { PartialEq::eq(&**self, &**other) }
@ -766,7 +769,7 @@ macro_rules! impl_eq {
fn ne(&self, other: &$rhs) -> bool { PartialEq::ne(&**self, &**other) }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> PartialEq<$lhs> for $rhs {
#[inline]
fn eq(&self, other: &$lhs) -> bool { PartialEq::eq(&**self, &**other) }
@ -780,7 +783,7 @@ macro_rules! impl_eq {
impl_eq! { String, &'a str }
impl_eq! { CowString<'a>, String }
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, 'b> PartialEq<&'b str> for CowString<'a> {
#[inline]
fn eq(&self, other: &&'b str) -> bool { PartialEq::eq(&**self, &**other) }
@ -788,7 +791,7 @@ impl<'a, 'b> PartialEq<&'b str> for CowString<'a> {
fn ne(&self, other: &&'b str) -> bool { PartialEq::ne(&**self, &**other) }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, 'b> PartialEq<CowString<'a>> for &'b str {
#[inline]
fn eq(&self, other: &CowString<'a>) -> bool { PartialEq::eq(&**self, &**other) }
@ -796,25 +799,25 @@ impl<'a, 'b> PartialEq<CowString<'a>> for &'b str {
fn ne(&self, other: &CowString<'a>) -> bool { PartialEq::ne(&**self, &**other) }
}
#[unstable = "waiting on Str stabilization"]
#[unstable(feature = "collections", reason = "waiting on Str stabilization")]
impl Str for String {
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn as_slice<'a>(&'a self) -> &'a str {
unsafe { mem::transmute(self.vec.as_slice()) }
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Default for String {
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn default() -> String {
String::new()
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl fmt::Display for String {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@ -822,7 +825,7 @@ impl fmt::Display for String {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl fmt::Debug for String {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@ -830,7 +833,7 @@ impl fmt::Debug for String {
}
}
#[unstable = "waiting on Hash stabilization"]
#[unstable(feature = "collections", reason = "waiting on Hash stabilization")]
impl<H: hash::Writer + hash::Hasher> hash::Hash<H> for String {
#[inline]
fn hash(&self, hasher: &mut H) {
@ -838,7 +841,8 @@ impl<H: hash::Writer + hash::Hasher> hash::Hash<H> for String {
}
}
#[unstable = "recent addition, needs more experience"]
#[unstable(feature = "collections",
reason = "recent addition, needs more experience")]
impl<'a> Add<&'a str> for String {
type Output = String;
@ -849,7 +853,7 @@ impl<'a> Add<&'a str> for String {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl ops::Index<ops::Range<uint>> for String {
type Output = str;
#[inline]
@ -857,7 +861,7 @@ impl ops::Index<ops::Range<uint>> for String {
&self[][*index]
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl ops::Index<ops::RangeTo<uint>> for String {
type Output = str;
#[inline]
@ -865,7 +869,7 @@ impl ops::Index<ops::RangeTo<uint>> for String {
&self[][*index]
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl ops::Index<ops::RangeFrom<uint>> for String {
type Output = str;
#[inline]
@ -873,7 +877,7 @@ impl ops::Index<ops::RangeFrom<uint>> for String {
&self[][*index]
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl ops::Index<ops::FullRange> for String {
type Output = str;
#[inline]
@ -882,7 +886,7 @@ impl ops::Index<ops::FullRange> for String {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl ops::Deref for String {
type Target = str;
@ -893,7 +897,7 @@ impl ops::Deref for String {
}
/// Wrapper type providing a `&String` reference via `Deref`.
#[unstable]
#[unstable(feature = "collections")]
pub struct DerefString<'a> {
x: DerefVec<'a, u8>
}
@ -921,7 +925,7 @@ impl<'a> Deref for DerefString<'a> {
/// let string = as_string("foo").clone();
/// string_consumer(string);
/// ```
#[unstable]
#[unstable(feature = "collections")]
pub fn as_string<'a>(x: &'a str) -> DerefString<'a> {
DerefString { x: as_vec(x.as_bytes()) }
}
@ -965,7 +969,7 @@ impl<'a> IntoCow<'a, String, str> for &'a str {
}
/// A clone-on-write string
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub type CowString<'a> = Cow<'a, String, str>;
impl<'a> Str for CowString<'a> {

View File

@ -44,7 +44,7 @@
//! let two = xs.pop();
//! ```
#![stable]
#![stable(feature = "rust1", since = "1.0.0")]
use core::prelude::*;
@ -134,7 +134,7 @@ use core::uint;
/// to reallocate, which can be slow. For this reason, it is recommended to use
/// `Vec::with_capacity` whenever possible to specify how big the vector is expected to get.
#[unsafe_no_drop_flag]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Vec<T> {
ptr: NonZero<*mut T>,
len: uint,
@ -159,7 +159,7 @@ impl<T> Vec<T> {
/// let mut vec: Vec<int> = Vec::new();
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new() -> Vec<T> {
// We want ptr to never be NULL so instead we set it to some arbitrary
// non-null value which is fine since we never call deallocate on the ptr
@ -194,7 +194,7 @@ impl<T> Vec<T> {
/// vec.push(11);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn with_capacity(capacity: uint) -> Vec<T> {
if mem::size_of::<T>() == 0 {
Vec { ptr: unsafe { NonZero::new(EMPTY as *mut T) }, len: 0, cap: uint::MAX }
@ -243,7 +243,7 @@ impl<T> Vec<T> {
/// }
/// }
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub unsafe fn from_raw_parts(ptr: *mut T, length: uint,
capacity: uint) -> Vec<T> {
Vec { ptr: NonZero::new(ptr), len: length, cap: capacity }
@ -255,7 +255,8 @@ impl<T> Vec<T> {
/// owned by the returned `Vec<T>`. The elements of the buffer are copied into the vector
/// without cloning, as if `ptr::read()` were called on them.
#[inline]
#[unstable = "may be better expressed via composition"]
#[unstable(feature = "collections",
reason = "may be better expressed via composition")]
pub unsafe fn from_raw_buf(ptr: *const T, elts: uint) -> Vec<T> {
let mut dst = Vec::with_capacity(elts);
dst.set_len(elts);
@ -273,7 +274,7 @@ impl<T> Vec<T> {
/// assert_eq!(vec.capacity(), 10);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn capacity(&self) -> uint {
self.cap
}
@ -292,7 +293,7 @@ impl<T> Vec<T> {
/// vec.reserve(10);
/// assert!(vec.capacity() >= 11);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn reserve(&mut self, additional: uint) {
if self.cap - self.len < additional {
let err_msg = "Vec::reserve: `uint` overflow";
@ -321,7 +322,7 @@ impl<T> Vec<T> {
/// vec.reserve_exact(10);
/// assert!(vec.capacity() >= 11);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn reserve_exact(&mut self, additional: uint) {
if self.cap - self.len < additional {
match self.len.checked_add(additional) {
@ -345,7 +346,7 @@ impl<T> Vec<T> {
/// vec.shrink_to_fit();
/// assert!(vec.capacity() >= 3);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn shrink_to_fit(&mut self) {
if mem::size_of::<T>() == 0 { return }
@ -376,7 +377,7 @@ impl<T> Vec<T> {
/// Note that this will drop any excess capacity. Calling this and
/// converting back to a vector with `into_vec()` is equivalent to calling
/// `shrink_to_fit()`.
#[unstable]
#[unstable(feature = "collections")]
pub fn into_boxed_slice(mut self) -> Box<[T]> {
self.shrink_to_fit();
unsafe {
@ -398,7 +399,7 @@ impl<T> Vec<T> {
/// vec.truncate(2);
/// assert_eq!(vec, vec![1, 2]);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn truncate(&mut self, len: uint) {
unsafe {
// drop any extra elements
@ -422,7 +423,7 @@ impl<T> Vec<T> {
/// foo(vec.as_mut_slice());
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn as_mut_slice<'a>(&'a mut self) -> &'a mut [T] {
unsafe {
mem::transmute(RawSlice {
@ -446,7 +447,7 @@ impl<T> Vec<T> {
/// }
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn into_iter(self) -> IntoIter<T> {
unsafe {
let ptr = *self.ptr;
@ -477,7 +478,7 @@ impl<T> Vec<T> {
/// }
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub unsafe fn set_len(&mut self, len: uint) {
self.len = len;
}
@ -503,7 +504,7 @@ impl<T> Vec<T> {
/// assert_eq!(v, vec!["baz", "qux"]);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn swap_remove(&mut self, index: uint) -> T {
let length = self.len();
self.swap(index, length - 1);
@ -527,7 +528,7 @@ impl<T> Vec<T> {
/// vec.insert(4, 5);
/// assert_eq!(vec, vec![1, 4, 2, 3, 5]);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn insert(&mut self, index: uint, element: T) {
let len = self.len();
assert!(index <= len);
@ -563,7 +564,7 @@ impl<T> Vec<T> {
/// assert_eq!(v.remove(1), 2);
/// assert_eq!(v, vec![1, 3]);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn remove(&mut self, index: uint) -> T {
let len = self.len();
assert!(index < len);
@ -597,7 +598,7 @@ impl<T> Vec<T> {
/// vec.retain(|&x| x%2 == 0);
/// assert_eq!(vec, vec![2, 4]);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn retain<F>(&mut self, mut f: F) where F: FnMut(&T) -> bool {
let len = self.len();
let mut del = 0u;
@ -631,7 +632,7 @@ impl<T> Vec<T> {
/// assert_eq!(vec, vec!(1, 2, 3));
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn push(&mut self, value: T) {
if mem::size_of::<T>() == 0 {
// zero-size types consume no memory, so we can't rely on the
@ -669,7 +670,7 @@ impl<T> Vec<T> {
/// assert_eq!(vec, vec![1, 2]);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn pop(&mut self) -> Option<T> {
if self.len == 0 {
None
@ -696,7 +697,8 @@ impl<T> Vec<T> {
/// assert_eq!(vec2, vec![]);
/// ```
#[inline]
#[unstable = "new API, waiting for dust to settle"]
#[unstable(feature = "collections",
reason = "new API, waiting for dust to settle")]
pub fn append(&mut self, other: &mut Self) {
if mem::size_of::<T>() == 0 {
// zero-size types consume no memory, so we can't rely on the
@ -732,7 +734,8 @@ impl<T> Vec<T> {
/// assert!(v.is_empty());
/// ```
#[inline]
#[unstable = "matches collection reform specification, waiting for dust to settle"]
#[unstable(feature = "collections",
reason = "matches collection reform specification, waiting for dust to settle")]
pub fn drain<'a>(&'a mut self) -> Drain<'a, T> {
unsafe {
let begin = *self.ptr as *const T;
@ -762,7 +765,7 @@ impl<T> Vec<T> {
/// assert!(v.is_empty());
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn clear(&mut self) {
self.truncate(0)
}
@ -776,7 +779,7 @@ impl<T> Vec<T> {
/// assert_eq!(a.len(), 3);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn len(&self) -> uint { self.len }
/// Returns `true` if the vector contains no elements.
@ -790,7 +793,7 @@ impl<T> Vec<T> {
/// v.push(1i);
/// assert!(!v.is_empty());
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_empty(&self) -> bool { self.len() == 0 }
/// Converts a `Vec<T>` to a `Vec<U>` where `T` and `U` have the same
@ -814,7 +817,8 @@ impl<T> Vec<T> {
/// let newtyped_bytes = bytes.map_in_place(|x| Newtype(x));
/// assert_eq!(newtyped_bytes.as_slice(), [Newtype(0x11), Newtype(0x22)].as_slice());
/// ```
#[unstable = "API may change to provide stronger guarantees"]
#[unstable(feature = "collections",
reason = "API may change to provide stronger guarantees")]
pub fn map_in_place<U, F>(self, mut f: F) -> Vec<U> where F: FnMut(T) -> U {
// FIXME: Assert statically that the types `T` and `U` have the same
// size.
@ -1005,7 +1009,8 @@ impl<T> Vec<T> {
/// assert_eq!(vec2, vec![2, 3]);
/// ```
#[inline]
#[unstable = "new API, waiting for dust to settle"]
#[unstable(feature = "collections",
reason = "new API, waiting for dust to settle")]
pub fn split_off(&mut self, at: usize) -> Self {
assert!(at < self.len(), "`at` out of bounds");
@ -1044,7 +1049,8 @@ impl<T: Clone> Vec<T> {
/// vec.resize(2, 0);
/// assert_eq!(vec, vec![1, 2]);
/// ```
#[unstable = "matches collection reform specification; waiting for dust to settle"]
#[unstable(feature = "collections",
reason = "matches collection reform specification; waiting for dust to settle")]
pub fn resize(&mut self, new_len: uint, value: T) {
let len = self.len();
@ -1068,7 +1074,8 @@ impl<T: Clone> Vec<T> {
/// assert_eq!(vec, vec![1, 2, 3, 4]);
/// ```
#[inline]
#[unstable = "likely to be replaced by a more optimized extend"]
#[unstable(feature = "collections",
reason = "likely to be replaced by a more optimized extend")]
pub fn push_all(&mut self, other: &[T]) {
self.reserve(other.len());
@ -1102,7 +1109,7 @@ impl<T: PartialEq> Vec<T> {
///
/// assert_eq!(vec, vec![1i, 2, 3, 2]);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn dedup(&mut self) {
unsafe {
// Although we have a mutable reference to `self`, we cannot make
@ -1236,7 +1243,7 @@ unsafe fn dealloc<T>(ptr: *mut T, len: uint) {
// Common trait implementations for Vec
////////////////////////////////////////////////////////////////////////////////
#[unstable]
#[unstable(feature = "collections")]
impl<T:Clone> Clone for Vec<T> {
fn clone(&self) -> Vec<T> { ::slice::SliceExt::to_vec(self.as_slice()) }
@ -1265,7 +1272,7 @@ impl<S: hash::Writer + hash::Hasher, T: Hash<S>> Hash<S> for Vec<T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Index<uint> for Vec<T> {
type Output = T;
@ -1275,7 +1282,7 @@ impl<T> Index<uint> for Vec<T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> IndexMut<uint> for Vec<T> {
type Output = T;
@ -1286,7 +1293,7 @@ impl<T> IndexMut<uint> for Vec<T> {
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ops::Index<ops::Range<uint>> for Vec<T> {
type Output = [T];
#[inline]
@ -1294,7 +1301,7 @@ impl<T> ops::Index<ops::Range<uint>> for Vec<T> {
self.as_slice().index(index)
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ops::Index<ops::RangeTo<uint>> for Vec<T> {
type Output = [T];
#[inline]
@ -1302,7 +1309,7 @@ impl<T> ops::Index<ops::RangeTo<uint>> for Vec<T> {
self.as_slice().index(index)
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ops::Index<ops::RangeFrom<uint>> for Vec<T> {
type Output = [T];
#[inline]
@ -1310,7 +1317,7 @@ impl<T> ops::Index<ops::RangeFrom<uint>> for Vec<T> {
self.as_slice().index(index)
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ops::Index<ops::FullRange> for Vec<T> {
type Output = [T];
#[inline]
@ -1319,7 +1326,7 @@ impl<T> ops::Index<ops::FullRange> for Vec<T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ops::IndexMut<ops::Range<uint>> for Vec<T> {
type Output = [T];
#[inline]
@ -1327,7 +1334,7 @@ impl<T> ops::IndexMut<ops::Range<uint>> for Vec<T> {
self.as_mut_slice().index_mut(index)
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ops::IndexMut<ops::RangeTo<uint>> for Vec<T> {
type Output = [T];
#[inline]
@ -1335,7 +1342,7 @@ impl<T> ops::IndexMut<ops::RangeTo<uint>> for Vec<T> {
self.as_mut_slice().index_mut(index)
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ops::IndexMut<ops::RangeFrom<uint>> for Vec<T> {
type Output = [T];
#[inline]
@ -1343,7 +1350,7 @@ impl<T> ops::IndexMut<ops::RangeFrom<uint>> for Vec<T> {
self.as_mut_slice().index_mut(index)
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ops::IndexMut<ops::FullRange> for Vec<T> {
type Output = [T];
#[inline]
@ -1352,19 +1359,19 @@ impl<T> ops::IndexMut<ops::FullRange> for Vec<T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ops::Deref for Vec<T> {
type Target = [T];
fn deref<'a>(&'a self) -> &'a [T] { self.as_slice() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ops::DerefMut for Vec<T> {
fn deref_mut<'a>(&'a mut self) -> &'a mut [T] { self.as_mut_slice() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> FromIterator<T> for Vec<T> {
#[inline]
fn from_iter<I:Iterator<Item=T>>(mut iterator: I) -> Vec<T> {
@ -1377,7 +1384,7 @@ impl<T> FromIterator<T> for Vec<T> {
}
}
#[unstable = "waiting on Extend stability"]
#[unstable(feature = "collections", reason = "waiting on Extend stability")]
impl<T> Extend<T> for Vec<T> {
#[inline]
fn extend<I: Iterator<Item=T>>(&mut self, mut iterator: I) {
@ -1452,7 +1459,8 @@ macro_rules! impl_eq_for_cowvec {
impl_eq_for_cowvec! { &'b [B] }
impl_eq_for_cowvec! { &'b mut [B] }
#[unstable = "waiting on PartialOrd stability"]
#[unstable(feature = "collections",
reason = "waiting on PartialOrd stability")]
impl<T: PartialOrd> PartialOrd for Vec<T> {
#[inline]
fn partial_cmp(&self, other: &Vec<T>) -> Option<Ordering> {
@ -1460,10 +1468,10 @@ impl<T: PartialOrd> PartialOrd for Vec<T> {
}
}
#[unstable = "waiting on Eq stability"]
#[unstable(feature = "collections", reason = "waiting on Eq stability")]
impl<T: Eq> Eq for Vec<T> {}
#[unstable = "waiting on Ord stability"]
#[unstable(feature = "collections", reason = "waiting on Ord stability")]
impl<T: Ord> Ord for Vec<T> {
#[inline]
fn cmp(&self, other: &Vec<T>) -> Ordering {
@ -1483,7 +1491,7 @@ impl<T> AsSlice<T> for Vec<T> {
/// foo(vec.as_slice());
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn as_slice<'a>(&'a self) -> &'a [T] {
unsafe {
mem::transmute(RawSlice {
@ -1494,7 +1502,8 @@ impl<T> AsSlice<T> for Vec<T> {
}
}
#[unstable = "recent addition, needs more experience"]
#[unstable(feature = "collections",
reason = "recent addition, needs more experience")]
impl<'a, T: Clone> Add<&'a [T]> for Vec<T> {
type Output = Vec<T>;
@ -1506,7 +1515,7 @@ impl<'a, T: Clone> Add<&'a [T]> for Vec<T> {
}
#[unsafe_destructor]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Drop for Vec<T> {
fn drop(&mut self) {
// This is (and should always remain) a no-op if the fields are
@ -1522,15 +1531,15 @@ impl<T> Drop for Vec<T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Default for Vec<T> {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn default() -> Vec<T> {
Vec::new()
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: fmt::Debug> fmt::Debug for Vec<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Debug::fmt(self.as_slice(), f)
@ -1548,11 +1557,12 @@ impl<'a> fmt::Writer for Vec<u8> {
// Clone-on-write
////////////////////////////////////////////////////////////////////////////////
#[unstable = "unclear how valuable this alias is"]
#[unstable(feature = "collections",
reason = "unclear how valuable this alias is")]
/// A clone-on-write vector
pub type CowVec<'a, T> = Cow<'a, Vec<T>, [T]>;
#[unstable]
#[unstable(feature = "collections")]
impl<'a, T> FromIterator<T> for CowVec<'a, T> where T: Clone {
fn from_iter<I: Iterator<Item=T>>(it: I) -> CowVec<'a, T> {
Cow::Owned(FromIterator::from_iter(it))
@ -1576,7 +1586,7 @@ impl<'a, T> IntoCow<'a, Vec<T>, [T]> for &'a [T] where T: Clone {
////////////////////////////////////////////////////////////////////////////////
/// An iterator that moves out of a vector.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct IntoIter<T> {
allocation: *mut T, // the block of memory allocated for the vector
cap: uint, // the capacity of the vector
@ -1590,7 +1600,7 @@ unsafe impl<T: Sync> Sync for IntoIter<T> { }
impl<T> IntoIter<T> {
#[inline]
/// Drops all items that have not yet been moved and returns the empty vector.
#[unstable]
#[unstable(feature = "collections")]
pub fn into_inner(mut self) -> Vec<T> {
unsafe {
for _x in self { }
@ -1601,7 +1611,7 @@ impl<T> IntoIter<T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Iterator for IntoIter<T> {
type Item = T;
@ -1638,7 +1648,7 @@ impl<T> Iterator for IntoIter<T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> DoubleEndedIterator for IntoIter<T> {
#[inline]
fn next_back<'a>(&'a mut self) -> Option<T> {
@ -1662,11 +1672,11 @@ impl<T> DoubleEndedIterator for IntoIter<T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ExactSizeIterator for IntoIter<T> {}
#[unsafe_destructor]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Drop for IntoIter<T> {
fn drop(&mut self) {
// destroy the remaining elements
@ -1681,14 +1691,15 @@ impl<T> Drop for IntoIter<T> {
/// An iterator that drains a vector.
#[unsafe_no_drop_flag]
#[unstable = "recently added as part of collections reform 2"]
#[unstable(feature = "collections",
reason = "recently added as part of collections reform 2")]
pub struct Drain<'a, T> {
ptr: *const T,
end: *const T,
marker: ContravariantLifetime<'a>,
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> Iterator for Drain<'a, T> {
type Item = T;
@ -1725,7 +1736,7 @@ impl<'a, T> Iterator for Drain<'a, T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> DoubleEndedIterator for Drain<'a, T> {
#[inline]
fn next_back(&mut self) -> Option<T> {
@ -1749,11 +1760,11 @@ impl<'a, T> DoubleEndedIterator for Drain<'a, T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> ExactSizeIterator for Drain<'a, T> {}
#[unsafe_destructor]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> Drop for Drain<'a, T> {
fn drop(&mut self) {
// self.ptr == self.end == null if drop has already been called,
@ -1769,13 +1780,13 @@ impl<'a, T> Drop for Drain<'a, T> {
////////////////////////////////////////////////////////////////////////////////
/// Wrapper type providing a `&Vec<T>` reference via `Deref`.
#[unstable]
#[unstable(feature = "collections")]
pub struct DerefVec<'a, T> {
x: Vec<T>,
l: ContravariantLifetime<'a>
}
#[unstable]
#[unstable(feature = "collections")]
impl<'a, T> Deref for DerefVec<'a, T> {
type Target = Vec<T>;
@ -1786,7 +1797,7 @@ impl<'a, T> Deref for DerefVec<'a, T> {
// Prevent the inner `Vec<T>` from attempting to deallocate memory.
#[unsafe_destructor]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> Drop for DerefVec<'a, T> {
fn drop(&mut self) {
self.x.len = 0;
@ -1795,7 +1806,7 @@ impl<'a, T> Drop for DerefVec<'a, T> {
}
/// Convert a slice to a wrapper type providing a `&Vec<T>` reference.
#[unstable]
#[unstable(feature = "collections")]
pub fn as_vec<'a, T>(x: &'a [T]) -> DerefVec<'a, T> {
unsafe {
DerefVec {

View File

@ -66,9 +66,9 @@ pub struct VecMap<V> {
v: Vec<Option<V>>,
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<V> Default for VecMap<V> {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
fn default() -> VecMap<V> { VecMap::new() }
}
@ -107,7 +107,7 @@ impl<V> VecMap<V> {
/// use std::collections::VecMap;
/// let mut map: VecMap<&str> = VecMap::new();
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new() -> VecMap<V> { VecMap { v: vec![] } }
/// Creates an empty `VecMap` with space for at least `capacity`
@ -119,7 +119,7 @@ impl<V> VecMap<V> {
/// use std::collections::VecMap;
/// let mut map: VecMap<&str> = VecMap::with_capacity(10);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn with_capacity(capacity: uint) -> VecMap<V> {
VecMap { v: Vec::with_capacity(capacity) }
}
@ -135,7 +135,7 @@ impl<V> VecMap<V> {
/// assert!(map.capacity() >= 10);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn capacity(&self) -> uint {
self.v.capacity()
}
@ -154,7 +154,7 @@ impl<V> VecMap<V> {
/// map.reserve_len(10);
/// assert!(map.capacity() >= 10);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn reserve_len(&mut self, len: uint) {
let cur_len = self.v.len();
if len >= cur_len {
@ -178,7 +178,7 @@ impl<V> VecMap<V> {
/// map.reserve_len_exact(10);
/// assert!(map.capacity() >= 10);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn reserve_len_exact(&mut self, len: uint) {
let cur_len = self.v.len();
if len >= cur_len {
@ -188,7 +188,7 @@ impl<V> VecMap<V> {
/// Returns an iterator visiting all keys in ascending order of the keys.
/// The iterator's element type is `uint`.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn keys<'r>(&'r self) -> Keys<'r, V> {
fn first<A, B>((a, _): (A, B)) -> A { a }
let first: fn((uint, &'r V)) -> uint = first; // coerce to fn pointer
@ -198,7 +198,7 @@ impl<V> VecMap<V> {
/// Returns an iterator visiting all values in ascending order of the keys.
/// The iterator's element type is `&'r V`.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn values<'r>(&'r self) -> Values<'r, V> {
fn second<A, B>((_, b): (A, B)) -> B { b }
let second: fn((uint, &'r V)) -> &'r V = second; // coerce to fn pointer
@ -224,7 +224,7 @@ impl<V> VecMap<V> {
/// println!("{}: {}", key, value);
/// }
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn iter<'r>(&'r self) -> Iter<'r, V> {
Iter {
front: 0,
@ -255,7 +255,7 @@ impl<V> VecMap<V> {
/// assert_eq!(value, &"x");
/// }
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn iter_mut<'r>(&'r mut self) -> IterMut<'r, V> {
IterMut {
front: 0,
@ -282,7 +282,7 @@ impl<V> VecMap<V> {
///
/// assert_eq!(vec, vec![(1, "a"), (2, "b"), (3, "c")]);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn into_iter(self) -> IntoIter<V> {
fn filter<A>((i, v): (uint, Option<A>)) -> Option<(uint, A)> {
v.map(|v| (i, v))
@ -310,7 +310,8 @@ impl<V> VecMap<V> {
///
/// assert_eq!(vec, vec![(1, "a"), (2, "b"), (3, "c")]);
/// ```
#[unstable = "matches collection reform specification, waiting for dust to settle"]
#[unstable(feature = "collections",
reason = "matches collection reform specification, waiting for dust to settle")]
pub fn drain<'a>(&'a mut self) -> Drain<'a, V> {
fn filter<A>((i, v): (uint, Option<A>)) -> Option<(uint, A)> {
v.map(|v| (i, v))
@ -332,7 +333,7 @@ impl<V> VecMap<V> {
/// a.insert(1, "a");
/// assert_eq!(a.len(), 1);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn len(&self) -> uint {
self.v.iter().filter(|elt| elt.is_some()).count()
}
@ -349,7 +350,7 @@ impl<V> VecMap<V> {
/// a.insert(1, "a");
/// assert!(!a.is_empty());
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_empty(&self) -> bool {
self.v.iter().all(|elt| elt.is_none())
}
@ -366,7 +367,7 @@ impl<V> VecMap<V> {
/// a.clear();
/// assert!(a.is_empty());
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn clear(&mut self) { self.v.clear() }
/// Returns a reference to the value corresponding to the key.
@ -381,7 +382,7 @@ impl<V> VecMap<V> {
/// assert_eq!(map.get(&1), Some(&"a"));
/// assert_eq!(map.get(&2), None);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn get(&self, key: &uint) -> Option<&V> {
if *key < self.v.len() {
match self.v[*key] {
@ -406,7 +407,7 @@ impl<V> VecMap<V> {
/// assert_eq!(map.contains_key(&2), false);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn contains_key(&self, key: &uint) -> bool {
self.get(key).is_some()
}
@ -426,7 +427,7 @@ impl<V> VecMap<V> {
/// }
/// assert_eq!(map[1], "b");
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn get_mut(&mut self, key: &uint) -> Option<&mut V> {
if *key < self.v.len() {
match *(&mut self.v[*key]) {
@ -454,7 +455,7 @@ impl<V> VecMap<V> {
/// assert_eq!(map.insert(37, "c"), Some("b"));
/// assert_eq!(map[37], "c");
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn insert(&mut self, key: uint, value: V) -> Option<V> {
let len = self.v.len();
if len <= key {
@ -476,7 +477,7 @@ impl<V> VecMap<V> {
/// assert_eq!(map.remove(&1), Some("a"));
/// assert_eq!(map.remove(&1), None);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn remove(&mut self, key: &uint) -> Option<V> {
if *key >= self.v.len() {
return None;
@ -486,17 +487,17 @@ impl<V> VecMap<V> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<V: PartialEq> PartialEq for VecMap<V> {
fn eq(&self, other: &VecMap<V>) -> bool {
iter::order::eq(self.iter(), other.iter())
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<V: Eq> Eq for VecMap<V> {}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<V: PartialOrd> PartialOrd for VecMap<V> {
#[inline]
fn partial_cmp(&self, other: &VecMap<V>) -> Option<Ordering> {
@ -504,7 +505,7 @@ impl<V: PartialOrd> PartialOrd for VecMap<V> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<V: Ord> Ord for VecMap<V> {
#[inline]
fn cmp(&self, other: &VecMap<V>) -> Ordering {
@ -512,7 +513,7 @@ impl<V: Ord> Ord for VecMap<V> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<V: fmt::Debug> fmt::Debug for VecMap<V> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(write!(f, "VecMap {{"));
@ -526,7 +527,7 @@ impl<V: fmt::Debug> fmt::Debug for VecMap<V> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<V> FromIterator<(uint, V)> for VecMap<V> {
fn from_iter<Iter: Iterator<Item=(uint, V)>>(iter: Iter) -> VecMap<V> {
let mut map = VecMap::new();
@ -535,7 +536,7 @@ impl<V> FromIterator<(uint, V)> for VecMap<V> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<V> Extend<(uint, V)> for VecMap<V> {
fn extend<Iter: Iterator<Item=(uint, V)>>(&mut self, mut iter: Iter) {
for (k, v) in iter {
@ -553,7 +554,7 @@ impl<V> Index<uint> for VecMap<V> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<V> IndexMut<uint> for VecMap<V> {
type Output = V;
@ -565,7 +566,7 @@ impl<V> IndexMut<uint> for VecMap<V> {
macro_rules! iterator {
(impl $name:ident -> $elem:ty, $($getter:ident),+) => {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, V> Iterator for $name<'a, V> {
type Item = $elem;
@ -600,7 +601,7 @@ macro_rules! iterator {
macro_rules! double_ended_iterator {
(impl $name:ident -> $elem:ty, $($getter:ident),+) => {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, V> DoubleEndedIterator for $name<'a, V> {
#[inline]
fn next_back(&mut self) -> Option<$elem> {
@ -626,7 +627,7 @@ macro_rules! double_ended_iterator {
}
/// An iterator over the key-value pairs of a map.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Iter<'a, V:'a> {
front: uint,
back: uint,
@ -649,7 +650,7 @@ double_ended_iterator! { impl Iter -> (uint, &'a V), as_ref }
/// An iterator over the key-value pairs of a map, with the
/// values being mutable.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct IterMut<'a, V:'a> {
front: uint,
back: uint,
@ -660,7 +661,7 @@ iterator! { impl IterMut -> (uint, &'a mut V), as_mut }
double_ended_iterator! { impl IterMut -> (uint, &'a mut V), as_mut }
/// An iterator over the keys of a map.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Keys<'a, V: 'a> {
iter: Map<(uint, &'a V), uint, Iter<'a, V>, fn((uint, &'a V)) -> uint>
}
@ -675,7 +676,7 @@ impl<'a, V> Clone for Keys<'a, V> {
}
/// An iterator over the values of a map.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Values<'a, V: 'a> {
iter: Map<(uint, &'a V), &'a V, Iter<'a, V>, fn((uint, &'a V)) -> &'a V>
}
@ -690,7 +691,7 @@ impl<'a, V> Clone for Values<'a, V> {
}
/// A consuming iterator over the key-value pairs of a map.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct IntoIter<V> {
iter: FilterMap<
(uint, Option<V>),
@ -699,7 +700,7 @@ pub struct IntoIter<V> {
fn((uint, Option<V>)) -> Option<(uint, V)>>
}
#[unstable]
#[unstable(feature = "collections")]
pub struct Drain<'a, V> {
iter: FilterMap<
(uint, Option<V>),
@ -708,7 +709,7 @@ pub struct Drain<'a, V> {
fn((uint, Option<V>)) -> Option<(uint, V)>>
}
#[unstable]
#[unstable(feature = "collections")]
impl<'a, V> Iterator for Drain<'a, V> {
type Item = (uint, V);
@ -716,43 +717,43 @@ impl<'a, V> Iterator for Drain<'a, V> {
fn size_hint(&self) -> (uint, Option<uint>) { self.iter.size_hint() }
}
#[unstable]
#[unstable(feature = "collections")]
impl<'a, V> DoubleEndedIterator for Drain<'a, V> {
fn next_back(&mut self) -> Option<(uint, V)> { self.iter.next_back() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, V> Iterator for Keys<'a, V> {
type Item = uint;
fn next(&mut self) -> Option<uint> { self.iter.next() }
fn size_hint(&self) -> (uint, Option<uint>) { self.iter.size_hint() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, V> DoubleEndedIterator for Keys<'a, V> {
fn next_back(&mut self) -> Option<uint> { self.iter.next_back() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, V> Iterator for Values<'a, V> {
type Item = &'a V;
fn next(&mut self) -> Option<(&'a V)> { self.iter.next() }
fn size_hint(&self) -> (uint, Option<uint>) { self.iter.size_hint() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, V> DoubleEndedIterator for Values<'a, V> {
fn next_back(&mut self) -> Option<(&'a V)> { self.iter.next_back() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<V> Iterator for IntoIter<V> {
type Item = (uint, V);
fn next(&mut self) -> Option<(uint, V)> { self.iter.next() }
fn size_hint(&self) -> (uint, Option<uint>) { self.iter.size_hint() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<V> DoubleEndedIterator for IntoIter<V> {
fn next_back(&mut self) -> Option<(uint, V)> { self.iter.next_back() }
}

View File

@ -69,7 +69,7 @@
//! }
//! ```
#![stable]
#![stable(feature = "rust1", since = "1.0.0")]
use mem::transmute;
use option::Option::{self, Some, None};
@ -86,10 +86,11 @@ use marker::Sized;
///
/// Every type with no non-`'static` references implements `Any`, so `Any` can
/// be used as a trait object to emulate the effects dynamic typing.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Any: 'static {
/// Get the `TypeId` of `self`
#[unstable = "this method will likely be replaced by an associated static"]
#[unstable(feature = "core",
reason = "this method will likely be replaced by an associated static")]
fn get_type_id(&self) -> TypeId;
}
@ -103,7 +104,7 @@ impl<T: 'static> Any for T {
impl Any {
/// Returns true if the boxed type is the same as `T`
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn is<T: 'static>(&self) -> bool {
// Get TypeId of the type this function is instantiated with
@ -118,7 +119,7 @@ impl Any {
/// Returns some reference to the boxed value if it is of type `T`, or
/// `None` if it isn't.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn downcast_ref<T: 'static>(&self) -> Option<&T> {
if self.is::<T>() {
@ -136,7 +137,7 @@ impl Any {
/// Returns some mutable reference to the boxed value if it is of type `T`, or
/// `None` if it isn't.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn downcast_mut<T: 'static>(&mut self) -> Option<&mut T> {
if self.is::<T>() {
@ -167,7 +168,7 @@ impl Any {
/// but this limitation may be removed in the future.
#[cfg_attr(stage0, lang = "type_id")]
#[derive(Clone, Copy, PartialEq, Eq, Show, Hash)]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct TypeId {
t: u64,
}
@ -175,7 +176,8 @@ pub struct TypeId {
impl TypeId {
/// Returns the `TypeId` of the type this generic function has been
/// instantiated with
#[unstable = "may grow a `Reflect` bound soon via marker traits"]
#[unstable(feature = "core",
reason = "may grow a `Reflect` bound soon via marker traits")]
pub fn of<T: ?Sized + 'static>() -> TypeId {
TypeId {
t: unsafe { intrinsics::type_id::<T>() },

View File

@ -12,7 +12,7 @@
//! up to a certain length. Eventually we should able to generalize
//! to all lengths.
#![unstable] // not yet reviewed
#![unstable(feature = "core")] // not yet reviewed
use clone::Clone;
use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering};
@ -26,7 +26,7 @@ use option::Option;
macro_rules! array_impls {
($($N:expr)+) => {
$(
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T:Copy> Clone for [T; $N] {
fn clone(&self) -> [T; $N] {
*self
@ -39,14 +39,14 @@ macro_rules! array_impls {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: fmt::Debug> fmt::Debug for [T; $N] {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Debug::fmt(&&self[], f)
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<A, B> PartialEq<[B; $N]> for [A; $N] where A: PartialEq<B> {
#[inline]
fn eq(&self, other: &[B; $N]) -> bool {
@ -58,7 +58,7 @@ macro_rules! array_impls {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, A, B, Rhs> PartialEq<Rhs> for [A; $N] where
A: PartialEq<B>,
Rhs: Deref<Target=[B]>,
@ -73,7 +73,7 @@ macro_rules! array_impls {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, A, B, Lhs> PartialEq<[B; $N]> for Lhs where
A: PartialEq<B>,
Lhs: Deref<Target=[A]>
@ -88,10 +88,10 @@ macro_rules! array_impls {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T:Eq> Eq for [T; $N] { }
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T:PartialOrd> PartialOrd for [T; $N] {
#[inline]
fn partial_cmp(&self, other: &[T; $N]) -> Option<Ordering> {
@ -115,7 +115,7 @@ macro_rules! array_impls {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T:Ord> Ord for [T; $N] {
#[inline]
fn cmp(&self, other: &[T; $N]) -> Ordering {

View File

@ -68,7 +68,7 @@
//! println!("live tasks: {}", old_task_count + 1);
//! ```
#![stable]
#![stable(feature = "rust1", since = "1.0.0")]
use self::Ordering::*;
@ -78,7 +78,7 @@ use intrinsics;
use cell::UnsafeCell;
/// A boolean type which can be safely shared between threads.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct AtomicBool {
v: UnsafeCell<usize>,
}
@ -86,7 +86,7 @@ pub struct AtomicBool {
unsafe impl Sync for AtomicBool {}
/// A signed integer type which can be safely shared between threads.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct AtomicIsize {
v: UnsafeCell<isize>,
}
@ -94,7 +94,7 @@ pub struct AtomicIsize {
unsafe impl Sync for AtomicIsize {}
/// An unsigned integer type which can be safely shared between threads.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct AtomicUsize {
v: UnsafeCell<usize>,
}
@ -102,7 +102,7 @@ pub struct AtomicUsize {
unsafe impl Sync for AtomicUsize {}
/// A raw pointer type which can be safely shared between threads.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct AtomicPtr<T> {
p: UnsafeCell<usize>,
}
@ -119,42 +119,42 @@ unsafe impl<T> Sync for AtomicPtr<T> {}
///
/// Rust's memory orderings are [the same as
/// C++'s](http://gcc.gnu.org/wiki/Atomic/GCCMM/AtomicSync).
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
#[derive(Copy)]
pub enum Ordering {
/// No ordering constraints, only atomic operations.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
Relaxed,
/// When coupled with a store, all previous writes become visible
/// to another thread that performs a load with `Acquire` ordering
/// on the same value.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
Release,
/// When coupled with a load, all subsequent loads will see data
/// written before a store with `Release` ordering on the same value
/// in another thread.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
Acquire,
/// When coupled with a load, uses `Acquire` ordering, and with a store
/// `Release` ordering.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
AcqRel,
/// Like `AcqRel` with the additional guarantee that all threads see all
/// sequentially consistent operations in the same order.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
SeqCst,
}
/// An `AtomicBool` initialized to `false`.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub const ATOMIC_BOOL_INIT: AtomicBool =
AtomicBool { v: UnsafeCell { value: 0 } };
/// An `AtomicIsize` initialized to `0`.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub const ATOMIC_ISIZE_INIT: AtomicIsize =
AtomicIsize { v: UnsafeCell { value: 0 } };
/// An `AtomicUsize` initialized to `0`.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub const ATOMIC_USIZE_INIT: AtomicUsize =
AtomicUsize { v: UnsafeCell { value: 0, } };
@ -173,7 +173,7 @@ impl AtomicBool {
/// let atomic_false = AtomicBool::new(false);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new(v: bool) -> AtomicBool {
let val = if v { UINT_TRUE } else { 0 };
AtomicBool { v: UnsafeCell::new(val) }
@ -197,7 +197,7 @@ impl AtomicBool {
/// let value = some_bool.load(Ordering::Relaxed);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn load(&self, order: Ordering) -> bool {
unsafe { atomic_load(self.v.get(), order) > 0 }
}
@ -220,7 +220,7 @@ impl AtomicBool {
///
/// Panics if `order` is `Acquire` or `AcqRel`.
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn store(&self, val: bool, order: Ordering) {
let val = if val { UINT_TRUE } else { 0 };
@ -241,7 +241,7 @@ impl AtomicBool {
/// let value = some_bool.swap(false, Ordering::Relaxed);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn swap(&self, val: bool, order: Ordering) -> bool {
let val = if val { UINT_TRUE } else { 0 };
@ -265,7 +265,7 @@ impl AtomicBool {
/// let value = some_bool.store(false, Ordering::Relaxed);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn compare_and_swap(&self, old: bool, new: bool, order: Ordering) -> bool {
let old = if old { UINT_TRUE } else { 0 };
let new = if new { UINT_TRUE } else { 0 };
@ -298,7 +298,7 @@ impl AtomicBool {
/// assert_eq!(false, foo.load(Ordering::SeqCst));
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn fetch_and(&self, val: bool, order: Ordering) -> bool {
let val = if val { UINT_TRUE } else { 0 };
@ -331,7 +331,7 @@ impl AtomicBool {
/// assert_eq!(true, foo.load(Ordering::SeqCst));
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn fetch_nand(&self, val: bool, order: Ordering) -> bool {
let val = if val { UINT_TRUE } else { 0 };
@ -363,7 +363,7 @@ impl AtomicBool {
/// assert_eq!(false, foo.load(Ordering::SeqCst));
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn fetch_or(&self, val: bool, order: Ordering) -> bool {
let val = if val { UINT_TRUE } else { 0 };
@ -395,7 +395,7 @@ impl AtomicBool {
/// assert_eq!(false, foo.load(Ordering::SeqCst));
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn fetch_xor(&self, val: bool, order: Ordering) -> bool {
let val = if val { UINT_TRUE } else { 0 };
@ -403,7 +403,7 @@ impl AtomicBool {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl AtomicIsize {
/// Creates a new `AtomicIsize`.
///
@ -580,7 +580,7 @@ impl AtomicIsize {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl AtomicUsize {
/// Creates a new `AtomicUsize`.
///
@ -769,7 +769,7 @@ impl<T> AtomicPtr<T> {
/// let atomic_ptr = AtomicPtr::new(ptr);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new(p: *mut T) -> AtomicPtr<T> {
AtomicPtr { p: UnsafeCell::new(p as usize) }
}
@ -793,7 +793,7 @@ impl<T> AtomicPtr<T> {
/// let value = some_ptr.load(Ordering::Relaxed);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn load(&self, order: Ordering) -> *mut T {
unsafe {
atomic_load(self.p.get(), order) as *mut T
@ -821,7 +821,7 @@ impl<T> AtomicPtr<T> {
///
/// Panics if `order` is `Acquire` or `AcqRel`.
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn store(&self, ptr: *mut T, order: Ordering) {
unsafe { atomic_store(self.p.get(), ptr as usize, order); }
}
@ -843,7 +843,7 @@ impl<T> AtomicPtr<T> {
/// let value = some_ptr.swap(other_ptr, Ordering::Relaxed);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn swap(&self, ptr: *mut T, order: Ordering) -> *mut T {
unsafe { atomic_swap(self.p.get(), ptr as usize, order) as *mut T }
}
@ -869,7 +869,7 @@ impl<T> AtomicPtr<T> {
/// let value = some_ptr.compare_and_swap(other_ptr, another_ptr, Ordering::Relaxed);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn compare_and_swap(&self, old: *mut T, new: *mut T, order: Ordering) -> *mut T {
unsafe {
atomic_compare_and_swap(self.p.get(), old as usize,
@ -890,7 +890,7 @@ unsafe fn atomic_store<T>(dst: *mut T, val: T, order:Ordering) {
}
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
unsafe fn atomic_load<T>(dst: *const T, order:Ordering) -> T {
match order {
Acquire => intrinsics::atomic_load_acq(dst),
@ -902,7 +902,7 @@ unsafe fn atomic_load<T>(dst: *const T, order:Ordering) -> T {
}
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
unsafe fn atomic_swap<T>(dst: *mut T, val: T, order: Ordering) -> T {
match order {
Acquire => intrinsics::atomic_xchg_acq(dst, val),
@ -915,7 +915,7 @@ unsafe fn atomic_swap<T>(dst: *mut T, val: T, order: Ordering) -> T {
/// Returns the old value (like __sync_fetch_and_add).
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
unsafe fn atomic_add<T>(dst: *mut T, val: T, order: Ordering) -> T {
match order {
Acquire => intrinsics::atomic_xadd_acq(dst, val),
@ -928,7 +928,7 @@ unsafe fn atomic_add<T>(dst: *mut T, val: T, order: Ordering) -> T {
/// Returns the old value (like __sync_fetch_and_sub).
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
unsafe fn atomic_sub<T>(dst: *mut T, val: T, order: Ordering) -> T {
match order {
Acquire => intrinsics::atomic_xsub_acq(dst, val),
@ -940,7 +940,7 @@ unsafe fn atomic_sub<T>(dst: *mut T, val: T, order: Ordering) -> T {
}
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
unsafe fn atomic_compare_and_swap<T>(dst: *mut T, old:T, new:T, order: Ordering) -> T {
match order {
Acquire => intrinsics::atomic_cxchg_acq(dst, old, new),
@ -952,7 +952,7 @@ unsafe fn atomic_compare_and_swap<T>(dst: *mut T, old:T, new:T, order: Ordering)
}
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
unsafe fn atomic_and<T>(dst: *mut T, val: T, order: Ordering) -> T {
match order {
Acquire => intrinsics::atomic_and_acq(dst, val),
@ -964,7 +964,7 @@ unsafe fn atomic_and<T>(dst: *mut T, val: T, order: Ordering) -> T {
}
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
unsafe fn atomic_nand<T>(dst: *mut T, val: T, order: Ordering) -> T {
match order {
Acquire => intrinsics::atomic_nand_acq(dst, val),
@ -977,7 +977,7 @@ unsafe fn atomic_nand<T>(dst: *mut T, val: T, order: Ordering) -> T {
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
unsafe fn atomic_or<T>(dst: *mut T, val: T, order: Ordering) -> T {
match order {
Acquire => intrinsics::atomic_or_acq(dst, val),
@ -990,7 +990,7 @@ unsafe fn atomic_or<T>(dst: *mut T, val: T, order: Ordering) -> T {
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
unsafe fn atomic_xor<T>(dst: *mut T, val: T, order: Ordering) -> T {
match order {
Acquire => intrinsics::atomic_xor_acq(dst, val),
@ -1023,7 +1023,7 @@ unsafe fn atomic_xor<T>(dst: *mut T, val: T, order: Ordering) -> T {
///
/// Panics if `order` is `Relaxed`.
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn fence(order: Ordering) {
unsafe {
match order {
@ -1036,7 +1036,9 @@ pub fn fence(order: Ordering) {
}
}
#[deprecated="renamed to AtomicIsize"]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0",
reason = "renamed to AtomicIsize")]
#[allow(missing_docs)]
pub struct AtomicInt {
v: UnsafeCell<int>,
@ -1044,7 +1046,9 @@ pub struct AtomicInt {
unsafe impl Sync for AtomicInt {}
#[deprecated="renamed to AtomicUsize"]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0",
reason = "renamed to AtomicUsize")]
#[allow(missing_docs)]
pub struct AtomicUint {
v: UnsafeCell<uint>,
@ -1052,11 +1056,15 @@ pub struct AtomicUint {
unsafe impl Sync for AtomicUint {}
#[deprecated="use ATOMIC_ISIZE_INIT instead"]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0",
reason = "use ATOMIC_ISIZE_INIT instead")]
#[allow(missing_docs, deprecated)]
pub const ATOMIC_INT_INIT: AtomicInt =
AtomicInt { v: UnsafeCell { value: 0 } };
#[deprecated="use ATOMIC_USIZE_INIT instead"]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0",
reason = "use ATOMIC_USIZE_INIT instead")]
#[allow(missing_docs, deprecated)]
pub const ATOMIC_UINT_INIT: AtomicUint =
AtomicUint { v: UnsafeCell { value: 0, } };

View File

@ -42,7 +42,8 @@
//! is desired, `to_mut` will obtain a mutable references to an owned
//! value, cloning if necessary.
#![unstable = "recently added as part of collections reform"]
#![unstable(feature = "core",
reason = "recently added as part of collections reform")]
use clone::Clone;
use cmp::{Eq, Ord, Ordering, PartialEq, PartialOrd};
@ -141,7 +142,7 @@ pub enum Cow<'a, T, B: ?Sized + 'a> where B: ToOwned<T> {
Owned(T)
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T, B: ?Sized> Clone for Cow<'a, T, B> where B: ToOwned<T> {
fn clone(&self) -> Cow<'a, T, B> {
match *self {
@ -195,7 +196,7 @@ impl<'a, T, B: ?Sized> Cow<'a, T, B> where B: ToOwned<T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T, B: ?Sized> Deref for Cow<'a, T, B> where B: ToOwned<T> {
type Target = B;
@ -207,10 +208,10 @@ impl<'a, T, B: ?Sized> Deref for Cow<'a, T, B> where B: ToOwned<T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T, B: ?Sized> Eq for Cow<'a, T, B> where B: Eq + ToOwned<T> {}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T, B: ?Sized> Ord for Cow<'a, T, B> where B: Ord + ToOwned<T> {
#[inline]
fn cmp(&self, other: &Cow<'a, T, B>) -> Ordering {
@ -218,7 +219,7 @@ impl<'a, T, B: ?Sized> Ord for Cow<'a, T, B> where B: Ord + ToOwned<T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, 'b, T, U, B: ?Sized, C: ?Sized> PartialEq<Cow<'b, U, C>> for Cow<'a, T, B> where
B: PartialEq<C> + ToOwned<T>,
C: ToOwned<U>,
@ -229,7 +230,7 @@ impl<'a, 'b, T, U, B: ?Sized, C: ?Sized> PartialEq<Cow<'b, U, C>> for Cow<'a, T,
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T, B: ?Sized> PartialOrd for Cow<'a, T, B> where B: PartialOrd + ToOwned<T> {
#[inline]
fn partial_cmp(&self, other: &Cow<'a, T, B>) -> Option<Ordering> {
@ -237,7 +238,7 @@ impl<'a, T, B: ?Sized> PartialOrd for Cow<'a, T, B> where B: PartialOrd + ToOwne
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T, B: ?Sized> fmt::Debug for Cow<'a, T, B> where
B: fmt::Debug + ToOwned<T>,
T: fmt::Debug,
@ -250,7 +251,7 @@ impl<'a, T, B: ?Sized> fmt::Debug for Cow<'a, T, B> where
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T, B: ?Sized> fmt::Display for Cow<'a, T, B> where
B: fmt::Display + ToOwned<T>,
T: fmt::Display,

View File

@ -139,7 +139,7 @@
//! ```
//!
#![stable]
#![stable(feature = "rust1", since = "1.0.0")]
use clone::Clone;
use cmp::PartialEq;
@ -152,7 +152,7 @@ use option::Option::{None, Some};
/// A mutable memory location that admits only `Copy` data.
///
/// See the [module-level documentation](../index.html) for more.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Cell<T> {
value: UnsafeCell<T>,
}
@ -167,7 +167,7 @@ impl<T:Copy> Cell<T> {
///
/// let c = Cell::new(5);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new(value: T) -> Cell<T> {
Cell {
value: UnsafeCell::new(value),
@ -186,7 +186,7 @@ impl<T:Copy> Cell<T> {
/// let five = c.get();
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn get(&self) -> T {
unsafe{ *self.value.get() }
}
@ -203,7 +203,7 @@ impl<T:Copy> Cell<T> {
/// c.set(10);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn set(&self, value: T) {
unsafe {
*self.value.get() = value;
@ -226,31 +226,31 @@ impl<T:Copy> Cell<T> {
/// let uc = unsafe { c.as_unsafe_cell() };
/// ```
#[inline]
#[unstable]
#[unstable(feature = "core")]
pub unsafe fn as_unsafe_cell<'a>(&'a self) -> &'a UnsafeCell<T> {
&self.value
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
unsafe impl<T> Send for Cell<T> where T: Send {}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T:Copy> Clone for Cell<T> {
fn clone(&self) -> Cell<T> {
Cell::new(self.get())
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T:Default + Copy> Default for Cell<T> {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn default() -> Cell<T> {
Cell::new(Default::default())
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T:PartialEq + Copy> PartialEq for Cell<T> {
fn eq(&self, other: &Cell<T>) -> bool {
self.get() == other.get()
@ -260,7 +260,7 @@ impl<T:PartialEq + Copy> PartialEq for Cell<T> {
/// A mutable memory location with dynamically checked borrow rules
///
/// See the [module-level documentation](../index.html) for more.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct RefCell<T> {
value: UnsafeCell<T>,
borrow: Cell<BorrowFlag>,
@ -282,7 +282,7 @@ impl<T> RefCell<T> {
///
/// let c = RefCell::new(5);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new(value: T) -> RefCell<T> {
RefCell {
value: UnsafeCell::new(value),
@ -301,7 +301,7 @@ impl<T> RefCell<T> {
///
/// let five = c.into_inner();
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn into_inner(self) -> T {
// Since this function takes `self` (the `RefCell`) by value, the
// compiler statically verifies that it is not currently borrowed.
@ -316,7 +316,7 @@ impl<T> RefCell<T> {
/// immutable borrows can be taken out at the same time.
///
/// Returns `None` if the value is currently mutably borrowed.
#[unstable = "may be renamed or removed"]
#[unstable(feature = "core", reason = "may be renamed or removed")]
pub fn try_borrow<'a>(&'a self) -> Option<Ref<'a, T>> {
match BorrowRef::new(&self.borrow) {
Some(b) => Some(Ref { _value: unsafe { &*self.value.get() }, _borrow: b }),
@ -359,7 +359,7 @@ impl<T> RefCell<T> {
///
/// assert!(result.is_err());
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn borrow<'a>(&'a self) -> Ref<'a, T> {
match self.try_borrow() {
Some(ptr) => ptr,
@ -373,7 +373,7 @@ impl<T> RefCell<T> {
/// cannot be borrowed while this borrow is active.
///
/// Returns `None` if the value is currently borrowed.
#[unstable = "may be renamed or removed"]
#[unstable(feature = "core", reason = "may be renamed or removed")]
pub fn try_borrow_mut<'a>(&'a self) -> Option<RefMut<'a, T>> {
match BorrowRefMut::new(&self.borrow) {
Some(b) => Some(RefMut { _value: unsafe { &mut *self.value.get() }, _borrow: b }),
@ -415,7 +415,7 @@ impl<T> RefCell<T> {
///
/// assert!(result.is_err());
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn borrow_mut<'a>(&'a self) -> RefMut<'a, T> {
match self.try_borrow_mut() {
Some(ptr) => ptr,
@ -429,31 +429,31 @@ impl<T> RefCell<T> {
///
/// This function is `unsafe` because `UnsafeCell`'s field is public.
#[inline]
#[unstable]
#[unstable(feature = "core")]
pub unsafe fn as_unsafe_cell<'a>(&'a self) -> &'a UnsafeCell<T> {
&self.value
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
unsafe impl<T> Send for RefCell<T> where T: Send {}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Clone> Clone for RefCell<T> {
fn clone(&self) -> RefCell<T> {
RefCell::new(self.borrow().clone())
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T:Default> Default for RefCell<T> {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn default() -> RefCell<T> {
RefCell::new(Default::default())
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: PartialEq> PartialEq for RefCell<T> {
fn eq(&self, other: &RefCell<T>) -> bool {
*self.borrow() == *other.borrow()
@ -496,10 +496,11 @@ impl<'b> Clone for BorrowRef<'b> {
}
}
/// Wraps a borrowed reference to a value in a `RefCell` box.
/// A wrapper type for an immutably borrowed value from a `RefCell<T>`.
///
/// See the [module-level documentation](../index.html) for more.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Ref<'b, T:'b> {
// FIXME #12808: strange name to try to avoid interfering with
// field accesses of the contained type via Deref
@ -507,7 +508,7 @@ pub struct Ref<'b, T:'b> {
_borrow: BorrowRef<'b>,
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'b, T> Deref for Ref<'b, T> {
type Target = T;
@ -523,7 +524,8 @@ impl<'b, T> Deref for Ref<'b, T> {
///
/// A `Clone` implementation would interfere with the widespread
/// use of `r.borrow().clone()` to clone the contents of a `RefCell`.
#[unstable = "likely to be moved to a method, pending language changes"]
#[unstable(feature = "core",
reason = "likely to be moved to a method, pending language changes")]
pub fn clone_ref<'b, T:Clone>(orig: &Ref<'b, T>) -> Ref<'b, T> {
Ref {
_value: orig._value,
@ -559,7 +561,7 @@ impl<'b> BorrowRefMut<'b> {
/// A wrapper type for a mutably borrowed value from a `RefCell<T>`.
///
/// See the [module-level documentation](../index.html) for more.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct RefMut<'b, T:'b> {
// FIXME #12808: strange name to try to avoid interfering with
// field accesses of the contained type via Deref
@ -567,7 +569,7 @@ pub struct RefMut<'b, T:'b> {
_borrow: BorrowRefMut<'b>,
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'b, T> Deref for RefMut<'b, T> {
type Target = T;
@ -577,7 +579,7 @@ impl<'b, T> Deref for RefMut<'b, T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'b, T> DerefMut for RefMut<'b, T> {
#[inline]
fn deref_mut<'a>(&'a mut self) -> &'a mut T {
@ -619,13 +621,13 @@ impl<'b, T> DerefMut for RefMut<'b, T> {
/// **NOTE:** `UnsafeCell<T>`'s fields are public to allow static initializers. It is not
/// recommended to access its fields directly, `get` should be used instead.
#[lang="unsafe"]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct UnsafeCell<T> {
/// Wrapped value
///
/// This field should not be accessed directly, it is made public for static
/// initializers.
#[unstable]
#[unstable(feature = "core")]
pub value: T,
}
@ -643,7 +645,7 @@ impl<T> UnsafeCell<T> {
///
/// let uc = UnsafeCell::new(5);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new(value: T) -> UnsafeCell<T> {
UnsafeCell { value: value }
}
@ -660,7 +662,7 @@ impl<T> UnsafeCell<T> {
/// let five = uc.get();
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn get(&self) -> *mut T { &self.value as *const T as *mut T }
/// Unwraps the value
@ -680,6 +682,6 @@ impl<T> UnsafeCell<T> {
/// let five = unsafe { uc.into_inner() };
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub unsafe fn into_inner(self) -> T { self.value }
}

View File

@ -64,12 +64,12 @@ static MAX_THREE_B: u32 = 0x10000u32;
*/
/// The highest valid code point
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub const MAX: char = '\u{10ffff}';
/// Converts from `u32` to a `char`
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn from_u32(i: u32) -> Option<char> {
// catch out-of-bounds and surrogates
if (i > MAX as u32) || (i >= 0xD800 && i <= 0xDFFF) {
@ -92,7 +92,7 @@ pub fn from_u32(i: u32) -> Option<char> {
/// Panics if given an `radix` > 36.
///
#[inline]
#[unstable = "pending integer conventions"]
#[unstable(feature = "core", reason = "pending integer conventions")]
pub fn from_digit(num: uint, radix: uint) -> Option<char> {
if radix > 36 {
panic!("from_digit: radix is too high (maximum 36)");
@ -111,7 +111,7 @@ pub fn from_digit(num: uint, radix: uint) -> Option<char> {
}
/// Basic `char` manipulations.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait CharExt {
/// Checks if a `char` parses as a numeric digit in the given radix.
///
@ -126,7 +126,8 @@ pub trait CharExt {
/// # Panics
///
/// Panics if given a radix > 36.
#[unstable = "pending integer conventions"]
#[unstable(feature = "core",
reason = "pending integer conventions")]
fn is_digit(self, radix: uint) -> bool;
/// Converts a character to the corresponding digit.
@ -140,7 +141,8 @@ pub trait CharExt {
/// # Panics
///
/// Panics if given a radix outside the range [0..36].
#[unstable = "pending integer conventions"]
#[unstable(feature = "core",
reason = "pending integer conventions")]
fn to_digit(self, radix: uint) -> Option<uint>;
/// Returns an iterator that yields the hexadecimal Unicode escape
@ -149,7 +151,7 @@ pub trait CharExt {
/// All characters are escaped with Rust syntax of the form `\\u{NNNN}`
/// where `NNNN` is the shortest hexadecimal representation of the code
/// point.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn escape_unicode(self) -> EscapeUnicode;
/// Returns an iterator that yields the 'default' ASCII and
@ -164,17 +166,17 @@ pub trait CharExt {
/// escaped.
/// * Any other chars in the range [0x20,0x7e] are not escaped.
/// * Any other chars are given hex Unicode escapes; see `escape_unicode`.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn escape_default(self) -> EscapeDefault;
/// Returns the amount of bytes this character would need if encoded in
/// UTF-8.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn len_utf8(self) -> uint;
/// Returns the amount of bytes this character would need if encoded in
/// UTF-16.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn len_utf16(self) -> uint;
/// Encodes this character as UTF-8 into the provided byte buffer,
@ -182,7 +184,7 @@ pub trait CharExt {
///
/// If the buffer is not large enough, nothing will be written into it
/// and a `None` will be returned.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn encode_utf8(self, dst: &mut [u8]) -> Option<uint>;
/// Encodes this character as UTF-16 into the provided `u16` buffer,
@ -190,18 +192,20 @@ pub trait CharExt {
///
/// If the buffer is not large enough, nothing will be written into it
/// and a `None` will be returned.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn encode_utf16(self, dst: &mut [u16]) -> Option<uint>;
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl CharExt for char {
#[unstable = "pending integer conventions"]
#[unstable(feature = "core",
reason = "pending integer conventions")]
fn is_digit(self, radix: uint) -> bool {
self.to_digit(radix).is_some()
}
#[unstable = "pending integer conventions"]
#[unstable(feature = "core",
reason = "pending integer conventions")]
fn to_digit(self, radix: uint) -> Option<uint> {
if radix > 36 {
panic!("to_digit: radix is too high (maximum 36)");
@ -216,12 +220,12 @@ impl CharExt for char {
else { None }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn escape_unicode(self) -> EscapeUnicode {
EscapeUnicode { c: self, state: EscapeUnicodeState::Backslash }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn escape_default(self) -> EscapeDefault {
let init_state = match self {
'\t' => EscapeDefaultState::Backslash('t'),
@ -237,7 +241,7 @@ impl CharExt for char {
}
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn len_utf8(self) -> uint {
let code = self as u32;
match () {
@ -249,20 +253,22 @@ impl CharExt for char {
}
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn len_utf16(self) -> uint {
let ch = self as u32;
if (ch & 0xFFFF_u32) == ch { 1 } else { 2 }
}
#[inline]
#[unstable = "pending decision about Iterator/Writer/Reader"]
#[unstable(feature = "core",
reason = "pending decision about Iterator/Writer/Reader")]
fn encode_utf8(self, dst: &mut [u8]) -> Option<uint> {
encode_utf8_raw(self as u32, dst)
}
#[inline]
#[unstable = "pending decision about Iterator/Writer/Reader"]
#[unstable(feature = "core",
reason = "pending decision about Iterator/Writer/Reader")]
fn encode_utf16(self, dst: &mut [u16]) -> Option<uint> {
encode_utf16_raw(self as u32, dst)
}
@ -274,7 +280,7 @@ impl CharExt for char {
/// If the buffer is not large enough, nothing will be written into it
/// and a `None` will be returned.
#[inline]
#[unstable]
#[unstable(feature = "core")]
pub fn encode_utf8_raw(code: u32, dst: &mut [u8]) -> Option<uint> {
// Marked #[inline] to allow llvm optimizing it away
if code < MAX_ONE_B && dst.len() >= 1 {
@ -306,7 +312,7 @@ pub fn encode_utf8_raw(code: u32, dst: &mut [u8]) -> Option<uint> {
/// If the buffer is not large enough, nothing will be written into it
/// and a `None` will be returned.
#[inline]
#[unstable]
#[unstable(feature = "core")]
pub fn encode_utf16_raw(mut ch: u32, dst: &mut [u16]) -> Option<uint> {
// Marked #[inline] to allow llvm optimizing it away
if (ch & 0xFFFF_u32) == ch && dst.len() >= 1 {
@ -327,14 +333,14 @@ pub fn encode_utf16_raw(mut ch: u32, dst: &mut [u16]) -> Option<uint> {
/// An iterator over the characters that represent a `char`, as escaped by
/// Rust's unicode escaping rules.
#[derive(Clone)]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct EscapeUnicode {
c: char,
state: EscapeUnicodeState
}
#[derive(Clone)]
#[unstable]
#[unstable(feature = "core")]
enum EscapeUnicodeState {
Backslash,
Type,
@ -344,7 +350,7 @@ enum EscapeUnicodeState {
Done,
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Iterator for EscapeUnicode {
type Item = char;
@ -390,13 +396,13 @@ impl Iterator for EscapeUnicode {
/// An iterator over the characters that represent a `char`, escaped
/// for maximum portability.
#[derive(Clone)]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct EscapeDefault {
state: EscapeDefaultState
}
#[derive(Clone)]
#[unstable]
#[unstable(feature = "core")]
enum EscapeDefaultState {
Backslash(char),
Char(char),
@ -404,7 +410,7 @@ enum EscapeDefaultState {
Unicode(EscapeUnicode),
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Iterator for EscapeDefault {
type Item = char;

View File

@ -19,15 +19,15 @@
//! explicitly, by convention implementing the `Clone` trait and calling
//! the `clone` method.
#![stable]
#![stable(feature = "rust1", since = "1.0.0")]
use marker::Sized;
/// A common trait for cloning an object.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Clone : Sized {
/// Returns a copy of the value.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn clone(&self) -> Self;
/// Perform copy-assignment from `source`.
@ -36,13 +36,14 @@ pub trait Clone : Sized {
/// but can be overridden to reuse the resources of `a` to avoid unnecessary
/// allocations.
#[inline(always)]
#[unstable = "this function is rarely used"]
#[unstable(feature = "core",
reason = "this function is rarely used")]
fn clone_from(&mut self, source: &Self) {
*self = source.clone()
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: ?Sized> Clone for &'a T {
/// Return a shallow copy of the reference.
#[inline]
@ -51,7 +52,7 @@ impl<'a, T: ?Sized> Clone for &'a T {
macro_rules! clone_impl {
($t:ty) => {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Clone for $t {
/// Return a deep copy of the value.
#[inline]
@ -81,7 +82,8 @@ clone_impl! { char }
macro_rules! extern_fn_clone {
($($A:ident),*) => (
#[unstable = "this may not be sufficient for fns with region parameters"]
#[unstable(feature = "core",
reason = "this may not be sufficient for fns with region parameters")]
impl<$($A,)* ReturnType> Clone for extern "Rust" fn($($A),*) -> ReturnType {
/// Return a copy of a function pointer
#[inline]

View File

@ -39,7 +39,7 @@
//! assert!(SketchyNum {num: 25} != SketchyNum {num: 57});
//! ```
#![stable]
#![stable(feature = "rust1", since = "1.0.0")]
use self::Ordering::*;
@ -68,16 +68,16 @@ use option::Option::{self, Some, None};
/// the rule that `eq` is a strict inverse of `ne`; that is, `!(a == b)` if and
/// only if `a != b`.
#[lang="eq"]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
#[old_orphan_check]
pub trait PartialEq<Rhs: ?Sized = Self> {
/// This method tests for `self` and `other` values to be equal, and is used by `==`.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn eq(&self, other: &Rhs) -> bool;
/// This method tests for `!=`.
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn ne(&self, other: &Rhs) -> bool { !self.eq(other) }
}
@ -90,7 +90,7 @@ pub trait PartialEq<Rhs: ?Sized = Self> {
/// - reflexive: `a == a`;
/// - symmetric: `a == b` implies `b == a`; and
/// - transitive: `a == b` and `b == c` implies `a == c`.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Eq: PartialEq<Self> {
// FIXME #13101: this method is used solely by #[deriving] to
// assert that every component of a type implements #[deriving]
@ -106,16 +106,16 @@ pub trait Eq: PartialEq<Self> {
/// An ordering is, e.g, a result of a comparison between two values.
#[derive(Clone, Copy, PartialEq, Show)]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub enum Ordering {
/// An ordering where a compared value is less [than another].
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
Less = -1,
/// An ordering where a compared value is equal [to another].
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
Equal = 0,
/// An ordering where a compared value is greater [than another].
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
Greater = 1,
}
@ -141,7 +141,7 @@ impl Ordering {
/// assert!(data == b);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn reverse(self) -> Ordering {
unsafe {
// this compiles really nicely (to a single instruction);
@ -164,7 +164,7 @@ impl Ordering {
/// true; and
/// - transitive, `a < b` and `b < c` implies `a < c`. The same must hold for
/// both `==` and `>`.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Ord: Eq + PartialOrd<Self> {
/// This method returns an ordering between `self` and `other` values.
///
@ -178,26 +178,26 @@ pub trait Ord: Eq + PartialOrd<Self> {
/// assert_eq!(10.cmp(&5), Greater); // because 10 > 5
/// assert_eq!( 5.cmp(&5), Equal); // because 5 == 5
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn cmp(&self, other: &Self) -> Ordering;
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Eq for Ordering {}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Ord for Ordering {
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn cmp(&self, other: &Ordering) -> Ordering {
(*self as int).cmp(&(*other as int))
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl PartialOrd for Ordering {
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn partial_cmp(&self, other: &Ordering) -> Option<Ordering> {
(*self as int).partial_cmp(&(*other as int))
}
@ -224,16 +224,16 @@ impl PartialOrd for Ordering {
/// `NaN < 0 == false` and `NaN >= 0 == false` (cf. IEEE 754-2008 section
/// 5.11).
#[lang="ord"]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
/// This method returns an ordering between `self` and `other` values
/// if one exists.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn partial_cmp(&self, other: &Rhs) -> Option<Ordering>;
/// This method tests less than (for `self` and `other`) and is used by the `<` operator.
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn lt(&self, other: &Rhs) -> bool {
match self.partial_cmp(other) {
Some(Less) => true,
@ -243,7 +243,7 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
/// This method tests less than or equal to (`<=`).
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn le(&self, other: &Rhs) -> bool {
match self.partial_cmp(other) {
Some(Less) | Some(Equal) => true,
@ -253,7 +253,7 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
/// This method tests greater than (`>`).
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn gt(&self, other: &Rhs) -> bool {
match self.partial_cmp(other) {
Some(Greater) => true,
@ -263,7 +263,7 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
/// This method tests greater than or equal to (`>=`).
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn ge(&self, other: &Rhs) -> bool {
match self.partial_cmp(other) {
Some(Greater) | Some(Equal) => true,
@ -274,14 +274,14 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
/// Compare and return the minimum of two values.
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn min<T: Ord>(v1: T, v2: T) -> T {
if v1 < v2 { v1 } else { v2 }
}
/// Compare and return the maximum of two values.
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn max<T: Ord>(v1: T, v2: T) -> T {
if v1 > v2 { v1 } else { v2 }
}
@ -290,7 +290,7 @@ pub fn max<T: Ord>(v1: T, v2: T) -> T {
///
/// Returns the first argument if the comparison determines them to be equal.
#[inline]
#[unstable]
#[unstable(feature = "core")]
pub fn partial_min<T: PartialOrd>(v1: T, v2: T) -> Option<T> {
match v1.partial_cmp(&v2) {
Some(Less) | Some(Equal) => Some(v1),
@ -303,7 +303,7 @@ pub fn partial_min<T: PartialOrd>(v1: T, v2: T) -> Option<T> {
///
/// Returns the first argument if the comparison determines them to be equal.
#[inline]
#[unstable]
#[unstable(feature = "core")]
pub fn partial_max<T: PartialOrd>(v1: T, v2: T) -> Option<T> {
match v1.partial_cmp(&v2) {
Some(Less) => Some(v2),
@ -322,7 +322,7 @@ mod impls {
macro_rules! partial_eq_impl {
($($t:ty)*) => ($(
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl PartialEq for $t {
#[inline]
fn eq(&self, other: &$t) -> bool { (*self) == (*other) }
@ -332,7 +332,7 @@ mod impls {
)*)
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl PartialEq for () {
#[inline]
fn eq(&self, _other: &()) -> bool { true }
@ -346,7 +346,7 @@ mod impls {
macro_rules! eq_impl {
($($t:ty)*) => ($(
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Eq for $t {}
)*)
}
@ -355,7 +355,7 @@ mod impls {
macro_rules! partial_ord_impl {
($($t:ty)*) => ($(
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl PartialOrd for $t {
#[inline]
fn partial_cmp(&self, other: &$t) -> Option<Ordering> {
@ -378,7 +378,7 @@ mod impls {
)*)
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl PartialOrd for () {
#[inline]
fn partial_cmp(&self, _: &()) -> Option<Ordering> {
@ -386,7 +386,7 @@ mod impls {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl PartialOrd for bool {
#[inline]
fn partial_cmp(&self, other: &bool) -> Option<Ordering> {
@ -398,7 +398,7 @@ mod impls {
macro_rules! ord_impl {
($($t:ty)*) => ($(
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Ord for $t {
#[inline]
fn cmp(&self, other: &$t) -> Ordering {
@ -410,13 +410,13 @@ mod impls {
)*)
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Ord for () {
#[inline]
fn cmp(&self, _other: &()) -> Ordering { Equal }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Ord for bool {
#[inline]
fn cmp(&self, other: &bool) -> Ordering {
@ -428,14 +428,14 @@ mod impls {
// & pointers
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, 'b, A: ?Sized, B: ?Sized> PartialEq<&'b B> for &'a A where A: PartialEq<B> {
#[inline]
fn eq(&self, other: & &'b B) -> bool { PartialEq::eq(*self, *other) }
#[inline]
fn ne(&self, other: & &'b B) -> bool { PartialEq::ne(*self, *other) }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, 'b, A: ?Sized, B: ?Sized> PartialOrd<&'b B> for &'a A where A: PartialOrd<B> {
#[inline]
fn partial_cmp(&self, other: &&'b B) -> Option<Ordering> {
@ -450,24 +450,24 @@ mod impls {
#[inline]
fn gt(&self, other: & &'b B) -> bool { PartialOrd::gt(*self, *other) }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, A: ?Sized> Ord for &'a A where A: Ord {
#[inline]
fn cmp(&self, other: & &'a A) -> Ordering { Ord::cmp(*self, *other) }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, A: ?Sized> Eq for &'a A where A: Eq {}
// &mut pointers
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, 'b, A: ?Sized, B: ?Sized> PartialEq<&'b mut B> for &'a mut A where A: PartialEq<B> {
#[inline]
fn eq(&self, other: &&'b mut B) -> bool { PartialEq::eq(*self, *other) }
#[inline]
fn ne(&self, other: &&'b mut B) -> bool { PartialEq::ne(*self, *other) }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, 'b, A: ?Sized, B: ?Sized> PartialOrd<&'b mut B> for &'a mut A where A: PartialOrd<B> {
#[inline]
fn partial_cmp(&self, other: &&'b mut B) -> Option<Ordering> {
@ -482,15 +482,15 @@ mod impls {
#[inline]
fn gt(&self, other: &&'b mut B) -> bool { PartialOrd::gt(*self, *other) }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, A: ?Sized> Ord for &'a mut A where A: Ord {
#[inline]
fn cmp(&self, other: &&'a mut A) -> Ordering { Ord::cmp(*self, *other) }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, A: ?Sized> Eq for &'a mut A where A: Eq {}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, 'b, A: ?Sized, B: ?Sized> PartialEq<&'b mut B> for &'a A where A: PartialEq<B> {
#[inline]
fn eq(&self, other: &&'b mut B) -> bool { PartialEq::eq(*self, *other) }
@ -498,7 +498,7 @@ mod impls {
fn ne(&self, other: &&'b mut B) -> bool { PartialEq::ne(*self, *other) }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, 'b, A: ?Sized, B: ?Sized> PartialEq<&'b B> for &'a mut A where A: PartialEq<B> {
#[inline]
fn eq(&self, other: &&'b B) -> bool { PartialEq::eq(*self, *other) }

View File

@ -81,7 +81,7 @@
//! }
//! ```
#![stable]
#![stable(feature = "rust1", since = "1.0.0")]
/// A trait that types which have a useful default value should implement.
///
@ -97,7 +97,7 @@
/// bar: f32,
/// }
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Default {
/// Returns the "default value" for a type.
///
@ -131,16 +131,16 @@ pub trait Default {
/// fn default() -> Kind { Kind::A }
/// }
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn default() -> Self;
}
macro_rules! default_impl {
($t:ty, $v:expr) => {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Default for $t {
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn default() -> $t { $v }
}
}

View File

@ -79,13 +79,14 @@
//! }
//! ```
#![stable]
#![stable(feature = "rust1", since = "1.0.0")]
use prelude::*;
use fmt::Display;
/// Base functionality for all errors in Rust.
#[unstable = "the exact API of this trait may change"]
#[unstable(feature = "core",
reason = "the exact API of this trait may change")]
pub trait Error: Display {
/// A short description of the error; usually a static string.
fn description(&self) -> &str;
@ -95,14 +96,15 @@ pub trait Error: Display {
}
/// A trait for types that can be converted from a given error type `E`.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait FromError<E> {
/// Perform the conversion.
#[stable(feature = "rust1", since = "1.0.0")]
fn from_error(err: E) -> Self;
}
// Any type is convertable from itself
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<E> FromError<E> for E {
fn from_error(err: E) -> E {
err

View File

@ -30,10 +30,12 @@
//! })
//! ```
#![deprecated = "It is unclear if this module is more robust than implementing \
Drop on a custom type, and this module is being removed with no \
replacement. Use a custom Drop implementation to regain existing \
functionality."]
#![unstable(feature = "core")]
#![deprecated(since = "1.0.0",
reason = "It is unclear if this module is more robust than implementing \
Drop on a custom type, and this module is being removed with no \
replacement. Use a custom Drop implementation to regain existing \
functionality.")]
#![allow(deprecated)]
use ops::{Drop, FnMut, FnOnce};

View File

@ -11,7 +11,7 @@
//! Utilities for formatting and printing strings
#![allow(unused_variables)]
#![stable]
#![stable(feature = "rust1", since = "1.0.0")]
use any;
use cell::{Cell, RefCell, Ref, RefMut};
@ -39,7 +39,8 @@ mod num;
mod float;
pub mod rt;
#[unstable = "core and I/O reconciliation may alter this definition"]
#[unstable(feature = "core",
reason = "core and I/O reconciliation may alter this definition")]
/// The type returned by formatter methods.
pub type Result = result::Result<(), Error>;
@ -48,7 +49,8 @@ pub type Result = result::Result<(), Error>;
/// This type does not support transmission of an error other than that an error
/// occurred. Any extra information must be arranged to be transmitted through
/// some other means.
#[unstable = "core and I/O reconciliation may alter this definition"]
#[unstable(feature = "core",
reason = "core and I/O reconciliation may alter this definition")]
#[derive(Copy, Show)]
pub struct Error;
@ -61,7 +63,8 @@ pub struct Error;
/// This trait should generally not be implemented by consumers of the standard
/// library. The `write!` macro accepts an instance of `io::Writer`, and the
/// `io::Writer` trait is favored over implementing this trait.
#[unstable = "waiting for core and I/O reconciliation"]
#[unstable(feature = "core",
reason = "waiting for core and I/O reconciliation")]
pub trait Writer {
/// Writes a slice of bytes into this writer, returning whether the write
/// succeeded.
@ -104,7 +107,8 @@ pub trait Writer {
/// A struct to represent both where to emit formatting strings to and how they
/// should be formatted. A mutable version of this is passed to all formatting
/// traits.
#[unstable = "name may change and implemented traits are also unstable"]
#[unstable(feature = "core",
reason = "name may change and implemented traits are also unstable")]
pub struct Formatter<'a> {
flags: uint,
fill: char,
@ -126,7 +130,8 @@ enum Void {}
/// family of functions. It contains a function to format the given value. At
/// compile time it is ensured that the function and the value have the correct
/// types, and then this struct is used to canonicalize arguments to one type.
#[unstable = "implementation detail of the `format_args!` macro"]
#[unstable(feature = "core",
reason = "implementation detail of the `format_args!` macro")]
#[derive(Copy)]
pub struct Argument<'a> {
value: &'a Void,
@ -165,7 +170,8 @@ impl<'a> Arguments<'a> {
/// When using the format_args!() macro, this function is used to generate the
/// Arguments structure.
#[doc(hidden)] #[inline]
#[unstable = "implementation detail of the `format_args!` macro"]
#[unstable(feature = "core",
reason = "implementation detail of the `format_args!` macro")]
pub fn new(pieces: &'a [&'a str],
args: &'a [Argument<'a>]) -> Arguments<'a> {
Arguments {
@ -182,7 +188,8 @@ impl<'a> Arguments<'a> {
/// created with `argumentuint`. However, failing to do so doesn't cause
/// unsafety, but will ignore invalid .
#[doc(hidden)] #[inline]
#[unstable = "implementation detail of the `format_args!` macro"]
#[unstable(feature = "core",
reason = "implementation detail of the `format_args!` macro")]
pub fn with_placeholders(pieces: &'a [&'a str],
fmt: &'a [rt::Argument],
args: &'a [Argument<'a>]) -> Arguments<'a> {
@ -203,7 +210,7 @@ impl<'a> Arguments<'a> {
/// and pass it to a function or closure, passed as the first argument. The
/// macro validates the format string at compile-time so usage of the `write`
/// and `format` functions can be safely performed.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
#[derive(Copy)]
pub struct Arguments<'a> {
// Format string pieces to print.
@ -217,14 +224,14 @@ pub struct Arguments<'a> {
args: &'a [Argument<'a>],
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> Debug for Arguments<'a> {
fn fmt(&self, fmt: &mut Formatter) -> Result {
Display::fmt(self, fmt)
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> Display for Arguments<'a> {
fn fmt(&self, fmt: &mut Formatter) -> Result {
write(fmt.buf, *self)
@ -233,7 +240,9 @@ impl<'a> Display for Arguments<'a> {
/// Format trait for the `:?` format. Useful for debugging, all types
/// should implement this.
#[deprecated = "renamed to Debug"]
#[unstable(feature = "core",
reason = "I/O and core have yet to be reconciled")]
#[deprecated(since = "1.0.0", reason = "renamed to Debug")]
#[cfg(not(stage0))]
pub trait Show {
/// Formats the value using the given formatter.
@ -242,7 +251,8 @@ pub trait Show {
/// Format trait for the `:?` format. Useful for debugging, all types
/// should implement this.
#[unstable = "I/O and core have yet to be reconciled"]
#[unstable(feature = "core",
reason = "I/O and core have yet to be reconciled")]
#[rustc_on_unimplemented = "`{Self}` cannot be formatted using `:?`; if it is defined in your \
crate, add `#[derive(Debug)]` or manually implement it"]
#[lang = "debug_trait"]
@ -259,7 +269,8 @@ impl<T: Show + ?Sized> Debug for T {
/// When a value can be semantically expressed as a String, this trait may be
/// used. It corresponds to the default format, `{}`.
#[deprecated = "renamed to Display"]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0", reason = "renamed to Display")]
#[cfg(not(stage0))]
pub trait String {
/// Formats the value using the given formatter.
@ -268,7 +279,8 @@ pub trait String {
/// When a value can be semantically expressed as a String, this trait may be
/// used. It corresponds to the default format, `{}`.
#[unstable = "I/O and core have yet to be reconciled"]
#[unstable(feature = "core",
reason = "I/O and core have yet to be reconciled")]
#[rustc_on_unimplemented = "`{Self}` cannot be formatted with the default formatter; try using \
`:?` instead if you are using a format string"]
pub trait Display {
@ -283,49 +295,56 @@ impl<T: String + ?Sized> Display for T {
}
/// Format trait for the `o` character
#[unstable = "I/O and core have yet to be reconciled"]
#[unstable(feature = "core",
reason = "I/O and core have yet to be reconciled")]
pub trait Octal {
/// Formats the value using the given formatter.
fn fmt(&self, &mut Formatter) -> Result;
}
/// Format trait for the `b` character
#[unstable = "I/O and core have yet to be reconciled"]
#[unstable(feature = "core",
reason = "I/O and core have yet to be reconciled")]
pub trait Binary {
/// Formats the value using the given formatter.
fn fmt(&self, &mut Formatter) -> Result;
}
/// Format trait for the `x` character
#[unstable = "I/O and core have yet to be reconciled"]
#[unstable(feature = "core",
reason = "I/O and core have yet to be reconciled")]
pub trait LowerHex {
/// Formats the value using the given formatter.
fn fmt(&self, &mut Formatter) -> Result;
}
/// Format trait for the `X` character
#[unstable = "I/O and core have yet to be reconciled"]
#[unstable(feature = "core",
reason = "I/O and core have yet to be reconciled")]
pub trait UpperHex {
/// Formats the value using the given formatter.
fn fmt(&self, &mut Formatter) -> Result;
}
/// Format trait for the `p` character
#[unstable = "I/O and core have yet to be reconciled"]
#[unstable(feature = "core",
reason = "I/O and core have yet to be reconciled")]
pub trait Pointer {
/// Formats the value using the given formatter.
fn fmt(&self, &mut Formatter) -> Result;
}
/// Format trait for the `e` character
#[unstable = "I/O and core have yet to be reconciled"]
#[unstable(feature = "core",
reason = "I/O and core have yet to be reconciled")]
pub trait LowerExp {
/// Formats the value using the given formatter.
fn fmt(&self, &mut Formatter) -> Result;
}
/// Format trait for the `E` character
#[unstable = "I/O and core have yet to be reconciled"]
#[unstable(feature = "core",
reason = "I/O and core have yet to be reconciled")]
pub trait UpperExp {
/// Formats the value using the given formatter.
fn fmt(&self, &mut Formatter) -> Result;
@ -339,8 +358,9 @@ pub trait UpperExp {
///
/// * output - the buffer to write output to
/// * args - the precompiled arguments generated by `format_args!`
#[unstable = "libcore and I/O have yet to be reconciled, and this is an \
implementation detail which should not otherwise be exported"]
#[unstable(feature = "core",
reason = "libcore and I/O have yet to be reconciled, and this is an \
implementation detail which should not otherwise be exported")]
pub fn write(output: &mut Writer, args: Arguments) -> Result {
let mut formatter = Formatter {
flags: 0,
@ -436,7 +456,8 @@ impl<'a> Formatter<'a> {
///
/// This function will correctly account for the flags provided as well as
/// the minimum width. It will not take precision into account.
#[unstable = "definition may change slightly over time"]
#[unstable(feature = "core",
reason = "definition may change slightly over time")]
pub fn pad_integral(&mut self,
is_positive: bool,
prefix: &str,
@ -512,7 +533,8 @@ impl<'a> Formatter<'a> {
/// is longer than this length
///
/// Notably this function ignored the `flag` parameters
#[unstable = "definition may change slightly over time"]
#[unstable(feature = "core",
reason = "definition may change slightly over time")]
pub fn pad(&mut self, s: &str) -> Result {
// Make sure there's a fast path up front
if self.width.is_none() && self.precision.is_none() {
@ -589,39 +611,42 @@ impl<'a> Formatter<'a> {
/// Writes some data to the underlying buffer contained within this
/// formatter.
#[unstable = "reconciling core and I/O may alter this definition"]
#[unstable(feature = "core",
reason = "reconciling core and I/O may alter this definition")]
pub fn write_str(&mut self, data: &str) -> Result {
self.buf.write_str(data)
}
/// Writes some formatted information into this instance
#[unstable = "reconciling core and I/O may alter this definition"]
#[unstable(feature = "core",
reason = "reconciling core and I/O may alter this definition")]
pub fn write_fmt(&mut self, fmt: Arguments) -> Result {
write(self.buf, fmt)
}
/// Flags for formatting (packed version of rt::Flag)
#[unstable = "return type may change and method was just created"]
#[unstable(feature = "core",
reason = "return type may change and method was just created")]
pub fn flags(&self) -> uint { self.flags }
/// Character used as 'fill' whenever there is alignment
#[unstable = "method was just created"]
#[unstable(feature = "core", reason = "method was just created")]
pub fn fill(&self) -> char { self.fill }
/// Flag indicating what form of alignment was requested
#[unstable = "method was just created"]
#[unstable(feature = "core", reason = "method was just created")]
pub fn align(&self) -> rt::Alignment { self.align }
/// Optionally specified integer width that the output should be
#[unstable = "method was just created"]
#[unstable(feature = "core", reason = "method was just created")]
pub fn width(&self) -> Option<uint> { self.width }
/// Optionally specified precision for numeric types
#[unstable = "method was just created"]
#[unstable(feature = "core", reason = "method was just created")]
pub fn precision(&self) -> Option<uint> { self.precision }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Display for Error {
fn fmt(&self, f: &mut Formatter) -> Result {
Display::fmt("an error occurred when formatting an argument", f)
@ -631,7 +656,8 @@ impl Display for Error {
/// This is a function which calls are emitted to by the compiler itself to
/// create the Argument structures that are passed into the `format` function.
#[doc(hidden)] #[inline]
#[unstable = "implementation detail of the `format_args!` macro"]
#[unstable(feature = "core",
reason = "implementation detail of the `format_args!` macro")]
pub fn argument<'a, T>(f: fn(&T, &mut Formatter) -> Result,
t: &'a T) -> Argument<'a> {
Argument::new(t, f)
@ -640,7 +666,8 @@ pub fn argument<'a, T>(f: fn(&T, &mut Formatter) -> Result,
/// When the compiler determines that the type of an argument *must* be a uint
/// (such as for width and precision), then it invokes this method.
#[doc(hidden)] #[inline]
#[unstable = "implementation detail of the `format_args!` macro"]
#[unstable(feature = "core",
reason = "implementation detail of the `format_args!` macro")]
pub fn argumentuint<'a>(s: &'a uint) -> Argument<'a> {
Argument::from_uint(s)
}
@ -650,11 +677,11 @@ pub fn argumentuint<'a>(s: &'a uint) -> Argument<'a> {
macro_rules! fmt_refs {
($($tr:ident),*) => {
$(
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: ?Sized + $tr> $tr for &'a T {
fn fmt(&self, f: &mut Formatter) -> Result { $tr::fmt(&**self, f) }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: ?Sized + $tr> $tr for &'a mut T {
fn fmt(&self, f: &mut Formatter) -> Result { $tr::fmt(&**self, f) }
}
@ -664,21 +691,21 @@ macro_rules! fmt_refs {
fmt_refs! { Debug, Display, Octal, Binary, LowerHex, UpperHex, LowerExp, UpperExp }
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Debug for bool {
fn fmt(&self, f: &mut Formatter) -> Result {
Display::fmt(self, f)
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Display for bool {
fn fmt(&self, f: &mut Formatter) -> Result {
Display::fmt(if *self { "true" } else { "false" }, f)
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Debug for str {
fn fmt(&self, f: &mut Formatter) -> Result {
try!(write!(f, "\""));
@ -689,14 +716,14 @@ impl Debug for str {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Display for str {
fn fmt(&self, f: &mut Formatter) -> Result {
f.pad(self)
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Debug for char {
fn fmt(&self, f: &mut Formatter) -> Result {
use char::CharExt;
@ -708,7 +735,7 @@ impl Debug for char {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Display for char {
fn fmt(&self, f: &mut Formatter) -> Result {
let mut utf8 = [0u8; 4];
@ -718,7 +745,7 @@ impl Display for char {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Pointer for *const T {
fn fmt(&self, f: &mut Formatter) -> Result {
f.flags |= 1 << (rt::FlagAlternate as uint);
@ -728,21 +755,21 @@ impl<T> Pointer for *const T {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Pointer for *mut T {
fn fmt(&self, f: &mut Formatter) -> Result {
Pointer::fmt(&(*self as *const T), f)
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> Pointer for &'a T {
fn fmt(&self, f: &mut Formatter) -> Result {
Pointer::fmt(&(*self as *const T), f)
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> Pointer for &'a mut T {
fn fmt(&self, f: &mut Formatter) -> Result {
Pointer::fmt(&(&**self as *const T), f)
@ -751,14 +778,14 @@ impl<'a, T> Pointer for &'a mut T {
macro_rules! floating { ($ty:ident) => {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Debug for $ty {
fn fmt(&self, fmt: &mut Formatter) -> Result {
Display::fmt(self, fmt)
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Display for $ty {
fn fmt(&self, fmt: &mut Formatter) -> Result {
use num::Float;
@ -780,7 +807,7 @@ macro_rules! floating { ($ty:ident) => {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl LowerExp for $ty {
fn fmt(&self, fmt: &mut Formatter) -> Result {
use num::Float;
@ -802,7 +829,7 @@ macro_rules! floating { ($ty:ident) => {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl UpperExp for $ty {
fn fmt(&self, fmt: &mut Formatter) -> Result {
use num::Float;
@ -829,11 +856,11 @@ floating! { f64 }
// Implementation of Display/Debug for various core types
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Debug for *const T {
fn fmt(&self, f: &mut Formatter) -> Result { Pointer::fmt(self, f) }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Debug for *mut T {
fn fmt(&self, f: &mut Formatter) -> Result { Pointer::fmt(self, f) }
}
@ -845,7 +872,7 @@ macro_rules! peel {
macro_rules! tuple {
() => ();
( $($name:ident,)+ ) => (
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<$($name:Debug),*> Debug for ($($name,)*) {
#[allow(non_snake_case, unused_assignments)]
fn fmt(&self, f: &mut Formatter) -> Result {
@ -871,12 +898,12 @@ macro_rules! tuple {
tuple! { T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, }
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> Debug for &'a (any::Any+'a) {
fn fmt(&self, f: &mut Formatter) -> Result { f.pad("&Any") }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Debug> Debug for [T] {
fn fmt(&self, f: &mut Formatter) -> Result {
if f.flags & (1 << (rt::FlagAlternate as uint)) == 0 {
@ -898,21 +925,21 @@ impl<T: Debug> Debug for [T] {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Debug for () {
fn fmt(&self, f: &mut Formatter) -> Result {
f.pad("()")
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Copy + Debug> Debug for Cell<T> {
fn fmt(&self, f: &mut Formatter) -> Result {
write!(f, "Cell {{ value: {:?} }}", self.get())
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Debug> Debug for RefCell<T> {
fn fmt(&self, f: &mut Formatter) -> Result {
match self.try_borrow() {
@ -922,14 +949,14 @@ impl<T: Debug> Debug for RefCell<T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'b, T: Debug> Debug for Ref<'b, T> {
fn fmt(&self, f: &mut Formatter) -> Result {
Debug::fmt(&**self, f)
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'b, T: Debug> Debug for RefMut<'b, T> {
fn fmt(&self, f: &mut Formatter) -> Result {
Debug::fmt(&*(self.deref()), f)

View File

@ -111,7 +111,8 @@ radix! { UpperHex, 16, "0x", x @ 0 ... 9 => b'0' + x,
/// A radix with in the range of `2..36`.
#[derive(Clone, Copy, PartialEq)]
#[unstable = "may be renamed or move to a different module"]
#[unstable(feature = "core",
reason = "may be renamed or move to a different module")]
pub struct Radix {
base: u8,
}
@ -135,7 +136,8 @@ impl GenericRadix for Radix {
}
/// A helper type for formatting radixes.
#[unstable = "may be renamed or move to a different module"]
#[unstable(feature = "core",
reason = "may be renamed or move to a different module")]
#[derive(Copy)]
pub struct RadixFmt<T, R>(T, R);
@ -147,20 +149,21 @@ pub struct RadixFmt<T, R>(T, R);
/// use std::fmt::radix;
/// assert_eq!(format!("{}", radix(55, 36)), "1j".to_string());
/// ```
#[unstable = "may be renamed or move to a different module"]
#[unstable(feature = "core",
reason = "may be renamed or move to a different module")]
pub fn radix<T>(x: T, base: u8) -> RadixFmt<T, Radix> {
RadixFmt(x, Radix::new(base))
}
macro_rules! radix_fmt {
($T:ty as $U:ty, $fmt:ident, $S:expr) => {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl fmt::Debug for RadixFmt<$T, Radix> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(self, f)
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl fmt::Display for RadixFmt<$T, Radix> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self { RadixFmt(ref x, radix) => radix.$fmt(*x as $U, f) }
@ -170,7 +173,7 @@ macro_rules! radix_fmt {
}
macro_rules! int_base {
($Trait:ident for $T:ident as $U:ident -> $Radix:ident) => {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl fmt::$Trait for $T {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
$Radix.fmt_int(*self as $U, f)
@ -181,7 +184,7 @@ macro_rules! int_base {
macro_rules! show {
($T:ident with $S:expr) => {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl fmt::Debug for $T {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(self, f)

View File

@ -14,7 +14,8 @@
//! These definitions are similar to their `ct` equivalents, but differ in that
//! these can be statically allocated and are slightly optimized for the runtime
#![unstable = "implementation detail of the `format_args!` macro"]
#![unstable(feature = "core",
reason = "implementation detail of the `format_args!` macro")]
pub use self::Alignment::*;
pub use self::Count::*;

View File

@ -56,7 +56,8 @@
//! assert_eq!(hash::<_, SipHasher>(&person1), hash::<_, SipHasher>(&person2));
//! ```
#![unstable = "module was recently redesigned"]
#![unstable(feature = "hash",
reason = "module was recently redesigned")]
use prelude::*;
@ -95,7 +96,8 @@ pub trait Hasher {
/// A common bound on the `Hasher` parameter to `Hash` implementations in order
/// to generically hash an aggregate.
#[experimental = "this trait will likely be replaced by io::Writer"]
#[unstable(feature = "hash",
reason = "this trait will likely be replaced by io::Writer")]
#[allow(missing_docs)]
pub trait Writer {
fn write(&mut self, bytes: &[u8]);

View File

@ -112,7 +112,8 @@ impl SipHasher {
}
/// Returns the computed hash.
#[deprecated = "renamed to finish"]
#[unstable(feature = "hash")]
#[deprecated(since = "1.0.0", reason = "renamed to finish")]
pub fn result(&self) -> u64 { self.finish() }
}

View File

@ -39,7 +39,7 @@
//! guaranteed to happen in order. This is the standard mode for working
//! with atomic types and is equivalent to Java's `volatile`.
#![unstable]
#![unstable(feature = "core")]
#![allow(missing_docs)]
use marker::Sized;
@ -221,7 +221,7 @@ extern "rust-intrinsic" {
///
/// `forget` is unsafe because the caller is responsible for
/// ensuring the argument is deallocated already.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn forget<T>(_: T) -> ();
/// Unsafely transforms a value of one type into a value of another type.
@ -237,7 +237,7 @@ extern "rust-intrinsic" {
/// let v: &[u8] = unsafe { mem::transmute("L") };
/// assert!(v == [76u8]);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn transmute<T,U>(e: T) -> U;
/// Gives the address for the return value of the enclosing function.
@ -297,7 +297,7 @@ extern "rust-intrinsic" {
/// }
/// }
/// ```
#[unstable]
#[unstable(feature = "core")]
pub fn copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T, count: uint);
/// Copies `count * size_of<T>` bytes from `src` to `dst`. The source
@ -327,12 +327,13 @@ extern "rust-intrinsic" {
/// }
/// ```
///
#[unstable]
#[unstable(feature = "core")]
pub fn copy_memory<T>(dst: *mut T, src: *const T, count: uint);
/// Invokes memset on the specified pointer, setting `count * size_of::<T>()`
/// bytes of memory starting at `dst` to `c`.
#[unstable = "uncertain about naming and semantics"]
#[unstable(feature = "core",
reason = "uncertain about naming and semantics")]
pub fn set_memory<T>(dst: *mut T, val: u8, count: uint);
/// Equivalent to the appropriate `llvm.memcpy.p0i8.0i8.*` intrinsic, with

File diff suppressed because it is too large Load Diff

View File

@ -48,7 +48,8 @@
// separate crate, libcoretest, to avoid bizarre issues.
#![crate_name = "core"]
#![unstable]
#![unstable(feature = "core")]
#![feature(staged_api)]
#![staged_api]
#![crate_type = "rlib"]
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",

View File

@ -52,7 +52,7 @@ macro_rules! panic {
/// assert!(a + b == 30, "a = {}, b = {}", a, b);
/// ```
#[macro_export]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
macro_rules! assert {
($cond:expr) => (
if !$cond {
@ -79,7 +79,7 @@ macro_rules! assert {
/// assert_eq!(a, b);
/// ```
#[macro_export]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
macro_rules! assert_eq {
($left:expr , $right:expr) => ({
match (&($left), &($right)) {
@ -123,7 +123,7 @@ macro_rules! assert_eq {
/// debug_assert!(a + b == 30, "a = {}, b = {}", a, b);
/// ```
#[macro_export]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
macro_rules! debug_assert {
($($arg:tt)*) => (if cfg!(not(ndebug)) { assert!($($arg)*); })
}
@ -185,7 +185,7 @@ macro_rules! write {
/// Equivalent to the `write!` macro, except that a newline is appended after
/// the message is written.
#[macro_export]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
macro_rules! writeln {
($dst:expr, $fmt:expr) => (
write!($dst, concat!($fmt, "\n"))
@ -235,7 +235,8 @@ macro_rules! writeln {
/// }
/// ```
#[macro_export]
#[unstable = "relationship with panic is unclear"]
#[unstable(feature = "core",
reason = "relationship with panic is unclear")]
macro_rules! unreachable {
() => ({
panic!("internal error: entered unreachable code")
@ -251,7 +252,8 @@ macro_rules! unreachable {
/// A standardised placeholder for marking unfinished code. It panics with the
/// message `"not yet implemented"` when executed.
#[macro_export]
#[unstable = "relationship with panic is unclear"]
#[unstable(feature = "core",
reason = "relationship with panic is unclear")]
macro_rules! unimplemented {
() => (panic!("not yet implemented"))
}

View File

@ -23,12 +23,13 @@
//! implemented using unsafe code. In that case, you may want to embed
//! some of the marker types below into your type.
#![stable]
#![stable(feature = "rust1", since = "1.0.0")]
use clone::Clone;
/// Types able to be transferred across thread boundaries.
#[unstable = "will be overhauled with new lifetime rules; see RFC 458"]
#[unstable(feature = "core",
reason = "will be overhauled with new lifetime rules; see RFC 458")]
#[lang="send"]
#[rustc_on_unimplemented = "`{Self}` cannot be sent between threads safely"]
pub unsafe trait Send: 'static {
@ -36,7 +37,7 @@ pub unsafe trait Send: 'static {
}
/// Types with a constant size known at compile-time.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
#[lang="sized"]
#[rustc_on_unimplemented = "`{Self}` does not have a constant size known at compile-time"]
pub trait Sized {
@ -142,7 +143,7 @@ pub trait Sized {
/// to consider though: if you think your type may _not_ be able to implement `Copy` in the future,
/// then it might be prudent to not implement `Copy`. This is because removing `Copy` is a breaking
/// change: that second example would fail to compile if we made `Foo` non-`Copy`.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
#[lang="copy"]
pub trait Copy {
// Empty.
@ -193,7 +194,8 @@ pub trait Copy {
/// around the value(s) which can be mutated when behind a `&`
/// reference; not doing this is undefined behaviour (for example,
/// `transmute`-ing from `&T` to `&mut T` is illegal).
#[unstable = "will be overhauled with new lifetime rules; see RFC 458"]
#[unstable(feature = "core",
reason = "will be overhauled with new lifetime rules; see RFC 458")]
#[lang="sync"]
#[rustc_on_unimplemented = "`{Self}` cannot be shared between threads safely"]
pub unsafe trait Sync {
@ -238,7 +240,8 @@ pub unsafe trait Sync {
/// `S<T>` is a subtype of `S<U>` if `T` is a subtype of `U`
/// (for example, `S<&'static int>` is a subtype of `S<&'a int>`
/// for some lifetime `'a`, but not the other way around).
#[unstable = "likely to change with new variance strategy"]
#[unstable(feature = "core",
reason = "likely to change with new variance strategy")]
#[lang="covariant_type"]
#[derive(PartialEq, Eq, PartialOrd, Ord)]
pub struct CovariantType<T: ?Sized>;
@ -287,7 +290,8 @@ impl<T: ?Sized> Clone for CovariantType<T> {
/// subtype of `S<U>` if `U` is a subtype of `T`; given that the
/// function requires arguments of type `T`, it must also accept
/// arguments of type `U`, hence such a conversion is safe.
#[unstable = "likely to change with new variance strategy"]
#[unstable(feature = "core",
reason = "likely to change with new variance strategy")]
#[lang="contravariant_type"]
#[derive(PartialEq, Eq, PartialOrd, Ord)]
pub struct ContravariantType<T: ?Sized>;
@ -317,14 +321,17 @@ impl<T: ?Sized> Clone for ContravariantType<T> {
/// The type system would infer that `value` is only read here and
/// never written, but in fact `Cell` uses unsafe code to achieve
/// interior mutability.
#[unstable = "likely to change with new variance strategy"]
#[unstable(feature = "core",
reason = "likely to change with new variance strategy")]
#[lang="invariant_type"]
#[derive(PartialEq, Eq, PartialOrd, Ord)]
pub struct InvariantType<T: ?Sized>;
#[unstable = "likely to change with new variance strategy"]
#[unstable(feature = "core",
reason = "likely to change with new variance strategy")]
impl<T: ?Sized> Copy for InvariantType<T> {}
#[unstable = "likely to change with new variance strategy"]
#[unstable(feature = "core",
reason = "likely to change with new variance strategy")]
impl<T: ?Sized> Clone for InvariantType<T> {
fn clone(&self) -> InvariantType<T> { *self }
}
@ -345,7 +352,8 @@ impl<T: ?Sized> Clone for InvariantType<T> {
///
/// For more information about variance, refer to this Wikipedia
/// article <http://en.wikipedia.org/wiki/Variance_%28computer_science%29>.
#[unstable = "likely to change with new variance strategy"]
#[unstable(feature = "core",
reason = "likely to change with new variance strategy")]
#[lang="covariant_lifetime"]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct CovariantLifetime<'a>;
@ -362,7 +370,8 @@ pub struct CovariantLifetime<'a>;
///
/// For more information about variance, refer to this Wikipedia
/// article <http://en.wikipedia.org/wiki/Variance_%28computer_science%29>.
#[unstable = "likely to change with new variance strategy"]
#[unstable(feature = "core",
reason = "likely to change with new variance strategy")]
#[lang="contravariant_lifetime"]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct ContravariantLifetime<'a>;
@ -374,7 +383,8 @@ pub struct ContravariantLifetime<'a>;
/// pointer that is actually a pointer into memory with lifetime `'a`,
/// and this pointer is itself stored in an inherently mutable
/// location (such as a `Cell`).
#[unstable = "likely to change with new variance strategy"]
#[unstable(feature = "core",
reason = "likely to change with new variance strategy")]
#[lang="invariant_lifetime"]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct InvariantLifetime<'a>;
@ -382,7 +392,8 @@ pub struct InvariantLifetime<'a>;
/// A type which is considered "not POD", meaning that it is not
/// implicitly copyable. This is typically embedded in other types to
/// ensure that they are never copied, even if they lack a destructor.
#[unstable = "likely to change with new variance strategy"]
#[unstable(feature = "core",
reason = "likely to change with new variance strategy")]
#[lang="no_copy_bound"]
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
#[allow(missing_copy_implementations)]
@ -390,7 +401,8 @@ pub struct NoCopy;
/// A type which is considered managed by the GC. This is typically
/// embedded in other types.
#[unstable = "likely to change with new variance strategy"]
#[unstable(feature = "core",
reason = "likely to change with new variance strategy")]
#[lang="managed_bound"]
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
#[allow(missing_copy_implementations)]

View File

@ -13,13 +13,13 @@
//! This module contains functions for querying the size and alignment of
//! types, initializing and manipulating memory.
#![stable]
#![stable(feature = "rust1", since = "1.0.0")]
use marker::Sized;
use intrinsics;
use ptr;
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub use intrinsics::transmute;
/// Moves a thing into the void.
@ -29,7 +29,7 @@ pub use intrinsics::transmute;
///
/// This function is the unsafe version of the `drop` function because it does
/// not run any destructors.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub use intrinsics::forget;
/// Returns the size of a type in bytes.
@ -42,7 +42,7 @@ pub use intrinsics::forget;
/// assert_eq!(4, mem::size_of::<i32>());
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn size_of<T>() -> uint {
unsafe { intrinsics::size_of::<T>() }
}
@ -57,7 +57,7 @@ pub fn size_of<T>() -> uint {
/// assert_eq!(4, mem::size_of_val(&5i32));
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn size_of_val<T>(_val: &T) -> uint {
size_of::<T>()
}
@ -74,7 +74,7 @@ pub fn size_of_val<T>(_val: &T) -> uint {
/// assert_eq!(4, mem::min_align_of::<i32>());
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn min_align_of<T>() -> uint {
unsafe { intrinsics::min_align_of::<T>() }
}
@ -89,7 +89,7 @@ pub fn min_align_of<T>() -> uint {
/// assert_eq!(4, mem::min_align_of_val(&5i32));
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn min_align_of_val<T>(_val: &T) -> uint {
min_align_of::<T>()
}
@ -107,7 +107,7 @@ pub fn min_align_of_val<T>(_val: &T) -> uint {
/// assert_eq!(4, mem::align_of::<i32>());
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn align_of<T>() -> uint {
// We use the preferred alignment as the default alignment for a type. This
// appears to be what clang migrated towards as well:
@ -129,7 +129,7 @@ pub fn align_of<T>() -> uint {
/// assert_eq!(4, mem::align_of_val(&5i32));
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn align_of_val<T>(_val: &T) -> uint {
align_of::<T>()
}
@ -153,7 +153,7 @@ pub fn align_of_val<T>(_val: &T) -> uint {
/// let x: int = unsafe { mem::zeroed() };
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub unsafe fn zeroed<T>() -> T {
intrinsics::init()
}
@ -174,7 +174,7 @@ pub unsafe fn zeroed<T>() -> T {
/// let x: int = unsafe { mem::uninitialized() };
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub unsafe fn uninitialized<T>() -> T {
intrinsics::uninit()
}
@ -196,7 +196,7 @@ pub unsafe fn uninitialized<T>() -> T {
/// assert_eq!(5, *y);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn swap<T>(x: &mut T, y: &mut T) {
unsafe {
// Give ourselves some scratch space to work with
@ -261,7 +261,7 @@ pub fn swap<T>(x: &mut T, y: &mut T) {
/// }
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn replace<T>(dest: &mut T, mut src: T) -> T {
swap(dest, &mut src);
src
@ -288,7 +288,7 @@ pub fn replace<T>(dest: &mut T, mut src: T) -> T {
/// println!("{}", *borrow);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn drop<T>(_x: T) { }
/// Interprets `src` as `&U`, and then reads `src` without moving the contained value.
@ -311,15 +311,16 @@ pub fn drop<T>(_x: T) { }
/// assert_eq!(1, one);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
ptr::read(src as *const T as *const U)
}
/// Transforms lifetime of the second pointer to match the first.
#[inline]
#[unstable = "this function may be removed in the future due to its \
questionable utility"]
#[unstable(feature = "core",
reason = "this function may be removed in the future due to its \
questionable utility")]
pub unsafe fn copy_lifetime<'a, S: ?Sized, T: ?Sized + 'a>(_ptr: &'a S,
ptr: &T) -> &'a T {
transmute(ptr)
@ -327,8 +328,9 @@ pub unsafe fn copy_lifetime<'a, S: ?Sized, T: ?Sized + 'a>(_ptr: &'a S,
/// Transforms lifetime of the second mutable pointer to match the first.
#[inline]
#[unstable = "this function may be removed in the future due to its \
questionable utility"]
#[unstable(feature = "core",
reason = "this function may be removed in the future due to its \
questionable utility")]
pub unsafe fn copy_mut_lifetime<'a, S: ?Sized, T: ?Sized + 'a>(_ptr: &'a mut S,
ptr: &mut T)
-> &'a mut T {

View File

@ -32,7 +32,7 @@ unsafe impl Zeroable for u64 {}
/// NULL or 0 that might allow certain optimizations.
#[lang="non_zero"]
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Show, Hash)]
#[unstable]
#[unstable(feature = "core")]
pub struct NonZero<T: Zeroable>(T);
impl<T: Zeroable> NonZero<T> {
@ -52,4 +52,4 @@ impl<T: Zeroable> Deref for NonZero<T> {
let NonZero(ref inner) = *self;
inner
}
}
}

View File

@ -14,7 +14,7 @@
// FIXME: MIN_VALUE and MAX_VALUE literals are parsed as -inf and inf #14353
#![allow(overflowing_literals)]
#![stable]
#![stable(feature = "rust1", since = "1.0.0")]
use intrinsics;
use mem;
@ -22,46 +22,47 @@ use num::Float;
use num::FpCategory as Fp;
use option::Option;
#[unstable = "pending integer conventions"]
#[unstable(feature = "core", reason = "pending integer conventions")]
pub const RADIX: uint = 2;
#[unstable = "pending integer conventions"]
#[unstable(feature = "core", reason = "pending integer conventions")]
pub const MANTISSA_DIGITS: uint = 24;
#[unstable = "pending integer conventions"]
#[unstable(feature = "core", reason = "pending integer conventions")]
pub const DIGITS: uint = 6;
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub const EPSILON: f32 = 1.19209290e-07_f32;
/// Smallest finite f32 value
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub const MIN_VALUE: f32 = -3.40282347e+38_f32;
/// Smallest positive, normalized f32 value
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub const MIN_POS_VALUE: f32 = 1.17549435e-38_f32;
/// Largest finite f32 value
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub const MAX_VALUE: f32 = 3.40282347e+38_f32;
#[unstable = "pending integer conventions"]
#[unstable(feature = "core", reason = "pending integer conventions")]
pub const MIN_EXP: int = -125;
#[unstable = "pending integer conventions"]
#[unstable(feature = "core", reason = "pending integer conventions")]
pub const MAX_EXP: int = 128;
#[unstable = "pending integer conventions"]
#[unstable(feature = "core", reason = "pending integer conventions")]
pub const MIN_10_EXP: int = -37;
#[unstable = "pending integer conventions"]
#[unstable(feature = "core", reason = "pending integer conventions")]
pub const MAX_10_EXP: int = 38;
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub const NAN: f32 = 0.0_f32/0.0_f32;
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub const INFINITY: f32 = 1.0_f32/0.0_f32;
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub const NEG_INFINITY: f32 = -1.0_f32/0.0_f32;
/// Various useful constants.
#[unstable = "naming scheme needs to be revisited"]
#[unstable(feature = "core",
reason = "naming scheme needs to be revisited")]
pub mod consts {
// FIXME: replace with mathematical constants from cmath.
@ -117,7 +118,7 @@ pub mod consts {
pub const LN_10: f32 = 2.30258509299404568401799145468436421_f32;
}
#[unstable = "trait is unstable"]
#[unstable(feature = "core", reason = "trait is unstable")]
impl Float for f32 {
#[inline]
fn nan() -> f32 { NAN }
@ -177,43 +178,53 @@ impl Float for f32 {
}
#[inline]
#[deprecated]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0")]
fn mantissa_digits(_: Option<f32>) -> uint { MANTISSA_DIGITS }
#[inline]
#[deprecated]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0")]
fn digits(_: Option<f32>) -> uint { DIGITS }
#[inline]
#[deprecated]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0")]
fn epsilon() -> f32 { EPSILON }
#[inline]
#[deprecated]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0")]
fn min_exp(_: Option<f32>) -> int { MIN_EXP }
#[inline]
#[deprecated]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0")]
fn max_exp(_: Option<f32>) -> int { MAX_EXP }
#[inline]
#[deprecated]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0")]
fn min_10_exp(_: Option<f32>) -> int { MIN_10_EXP }
#[inline]
#[deprecated]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0")]
fn max_10_exp(_: Option<f32>) -> int { MAX_10_EXP }
#[inline]
#[deprecated]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0")]
fn min_value() -> f32 { MIN_VALUE }
#[inline]
#[deprecated]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0")]
fn min_pos_value(_: Option<f32>) -> f32 { MIN_POS_VALUE }
#[inline]
#[deprecated]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0")]
fn max_value() -> f32 { MAX_VALUE }
/// Returns the mantissa, exponent and sign as integers.

View File

@ -14,7 +14,7 @@
// FIXME: MIN_VALUE and MAX_VALUE literals are parsed as -inf and inf #14353
#![allow(overflowing_literals)]
#![stable]
#![stable(feature = "rust1", since = "1.0.0")]
use intrinsics;
use mem;
@ -26,45 +26,46 @@ use option::Option;
// constants are implemented in favour of referencing the respective
// members of `Bounded` and `Float`.
#[unstable = "pending integer conventions"]
#[unstable(feature = "core", reason = "pending integer conventions")]
pub const RADIX: uint = 2;
pub const MANTISSA_DIGITS: uint = 53;
#[unstable = "pending integer conventions"]
#[unstable(feature = "core", reason = "pending integer conventions")]
pub const DIGITS: uint = 15;
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub const EPSILON: f64 = 2.2204460492503131e-16_f64;
/// Smallest finite f64 value
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub const MIN_VALUE: f64 = -1.7976931348623157e+308_f64;
/// Smallest positive, normalized f64 value
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub const MIN_POS_VALUE: f64 = 2.2250738585072014e-308_f64;
/// Largest finite f64 value
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub const MAX_VALUE: f64 = 1.7976931348623157e+308_f64;
#[unstable = "pending integer conventions"]
#[unstable(feature = "core", reason = "pending integer conventions")]
pub const MIN_EXP: int = -1021;
#[unstable = "pending integer conventions"]
#[unstable(feature = "core", reason = "pending integer conventions")]
pub const MAX_EXP: int = 1024;
#[unstable = "pending integer conventions"]
#[unstable(feature = "core", reason = "pending integer conventions")]
pub const MIN_10_EXP: int = -307;
#[unstable = "pending integer conventions"]
#[unstable(feature = "core", reason = "pending integer conventions")]
pub const MAX_10_EXP: int = 308;
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub const NAN: f64 = 0.0_f64/0.0_f64;
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub const INFINITY: f64 = 1.0_f64/0.0_f64;
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub const NEG_INFINITY: f64 = -1.0_f64/0.0_f64;
/// Various useful constants.
#[unstable = "naming scheme needs to be revisited"]
#[unstable(feature = "core",
reason = "naming scheme needs to be revisited")]
pub mod consts {
// FIXME: replace with mathematical constants from cmath.
@ -124,7 +125,7 @@ pub mod consts {
pub const LN_10: f64 = 2.30258509299404568401799145468436421_f64;
}
#[unstable = "trait is unstable"]
#[unstable(feature = "core", reason = "trait is unstable")]
impl Float for f64 {
#[inline]
fn nan() -> f64 { NAN }
@ -184,43 +185,53 @@ impl Float for f64 {
}
#[inline]
#[deprecated]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0")]
fn mantissa_digits(_: Option<f64>) -> uint { MANTISSA_DIGITS }
#[inline]
#[deprecated]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0")]
fn digits(_: Option<f64>) -> uint { DIGITS }
#[inline]
#[deprecated]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0")]
fn epsilon() -> f64 { EPSILON }
#[inline]
#[deprecated]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0")]
fn min_exp(_: Option<f64>) -> int { MIN_EXP }
#[inline]
#[deprecated]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0")]
fn max_exp(_: Option<f64>) -> int { MAX_EXP }
#[inline]
#[deprecated]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0")]
fn min_10_exp(_: Option<f64>) -> int { MIN_10_EXP }
#[inline]
#[deprecated]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0")]
fn max_10_exp(_: Option<f64>) -> int { MAX_10_EXP }
#[inline]
#[deprecated]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0")]
fn min_value() -> f64 { MIN_VALUE }
#[inline]
#[deprecated]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0")]
fn min_pos_value(_: Option<f64>) -> f64 { MIN_POS_VALUE }
#[inline]
#[deprecated]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0")]
fn max_value() -> f64 { MAX_VALUE }
/// Returns the mantissa, exponent and sign as integers.

View File

@ -10,7 +10,7 @@
//! Operations and constants for signed 16-bits integers (`i16` type)
#![stable]
#![stable(feature = "rust1", since = "1.0.0")]
#![doc(primitive = "i16")]
int_module! { i16, 16 }

View File

@ -10,7 +10,7 @@
//! Operations and constants for signed 32-bits integers (`i32` type)
#![stable]
#![stable(feature = "rust1", since = "1.0.0")]
#![doc(primitive = "i32")]
int_module! { i32, 32 }

View File

@ -10,7 +10,7 @@
//! Operations and constants for signed 64-bits integers (`i64` type)
#![stable]
#![stable(feature = "rust1", since = "1.0.0")]
#![doc(primitive = "i64")]
int_module! { i64, 64 }

View File

@ -10,7 +10,7 @@
//! Operations and constants for signed 8-bits integers (`i8` type)
#![stable]
#![stable(feature = "rust1", since = "1.0.0")]
#![doc(primitive = "i8")]
int_module! { i8, 8 }

View File

@ -14,7 +14,8 @@
//! alpha cycle along with the development of clearer conventions
//! around integer types.
#![deprecated = "replaced by isize"]
#![unstable(feature = "core")]
#![deprecated(since = "1.0.0", reason = "replaced by isize")]
#[cfg(target_pointer_width = "32")] int_module! { int, 32 }
#[cfg(target_pointer_width = "64")] int_module! { int, 64 }

View File

@ -14,21 +14,21 @@ macro_rules! int_module { ($T:ty, $bits:expr) => (
// FIXME(#11621): Should be deprecated once CTFE is implemented in favour of
// calling the `mem::size_of` function.
#[unstable]
#[unstable(feature = "core")]
pub const BITS : uint = $bits;
// FIXME(#11621): Should be deprecated once CTFE is implemented in favour of
// calling the `mem::size_of` function.
#[unstable]
#[unstable(feature = "core")]
pub const BYTES : uint = ($bits / 8);
// FIXME(#11621): Should be deprecated once CTFE is implemented in favour of
// calling the `Bounded::min_value` function.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub const MIN: $T = (-1 as $T) << (BITS - 1);
// FIXME(#9837): Compute MIN like this so the high bits that shouldn't exist are 0.
// FIXME(#11621): Should be deprecated once CTFE is implemented in favour of
// calling the `Bounded::max_value` function.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub const MAX: $T = !MIN;
) }

View File

@ -14,7 +14,7 @@
//! new type will gradually take place over the alpha cycle along with
//! the development of clearer conventions around integer types.
#![stable]
#![stable(feature = "rust1", since = "1.0.0")]
#![doc(primitive = "isize")]
#[cfg(target_pointer_width = "32")]

View File

@ -12,7 +12,7 @@
//! Numeric traits and functions for the built-in numeric types.
#![stable]
#![stable(feature = "rust1", since = "1.0.0")]
#![allow(missing_docs)]
use char::CharExt;
@ -30,7 +30,7 @@ use option::Option::{Some, None};
use str::{FromStr, StrExt};
/// A built-in signed or unsigned integer.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Int
: Copy + Clone
+ NumCast
@ -50,22 +50,26 @@ pub trait Int
{
/// Returns the `0` value of this integer type.
// FIXME (#5527): Should be an associated constant
#[unstable = "unsure about its place in the world"]
#[unstable(feature = "core",
reason = "unsure about its place in the world")]
fn zero() -> Self;
/// Returns the `1` value of this integer type.
// FIXME (#5527): Should be an associated constant
#[unstable = "unsure about its place in the world"]
#[unstable(feature = "core",
reason = "unsure about its place in the world")]
fn one() -> Self;
/// Returns the smallest value that can be represented by this integer type.
// FIXME (#5527): Should be and associated constant
#[unstable = "unsure about its place in the world"]
#[unstable(feature = "core",
reason = "unsure about its place in the world")]
fn min_value() -> Self;
/// Returns the largest value that can be represented by this integer type.
// FIXME (#5527): Should be and associated constant
#[unstable = "unsure about its place in the world"]
#[unstable(feature = "core",
reason = "unsure about its place in the world")]
fn max_value() -> Self;
/// Returns the number of ones in the binary representation of `self`.
@ -79,7 +83,8 @@ pub trait Int
///
/// assert_eq!(n.count_ones(), 3);
/// ```
#[unstable = "pending integer conventions"]
#[unstable(feature = "core",
reason = "pending integer conventions")]
fn count_ones(self) -> uint;
/// Returns the number of zeros in the binary representation of `self`.
@ -93,7 +98,8 @@ pub trait Int
///
/// assert_eq!(n.count_zeros(), 5);
/// ```
#[unstable = "pending integer conventions"]
#[unstable(feature = "core",
reason = "pending integer conventions")]
#[inline]
fn count_zeros(self) -> uint {
(!self).count_ones()
@ -111,7 +117,8 @@ pub trait Int
///
/// assert_eq!(n.leading_zeros(), 10);
/// ```
#[unstable = "pending integer conventions"]
#[unstable(feature = "core",
reason = "pending integer conventions")]
fn leading_zeros(self) -> uint;
/// Returns the number of trailing zeros in the binary representation
@ -126,7 +133,8 @@ pub trait Int
///
/// assert_eq!(n.trailing_zeros(), 3);
/// ```
#[unstable = "pending integer conventions"]
#[unstable(feature = "core",
reason = "pending integer conventions")]
fn trailing_zeros(self) -> uint;
/// Shifts the bits to the left by a specified amount amount, `n`, wrapping
@ -142,7 +150,8 @@ pub trait Int
///
/// assert_eq!(n.rotate_left(12), m);
/// ```
#[unstable = "pending integer conventions"]
#[unstable(feature = "core",
reason = "pending integer conventions")]
fn rotate_left(self, n: uint) -> Self;
/// Shifts the bits to the right by a specified amount amount, `n`, wrapping
@ -158,7 +167,8 @@ pub trait Int
///
/// assert_eq!(n.rotate_right(12), m);
/// ```
#[unstable = "pending integer conventions"]
#[unstable(feature = "core",
reason = "pending integer conventions")]
fn rotate_right(self, n: uint) -> Self;
/// Reverses the byte order of the integer.
@ -173,7 +183,7 @@ pub trait Int
///
/// assert_eq!(n.swap_bytes(), m);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn swap_bytes(self) -> Self;
/// Convert an integer from big endian to the target's endianness.
@ -193,7 +203,7 @@ pub trait Int
/// assert_eq!(Int::from_be(n), n.swap_bytes())
/// }
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
fn from_be(x: Self) -> Self {
if cfg!(target_endian = "big") { x } else { x.swap_bytes() }
@ -216,7 +226,7 @@ pub trait Int
/// assert_eq!(Int::from_le(n), n.swap_bytes())
/// }
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
fn from_le(x: Self) -> Self {
if cfg!(target_endian = "little") { x } else { x.swap_bytes() }
@ -239,7 +249,7 @@ pub trait Int
/// assert_eq!(n.to_be(), n.swap_bytes())
/// }
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
fn to_be(self) -> Self { // or not to be?
if cfg!(target_endian = "big") { self } else { self.swap_bytes() }
@ -262,7 +272,7 @@ pub trait Int
/// assert_eq!(n.to_le(), n.swap_bytes())
/// }
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
fn to_le(self) -> Self {
if cfg!(target_endian = "little") { self } else { self.swap_bytes() }
@ -279,7 +289,7 @@ pub trait Int
/// assert_eq!(5u16.checked_add(65530), Some(65535));
/// assert_eq!(6u16.checked_add(65530), None);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn checked_add(self, other: Self) -> Option<Self>;
/// Checked integer subtraction. Computes `self - other`, returning `None`
@ -293,7 +303,7 @@ pub trait Int
/// assert_eq!((-127i8).checked_sub(1), Some(-128));
/// assert_eq!((-128i8).checked_sub(1), None);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn checked_sub(self, other: Self) -> Option<Self>;
/// Checked integer multiplication. Computes `self * other`, returning
@ -307,7 +317,7 @@ pub trait Int
/// assert_eq!(5u8.checked_mul(51), Some(255));
/// assert_eq!(5u8.checked_mul(52), None);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn checked_mul(self, other: Self) -> Option<Self>;
/// Checked integer division. Computes `self / other`, returning `None` if
@ -322,12 +332,12 @@ pub trait Int
/// assert_eq!((-128i8).checked_div(-1), None);
/// assert_eq!((1i8).checked_div(0), None);
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn checked_div(self, other: Self) -> Option<Self>;
/// Saturating integer addition. Computes `self + other`, saturating at
/// the numeric bounds instead of overflowing.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
fn saturating_add(self, other: Self) -> Self {
match self.checked_add(other) {
@ -339,7 +349,7 @@ pub trait Int
/// Saturating integer subtraction. Computes `self - other`, saturating at
/// the numeric bounds instead of overflowing.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
fn saturating_sub(self, other: Self) -> Self {
match self.checked_sub(other) {
@ -358,7 +368,8 @@ pub trait Int
///
/// assert_eq!(2.pow(4), 16);
/// ```
#[unstable = "pending integer conventions"]
#[unstable(feature = "core",
reason = "pending integer conventions")]
#[inline]
fn pow(self, mut exp: uint) -> Self {
let mut base = self;
@ -390,7 +401,7 @@ macro_rules! uint_impl {
$add_with_overflow:path,
$sub_with_overflow:path,
$mul_with_overflow:path) => {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Int for $T {
#[inline]
fn zero() -> $T { 0 }
@ -521,7 +532,7 @@ macro_rules! int_impl {
$add_with_overflow:path,
$sub_with_overflow:path,
$mul_with_overflow:path) => {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Int for $T {
#[inline]
fn zero() -> $T { 0 }
@ -614,14 +625,14 @@ int_impl! { int = i64, u64, 64,
intrinsics::i64_mul_with_overflow }
/// A built-in two's complement integer.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait SignedInt
: Int
+ Neg<Output=Self>
{
/// Computes the absolute value of `self`. `Int::min_value()` will be
/// returned if the number is `Int::min_value()`.
#[unstable = "overflow in debug builds?"]
#[unstable(feature = "core", reason = "overflow in debug builds?")]
fn abs(self) -> Self;
/// Returns a number representing sign of `self`.
@ -629,23 +640,23 @@ pub trait SignedInt
/// - `0` if the number is zero
/// - `1` if the number is positive
/// - `-1` if the number is negative
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn signum(self) -> Self;
/// Returns `true` if `self` is positive and `false` if the number
/// is zero or negative.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn is_positive(self) -> bool;
/// Returns `true` if `self` is negative and `false` if the number
/// is zero or positive.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn is_negative(self) -> bool;
}
macro_rules! signed_int_impl {
($T:ty) => {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl SignedInt for $T {
#[inline]
fn abs(self) -> $T {
@ -677,10 +688,10 @@ signed_int_impl! { i64 }
signed_int_impl! { int }
/// A built-in unsigned integer.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait UnsignedInt: Int {
/// Returns `true` iff `self == 2^k` for some `k`.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
fn is_power_of_two(self) -> bool {
(self - Int::one()) & self == Int::zero() && !(self == Int::zero())
@ -688,7 +699,7 @@ pub trait UnsignedInt: Int {
/// Returns the smallest power of two greater than or equal to `self`.
/// Unspecified behavior on overflow.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
fn next_power_of_two(self) -> Self {
let bits = size_of::<Self>() * 8;
@ -699,7 +710,7 @@ pub trait UnsignedInt: Int {
/// Returns the smallest power of two greater than or equal to `n`. If the
/// next power of two is greater than the type's maximum value, `None` is
/// returned, otherwise the power of two is wrapped in `Some`.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn checked_next_power_of_two(self) -> Option<Self> {
let npot = self.next_power_of_two();
if npot >= self {
@ -710,23 +721,23 @@ pub trait UnsignedInt: Int {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl UnsignedInt for uint {}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl UnsignedInt for u8 {}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl UnsignedInt for u16 {}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl UnsignedInt for u32 {}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl UnsignedInt for u64 {}
/// A generic trait for converting a value to a number.
#[unstable = "trait is likely to be removed"]
#[unstable(feature = "core", reason = "trait is likely to be removed")]
pub trait ToPrimitive {
/// Converts the value of `self` to an `int`.
#[inline]
@ -991,7 +1002,7 @@ impl_to_primitive_float! { f32 }
impl_to_primitive_float! { f64 }
/// A generic trait for converting a number to a value.
#[unstable = "trait is likely to be removed"]
#[unstable(feature = "core", reason = "trait is likely to be removed")]
pub trait FromPrimitive : ::marker::Sized {
/// Convert an `int` to return an optional value of this type. If the
/// value cannot be represented by this value, the `None` is returned.
@ -1073,73 +1084,73 @@ pub trait FromPrimitive : ::marker::Sized {
}
/// A utility function that just calls `FromPrimitive::from_int`.
#[unstable = "likely to be removed"]
#[unstable(feature = "core", reason = "likely to be removed")]
pub fn from_int<A: FromPrimitive>(n: int) -> Option<A> {
FromPrimitive::from_int(n)
}
/// A utility function that just calls `FromPrimitive::from_i8`.
#[unstable = "likely to be removed"]
#[unstable(feature = "core", reason = "likely to be removed")]
pub fn from_i8<A: FromPrimitive>(n: i8) -> Option<A> {
FromPrimitive::from_i8(n)
}
/// A utility function that just calls `FromPrimitive::from_i16`.
#[unstable = "likely to be removed"]
#[unstable(feature = "core", reason = "likely to be removed")]
pub fn from_i16<A: FromPrimitive>(n: i16) -> Option<A> {
FromPrimitive::from_i16(n)
}
/// A utility function that just calls `FromPrimitive::from_i32`.
#[unstable = "likely to be removed"]
#[unstable(feature = "core", reason = "likely to be removed")]
pub fn from_i32<A: FromPrimitive>(n: i32) -> Option<A> {
FromPrimitive::from_i32(n)
}
/// A utility function that just calls `FromPrimitive::from_i64`.
#[unstable = "likely to be removed"]
#[unstable(feature = "core", reason = "likely to be removed")]
pub fn from_i64<A: FromPrimitive>(n: i64) -> Option<A> {
FromPrimitive::from_i64(n)
}
/// A utility function that just calls `FromPrimitive::from_uint`.
#[unstable = "likely to be removed"]
#[unstable(feature = "core", reason = "likely to be removed")]
pub fn from_uint<A: FromPrimitive>(n: uint) -> Option<A> {
FromPrimitive::from_uint(n)
}
/// A utility function that just calls `FromPrimitive::from_u8`.
#[unstable = "likely to be removed"]
#[unstable(feature = "core", reason = "likely to be removed")]
pub fn from_u8<A: FromPrimitive>(n: u8) -> Option<A> {
FromPrimitive::from_u8(n)
}
/// A utility function that just calls `FromPrimitive::from_u16`.
#[unstable = "likely to be removed"]
#[unstable(feature = "core", reason = "likely to be removed")]
pub fn from_u16<A: FromPrimitive>(n: u16) -> Option<A> {
FromPrimitive::from_u16(n)
}
/// A utility function that just calls `FromPrimitive::from_u32`.
#[unstable = "likely to be removed"]
#[unstable(feature = "core", reason = "likely to be removed")]
pub fn from_u32<A: FromPrimitive>(n: u32) -> Option<A> {
FromPrimitive::from_u32(n)
}
/// A utility function that just calls `FromPrimitive::from_u64`.
#[unstable = "likely to be removed"]
#[unstable(feature = "core", reason = "likely to be removed")]
pub fn from_u64<A: FromPrimitive>(n: u64) -> Option<A> {
FromPrimitive::from_u64(n)
}
/// A utility function that just calls `FromPrimitive::from_f32`.
#[unstable = "likely to be removed"]
#[unstable(feature = "core", reason = "likely to be removed")]
pub fn from_f32<A: FromPrimitive>(n: f32) -> Option<A> {
FromPrimitive::from_f32(n)
}
/// A utility function that just calls `FromPrimitive::from_f64`.
#[unstable = "likely to be removed"]
#[unstable(feature = "core", reason = "likely to be removed")]
pub fn from_f64<A: FromPrimitive>(n: f64) -> Option<A> {
FromPrimitive::from_f64(n)
}
@ -1190,13 +1201,13 @@ impl_from_primitive! { f64, to_f64 }
/// ```
///
#[inline]
#[unstable = "likely to be removed"]
#[unstable(feature = "core", reason = "likely to be removed")]
pub fn cast<T: NumCast,U: NumCast>(n: T) -> Option<U> {
NumCast::from(n)
}
/// An interface for casting between machine scalars.
#[unstable = "trait is likely to be removed"]
#[unstable(feature = "core", reason = "trait is likely to be removed")]
pub trait NumCast: ToPrimitive {
/// Creates a number from another value that can be converted into a primitive via the
/// `ToPrimitive` trait.
@ -1231,7 +1242,7 @@ impl_num_cast! { f64, to_f64 }
/// Used for representing the classification of floating point numbers
#[derive(Copy, PartialEq, Show)]
#[unstable = "may be renamed"]
#[unstable(feature = "core", reason = "may be renamed")]
pub enum FpCategory {
/// "Not a Number", often obtained by dividing by zero
Nan,
@ -1251,7 +1262,8 @@ pub enum FpCategory {
//
// FIXME(#8888): Several of these functions have a parameter named
// `unused_self`. Removing it requires #8888 to be fixed.
#[unstable = "distribution of methods between core/std is unclear"]
#[unstable(feature = "core",
reason = "distribution of methods between core/std is unclear")]
pub trait Float
: Copy + Clone
+ NumCast
@ -1280,34 +1292,56 @@ pub trait Float
// FIXME (#5527): These should be associated constants
/// Returns the number of binary digits of mantissa that this type supports.
#[deprecated = "use `std::f32::MANTISSA_DIGITS` or `std::f64::MANTISSA_DIGITS` as appropriate"]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0",
reason = "use `std::f32::MANTISSA_DIGITS` or \
`std::f64::MANTISSA_DIGITS` as appropriate")]
fn mantissa_digits(unused_self: Option<Self>) -> uint;
/// Returns the number of base-10 digits of precision that this type supports.
#[deprecated = "use `std::f32::DIGITS` or `std::f64::DIGITS` as appropriate"]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0",
reason = "use `std::f32::DIGITS` or `std::f64::DIGITS` as appropriate")]
fn digits(unused_self: Option<Self>) -> uint;
/// Returns the difference between 1.0 and the smallest representable number larger than 1.0.
#[deprecated = "use `std::f32::EPSILON` or `std::f64::EPSILON` as appropriate"]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0",
reason = "use `std::f32::EPSILON` or `std::f64::EPSILON` as appropriate")]
fn epsilon() -> Self;
/// Returns the minimum binary exponent that this type can represent.
#[deprecated = "use `std::f32::MIN_EXP` or `std::f64::MIN_EXP` as appropriate"]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0",
reason = "use `std::f32::MIN_EXP` or `std::f64::MIN_EXP` as appropriate")]
fn min_exp(unused_self: Option<Self>) -> int;
/// Returns the maximum binary exponent that this type can represent.
#[deprecated = "use `std::f32::MAX_EXP` or `std::f64::MAX_EXP` as appropriate"]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0",
reason = "use `std::f32::MAX_EXP` or `std::f64::MAX_EXP` as appropriate")]
fn max_exp(unused_self: Option<Self>) -> int;
/// Returns the minimum base-10 exponent that this type can represent.
#[deprecated = "use `std::f32::MIN_10_EXP` or `std::f64::MIN_10_EXP` as appropriate"]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0",
reason = "use `std::f32::MIN_10_EXP` or `std::f64::MIN_10_EXP` as appropriate")]
fn min_10_exp(unused_self: Option<Self>) -> int;
/// Returns the maximum base-10 exponent that this type can represent.
#[deprecated = "use `std::f32::MAX_10_EXP` or `std::f64::MAX_10_EXP` as appropriate"]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0",
reason = "use `std::f32::MAX_10_EXP` or `std::f64::MAX_10_EXP` as appropriate")]
fn max_10_exp(unused_self: Option<Self>) -> int;
/// Returns the smallest finite value that this type can represent.
#[deprecated = "use `std::f32::MIN_VALUE` or `std::f64::MIN_VALUE` as appropriate"]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0",
reason = "use `std::f32::MIN_VALUE` or `std::f64::MIN_VALUE` as appropriate")]
fn min_value() -> Self;
/// Returns the smallest normalized positive number that this type can represent.
#[deprecated = "use `std::f32::MIN_POS_VALUE` or `std::f64::MIN_POS_VALUE` as appropriate"]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0",
reason = "use `std::f32::MIN_POS_VALUE` or \
`std::f64::MIN_POS_VALUE` as appropriate")]
fn min_pos_value(unused_self: Option<Self>) -> Self;
/// Returns the largest finite value that this type can represent.
#[deprecated = "use `std::f32::MAX_VALUE` or `std::f64::MAX_VALUE` as appropriate"]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0",
reason = "use `std::f32::MAX_VALUE` or `std::f64::MAX_VALUE` as appropriate")]
fn max_value() -> Self;
/// Returns true if this value is NaN and false otherwise.
@ -1394,20 +1428,21 @@ pub trait Float
}
/// A generic trait for converting a string with a radix (base) to a value
#[unstable = "might need to return Result"]
#[unstable(feature = "core", reason = "might need to return Result")]
pub trait FromStrRadix {
fn from_str_radix(str: &str, radix: uint) -> Option<Self>;
}
/// A utility function that just calls FromStrRadix::from_str_radix.
#[unstable = "might need to return Result"]
#[unstable(feature = "core", reason = "might need to return Result")]
pub fn from_str_radix<T: FromStrRadix>(str: &str, radix: uint) -> Option<T> {
FromStrRadix::from_str_radix(str, radix)
}
macro_rules! from_str_radix_float_impl {
($T:ty) => {
#[unstable = "might need to return Result"]
#[unstable(feature = "core",
reason = "might need to return Result")]
impl FromStr for $T {
/// Convert a string in base 10 to a float.
/// Accepts an optional decimal exponent.
@ -1440,7 +1475,8 @@ macro_rules! from_str_radix_float_impl {
}
}
#[unstable = "might need to return Result"]
#[unstable(feature = "core",
reason = "might need to return Result")]
impl FromStrRadix for $T {
/// Convert a string in a given base to a float.
///
@ -1604,7 +1640,8 @@ from_str_radix_float_impl! { f64 }
macro_rules! from_str_radix_int_impl {
($T:ty) => {
#[unstable = "might need to return Result"]
#[unstable(feature = "core",
reason = "might need to return Result")]
impl FromStr for $T {
#[inline]
fn from_str(src: &str) -> Option<$T> {
@ -1612,7 +1649,8 @@ macro_rules! from_str_radix_int_impl {
}
}
#[unstable = "might need to return Result"]
#[unstable(feature = "core",
reason = "might need to return Result")]
impl FromStrRadix for $T {
fn from_str_radix(src: &str, radix: uint) -> Option<$T> {
assert!(radix >= 2 && radix <= 36,

View File

@ -10,7 +10,7 @@
//! Operations and constants for unsigned 16-bits integers (`u16` type)
#![stable]
#![stable(feature = "rust1", since = "1.0.0")]
#![doc(primitive = "u16")]
uint_module! { u16, i16, 16 }

View File

@ -10,7 +10,7 @@
//! Operations and constants for unsigned 32-bits integers (`u32` type)
#![stable]
#![stable(feature = "rust1", since = "1.0.0")]
#![doc(primitive = "u32")]
uint_module! { u32, i32, 32 }

View File

@ -10,7 +10,7 @@
//! Operations and constants for unsigned 64-bits integer (`u64` type)
#![stable]
#![stable(feature = "rust1", since = "1.0.0")]
#![doc(primitive = "u64")]
uint_module! { u64, i64, 64 }

View File

@ -10,7 +10,7 @@
//! Operations and constants for unsigned 8-bits integers (`u8` type)
#![stable]
#![stable(feature = "rust1", since = "1.0.0")]
#![doc(primitive = "u8")]
uint_module! { u8, i8, 8 }

View File

@ -14,6 +14,7 @@
//! alpha cycle along with the development of clearer conventions
//! around integer types.
#![deprecated = "replaced by usize"]
#![unstable(feature = "core")]
#![deprecated(since = "1.0.0", reason = "replaced by usize")]
uint_module! { uint, int, ::int::BITS }

View File

@ -12,14 +12,14 @@
macro_rules! uint_module { ($T:ty, $T_SIGNED:ty, $bits:expr) => (
#[unstable]
#[unstable(feature = "core")]
pub const BITS : uint = $bits;
#[unstable]
#[unstable(feature = "core")]
pub const BYTES : uint = ($bits / 8);
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub const MIN: $T = 0 as $T;
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub const MAX: $T = 0 as $T - 1 as $T;
) }

View File

@ -14,7 +14,7 @@
//! new type will gradually take place over the alpha cycle along with
//! the development of clearer conventions around integer types.
#![stable]
#![stable(feature = "rust1", since = "1.0.0")]
#![doc(primitive = "usize")]
uint_module! { usize, isize, ::isize::BITS }

View File

@ -65,7 +65,7 @@
//! See the documentation for each trait for a minimum implementation that prints
//! something to the screen.
#![stable]
#![stable(feature = "rust1", since = "1.0.0")]
use marker::Sized;
use fmt;
@ -92,10 +92,10 @@ use fmt;
/// }
/// ```
#[lang="drop"]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Drop {
/// The `drop` method, called when the value goes out of scope.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn drop(&mut self);
}
@ -103,7 +103,8 @@ pub trait Drop {
// based on "op T" where T is expected to be `Copy`able
macro_rules! forward_ref_unop {
(impl $imp:ident, $method:ident for $t:ty) => {
#[unstable = "recently added, waiting for dust to settle"]
#[unstable(feature = "core",
reason = "recently added, waiting for dust to settle")]
impl<'a> $imp for &'a $t {
type Output = <$t as $imp>::Output;
@ -119,7 +120,8 @@ macro_rules! forward_ref_unop {
// based on "T op U" where T and U are expected to be `Copy`able
macro_rules! forward_ref_binop {
(impl $imp:ident, $method:ident for $t:ty, $u:ty) => {
#[unstable = "recently added, waiting for dust to settle"]
#[unstable(feature = "core",
reason = "recently added, waiting for dust to settle")]
impl<'a> $imp<$u> for &'a $t {
type Output = <$t as $imp<$u>>::Output;
@ -129,7 +131,8 @@ macro_rules! forward_ref_binop {
}
}
#[unstable = "recently added, waiting for dust to settle"]
#[unstable(feature = "core",
reason = "recently added, waiting for dust to settle")]
impl<'a> $imp<&'a $u> for $t {
type Output = <$t as $imp<$u>>::Output;
@ -139,7 +142,8 @@ macro_rules! forward_ref_binop {
}
}
#[unstable = "recently added, waiting for dust to settle"]
#[unstable(feature = "core",
reason = "recently added, waiting for dust to settle")]
impl<'a, 'b> $imp<&'a $u> for &'b $t {
type Output = <$t as $imp<$u>>::Output;
@ -178,19 +182,19 @@ macro_rules! forward_ref_binop {
/// }
/// ```
#[lang="add"]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Add<RHS=Self> {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
type Output;
/// The method for the `+` operator
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn add(self, rhs: RHS) -> Self::Output;
}
macro_rules! add_impl {
($($t:ty)*) => ($(
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Add for $t {
type Output = $t;
@ -231,19 +235,19 @@ add_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 }
/// }
/// ```
#[lang="sub"]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Sub<RHS=Self> {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
type Output;
/// The method for the `-` operator
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn sub(self, rhs: RHS) -> Self::Output;
}
macro_rules! sub_impl {
($($t:ty)*) => ($(
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Sub for $t {
type Output = $t;
@ -284,19 +288,19 @@ sub_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 }
/// }
/// ```
#[lang="mul"]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Mul<RHS=Self> {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
type Output;
/// The method for the `*` operator
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn mul(self, rhs: RHS) -> Self::Output;
}
macro_rules! mul_impl {
($($t:ty)*) => ($(
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Mul for $t {
type Output = $t;
@ -337,19 +341,19 @@ mul_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 }
/// }
/// ```
#[lang="div"]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Div<RHS=Self> {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
type Output;
/// The method for the `/` operator
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn div(self, rhs: RHS) -> Self::Output;
}
macro_rules! div_impl {
($($t:ty)*) => ($(
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Div for $t {
type Output = $t;
@ -390,19 +394,19 @@ div_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 }
/// }
/// ```
#[lang="rem"]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Rem<RHS=Self> {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
type Output = Self;
/// The method for the `%` operator
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn rem(self, rhs: RHS) -> Self::Output;
}
macro_rules! rem_impl {
($($t:ty)*) => ($(
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Rem for $t {
type Output = $t;
@ -416,7 +420,7 @@ macro_rules! rem_impl {
macro_rules! rem_float_impl {
($t:ty, $fmod:ident) => {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Rem for $t {
type Output = $t;
@ -462,25 +466,25 @@ rem_float_impl! { f64, fmod }
/// }
/// ```
#[lang="neg"]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Neg {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
type Output;
/// The method for the unary `-` operator
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn neg(self) -> Self::Output;
}
macro_rules! neg_impl {
($($t:ty)*) => ($(
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Neg for $t {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
type Output = $t;
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn neg(self) -> $t { -self }
}
@ -490,7 +494,7 @@ macro_rules! neg_impl {
macro_rules! neg_uint_impl {
($t:ty, $t_signed:ty) => {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Neg for $t {
type Output = $t;
@ -538,19 +542,19 @@ neg_uint_impl! { u64, i64 }
/// }
/// ```
#[lang="not"]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Not {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
type Output;
/// The method for the unary `!` operator
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn not(self) -> Self::Output;
}
macro_rules! not_impl {
($($t:ty)*) => ($(
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Not for $t {
type Output = $t;
@ -591,19 +595,19 @@ not_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 }
/// }
/// ```
#[lang="bitand"]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait BitAnd<RHS=Self> {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
type Output;
/// The method for the `&` operator
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn bitand(self, rhs: RHS) -> Self::Output;
}
macro_rules! bitand_impl {
($($t:ty)*) => ($(
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl BitAnd for $t {
type Output = $t;
@ -644,19 +648,19 @@ bitand_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 }
/// }
/// ```
#[lang="bitor"]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait BitOr<RHS=Self> {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
type Output;
/// The method for the `|` operator
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn bitor(self, rhs: RHS) -> Self::Output;
}
macro_rules! bitor_impl {
($($t:ty)*) => ($(
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl BitOr for $t {
type Output = $t;
@ -697,19 +701,19 @@ bitor_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 }
/// }
/// ```
#[lang="bitxor"]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait BitXor<RHS=Self> {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
type Output;
/// The method for the `^` operator
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn bitxor(self, rhs: RHS) -> Self::Output;
}
macro_rules! bitxor_impl {
($($t:ty)*) => ($(
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl BitXor for $t {
type Output = $t;
@ -750,19 +754,19 @@ bitxor_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 }
/// }
/// ```
#[lang="shl"]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Shl<RHS> {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
type Output;
/// The method for the `<<` operator
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn shl(self, rhs: RHS) -> Self::Output;
}
macro_rules! shl_impl {
($t:ty, $f:ty) => (
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Shl<$f> for $t {
type Output = $t;
@ -821,13 +825,13 @@ shl_impl_all! { u8 u16 u32 u64 usize i8 i16 i32 i64 isize }
/// }
/// ```
#[lang="shr"]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Shr<RHS> {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
type Output;
/// The method for the `>>` operator
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn shr(self, rhs: RHS) -> Self::Output;
}
@ -894,12 +898,12 @@ shr_impl_all! { u8 u16 u32 u64 usize i8 i16 i32 i64 isize }
/// ```
#[lang="index"]
#[rustc_on_unimplemented = "the type `{Self}` cannot be indexed by `{Index}`"]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Index<Index: ?Sized> {
type Output: ?Sized;
/// The method for the indexing (`Foo[Bar]`) operation
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn index<'a>(&'a self, index: &Index) -> &'a Self::Output;
}
@ -933,22 +937,22 @@ pub trait Index<Index: ?Sized> {
/// ```
#[lang="index_mut"]
#[rustc_on_unimplemented = "the type `{Self}` cannot be mutably indexed by `{Index}`"]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait IndexMut<Index: ?Sized> {
type Output: ?Sized;
/// The method for the indexing (`Foo[Bar]`) operation
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn index_mut<'a>(&'a mut self, index: &Index) -> &'a mut Self::Output;
}
/// An unbounded range.
#[derive(Copy, Clone, PartialEq, Eq)]
#[lang="full_range"]
#[unstable = "may be renamed to RangeFull"]
#[unstable(feature = "core", reason = "may be renamed to RangeFull")]
pub struct FullRange;
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl fmt::Debug for FullRange {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt::Debug::fmt("..", fmt)
@ -958,7 +962,7 @@ impl fmt::Debug for FullRange {
/// A (half-open) range which is bounded at both ends.
#[derive(Copy, Clone, PartialEq, Eq)]
#[lang="range"]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Range<Idx> {
/// The lower bound of the range (inclusive).
pub start: Idx,
@ -966,7 +970,7 @@ pub struct Range<Idx> {
pub end: Idx,
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<Idx: fmt::Debug> fmt::Debug for Range<Idx> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "{:?}..{:?}", self.start, self.end)
@ -976,7 +980,7 @@ impl<Idx: fmt::Debug> fmt::Debug for Range<Idx> {
/// A range which is only bounded below.
#[derive(Copy, Clone, PartialEq, Eq)]
#[lang="range_from"]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct RangeFrom<Idx> {
/// The lower bound of the range (inclusive).
pub start: Idx,
@ -984,7 +988,7 @@ pub struct RangeFrom<Idx> {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<Idx: fmt::Debug> fmt::Debug for RangeFrom<Idx> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "{:?}..", self.start)
@ -994,13 +998,13 @@ impl<Idx: fmt::Debug> fmt::Debug for RangeFrom<Idx> {
/// A range which is only bounded above.
#[derive(Copy, Clone, PartialEq, Eq)]
#[lang="range_to"]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct RangeTo<Idx> {
/// The upper bound of the range (exclusive).
pub end: Idx,
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<Idx: fmt::Debug> fmt::Debug for RangeTo<Idx> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "..{:?}", self.end)
@ -1037,24 +1041,24 @@ impl<Idx: fmt::Debug> fmt::Debug for RangeTo<Idx> {
/// }
/// ```
#[lang="deref"]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Deref {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
type Target: ?Sized;
/// The method called to dereference a value
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn deref<'a>(&'a self) -> &'a Self::Target;
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: ?Sized> Deref for &'a T {
type Target = T;
fn deref(&self) -> &T { *self }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: ?Sized> Deref for &'a mut T {
type Target = T;
@ -1097,42 +1101,49 @@ impl<'a, T: ?Sized> Deref for &'a mut T {
/// }
/// ```
#[lang="deref_mut"]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait DerefMut: Deref {
/// The method called to mutably dereference a value
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn deref_mut<'a>(&'a mut self) -> &'a mut Self::Target;
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: ?Sized> DerefMut for &'a mut T {
fn deref_mut(&mut self) -> &mut T { *self }
}
/// A version of the call operator that takes an immutable receiver.
#[lang="fn"]
#[unstable = "uncertain about variadic generics, input versus associated types"]
pub trait Fn<Args,Result> {
#[unstable(feature = "core",
reason = "uncertain about variadic generics, input versus associated types")]
#[cfg(stage0)]
pub trait Fn<Args,Output> {
/// This is called when the call operator is used.
extern "rust-call" fn call(&self, args: Args) -> Result;
extern "rust-call" fn call(&self, args: Args) -> Output;
}
/// A version of the call operator that takes a mutable receiver.
#[lang="fn_mut"]
#[unstable = "uncertain about variadic generics, input versus associated types"]
pub trait FnMut<Args,Result> {
#[unstable(feature = "core",
reason = "uncertain about variadic generics, input versus associated types")]
#[cfg(stage0)]
pub trait FnMut<Args,Output> {
/// This is called when the call operator is used.
extern "rust-call" fn call_mut(&mut self, args: Args) -> Result;
extern "rust-call" fn call_mut(&mut self, args: Args) -> Output;
}
/// A version of the call operator that takes a by-value receiver.
#[lang="fn_once"]
#[unstable = "uncertain about variadic generics, input versus associated types"]
pub trait FnOnce<Args,Result> {
#[unstable(feature = "core",
reason = "uncertain about variadic generics, input versus associated types")]
#[cfg(stage0)]
pub trait FnOnce<Args,Output> {
/// This is called when the call operator is used.
extern "rust-call" fn call_once(self, args: Args) -> Result;
extern "rust-call" fn call_once(self, args: Args) -> Output;
}
#[cfg(stage0)]
impl<F: ?Sized, A, R> FnMut<A, R> for F
where F : Fn<A, R>
{
@ -1141,6 +1152,7 @@ impl<F: ?Sized, A, R> FnMut<A, R> for F
}
}
#[cfg(stage0)]
impl<F,A,R> FnOnce<A,R> for F
where F : FnMut<A,R>
{
@ -1148,3 +1160,61 @@ impl<F,A,R> FnOnce<A,R> for F
self.call_mut(args)
}
}
/// A version of the call operator that takes an immutable receiver.
#[lang="fn"]
#[unstable(feature = "core",
reason = "uncertain about variadic generics, input versus associated types")]
#[cfg(not(stage0))]
pub trait Fn<Args> {
type Output;
/// This is called when the call operator is used.
extern "rust-call" fn call(&self, args: Args) -> Self::Output;
}
/// A version of the call operator that takes a mutable receiver.
#[lang="fn_mut"]
#[unstable(feature = "core",
reason = "uncertain about variadic generics, input versus associated types")]
#[cfg(not(stage0))]
pub trait FnMut<Args> {
type Output;
/// This is called when the call operator is used.
extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output;
}
/// A version of the call operator that takes a by-value receiver.
#[lang="fn_once"]
#[unstable(feature = "core",
reason = "uncertain about variadic generics, input versus associated types")]
#[cfg(not(stage0))]
pub trait FnOnce<Args> {
type Output;
/// This is called when the call operator is used.
extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
}
#[cfg(not(stage0))]
impl<F: ?Sized, A> FnMut<A> for F
where F : Fn<A>
{
type Output = <F as Fn<A>>::Output;
extern "rust-call" fn call_mut(&mut self, args: A) -> <F as Fn<A>>::Output {
self.call(args)
}
}
#[cfg(not(stage0))]
impl<F,A> FnOnce<A> for F
where F : FnMut<A>
{
type Output = <F as FnMut<A>>::Output;
extern "rust-call" fn call_once(mut self, args: A) -> <F as FnMut<A>>::Output {
self.call_mut(args)
}
}

View File

@ -141,7 +141,7 @@
//! }
//! ```
#![stable]
#![stable(feature = "rust1", since = "1.0.0")]
use self::Option::*;
@ -164,13 +164,13 @@ use slice;
/// The `Option` type.
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Show, Hash)]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub enum Option<T> {
/// No value
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
None,
/// Some value `T`
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
Some(T)
}
@ -195,7 +195,7 @@ impl<T> Option<T> {
/// assert_eq!(x.is_some(), false);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_some(&self) -> bool {
match *self {
Some(_) => true,
@ -215,7 +215,7 @@ impl<T> Option<T> {
/// assert_eq!(x.is_none(), true);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_none(&self) -> bool {
!self.is_some()
}
@ -241,7 +241,7 @@ impl<T> Option<T> {
/// println!("still can print num_as_str: {:?}", num_as_str);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn as_ref<'r>(&'r self) -> Option<&'r T> {
match *self {
Some(ref x) => Some(x),
@ -262,7 +262,7 @@ impl<T> Option<T> {
/// assert_eq!(x, Some(42));
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn as_mut<'r>(&'r mut self) -> Option<&'r mut T> {
match *self {
Some(ref mut x) => Some(x),
@ -285,7 +285,8 @@ impl<T> Option<T> {
/// assert_eq!(x, Some("Dirt"));
/// ```
#[inline]
#[unstable = "waiting for mut conventions"]
#[unstable(feature = "core",
reason = "waiting for mut conventions")]
pub fn as_mut_slice<'r>(&'r mut self) -> &'r mut [T] {
match *self {
Some(ref mut x) => {
@ -322,7 +323,7 @@ impl<T> Option<T> {
/// x.expect("the world is ending"); // panics with `world is ending`
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn expect(self, msg: &str) -> T {
match self {
Some(val) => val,
@ -354,7 +355,7 @@ impl<T> Option<T> {
/// assert_eq!(x.unwrap(), "air"); // fails
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn unwrap(self) -> T {
match self {
Some(val) => val,
@ -371,7 +372,7 @@ impl<T> Option<T> {
/// assert_eq!(None.unwrap_or("bike"), "bike");
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn unwrap_or(self, def: T) -> T {
match self {
Some(x) => x,
@ -389,7 +390,7 @@ impl<T> Option<T> {
/// assert_eq!(None.unwrap_or_else(|| 2 * k), 20);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn unwrap_or_else<F: FnOnce() -> T>(self, f: F) -> T {
match self {
Some(x) => x,
@ -413,7 +414,7 @@ impl<T> Option<T> {
/// let num_as_int: Option<uint> = num_as_str.map(|n| n.len());
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Option<U> {
match self {
Some(x) => Some(f(x)),
@ -433,7 +434,7 @@ impl<T> Option<T> {
/// assert_eq!(x.map_or(42, |v| v.len()), 42);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn map_or<U, F: FnOnce(T) -> U>(self, def: U, f: F) -> U {
match self {
Some(t) => f(t),
@ -455,7 +456,7 @@ impl<T> Option<T> {
/// assert_eq!(x.map_or_else(|| 2 * k, |v| v.len()), 42);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn map_or_else<U, D: FnOnce() -> U, F: FnOnce(T) -> U>(self, def: D, f: F) -> U {
match self {
Some(t) => f(t),
@ -476,7 +477,7 @@ impl<T> Option<T> {
/// assert_eq!(x.ok_or(0), Err(0));
/// ```
#[inline]
#[unstable]
#[unstable(feature = "core")]
pub fn ok_or<E>(self, err: E) -> Result<T, E> {
match self {
Some(v) => Ok(v),
@ -497,7 +498,7 @@ impl<T> Option<T> {
/// assert_eq!(x.ok_or_else(|| 0), Err(0));
/// ```
#[inline]
#[unstable]
#[unstable(feature = "core")]
pub fn ok_or_else<E, F: FnOnce() -> E>(self, err: F) -> Result<T, E> {
match self {
Some(v) => Ok(v),
@ -521,7 +522,7 @@ impl<T> Option<T> {
/// assert_eq!(x.iter().next(), None);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn iter(&self) -> Iter<T> {
Iter { inner: Item { opt: self.as_ref() } }
}
@ -542,7 +543,8 @@ impl<T> Option<T> {
/// assert_eq!(x.iter_mut().next(), None);
/// ```
#[inline]
#[unstable = "waiting for iterator conventions"]
#[unstable(feature = "core",
reason = "waiting for iterator conventions")]
pub fn iter_mut(&mut self) -> IterMut<T> {
IterMut { inner: Item { opt: self.as_mut() } }
}
@ -561,7 +563,7 @@ impl<T> Option<T> {
/// assert!(v.is_empty());
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn into_iter(self) -> IntoIter<T> {
IntoIter { inner: Item { opt: self } }
}
@ -592,7 +594,7 @@ impl<T> Option<T> {
/// assert_eq!(x.and(y), None);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn and<U>(self, optb: Option<U>) -> Option<U> {
match self {
Some(_) => optb,
@ -615,7 +617,7 @@ impl<T> Option<T> {
/// assert_eq!(None.and_then(sq).and_then(sq), None);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn and_then<U, F: FnOnce(T) -> Option<U>>(self, f: F) -> Option<U> {
match self {
Some(x) => f(x),
@ -645,7 +647,7 @@ impl<T> Option<T> {
/// assert_eq!(x.or(y), None);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn or(self, optb: Option<T>) -> Option<T> {
match self {
Some(_) => self,
@ -667,7 +669,7 @@ impl<T> Option<T> {
/// assert_eq!(None.or_else(nobody), None);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn or_else<F: FnOnce() -> Option<T>>(self, f: F) -> Option<T> {
match self {
Some(_) => self,
@ -693,7 +695,7 @@ impl<T> Option<T> {
/// assert_eq!(x, None);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn take(&mut self) -> Option<T> {
mem::replace(self, None)
}
@ -702,7 +704,8 @@ impl<T> Option<T> {
impl<'a, T: Clone, D: Deref<Target=T>> Option<D> {
/// Maps an Option<D> to an Option<T> by dereffing and cloning the contents of the Option.
/// Useful for converting an Option<&T> to an Option<T>.
#[unstable = "recently added as part of collections reform"]
#[unstable(feature = "core",
reason = "recently added as part of collections reform")]
pub fn cloned(self) -> Option<T> {
self.map(|t| t.deref().clone())
}
@ -732,7 +735,7 @@ impl<T: Default> Option<T> {
/// assert_eq!(0, bad_year);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn unwrap_or_default(self) -> T {
match self {
Some(x) => x,
@ -745,7 +748,8 @@ impl<T: Default> Option<T> {
// Trait implementations
/////////////////////////////////////////////////////////////////////////////
#[unstable = "waiting on the stability of the trait itself"]
#[unstable(feature = "core",
reason = "waiting on the stability of the trait itself")]
impl<T> AsSlice<T> for Option<T> {
/// Convert from `Option<T>` to `&[T]` (without copying)
#[inline]
@ -760,10 +764,10 @@ impl<T> AsSlice<T> for Option<T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Default for Option<T> {
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn default() -> Option<T> { None }
}
@ -803,10 +807,10 @@ impl<A> DoubleEndedIterator for Item<A> {
impl<A> ExactSizeIterator for Item<A> {}
/// An iterator over a reference of the contained item in an Option.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Iter<'a, A: 'a> { inner: Item<&'a A> }
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, A> Iterator for Iter<'a, A> {
type Item = &'a A;
@ -816,16 +820,16 @@ impl<'a, A> Iterator for Iter<'a, A> {
fn size_hint(&self) -> (uint, Option<uint>) { self.inner.size_hint() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, A> DoubleEndedIterator for Iter<'a, A> {
#[inline]
fn next_back(&mut self) -> Option<&'a A> { self.inner.next_back() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, A> ExactSizeIterator for Iter<'a, A> {}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, A> Clone for Iter<'a, A> {
fn clone(&self) -> Iter<'a, A> {
Iter { inner: self.inner.clone() }
@ -833,10 +837,10 @@ impl<'a, A> Clone for Iter<'a, A> {
}
/// An iterator over a mutable reference of the contained item in an Option.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct IterMut<'a, A: 'a> { inner: Item<&'a mut A> }
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, A> Iterator for IterMut<'a, A> {
type Item = &'a mut A;
@ -846,20 +850,20 @@ impl<'a, A> Iterator for IterMut<'a, A> {
fn size_hint(&self) -> (uint, Option<uint>) { self.inner.size_hint() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, A> DoubleEndedIterator for IterMut<'a, A> {
#[inline]
fn next_back(&mut self) -> Option<&'a mut A> { self.inner.next_back() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, A> ExactSizeIterator for IterMut<'a, A> {}
/// An iterator over the item contained inside an Option.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct IntoIter<A> { inner: Item<A> }
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<A> Iterator for IntoIter<A> {
type Item = A;
@ -869,20 +873,20 @@ impl<A> Iterator for IntoIter<A> {
fn size_hint(&self) -> (uint, Option<uint>) { self.inner.size_hint() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<A> DoubleEndedIterator for IntoIter<A> {
#[inline]
fn next_back(&mut self) -> Option<A> { self.inner.next_back() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<A> ExactSizeIterator for IntoIter<A> {}
/////////////////////////////////////////////////////////////////////////////
// FromIterator
/////////////////////////////////////////////////////////////////////////////
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<A, V: FromIterator<A>> FromIterator<Option<A>> for Option<V> {
/// Takes each element in the `Iterator`: if it is `None`, no further
/// elements are taken, and the `None` is returned. Should no `None` occur, a
@ -902,7 +906,7 @@ impl<A, V: FromIterator<A>> FromIterator<Option<A>> for Option<V> {
/// assert!(res == Some(vec!(2, 3)));
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn from_iter<I: Iterator<Item=Option<A>>>(iter: I) -> Option<V> {
// FIXME(#11084): This could be replaced with Iterator::scan when this
// performance bug is closed.

View File

@ -86,7 +86,7 @@
//! but C APIs hand out a lot of pointers generally, so are a common source
//! of unsafe pointers in Rust.
#![stable]
#![stable(feature = "rust1", since = "1.0.0")]
use mem;
use clone::Clone;
@ -99,13 +99,14 @@ use cmp::Ordering::{self, Less, Equal, Greater};
// FIXME #19649: intrinsic docs don't render, so these have no docs :(
#[unstable]
#[unstable(feature = "core")]
pub use intrinsics::copy_nonoverlapping_memory;
#[unstable]
#[unstable(feature = "core")]
pub use intrinsics::copy_memory;
#[unstable = "uncertain about naming and semantics"]
#[unstable(feature = "core",
reason = "uncertain about naming and semantics")]
pub use intrinsics::set_memory;
@ -120,7 +121,7 @@ pub use intrinsics::set_memory;
/// assert!(p.is_null());
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn null<T>() -> *const T { 0 as *const T }
/// Creates a null mutable raw pointer.
@ -134,7 +135,7 @@ pub fn null<T>() -> *const T { 0 as *const T }
/// assert!(p.is_null());
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn null_mut<T>() -> *mut T { 0 as *mut T }
/// Zeroes out `count * size_of::<T>` bytes of memory at `dst`. `count` may be
@ -145,7 +146,8 @@ pub fn null_mut<T>() -> *mut T { 0 as *mut T }
/// Beyond accepting a raw pointer, this is unsafe because it will not drop the
/// contents of `dst`, and may be used to create invalid instances of `T`.
#[inline]
#[unstable = "may play a larger role in std::ptr future extensions"]
#[unstable(feature = "core",
reason = "may play a larger role in std::ptr future extensions")]
pub unsafe fn zero_memory<T>(dst: *mut T, count: uint) {
set_memory(dst, 0, count);
}
@ -158,7 +160,7 @@ pub unsafe fn zero_memory<T>(dst: *mut T, count: uint) {
///
/// This is only unsafe because it accepts a raw pointer.
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub unsafe fn swap<T>(x: *mut T, y: *mut T) {
// Give ourselves some scratch space to work with
let mut tmp: T = mem::uninitialized();
@ -182,7 +184,7 @@ pub unsafe fn swap<T>(x: *mut T, y: *mut T) {
/// This is only unsafe because it accepts a raw pointer.
/// Otherwise, this operation is identical to `mem::replace`.
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub unsafe fn replace<T>(dest: *mut T, mut src: T) -> T {
mem::swap(mem::transmute(dest), &mut src); // cannot overlap
src
@ -200,7 +202,7 @@ pub unsafe fn replace<T>(dest: *mut T, mut src: T) -> T {
/// `zero_memory`, or `copy_memory`). Note that `*src = foo` counts as a use
/// because it will attempt to drop the value previously at `*src`.
#[inline(always)]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub unsafe fn read<T>(src: *const T) -> T {
let mut tmp: T = mem::uninitialized();
copy_nonoverlapping_memory(&mut tmp, src, 1);
@ -213,7 +215,8 @@ pub unsafe fn read<T>(src: *const T) -> T {
///
/// This is unsafe for the same reasons that `read` is unsafe.
#[inline(always)]
#[unstable = "may play a larger role in std::ptr future extensions"]
#[unstable(feature = "core",
reason = "may play a larger role in std::ptr future extensions")]
pub unsafe fn read_and_zero<T>(dest: *mut T) -> T {
// Copy the data out from `dest`:
let tmp = read(&*dest);
@ -236,18 +239,18 @@ pub unsafe fn read_and_zero<T>(dest: *mut T) -> T {
/// This is appropriate for initializing uninitialized memory, or overwriting
/// memory that has previously been `read` from.
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub unsafe fn write<T>(dst: *mut T, src: T) {
intrinsics::move_val_init(&mut *dst, src)
}
/// Methods on raw pointers
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait PtrExt: Sized {
type Target;
/// Returns true if the pointer is null.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn is_null(self) -> bool;
/// Returns `None` if the pointer is null, or else returns a reference to
@ -259,8 +262,9 @@ pub trait PtrExt: Sized {
/// null-safety, it is important to note that this is still an unsafe
/// operation because the returned value could be pointing to invalid
/// memory.
#[unstable = "Option is not clearly the right return type, and we may want \
to tie the return lifetime to a borrow of the raw pointer"]
#[unstable(feature = "core",
reason = "Option is not clearly the right return type, and we may want \
to tie the return lifetime to a borrow of the raw pointer")]
unsafe fn as_ref<'a>(&self) -> Option<&'a Self::Target>;
/// Calculates the offset from a pointer. `count` is in units of T; e.g. a
@ -271,12 +275,12 @@ pub trait PtrExt: Sized {
/// The offset must be in-bounds of the object, or one-byte-past-the-end.
/// Otherwise `offset` invokes Undefined Behaviour, regardless of whether
/// the pointer is used.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
unsafe fn offset(self, count: int) -> Self;
}
/// Methods on mutable raw pointers
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait MutPtrExt {
type Target;
@ -287,28 +291,30 @@ pub trait MutPtrExt {
///
/// As with `as_ref`, this is unsafe because it cannot verify the validity
/// of the returned pointer.
#[unstable = "Option is not clearly the right return type, and we may want \
to tie the return lifetime to a borrow of the raw pointer"]
#[unstable(feature = "core",
reason = "Option is not clearly the right return type, and we may want \
to tie the return lifetime to a borrow of the raw pointer")]
unsafe fn as_mut<'a>(&self) -> Option<&'a mut Self::Target>;
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> PtrExt for *const T {
type Target = T;
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn is_null(self) -> bool { self as uint == 0 }
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
unsafe fn offset(self, count: int) -> *const T {
intrinsics::offset(self, count)
}
#[inline]
#[unstable = "return value does not necessarily convey all possible \
information"]
#[unstable(feature = "core",
reason = "return value does not necessarily convey all possible \
information")]
unsafe fn as_ref<'a>(&self) -> Option<&'a T> {
if self.is_null() {
None
@ -318,23 +324,24 @@ impl<T> PtrExt for *const T {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> PtrExt for *mut T {
type Target = T;
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn is_null(self) -> bool { self as uint == 0 }
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
unsafe fn offset(self, count: int) -> *mut T {
intrinsics::offset(self, count) as *mut T
}
#[inline]
#[unstable = "return value does not necessarily convey all possible \
information"]
#[unstable(feature = "core",
reason = "return value does not necessarily convey all possible \
information")]
unsafe fn as_ref<'a>(&self) -> Option<&'a T> {
if self.is_null() {
None
@ -344,13 +351,14 @@ impl<T> PtrExt for *mut T {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> MutPtrExt for *mut T {
type Target = T;
#[inline]
#[unstable = "return value does not necessarily convey all possible \
information"]
#[unstable(feature = "core",
reason = "return value does not necessarily convey all possible \
information")]
unsafe fn as_mut<'a>(&self) -> Option<&'a mut T> {
if self.is_null() {
None
@ -361,7 +369,7 @@ impl<T> MutPtrExt for *mut T {
}
// Equality for pointers
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> PartialEq for *const T {
#[inline]
fn eq(&self, other: &*const T) -> bool {
@ -371,10 +379,10 @@ impl<T> PartialEq for *const T {
fn ne(&self, other: &*const T) -> bool { !self.eq(other) }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Eq for *const T {}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> PartialEq for *mut T {
#[inline]
fn eq(&self, other: &*mut T) -> bool {
@ -384,10 +392,10 @@ impl<T> PartialEq for *mut T {
fn ne(&self, other: &*mut T) -> bool { !self.eq(other) }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Eq for *mut T {}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Clone for *const T {
#[inline]
fn clone(&self) -> *const T {
@ -395,7 +403,7 @@ impl<T> Clone for *const T {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Clone for *mut T {
#[inline]
fn clone(&self) -> *mut T {
@ -408,7 +416,7 @@ mod externfnpointers {
use mem;
use cmp::PartialEq;
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<_R> PartialEq for extern "C" fn() -> _R {
#[inline]
fn eq(&self, other: &extern "C" fn() -> _R) -> bool {
@ -419,7 +427,7 @@ mod externfnpointers {
}
macro_rules! fnptreq {
($($p:ident),*) => {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<_R,$($p),*> PartialEq for extern "C" fn($($p),*) -> _R {
#[inline]
fn eq(&self, other: &extern "C" fn($($p),*) -> _R) -> bool {
@ -439,7 +447,7 @@ mod externfnpointers {
}
// Comparison for pointers
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Ord for *const T {
#[inline]
fn cmp(&self, other: &*const T) -> Ordering {
@ -453,7 +461,7 @@ impl<T> Ord for *const T {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> PartialOrd for *const T {
#[inline]
fn partial_cmp(&self, other: &*const T) -> Option<Ordering> {
@ -473,7 +481,7 @@ impl<T> PartialOrd for *const T {
fn ge(&self, other: &*const T) -> bool { *self >= *other }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Ord for *mut T {
#[inline]
fn cmp(&self, other: &*mut T) -> Ordering {
@ -487,7 +495,7 @@ impl<T> Ord for *mut T {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> PartialOrd for *mut T {
#[inline]
fn partial_cmp(&self, other: &*mut T) -> Option<Ordering> {
@ -513,32 +521,34 @@ impl<T> PartialOrd for *mut T {
/// raw `*mut T` (which conveys no particular ownership semantics).
/// Useful for building abstractions like `Vec<T>` or `Box<T>`, which
/// internally use raw pointers to manage the memory that they own.
#[unstable = "recently added to this module"]
#[unstable(feature = "core", reason = "recently added to this module")]
pub struct Unique<T>(pub *mut T);
/// `Unique` pointers are `Send` if `T` is `Send` because the data they
/// reference is unaliased. Note that this aliasing invariant is
/// unenforced by the type system; the abstraction using the
/// `Unique` must enforce it.
#[unstable = "recently added to this module"]
#[unstable(feature = "core", reason = "recently added to this module")]
unsafe impl<T:Send> Send for Unique<T> { }
/// `Unique` pointers are `Sync` if `T` is `Sync` because the data they
/// reference is unaliased. Note that this aliasing invariant is
/// unenforced by the type system; the abstraction using the
/// `Unique` must enforce it.
#[unstable = "recently added to this module"]
#[unstable(feature = "core", reason = "recently added to this module")]
unsafe impl<T:Sync> Sync for Unique<T> { }
impl<T> Unique<T> {
/// Returns a null Unique.
#[unstable = "recently added to this module"]
#[unstable(feature = "core",
reason = "recently added to this module")]
pub fn null() -> Unique<T> {
Unique(null_mut())
}
/// Return an (unsafe) pointer into the memory owned by `self`.
#[unstable = "recently added to this module"]
#[unstable(feature = "core",
reason = "recently added to this module")]
pub unsafe fn offset(self, offset: int) -> *mut T {
self.0.offset(offset)
}

View File

@ -9,7 +9,7 @@
// except according to those terms.
#![allow(missing_docs)]
#![unstable]
#![unstable(feature = "core")]
//! Contains struct definitions for the layout of compiler built-in types.
//!

View File

@ -224,7 +224,7 @@
//!
//! `try!` is imported by the prelude, and is available everywhere.
#![stable]
#![stable(feature = "rust1", since = "1.0.0")]
use self::Result::{Ok, Err};
@ -241,14 +241,14 @@ use slice;
/// See the [`std::result`](index.html) module documentation for details.
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Show, Hash)]
#[must_use]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub enum Result<T, E> {
/// Contains the success value
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
Ok(T),
/// Contains the error value
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
Err(E)
}
@ -256,7 +256,7 @@ pub enum Result<T, E> {
// Type implementation
/////////////////////////////////////////////////////////////////////////////
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T, E> Result<T, E> {
/////////////////////////////////////////////////////////////////////////
// Querying the contained values
@ -274,7 +274,7 @@ impl<T, E> Result<T, E> {
/// assert_eq!(x.is_ok(), false);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_ok(&self) -> bool {
match *self {
Ok(_) => true,
@ -294,7 +294,7 @@ impl<T, E> Result<T, E> {
/// assert_eq!(x.is_err(), true);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_err(&self) -> bool {
!self.is_ok()
}
@ -318,7 +318,7 @@ impl<T, E> Result<T, E> {
/// assert_eq!(x.ok(), None);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn ok(self) -> Option<T> {
match self {
Ok(x) => Some(x),
@ -341,7 +341,7 @@ impl<T, E> Result<T, E> {
/// assert_eq!(x.err(), Some("Nothing here"));
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn err(self) -> Option<E> {
match self {
Ok(_) => None,
@ -366,7 +366,7 @@ impl<T, E> Result<T, E> {
/// assert_eq!(x.as_ref(), Err(&"Error"));
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn as_ref(&self) -> Result<&T, &E> {
match *self {
Ok(ref x) => Ok(x),
@ -393,7 +393,7 @@ impl<T, E> Result<T, E> {
/// assert_eq!(x.unwrap_err(), 0);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn as_mut(&mut self) -> Result<&mut T, &mut E> {
match *self {
Ok(ref mut x) => Ok(x),
@ -417,7 +417,8 @@ impl<T, E> Result<T, E> {
/// assert!(x.as_mut_slice().is_empty());
/// ```
#[inline]
#[unstable = "waiting for mut conventions"]
#[unstable(feature = "core",
reason = "waiting for mut conventions")]
pub fn as_mut_slice(&mut self) -> &mut [T] {
match *self {
Ok(ref mut x) => slice::mut_ref_slice(x),
@ -463,7 +464,7 @@ impl<T, E> Result<T, E> {
/// assert!(sum == 10);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn map<U, F: FnOnce(T) -> U>(self, op: F) -> Result<U,E> {
match self {
Ok(t) => Ok(op(t)),
@ -489,7 +490,7 @@ impl<T, E> Result<T, E> {
/// assert_eq!(x.map_err(stringify), Err("error code: 13".to_string()));
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn map_err<F, O: FnOnce(E) -> F>(self, op: O) -> Result<T,F> {
match self {
Ok(t) => Ok(t),
@ -513,7 +514,7 @@ impl<T, E> Result<T, E> {
/// assert_eq!(x.iter().next(), None);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn iter(&self) -> Iter<T> {
Iter { inner: self.as_ref().ok() }
}
@ -534,7 +535,7 @@ impl<T, E> Result<T, E> {
/// assert_eq!(x.iter_mut().next(), None);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn iter_mut(&mut self) -> IterMut<T> {
IterMut { inner: self.as_mut().ok() }
}
@ -553,7 +554,7 @@ impl<T, E> Result<T, E> {
/// assert_eq!(v, vec![]);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn into_iter(self) -> IntoIter<T> {
IntoIter { inner: self.ok() }
}
@ -584,7 +585,7 @@ impl<T, E> Result<T, E> {
/// assert_eq!(x.and(y), Ok("different result type"));
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn and<U>(self, res: Result<U, E>) -> Result<U, E> {
match self {
Ok(_) => res,
@ -608,7 +609,7 @@ impl<T, E> Result<T, E> {
/// assert_eq!(Err(3).and_then(sq).and_then(sq), Err(3));
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn and_then<U, F: FnOnce(T) -> Result<U, E>>(self, op: F) -> Result<U, E> {
match self {
Ok(t) => op(t),
@ -638,7 +639,7 @@ impl<T, E> Result<T, E> {
/// assert_eq!(x.or(y), Ok(2));
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn or(self, res: Result<T, E>) -> Result<T, E> {
match self {
Ok(_) => self,
@ -662,7 +663,7 @@ impl<T, E> Result<T, E> {
/// assert_eq!(Err(3).or_else(err).or_else(err), Err(3));
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn or_else<F, O: FnOnce(E) -> Result<T, F>>(self, op: O) -> Result<T, F> {
match self {
Ok(t) => Ok(t),
@ -684,7 +685,7 @@ impl<T, E> Result<T, E> {
/// assert_eq!(x.unwrap_or(optb), optb);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn unwrap_or(self, optb: T) -> T {
match self {
Ok(t) => t,
@ -704,7 +705,7 @@ impl<T, E> Result<T, E> {
/// assert_eq!(Err("foo").unwrap_or_else(count), 3);
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn unwrap_or_else<F: FnOnce(E) -> T>(self, op: F) -> T {
match self {
Ok(t) => t,
@ -713,7 +714,7 @@ impl<T, E> Result<T, E> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T, E: Debug> Result<T, E> {
/// Unwraps a result, yielding the content of an `Ok`.
///
@ -734,7 +735,7 @@ impl<T, E: Debug> Result<T, E> {
/// x.unwrap(); // panics with `emergency failure`
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn unwrap(self) -> T {
match self {
Ok(t) => t,
@ -744,7 +745,7 @@ impl<T, E: Debug> Result<T, E> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Debug, E> Result<T, E> {
/// Unwraps a result, yielding the content of an `Err`.
///
@ -765,7 +766,7 @@ impl<T: Debug, E> Result<T, E> {
/// assert_eq!(x.unwrap_err(), "emergency failure");
/// ```
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn unwrap_err(self) -> E {
match self {
Ok(t) =>
@ -782,7 +783,7 @@ impl<T: Debug, E> Result<T, E> {
impl<T, E> AsSlice<T> for Result<T, E> {
/// Convert from `Result<T, E>` to `&[T]` (without copying)
#[inline]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn as_slice<'a>(&'a self) -> &'a [T] {
match *self {
Ok(ref x) => slice::ref_slice(x),
@ -800,10 +801,10 @@ impl<T, E> AsSlice<T> for Result<T, E> {
/////////////////////////////////////////////////////////////////////////////
/// An iterator over a reference to the `Ok` variant of a `Result`.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Iter<'a, T: 'a> { inner: Option<&'a T> }
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> Iterator for Iter<'a, T> {
type Item = &'a T;
@ -816,13 +817,13 @@ impl<'a, T> Iterator for Iter<'a, T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> DoubleEndedIterator for Iter<'a, T> {
#[inline]
fn next_back(&mut self) -> Option<&'a T> { self.inner.take() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> ExactSizeIterator for Iter<'a, T> {}
impl<'a, T> Clone for Iter<'a, T> {
@ -830,10 +831,10 @@ impl<'a, T> Clone for Iter<'a, T> {
}
/// An iterator over a mutable reference to the `Ok` variant of a `Result`.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct IterMut<'a, T: 'a> { inner: Option<&'a mut T> }
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> Iterator for IterMut<'a, T> {
type Item = &'a mut T;
@ -846,20 +847,20 @@ impl<'a, T> Iterator for IterMut<'a, T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> DoubleEndedIterator for IterMut<'a, T> {
#[inline]
fn next_back(&mut self) -> Option<&'a mut T> { self.inner.take() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> ExactSizeIterator for IterMut<'a, T> {}
/// An iterator over the value in a `Ok` variant of a `Result`.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct IntoIter<T> { inner: Option<T> }
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Iterator for IntoIter<T> {
type Item = T;
@ -872,20 +873,20 @@ impl<T> Iterator for IntoIter<T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> DoubleEndedIterator for IntoIter<T> {
#[inline]
fn next_back(&mut self) -> Option<T> { self.inner.take() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ExactSizeIterator for IntoIter<T> {}
/////////////////////////////////////////////////////////////////////////////
// FromIterator
/////////////////////////////////////////////////////////////////////////////
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<A, E, V: FromIterator<A>> FromIterator<Result<A, E>> for Result<V, E> {
/// Takes each element in the `Iterator`: if it is an `Err`, no further
/// elements are taken, and the `Err` is returned. Should no `Err` occur, a
@ -949,7 +950,7 @@ impl<A, E, V: FromIterator<A>> FromIterator<Result<A, E>> for Result<V, E> {
/// If an `Err` is encountered, it is immediately returned.
/// Otherwise, the folded value is returned.
#[inline]
#[unstable]
#[unstable(feature = "core")]
pub fn fold<T,
V,
E,

View File

@ -19,7 +19,6 @@
//! provided beyond this module.
//!
//! ```rust
//! #[allow(unstable)];
//!
//! fn main() {
//! use std::simd::f32x4;
@ -37,7 +36,7 @@
#![allow(non_camel_case_types)]
#![allow(missing_docs)]
#[unstable]
#[unstable(feature = "core")]
#[simd]
#[derive(Copy, Show)]
#[repr(C)]
@ -46,26 +45,26 @@ pub struct i8x16(pub i8, pub i8, pub i8, pub i8,
pub i8, pub i8, pub i8, pub i8,
pub i8, pub i8, pub i8, pub i8);
#[unstable]
#[unstable(feature = "core")]
#[simd]
#[derive(Copy, Show)]
#[repr(C)]
pub struct i16x8(pub i16, pub i16, pub i16, pub i16,
pub i16, pub i16, pub i16, pub i16);
#[unstable]
#[unstable(feature = "core")]
#[simd]
#[derive(Copy, Show)]
#[repr(C)]
pub struct i32x4(pub i32, pub i32, pub i32, pub i32);
#[unstable]
#[unstable(feature = "core")]
#[simd]
#[derive(Copy, Show)]
#[repr(C)]
pub struct i64x2(pub i64, pub i64);
#[unstable]
#[unstable(feature = "core")]
#[simd]
#[derive(Copy, Show)]
#[repr(C)]
@ -74,32 +73,32 @@ pub struct u8x16(pub u8, pub u8, pub u8, pub u8,
pub u8, pub u8, pub u8, pub u8,
pub u8, pub u8, pub u8, pub u8);
#[unstable]
#[unstable(feature = "core")]
#[simd]
#[derive(Copy, Show)]
#[repr(C)]
pub struct u16x8(pub u16, pub u16, pub u16, pub u16,
pub u16, pub u16, pub u16, pub u16);
#[unstable]
#[unstable(feature = "core")]
#[simd]
#[derive(Copy, Show)]
#[repr(C)]
pub struct u32x4(pub u32, pub u32, pub u32, pub u32);
#[unstable]
#[unstable(feature = "core")]
#[simd]
#[derive(Copy, Show)]
#[repr(C)]
pub struct u64x2(pub u64, pub u64);
#[unstable]
#[unstable(feature = "core")]
#[simd]
#[derive(Copy, Show)]
#[repr(C)]
pub struct f32x4(pub f32, pub f32, pub f32, pub f32);
#[unstable]
#[unstable(feature = "core")]
#[simd]
#[derive(Copy, Show)]
#[repr(C)]

View File

@ -12,7 +12,7 @@
//!
//! For more details `std::slice`.
#![stable]
#![stable(feature = "rust1", since = "1.0.0")]
#![doc(primitive = "slice")]
// How this module is organized.
@ -125,7 +125,7 @@ pub trait SliceExt {
fn clone_from_slice(&mut self, &[Self::Item]) -> uint where Self::Item: Clone;
}
#[unstable]
#[unstable(feature = "core")]
impl<T> SliceExt for [T] {
type Item = T;
@ -230,7 +230,7 @@ impl<T> SliceExt for [T] {
self.repr().data
}
#[unstable]
#[unstable(feature = "core")]
fn binary_search_by<F>(&self, mut f: F) -> Result<uint, uint> where
F: FnMut(&T) -> Ordering
{
@ -410,12 +410,12 @@ impl<T> SliceExt for [T] {
m >= n && needle == &self[m-n..]
}
#[unstable]
#[unstable(feature = "core")]
fn binary_search(&self, x: &T) -> Result<uint, uint> where T: Ord {
self.binary_search_by(|p| p.cmp(x))
}
#[unstable]
#[unstable(feature = "core")]
fn next_permutation(&mut self) -> bool where T: Ord {
// These cases only have 1 permutation each, so we can't do anything.
if self.len() < 2 { return false; }
@ -446,7 +446,7 @@ impl<T> SliceExt for [T] {
true
}
#[unstable]
#[unstable(feature = "core")]
fn prev_permutation(&mut self) -> bool where T: Ord {
// These cases only have 1 permutation each, so we can't do anything.
if self.len() < 2 { return false; }
@ -489,7 +489,7 @@ impl<T> SliceExt for [T] {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ops::Index<uint> for [T] {
type Output = T;
@ -500,7 +500,7 @@ impl<T> ops::Index<uint> for [T] {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ops::IndexMut<uint> for [T] {
type Output = T;
@ -511,7 +511,7 @@ impl<T> ops::IndexMut<uint> for [T] {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ops::Index<ops::Range<uint>> for [T] {
type Output = [T];
#[inline]
@ -526,7 +526,7 @@ impl<T> ops::Index<ops::Range<uint>> for [T] {
}
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ops::Index<ops::RangeTo<uint>> for [T] {
type Output = [T];
#[inline]
@ -534,7 +534,7 @@ impl<T> ops::Index<ops::RangeTo<uint>> for [T] {
self.index(&ops::Range{ start: 0, end: index.end })
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ops::Index<ops::RangeFrom<uint>> for [T] {
type Output = [T];
#[inline]
@ -542,7 +542,7 @@ impl<T> ops::Index<ops::RangeFrom<uint>> for [T] {
self.index(&ops::Range{ start: index.start, end: self.len() })
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ops::Index<ops::FullRange> for [T] {
type Output = [T];
#[inline]
@ -551,7 +551,7 @@ impl<T> ops::Index<ops::FullRange> for [T] {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ops::IndexMut<ops::Range<uint>> for [T] {
type Output = [T];
#[inline]
@ -566,7 +566,7 @@ impl<T> ops::IndexMut<ops::Range<uint>> for [T] {
}
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ops::IndexMut<ops::RangeTo<uint>> for [T] {
type Output = [T];
#[inline]
@ -574,7 +574,7 @@ impl<T> ops::IndexMut<ops::RangeTo<uint>> for [T] {
self.index_mut(&ops::Range{ start: 0, end: index.end })
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ops::IndexMut<ops::RangeFrom<uint>> for [T] {
type Output = [T];
#[inline]
@ -583,7 +583,7 @@ impl<T> ops::IndexMut<ops::RangeFrom<uint>> for [T] {
self.index_mut(&ops::Range{ start: index.start, end: len })
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ops::IndexMut<ops::FullRange> for [T] {
type Output = [T];
#[inline]
@ -598,33 +598,34 @@ impl<T> ops::IndexMut<ops::FullRange> for [T] {
////////////////////////////////////////////////////////////////////////////////
/// Data that is viewable as a slice.
#[unstable = "will be replaced by slice syntax"]
#[unstable(feature = "core",
reason = "will be replaced by slice syntax")]
pub trait AsSlice<T> {
/// Work with `self` as a slice.
fn as_slice<'a>(&'a self) -> &'a [T];
}
#[unstable = "trait is experimental"]
#[unstable(feature = "core", reason = "trait is experimental")]
impl<T> AsSlice<T> for [T] {
#[inline(always)]
fn as_slice<'a>(&'a self) -> &'a [T] { self }
}
#[unstable = "trait is experimental"]
#[unstable(feature = "core", reason = "trait is experimental")]
impl<'a, T, U: ?Sized + AsSlice<T>> AsSlice<T> for &'a U {
#[inline(always)]
fn as_slice(&self) -> &[T] { AsSlice::as_slice(*self) }
}
#[unstable = "trait is experimental"]
#[unstable(feature = "core", reason = "trait is experimental")]
impl<'a, T, U: ?Sized + AsSlice<T>> AsSlice<T> for &'a mut U {
#[inline(always)]
fn as_slice(&self) -> &[T] { AsSlice::as_slice(*self) }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> Default for &'a [T] {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn default() -> &'a [T] { &[] }
}
@ -635,7 +636,7 @@ impl<'a, T> Default for &'a [T] {
// The shared definition of the `Iter` and `IterMut` iterators
macro_rules! iterator {
(struct $name:ident -> $ptr:ty, $elem:ty) => {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> Iterator for $name<'a, T> {
type Item = $elem;
@ -673,7 +674,7 @@ macro_rules! iterator {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> DoubleEndedIterator for $name<'a, T> {
#[inline]
fn next_back(&mut self) -> Option<$elem> {
@ -715,14 +716,14 @@ macro_rules! make_slice {
}
/// Immutable slice iterator
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Iter<'a, T: 'a> {
ptr: *const T,
end: *const T,
marker: marker::ContravariantLifetime<'a>
}
#[unstable]
#[unstable(feature = "core")]
impl<'a, T> ops::Index<ops::Range<uint>> for Iter<'a, T> {
type Output = [T];
#[inline]
@ -731,7 +732,7 @@ impl<'a, T> ops::Index<ops::Range<uint>> for Iter<'a, T> {
}
}
#[unstable]
#[unstable(feature = "core")]
impl<'a, T> ops::Index<ops::RangeTo<uint>> for Iter<'a, T> {
type Output = [T];
#[inline]
@ -740,7 +741,7 @@ impl<'a, T> ops::Index<ops::RangeTo<uint>> for Iter<'a, T> {
}
}
#[unstable]
#[unstable(feature = "core")]
impl<'a, T> ops::Index<ops::RangeFrom<uint>> for Iter<'a, T> {
type Output = [T];
#[inline]
@ -749,7 +750,7 @@ impl<'a, T> ops::Index<ops::RangeFrom<uint>> for Iter<'a, T> {
}
}
#[unstable]
#[unstable(feature = "core")]
impl<'a, T> ops::Index<ops::FullRange> for Iter<'a, T> {
type Output = [T];
#[inline]
@ -763,7 +764,7 @@ impl<'a, T> Iter<'a, T> {
///
/// This has the same lifetime as the original slice, and so the
/// iterator can continue to be used while this exists.
#[unstable]
#[unstable(feature = "core")]
pub fn as_slice(&self) -> &'a [T] {
make_slice!(T => &'a [T]: self.ptr, self.end)
}
@ -773,15 +774,15 @@ impl<'a,T> Copy for Iter<'a,T> {}
iterator!{struct Iter -> *const T, &'a T}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> ExactSizeIterator for Iter<'a, T> {}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> Clone for Iter<'a, T> {
fn clone(&self) -> Iter<'a, T> { *self }
}
#[unstable = "trait is experimental"]
#[unstable(feature = "core", reason = "trait is experimental")]
impl<'a, T> RandomAccessIterator for Iter<'a, T> {
#[inline]
fn indexable(&self) -> uint {
@ -807,7 +808,7 @@ impl<'a, T> RandomAccessIterator for Iter<'a, T> {
}
/// Mutable slice iterator.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct IterMut<'a, T: 'a> {
ptr: *mut T,
end: *mut T,
@ -815,7 +816,7 @@ pub struct IterMut<'a, T: 'a> {
}
#[unstable]
#[unstable(feature = "core")]
impl<'a, T> ops::Index<ops::Range<uint>> for IterMut<'a, T> {
type Output = [T];
#[inline]
@ -823,7 +824,7 @@ impl<'a, T> ops::Index<ops::Range<uint>> for IterMut<'a, T> {
self.index(&ops::FullRange).index(index)
}
}
#[unstable]
#[unstable(feature = "core")]
impl<'a, T> ops::Index<ops::RangeTo<uint>> for IterMut<'a, T> {
type Output = [T];
#[inline]
@ -831,7 +832,7 @@ impl<'a, T> ops::Index<ops::RangeTo<uint>> for IterMut<'a, T> {
self.index(&ops::FullRange).index(index)
}
}
#[unstable]
#[unstable(feature = "core")]
impl<'a, T> ops::Index<ops::RangeFrom<uint>> for IterMut<'a, T> {
type Output = [T];
#[inline]
@ -839,7 +840,7 @@ impl<'a, T> ops::Index<ops::RangeFrom<uint>> for IterMut<'a, T> {
self.index(&ops::FullRange).index(index)
}
}
#[unstable]
#[unstable(feature = "core")]
impl<'a, T> ops::Index<ops::FullRange> for IterMut<'a, T> {
type Output = [T];
#[inline]
@ -848,7 +849,7 @@ impl<'a, T> ops::Index<ops::FullRange> for IterMut<'a, T> {
}
}
#[unstable]
#[unstable(feature = "core")]
impl<'a, T> ops::IndexMut<ops::Range<uint>> for IterMut<'a, T> {
type Output = [T];
#[inline]
@ -856,7 +857,7 @@ impl<'a, T> ops::IndexMut<ops::Range<uint>> for IterMut<'a, T> {
self.index_mut(&ops::FullRange).index_mut(index)
}
}
#[unstable]
#[unstable(feature = "core")]
impl<'a, T> ops::IndexMut<ops::RangeTo<uint>> for IterMut<'a, T> {
type Output = [T];
#[inline]
@ -864,7 +865,7 @@ impl<'a, T> ops::IndexMut<ops::RangeTo<uint>> for IterMut<'a, T> {
self.index_mut(&ops::FullRange).index_mut(index)
}
}
#[unstable]
#[unstable(feature = "core")]
impl<'a, T> ops::IndexMut<ops::RangeFrom<uint>> for IterMut<'a, T> {
type Output = [T];
#[inline]
@ -872,7 +873,7 @@ impl<'a, T> ops::IndexMut<ops::RangeFrom<uint>> for IterMut<'a, T> {
self.index_mut(&ops::FullRange).index_mut(index)
}
}
#[unstable]
#[unstable(feature = "core")]
impl<'a, T> ops::IndexMut<ops::FullRange> for IterMut<'a, T> {
type Output = [T];
#[inline]
@ -889,7 +890,7 @@ impl<'a, T> IterMut<'a, T> {
/// to consume the iterator. Consider using the `Slice` and
/// `SliceMut` implementations for obtaining slices with more
/// restricted lifetimes that do not consume the iterator.
#[unstable]
#[unstable(feature = "core")]
pub fn into_slice(self) -> &'a mut [T] {
make_slice!(T => &'a mut [T]: self.ptr, self.end)
}
@ -897,7 +898,7 @@ impl<'a, T> IterMut<'a, T> {
iterator!{struct IterMut -> *mut T, &'a mut T}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> ExactSizeIterator for IterMut<'a, T> {}
/// An internal abstraction over the splitting iterators, so that
@ -910,7 +911,7 @@ trait SplitIter: DoubleEndedIterator {
/// An iterator over subslices separated by elements that match a predicate
/// function.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Split<'a, T:'a, P> where P: FnMut(&T) -> bool {
v: &'a [T],
pred: P,
@ -918,7 +919,7 @@ pub struct Split<'a, T:'a, P> where P: FnMut(&T) -> bool {
}
// FIXME(#19839) Remove in favor of `#[derive(Clone)]`
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T, P> Clone for Split<'a, T, P> where P: Clone + FnMut(&T) -> bool {
fn clone(&self) -> Split<'a, T, P> {
Split {
@ -929,7 +930,7 @@ impl<'a, T, P> Clone for Split<'a, T, P> where P: Clone + FnMut(&T) -> bool {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T, P> Iterator for Split<'a, T, P> where P: FnMut(&T) -> bool {
type Item = &'a [T];
@ -957,7 +958,7 @@ impl<'a, T, P> Iterator for Split<'a, T, P> where P: FnMut(&T) -> bool {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T, P> DoubleEndedIterator for Split<'a, T, P> where P: FnMut(&T) -> bool {
#[inline]
fn next_back(&mut self) -> Option<&'a [T]> {
@ -983,7 +984,7 @@ impl<'a, T, P> SplitIter for Split<'a, T, P> where P: FnMut(&T) -> bool {
/// An iterator over the subslices of the vector which are separated
/// by elements that match `pred`.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct SplitMut<'a, T:'a, P> where P: FnMut(&T) -> bool {
v: &'a mut [T],
pred: P,
@ -1002,7 +1003,7 @@ impl<'a, T, P> SplitIter for SplitMut<'a, T, P> where P: FnMut(&T) -> bool {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T, P> Iterator for SplitMut<'a, T, P> where P: FnMut(&T) -> bool {
type Item = &'a mut [T];
@ -1037,7 +1038,7 @@ impl<'a, T, P> Iterator for SplitMut<'a, T, P> where P: FnMut(&T) -> bool {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T, P> DoubleEndedIterator for SplitMut<'a, T, P> where
P: FnMut(&T) -> bool,
{
@ -1092,7 +1093,7 @@ impl<T, I: SplitIter<Item=T>> Iterator for GenericSplitN<I> {
/// An iterator over subslices separated by elements that match a predicate
/// function, limited to a given number of splits.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct SplitN<'a, T: 'a, P> where P: FnMut(&T) -> bool {
inner: GenericSplitN<Split<'a, T, P>>
}
@ -1100,14 +1101,14 @@ pub struct SplitN<'a, T: 'a, P> where P: FnMut(&T) -> bool {
/// An iterator over subslices separated by elements that match a
/// predicate function, limited to a given number of splits, starting
/// from the end of the slice.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct RSplitN<'a, T: 'a, P> where P: FnMut(&T) -> bool {
inner: GenericSplitN<Split<'a, T, P>>
}
/// An iterator over subslices separated by elements that match a predicate
/// function, limited to a given number of splits.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct SplitNMut<'a, T: 'a, P> where P: FnMut(&T) -> bool {
inner: GenericSplitN<SplitMut<'a, T, P>>
}
@ -1115,14 +1116,14 @@ pub struct SplitNMut<'a, T: 'a, P> where P: FnMut(&T) -> bool {
/// An iterator over subslices separated by elements that match a
/// predicate function, limited to a given number of splits, starting
/// from the end of the slice.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct RSplitNMut<'a, T: 'a, P> where P: FnMut(&T) -> bool {
inner: GenericSplitN<SplitMut<'a, T, P>>
}
macro_rules! forward_iterator {
($name:ident: $elem:ident, $iter_of:ty) => {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, $elem, P> Iterator for $name<'a, $elem, P> where
P: FnMut(&T) -> bool
{
@ -1148,13 +1149,13 @@ forward_iterator! { RSplitNMut: T, &'a mut [T] }
/// An iterator over overlapping subslices of length `size`.
#[derive(Clone)]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Windows<'a, T:'a> {
v: &'a [T],
size: uint
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> Iterator for Windows<'a, T> {
type Item = &'a [T];
@ -1186,13 +1187,13 @@ impl<'a, T> Iterator for Windows<'a, T> {
/// When the slice len is not evenly divided by the chunk size, the last slice
/// of the iteration will be the remainder.
#[derive(Clone)]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Chunks<'a, T:'a> {
v: &'a [T],
size: uint
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> Iterator for Chunks<'a, T> {
type Item = &'a [T];
@ -1221,7 +1222,7 @@ impl<'a, T> Iterator for Chunks<'a, T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> DoubleEndedIterator for Chunks<'a, T> {
#[inline]
fn next_back(&mut self) -> Option<&'a [T]> {
@ -1237,10 +1238,10 @@ impl<'a, T> DoubleEndedIterator for Chunks<'a, T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> ExactSizeIterator for Chunks<'a, T> {}
#[unstable = "trait is experimental"]
#[unstable(feature = "core", reason = "trait is experimental")]
impl<'a, T> RandomAccessIterator for Chunks<'a, T> {
#[inline]
fn indexable(&self) -> uint {
@ -1264,13 +1265,13 @@ impl<'a, T> RandomAccessIterator for Chunks<'a, T> {
/// An iterator over a slice in (non-overlapping) mutable chunks (`size`
/// elements at a time). When the slice len is not evenly divided by the chunk
/// size, the last slice of the iteration will be the remainder.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct ChunksMut<'a, T:'a> {
v: &'a mut [T],
chunk_size: uint
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> Iterator for ChunksMut<'a, T> {
type Item = &'a mut [T];
@ -1300,7 +1301,7 @@ impl<'a, T> Iterator for ChunksMut<'a, T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> DoubleEndedIterator for ChunksMut<'a, T> {
#[inline]
fn next_back(&mut self) -> Option<&'a mut [T]> {
@ -1318,7 +1319,7 @@ impl<'a, T> DoubleEndedIterator for ChunksMut<'a, T> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> ExactSizeIterator for ChunksMut<'a, T> {}
//
@ -1326,7 +1327,7 @@ impl<'a, T> ExactSizeIterator for ChunksMut<'a, T> {}
//
/// Converts a pointer to A into a slice of length 1 (without copying).
#[unstable]
#[unstable(feature = "core")]
pub fn ref_slice<'a, A>(s: &'a A) -> &'a [A] {
unsafe {
transmute(RawSlice { data: s, len: 1 })
@ -1334,7 +1335,7 @@ pub fn ref_slice<'a, A>(s: &'a A) -> &'a [A] {
}
/// Converts a pointer to A into a slice of length 1 (without copying).
#[unstable]
#[unstable(feature = "core")]
pub fn mut_ref_slice<'a, A>(s: &'a mut A) -> &'a mut [A] {
unsafe {
let ptr: *const A = transmute(s);
@ -1368,7 +1369,8 @@ pub fn mut_ref_slice<'a, A>(s: &'a mut A) -> &'a mut [A] {
/// }
/// ```
#[inline]
#[unstable = "should be renamed to from_raw_parts"]
#[unstable(feature = "core",
reason = "should be renamed to from_raw_parts")]
pub unsafe fn from_raw_buf<'a, T>(p: &'a *const T, len: uint) -> &'a [T] {
transmute(RawSlice { data: *p, len: len })
}
@ -1380,7 +1382,8 @@ pub unsafe fn from_raw_buf<'a, T>(p: &'a *const T, len: uint) -> &'a [T] {
/// not being able to provide a non-aliasing guarantee of the returned mutable
/// slice.
#[inline]
#[unstable = "should be renamed to from_raw_parts_mut"]
#[unstable(feature = "core",
reason = "should be renamed to from_raw_parts_mut")]
pub unsafe fn from_raw_mut_buf<'a, T>(p: &'a *mut T, len: uint) -> &'a mut [T] {
transmute(RawSlice { data: *p, len: len })
}
@ -1390,7 +1393,7 @@ pub unsafe fn from_raw_mut_buf<'a, T>(p: &'a *mut T, len: uint) -> &'a mut [T] {
//
/// Operations on `[u8]`.
#[unstable = "needs review"]
#[unstable(feature = "core", reason = "needs review")]
pub mod bytes {
use ptr;
use slice::SliceExt;
@ -1403,7 +1406,6 @@ pub mod bytes {
impl MutableByteVector for [u8] {
#[inline]
#[allow(unstable)]
fn set_memory(&mut self, value: u8) {
unsafe { ptr::set_memory(self.as_mut_ptr(), value, self.len()) };
}
@ -1432,7 +1434,7 @@ pub mod bytes {
// Boilerplate traits
//
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<A, B> PartialEq<[B]> for [A] where A: PartialEq<B> {
fn eq(&self, other: &[B]) -> bool {
self.len() == other.len() &&
@ -1444,17 +1446,17 @@ impl<A, B> PartialEq<[B]> for [A] where A: PartialEq<B> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Eq> Eq for [T] {}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Ord> Ord for [T] {
fn cmp(&self, other: &[T]) -> Ordering {
order::cmp(self.iter(), other.iter())
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: PartialOrd> PartialOrd for [T] {
#[inline]
fn partial_cmp(&self, other: &[T]) -> Option<Ordering> {
@ -1479,7 +1481,7 @@ impl<T: PartialOrd> PartialOrd for [T] {
}
/// Extension methods for slices containing integers.
#[unstable]
#[unstable(feature = "core")]
pub trait IntSliceExt<U, S> {
/// Converts the slice to an immutable slice of unsigned integers with the same width.
fn as_unsigned<'a>(&'a self) -> &'a [U];
@ -1494,7 +1496,7 @@ pub trait IntSliceExt<U, S> {
macro_rules! impl_int_slice {
($u:ty, $s:ty, $t:ty) => {
#[unstable]
#[unstable(feature = "core")]
impl IntSliceExt<$u, $s> for [$t] {
#[inline]
fn as_unsigned(&self) -> &[$u] { unsafe { transmute(self) } }

View File

@ -47,7 +47,7 @@ macro_rules! delegate_iter {
}
};
($te:ty : $ti:ty) => {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> Iterator for $ti {
type Item = $te;
@ -60,7 +60,7 @@ macro_rules! delegate_iter {
self.0.size_hint()
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> DoubleEndedIterator for $ti {
#[inline]
fn next_back(&mut self) -> Option<$te> {
@ -69,7 +69,7 @@ macro_rules! delegate_iter {
}
};
(pattern $te:ty : $ti:ty) => {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, P: CharEq> Iterator for $ti {
type Item = $te;
@ -82,7 +82,7 @@ macro_rules! delegate_iter {
self.0.size_hint()
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, P: CharEq> DoubleEndedIterator for $ti {
#[inline]
fn next_back(&mut self) -> Option<$te> {
@ -91,7 +91,7 @@ macro_rules! delegate_iter {
}
};
(pattern forward $te:ty : $ti:ty) => {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, P: CharEq> Iterator for $ti {
type Item = $te;
@ -110,7 +110,8 @@ macro_rules! delegate_iter {
/// A trait to abstract the idea of creating a new instance of a type from a
/// string.
// FIXME(#17307): there should be an `E` associated type for a `Result` return
#[unstable = "will return a Result once associated types are working"]
#[unstable(feature = "core",
reason = "will return a Result once associated types are working")]
pub trait FromStr {
/// Parses a string `s` to return an optional value of this type. If the
/// string is ill-formatted, the None is returned.
@ -145,7 +146,8 @@ Section: Creating a string
/// Errors which can occur when attempting to interpret a byte slice as a `str`.
#[derive(Copy, Eq, PartialEq, Clone, Show)]
#[unstable = "error enumeration recently added and definitions may be refined"]
#[unstable(feature = "core",
reason = "error enumeration recently added and definitions may be refined")]
pub enum Utf8Error {
/// An invalid byte was detected at the byte offset given.
///
@ -169,7 +171,7 @@ pub enum Utf8Error {
///
/// Returns `Err` if the slice is not utf-8 with a description as to why the
/// provided slice is not utf-8.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn from_utf8(v: &[u8]) -> Result<&str, Utf8Error> {
try!(run_utf8_validation_iterator(&mut v.iter()));
Ok(unsafe { from_utf8_unchecked(v) })
@ -177,7 +179,7 @@ pub fn from_utf8(v: &[u8]) -> Result<&str, Utf8Error> {
/// Converts a slice of bytes to a string slice without checking
/// that the string contains valid UTF-8.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub unsafe fn from_utf8_unchecked<'a>(v: &'a [u8]) -> &'a str {
mem::transmute(v)
}
@ -195,7 +197,9 @@ pub unsafe fn from_utf8_unchecked<'a>(v: &'a [u8]) -> &'a str {
/// # Panics
///
/// This function will panic if the string pointed to by `s` is not valid UTF-8.
#[deprecated = "use std::ffi::c_str_to_bytes + str::from_utf8"]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0",
reason = "use std::ffi::c_str_to_bytes + str::from_utf8")]
pub unsafe fn from_c_str(s: *const i8) -> &'static str {
let s = s as *const u8;
let mut len = 0;
@ -207,7 +211,8 @@ pub unsafe fn from_c_str(s: *const i8) -> &'static str {
}
/// Something that can be used to compare against a character
#[unstable = "definition may change as pattern-related methods are stabilized"]
#[unstable(feature = "core",
reason = "definition may change as pattern-related methods are stabilized")]
pub trait CharEq {
/// Determine if the splitter should split at the given character
fn matches(&mut self, char) -> bool;
@ -244,7 +249,7 @@ impl<'a> CharEq for &'a [char] {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Error for Utf8Error {
fn description(&self) -> &str {
match *self {
@ -254,7 +259,7 @@ impl Error for Utf8Error {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl fmt::Display for Utf8Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
@ -276,7 +281,7 @@ Section: Iterators
///
/// Created with the method `.chars()`.
#[derive(Clone, Copy)]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Chars<'a> {
iter: slice::Iter<'a, u8>
}
@ -307,7 +312,7 @@ fn unwrap_or_0(opt: Option<&u8>) -> u8 {
/// Reads the next code point out of a byte iterator (assuming a
/// UTF-8-like encoding).
#[unstable]
#[unstable(feature = "core")]
pub fn next_code_point(bytes: &mut slice::Iter<u8>) -> Option<u32> {
// Decode UTF-8
let x = match bytes.next() {
@ -339,7 +344,7 @@ pub fn next_code_point(bytes: &mut slice::Iter<u8>) -> Option<u32> {
Some(ch)
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> Iterator for Chars<'a> {
type Item = char;
@ -360,7 +365,7 @@ impl<'a> Iterator for Chars<'a> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> DoubleEndedIterator for Chars<'a> {
#[inline]
fn next_back(&mut self) -> Option<char> {
@ -397,13 +402,13 @@ impl<'a> DoubleEndedIterator for Chars<'a> {
/// External iterator for a string's characters and their byte offsets.
/// Use with the `std::iter` module.
#[derive(Clone)]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct CharIndices<'a> {
front_offset: uint,
iter: Chars<'a>,
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> Iterator for CharIndices<'a> {
type Item = (uint, char);
@ -427,7 +432,7 @@ impl<'a> Iterator for CharIndices<'a> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> DoubleEndedIterator for CharIndices<'a> {
#[inline]
fn next_back(&mut self) -> Option<(uint, char)> {
@ -446,7 +451,7 @@ impl<'a> DoubleEndedIterator for CharIndices<'a> {
/// Use with the `std::iter` module.
///
/// Created with `StrExt::bytes`
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
#[derive(Clone)]
pub struct Bytes<'a>(Map<&'a u8, u8, slice::Iter<'a, u8>, BytesDeref>);
delegate_iter!{exact u8 : Bytes<'a>}
@ -456,6 +461,7 @@ delegate_iter!{exact u8 : Bytes<'a>}
#[derive(Copy, Clone)]
struct BytesDeref;
#[cfg(stage0)]
impl<'a> Fn(&'a u8) -> u8 for BytesDeref {
#[inline]
extern "rust-call" fn call(&self, (ptr,): (&'a u8,)) -> u8 {
@ -463,6 +469,16 @@ impl<'a> Fn(&'a u8) -> u8 for BytesDeref {
}
}
#[cfg(not(stage0))]
impl<'a> Fn<(&'a u8,)> for BytesDeref {
type Output = u8;
#[inline]
extern "rust-call" fn call(&self, (ptr,): (&'a u8,)) -> u8 {
*ptr
}
}
/// An iterator over the substrings of a string, separated by `sep`.
#[derive(Clone)]
struct CharSplits<'a, Sep> {
@ -486,13 +502,13 @@ struct CharSplitsN<'a, Sep> {
}
/// An iterator over the lines of a string, separated by `\n`.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Lines<'a> {
inner: CharSplits<'a, char>,
}
/// An iterator over the lines of a string, separated by either `\n` or (`\r\n`).
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct LinesAny<'a> {
inner: Map<&'a str, &'a str, Lines<'a>, fn(&str) -> &str>,
}
@ -509,7 +525,7 @@ impl<'a, Sep> CharSplits<'a, Sep> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, Sep: CharEq> Iterator for CharSplits<'a, Sep> {
type Item = &'a str;
@ -544,7 +560,7 @@ impl<'a, Sep: CharEq> Iterator for CharSplits<'a, Sep> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, Sep: CharEq> DoubleEndedIterator for CharSplits<'a, Sep> {
#[inline]
fn next_back(&mut self) -> Option<&'a str> {
@ -586,7 +602,7 @@ impl<'a, Sep: CharEq> DoubleEndedIterator for CharSplits<'a, Sep> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, Sep: CharEq> Iterator for CharSplitsN<'a, Sep> {
type Item = &'a str;
@ -892,7 +908,7 @@ impl Searcher {
/// An iterator over the start and end indices of the matches of a
/// substring within a larger string
#[derive(Clone)]
#[unstable = "type may be removed"]
#[unstable(feature = "core", reason = "type may be removed")]
pub struct MatchIndices<'a> {
// constants
haystack: &'a str,
@ -903,14 +919,14 @@ pub struct MatchIndices<'a> {
/// An iterator over the substrings of a string separated by a given
/// search string
#[derive(Clone)]
#[unstable = "type may be removed"]
#[unstable(feature = "core", reason = "type may be removed")]
pub struct SplitStr<'a> {
it: MatchIndices<'a>,
last_end: uint,
finished: bool
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> Iterator for MatchIndices<'a> {
type Item = (uint, uint);
@ -927,7 +943,7 @@ impl<'a> Iterator for MatchIndices<'a> {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> Iterator for SplitStr<'a> {
type Item = &'a str;
@ -1087,7 +1103,8 @@ static UTF8_CHAR_WIDTH: [u8; 256] = [
/// the next `char` in a string. This can be used as a data structure
/// for iterating over the UTF-8 bytes of a string.
#[derive(Copy)]
#[unstable = "naming is uncertain with container conventions"]
#[unstable(feature = "core",
reason = "naming is uncertain with container conventions")]
pub struct CharRange {
/// Current `char`
pub ch: char,
@ -1113,7 +1130,7 @@ mod traits {
use ops;
use str::{StrExt, eq_slice};
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Ord for str {
#[inline]
fn cmp(&self, other: &str) -> Ordering {
@ -1129,7 +1146,7 @@ mod traits {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl PartialEq for str {
#[inline]
fn eq(&self, other: &str) -> bool {
@ -1139,10 +1156,10 @@ mod traits {
fn ne(&self, other: &str) -> bool { !(*self).eq(other) }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Eq for str {}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl PartialOrd for str {
#[inline]
fn partial_cmp(&self, other: &str) -> Option<Ordering> {
@ -1176,7 +1193,7 @@ mod traits {
/// // byte 100 is outside the string
/// // &s[3 .. 100];
/// ```
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl ops::Index<ops::Range<uint>> for str {
type Output = str;
#[inline]
@ -1199,7 +1216,7 @@ mod traits {
///
/// Panics when `end` does not point to a valid character, or is
/// out of bounds.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl ops::Index<ops::RangeTo<uint>> for str {
type Output = str;
#[inline]
@ -1219,7 +1236,7 @@ mod traits {
///
/// Panics when `begin` does not point to a valid character, or is
/// out of bounds.
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl ops::Index<ops::RangeFrom<uint>> for str {
type Output = str;
#[inline]
@ -1233,7 +1250,7 @@ mod traits {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl ops::Index<ops::FullRange> for str {
type Output = str;
#[inline]
@ -1244,9 +1261,10 @@ mod traits {
}
/// Any string that can be represented as a slice
#[unstable = "Instead of taking this bound generically, this trait will be \
replaced with one of slicing syntax (&foo[]), deref coercions, or \
a more generic conversion trait"]
#[unstable(feature = "core",
reason = "Instead of taking this bound generically, this trait will be \
replaced with one of slicing syntax (&foo[]), deref coercions, or \
a more generic conversion trait")]
pub trait Str {
/// Work with `self` as a slice.
fn as_slice<'a>(&'a self) -> &'a str;
@ -1264,25 +1282,26 @@ impl<'a, S: ?Sized> Str for &'a S where S: Str {
/// Return type of `StrExt::split`
#[derive(Clone)]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Split<'a, P>(CharSplits<'a, P>);
delegate_iter!{pattern &'a str : Split<'a, P>}
/// Return type of `StrExt::split_terminator`
#[derive(Clone)]
#[unstable = "might get removed in favour of a constructor method on Split"]
#[unstable(feature = "core",
reason = "might get removed in favour of a constructor method on Split")]
pub struct SplitTerminator<'a, P>(CharSplits<'a, P>);
delegate_iter!{pattern &'a str : SplitTerminator<'a, P>}
/// Return type of `StrExt::splitn`
#[derive(Clone)]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct SplitN<'a, P>(CharSplitsN<'a, P>);
delegate_iter!{pattern forward &'a str : SplitN<'a, P>}
/// Return type of `StrExt::rsplitn`
#[derive(Clone)]
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct RSplitN<'a, P>(CharSplitsN<'a, P>);
delegate_iter!{pattern forward &'a str : RSplitN<'a, P>}
@ -1648,7 +1667,7 @@ impl StrExt for str {
/// Pluck a code point out of a UTF-8-like byte slice and return the
/// index of the next code point.
#[inline]
#[unstable]
#[unstable(feature = "core")]
pub fn char_range_at_raw(bytes: &[u8], i: uint) -> (u32, usize) {
if bytes[i] < 128u8 {
return (bytes[i] as u32, i + 1);
@ -1671,13 +1690,13 @@ pub fn char_range_at_raw(bytes: &[u8], i: uint) -> (u32, usize) {
multibyte_char_range_at(bytes, i)
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> Default for &'a str {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn default() -> &'a str { "" }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> Iterator for Lines<'a> {
type Item = &'a str;
@ -1687,13 +1706,13 @@ impl<'a> Iterator for Lines<'a> {
fn size_hint(&self) -> (uint, Option<uint>) { self.inner.size_hint() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> DoubleEndedIterator for Lines<'a> {
#[inline]
fn next_back(&mut self) -> Option<&'a str> { self.inner.next_back() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> Iterator for LinesAny<'a> {
type Item = &'a str;
@ -1703,7 +1722,7 @@ impl<'a> Iterator for LinesAny<'a> {
fn size_hint(&self) -> (uint, Option<uint>) { self.inner.size_hint() }
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> DoubleEndedIterator for LinesAny<'a> {
#[inline]
fn next_back(&mut self) -> Option<&'a str> { self.inner.next_back() }

View File

@ -33,7 +33,7 @@
//! * `Ord`
//! * `Default`
#![stable]
#![stable(feature = "rust1", since = "1.0.0")]
use clone::Clone;
use cmp::*;
@ -55,14 +55,14 @@ macro_rules! tuple_impls {
}
)+) => {
$(
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<$($T:Clone),+> Clone for ($($T,)+) {
fn clone(&self) -> ($($T,)+) {
($(e!(self.$idx.clone()),)+)
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<$($T:PartialEq),+> PartialEq for ($($T,)+) {
#[inline]
fn eq(&self, other: &($($T,)+)) -> bool {
@ -74,10 +74,10 @@ macro_rules! tuple_impls {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<$($T:Eq),+> Eq for ($($T,)+) {}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<$($T:PartialOrd + PartialEq),+> PartialOrd for ($($T,)+) {
#[inline]
fn partial_cmp(&self, other: &($($T,)+)) -> Option<Ordering> {
@ -101,7 +101,7 @@ macro_rules! tuple_impls {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<$($T:Ord),+> Ord for ($($T,)+) {
#[inline]
fn cmp(&self, other: &($($T,)+)) -> Ordering {
@ -109,9 +109,9 @@ macro_rules! tuple_impls {
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl<$($T:Default),+> Default for ($($T,)+) {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
fn default() -> ($($T,)+) {
($({ let x: $T = Default::default(); x},)+)

View File

@ -114,7 +114,6 @@ fn discard_doesnt_unborrow() {
}
#[test]
#[allow(unstable)]
fn clone_ref_updates_flag() {
let x = RefCell::new(0i);
{

View File

@ -12,7 +12,6 @@
#![feature(unboxed_closures)]
#![feature(box_syntax)]
#![allow(unknown_features)] #![feature(int_uint)]
#![allow(unstable)]
extern crate core;
extern crate test;

View File

@ -15,15 +15,18 @@
//! [mz]: https://code.google.com/p/miniz/
#![crate_name = "flate"]
#![unstable]
#![unstable(feature = "rustc_private")]
#![feature(staged_api)]
#![staged_api]
#![allow(unknown_features)] #![feature(int_uint)]
#![allow(unstable)]
#![crate_type = "rlib"]
#![crate_type = "dylib"]
#![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(hash)]
#![feature(core)]
#![feature(libc)]
#[cfg(test)] #[macro_use] extern crate log;

View File

@ -15,7 +15,8 @@
//! generated instead.
#![crate_name = "fmt_macros"]
#![unstable]
#![unstable(feature = "rustc_private")]
#![feature(staged_api)]
#![staged_api]
#![crate_type = "rlib"]
#![crate_type = "dylib"]
@ -26,7 +27,9 @@
#![feature(slicing_syntax)]
#![allow(unknown_features)] #![feature(int_uint)]
#![allow(unstable)]
#![feature(collections)]
#![feature(core)]
#![feature(unicode)]
pub use self::Piece::*;
pub use self::Position::*;

View File

@ -78,7 +78,9 @@
//! ```
#![crate_name = "getopts"]
#![unstable = "use the crates.io `getopts` library instead"]
#![unstable(feature = "rustc_private",
reason = "use the crates.io `getopts` library instead")]
#![feature(staged_api)]
#![staged_api]
#![crate_type = "rlib"]
#![crate_type = "dylib"]
@ -88,8 +90,10 @@
html_playground_url = "http://play.rust-lang.org/")]
#![feature(slicing_syntax)]
#![allow(unknown_features)] #![feature(int_uint)]
#![allow(unstable)]
#![deny(missing_docs)]
#![feature(collections)]
#![feature(core)]
#![cfg_attr(test, feature(rustc_private))]
#[cfg(test)] #[macro_use] extern crate log;
@ -538,7 +542,9 @@ pub fn opt(short_name: &str,
impl Fail {
/// Convert a `Fail` enum into an error string.
#[deprecated="use `fmt::String` (`{}` format specifier)"]
#[unstable(feature = "rustc_private")]
#[deprecated(since = "1.0.0",
reason = "use `fmt::String` (`{}` format specifier)")]
pub fn to_err_msg(self) -> String {
self.to_string()
}

View File

@ -265,7 +265,8 @@
//! * [DOT language](http://www.graphviz.org/doc/info/lang.html)
#![crate_name = "graphviz"]
#![unstable]
#![unstable(feature = "rustc_private")]
#![feature(staged_api)]
#![staged_api]
#![crate_type = "rlib"]
#![crate_type = "dylib"]
@ -274,7 +275,10 @@
html_root_url = "http://doc.rust-lang.org/nightly/")]
#![feature(slicing_syntax)]
#![allow(unknown_features)] #![feature(int_uint)]
#![allow(unstable)]
#![feature(collections)]
#![feature(core)]
#![feature(io)]
#![feature(path)]
use self::LabelText::*;

View File

@ -8,7 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![deprecated = "use std::vec::CowVec"]
#![unstable(feature = "rustc_private")]
#![deprecated(since = "1.0.0", reason = "use std::vec::CowVec")]
pub use self::MaybeOwnedVector::*;

View File

@ -10,15 +10,18 @@
#![crate_name = "libc"]
#![crate_type = "rlib"]
#![cfg_attr(not(feature = "cargo-build"), unstable)]
#![cfg_attr(not(feature = "cargo-build"),
unstable(feature = "libc"))]
#![cfg_attr(not(feature = "cargo-build"), feature(staged_api))]
#![cfg_attr(not(feature = "cargo-build"), staged_api)]
#![cfg_attr(not(feature = "cargo-build"), feature(core))]
#![allow(unknown_features)] #![feature(int_uint)]
#![allow(unstable)]
#![no_std]
#![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/",
html_playground_url = "http://play.rust-lang.org/")]
#![cfg_attr(test, feature(test))]
//! Bindings for the C standard library and other platform libraries
//!
@ -73,7 +76,6 @@
//! one from Berkeley after the lawsuits died down and the CSRG dissolved.
#![allow(bad_style, raw_pointer_derive)]
#[cfg(feature = "cargo-build")] extern crate "std" as core;
#[cfg(not(feature = "cargo-build"))] extern crate core;

View File

@ -156,7 +156,9 @@
//! if logging is disabled, none of the components of the log will be executed.
#![crate_name = "log"]
#![unstable = "use the crates.io `log` library instead"]
#![unstable(feature = "rustc_private",
reason = "use the crates.io `log` library instead")]
#![feature(staged_api)]
#![staged_api]
#![crate_type = "rlib"]
#![crate_type = "dylib"]
@ -169,8 +171,13 @@
#![feature(slicing_syntax)]
#![feature(box_syntax)]
#![allow(unknown_features)] #![feature(int_uint)]
#![allow(unstable)]
#![deny(missing_docs)]
#![feature(collections)]
#![feature(core)]
#![feature(io)]
#![feature(os)]
#![feature(rustc_private)]
#![feature(std_misc)]
use std::cell::RefCell;
use std::fmt;

View File

@ -17,7 +17,7 @@
//! internally. The `IndependentSample` trait is for generating values
//! that do not need to record state.
#![unstable]
#![unstable(feature = "rand")]
use core::prelude::*;
use core::num::{Float, Int};

View File

@ -23,10 +23,11 @@
html_root_url = "http://doc.rust-lang.org/nightly/",
html_playground_url = "http://play.rust-lang.org/")]
#![allow(unknown_features)] #![feature(int_uint)]
#![allow(unstable)]
#![no_std]
#![unstable]
#![unstable(feature = "rand")]
#![feature(staged_api)]
#![staged_api]
#![feature(core)]
#[macro_use]
extern crate core;

View File

@ -141,9 +141,9 @@ impl<R: Rng + Default> Reseeder<R> for ReseedWithDefault {
*rng = Default::default();
}
}
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
impl Default for ReseedWithDefault {
#[stable]
#[stable(feature = "rust1", since = "1.0.0")]
fn default() -> ReseedWithDefault { ReseedWithDefault }
}

View File

@ -16,7 +16,8 @@
//! http://www.matroska.org/technical/specs/rfc/index.html
#![crate_name = "rbml"]
#![unstable]
#![unstable(feature = "rustc_private")]
#![feature(staged_api)]
#![staged_api]
#![crate_type = "rlib"]
#![crate_type = "dylib"]
@ -27,7 +28,10 @@
#![allow(unknown_features)]
#![feature(slicing_syntax)]
#![allow(unknown_features)] #![feature(int_uint)]
#![allow(unstable)]
#![feature(collections)]
#![feature(core)]
#![feature(io)]
#![feature(rustc_private)]
extern crate serialize;
#[macro_use] extern crate log;
@ -853,7 +857,10 @@ pub mod writer {
// Set to true to generate more debugging in EBML code.
// Totally lame approach.
#[cfg(not(ndebug))]
static DEBUG: bool = true;
#[cfg(ndebug)]
static DEBUG: bool = false;
impl<'a, W: Writer + Seek> Encoder<'a, W> {
// used internally to emit things like the vector length and so on

View File

@ -15,7 +15,8 @@
//! This API is completely unstable and subject to change.
#![crate_name = "rustc"]
#![unstable]
#![unstable(feature = "rustc_private")]
#![feature(staged_api)]
#![staged_api]
#![crate_type = "dylib"]
#![crate_type = "rlib"]
@ -29,7 +30,17 @@
#![feature(box_syntax)]
#![allow(unknown_features)] #![feature(int_uint)]
#![feature(rustc_diagnostic_macros)]
#![allow(unstable)]
#![feature(collections)]
#![feature(core)]
#![feature(io)]
#![feature(libc)]
#![feature(os)]
#![feature(path)]
#![feature(rustc_private)]
#![feature(std_misc)]
#![feature(unicode)]
#![feature(hash)]
#![cfg_attr(test, feature(test))]
extern crate arena;
extern crate flate;

View File

@ -46,7 +46,7 @@ use std::{i8, i16, i32, i64, u8, u16, u32, u64, f32, f64};
use syntax::{abi, ast, ast_map};
use syntax::ast_util::is_shift_binop;
use syntax::attr::{self, AttrMetaMethods};
use syntax::codemap::{self, Span, DUMMY_SP};
use syntax::codemap::{self, Span};
use syntax::parse::token;
use syntax::ast::{TyIs, TyUs, TyI8, TyU8, TyI16, TyU16, TyI32, TyU32, TyI64, TyU64};
use syntax::ast_util;
@ -662,9 +662,6 @@ impl LintPass for UnusedAttributes {
// FIXME: #14407 these are only looked at on-demand so we can't
// guarantee they'll have already been checked
"deprecated",
"experimental",
"frozen",
"locked",
"must_use",
"stable",
"unstable",
@ -1696,37 +1693,16 @@ declare_lint! {
"detects use of #[deprecated] items"
}
declare_lint! {
UNSTABLE,
Warn,
"detects use of #[unstable] items (incl. items with no stability attribute)"
}
/// Checks for use of items with `#[deprecated]`, `#[unstable]` and
/// `#[unstable]` attributes, or no stability attribute.
/// Checks for use of items with `#[deprecated]` attributes
#[derive(Copy)]
pub struct Stability { this_crate_staged: bool }
pub struct Stability;
impl Stability {
pub fn new() -> Stability { Stability { this_crate_staged: false } }
fn lint(&self, cx: &Context, _id: ast::DefId, span: Span, stability: &Option<attr::Stability>) {
fn lint(&self, cx: &Context, id: ast::DefId, span: Span) {
let ref stability = stability::lookup(cx.tcx, id);
let cross_crate = !ast_util::is_local(id);
let staged = (!cross_crate && self.this_crate_staged)
|| (cross_crate && stability::is_staged_api(cx.tcx, id));
if !staged { return }
// stability attributes are promises made across crates; only
// check DEPRECATED for crate-local usage.
// deprecated attributes apply in-crate and cross-crate
let (lint, label) = match *stability {
// no stability attributes == Unstable
None if cross_crate => (UNSTABLE, "unmarked"),
Some(attr::Stability { level: attr::Unstable, .. }) if cross_crate =>
(UNSTABLE, "unstable"),
Some(attr::Stability { level: attr::Deprecated, .. }) =>
Some(attr::Stability { deprecated_since: Some(_), .. }) =>
(DEPRECATED, "deprecated"),
_ => return
};
@ -1736,7 +1712,7 @@ impl Stability {
fn output(cx: &Context, span: Span, stability: &Option<attr::Stability>,
lint: &'static Lint, label: &'static str) {
let msg = match *stability {
Some(attr::Stability { text: Some(ref s), .. }) => {
Some(attr::Stability { reason: Some(ref s), .. }) => {
format!("use of {} item: {}", label, *s)
}
_ => format!("use of {} item", label)
@ -1745,111 +1721,21 @@ impl Stability {
cx.span_lint(lint, span, &msg[]);
}
}
fn is_internal(&self, cx: &Context, span: Span) -> bool {
cx.tcx.sess.codemap().span_is_internal(span)
}
}
impl LintPass for Stability {
fn get_lints(&self) -> LintArray {
lint_array!(DEPRECATED, UNSTABLE)
}
fn check_crate(&mut self, _: &Context, c: &ast::Crate) {
// Just mark the #[staged_api] attribute used, though nothing else is done
// with it during this pass over the source.
for attr in c.attrs.iter() {
if attr.name().get() == "staged_api" {
match attr.node.value.node {
ast::MetaWord(_) => {
attr::mark_used(attr);
self.this_crate_staged = true;
}
_ => (/*pass*/)
}
}
}
}
fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
if self.is_internal(cx, e.span) { return; }
let mut span = e.span;
let id = match e.node {
ast::ExprPath(..) | ast::ExprQPath(..) | ast::ExprStruct(..) => {
match cx.tcx.def_map.borrow().get(&e.id) {
Some(&def) => def.def_id(),
None => return
}
}
ast::ExprMethodCall(i, _, _) => {
span = i.span;
let method_call = ty::MethodCall::expr(e.id);
match cx.tcx.method_map.borrow().get(&method_call) {
Some(method) => {
match method.origin {
ty::MethodStatic(def_id) => {
def_id
}
ty::MethodStaticClosure(def_id) => {
def_id
}
ty::MethodTypeParam(ty::MethodParam {
ref trait_ref,
method_num: index,
..
}) |
ty::MethodTraitObject(ty::MethodObject {
ref trait_ref,
method_num: index,
..
}) => {
ty::trait_item(cx.tcx, trait_ref.def_id, index).def_id()
}
}
}
None => return
}
}
_ => return
};
self.lint(cx, id, span);
lint_array!(DEPRECATED)
}
fn check_item(&mut self, cx: &Context, item: &ast::Item) {
if self.is_internal(cx, item.span) { return }
stability::check_item(cx.tcx, item,
&mut |id, sp, stab| self.lint(cx, id, sp, stab));
}
match item.node {
ast::ItemExternCrate(_) => {
// compiler-generated `extern crate` items have a dummy span.
if item.span == DUMMY_SP { return }
let cnum = match cx.tcx.sess.cstore.find_extern_mod_stmt_cnum(item.id) {
Some(cnum) => cnum,
None => return,
};
let id = ast::DefId { krate: cnum, node: ast::CRATE_NODE_ID };
self.lint(cx, id, item.span);
}
ast::ItemTrait(_, _, ref supertraits, _) => {
for t in supertraits.iter() {
if let ast::TraitTyParamBound(ref t, _) = *t {
let id = ty::trait_ref_to_def_id(cx.tcx, &t.trait_ref);
self.lint(cx, id, t.trait_ref.path.span);
}
}
}
ast::ItemImpl(_, _, _, Some(ref t), _, _) => {
let id = ty::trait_ref_to_def_id(cx.tcx, t);
self.lint(cx, id, t.path.span);
}
_ => (/* pass */)
}
fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
stability::check_expr(cx.tcx, e,
&mut |id, sp, stab| self.lint(cx, id, sp, stab));
}
}
@ -2096,9 +1982,9 @@ declare_lint! {
}
declare_lint! {
pub UNKNOWN_FEATURES,
pub UNUSED_FEATURES,
Deny,
"unknown features found in crate-level #[feature] directives"
"unused or unknown features found in crate-level #[feature] directives"
}
declare_lint! {
@ -2142,7 +2028,7 @@ impl LintPass for HardwiredLints {
DEAD_CODE,
UNREACHABLE_CODE,
WARNINGS,
UNKNOWN_FEATURES,
UNUSED_FEATURES,
UNKNOWN_CRATE_TYPES,
VARIANT_SIZE_DIFFERENCES,
FAT_PTR_TRANSMUTES

View File

@ -211,6 +211,7 @@ impl LintStore {
UnusedAllocation,
MissingCopyImplementations,
UnstableFeatures,
Stability,
UnconditionalRecursion,
);
@ -218,7 +219,6 @@ impl LintStore {
TypeLimits,
RawPointerDerive,
MissingDoc,
Stability,
MissingDebugImplementations,
);
@ -236,6 +236,7 @@ impl LintStore {
// Insert temporary renamings for a one-time deprecation
self.register_renamed("raw_pointer_deriving", "raw_pointer_derive");
self.register_renamed("unknown_features", "unused_features");
}
#[allow(unused_variables)]
@ -295,15 +296,6 @@ impl LintStore {
},
None => unreachable!()
}
match self.by_name.get("unstable") {
Some(&Id(lint_id)) => if self.get_level_source(lint_id).0 != Forbid {
self.set_level(lint_id, (lvl, ReleaseChannel))
},
Some(&Renamed(_, lint_id)) => if self.get_level_source(lint_id).0 != Forbid {
self.set_level(lint_id, (lvl, ReleaseChannel))
},
None => unreachable!()
}
}
}
@ -809,6 +801,5 @@ pub fn check_crate(tcx: &ty::ctxt,
}
}
tcx.sess.abort_if_errors();
*tcx.node_lint_levels.borrow_mut() = cx.node_levels.into_inner();
}

View File

@ -904,8 +904,8 @@ impl<'a, 'tcx> rbml_writer_helpers<'tcx> for Encoder<'a> {
try!(this.emit_struct_field("method_num", 0, |this| {
this.emit_uint(o.method_num)
}));
try!(this.emit_struct_field("real_index", 0, |this| {
this.emit_uint(o.real_index)
try!(this.emit_struct_field("vtable_index", 0, |this| {
this.emit_uint(o.vtable_index)
}));
Ok(())
})
@ -1492,8 +1492,8 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
this.read_uint()
}).unwrap()
},
real_index: {
this.read_struct_field("real_index", 3, |this| {
vtable_index: {
this.read_struct_field("vtable_index", 3, |this| {
this.read_uint()
}).unwrap()
},

View File

@ -79,16 +79,13 @@ pub struct InferCtxt<'a, 'tcx: 'a> {
type_variables: RefCell<type_variable::TypeVariableTable<'tcx>>,
// Map from integral variable to the kind of integer it represents
int_unification_table:
RefCell<UnificationTable<ty::IntVid, Option<IntVarValue>>>,
int_unification_table: RefCell<UnificationTable<ty::IntVid>>,
// Map from floating variable to the kind of float it represents
float_unification_table:
RefCell<UnificationTable<ty::FloatVid, Option<ast::FloatTy>>>,
float_unification_table: RefCell<UnificationTable<ty::FloatVid>>,
// For region variables.
region_vars:
RegionVarBindings<'a, 'tcx>,
region_vars: RegionVarBindings<'a, 'tcx>,
}
/// A map returned by `skolemize_late_bound_regions()` indicating the skolemized

View File

@ -19,7 +19,7 @@ use std::u32;
use util::snapshot_vec as sv;
pub struct TypeVariableTable<'tcx> {
values: sv::SnapshotVec<TypeVariableData<'tcx>,UndoEntry,Delegate>,
values: sv::SnapshotVec<Delegate<'tcx>>,
}
struct TypeVariableData<'tcx> {
@ -42,7 +42,7 @@ enum UndoEntry {
Relate(ty::TyVid, ty::TyVid),
}
struct Delegate;
struct Delegate<'tcx>;
type Relation = (RelationDir, ty::TyVid);
@ -195,9 +195,12 @@ impl<'tcx> TypeVariableTable<'tcx> {
}
}
impl<'tcx> sv::SnapshotVecDelegate<TypeVariableData<'tcx>,UndoEntry> for Delegate {
impl<'tcx> sv::SnapshotVecDelegate for Delegate<'tcx> {
type Value = TypeVariableData<'tcx>;
type Undo = UndoEntry;
fn reverse(&mut self,
values: &mut Vec<TypeVariableData>,
values: &mut Vec<TypeVariableData<'tcx>>,
action: UndoEntry) {
match action {
SpecifyVar(vid, relations) => {

View File

@ -19,7 +19,6 @@ use middle::infer::InferCtxt;
use std::cell::RefCell;
use std::fmt::Debug;
use syntax::ast;
use util::ppaux::Repr;
use util::snapshot_vec as sv;
/// This trait is implemented by any type that can serve as a type
@ -32,7 +31,9 @@ use util::snapshot_vec as sv;
/// (possibly not yet known) sort of integer.
///
/// Implementations of this trait are at the end of this file.
pub trait UnifyKey<'tcx, V> : Clone + Debug + PartialEq + Repr<'tcx> {
pub trait UnifyKey : Clone + Debug + PartialEq {
type Value : UnifyValue;
fn index(&self) -> uint;
fn from_index(u: uint) -> Self;
@ -40,7 +41,7 @@ pub trait UnifyKey<'tcx, V> : Clone + Debug + PartialEq + Repr<'tcx> {
// Given an inference context, returns the unification table
// appropriate to this key type.
fn unification_table<'v>(infcx: &'v InferCtxt)
-> &'v RefCell<UnificationTable<Self,V>>;
-> &'v RefCell<UnificationTable<Self>>;
fn tag(k: Option<Self>) -> &'static str;
}
@ -51,7 +52,7 @@ pub trait UnifyKey<'tcx, V> : Clone + Debug + PartialEq + Repr<'tcx> {
/// whose value is not yet set).
///
/// Implementations of this trait are at the end of this file.
pub trait UnifyValue<'tcx> : Clone + Repr<'tcx> + PartialEq {
pub trait UnifyValue : Clone + PartialEq + Debug {
}
/// Value of a unification key. We implement Tarjan's union-find
@ -62,21 +63,21 @@ pub trait UnifyValue<'tcx> : Clone + Repr<'tcx> + PartialEq {
/// to keep the DAG relatively balanced, which helps keep the running
/// time of the algorithm under control. For more information, see
/// <http://en.wikipedia.org/wiki/Disjoint-set_data_structure>.
#[derive(PartialEq,Clone)]
pub enum VarValue<K,V> {
#[derive(PartialEq,Clone,Show)]
pub enum VarValue<K:UnifyKey> {
Redirect(K),
Root(V, uint),
Root(K::Value, uint),
}
/// Table of unification keys and their values.
pub struct UnificationTable<K,V> {
pub struct UnificationTable<K:UnifyKey> {
/// Indicates the current value of each key.
values: sv::SnapshotVec<VarValue<K,V>,(),Delegate>,
values: sv::SnapshotVec<Delegate<K>>,
}
/// At any time, users may snapshot a unification table. The changes
/// made during the snapshot may either be *committed* or *rolled back*.
pub struct Snapshot<K> {
pub struct Snapshot<K:UnifyKey> {
// Link snapshot to the key type `K` of the table.
marker: marker::CovariantType<K>,
snapshot: sv::Snapshot,
@ -84,22 +85,22 @@ pub struct Snapshot<K> {
/// Internal type used to represent the result of a `get()` operation.
/// Conveys the current root and value of the key.
pub struct Node<K,V> {
pub struct Node<K:UnifyKey> {
pub key: K,
pub value: V,
pub value: K::Value,
pub rank: uint,
}
#[derive(Copy)]
pub struct Delegate;
pub struct Delegate<K>;
// We can't use V:LatticeValue, much as I would like to,
// because frequently the pattern is that V=Option<U> for some
// other type parameter U, and we have no way to say
// Option<U>:LatticeValue.
impl<'tcx, V:PartialEq+Clone+Repr<'tcx>, K:UnifyKey<'tcx, V>> UnificationTable<K,V> {
pub fn new() -> UnificationTable<K,V> {
impl<K:UnifyKey> UnificationTable<K> {
pub fn new() -> UnificationTable<K> {
UnificationTable {
values: sv::SnapshotVec::new(Delegate),
}
@ -126,7 +127,7 @@ impl<'tcx, V:PartialEq+Clone+Repr<'tcx>, K:UnifyKey<'tcx, V>> UnificationTable<K
self.values.commit(snapshot.snapshot);
}
pub fn new_key(&mut self, value: V) -> K {
pub fn new_key(&mut self, value: K::Value) -> K {
let index = self.values.push(Root(value, 0));
let k = UnifyKey::from_index(index);
debug!("{}: created new key: {:?}",
@ -137,12 +138,12 @@ impl<'tcx, V:PartialEq+Clone+Repr<'tcx>, K:UnifyKey<'tcx, V>> UnificationTable<K
/// Find the root node for `vid`. This uses the standard union-find algorithm with path
/// compression: http://en.wikipedia.org/wiki/Disjoint-set_data_structure
pub fn get(&mut self, tcx: &ty::ctxt, vid: K) -> Node<K,V> {
pub fn get(&mut self, tcx: &ty::ctxt, vid: K) -> Node<K> {
let index = vid.index();
let value = (*self.values.get(index)).clone();
match value {
Redirect(redirect) => {
let node: Node<K,V> = self.get(tcx, redirect.clone());
let node: Node<K> = self.get(tcx, redirect.clone());
if node.key != redirect {
// Path compression
self.values.set(index, Redirect(node.key.clone()));
@ -164,16 +165,15 @@ impl<'tcx, V:PartialEq+Clone+Repr<'tcx>, K:UnifyKey<'tcx, V>> UnificationTable<K
/// Sets the value for `vid` to `new_value`. `vid` MUST be a root node! Also, we must be in the
/// middle of a snapshot.
pub fn set(&mut self,
tcx: &ty::ctxt<'tcx>,
key: K,
new_value: VarValue<K,V>)
pub fn set<'tcx>(&mut self,
_tcx: &ty::ctxt<'tcx>,
key: K,
new_value: VarValue<K>)
{
assert!(self.is_root(&key));
debug!("Updating variable {} to {}",
key.repr(tcx),
new_value.repr(tcx));
debug!("Updating variable {:?} to {:?}",
key, new_value);
self.values.set(key.index(), new_value);
}
@ -181,16 +181,16 @@ impl<'tcx, V:PartialEq+Clone+Repr<'tcx>, K:UnifyKey<'tcx, V>> UnificationTable<K
/// Either redirects node_a to node_b or vice versa, depending on the relative rank. Returns
/// the new root and rank. You should then update the value of the new root to something
/// suitable.
pub fn unify(&mut self,
tcx: &ty::ctxt<'tcx>,
node_a: &Node<K,V>,
node_b: &Node<K,V>)
-> (K, uint)
pub fn unify<'tcx>(&mut self,
tcx: &ty::ctxt<'tcx>,
node_a: &Node<K>,
node_b: &Node<K>)
-> (K, uint)
{
debug!("unify(node_a(id={}, rank={}), node_b(id={}, rank={}))",
node_a.key.repr(tcx),
debug!("unify(node_a(id={:?}, rank={:?}), node_b(id={:?}, rank={:?}))",
node_a.key,
node_a.rank,
node_b.key.repr(tcx),
node_b.key,
node_b.rank);
if node_a.rank > node_b.rank {
@ -212,8 +212,11 @@ impl<'tcx, V:PartialEq+Clone+Repr<'tcx>, K:UnifyKey<'tcx, V>> UnificationTable<K
}
}
impl<K,V> sv::SnapshotVecDelegate<VarValue<K,V>,()> for Delegate {
fn reverse(&mut self, _: &mut Vec<VarValue<K,V>>, _: ()) {
impl<K> sv::SnapshotVecDelegate for Delegate<K> {
type Value = VarValue<K>;
type Undo = ();
fn reverse(&mut self, _: &mut Vec<VarValue<K>>, _: ()) {
panic!("Nothing to reverse");
}
}
@ -224,7 +227,7 @@ impl<K,V> sv::SnapshotVecDelegate<VarValue<K,V>,()> for Delegate {
/// Indicates a type that does not have any kind of subtyping
/// relationship.
pub trait SimplyUnifiable<'tcx> : Clone + PartialEq + Repr<'tcx> {
pub trait SimplyUnifiable<'tcx> : Clone + PartialEq + Debug {
fn to_type(&self, tcx: &ty::ctxt<'tcx>) -> Ty<'tcx>;
fn to_type_err(expected_found<Self>) -> ty::type_err<'tcx>;
}
@ -242,8 +245,11 @@ pub fn err<'tcx, V:SimplyUnifiable<'tcx>>(a_is_expected: bool,
}
}
pub trait InferCtxtMethodsForSimplyUnifiableTypes<'tcx, V:SimplyUnifiable<'tcx>,
K:UnifyKey<'tcx, Option<V>>> {
pub trait InferCtxtMethodsForSimplyUnifiableTypes<'tcx,K,V>
where K : UnifyKey<Value=Option<V>>,
V : SimplyUnifiable<'tcx>,
Option<V> : UnifyValue,
{
fn simple_vars(&self,
a_is_expected: bool,
a_id: K,
@ -257,8 +263,10 @@ pub trait InferCtxtMethodsForSimplyUnifiableTypes<'tcx, V:SimplyUnifiable<'tcx>,
fn probe_var(&self, a_id: K) -> Option<Ty<'tcx>>;
}
impl<'a,'tcx,V:SimplyUnifiable<'tcx>,K:UnifyKey<'tcx, Option<V>>>
InferCtxtMethodsForSimplyUnifiableTypes<'tcx, V, K> for InferCtxt<'a, 'tcx>
impl<'a,'tcx,V,K> InferCtxtMethodsForSimplyUnifiableTypes<'tcx,K,V> for InferCtxt<'a,'tcx>
where K : UnifyKey<Value=Option<V>>,
V : SimplyUnifiable<'tcx>,
Option<V> : UnifyValue,
{
/// Unifies two simple keys. Because simple keys do not have any subtyping relationships, if
/// both keys have already been associated with a value, then those two values must be the
@ -271,8 +279,8 @@ impl<'a,'tcx,V:SimplyUnifiable<'tcx>,K:UnifyKey<'tcx, Option<V>>>
{
let tcx = self.tcx;
let table = UnifyKey::unification_table(self);
let node_a = table.borrow_mut().get(tcx, a_id);
let node_b = table.borrow_mut().get(tcx, b_id);
let node_a: Node<K> = table.borrow_mut().get(tcx, a_id);
let node_b: Node<K> = table.borrow_mut().get(tcx, b_id);
let a_id = node_a.key.clone();
let b_id = node_b.key.clone();
@ -346,14 +354,14 @@ impl<'a,'tcx,V:SimplyUnifiable<'tcx>,K:UnifyKey<'tcx, Option<V>>>
// Integral type keys
impl<'tcx> UnifyKey<'tcx, Option<IntVarValue>> for ty::IntVid {
impl UnifyKey for ty::IntVid {
type Value = Option<IntVarValue>;
fn index(&self) -> uint { self.index as uint }
fn from_index(i: uint) -> ty::IntVid { ty::IntVid { index: i as u32 } }
fn unification_table<'v>(infcx: &'v InferCtxt)
-> &'v RefCell<UnificationTable<ty::IntVid, Option<IntVarValue>>>
{
fn unification_table<'v>(infcx: &'v InferCtxt) -> &'v RefCell<UnificationTable<ty::IntVid>> {
return &infcx.int_unification_table;
}
@ -375,18 +383,18 @@ impl<'tcx> SimplyUnifiable<'tcx> for IntVarValue {
}
}
impl<'tcx> UnifyValue<'tcx> for Option<IntVarValue> { }
impl UnifyValue for Option<IntVarValue> { }
// Floating point type keys
impl<'tcx> UnifyKey<'tcx, Option<ast::FloatTy>> for ty::FloatVid {
impl UnifyKey for ty::FloatVid {
type Value = Option<ast::FloatTy>;
fn index(&self) -> uint { self.index as uint }
fn from_index(i: uint) -> ty::FloatVid { ty::FloatVid { index: i as u32 } }
fn unification_table<'v>(infcx: &'v InferCtxt)
-> &'v RefCell<UnificationTable<ty::FloatVid, Option<ast::FloatTy>>>
{
fn unification_table<'v>(infcx: &'v InferCtxt) -> &'v RefCell<UnificationTable<ty::FloatVid>> {
return &infcx.float_unification_table;
}
@ -395,7 +403,7 @@ impl<'tcx> UnifyKey<'tcx, Option<ast::FloatTy>> for ty::FloatVid {
}
}
impl<'tcx> UnifyValue<'tcx> for Option<ast::FloatTy> {
impl UnifyValue for Option<ast::FloatTy> {
}
impl<'tcx> SimplyUnifiable<'tcx> for ast::FloatTy {
@ -407,12 +415,3 @@ impl<'tcx> SimplyUnifiable<'tcx> for ast::FloatTy {
ty::terr_float_mismatch(err)
}
}
impl<'tcx, K:Repr<'tcx>, V:Repr<'tcx>> Repr<'tcx> for VarValue<K,V> {
fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String {
match *self {
Redirect(ref k) => format!("Redirect({})", k.repr(tcx)),
Root(ref v, r) => format!("Root({}, {})", v.repr(tcx), r)
}
}
}

View File

@ -11,24 +11,30 @@
//! A pass that annotates every item and method with its stability level,
//! propagating default levels lexically from parent to children ast nodes.
use session::Session;
use lint;
use middle::ty;
use metadata::csearch;
use syntax::codemap::Span;
use syntax::parse::token::InternedString;
use syntax::codemap::{Span, DUMMY_SP};
use syntax::{attr, visit};
use syntax::ast;
use syntax::ast::{Attribute, Block, Crate, DefId, FnDecl, NodeId, Variant};
use syntax::ast::{Item, RequiredMethod, ProvidedMethod, TraitItem};
use syntax::ast::{TypeMethod, Method, Generics, StructField, TypeTraitItem};
use syntax::ast_util::is_local;
use syntax::attr::Stability;
use syntax::attr::{Stability, AttrMetaMethods};
use syntax::visit::{FnKind, FkMethod, Visitor};
use util::nodemap::{NodeMap, DefIdMap};
use syntax::feature_gate::emit_feature_warn;
use util::nodemap::{NodeMap, DefIdMap, FnvHashSet, FnvHashMap};
use util::ppaux::Repr;
use std::mem::replace;
/// A stability index, giving the stability level for items and methods.
pub struct Index {
// Indicates whether this crate has #![feature(staged_api)]
staged_api: bool,
// stability for crate-local items; unmarked stability == no entry
local: NodeMap<Stability>,
// cache for extern-crate items; unmarked stability == entry with None
@ -36,23 +42,24 @@ pub struct Index {
}
// A private tree-walker for producing an Index.
struct Annotator {
struct Annotator<'a> {
sess: &'a Session,
index: Index,
parent: Option<Stability>
}
impl Annotator {
impl<'a> Annotator<'a> {
// Determine the stability for a node based on its attributes and inherited
// stability. The stability is recorded in the index and used as the parent.
fn annotate<F>(&mut self, id: NodeId, use_parent: bool,
attrs: &Vec<Attribute>, f: F) where
attrs: &Vec<Attribute>, item_sp: Span, f: F) where
F: FnOnce(&mut Annotator),
{
match attr::find_stability(attrs.as_slice()) {
match attr::find_stability(self.sess.diagnostic(), attrs.as_slice(), item_sp) {
Some(stab) => {
self.index.local.insert(id, stab.clone());
// Don't inherit #[stable]
// Don't inherit #[stable(feature = "rust1", since = "1.0.0")]
if stab.level != attr::Stable {
let parent = replace(&mut self.parent, Some(stab));
f(self);
@ -71,7 +78,7 @@ impl Annotator {
}
}
impl<'v> Visitor<'v> for Annotator {
impl<'a, 'v> Visitor<'v> for Annotator<'a> {
fn visit_item(&mut self, i: &Item) {
// FIXME (#18969): the following is a hack around the fact
// that we cannot currently annotate the stability of
@ -86,72 +93,276 @@ impl<'v> Visitor<'v> for Annotator {
_ => true,
};
self.annotate(i.id, use_parent, &i.attrs, |v| visit::walk_item(v, i));
self.annotate(i.id, use_parent, &i.attrs, i.span, |v| visit::walk_item(v, i));
if let ast::ItemStruct(ref sd, _) = i.node {
sd.ctor_id.map(|id| {
self.annotate(id, true, &i.attrs, |_| {})
self.annotate(id, true, &i.attrs, i.span, |_| {})
});
}
}
fn visit_fn(&mut self, fk: FnKind<'v>, _: &'v FnDecl,
_: &'v Block, _: Span, _: NodeId) {
_: &'v Block, sp: Span, _: NodeId) {
if let FkMethod(_, _, meth) = fk {
// Methods are not already annotated, so we annotate it
self.annotate(meth.id, true, &meth.attrs, |_| {});
self.annotate(meth.id, true, &meth.attrs, sp, |_| {});
}
// Items defined in a function body have no reason to have
// a stability attribute, so we don't recurse.
}
fn visit_trait_item(&mut self, t: &TraitItem) {
let (id, attrs) = match *t {
RequiredMethod(TypeMethod {id, ref attrs, ..}) => (id, attrs),
let (id, attrs, sp) = match *t {
RequiredMethod(TypeMethod {id, ref attrs, span, ..}) => (id, attrs, span),
// work around lack of pattern matching for @ types
ProvidedMethod(ref method) => {
match **method {
Method {ref attrs, id, ..} => (id, attrs),
Method {ref attrs, id, span, ..} => (id, attrs, span),
}
}
TypeTraitItem(ref typedef) => (typedef.ty_param.id, &typedef.attrs),
TypeTraitItem(ref typedef) => (typedef.ty_param.id, &typedef.attrs,
typedef.ty_param.span),
};
self.annotate(id, true, attrs, |v| visit::walk_trait_item(v, t));
self.annotate(id, true, attrs, sp, |v| visit::walk_trait_item(v, t));
}
fn visit_variant(&mut self, var: &Variant, g: &'v Generics) {
self.annotate(var.node.id, true, &var.node.attrs,
self.annotate(var.node.id, true, &var.node.attrs, var.span,
|v| visit::walk_variant(v, var, g))
}
fn visit_struct_field(&mut self, s: &StructField) {
self.annotate(s.node.id, true, &s.node.attrs,
self.annotate(s.node.id, true, &s.node.attrs, s.span,
|v| visit::walk_struct_field(v, s));
}
fn visit_foreign_item(&mut self, i: &ast::ForeignItem) {
self.annotate(i.id, true, &i.attrs, |_| {});
self.annotate(i.id, true, &i.attrs, i.span, |_| {});
}
}
impl Index {
/// Construct the stability index for a crate being compiled.
pub fn build(krate: &Crate) -> Index {
pub fn build(sess: &Session, krate: &Crate) -> Index {
let mut staged_api = false;
for attr in krate.attrs.iter() {
if attr.name().get() == "staged_api" {
match attr.node.value.node {
ast::MetaWord(_) => {
attr::mark_used(attr);
staged_api = true;
}
_ => (/*pass*/)
}
}
}
let index = Index {
staged_api: staged_api,
local: NodeMap(),
extern_cache: DefIdMap()
};
if !staged_api {
return index;
}
let mut annotator = Annotator {
index: Index {
local: NodeMap(),
extern_cache: DefIdMap()
},
sess: sess,
index: index,
parent: None
};
annotator.annotate(ast::CRATE_NODE_ID, true, &krate.attrs,
annotator.annotate(ast::CRATE_NODE_ID, true, &krate.attrs, krate.span,
|v| visit::walk_crate(v, krate));
annotator.index
}
}
/// Cross-references the feature names of unstable APIs with enabled
/// features and possibly prints errors. Returns a list of all
/// features used.
pub fn check_unstable_api_usage(tcx: &ty::ctxt) -> FnvHashSet<InternedString> {
let ref active_lib_features = tcx.sess.features.borrow().lib_features;
// Put the active features into a map for quick lookup
let active_features = active_lib_features.iter().map(|&(ref s, _)| s.clone()).collect();
let mut checker = Checker {
tcx: tcx,
active_features: active_features,
used_features: FnvHashSet()
};
let krate = tcx.map.krate();
visit::walk_crate(&mut checker, krate);
let used_features = checker.used_features;
return used_features;
}
struct Checker<'a, 'tcx: 'a> {
tcx: &'a ty::ctxt<'tcx>,
active_features: FnvHashSet<InternedString>,
used_features: FnvHashSet<InternedString>
}
impl<'a, 'tcx> Checker<'a, 'tcx> {
fn check(&mut self, id: ast::DefId, span: Span, stab: &Option<Stability>) {
// Only the cross-crate scenario matters when checking unstable APIs
let cross_crate = !is_local(id);
if !cross_crate { return }
match *stab {
Some(Stability { level: attr::Unstable, ref feature, ref reason, .. }) => {
self.used_features.insert(feature.clone());
if !self.active_features.contains(feature) {
let msg = match *reason {
Some(ref r) => format!("use of unstable library feature '{}': {}",
feature.get(), r.get()),
None => format!("use of unstable library feature '{}'", feature.get())
};
emit_feature_warn(&self.tcx.sess.parse_sess.span_diagnostic,
feature.get(), span, &msg[]);
}
}
Some(..) => {
// Stable APIs are always ok to call and deprecated APIs are
// handled by a lint.
}
None => {
// This is an 'unmarked' API, which should not exist
// in the standard library.
self.tcx.sess.span_err(span, "use of unmarked library feature");
self.tcx.sess.span_note(span, "this is either a bug in the library you are \
using or a bug in the compiler - there is \
no way to use this feature");
}
}
}
}
impl<'a, 'v, 'tcx> Visitor<'v> for Checker<'a, 'tcx> {
fn visit_item(&mut self, item: &ast::Item) {
check_item(self.tcx, item,
&mut |id, sp, stab| self.check(id, sp, stab));
visit::walk_item(self, item);
}
fn visit_expr(&mut self, ex: &ast::Expr) {
check_expr(self.tcx, ex,
&mut |id, sp, stab| self.check(id, sp, stab));
visit::walk_expr(self, ex);
}
}
/// Helper for discovering nodes to check for stability
pub fn check_item(tcx: &ty::ctxt, item: &ast::Item,
cb: &mut FnMut(ast::DefId, Span, &Option<Stability>)) {
match item.node {
ast::ItemExternCrate(_) => {
// compiler-generated `extern crate` items have a dummy span.
if item.span == DUMMY_SP { return }
let cnum = match tcx.sess.cstore.find_extern_mod_stmt_cnum(item.id) {
Some(cnum) => cnum,
None => return,
};
let id = ast::DefId { krate: cnum, node: ast::CRATE_NODE_ID };
maybe_do_stability_check(tcx, id, item.span, cb);
}
ast::ItemTrait(_, _, ref supertraits, _) => {
for t in supertraits.iter() {
if let ast::TraitTyParamBound(ref t, _) = *t {
let id = ty::trait_ref_to_def_id(tcx, &t.trait_ref);
maybe_do_stability_check(tcx, id, t.trait_ref.path.span, cb);
}
}
}
ast::ItemImpl(_, _, _, Some(ref t), _, _) => {
let id = ty::trait_ref_to_def_id(tcx, t);
maybe_do_stability_check(tcx, id, t.path.span, cb);
}
_ => (/* pass */)
}
}
/// Helper for discovering nodes to check for stability
pub fn check_expr(tcx: &ty::ctxt, e: &ast::Expr,
cb: &mut FnMut(ast::DefId, Span, &Option<Stability>)) {
if is_internal(tcx, e.span) { return; }
let mut span = e.span;
let id = match e.node {
ast::ExprPath(..) | ast::ExprQPath(..) | ast::ExprStruct(..) => {
match tcx.def_map.borrow().get(&e.id) {
Some(&def) => def.def_id(),
None => return
}
}
ast::ExprMethodCall(i, _, _) => {
span = i.span;
let method_call = ty::MethodCall::expr(e.id);
match tcx.method_map.borrow().get(&method_call) {
Some(method) => {
match method.origin {
ty::MethodStatic(def_id) => {
def_id
}
ty::MethodStaticClosure(def_id) => {
def_id
}
ty::MethodTypeParam(ty::MethodParam {
ref trait_ref,
method_num: index,
..
}) |
ty::MethodTraitObject(ty::MethodObject {
ref trait_ref,
method_num: index,
..
}) => {
ty::trait_item(tcx, trait_ref.def_id, index).def_id()
}
}
}
None => return
}
}
_ => return
};
maybe_do_stability_check(tcx, id, span, cb);
}
fn maybe_do_stability_check(tcx: &ty::ctxt, id: ast::DefId, span: Span,
cb: &mut FnMut(ast::DefId, Span, &Option<Stability>)) {
if !is_staged_api(tcx, id) { return }
let ref stability = lookup(tcx, id);
cb(id, span, stability);
}
fn is_internal(tcx: &ty::ctxt, span: Span) -> bool {
tcx.sess.codemap().span_is_internal(span)
}
fn is_staged_api(tcx: &ty::ctxt, id: DefId) -> bool {
match ty::trait_item_of_item(tcx, id) {
Some(ty::MethodTraitItemId(trait_method_id))
if trait_method_id != id => {
is_staged_api(tcx, trait_method_id)
}
_ if is_local(id) => {
tcx.stability.borrow().staged_api
}
_ => {
csearch::is_staged_api(&tcx.sess.cstore, id)
}
}
}
/// Lookup the stability for a node, loading external crate
/// metadata as necessary.
pub fn lookup(tcx: &ty::ctxt, id: DefId) -> Option<Stability> {
@ -190,18 +401,23 @@ pub fn lookup(tcx: &ty::ctxt, id: DefId) -> Option<Stability> {
})
}
pub fn is_staged_api(tcx: &ty::ctxt, id: DefId) -> bool {
match ty::trait_item_of_item(tcx, id) {
Some(ty::MethodTraitItemId(trait_method_id))
if trait_method_id != id => {
is_staged_api(tcx, trait_method_id)
}
_ if is_local(id) => {
// Unused case
unreachable!()
}
_ => {
csearch::is_staged_api(&tcx.sess.cstore, id)
}
/// Given the list of enabled features that were not language features (i.e. that
/// were expected to be library features), and the list of features used from
/// libraries, identify activated features that don't exist and error about them.
pub fn check_unused_features(sess: &Session,
used_lib_features: &FnvHashSet<InternedString>) {
let ref lib_features = sess.features.borrow().lib_features;
let mut active_lib_features: FnvHashMap<InternedString, Span>
= lib_features.clone().into_iter().collect();
for used_feature in used_lib_features.iter() {
active_lib_features.remove(used_feature);
}
for (_, &span) in active_lib_features.iter() {
sess.add_lint(lint::builtin::UNUSED_FEATURES,
ast::CRATE_NODE_ID,
span,
"unused or unknown feature".to_string());
}
}

View File

@ -408,7 +408,7 @@ fn note_obligation_cause_code<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
}
ObligationCauseCode::CompareImplMethodObligation => {
span_note!(tcx.sess, cause_span,
"the requirement `{}` appears on the impl method\
"the requirement `{}` appears on the impl method \
but not on the corresponding trait method",
predicate.user_string(infcx.tcx));
}

View File

@ -394,7 +394,7 @@ fn process_predicate<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx>,
ty::Predicate::Projection(ref data) => {
let project_obligation = obligation.with(data.clone());
let result = project::poly_project_and_unify_type(selcx, &project_obligation);
debug!("poly_project_and_unify_type({}) = {}",
debug!("process_predicate: poly_project_and_unify_type({}) returned {}",
project_obligation.repr(tcx),
result.repr(tcx));
match result {

View File

@ -18,7 +18,7 @@ pub use self::ObligationCauseCode::*;
use middle::mem_categorization::Typer;
use middle::subst;
use middle::ty::{self, Ty};
use middle::infer::InferCtxt;
use middle::infer::{self, InferCtxt};
use std::slice::Iter;
use std::rc::Rc;
use syntax::ast;
@ -392,6 +392,65 @@ pub fn type_known_to_meet_builtin_bound<'a,'tcx>(infcx: &InferCtxt<'a,'tcx>,
}
}
pub fn normalize_param_env_or_error<'a,'tcx>(unnormalized_env: ty::ParameterEnvironment<'a,'tcx>,
cause: ObligationCause<'tcx>)
-> ty::ParameterEnvironment<'a,'tcx>
{
match normalize_param_env(&unnormalized_env, cause) {
Ok(p) => p,
Err(errors) => {
// I'm not wild about reporting errors here; I'd prefer to
// have the errors get reported at a defined place (e.g.,
// during typeck). Instead I have all parameter
// environments, in effect, going through this function
// and hence potentially reporting errors. This ensurse of
// course that we never forget to normalize (the
// alternative seemed like it would involve a lot of
// manual invocations of this fn -- and then we'd have to
// deal with the errors at each of those sites).
//
// In any case, in practice, typeck constructs all the
// parameter environments once for every fn as it goes,
// and errors will get reported then; so after typeck we
// can be sure that no errors should occur.
let infcx = infer::new_infer_ctxt(unnormalized_env.tcx);
report_fulfillment_errors(&infcx, &errors);
// Normalized failed? use what they gave us, it's better than nothing.
unnormalized_env
}
}
}
pub fn normalize_param_env<'a,'tcx>(param_env: &ty::ParameterEnvironment<'a,'tcx>,
cause: ObligationCause<'tcx>)
-> Result<ty::ParameterEnvironment<'a,'tcx>,
Vec<FulfillmentError<'tcx>>>
{
let tcx = param_env.tcx;
debug!("normalize_param_env(param_env={})",
param_env.repr(tcx));
let predicates: Vec<ty::Predicate<'tcx>> = {
let infcx = infer::new_infer_ctxt(tcx);
let mut selcx = &mut SelectionContext::new(&infcx, param_env);
let mut fulfill_cx = FulfillmentContext::new();
let Normalized { value: predicates, obligations } =
project::normalize(selcx, cause, &param_env.caller_bounds);
for obligation in obligations.into_iter() {
fulfill_cx.register_predicate_obligation(selcx.infcx(), obligation);
}
try!(fulfill_cx.select_all_or_error(selcx.infcx(), param_env));
predicates.iter().map(|p| infcx.resolve_type_vars_if_possible(p)).collect()
};
debug!("normalize_param_env: predicates={}",
predicates.repr(tcx));
Ok(param_env.with_caller_bounds(predicates))
}
impl<'tcx,O> Obligation<'tcx,O> {
pub fn new(cause: ObligationCause<'tcx>,
trait_ref: O)

View File

@ -122,17 +122,15 @@ fn trait_has_sized_self<'tcx>(tcx: &ty::ctxt<'tcx>,
trait_def_id: ast::DefId)
-> bool
{
let trait_def = ty::lookup_trait_def(tcx, trait_def_id);
let param_env = ty::construct_parameter_environment(tcx,
&trait_def.generics,
ast::DUMMY_NODE_ID);
let predicates = param_env.caller_bounds.predicates.as_slice().to_vec();
let sized_def_id = match tcx.lang_items.sized_trait() {
Some(def_id) => def_id,
None => { return false; /* No Sized trait, can't require it! */ }
};
// Search for a predicate like `Self : Sized` amongst the trait bounds.
let trait_def = ty::lookup_trait_def(tcx, trait_def_id);
let free_substs = ty::construct_free_substs(tcx, &trait_def.generics, ast::DUMMY_NODE_ID);
let predicates = trait_def.generics.to_bounds(tcx, &free_substs).predicates.into_vec();
elaborate_predicates(tcx, predicates)
.any(|predicate| {
match predicate {

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