Skip to content

Commit 5b04bbf

Browse files
committed
Auto merge of #75692 - JohnTitor:rollup-8gr04ah, r=JohnTitor
Rollup of 9 pull requests Successful merges: - #75038 (See also X-Link mem::{swap, take, replace}) - #75049 (docs(marker/copy): provide example for `&T` being `Copy`) - #75499 (Fix documentation error) - #75554 (Fix clashing_extern_declarations stack overflow for recursive types.) - #75646 (Move to intra doc links for keyword documentation) - #75652 (Resolve true and false as booleans) - #75658 (Don't emit "is not a logical operator" error outside of associative expressions) - #75665 (Add doc examples coverage) - #75685 (Switch to intra-doc links in /src/sys/unix/ext/*.rs) Failed merges: r? @ghost
2 parents c03c213 + 07ea340 commit 5b04bbf

32 files changed

+556
-449
lines changed

library/core/src/marker.rs

+15
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ pub trait StructuralEq {
291291
///
292292
/// ```
293293
/// # #[allow(dead_code)]
294+
/// #[derive(Copy, Clone)]
294295
/// struct Point {
295296
/// x: i32,
296297
/// y: i32,
@@ -315,6 +316,20 @@ pub trait StructuralEq {
315316
/// the trait `Copy` may not be implemented for this type; field `points` does not implement `Copy`
316317
/// ```
317318
///
319+
/// Shared references (`&T`) are also `Copy`, so a type can be `Copy`, even when it holds
320+
/// shared references of types `T` that are *not* `Copy`. Consider the following struct,
321+
/// which can implement `Copy`, because it only holds a *shared reference* to our non-`Copy`
322+
/// type `PointList` from above:
323+
///
324+
/// ```
325+
/// # #![allow(dead_code)]
326+
/// # struct PointList;
327+
/// #[derive(Copy, Clone)]
328+
/// struct PointListWrapper<'a> {
329+
/// point_list_ref: &'a PointList,
330+
/// }
331+
/// ```
332+
///
318333
/// ## When *can't* my type be `Copy`?
319334
///
320335
/// Some types can't be copied safely. For example, copying `&mut T` would create an aliased

library/core/src/mem/mod.rs

+16
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,9 @@ pub unsafe fn uninitialized<T>() -> T {
670670

671671
/// Swaps the values at two mutable locations, without deinitializing either one.
672672
///
673+
/// * If you want to swap with a default or dummy value, see [`take`].
674+
/// * If you want to swap with a passed value, returning the old value, see [`replace`].
675+
///
673676
/// # Examples
674677
///
675678
/// ```
@@ -683,6 +686,9 @@ pub unsafe fn uninitialized<T>() -> T {
683686
/// assert_eq!(42, x);
684687
/// assert_eq!(5, y);
685688
/// ```
689+
///
690+
/// [`replace`]: fn.replace.html
691+
/// [`take`]: fn.take.html
686692
#[inline]
687693
#[stable(feature = "rust1", since = "1.0.0")]
688694
pub fn swap<T>(x: &mut T, y: &mut T) {
@@ -695,6 +701,9 @@ pub fn swap<T>(x: &mut T, y: &mut T) {
695701

696702
/// Replaces `dest` with the default value of `T`, returning the previous `dest` value.
697703
///
704+
/// * If you want to replace the values of two variables, see [`swap`].
705+
/// * If you want to replace with a passed value instead of the default value, see [`replace`].
706+
///
698707
/// # Examples
699708
///
700709
/// A simple example:
@@ -747,6 +756,8 @@ pub fn swap<T>(x: &mut T, y: &mut T) {
747756
/// ```
748757
///
749758
/// [`Clone`]: ../../std/clone/trait.Clone.html
759+
/// [`replace`]: fn.replace.html
760+
/// [`swap`]: fn.swap.html
750761
#[inline]
751762
#[stable(feature = "mem_take", since = "1.40.0")]
752763
pub fn take<T: Default>(dest: &mut T) -> T {
@@ -757,6 +768,9 @@ pub fn take<T: Default>(dest: &mut T) -> T {
757768
///
758769
/// Neither value is dropped.
759770
///
771+
/// * If you want to replace the values of two variables, see [`swap`].
772+
/// * If you want to replace with a default value, see [`take`].
773+
///
760774
/// # Examples
761775
///
762776
/// A simple example:
@@ -810,6 +824,8 @@ pub fn take<T: Default>(dest: &mut T) -> T {
810824
/// ```
811825
///
812826
/// [`Clone`]: ../../std/clone/trait.Clone.html
827+
/// [`swap`]: fn.swap.html
828+
/// [`take`]: fn.take.html
813829
#[inline]
814830
#[stable(feature = "rust1", since = "1.0.0")]
815831
#[must_use = "if you don't need the old value, you can just assign the new value directly"]

library/core/src/str/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2031,7 +2031,7 @@ mod traits {
20312031
/// # Panics
20322032
///
20332033
/// Panics if `begin` does not point to the starting byte offset of
2034-
/// a character (as defined by `is_char_boundary`), or if `begin >= len`.
2034+
/// a character (as defined by `is_char_boundary`), or if `begin > len`.
20352035
#[stable(feature = "str_checked_slicing", since = "1.20.0")]
20362036
unsafe impl SliceIndex<str> for ops::RangeFrom<usize> {
20372037
type Output = str;

library/std/src/keyword_docs.rs

+4-16
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ mod as_keyword {}
9898
/// [Reference on "break expression"]: ../reference/expressions/loop-expr.html#break-expressions
9999
/// [Reference on "break and loop values"]:
100100
/// ../reference/expressions/loop-expr.html#break-and-loop-values
101-
///
102101
mod break_keyword {}
103102

104103
#[doc(keyword = "const")]
@@ -336,7 +335,6 @@ mod else_keyword {}
336335
/// For more information, take a look at the [Rust Book] or the [Reference]
337336
///
338337
/// [ADT]: https://en.wikipedia.org/wiki/Algebraic_data_type
339-
/// [`Option`]: option/enum.Option.html
340338
/// [Rust Book]: ../book/ch06-01-defining-an-enum.html
341339
/// [Reference]: ../reference/items/enumerations.html
342340
mod enum_keyword {}
@@ -534,7 +532,6 @@ mod fn_keyword {}
534532
/// [`in`]: keyword.in.html
535533
/// [`impl`]: keyword.impl.html
536534
/// [higher-ranked trait bounds]: ../reference/trait-bounds.html#higher-ranked-trait-bounds
537-
/// [`IntoIterator`]: iter/trait.IntoIterator.html
538535
/// [Rust book]:
539536
/// ../book/ch03-05-control-flow.html#looping-through-a-collection-with-for
540537
/// [Reference]: ../reference/expressions/loop-expr.html#iterator-loops
@@ -993,7 +990,6 @@ mod mod_keyword {}
993990
/// For more information on the `move` keyword, see the [closure]'s section
994991
/// of the Rust book or the [threads] section
995992
///
996-
/// [`Fn` trait]: ../std/ops/trait.Fn.html
997993
/// [closure]: ../book/ch13-01-closures.html
998994
/// [threads]: ../book/ch16-01-threads.html#using-move-closures-with-threads
999995
mod move_keyword {}
@@ -1413,9 +1409,7 @@ mod self_upper_keyword {}
14131409
/// [`extern`]: keyword.extern.html
14141410
/// [`mut`]: keyword.mut.html
14151411
/// [`unsafe`]: keyword.unsafe.html
1416-
/// [`drop`]: mem/fn.drop.html
1417-
/// [`Sync`]: marker/trait.Sync.html
1418-
/// [`RefCell`]: cell/struct.RefCell.html
1412+
/// [`RefCell`]: cell::RefCell
14191413
/// [Reference]: ../reference/items/static-items.html
14201414
mod static_keyword {}
14211415

@@ -1522,7 +1516,7 @@ mod static_keyword {}
15221516
/// For more information on structs, take a look at the [Rust Book][book] or the
15231517
/// [Reference][reference].
15241518
///
1525-
/// [`PhantomData`]: marker/struct.PhantomData.html
1519+
/// [`PhantomData`]: marker::PhantomData
15261520
/// [book]: ../book/ch05-01-defining-structs.html
15271521
/// [reference]: ../reference/items/structs.html
15281522
mod struct_keyword {}
@@ -1733,8 +1727,6 @@ mod super_keyword {}
17331727
/// [`for`]: keyword.for.html
17341728
/// [`impl`]: keyword.impl.html
17351729
/// [`unsafe`]: keyword.unsafe.html
1736-
/// [`Send`]: marker/trait.Send.html
1737-
/// [`Sync`]: marker/trait.Sync.html
17381730
/// [Ref-Traits]: ../reference/items/traits.html
17391731
/// [Ref-Trait-Objects]: ../reference/types/trait-object.html
17401732
mod trait_keyword {}
@@ -1764,7 +1756,6 @@ mod trait_keyword {}
17641756
/// [`while`]: keyword.while.html
17651757
/// [`match`]: ../reference/expressions/match-expr.html#match-guards
17661758
/// [`false`]: keyword.false.html
1767-
/// [`bool`]: primitive.bool.html
17681759
mod true_keyword {}
17691760

17701761
#[doc(keyword = "type")]
@@ -1986,9 +1977,6 @@ mod type_keyword {}
19861977
/// [`static`]: keyword.static.html
19871978
/// [`union`]: keyword.union.html
19881979
/// [`impl`]: keyword.impl.html
1989-
/// [Send]: marker/trait.Send.html
1990-
/// [Sync]: marker/trait.Sync.html
1991-
/// [`Vec::set_len`]: vec/struct.Vec.html#method.set_len
19921980
/// [raw pointers]: ../reference/types/pointer.html
19931981
/// [memory safety]: ../book/ch19-01-unsafe-rust.html
19941982
/// [Rustnomicon]: ../nomicon/index.html
@@ -2178,7 +2166,7 @@ mod where_keyword {}
21782166
///
21792167
/// It is available for use in stable rust from version 1.39 onwards.
21802168
///
2181-
/// [`Future`]: ./future/trait.Future.html
2169+
/// [`Future`]: future::Future
21822170
/// [async book]: https://rust-lang.github.io/async-book/
21832171
mod async_keyword {}
21842172

@@ -2197,7 +2185,7 @@ mod async_keyword {}
21972185
///
21982186
/// It is available for use in stable rust from version 1.39 onwards.
21992187
///
2200-
/// [`Future`]: ./future/trait.Future.html
2188+
/// [`Future`]: future::Future
22012189
/// [async book]: https://rust-lang.github.io/async-book/
22022190
mod await_keyword {}
22032191

library/std/src/sys/unix/ext/fs.rs

+13-32
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ use crate::sys;
99
use crate::sys::platform::fs::MetadataExt as UnixMetadataExt;
1010
use crate::sys_common::{AsInner, AsInnerMut, FromInner};
1111

12-
/// Unix-specific extensions to [`File`].
13-
///
14-
/// [`File`]: ../../../../std/fs/struct.File.html
12+
/// Unix-specific extensions to [`fs::File`].
1513
#[stable(feature = "file_offset", since = "1.15.0")]
1614
pub trait FileExt {
1715
/// Reads a number of bytes starting from a given offset.
@@ -55,19 +53,18 @@ pub trait FileExt {
5553
///
5654
/// The current file cursor is not affected by this function.
5755
///
58-
/// Similar to [`Read::read_exact`] but uses [`read_at`] instead of `read`.
56+
/// Similar to [`io::Read::read_exact`] but uses [`read_at`] instead of `read`.
5957
///
60-
/// [`Read::read_exact`]: ../../../../std/io/trait.Read.html#method.read_exact
61-
/// [`read_at`]: #tymethod.read_at
58+
/// [`read_at`]: FileExt::read_at
6259
///
6360
/// # Errors
6461
///
6562
/// If this function encounters an error of the kind
66-
/// [`ErrorKind::Interrupted`] then the error is ignored and the operation
63+
/// [`io::ErrorKind::Interrupted`] then the error is ignored and the operation
6764
/// will continue.
6865
///
6966
/// If this function encounters an "end of file" before completely filling
70-
/// the buffer, it returns an error of the kind [`ErrorKind::UnexpectedEof`].
67+
/// the buffer, it returns an error of the kind [`io::ErrorKind::UnexpectedEof`].
7168
/// The contents of `buf` are unspecified in this case.
7269
///
7370
/// If any other read error is encountered then this function immediately
@@ -77,9 +74,6 @@ pub trait FileExt {
7774
/// has read, but it will never read more than would be necessary to
7875
/// completely fill the buffer.
7976
///
80-
/// [`ErrorKind::Interrupted`]: ../../../../std/io/enum.ErrorKind.html#variant.Interrupted
81-
/// [`ErrorKind::UnexpectedEof`]: ../../../../std/io/enum.ErrorKind.html#variant.UnexpectedEof
82-
///
8377
/// # Examples
8478
///
8579
/// ```no_run
@@ -161,19 +155,18 @@ pub trait FileExt {
161155
/// The current file cursor is not affected by this function.
162156
///
163157
/// This method will continuously call [`write_at`] until there is no more data
164-
/// to be written or an error of non-[`ErrorKind::Interrupted`] kind is
158+
/// to be written or an error of non-[`io::ErrorKind::Interrupted`] kind is
165159
/// returned. This method will not return until the entire buffer has been
166160
/// successfully written or such an error occurs. The first error that is
167-
/// not of [`ErrorKind::Interrupted`] kind generated from this method will be
161+
/// not of [`io::ErrorKind::Interrupted`] kind generated from this method will be
168162
/// returned.
169163
///
170164
/// # Errors
171165
///
172166
/// This function will return the first error of
173-
/// non-[`ErrorKind::Interrupted`] kind that [`write_at`] returns.
167+
/// non-[`io::ErrorKind::Interrupted`] kind that [`write_at`] returns.
174168
///
175-
/// [`ErrorKind::Interrupted`]: ../../../../std/io/enum.ErrorKind.html#variant.Interrupted
176-
/// [`write_at`]: #tymethod.write_at
169+
/// [`write_at`]: FileExt::write_at
177170
///
178171
/// # Examples
179172
///
@@ -223,8 +216,6 @@ impl FileExt for fs::File {
223216
}
224217

225218
/// Unix-specific extensions to [`fs::Permissions`].
226-
///
227-
/// [`fs::Permissions`]: ../../../../std/fs/struct.Permissions.html
228219
#[stable(feature = "fs_ext", since = "1.1.0")]
229220
pub trait PermissionsExt {
230221
/// Returns the underlying raw `st_mode` bits that contain the standard
@@ -302,8 +293,6 @@ impl PermissionsExt for Permissions {
302293
}
303294

304295
/// Unix-specific extensions to [`fs::OpenOptions`].
305-
///
306-
/// [`fs::OpenOptions`]: ../../../../std/fs/struct.OpenOptions.html
307296
#[stable(feature = "fs_ext", since = "1.1.0")]
308297
pub trait OpenOptionsExt {
309298
/// Sets the mode bits that a new file will be created with.
@@ -372,8 +361,6 @@ impl OpenOptionsExt for OpenOptions {
372361
}
373362

374363
/// Unix-specific extensions to [`fs::Metadata`].
375-
///
376-
/// [`fs::Metadata`]: ../../../../std/fs/struct.Metadata.html
377364
#[stable(feature = "metadata_ext", since = "1.1.0")]
378365
pub trait MetadataExt {
379366
/// Returns the ID of the device containing the file.
@@ -535,7 +522,7 @@ pub trait MetadataExt {
535522
fn atime(&self) -> i64;
536523
/// Returns the last access time of the file, in nanoseconds since [`atime`].
537524
///
538-
/// [`atime`]: #tymethod.atime
525+
/// [`atime`]: MetadataExt::atime
539526
///
540527
/// # Examples
541528
///
@@ -571,7 +558,7 @@ pub trait MetadataExt {
571558
fn mtime(&self) -> i64;
572559
/// Returns the last modification time of the file, in nanoseconds since [`mtime`].
573560
///
574-
/// [`mtime`]: #tymethod.mtime
561+
/// [`mtime`]: MetadataExt::mtime
575562
///
576563
/// # Examples
577564
///
@@ -607,7 +594,7 @@ pub trait MetadataExt {
607594
fn ctime(&self) -> i64;
608595
/// Returns the last status change time of the file, in nanoseconds since [`ctime`].
609596
///
610-
/// [`ctime`]: #tymethod.ctime
597+
/// [`ctime`]: MetadataExt::ctime
611598
///
612599
/// # Examples
613600
///
@@ -714,12 +701,10 @@ impl MetadataExt for fs::Metadata {
714701
}
715702
}
716703

717-
/// Unix-specific extensions for [`FileType`].
704+
/// Unix-specific extensions for [`fs::FileType`].
718705
///
719706
/// Adds support for special Unix file types such as block/character devices,
720707
/// pipes, and sockets.
721-
///
722-
/// [`FileType`]: ../../../../std/fs/struct.FileType.html
723708
#[stable(feature = "file_type_ext", since = "1.5.0")]
724709
pub trait FileTypeExt {
725710
/// Returns `true` if this file type is a block device.
@@ -813,8 +798,6 @@ impl FileTypeExt for fs::FileType {
813798
}
814799

815800
/// Unix-specific extension methods for [`fs::DirEntry`].
816-
///
817-
/// [`fs::DirEntry`]: ../../../../std/fs/struct.DirEntry.html
818801
#[stable(feature = "dir_entry_ext", since = "1.1.0")]
819802
pub trait DirEntryExt {
820803
/// Returns the underlying `d_ino` field in the contained `dirent`
@@ -875,8 +858,6 @@ pub fn symlink<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Result<()>
875858
}
876859

877860
/// Unix-specific extensions to [`fs::DirBuilder`].
878-
///
879-
/// [`fs::DirBuilder`]: ../../../../std/fs/struct.DirBuilder.html
880861
#[stable(feature = "dir_builder", since = "1.6.0")]
881862
pub trait DirBuilderExt {
882863
/// Sets the mode to create new directories with. This option defaults to

0 commit comments

Comments
 (0)