Skip to content

Commit 3ee016a

Browse files
committed
Auto merge of rust-lang#91959 - matthiaskrgr:rollup-rhajuvw, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#90521 (Stabilize `destructuring_assignment`) - rust-lang#91479 (Add `[T]::as_simd(_mut)`) - rust-lang#91584 (Improve code for rustdoc-gui tester) - rust-lang#91886 (core: minor `Option` doc correction) - rust-lang#91888 (Handle unordered const/ty generics for object lifetime defaults) - rust-lang#91905 (Fix source code page sidebar on mobile) - rust-lang#91906 (Removed `in_band_lifetimes` from `library\proc_macro`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents df89fd2 + 6c6cfa8 commit 3ee016a

File tree

63 files changed

+272
-424
lines changed

Some content is hidden

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

63 files changed

+272
-424
lines changed

compiler/rustc_ast_lowering/src/expr.rs

-19
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use rustc_errors::struct_span_err;
99
use rustc_hir as hir;
1010
use rustc_hir::def::Res;
1111
use rustc_hir::definitions::DefPathData;
12-
use rustc_session::parse::feature_err;
1312
use rustc_span::hygiene::ExpnId;
1413
use rustc_span::source_map::{respan, DesugaringKind, Span, Spanned};
1514
use rustc_span::symbol::{sym, Ident, Symbol};
@@ -962,24 +961,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
962961
self.lower_span(eq_sign_span),
963962
);
964963
}
965-
if !self.sess.features_untracked().destructuring_assignment {
966-
let mut err = feature_err(
967-
&self.sess.parse_sess,
968-
sym::destructuring_assignment,
969-
eq_sign_span,
970-
"destructuring assignments are unstable",
971-
);
972-
err.span_label(lhs.span, "cannot assign to this expression");
973-
if self.is_in_loop_condition {
974-
err.span_suggestion_verbose(
975-
lhs.span.shrink_to_lo(),
976-
"you might have meant to use pattern destructuring",
977-
"let ".to_string(),
978-
rustc_errors::Applicability::MachineApplicable,
979-
);
980-
}
981-
err.emit();
982-
}
983964

984965
let mut assignments = vec![];
985966

compiler/rustc_ast_lowering/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ use rustc_hir::def::{DefKind, Namespace, PartialRes, PerNS, Res};
5252
use rustc_hir::def_id::{DefId, DefPathHash, LocalDefId, CRATE_DEF_ID};
5353
use rustc_hir::definitions::{DefKey, DefPathData, Definitions};
5454
use rustc_hir::intravisit;
55-
use rustc_hir::{ConstArg, GenericArg, InferKind, ParamName};
55+
use rustc_hir::{ConstArg, GenericArg, ParamName};
5656
use rustc_index::vec::{Idx, IndexVec};
5757
use rustc_query_system::ich::StableHashingContext;
5858
use rustc_session::lint::builtin::BARE_TRAIT_OBJECTS;
@@ -1113,7 +1113,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11131113
return GenericArg::Infer(hir::InferArg {
11141114
hir_id: self.lower_node_id(ty.id),
11151115
span: self.lower_span(ty.span),
1116-
kind: InferKind::Type,
11171116
});
11181117
}
11191118
// We parse const arguments as path types as we cannot distinguish them during

compiler/rustc_ast_passes/src/feature_gate.rs

-5
Original file line numberDiff line numberDiff line change
@@ -724,11 +724,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
724724
gate_all!(half_open_range_patterns, "half-open range patterns are unstable");
725725
gate_all!(inline_const, "inline-const is experimental");
726726
gate_all!(inline_const_pat, "inline-const in pattern position is experimental");
727-
if sess.parse_sess.span_diagnostic.err_count() == 0 {
728-
// Errors for `destructuring_assignment` can get quite noisy, especially where `_` is
729-
// involved, so we only emit errors where there are no other parsing errors.
730-
gate_all!(destructuring_assignment, "destructuring assignments are unstable");
731-
}
732727

733728
// All uses of `gate_all!` below this point were added in #65742,
734729
// and subsequently disabled (with the non-early gating readded).

compiler/rustc_expand/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![feature(crate_visibility_modifier)]
22
#![feature(decl_macro)]
3-
#![feature(destructuring_assignment)]
3+
#![cfg_attr(bootstrap, feature(destructuring_assignment))]
44
#![feature(if_let_guard)]
55
#![feature(let_else)]
66
#![feature(proc_macro_diagnostic)]

