Skip to content

Commit 43b9d5f

Browse files
author
The Miri Cronjob Bot
committed
Merge from rustc
2 parents c21a43f + c3dfc2e commit 43b9d5f

File tree

18 files changed

+106
-69
lines changed

18 files changed

+106
-69
lines changed

alloc/src/slice.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,6 @@ impl<T> [T] {
493493
///
494494
/// # Examples
495495
///
496-
/// Basic usage:
497-
///
498496
/// ```
499497
/// assert_eq!([1, 2].repeat(3), vec![1, 2, 1, 2, 1, 2]);
500498
/// ```

alloc/src/str.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,6 @@ impl str {
246246
///
247247
/// # Examples
248248
///
249-
/// Basic usage:
250-
///
251249
/// ```
252250
/// let s = "this is old";
253251
///
@@ -303,8 +301,6 @@ impl str {
303301
///
304302
/// # Examples
305303
///
306-
/// Basic usage:
307-
///
308304
/// ```
309305
/// let s = "foo foo 123 foo";
310306
/// assert_eq!("new new 123 foo", s.replacen("foo", "new", 2));

core/src/fmt/num.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,8 +678,8 @@ impl fmt::Display for i128 {
678678
/// It also has to handle 1 last item, as 10^40 > 2^128 > 10^39, whereas
679679
/// 10^20 > 2^64 > 10^19.
680680
fn fmt_u128(n: u128, is_nonnegative: bool, f: &mut fmt::Formatter<'_>) -> fmt::Result {
681-
// 2^128 is about 3*10^38, so 39 gives an extra byte of space
682-
let mut buf = [MaybeUninit::<u8>::uninit(); 39];
681+
const MAX_DEC_N: usize = u128::MAX.ilog(10) as usize + 1;
682+
let mut buf = [MaybeUninit::<u8>::uninit(); MAX_DEC_N];
683683
let mut curr = buf.len();
684684

685685
let (n, rem) = udiv_1e19(n);

core/src/num/nonzero.rs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -551,8 +551,6 @@ macro_rules! nonzero_integer {
551551
///
552552
/// # Examples
553553
///
554-
/// Basic usage:
555-
///
556554
/// ```
557555
/// # use std::num::NonZero;
558556
/// #
@@ -583,8 +581,6 @@ macro_rules! nonzero_integer {
583581
///
584582
/// # Examples
585583
///
586-
/// Basic usage:
587-
///
588584
/// ```
589585
/// # use std::num::NonZero;
590586
/// #
@@ -612,8 +608,6 @@ macro_rules! nonzero_integer {
612608
///
613609
/// # Example
614610
///
615-
/// Basic usage:
616-
///
617611
/// ```
618612
/// #![feature(isolate_most_least_significant_one)]
619613
///
@@ -644,8 +638,6 @@ macro_rules! nonzero_integer {
644638
///
645639
/// # Example
646640
///
647-
/// Basic usage:
648-
///
649641
/// ```
650642
/// #![feature(isolate_most_least_significant_one)]
651643
///
@@ -676,8 +668,6 @@ macro_rules! nonzero_integer {
676668
///
677669
/// # Examples
678670
///
679-
/// Basic usage:
680-
///
681671
/// ```
682672
/// # use std::num::NonZero;
683673
/// #
@@ -713,8 +703,6 @@ macro_rules! nonzero_integer {
713703
///
714704
/// # Examples
715705
///
716-
/// Basic usage:
717-
///
718706
/// ```
719707
/// #![feature(nonzero_bitwise)]
720708
/// # use std::num::NonZero;
@@ -746,8 +734,6 @@ macro_rules! nonzero_integer {
746734
///
747735
/// # Examples
748736
///
749-
/// Basic usage:
750-
///
751737
/// ```
752738
/// #![feature(nonzero_bitwise)]
753739
/// # use std::num::NonZero;
@@ -775,8 +761,6 @@ macro_rules! nonzero_integer {
775761
///
776762
/// # Examples
777763
///
778-
/// Basic usage:
779-
///
780764
/// ```
781765
/// #![feature(nonzero_bitwise)]
782766
/// # use std::num::NonZero;
@@ -805,8 +789,6 @@ macro_rules! nonzero_integer {
805789
///
806790
/// # Examples
807791
///
808-
/// Basic usage:
809-
///
810792
/// ```
811793
/// #![feature(nonzero_bitwise)]
812794
/// # use std::num::NonZero;
@@ -837,8 +819,6 @@ macro_rules! nonzero_integer {
837819
///
838820
/// # Examples
839821
///
840-
/// Basic usage:
841-
///
842822
/// ```
843823
/// #![feature(nonzero_bitwise)]
844824
/// # use std::num::NonZero;
@@ -872,8 +852,6 @@ macro_rules! nonzero_integer {
872852
///
873853
/// # Examples
874854
///
875-
/// Basic usage:
876-
///
877855
/// ```
878856
/// #![feature(nonzero_bitwise)]
879857
/// # use std::num::NonZero;
@@ -907,8 +885,6 @@ macro_rules! nonzero_integer {
907885
///
908886
/// # Examples
909887
///
910-
/// Basic usage:
911-
///
912888
/// ```
913889
/// #![feature(nonzero_bitwise)]
914890
/// # use std::num::NonZero;
@@ -942,8 +918,6 @@ macro_rules! nonzero_integer {
942918
///
943919
/// # Examples
944920
///
945-
/// Basic usage:
946-
///
947921
/// ```
948922
/// #![feature(nonzero_bitwise)]
949923
/// # use std::num::NonZero;
@@ -1635,8 +1609,6 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
16351609
///
16361610
/// # Examples
16371611
///
1638-
/// Basic usage:
1639-
///
16401612
/// ```
16411613
/// # use std::num::NonZero;
16421614
/// #
@@ -1666,7 +1638,6 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
16661638
///
16671639
/// # Examples
16681640
///
1669-
/// Basic usage:
16701641
/// ```
16711642
/// # use std::num::NonZero;
16721643
/// #
@@ -1699,8 +1670,6 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
16991670
///
17001671
/// # Examples
17011672
///
1702-
/// Basic usage:
1703-
///
17041673
/// ```
17051674
/// # use std::num::NonZero;
17061675
///
@@ -2138,8 +2107,6 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
21382107
///
21392108
/// # Examples
21402109
///
2141-
/// Basic usage:
2142-
///
21432110
/// ```
21442111
/// # use std::num::NonZero;
21452112
///

std/src/ffi/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ pub use core::ffi::{
178178
c_char, c_double, c_float, c_int, c_long, c_longlong, c_schar, c_short, c_uchar, c_uint,
179179
c_ulong, c_ulonglong, c_ushort,
180180
};
181+
#[unstable(feature = "c_size_t", issue = "88345")]
182+
pub use core::ffi::{c_ptrdiff_t, c_size_t, c_ssize_t};
181183

182184
#[doc(inline)]
183185
#[stable(feature = "cstr_from_bytes_until_nul", since = "1.69.0")]

std/src/fs.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,9 +1311,39 @@ impl Write for &File {
13111311
}
13121312
#[stable(feature = "rust1", since = "1.0.0")]
13131313
impl Seek for &File {
1314+
/// Seek to an offset, in bytes in a file.
1315+
///
1316+
/// See [`Seek::seek`] docs for more info.
1317+
///
1318+
/// # Platform-specific behavior
1319+
///
1320+
/// This function currently corresponds to the `lseek64` function on Unix
1321+
/// and the `SetFilePointerEx` function on Windows. Note that this [may
1322+
/// change in the future][changes].
1323+
///
1324+
/// [changes]: io#platform-specific-behavior
13141325
fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
13151326
self.inner.seek(pos)
13161327
}
1328+
1329+
/// Returns the length of this file (in bytes).
1330+
///
1331+
/// See [`Seek::stream_len`] docs for more info.
1332+
///
1333+
/// # Platform-specific behavior
1334+
///
1335+
/// This function currently corresponds to the `statx` function on Linux
1336+
/// (with fallbacks) and the `GetFileSizeEx` function on Windows. Note that
1337+
/// this [may change in the future][changes].
1338+
///
1339+
/// [changes]: io#platform-specific-behavior
1340+
fn stream_len(&mut self) -> io::Result<u64> {
1341+
if let Some(result) = self.inner.size() {
1342+
return result;
1343+
}
1344+
io::stream_len_default(self)
1345+
}
1346+
13171347
fn stream_position(&mut self) -> io::Result<u64> {
13181348
self.inner.tell()
13191349
}
@@ -1363,6 +1393,9 @@ impl Seek for File {
13631393
fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
13641394
(&*self).seek(pos)
13651395
}
1396+
fn stream_len(&mut self) -> io::Result<u64> {
1397+
(&*self).stream_len()
1398+
}
13661399
fn stream_position(&mut self) -> io::Result<u64> {
13671400
(&*self).stream_position()
13681401
}
@@ -1412,6 +1445,9 @@ impl Seek for Arc<File> {
14121445
fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
14131446
(&**self).seek(pos)
14141447
}
1448+
fn stream_len(&mut self) -> io::Result<u64> {
1449+
(&**self).stream_len()
1450+
}
14151451
fn stream_position(&mut self) -> io::Result<u64> {
14161452
(&**self).stream_position()
14171453
}

std/src/io/mod.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2028,7 +2028,7 @@ pub trait Seek {
20282028

20292029
/// Returns the length of this stream (in bytes).
20302030
///
2031-
/// This method is implemented using up to three seek operations. If this
2031+
/// The default implementation uses up to three seek operations. If this
20322032
/// method returns successfully, the seek position is unchanged (i.e. the
20332033
/// position before calling this method is the same as afterwards).
20342034
/// However, if this method returns an error, the seek position is
@@ -2062,16 +2062,7 @@ pub trait Seek {
20622062
/// ```
20632063
#[unstable(feature = "seek_stream_len", issue = "59359")]
20642064
fn stream_len(&mut self) -> Result<u64> {
2065-
let old_pos = self.stream_position()?;
2066-
let len = self.seek(SeekFrom::End(0))?;
2067-
2068-
// Avoid seeking a third time when we were already at the end of the
2069-
// stream. The branch is usually way cheaper than a seek operation.
2070-
if old_pos != len {
2071-
self.seek(SeekFrom::Start(old_pos))?;
2072-
}
2073-
2074-
Ok(len)
2065+
stream_len_default(self)
20752066
}
20762067

20772068
/// Returns the current seek position from the start of the stream.
@@ -2132,6 +2123,19 @@ pub trait Seek {
21322123
}
21332124
}
21342125

2126+
pub(crate) fn stream_len_default<T: Seek + ?Sized>(self_: &mut T) -> Result<u64> {
2127+
let old_pos = self_.stream_position()?;
2128+
let len = self_.seek(SeekFrom::End(0))?;
2129+
2130+
// Avoid seeking a third time when we were already at the end of the
2131+
// stream. The branch is usually way cheaper than a seek operation.
2132+
if old_pos != len {
2133+
self_.seek(SeekFrom::Start(old_pos))?;
2134+
}
2135+
2136+
Ok(len)
2137+
}
2138+
21352139
/// Enumeration of possible methods to seek within an I/O object.
21362140
///
21372141
/// It is used by the [`Seek`] trait.

std/src/keyword_docs.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,10 +1916,6 @@ mod type_keyword {}
19161916
/// - and to declare that a programmer has checked that these contracts have been upheld (`unsafe
19171917
/// {}` and `unsafe impl`, but also `unsafe fn` -- see below).
19181918
///
1919-
/// They are not mutually exclusive, as can be seen in `unsafe fn`: the body of an `unsafe fn` is,
1920-
/// by default, treated like an unsafe block. The `unsafe_op_in_unsafe_fn` lint can be enabled to
1921-
/// change that.
1922-
///
19231919
/// # Unsafe abilities
19241920
///
19251921
/// **No matter what, Safe Rust can't cause Undefined Behavior**. This is
@@ -1961,13 +1957,6 @@ mod type_keyword {}
19611957
/// - `unsafe impl`: the contract necessary to implement the trait has been
19621958
/// checked by the programmer and is guaranteed to be respected.
19631959
///
1964-
/// By default, `unsafe fn` also acts like an `unsafe {}` block
1965-
/// around the code inside the function. This means it is not just a signal to
1966-
/// the caller, but also promises that the preconditions for the operations
1967-
/// inside the function are upheld. Mixing these two meanings can be confusing, so the
1968-
/// `unsafe_op_in_unsafe_fn` lint can be enabled to warn against that and require explicit unsafe
1969-
/// blocks even inside `unsafe fn`.
1970-
///
19711960
/// See the [Rustonomicon] and the [Reference] for more information.
19721961
///
19731962
/// # Examples
@@ -2109,6 +2098,7 @@ mod type_keyword {}
21092098
/// impl Indexable for i32 {
21102099
/// const LEN: usize = 1;
21112100
///
2101+
/// /// See `Indexable` for the safety contract.
21122102
/// unsafe fn idx_unchecked(&self, idx: usize) -> i32 {
21132103
/// debug_assert_eq!(idx, 0);
21142104
/// *self
@@ -2120,6 +2110,7 @@ mod type_keyword {}
21202110
/// impl Indexable for [i32; 42] {
21212111
/// const LEN: usize = 42;
21222112
///
2113+
/// /// See `Indexable` for the safety contract.
21232114
/// unsafe fn idx_unchecked(&self, idx: usize) -> i32 {
21242115
/// // SAFETY: As per this trait's documentation, the caller ensures
21252116
/// // that `idx < 42`.
@@ -2132,6 +2123,7 @@ mod type_keyword {}
21322123
/// impl Indexable for ! {
21332124
/// const LEN: usize = 0;
21342125
///
2126+
/// /// See `Indexable` for the safety contract.
21352127
/// unsafe fn idx_unchecked(&self, idx: usize) -> i32 {
21362128
/// // SAFETY: As per this trait's documentation, the caller ensures
21372129
/// // that `idx < 0`, which is impossible, so this is dead code.
@@ -2153,11 +2145,14 @@ mod type_keyword {}
21532145
/// contract of `idx_unchecked`. Implementing `Indexable` is safe because when writing
21542146
/// `idx_unchecked`, we don't have to worry: our *callers* need to discharge a proof obligation
21552147
/// (like `use_indexable` does), but the *implementation* of `get_unchecked` has no proof obligation
2156-
/// to contend with. Of course, the implementation of `Indexable` may choose to call other unsafe
2157-
/// operations, and then it needs an `unsafe` *block* to indicate it discharged the proof
2158-
/// obligations of its callees. (We enabled `unsafe_op_in_unsafe_fn`, so the body of `idx_unchecked`
2159-
/// is not implicitly an unsafe block.) For that purpose it can make use of the contract that all
2160-
/// its callers must uphold -- the fact that `idx < LEN`.
2148+
/// to contend with. Of course, the implementation may choose to call other unsafe operations, and
2149+
/// then it needs an `unsafe` *block* to indicate it discharged the proof obligations of its
2150+
/// callees. For that purpose it can make use of the contract that all its callers must uphold --
2151+
/// the fact that `idx < LEN`.
2152+
///
2153+
/// Note that unlike normal `unsafe fn`, an `unsafe fn` in a trait implementation does not get to
2154+
/// just pick an arbitrary safety contract! It *has* to use the safety contract defined by the trait
2155+
/// (or one with weaker preconditions).
21612156
///
21622157
/// Formally speaking, an `unsafe fn` in a trait is a function with *preconditions* that go beyond
21632158
/// those encoded by the argument types (such as `idx < LEN`), whereas an `unsafe trait` can declare

std/src/sys/fs/hermit.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,10 @@ impl File {
422422
self.0.seek(pos)
423423
}
424424

425+
pub fn size(&self) -> Option<io::Result<u64>> {
426+
None
427+
}
428+
425429
pub fn tell(&self) -> io::Result<u64> {
426430
self.0.tell()
427431
}

std/src/sys/fs/solid.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,10 @@ impl File {
459459
self.tell()
460460
}
461461

462+
pub fn size(&self) -> Option<io::Result<u64>> {
463+
None
464+
}
465+
462466
pub fn tell(&self) -> io::Result<u64> {
463467
unsafe {
464468
let mut out_offset = MaybeUninit::uninit();

0 commit comments

Comments
 (0)