Skip to content

Commit 7c46fb2

Browse files
committedFeb 3, 2023
Auto merge of rust-lang#107625 - matthiaskrgr:rollup-xr9oldy, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#106575 (Suggest `move` in nested closure when appropriate) - rust-lang#106805 (Suggest `{var:?}` when finding `{?:var}` in inline format strings) - rust-lang#107500 (Add tests to assert current behavior of large future sizes) - rust-lang#107598 (Fix benchmarks in library/core with black_box) - rust-lang#107602 (Parse and recover from type ascription in patterns) - rust-lang#107608 (Use triple rather than arch for fuchsia test-runner) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 5d32458 + b6e8ebf commit 7c46fb2

File tree

21 files changed

+521
-122
lines changed

21 files changed

+521
-122
lines changed
 

‎compiler/rustc_borrowck/src/diagnostics/region_errors.rs‎

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -583,10 +583,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
583583
let err = FnMutError {
584584
span: *span,
585585
ty_err: match output_ty.kind() {
586-
ty::Closure(_, _) => FnMutReturnTypeErr::ReturnClosure { span: *span },
587586
ty::Generator(def, ..) if self.infcx.tcx.generator_is_async(*def) => {
588587
FnMutReturnTypeErr::ReturnAsyncBlock { span: *span }
589588
}
589+
_ if output_ty.contains_closure() => {
590+
FnMutReturnTypeErr::ReturnClosure { span: *span }
591+
}
590592
_ => FnMutReturnTypeErr::ReturnRef { span: *span },
591593
},
592594
};
@@ -997,7 +999,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
997999
fn suggest_move_on_borrowing_closure(&self, diag: &mut Diagnostic) {
9981000
let map = self.infcx.tcx.hir();
9991001
let body_id = map.body_owned_by(self.mir_def_id());
1000-
let expr = &map.body(body_id).value;
1002+
let expr = &map.body(body_id).value.peel_blocks();
10011003
let mut closure_span = None::<rustc_span::Span>;
10021004
match expr.kind {
10031005
hir::ExprKind::MethodCall(.., args, _) => {
@@ -1012,20 +1014,14 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
10121014
}
10131015
}
10141016
}
1015-
hir::ExprKind::Block(blk, _) => {
1016-
if let Some(expr) = blk.expr {
1017-
// only when the block is a closure
1018-
if let hir::ExprKind::Closure(hir::Closure {
1019-
capture_clause: hir::CaptureBy::Ref,
1020-
body,
1021-
..
1022-
}) = expr.kind
1023-
{
1024-
let body = map.body(*body);
1025-
if !matches!(body.generator_kind, Some(hir::GeneratorKind::Async(..))) {
1026-
closure_span = Some(expr.span.shrink_to_lo());
1027-
}
1028-
}
1017+
hir::ExprKind::Closure(hir::Closure {
1018+
capture_clause: hir::CaptureBy::Ref,
1019+
body,
1020+
..
1021+
}) => {
1022+
let body = map.body(*body);
1023+
if !matches!(body.generator_kind, Some(hir::GeneratorKind::Async(..))) {
1024+
closure_span = Some(expr.span.shrink_to_lo());
10291025
}
10301026
}
10311027
_ => {}

‎compiler/rustc_middle/src/ty/sty.rs‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,6 +2043,28 @@ impl<'tcx> Ty<'tcx> {
20432043
cf.is_break()
20442044
}
20452045

2046+
/// Checks whether a type recursively contains any closure
2047+
///
2048+
/// Example: `Option<[closure@file.rs:4:20]>` returns true
2049+
pub fn contains_closure(self) -> bool {
2050+
struct ContainsClosureVisitor;
2051+
2052+
impl<'tcx> TypeVisitor<'tcx> for ContainsClosureVisitor {
2053+
type BreakTy = ();
2054+
2055+
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
2056+
if let ty::Closure(_, _) = t.kind() {
2057+
ControlFlow::Break(())
2058+
} else {
2059+
t.super_visit_with(self)
2060+
}
2061+
}
2062+
}
2063+
2064+
let cf = self.visit_with(&mut ContainsClosureVisitor);
2065+
cf.is_break()
2066+
}
2067+
20462068
/// Returns the type and mutability of `*ty`.
20472069
///
20482070
/// The parameter `explicit` indicates if this is an *explicit* dereference.

‎compiler/rustc_parse/src/parser/diagnostics.rs‎

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2405,26 +2405,42 @@ impl<'a> Parser<'a> {
24052405
if !matches!(first_pat.kind, PatKind::Ident(_, _, None) | PatKind::Path(..))
24062406
|| !self.look_ahead(1, |token| token.is_ident() && !token.is_reserved_ident())
24072407
{
2408+
let mut snapshot_type = self.create_snapshot_for_diagnostic();
2409+
snapshot_type.bump(); // `:`
2410+
match snapshot_type.parse_ty() {
2411+
Err(inner_err) => {
2412+
inner_err.cancel();
2413+
}
2414+
Ok(ty) => {
2415+
let Err(mut err) = self.expected_one_of_not_found(&[], &[]) else {
2416+
return first_pat;
2417+
};
2418+
err.span_label(ty.span, "specifying the type of a pattern isn't supported");
2419+
self.restore_snapshot(snapshot_type);
2420+
let span = first_pat.span.to(ty.span);
2421+
first_pat = self.mk_pat(span, PatKind::Wild);
2422+
err.emit();
2423+
}
2424+
}
24082425
return first_pat;
24092426
}
24102427
// The pattern looks like it might be a path with a `::` -> `:` typo:
24112428
// `match foo { bar:baz => {} }`
2412-
let span = self.token.span;
2429+
let colon_span = self.token.span;
24132430
// We only emit "unexpected `:`" error here if we can successfully parse the
24142431
// whole pattern correctly in that case.
2415-
let snapshot = self.create_snapshot_for_diagnostic();
2432+
let mut snapshot_pat = self.create_snapshot_for_diagnostic();
2433+
let mut snapshot_type = self.create_snapshot_for_diagnostic();
24162434

24172435
// Create error for "unexpected `:`".
24182436
match self.expected_one_of_not_found(&[], &[]) {
24192437
Err(mut err) => {
2420-
self.bump(); // Skip the `:`.
2421-
match self.parse_pat_no_top_alt(expected) {
2438+
// Skip the `:`.
2439+
snapshot_pat.bump();
2440+
snapshot_type.bump();
2441+
match snapshot_pat.parse_pat_no_top_alt(expected) {
24222442
Err(inner_err) => {
2423-
// Carry on as if we had not done anything, callers will emit a
2424-
// reasonable error.
24252443
inner_err.cancel();
2426-
err.cancel();
2427-
self.restore_snapshot(snapshot);
24282444
}
24292445
Ok(mut pat) => {
24302446
// We've parsed the rest of the pattern.
@@ -2488,22 +2504,33 @@ impl<'a> Parser<'a> {
24882504
_ => {}
24892505
}
24902506
if show_sugg {
2491-
err.span_suggestion(
2492-
span,
2507+
err.span_suggestion_verbose(
2508+
colon_span.until(self.look_ahead(1, |t| t.span)),
24932509
"maybe write a path separator here",
24942510
"::",
24952511
Applicability::MaybeIncorrect,
24962512
);
24972513
} else {
24982514
first_pat = self.mk_pat(new_span, PatKind::Wild);
24992515
}
2500-
err.emit();
2516+
self.restore_snapshot(snapshot_pat);
25012517
}
25022518
}
2519+
match snapshot_type.parse_ty() {
2520+
Err(inner_err) => {
2521+
inner_err.cancel();
2522+
}
2523+
Ok(ty) => {
2524+
err.span_label(ty.span, "specifying the type of a pattern isn't supported");
2525+
self.restore_snapshot(snapshot_type);
2526+
let new_span = first_pat.span.to(ty.span);
2527+
first_pat = self.mk_pat(new_span, PatKind::Wild);
2528+
}
2529+
}
2530+
err.emit();
25032531
}
25042532
_ => {
25052533
// Carry on as if we had not done anything. This should be unreachable.
2506-
self.restore_snapshot(snapshot);
25072534
}
25082535
};
25092536
first_pat

‎compiler/rustc_parse_format/src/lib.rs‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,13 @@ impl<'a> Iterator for Parser<'a> {
273273
);
274274
}
275275
} else {
276-
self.suggest_positional_arg_instead_of_captured_arg(arg);
276+
if let Some(&(_, maybe)) = self.cur.peek() {
277+
if maybe == '?' {
278+
self.suggest_format();
279+
} else {
280+
self.suggest_positional_arg_instead_of_captured_arg(arg);
281+
}
282+
}
277283
}
278284
Some(NextArgument(Box::new(arg)))
279285
}
@@ -832,6 +838,27 @@ impl<'a> Parser<'a> {
832838
if found { Some(cur) } else { None }
833839
}
834840

841+
fn suggest_format(&mut self) {
842+
if let (Some(pos), Some(_)) = (self.consume_pos('?'), self.consume_pos(':')) {
843+
let word = self.word();
844+
let _end = self.current_pos();
845+
let pos = self.to_span_index(pos);
846+
self.errors.insert(
847+
0,
848+
ParseError {
849+
description: "expected format parameter to occur after `:`".to_owned(),
850+
note: Some(
851+
format!("`?` comes after `:`, try `{}:{}` instead", word, "?").to_owned(),
852+
),
853+
label: "expected `?` to occur after `:`".to_owned(),
854+
span: pos.to(pos),
855+
secondary_label: None,
856+
should_be_replaced_with_positional_argument: false,
857+
},
858+
);
859+
}
860+
}
861+
835862
fn suggest_positional_arg_instead_of_captured_arg(&mut self, arg: Argument<'a>) {
836863
if let Some(end) = self.consume_pos('.') {
837864
let byte_pos = self.to_span_index(end);
Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
use test::Bencher;
1+
use test::{black_box, Bencher};
22

33
const CHARS: [char; 9] = ['0', 'x', '2', '5', 'A', 'f', '7', '8', '9'];
44
const RADIX: [u32; 5] = [2, 8, 10, 16, 32];
55

66
#[bench]
77
fn bench_to_digit_radix_2(b: &mut Bencher) {
8-
b.iter(|| CHARS.iter().cycle().take(10_000).map(|c| c.to_digit(2)).min())
8+
b.iter(|| CHARS.iter().cycle().take(10_000).map(|c| black_box(c).to_digit(2)).min())
99
}
1010

1111
#[bench]
1212
fn bench_to_digit_radix_10(b: &mut Bencher) {
13-
b.iter(|| CHARS.iter().cycle().take(10_000).map(|c| c.to_digit(10)).min())
13+
b.iter(|| CHARS.iter().cycle().take(10_000).map(|c| black_box(c).to_digit(10)).min())
1414
}
1515

1616
#[bench]
1717
fn bench_to_digit_radix_16(b: &mut Bencher) {
18-
b.iter(|| CHARS.iter().cycle().take(10_000).map(|c| c.to_digit(16)).min())
18+
b.iter(|| CHARS.iter().cycle().take(10_000).map(|c| black_box(c).to_digit(16)).min())
1919
}
2020

2121
#[bench]
2222
fn bench_to_digit_radix_36(b: &mut Bencher) {
23-
b.iter(|| CHARS.iter().cycle().take(10_000).map(|c| c.to_digit(36)).min())
23+
b.iter(|| CHARS.iter().cycle().take(10_000).map(|c| black_box(c).to_digit(36)).min())
2424
}
2525

2626
#[bench]
@@ -31,47 +31,59 @@ fn bench_to_digit_radix_var(b: &mut Bencher) {
3131
.cycle()
3232
.zip(RADIX.iter().cycle())
3333
.take(10_000)
34-
.map(|(c, radix)| c.to_digit(*radix))
34+
.map(|(c, radix)| black_box(c).to_digit(*radix))
3535
.min()
3636
})
3737
}
3838

3939
#[bench]
4040
fn bench_to_ascii_uppercase(b: &mut Bencher) {
41-
b.iter(|| CHARS.iter().cycle().take(10_000).map(|c| c.to_ascii_uppercase()).min())
41+
b.iter(|| CHARS.iter().cycle().take(10_000).map(|c| black_box(c).to_ascii_uppercase()).min())
4242
}
4343

4444
#[bench]
4545
fn bench_to_ascii_lowercase(b: &mut Bencher) {
46-
b.iter(|| CHARS.iter().cycle().take(10_000).map(|c| c.to_ascii_lowercase()).min())
46+
b.iter(|| CHARS.iter().cycle().take(10_000).map(|c| black_box(c).to_ascii_lowercase()).min())
4747
}
4848

4949
#[bench]
5050
fn bench_ascii_mix_to_uppercase(b: &mut Bencher) {
51-
b.iter(|| (0..=255).cycle().take(10_000).map(|b| char::from(b).to_uppercase()).count())
51+
b.iter(|| {
52+
(0..=255).cycle().take(10_000).map(|b| black_box(char::from(b)).to_uppercase()).count()
53+
})
5254
}
5355

5456
#[bench]
5557
fn bench_ascii_mix_to_lowercase(b: &mut Bencher) {
56-
b.iter(|| (0..=255).cycle().take(10_000).map(|b| char::from(b).to_lowercase()).count())
58+
b.iter(|| {
59+
(0..=255).cycle().take(10_000).map(|b| black_box(char::from(b)).to_lowercase()).count()
60+
})
5761
}
5862

5963
#[bench]
6064
fn bench_ascii_char_to_uppercase(b: &mut Bencher) {
61-
b.iter(|| (0..=127).cycle().take(10_000).map(|b| char::from(b).to_uppercase()).count())
65+
b.iter(|| {
66+
(0..=127).cycle().take(10_000).map(|b| black_box(char::from(b)).to_uppercase()).count()
67+
})
6268
}
6369

6470
#[bench]
6571
fn bench_ascii_char_to_lowercase(b: &mut Bencher) {
66-
b.iter(|| (0..=127).cycle().take(10_000).map(|b| char::from(b).to_lowercase()).count())
72+
b.iter(|| {
73+
(0..=127).cycle().take(10_000).map(|b| black_box(char::from(b)).to_lowercase()).count()
74+
})
6775
}
6876

6977
#[bench]
7078
fn bench_non_ascii_char_to_uppercase(b: &mut Bencher) {
71-
b.iter(|| (128..=255).cycle().take(10_000).map(|b| char::from(b).to_uppercase()).count())
79+
b.iter(|| {
80+
(128..=255).cycle().take(10_000).map(|b| black_box(char::from(b)).to_uppercase()).count()
81+
})
7282
}
7383

7484
#[bench]
7585
fn bench_non_ascii_char_to_lowercase(b: &mut Bencher) {
76-
b.iter(|| (128..=255).cycle().take(10_000).map(|b| char::from(b).to_lowercase()).count())
86+
b.iter(|| {
87+
(128..=255).cycle().take(10_000).map(|b| black_box(char::from(b)).to_lowercase()).count()
88+
})
7789
}
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
use super::super::*;
22
use core::num::flt2dec::strategy::dragon::*;
33
use std::mem::MaybeUninit;
4-
use test::Bencher;
4+
use test::{black_box, Bencher};
55

66
#[bench]
77
fn bench_small_shortest(b: &mut Bencher) {
88
let decoded = decode_finite(3.141592f64);
99
let mut buf = [MaybeUninit::new(0); MAX_SIG_DIGITS];
1010
b.iter(|| {
11-
format_shortest(&decoded, &mut buf);
11+
format_shortest(black_box(&decoded), &mut buf);
1212
});
1313
}
1414

@@ -17,7 +17,7 @@ fn bench_big_shortest(b: &mut Bencher) {
1717
let decoded = decode_finite(f64::MAX);
1818
let mut buf = [MaybeUninit::new(0); MAX_SIG_DIGITS];
1919
b.iter(|| {
20-
format_shortest(&decoded, &mut buf);
20+
format_shortest(black_box(&decoded), &mut buf);
2121
});
2222
}
2323

@@ -26,7 +26,7 @@ fn bench_small_exact_3(b: &mut Bencher) {
2626
let decoded = decode_finite(3.141592f64);
2727
let mut buf = [MaybeUninit::new(0); 3];
2828
b.iter(|| {
29-
format_exact(&decoded, &mut buf, i16::MIN);
29+
format_exact(black_box(&decoded), &mut buf, i16::MIN);
3030
});
3131
}
3232

@@ -35,7 +35,7 @@ fn bench_big_exact_3(b: &mut Bencher) {
3535
let decoded = decode_finite(f64::MAX);
3636
let mut buf = [MaybeUninit::new(0); 3];
3737
b.iter(|| {
38-
format_exact(&decoded, &mut buf, i16::MIN);
38+
format_exact(black_box(&decoded), &mut buf, i16::MIN);
3939
});
4040
}
4141

@@ -44,7 +44,7 @@ fn bench_small_exact_12(b: &mut Bencher) {
4444
let decoded = decode_finite(3.141592f64);
4545
let mut buf = [MaybeUninit::new(0); 12];
4646
b.iter(|| {
47-
format_exact(&decoded, &mut buf, i16::MIN);
47+
format_exact(black_box(&decoded), &mut buf, i16::MIN);
4848
});
4949
}
5050

@@ -53,7 +53,7 @@ fn bench_big_exact_12(b: &mut Bencher) {
5353
let decoded = decode_finite(f64::MAX);
5454
let mut buf = [MaybeUninit::new(0); 12];
5555
b.iter(|| {
56-
format_exact(&decoded, &mut buf, i16::MIN);
56+
format_exact(black_box(&decoded), &mut buf, i16::MIN);
5757
});
5858
}
5959

@@ -62,7 +62,7 @@ fn bench_small_exact_inf(b: &mut Bencher) {
6262
let decoded = decode_finite(3.141592f64);
6363
let mut buf = [MaybeUninit::new(0); 1024];
6464
b.iter(|| {
65-
format_exact(&decoded, &mut buf, i16::MIN);
65+
format_exact(black_box(&decoded), &mut buf, i16::MIN);
6666
});
6767
}
6868

@@ -71,6 +71,6 @@ fn bench_big_exact_inf(b: &mut Bencher) {
7171
let decoded = decode_finite(f64::MAX);
7272
let mut buf = [MaybeUninit::new(0); 1024];
7373
b.iter(|| {
74-
format_exact(&decoded, &mut buf, i16::MIN);
74+
format_exact(black_box(&decoded), &mut buf, i16::MIN);
7575
});
7676
}

‎library/core/benches/num/flt2dec/strategy/grisu.rs‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::super::*;
22
use core::num::flt2dec::strategy::grisu::*;
33
use std::mem::MaybeUninit;
4-
use test::Bencher;
4+
use test::{black_box, Bencher};
55

66
pub fn decode_finite<T: DecodableFloat>(v: T) -> Decoded {
77
match decode(v).1 {
@@ -15,7 +15,7 @@ fn bench_small_shortest(b: &mut Bencher) {
1515
let decoded = decode_finite(3.141592f64);
1616
let mut buf = [MaybeUninit::new(0); MAX_SIG_DIGITS];
1717
b.iter(|| {
18-
format_shortest(&decoded, &mut buf);
18+
format_shortest(black_box(&decoded), &mut buf);
1919
});
2020
}
2121

@@ -24,7 +24,7 @@ fn bench_big_shortest(b: &mut Bencher) {
2424
let decoded = decode_finite(f64::MAX);
2525
let mut buf = [MaybeUninit::new(0); MAX_SIG_DIGITS];
2626
b.iter(|| {
27-
format_shortest(&decoded, &mut buf);
27+
format_shortest(black_box(&decoded), &mut buf);
2828
});
2929
}
3030

@@ -33,7 +33,7 @@ fn bench_small_exact_3(b: &mut Bencher) {
3333
let decoded = decode_finite(3.141592f64);
3434
let mut buf = [MaybeUninit::new(0); 3];
3535
b.iter(|| {
36-
format_exact(&decoded, &mut buf, i16::MIN);
36+
format_exact(black_box(&decoded), &mut buf, i16::MIN);
3737
});
3838
}
3939

@@ -42,7 +42,7 @@ fn bench_big_exact_3(b: &mut Bencher) {
4242
let decoded = decode_finite(f64::MAX);
4343
let mut buf = [MaybeUninit::new(0); 3];
4444
b.iter(|| {
45-
format_exact(&decoded, &mut buf, i16::MIN);
45+
format_exact(black_box(&decoded), &mut buf, i16::MIN);
4646
});
4747
}
4848

@@ -51,7 +51,7 @@ fn bench_small_exact_12(b: &mut Bencher) {
5151
let decoded = decode_finite(3.141592f64);
5252
let mut buf = [MaybeUninit::new(0); 12];
5353
b.iter(|| {
54-
format_exact(&decoded, &mut buf, i16::MIN);
54+
format_exact(black_box(&decoded), &mut buf, i16::MIN);
5555
});
5656
}
5757

@@ -60,7 +60,7 @@ fn bench_big_exact_12(b: &mut Bencher) {
6060
let decoded = decode_finite(f64::MAX);
6161
let mut buf = [MaybeUninit::new(0); 12];
6262
b.iter(|| {
63-
format_exact(&decoded, &mut buf, i16::MIN);
63+
format_exact(black_box(&decoded), &mut buf, i16::MIN);
6464
});
6565
}
6666

@@ -69,7 +69,7 @@ fn bench_small_exact_inf(b: &mut Bencher) {
6969
let decoded = decode_finite(3.141592f64);
7070
let mut buf = [MaybeUninit::new(0); 1024];
7171
b.iter(|| {
72-
format_exact(&decoded, &mut buf, i16::MIN);
72+
format_exact(black_box(&decoded), &mut buf, i16::MIN);
7373
});
7474
}
7575

@@ -78,6 +78,6 @@ fn bench_big_exact_inf(b: &mut Bencher) {
7878
let decoded = decode_finite(f64::MAX);
7979
let mut buf = [MaybeUninit::new(0); 1024];
8080
b.iter(|| {
81-
format_exact(&decoded, &mut buf, i16::MIN);
81+
format_exact(black_box(&decoded), &mut buf, i16::MIN);
8282
});
8383
}

‎src/ci/docker/scripts/fuchsia-test-runner.py‎

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@
1919
import signal
2020
import subprocess
2121
import sys
22-
from typing import ClassVar, List
22+
from typing import ClassVar, List, Optional
2323

2424

2525
@dataclass
2626
class TestEnvironment:
2727
rust_dir: str
2828
sdk_dir: str
29-
target_arch: str
30-
package_server_pid: int = None
31-
emu_addr: str = None
32-
libstd_name: str = None
33-
libtest_name: str = None
29+
target: str
30+
package_server_pid: Optional[int] = None
31+
emu_addr: Optional[str] = None
32+
libstd_name: Optional[str] = None
33+
libtest_name: Optional[str] = None
3434
verbose: bool = False
3535

3636
@staticmethod
@@ -40,6 +40,15 @@ def tmp_dir():
4040
return os.path.abspath(tmp_dir)
4141
return os.path.join(os.path.dirname(__file__), "tmp~")
4242

43+
@staticmethod
44+
def triple_to_arch(triple):
45+
if "x86_64" in triple:
46+
return "x64"
47+
elif "aarch64" in triple:
48+
return "arm64"
49+
else:
50+
raise Exception(f"Unrecognized target triple {triple}")
51+
4352
@classmethod
4453
def env_file_path(cls):
4554
return os.path.join(cls.tmp_dir(), "test_env.json")
@@ -49,7 +58,7 @@ def from_args(cls, args):
4958
return cls(
5059
os.path.abspath(args.rust),
5160
os.path.abspath(args.sdk),
52-
args.target_arch,
61+
args.target,
5362
verbose=args.verbose,
5463
)
5564

@@ -60,21 +69,14 @@ def read_from_file(cls):
6069
return cls(
6170
test_env["rust_dir"],
6271
test_env["sdk_dir"],
63-
test_env["target_arch"],
72+
test_env["target"],
6473
libstd_name=test_env["libstd_name"],
6574
libtest_name=test_env["libtest_name"],
6675
emu_addr=test_env["emu_addr"],
6776
package_server_pid=test_env["package_server_pid"],
6877
verbose=test_env["verbose"],
6978
)
7079

71-
def image_name(self):
72-
if self.target_arch == "x64":
73-
return "qemu-x64"
74-
if self.target_arch == "arm64":
75-
return "qemu-arm64"
76-
raise Exception(f"Unrecognized target architecture {self.target_arch}")
77-
7880
def write_to_file(self):
7981
with open(self.env_file_path(), "w", encoding="utf-8") as f:
8082
f.write(json.dumps(self.__dict__))
@@ -108,13 +110,6 @@ def output_dir(self):
108110
def repo_dir(self):
109111
return os.path.join(self.tmp_dir(), self.TEST_REPO_NAME)
110112

111-
def rustlib_dir(self):
112-
if self.target_arch == "x64":
113-
return "x86_64-unknown-fuchsia"
114-
if self.target_arch == "arm64":
115-
return "aarch64-unknown-fuchsia"
116-
raise Exception(f"Unrecognized target architecture {self.target_arch}")
117-
118113
def libs_dir(self):
119114
return os.path.join(
120115
self.rust_dir,
@@ -125,7 +120,7 @@ def rustlibs_dir(self):
125120
return os.path.join(
126121
self.libs_dir(),
127122
"rustlib",
128-
self.rustlib_dir(),
123+
self.target,
129124
"lib",
130125
)
131126

@@ -384,7 +379,7 @@ def start(self):
384379
"--emulator-log",
385380
self.emulator_log_path(),
386381
"--image-name",
387-
self.image_name(),
382+
"qemu-" + self.triple_to_arch(self.target),
388383
],
389384
stdout=self.subprocess_output(),
390385
stderr=self.subprocess_output(),
@@ -642,11 +637,11 @@ def log(msg):
642637
package_dir=package_dir,
643638
package_name=package_name,
644639
rust_dir=self.rust_dir,
645-
rustlib_dir=self.rustlib_dir(),
640+
rustlib_dir=self.target,
646641
sdk_dir=self.sdk_dir,
647642
libstd_name=self.libstd_name,
648643
libtest_name=self.libtest_name,
649-
target_arch=self.target_arch,
644+
target_arch=self.triple_to_arch(self.target),
650645
)
651646
)
652647
for shared_lib in shared_libs:
@@ -969,8 +964,8 @@ def print_help(args):
969964
action="store_true",
970965
)
971966
start_parser.add_argument(
972-
"--target-arch",
973-
help="the architecture of the image to test",
967+
"--target",
968+
help="the target platform to test",
974969
required=True,
975970
)
976971
start_parser.set_defaults(func=start)

