Skip to content

Commit 0ebb78f

Browse files
committed
Auto merge of rust-lang#3367 - rust-lang:rustup-2024-03-09, r=RalfJung
Automatic Rustup
2 parents b0fad9a + 862f918 commit 0ebb78f

File tree

313 files changed

+5044
-2397
lines changed

Some content is hidden

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

313 files changed

+5044
-2397
lines changed

compiler/rustc_ast/src/ast.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -2302,6 +2302,9 @@ pub enum InlineAsmOperand {
23022302
Sym {
23032303
sym: InlineAsmSym,
23042304
},
2305+
Label {
2306+
block: P<Block>,
2307+
},
23052308
}
23062309

23072310
impl InlineAsmOperand {
@@ -2311,7 +2314,7 @@ impl InlineAsmOperand {
23112314
| Self::Out { reg, .. }
23122315
| Self::InOut { reg, .. }
23132316
| Self::SplitInOut { reg, .. } => Some(reg),
2314-
Self::Const { .. } | Self::Sym { .. } => None,
2317+
Self::Const { .. } | Self::Sym { .. } | Self::Label { .. } => None,
23152318
}
23162319
}
23172320
}

compiler/rustc_ast/src/mut_visit.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,7 @@ pub fn noop_visit_inline_asm<T: MutVisitor>(asm: &mut InlineAsm, vis: &mut T) {
13311331
}
13321332
InlineAsmOperand::Const { anon_const } => vis.visit_anon_const(anon_const),
13331333
InlineAsmOperand::Sym { sym } => vis.visit_inline_asm_sym(sym),
1334+
InlineAsmOperand::Label { block } => vis.visit_block(block),
13341335
}
13351336
}
13361337
}

compiler/rustc_ast/src/visit.rs

+1
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,7 @@ pub fn walk_inline_asm<'a, V: Visitor<'a>>(visitor: &mut V, asm: &'a InlineAsm)
823823
try_visit!(visitor.visit_anon_const(anon_const))
824824
}
825825
InlineAsmOperand::Sym { sym } => try_visit!(visitor.visit_inline_asm_sym(sym)),
826+
InlineAsmOperand::Label { block } => try_visit!(visitor.visit_block(block)),
826827
}
827828
}
828829
V::Result::output()

compiler/rustc_ast_lowering/messages.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ ast_lowering_invalid_abi_suggestion = did you mean
8888
ast_lowering_invalid_asm_template_modifier_const =
8989
asm template modifiers are not allowed for `const` arguments
9090
91+
ast_lowering_invalid_asm_template_modifier_label =
92+
asm template modifiers are not allowed for `label` arguments
93+
9194
ast_lowering_invalid_asm_template_modifier_reg_class =
9295
invalid asm template modifier for this register class
9396

compiler/rustc_ast_lowering/src/asm.rs

+23-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ use crate::{ImplTraitContext, ImplTraitPosition, ParamMode, ResolverAstLoweringE
33
use super::errors::{
44
AbiSpecifiedMultipleTimes, AttSyntaxOnlyX86, ClobberAbiNotSupported,
55
InlineAsmUnsupportedTarget, InvalidAbiClobberAbi, InvalidAsmTemplateModifierConst,
6-
InvalidAsmTemplateModifierRegClass, InvalidAsmTemplateModifierRegClassSub,
7-
InvalidAsmTemplateModifierSym, InvalidRegister, InvalidRegisterClass, RegisterClassOnlyClobber,
8-
RegisterConflict,
6+
InvalidAsmTemplateModifierLabel, InvalidAsmTemplateModifierRegClass,
7+
InvalidAsmTemplateModifierRegClassSub, InvalidAsmTemplateModifierSym, InvalidRegister,
8+
InvalidRegisterClass, RegisterClassOnlyClobber, RegisterConflict,
99
};
1010
use super::LoweringContext;
1111

@@ -237,6 +237,18 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
237237
}
238238
}
239239
}
240+
InlineAsmOperand::Label { block } => {
241+
if !self.tcx.features().asm_goto {
242+
feature_err(
243+
sess,
244+
sym::asm_goto,
245+
*op_sp,
246+
"label operands for inline assembly are unstable",
247+
)
248+
.emit();
249+
}
250+
hir::InlineAsmOperand::Label { block: self.lower_block(block, false) }
251+
}
240252
};
241253
(op, self.lower_span(*op_sp))
242254
})
@@ -296,6 +308,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
296308
op_span: op_sp,
297309
});
298310
}
311+
hir::InlineAsmOperand::Label { .. } => {
312+
self.dcx().emit_err(InvalidAsmTemplateModifierLabel {
313+
placeholder_span,
314+
op_span: op_sp,
315+
});
316+
}
299317
}
300318
}
301319
}
@@ -335,7 +353,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
335353

336354
hir::InlineAsmOperand::Const { .. }
337355
| hir::InlineAsmOperand::SymFn { .. }
338-
| hir::InlineAsmOperand::SymStatic { .. } => {
356+
| hir::InlineAsmOperand::SymStatic { .. }
357+
| hir::InlineAsmOperand::Label { .. } => {
339358
unreachable!("{op:?} is not a register operand");
340359
}
341360
};

