Skip to content

Commit 74abffe

Browse files
committed
Auto merge of #49642 - kennytm:rollup, r=kennytm
Rollup of 25 pull requests Successful merges: - #49179 (Handle future deprecation annotations ) - #49512 (Add support for variant and types fields for intra links) - #49515 (fix targetted value background) - #49516 (Add missing anchor for union type fields) - #49532 (Add test for rustdoc ignore test) - #49533 (Add #[must_use] to a few standard library methods) - #49540 (Fix miri Discriminant() for non-ADT) - #49559 (Introduce Vec::resize_with method (see #41758)) - #49570 (avoid IdxSets containing garbage above the universe length) - #49577 (Stabilize String::replace_range) - #49599 (Fix typo) - #49603 (Fix url for intra link provided method) - #49607 (Stabilize iterator methods in 1.27) - #49609 (run-pass/attr-stmt-expr: expand test cases) - #49612 (Fix "since" version for getpid feature.) - #49618 (Fix build error when compiling libcore for 16bit targets) - #49619 (tweak core::fmt docs) - #49637 (Stabilize parent_id()) - #49639 (Update Cargo) - #49628 (Re-write the documentation index) - #49594 (Add some performance guidance to std::fs and std::io docs) - #49625 (miri: add public alloc_kind accessor) - #49634 (Add a test for the fix to issue #43058) - #49641 (Regression test for #46314) - #49547 (Unignore borrowck test) Failed merges:
2 parents fb44b4c + 00ada06 commit 74abffe

File tree

40 files changed

+595
-160
lines changed

40 files changed

+595
-160
lines changed

src/doc/index.md

+63-46
Original file line numberDiff line numberDiff line change
@@ -6,55 +6,72 @@ nav {
66
}
77
</style>
88

9-
This page is an overview of the documentation included with your Rust install.
10-
Other unofficial documentation may exist elsewhere; for example, the [Rust
11-
Learning] project collects documentation from the community, and [Docs.rs]
12-
builds documentation for individual Rust packages.
9+
Welcome to an overview of the documentation provided by the Rust project.
10+
All of these projects are managed by the Docs Team; there are other
11+
unofficial documentation resources as well!
1312

14-
# API Documentation
13+
Many of these resources take the form of "books"; we collectively call these
14+
"The Rust Bookshelf." Some are large, some are small.
1515

16-
Rust provides a standard library with a number of features; [we host its
17-
documentation here][api].
16+
## Learn Rust
1817

19-
# Extended Error Documentation
18+
If you'd like to learn Rust, this is the spot for you! All of these resources
19+
assume that you have programmed before, but not in any specific language:
20+
21+
### The Rust Programming Language
22+
23+
Affectionately nicknamed "the book," [The Rust Programming
24+
Language](book/index.html) will give you an overview of the language from
25+
first principles. You'll build a few projects along the way, and by the end,
26+
you'll have a solid grasp of the language.
27+
28+
### Rust By Example
29+
30+
If reading multiple hundreds of pages about a language isn't your style, then
31+
[Rust By Example](rust-by-example/index.html) has you covered. While the book talks about code with
32+
a lot of words, RBE shows off a bunch of code, and keeps the talking to a
33+
minimum. It also includes exercises!
34+
35+
## Use Rust
36+
37+
Once you've gotten familliar with the language, these resources can help you
38+
when you're actually using it day-to-day.
39+
40+
### The Standard Library
41+
42+
Rust's standard library has [extensive API documentation](std/index.html),
43+
with explanations of how to use various things, as well as example code for
44+
accomplishing various tasks.
45+
46+
### The Cargo Book
47+
48+
[The Cargo Book](cargo/index.html) is a guide to Cargo, Rust's build tool and dependency manager.
49+
50+
### The Rustdoc Book
51+
52+
[The Rustdoc Book](rustdoc/index.html) describes our documentation tool, `rustdoc`.
53+
54+
### Extended Error Listing
2055

