Skip to content

Commit 007651c

Browse files
committed
Require documentation by default for libstd
Adds documentation for various things that I understand. Adds #[allow(missing_doc)] for lots of things that I don't understand.
1 parent 4a5d887 commit 007651c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+699
-69
lines changed

src/libstd/at_vec.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ pub fn build_sized_opt<A>(size: Option<uint>,
101101
}
102102

103103
// Appending
104+
105+
/// Iterates over the `rhs` vector, copying each element and appending it to the
106+
/// `lhs`. Afterwards, the `lhs` is then returned for use again.
104107
#[inline(always)]
105108
pub fn append<T:Copy>(lhs: @[T], rhs: &const [T]) -> @[T] {
106109
do build_sized(lhs.len() + rhs.len()) |push| {
@@ -211,6 +214,9 @@ pub mod raw {
211214
(**repr).unboxed.fill = new_len * sys::size_of::<T>();
212215
}
213216

217+
/**
218+
* Pushes a new value onto this vector.
219+
*/
214220
#[inline(always)]
215221
pub unsafe fn push<T>(v: &mut @[T], initval: T) {
216222
let repr: **VecRepr = transmute_copy(&v);
@@ -223,7 +229,7 @@ pub mod raw {
223229
}
224230

225231
#[inline(always)] // really pretty please
226-
pub unsafe fn push_fast<T>(v: &mut @[T], initval: T) {
232+
unsafe fn push_fast<T>(v: &mut @[T], initval: T) {
227233
let repr: **mut VecRepr = ::cast::transmute(v);
228234
let fill = (**repr).unboxed.fill;
229235
(**repr).unboxed.fill += sys::size_of::<T>();
@@ -232,7 +238,7 @@ pub mod raw {
232238
move_val_init(&mut(*p), initval);
233239
}
234240

235-
pub unsafe fn push_slow<T>(v: &mut @[T], initval: T) {
241+
unsafe fn push_slow<T>(v: &mut @[T], initval: T) {
236242
reserve_at_least(&mut *v, v.len() + 1u);
237243
push_fast(v, initval);
238244
}

src/libstd/cast.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
2727
dest
2828
}
2929

30+
/// Casts the value at `src` to U. The two types must have the same length.
3031
#[cfg(target_word_size = "32", not(stage0))]
3132
#[inline(always)]
3233
pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
@@ -37,6 +38,7 @@ pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
3738
dest
3839
}
3940

41+
/// Casts the value at `src` to U. The two types must have the same length.
4042
#[cfg(target_word_size = "64", not(stage0))]
4143
#[inline(always)]
4244
pub unsafe fn transmute_copy<T, U>(src: &T) -> U {

src/libstd/cell.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Similar to a mutable option type, but friendlier.
2323

2424
#[mutable]
2525
#[deriving(Clone, DeepClone, Eq)]
26+
#[allow(missing_doc)]
2627
pub struct Cell<T> {
2728
priv value: Option<T>
2829
}
@@ -32,6 +33,7 @@ pub fn Cell<T>(value: T) -> Cell<T> {
3233
Cell { value: Some(value) }
3334
}
3435

36+
/// Creates a new empty cell with no value inside.
3537
pub fn empty_cell<T>() -> Cell<T> {
3638
Cell { value: None }
3739
}

src/libstd/char.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,12 @@ use cmp::{Eq, Ord};
5353
Cn Unassigned a reserved unassigned code point or a noncharacter
5454
*/
5555

56+
/// Returns whether the specified character is considered a unicode alphabetic
57+
/// character
5658
pub fn is_alphabetic(c: char) -> bool { derived_property::Alphabetic(c) }
59+
#[allow(missing_doc)]
5760
pub fn is_XID_start(c: char) -> bool { derived_property::XID_Start(c) }
61+
#[allow(missing_doc)]
5862
pub fn is_XID_continue(c: char) -> bool { derived_property::XID_Continue(c) }
5963

6064
///
@@ -256,6 +260,7 @@ pub fn len_utf8_bytes(c: char) -> uint {
256260
)
257261
}
258262

263+
#[allow(missing_doc)]
259264
pub trait Char {
260265
fn is_alphabetic(&self) -> bool;
261266
fn is_XID_start(&self) -> bool;

src/libstd/clone.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ by convention implementing the `Clone` trait and calling the
2424

2525
use core::kinds::Const;
2626

27+
/// A common trait for cloning an object.
2728
pub trait Clone {
2829
/// Returns a copy of the value. The contents of owned pointers
2930
/// are copied to maintain uniqueness, while the contents of
@@ -85,6 +86,8 @@ clone_impl!(())
8586
clone_impl!(bool)
8687
clone_impl!(char)
8788

89+
/// A trait distinct from `Clone` which represents "deep copies" of things like
90+
/// managed boxes which would otherwise not be copied.
8891
pub trait DeepClone {
8992
/// Return a deep copy of the value. Unlike `Clone`, the contents of shared pointer types
9093
/// *are* copied. Note that this is currently unimplemented for managed boxes, as

src/libstd/cmp.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ and `Eq` to overload the `==` and `!=` operators.
2020
2121
*/
2222

23+
#[allow(missing_doc)];
24+
2325
/**
2426
* Trait for values that can be compared for equality and inequality.
2527
*

src/libstd/comm.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
Message passing
1313
*/
1414

15+
#[allow(missing_doc)];
16+
1517
use cast::{transmute, transmute_mut};
1618
use container::Container;
1719
use either::{Either, Left, Right};

src/libstd/condition.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
/*! Condition handling */
1212

13+
#[allow(missing_doc)];
14+
1315
use local_data::{local_data_pop, local_data_set};
1416
use local_data;
1517
use prelude::*;

src/libstd/container.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
1313
use option::Option;
1414

15+
/// A trait to represent the abstract idea of a container. The only concrete
16+
/// knowledge known is the number of elements contained within.
1517
pub trait Container {
1618
/// Return the number of elements in the container
1719
fn len(&const self) -> uint;
@@ -20,16 +22,19 @@ pub trait Container {
2022
fn is_empty(&const self) -> bool;
2123
}
2224

25+
/// A trait to represent mutable containers
2326
pub trait Mutable: Container {
2427
/// Clear the container, removing all values.
2528
fn clear(&mut self);
2629
}
2730

31+
/// A map is a key-value store where values may be looked up by their keys. This
32+
/// trait provides basic operations to operate on these stores.
2833
pub trait Map<K, V>: Mutable {
2934
/// Return true if the map contains a value for the specified key
3035
fn contains_key(&self, key: &K) -> bool;
3136

32-
// Visits all keys and values
37+
/// Visits all keys and values
3338
fn each<'a>(&'a self, f: &fn(&K, &'a V) -> bool) -> bool;
3439

3540
/// Visit all keys
@@ -65,6 +70,9 @@ pub trait Map<K, V>: Mutable {
6570
fn pop(&mut self, k: &K) -> Option<V>;
6671
}
6772

73+
/// A set is a group of objects which are each distinct from one another. This
74+
/// trait represents actions which can be performed on sets to manipulate and
75+
/// iterate over them.
6876
pub trait Set<T>: Mutable {
6977
/// Return true if the set contains a value
7078
fn contains(&self, value: &T) -> bool;

src/libstd/core.rc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,15 @@ they contained the following prologue:
5656
#[license = "MIT/ASL2"];
5757
#[crate_type = "lib"];
5858

59+
// NOTE: remove these two attributes after the next snapshot
60+
#[no_core]; // for stage0
61+
#[allow(unrecognized_lint)]; // otherwise stage0 is seriously ugly
5962

6063
// Don't link to std. We are std.
61-
#[no_core]; // for stage0
6264
#[no_std];
6365

6466
#[deny(non_camel_case_types)];
67+
#[deny(missing_doc)];
6568

6669
// Make core testable by not duplicating lang items. See #2912
6770
#[cfg(test)] extern mod realstd(name = "std");

src/libstd/from_str.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
1313
use option::Option;
1414

15+
/// A trait to abstract the idea of creating a new instance of a type from a
16+
/// string.
1517
pub trait FromStr {
18+
/// Parses a string `s` to return an optional value of this type. If the
19+
/// string is ill-formatted, the None is returned.
1620
fn from_str(s: &str) -> Option<Self>;
1721
}

src/libstd/hash.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* CPRNG like rand::rng.
2020
*/
2121

22+
#[allow(missing_doc)];
23+
2224
use container::Container;
2325
use old_iter::BaseIter;
2426
use rt::io::Writer;

src/libstd/hashmap.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ struct Bucket<K,V> {
3434
value: V,
3535
}
3636

37+
/// A hash map implementation which uses linear probing along with the SipHash
38+
/// hash function for internal state. This means that the order of all hash maps
39+
/// is randomized by keying each hash map randomly on creation.
40+
///
41+
/// It is required that the keys implement the `Eq` and `Hash` traits, although
42+
/// this can frequently be achieved by just implementing the `Eq` and
43+
/// `IterBytes` traits as `Hash` is automatically implemented for types that
44+
/// implement `IterBytes`.
3745
pub struct HashMap<K,V> {
3846
priv k0: u64,
3947
priv k1: u64,
@@ -53,6 +61,7 @@ fn resize_at(capacity: uint) -> uint {
5361
((capacity as float) * 3. / 4.) as uint
5462
}
5563

64+
/// Creates a new hash map with the specified capacity.
5665
pub fn linear_map_with_capacity<K:Eq + Hash,V>(
5766
initial_capacity: uint) -> HashMap<K, V> {
5867
let mut r = rand::task_rng();
@@ -539,6 +548,9 @@ impl<K:Hash + Eq,V:Eq> Eq for HashMap<K, V> {
539548
fn ne(&self, other: &HashMap<K, V>) -> bool { !self.eq(other) }
540549
}
541550

551+
/// An implementation of a hash set using the underlying representation of a
552+
/// HashMap where the value is (). As with the `HashMap` type, a `HashSet`
553+
/// requires that the elements implement the `Eq` and `Hash` traits.
542554
pub struct HashSet<T> {
543555
priv map: HashMap<T, ()>
544556
}

src/libstd/io.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ implement `Reader` and `Writer`, where appropriate.
4444
4545
*/
4646

47+
#[allow(missing_doc)];
48+
4749
use result::Result;
4850

4951
use container::Container;

src/libstd/iter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ use vec::OwnedVector;
4646
use num::{One, Zero};
4747
use ops::{Add, Mul};
4848

49+
#[allow(missing_doc)]
4950
pub trait Times {
5051
fn times(&self, it: &fn() -> bool) -> bool;
5152
}

0 commit comments

Comments
 (0)