Skip to content

Commit 82eb03e

Browse files
committed
Auto merge of rust-lang#139301 - matthiaskrgr:rollup-sa6ali8, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#139080 (Experimental feature gate for `super let`) - rust-lang#139145 (slice: Remove some uses of unsafe in first/last chunk methods) - rust-lang#139149 (unstable book: document import_trait_associated_functions) - rust-lang#139273 (Apply requested API changes to `cell_update`) - rust-lang#139282 (rustdoc: make settings checkboxes always square) - rust-lang#139283 (Rustc dev guide subtree update) - rust-lang#139294 (Fix the `f16`/`f128` feature gates on integer literals) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 946aea0 + 29c0fe7 commit 82eb03e

Some content is hidden

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

56 files changed

+737
-506
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -332,17 +332,19 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
332332
ast::ExprKind::TryBlock(_) => {
333333
gate!(&self, try_blocks, e.span, "`try` expression is experimental");
334334
}
335-
ast::ExprKind::Lit(token::Lit { kind: token::LitKind::Float, suffix, .. }) => {
336-
match suffix {
337-
Some(sym::f16) => {
338-
gate!(&self, f16, e.span, "the type `f16` is unstable")
339-
}
340-
Some(sym::f128) => {
341-
gate!(&self, f128, e.span, "the type `f128` is unstable")
342-
}
343-
_ => (),
335+
ast::ExprKind::Lit(token::Lit {
336+
kind: token::LitKind::Float | token::LitKind::Integer,
337+
suffix,
338+
..
339+
}) => match suffix {
340+
Some(sym::f16) => {
341+
gate!(&self, f16, e.span, "the type `f16` is unstable")
344342
}
345-
}
343+
Some(sym::f128) => {
344+
gate!(&self, f128, e.span, "the type `f128` is unstable")
345+
}
346+
_ => (),
347+
},
346348
_ => {}
347349
}
348350
visit::walk_expr(self, e)
@@ -511,6 +513,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
511513
gate_all!(contracts, "contracts are incomplete");
512514
gate_all!(contracts_internals, "contract internal machinery is for internal use only");
513515
gate_all!(where_clause_attrs, "attributes in `where` clause are unstable");
516+
gate_all!(super_let, "`super let` is experimental");
514517

