Skip to content

Commit d0c78dd

Browse files
eddybdavidtwco
authored andcommitted
syntax: revert ast::AsyncArgument and associated changes.
Here follows the main reverts applied in order to make this commit: Revert "Rollup merge of rust-lang#60676 - davidtwco:issue-60674, r=cramertj" This reverts commit 45b0945, reversing changes made to f6df1f6. Revert "Rollup merge of rust-lang#60437 - davidtwco:issue-60236, r=nikomatsakis" This reverts commit 16939a5, reversing changes made to 12bf981. Revert "Rollup merge of rust-lang#59823 - davidtwco:issue-54716, r=cramertj" This reverts commit 62d1574, reversing changes made to 4eff852.
1 parent c57ed9d commit d0c78dd

File tree

15 files changed

+108
-520
lines changed

15 files changed

+108
-520
lines changed

src/librustc/hir/lowering.rs

+37-150
Original file line numberDiff line numberDiff line change
@@ -465,32 +465,6 @@ impl<'a> LoweringContext<'a> {
465465
visit::walk_pat(self, p)
466466
}
467467

468-
fn visit_fn(&mut self, fk: visit::FnKind<'lcx>, fd: &'lcx FnDecl, s: Span, _: NodeId) {
469-
if fk.header().map(|h| h.asyncness.node.is_async()).unwrap_or(false) {
470-
// Don't visit the original pattern for async functions as it will be
471-
// replaced.
472-
for arg in &fd.inputs {
473-
if let ArgSource::AsyncFn(pat) = &arg.source { self.visit_pat(pat); }
474-
self.visit_ty(&arg.ty)
475-
}
476-
self.visit_fn_ret_ty(&fd.output);
477-
478-
match fk {
479-
visit::FnKind::ItemFn(_, decl, _, body) => {
480-
self.visit_fn_header(decl);
481-
self.visit_block(body)
482-
},
483-
visit::FnKind::Method(_, sig, _, body) => {
484-
self.visit_fn_header(&sig.header);
485-
self.visit_block(body)
486-
},
487-
visit::FnKind::Closure(body) => self.visit_expr(body),
488-
}
489-
} else {
490-
visit::walk_fn(self, fk, fd, s)
491-
}
492-
}
493-
494468
fn visit_item(&mut self, item: &'lcx Item) {
495469
let hir_id = self.lctx.allocate_hir_id_counter(item.id);
496470

@@ -2266,17 +2240,10 @@ impl<'a> LoweringContext<'a> {
22662240
init: l.init.as_ref().map(|e| P(self.lower_expr(e))),
22672241
span: l.span,
22682242
attrs: l.attrs.clone(),
2269-
source: self.lower_local_source(l.source),
2243+
source: hir::LocalSource::Normal,
22702244
}, ids)
22712245
}
22722246

