Skip to content

Commit c76f3c3

Browse files
committed
Auto merge of #57737 - Centril:rollup, r=Centril
Rollup of 10 pull requests Successful merges: - #56594 (Remove confusing comment about ideally using `!` for `c_void`) - #57340 (Use correct tracking issue for c_variadic) - #57357 (Cleanup PartialEq docs.) - #57551 (resolve: Add a test for issue #57539) - #57636 (Fix sources sidebar not showing up) - #57646 (Fixes text becoming invisible when element targetted) - #57654 (Add some links in std::fs.) - #57683 (Document Unpin in std::prelude documentation) - #57685 (Enhance `Pin` impl applicability for `PartialEq` and `PartialOrd`.) - #57710 (Fix non-clickable urls) Failed merges: r? @ghost
2 parents f613dc1 + ff583ac commit c76f3c3

File tree

13 files changed

+138
-66
lines changed

13 files changed

+138
-66
lines changed

src/libcore/cmp.rs

+22-16
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ use self::Ordering::*;
9191
/// For example, let's tweak our previous code a bit:
9292
///
9393
/// ```
94+
/// // The derive implements <BookFormat> == <BookFormat> comparisons
95+
/// #[derive(PartialEq)]
9496
/// enum BookFormat {
9597
/// Paperback,
9698
/// Hardback,
@@ -102,31 +104,34 @@ use self::Ordering::*;
102104
/// format: BookFormat,
103105
/// }
104106
///
107+
/// // Implement <Book> == <BookFormat> comparisons
105108
/// impl PartialEq<BookFormat> for Book {
106109
/// fn eq(&self, other: &BookFormat) -> bool {
107-
/// match (&self.format, other) {
108-
/// (BookFormat::Paperback, BookFormat::Paperback) => true,
109-
/// (BookFormat::Hardback, BookFormat::Hardback) => true,
110-
/// (BookFormat::Ebook, BookFormat::Ebook) => true,
111-
/// (_, _) => false,
112-
/// }
110+
/// self.format == *other
111+
/// }
112+
/// }
113+
///
114+
/// // Implement <BookFormat> == <Book> comparisons
115+
/// impl PartialEq<Book> for BookFormat {
116+
/// fn eq(&self, other: &Book) -> bool {
117+
/// *self == other.format
113118
/// }
114119
/// }
115120
///
116121
/// let b1 = Book { isbn: 3, format: BookFormat::Paperback };
117122
///
118123
/// assert!(b1 == BookFormat::Paperback);
119-
/// assert!(b1 != BookFormat::Ebook);
124+
/// assert!(BookFormat::Ebook != b1);
120125
/// ```
121126
///
122127
/// By changing `impl PartialEq for Book` to `impl PartialEq<BookFormat> for Book`,
123-
/// we've changed what type we can use on the right side of the `==` operator.
124-
/// This lets us use it in the `assert!` statements at the bottom.
128+
/// we allow `BookFormat`s to be compared with `Book`s.
125129
///
126130
/// You can also combine these implementations to let the `==` operator work with
127131
/// two different types:
128132
///
129133
/// ```
134+
/// #[derive(PartialEq)]
130135
/// enum BookFormat {
131136
/// Paperback,
132137
/// Hardback,
@@ -140,12 +145,13 @@ use self::Ordering::*;
140145
///
141146
/// impl PartialEq<BookFormat> for Book {
142147
/// fn eq(&self, other: &BookFormat) -> bool {
143-
/// match (&self.format, other) {
144-
/// (&BookFormat::Paperback, &BookFormat::Paperback) => true,
145-
/// (&BookFormat::Hardback, &BookFormat::Hardback) => true,
146-
/// (&BookFormat::Ebook, &BookFormat::Ebook) => true,
147-
/// (_, _) => false,
148-
/// }
148+
/// self.format == *other
149+
/// }
150+
/// }
151+
///
152+
/// impl PartialEq<Book> for BookFormat {
153+
/// fn eq(&self, other: &Book) -> bool {
154+
/// *self == other.format
149155
/// }
150156
/// }
151157
///
@@ -159,7 +165,7 @@ use self::Ordering::*;
159165
/// let b2 = Book { isbn: 3, format: BookFormat::Ebook };
160166
///
161167
/// assert!(b1 == BookFormat::Paperback);
162-
/// assert!(b1 != BookFormat::Ebook);
168+
/// assert!(BookFormat::Ebook != b1);
163169
/// assert!(b1 == b2);
164170
/// ```
165171
///

