syntax: revert ast::AsyncArgument and associated changes.
Here follows the main reverts applied in order to make this commit: Revert "Rollup merge of #60676 - davidtwco:issue-60674, r=cramertj" This reverts commit45b09453db, reversing changes made tof6df1f6c30. Revert "Rollup merge of #60437 - davidtwco:issue-60236, r=nikomatsakis" This reverts commit16939a50ea, reversing changes made to12bf981552. Revert "Rollup merge of #59823 - davidtwco:issue-54716, r=cramertj" This reverts commit62d1574876, reversing changes made to4eff8526a7.
This commit is contained in:
committed by
David Wood
parent
c57ed9d947
commit
d0c78dd7aa
@@ -1,9 +1,9 @@
|
||||
// ignore-tidy-filelength
|
||||
|
||||
use crate::ast::{AngleBracketedArgs, AsyncArgument, ParenthesizedArgs, AttrStyle, BareFnTy};
|
||||
use crate::ast::{AngleBracketedArgs, ParenthesizedArgs, AttrStyle, BareFnTy};
|
||||
use crate::ast::{GenericBound, TraitBoundModifier};
|
||||
use crate::ast::Unsafety;
|
||||
use crate::ast::{Mod, AnonConst, Arg, ArgSource, Arm, Guard, Attribute, BindingMode, TraitItemKind};
|
||||
use crate::ast::{Mod, AnonConst, Arg, Arm, Guard, Attribute, BindingMode, TraitItemKind};
|
||||
use crate::ast::Block;
|
||||
use crate::ast::{BlockCheckMode, CaptureBy, Movability};
|
||||
use crate::ast::{Constness, Crate};
|
||||
@@ -16,7 +16,7 @@ use crate::ast::{GenericParam, GenericParamKind};
|
||||
use crate::ast::GenericArg;
|
||||
use crate::ast::{Ident, ImplItem, IsAsync, IsAuto, Item, ItemKind};
|
||||
use crate::ast::{Label, Lifetime};
|
||||
use crate::ast::{Local, LocalSource};
|
||||
use crate::ast::Local;
|
||||
use crate::ast::MacStmtStyle;
|
||||
use crate::ast::{Mac, Mac_, MacDelimiter};
|
||||
use crate::ast::{MutTy, Mutability};
|
||||
@@ -51,7 +51,7 @@ use crate::parse::diagnostics::{Error, dummy_arg};
|
||||
|
||||
use errors::{Applicability, DiagnosticBuilder, DiagnosticId, FatalError};
|
||||
use rustc_target::spec::abi::{self, Abi};
|
||||
use syntax_pos::{Span, BytePos, DUMMY_SP, FileName, hygiene::CompilerDesugaringKind};
|
||||
use syntax_pos::{Span, BytePos, DUMMY_SP, FileName};
|
||||
use log::debug;
|
||||
|
||||
use std::borrow::Cow;
|
||||
@@ -1126,7 +1126,6 @@ impl<'a> Parser<'a> {
|
||||
IsAsync::Async {
|
||||
closure_id: ast::DUMMY_NODE_ID,
|
||||
return_impl_trait_id: ast::DUMMY_NODE_ID,
|
||||
arguments: Vec::new(),
|
||||
}
|
||||
} else {
|
||||
IsAsync::NotAsync
|
||||
@@ -1185,12 +1184,12 @@ impl<'a> Parser<'a> {
|
||||
// trait item macro.
|
||||
(Ident::invalid(), ast::TraitItemKind::Macro(mac), ast::Generics::default())
|
||||
} else {
|
||||
let (constness, unsafety, mut asyncness, abi) = self.parse_fn_front_matter()?;
|
||||
let (constness, unsafety, asyncness, abi) = self.parse_fn_front_matter()?;
|
||||
|
||||
let ident = self.parse_ident()?;
|
||||
let mut generics = self.parse_generics()?;
|
||||
|
||||
let mut decl = self.parse_fn_decl_with_self(|p: &mut Parser<'a>| {
|
||||
let decl = self.parse_fn_decl_with_self(|p: &mut Parser<'a>| {
|
||||
// This is somewhat dubious; We don't want to allow
|
||||
// argument names to be left off if there is a
|
||||
// definition...
|
||||
@@ -1199,7 +1198,6 @@ impl<'a> Parser<'a> {
|
||||
p.parse_arg_general(p.span.rust_2018(), true, false)
|
||||
})?;
|
||||
generics.where_clause = self.parse_where_clause()?;
|
||||
self.construct_async_arguments(&mut asyncness, &mut decl);
|
||||
|
||||
let sig = ast::MethodSig {
|
||||
header: FnHeader {
|
||||
@@ -1563,7 +1561,7 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
};
|
||||
|
||||
Ok(Arg { ty, pat, id: ast::DUMMY_NODE_ID, source: ast::ArgSource::Normal })
|
||||
Ok(Arg { ty, pat, id: ast::DUMMY_NODE_ID })
|
||||
}
|
||||
|
||||
/// Parses an argument in a lambda header (e.g., `|arg, arg|`).
|
||||
@@ -1581,8 +1579,7 @@ impl<'a> Parser<'a> {
|
||||
Ok(Arg {
|
||||
ty: t,
|
||||
pat,
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
source: ast::ArgSource::Normal,
|
||||
id: ast::DUMMY_NODE_ID
|
||||
})
|
||||
}
|
||||
|
||||
@@ -4213,7 +4210,6 @@ impl<'a> Parser<'a> {
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
span: lo.to(hi),
|
||||
attrs,
|
||||
source: LocalSource::Normal,
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -5660,16 +5656,15 @@ impl<'a> Parser<'a> {
|
||||
/// Parses an item-position function declaration.
|
||||
fn parse_item_fn(&mut self,
|
||||
unsafety: Unsafety,
|
||||
mut asyncness: Spanned<IsAsync>,
|
||||
asyncness: Spanned<IsAsync>,
|
||||
constness: Spanned<Constness>,
|
||||
abi: Abi)
|
||||
-> PResult<'a, ItemInfo> {
|
||||
let (ident, mut generics) = self.parse_fn_header()?;
|
||||
let allow_c_variadic = abi == Abi::C && unsafety == Unsafety::Unsafe;
|
||||
let mut decl = self.parse_fn_decl(allow_c_variadic)?;
|
||||
let decl = self.parse_fn_decl(allow_c_variadic)?;
|
||||
generics.where_clause = self.parse_where_clause()?;
|
||||
let (inner_attrs, body) = self.parse_inner_attrs_and_block()?;
|
||||
self.construct_async_arguments(&mut asyncness, &mut decl);
|
||||
let header = FnHeader { unsafety, asyncness, constness, abi };
|
||||
Ok((ident, ItemKind::Fn(decl, header, generics, body), Some(inner_attrs)))
|
||||
}
|
||||
@@ -5849,14 +5844,13 @@ impl<'a> Parser<'a> {
|
||||
Ok((Ident::invalid(), vec![], ast::Generics::default(),
|
||||
ast::ImplItemKind::Macro(mac)))
|
||||
} else {
|
||||
let (constness, unsafety, mut asyncness, abi) = self.parse_fn_front_matter()?;
|
||||
let (constness, unsafety, asyncness, abi) = self.parse_fn_front_matter()?;
|
||||
let ident = self.parse_ident()?;
|
||||
let mut generics = self.parse_generics()?;
|
||||
let mut decl = self.parse_fn_decl_with_self(|p| {
|
||||
let decl = self.parse_fn_decl_with_self(|p| {
|
||||
p.parse_arg_general(true, true, false)
|
||||
})?;
|
||||
generics.where_clause = self.parse_where_clause()?;
|
||||
self.construct_async_arguments(&mut asyncness, &mut decl);
|
||||
*at_end = true;
|
||||
let (inner_attrs, body) = self.parse_inner_attrs_and_block()?;
|
||||
let header = ast::FnHeader { abi, unsafety, constness, asyncness };
|
||||
@@ -7218,7 +7212,6 @@ impl<'a> Parser<'a> {
|
||||
respan(async_span, IsAsync::Async {
|
||||
closure_id: ast::DUMMY_NODE_ID,
|
||||
return_impl_trait_id: ast::DUMMY_NODE_ID,
|
||||
arguments: Vec::new(),
|
||||
}),
|
||||
respan(fn_span, Constness::NotConst),
|
||||
Abi::Rust)?;
|
||||
@@ -7849,116 +7842,6 @@ impl<'a> Parser<'a> {
|
||||
Applicability::MaybeIncorrect,
|
||||
).emit();
|
||||
}
|
||||
|
||||
/// When lowering a `async fn` to the HIR, we need to move all of the arguments of the function
|
||||
/// into the generated closure so that they are dropped when the future is polled and not when
|
||||
/// it is created.
|
||||
///
|
||||
/// The arguments of the function are replaced in HIR lowering with the arguments created by
|
||||
/// this function and the statements created here are inserted at the top of the closure body.
|
||||
fn construct_async_arguments(&mut self, asyncness: &mut Spanned<IsAsync>, decl: &mut FnDecl) {
|
||||
// FIXME(davidtwco): This function should really live in the HIR lowering but because
|
||||
// the types constructed here need to be used in parts of resolve so that the correct
|
||||
// locals are considered upvars, it is currently easier for it to live here in the parser,
|
||||
// where it can be constructed once.
|
||||
if let IsAsync::Async { ref mut arguments, .. } = asyncness.node {
|
||||
for (index, input) in decl.inputs.iter_mut().enumerate() {
|
||||
let id = ast::DUMMY_NODE_ID;
|
||||
let span = input.pat.span;
|
||||
let desugared_span = self.sess.source_map()
|
||||
.mark_span_with_reason(CompilerDesugaringKind::Async, span, None);
|
||||
|
||||
// Construct a name for our temporary argument.
|
||||
let name = format!("__arg{}", index);
|
||||
let ident = Ident::from_str(&name).gensym();
|
||||
|
||||
// Check if this is a ident pattern, if so, we can optimize and avoid adding a
|
||||
// `let <pat> = __argN;` statement, instead just adding a `let <pat> = <pat>;`
|
||||
// statement.
|
||||
let (binding_mode, ident, is_simple_pattern) = match input.pat.node {
|
||||
PatKind::Ident(binding_mode @ BindingMode::ByValue(_), ident, _) => {
|
||||
// Simple patterns like this don't have a generated argument, but they are
|
||||
// moved into the closure with a statement, so any `mut` bindings on the
|
||||
// argument will be unused. This binding mode can't be removed, because
|
||||
// this would affect the input to procedural macros, but they can have
|
||||
// their span marked as being the result of a compiler desugaring so
|
||||
// that they aren't linted against.
|
||||
input.pat.span = desugared_span;
|
||||
|
||||
(binding_mode, ident, true)
|
||||
}
|
||||
_ => (BindingMode::ByValue(Mutability::Mutable), ident, false),
|
||||
};
|
||||
|
||||
// Construct an argument representing `__argN: <ty>` to replace the argument of the
|
||||
// async function if it isn't a simple pattern.
|
||||
let arg = if is_simple_pattern {
|
||||
None
|
||||
} else {
|
||||
Some(Arg {
|
||||
ty: input.ty.clone(),
|
||||
id,
|
||||
pat: P(Pat {
|
||||
id,
|
||||
node: PatKind::Ident(
|
||||
BindingMode::ByValue(Mutability::Immutable), ident, None,
|
||||
),
|
||||
span: desugared_span,
|
||||
}),
|
||||
source: ArgSource::AsyncFn(input.pat.clone()),
|
||||
})
|
||||
};
|
||||
|
||||
// Construct a `let __argN = __argN;` statement to insert at the top of the
|
||||
// async closure. This makes sure that the argument is captured by the closure and
|
||||
// that the drop order is correct.
|
||||
let move_local = Local {
|
||||
pat: P(Pat {
|
||||
id,
|
||||
node: PatKind::Ident(binding_mode, ident, None),
|
||||
span: desugared_span,
|
||||
}),
|
||||
// We explicitly do not specify the type for this statement. When the user's
|
||||
// argument type is `impl Trait` then this would require the
|
||||
// `impl_trait_in_bindings` feature to also be present for that same type to
|
||||
// be valid in this binding. At the time of writing (13 Mar 19),
|
||||
// `impl_trait_in_bindings` is not stable.
|
||||
ty: None,
|
||||
init: Some(P(Expr {
|
||||
id,
|
||||
node: ExprKind::Path(None, ast::Path {
|
||||
span,
|
||||
segments: vec![PathSegment { ident, id, args: None }],
|
||||
}),
|
||||
span,
|
||||
attrs: ThinVec::new(),
|
||||
})),
|
||||
id,
|
||||
span,
|
||||
attrs: ThinVec::new(),
|
||||
source: LocalSource::AsyncFn,
|
||||
};
|
||||
|
||||
// Construct a `let <pat> = __argN;` statement to insert at the top of the
|
||||
// async closure if this isn't a simple pattern.
|
||||
let pat_stmt = if is_simple_pattern {
|
||||
None
|
||||
} else {
|
||||
Some(Stmt {
|
||||
id,
|
||||
node: StmtKind::Local(P(Local {
|
||||
pat: input.pat.clone(),
|
||||
..move_local.clone()
|
||||
})),
|
||||
span,
|
||||
})
|
||||
};
|
||||
|
||||
let move_stmt = Stmt { id, node: StmtKind::Local(P(move_local)), span };
|
||||
arguments.push(AsyncArgument { ident, arg, pat_stmt, move_stmt });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn emit_unclosed_delims(unclosed_delims: &mut Vec<UnmatchedBrace>, handler: &errors::Handler) {
|
||||
|
||||
Reference in New Issue
Block a user