Skip to content

Commit d6525ef

Browse files
committed
Auto merge of #57542 - Centril:rollup, r=Centril
Rollup of 26 pull requests Successful merges: - #56425 (Redo the docs for Vec::set_len) - #56906 (Issue #56905) - #57042 (Don't call `FieldPlacement::count` when count is too large) - #57175 (Stabilize `let` bindings and destructuring in constants and const fn) - #57192 (Change std::error::Error trait documentation to talk about `source` instead of `cause`) - #57296 (Fixed the link to the ? operator) - #57368 (Use CMAKE_{C,CXX}_COMPILER_LAUNCHER for ccache) - #57400 (Rustdoc: update Source Serif Pro and replace Heuristica italic) - #57417 (rustdoc: use text-based doctest parsing if a macro is wrapping main) - #57433 (Add link destination for `read-ownership`) - #57434 (Remove `CrateNum::Invalid`.) - #57441 (Supporting backtrace for x86_64-fortanix-unknown-sgx.) - #57450 (actually take a slice in this example) - #57459 (Reference tracking issue for inherent associated types in diagnostic) - #57463 (docs: Fix some 'second-edition' links) - #57466 (Remove outdated comment) - #57493 (use structured suggestion when casting a reference) - #57498 (make note of one more normalization that Paths do) - #57499 (note that FromStr does not work for borrowed types) - #57505 (Remove submodule step from README) - #57510 (Add a profiles section to the manifest) - #57511 (Fix undefined behavior) - #57519 (Correct RELEASES.md for 1.32.0) - #57522 (don't unwrap unexpected tokens in `format!`) - #57530 (Fixing a typographical error.) - #57535 (Stabilise irrefutable if-let and while-let patterns) Failed merges: r? @ghost
2 parents 1190f7c + 3117784 commit d6525ef

File tree

170 files changed

+999
-1485
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

170 files changed

+999
-1485
lines changed

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ Read ["Installation"] from [The Book].
3838
3. Build and install:
3939

4040
```sh
41-
$ git submodule update --init --recursive --progress
4241
$ ./x.py build && sudo ./x.py install
4342
```
4443

RELEASES.md

