Skip to content

Commit 720735b

Browse files
committed
Auto merge of #25588 - bluss:doc-string-from, r=alexcrichton
Use stable code in doc examples (libcollections) Main task is to change from String::from_str to String::from in examples for String (the latter constructor is stable). While I'm at it, also remove redundant feature flags, fix some other instances of unstable code in examples (in examples for stable methods), and remove some use of usize in examples too.
2 parents f6b446f + 93701b3 commit 720735b

File tree

8 files changed

+22
-64
lines changed

8 files changed

+22
-64
lines changed

src/liballoc/rc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
//! and have the `Owner` remain allocated as long as any `Gadget` points at it.
3333
//!
3434
//! ```rust
35-
//! # #![feature(alloc, collections)]
35+
//! # #![feature(alloc)]
3636
//! use std::rc::Rc;
3737
//!
3838
//! struct Owner {
@@ -49,7 +49,7 @@
4949
//! fn main() {
5050
//! // Create a reference counted Owner.
5151
//! let gadget_owner : Rc<Owner> = Rc::new(
52-
//! Owner { name: String::from_str("Gadget Man") }
52+
//! Owner { name: String::from("Gadget Man") }
5353
//! );
5454
//!
5555
//! // Create Gadgets belonging to gadget_owner. To increment the reference

