Skip to content

Commit a5077d9

Browse files
committed
Auto merge of rust-lang#3292 - rust-lang:rustup-2024-02-08, r=saethlin
Automatic Rustup
2 parents 35551d0 + 964a576 commit a5077d9

File tree

687 files changed

+8146
-2481
lines changed

Some content is hidden

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

687 files changed

+8146
-2481
lines changed

.github/workflows/ci.yml

+16-4
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,8 @@ jobs:
364364
os: macos-13
365365
- name: dist-aarch64-apple
366366
env:
367-
SCRIPT: "./x.py dist bootstrap --include-default-paths --stage 2"
368-
RUST_CONFIGURE_ARGS: "--build=x86_64-apple-darwin --host=aarch64-apple-darwin --target=aarch64-apple-darwin --enable-full-tools --enable-sanitizers --enable-profiler --disable-docs --set rust.jemalloc"
367+
SCRIPT: "./x.py dist bootstrap --include-default-paths --host=aarch64-apple-darwin --target=aarch64-apple-darwin"
368+
RUST_CONFIGURE_ARGS: "--enable-full-tools --enable-sanitizers --enable-profiler --set rust.jemalloc --set llvm.ninja=false --set rust.lto=thin"
369369
RUSTC_RETRY_LINKER_ON_SEGFAULT: 1
370370
SELECT_XCODE: /Applications/Xcode_13.4.1.app
371371
USE_XCODE_CLANG: 1
@@ -375,8 +375,20 @@ jobs:
375375
NO_DEBUG_ASSERTIONS: 1
376376
NO_OVERFLOW_CHECKS: 1
377377
DIST_REQUIRE_ALL_TOOLS: 1
378-
JEMALLOC_SYS_WITH_LG_PAGE: 14
379-
os: macos-13
378+
os: macos-14
379+
- name: aarch64-apple
380+
env:
381+
SCRIPT: "./x.py --stage 2 test --host=aarch64-apple-darwin --target=aarch64-apple-darwin"
382+
RUST_CONFIGURE_ARGS: "--enable-sanitizers --enable-profiler --set rust.jemalloc"
383+
RUSTC_RETRY_LINKER_ON_SEGFAULT: 1
384+
SELECT_XCODE: /Applications/Xcode_13.4.1.app
385+
USE_XCODE_CLANG: 1
386+
MACOSX_DEPLOYMENT_TARGET: 11.0
387+
MACOSX_STD_DEPLOYMENT_TARGET: 11.0
388+
NO_LLVM_ASSERTIONS: 1
389+
NO_DEBUG_ASSERTIONS: 1
390+
NO_OVERFLOW_CHECKS: 1
391+
os: macos-14
380392
- name: x86_64-msvc
381393
env:
382394
RUST_CONFIGURE_ARGS: "--build=x86_64-pc-windows-msvc --enable-profiler"

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -5321,6 +5321,7 @@ version = "0.0.0"
53215321
dependencies = [
53225322
"core",
53235323
"getopts",
5324+
"libc",
53245325
"panic_abort",
53255326
"panic_unwind",
53265327
"std",

compiler/rustc_ast_lowering/messages.ftl

-3
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,6 @@ ast_lowering_never_pattern_with_guard =
123123
a guard on a never pattern will never be run
124124
.suggestion = remove this guard
125125
126-
ast_lowering_not_supported_for_lifetime_binder_async_closure =
127-
`for<...>` binders on `async` closures are not currently supported
128-
129126
ast_lowering_previously_used_here = previously used here
130127
131128
ast_lowering_register1 = register `{$reg1_name}`

compiler/rustc_ast_lowering/src/errors.rs

-7
Original file line numberDiff line numberDiff line change
@@ -326,13 +326,6 @@ pub struct MisplacedRelaxTraitBound {
326326
pub span: Span,
327327
}
328328

329-
#[derive(Diagnostic, Clone, Copy)]
330-
#[diag(ast_lowering_not_supported_for_lifetime_binder_async_closure)]
331-
pub struct NotSupportedForLifetimeBinderAsyncClosure {
332-
#[primary_span]
333-
pub span: Span,
334-
}
335-
336329
#[derive(Diagnostic)]
337330
#[diag(ast_lowering_match_arm_with_no_body)]
338331
pub struct MatchArmWithNoBody {

compiler/rustc_ast_lowering/src/expr.rs

+18-20
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
use std::assert_matches::assert_matches;
2+
13
use super::errors::{
24
AsyncCoroutinesNotSupported, AwaitOnlyInAsyncFnAndBlocks, BaseExpressionDoubleDot,
35
ClosureCannotBeStatic, CoroutineTooManyParameters,
46
FunctionalRecordUpdateDestructuringAssignment, InclusiveRangeWithNoEnd, MatchArmWithNoBody,
5-
NeverPatternWithBody, NeverPatternWithGuard, NotSupportedForLifetimeBinderAsyncClosure,
6-
UnderscoreExprLhsAssign,
7+
NeverPatternWithBody, NeverPatternWithGuard, UnderscoreExprLhsAssign,
78
};
89
use super::ResolverAstLoweringExt;
910
use super::{ImplTraitContext, LoweringContext, ParamMode, ParenthesizedGenericArgs};
@@ -1028,30 +1029,27 @@ impl<'hir> LoweringContext<'_, 'hir> {
10281029
fn_decl_span: Span,
10291030
fn_arg_span: Span,
10301031
) -> hir::ExprKind<'hir> {
1031-
if let &ClosureBinder::For { span, .. } = binder {
1032-
self.dcx().emit_err(NotSupportedForLifetimeBinderAsyncClosure { span });
1033-
}
1034-
10351032
let (binder_clause, generic_params) = self.lower_closure_binder(binder);
10361033

1034+
assert_matches!(
1035+
coroutine_kind,
1036+
CoroutineKind::Async { .. },
1037+
"only async closures are supported currently"
1038+
);
1039+
10371040
let body = self.with_new_scopes(fn_decl_span, |this| {
1041+
let inner_decl =
1042+
FnDecl { inputs: decl.inputs.clone(), output: FnRetTy::Default(fn_decl_span) };
1043+
10381044
// Transform `async |x: u8| -> X { ... }` into
10391045
// `|x: u8| || -> X { ... }`.
10401046
let body_id = this.lower_body(|this| {
1041-
let async_ret_ty = if let FnRetTy::Ty(ty) = &decl.output {
1042-
let itctx = ImplTraitContext::Disallowed(ImplTraitPosition::AsyncBlock);
1043-
Some(hir::FnRetTy::Return(this.lower_ty(ty, &itctx)))
1044-
} else {
1045-
None
1046-
};
1047-
10481047
let (parameters, expr) = this.lower_coroutine_body_with_moved_arguments(
1049-
decl,
1048+
&inner_decl,
10501049
|this| this.with_new_scopes(fn_decl_span, |this| this.lower_expr_mut(body)),
10511050
body.span,
10521051
coroutine_kind,
10531052
hir::CoroutineSource::Closure,
1054-
async_ret_ty,
10551053
);
10561054

10571055
let hir_id = this.lower_node_id(coroutine_kind.closure_id());
@@ -1062,15 +1060,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
10621060
body_id
10631061
});
10641062

1065-
let outer_decl =
1066-
FnDecl { inputs: decl.inputs.clone(), output: FnRetTy::Default(fn_decl_span) };
1067-
10681063
let bound_generic_params = self.lower_lifetime_binder(closure_id, generic_params);
10691064
// We need to lower the declaration outside the new scope, because we
10701065
// have to conserve the state of being inside a loop condition for the
10711066
// closure argument types.
10721067
let fn_decl =
1073-
self.lower_fn_decl(&outer_decl, closure_id, fn_decl_span, FnDeclKind::Closure, None);
1068+
self.lower_fn_decl(&decl, closure_id, fn_decl_span, FnDeclKind::Closure, None);
10741069

10751070
let c = self.arena.alloc(hir::Closure {
10761071
def_id: self.local_def_id(closure_id),
@@ -1081,7 +1076,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
10811076
body,
10821077
fn_decl_span: self.lower_span(fn_decl_span),
10831078
fn_arg_span: Some(self.lower_span(fn_arg_span)),
1084-
kind: hir::ClosureKind::Closure,
1079+
// Lower this as a `CoroutineClosure`. That will ensure that HIR typeck
1080+
// knows that a `FnDecl` output type like `-> &str` actually means
1081+
// "coroutine that returns &str", rather than directly returning a `&str`.
1082+
kind: hir::ClosureKind::CoroutineClosure(hir::CoroutineDesugaring::Async),
10851083
constness: hir::Constness::NotConst,
10861084
});
10871085
hir::ExprKind::Closure(c)

compiler/rustc_ast_lowering/src/item.rs

+19-13
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
498498
}
499499
}
500500

501-
let res =
502-
self.expect_full_res_from_use(id).map(|res| self.lower_res(res)).collect();
501+
let res = self.lower_import_res(id, path.span);
503502
let path = self.lower_use_path(res, &path, ParamMode::Explicit);
504503
hir::ItemKind::Use(path, hir::UseKind::Single)
505504
}
@@ -535,7 +534,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
535534
// for that we return the `{}` import (called the
536535
// `ListStem`).
537536