2273-
fn lower_local_source(&mut self, ls: LocalSource) -> hir::LocalSource {
2274-
match ls {
2275-
LocalSource::Normal => hir::LocalSource::Normal,
2276-
LocalSource::AsyncFn => hir::LocalSource::AsyncFn,
2277-
}
2278-
}
2279-
22802247
fn lower_mutability(&mut self, m: Mutability) -> hir::Mutability {
22812248
match m {
22822249
Mutability::Mutable => hir::MutMutable,
@@ -2292,14 +2259,7 @@ impl<'a> LoweringContext<'a> {
22922259
hir::Arg {
22932260
hir_id: self.lower_node_id(arg.id),
22942261
pat: self.lower_pat(&arg.pat),
2295-
source: self.lower_arg_source(&arg.source),
2296-
}
2297-
}
2298-
2299-
fn lower_arg_source(&mut self, source: &ArgSource) -> hir::ArgSource {
2300-
match source {
2301-
ArgSource::Normal => hir::ArgSource::Normal,
2302-
ArgSource::AsyncFn(pat) => hir::ArgSource::AsyncFn(self.lower_pat(pat)),
2262+
source: hir::ArgSource::Normal,
23032263
}
23042264
}
23052265

@@ -3028,44 +2988,13 @@ impl<'a> LoweringContext<'a> {
30282988
fn lower_async_body(
30292989
&mut self,
30302990
decl: &FnDecl,
3031-
asyncness: &IsAsync,
2991+
asyncness: IsAsync,
30322992
body: &Block,
30332993
) -> hir::BodyId {
30342994
self.lower_body(Some(&decl), |this| {
3035-
if let IsAsync::Async { closure_id, ref arguments, .. } = asyncness {
3036-
let mut body = body.clone();
3037-
3038-
// Async function arguments are lowered into the closure body so that they are
3039-
// captured and so that the drop order matches the equivalent non-async functions.
3040-
//
3041-
// async fn foo(<pattern>: <ty>, <pattern>: <ty>, <pattern>: <ty>) {
3042-
// async move {
3043-
// }
3044-
// }
3045-
//
3046-
// // ...becomes...
3047-
// fn foo(__arg0: <ty>, __arg1: <ty>, __arg2: <ty>) {
3048-
// async move {
3049-
// let __arg2 = __arg2;
3050-
// let <pattern> = __arg2;
3051-
// let __arg1 = __arg1;
3052-
// let <pattern> = __arg1;
3053-
// let __arg0 = __arg0;
3054-
// let <pattern> = __arg0;
3055-
// }
3056-
// }
3057-
//
3058-
// If `<pattern>` is a simple ident, then it is lowered to a single
3059-
// `let <pattern> = <pattern>;` statement as an optimization.
3060-
for a in arguments.iter().rev() {
3061-
if let Some(pat_stmt) = a.pat_stmt.clone() {
3062-
body.stmts.insert(0, pat_stmt);
3063-
}
3064-
body.stmts.insert(0, a.move_stmt.clone());
3065-
}
3066-
2995+
if let IsAsync::Async { closure_id, .. } = asyncness {
30672996
let async_expr = this.make_async_expr(
3068-
CaptureBy::Value, *closure_id, None, body.span,
2997+
CaptureBy::Value, closure_id, None, body.span,
30692998
|this| {
30702999
let body = this.lower_block(&body, false);
30713000
this.expr_block(body, ThinVec::new())
@@ -3126,47 +3055,26 @@ impl<'a> LoweringContext<'a> {
31263055
value
31273056
)
31283057
}
3129-
ItemKind::Fn(ref decl, ref header, ref generics, ref body) => {
3058+
ItemKind::Fn(ref decl, header, ref generics, ref body) => {
31303059
let fn_def_id = self.resolver.definitions().local_def_id(id);
31313060
self.with_new_scopes(|this| {
3061+
// Note: we don't need to change the return type from `T` to
3062+
// `impl Future<Output = T>` here because lower_body
3063+
// only cares about the input argument patterns in the function
3064+
// declaration (decl), not the return types.
3065+
let body_id = this.lower_async_body(decl, header.asyncness.node, body);
3066+
let (generics, fn_decl) = this.add_in_band_defs(
3067+
generics,
3068+
fn_def_id,
3069+
AnonymousLifetimeMode::PassThrough,
3070+
|this, idty| this.lower_fn_decl(
3071+
decl,
3072+
Some((fn_def_id, idty)),
3073+
true,
3074+
header.asyncness.node.opt_return_id()
3075+
),
3076+
);
31323077
this.current_item = Some(ident.span);
3133-
let mut lower_fn = |decl: &FnDecl| {
3134-
// Note: we don't need to change the return type from `T` to
3135-
// `impl Future<Output = T>` here because lower_body
3136-
// only cares about the input argument patterns in the function
3137-
// declaration (decl), not the return types.
3138-
let body_id = this.lower_async_body(&decl, &header.asyncness.node, body);
3139-
3140-
let (generics, fn_decl) = this.add_in_band_defs(
3141-
generics,
3142-
fn_def_id,
3143-
AnonymousLifetimeMode::PassThrough,
3144-
|this, idty| this.lower_fn_decl(
3145-
&decl,
3146-
Some((fn_def_id, idty)),
3147-
true,
3148-
header.asyncness.node.opt_return_id()
3149-
),
3150-
);
3151-
3152-
(body_id, generics, fn_decl)
3153-
};
3154-
3155-
let (body_id, generics, fn_decl) = if let IsAsync::Async {
3156-
arguments, ..
3157-
} = &header.asyncness.node {
3158-
let mut decl = decl.clone();
3159-
// Replace the arguments of this async function with the generated
3160-
// arguments that will be moved into the closure.
3161-
for (i, a) in arguments.clone().drain(..).enumerate() {
3162-
if let Some(arg) = a.arg {
3163-
decl.inputs[i] = arg;
3164-
}
3165-
}
3166-
lower_fn(&decl)
3167-
} else {
3168-
lower_fn(decl)
3169-
};
31703078

31713079
hir::ItemKind::Fn(
31723080
fn_decl,
@@ -3638,36 +3546,15 @@ impl<'a> LoweringContext<'a> {
36383546
)
36393547
}
36403548
ImplItemKind::Method(ref sig, ref body) => {
3641-
let mut lower_method = |sig: &MethodSig| {
3642-
let body_id = self.lower_async_body(
3643-
&sig.decl, &sig.header.asyncness.node, body
3644-
);
3645-
let impl_trait_return_allow = !self.is_in_trait_impl;
3646-
let (generics, sig) = self.lower_method_sig(
3647-
&i.generics,
3648-
sig,
3649-
impl_item_def_id,
3650-
impl_trait_return_allow,
3651-
sig.header.asyncness.node.opt_return_id(),
3652-
);
3653-
(body_id, generics, sig)
3654-
};
3655-
3656-
let (body_id, generics, sig) = if let IsAsync::Async {
3657-
ref arguments, ..
3658-
} = sig.header.asyncness.node {
3659-
let mut sig = sig.clone();
3660-
// Replace the arguments of this async function with the generated
3661-
// arguments that will be moved into the closure.
3662-
for (i, a) in arguments.clone().drain(..).enumerate() {
3663-
if let Some(arg) = a.arg {
3664-
sig.decl.inputs[i] = arg;
3665-
}
3666-
}
3667-
lower_method(&sig)
3668-
} else {
3669-
lower_method(sig)
3670-
};
3549+
let body_id = self.lower_async_body(&sig.decl, sig.header.asyncness.node, body);
3550+
let impl_trait_return_allow = !self.is_in_trait_impl;
3551+
let (generics, sig) = self.lower_method_sig(
3552+
&i.generics,
3553+
sig,
3554+
impl_item_def_id,
3555+
impl_trait_return_allow,
3556+
sig.header.asyncness.node.opt_return_id(),
3557+
);
36713558
self.current_item = Some(i.span);
36723559

36733560
(generics, hir::ImplItemKind::Method(sig, body_id))
@@ -3860,7 +3747,7 @@ impl<'a> LoweringContext<'a> {
38603747
impl_trait_return_allow: bool,
38613748
is_async: Option<NodeId>,
38623749
) -> (hir::Generics, hir::MethodSig) {
3863-
let header = self.lower_fn_header(&sig.header);
3750+
let header = self.lower_fn_header(sig.header);
38643751
let (generics, decl) = self.add_in_band_defs(
38653752
generics,
38663753
fn_def_id,
@@ -3882,10 +3769,10 @@ impl<'a> LoweringContext<'a> {
38823769
}
38833770
}
38843771

3885-
fn lower_fn_header(&mut self, h: &FnHeader) -> hir::FnHeader {
3772+
fn lower_fn_header(&mut self, h: FnHeader) -> hir::FnHeader {
38863773
hir::FnHeader {
38873774
unsafety: self.lower_unsafety(h.unsafety),
3888-
asyncness: self.lower_asyncness(&h.asyncness.node),
3775+
asyncness: self.lower_asyncness(h.asyncness.node),
38893776
constness: self.lower_constness(h.constness),
38903777
abi: h.abi,
38913778
}
@@ -3905,7 +3792,7 @@ impl<'a> LoweringContext<'a> {
39053792
}
39063793
}
39073794

3908-
fn lower_asyncness(&mut self, a: &IsAsync) -> hir::IsAsync {
3795+
fn lower_asyncness(&mut self, a: IsAsync) -> hir::IsAsync {
39093796
match a {
39103797
IsAsync::Async { .. } => hir::IsAsync::Async,
39113798
IsAsync::NotAsync => hir::IsAsync::NotAsync,
@@ -4222,7 +4109,7 @@ impl<'a> LoweringContext<'a> {
42224109
}
42234110
ExprKind::Await(_origin, ref expr) => self.lower_await(e.span, expr),
42244111
ExprKind::Closure(
4225-
capture_clause, ref asyncness, movability, ref decl, ref body, fn_decl_span
4112+
capture_clause, asyncness, movability, ref decl, ref body, fn_decl_span
42264113
) => {
42274114
if let IsAsync::Async { closure_id, .. } = asyncness {
42284115
let outer_decl = FnDecl {
@@ -4260,7 +4147,7 @@ impl<'a> LoweringContext<'a> {
42604147
Some(&**ty)
42614148
} else { None };
42624149
let async_body = this.make_async_expr(
4263-
capture_clause, *closure_id, async_ret_ty, body.span,
4150+
capture_clause, closure_id, async_ret_ty, body.span,
42644151
|this| {
42654152
this.with_new_scopes(|this| this.lower_expr(body))
42664153
});

src/librustc/hir/map/def_collector.rs

+9-32
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,16 @@ impl<'a> DefCollector<'a> {
6464
id: NodeId,
6565
name: Name,
6666
span: Span,
67-
header: &'a FnHeader,
67+
header: &FnHeader,
6868
generics: &'a Generics,
6969
decl: &'a FnDecl,
7070
body: &'a Block,
7171
) {
72-
let (closure_id, return_impl_trait_id, arguments) = match &header.asyncness.node {
72+
let (closure_id, return_impl_trait_id) = match header.asyncness.node {
7373
IsAsync::Async {
7474
closure_id,
7575
return_impl_trait_id,
76-
arguments,
77-
} => (closure_id, return_impl_trait_id, arguments),
76+
} => (closure_id, return_impl_trait_id),
7877
_ => unreachable!(),
7978
};
8079

@@ -83,38 +82,16 @@ impl<'a> DefCollector<'a> {
8382
let fn_def_data = DefPathData::ValueNs(name.as_interned_str());
8483
let fn_def = self.create_def(id, fn_def_data, span);
8584
return self.with_parent(fn_def, |this| {
86-
this.create_def(*return_impl_trait_id, DefPathData::ImplTrait, span);
85+
this.create_def(return_impl_trait_id, DefPathData::ImplTrait, span);
8786

8887
visit::walk_generics(this, generics);
89-
90-
// Walk the generated arguments for the `async fn`.
91-
for (i, a) in arguments.iter().enumerate() {
92-
use visit::Visitor;
93-
if let Some(arg) = &a.arg {
94-
this.visit_ty(&arg.ty);
95-
} else {
96-
this.visit_ty(&decl.inputs[i].ty);
97-
}
98-
}
99-
100-
// We do not invoke `walk_fn_decl` as this will walk the arguments that are being
101-
// replaced.
102-
visit::walk_fn_ret_ty(this, &decl.output);
88+
visit::walk_fn_decl(this, decl);
10389

10490
let closure_def = this.create_def(
105-
*closure_id, DefPathData::ClosureExpr, span,
91+
closure_id, DefPathData::ClosureExpr, span,
10692
);
10793
this.with_parent(closure_def, |this| {
108-
use visit::Visitor;
109-
// Walk each of the generated statements before the regular block body.
110-
for a in arguments {
111-
this.visit_stmt(&a.move_stmt);
112-
if let Some(pat_stmt) = &a.pat_stmt {
113-
this.visit_stmt(&pat_stmt);
114-
}
115-
}
116-
117-
visit::walk_block(this, &body);
94+
visit::walk_block(this, body);
11895
})
11996
})
12097
}
@@ -302,7 +279,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
302279

303280
match expr.node {
304281
ExprKind::Mac(..) => return self.visit_macro_invoc(expr.id),
305-
ExprKind::Closure(_, ref asyncness, ..) => {
282+
ExprKind::Closure(_, asyncness, ..) => {
306283
let closure_def = self.create_def(expr.id,
307284
DefPathData::ClosureExpr,
308285
expr.span);
@@ -311,7 +288,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
311288
// Async closures desugar to closures inside of closures, so
312289
// we must create two defs.
313290
if let IsAsync::Async { closure_id, .. } = asyncness {
314-
let async_def = self.create_def(*closure_id,
291+
let async_def = self.create_def(closure_id,
315292
DefPathData::ClosureExpr,
316293
expr.span);
317294
self.parent_def = Some(async_def);

src/librustc/lint/context.rs

-24
Original file line numberDiff line numberDiff line change
@@ -1335,30 +1335,6 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
13351335

13361336
run_early_pass!(self, check_mac, mac);
13371337
}
1338-
1339-
fn visit_fn_header(&mut self, header: &'a ast::FnHeader) {
1340-
// Unlike in HIR lowering and name resolution, the `AsyncArgument` statements are not added
1341-
// to the function body and the arguments do not replace those in the declaration. They are
1342-
// still visited manually here so that buffered lints can be emitted.
1343-
if let ast::IsAsync::Async { ref arguments, .. } = header.asyncness.node {
1344-
for a in arguments {
1345-
// Visit the argument..
1346-
if let Some(arg) = &a.arg {
1347-
self.visit_pat(&arg.pat);
1348-
if let ast::ArgSource::AsyncFn(pat) = &arg.source {
1349-
self.visit_pat(pat);
1350-
}
1351-
self.visit_ty(&arg.ty);
1352-
}
1353-
1354-
// ..and the statement.
1355-
self.visit_stmt(&a.move_stmt);
1356-
if let Some(pat_stmt) = &a.pat_stmt {
1357-
self.visit_stmt(&pat_stmt);
1358-
}
1359-
}
1360-
}
1361-
}
13621338
}
13631339

13641340
struct LateLintPassObjects<'a> {

0 commit comments

Comments
 (0)