diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-05-03 16:25:09 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-05-03 16:25:09 +0200 |
| commit | 6f7a1eabdf2770d1a83ad6f1968162f64b36a13d (patch) | |
| tree | 928e4e1504008643140afc74d2c998e62e0947e9 | |
| parent | d5809a8b3365dbecff4e31e10d8f8bb064232fb7 (diff) | |
| parent | 2fe50bc01bf9023b64a72407bb41a1f3b7245abd (diff) | |
| download | rust-6f7a1eabdf2770d1a83ad6f1968162f64b36a13d.tar.gz rust-6f7a1eabdf2770d1a83ad6f1968162f64b36a13d.zip | |
Rollup merge of #60501 - taiki-e:async-await-mutable-arguments, r=cramertj
Propagate mutability from arguments to local bindings in async fn Fixes #60498 cc @nikomatsakis r? @davidtwco
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 10 | ||||
| -rw-r--r-- | src/test/ui/async-await/mutable-arguments.rs | 10 |
2 files changed, 14 insertions, 6 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index f70acb3e7da..c5173aa5569 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -8725,9 +8725,9 @@ impl<'a> Parser<'a> { // 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 (ident, is_simple_pattern) = match input.pat.node { - PatKind::Ident(_, ident, _) => (ident, true), - _ => (ident, false), + let (binding_mode, ident, is_simple_pattern) = match input.pat.node { + PatKind::Ident(binding_mode, ident, _) => (binding_mode, ident, true), + _ => (BindingMode::ByValue(Mutability::Immutable), ident, false), }; // Construct an argument representing `__argN: <ty>` to replace the argument of the @@ -8755,9 +8755,7 @@ impl<'a> Parser<'a> { let move_local = Local { pat: P(Pat { id, - node: PatKind::Ident( - BindingMode::ByValue(Mutability::Immutable), ident, None, - ), + node: PatKind::Ident(binding_mode, ident, None), span, }), // We explicitly do not specify the type for this statement. When the user's diff --git a/src/test/ui/async-await/mutable-arguments.rs b/src/test/ui/async-await/mutable-arguments.rs new file mode 100644 index 00000000000..4d6dba74097 --- /dev/null +++ b/src/test/ui/async-await/mutable-arguments.rs @@ -0,0 +1,10 @@ +// edition:2018 +// run-pass + +#![feature(async_await)] + +async fn foo(n: u32, mut vec: Vec<u32>) { + vec.push(n); +} + +fn main() {} |