src/libcollections/btree/map.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1291,14 +1291,13 @@ impl<K, V> BTreeMap<K, V> {
12911291
/// # Examples
12921292
///
12931293
/// ```
1294-
/// # #![feature(core)]
12951294
/// use std::collections::BTreeMap;
12961295
///
12971296
/// let mut a = BTreeMap::new();
12981297
/// a.insert(1, "a");
12991298
/// a.insert(2, "b");
13001299
///
1301-
/// let keys: Vec<usize> = a.keys().cloned().collect();
1300+
/// let keys: Vec<_> = a.keys().cloned().collect();
13021301
/// assert_eq!(keys, [1, 2]);
13031302
/// ```
13041303
#[stable(feature = "rust1", since = "1.0.0")]
@@ -1314,7 +1313,6 @@ impl<K, V> BTreeMap<K, V> {
13141313
/// # Examples
13151314
///
13161315
/// ```
1317-
/// # #![feature(core)]
13181316
/// use std::collections::BTreeMap;
13191317
///
13201318
/// let mut a = BTreeMap::new();
@@ -1555,7 +1553,6 @@ impl<K: Ord, V> BTreeMap<K, V> {
15551553
/// # Examples
15561554
///
15571555
/// ```
1558-
/// # #![feature(collections)]
15591556
/// use std::collections::BTreeMap;
15601557
///
15611558
/// let mut count: BTreeMap<&str, usize> = BTreeMap::new();

src/libcollections/btree/set.rs

+6-16
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ impl<T> BTreeSet<T> {
115115
/// # Examples
116116
///
117117
/// ```
118-
/// # #![feature(core)]
119118
/// use std::collections::BTreeSet;
120119
///
121120
/// let set: BTreeSet<usize> = [1, 2, 3, 4].iter().cloned().collect();
@@ -124,7 +123,7 @@ impl<T> BTreeSet<T> {
124123
/// println!("{}", x);
125124
/// }
126125
///
127-
/// let v: Vec<usize> = set.iter().cloned().collect();
126+
/// let v: Vec<_> = set.iter().cloned().collect();
128127
/// assert_eq!(v, [1, 2, 3, 4]);
129128
/// ```
130129
#[stable(feature = "rust1", since = "1.0.0")]
@@ -171,7 +170,6 @@ impl<T: Ord> BTreeSet<T> {
171170
/// # Examples
172171
///
173172
/// ```
174-
/// # #![feature(core)]
175173
/// use std::collections::BTreeSet;
176174
///
177175
/// let mut a = BTreeSet::new();
@@ -182,7 +180,7 @@ impl<T: Ord> BTreeSet<T> {
182180
/// b.insert(2);
183181
/// b.insert(3);
184182
///
185-
/// let diff: Vec<usize> = a.difference(&b).cloned().collect();
183+
/// let diff: Vec<_> = a.difference(&b).cloned().collect();
186184
/// assert_eq!(diff, [1]);
187185
/// ```
188186
#[stable(feature = "rust1", since = "1.0.0")]
@@ -195,7 +193,6 @@ impl<T: Ord> BTreeSet<T> {
195193
/// # Examples
196194
///
197195
/// ```
198-
/// # #![feature(core)]
199196
/// use std::collections::BTreeSet;
200197
///
201198
/// let mut a = BTreeSet::new();
@@ -206,7 +203,7 @@ impl<T: Ord> BTreeSet<T> {
206203
/// b.insert(2);
207204
/// b.insert(3);
208205
///
209-
/// let sym_diff: Vec<usize> = a.symmetric_difference(&b).cloned().collect();
206+
/// let sym_diff: Vec<_> = a.symmetric_difference(&b).cloned().collect();
210207
/// assert_eq!(sym_diff, [1, 3]);
211208
/// ```
212209
#[stable(feature = "rust1", since = "1.0.0")]
@@ -220,7 +217,6 @@ impl<T: Ord> BTreeSet<T> {
220217
/// # Examples
221218
///
222219
/// ```
223-
/// # #![feature(core)]
224220
/// use std::collections::BTreeSet;
225221
///
226222
/// let mut a = BTreeSet::new();
@@ -231,7 +227,7 @@ impl<T: Ord> BTreeSet<T> {
231227
/// b.insert(2);
232228
/// b.insert(3);
233229
///
234-
/// let intersection: Vec<usize> = a.intersection(&b).cloned().collect();
230+
/// let intersection: Vec<_> = a.intersection(&b).cloned().collect();
235231
/// assert_eq!(intersection, [2]);
236232
/// ```
237233
#[stable(feature = "rust1", since = "1.0.0")]
@@ -245,7 +241,6 @@ impl<T: Ord> BTreeSet<T> {
245241
/// # Examples
246242
///
247243
/// ```
248-
/// # #![feature(core)]
249244
/// use std::collections::BTreeSet;
250245
///
251246
/// let mut a = BTreeSet::new();
@@ -254,7 +249,7 @@ impl<T: Ord> BTreeSet<T> {
254249
/// let mut b = BTreeSet::new();
255250
/// b.insert(2);
256251
///
257-
/// let union: Vec<usize> = a.union(&b).cloned().collect();
252+
/// let union: Vec<_> = a.union(&b).cloned().collect();
258253
/// assert_eq!(union, [1, 2]);
259254
/// ```
260255
#[stable(feature = "rust1", since = "1.0.0")]
@@ -318,7 +313,6 @@ impl<T: Ord> BTreeSet<T> {
318313
/// # Examples
319314
///
320315
/// ```
321-
/// # #![feature(core)]
322316
/// use std::collections::BTreeSet;
323317
///
324318
/// let set: BTreeSet<_> = [1, 2, 3].iter().cloned().collect();
@@ -336,7 +330,6 @@ impl<T: Ord> BTreeSet<T> {
336330
/// # Examples
337331
///
338332
/// ```
339-
/// # #![feature(core)]
340333
/// use std::collections::BTreeSet;
341334
///
342335
/// let a: BTreeSet<_> = [1, 2, 3].iter().cloned().collect();
@@ -358,7 +351,6 @@ impl<T: Ord> BTreeSet<T> {
358351
/// # Examples
359352
///
360353
/// ```
361-
/// # #![feature(core)]
362354
/// use std::collections::BTreeSet;
363355
///
364356
/// let sup: BTreeSet<_> = [1, 2, 3].iter().cloned().collect();
@@ -401,7 +393,6 @@ impl<T: Ord> BTreeSet<T> {
401393
/// # Examples
402394
///
403395
/// ```
404-
/// # #![feature(core)]
405396
/// use std::collections::BTreeSet;
406397
///
407398
/// let sub: BTreeSet<_> = [1, 2].iter().cloned().collect();
@@ -483,12 +474,11 @@ impl<T> IntoIterator for BTreeSet<T> {
483474
/// # Examples
484475
///
485476
/// ```
486-
/// # #![feature(core)]
487477
/// use std::collections::BTreeSet;
488478
///
489479
/// let set: BTreeSet<usize> = [1, 2, 3, 4].iter().cloned().collect();
490480
///
491-
/// let v: Vec<usize> = set.into_iter().collect();
481+
/// let v: Vec<_> = set.into_iter().collect();
492482
/// assert_eq!(v, [1, 2, 3, 4]);
493483
/// ```
494484
fn into_iter(self) -> IntoIter<T> {

src/libcollections/linked_list.rs

-5
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ impl<T> LinkedList<T> {
230230
/// # Examples
231231
///
232232
/// ```
233-
/// # #![feature(collections)]
234233
/// use std::collections::LinkedList;
235234
///
236235
/// let mut a = LinkedList::new();
@@ -473,7 +472,6 @@ impl<T> LinkedList<T> {
473472
/// # Examples
474473
///
475474
/// ```
476-
/// # #![feature(collections)]
477475
/// use std::collections::LinkedList;
478476
///
479477
/// let mut dl = LinkedList::new();
@@ -521,7 +519,6 @@ impl<T> LinkedList<T> {
521519
/// # Examples
522520
///
523521
/// ```
524-
/// # #![feature(collections)]
525522
/// use std::collections::LinkedList;
526523
///
527524
/// let mut d = LinkedList::new();
@@ -540,7 +537,6 @@ impl<T> LinkedList<T> {
540537
/// # Examples
541538
///
542539
/// ```
543-
/// # #![feature(collections)]
544540
/// use std::collections::LinkedList;
545541
///
546542
/// let mut d = LinkedList::new();
@@ -566,7 +562,6 @@ impl<T> LinkedList<T> {
566562
/// # Examples
567563
///
568564
/// ```
569-
/// # #![feature(collections)]
570565
/// use std::collections::LinkedList;
571566
///
572567
/// let mut d = LinkedList::new();

src/libcollections/slice.rs

-2
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,6 @@ impl<T> [T] {
529529
/// found; the fourth could match any position in `[1,4]`.
530530
///
531531
/// ```rust
532-
/// # #![feature(core)]
533532
/// let s = [0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55];
534533
///
535534
/// let seek = 13;
@@ -865,7 +864,6 @@ impl<T> [T] {
865864
/// found; the fourth could match any position in `[1,4]`.
866865
///
867866
/// ```rust
868-
/// # #![feature(core)]
869867
/// let s = [0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55];
870868
///
871869
/// assert_eq!(s.binary_search(&13), Ok(9));

src/libcollections/string.rs

+9-21
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,6 @@ impl String {
121121
/// # Examples
122122
///
123123
/// ```
124-
/// # #![feature(core)]
125-
/// use std::str::Utf8Error;
126-
///
127124
/// let hello_vec = vec![104, 101, 108, 108, 111];
128125
/// let s = String::from_utf8(hello_vec).unwrap();
129126
/// assert_eq!(s, "hello");
@@ -346,8 +343,7 @@ impl String {
346343
/// # Examples
347344
///
348345
/// ```
349-
/// # #![feature(collections)]
350-
/// let s = String::from_str("hello");
346+
/// let s = String::from("hello");
351347
/// let bytes = s.into_bytes();
352348
/// assert_eq!(bytes, [104, 101, 108, 108, 111]);
353349
/// ```
@@ -370,8 +366,7 @@ impl String {
370366
/// # Examples
371367
///
372368
/// ```
373-
/// # #![feature(collections)]
374-
/// let mut s = String::from_str("foo");
369+
/// let mut s = String::from("foo");
375370
/// s.push_str("bar");
376371
/// assert_eq!(s, "foobar");
377372
/// ```
@@ -447,8 +442,7 @@ impl String {
447442
/// # Examples
448443
///
449444
/// ```
450-
/// # #![feature(collections)]
451-
/// let mut s = String::from_str("foo");
445+
/// let mut s = String::from("foo");
452446
/// s.reserve(100);
453447
/// assert!(s.capacity() >= 100);
454448
/// s.shrink_to_fit();
@@ -465,8 +459,7 @@ impl String {
465459
/// # Examples
466460
///
467461
/// ```
468-
/// # #![feature(collections)]
469-
/// let mut s = String::from_str("abc");
462+
/// let mut s = String::from("abc");
470463
/// s.push('1');
471464
/// s.push('2');
472465
/// s.push('3');
@@ -501,8 +494,7 @@ impl String {
501494
/// # Examples
502495
///
503496
/// ```
504-
/// # #![feature(collections)]
505-
/// let s = String::from_str("hello");
497+
/// let s = String::from("hello");
506498
/// let b: &[_] = &[104, 101, 108, 108, 111];
507499
/// assert_eq!(s.as_bytes(), b);
508500
/// ```
@@ -522,8 +514,7 @@ impl String {
522514
/// # Examples
523515
///
524516
/// ```
525-
/// # #![feature(collections)]
526-
/// let mut s = String::from_str("hello");
517+
/// let mut s = String::from("hello");
527518
/// s.truncate(2);
528519
/// assert_eq!(s, "he");
529520
/// ```
@@ -540,8 +531,7 @@ impl String {
540531
/// # Examples
541532
///
542533
/// ```
543-
/// # #![feature(collections)]
544-
/// let mut s = String::from_str("foo");
534+
/// let mut s = String::from("foo");
545535
/// assert_eq!(s.pop(), Some('o'));
546536
/// assert_eq!(s.pop(), Some('o'));
547537
/// assert_eq!(s.pop(), Some('f'));
@@ -578,8 +568,7 @@ impl String {
578568
/// # Examples
579569
///
580570
/// ```
581-
/// # #![feature(collections)]
582-
/// let mut s = String::from_str("foo");
571+
/// let mut s = String::from("foo");
583572
/// assert_eq!(s.remove(0), 'f');
584573
/// assert_eq!(s.remove(1), 'o');
585574
/// assert_eq!(s.remove(0), 'o');
@@ -641,8 +630,7 @@ impl String {
641630
/// # Examples
642631
///
643632
/// ```
644-
/// # #![feature(collections)]
645-
/// let mut s = String::from_str("hello");
633+
/// let mut s = String::from("hello");
646634
/// unsafe {
647635
/// let vec = s.as_mut_vec();
648636
/// assert!(vec == &[104, 101, 108, 108, 111]);

src/libcollections/vec.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ static MAX_MEMORY_SIZE: usize = isize::MAX as usize;
9191
/// # Examples
9292
///
9393
/// ```
94-
/// # #![feature(collections)]
9594
/// let mut vec = Vec::new();
9695
/// vec.push(1);
9796
/// vec.push(2);
@@ -105,9 +104,9 @@ static MAX_MEMORY_SIZE: usize = isize::MAX as usize;
105104
/// vec[0] = 7;
106105
/// assert_eq!(vec[0], 7);
107106
///
108-
/// vec.push_all(&[1, 2, 3]);
107+
/// vec.extend([1, 2, 3].iter().cloned());
109108
///
110-
/// for x in vec.iter() {
109+
/// for x in &vec {
111110
/// println!("{}", x);
112111
/// }
113112
/// assert_eq!(vec, [7, 1, 2, 3]);
@@ -369,9 +368,8 @@ impl<T> Vec<T> {
369368
/// # Examples
370369
///
371370
/// ```
372-
/// # #![feature(collections)]
373371
/// let mut vec = Vec::with_capacity(10);
374-
/// vec.push_all(&[1, 2, 3]);
372+
/// vec.extend([1, 2, 3].iter().cloned());
375373
/// assert_eq!(vec.capacity(), 10);
376374
/// vec.shrink_to_fit();
377375
/// assert!(vec.capacity() >= 3);
@@ -425,7 +423,6 @@ impl<T> Vec<T> {
425423
/// # Examples
426424
///
427425
/// ```
428-
/// # #![feature(collections)]
429426
/// let mut vec = vec![1, 2, 3, 4];
430427
/// vec.truncate(2);
431428
/// assert_eq!(vec, [1, 2]);
@@ -555,7 +552,6 @@ impl<T> Vec<T> {
555552
/// # Examples
556553
///
557554
/// ```
558-
/// # #![feature(collections)]
559555
/// let mut v = vec![1, 2, 3];
560556
/// assert_eq!(v.remove(1), 2);
561557
/// assert_eq!(v, [1, 3]);
@@ -743,7 +739,7 @@ impl<T> Vec<T> {
743739
/// # Examples
744740
///
745741
/// ```
746-
/// # #![feature(collections_drain, collections_range)]
742+
/// # #![feature(collections_drain)]
747743
///
748744
/// // Draining using `..` clears the whole vector.
749745
/// let mut v = vec![1, 2, 3];

0 commit comments

Comments
 (0)