about summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-06-04 05:37:44 +0000
committerbors <bors@rust-lang.org>2019-06-04 05:37:44 +0000
commitc22ce2806c3198c9a2b90b78d00c5451593c833f (patch)
treecddcdf9c039932b2d5d48e4e3a8c05ffd865c54c /src/libsyntax/parse
parentdc7c4aa804c4f26ba6de8a39d3c8eea88e8b8938 (diff)
parent5baa58ea5f6d69e07054a3dde21e7b0ef8c75a1b (diff)
downloadrust-c22ce2806c3198c9a2b90b78d00c5451593c833f.tar.gz
rust-c22ce2806c3198c9a2b90b78d00c5451593c833f.zip
Auto merge of #61510 - Centril:rollup-bvi95y2, r=Centril
Rollup of 13 pull requests

Successful merges:

 - #61135 (Fix documentation of `Rc::make_mut` regarding `rc::Weak`.)
 - #61404 (miri unsizing: fix projecting into a field of an operand)
 - #61409 (Fix an ICE with a const argument in a trait)
 - #61413 (Re-implement async fn drop order lowering )
 - #61419 (Add an unusual-conversion example to to_uppercase)
 - #61420 (Succinctify splice docs)
 - #61444 (Suggest using `as_ref` on `*const T`)
 - #61446 (On TerminatorKind::DropAndReplace still handle unused_mut correctly)
 - #61485 (azure: retry s3 upload if it fails)
 - #61489 (ci: Reenable step timings on AppVeyor)
 - #61496 (Do not panic in tidy on unbalanced parentheses in cfg's)
 - #61497 (Treat 0 as special value for codegen-units-std)
 - #61499 (Add regression test for existential type ICE #53457)

Failed merges:

r? @ghost
Diffstat (limited to 'src/libsyntax/parse')
-rw-r--r--src/libsyntax/parse/diagnostics.rs2
-rw-r--r--src/libsyntax/parse/parser.rs151
2 files changed, 20 insertions, 133 deletions
diff --git a/src/libsyntax/parse/diagnostics.rs b/src/libsyntax/parse/diagnostics.rs
index af9092dd5b0..5df22f28797 100644
--- a/src/libsyntax/parse/diagnostics.rs
+++ b/src/libsyntax/parse/diagnostics.rs
@@ -27,7 +27,7 @@ crate fn dummy_arg(ident: Ident) -> Arg {
         span: ident.span,
         id: ast::DUMMY_NODE_ID
     };
-    Arg { ty: P(ty), pat: pat, id: ast::DUMMY_NODE_ID, source: ast::ArgSource::Normal }
+    Arg { ty: P(ty), pat: pat, id: ast::DUMMY_NODE_ID }
 }
 
 pub enum Error {
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index f200d3ec8d5..ae1e5116c67 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -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,
         }))
     }
 
@@ -5244,9 +5240,13 @@ impl<'a> Parser<'a> {
                     // FIXME(const_generics): to distinguish between idents for types and consts,
                     // we should introduce a GenericArg::Ident in the AST and distinguish when
                     // lowering to the HIR. For now, idents for const args are not permitted.
-                    return Err(
-                        self.fatal("identifiers may currently not be used for const generics")
-                    );
+                    if self.token.is_keyword(kw::True) || self.token.is_keyword(kw::False) {
+                        self.parse_literal_maybe_minus()?
+                    } else {
+                        return Err(
+                            self.fatal("identifiers may currently not be used for const generics")
+                        );
+                    }
                 } else {
                     self.parse_literal_maybe_minus()?
                 };
@@ -5660,16 +5660,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 +5848,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 +7216,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 +7846,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) {