Commit graph

2630 commits

Author SHA1 Message Date
Mazdak Farrokhzad
16939a50ea
Rollup merge of #60437 - davidtwco:issue-60236, r=nikomatsakis
Ensure that drop order of `async fn` matches `fn` and that users cannot refer to generated arguments.

Fixes #60236 and fixes #60438.

This PR modifies the lowering of `async fn` arguments so that the
drop order matches the equivalent `fn`.

Previously, async function arguments were lowered as shown below:

    async fn foo(<pattern>: <ty>) {
      async move {
      }
    } // <-- dropped as you "exit" the fn

    // ...becomes...
    fn foo(__arg0: <ty>) {
      async move {
        let <pattern> = __arg0;
      } // <-- dropped as you "exit" the async block
    }

After this PR, async function arguments will be lowered as:

    async fn foo(<pattern>: <ty>, <pattern>: <ty>, <pattern>: <ty>) {
      async move {
      }
    } // <-- dropped as you "exit" the fn

    // ...becomes...
    fn foo(__arg0: <ty>, __arg1: <ty>, __arg2: <ty>) {
      async move {
        let __arg2 = __arg2;
        let <pattern> = __arg2;
        let __arg1 = __arg1;
        let <pattern> = __arg1;
        let __arg0 = __arg0;
        let <pattern> = __arg0;
      } // <-- dropped as you "exit" the async block
    }

If `<pattern>` is a simple ident, then it is lowered to a single
`let <pattern> = <pattern>;` statement as an optimization.

This PR also stops users from referring to the generated `__argN`
identifiers.

r? @nikomatsakis
2019-05-02 01:09:29 +02:00
David Wood
f47735c3dc
Ensure that users cannot use generated arguments.
This commit gensyms the generated ident for replacement arguments so
that users cannot refer to them. It also ensures that levenshtein
distance suggestions do not suggest gensymed identifiers.
2019-05-01 15:00:43 +01:00
David Wood
b05d5db87b
Ensure that drop order of async fn matches fn.
This commit modifies the lowering of `async fn` arguments so that the
drop order matches the equivalent `fn`.

Previously, async function arguments were lowered as shown below:

    async fn foo(<pattern>: <ty>) {
      async move {
      }
    } // <-- dropped as you "exit" the fn

    // ...becomes...
    fn foo(__arg0: <ty>) {
      async move {
        let <pattern> = __arg0;
      } // <-- dropped as you "exit" the async block
    }

After this PR, async function arguments will be lowered as:

    async fn foo(<pattern>: <ty>, <pattern>: <ty>, <pattern>: <ty>) {
      async move {
      }
    } // <-- dropped as you "exit" the fn

    // ...becomes...
    fn foo(__arg0: <ty>, __arg1: <ty>, __arg2: <ty>) {
      async move {
        let __arg2 = __arg2;
        let <pattern> = __arg2;
        let __arg1 = __arg1;
        let <pattern> = __arg1;
        let __arg0 = __arg0;
        let <pattern> = __arg0;
      } // <-- dropped as you "exit" the async block
    }

If `<pattern>` is a simple ident, then it is lowered to a single
`let <pattern> = <pattern>;` statement as an optimization.
2019-05-01 14:40:59 +01:00
Andrew Xu
d3fff6cda7 move some functions from parser.rs to diagostics.rs
parser.rs is too big. Some functions only for error reporting and error
recovery are being moved to diagostics.rs.
2019-05-01 19:54:48 +08:00
varkor
aa388f1d11 ignore-tidy-filelength on all files with greater than 3000 lines 2019-04-25 21:39:09 +01:00
Mazdak Farrokhzad
eb4860c77c
Rollup merge of #60186 - estebank:accept-suffix, r=nikomatsakis
Temporarily accept [i|u][32|size] suffixes on a tuple index and warn

Fix #60138.