‎src/doc/rustc/src/platform-support/fuchsia.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ test environment with:
697697
src/ci/docker/scripts/fuchsia-test-runner.py start
698698
--rust ${RUST_SRC_PATH}/install
699699
--sdk ${SDK_PATH}
700-
--target-arch {x64,arm64}
700+
--target-triple {x86_64-unknown-fuchsia|aarch64-unknown-fuchsia}
701701
```
702702

703703
Where `${RUST_SRC_PATH}/install` is the `prefix` set in `config.toml` and
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// edition: 2021
2+
// run-pass
3+
4+
async fn test(_arg: [u8; 16]) {}
5+
6+
async fn use_future(fut: impl std::future::Future<Output = ()>) {
7+
fut.await
8+
}
9+
10+
fn main() {
11+
let actual = std::mem::size_of_val(
12+
&use_future(use_future(use_future(use_future(use_future(test([0; 16])))))));
13+
// Not using an exact number in case it slightly changes over different commits
14+
let expected = 550;
15+
assert!(actual > expected, "expected: >{expected}, actual: {actual}");
16+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// compile-flags: -Z print-type-sizes --crate-type=lib
2+
// edition: 2021
3+
// build-pass
4+
// ignore-pass
5+
6+
pub async fn test() {
7+
let _ = a([0u8; 1024]).await;
8+
}
9+
10+
pub async fn a<T>(t: T) -> T {
11+
b(t).await
12+
}
13+
async fn b<T>(t: T) -> T {
14+
c(t).await
15+
}
16+
async fn c<T>(t: T) -> T {
17+
t
18+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
print-type-size type: `[async fn body@$DIR/large-arg.rs:6:21: 8:2]`: 3076 bytes, alignment: 1 bytes
2+
print-type-size discriminant: 1 bytes
3+
print-type-size variant `Suspend0`: 3075 bytes
4+
print-type-size local `.__awaitee`: 3075 bytes, offset: 0 bytes, alignment: 1 bytes
5+
print-type-size variant `Unresumed`: 0 bytes
6+
print-type-size variant `Returned`: 0 bytes
7+
print-type-size variant `Panicked`: 0 bytes
8+
print-type-size type: `[async fn body@$DIR/large-arg.rs:10:30: 12:2]`: 3075 bytes, alignment: 1 bytes
9+
print-type-size discriminant: 1 bytes
10+
print-type-size variant `Suspend0`: 3074 bytes
11+
print-type-size upvar `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes
12+
print-type-size local `.__awaitee`: 2050 bytes
13+
print-type-size variant `Unresumed`: 1024 bytes
14+
print-type-size upvar `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes
15+
print-type-size variant `Returned`: 1024 bytes
16+
print-type-size upvar `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes
17+
print-type-size variant `Panicked`: 1024 bytes
18+
print-type-size upvar `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes
19+
print-type-size type: `std::mem::ManuallyDrop<[async fn body@$DIR/large-arg.rs:10:30: 12:2]>`: 3075 bytes, alignment: 1 bytes
20+
print-type-size field `.value`: 3075 bytes
21+
print-type-size type: `std::mem::MaybeUninit<[async fn body@$DIR/large-arg.rs:10:30: 12:2]>`: 3075 bytes, alignment: 1 bytes
22+
print-type-size variant `MaybeUninit`: 3075 bytes
23+
print-type-size field `.uninit`: 0 bytes
24+
print-type-size field `.value`: 3075 bytes
25+
print-type-size type: `[async fn body@$DIR/large-arg.rs:13:26: 15:2]`: 2050 bytes, alignment: 1 bytes
26+
print-type-size discriminant: 1 bytes
27+
print-type-size variant `Suspend0`: 2049 bytes
28+
print-type-size upvar `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes
29+
print-type-size local `.__awaitee`: 1025 bytes
30+
print-type-size variant `Unresumed`: 1024 bytes
31+
print-type-size upvar `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes
32+
print-type-size variant `Returned`: 1024 bytes
33+
print-type-size upvar `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes
34+
print-type-size variant `Panicked`: 1024 bytes
35+
print-type-size upvar `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes
36+
print-type-size type: `std::mem::ManuallyDrop<[async fn body@$DIR/large-arg.rs:13:26: 15:2]>`: 2050 bytes, alignment: 1 bytes
37+
print-type-size field `.value`: 2050 bytes
38+
print-type-size type: `std::mem::MaybeUninit<[async fn body@$DIR/large-arg.rs:13:26: 15:2]>`: 2050 bytes, alignment: 1 bytes
39+
print-type-size variant `MaybeUninit`: 2050 bytes
40+
print-type-size field `.uninit`: 0 bytes
41+
print-type-size field `.value`: 2050 bytes
42+
print-type-size type: `[async fn body@$DIR/large-arg.rs:16:26: 18:2]`: 1025 bytes, alignment: 1 bytes
43+
print-type-size discriminant: 1 bytes
44+
print-type-size variant `Unresumed`: 1024 bytes
45+
print-type-size upvar `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes
46+
print-type-size variant `Returned`: 1024 bytes
47+
print-type-size upvar `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes
48+
print-type-size variant `Panicked`: 1024 bytes
49+
print-type-size upvar `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes
50+
print-type-size type: `std::mem::ManuallyDrop<[async fn body@$DIR/large-arg.rs:16:26: 18:2]>`: 1025 bytes, alignment: 1 bytes
51+
print-type-size field `.value`: 1025 bytes
52+
print-type-size type: `std::mem::MaybeUninit<[async fn body@$DIR/large-arg.rs:16:26: 18:2]>`: 1025 bytes, alignment: 1 bytes
53+
print-type-size variant `MaybeUninit`: 1025 bytes
54+
print-type-size field `.uninit`: 0 bytes
55+
print-type-size field `.value`: 1025 bytes
56+
print-type-size type: `std::task::Poll<[u8; 1024]>`: 1025 bytes, alignment: 1 bytes
57+
print-type-size discriminant: 1 bytes
58+
print-type-size variant `Ready`: 1024 bytes
59+
print-type-size field `.0`: 1024 bytes
60+
print-type-size variant `Pending`: 0 bytes
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// run-rustfix
2+
#![allow(dead_code, path_statements)]
3+
fn foo1(s: &str) -> impl Iterator<Item = String> + '_ {
4+
None.into_iter()
5+
.flat_map(move |()| s.chars().map(move |c| format!("{}{}", c, s)))
6+
//~^ ERROR captured variable cannot escape `FnMut` closure body
7+
//~| HELP consider adding 'move' keyword before the nested closure
8+
}
9+
10+
fn foo2(s: &str) -> impl Sized + '_ {
11+
move |()| s.chars().map(move |c| format!("{}{}", c, s))
12+
//~^ ERROR lifetime may not live long enough
13+
//~| HELP consider adding 'move' keyword before the nested closure
14+
}
15+
16+
pub struct X;
17+
pub fn foo3<'a>(
18+
bar: &'a X,
19+
) -> impl Iterator<Item = ()> + 'a {
20+
Some(()).iter().flat_map(move |()| {
21+
Some(()).iter().map(move |()| { bar; }) //~ ERROR captured variable cannot escape
22+
//~^ HELP consider adding 'move' keyword before the nested closure
23+
})
24+
}
25+
26+
fn main() {}