2156
Many of Rust's errors come with error codes, and you can request extended
22-
diagnostics from the compiler on those errors. We also [have the text of those
23-
extended errors on the web][err], if you prefer to read them that way.
24-
25-
# The Rust Bookshelf
26-
27-
Rust provides a number of book-length sets of documentation, collectively
28-
nicknamed 'The Rust Bookshelf.'
29-
30-
* [The Rust Programming Language][book] teaches you how to program in Rust.
31-
* [Rust By Example][rbe] teaches you how to program in Rust using editable examples.
32-
* [The Cargo Book][cargo-book] is a guide to Cargo, Rust's build tool and dependency manager.
33-
* [The Unstable Book][unstable-book] has documentation for unstable features.
34-
* [The Rustonomicon][nomicon] is your guidebook to the dark arts of unsafe Rust.
35-
* [The Reference][ref] is not a formal spec, but is more detailed and comprehensive than the book.
36-
* [The Rustdoc Book][rustdoc-book] describes our documentation tool, `rustdoc`.
37-
38-
Initially, documentation lands in the Unstable Book, and then, as part of the
39-
stabilization process, is moved into the Book, Nomicon, or Reference.
40-
41-
Another few words about the reference: it is guaranteed to be accurate, but not
42-
complete. We have a policy that features must have documentation to be stabilized,
43-
but we did not always have this policy, and so there are some stable things that
44-
are not yet in the reference. We're working on back-filling things that landed
45-
before this policy was put into place. That work is being tracked
46-
[here][refchecklist].
47-
48-
[Rust Learning]: https://github.com/ctjhoa/rust-learning
49-
[Docs.rs]: https://docs.rs/
50-
[api]: std/index.html
51-
[ref]: reference/index.html
52-
[refchecklist]: https://github.com/rust-lang-nursery/reference/issues/9
53-
[err]: error-index.html
54-
[book]: book/index.html
55-
[rbe]: rust-by-example/index.html
56-
[nomicon]: nomicon/index.html
57-
[unstable-book]: unstable-book/index.html
58-
[rustdoc-book]: rustdoc/index.html
59-
[cargo-book]: cargo/index.html
57+
diagnostics from the compiler on those errors. You can also [read them
58+
here](error-index.html), if you prefer to read them that way.
59+
60+
## Master Rust
61+
62+
Once you're quite familiar with the language, you may find these advanced
63+
resources useful.
64+
65+
### The Reference
66+
67+
[The Reference](reference/index.html) is not a formal spec, but is more detailed and
68+
comprehensive than the book.
69+
70+
### The Rustonomicon
71+
72+
[The Rustonomicon](nomicon/index.html) is your guidebook to the dark arts of unsafe
73+
Rust. It's also sometimes called "the 'nomicon."
74+
75+
### The Unstable Book
6076

77+
[The Unstable Book](unstable-book/index.html) has documentation for unstable features.

src/doc/unstable-book/src/library-features/splice.md

-22
This file was deleted.

src/liballoc/borrow.rs

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ pub trait ToOwned {
5959
/// let vv: Vec<i32> = v.to_owned();
6060
/// ```
6161
#[stable(feature = "rust1", since = "1.0.0")]
62+
#[must_use = "cloning is often expensive and is not expected to have side effects"]
6263
fn to_owned(&self) -> Self::Owned;
6364

6465
/// Uses borrowed data to replace owned data, usually by cloning.

src/liballoc/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@
9999
#![feature(fundamental)]
100100
#![feature(generic_param_attrs)]
101101
#![cfg_attr(stage0, feature(i128_type))]
102-
#![feature(iter_rfold)]
103102
#![feature(lang_items)]
104103
#![feature(needs_allocator)]
105104
#![feature(nonzero)]

src/liballoc/string.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -1517,7 +1517,7 @@ impl String {
15171517
}
15181518
}
15191519

