Skip to content

Commit 853f300

Browse files
committed
Auto merge of #62407 - Centril:rollup-g0zmff7, r=Centril
Rollup of 10 pull requests Successful merges: - #62123 ( Remove needless lifetimes (std)) - #62150 (Implement mem::{zeroed,uninitialized} in terms of MaybeUninit.) - #62169 (Derive which queries to save using the proc macro) - #62238 (Fix code block information icon position) - #62292 (Move `async || ...` closures into `#![feature(async_closure)]`) - #62323 (Clarify unaligned fields in ptr::{read,write}_unaligned) - #62324 (Reduce reliance on `await!(...)` macro) - #62371 (Add tracking issue for Box::into_pin) - #62383 (Improve error span for async type inference error) - #62388 (Break out of the correct number of scopes in loops) Failed merges: r? @ghost
2 parents f119bf2 + 1808189 commit 853f300

File tree

77 files changed

+496
-281
lines changed

Some content is hidden

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

77 files changed

+496
-281
lines changed

src/liballoc/boxed.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ impl<T: ?Sized> Box<T> {
320320
/// This conversion does not allocate on the heap and happens in place.
321321
///
322322
/// This is also available via [`From`].
323-
#[unstable(feature = "box_into_pin", issue = "0")]
323+
#[unstable(feature = "box_into_pin", issue = "62370")]
324324
pub fn into_pin(boxed: Box<T>) -> Pin<Box<T>> {
325325
// It's not possible to move or replace the insides of a `Pin<Box<T>>`
326326
// when `T: !Unpin`, so it's safe to pin it directly without any

src/liballoc/collections/btree/map.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2032,7 +2032,7 @@ impl<K, V> BTreeMap<K, V> {
20322032
/// assert_eq!(keys, [1, 2]);
20332033
/// ```
20342034
#[stable(feature = "rust1", since = "1.0.0")]
2035-
pub fn keys<'a>(&'a self) -> Keys<'a, K, V> {
2035+
pub fn keys(&self) -> Keys<'_, K, V> {
20362036
Keys { inner: self.iter() }
20372037
}
20382038

@@ -2053,7 +2053,7 @@ impl<K, V> BTreeMap<K, V> {
20532053
/// assert_eq!(values, ["hello", "goodbye"]);
20542054
/// ```
20552055
#[stable(feature = "rust1", since = "1.0.0")]
2056-
pub fn values<'a>(&'a self) -> Values<'a, K, V> {
2056+
pub fn values(&self) -> Values<'_, K, V> {
20572057
Values { inner: self.iter() }
20582058
}
20592059

@@ -2557,8 +2557,8 @@ enum UnderflowResult<'a, K, V> {
25572557
Stole(NodeRef<marker::Mut<'a>, K, V, marker::Internal>),
25582558
}
25592559

2560-
fn handle_underfull_node<'a, K, V>(node: NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal>)
2561-
-> UnderflowResult<'a, K, V> {
2560+
fn handle_underfull_node<K, V>(node: NodeRef<marker::Mut<'_>, K, V, marker::LeafOrInternal>)
2561+
-> UnderflowResult<'_, K, V> {
25622562
let parent = if let Ok(parent) = node.ascend() {
25632563
parent
25642564
} else {

src/liballoc/collections/btree/node.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ impl<BorrowType, K, V, Type> NodeRef<BorrowType, K, V, Type> {
394394
}
395395

396396
/// Temporarily takes out another, immutable reference to the same node.
397-
fn reborrow<'a>(&'a self) -> NodeRef<marker::Immut<'a>, K, V, Type> {
397+
fn reborrow(&self) -> NodeRef<marker::Immut<'_>, K, V, Type> {
398398
NodeRef {
399399
height: self.height,
400400
node: self.node,

src/liballoc/string.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ impl String {
552552
/// assert_eq!("Hello �World", output);
553553
/// ```
554554
#[stable(feature = "rust1", since = "1.0.0")]
555-
pub fn from_utf8_lossy<'a>(v: &'a [u8]) -> Cow<'a, str> {
555+
pub fn from_utf8_lossy(v: &[u8]) -> Cow<'_, str> {
556556
let mut iter = lossy::Utf8Lossy::from_bytes(v).chunks();
557557

558558
let (first_valid, first_broken) = if let Some(chunk) = iter.next() {

src/libcore/intrinsics.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -700,17 +700,15 @@ extern "rust-intrinsic" {
700700
/// which is unsafe unless `T` is `Copy`. Also, even if T is
701701
/// `Copy`, an all-zero value may not correspond to any legitimate
702702
/// state for the type in question.
703+
#[unstable(feature = "core_intrinsics",
704+
reason = "intrinsics are unlikely to ever be stabilized, instead \
705+
they should be used through stabilized interfaces \
706+
in the rest of the standard library",
707+
issue = "0")]
708+
#[rustc_deprecated(reason = "no longer used by rustc, will be removed - use MaybeUnint instead",
709+
since = "1.38.0")]
703710
pub fn init<T>() -> T;
704711

