Skip to content

Commit 4c5ce1f

Browse files
committed
Auto merge of rust-lang#119578 - matthiaskrgr:rollup-42yizmx, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - rust-lang#117636 (add test for rust-lang#117626) - rust-lang#118704 (Promote `riscv32{im|imafc}` targets to tier 2) - rust-lang#119184 (Switch from using `//~ERROR` annotations with `--error-format` to `error-pattern`) - rust-lang#119325 (custom mir: make it clear what the return block is) - rust-lang#119391 (Use Result::flatten in catch_with_exit_code) - rust-lang#119431 (Support reg_addr register class in s390x inline assembly) - rust-lang#119475 (Remove libtest's dylib) - rust-lang#119532 (Make offset_of field parsing use metavariable which handles any spacing) - rust-lang#119553 (stop feed vis when cant access for trait item) - rust-lang#119574 (Miri subtree update) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 090d5ea + 6579378 commit 4c5ce1f

File tree

119 files changed

+1971
-1330
lines changed

Some content is hidden

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

119 files changed

+1971
-1330
lines changed

compiler/rustc_codegen_gcc/src/asm.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,7 @@ fn reg_to_gcc(reg: InlineAsmRegOrRegClass) -> ConstraintOrRegister {
634634
}
635635
InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => "r",
636636
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::reg) => "r",
637+
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::reg_addr) => "a",
637638
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::freg) => "f",
638639
InlineAsmRegClass::Err => unreachable!(),
639640
}
@@ -704,7 +705,9 @@ fn dummy_output_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, reg: InlineAsmRegCl
704705
InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => {
705706
bug!("LLVM backend does not support SPIR-V")
706707
},
707-
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::reg) => cx.type_i32(),
708+
InlineAsmRegClass::S390x(
709+
S390xInlineAsmRegClass::reg | S390xInlineAsmRegClass::reg_addr
710+
) => cx.type_i32(),
708711
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::freg) => cx.type_f64(),
709712
InlineAsmRegClass::Err => unreachable!(),
710713
}

compiler/rustc_codegen_llvm/src/asm.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,7 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'_>>) ->
690690
InlineAsmRegClass::Avr(AvrInlineAsmRegClass::reg_iw) => "w",
691691
InlineAsmRegClass::Avr(AvrInlineAsmRegClass::reg_ptr) => "e",
692692
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::reg) => "r",
693+
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::reg_addr) => "a",
693694
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::freg) => "f",
694695
InlineAsmRegClass::Msp430(Msp430InlineAsmRegClass::reg) => "r",
695696
InlineAsmRegClass::M68k(M68kInlineAsmRegClass::reg) => "r",
@@ -867,7 +868,9 @@ fn dummy_output_type<'ll>(cx: &CodegenCx<'ll, '_>, reg: InlineAsmRegClass) -> &'
867868
InlineAsmRegClass::Avr(AvrInlineAsmRegClass::reg_pair) => cx.type_i16(),
868869
InlineAsmRegClass::Avr(AvrInlineAsmRegClass::reg_iw) => cx.type_i16(),
869870
InlineAsmRegClass::Avr(AvrInlineAsmRegClass::reg_ptr) => cx.type_i16(),
870-
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::reg) => cx.type_i32(),
871+
InlineAsmRegClass::S390x(
872+
S390xInlineAsmRegClass::reg | S390xInlineAsmRegClass::reg_addr,
873+
) => cx.type_i32(),
871874
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::freg) => cx.type_f64(),
872875
InlineAsmRegClass::Msp430(Msp430InlineAsmRegClass::reg) => cx.type_i16(),
873876
InlineAsmRegClass::M68k(M68kInlineAsmRegClass::reg) => cx.type_i32(),