‎tests/ui/borrowck/issue-95079-missing-move-in-nested-closure.rs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// run-rustfix
2+
#![allow(dead_code, path_statements)]
13
fn foo1(s: &str) -> impl Iterator<Item = String> + '_ {
24
None.into_iter()
35
.flat_map(move |()| s.chars().map(|c| format!("{}{}", c, s)))
@@ -11,4 +13,14 @@ fn foo2(s: &str) -> impl Sized + '_ {
1113
//~| HELP consider adding 'move' keyword before the nested closure
1214
}
1315

16+
pub struct X;
17+
pub fn foo3<'a>(
18+
bar: &'a X,
19+
) -> impl Iterator<Item = ()> + 'a {
20+
Some(()).iter().flat_map(move |()| {
21+
Some(()).iter().map(|()| { bar; }) //~ ERROR captured variable cannot escape
22+
//~^ HELP consider adding 'move' keyword before the nested closure
23+
})
24+
}
25+
1426
fn main() {}
Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error: captured variable cannot escape `FnMut` closure body
2-
--> $DIR/issue-95079-missing-move-in-nested-closure.rs:3:29
2+
--> $DIR/issue-95079-missing-move-in-nested-closure.rs:5:29
33
|
44
LL | fn foo1(s: &str) -> impl Iterator<Item = String> + '_ {
55
| - variable defined here
66
LL | None.into_iter()
77
LL | .flat_map(move |()| s.chars().map(|c| format!("{}{}", c, s)))
88
| - -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
99
| | |
10-
| | returns a reference to a captured variable which escapes the closure body
10+
| | returns a closure that contains a reference to a captured variable, which then escapes the closure body
1111
| | variable captured here
1212
| inferred to be a `FnMut` closure
1313
|
@@ -19,12 +19,12 @@ LL | .flat_map(move |()| s.chars().map(move |c| format!("{}{}", c, s)))
1919
| ++++
2020

