Skip to content

Commit 6163394

Browse files
committed
Auto merge of rust-lang#72262 - Dylan-DPC:rollup-x56q1jj, r=Dylan-DPC
Rollup of 7 pull requests Successful merges: - rust-lang#71625 (Improve the documentation for ManuallyDrop to resolve conflicting usage of terminology) - rust-lang#71919 (Update transitive dependency to work towards removing syn <1.0 dep) - rust-lang#72166 (Simpler slice `Iterator` methods) - rust-lang#72216 (Remove `lang_items\(\).*\.unwrap\(\)`) - rust-lang#72230 (Updated documentation of Prefix::VerbatimDisk) - rust-lang#72234 (Implement Default for proc_macro::TokenStream) - rust-lang#72258 (Fix typo Arbintrary to Arbitrary) Failed merges: r? @ghost
2 parents 31add7e + e43dd47 commit 6163394

File tree

16 files changed

+218
-115
lines changed

16 files changed

+218
-115
lines changed

Cargo.lock

+31-55
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ dependencies = [
438438
"proc-macro2 1.0.3",
439439
"quote 1.0.2",
440440
"syn 1.0.11",
441-
"synstructure 0.12.1",
441+
"synstructure",
442442
]
443443

444444
[[package]]
@@ -937,13 +937,13 @@ checksum = "a0afaad2b26fa326569eb264b1363e8ae3357618c43982b3f285f0774ce76b69"
937937

938938
[[package]]
939939
name = "derive-new"
940-
version = "0.5.6"
940+
version = "0.5.8"
941941
source = "registry+https://github.com/rust-lang/crates.io-index"
942-
checksum = "6ca414e896ae072546f4d789f452daaecf60ddee4c9df5dc6d5936d769e3d87c"
942+
checksum = "71f31892cd5c62e414316f2963c5689242c43d8e7bbcaaeca97e5e28c95d91d9"
943943
dependencies = [
944-
"proc-macro2 0.4.30",
945-
"quote 0.6.12",
946-
"syn 0.15.35",
944+
"proc-macro2 1.0.3",
945+
"quote 1.0.2",
946+
"syn 1.0.11",
947947
]
948948

