Skip to content

Commit e5c5d66

Browse files
authored
Merge branch 'rust-lang:master' into smart-ptr-as-ref
2 parents 873ff91 + fd4dc18 commit e5c5d66

File tree

988 files changed

+9887
-8290
lines changed

Some content is hidden

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

988 files changed

+9887
-8290
lines changed

.mailmap

+7-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ Jacob Greenfield <xales@naveria.com>
276276
Jacob Pratt <jacob@jhpratt.dev> <the.z.cuber@gmail.com>
277277
Jacob Pratt <jacob@jhpratt.dev> <jacopratt@tesla.com>
278278
Jake Goulding <jake.goulding@integer32.com>
279-
Jake Goulding <jake.goulding@integer32.com> <jake.goulding@gmail.com>
279+
Jake Goulding <jake.goulding@integer32.com> <jake.goulding@gmail.com>
280280
Jake Goulding <jake.goulding@integer32.com> <shepmaster@mac.com>
281281
Jake Vossen <jake@vossen.dev>
282282
Jakob Degen <jakob.e.degen@gmail.com> <jakob@degen.com>
@@ -408,10 +408,13 @@ Luqman Aden <me@luqman.ca> <laden@mozilla.com>
408408
Luqman Aden <me@luqman.ca> <rust@luqman.ca>
409409
Lzu Tao <taolzu@gmail.com>
410410
Maik Klein <maikklein@googlemail.com>
411+
Maja Kądziołka <maya@compilercrim.es> <github@compilercrim.es>
412+
Maja Kądziołka <maya@compilercrim.es> <kuba@kadziolka.net>
411413
Malo Jaffré <jaffre.malo@gmail.com>
412414
Manish Goregaokar <manishsmail@gmail.com>
413415
Mara Bos <m-ou.se@m-ou.se>
414416
Marcell Pardavi <marcell.pardavi@gmail.com>
417+
Marco Ieni <11428655+MarcoIeni@users.noreply.github.com>
415418
Marcus Klaas de Vries <mail@marcusklaas.nl>
416419
Margaret Meyerhofer <mmeyerho@andrew.cmu.edu> <mmeyerho@andrew>
417420
Mark Mansi <markm@cs.wisc.edu>
@@ -565,6 +568,9 @@ Robert Habermeier <rphmeier@gmail.com>
565568
Robert Millar <robert.millar@cantab.net>
566569
Roc Yu <rocyu@protonmail.com>
567570
Rohit Joshi <rohitjoshi@users.noreply.github.com> Rohit Joshi <rohit.joshi@capitalone.com>
571+
Ross Smyth <18294397+RossSmyth@users.noreply.github.com>
572+
Ross Smyth <18294397+RossSmyth@users.noreply.github.com> <crs2017@gmail.com>
573+
Ross Smyth <18294397+RossSmyth@users.noreply.github.com> <rsmyth@electrocraft.com>
568574
Roxane Fruytier <roxane.fruytier@hotmail.com>
569575
Rui <xiongmao86dev@sina.com>
570576
Russell Johnston <rpjohnst@gmail.com>

Cargo.lock

+11-4
Original file line numberDiff line numberDiff line change
@@ -3150,6 +3150,12 @@ version = "2.1.1"
31503150
source = "registry+https://github.com/rust-lang/crates.io-index"
31513151
checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d"
31523152

