Commit Graph

9467 Commits

Author SHA1 Message Date
Mazdak Farrokhzad 4737095416 Rollup merge of #65040 - Centril:items-cleanup, r=estebank
syntax: more cleanups in item and function signature parsing

Follow up to https://github.com/rust-lang/rust/pull/64910.

Best read commit-by-commit.

r? @estebank
2019-10-08 05:02:35 +02:00
Charles Lew 2dab187024 Fix compilation error after rebase. 2019-10-07 14:33:49 +08:00
Mazdak Farrokhzad 6b23c22cca syntax: refactor with new fn parse_use_tree_glob_or_nested. 2019-10-07 06:47:24 +02:00
Mazdak Farrokhzad 9c6582a2c0 syntax: use parse_extern_abi more. 2019-10-07 06:18:47 +02:00
Charles Lew eb492455f2 Address review comments. 2019-10-07 12:01:56 +08:00
Charles Lew e70ffed9cd Add feature gate for raw_dylib. 2019-10-07 12:01:54 +08:00
Mazdak Farrokhzad a7ba754b6c syntax: unify and simplify fn signature parsing. 2019-10-07 06:01:38 +02:00
Mazdak Farrokhzad 7f9638d5d4 syntax: unify trait parsing a bit. 2019-10-07 06:01:38 +02:00
Mazdak Farrokhzad 090f3fd0c9 syntax: further item parsing cleanup 2019-10-07 06:01:38 +02:00
Mazdak Farrokhzad 3bdbfbe8b9 syntax: de-dups in item parsing. 2019-10-07 05:59:56 +02:00
Mazdak Farrokhzad e0fe4be465 syntax: cleanup associated const parsing. 2019-10-07 05:59:56 +02:00
bors 4ac4809ccf Auto merge of #64906 - Aaron1011:feature/extern-const-fn, r=Centril
Add support for `const unsafe? extern fn`

This works just as you might expect - an `const extern fn` is a `const fn` that is callable from foreign code.

Currently, panicking is not allowed in `const`s. When https://github.com/rust-lang/rfcs/pull/2345 (https://github.com/rust-lang/rust/issues/51999) is stabilized, then panicking in an `const extern fn` will produce a compile-time error when invoked at compile time, and an abort when invoked at runtime.

