Skip to content

Commit 1b2c53a

Browse files
committed
Auto merge of rust-lang#122182 - matthiaskrgr:rollup-gzimi4c, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#118623 (Improve std::fs::read_to_string example) - rust-lang#119365 (Add asm goto support to `asm!`) - rust-lang#120608 (Docs for std::ptr::slice_from_raw_parts) - rust-lang#121832 (Add new Tier-3 target: `loongarch64-unknown-linux-musl`) - rust-lang#121938 (Fix quadratic behavior of repeated vectored writes) - rust-lang#122099 (Add `#[inline]` to `BTreeMap::new` constructor) - rust-lang#122103 (Make TAITs and ATPITs capture late-bound lifetimes in scope) - rust-lang#122143 (PassWrapper: update for llvm/llvm-project@a3319371970b) Failed merges: - rust-lang#122076 (Tweak the way we protect in-place function arguments in interpreters) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 14fbc3c + 0d235ef commit 1b2c53a

File tree

107 files changed

+1126
-422
lines changed

Some content is hidden

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

107 files changed

+1126
-422
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 4 additions & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 23 additions & 4 deletions
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

Lines changed: 10 additions & 0 deletions
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/item.rs

Lines changed: 14 additions & 2 deletions
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

Lines changed: 25 additions & 33 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 0 deletions
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)