src/libcore/ffi.rs

+21-18
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,27 @@ use ::fmt;
1212
/// and `*mut c_void` is equivalent to C's `void*`. That said, this is
1313
/// *not* the same as C's `void` return type, which is Rust's `()` type.
1414
///
15-
/// Ideally, this type would be equivalent to [`!`], but currently it may
16-
/// be more ideal to use `c_void` for FFI purposes.
15+
/// To model pointers to opaque types in FFI, until `extern type` is
16+
/// stabilized, it is recommended to use a newtype wrapper around an empty
17+
/// byte array. See the [Nomicon] for details.
1718
///
18-
/// [`!`]: ../../std/primitive.never.html
1919
/// [pointer]: ../../std/primitive.pointer.html
20+
/// [Nomicon]: https://doc.rust-lang.org/nomicon/ffi.html#representing-opaque-structs
2021
// N.B., for LLVM to recognize the void pointer type and by extension
2122
// functions like malloc(), we need to have it represented as i8* in
2223
// LLVM bitcode. The enum used here ensures this and prevents misuse
23-
// of the "raw" type by only having private variants.. We need two
24+
// of the "raw" type by only having private variants. We need two
2425
// variants, because the compiler complains about the repr attribute
25-
// otherwise.
26+
// otherwise and we need at least one variant as otherwise the enum
27+
// would be uninhabited and at least dereferencing such pointers would
28+
// be UB.
2629
#[repr(u8)]
2730
#[stable(feature = "raw_os", since = "1.1.0")]
2831
pub enum c_void {
29-
#[unstable(feature = "c_void_variant", reason = "should not have to exist",
32+
#[unstable(feature = "c_void_variant", reason = "temporary implementation detail",
3033
issue = "0")]
3134
#[doc(hidden)] __variant1,
32-
#[unstable(feature = "c_void_variant", reason = "should not have to exist",
35+
#[unstable(feature = "c_void_variant", reason = "temporary implementation detail",
3336
issue = "0")]
3437
#[doc(hidden)] __variant2,
3538
}
@@ -49,7 +52,7 @@ impl fmt::Debug for c_void {
4952
#[unstable(feature = "c_variadic",
5053
reason = "the `c_variadic` feature has not been properly tested on \
5154
all supported platforms",
52-
issue = "27745")]
55+
issue = "44930")]
5356
extern {
5457
type VaListImpl;
5558
}
@@ -74,7 +77,7 @@ impl fmt::Debug for VaListImpl {
7477
#[unstable(feature = "c_variadic",
7578
reason = "the `c_variadic` feature has not been properly tested on \
7679
all supported platforms",
77-
issue = "27745")]
80+
issue = "44930")]
7881
struct VaListImpl {
7982
stack: *mut (),
8083
gr_top: *mut (),
@@ -90,7 +93,7 @@ struct VaListImpl {
9093
#[unstable(feature = "c_variadic",
9194
reason = "the `c_variadic` feature has not been properly tested on \
9295
all supported platforms",
93-
issue = "27745")]
96+
issue = "44930")]
9497
struct VaListImpl {
9598
gpr: u8,
9699
fpr: u8,
@@ -106,7 +109,7 @@ struct VaListImpl {
106109
#[unstable(feature = "c_variadic",
107110
reason = "the `c_variadic` feature has not been properly tested on \
108111
all supported platforms",
109-
issue = "27745")]
112+
issue = "44930")]
110113
struct VaListImpl {
111114
gp_offset: i32,
112115
fp_offset: i32,
@@ -120,7 +123,7 @@ struct VaListImpl {
120123
#[unstable(feature = "c_variadic",
121124
reason = "the `c_variadic` feature has not been properly tested on \
122125
all supported platforms",
123-
issue = "27745")]
126+
issue = "44930")]
124127
#[repr(transparent)]
125128
pub struct VaList<'a>(&'a mut VaListImpl);
126129