705-
/// Creates an uninitialized value.
706-
///
707-
/// `uninit` is unsafe because there is no guarantee of what its
708-
/// contents are. In particular its drop-flag may be set to any
709-
/// state, which means it may claim either dropped or
710-
/// undropped. In the general case one must use `ptr::write` to
711-
/// initialize memory previous set to the result of `uninit`.
712-
pub fn uninit<T>() -> T;
713-
714712
/// Moves a value out of scope without running drop glue.
715713
pub fn forget<T: ?Sized>(_: T);
716714

src/libcore/marker.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ macro_rules! impls{
498498
/// # end: *const T,
499499
/// # phantom: PhantomData<&'a T>,
500500
/// # }
501-
/// fn borrow_vec<'a, T>(vec: &'a Vec<T>) -> Slice<'a, T> {
501+
/// fn borrow_vec<T>(vec: &Vec<T>) -> Slice<'_, T> {
502502
/// let ptr = vec.as_ptr();
503503
/// Slice {
504504
/// start: ptr,

src/libcore/mem/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,7 @@ pub const fn needs_drop<T>() -> bool {
450450
#[inline]
451451
#[stable(feature = "rust1", since = "1.0.0")]
452452
pub unsafe fn zeroed<T>() -> T {
453-
intrinsics::panic_if_uninhabited::<T>();
454-
intrinsics::init()
453+
MaybeUninit::zeroed().assume_init()
455454
}
456455

457456
/// Bypasses Rust's normal memory-initialization checks by pretending to
@@ -476,8 +475,7 @@ pub unsafe fn zeroed<T>() -> T {
476475
#[rustc_deprecated(since = "1.38.0", reason = "use `mem::MaybeUninit` instead")]
477476
#[stable(feature = "rust1", since = "1.0.0")]
478477
pub unsafe fn uninitialized<T>() -> T {
479-
intrinsics::panic_if_uninhabited::<T>();
480-
intrinsics::uninit()
478+
MaybeUninit::uninit().assume_init()
481479
}
482480

483481
/// Swaps the values at two mutable locations, without deinitializing either one.

src/libcore/ops/index.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub trait Index<Idx: ?Sized> {
105105
/// impl Index<Side> for Balance {
106106
/// type Output = Weight;
107107
///
108-
/// fn index<'a>(&'a self, index: Side) -> &'a Self::Output {
108+
/// fn index(&self, index: Side) -> &Self::Output {
109109
/// println!("Accessing {:?}-side of balance immutably", index);
110110
/// match index {
111111
/// Side::Left => &self.left,
@@ -115,7 +115,7 @@ pub trait Index<Idx: ?Sized> {
115115
/// }
116116
///
117117
/// impl IndexMut<Side> for Balance {
118-
/// fn index_mut<'a>(&'a mut self, index: Side) -> &'a mut Self::Output {
118+
/// fn index_mut(&mut self, index: Side) -> &mut Self::Output {
119119
/// println!("Accessing {:?}-side of balance mutably", index);
120120
/// match index {
121121
/// Side::Left => &mut self.left,

src/libcore/ptr/mod.rs

+53-35
Original file line numberDiff line numberDiff line change
@@ -625,42 +625,50 @@ pub unsafe fn read<T>(src: *const T) -> T {
625625
/// [read-ownership]: ./fn.read.html#ownership-of-the-returned-value
626626
/// [valid]: ../ptr/index.html#safety
627627
///
628-
/// # Examples
628+
/// ## On `packed` structs
629629
///
630-
/// Access members of a packed struct by reference:
630+
/// It is currently impossible to create raw pointers to unaligned fields
631+
/// of a packed struct.
631632
///
632-
/// ```
633-
/// use std::ptr;
633+
/// Attempting to create a raw pointer to an `unaligned` struct field with
634+
/// an expression such as `&packed.unaligned as *const FieldType` creates an
635+
/// intermediate unaligned reference before converting that to a raw pointer.
636+
/// That this reference is temporary and immediately cast is inconsequential
637+
/// as the compiler always expects references to be properly aligned.
638+
/// As a result, using `&packed.unaligned as *const FieldType` causes immediate
639+
/// *undefined behavior* in your program.
634640
///
641+
/// An example of what not to do and how this relates to `read_unaligned` is:
642+
///
643+
/// ```no_run
635644
/// #[repr(packed, C)]
636645
/// struct Packed {
637646
/// _padding: u8,
638647
/// unaligned: u32,
639648
/// }
640649
///
641-
/// let x = Packed {
650+
/// let packed = Packed {
642651
/// _padding: 0x00,
643652
/// unaligned: 0x01020304,
644653
/// };
645654
///
646655
/// let v = unsafe {
647-
/// // Take the address of a 32-bit integer which is not aligned.
648-
/// // This must be done as a raw pointer; unaligned references are invalid.
649-
/// let unaligned = &x.unaligned as *const u32;
650-
///
651-
/// // Dereferencing normally will emit an aligned load instruction,
652-
/// // causing undefined behavior.
653-
/// // let v = *unaligned; // ERROR
656+
/// // Here we attempt to take the address of a 32-bit integer which is not aligned.
657+
/// let unaligned =
658+
/// // A temporary unaligned reference is created here which results in
659+
/// // undefined behavior regardless of whether the reference is used or not.
660+
/// &packed.unaligned
661+
/// // Casting to a raw pointer doesn't help; the mistake already happened.
662+
/// as *const u32;
654663
///
655-
/// // Instead, use `read_unaligned` to read improperly aligned values.
656-
/// let v = ptr::read_unaligned(unaligned);
664+
/// let v = std::ptr::read_unaligned(unaligned);
657665
///
658666
/// v
659667
/// };
660-
///
661-
/// // Accessing unaligned values directly is safe.
662-
/// assert!(x.unaligned == v);
663668
/// ```
669+
///
670+
/// Accessing unaligned fields directly with e.g. `packed.unaligned` is safe however.
671+
// FIXME: Update docs based on outcome of RFC #2582 and friends.
664672
#[inline]
665673
#[stable(feature = "ptr_unaligned", since = "1.17.0")]
666674
pub unsafe fn read_unaligned<T>(src: *const T) -> T {
@@ -789,38 +797,48 @@ pub unsafe fn write<T>(dst: *mut T, src: T) {
789797
///
790798
/// [valid]: ../ptr/index.html#safety
791799
///
792-
/// # Examples
800+
/// ## On `packed` structs
793801
///
794-
/// Access fields in a packed struct:
802+
/// It is currently impossible to create raw pointers to unaligned fields
803+
/// of a packed struct.
795804
///
796-
/// ```
797-
/// use std::{mem, ptr};
805+
/// Attempting to create a raw pointer to an `unaligned` struct field with
806+
/// an expression such as `&packed.unaligned as *const FieldType` creates an
807+
/// intermediate unaligned reference before converting that to a raw pointer.
808+
/// That this reference is temporary and immediately cast is inconsequential
809+
/// as the compiler always expects references to be properly aligned.
810+
/// As a result, using `&packed.unaligned as *const FieldType` causes immediate
811+
/// *undefined behavior* in your program.
798812
///
813+
/// An example of what not to do and how this relates to `write_unaligned` is:
814+
///
815+
/// ```no_run
799816
/// #[repr(packed, C)]
800-
/// #[derive(Default)]
801817
/// struct Packed {
802818
/// _padding: u8,
803819
/// unaligned: u32,
804820
/// }
805821
///
806822
/// let v = 0x01020304;
807-
/// let mut x: Packed = unsafe { mem::zeroed() };
808-
///
809-
/// unsafe {
810-
/// // Take a reference to a 32-bit integer which is not aligned.
811-
/// let unaligned = &mut x.unaligned as *mut u32;
823+
/// let mut packed: Packed = unsafe { std::mem::zeroed() };
812824
///
813-
/// // Dereferencing normally will emit an aligned store instruction,
814-
/// // causing undefined behavior because the pointer is not aligned.
815-
/// // *unaligned = v; // ERROR
825+
/// let v = unsafe {
826+
/// // Here we attempt to take the address of a 32-bit integer which is not aligned.
827+
/// let unaligned =
828+
/// // A temporary unaligned reference is created here which results in
829+
/// // undefined behavior regardless of whether the reference is used or not.
830+
/// &mut packed.unaligned
831+
/// // Casting to a raw pointer doesn't help; the mistake already happened.
832+
/// as *mut u32;
816833
///
817-
/// // Instead, use `write_unaligned` to write improperly aligned values.
818-
/// ptr::write_unaligned(unaligned, v);
819-
/// }
834+
/// std::ptr::write_unaligned(unaligned, v);
820835
///
821-
/// // Accessing unaligned values directly is safe.
822-
/// assert!(x.unaligned == v);
836+
/// v
837+
/// };
823838
/// ```
839+
///
840+
/// Accessing unaligned fields directly with e.g. `packed.unaligned` is safe however.
841+
// FIXME: Update docs based on outcome of RFC #2582 and friends.
824842
#[inline]
825843
#[stable(feature = "ptr_unaligned", since = "1.17.0")]
826844
pub unsafe fn write_unaligned<T>(dst: *mut T, src: T) {

src/librustc/query/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -422,11 +422,6 @@ rustc_queries! {
422422
"const-evaluating `{}`",
423423
tcx.def_path_str(key.value.instance.def.def_id())
424424
}
425-
cache_on_disk_if(_, opt_result) {
426-
// Only store results without errors
427-
// FIXME: We never store these
428-
opt_result.map_or(true, |r| r.is_ok())
429-
}
430425
}
431426

432427
/// Results of evaluating const items or constants embedded in

src/librustc/ty/query/on_disk_cache.rs

+13-19
Original file line numberDiff line numberDiff line change
@@ -201,28 +201,22 @@ impl<'sess> OnDiskCache<'sess> {
201201
let mut query_result_index = EncodedQueryResultIndex::new();
202202

203203
time(tcx.sess, "encode query results", || {
204-
use crate::ty::query::queries::*;
205204
let enc = &mut encoder;
206205
let qri = &mut query_result_index;
207206

208-
encode_query_results::<type_of<'_>, _>(tcx, enc, qri)?;
209-
encode_query_results::<generics_of<'_>, _>(tcx, enc, qri)?;
210-
encode_query_results::<predicates_of<'_>, _>(tcx, enc, qri)?;
211-
encode_query_results::<used_trait_imports<'_>, _>(tcx, enc, qri)?;
212-
encode_query_results::<typeck_tables_of<'_>, _>(tcx, enc, qri)?;
213-
encode_query_results::<codegen_fulfill_obligation<'_>, _>(tcx, enc, qri)?;
214-
encode_query_results::<optimized_mir<'_>, _>(tcx, enc, qri)?;
215-
encode_query_results::<unsafety_check_result<'_>, _>(tcx, enc, qri)?;
216-
encode_query_results::<borrowck<'_>, _>(tcx, enc, qri)?;
217-
encode_query_results::<mir_borrowck<'_>, _>(tcx, enc, qri)?;
218-
encode_query_results::<mir_const_qualif<'_>, _>(tcx, enc, qri)?;
219-
encode_query_results::<const_is_rvalue_promotable_to_static<'_>, _>(tcx, enc, qri)?;
220-
encode_query_results::<symbol_name<'_>, _>(tcx, enc, qri)?;
221-
encode_query_results::<check_match<'_>, _>(tcx, enc, qri)?;
222-
encode_query_results::<codegen_fn_attrs<'_>, _>(tcx, enc, qri)?;
223-
encode_query_results::<specialization_graph_of<'_>, _>(tcx, enc, qri)?;
224-
encode_query_results::<const_eval<'_>, _>(tcx, enc, qri)?;
225-
// FIXME: Include const_eval_raw?
207+
macro_rules! encode_queries {
208+
($($query:ident,)*) => {
209+
$(
210+
encode_query_results::<ty::query::queries::$query<'_>, _>(
211+
tcx,
212+
enc,
213+
qri
214+
)?;
215+
)*
216+
}
217+
}
218+
219+
rustc_cached_queries!(encode_queries!);
226220

227221
Ok(())
228222
})?;

src/librustc_codegen_llvm/intrinsic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
234234
return;
235235
}
236236
// Effectively no-ops
237-
"uninit" | "forget" => {
237+
"forget" => {
238238
return;
239239
}
240240
"needs_drop" => {

src/librustc_macros/src/query.rs

+13
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
414414
let mut dep_node_force_stream = quote! {};
415415
let mut try_load_from_on_disk_cache_stream = quote! {};
416416
let mut no_force_queries = Vec::new();
417+
let mut cached_queries = quote! {};
417418

418419
for group in groups.0 {
419420
let mut group_stream = quote! {};
@@ -427,6 +428,12 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
427428
_ => quote! { #result_full },
428429
};
429430

431+
if modifiers.cache.is_some() {
432+
cached_queries.extend(quote! {
433+
#name,
434+
});
435+
}
436+
430437
if modifiers.cache.is_some() && !modifiers.no_force {
431438
try_load_from_on_disk_cache_stream.extend(quote! {
432439
DepKind::#name => {
@@ -549,6 +556,12 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
549556
}
550557
}
551558
}
559+
macro_rules! rustc_cached_queries {
560+
($($macro:tt)*) => {
561+
$($macro)*(#cached_queries);
562+
}
563+
}
564+
552565
#query_description_stream
553566

554567
impl DepNode {

0 commit comments

Comments
 (0)