Commit graph

2852 commits

Author SHA1 Message Date
Mazdak Farrokhzad
a7ba754b6c syntax: unify and simplify fn signature parsing. 2019-10-07 06:01:38 +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
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
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
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
Mazdak Farrokhzad
573a8d8d30 syntax: extract error_on_invalid_abi. 2019-09-30 06:47:35 +02:00
Mazdak Farrokhzad
66bf323a3b syntax: cleanup parse_visibility. 2019-09-30 06:42:56 +02:00
Mazdak Farrokhzad
5b80ead489 syntax: misc cleanup 2019-09-30 06:21:30 +02:00
Mazdak Farrokhzad
347deac455 syntax: reorder param parsing to make more sense. 2019-09-30 05:32:46 +02:00
Mazdak Farrokhzad
0492302dbd syntax refactor parse_self_param (5) 2019-09-30 04:36:57 +02:00
Mazdak Farrokhzad
4306d0037e syntax refactor parse_self_param (4) 2019-09-30 04:36:57 +02:00
Mazdak Farrokhzad
ac454e9af9 syntax refactor parse_self_param (3) 2019-09-30 04:36:57 +02:00
Mazdak Farrokhzad
f688f8aedf syntax refactor parse_self_param (2) 2019-09-30 04:36:57 +02:00
Mazdak Farrokhzad
40dc9da44c syntax refactor parse_self_param (1) 2019-09-30 04:36:57 +02:00
Mazdak Farrokhzad
4fa9c3bca3 syntax refactor parse_fn_params 2019-09-30 04:36:27 +02:00
Mazdak Farrokhzad
378cc98cd9 syntax: is_named_argument -> is_named_param. 2019-09-30 03:31:09 +02:00
Mazdak Farrokhzad
64afa26253
Rollup merge of #64894 - Centril:fix-64682, r=petrochenkov
syntax: fix dropping of attribute on first param of non-method assocated fn

Fixes #64682.

The general idea is that we bake parsing of `self` into `parse_param_general` and then we just use standard list parsing. Overall, this simplifies the parsing and makes it more consistent.

r? @petrochenkov cc @c410-f3r
2019-09-29 20:34:18 +02:00
Mazdak Farrokhzad
8fd03b1e47 syntax: fix #64682.
Fuse parsing of `self` into `parse_param_general`.
2019-09-29 12:55:45 +02:00
Eduard-Mihai Burtescu
8a9d775888 syntax: don't keep a redundant c_variadic flag in the AST. 2019-09-28 17:38:59 +03:00
varkor
c3d8791373 Rename Ty.node to Ty.kind 2019-09-26 18:21:10 +01:00
Caio
299d696b91 Stabilize param_attrs in Rust 1.39.0 2019-09-11 10:13:43 -03:00
Caio
63a5f399ae Resolve attributes in several places
Arm, Field, FieldPat, GenericParam, Param, StructField and Variant
2019-09-09 09:27:15 -03:00
Alexander Regueiro
49d2fd1725 Aggregation of cosmetic changes made during work on REPL PRs: libsyntax 2019-09-07 16:29:04 +01:00
Aleksey Kladov
055d3798d4 reduce visibility 2019-09-06 22:04:36 +03:00
bors
bbd48e6f16 Auto merge of #63127 - kper:pr, r=nikomatsakis
Cleanup: Consistently use `Param` instead of `Arg` #62426

Fixes #62426
2019-08-28 03:42:00 +00:00
Kevin Per
e0ce9f8c0a Cleanup: Consistently use Param instead of Arg #62426 2019-08-27 14:07:41 +02:00
Mazdak Farrokhzad
0da7098116
Rollup merge of #63761 - petrochenkov:procattrs, r=eddyb
Propagate spans and attributes from proc macro definitions

Thanks to https://github.com/rust-lang/rust/pull/63269 we now have spans and attributes from proc macro definitions available in metadata.

However, that PR didn't actually put them into use! This PR finishes that work.