+24
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ Stabilized APIs
121121
- [`i64::from_be_bytes`]
122122
- [`i64::from_le_bytes`]
123123
- [`i64::from_ne_bytes`]
124+
- [`i128::to_be_bytes`]
125+
- [`i128::to_le_bytes`]
126+
- [`i128::to_ne_bytes`]
127+
- [`i128::from_be_bytes`]
128+
- [`i128::from_le_bytes`]
129+
- [`i128::from_ne_bytes`]
124130
- [`isize::to_be_bytes`]
125131
- [`isize::to_le_bytes`]
126132
- [`isize::to_ne_bytes`]
@@ -151,6 +157,12 @@ Stabilized APIs
151157
- [`u64::from_be_bytes`]
152158
- [`u64::from_le_bytes`]
153159
- [`u64::from_ne_bytes`]
160+
- [`u128::to_be_bytes`]
161+
- [`u128::to_le_bytes`]
162+
- [`u128::to_ne_bytes`]
163+
- [`u128::from_be_bytes`]
164+
- [`u128::from_le_bytes`]
165+
- [`u128::from_ne_bytes`]
154166
- [`usize::to_be_bytes`]
155167
- [`usize::to_le_bytes`]
156168
- [`usize::to_ne_bytes`]
@@ -208,6 +220,12 @@ Compatibility Notes
208220
[`UnsafeCell::get`]: https://doc.rust-lang.org/std/cell/struct.UnsafeCell.html#method.get
209221
[`slice::as_ptr`]: https://doc.rust-lang.org/std/primitive.slice.html#method.as_ptr
210222
[`char::is_ascii`]: https://doc.rust-lang.org/std/primitive.char.html#method.is_ascii
223+
[`i128::from_be_bytes`]: https://doc.rust-lang.org/stable/std/primitive.i128.html#method.from_be_bytes
224+
[`i128::from_le_bytes`]: https://doc.rust-lang.org/stable/std/primitive.i128.html#method.from_le_bytes
225+
[`i128::from_ne_bytes`]: https://doc.rust-lang.org/stable/std/primitive.i128.html#method.from_ne_bytes
226+
[`i128::to_be_bytes`]: https://doc.rust-lang.org/stable/std/primitive.i128.html#method.to_be_bytes
227+
[`i128::to_le_bytes`]: https://doc.rust-lang.org/stable/std/primitive.i128.html#method.to_le_bytes
228+
[`i128::to_ne_bytes`]: https://doc.rust-lang.org/stable/std/primitive.i128.html#method.to_ne_bytes
211229
[`i16::from_be_bytes`]: https://doc.rust-lang.org/stable/std/primitive.i16.html#method.from_be_bytes
212230
[`i16::from_le_bytes`]: https://doc.rust-lang.org/stable/std/primitive.i16.html#method.from_le_bytes
213231
[`i16::from_ne_bytes`]: https://doc.rust-lang.org/stable/std/primitive.i16.html#method.from_ne_bytes
@@ -240,6 +258,12 @@ Compatibility Notes
240258
[`isize::to_ne_bytes`]: https://doc.rust-lang.org/stable/std/primitive.isize.html#method.to_ne_bytes
241259
[`iter::empty`]: https://doc.rust-lang.org/std/iter/fn.empty.html
242260
[`str::as_ptr`]: https://doc.rust-lang.org/std/primitive.str.html#method.as_ptr
261+
[`u128::from_be_bytes`]: https://doc.rust-lang.org/stable/std/primitive.u128.html#method.from_be_bytes
262+
[`u128::from_le_bytes`]: https://doc.rust-lang.org/stable/std/primitive.u128.html#method.from_le_bytes
263+
[`u128::from_ne_bytes`]: https://doc.rust-lang.org/stable/std/primitive.u128.html#method.from_ne_bytes
264+
[`u128::to_be_bytes`]: https://doc.rust-lang.org/stable/std/primitive.u128.html#method.to_be_bytes
265+
[`u128::to_le_bytes`]: https://doc.rust-lang.org/stable/std/primitive.u128.html#method.to_le_bytes
266+
[`u128::to_ne_bytes`]: https://doc.rust-lang.org/stable/std/primitive.u128.html#method.to_ne_bytes
243267
[`u16::from_be_bytes`]: https://doc.rust-lang.org/stable/std/primitive.u16.html#method.from_be_bytes
244268
[`u16::from_le_bytes`]: https://doc.rust-lang.org/stable/std/primitive.u16.html#method.from_le_bytes
245269
[`u16::from_ne_bytes`]: https://doc.rust-lang.org/stable/std/primitive.u16.html#method.from_ne_bytes

config.toml.example

+1-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@
288288
#codegen-units-std = 1
289289

290290
# Whether or not debug assertions are enabled for the compiler and standard
291-
# library. Also enables compilation of debug! and trace! logging macros.
291+
# library.
292292
#debug-assertions = false
293293

294294
# Whether or not debuginfo is emitted

src/bootstrap/native.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -346,15 +346,13 @@ fn configure_cmake(builder: &Builder,
346346
if builder.config.llvm_clang_cl.is_some() && target.contains("i686") {
347347
cfg.env("SCCACHE_EXTRA_ARGS", "-m32");
348348
}
349-
350-
// If ccache is configured we inform the build a little differently how
351-
// to invoke ccache while also invoking our compilers.
352-
} else if let Some(ref ccache) = builder.config.ccache {
353-
cfg.define("CMAKE_C_COMPILER", ccache)
354-
.define("CMAKE_C_COMPILER_ARG1", sanitize_cc(cc))
355-
.define("CMAKE_CXX_COMPILER", ccache)
356-
.define("CMAKE_CXX_COMPILER_ARG1", sanitize_cc(cxx));
357349
} else {
350+
// If ccache is configured we inform the build a little differently how
351+
// to invoke ccache while also invoking our compilers.
352+
if let Some(ref ccache) = builder.config.ccache {
353+
cfg.define("CMAKE_C_COMPILER_LAUNCHER", ccache)
354+
.define("CMAKE_CXX_COMPILER_LAUNCHER", ccache);
355+
}
358356
cfg.define("CMAKE_C_COMPILER", sanitize_cc(cc))
359357
.define("CMAKE_CXX_COMPILER", sanitize_cc(cxx));
360358
}