1520-
/// Creates a splicing iterator that removes the specified range in the string,
1520+
/// Removes the specified range in the string,
15211521
/// and replaces it with the given string.
15221522
/// The given string doesn't need to be the same length as the range.
15231523
///
@@ -1537,21 +1537,20 @@ impl String {
15371537
/// Basic usage:
15381538
///
15391539
/// ```
1540-
/// #![feature(splice)]
15411540
/// let mut s = String::from("α is alpha, β is beta");
15421541
/// let beta_offset = s.find('β').unwrap_or(s.len());
15431542
///
15441543
/// // Replace the range up until the β from the string
1545-
/// s.splice(..beta_offset, "Α is capital alpha; ");
1544+
/// s.replace_range(..beta_offset, "Α is capital alpha; ");
15461545
/// assert_eq!(s, "Α is capital alpha; β is beta");
15471546
/// ```
1548-
#[unstable(feature = "splice", reason = "recently added", issue = "44643")]
1549-
pub fn splice<R>(&mut self, range: R, replace_with: &str)
1547+
#[stable(feature = "splice", since = "1.27.0")]
1548+
pub fn replace_range<R>(&mut self, range: R, replace_with: &str)
15501549
where R: RangeBounds<usize>
15511550
{
15521551
// Memory safety
15531552
//
1554-
// The String version of Splice does not have the memory safety issues
1553+
// Replace_range does not have the memory safety issues of a vector Splice.
15551554
// of the vector version. The data is just plain bytes.
15561555

15571556
match range.start() {

src/liballoc/tests/string.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -443,53 +443,53 @@ fn test_drain() {
443443
}
444444

445445
#[test]
446-
fn test_splice() {
446+
fn test_replace_range() {
447447
let mut s = "Hello, world!".to_owned();
448-
s.splice(7..12, "世界");
448+
s.replace_range(7..12, "世界");
449449
assert_eq!(s, "Hello, 世界!");
450450
}
451451

452452
#[test]
453453
#[should_panic]
454-
fn test_splice_char_boundary() {
454+
fn test_replace_range_char_boundary() {
455455
let mut s = "Hello, 世界!".to_owned();
456-
s.splice(..8, "");
456+
s.replace_range(..8, "");
457457
}
458458

459459
#[test]
460-
fn test_splice_inclusive_range() {
460+
fn test_replace_range_inclusive_range() {
461461
let mut v = String::from("12345");
462-
v.splice(2..=3, "789");
462+
v.replace_range(2..=3, "789");
463463
assert_eq!(v, "127895");
464-
v.splice(1..=2, "A");
464+
v.replace_range(1..=2, "A");
465465
assert_eq!(v, "1A895");
466466
}
467467

468468
#[test]
469469
#[should_panic]
470-
fn test_splice_out_of_bounds() {
470+
fn test_replace_range_out_of_bounds() {
471471
let mut s = String::from("12345");
472-
s.splice(5..6, "789");
472+
s.replace_range(5..6, "789");
473473
}
474474

475475
#[test]
476476
#[should_panic]
477-
fn test_splice_inclusive_out_of_bounds() {
477+
fn test_replace_range_inclusive_out_of_bounds() {
478478
let mut s = String::from("12345");
479-
s.splice(5..=5, "789");
479+
s.replace_range(5..=5, "789");
480480
}
481481

482482
#[test]
483-
fn test_splice_empty() {
483+
fn test_replace_range_empty() {
484484
let mut s = String::from("12345");
485-
s.splice(1..2, "");
485+
s.replace_range(1..2, "");
486486
assert_eq!(s, "1345");
487487
}
488488

489489
#[test]
490-
fn test_splice_unbounded() {
490+
fn test_replace_range_unbounded() {
491491
let mut s = String::from("12345");
492-
s.splice(.., "");
492+
s.replace_range(.., "");
493493
assert_eq!(s, "");
494494
}
495495

src/liballoc/vec.rs

+57-7
Original file line numberDiff line numberDiff line change
@@ -1283,6 +1283,49 @@ impl<T> Vec<T> {
12831283
}
12841284
other
12851285
}
1286+
1287+
/// Resizes the `Vec` in-place so that `len` is equal to `new_len`.
1288+
///
1289+
/// If `new_len` is greater than `len`, the `Vec` is extended by the
1290+
/// difference, with each additional slot filled with the result of
1291+
/// calling the closure `f`. The return values from `f` will end up
1292+
/// in the `Vec` in the order they have been generated.
1293+
///
1294+
/// If `new_len` is less than `len`, the `Vec` is simply truncated.
1295+
///
1296+
/// This method uses a closure to create new values on every push. If
1297+
/// you'd rather [`Clone`] a given value, use [`resize`]. If you want
1298+
/// to use the [`Default`] trait to generate values, you can pass
1299+
/// [`Default::default()`] as the second argument..
1300+
///
1301+
/// # Examples
1302+
///
1303+
/// ```
1304+
/// #![feature(vec_resize_with)]
1305+
///
1306+
/// let mut vec = vec![1, 2, 3];
1307+
/// vec.resize_with(5, Default::default);
1308+
/// assert_eq!(vec, [1, 2, 3, 0, 0]);
1309+
///
1310+
/// let mut vec = vec![];
1311+
/// let mut p = 1;
1312+
/// vec.resize_with(4, || { p *= 2; p });
1313+
/// assert_eq!(vec, [2, 4, 8, 16]);
1314+
/// ```
1315+
///
1316+
/// [`resize`]: #method.resize
1317+
/// [`Clone`]: ../../std/clone/trait.Clone.html
1318+
#[unstable(feature = "vec_resize_with", issue = "41758")]
1319+
pub fn resize_with<F>(&mut self, new_len: usize, f: F)
1320+
where F: FnMut() -> T
1321+
{
1322+
let len = self.len();
1323+
if new_len > len {
1324+
self.extend_with(new_len - len, ExtendFunc(f));
1325+
} else {
1326+
self.truncate(new_len);
1327+
}
1328+
}
12861329
}
12871330

12881331
impl<T: Clone> Vec<T> {
@@ -1293,8 +1336,8 @@ impl<T: Clone> Vec<T> {
12931336
/// If `new_len` is less than `len`, the `Vec` is simply truncated.
12941337
///
12951338
/// This method requires [`Clone`] to be able clone the passed value. If
1296-
/// you'd rather create a value with [`Default`] instead, see
1297-
/// [`resize_default`].
1339+
/// you need more flexibility (or want to rely on [`Default`] instead of
1340+
/// [`Clone`]), use [`resize_with`].
12981341
///
12991342
/// # Examples
13001343
///
@@ -1310,7 +1353,7 @@ impl<T: Clone> Vec<T> {
13101353
///
13111354
/// [`Clone`]: ../../std/clone/trait.Clone.html
13121355
/// [`Default`]: ../../std/default/trait.Default.html
1313-
/// [`resize_default`]: #method.resize_default
1356+
/// [`resize_with`]: #method.resize_with
13141357
#[stable(feature = "vec_resize", since = "1.5.0")]
13151358
pub fn resize(&mut self, new_len: usize, value: T) {
13161359
let len = self.len();
@@ -1389,24 +1432,31 @@ impl<T: Default> Vec<T> {
13891432

13901433
// This code generalises `extend_with_{element,default}`.
13911434
trait ExtendWith<T> {
1392-
fn next(&self) -> T;
1435+
fn next(&mut self) -> T;
13931436
fn last(self) -> T;
13941437
}
13951438

13961439
struct ExtendElement<T>(T);
13971440
impl<T: Clone> ExtendWith<T> for ExtendElement<T> {
1398-
fn next(&self) -> T { self.0.clone() }
1441+
fn next(&mut self) -> T { self.0.clone() }
13991442
fn last(self) -> T { self.0 }
14001443
}
14011444

14021445
struct ExtendDefault;
14031446
impl<T: Default> ExtendWith<T> for ExtendDefault {
1404-
fn next(&self) -> T { Default::default() }
1447+
fn next(&mut self) -> T { Default::default() }
14051448
fn last(self) -> T { Default::default() }
14061449
}
1450+
1451+
struct ExtendFunc<F>(F);
1452+
impl<T, F: FnMut() -> T> ExtendWith<T> for ExtendFunc<F> {
1453+
fn next(&mut self) -> T { (self.0)() }
1454+
fn last(mut self) -> T { (self.0)() }
1455+
}
1456+
14071457
impl<T> Vec<T> {
14081458
/// Extend the vector by `n` values, using the given generator.
1409-
fn extend_with<E: ExtendWith<T>>(&mut self, n: usize, value: E) {
1459+
fn extend_with<E: ExtendWith<T>>(&mut self, n: usize, mut value: E) {
14101460
self.reserve(n);
14111461

14121462
unsafe {

src/libcore/clone.rs

+1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ pub trait Clone : Sized {
117117
/// assert_eq!("Hello", hello.clone());
118118
/// ```
119119
#[stable(feature = "rust1", since = "1.0.0")]
120+
#[must_use = "cloning is often expensive and is not expected to have side effects"]
120121
fn clone(&self) -> Self;
121122

122123
/// Performs copy-assignment from `source`.

0 commit comments

Comments
 (0)