538-
let prefix = Path { segments, span: prefix.span.to(path.span), tokens: None };
537+
let span = prefix.span.to(path.span);
538+
let prefix = Path { segments, span, tokens: None };
539539

540540
// Add all the nested `PathListItem`s to the HIR.
541541
for &(ref use_tree, id) in trees {
@@ -569,9 +569,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
569569
});
570570
}
571571

572-
let res =
573-
self.expect_full_res_from_use(id).map(|res| self.lower_res(res)).collect();
574-
let path = self.lower_use_path(res, &prefix, ParamMode::Explicit);
572+
let path = if trees.is_empty() && !prefix.segments.is_empty() {
573+
// For empty lists we need to lower the prefix so it is checked for things
574+
// like stability later.
575+
let res = self.lower_import_res(id, span);
576+
self.lower_use_path(res, &prefix, ParamMode::Explicit)
577+
} else {
578+
// For non-empty lists we can just drop all the data, the prefix is already
579+
// present in HIR as a part of nested imports.
580+
self.arena.alloc(hir::UsePath { res: smallvec![], segments: &[], span })
581+
};
575582
hir::ItemKind::Use(path, hir::UseKind::ListStem)
576583
}
577584
}
@@ -1091,7 +1098,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
10911098
body.span,
10921099
coroutine_kind,
10931100
hir::CoroutineSource::Fn,
1094-
None,
10951101
);
10961102