compiler/rustc_ast_lowering/src/errors.rs

+10
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,16 @@ pub struct InvalidAsmTemplateModifierSym {
261261
pub op_span: Span,
262262
}
263263

264+
#[derive(Diagnostic, Clone, Copy)]
265+
#[diag(ast_lowering_invalid_asm_template_modifier_label)]
266+
pub struct InvalidAsmTemplateModifierLabel {
267+
#[primary_span]
268+
#[label(ast_lowering_template_modifier)]
269+
pub placeholder_span: Span,
270+
#[label(ast_lowering_argument)]
271+
pub op_span: Span,
272+
}
273+
264274
#[derive(Diagnostic, Clone, Copy)]
265275
#[diag(ast_lowering_register_class_only_clobber)]
266276
pub struct RegisterClassOnlyClobber {

compiler/rustc_ast_lowering/src/format.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use super::LoweringContext;
2+
use core::ops::ControlFlow;
23
use rustc_ast as ast;
34
use rustc_ast::visit::Visitor;
45
use rustc_ast::*;
@@ -594,30 +595,32 @@ fn expand_format_args<'hir>(
594595
}
595596

596597
fn may_contain_yield_point(e: &ast::Expr) -> bool {
597-
struct MayContainYieldPoint(bool);
598+
struct MayContainYieldPoint;
598599

599600
impl Visitor<'_> for MayContainYieldPoint {
600-
fn visit_expr(&mut self, e: &ast::Expr) {
601+
type Result = ControlFlow<()>;
602+
603+
fn visit_expr(&mut self, e: &ast::Expr) -> ControlFlow<()> {
601604
if let ast::ExprKind::Await(_, _) | ast::ExprKind::Yield(_) = e.kind {
602-
self.0 = true;
605+
ControlFlow::Break(())
603606
} else {
604607
visit::walk_expr(self, e);
608+
ControlFlow::Continue(())
605609
}
606610
}
607611

608-
fn visit_mac_call(&mut self, _: &ast::MacCall) {
612+
fn visit_mac_call(&mut self, _: &ast::MacCall) -> ControlFlow<()> {
609613
// Macros should be expanded at this point.
610614
unreachable!("unexpanded macro in ast lowering");
611615
}
612616

613-
fn visit_item(&mut self, _: &ast::Item) {
617+
fn visit_item(&mut self, _: &ast::Item) -> ControlFlow<()> {
614618
// Do not recurse into nested items.
619+
ControlFlow::Continue(())
615620
}
616621
}
617622

618-
let mut visitor = MayContainYieldPoint(false);
619-
visitor.visit_expr(e);
620-
visitor.0
623+
MayContainYieldPoint.visit_expr(e).is_break()
621624
}
622625

623626
fn for_all_argument_indexes(template: &mut [FormatArgsPiece], mut f: impl FnMut(&mut usize)) {

compiler/rustc_ast_lowering/src/item.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
275275
}
276276
Some(ty) => this.lower_ty(
277277
ty,
278-
ImplTraitContext::TypeAliasesOpaqueTy { in_assoc_ty: false },
278+
ImplTraitContext::OpaqueTy {
279+
origin: hir::OpaqueTyOrigin::TyAlias {
280+
parent: this.local_def_id(id),
281+
in_assoc_ty: false,
282+
},
283+
fn_kind: None,
284+
},
279285
),
280286
},
281287
);
@@ -936,7 +942,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
936942
Some(ty) => {
937943
let ty = this.lower_ty(
938944
ty,
939-
ImplTraitContext::TypeAliasesOpaqueTy { in_assoc_ty: true },
945+
ImplTraitContext::OpaqueTy {
946+
origin: hir::OpaqueTyOrigin::TyAlias {
947+
parent: this.local_def_id(i.id),
948+
in_assoc_ty: true,
949+
},
950+
fn_kind: None,
951+
},
940952
);
941953
hir::ImplItemKind::Type(ty)
942954
}

compiler/rustc_ast_lowering/src/lib.rs

