Skip to content

Commit fbeb426

Browse files
committed
Auto merge of rust-lang#120394 - matthiaskrgr:rollup-hq30gxj, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#103522 (stabilise array methods) - rust-lang#113489 (impl `From<&[T; N]>` for `Cow<[T]>`) - rust-lang#119562 (Rename `pointer` field on `Pin`) - rust-lang#119800 (Document `rustc_index::vec::IndexVec`) - rust-lang#120368 (llvm-wrapper: remove llvm 12 hack) - rust-lang#120378 (always normalize `LoweredTy` in the new solver) - rust-lang#120382 (Classify closure arguments in refutable pattern in argument error) - rust-lang#120389 (Add fmease to the compiler review rotation) r? `@ghost` `@rustbot` modify labels: rollup
2 parents e7bbe8c + c906e0b commit fbeb426

35 files changed

+131
-84
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,14 @@ pub struct LoweredTy<'tcx> {
369369

370370
impl<'tcx> LoweredTy<'tcx> {
371371
pub fn from_raw(fcx: &FnCtxt<'_, 'tcx>, span: Span, raw: Ty<'tcx>) -> LoweredTy<'tcx> {
372-
LoweredTy { raw, normalized: fcx.normalize(span, raw) }
372+
// FIXME(-Znext-solver): We're still figuring out how to best handle
373+
// normalization and this doesn't feel too great. We should look at this
374+
// code again before stabilizing it.
375+
let normalized = if fcx.next_trait_solver() {
376+
fcx.try_structurally_resolve_type(span, raw)
377+
} else {
378+
fcx.normalize(span, raw)
379+
};
380+
LoweredTy { raw, normalized }
373381
}
374382
}

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2040,7 +2040,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
20402040
let field_is_local = sole_field.did.is_local();
20412041
let field_is_accessible =
20422042
sole_field.vis.is_accessible_from(expr.hir_id.owner.def_id, self.tcx)
2043-
// Skip suggestions for unstable public fields (for example `Pin::pointer`)
2043+
// Skip suggestions for unstable public fields (for example `Pin::__pointer`)
20442044
&& matches!(self.tcx.eval_stability(sole_field.did, None, expr.span, None), EvalResult::Allow | EvalResult::Unmarked);
20452045

20462046
if !field_is_local && !field_is_accessible {

compiler/rustc_index/src/vec.rs

+7
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ use std::vec;
1212
use crate::{Idx, IndexSlice};
1313

1414
/// An owned contiguous collection of `T`s, indexed by `I` rather than by `usize`.
15+
/// Its purpose is to avoid mixing indexes.
1516
///
1617
/// While it's possible to use `u32` or `usize` directly for `I`,
1718
/// you almost certainly want to use a [`newtype_index!`]-generated type instead.
1819
///
20+
/// This allows to index the IndexVec with the new index type.
21+
///
1922
/// [`newtype_index!`]: ../macro.newtype_index.html
2023
#[derive(Clone, PartialEq, Eq, Hash)]
2124
#[repr(transparent)]
@@ -25,11 +28,13 @@ pub struct IndexVec<I: Idx, T> {
2528
}
2629

2730
impl<I: Idx, T> IndexVec<I, T> {
31+
/// Constructs a new, empty `IndexVec<I, T>`.
2832
#[inline]
2933
pub const fn new() -> Self {
3034
IndexVec::from_raw(Vec::new())
3135
}
3236

37+
/// Constructs a new `IndexVec<I, T>` from a `Vec<T>`.
3338
#[inline]
3439
pub const fn from_raw(raw: Vec<T>) -> Self {
3540
IndexVec { raw, _marker: PhantomData }
@@ -59,6 +64,7 @@ impl<I: Idx, T> IndexVec<I, T> {
5964
IndexVec::from_raw(vec![elem; universe.len()])
6065
}
6166

67+
/// Creates a new IndexVec with n copies of the `elem`.
6268
#[inline]
6369
pub fn from_elem_n(elem: T, n: usize) -> Self
6470
where
@@ -85,6 +91,7 @@ impl<I: Idx, T> IndexVec<I, T> {
8591
IndexSlice::from_raw_mut(&mut self.raw)
8692
}
8793

94+
/// Pushes an element to the array returning the index where it was pushed to.
8895
#[inline]
8996
pub fn push(&mut self, d: T) -> I {
9097
let idx = self.next_index();

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -945,12 +945,7 @@ LLVMRustOptimize(
945945
break;
946946
case LLVMRustOptStage::PreLinkThinLTO:
947947
MPM = PB.buildThinLTOPreLinkDefaultPipeline(OptLevel);
948-
// The ThinLTOPreLink pipeline already includes ThinLTOBuffer passes. However, callback
949-
// passes may still run afterwards. This means we need to run the buffer passes again.
950-
// FIXME: In LLVM 13, the ThinLTOPreLink pipeline also runs OptimizerLastEPCallbacks
951-
// before the RequiredLTOPreLinkPasses, in which case we can remove these hacks.
952-
if (OptimizerLastEPCallbacks.empty())
953-
NeedThinLTOBufferPasses = false;
948+
NeedThinLTOBufferPasses = false;
954949
for (const auto &C : OptimizerLastEPCallbacks)
955950
C(MPM, OptLevel);
956951
break;

compiler/rustc_mir_build/src/thir/pattern/check_match.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,18 @@ pub(crate) fn check_match(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), Err
4747
};
4848
visitor.visit_expr(&thir[expr]);
4949

50+
let origin = match tcx.def_kind(def_id) {
51+
DefKind::AssocFn | DefKind::Fn => "function argument",
52+
DefKind::Closure => "closure argument",
53+
// other types of MIR don't have function parameters, and we don't need to
54+
// categorize those for the irrefutable check.
55+
_ if thir.params.is_empty() => "",
56+
kind => bug!("unexpected function parameters in THIR: {kind:?} {def_id:?}"),
57+
};
58+
5059
for param in thir.params.iter() {
5160
if let Some(box ref pattern) = param.pat {
52-
visitor.check_binding_is_irrefutable(pattern, "function argument", None, None);
61+
visitor.check_binding_is_irrefutable(pattern, origin, None, None);
5362
}
5463
}
5564
visitor.error

library/alloc/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@
103103
#![feature(allocator_api)]
104104
#![feature(array_chunks)]
105105
#![feature(array_into_iter_constructors)]
106-
#![feature(array_methods)]
107106
#![feature(array_windows)]
108107
#![feature(ascii_char)]
109108
#![feature(assert_matches)]

library/alloc/src/vec/cow.rs

+13
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@ impl<'a, T: Clone> From<&'a [T]> for Cow<'a, [T]> {
1515
}
1616
}
1717

18+
#[stable(feature = "cow_from_array_ref", since = "CURRENT_RUSTC_VERSION")]
19+
impl<'a, T: Clone, const N: usize> From<&'a [T; N]> for Cow<'a, [T]> {
20+
/// Creates a [`Borrowed`] variant of [`Cow`]
21+
/// from a reference to an array.
22+
///
23+
/// This conversion does not allocate or clone the data.
24+
///
25+
/// [`Borrowed`]: crate::borrow::Cow::Borrowed
26+
fn from(s: &'a [T; N]) -> Cow<'a, [T]> {
27+
Cow::Borrowed(s as &[_])
28+
}
29+
}
30+
1831
#[stable(feature = "cow_from_vec", since = "1.8.0")]
1932
impl<'a, T: Clone> From<Vec<T>> for Cow<'a, [T]> {
2033
/// Creates an [`Owned`] variant of [`Cow`]

library/core/src/array/mod.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -559,8 +559,6 @@ impl<T, const N: usize> [T; N] {
559559
/// # Example
560560
///
561561
/// ```
562-
/// #![feature(array_methods)]
563-
///
564562
/// let floats = [3.1, 2.7, -1.0];
565563
/// let float_refs: [&f64; 3] = floats.each_ref();
566564
/// assert_eq!(float_refs, [&3.1, &2.7, &-1.0]);
@@ -571,16 +569,14 @@ impl<T, const N: usize> [T; N] {
571569
/// array if its elements are not [`Copy`].
572570
///
573571
/// ```
574-
/// #![feature(array_methods)]
575-
///
576572
/// let strings = ["Ferris".to_string(), "♥".to_string(), "Rust".to_string()];
577573
/// let is_ascii = strings.each_ref().map(|s| s.is_ascii());
578574
/// assert_eq!(is_ascii, [true, false, true]);
579575
///
580576
/// // We can still access the original array: it has not been moved.
581577
/// assert_eq!(strings.len(), 3);
582578
/// ```
583-
#[unstable(feature = "array_methods", issue = "76118")]
579+
#[stable(feature = "array_methods", since = "CURRENT_RUSTC_VERSION")]
584580
pub fn each_ref(&self) -> [&T; N] {
585581
from_trusted_iterator(self.iter())
586582
}
@@ -592,15 +588,14 @@ impl<T, const N: usize> [T; N] {
592588
/// # Example
593589
///
594590
/// ```
595-
/// #![feature(array_methods)]
596591
///
597592
/// let mut floats = [3.1, 2.7, -1.0];
598593
/// let float_refs: [&mut f64; 3] = floats.each_mut();
599594
/// *float_refs[0] = 0.0;
600595
/// assert_eq!(float_refs, [&mut 0.0, &mut 2.7, &mut -1.0]);
601596
/// assert_eq!(floats, [0.0, 2.7, -1.0]);
602597
/// ```
603-
#[unstable(feature = "array_methods", issue = "76118")]
598+
#[stable(feature = "array_methods", since = "CURRENT_RUSTC_VERSION")]
604599
pub fn each_mut(&mut self) -> [&mut T; N] {
605600
from_trusted_iterator(self.iter_mut())
606601
}

library/core/src/pin.rs

+26-20
Original file line numberDiff line numberDiff line change
@@ -1092,14 +1092,20 @@ pub struct Pin<Ptr> {
10921092
// - deter downstream users from accessing it (which would be unsound!),
10931093
// - let the `pin!` macro access it (such a macro requires using struct
10941094
// literal syntax in order to benefit from lifetime extension).
1095-
// Long-term, `unsafe` fields or macro hygiene are expected to offer more robust alternatives.
1095+
//
1096+
// However, if the `Deref` impl exposes a field with the same name as this
1097+
// field, then the two will collide, resulting in a confusing error when the
1098+
// user attempts to access the field through a `Pin<Ptr>`. Therefore, the
1099+
// name `__pointer` is designed to be unlikely to collide with any other
1100+
// field. Long-term, macro hygiene is expected to offer a more robust
1101+
// alternative, alongside `unsafe` fields.
10961102
#[unstable(feature = "unsafe_pin_internals", issue = "none")]
10971103
#[doc(hidden)]
1098-
pub pointer: Ptr,
1104+
pub __pointer: Ptr,
10991105
}
11001106

11011107
// The following implementations aren't derived in order to avoid soundness
1102-
// issues. `&self.pointer` should not be accessible to untrusted trait
1108+
// issues. `&self.__pointer` should not be accessible to untrusted trait
11031109
// implementations.
11041110
//
11051111
// See <https://internals.rust-lang.org/t/unsoundness-in-pin/11311/73> for more details.
@@ -1212,7 +1218,7 @@ impl<Ptr: Deref<Target: Unpin>> Pin<Ptr> {
12121218
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
12131219
#[stable(feature = "pin_into_inner", since = "1.39.0")]
12141220
pub const fn into_inner(pin: Pin<Ptr>) -> Ptr {
1215-
pin.pointer
1221+
pin.__pointer
12161222
}
12171223
}
12181224

@@ -1349,7 +1355,7 @@ impl<Ptr: Deref> Pin<Ptr> {
13491355
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
13501356
#[stable(feature = "pin", since = "1.33.0")]
13511357
pub const unsafe fn new_unchecked(pointer: Ptr) -> Pin<Ptr> {
1352-
Pin { pointer }
1358+
Pin { __pointer: pointer }
13531359
}
13541360

13551361
/// Gets a shared reference to the pinned value this [`Pin`] points to.
@@ -1363,7 +1369,7 @@ impl<Ptr: Deref> Pin<Ptr> {
13631369
#[inline(always)]
13641370
pub fn as_ref(&self) -> Pin<&Ptr::Target> {
13651371
// SAFETY: see documentation on this function
1366-
unsafe { Pin::new_unchecked(&*self.pointer) }
1372+
unsafe { Pin::new_unchecked(&*self.__pointer) }
13671373
}
13681374

13691375
/// Unwraps this `Pin<Ptr>`, returning the underlying `Ptr`.
@@ -1388,7 +1394,7 @@ impl<Ptr: Deref> Pin<Ptr> {
13881394
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
13891395
#[stable(feature = "pin_into_inner", since = "1.39.0")]
13901396
pub const unsafe fn into_inner_unchecked(pin: Pin<Ptr>) -> Ptr {
1391-
pin.pointer
1397+
pin.__pointer
13921398
}
13931399
}
13941400

@@ -1426,7 +1432,7 @@ impl<Ptr: DerefMut> Pin<Ptr> {
14261432
#[inline(always)]
14271433
pub fn as_mut(&mut self) -> Pin<&mut Ptr::Target> {
14281434
// SAFETY: see documentation on this function
1429-
unsafe { Pin::new_unchecked(&mut *self.pointer) }
1435+
unsafe { Pin::new_unchecked(&mut *self.__pointer) }
14301436
}
14311437

14321438
/// Assigns a new value to the memory location pointed to by the `Pin<Ptr>`.
@@ -1455,7 +1461,7 @@ impl<Ptr: DerefMut> Pin<Ptr> {
14551461
where
14561462
Ptr::Target: Sized,
14571463
{
1458-
*(self.pointer) = value;
1464+
*(self.__pointer) = value;
14591465
}
14601466
}
14611467

@@ -1481,7 +1487,7 @@ impl<'a, T: ?Sized> Pin<&'a T> {
14811487
U: ?Sized,
14821488
F: FnOnce(&T) -> &U,
14831489
{
1484-
let pointer = &*self.pointer;
1490+
let pointer = &*self.__pointer;
14851491
let new_pointer = func(pointer);
14861492

14871493
// SAFETY: the safety contract for `new_unchecked` must be
@@ -1511,7 +1517,7 @@ impl<'a, T: ?Sized> Pin<&'a T> {
15111517
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
15121518
#[stable(feature = "pin", since = "1.33.0")]
15131519
pub const fn get_ref(self) -> &'a T {
1514-
self.pointer
1520+
self.__pointer
15151521
}
15161522
}
15171523

@@ -1522,7 +1528,7 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
15221528
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
15231529
#[stable(feature = "pin", since = "1.33.0")]
15241530
pub const fn into_ref(self) -> Pin<&'a T> {
1525-
Pin { pointer: self.pointer }
1531+
Pin { __pointer: self.__pointer }
15261532
}
15271533

15281534
/// Gets a mutable reference to the data inside of this `Pin`.
@@ -1542,7 +1548,7 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
15421548
where
15431549
T: Unpin,
15441550
{
1545-
self.pointer
1551+
self.__pointer
15461552
}
15471553

15481554
/// Gets a mutable reference to the data inside of this `Pin`.
@@ -1560,7 +1566,7 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
15601566
#[stable(feature = "pin", since = "1.33.0")]
15611567
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
15621568
pub const unsafe fn get_unchecked_mut(self) -> &'a mut T {
1563-
self.pointer
1569+
self.__pointer
15641570
}
15651571

15661572
/// Construct a new pin by mapping the interior value.
@@ -1684,21 +1690,21 @@ impl<Ptr: Receiver> Receiver for Pin<Ptr> {}
16841690
#[stable(feature = "pin", since = "1.33.0")]
16851691
impl<Ptr: fmt::Debug> fmt::Debug for Pin<Ptr> {
16861692
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1687-
fmt::Debug::fmt(&self.pointer, f)
1693+
fmt::Debug::fmt(&self.__pointer, f)
16881694
}
16891695
}
16901696

16911697
#[stable(feature = "pin", since = "1.33.0")]
16921698
impl<Ptr: fmt::Display> fmt::Display for Pin<Ptr> {
16931699
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1694-
fmt::Display::fmt(&self.pointer, f)
1700+
fmt::Display::fmt(&self.__pointer, f)
16951701
}
16961702
}
16971703

16981704
#[stable(feature = "pin", since = "1.33.0")]
16991705
impl<Ptr: fmt::Pointer> fmt::Pointer for Pin<Ptr> {
17001706
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1701-
fmt::Pointer::fmt(&self.pointer, f)
1707+
fmt::Pointer::fmt(&self.__pointer, f)
17021708
}
17031709
}
17041710

@@ -1941,16 +1947,16 @@ pub macro pin($value:expr $(,)?) {
19411947
// instead, dropped _at the end of the enscoping block_.
19421948
// For instance,
19431949
// ```rust
1944-
// let p = Pin { pointer: &mut <temporary> };
1950+
// let p = Pin { __pointer: &mut <temporary> };
19451951
// ```
19461952
// becomes:
19471953
// ```rust
19481954
// let mut anon = <temporary>;
1949-
// let p = Pin { pointer: &mut anon };
1955+
// let p = Pin { __pointer: &mut anon };
19501956
// ```
19511957
// which is *exactly* what we want.
19521958
//
19531959
// See https://doc.rust-lang.org/1.58.1/reference/destructors.html#temporary-lifetime-extension
19541960
// for more info.
1955-
$crate::pin::Pin::<&mut _> { pointer: &mut { $value } }
1961+
$crate::pin::Pin::<&mut _> { __pointer: &mut { $value } }
19561962
}

library/core/tests/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![feature(alloc_layout_extra)]
22
#![feature(array_chunks)]
3-
#![feature(array_methods)]
43
#![feature(array_windows)]
54
#![feature(ascii_char)]
65
#![feature(ascii_char_variants)]

src/etc/natvis/libcore.natvis

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@
9999
</Type>
100100

101101
<Type Name="core::pin::Pin&lt;*&gt;">
102-
<DisplayString>Pin({(void*)pointer}: {pointer})</DisplayString>
102+
<DisplayString>Pin({(void*)__pointer}: {__pointer})</DisplayString>
103103
<Expand>
104-
<ExpandedItem>pointer</ExpandedItem>
104+
<ExpandedItem>__pointer</ExpandedItem>
105105
</Expand>
106106
</Type>
107107

src/librustdoc/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
html_playground_url = "https://play.rust-lang.org/"
44
)]
55
#![feature(rustc_private)]
6-
#![feature(array_methods)]
76
#![feature(assert_matches)]
87
#![feature(box_patterns)]
98
#![feature(if_let_guard)]

tests/mir-opt/inline/inline_coroutine.main.Inline.panic-abort.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
- _4 = g() -> [return: bb1, unwind unreachable];
3737
+ _4 = {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8 (#0)};
3838
+ _3 = &mut _4;
39-
+ _2 = Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8}> { pointer: _3 };
39+
+ _2 = Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8}> { __pointer: _3 };
4040
+ StorageDead(_3);
4141
+ StorageLive(_5);
4242
+ _5 = const false;

tests/mir-opt/inline/inline_coroutine.main.Inline.panic-unwind.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
- _4 = g() -> [return: bb1, unwind continue];
3737
+ _4 = {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8 (#0)};
3838
+ _3 = &mut _4;
39-
+ _2 = Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8}> { pointer: _3 };
39+
+ _2 = Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8}> { __pointer: _3 };
4040
+ StorageDead(_3);
4141
+ StorageLive(_5);
4242
+ _5 = const false;

tests/ui/feature-gates/feature-gate-unsafe_pin_internals.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use core::{marker::PhantomPinned, pin::Pin};
77

88
/// The `unsafe_pin_internals` is indeed unsound.
99
fn non_unsafe_pin_new_unchecked<T>(pointer: &mut T) -> Pin<&mut T> {
10-
Pin { pointer }
10+
Pin { __pointer: pointer }
1111
}
1212

1313
fn main() {

0 commit comments

Comments
 (0)