Attributes `rustc_macro_transparency`, `allow_internal_unstable`, `allow_internal_unsafe`, `local_inner_macros`, `rustc_builtin_macro`, `stable`, `unstable`, `rustc_deprecated`, `deprecated` now have effect when applied to proc macro definition functions.
From those attributes only `deprecated` is both stable and supposed to be used in new code.
(`#![staged_api]` still cannot be used in proc macro crates for unrelated reasons though.)

`Span::def_site` from the proc macro API now returns the correct location of the proc macro definition.

Also, I made a mistake in https://github.com/rust-lang/rust/pull/63269#discussion_r312702919, loaded proc macros didn't actually use the resolver cache.
This PR fixes the caching issue, now proc macros go through the `Resolver::macro_map` cache as well.

(Also, the first commit turns `proc_macro::quote` into a regular built-in macro to reduce the number of places where `SyntaxExtension`s need to be manually created.)
2019-08-27 08:17:51 +02:00
Vadim Petrochenkov
c476b55e52 proc_macro: Update Span::def_site to use the proc macro definition location
Which is no longer dummy and is available from metadata now.
2019-08-27 01:34:10 +03:00
Mazdak Farrokhzad
1caaa40768 parser: gracefully handle fn foo(A | B: type). 2019-08-25 05:45:19 +02:00
Mazdak Farrokhzad
5f6bec8ecf parser: drive-by: simplify parse_arg_general. 2019-08-24 21:53:55 +02:00
Vadim Petrochenkov
73dee258c1 hygiene: Remove Options from functions returning ExpnInfo
The expansion info is not optional and should always exist
2019-08-15 20:39:27 +03:00
Vadim Petrochenkov
dfcbe75900 syntax_pos: Introduce a helper for checking whether a span comes from expansion 2019-08-15 20:38:12 +03:00
Eduard-Mihai Burtescu
34dcca20e5 syntax: account for CVarArgs being in the argument list. 2019-08-12 15:28:10 +03:00
Mazdak Farrokhzad
bcfcbfc923 parser: {check,expect}_lifetime into ty.rs 2019-08-11 20:46:34 +02:00
Mazdak Farrokhzad
385d07f359 parser: move into generics.rs 2019-08-11 20:44:09 +02:00
Mazdak Farrokhzad
d6d93b3d82 parser: move into stmt.rs 2019-08-11 20:32:29 +02:00
Mazdak Farrokhzad
28db7c5968 parser: move parse_fn_block_decl into expr.rs 2019-08-11 20:04:09 +02:00
Mazdak Farrokhzad
848ec4aa3c parser: move parse_ident_or_underscore into item.rs 2019-08-11 20:00:38 +02:00
Mazdak Farrokhzad
3dbfbafe3e parser: split into {ty, path}.rs 2019-08-11 19:59:27 +02:00
Mazdak Farrokhzad
e81347c368 parser: split into {item,module}.rs 2019-08-11 18:34:42 +02:00
Mazdak Farrokhzad
e742de2569 parser: split into pat.rs 2019-08-11 15:24:37 +02:00
Mazdak Farrokhzad
81e6b5094e parser: split into expr.rs 2019-08-11 13:14:30 +02:00
Esteban Küber
b7f7756566 Recover parser from foo(_, _) 2019-08-09 07:18:05 -07:00
bors
d3f8a0b5df Auto merge of #63213 - varkor:itemkind-tyalias, r=Centril
Rename `ItemKind::Ty` to `ItemKind::TyAlias`

The current name is not entirely clear without context and `TyAlias` is consistent with `ItemKind::TraitAlias`.
2019-08-04 20:03:28 +00:00
varkor
63659ca9f6 Rename ItemImplKind::Type to ItemImplKind::TyAlias 2019-08-04 20:16:41 +01:00
varkor
8aa45c65d8 Rename ItemKind::Ty to ItemKind::TyAlias 2019-08-04 20:13:37 +01:00
bors
f01b9f803b Auto merge of #62816 - estebank:type-ascription-macros, r=petrochenkov
Point at type ascription before macro invocation on expansion parse error

Fix https://github.com/rust-lang/rust/issues/47666. Follow up to https://github.com/rust-lang/rust/pull/62791.

r? @petrochenkov
2019-08-04 16:19:04 +00:00