compiler/rustc_feature/src/accepted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ declare_features! (
114114
(accepted, default_type_params, "1.0.0", None, None),
115115
/// Allows `#[deprecated]` attribute.
116116
(accepted, deprecated, "1.9.0", Some(29935), None),
117+
/// Allows the use of destructuring assignments.
118+
(accepted, destructuring_assignment, "1.59.0", Some(71126), None),
117119
/// Allows `#[doc(alias = "...")]`.
118120
(accepted, doc_alias, "1.48.0", Some(50146), None),
119121
/// Allows `..` in tuple (struct) patterns.

compiler/rustc_feature/src/active.rs

-2
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,6 @@ declare_features! (
356356
(active, default_type_parameter_fallback, "1.3.0", Some(27336), None),
357357
/// Allows `#[derive(Default)]` and `#[default]` on enums.
358358
(active, derive_default_enum, "1.56.0", Some(86985), None),
359-
/// Allows the use of destructuring assignments.
360-
(active, destructuring_assignment, "1.49.0", Some(71126), None),
361359
/// Tells rustdoc to automatically generate `#[doc(cfg(...))]`.
362360
(active, doc_auto_cfg, "1.58.0", Some(43781), None),
363361
/// Allows `#[doc(cfg(...))]`.

compiler/rustc_hir/src/hir.rs

-14
Original file line numberDiff line numberDiff line change
@@ -255,23 +255,9 @@ pub struct ConstArg {
255255
pub span: Span,
256256
}
257257

258-
#[derive(Copy, Clone, Encodable, Debug, HashStable_Generic)]
259-
pub enum InferKind {
260-
Const,
261-
Type,
262-
}
263-
264-
impl InferKind {
265-
#[inline]
266-
pub fn is_type(self) -> bool {
267-
matches!(self, InferKind::Type)
268-
}
269-
}
270-
271258
#[derive(Encodable, Debug, HashStable_Generic)]
272259
pub struct InferArg {
273260
pub hir_id: HirId,
274-
pub kind: InferKind,
275261
pub span: Span,
276262
}
277263

compiler/rustc_parse/src/parser/expr.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,6 @@ impl<'a> Parser<'a> {
12971297
} else if self.eat_keyword(kw::Let) {
12981298
self.parse_let_expr(attrs)
12991299
} else if self.eat_keyword(kw::Underscore) {
1300-
self.sess.gated_spans.gate(sym::destructuring_assignment, self.prev_token.span);
13011300
Ok(self.mk_expr(self.prev_token.span, ExprKind::Underscore, attrs))
13021301
} else if !self.unclosed_delims.is_empty() && self.check(&token::Semi) {
13031302
// Don't complain about bare semicolons after unclosed braces
@@ -2620,7 +2619,6 @@ impl<'a> Parser<'a> {
26202619
let exp_span = self.prev_token.span;
26212620
// We permit `.. }` on the left-hand side of a destructuring assignment.
26222621
if self.check(&token::CloseDelim(close_delim)) {
2623-
self.sess.gated_spans.gate(sym::destructuring_assignment, self.prev_token.span);
26242622
base = ast::StructRest::Rest(self.prev_token.span.shrink_to_hi());
26252623
break;
26262624
}

compiler/rustc_resolve/src/late/lifetimes.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -2541,8 +2541,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
25412541
GenericParamDefKind::Type { object_lifetime_default, .. } => {
25422542
Some(object_lifetime_default)
25432543
}
2544-
GenericParamDefKind::Lifetime
2545-
| GenericParamDefKind::Const { .. } => None,
2544+
GenericParamDefKind::Const { .. } => Some(Set1::Empty),
2545+
GenericParamDefKind::Lifetime => None,
25462546
})
25472547
.collect()
25482548
})
@@ -2569,12 +2569,11 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
25692569
}
25702570
GenericArg::Const(ct) => {
25712571
self.visit_anon_const(&ct.value);
2572+
i += 1;
25722573
}
25732574
GenericArg::Infer(inf) => {
25742575
self.visit_id(inf.hir_id);
2575-
if inf.kind.is_type() {
2576-
i += 1;
2577-
}
2576+
i += 1;
25782577
}
25792578
}
25802579
}

compiler/rustc_typeck/src/check/expr.rs

-5
Original file line numberDiff line numberDiff line change
@@ -878,11 +878,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
878878
"let ".to_string(),
879879
Applicability::MachineApplicable,
880880
);
881-
if !self.sess().features_untracked().destructuring_assignment {
882-
// We already emit an E0658 with a suggestion for `while let`, this is
883-
// redundant output.
884-
err.delay_as_bug();
885-
}
886881
break;
887882
}
888883
hir::Node::Item(_)

library/alloc/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
#![feature(cfg_target_has_atomic)]
137137
#![feature(const_fn_trait_bound)]
138138
#![feature(const_trait_impl)]
139-
#![feature(destructuring_assignment)]
139+
#![cfg_attr(bootstrap, feature(destructuring_assignment))]
140140
#![feature(dropck_eyepatch)]
141141
#![feature(exclusive_range_pattern)]
142142
#![feature(fundamental)]