10971103
// FIXME(async_fn_track_caller): Can this be moved above?
@@ -1113,7 +1119,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
11131119
body_span: Span,
11141120
coroutine_kind: CoroutineKind,
11151121
coroutine_source: hir::CoroutineSource,
1116-
return_type_hint: Option<hir::FnRetTy<'hir>>,
11171122
) -> (&'hir [hir::Param<'hir>], hir::Expr<'hir>) {
11181123
let mut parameters: Vec<hir::Param<'_>> = Vec::new();
11191124
let mut statements: Vec<hir::Stmt<'_>> = Vec::new();
@@ -1283,12 +1288,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
12831288
};
12841289
let closure_id = coroutine_kind.closure_id();
12851290
let coroutine_expr = self.make_desugared_coroutine_expr(
1286-
// FIXME(async_closures): This should only move locals,
1287-
// and not upvars. Capturing closure upvars by ref doesn't
1288-
// work right now anyways, so whatever.
1289-
CaptureBy::Value { move_kw: rustc_span::DUMMY_SP },
1291+
// The default capture mode here is by-ref. Later on during upvar analysis,
1292+
// we will force the captured arguments to by-move, but for async closures,
1293+
// we want to make sure that we avoid unnecessarily moving captures, or else
1294+
// all async closures would default to `FnOnce` as their calling mode.
1295+
CaptureBy::Ref,
12901296
closure_id,
1291-
return_type_hint,
1297+
None,
12921298
body_span,
12931299
desugaring_kind,
12941300
coroutine_source,

compiler/rustc_ast_lowering/src/lib.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#![allow(internal_features)]
3434
#![feature(rustdoc_internals)]
3535
#![doc(rust_logo)]
36+
#![feature(assert_matches)]
3637
#![feature(box_patterns)]
3738
#![feature(let_chains)]
3839
#![deny(rustc::untranslatable_diagnostic)]
@@ -63,7 +64,7 @@ use rustc_middle::ty::{ResolverAstLowering, TyCtxt};
6364
use rustc_session::parse::{add_feature_diagnostics, feature_err};
6465
use rustc_span::symbol::{kw, sym, Ident, Symbol};
6566
use rustc_span::{DesugaringKind, Span, DUMMY_SP};
66-
use smallvec::SmallVec;
67+
use smallvec::{smallvec, SmallVec};
6768
use std::collections::hash_map::Entry;
6869
use thin_vec::ThinVec;
6970

@@ -298,7 +299,6 @@ enum ImplTraitPosition {
298299
Path,
299300
Variable,
300301
Trait,
301-
AsyncBlock,
302302
Bound,
303303
Generic,
304304
ExternFnParam,
@@ -325,7 +325,6 @@ impl std::fmt::Display for ImplTraitPosition {
325325
ImplTraitPosition::Path => "paths",
326326
ImplTraitPosition::Variable => "the type of variable bindings",
327327
ImplTraitPosition::Trait => "traits",
328-
ImplTraitPosition::AsyncBlock => "async blocks",
329328
ImplTraitPosition::Bound => "bounds",
330329
ImplTraitPosition::Generic => "generics",
331330
ImplTraitPosition::ExternFnParam => "`extern fn` parameters",
@@ -751,8 +750,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
751750
self.resolver.get_partial_res(id).map_or(Res::Err, |pr| pr.expect_full_res())
752751
}
753752

754-
fn expect_full_res_from_use(&mut self, id: NodeId) -> impl Iterator<Item = Res<NodeId>> {
755-
self.resolver.get_import_res(id).present_items()
753+
fn lower_import_res(&mut self, id: NodeId, span: Span) -> SmallVec<[Res; 3]> {
754+
let res = self.resolver.get_import_res(id).present_items();
755+
let res: SmallVec<_> = res.map(|res| self.lower_res(res)).collect();
756+
if res.is_empty() {
757+
self.dcx().span_delayed_bug(span, "no resolution for an import");
758+
return smallvec![Res::Err];
759+
}
760+
res
756761
}
757762

758763
fn make_lang_item_qpath(&mut self, lang_item: hir::LangItem, span: Span) -> hir::QPath<'hir> {

compiler/rustc_ast_lowering/src/path.rs

+1
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
196196
p: &Path,
197197
param_mode: ParamMode,
198198
) -> &'hir hir::UsePath<'hir> {
199+
assert!((1..=3).contains(&res.len()));
199200
self.arena.alloc(hir::UsePath {
200201
res,
201202
segments: self.arena.alloc_from_iter(p.segments.iter().map(|segment| {

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+15-8
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
858858
use crate::session_diagnostics::CaptureVarCause::*;
859859
match kind {
860860
hir::ClosureKind::Coroutine(_) => MoveUseInCoroutine { var_span },
861-
hir::ClosureKind::Closure => MoveUseInClosure { var_span },
861+
hir::ClosureKind::Closure | hir::ClosureKind::CoroutineClosure(_) => {
862+
MoveUseInClosure { var_span }
863+
}
862864
}
863865
});
864866

@@ -905,7 +907,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
905907
hir::ClosureKind::Coroutine(_) => {
906908
BorrowUsePlaceCoroutine { place: desc_place, var_span, is_single_var: true }
907909
}
908-
hir::ClosureKind::Closure => {
910+
hir::ClosureKind::Closure | hir::ClosureKind::CoroutineClosure(_) => {
909911
BorrowUsePlaceClosure { place: desc_place, var_span, is_single_var: true }
910912
}
911913
}
@@ -1056,7 +1058,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
10561058
var_span,
10571059
is_single_var: true,
10581060
},
1059-
hir::ClosureKind::Closure => BorrowUsePlaceClosure {
1061+
hir::ClosureKind::Closure
1062+
| hir::ClosureKind::CoroutineClosure(_) => BorrowUsePlaceClosure {
10601063
place: desc_place,
10611064
var_span,
10621065
is_single_var: true,
@@ -1140,7 +1143,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11401143
var_span,
11411144
is_single_var: false,
11421145
},
1143-
hir::ClosureKind::Closure => {
1146+
hir::ClosureKind::Closure | hir::ClosureKind::CoroutineClosure(_) => {
11441147
BorrowUsePlaceClosure { place: desc_place, var_span, is_single_var: false }
11451148
}
11461149
}
@@ -1158,7 +1161,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11581161
hir::ClosureKind::Coroutine(_) => {
11591162
FirstBorrowUsePlaceCoroutine { place: borrow_place_desc, var_span }
11601163
}
1161-
hir::ClosureKind::Closure => {
1164+
hir::ClosureKind::Closure | hir::ClosureKind::CoroutineClosure(_) => {
11621165
FirstBorrowUsePlaceClosure { place: borrow_place_desc, var_span }
11631166
}
11641167
}
@@ -1175,7 +1178,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11751178
hir::ClosureKind::Coroutine(_) => {
11761179
SecondBorrowUsePlaceCoroutine { place: desc_place, var_span }
11771180
}
1178-
hir::ClosureKind::Closure => {
1181+
hir::ClosureKind::Closure | hir::ClosureKind::CoroutineClosure(_) => {
11791182
SecondBorrowUsePlaceClosure { place: desc_place, var_span }
11801183
}
11811184
}
@@ -2942,7 +2945,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
29422945
use crate::session_diagnostics::CaptureVarCause::*;
29432946
match kind {
29442947
hir::ClosureKind::Coroutine(_) => BorrowUseInCoroutine { var_span },
2945-
hir::ClosureKind::Closure => BorrowUseInClosure { var_span },
2948+
hir::ClosureKind::Closure | hir::ClosureKind::CoroutineClosure(_) => {
2949+
BorrowUseInClosure { var_span }
2950+
}
29462951
}
29472952
});
29482953

@@ -2958,7 +2963,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
29582963
use crate::session_diagnostics::CaptureVarCause::*;
29592964
match kind {
29602965
hir::ClosureKind::Coroutine(_) => BorrowUseInCoroutine { var_span },
2961-
hir::ClosureKind::Closure => BorrowUseInClosure { var_span },
2966+
hir::ClosureKind::Closure | hir::ClosureKind::CoroutineClosure(_) => {
2967+
BorrowUseInClosure { var_span }
2968+
}
29622969
}
29632970
});
29642971

compiler/rustc_borrowck/src/diagnostics/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ impl UseSpans<'_> {
614614
PartialAssignment => AssignPartInCoroutine { path_span },
615615
});
616616
}
617-
hir::ClosureKind::Closure => {
617+
hir::ClosureKind::Closure | hir::ClosureKind::CoroutineClosure(_) => {
618618
err.subdiagnostic(match action {
619619
Borrow => BorrowInClosure { path_span },
620620
MatchOn | Use => UseInClosure { path_span },
@@ -1253,7 +1253,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
12531253
hir::ClosureKind::Coroutine(_) => {
12541254
CaptureVarCause::PartialMoveUseInCoroutine { var_span, is_partial }
12551255
}
1256-
hir::ClosureKind::Closure => {
1256+
hir::ClosureKind::Closure | hir::ClosureKind::CoroutineClosure(_) => {
12571257
CaptureVarCause::PartialMoveUseInClosure { var_span, is_partial }
12581258
}
12591259
})

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1472,7 +1472,7 @@ fn suggest_ampmut<'tcx>(
14721472
}
14731473

14741474
fn is_closure_or_coroutine(ty: Ty<'_>) -> bool {
1475-
ty.is_closure() || ty.is_coroutine()
1475+
ty.is_closure() || ty.is_coroutine() || ty.is_coroutine_closure()
14761476
}
14771477

14781478
/// Given a field that needs to be mutable, returns a span where the " mut " could go.

0 commit comments

Comments
 (0)