Skip to content

Commit 97bf23d

Browse files
committed
Auto merge of #112877 - Nilstrieb:rollup-5g5hegl, r=Nilstrieb
Rollup of 6 pull requests Successful merges: - #112632 (Implement PartialOrd for `Vec`s over different allocators) - #112759 (Make closure_saved_names_of_captured_variables a query. ) - #112772 (Add a fully fledged `Clause` type, rename old `Clause` to `ClauseKind`) - #112790 (Syntactically accept `become` expressions (explicit tail calls experiment)) - #112830 (More codegen cleanups) - #112844 (Add retag in MIR transform: `Adt` for `Unique` may contain a reference) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 67da586 + 82e6a16 commit 97bf23d

File tree

137 files changed

+950
-775
lines changed

Some content is hidden

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

137 files changed

+950
-775
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,7 @@ impl Expr {
12951295
ExprKind::Yield(..) => ExprPrecedence::Yield,
12961296
ExprKind::Yeet(..) => ExprPrecedence::Yeet,
12971297
ExprKind::FormatArgs(..) => ExprPrecedence::FormatArgs,
1298+
ExprKind::Become(..) => ExprPrecedence::Become,
12981299
ExprKind::Err => ExprPrecedence::Err,
12991300
}
13001301
}
@@ -1515,6 +1516,11 @@ pub enum ExprKind {
15151516
/// with an optional value to be returned.
15161517
Yeet(Option<P<Expr>>),
15171518

1519+
/// A tail call return, with the value to be returned.
1520+
///
1521+
/// While `.0` must be a function call, we check this later, after parsing.
1522+
Become(P<Expr>),
1523+
15181524
/// Bytes included via `include_bytes!`
15191525
/// Added for optimization purposes to avoid the need to escape
15201526
/// large binary blobs - should always behave like [`ExprKind::Lit`]

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,7 @@ pub fn noop_visit_expr<T: MutVisitor>(
14571457
ExprKind::Yeet(expr) => {
14581458
visit_opt(expr, |expr| vis.visit_expr(expr));
14591459
}
1460+
ExprKind::Become(expr) => vis.visit_expr(expr),
14601461
ExprKind::InlineAsm(asm) => vis.visit_inline_asm(asm),
14611462
ExprKind::FormatArgs(fmt) => vis.visit_format_args(fmt),
14621463
ExprKind::OffsetOf(container, fields) => {

compiler/rustc_ast/src/util/parser.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ pub enum ExprPrecedence {
245245
Ret,
246246
Yield,
247247
Yeet,
248+
Become,
248249

249250
Range,
250251

@@ -298,7 +299,8 @@ impl ExprPrecedence {
298299
| ExprPrecedence::Continue
299300
| ExprPrecedence::Ret
300301
| ExprPrecedence::Yield
301-
| ExprPrecedence::Yeet => PREC_JUMP,
302+
| ExprPrecedence::Yeet
303+
| ExprPrecedence::Become => PREC_JUMP,
302304

303305
// `Range` claims to have higher precedence than `Assign`, but `x .. x = x` fails to
304306
// parse, instead of parsing as `(x .. x) = x`. Giving `Range` a lower precedence

compiler/rustc_ast/src/visit.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
908908
ExprKind::Yeet(optional_expression) => {
909909
walk_list!(visitor, visit_expr, optional_expression);
910910
}
911+
ExprKind::Become(expr) => visitor.visit_expr(expr),
911912
ExprKind::MacCall(mac) => visitor.visit_mac_call(mac),
912913
ExprKind::Paren(subexpression) => visitor.visit_expr(subexpression),
913914
ExprKind::InlineAsm(asm) => visitor.visit_inline_asm(asm),

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
275275
hir::ExprKind::Ret(e)
276276
}
277277
ExprKind::Yeet(sub_expr) => self.lower_expr_yeet(e.span, sub_expr.as_deref()),
278+
ExprKind::Become(sub_expr) => {
279+
let sub_expr = self.lower_expr(sub_expr);
280+
281+
// FIXME(explicit_tail_calls): Use `hir::ExprKind::Become` once we implemented it
282+
hir::ExprKind::Ret(Some(sub_expr))
283+
}
278284
ExprKind::InlineAsm(asm) => {
279285
hir::ExprKind::InlineAsm(self.lower_inline_asm(e.span, asm))
280286
}

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
555555
gate_all!(dyn_star, "`dyn*` trait objects are experimental");
556556
gate_all!(const_closures, "const closures are experimental");
557557
gate_all!(builtin_syntax, "`builtin #` syntax is unstable");
558+
gate_all!(explicit_tail_calls, "`become` expression is experimental");
558559

559560
if !visitor.features.negative_bounds {
560561
for &span in spans.get(&sym::negative_bounds).iter().copied().flatten() {

compiler/rustc_ast_pretty/src/pprust/state/expr.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,11 @@ impl<'a> State<'a> {
537537
self.print_expr_maybe_paren(expr, parser::PREC_JUMP);
538538
}
539539
}
540+
ast::ExprKind::Become(result) => {
541+
self.word("become");
542+
self.word(" ");
543+
self.print_expr_maybe_paren(result, parser::PREC_JUMP);
544+
}
540545
ast::ExprKind::InlineAsm(a) => {
541546
// FIXME: This should have its own syntax, distinct from a macro invocation.
542547
self.word("asm!");

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
679679

680680
// Find out if the predicates show that the type is a Fn or FnMut
681681
let find_fn_kind_from_did = |(pred, _): (ty::Predicate<'tcx>, _)| {
682-
if let ty::PredicateKind::Clause(ty::Clause::Trait(pred)) = pred.kind().skip_binder()
682+
if let ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred)) = pred.kind().skip_binder()
683683
&& pred.self_ty() == ty
684684
{
685685
if Some(pred.def_id()) == tcx.lang_items().fn_trait() {
@@ -776,7 +776,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
776776
let predicates: Result<Vec<_>, _> = errors
777777
.into_iter()
778778
.map(|err| match err.obligation.predicate.kind().skip_binder() {
779-
PredicateKind::Clause(ty::Clause::Trait(predicate)) => {
779+
PredicateKind::Clause(ty::ClauseKind::Trait(predicate)) => {
780780
match predicate.self_ty().kind() {
781781
ty::Param(param_ty) => Ok((
782782
generics.type_param(param_ty, tcx),

compiler/rustc_borrowck/src/diagnostics/region_name.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -939,8 +939,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
939939
{
940940
predicates.iter().any(|pred| {
941941
match pred.kind().skip_binder() {
942-
ty::PredicateKind::Clause(ty::Clause::Trait(data)) if data.self_ty() == ty => {}
943-
ty::PredicateKind::Clause(ty::Clause::Projection(data)) if data.projection_ty.self_ty() == ty => {}
942+
ty::PredicateKind::Clause(ty::ClauseKind::Trait(data)) if data.self_ty() == ty => {}
943+
ty::PredicateKind::Clause(ty::ClauseKind::Projection(data)) if data.projection_ty.self_ty() == ty => {}
944944
_ => return false,
945945
}
946946
tcx.any_free_region_meets(pred, |r| {

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,9 @@ fn check_opaque_type_well_formed<'tcx>(
330330
// Require the hidden type to be well-formed with only the generics of the opaque type.
331331
// Defining use functions may have more bounds than the opaque type, which is ok, as long as the
332332
// hidden type is well formed even without those bounds.
333-
let predicate =
334-
ty::Binder::dummy(ty::PredicateKind::Clause(ty::Clause::WellFormed(definition_ty.into())));
333+
let predicate = ty::Binder::dummy(ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(
334+
definition_ty.into(),
335+
)));
335336
ocx.register_obligation(Obligation::misc(tcx, definition_span, def_id, param_env, predicate));
336337

337338
// Check that all obligations are satisfied by the implementation's

0 commit comments

Comments
 (0)