515518
if !visitor.features.never_patterns() {
516519
if let Some(spans) = spans.get(&sym::never_patterns) {

compiler/rustc_feature/src/unstable.rs

+2
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,8 @@ declare_features! (
629629
(unstable, strict_provenance_lints, "1.61.0", Some(130351)),
630630
/// Allows string patterns to dereference values to match them.
631631
(unstable, string_deref_patterns, "1.67.0", Some(87121)),
632+
/// Allows `super let` statements.
633+
(incomplete, super_let, "CURRENT_RUSTC_VERSION", Some(139076)),
632634
/// Allows subtrait items to shadow supertrait items.
633635
(unstable, supertrait_item_shadowing, "1.86.0", Some(89151)),
634636
/// Allows using `#[thread_local]` on `static` items.

compiler/rustc_parse/src/parser/stmt.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,20 @@ impl<'a> Parser<'a> {
7373
});
7474
}
7575

76-
let stmt = if self.token.is_keyword(kw::Let) {
76+
let stmt = if self.token.is_keyword(kw::Super) && self.is_keyword_ahead(1, &[kw::Let]) {
77+
self.collect_tokens(None, attrs, force_collect, |this, attrs| {
78+
this.expect_keyword(exp!(Super))?;
79+
this.psess.gated_spans.gate(sym::super_let, this.prev_token.span);
80+
this.expect_keyword(exp!(Let))?;
81+
let local = this.parse_local(attrs)?; // FIXME(mara): implement super let
82+
let trailing = Trailing::from(capture_semi && this.token == token::Semi);
83+
Ok((
84+
this.mk_stmt(lo.to(this.prev_token.span), StmtKind::Let(local)),
85+
trailing,
86+
UsePreAttrPos::No,
87+
))
88+
})?
89+
} else if self.token.is_keyword(kw::Let) {
7790
self.collect_tokens(None, attrs, force_collect, |this, attrs| {
7891
this.expect_keyword(exp!(Let))?;
7992
let local = this.parse_local(attrs)?;

compiler/rustc_parse/src/parser/token_type.rs

+4
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ pub enum TokenType {
114114
KwSelfUpper,
115115
KwStatic,
116116
KwStruct,
117+
KwSuper,
117118
KwTrait,
118119
KwTry,
119120
KwType,
@@ -250,6 +251,7 @@ impl TokenType {
250251
KwSelfUpper,
251252
KwStatic,
252253
KwStruct,
254+
KwSuper,
253255
KwTrait,
254256
KwTry,
255257
KwType,
@@ -324,6 +326,7 @@ impl TokenType {
324326
TokenType::KwSelfUpper => Some(kw::SelfUpper),
325327
TokenType::KwStatic => Some(kw::Static),
326328
TokenType::KwStruct => Some(kw::Struct),
329+
TokenType::KwSuper => Some(kw::Super),
327330
TokenType::KwTrait => Some(kw::Trait),
328331
TokenType::KwTry => Some(kw::Try),
329332
TokenType::KwType => Some(kw::Type),
@@ -549,6 +552,7 @@ macro_rules! exp {
549552
(SelfUpper) => { exp!(@kw, SelfUpper, KwSelfUpper) };
550553
(Static) => { exp!(@kw, Static, KwStatic) };
551554
(Struct) => { exp!(@kw, Struct, KwStruct) };
555+
(Super) => { exp!(@kw, Super, KwSuper) };
552556
(Trait) => { exp!(@kw, Trait, KwTrait) };
553557
(Try) => { exp!(@kw, Try, KwTry) };
554558
(Type) => { exp!(@kw, Type, KwType) };

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2040,6 +2040,7 @@ symbols! {
20402040
sub_assign,
20412041
sub_with_overflow,
20422042
suggestion,
2043+
super_let,
20432044
supertrait_item_shadowing,
20442045
surface_async_drop_in_place,
20452046
sym,

library/core/src/cell.rs

+4-11
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ impl<T: Copy> Cell<T> {
544544
unsafe { *self.value.get() }
545545
}
546546

547-
/// Updates the contained value using a function and returns the new value.
547+
/// Updates the contained value using a function.
548548
///
549549
/// # Examples
550550
///
@@ -554,21 +554,14 @@ impl<T: Copy> Cell<T> {
554554
/// use std::cell::Cell;
555555
///
556556
/// let c = Cell::new(5);
557-
/// let new = c.update(|x| x + 1);
558-
///
559-
/// assert_eq!(new, 6);
557+
/// c.update(|x| x + 1);
560558
/// assert_eq!(c.get(), 6);
561559
/// ```
562560
#[inline]
563561
#[unstable(feature = "cell_update", issue = "50186")]
564-
pub fn update<F>(&self, f: F) -> T
565-
where
566-
F: FnOnce(T) -> T,
567-
{
562+
pub fn update(&self, f: impl FnOnce(T) -> T) {
568563
let old = self.get();
569-
let new = f(old);
570-
self.set(new);
571-
new
564+
self.set(f(old));
572565
}
573566
}
574567

library/core/src/slice/mod.rs

+34-60
Original file line numberDiff line numberDiff line change
@@ -382,16 +382,11 @@ impl<T> [T] {
382382
#[stable(feature = "slice_first_last_chunk", since = "1.77.0")]
383383
#[rustc_const_stable(feature = "slice_first_last_chunk", since = "1.77.0")]
384384
pub const fn split_first_chunk<const N: usize>(&self) -> Option<(&[T; N], &[T])> {
385-
if self.len() < N {
386-
None
387-
} else {
388-
// SAFETY: We manually verified the bounds of the split.
389-
let (first, tail) = unsafe { self.split_at_unchecked(N) };
385+
let Some((first, tail)) = self.split_at_checked(N) else { return None };
390386

391-
// SAFETY: We explicitly check for the correct number of elements,
392-
// and do not let the references outlive the slice.
393-
Some((unsafe { &*(first.as_ptr().cast::<[T; N]>()) }, tail))
394-
}
387+
// SAFETY: We explicitly check for the correct number of elements,
388+
// and do not let the references outlive the slice.
389+
Some((unsafe { &*(first.as_ptr().cast::<[T; N]>()) }, tail))
395390
}
396391

397392
/// Returns a mutable array reference to the first `N` items in the slice and the remaining
@@ -419,17 +414,12 @@ impl<T> [T] {
419414
pub const fn split_first_chunk_mut<const N: usize>(
420415
&mut self,
421416
) -> Option<(&mut [T; N], &mut [T])> {
422-
if self.len() < N {
423-
None
424-
} else {
425-
// SAFETY: We manually verified the bounds of the split.
426-
let (first, tail) = unsafe { self.split_at_mut_unchecked(N) };
417+
let Some((first, tail)) = self.split_at_mut_checked(N) else { return None };
427418

428-
// SAFETY: We explicitly check for the correct number of elements,
429-
// do not let the reference outlive the slice,
430-
// and enforce exclusive mutability of the chunk by the split.
431-
Some((unsafe { &mut *(first.as_mut_ptr().cast::<[T; N]>()) }, tail))
432-
}
419+
// SAFETY: We explicitly check for the correct number of elements,
420+
// do not let the reference outlive the slice,
421+
// and enforce exclusive mutability of the chunk by the split.
422+
Some((unsafe { &mut *(first.as_mut_ptr().cast::<[T; N]>()) }, tail))
433423
}
434424

435425
/// Returns an array reference to the last `N` items in the slice and the remaining slice.
@@ -452,16 +442,12 @@ impl<T> [T] {
452442
#[stable(feature = "slice_first_last_chunk", since = "1.77.0")]
453443
#[rustc_const_stable(feature = "slice_first_last_chunk", since = "1.77.0")]
454444
pub const fn split_last_chunk<const N: usize>(&self) -> Option<(&[T], &[T; N])> {
455-
if self.len() < N {
456-
None
457-
} else {
458-
// SAFETY: We manually verified the bounds of the split.
459-
let (init, last) = unsafe { self.split_at_unchecked(self.len() - N) };
445+
let Some(index) = self.len().checked_sub(N) else { return None };
446+
let (init, last) = self.split_at(index);
460447

461-
// SAFETY: We explicitly check for the correct number of elements,
462-
// and do not let the references outlive the slice.
463-
Some((init, unsafe { &*(last.as_ptr().cast::<[T; N]>()) }))
464-
}
448+
// SAFETY: We explicitly check for the correct number of elements,
449+
// and do not let the references outlive the slice.
450+
Some((init, unsafe { &*(last.as_ptr().cast::<[T; N]>()) }))
465451
}
466452

467453
/// Returns a mutable array reference to the last `N` items in the slice and the remaining
@@ -489,17 +475,13 @@ impl<T> [T] {
489475
pub const fn split_last_chunk_mut<const N: usize>(
490476
&mut self,
491477
) -> Option<(&mut [T], &mut [T; N])> {
492-
if self.len() < N {
493-
None
494-
} else {
495-
// SAFETY: We manually verified the bounds of the split.
496-
let (init, last) = unsafe { self.split_at_mut_unchecked(self.len() - N) };
478+
let Some(index) = self.len().checked_sub(N) else { return None };
479+
let (init, last) = self.split_at_mut(index);
497480

498-
// SAFETY: We explicitly check for the correct number of elements,
499-
// do not let the reference outlive the slice,
500-
// and enforce exclusive mutability of the chunk by the split.
501-
Some((init, unsafe { &mut *(last.as_mut_ptr().cast::<[T; N]>()) }))
502-
}
481+
// SAFETY: We explicitly check for the correct number of elements,
482+
// do not let the reference outlive the slice,
483+
// and enforce exclusive mutability of the chunk by the split.
484+
Some((init, unsafe { &mut *(last.as_mut_ptr().cast::<[T; N]>()) }))
503485
}
504486

505487
/// Returns an array reference to the last `N` items in the slice.
@@ -522,17 +504,13 @@ impl<T> [T] {
522504
#[stable(feature = "slice_first_last_chunk", since = "1.77.0")]
523505
#[rustc_const_stable(feature = "const_slice_last_chunk", since = "1.80.0")]
524506
pub const fn last_chunk<const N: usize>(&self) -> Option<&[T; N]> {
525-
if self.len() < N {
526-
None
527-
} else {
528-
// SAFETY: We manually verified the bounds of the slice.
529-
// FIXME(const-hack): Without const traits, we need this instead of `get_unchecked`.
530-
let last = unsafe { self.split_at_unchecked(self.len() - N).1 };
507+
// FIXME(const-hack): Without const traits, we need this instead of `get`.
508+
let Some(index) = self.len().checked_sub(N) else { return None };
509+
let (_, last) = self.split_at(index);
531510

532-
// SAFETY: We explicitly check for the correct number of elements,
533-
// and do not let the references outlive the slice.
534-
Some(unsafe { &*(last.as_ptr().cast::<[T; N]>()) })
535-
}
511+
// SAFETY: We explicitly check for the correct number of elements,
512+
// and do not let the references outlive the slice.
513+
Some(unsafe { &*(last.as_ptr().cast::<[T; N]>()) })
536514
}
537515

538516
/// Returns a mutable array reference to the last `N` items in the slice.
@@ -556,18 +534,14 @@ impl<T> [T] {
556534
#[stable(feature = "slice_first_last_chunk", since = "1.77.0")]
557535
#[rustc_const_stable(feature = "const_slice_first_last_chunk", since = "1.83.0")]
558536
pub const fn last_chunk_mut<const N: usize>(&mut self) -> Option<&mut [T; N]> {
559-
if self.len() < N {
560-
None
561-
} else {
562-
// SAFETY: We manually verified the bounds of the slice.
563-
// FIXME(const-hack): Without const traits, we need this instead of `get_unchecked`.
564-
let last = unsafe { self.split_at_mut_unchecked(self.len() - N).1 };
565-
566-
// SAFETY: We explicitly check for the correct number of elements,
567-
// do not let the reference outlive the slice,
568-
// and require exclusive access to the entire slice to mutate the chunk.
569-
Some(unsafe { &mut *(last.as_mut_ptr().cast::<[T; N]>()) })
570-
}
537+
// FIXME(const-hack): Without const traits, we need this instead of `get`.
538+
let Some(index) = self.len().checked_sub(N) else { return None };
539+
let (_, last) = self.split_at_mut(index);
540+
541+
// SAFETY: We explicitly check for the correct number of elements,
542+
// do not let the reference outlive the slice,
543+
// and require exclusive access to the entire slice to mutate the chunk.
544+
Some(unsafe { &mut *(last.as_mut_ptr().cast::<[T; N]>()) })
571545
}
572546

573547
/// Returns a reference to an element or subslice depending on the type of

library/coretests/tests/cell.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ fn smoketest_cell() {
5050
fn cell_update() {
5151
let x = Cell::new(10);
5252

53-
assert_eq!(x.update(|x| x + 5), 15);
53+
x.update(|x| x + 5);
5454
assert_eq!(x.get(), 15);
5555

56-
assert_eq!(x.update(|x| x / 3), 5);
56+
x.update(|x| x / 3);
5757
assert_eq!(x.get(), 5);
5858
}
5959

src/doc/rustc-dev-guide/.github/workflows/ci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
MDBOOK_LINKCHECK2_VERSION: 0.9.1
1919
MDBOOK_MERMAID_VERSION: 0.12.6
2020
MDBOOK_TOC_VERSION: 0.11.2
21+
MDBOOK_OUTPUT__LINKCHECK__FOLLOW_WEB_LINKS: ${{ github.event_name != 'pull_request' }}
2122
DEPLOY_DIR: book/html
2223
BASE_SHA: ${{ github.event.pull_request.base.sha }}
2324
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

src/doc/rustc-dev-guide/book.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,7 @@ warning-policy = "error"
6262
"/diagnostics/sessiondiagnostic.html" = "diagnostic-structs.html"
6363
"/diagnostics/diagnostic-codes.html" = "error-codes.html"
6464
"/miri.html" = "const-eval/interpret.html"
65-
"/tests/integration.html" = "ecosystem.html"
65+
"/tests/fuchsia.html" = "ecosystem-test-jobs/fuchsia.html"
6666
"/tests/headers.html" = "directives.html"
67+
"/tests/integration.html" = "ecosystem.html"
68+
"/tests/rust-for-linux.html" = "ecosystem-test-jobs/rust-for-linux.html"

0 commit comments

Comments
 (0)