compiler/rustc_driver_impl/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#![feature(lazy_cell)]
1313
#![feature(let_chains)]
1414
#![feature(panic_update_hook)]
15+
#![feature(result_flattening)]
1516
#![recursion_limit = "256"]
1617
#![deny(rustc::untranslatable_diagnostic)]
1718
#![deny(rustc::diagnostic_outside_of_impl)]
@@ -1249,8 +1250,7 @@ pub fn catch_fatal_errors<F: FnOnce() -> R, R>(f: F) -> Result<R, ErrorGuarantee
12491250
/// Variant of `catch_fatal_errors` for the `interface::Result` return type
12501251
/// that also computes the exit code.
12511252
pub fn catch_with_exit_code(f: impl FnOnce() -> interface::Result<()>) -> i32 {
1252-
let result = catch_fatal_errors(f).and_then(|result| result);
1253-
match result {
1253+
match catch_fatal_errors(f).flatten() {
12541254
Ok(()) => EXIT_SUCCESS,
12551255
Err(_) => EXIT_FAILURE,
12561256
}

compiler/rustc_mir_build/src/build/custom/parse/instruction.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
6161
@call(mir_drop, args) => {
6262
Ok(TerminatorKind::Drop {
6363
place: self.parse_place(args[0])?,
64-
target: self.parse_block(args[1])?,
64+
target: self.parse_return_to(args[1])?,
6565
unwind: self.parse_unwind_action(args[2])?,
6666
replace: false,
6767
})
@@ -104,6 +104,14 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
104104
)
105105
}
106106

107+
fn parse_return_to(&self, expr_id: ExprId) -> PResult<BasicBlock> {
108+
parse_by_kind!(self, expr_id, _, "return block",
109+
@call(mir_return_to, args) => {
110+
self.parse_block(args[0])
111+
},
112+
)
113+
}
114+
107115
fn parse_match(&self, arms: &[ArmId], span: Span) -> PResult<SwitchTargets> {
108116
let Some((otherwise, rest)) = arms.split_last() else {
109117
return Err(ParseError {
@@ -146,7 +154,7 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
146154
ExprKind::Assign { lhs, rhs } => (*lhs, *rhs),
147155
);
148156
let destination = self.parse_place(destination)?;
149-
let target = self.parse_block(args[1])?;
157+
let target = self.parse_return_to(args[1])?;
150158
let unwind = self.parse_unwind_action(args[2])?;
151159

152160
parse_by_kind!(self, call, _, "function call",

compiler/rustc_parse/messages.ftl

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ parse_ambiguous_range_pattern = the range pattern here has ambiguous interpretat
1010
parse_array_brackets_instead_of_braces = this is a block expression, not an array
1111
.suggestion = to make an array, use square brackets instead of curly braces
1212
13+
parse_array_index_offset_of = array indexing not supported in offset_of
14+
1315
parse_assignment_else_not_allowed = <assignment> ... else {"{"} ... {"}"} is not allowed
1416
1517
parse_assoc_lifetime = associated lifetimes are not supported
@@ -405,6 +407,8 @@ parse_invalid_logical_operator = `{$incorrect}` is not a logical operator
405407
406408
parse_invalid_meta_item = expected unsuffixed literal or identifier, found `{$token}`
407409
410+
parse_invalid_offset_of = offset_of expects dot-separated field and variant names
411+
408412
parse_invalid_unicode_escape = invalid unicode character escape
409413
.label = invalid escape
410414
.help = unicode escape must {$surrogate ->

compiler/rustc_parse/src/errors.rs

+8
Original file line numberDiff line numberDiff line change
@@ -2887,3 +2887,11 @@ pub(crate) struct TransposeDynOrImplSugg<'a> {
28872887
pub insertion_span: Span,
28882888
pub kw: &'a str,
28892889
}
2890+
2891+
#[derive(Diagnostic)]
2892+
#[diag(parse_array_index_offset_of)]
2893+
pub(crate) struct ArrayIndexInOffsetOf(#[primary_span] pub Span);
2894+
2895+
#[derive(Diagnostic)]
2896+
#[diag(parse_invalid_offset_of)]
2897+
pub(crate) struct InvalidOffsetOf(#[primary_span] pub Span);

compiler/rustc_parse/src/parser/expr.rs

+121-43
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ impl<'a> Parser<'a> {
10231023
// we should break everything including floats into more basic proc-macro style
10241024
// tokens in the lexer (probably preferable).
10251025
// See also `TokenKind::break_two_token_op` which does similar splitting of `>>` into `>`.
1026-
fn break_up_float(&mut self, float: Symbol) -> DestructuredFloat {
1026+
fn break_up_float(&self, float: Symbol, span: Span) -> DestructuredFloat {
10271027
#[derive(Debug)]
10281028
enum FloatComponent {
10291029
IdentLike(String),
@@ -1053,7 +1053,6 @@ impl<'a> Parser<'a> {
10531053
// With proc macros the span can refer to anything, the source may be too short,
10541054
// or too long, or non-ASCII. It only makes sense to break our span into components
10551055
// if its underlying text is identical to our float literal.
1056-
let span = self.token.span;
10571056
let can_take_span_apart =
10581057
|| self.span_to_snippet(span).as_deref() == Ok(float_str).as_deref();
10591058

@@ -1115,7 +1114,7 @@ impl<'a> Parser<'a> {
11151114
float: Symbol,
11161115
suffix: Option<Symbol>,
11171116
) -> P<Expr> {
1118-
match self.break_up_float(float) {
1117+
match self.break_up_float(float, self.token.span) {
11191118
// 1e2
11201119
DestructuredFloat::Single(sym, _sp) => {
11211120
self.parse_expr_tuple_field_access(lo, base, sym, suffix, None)
@@ -1143,40 +1142,105 @@ impl<'a> Parser<'a> {
11431142
}
11441143
}
11451144

1146-
fn parse_field_name_maybe_tuple(&mut self) -> PResult<'a, ThinVec<Ident>> {
1147-
let token::Literal(token::Lit { kind: token::Float, symbol, suffix }) = self.token.kind
1148-
else {
1149-
return Ok(thin_vec![self.parse_field_name()?]);
1150-
};
1151-
Ok(match self.break_up_float(symbol) {
1152-
// 1e2
1153-
DestructuredFloat::Single(sym, sp) => {
1154-
self.bump();
1155-
thin_vec![Ident::new(sym, sp)]
1156-
}
1157-
// 1.
1158-
DestructuredFloat::TrailingDot(sym, sym_span, dot_span) => {
1159-
assert!(suffix.is_none());
1160-
// Analogous to `Self::break_and_eat`
1161-
self.break_last_token = true;
1162-
// This might work, in cases like `1. 2`, and might not,
1163-
// in cases like `offset_of!(Ty, 1.)`. It depends on what comes
1164-
// after the float-like token, and therefore we have to make
1165-
// the other parts of the parser think that there is a dot literal.
1166-
self.token = Token::new(token::Ident(sym, false), sym_span);
1167-
self.bump_with((Token::new(token::Dot, dot_span), self.token_spacing));
1168-
thin_vec![Ident::new(sym, sym_span)]
1169-
}
1170-
// 1.2 | 1.2e3
1171-
DestructuredFloat::MiddleDot(symbol1, ident1_span, _dot_span, symbol2, ident2_span) => {
1172-
self.bump();
1173-
thin_vec![Ident::new(symbol1, ident1_span), Ident::new(symbol2, ident2_span)]
1145+
/// Parse the field access used in offset_of, matched by `$(e:expr)+`.
1146+
/// Currently returns a list of idents. However, it should be possible in
1147+
/// future to also do array indices, which might be arbitrary expressions.
1148+
fn parse_floating_field_access(&mut self) -> PResult<'a, P<[Ident]>> {
1149+
let mut fields = Vec::new();
1150+
let mut trailing_dot = None;
1151+
1152+
loop {
1153+
// This is expected to use a metavariable $(args:expr)+, but the builtin syntax
1154+
// could be called directly. Calling `parse_expr` allows this function to only
1155+
// consider `Expr`s.
1156+
let expr = self.parse_expr()?;
1157+
let mut current = &expr;
1158+
let start_idx = fields.len();
1159+
loop {
1160+
match current.kind {
1161+
ExprKind::Field(ref left, right) => {
1162+
// Field access is read right-to-left.
1163+
fields.insert(start_idx, right);
1164+
trailing_dot = None;
1165+
current = left;
1166+
}
1167+
// Parse this both to give helpful error messages and to
1168+
// verify it can be done with this parser setup.
1169+
ExprKind::Index(ref left, ref _right, span) => {
1170+
self.dcx().emit_err(errors::ArrayIndexInOffsetOf(span));
1171+
current = left;
1172+
}
1173+
ExprKind::Lit(token::Lit {
1174+
kind: token::Float | token::Integer,
1175+
symbol,
1176+
suffix,
1177+
}) => {
1178+
if let Some(suffix) = suffix {
1179+
self.expect_no_tuple_index_suffix(current.span, suffix);
1180+
}
1181+
match self.break_up_float(symbol, current.span) {
1182+
// 1e2
1183+
DestructuredFloat::Single(sym, sp) => {
1184+
trailing_dot = None;
1185+
fields.insert(start_idx, Ident::new(sym, sp));
1186+
}
1187+
// 1.
1188+
DestructuredFloat::TrailingDot(sym, sym_span, dot_span) => {
1189+
assert!(suffix.is_none());
1190+
trailing_dot = Some(dot_span);
1191+
fields.insert(start_idx, Ident::new(sym, sym_span));
1192+
}
1193+
// 1.2 | 1.2e3
1194+
DestructuredFloat::MiddleDot(
1195+
symbol1,
1196+
span1,
1197+
_dot_span,
1198+
symbol2,
1199+
span2,
1200+
) => {
1201+
trailing_dot = None;
1202+
fields.insert(start_idx, Ident::new(symbol2, span2));
1203+
fields.insert(start_idx, Ident::new(symbol1, span1));
1204+
}
1205+
DestructuredFloat::Error => {
1206+
trailing_dot = None;
1207+
fields.insert(start_idx, Ident::new(symbol, self.prev_token.span));
1208+
}
1209+
}
1210+
break;
1211+
}
1212+
ExprKind::Path(None, Path { ref segments, .. }) => {
1213+
match &segments[..] {
1214+
[PathSegment { ident, args: None, .. }] => {
1215+
trailing_dot = None;
1216+
fields.insert(start_idx, *ident)
1217+
}
1218+
_ => {
1219+
self.dcx().emit_err(errors::InvalidOffsetOf(current.span));
1220+
break;
1221+
}
1222+
}
1223+
break;
1224+
}
1225+
_ => {
1226+
self.dcx().emit_err(errors::InvalidOffsetOf(current.span));
1227+
break;
1228+
}
1229+
}
11741230
}
1175-
DestructuredFloat::Error => {
1176-
self.bump();
1177-
thin_vec![Ident::new(symbol, self.prev_token.span)]
1231+
1232+
if matches!(self.token.kind, token::CloseDelim(..) | token::Comma) {
1233+
break;
1234+
} else if trailing_dot.is_none() {
1235+
// This loop should only repeat if there is a trailing dot.
1236+
self.dcx().emit_err(errors::InvalidOffsetOf(self.token.span));
1237+
break;
11781238
}
1179-
})
1239+
}
1240+
if let Some(dot) = trailing_dot {
1241+
self.dcx().emit_err(errors::InvalidOffsetOf(dot));
1242+
}
1243+
Ok(fields.into_iter().collect())
11801244
}
11811245

11821246
fn parse_expr_tuple_field_access(
@@ -1907,15 +1971,29 @@ impl<'a> Parser<'a> {
19071971
let container = self.parse_ty()?;
19081972
self.expect(&TokenKind::Comma)?;
19091973

1910-
let seq_sep = SeqSep { sep: Some(token::Dot), trailing_sep_allowed: false };
1911-
let (fields, _trailing, _recovered) = self.parse_seq_to_before_end(
1912-
&TokenKind::CloseDelim(Delimiter::Parenthesis),
1913-
seq_sep,
1914-
Parser::parse_field_name_maybe_tuple,
1915-
)?;
1916-
let fields = fields.into_iter().flatten().collect::<Vec<_>>();
1974+
let fields = self.parse_floating_field_access()?;
1975+
let trailing_comma = self.eat_noexpect(&TokenKind::Comma);
1976+
1977+
if let Err(mut e) =
1978+
self.expect_one_of(&[], &[TokenKind::CloseDelim(Delimiter::Parenthesis)])
1979+
{
1980+
if trailing_comma {
1981+
e.note("unexpected third argument to offset_of");
1982+
} else {
1983+
e.note("offset_of expects dot-separated field and variant names");
1984+
}
1985+
e.emit();
1986+
}
1987+
1988+
// Eat tokens until the macro call ends.
1989+
if self.may_recover() {
1990+
while !matches!(self.token.kind, token::CloseDelim(..) | token::Eof) {
1991+
self.bump();
1992+
}
1993+
}
1994+
19171995
let span = lo.to(self.token.span);
1918-
Ok(self.mk_expr(span, ExprKind::OffsetOf(container, fields.into())))
1996+
Ok(self.mk_expr(span, ExprKind::OffsetOf(container, fields)))
19191997
}
19201998

19211999
/// Returns a string literal if the next token is a string literal.

compiler/rustc_resolve/src/late.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -3076,7 +3076,16 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
30763076
}
30773077

30783078
let feed_visibility = |this: &mut Self, def_id| {
3079-
let vis = this.r.tcx.visibility(def_id).expect_local();
3079+
let vis = this.r.tcx.visibility(def_id);
3080+
let vis = if vis.is_visible_locally() {
3081+
vis.expect_local()
3082+
} else {
3083+
this.r.dcx().span_delayed_bug(
3084+
span,
3085+
"error should be emitted when an unexpected trait item is used",
3086+
);
3087+
rustc_middle::ty::Visibility::Public
3088+
};
30803089
this.r.feed_visibility(this.r.local_def_id(id), vis);
30813090
};
30823091

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,7 @@ symbols! {
10411041
mir_offset,
10421042
mir_retag,
10431043
mir_return,
1044+
mir_return_to,
10441045
mir_set_discriminant,
10451046
mir_static,
10461047
mir_static_mut,

compiler/rustc_target/src/asm/s390x.rs

+15-14
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::fmt;
66
def_reg_class! {
77
S390x S390xInlineAsmRegClass {
88
reg,
9+
reg_addr,
910
freg,
1011
}
1112
}
@@ -36,7 +37,7 @@ impl S390xInlineAsmRegClass {
3637
arch: InlineAsmArch,
3738
) -> &'static [(InlineAsmType, Option<Symbol>)] {
3839
match (self, arch) {
39-
(Self::reg, _) => types! { _: I8, I16, I32, I64; },
40+
(Self::reg | Self::reg_addr, _) => types! { _: I8, I16, I32, I64; },
4041
(Self::freg, _) => types! { _: F32, F64; },
4142
}
4243
}
@@ -45,19 +46,19 @@ impl S390xInlineAsmRegClass {
4546
def_regs! {
4647
S390x S390xInlineAsmReg S390xInlineAsmRegClass {
4748
r0: reg = ["r0"],
48-
r1: reg = ["r1"],
49-
r2: reg = ["r2"],
50-
r3: reg = ["r3"],
51-
r4: reg = ["r4"],
52-
r5: reg = ["r5"],
53-
r6: reg = ["r6"],
54-
r7: reg = ["r7"],
55-
r8: reg = ["r8"],
56-
r9: reg = ["r9"],
57-
r10: reg = ["r10"],
58-
r12: reg = ["r12"],
59-
r13: reg = ["r13"],
60-
r14: reg = ["r14"],
49+
r1: reg, reg_addr = ["r1"],
50+
r2: reg, reg_addr = ["r2"],
51+
r3: reg, reg_addr = ["r3"],
52+
r4: reg, reg_addr = ["r4"],
53+
r5: reg, reg_addr = ["r5"],
54+
r6: reg, reg_addr = ["r6"],
55+
r7: reg, reg_addr = ["r7"],
56+
r8: reg, reg_addr = ["r8"],
57+
r9: reg, reg_addr = ["r9"],
58+
r10: reg, reg_addr = ["r10"],
59+
r12: reg, reg_addr = ["r12"],
60+
r13: reg, reg_addr = ["r13"],
61+
r14: reg, reg_addr = ["r14"],
6162
f0: freg = ["f0"],
6263
f1: freg = ["f1"],
6364
f2: freg = ["f2"],

0 commit comments

Comments
 (0)