src/doc/unstable-book/src/language-features/irrefutable-let-patterns.md

-28
This file was deleted.

src/liballoc/vec.rs

+62-27
Original file line numberDiff line numberDiff line change
@@ -738,53 +738,88 @@ impl<T> Vec<T> {
738738
self
739739
}
740740

741-
/// Sets the length of a vector.
741+
/// Forces the length of the vector to `new_len`.
742742
///
743-
/// This will explicitly set the size of the vector, without actually
744-
/// modifying its buffers, so it is up to the caller to ensure that the
745-
/// vector is actually the specified size.
743+
/// This is a low-level operation that maintains none of the normal
744+
/// invariants of the type. Normally changing the length of a vector
745+
/// is done using one of the safe operations instead, such as
746+
/// [`truncate`], [`resize`], [`extend`], or [`clear`].
746747
///
747-
/// # Examples
748+
/// [`truncate`]: #method.truncate
749+
/// [`resize`]: #method.resize
750+
/// [`extend`]: #method.extend-1
751+
/// [`clear`]: #method.clear
748752
///
749-
/// ```
750-
/// use std::ptr;
753+
/// # Safety
751754
///
752-
/// let mut vec = vec!['r', 'u', 's', 't'];
755+
/// - `new_len` must be less than or equal to [`capacity()`].
756+
/// - The elements at `old_len..new_len` must be initialized.
753757
///
754-
/// unsafe {
755-
/// ptr::drop_in_place(&mut vec[3]);
756-
/// vec.set_len(3);
758+
/// [`capacity()`]: #method.capacity
759+
///
760+
/// # Examples
761+
///
762+
/// This method can be useful for situations in which the vector
763+
/// is serving as a buffer for other code, particularly over FFI:
764+
///
765+
/// ```no_run
766+
/// # #![allow(dead_code)]
767+
/// # // This is just a minimal skeleton for the doc example;
768+
/// # // don't use this as a starting point for a real library.
769+
/// # pub struct StreamWrapper { strm: *mut std::ffi::c_void }
770+
/// # const Z_OK: i32 = 0;
771+
/// # extern "C" {
772+
/// # fn deflateGetDictionary(
773+
/// # strm: *mut std::ffi::c_void,
774+
/// # dictionary: *mut u8,
775+
/// # dictLength: *mut usize,
776+
/// # ) -> i32;
777+
/// # }
778+
/// # impl StreamWrapper {
779+
/// pub fn get_dictionary(&self) -> Option<Vec<u8>> {
780+
/// // Per the FFI method's docs, "32768 bytes is always enough".
781+
/// let mut dict = Vec::with_capacity(32_768);
782+
/// let mut dict_length = 0;
783+
/// // SAFETY: When `deflateGetDictionary` returns `Z_OK`, it holds that:
784+
/// // 1. `dict_length` elements were initialized.
785+
/// // 2. `dict_length` <= the capacity (32_768)
786+
/// // which makes `set_len` safe to call.
787+
/// unsafe {
788+
/// // Make the FFI call...
789+
/// let r = deflateGetDictionary(self.strm, dict.as_mut_ptr(), &mut dict_length);
790+
/// if r == Z_OK {
791+
/// // ...and update the length to what was initialized.
792+
/// dict.set_len(dict_length);
793+
/// Some(dict)
794+
/// } else {
795+
/// None
796+
/// }
797+
/// }
757798
/// }
758-
/// assert_eq!(vec, ['r', 'u', 's']);
799+
/// # }
759800
/// ```
760801
///
761-
/// In this example, there is a memory leak since the memory locations
762-
/// owned by the inner vectors were not freed prior to the `set_len` call:
802+
/// While the following example is sound, there is a memory leak since
803+
/// the inner vectors were not freed prior to the `set_len` call:
763804
///
764805
/// ```
765806
/// let mut vec = vec![vec![1, 0, 0],
766807
/// vec![0, 1, 0],
767808
/// vec![0, 0, 1]];
809+
/// // SAFETY:
810+
/// // 1. `old_len..0` is empty so no elements need to be initialized.
811+
/// // 2. `0 <= capacity` always holds whatever `capacity` is.
768812
/// unsafe {
769813
/// vec.set_len(0);
770814
/// }
771815
/// ```
772816
///
773-
/// In this example, the vector gets expanded from zero to four items
774-
/// without any memory allocations occurring, resulting in vector
775-
/// values of unallocated memory:
776-
///
777-
/// ```
778-
/// let mut vec: Vec<char> = Vec::new();
779-
///
780-
/// unsafe {
781-
/// vec.set_len(4);
782-
/// }
783-
/// ```
817+
/// Normally, here, one would use [`clear`] instead to correctly drop
818+
/// the contents and thus not leak memory.
784819
#[inline]
785820
#[stable(feature = "rust1", since = "1.0.0")]
786-
pub unsafe fn set_len(&mut self, len: usize) {
787-
self.len = len;
821+
pub unsafe fn set_len(&mut self, new_len: usize) {
822+
self.len = new_len;
788823
}
789824

790825
/// Removes an element from the vector and returns it.

src/libcore/ptr.rs

+1
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,7 @@ pub unsafe fn write_unaligned<T>(dst: *mut T, src: T) {
849849
/// [valid]: ../ptr/index.html#safety
850850
/// [`Copy`]: ../marker/trait.Copy.html
851851
/// [`read`]: ./fn.read.html
852+
/// [read-ownership]: ./fn.read.html#ownership-of-the-returned-value
852853
///
853854
/// Just like in C, whether an operation is volatile has no bearing whatsoever
854855
/// on questions involving concurrent access from multiple threads. Volatile

src/libcore/str/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ pub mod pattern;
2020
#[allow(missing_docs)]
2121
pub mod lossy;
2222

23-
/// A trait to abstract the idea of creating a new instance of a type from a
24-
/// string.
23+
/// Parse a value from a string
2524
///
2625
/// `FromStr`'s [`from_str`] method is often used implicitly, through
2726
/// [`str`]'s [`parse`] method. See [`parse`]'s documentation for examples.
@@ -30,6 +29,11 @@ pub mod lossy;
3029
/// [`str`]: ../../std/primitive.str.html
3130
/// [`parse`]: ../../std/primitive.str.html#method.parse
3231
///
32+
/// `FromStr` does not have a lifetime parameter, and so you can only parse types
33+
/// that do not contain a lifetime parameter themselves. In other words, you can
34+
/// parse an `i32` with `FromStr`, but not a `&i32`. You can parse a struct that
35+
/// contains an `i32`, but not one that contains an `&i32`.
36+
///
3337
/// # Examples
3438
///
3539
/// Basic implementation of `FromStr` on an example `Point` type:

src/librustc/hir/def_id.rs

-4
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ pub enum CrateNum {
1717
// FIXME(jseyfried): this is also used for custom derives until proc-macro crates get
1818
// `CrateNum`s.
1919
BuiltinMacros,
20-
/// A CrateNum value that indicates that something is wrong.
21-
Invalid,
2220
/// A special CrateNum that we use for the tcx.rcache when decoding from
2321
/// the incr. comp. cache.
2422
ReservedForIncrCompCache,
@@ -29,7 +27,6 @@ impl ::std::fmt::Debug for CrateNum {
2927
fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
3028
match self {
3129
CrateNum::Index(id) => write!(fmt, "crate{}", id.private),
32-
CrateNum::Invalid => write!(fmt, "invalid crate"),
3330
CrateNum::BuiltinMacros => write!(fmt, "builtin macros crate"),
3431
CrateNum::ReservedForIncrCompCache => write!(fmt, "crate for decoding incr comp cache"),
3532
}
@@ -90,7 +87,6 @@ impl fmt::Display for CrateNum {
9087
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
9188
match self {
9289
CrateNum::Index(id) => fmt::Display::fmt(&id.private, f),
93-
CrateNum::Invalid => write!(f, "invalid crate"),
9490
CrateNum::BuiltinMacros => write!(f, "builtin macros crate"),
9591
CrateNum::ReservedForIncrCompCache => write!(f, "crate for decoding incr comp cache"),
9692
}

src/librustc/lint/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ declare_lint! {
286286

287287
declare_lint! {
288288
pub IRREFUTABLE_LET_PATTERNS,
289-
Deny,
289+
Warn,
290290
"detects irrefutable patterns in if-let and while-let statements"
291291
}
292292

src/librustc/ty/context.rs

+10
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,12 @@ pub struct TypeckTables<'tcx> {
417417
/// All the existential types that are restricted to concrete types
418418
/// by this function
419419
pub concrete_existential_types: FxHashMap<DefId, Ty<'tcx>>,
420+
421+
/// Given the closure ID this map provides the list of UpvarIDs used by it.
422+
/// The upvarID contains the HIR node ID and it also contains the full path
423+
/// leading to the member of the struct or tuple that is used instead of the
424+
/// entire variable.
425+
pub upvar_list: ty::UpvarListMap,
420426
}
421427

422428
impl<'tcx> TypeckTables<'tcx> {
@@ -441,6 +447,7 @@ impl<'tcx> TypeckTables<'tcx> {
441447
tainted_by_errors: false,
442448
free_region_map: Default::default(),
443449
concrete_existential_types: Default::default(),
450+
upvar_list: Default::default(),
444451
}
445452
}
446453

@@ -741,6 +748,8 @@ impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for TypeckTables<'gcx> {
741748
tainted_by_errors,
742749
ref free_region_map,
743750
ref concrete_existential_types,
751+
ref upvar_list,
752+
744753
} = *self;
745754

746755
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
@@ -783,6 +792,7 @@ impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for TypeckTables<'gcx> {
783792
tainted_by_errors.hash_stable(hcx, hasher);
784793
free_region_map.hash_stable(hcx, hasher);
785794
concrete_existential_types.hash_stable(hcx, hasher);
795+
upvar_list.hash_stable(hcx, hasher);
786796
})
787797
}
788798
}

src/librustc/ty/layout.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1842,7 +1842,11 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
18421842
return Ok(None);
18431843
}
18441844
}
1845-
if let FieldPlacement::Array { .. } = layout.fields {
1845+
if let FieldPlacement::Array { count: original_64_bit_count, .. } = layout.fields {
1846+
// rust-lang/rust#57038: avoid ICE within FieldPlacement::count when count too big
1847+
if original_64_bit_count > usize::max_value() as u64 {
1848+
return Err(LayoutError::SizeOverflow(layout.ty));
1849+
}
18461850
if layout.fields.count() > 0 {
18471851
return self.find_niche(layout.field(self, 0)?);
18481852
} else {

src/librustc/ty/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,7 @@ pub struct UpvarBorrow<'tcx> {
808808
pub region: ty::Region<'tcx>,
809809
}
810810

811+
pub type UpvarListMap = FxHashMap<DefId, Vec<UpvarId>>;
811812
pub type UpvarCaptureMap<'tcx> = FxHashMap<UpvarId, UpvarCapture<'tcx>>;
812813

813814
#[derive(Copy, Clone)]

0 commit comments

Comments
 (0)