#59553 will need to be kept open to track the change back to rejecting this code a few versions down thee line.
2019-04-24 05:16:22 +02:00
Esteban Küber
4c015739ea review comment: change linked ticket 2019-04-23 14:31:42 -07:00
Mazdak Farrokhzad
62d1574876
Rollup merge of #59823 - davidtwco:issue-54716, r=cramertj
[wg-async-await] Drop `async fn` arguments in async block

Fixes #54716.

This PR modifies the HIR lowering (and some other places to make this work) so that unused arguments to a async function are always dropped inside the async move block and not at the end of the function body.

```
async fn foo(<pattern>: <type>) {
  async move {
  }
} // <-- dropped as you "exit" the fn

// ...becomes...
fn foo(__arg0: <ty>) {
  async move {
    let <pattern>: <ty> = __arg0;
  } // <-- dropped as you "exit" the async block
}
```

However, the exact ordering of drops is not the same as a regular function, [as visible in this playground example](https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=be39af1a58e5d430be1eb3c722cb1ec3) - I believe this to be an unrelated issue. There is a [Zulip topic](https://rust-lang.zulipchat.com/#narrow/stream/187312-t-compiler.2Fwg-async-await/topic/.2354716.20drop.20order) for this.

r? @cramertj
cc @nikomatsakis
2019-04-23 21:50:52 +02:00
Esteban Küber
e3fb331695 Temporarily accept [i|u][32|size] suffixes on a tuple index and warn 2019-04-22 16:02:53 -07:00
David Wood
9d7da824d6
Introduce ArgSource for diagnostics.
This commit introduces an `ArgSource` enum that is lowered into the HIR
so that diagnostics can correctly refer to the argument pattern's
original name rather than the generated pattern.
2019-04-21 16:46:32 +01:00
David Wood
92e72df2c1
Do not specify type in generated let bindings.
This avoids issues with `impl_trait_in_bindings` as the type from the
argument is normally used as the let binding, but `impl Trait` is
unstable in binding position.
2019-04-21 16:46:32 +01:00
David Wood
879abb1641
Add AsyncArgument to AST.
This commit adds an `AsyncArgument` struct to the AST that contains the
generated argument and statement that will be used in HIR lowering, name
resolution and def collection.
2019-04-21 16:46:32 +01:00
bors
31a75a1728 Auto merge of #60124 - petrochenkov:stanomut, r=eddyb
Remove mutability from `Def::Static`

Querify `TyCtxt::is_static`.
Use `Mutability` instead of bool in foreign statics in AST/HIR.

cc https://github.com/rust-lang/rust/pull/60110
r? @eddyb
2019-04-21 13:40:22 +00:00
Vadim Petrochenkov
4eb94b4407 AST/HIR: Use Mutability instead of bool in foreign statics 2019-04-21 15:29:58 +03:00
bors
06a271a6eb Auto merge of #60119 - estebank:bad-recovery, r=davidtwco
Remove assumption from recovery code

Fix #60115.
2019-04-21 10:13:27 +00:00
David Wood
41c6bb1096
Introduce LocalSource into the AST.
This will be used to keep track of the origin of a local in the AST. In
particular, it will be used by `async fn` lowering for the locals in
`let <pat>: <ty> = __arg0;` statements.
2019-04-21 09:48:11 +01:00
bors
4d9c6cd722 Auto merge of #60132 - davidtwco:issue-60075, r=estebank
Fix fn front matter parsing ICE from invalid code.

Fixes #60075.

This PR fixes an "unreachable code" ICE that results from parsing
invalid code where the compiler is expecting the next trait item
declaration in the middle of the previous trait item due to extra
closing braces.

r? @estebank (thanks for the minimized test case)
2019-04-21 07:20:14 +00:00
David Wood
60c6ed9664
Fix fn front matter parsing ICE from invalid code.
This commit fixes an "unreachable code" ICE that results from parsing
invalid code where the compiler is expecting the next trait item
declaration in the middle of the previous trait item due to extra
closing braces.
2019-04-20 11:36:04 +01:00
Esteban Küber
30b779f398 Remove assumption from recovery code 2019-04-19 11:04:41 -07:00
Vadim Petrochenkov
aa393b0cde Some cleanup to maybe_parse_struct_expr 2019-04-19 10:32:44 -07:00
Esteban Küber
4c4ca60edd remove duplicated code and simplify logic 2019-04-19 10:13:45 -07:00
Esteban Küber
f1be8d16c5 Identify missing ambiguous case with best effort suggestion 2019-04-19 10:13:45 -07:00
Esteban Küber
2f36b54f0f Emit specific error for struct literal in conditions 2019-04-19 10:13:44 -07:00
Mazdak Farrokhzad
af4acd0533
Rollup merge of #59866 - estebank:recover-missing-semi, r=petrochenkov
Recover from missing semicolon based on the found token

When encountering one of a few keywords when a semicolon was
expected, suggest the semicolon and recover:

```
error: expected one of `.`, `;`, `?`, or an operator, found `let`
  --> $DIR/recover-missing-semi.rs:4:5
   |
LL |     let _: usize = ()
   |                      - help: missing semicolon here
LL |
LL |     let _ = 3;
   |     ^^^

error[E0308]: mismatched types
  --> $DIR/recover-missing-semi.rs:2:20
   |
LL |     let _: usize = ()
   |                    ^^ expected usize, found ()
   |
   = note: expected type `usize`
              found type `()`
```
2019-04-12 20:36:16 +02:00
Mazdak Farrokhzad
8f111951a1
Rollup merge of #59847 - Kampfkarren:try-block-catch, r=estebank
Error when using `catch` after `try`

Part of https://github.com/rust-lang/rust/issues/31436
2019-04-12 20:36:11 +02:00
bors
cd8b437362 Auto merge of #59227 - Zoxc:fix-get, r=eddyb
Fix lifetime on LocalInternedString::get function

cc @eddyb @nnethercote
2019-04-11 23:36:13 +00:00
Esteban Küber
9b6b3d618c review comments 2019-04-11 14:45:23 -07:00
Kampfkarren
1156ce6f54 Feedback 2019-04-10 19:22:43 -07:00
Esteban Küber
ac037c1359 Recover from missing semicolon based on the found token
When encountering one of a few keywords when a semicolon was
expected, suggest the semicolon and recover:

```
error: expected one of `.`, `;`, `?`, or an operator, found `let`
  --> $DIR/recover-missing-semi.rs:4:5
   |
LL |     let _: usize = ()
   |                      - help: missing semicolon here
LL |
LL |     let _ = 3;
   |     ^^^

error[E0308]: mismatched types
  --> $DIR/recover-missing-semi.rs:2:20
   |
LL |     let _: usize = ()
   |                    ^^ expected usize, found ()
   |
   = note: expected type `usize`
              found type `()`
```
2019-04-10 18:07:52 -07:00
Kampfkarren
de02dd96fd Adhere to tidy script 2019-04-10 10:41:47 -07:00
Kampfkarren
4a938b5b3c Special error when using catch after try 2019-04-10 10:35:48 -07:00
Mazdak Farrokhzad
d2fd3fe957
Rollup merge of #59041 - saleemjaffer:trait_doc_comment_better_error_msg, r=pnkfelix
fixes rust-lang#56766

fixes #56766
2019-04-01 17:29:53 +02:00
John Kåre Alsaker
438f6b04c6 Fix lifetime on LocalInternedString::get function 2019-03-31 03:11:55 +02:00
Mazdak Farrokhzad
c28704c2a8
Rollup merge of #59453 - estebank:recover-tuple-parse, r=petrochenkov
Recover from parse error in tuple syntax
2019-03-30 07:51:36 +01:00
Esteban Küber
9ea6790a64 Deduplicate parse recovery code 2019-03-28 19:58:45 -07:00
Esteban Küber
e3918cf621 Recover from parse error in tuple syntax 2019-03-28 04:47:37 -07:00
Mazdak Farrokhzad
dcd531ea15
Rollup merge of #59198 - estebank:recovered-pattern, r=zackmdavis
Do not complain about unmentioned fields in recovered patterns

When the parser has to recover from malformed code in a pattern, do not
complain about missing fields.

Fix #59145.
2019-03-28 08:43:32 +01:00
Josh Stone
be34621ffc
Rollup merge of #59421 - estebank:tuple-index-suffix, r=petrochenkov
Reject integer suffix when tuple indexing

Fix #59418.

r? @varkor
2019-03-27 18:15:35 -07:00
Josh Stone
c818c1a1d6
Rollup merge of #57565 - petrochenkov:turbowarn, r=Centril
syntax: Remove warning for unnecessary path disambiguators

`rustfmt` is now stable and it removes unnecessary turbofishes, so removing the warning as discussed in https://github.com/rust-lang/rust/pull/43540 (where it was introduced).
One hardcoded warning less.

Closes https://github.com/rust-lang/rust/issues/58055

r? @nikomatsakis
2019-03-27 18:15:19 -07:00
Esteban Küber
8d1cc72cf9 Add specific message for tuple struct invoked with suffixed numeric field name 2019-03-26 12:32:32 -07:00
Esteban Küber
1bb3694b1a Reword invalid suffixe errors 2019-03-26 12:09:13 -07:00
Esteban Küber
c7ddb83980 Use expect_no_suffix for error 2019-03-26 10:18:18 -07:00
Mazdak Farrokhzad
b316514dbd
Rollup merge of #59150 - estebank:type-ascription, r=varkor
Expand suggestions for type ascription parse errors

Fix #51222. CC #48016, #47666, #54516, #34255.
2019-03-26 09:05:39 +01:00
Esteban Küber
6ad77b0938 review comments 2019-03-25 21:38:23 -07:00
Esteban Küber
91b7423760 Reject integer suffix when tuple indexing 2019-03-25 16:11:21 -07:00
David Wood
5c3d1e5d76 Separate variant id and variant constructor id.
This commit makes two changes - separating the `NodeId` that identifies
an enum variant from the `NodeId` that identifies the variant's
constructor; and no longer creating a `NodeId` for `Struct`-style enum
variants and structs.

Separation of the variant id and variant constructor id will allow the
rest of RFC 2008 to be implemented by lowering the visibility of the
variant's constructor without lowering the visbility of the variant
itself.

No longer creating a `NodeId` for `Struct`-style enum variants and
structs mostly simplifies logic as previously this `NodeId` wasn't used.
There were various cases where the `NodeId` wouldn't be used unless
there was an unit or tuple struct or enum variant but not all uses of
this `NodeId` had that condition, by removing this `NodeId`, this must
be explicitly dealt with. This change mostly applied cleanly, but there
were one or two cases in name resolution and one case in type check
where the existing logic required a id for `Struct`-style enum variants
and structs.
2019-03-24 12:10:16 +03:00
Esteban Küber
9bfb0ef818 Tweak unsupported negative trait bounds message 2019-03-23 13:05:30 -07:00
Vadim Petrochenkov
4b382946e4 syntax: Remove warning for unnecessary path disambiguators 2019-03-23 17:20:11 +03:00
bors
d51a437e28 Auto merge of #59058 - petrochenkov:assocrecov3, r=estebank
syntax: Better recovery for `$ty::AssocItem` and `ty!()::AssocItem`

This PR improves on https://github.com/rust-lang/rust/pull/46788 covering a few missing cases.

Fixes https://github.com/rust-lang/rust/issues/52307
Fixes https://github.com/rust-lang/rust/issues/53776
r? @estebank
2019-03-23 05:51:16 +00:00
Esteban Küber
d72ef21ddd Reword type ascription note to reduce verbosity 2019-03-22 20:14:20 -07:00