@@ -140,7 +143,7 @@ mod sealed_trait {
140143
#[unstable(feature = "c_variadic",
141144
reason = "the `c_variadic` feature has not been properly tested on \
142145
all supported platforms",
143-
issue = "27745")]
146+
issue = "44930")]
144147
pub trait VaArgSafe {}
145148
}
146149

@@ -150,7 +153,7 @@ macro_rules! impl_va_arg_safe {
150153
#[unstable(feature = "c_variadic",
151154
reason = "the `c_variadic` feature has not been properly tested on \
152155
all supported platforms",
153-
issue = "27745")]
156+
issue = "44930")]
154157
impl sealed_trait::VaArgSafe for $t {}
155158
)+
156159
}
@@ -163,20 +166,20 @@ impl_va_arg_safe!{f64}
163166
#[unstable(feature = "c_variadic",
164167
reason = "the `c_variadic` feature has not been properly tested on \
165168
all supported platforms",
166-
issue = "27745")]
169+
issue = "44930")]
167170
impl<T> sealed_trait::VaArgSafe for *mut T {}
168171
#[unstable(feature = "c_variadic",
169172
reason = "the `c_variadic` feature has not been properly tested on \
170173
all supported platforms",
171-
issue = "27745")]
174+
issue = "44930")]
172175
impl<T> sealed_trait::VaArgSafe for *const T {}
173176

174177
impl<'a> VaList<'a> {
175178
/// Advance to the next arg.
176179
#[unstable(feature = "c_variadic",
177180
reason = "the `c_variadic` feature has not been properly tested on \
178181
all supported platforms",
179-
issue = "27745")]
182+
issue = "44930")]
180183
pub unsafe fn arg<T: sealed_trait::VaArgSafe>(&mut self) -> T {
181184
va_arg(self)
182185
}
@@ -185,7 +188,7 @@ impl<'a> VaList<'a> {
185188
#[unstable(feature = "c_variadic",
186189
reason = "the `c_variadic` feature has not been properly tested on \
187190
all supported platforms",
188-
issue = "27745")]
191+
issue = "44930")]
189192
pub unsafe fn copy<F, R>(&self, f: F) -> R
190193
where F: for<'copy> FnOnce(VaList<'copy>) -> R {
191194
#[cfg(any(all(not(target_arch = "aarch64"), not(target_arch = "powerpc"),

src/libcore/pin.rs

+45-3
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999

100100
use fmt;
101101
use marker::{Sized, Unpin};
102+
use cmp::{self, PartialEq, PartialOrd};
102103
use ops::{Deref, DerefMut, Receiver, CoerceUnsized, DispatchFromDyn};
103104

104105
/// A pinned pointer.
@@ -112,16 +113,57 @@ use ops::{Deref, DerefMut, Receiver, CoerceUnsized, DispatchFromDyn};
112113
/// [`Unpin`]: ../../std/marker/trait.Unpin.html
113114
/// [`pin` module]: ../../std/pin/index.html
114115
//
115-
// Note: the derives below are allowed because they all only use `&P`, so they
116-
// cannot move the value behind `pointer`.
116+
// Note: the derives below, and the explicit `PartialEq` and `PartialOrd`
117+
// implementations, are allowed because they all only use `&P`, so they cannot move
118+
// the value behind `pointer`.
117119
#[stable(feature = "pin", since = "1.33.0")]
118120
#[fundamental]
119121
#[repr(transparent)]
120-
#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
122+
#[derive(Copy, Clone, Hash, Eq, Ord)]
121123
pub struct Pin<P> {
122124
pointer: P,
123125
}
124126

127+
#[stable(feature = "pin_partialeq_partialord_impl_applicability", since = "1.34.0")]
128+
impl<P, Q> PartialEq<Pin<Q>> for Pin<P>
129+
where
130+
P: PartialEq<Q>,
131+
{
132+
fn eq(&self, other: &Pin<Q>) -> bool {
133+
self.pointer == other.pointer
134+
}
135+
136+
fn ne(&self, other: &Pin<Q>) -> bool {
137+
self.pointer != other.pointer
138+
}
139+
}
140+
141+
#[stable(feature = "pin_partialeq_partialord_impl_applicability", since = "1.34.0")]
142+
impl<P, Q> PartialOrd<Pin<Q>> for Pin<P>
143+
where
144+
P: PartialOrd<Q>,
145+
{
146+
fn partial_cmp(&self, other: &Pin<Q>) -> Option<cmp::Ordering> {
147+
self.pointer.partial_cmp(&other.pointer)
148+
}
149+
150+
fn lt(&self, other: &Pin<Q>) -> bool {
151+
self.pointer < other.pointer
152+
}
153+
154+
fn le(&self, other: &Pin<Q>) -> bool {
155+
self.pointer <= other.pointer
156+
}
157+
158+
fn gt(&self, other: &Pin<Q>) -> bool {
159+
self.pointer > other.pointer
160+
}
161+
162+
fn ge(&self, other: &Pin<Q>) -> bool {
163+
self.pointer >= other.pointer
164+
}
165+
}
166+
125167
impl<P: Deref> Pin<P>
126168
where
127169
P::Target: Unpin,

src/librustdoc/html/render.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,7 @@ themePicker.onblur = handleThemeButtonsBlur;
10761076
all_sources.sort();
10771077
let mut w = try_err!(File::create(&dst), &dst);
10781078
try_err!(writeln!(&mut w,
1079-
"var N = null;var sourcesIndex = {{}};\n{}",
1079+
"var N = null;var sourcesIndex = {{}};\n{}\ncreateSourceSidebar();",
10801080
all_sources.join("\n")),
10811081
&dst);
10821082
}