2121
error: lifetime may not live long enough
22-
--> $DIR/issue-95079-missing-move-in-nested-closure.rs:9:15
22+
--> $DIR/issue-95079-missing-move-in-nested-closure.rs:11:15
2323
|
2424
LL | move |()| s.chars().map(|c| format!("{}{}", c, s))
2525
| --------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'1` must outlive `'2`
2626
| | |
27-
| | return type of closure `Map<Chars<'_>, [closure@$DIR/issue-95079-missing-move-in-nested-closure.rs:9:29: 9:32]>` contains a lifetime `'2`
27+
| | return type of closure `Map<Chars<'_>, [closure@$DIR/issue-95079-missing-move-in-nested-closure.rs:11:29: 11:32]>` contains a lifetime `'2`
2828
| lifetime `'1` represents this closure's body
2929
|
3030
= note: closure implements `Fn`, so references to captured variables can't escape the closure
@@ -33,5 +33,26 @@ help: consider adding 'move' keyword before the nested closure
3333
LL | move |()| s.chars().map(move |c| format!("{}{}", c, s))
3434
| ++++
3535

36-
error: aborting due to 2 previous errors
36+
error: captured variable cannot escape `FnMut` closure body
37+
--> $DIR/issue-95079-missing-move-in-nested-closure.rs:21:9
38+
|
39+
LL | bar: &'a X,
40+
| --- variable defined here
41+
LL | ) -> impl Iterator<Item = ()> + 'a {
42+
LL | Some(()).iter().flat_map(move |()| {
43+
| - inferred to be a `FnMut` closure
44+
LL | Some(()).iter().map(|()| { bar; })
45+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^---^^^^
46+
| | |
47+
| | variable captured here
48+
| returns a closure that contains a reference to a captured variable, which then escapes the closure body
49+
|
50+
= note: `FnMut` closures only have access to their captured variables while they are executing...
51+
= note: ...therefore, they cannot allow references to captured variables to escape
52+
help: consider adding 'move' keyword before the nested closure
53+
|
54+
LL | Some(()).iter().map(move |()| { bar; })
55+
| ++++
56+
57+
error: aborting due to 3 previous errors
3758

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
fn main() {
2+
let bar = 3;
3+
format!("{?:}", bar);
4+
//~^ ERROR invalid format string: expected format parameter to occur after `:`
5+
format!("{?:bar}");
6+
//~^ ERROR invalid format string: expected format parameter to occur after `:`
7+
format!("{?:?}", bar);
8+
//~^ ERROR invalid format string: expected format parameter to occur after `:`
9+
format!("{??}", bar);
10+
//~^ ERROR invalid format string: expected `'}'`, found `'?'`
11+
format!("{?;bar}");
12+
//~^ ERROR invalid format string: expected `'}'`, found `'?'`
13+
format!("{?:#?}", bar);
14+
//~^ ERROR invalid format string: expected format parameter to occur after `:`
15+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
error: invalid format string: expected format parameter to occur after `:`
2+
--> $DIR/format-string-wrong-order.rs:3:15
3+
|
4+
LL | format!("{?:}", bar);
5+
| ^ expected `?` to occur after `:` in format string
6+
|
7+
= note: `?` comes after `:`, try `:?` instead
8+
9+
error: invalid format string: expected format parameter to occur after `:`
10+
--> $DIR/format-string-wrong-order.rs:5:15
11+
|
12+
LL | format!("{?:bar}");
13+
| ^ expected `?` to occur after `:` in format string
14+
|
15+
= note: `?` comes after `:`, try `bar:?` instead
16+
17+
error: invalid format string: expected format parameter to occur after `:`
18+
--> $DIR/format-string-wrong-order.rs:7:15
19+
|
20+
LL | format!("{?:?}", bar);
21+
| ^ expected `?` to occur after `:` in format string
22+
|
23+
= note: `?` comes after `:`, try `:?` instead
24+
25+
error: invalid format string: expected `'}'`, found `'?'`
26+
--> $DIR/format-string-wrong-order.rs:9:15
27+
|
28+
LL | format!("{??}", bar);
29+
| -^ expected `}` in format string
30+
| |
31+
| because of this opening brace
32+
|
33+
= note: if you intended to print `{`, you can escape it using `{{`
34+
35+
error: invalid format string: expected `'}'`, found `'?'`
36+
--> $DIR/format-string-wrong-order.rs:11:15
37+
|
38+
LL | format!("{?;bar}");
39+
| -^ expected `}` in format string
40+
| |
41+
| because of this opening brace
42+
|
43+
= note: if you intended to print `{`, you can escape it using `{{`
44+
45+
error: invalid format string: expected format parameter to occur after `:`
46+
--> $DIR/format-string-wrong-order.rs:13:15
47+
|
48+
LL | format!("{?:#?}", bar);
49+
| ^ expected `?` to occur after `:` in format string
50+
|
51+
= note: `?` comes after `:`, try `:?` instead
52+
53+
error: aborting due to 6 previous errors
54+

‎tests/ui/parser/issues/issue-87086-colon-path-sep.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ fn main() {
6868
Foo:Bar::Baz => {}
6969
//~^ ERROR: expected one of
7070
//~| HELP: maybe write a path separator here
71-
//~| ERROR: failed to resolve: `Bar` is a variant, not a module
7271
}
7372
match myfoo {
7473
Foo::Bar => {}

‎tests/ui/parser/issues/issue-87086-colon-path-sep.stderr‎

Lines changed: 55 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,89 +2,118 @@ error: expected one of `@` or `|`, found `:`
22
--> $DIR/issue-87086-colon-path-sep.rs:17:12
33
|
44
LL | Foo:Bar => {}
5-
| ^
5+
| ^--- specifying the type of a pattern isn't supported
66
| |
77
| expected one of `@` or `|`
8-
| help: maybe write a path separator here: `::`
8+
|
9+
help: maybe write a path separator here
10+
|
11+
LL | Foo::Bar => {}
12+
| ~~
913

1014
error: expected one of `!`, `(`, `...`, `..=`, `..`, `::`, `{`, or `|`, found `:`
1115
--> $DIR/issue-87086-colon-path-sep.rs:23:17
1216
|
1317
LL | qux::Foo:Bar => {}
14-
| ^
18+
| ^--- specifying the type of a pattern isn't supported
1519
| |
1620
| expected one of 8 possible tokens
17-
| help: maybe write a path separator here: `::`
21+
|
22+
help: maybe write a path separator here
23+
|
24+
LL | qux::Foo::Bar => {}
25+
| ~~
1826

1927
error: expected one of `@` or `|`, found `:`
2028
--> $DIR/issue-87086-colon-path-sep.rs:29:12
2129
|
2230
LL | qux:Foo::Baz => {}
23-
| ^
31+
| ^-------- specifying the type of a pattern isn't supported
2432
| |
2533
| expected one of `@` or `|`
26-
| help: maybe write a path separator here: `::`
34+
|
35+
help: maybe write a path separator here
36+
|
37+
LL | qux::Foo::Baz => {}
38+
| ~~
2739

2840
error: expected one of `@` or `|`, found `:`
2941
--> $DIR/issue-87086-colon-path-sep.rs:35:12
3042
|
3143
LL | qux: Foo::Baz if true => {}
32-
| ^
44+
| ^ -------- specifying the type of a pattern isn't supported
3345
| |
3446
| expected one of `@` or `|`
35-
| help: maybe write a path separator here: `::`
47+
|
48+
help: maybe write a path separator here
49+
|
50+
LL | qux::Foo::Baz if true => {}
51+
| ~~
3652

3753
error: expected one of `@` or `|`, found `:`
3854
--> $DIR/issue-87086-colon-path-sep.rs:40:15
3955
|
4056
LL | if let Foo:Bar = f() {
41-
| ^
57+
| ^--- specifying the type of a pattern isn't supported
4258
| |
4359
| expected one of `@` or `|`
44-
| help: maybe write a path separator here: `::`
60+
|
61+
help: maybe write a path separator here
62+
|
63+
LL | if let Foo::Bar = f() {
64+
| ~~
4565

4666
error: expected one of `@` or `|`, found `:`
4767
--> $DIR/issue-87086-colon-path-sep.rs:48:16
4868
|
4969
LL | ref qux: Foo::Baz => {}
50-
| ^
70+
| ^ -------- specifying the type of a pattern isn't supported
5171
| |
5272
| expected one of `@` or `|`
53-
| help: maybe write a path separator here: `::`
73+
|
74+
help: maybe write a path separator here
75+
|
76+
LL | ref qux::Foo::Baz => {}
77+
| ~~
5478

5579
error: expected one of `@` or `|`, found `:`
5680
--> $DIR/issue-87086-colon-path-sep.rs:57:16
5781
|
5882
LL | mut qux: Foo::Baz => {}
59-
| ^
83+
| ^ -------- specifying the type of a pattern isn't supported
6084
| |
6185
| expected one of `@` or `|`
62-
| help: maybe write a path separator here: `::`
86+
|
87+
help: maybe write a path separator here
88+
|
89+
LL | mut qux::Foo::Baz => {}
90+
| ~~
6391

6492
error: expected one of `@` or `|`, found `:`
6593
--> $DIR/issue-87086-colon-path-sep.rs:68:12
6694
|
6795
LL | Foo:Bar::Baz => {}
68-
| ^
96+
| ^-------- specifying the type of a pattern isn't supported
6997
| |
7098
| expected one of `@` or `|`
71-
| help: maybe write a path separator here: `::`
99+
|
100+
help: maybe write a path separator here
101+
|
102+
LL | Foo::Bar::Baz => {}
103+
| ~~
72104

73105
error: expected one of `@` or `|`, found `:`
74-
--> $DIR/issue-87086-colon-path-sep.rs:75:12
106+
--> $DIR/issue-87086-colon-path-sep.rs:74:12
75107
|
76108
LL | Foo:Bar => {}
77-
| ^
109+
| ^--- specifying the type of a pattern isn't supported
78110
| |
79111
| expected one of `@` or `|`
80-
| help: maybe write a path separator here: `::`
81-
82-
error[E0433]: failed to resolve: `Bar` is a variant, not a module
83-
--> $DIR/issue-87086-colon-path-sep.rs:68:13
84112
|
85-
LL | Foo:Bar::Baz => {}
86-
| ^^^ `Bar` is a variant, not a module
113+
help: maybe write a path separator here
114+
|
115+
LL | Foo::Bar => {}
116+
| ~~
87117

88-
error: aborting due to 10 previous errors
118+
error: aborting due to 9 previous errors
89119

90-
For more information about this error, try `rustc --explain E0433`.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
fn foo(x: bool) -> i32 {
2+
match x {
3+
x: i32 => x, //~ ERROR expected
4+
//~^ ERROR mismatched types
5+
true => 42.,
6+
false => 0.333,
7+
}
8+
}
9+
10+
fn main() {
11+
match foo(true) {
12+
42: i32 => (), //~ ERROR expected
13+
_: f64 => (), //~ ERROR expected
14+
x: i32 => (), //~ ERROR expected
15+
}
16+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
error: expected one of `@` or `|`, found `:`
2+
--> $DIR/type-ascription-in-pattern.rs:3:10
3+
|
4+
LL | x: i32 => x,
5+
| ^ --- specifying the type of a pattern isn't supported
6+
| |
7+
| expected one of `@` or `|`
8+
|
9+
help: maybe write a path separator here
10+
|
11+
LL | x::i32 => x,
12+
| ~~
13+
14+
error: expected one of `...`, `..=`, `..`, or `|`, found `:`
15+
--> $DIR/type-ascription-in-pattern.rs:12:11
16+
|
17+
LL | 42: i32 => (),
18+
| ^ --- specifying the type of a pattern isn't supported
19+
| |
20+
| expected one of `...`, `..=`, `..`, or `|`
21+
22+
error: expected `|`, found `:`
23+
--> $DIR/type-ascription-in-pattern.rs:13:10
24+
|
25+
LL | _: f64 => (),
26+
| ^ --- specifying the type of a pattern isn't supported
27+
| |
28+
| expected `|`
29+
30+
error: expected one of `@` or `|`, found `:`
31+
--> $DIR/type-ascription-in-pattern.rs:14:10
32+
|
33+
LL | x: i32 => (),
34+
| ^ --- specifying the type of a pattern isn't supported
35+
| |
36+
| expected one of `@` or `|`
37+
|
38+
help: maybe write a path separator here
39+
|
40+
LL | x::i32 => (),
41+
| ~~
42+
43+
error[E0308]: mismatched types
44+
--> $DIR/type-ascription-in-pattern.rs:3:19
45+
|
46+
LL | fn foo(x: bool) -> i32 {
47+
| --- expected `i32` because of return type
48+
LL | match x {
49+
LL | x: i32 => x,
50+
| ^ expected `i32`, found `bool`
51+
52+
error: aborting due to 5 previous errors
53+
54+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)
Please sign in to comment.