Skip to content

Commit 035d865

Browse files
committed
Merge from rustc
2 parents e8a25b0 + 43714ed commit 035d865

File tree

482 files changed

+12445
-6251
lines changed

Some content is hidden

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

482 files changed

+12445
-6251
lines changed

.github/workflows/ci.yml

+3
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,9 @@ jobs:
288288
- name: x86_64-gnu-aux
289289
os: ubuntu-20.04-4core-16gb
290290
env: {}
291+
- name: x86_64-gnu-integration
292+
os: ubuntu-20.04-16core-64gb
293+
env: {}
291294
- name: x86_64-gnu-debug
292295
os: ubuntu-20.04-8core-32gb
293296
env: {}

Cargo.lock

+31-5
Original file line numberDiff line numberDiff line change
@@ -795,10 +795,6 @@ dependencies = [
795795
"rustc-demangle",
796796
]
797797

798-
[[package]]
799-
name = "coverage_test_macros"
800-
version = "0.0.0"
801-
802798
[[package]]
803799
name = "cpufeatures"
804800
version = "0.2.8"
@@ -3760,6 +3756,7 @@ dependencies = [
37603756
"rustc_monomorphize",
37613757
"rustc_parse",
37623758
"rustc_passes",
3759+
"rustc_pattern_analysis",
37633760
"rustc_privacy",
37643761
"rustc_query_system",
37653762
"rustc_resolve",
@@ -4233,6 +4230,7 @@ dependencies = [
42334230
"rustc_infer",
42344231
"rustc_macros",
42354232
"rustc_middle",
4233+
"rustc_pattern_analysis",
42364234
"rustc_session",
42374235
"rustc_span",
42384236
"rustc_target",
@@ -4266,7 +4264,6 @@ dependencies = [
42664264
name = "rustc_mir_transform"
42674265
version = "0.0.0"
42684266
dependencies = [
4269-
"coverage_test_macros",
42704267
"either",
42714268
"itertools",
42724269
"rustc_arena",
@@ -4308,6 +4305,13 @@ dependencies = [
43084305
"tracing",
43094306
]
43104307

4308+
[[package]]
4309+
name = "rustc_next_trait_solver"
4310+
version = "0.0.0"
4311+
dependencies = [
4312+
"rustc_type_ir",
4313+
]
4314+
43114315
[[package]]
43124316
name = "rustc_parse"
43134317
version = "0.0.0"
@@ -4362,6 +4366,26 @@ dependencies = [
43624366
"tracing",
43634367
]
43644368

4369+
[[package]]
4370+
name = "rustc_pattern_analysis"
4371+
version = "0.0.0"
4372+
dependencies = [
4373+
"rustc_apfloat",
4374+
"rustc_arena",
4375+
"rustc_data_structures",
4376+
"rustc_errors",
4377+
"rustc_fluent_macro",
4378+
"rustc_hir",
4379+
"rustc_index",
4380+
"rustc_macros",
4381+
"rustc_middle",
4382+
"rustc_session",
4383+
"rustc_span",
4384+
"rustc_target",
4385+
"smallvec",
4386+
"tracing",
4387+
]
4388+
43654389
[[package]]
43664390
name = "rustc_privacy"
43674391
version = "0.0.0"
@@ -4492,6 +4516,7 @@ dependencies = [
44924516
name = "rustc_smir"
44934517
version = "0.0.0"
44944518
dependencies = [
4519+
"rustc_abi",
44954520
"rustc_data_structures",
44964521
"rustc_hir",
44974522
"rustc_middle",
@@ -4576,6 +4601,7 @@ dependencies = [
45764601
"rustc_infer",
45774602
"rustc_macros",
45784603
"rustc_middle",
4604+
"rustc_next_trait_solver",
45794605
"rustc_parse_format",
45804606
"rustc_query_system",
45814607
"rustc_session",

compiler/rustc_ast/src/ast.rs

+48-10
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,24 @@ impl Pat {
658658
pub fn is_rest(&self) -> bool {
659659
matches!(self.kind, PatKind::Rest)
660660
}
661+
662+
/// Whether this could be a never pattern, taking into account that a macro invocation can
663+
/// return a never pattern. Used to inform errors during parsing.
664+
pub fn could_be_never_pattern(&self) -> bool {
665+
let mut could_be_never_pattern = false;
666+
self.walk(&mut |pat| match &pat.kind {
667+
PatKind::Never | PatKind::MacCall(_) => {
668+
could_be_never_pattern = true;
669+
false
670+
}
671+
PatKind::Or(s) => {
672+
could_be_never_pattern = s.iter().all(|p| p.could_be_never_pattern());
673+
false
674+
}
675+
_ => true,
676+
});
677+
could_be_never_pattern
678+
}
661679
}
662680

663681
/// A single field in a struct pattern.
@@ -1080,8 +1098,8 @@ pub struct Arm {
10801098
pub pat: P<Pat>,
10811099
/// Match arm guard, e.g. `n > 10` in `match foo { n if n > 10 => {}, _ => {} }`
10821100
pub guard: Option<P<Expr>>,
1083-
/// Match arm body.
1084-
pub body: P<Expr>,
1101+
/// Match arm body. Omitted if the pattern is a never pattern.
1102+
pub body: Option<P<Expr>>,
10851103
pub span: Span,
10861104
pub id: NodeId,
10871105
pub is_placeholder: bool,
@@ -1311,7 +1329,7 @@ pub struct Closure {
13111329
pub binder: ClosureBinder,
13121330
pub capture_clause: CaptureBy,
13131331
pub constness: Const,
1314-
pub coro_kind: Option<CoroutineKind>,
1332+
pub coroutine_kind: Option<CoroutineKind>,
13151333
pub movability: Movability,
13161334
pub fn_decl: P<FnDecl>,
13171335
pub body: P<Expr>,
@@ -1516,6 +1534,7 @@ pub enum ExprKind {
15161534
pub enum GenBlockKind {
15171535
Async,
15181536
Gen,
1537+
AsyncGen,
15191538
}
15201539

15211540
impl fmt::Display for GenBlockKind {
@@ -1529,6 +1548,7 @@ impl GenBlockKind {
15291548
match self {
15301549
GenBlockKind::Async => "async",
15311550
GenBlockKind::Gen => "gen",
1551+
GenBlockKind::AsyncGen => "async gen",
15321552
}
15331553
}
15341554
}
@@ -2413,10 +2433,12 @@ pub enum Unsafe {
24132433
/// Iterator`.
24142434
#[derive(Copy, Clone, Encodable, Decodable, Debug)]
24152435
pub enum CoroutineKind {
2416-
/// `async`, which evaluates to `impl Future`
2436+
/// `async`, which returns an `impl Future`
24172437
Async { span: Span, closure_id: NodeId, return_impl_trait_id: NodeId },
2418-
/// `gen`, which evaluates to `impl Iterator`
2438+
/// `gen`, which returns an `impl Iterator`
24192439
Gen { span: Span, closure_id: NodeId, return_impl_trait_id: NodeId },
2440+
/// `async gen`, which returns an `impl AsyncIterator`
2441+
AsyncGen { span: Span, closure_id: NodeId, return_impl_trait_id: NodeId },
24202442
}
24212443

24222444
impl CoroutineKind {
@@ -2428,12 +2450,23 @@ impl CoroutineKind {
24282450
matches!(self, CoroutineKind::Gen { .. })
24292451
}
24302452

2453+
pub fn closure_id(self) -> NodeId {
2454+
match self {
2455+
CoroutineKind::Async { closure_id, .. }
2456+
| CoroutineKind::Gen { closure_id, .. }
2457+
| CoroutineKind::AsyncGen { closure_id, .. } => closure_id,
2458+
}
2459+
}
2460+
24312461
/// In this case this is an `async` or `gen` return, the `NodeId` for the generated `impl Trait`
24322462
/// item.
24332463
pub fn return_id(self) -> (NodeId, Span) {
24342464
match self {
24352465
CoroutineKind::Async { return_impl_trait_id, span, .. }
2436-
| CoroutineKind::Gen { return_impl_trait_id, span, .. } => (return_impl_trait_id, span),
2466+
| CoroutineKind::Gen { return_impl_trait_id, span, .. }
2467+
| CoroutineKind::AsyncGen { return_impl_trait_id, span, .. } => {
2468+
(return_impl_trait_id, span)
2469+
}
24372470
}
24382471
}
24392472
}
@@ -2838,7 +2871,7 @@ pub struct FnHeader {
28382871
/// The `unsafe` keyword, if any
28392872
pub unsafety: Unsafe,
28402873
/// Whether this is `async`, `gen`, or nothing.
2841-
pub coro_kind: Option<CoroutineKind>,
2874+
pub coroutine_kind: Option<CoroutineKind>,
28422875
/// The `const` keyword, if any
28432876
pub constness: Const,
28442877
/// The `extern` keyword and corresponding ABI string, if any
@@ -2848,17 +2881,22 @@ pub struct FnHeader {
28482881
impl FnHeader {
28492882
/// Does this function header have any qualifiers or is it empty?
28502883
pub fn has_qualifiers(&self) -> bool {
2851-
let Self { unsafety, coro_kind, constness, ext } = self;
2884+
let Self { unsafety, coroutine_kind, constness, ext } = self;
28522885
matches!(unsafety, Unsafe::Yes(_))
2853-
|| coro_kind.is_some()
2886+
|| coroutine_kind.is_some()
28542887
|| matches!(constness, Const::Yes(_))
28552888
|| !matches!(ext, Extern::None)
28562889
}
28572890
}
28582891

28592892
impl Default for FnHeader {
28602893
fn default() -> FnHeader {
2861-
FnHeader { unsafety: Unsafe::No, coro_kind: None, constness: Const::No, ext: Extern::None }
2894+
FnHeader {
2895+
unsafety: Unsafe::No,
2896+
coroutine_kind: None,
2897+
constness: Const::No,
2898+
ext: Extern::None,
2899+
}
28622900
}
28632901
}
28642902

compiler/rustc_ast/src/mut_visit.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ pub trait MutVisitor: Sized {
121121
noop_visit_fn_decl(d, self);
122122
}
123123

124-
fn visit_coro_kind(&mut self, a: &mut CoroutineKind) {
125-
noop_visit_coro_kind(a, self);
124+
fn visit_coroutine_kind(&mut self, a: &mut CoroutineKind) {
125+
noop_visit_coroutine_kind(a, self);
126126
}
127127

128128
fn visit_closure_binder(&mut self, b: &mut ClosureBinder) {
@@ -453,7 +453,7 @@ pub fn noop_flat_map_arm<T: MutVisitor>(mut arm: Arm, vis: &mut T) -> SmallVec<[
453453
vis.visit_id(id);
454454
vis.visit_pat(pat);
455455
visit_opt(guard, |guard| vis.visit_expr(guard));
456-
vis.visit_expr(body);
456+
visit_opt(body, |body| vis.visit_expr(body));
457457
vis.visit_span(span);
458458
smallvec![arm]
459459
}
@@ -871,10 +871,11 @@ pub fn noop_visit_closure_binder<T: MutVisitor>(binder: &mut ClosureBinder, vis:
871871
}
872872
}
873873

874-
pub fn noop_visit_coro_kind<T: MutVisitor>(coro_kind: &mut CoroutineKind, vis: &mut T) {
875-
match coro_kind {
874+
pub fn noop_visit_coroutine_kind<T: MutVisitor>(coroutine_kind: &mut CoroutineKind, vis: &mut T) {
875+
match coroutine_kind {
876876
CoroutineKind::Async { span, closure_id, return_impl_trait_id }
877-
| CoroutineKind::Gen { span, closure_id, return_impl_trait_id } => {
877+
| CoroutineKind::Gen { span, closure_id, return_impl_trait_id }
878+
| CoroutineKind::AsyncGen { span, closure_id, return_impl_trait_id } => {
878879
vis.visit_span(span);
879880
vis.visit_id(closure_id);
880881
vis.visit_id(return_impl_trait_id);
@@ -1171,9 +1172,9 @@ fn visit_const_item<T: MutVisitor>(
11711172
}
11721173

11731174
pub fn noop_visit_fn_header<T: MutVisitor>(header: &mut FnHeader, vis: &mut T) {
1174-
let FnHeader { unsafety, coro_kind, constness, ext: _ } = header;
1175+
let FnHeader { unsafety, coroutine_kind, constness, ext: _ } = header;
11751176
visit_constness(constness, vis);
1176-
coro_kind.as_mut().map(|coro_kind| vis.visit_coro_kind(coro_kind));
1177+
coroutine_kind.as_mut().map(|coroutine_kind| vis.visit_coroutine_kind(coroutine_kind));
11771178
visit_unsafety(unsafety, vis);
11781179
}
11791180

@@ -1407,7 +1408,7 @@ pub fn noop_visit_expr<T: MutVisitor>(
14071408
binder,
14081409
capture_clause,
14091410
constness,
1410-
coro_kind,
1411+
coroutine_kind,
14111412
movability: _,
14121413
fn_decl,
14131414
body,
@@ -1416,7 +1417,7 @@ pub fn noop_visit_expr<T: MutVisitor>(
14161417
}) => {
14171418
vis.visit_closure_binder(binder);
14181419
visit_constness(constness, vis);
1419-
coro_kind.as_mut().map(|coro_kind| vis.visit_coro_kind(coro_kind));
1420+
coroutine_kind.as_mut().map(|coroutine_kind| vis.visit_coroutine_kind(coroutine_kind));
14201421
vis.visit_capture_by(capture_clause);
14211422
vis.visit_fn_decl(fn_decl);
14221423
vis.visit_expr(body);

compiler/rustc_ast/src/visit.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
861861
ExprKind::Closure(box Closure {
862862
binder,
863863
capture_clause,
864-
coro_kind: _,
864+
coroutine_kind: _,
865865
constness: _,
866866
movability: _,
867867
fn_decl,
@@ -951,7 +951,7 @@ pub fn walk_param<'a, V: Visitor<'a>>(visitor: &mut V, param: &'a Param) {
951951
pub fn walk_arm<'a, V: Visitor<'a>>(visitor: &mut V, arm: &'a Arm) {
952952
visitor.visit_pat(&arm.pat);
953953
walk_list!(visitor, visit_expr, &arm.guard);
954-
visitor.visit_expr(&arm.body);
954+
walk_list!(visitor, visit_expr, &arm.body);
955955
walk_list!(visitor, visit_attribute, &arm.attrs);
956956
}
957957

compiler/rustc_ast_lowering/messages.ftl

+13
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ ast_lowering_invalid_register =
9191
ast_lowering_invalid_register_class =
9292
invalid register class `{$reg_class}`: {$error}
9393
94+
ast_lowering_match_arm_with_no_body =
95+
`match` arm with no body
96+
.suggestion = add a body after the pattern
97+
9498
ast_lowering_misplaced_assoc_ty_binding =
9599
associated type bounds are only allowed in where clauses and function signatures, not in {$position}
96100
@@ -104,6 +108,15 @@ ast_lowering_misplaced_impl_trait =
104108
ast_lowering_misplaced_relax_trait_bound =
105109
`?Trait` bounds are only permitted at the point where a type parameter is declared
106110
111+
ast_lowering_never_pattern_with_body =
112+
a never pattern is always unreachable
113+
.label = this will never be executed
114+
.suggestion = remove this expression
115+
116+
ast_lowering_never_pattern_with_guard =
117+
a guard on a never pattern will never be run
118+
.suggestion = remove this guard
119+
107120
ast_lowering_not_supported_for_lifetime_binder_async_closure =
108121
`for<...>` binders on `async` closures are not currently supported
109122

compiler/rustc_ast_lowering/src/errors.rs

+26
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,32 @@ pub struct NotSupportedForLifetimeBinderAsyncClosure {
340340
pub span: Span,
341341
}
342342

343+
#[derive(Diagnostic)]
344+
#[diag(ast_lowering_match_arm_with_no_body)]
345+
pub struct MatchArmWithNoBody {
346+
#[primary_span]
347+
pub span: Span,
348+
#[suggestion(code = " => todo!(),", applicability = "has-placeholders")]
349+
pub suggestion: Span,
350+
}
351+
352+
#[derive(Diagnostic)]
353+
#[diag(ast_lowering_never_pattern_with_body)]
354+
pub struct NeverPatternWithBody {
355+
#[primary_span]
356+
#[label]
357+
#[suggestion(code = "", applicability = "maybe-incorrect")]
358+
pub span: Span,
359+
}
360+
361+
#[derive(Diagnostic)]
362+
#[diag(ast_lowering_never_pattern_with_guard)]
363+
pub struct NeverPatternWithGuard {
364+
#[primary_span]
365+
#[suggestion(code = "", applicability = "maybe-incorrect")]
366+
pub span: Span,
367+
}
368+
343369
#[derive(Diagnostic, Clone, Copy)]
344370
#[diag(ast_lowering_arbitrary_expression_in_pattern)]
345371
pub struct ArbitraryExpressionInPattern {

0 commit comments

Comments
 (0)