Skip to content

Commit a3ea86e

Browse files
authored
Merge pull request #4222 from rust-lang/rustup-2025-03-07
Automatic Rustup
2 parents 7c3979e + 245aad1 commit a3ea86e

File tree

227 files changed

+2693
-1341
lines changed

Some content is hidden

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

227 files changed

+2693
-1341
lines changed

compiler/rustc_abi/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1812,7 +1812,7 @@ where
18121812
f.debug_struct("Layout")
18131813
.field("size", size)
18141814
.field("align", align)
1815-
.field("abi", backend_repr)
1815+
.field("backend_repr", backend_repr)
18161816
.field("fields", fields)
18171817
.field("largest_niche", largest_niche)
18181818
.field("uninhabited", uninhabited)

compiler/rustc_ast/src/ast.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2641,6 +2641,8 @@ pub enum SelfKind {
26412641
Value(Mutability),
26422642
/// `&'lt self`, `&'lt mut self`
26432643
Region(Option<Lifetime>, Mutability),
2644+
/// `&'lt pin const self`, `&'lt pin mut self`
2645+
Pinned(Option<Lifetime>, Mutability),
26442646
/// `self: TYPE`, `mut self: TYPE`
26452647
Explicit(P<Ty>, Mutability),
26462648
}
@@ -2650,6 +2652,8 @@ impl SelfKind {
26502652
match self {
26512653
SelfKind::Region(None, mutbl) => mutbl.ref_prefix_str().to_string(),
26522654
SelfKind::Region(Some(lt), mutbl) => format!("&{lt} {}", mutbl.prefix_str()),
2655+
SelfKind::Pinned(None, mutbl) => format!("&pin {}", mutbl.ptr_str()),
2656+
SelfKind::Pinned(Some(lt), mutbl) => format!("&{lt} pin {}", mutbl.ptr_str()),
26532657
SelfKind::Value(_) | SelfKind::Explicit(_, _) => {
26542658
unreachable!("if we had an explicit self, we wouldn't be here")
26552659
}
@@ -2666,11 +2670,13 @@ impl Param {
26662670
if ident.name == kw::SelfLower {
26672671
return match self.ty.kind {
26682672
TyKind::ImplicitSelf => Some(respan(self.pat.span, SelfKind::Value(mutbl))),
2669-
TyKind::Ref(lt, MutTy { ref ty, mutbl })
2670-
| TyKind::PinnedRef(lt, MutTy { ref ty, mutbl })
2673+
TyKind::Ref(lt, MutTy { ref ty, mutbl }) if ty.kind.is_implicit_self() => {
2674+
Some(respan(self.pat.span, SelfKind::Region(lt, mutbl)))
2675+
}
2676+
TyKind::PinnedRef(lt, MutTy { ref ty, mutbl })
26712677
if ty.kind.is_implicit_self() =>
26722678
{
2673-
Some(respan(self.pat.span, SelfKind::Region(lt, mutbl)))
2679+
Some(respan(self.pat.span, SelfKind::Pinned(lt, mutbl)))
26742680
}
26752681
_ => Some(respan(
26762682
self.pat.span.to(self.ty.span),
@@ -2712,6 +2718,15 @@ impl Param {
27122718
tokens: None,
27132719
}),
27142720
),
2721+
SelfKind::Pinned(lt, mutbl) => (
2722+
mutbl,
2723+
P(Ty {
2724+
id: DUMMY_NODE_ID,
2725+
kind: TyKind::PinnedRef(lt, MutTy { ty: infer_ty, mutbl }),
2726+
span,
2727+
tokens: None,
2728+
}),
2729+
),
27152730
};
27162731
Param {
27172732
attrs,

compiler/rustc_ast/src/ast_traits.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,16 +209,12 @@ impl HasTokens for Attribute {
209209
impl HasTokens for Nonterminal {
210210
fn tokens(&self) -> Option<&LazyAttrTokenStream> {
211211
match self {
212-
Nonterminal::NtItem(item) => item.tokens(),
213-
Nonterminal::NtStmt(stmt) => stmt.tokens(),
214212
Nonterminal::NtExpr(expr) | Nonterminal::NtLiteral(expr) => expr.tokens(),
215213
Nonterminal::NtBlock(block) => block.tokens(),
216214
}
217215
}
218216
fn tokens_mut(&mut self) -> Option<&mut Option<LazyAttrTokenStream>> {
219217
match self {
220-
Nonterminal::NtItem(item) => item.tokens_mut(),
221-
Nonterminal::NtStmt(stmt) => stmt.tokens_mut(),
222218
Nonterminal::NtExpr(expr) | Nonterminal::NtLiteral(expr) => expr.tokens_mut(),
223219
Nonterminal::NtBlock(block) => block.tokens_mut(),
224220
}

compiler/rustc_ast/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
77
// tidy-alphabetical-start
88
#![allow(internal_features)]
9+
#![cfg_attr(doc, recursion_limit = "256")] // FIXME(nnethercote): will be removed by #124141
910
#![doc(
1011
html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/",
1112
test(attr(deny(warnings)))

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -895,19 +895,7 @@ pub fn visit_token<T: MutVisitor>(vis: &mut T, t: &mut Token) {
895895
// multiple items there....
896896
fn visit_nonterminal<T: MutVisitor>(vis: &mut T, nt: &mut token::Nonterminal) {
897897
match nt {
898-
token::NtItem(item) => visit_clobber(item, |item| {
899-
// This is probably okay, because the only visitors likely to
900-
// peek inside interpolated nodes will be renamings/markings,
901-
// which map single items to single items.
902-
vis.flat_map_item(item).expect_one("expected visitor to produce exactly one item")
903-
}),
904898
token::NtBlock(block) => vis.visit_block(block),
905-
token::NtStmt(stmt) => visit_clobber(stmt, |stmt| {
906-
// See reasoning above.
907-
stmt.map(|stmt| {
908-
vis.flat_map_stmt(stmt).expect_one("expected visitor to produce exactly one item")
909-
})
910-
}),
911899
token::NtExpr(expr) => vis.visit_expr(expr),
912900
token::NtLiteral(expr) => vis.visit_expr(expr),
913901
}

compiler/rustc_ast/src/token.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,7 @@ impl Token {
870870
/// Is this a pre-parsed expression dropped into the token stream
871871
/// (which happens while parsing the result of macro expansion)?
872872
pub fn is_whole_expr(&self) -> bool {
873+
#[allow(irrefutable_let_patterns)] // FIXME: temporary
873874
if let Interpolated(nt) = &self.kind
874875
&& let NtExpr(_) | NtLiteral(_) | NtBlock(_) = &**nt
875876
{
@@ -1103,9 +1104,7 @@ pub enum NtExprKind {
11031104
#[derive(Clone, Encodable, Decodable)]
11041105
/// For interpolation during macro expansion.
11051106
pub enum Nonterminal {
1106-
NtItem(P<ast::Item>),
11071107
NtBlock(P<ast::Block>),
1108-
NtStmt(P<ast::Stmt>),
11091108
NtExpr(P<ast::Expr>),
11101109
NtLiteral(P<ast::Expr>),
11111110
}
@@ -1196,18 +1195,14 @@ impl fmt::Display for NonterminalKind {
11961195
impl Nonterminal {
11971196
pub fn use_span(&self) -> Span {
11981197
match self {
1199-
NtItem(item) => item.span,
12001198
NtBlock(block) => block.span,
1201-
NtStmt(stmt) => stmt.span,
12021199
NtExpr(expr) | NtLiteral(expr) => expr.span,
12031200
}
12041201
}
12051202

12061203
pub fn descr(&self) -> &'static str {
12071204
match self {
1208-
NtItem(..) => "item",
12091205
NtBlock(..) => "block",
1210-
NtStmt(..) => "statement",
12111206
NtExpr(..) => "expression",
12121207
NtLiteral(..) => "literal",
12131208
}
@@ -1227,9 +1222,7 @@ impl PartialEq for Nonterminal {
12271222
impl fmt::Debug for Nonterminal {
12281223
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
12291224
match *self {
1230-
NtItem(..) => f.pad("NtItem(..)"),
12311225
NtBlock(..) => f.pad("NtBlock(..)"),
1232-
NtStmt(..) => f.pad("NtStmt(..)"),
12331226
NtExpr(..) => f.pad("NtExpr(..)"),
12341227
NtLiteral(..) => f.pad("NtLiteral(..)"),
12351228
}

compiler/rustc_ast/src/tokenstream.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use rustc_macros::{Decodable, Encodable, HashStable_Generic};
2323
use rustc_serialize::{Decodable, Encodable};
2424
use rustc_span::{DUMMY_SP, Span, SpanDecoder, SpanEncoder, Symbol, sym};
2525

26-
use crate::ast::{AttrStyle, StmtKind};
26+
use crate::ast::AttrStyle;
2727
use crate::ast_traits::{HasAttrs, HasTokens};
2828
use crate::token::{self, Delimiter, InvisibleOrigin, Nonterminal, Token, TokenKind};
2929
use crate::{AttrVec, Attribute};
@@ -461,13 +461,7 @@ impl TokenStream {
461461

462462
pub fn from_nonterminal_ast(nt: &Nonterminal) -> TokenStream {
463463
match nt {
464-
Nonterminal::NtItem(item) => TokenStream::from_ast(item),
465464
Nonterminal::NtBlock(block) => TokenStream::from_ast(block),
466-
Nonterminal::NtStmt(stmt) if let StmtKind::Empty = stmt.kind => {
467-
// FIXME: Properly collect tokens for empty statements.
468-
TokenStream::token_alone(token::Semi, stmt.span)
469-
}
470-
Nonterminal::NtStmt(stmt) => TokenStream::from_ast(stmt),
471465
Nonterminal::NtExpr(expr) | Nonterminal::NtLiteral(expr) => TokenStream::from_ast(expr),
472466
}
473467
}

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
3333
// tidy-alphabetical-start
3434
#![allow(internal_features)]
35+
#![cfg_attr(doc, recursion_limit = "256")] // FIXME(nnethercote): will be removed by #124141
3536
#![doc(rust_logo)]
3637
#![feature(assert_matches)]
3738
#![feature(box_patterns)]
@@ -136,6 +137,7 @@ struct LoweringContext<'a, 'hir> {
136137

137138
allow_try_trait: Arc<[Symbol]>,
138139
allow_gen_future: Arc<[Symbol]>,
140+
allow_pattern_type: Arc<[Symbol]>,
139141
allow_async_iterator: Arc<[Symbol]>,
140142
allow_for_await: Arc<[Symbol]>,
141143
allow_async_fn_traits: Arc<[Symbol]>,
@@ -176,6 +178,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
176178
impl_trait_defs: Vec::new(),
177179
impl_trait_bounds: Vec::new(),
178180
allow_try_trait: [sym::try_trait_v2, sym::yeet_desugar_details].into(),
181+
allow_pattern_type: [sym::pattern_types, sym::pattern_type_range_trait].into(),
179182
allow_gen_future: if tcx.features().async_fn_track_caller() {
180183
[sym::gen_future, sym::closure_track_caller].into()
181184
} else {
@@ -926,7 +929,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
926929
if let Some(first_char) = constraint.ident.as_str().chars().next()
927930
&& first_char.is_ascii_lowercase()
928931
{
929-
tracing::info!(?data, ?data.inputs);
930932
let err = match (&data.inputs[..], &data.output) {
931933
([_, ..], FnRetTy::Default(_)) => {
932934
errors::BadReturnTypeNotation::Inputs { span: data.inputs_span }
@@ -1365,7 +1367,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13651367
}
13661368
}
13671369
TyKind::Pat(ty, pat) => {
1368-
hir::TyKind::Pat(self.lower_ty(ty, itctx), self.lower_ty_pat(pat))
1370+
hir::TyKind::Pat(self.lower_ty(ty, itctx), self.lower_ty_pat(pat, ty.span))
13691371
}
13701372
TyKind::MacCall(_) => {
13711373
span_bug!(t.span, "`TyKind::MacCall` should have been expanded by now")

compiler/rustc_ast_lowering/src/pat.rs

Lines changed: 112 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ use std::sync::Arc;
33
use rustc_ast::ptr::P;
44
use rustc_ast::*;
55
use rustc_data_structures::stack::ensure_sufficient_stack;
6-
use rustc_hir as hir;
7-
use rustc_hir::def::Res;
6+
use rustc_hir::def::{DefKind, Res};
7+
use rustc_hir::{self as hir, LangItem};
88
use rustc_middle::span_bug;
99
use rustc_span::source_map::{Spanned, respan};
10-
use rustc_span::{Ident, Span};
10+
use rustc_span::{DesugaringKind, Ident, Span, kw};
1111

1212
use super::errors::{
1313
ArbitraryExpressionInPattern, ExtraDoubleDot, MisplacedDoubleDot, SubTupleBinding,
@@ -430,22 +430,124 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
430430
self.arena.alloc(hir::PatExpr { hir_id: self.lower_node_id(expr.id), span, kind })
431431
}
432432

433-
pub(crate) fn lower_ty_pat(&mut self, pattern: &TyPat) -> &'hir hir::TyPat<'hir> {
434-
self.arena.alloc(self.lower_ty_pat_mut(pattern))
433+
pub(crate) fn lower_ty_pat(
434+
&mut self,
435+
pattern: &TyPat,
436+
base_type: Span,
437+
) -> &'hir hir::TyPat<'hir> {
438+
self.arena.alloc(self.lower_ty_pat_mut(pattern, base_type))
435439
}
436440

437-
fn lower_ty_pat_mut(&mut self, pattern: &TyPat) -> hir::TyPat<'hir> {
441+
fn lower_ty_pat_mut(&mut self, pattern: &TyPat, base_type: Span) -> hir::TyPat<'hir> {
438442
// loop here to avoid recursion
439443
let pat_hir_id = self.lower_node_id(pattern.id);
440444
let node = match &pattern.kind {
441-
TyPatKind::Range(e1, e2, Spanned { node: end, .. }) => hir::TyPatKind::Range(
442-
e1.as_deref().map(|e| self.lower_anon_const_to_const_arg(e)),
443-
e2.as_deref().map(|e| self.lower_anon_const_to_const_arg(e)),
444-
self.lower_range_end(end, e2.is_some()),
445+
TyPatKind::Range(e1, e2, Spanned { node: end, span }) => hir::TyPatKind::Range(
446+
e1.as_deref().map(|e| self.lower_anon_const_to_const_arg(e)).unwrap_or_else(|| {
447+
self.lower_ty_pat_range_end(
448+
hir::LangItem::RangeMin,
449+
span.shrink_to_lo(),
450+
base_type,
451+
)
452+
}),
453+
e2.as_deref()
454+
.map(|e| match end {
455+
RangeEnd::Included(..) => self.lower_anon_const_to_const_arg(e),
456+
RangeEnd::Excluded => self.lower_excluded_range_end(e),
457+
})
458+
.unwrap_or_else(|| {
459+
self.lower_ty_pat_range_end(
460+
hir::LangItem::RangeMax,
461+
span.shrink_to_hi(),
462+
base_type,
463+
)
464+
}),
445465
),
446466
TyPatKind::Err(guar) => hir::TyPatKind::Err(*guar),
447467
};
448468

449469
hir::TyPat { hir_id: pat_hir_id, kind: node, span: self.lower_span(pattern.span) }
450470
}
471+
472+
/// Lowers the range end of an exclusive range (`2..5`) to an inclusive range 2..=(5 - 1).
473+
/// This way the type system doesn't have to handle the distinction between inclusive/exclusive ranges.
474+
fn lower_excluded_range_end(&mut self, e: &AnonConst) -> &'hir hir::ConstArg<'hir> {
475+
let span = self.lower_span(e.value.span);
476+
let unstable_span = self.mark_span_with_reason(
477+
DesugaringKind::PatTyRange,
478+
span,
479+
Some(Arc::clone(&self.allow_pattern_type)),
480+
);
481+
let anon_const = self.with_new_scopes(span, |this| {
482+
let def_id = this.local_def_id(e.id);
483+
let hir_id = this.lower_node_id(e.id);
484+
let body = this.lower_body(|this| {
485+
// Need to use a custom function as we can't just subtract `1` from a `char`.
486+
let kind = hir::ExprKind::Path(this.make_lang_item_qpath(
487+
hir::LangItem::RangeSub,
488+
unstable_span,
489+
None,
490+
));
491+
let fn_def = this.arena.alloc(hir::Expr { hir_id: this.next_id(), kind, span });
492+
let args = this.arena.alloc([this.lower_expr_mut(&e.value)]);
493+
(
494+
&[],
495+
hir::Expr {
496+
hir_id: this.next_id(),
497+
kind: hir::ExprKind::Call(fn_def, args),
498+
span,
499+
},
500+
)
501+
});
502+
hir::AnonConst { def_id, hir_id, body, span }
503+
});
504+
self.arena.alloc(hir::ConstArg {
505+
hir_id: self.next_id(),
506+
kind: hir::ConstArgKind::Anon(self.arena.alloc(anon_const)),
507+
})
508+
}
509+
510+
/// When a range has no end specified (`1..` or `1..=`) or no start specified (`..5` or `..=5`),
511+
/// we instead use a constant of the MAX/MIN of the type.
512+
/// This way the type system does not have to handle the lack of a start/end.
513+
fn lower_ty_pat_range_end(
514+
&mut self,
515+
lang_item: LangItem,
516+
span: Span,
517+
base_type: Span,
518+
) -> &'hir hir::ConstArg<'hir> {
519+
let parent_def_id = self.current_hir_id_owner.def_id;
520+
let node_id = self.next_node_id();
521+
522+
// Add a definition for the in-band const def.
523+
// We're generating a range end that didn't exist in the AST,
524+
// so the def collector didn't create the def ahead of time. That's why we have to do
525+
// it here.
526+
let def_id = self.create_def(parent_def_id, node_id, kw::Empty, DefKind::AnonConst, span);
527+
let hir_id = self.lower_node_id(node_id);
528+
529+
let unstable_span = self.mark_span_with_reason(
530+
DesugaringKind::PatTyRange,
531+
self.lower_span(span),
532+
Some(Arc::clone(&self.allow_pattern_type)),
533+
);
534+
let span = self.lower_span(base_type);
535+
536+
let path_expr = hir::Expr {
537+
hir_id: self.next_id(),
538+
kind: hir::ExprKind::Path(self.make_lang_item_qpath(lang_item, unstable_span, None)),
539+
span,
540+
};
541+
542+
let ct = self.with_new_scopes(span, |this| {
543+
self.arena.alloc(hir::AnonConst {
544+
def_id,
545+
hir_id,
546+
body: this.lower_body(|_this| (&[], path_expr)),
547+
span,
548+
})
549+
});
550+
let hir_id = self.next_id();
551+
self.arena.alloc(hir::ConstArg { kind: hir::ConstArgKind::Anon(ct), hir_id })
552+
}
451553
}

compiler/rustc_ast_lowering/src/path.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
268268
}
269269
GenericArgs::Parenthesized(data) => match generic_args_mode {
270270
GenericArgsMode::ReturnTypeNotation => {
271-
tracing::info!(?data, ?data.inputs);
272271
let err = match (&data.inputs[..], &data.output) {
273272
([_, ..], FnRetTy::Default(_)) => {
274273
BadReturnTypeNotation::Inputs { span: data.inputs_span }

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,6 +1783,13 @@ impl<'a> State<'a> {
17831783
self.print_mutability(*m, false);
17841784
self.word("self")
17851785
}
1786+
SelfKind::Pinned(lt, m) => {
1787+
self.word("&");
1788+
self.print_opt_lifetime(lt);
1789+
self.word("pin ");
1790+
self.print_mutability(*m, true);
1791+
self.word("self")
1792+
}
17861793
SelfKind::Explicit(typ, m) => {
17871794
self.print_mutability(*m, false);
17881795
self.word("self");

compiler/rustc_attr_parsing/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
7878
// tidy-alphabetical-start
7979
#![allow(internal_features)]
80+
#![cfg_attr(doc, recursion_limit = "256")] // FIXME(nnethercote): will be removed by #124141
8081
#![doc(rust_logo)]
8182
#![feature(let_chains)]
8283
#![feature(rustdoc_internals)]

0 commit comments

Comments
 (0)