Since this is extending the language (we're allowing the `const` keyword in a new context), I believe that this will need an FCP. However, it's a very minor change, so I didn't think that filing an RFC was necessary.

This will allow libc (and other FFI crates) to make many functions `const`, without having to give up on making them `extern` as well.

Tracking issue: https://github.com/rust-lang/rust/issues/64926.
2019-10-07 00:12:12 +00:00
Tyler Mandry f5c8e12a7e Rollup merge of #65123 - Centril:mac-invoc-in-mut-pat, r=estebank
Account for macro invocation in `let mut $pat` diagnostic.

Fixes https://github.com/rust-lang/rust/issues/65122.

r? @estebank
2019-10-05 21:55:07 -07:00
Tyler Mandry c7d7e3730a Rollup merge of #64909 - estebank:turbofish-reloaded, r=Centril
When encountering chained operators use heuristics to recover from bad turbofish
2019-10-05 21:54:52 -07:00
Mazdak Farrokhzad 5f94a53d1a Account for macro invocation in let mut $pat diagnostic. 2019-10-05 04:34:26 +02:00
Tyler Mandry dd9ccb20fc Rollup merge of #65055 - GuillaumeGomez:long-err-explanation-E0556, r=petrochenkov
Add long error explanation for E0556

Part of #61137
2019-10-03 16:25:47 -07:00
Tyler Mandry 2a9bd75994 Rollup merge of #64690 - petrochenkov:mixed, r=dtolnay
proc_macro API: Expose `macro_rules` hygiene

Proc macros do not have direct access to our oldest and most stable hygiene kind - `macro_rules` hygiene.

To emulate it macro authors have to go through two steps - first generate a temporary `macro_rules` item (using a derive, at least until https://github.com/rust-lang/rust/pull/64035 is merged), then generate a macro call to that item. Popular crates like [proc_macro_hack](https://crates.io/crates/proc-macro-hack) use this trick to generate hygienic identifiers from proc macros.

I'd say that these workarounds with nested macro definitions have more chances to hit some corner cases in our hygiene system, in which we don't have full confidence.
So, let's provide a direct access to `macro_rules` hygiene instead.

This PR does that by adding a new method `Span::mixed_site` (bikeshedding is welcome) in addition to existing `Span::call_site` (stable) and `Span::def_site` (unstable).
Identifiers with this span resolve at def-site in for local variables, labels and `$crate`, and resolve at call-site for everything else, i.e. exactly like identifiers produced by `macro_rules`.

This API addition opens the way to stabilizing proc macros in expression positions (https://github.com/rust-lang/rust/issues/54727), for which use of call-site hygiene or workarounds with temporary items would be quite unfortunate.
(`macro_rules` expanded in expression position, on the other hand, are stable since 1.0 and widely used.)

r? @dtolnay @alexcrichton
2019-10-03 16:25:39 -07:00
Tyler Mandry da0afc1638 Rollup merge of #64675 - Centril:deprecate-plugin, r=oli-obk
Deprecate `#![plugin]` & `#[plugin_registrar]`

This PR deprecates `#![plugin]` and `#[plugin_registrar]`.

~A removal deadline is set: 1.44.0. This will be in 9 months from now and should give everyone who is still relying on the feature ample time to rid themselves of this dependency.~

cc https://github.com/rust-lang/rust/issues/29597

r? @Mark-Simulacrum
2019-10-03 16:25:37 -07:00
Esteban Küber 02f57f83a9 review comments 2019-10-03 13:22:18 -07:00
Esteban Küber f1499a8646 review comments 2019-10-03 11:55:19 -07:00
Esteban Küber dfdc369b40 review comments 2019-10-03 11:55:19 -07:00
Esteban Küber d7dceaa0c5 Account for missing turbofish in paths too 2019-10-03 11:55:18 -07:00
Esteban Küber 6c9f298a8b review comments 2019-10-03 11:55:18 -07:00
Esteban Küber ed60cf2475 When encountering chained operators use heuristics to recover from bad turbofish 2019-10-03 11:55:18 -07:00
Guillaume Gomez e86af1bbeb Add long error explanation for E0556 2019-10-03 14:11:31 +02:00
Vadim Petrochenkov d1310dc6c9 proc_macro: Add Span::mixed_site exposing macro_rules hygiene 2019-10-03 11:28:06 +03:00
Mazdak Farrokhzad 1b8ec975fc plugin_registrary: use normal deprecation instead of hard coded warning. 2019-10-03 07:03:01 +02:00
Mazdak Farrokhzad 287ceed469 Deprecate #![plugin] and #[plugin_registrar]. 2019-10-03 06:46:52 +02:00
David Wood 2537a8aa7a syntax: improve parameter without type suggestions
This commit improves the suggestions provided when function parameters
do not have types:

- A new suggestion is added for arbitrary self types, which suggests
adding `self: ` before the type.

- Existing suggestions are now provided when a `<` is found where a `:`
was expected (previously only `,` and `)` or trait items), this gives
suggestions in the case where the unnamed parameter type is generic
in a free function.

- The suggestion that a type name be provided (e.g. `fn foo(HashMap<u32>)`
-> `fn foo(HashMap: TypeName<u32>)`) will no longer occur when a `<` was
found instead of `:`.

- The ident will not be used for recovery when a `<` was found instead
of `:`.

Signed-off-by: David Wood <david@davidtw.co>
2019-10-02 09:51:27 +01:00
Aaron Hill 84b680f56f Add missing 'bump' 2019-10-02 01:04:22 -04:00
Aaron Hill 73b50d211b Add support for 'extern const fn'
This works just as you might expect - an 'extern const fn' is a 'const
fn' that is callable from foreign code.

Currently, panicking is not allowed in consts. When RFC 2345 is
stabilized, then panicking in an 'extern const fn' will produce a
compile-time error when invoked at compile time, and an abort when
invoked at runtime.

Since this is extending the language (we're allowing the `const` keyword
in a new context), I believe that this will need an FCP. However, it's a
very minor change, so I didn't think that filing an RFC was necessary.

This will allow libc (and other FFI crates) to make many functions
`const`, without having to give up on making them `extern` as well.
2019-10-02 00:38:52 -04:00
Mazdak Farrokhzad db9689333a Rollup merge of #64910 - Centril:params-cleanup, r=petrochenkov
syntax: cleanup param, method, and misc parsing

Do some misc cleanup of the parser:
- Method and parameter parsing is refactored.
- A parser for `const | mut` is introduced that https://github.com/rust-lang/rust/pull/64588 can reuse.
- Some other misc parsing.

Next up in a different PR:
- ~Implementing https://github.com/rust-lang/rust/issues/64252.~ -- maybe some other time...
- Heavily restructuring up `item.rs` which is a mess (hopefully, no promises ^^).

r? @petrochenkov
2019-10-01 23:56:21 +02:00
Mazdak Farrokhzad 24a84fae34 Rollup merge of #64907 - alexreg:tidy-up, r=Mark-Simulacrum
A small amount of tidying-up factored out from PR #64648

As requested by @Mark-Simulacrum, I put this in a separate commit to make it easier to review. (As far as I can tell, no violations of the policy here, and they are simply in a separate PR because they're not directly related to the import of that PR.)

r? @Mark-Simulacrum
2019-10-01 09:55:34 +02:00
Mazdak Farrokhzad f45de9a690 Rollup merge of #64887 - Centril:recover-trailing-vert, r=estebank
syntax: recover trailing `|` in or-patterns

Fixes https://github.com/rust-lang/rust/issues/64879.

For example (this also shows that we are sensitive to the typo `||`):

```
error: a trailing `|` is not allowed in an or-pattern
  --> $DIR/remove-leading-vert.rs:33:11
   |
LL |         A || => {}
   |         - ^^ help: remove the `||`
   |         |
   |         while parsing this or-pattern starting here
   |
   = note: alternatives in or-patterns are separated with `|`, not `||`
```

r? @estebank
2019-10-01 09:55:29 +02:00
Mazdak Farrokhzad 3bd34e04e3 Rollup merge of #63931 - petrochenkov:stabmac, r=Centril
Stabilize macros in some more positions

- Fn-like macros and attribute macros in `extern` blocks
- Fn-like procedural macros in type positions
- ~Attribute macros on inline modules~ (moved to https://github.com/rust-lang/rust/pull/64273)

Stabilization report: https://github.com/rust-lang/rust/pull/63931#issuecomment-526362396.

Closes https://github.com/rust-lang/rust/issues/49476
cc https://github.com/rust-lang/rust/issues/54727
2019-10-01 09:55:28 +02:00
Mazdak Farrokhzad 64130fd2c4 Rollup merge of #63674 - petrochenkov:meta2, r=Centril
syntax: Support modern attribute syntax in the `meta` matcher

Where "modern" means https://github.com/rust-lang/rust/pull/57367:
```
PATH
PATH `(` TOKEN_STREAM `)`
PATH `[` TOKEN_STREAM `]`
PATH `{` TOKEN_STREAM `}`
```

Unfortunately, `meta` wasn't future-proofed using the `FOLLOW` token set like other matchers (https://github.com/rust-lang/rust/issues/34011), so code like `$meta:meta {` or `$meta:meta [` may break, and we need a crater run to find out how often this happens in practice.

Closes https://github.com/rust-lang/rust/issues/49629 (by fully supporting `meta` rather than removing it.)
2019-10-01 09:55:26 +02:00
Mazdak Farrokhzad 5c5dd8069d syntax: reformat passing of FnHeader to parse_item_fn. 2019-10-01 06:10:06 +02:00
Mazdak Farrokhzad e04690440b syntax: de-closure-ify check_or_expected. 2019-10-01 05:55:28 +02:00
Mazdak Farrokhzad 49780d21b6 syntax: merge things back into parse_visibility. 2019-10-01 05:53:23 +02:00
Mazdak Farrokhzad 30647d1a85 syntax: put helpers of parse_self_param in the method. 2019-10-01 05:45:41 +02:00
Mazdak Farrokhzad df298b49f2 syntax: document some methods. 2019-10-01 05:13:42 +02:00
Vadim Petrochenkov 6ea4a52f47 Address review comments 2019-10-01 01:10:12 +03:00
Tyler Mandry 3add9790ab Rollup merge of #64838 - GuillaumeGomez:long-err-explanation-e0550, r=oli-obk
Add long error explanation for E0550

Part of #61137
2019-09-30 14:38:24 -07:00
Vadim Petrochenkov 957986d056 syntax: Support modern attribute syntax in the meta matcher 2019-09-30 22:58:22 +03:00
Vadim Petrochenkov 535d4743a4 syntax: Split ast::Attribute into container and inner parts 2019-09-30 22:36:25 +03:00
Vadim Petrochenkov 5ae38bbc7c Stabilize proc macros in type positions 2019-09-30 21:59:35 +03:00
Vadim Petrochenkov 349259d55f Stabilize macros in extern blocks
Add some tests for macros in extern blocks, remove duplicate tests
2019-09-30 21:59:35 +03:00
Guillaume Gomez 67eabe110b Add long error explanation for E0550 2019-09-30 15:52:47 +02:00
bors 22bc9e1d9c Auto merge of #64778 - csmoe:index, r=eddyb
Introduce librustc_index crate

Closes #50592
2019-09-30 13:33:15 +00:00
Mazdak Farrokhzad 151ce96e3e syntax: reduce repetition in fn parsing. 2019-09-30 09:32:51 +02:00