library/core/src/option.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -512,11 +512,11 @@ use crate::{
512512
#[rustc_diagnostic_item = "Option"]
513513
#[stable(feature = "rust1", since = "1.0.0")]
514514
pub enum Option<T> {
515-
/// No value
515+
/// No value.
516516
#[lang = "None"]
517517
#[stable(feature = "rust1", since = "1.0.0")]
518518
None,
519-
/// Some value `T`
519+
/// Some value of type `T`.
520520
#[lang = "Some"]
521521
#[stable(feature = "rust1", since = "1.0.0")]
522522
Some(#[stable(feature = "rust1", since = "1.0.0")] T),

library/core/src/slice/mod.rs

+119
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ use crate::option::Option::{None, Some};
1616
use crate::ptr;
1717
use crate::result::Result;
1818
use crate::result::Result::{Err, Ok};
19+
#[cfg(not(miri))] // Miri does not support all SIMD intrinsics
20+
use crate::simd::{self, Simd};
1921
use crate::slice;
2022

2123
#[unstable(
@@ -3512,6 +3514,123 @@ impl<T> [T] {
35123514
}
35133515
}
35143516

3517+
/// Split a slice into a prefix, a middle of aligned SIMD types, and a suffix.
3518+
///
3519+
/// This is a safe wrapper around [`slice::align_to`], so has the same weak
3520+
/// postconditions as that method. You're only assured that
3521+
/// `self.len() == prefix.len() + middle.len() * LANES + suffix.len()`.
3522+
///
3523+
/// Notably, all of the following are possible:
3524+
/// - `prefix.len() >= LANES`.
3525+
/// - `middle.is_empty()` despite `self.len() >= 3 * LANES`.
3526+
/// - `suffix.len() >= LANES`.
3527+
///
3528+
/// That said, this is a safe method, so if you're only writing safe code,
3529+
/// then this can at most cause incorrect logic, not unsoundness.
3530+
///
3531+
/// # Panics
3532+
///
3533+
/// This will panic if the size of the SIMD type is different from
3534+
/// `LANES` times that of the scalar.
3535+
///
3536+
/// At the time of writing, the trait restrictions on `Simd<T, LANES>` keeps
3537+
/// that from ever happening, as only power-of-two numbers of lanes are
3538+
/// supported. It's possible that, in the future, those restrictions might
3539+
/// be lifted in a way that would make it possible to see panics from this
3540+
/// method for something like `LANES == 3`.
3541+
///
3542+
/// # Examples
3543+
///
3544+
/// ```
3545+
/// #![feature(portable_simd)]
3546+
///
3547+
/// let short = &[1, 2, 3];
3548+
/// let (prefix, middle, suffix) = short.as_simd::<4>();
3549+
/// assert_eq!(middle, []); // Not enough elements for anything in the middle
3550+
///
3551+
/// // They might be split in any possible way between prefix and suffix
3552+
/// let it = prefix.iter().chain(suffix).copied();
3553+
/// assert_eq!(it.collect::<Vec<_>>(), vec![1, 2, 3]);
3554+
///
3555+
/// fn basic_simd_sum(x: &[f32]) -> f32 {
3556+
/// use std::ops::Add;
3557+
/// use std::simd::f32x4;
3558+
/// let (prefix, middle, suffix) = x.as_simd();
3559+
/// let sums = f32x4::from_array([
3560+
/// prefix.iter().copied().sum(),
3561+
/// 0.0,
3562+
/// 0.0,
3563+
/// suffix.iter().copied().sum(),
3564+
/// ]);
3565+
/// let sums = middle.iter().copied().fold(sums, f32x4::add);
3566+
/// sums.horizontal_sum()
3567+
/// }
3568+
///
3569+
/// let numbers: Vec<f32> = (1..101).map(|x| x as _).collect();
3570+
/// assert_eq!(basic_simd_sum(&numbers[1..99]), 4949.0);
3571+
/// ```
3572+
#[unstable(feature = "portable_simd", issue = "86656")]
3573+
#[cfg(not(miri))] // Miri does not support all SIMD intrinsics
3574+
pub fn as_simd<const LANES: usize>(&self) -> (&[T], &[Simd<T, LANES>], &[T])
3575+
where
3576+
Simd<T, LANES>: AsRef<[T; LANES]>,
3577+
T: simd::SimdElement,
3578+
simd::LaneCount<LANES>: simd::SupportedLaneCount,
3579+
{
3580+
// These are expected to always match, as vector types are laid out like
3581+
// arrays per <https://llvm.org/docs/LangRef.html#vector-type>, but we
3582+
// might as well double-check since it'll optimize away anyhow.
3583+
assert_eq!(mem::size_of::<Simd<T, LANES>>(), mem::size_of::<[T; LANES]>());
3584+
3585+
// SAFETY: The simd types have the same layout as arrays, just with
3586+
// potentially-higher alignment, so the de-facto transmutes are sound.
3587+
unsafe { self.align_to() }
3588+
}
3589+
3590+
/// Split a slice into a prefix, a middle of aligned SIMD types, and a suffix.
3591+
///
3592+
/// This is a safe wrapper around [`slice::align_to_mut`], so has the same weak
3593+
/// postconditions as that method. You're only assured that
3594+
/// `self.len() == prefix.len() + middle.len() * LANES + suffix.len()`.
3595+
///
3596+
/// Notably, all of the following are possible:
3597+
/// - `prefix.len() >= LANES`.
3598+
/// - `middle.is_empty()` despite `self.len() >= 3 * LANES`.
3599+
/// - `suffix.len() >= LANES`.
3600+
///
3601+
/// That said, this is a safe method, so if you're only writing safe code,
3602+
/// then this can at most cause incorrect logic, not unsoundness.
3603+
///
3604+
/// This is the mutable version of [`slice::as_simd`]; see that for examples.
3605+
///
3606+
/// # Panics
3607+
///
3608+
/// This will panic if the size of the SIMD type is different from
3609+
/// `LANES` times that of the scalar.
3610+
///
3611+
/// At the time of writing, the trait restrictions on `Simd<T, LANES>` keeps
3612+
/// that from ever happening, as only power-of-two numbers of lanes are
3613+
/// supported. It's possible that, in the future, those restrictions might
3614+
/// be lifted in a way that would make it possible to see panics from this
3615+
/// method for something like `LANES == 3`.
3616+
#[unstable(feature = "portable_simd", issue = "86656")]
3617+
#[cfg(not(miri))] // Miri does not support all SIMD intrinsics
3618+
pub fn as_simd_mut<const LANES: usize>(&mut self) -> (&mut [T], &mut [Simd<T, LANES>], &mut [T])
3619+
where
3620+
Simd<T, LANES>: AsMut<[T; LANES]>,
3621+
T: simd::SimdElement,
3622+
simd::LaneCount<LANES>: simd::SupportedLaneCount,
3623+
{
3624+
// These are expected to always match, as vector types are laid out like
3625+
// arrays per <https://llvm.org/docs/LangRef.html#vector-type>, but we
3626+
// might as well double-check since it'll optimize away anyhow.
3627+
assert_eq!(mem::size_of::<Simd<T, LANES>>(), mem::size_of::<[T; LANES]>());
3628+
3629+
// SAFETY: The simd types have the same layout as arrays, just with
3630+
// potentially-higher alignment, so the de-facto transmutes are sound.
3631+
unsafe { self.align_to_mut() }
3632+
}
3633+
35153634
/// Checks if the elements of this slice are sorted.
35163635
///
35173636
/// That is, for each element `a` and its following element `b`, `a <= b` must hold. If the

library/proc_macro/src/bridge/client.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ macro_rules! define_handles {
7878
}
7979
}
8080

81-
impl<S: server::Types> Decode<'_, 's, HandleStore<server::MarkedTypes<S>>>
81+
impl<'s, S: server::Types> Decode<'_, 's, HandleStore<server::MarkedTypes<S>>>
8282
for &'s Marked<S::$oty, $oty>
8383
{
8484
fn decode(r: &mut Reader<'_>, s: &'s HandleStore<server::MarkedTypes<S>>) -> Self {
@@ -92,7 +92,7 @@ macro_rules! define_handles {
9292
}
9393
}
9494

95-
impl<S: server::Types> DecodeMut<'_, 's, HandleStore<server::MarkedTypes<S>>>
95+
impl<'s, S: server::Types> DecodeMut<'_, 's, HandleStore<server::MarkedTypes<S>>>
9696
for &'s mut Marked<S::$oty, $oty>
9797
{
9898
fn decode(

library/proc_macro/src/bridge/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -295,13 +295,13 @@ impl<T, M> Unmark for Marked<T, M> {
295295
self.value
296296
}
297297
}
298-
impl<T, M> Unmark for &'a Marked<T, M> {
298+
impl<'a, T, M> Unmark for &'a Marked<T, M> {
299299
type Unmarked = &'a T;
300300
fn unmark(self) -> Self::Unmarked {
301301
&self.value
302302
}
303303
}
304-
impl<T, M> Unmark for &'a mut Marked<T, M> {
304+
impl<'a, T, M> Unmark for &'a mut Marked<T, M> {
305305
type Unmarked = &'a mut T;
306306
fn unmark(self) -> Self::Unmarked {
307307
&mut self.value
@@ -356,8 +356,8 @@ mark_noop! {
356356
(),
357357
bool,
358358
char,
359-
&'a [u8],
360-
&'a str,
359+
&'_ [u8],
360+
&'_ str,
361361
String,
362362
usize,
363363
Delimiter,

0 commit comments

Comments
 (0)