+25-33
Original file line numberDiff line numberDiff line change
@@ -265,13 +265,12 @@ enum ImplTraitContext {
265265
/// Example: `fn foo() -> impl Debug`, where `impl Debug` is conceptually
266266
/// equivalent to a new opaque type like `type T = impl Debug; fn foo() -> T`.
267267
///
268-
ReturnPositionOpaqueTy {
269-
/// Origin: Either OpaqueTyOrigin::FnReturn or OpaqueTyOrigin::AsyncFn,
268+
OpaqueTy {
270269
origin: hir::OpaqueTyOrigin,
271-
fn_kind: FnDeclKind,
270+
/// Only used to change the lifetime capture rules, since
271+
/// RPITIT captures all in scope, RPIT does not.
272+
fn_kind: Option<FnDeclKind>,
272273
},
273-
/// Impl trait in type aliases.
274-
TypeAliasesOpaqueTy { in_assoc_ty: bool },
275274
/// `impl Trait` is unstably accepted in this position.
276275
FeatureGated(ImplTraitPosition, Symbol),
277276
/// `impl Trait` is not accepted in this position.
@@ -1075,9 +1074,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10751074
// Disallow ATB in dyn types
10761075
if self.is_in_dyn_type {
10771076
let suggestion = match itctx {
1078-
ImplTraitContext::ReturnPositionOpaqueTy { .. }
1079-
| ImplTraitContext::TypeAliasesOpaqueTy { .. }
1080-
| ImplTraitContext::Universal => {
1077+
ImplTraitContext::OpaqueTy { .. } | ImplTraitContext::Universal => {
10811078
let bound_end_span = constraint
10821079
.gen_args
10831080
.as_ref()
@@ -1417,24 +1414,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
14171414
TyKind::ImplTrait(def_node_id, bounds) => {
14181415
let span = t.span;
14191416
match itctx {
1420-
ImplTraitContext::ReturnPositionOpaqueTy { origin, fn_kind } => self
1421-
.lower_opaque_impl_trait(
1422-
span,
1423-
origin,
1424-
*def_node_id,
1425-
bounds,
1426-
Some(fn_kind),
1427-
itctx,
1428-
),
1429-
ImplTraitContext::TypeAliasesOpaqueTy { in_assoc_ty } => self
1430-
.lower_opaque_impl_trait(
1431-
span,
1432-
hir::OpaqueTyOrigin::TyAlias { in_assoc_ty },
1433-
*def_node_id,
1434-
bounds,
1435-
None,
1436-
itctx,
1437-
),
1417+
ImplTraitContext::OpaqueTy { origin, fn_kind } => self.lower_opaque_impl_trait(
1418+
span,
1419+
origin,
1420+
*def_node_id,
1421+
bounds,
1422+
fn_kind,
1423+
itctx,
1424+
),
14381425
ImplTraitContext::Universal => {
14391426
let span = t.span;
14401427

@@ -1553,9 +1540,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
15531540

15541541
let captured_lifetimes_to_duplicate = match origin {
15551542
hir::OpaqueTyOrigin::TyAlias { .. } => {
1556-
// in a TAIT like `type Foo<'a> = impl Foo<'a>`, we don't duplicate any
1557-
// lifetimes, since we don't have the issue that any are late-bound.
1558-
Vec::new()
1543+
// type alias impl trait and associated type position impl trait were
1544+
// decided to capture all in-scope lifetimes, which we collect for
1545+
// all opaques during resolution.
1546+
self.resolver
1547+
.take_extra_lifetime_params(opaque_ty_node_id)
1548+
.into_iter()
1549+
.map(|(ident, id, _)| Lifetime { id, ident })
1550+
.collect()
15591551
}
15601552
hir::OpaqueTyOrigin::FnReturn(..) => {
15611553
if matches!(
@@ -1823,9 +1815,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
18231815
FnDeclKind::Fn
18241816
| FnDeclKind::Inherent
18251817
| FnDeclKind::Trait
1826-
| FnDeclKind::Impl => ImplTraitContext::ReturnPositionOpaqueTy {
1818+
| FnDeclKind::Impl => ImplTraitContext::OpaqueTy {
18271819
origin: hir::OpaqueTyOrigin::FnReturn(self.local_def_id(fn_node_id)),
1828-
fn_kind: kind,
1820+
fn_kind: Some(kind),
18291821
},
18301822
FnDeclKind::ExternFn => {
18311823
ImplTraitContext::Disallowed(ImplTraitPosition::ExternFnReturn)
@@ -1919,9 +1911,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19191911
output,
19201912
coro,
19211913
opaque_ty_span,
1922-
ImplTraitContext::ReturnPositionOpaqueTy {
1914+
ImplTraitContext::OpaqueTy {
19231915
origin: hir::OpaqueTyOrigin::FnReturn(fn_def_id),
1924-
fn_kind,
1916+
fn_kind: Some(fn_kind),
19251917
},
19261918
);
19271919
arena_vec![this; bound]

compiler/rustc_ast_lowering/src/path.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
423423
// fn f(_: impl Fn() -> impl Debug) -> impl Fn() -> impl Debug
424424
// // disallowed --^^^^^^^^^^ allowed --^^^^^^^^^^
425425
// ```
426-
FnRetTy::Ty(ty) if matches!(itctx, ImplTraitContext::ReturnPositionOpaqueTy { .. }) => {
426+
FnRetTy::Ty(ty) if matches!(itctx, ImplTraitContext::OpaqueTy { .. }) => {
427427
if self.tcx.features().impl_trait_in_fn_trait_return {
428428
self.lower_ty(ty, itctx)
429429
} else {

compiler/rustc_ast_pretty/src/pprust/state.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1452,6 +1452,10 @@ impl<'a> State<'a> {
14521452
s.print_path(&sym.path, true, 0);
14531453
}
14541454
}
1455+
InlineAsmOperand::Label { block } => {
1456+
s.head("label");
1457+
s.print_block(block);
1458+
}
14551459
}
14561460
}
14571461
AsmArg::ClobberAbi(abi) => {

0 commit comments

Comments
 (0)