src/librustdoc/html/static/rustdoc.css

-4
Original file line numberDiff line numberDiff line change
@@ -391,10 +391,6 @@ h4 > code, h3 > code, .invisible > code {
391391
display: block;
392392
}
393393

394-
.in-band, code {
395-
z-index: -5;
396-
}
397-
398394
.invisible {
399395
width: 100%;
400396
display: inline-block;

src/librustdoc/html/static/source-script.js

-2
Original file line numberDiff line numberDiff line change
@@ -137,5 +137,3 @@ function createSourceSidebar() {
137137

138138
main.insertBefore(sidebar, main.firstChild);
139139
}
140-
141-
createSourceSidebar();

src/librustdoc/html/static/themes/dark.css

+1-7
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,6 @@ pre {
8282
border-bottom-color: #ddd;
8383
}
8484

85-
:target { background: #494a3d; }
86-
87-
:target > .in-band {
88-
background: #494a3d;
89-
}
90-
9185
.content .method .where,
9286
.content .fn .where,
9387
.content .where.fmt-newline {
@@ -252,7 +246,7 @@ a.test-arrow:hover{
252246
color: #999;
253247
}
254248

255-
:target > code {
249+
:target > code, :target > .in-band {
256250
background-color: #494a3d;
257251
}
258252

src/librustdoc/html/static/themes/light.css

+1-7
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,6 @@ pre {
8484
border-bottom-color: #ddd;
8585
}
8686

87-
:target { background: #FDFFD3; }
88-
89-
:target > .in-band {
90-
background: #FDFFD3;
91-
}
92-
9387
.content .method .where,
9488
.content .fn .where,
9589
.content .where.fmt-newline {
@@ -247,7 +241,7 @@ a.test-arrow:hover{
247241
color: #999;
248242
}
249243

250-
:target > code {
244+
:target > code, :target > .in-band {
251245
background: #FDFFD3;
252246
}
253247

src/libstd/ffi/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ pub use core::ffi::c_void;
169169
#[unstable(feature = "c_variadic",
170170
reason = "the `c_variadic` feature has not been properly tested on \
171171
all supported platforms",
172-
issue = "27745")]
172+
issue = "44930")]
173173
pub use core::ffi::VaList;
174174

175175
mod c_str;

0 commit comments

Comments
 (0)