3153+
[[package]]
3154+
name = "rustc-literal-escaper"
3155+
version = "0.0.2"
3156+
source = "registry+https://github.com/rust-lang/crates.io-index"
3157+
checksum = "0041b6238913c41fe704213a4a9329e2f685a156d1781998128b4149c230ad04"
3158+
31533159
[[package]]
31543160
name = "rustc-main"
31553161
version = "0.0.0"
@@ -3242,10 +3248,10 @@ version = "0.0.0"
32423248
dependencies = [
32433249
"bitflags",
32443250
"memchr",
3251+
"rustc-literal-escaper",
32453252
"rustc_ast_ir",
32463253
"rustc_data_structures",
32473254
"rustc_index",
3248-
"rustc_lexer",
32493255
"rustc_macros",
32503256
"rustc_serialize",
32513257
"rustc_span",
@@ -4200,6 +4206,7 @@ name = "rustc_parse"
42004206
version = "0.0.0"
42014207
dependencies = [
42024208
"bitflags",
4209+
"rustc-literal-escaper",
42034210
"rustc_ast",
42044211
"rustc_ast_pretty",
42054212
"rustc_data_structures",
@@ -4222,6 +4229,7 @@ dependencies = [
42224229
name = "rustc_parse_format"
42234230
version = "0.0.0"
42244231
dependencies = [
4232+
"rustc-literal-escaper",
42254233
"rustc_index",
42264234
"rustc_lexer",
42274235
]
@@ -4432,7 +4440,7 @@ dependencies = [
44324440
"rustc_span",
44334441
"rustc_target",
44344442
"scoped-tls",
4435-
"stable_mir",
4443+
"serde",
44364444
"tracing",
44374445
]
44384446

@@ -4990,8 +4998,7 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
49904998
name = "stable_mir"
49914999
version = "0.1.0-preview"
49925000
dependencies = [
4993-
"scoped-tls",
4994-
"serde",
5001+
"rustc_smir",
49955002
]
49965003

49975004
[[package]]

compiler/rustc_ast/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ edition = "2024"
77
# tidy-alphabetical-start
88
bitflags = "2.4.1"
99
memchr = "2.7.4"
10+
rustc-literal-escaper = "0.0.2"
1011
rustc_ast_ir = { path = "../rustc_ast_ir" }
1112
rustc_data_structures = { path = "../rustc_data_structures" }
1213
rustc_index = { path = "../rustc_index" }
13-
rustc_lexer = { path = "../rustc_lexer" }
1414
rustc_macros = { path = "../rustc_macros" }
1515
rustc_serialize = { path = "../rustc_serialize" }
1616
rustc_span = { path = "../rustc_span" }

compiler/rustc_ast/src/ast.rs

+70-1
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,75 @@ impl BinOpKind {
981981

982982
pub type BinOp = Spanned<BinOpKind>;
983983

984+
// Sometimes `BinOpKind` and `AssignOpKind` need the same treatment. The
985+
// operations covered by `AssignOpKind` are a subset of those covered by
986+
// `BinOpKind`, so it makes sense to convert `AssignOpKind` to `BinOpKind`.
987+
impl From<AssignOpKind> for BinOpKind {
988+
fn from(op: AssignOpKind) -> BinOpKind {
989+
match op {
990+
AssignOpKind::AddAssign => BinOpKind::Add,
991+
AssignOpKind::SubAssign => BinOpKind::Sub,
992+
AssignOpKind::MulAssign => BinOpKind::Mul,
993+
AssignOpKind::DivAssign => BinOpKind::Div,
994+
AssignOpKind::RemAssign => BinOpKind::Rem,
995+
AssignOpKind::BitXorAssign => BinOpKind::BitXor,
996+
AssignOpKind::BitAndAssign => BinOpKind::BitAnd,
997+
AssignOpKind::BitOrAssign => BinOpKind::BitOr,
998+
AssignOpKind::ShlAssign => BinOpKind::Shl,
999+
AssignOpKind::ShrAssign => BinOpKind::Shr,
1000+
}
1001+
}
1002+
}
1003+
1004+
#[derive(Clone, Copy, Debug, PartialEq, Encodable, Decodable, HashStable_Generic)]
1005+
pub enum AssignOpKind {
1006+
/// The `+=` operator (addition)
1007+
AddAssign,
1008+
/// The `-=` operator (subtraction)
1009+
SubAssign,
1010+
/// The `*=` operator (multiplication)
1011+
MulAssign,
1012+
/// The `/=` operator (division)
1013+
DivAssign,
1014+
/// The `%=` operator (modulus)
1015+
RemAssign,
1016+
/// The `^=` operator (bitwise xor)
1017+
BitXorAssign,
1018+
/// The `&=` operator (bitwise and)
1019+
BitAndAssign,
1020+
/// The `|=` operator (bitwise or)
1021+
BitOrAssign,
1022+
/// The `<<=` operator (shift left)
1023+
ShlAssign,
1024+
/// The `>>=` operator (shift right)
1025+
ShrAssign,
1026+
}
1027+
1028+
impl AssignOpKind {
1029+
pub fn as_str(&self) -> &'static str {
1030+
use AssignOpKind::*;
1031+
match self {
1032+
AddAssign => "+=",
1033+
SubAssign => "-=",
1034+
MulAssign => "*=",
1035+
DivAssign => "/=",
1036+
RemAssign => "%=",
1037+
BitXorAssign => "^=",
1038+
BitAndAssign => "&=",
1039+
BitOrAssign => "|=",
1040+
ShlAssign => "<<=",
1041+
ShrAssign => ">>=",
1042+
}
1043+
}
1044+
1045+
/// AssignOps are always by value.
1046+
pub fn is_by_value(self) -> bool {
1047+
true
1048+
}
1049+
}
1050+
1051+
pub type AssignOp = Spanned<AssignOpKind>;
1052+
9841053
/// Unary operator.
9851054
///
9861055
/// Note that `&data` is not an operator, it's an `AddrOf` expression.
@@ -1593,7 +1662,7 @@ pub enum ExprKind {
15931662
/// An assignment with an operator.
15941663
///
15951664
/// E.g., `a += 1`.
1596-
AssignOp(BinOp, P<Expr>, P<Expr>),
1665+
AssignOp(AssignOp, P<Expr>, P<Expr>),
15971666
/// Access of a named (e.g., `obj.foo`) or unnamed (e.g., `obj.0`) struct field.
15981667
Field(P<Expr>, Ident),
15991668
/// An indexing operation (e.g., `foo[2]`).

compiler/rustc_ast/src/attr/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,14 @@ impl MetaItemInner {
570570
}
571571
}
572572

573+
/// Returns the bool if `self` is a boolean `MetaItemInner::Literal`.
574+
pub fn boolean_literal(&self) -> Option<bool> {
575+
match self {
576+
MetaItemInner::Lit(MetaItemLit { kind: LitKind::Bool(b), .. }) => Some(*b),
577+
_ => None,
578+
}
579+
}
580+
573581
/// Returns the `MetaItem` if `self` is a `MetaItemInner::MetaItem` or if it's
574582
/// `MetaItemInner::Lit(MetaItemLit { kind: LitKind::Bool(_), .. })`.
575583
pub fn meta_item_or_bool(&self) -> Option<&MetaItemInner> {

compiler/rustc_ast/src/expand/autodiff_attrs.rs

+13
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ pub struct AutoDiffAttrs {
7777
/// e.g. in the [JAX
7878
/// Documentation](https://jax.readthedocs.io/en/latest/_tutorials/advanced-autodiff.html#how-it-s-made-two-foundational-autodiff-functions).
7979
pub mode: DiffMode,
80+
/// A user-provided, batching width. If not given, we will default to 1 (no batching).
81+
/// Calling a differentiated, non-batched function through a loop 100 times is equivalent to:
82+
/// - Calling the function 50 times with a batch size of 2
83+
/// - Calling the function 25 times with a batch size of 4,
84+
/// etc. A batched function takes more (or longer) arguments, and might be able to benefit from
85+
/// cache locality, better re-usal of primal values, and other optimizations.
86+
/// We will (before LLVM's vectorizer runs) just generate most LLVM-IR instructions `width`
87+
/// times, so this massively increases code size. As such, values like 1024 are unlikely to
88+
/// work. We should consider limiting this to u8 or u16, but will leave it at u32 for
89+
/// experiments for now and focus on documenting the implications of a large width.
90+
pub width: u32,
8091
pub ret_activity: DiffActivity,
8192
pub input_activity: Vec<DiffActivity>,
8293
}
@@ -222,13 +233,15 @@ impl AutoDiffAttrs {
222233
pub const fn error() -> Self {
223234
AutoDiffAttrs {
224235
mode: DiffMode::Error,
236+
width: 0,
225237
ret_activity: DiffActivity::None,
226238
input_activity: Vec::new(),
227239
}
228240
}
229241
pub fn source() -> Self {
230242
AutoDiffAttrs {
231243
mode: DiffMode::Source,
244+
width: 0,
232245
ret_activity: DiffActivity::None,
233246
input_activity: Vec::new(),
234247
}

compiler/rustc_ast/src/util/literal.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use std::{ascii, fmt, str};
44

5-
use rustc_lexer::unescape::{
5+
use rustc_literal_escaper::{
66
MixedUnit, Mode, byte_from_char, unescape_byte, unescape_char, unescape_mixed, unescape_unicode,
77
};
88
use rustc_span::{Span, Symbol, kw, sym};

compiler/rustc_ast/src/util/parser.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_span::kw;
22

3-
use crate::ast::{self, BinOpKind, RangeLimits};
3+
use crate::ast::{self, AssignOpKind, BinOpKind, RangeLimits};
44
use crate::token::{self, Token};
55

66
/// Associative operator.
@@ -9,7 +9,7 @@ pub enum AssocOp {
99
/// A binary op.
1010
Binary(BinOpKind),
1111
/// `?=` where ? is one of the assignable BinOps
12-
AssignOp(BinOpKind),
12+
AssignOp(AssignOpKind),
1313
/// `=`
1414
Assign,
1515
/// `as`
@@ -44,16 +44,16 @@ impl AssocOp {
4444
token::Or => Some(Binary(BinOpKind::BitOr)),
4545
token::Shl => Some(Binary(BinOpKind::Shl)),
4646
token::Shr => Some(Binary(BinOpKind::Shr)),
47-
token::PlusEq => Some(AssignOp(BinOpKind::Add)),
48-
token::MinusEq => Some(AssignOp(BinOpKind::Sub)),
49-
token::StarEq => Some(AssignOp(BinOpKind::Mul)),
50-
token::SlashEq => Some(AssignOp(BinOpKind::Div)),
51-
token::PercentEq => Some(AssignOp(BinOpKind::Rem)),
52-
token::CaretEq => Some(AssignOp(BinOpKind::BitXor)),
53-
token::AndEq => Some(AssignOp(BinOpKind::BitAnd)),
54-
token::OrEq => Some(AssignOp(BinOpKind::BitOr)),
55-
token::ShlEq => Some(AssignOp(BinOpKind::Shl)),
56-
token::ShrEq => Some(AssignOp(BinOpKind::Shr)),
47+
token::PlusEq => Some(AssignOp(AssignOpKind::AddAssign)),
48+
token::MinusEq => Some(AssignOp(AssignOpKind::SubAssign)),
49+
token::StarEq => Some(AssignOp(AssignOpKind::MulAssign)),
50+
token::SlashEq => Some(AssignOp(AssignOpKind::DivAssign)),
51+
token::PercentEq => Some(AssignOp(AssignOpKind::RemAssign)),
52+
token::CaretEq => Some(AssignOp(AssignOpKind::BitXorAssign)),
53+
token::AndEq => Some(AssignOp(AssignOpKind::BitAndAssign)),
54+
token::OrEq => Some(AssignOp(AssignOpKind::BitOrAssign)),
55+
token::ShlEq => Some(AssignOp(AssignOpKind::ShlAssign)),
56+
token::ShrEq => Some(AssignOp(AssignOpKind::ShrAssign)),
5757
token::Lt => Some(Binary(BinOpKind::Lt)),
5858
token::Le => Some(Binary(BinOpKind::Le)),
5959
token::Ge => Some(Binary(BinOpKind::Ge)),

compiler/rustc_ast_lowering/src/expr.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
7474
// Merge attributes into the inner expression.
7575
if !e.attrs.is_empty() {
7676
let old_attrs = self.attrs.get(&ex.hir_id.local_id).copied().unwrap_or(&[]);
77-
self.attrs.insert(
78-
ex.hir_id.local_id,
79-
&*self.arena.alloc_from_iter(
80-
self.lower_attrs_vec(&e.attrs, e.span)
81-
.into_iter()
82-
.chain(old_attrs.iter().cloned()),
83-
),
77+
let attrs = &*self.arena.alloc_from_iter(
78+
self.lower_attrs_vec(&e.attrs, e.span)
79+
.into_iter()
80+
.chain(old_attrs.iter().cloned()),
8481
);
82+
if attrs.is_empty() {
83+
return ex;
84+
}
85+
86+
self.attrs.insert(ex.hir_id.local_id, attrs);
8587
}
8688
return ex;
8789
}
@@ -274,7 +276,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
274276
}
275277
ExprKind::Assign(el, er, span) => self.lower_expr_assign(el, er, *span, e.span),
276278
ExprKind::AssignOp(op, el, er) => hir::ExprKind::AssignOp(
277-
self.lower_binop(*op),
279+
self.lower_assign_op(*op),
278280
self.lower_expr(el),
279281
self.lower_expr(er),
280282
),
@@ -443,6 +445,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
443445
Spanned { node: b.node, span: self.lower_span(b.span) }
444446
}
445447

448+
fn lower_assign_op(&mut self, a: AssignOp) -> AssignOp {
449+
Spanned { node: a.node, span: self.lower_span(a.span) }
450+
}
451+
446452
fn lower_legacy_const_generics(
447453
&mut self,
448454
mut f: Expr,

compiler/rustc_ast_lowering/src/item.rs

-3
Original file line numberDiff line numberDiff line change
@@ -676,12 +676,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
676676
let ty =
677677
self.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::StaticTy));
678678
let safety = self.lower_safety(*safety, hir::Safety::Unsafe);
679-
680-
// njn: where for this?
681679
if define_opaque.is_some() {
682680
self.dcx().span_err(i.span, "foreign statics cannot define opaque types");
683681
}
684-
685682
(ident, hir::ForeignItemKind::Static(ty, *mutability, safety))
686683
}
687684
ForeignItemKind::TyAlias(box TyAlias { ident, .. }) => {

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) {

0 commit comments

Comments
 (0)