949949
[[package]]
@@ -1144,14 +1144,14 @@ dependencies = [
11441144

11451145
[[package]]
11461146
name = "failure_derive"
1147-
version = "0.1.5"
1147+
version = "0.1.8"
11481148
source = "registry+https://github.com/rust-lang/crates.io-index"
1149-
checksum = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1"
1149+
checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4"
11501150
dependencies = [
1151-
"proc-macro2 0.4.30",
1152-
"quote 0.6.12",
1153-
"syn 0.15.35",
1154-
"synstructure 0.10.2",
1151+
"proc-macro2 1.0.3",
1152+
"quote 1.0.2",
1153+
"syn 1.0.11",
1154+
"synstructure",
11551155
]
11561156

11571157
[[package]]
@@ -1404,30 +1404,18 @@ dependencies = [
14041404

14051405
[[package]]
14061406
name = "handlebars"
1407-
version = "2.0.1"
1407+
version = "3.0.1"
14081408
source = "registry+https://github.com/rust-lang/crates.io-index"
1409-
checksum = "df044dd42cdb7e32f28557b661406fc0f2494be75199779998810dbc35030e0d"
1409+
checksum = "ba758d094d31274eb49d15da6f326b96bf3185239a6359bf684f3d5321148900"
14101410
dependencies = [
1411-
"hashbrown 0.5.0",
1412-
"lazy_static 1.4.0",
14131411
"log",
14141412
"pest",
14151413
"pest_derive",
14161414
"quick-error",
1417-
"regex",
14181415
"serde",
14191416
"serde_json",
14201417
]
14211418

1422-
[[package]]
1423-
name = "hashbrown"
1424-
version = "0.5.0"
1425-
source = "registry+https://github.com/rust-lang/crates.io-index"
1426-
checksum = "e1de41fb8dba9714efd92241565cdff73f78508c95697dd56787d3cba27e2353"
1427-
dependencies = [
1428-
"serde",
1429-
]
1430-
14311419
[[package]]
14321420
name = "hashbrown"
14331421
version = "0.6.2"
@@ -2054,9 +2042,9 @@ dependencies = [
20542042

20552043
[[package]]
20562044
name = "mdbook"
2057-
version = "0.3.5"
2045+
version = "0.3.7"
20582046
source = "registry+https://github.com/rust-lang/crates.io-index"
2059-
checksum = "031bdd9d4893c983e2f69ebc4b59070feee8276a584c4aabdcb351235ea28016"
2047+
checksum = "e7ec525f7ebccc2dd935c263717250cd37f9a4b264a77c5dbc950ea2734d8159"
20602048
dependencies = [
20612049
"ammonia",
20622050
"chrono",
@@ -2556,15 +2544,15 @@ dependencies = [
25562544

25572545
[[package]]
25582546
name = "pest_generator"
2559-
version = "2.1.0"
2547+
version = "2.1.3"
25602548
source = "registry+https://github.com/rust-lang/crates.io-index"
2561-
checksum = "63120576c4efd69615b5537d3d052257328a4ca82876771d6944424ccfd9f646"
2549+
checksum = "99b8db626e31e5b81787b9783425769681b347011cc59471e33ea46d2ea0cf55"
25622550
dependencies = [
25632551
"pest",
25642552
"pest_meta",
2565-
"proc-macro2 0.4.30",
2566-
"quote 0.6.12",
2567-
"syn 0.15.35",
2553+
"proc-macro2 1.0.3",
2554+
"quote 1.0.2",
2555+
"syn 1.0.11",
25682556
]
25692557

25702558
[[package]]
@@ -2784,9 +2772,9 @@ checksum = "6ddd112cca70a4d30883b2d21568a1d376ff8be4758649f64f973c6845128ad3"
27842772

27852773
[[package]]
27862774
name = "quick-error"
2787-
version = "1.2.2"
2775+
version = "1.2.3"
27882776
source = "registry+https://github.com/rust-lang/crates.io-index"
2789-
checksum = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0"
2777+
checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
27902778

27912779
[[package]]
27922780
name = "quine-mc_cluskey"
@@ -3448,7 +3436,7 @@ dependencies = [
34483436
"proc-macro2 1.0.3",
34493437
"quote 1.0.2",
34503438
"syn 1.0.11",
3451-
"synstructure 0.12.1",
3439+
"synstructure",
34523440
]
34533441

34543442
[[package]]
@@ -4058,7 +4046,7 @@ dependencies = [
40584046
"proc-macro2 1.0.3",
40594047
"quote 1.0.2",
40604048
"syn 1.0.11",
4061-
"synstructure 0.12.1",
4049+
"synstructure",
40624050
]
40634051

40644052
[[package]]
@@ -4629,13 +4617,13 @@ dependencies = [
46294617

46304618
[[package]]
46314619
name = "serde_derive"
4632-
version = "1.0.81"
4620+
version = "1.0.106"
46334621
source = "registry+https://github.com/rust-lang/crates.io-index"
4634-
checksum = "477b13b646f5b5b56fc95bedfc3b550d12141ce84f466f6c44b9a17589923885"
4622+
checksum = "9e549e3abf4fb8621bd1609f11dfc9f5e50320802273b12f3811a67e6716ea6c"
46354623
dependencies = [
4636-
"proc-macro2 0.4.30",
4637-
"quote 0.6.12",
4638-
"syn 0.15.35",
4624+
"proc-macro2 1.0.3",
4625+
"quote 1.0.2",
4626+
"syn 1.0.11",
46394627
]
46404628

46414629
[[package]]
@@ -4799,7 +4787,7 @@ dependencies = [
47994787
"core",
48004788
"dlmalloc",
48014789
"fortanix-sgx-abi",
4802-
"hashbrown 0.6.2",
4790+
"hashbrown",
48034791
"hermit-abi",
48044792
"libc",
48054793
"panic_abort",
@@ -4931,18 +4919,6 @@ dependencies = [
49314919
"unicode-xid 0.2.0",
49324920
]
49334921

4934-
[[package]]
4935-
name = "synstructure"
4936-
version = "0.10.2"
4937-
source = "registry+https://github.com/rust-lang/crates.io-index"
4938-
checksum = "02353edf96d6e4dc81aea2d8490a7e9db177bf8acb0e951c24940bf866cb313f"
4939-
dependencies = [
4940-
"proc-macro2 0.4.30",
4941-
"quote 0.6.12",
4942-
"syn 0.15.35",
4943-
"unicode-xid 0.1.0",
4944-
]
4945-
49464922
[[package]]
49474923
name = "synstructure"
49484924
version = "0.12.1"

src/libcore/iter/traits/iterator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ pub trait Iterator {
333333
#[inline]
334334
#[stable(feature = "rust1", since = "1.0.0")]
335335
fn nth(&mut self, mut n: usize) -> Option<Self::Item> {
336-
for x in self {
336+
while let Some(x) = self.next() {
337337
if n == 0 {
338338
return Some(x);
339339
}

src/libcore/mem/manually_drop.rs

+29-10
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ use crate::ptr;
77
///
88
/// `ManuallyDrop<T>` is subject to the same layout optimizations as `T`.
99
/// As a consequence, it has *no effect* on the assumptions that the compiler makes
10-
/// about all values being initialized at their type. In particular, initializing
11-
/// a `ManuallyDrop<&mut T>` with [`mem::zeroed`] is undefined behavior.
10+
/// about its contents. For example, initializing a `ManuallyDrop<&mut T>`
11+
/// with [`mem::zeroed`] is undefined behavior.
1212
/// If you need to handle uninitialized data, use [`MaybeUninit<T>`] instead.
1313
///
1414
/// # Examples
1515
///
16-
/// This wrapper helps with explicitly documenting the drop order dependencies between fields of
17-
/// the type:
16+
/// This wrapper can be used to enforce a particular drop order on fields, regardless
17+
/// of how they are defined in the struct:
1818
///
1919
/// ```rust
2020
/// use std::mem::ManuallyDrop;
@@ -43,8 +43,18 @@ use crate::ptr;
4343
/// }
4444
/// ```
4545
///
46+
/// However, care should be taken when using this pattern as it can lead to *leak amplification*.
47+
/// In this example, if the `Drop` implementation for `Peach` were to panic, the `banana` field
48+
/// would also be leaked.
49+
///
50+
/// In contrast, the automatically-generated compiler drop implementation would have ensured
51+
/// that all fields are dropped even in the presence of panics. This is especially important when
52+
/// working with [pinned] data, where reusing the memory without calling the destructor could lead
53+
/// to Undefined Behaviour.
54+
///
4655
/// [`mem::zeroed`]: fn.zeroed.html
4756
/// [`MaybeUninit<T>`]: union.MaybeUninit.html
57+
/// [pinned]: ../pin/index.html
4858
#[stable(feature = "manually_drop", since = "1.20.0")]
4959
#[lang = "manually_drop"]
5060
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
@@ -113,19 +123,28 @@ impl<T> ManuallyDrop<T> {
113123
}
114124

115125
impl<T: ?Sized> ManuallyDrop<T> {
116-
/// Manually drops the contained value.
126+
/// Manually drops the contained value. This is exactly equivalent to calling
127+
/// [`ptr::drop_in_place`] with a pointer to the contained value. As such, unless
128+
/// the contained value is a packed struct, the destructor will be called in-place
129+
/// without moving the value, and thus can be used to safely drop [pinned] data.
117130
///
118131
/// If you have ownership of the value, you can use [`ManuallyDrop::into_inner`] instead.
119132
///
120133
/// # Safety
121134
///
122-
/// This function runs the destructor of the contained value and thus the wrapped value
123-
/// now represents uninitialized data. It is up to the user of this method to ensure the
124-
/// uninitialized data is not actually used.
125-
/// In particular, this function can only be called at most once
126-
/// for a given instance of `ManuallyDrop<T>`.
135+
/// This function runs the destructor of the contained value. Other than changes made by
136+
/// the destructor itself, the memory is left unchanged, and so as far as the compiler is
137+
/// concerned still holds a bit-pattern which is valid for the type `T`.
138+
///
139+
/// However, this "zombie" value should not be exposed to safe code, and this function
140+
/// should not be called more than once. To use a value after it's been dropped, or drop
141+
/// a value multiple times, can cause Undefined Behavior (depending on what `drop` does).
142+
/// This is normally prevented by the type system, but users of `ManuallyDrop` must
143+
/// uphold those guarantees without assistance from the compiler.
127144
///
128145
/// [`ManuallyDrop::into_inner`]: #method.into_inner
146+
/// [`ptr::drop_in_place`]: ../ptr/fn.drop_in_place.html
147+
/// [pinned]: ../pin/index.html
129148
#[stable(feature = "manually_drop", since = "1.20.0")]
130149
#[inline]
131150
pub unsafe fn drop(slot: &mut ManuallyDrop<T>) {

src/libcore/ptr/mod.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,17 @@ mod mut_ptr;
110110
/// as the compiler doesn't need to prove that it's sound to elide the
111111
/// copy.
112112
///
113+
/// * It can be used to drop [pinned] data when `T` is not `repr(packed)`
114+
/// (pinned data must not be moved before it is dropped).
115+
///
113116
/// Unaligned values cannot be dropped in place, they must be copied to an aligned
114-
/// location first using [`ptr::read_unaligned`].
117+
/// location first using [`ptr::read_unaligned`]. For packed structs, this move is
118+
/// done automatically by the compiler. This means the fields of packed structs
119+
/// are not dropped in-place.
115120
///
116121
/// [`ptr::read`]: ../ptr/fn.read.html
117122
/// [`ptr::read_unaligned`]: ../ptr/fn.read_unaligned.html
123+
/// [pinned]: ../pin/index.html
118124
///
119125
/// # Safety
120126
///

0 commit comments

Comments
 (0)