about summary refs log tree commit diff
path: root/src/libsyntax/ext/expand.rs
AgeCommit message (Collapse)AuthorLines
2019-08-05Drop span argument from mk_list_itemMark Rousskov-2/+2
2019-08-05Auto merge of #63248 - petrochenkov:nomarker, r=matthewjasperbors-15/+4
Move special treatment of `derive(Copy, PartialEq, Eq)` from expansion infrastructure to elsewhere As described in https://github.com/rust-lang/rust/pull/62086#issuecomment-515195477. Reminder: - `derive(PartialEq, Eq)` makes the type it applied to a "structural match" type, so constants of this type can be used in patterns (and const generics in the future). - `derive(Copy)` notifies other derives that the type it applied to implements `Copy`, so `derive(Clone)` can generate optimized code and other derives can generate code working with `packed` types and types with `rustc_layout_scalar_valid_range` attributes. First, the special behavior is now enabled after properly resolving the derives, rather than after textually comparing them with `"Copy"`, `"PartialEq"` and `"Eq"` in `fn add_derived_markers`. The markers are no longer kept as attributes in AST since derives cannot modify items and previously did it through hacks in the expansion infra. Instead, the markers are now kept in a "global context" available from all the necessary places, namely - resolver. For `derive(PartialEq, Eq)` the markers are created by the derive macros themselves and then consumed during HIR lowering to add the `#[structural_match]` attribute in HIR. This is still a hack, but now it's a hack local to two specific macros rather than affecting the whole expansion infra. Ideally we should find the way to put `#[structural_match]` on the impls rather than on the original item, and then consume it in `rustc_mir`, then no hacks in expansion and lowering will be required. (I'll make an issue about this for someone else to solve, after this PR lands.) The marker for `derive(Copy)` cannot be emitted by the `Copy` macro itself because we need to know it *before* the `Copy` macro is expanded for expanding other macros. So we have to do it in resolve and block expansion of any derives in a `derive(...)` container until we know for sure whether this container has `Copy` in it or not. Nasty stuff. r? @eddyb or @matthewjasper
2019-08-04Auto merge of #62816 - estebank:type-ascription-macros, r=petrochenkovbors-2/+7
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-03Move special treatment of `derive(Copy, PartialEq, Eq)` from expansion ↵Vadim Petrochenkov-15/+4
infrastructure to elsewhere
2019-07-31Remove AttrId from Attribute constructorsMark Rousskov-4/+8
2019-07-31Unify spanned and non-spanned Attribute ctorsMark Rousskov-2/+2
There is no difference in the code/arguments, so go with the shorter name throughout the code.
2019-07-30Point at type ascription before macro invocation on expansion parse errorEsteban Küber-2/+7
2019-07-27Move proc macro server into libsyntaxVadim Petrochenkov-1/+1
2019-07-25Rollup merge of #60938 - jonas-schievink:doc-include-paths, r=petrochenkovMazdak Farrokhzad-5/+1
rustdoc: make #[doc(include)] relative to the containing file This matches the behavior of other in-source paths like `#[path]` and the `include_X!` macros. Fixes https://github.com/rust-lang/rust/pull/58373#issuecomment-462349380 Also addresses https://github.com/rust-lang/rust/issues/44732#issuecomment-467660239 cc #44732 This is still missing a stdsimd change (https://github.com/jonas-schievink/stdsimd/commit/42ed30e0b5fb5e2d11765b5d1e1f36234af85984), so CI will currently fail. I'll land that change once I get initial feedback for this PR.
2019-07-23Normalize use of backticks in compiler messages for libsyntax/*Samy Kacimi-1/+1
https://github.com/rust-lang/rust/issues/60532
2019-07-23Make path::resolve a method on ExtCtxtJonas Schievink-2/+1
2019-07-23Make #[doc(include)] paths behave like other pathsJonas Schievink-5/+2
This makes them relative to the containing file instead of the crate root
2019-07-19Adjust other names after the `Mark` renamingVadim Petrochenkov-14/+14
2019-07-19libsyntax: Remove `Mark` into `ExpnId`Vadim Petrochenkov-6/+6
2019-07-13Detect `fn` with a body in an `extern` blockEsteban Küber-1/+1
2019-07-11expand: Move "derive containers" into a separate `InvocationKind` variantVadim Petrochenkov-14/+25
`InvocationKind::Attr { attr: None, .. }` meaning something entirely different from a regular attribute was confusing as hell.
2019-07-11expand: Merge `expand_{bang,attr,derive}_invoc` into a single functionVadim Petrochenkov-116/+78
It's more convenient to have all this highly related stuff together on one screen (for future refactorings). The `expand_invoc` function is compact enough now, after all the previous refactorings.
2019-07-11expand: It's always possible to create a dummy AST fragmentVadim Petrochenkov-44/+39
Remove a bunch of `Option`s that assumed that dummy fragment creation could fail. The test output changed due to not performing the expansion in `fn expand_invoc` in case of the recursion limit hit.
2019-07-11hygiene: Make sure each `Mark` has an associated expansion infoVadim Petrochenkov-2/+12
The root expansion was missing one. Expansions created for "derive containers" (see one of the next commits for the description) also didn't get expansion info.
2019-07-11hygiene: Introduce a helper method for creating new expansionsVadim Petrochenkov-2/+2
Creating a fresh expansion and immediately generating a span from it is the most common scenario. Also avoid allocating `allow_internal_unstable` lists for derive markers repeatedly. And rename `ExpnInfo::with_unstable` to `ExpnInfo::allow_unstable`, seems to be a better fitting name.
2019-07-11resolve/expand: Catch macro kind mismatches early in resolveVadim Petrochenkov-34/+5
This way we are processing all of them in a single point, rather than separately for each syntax extension kind. Also, the standard expected/found wording is used.
2019-07-11resolve/expand: `resolve_macro_invocation` no longer returns determinate errorsVadim Petrochenkov-58/+53
It either returns the indeterminacy error, or valid (but perhaps dummy) `SyntaxExtension`. With this change enum `Determinacy` is no longer used in libsyntax and can be moved to resolve. The regressions in diagnosics are fixed in the next commits.
2019-07-11syntax: Make def-site span mandatory in ↵Vadim Petrochenkov-1/+1
ExpnInfo/MacroBacktrace/DiagnosticSpanMacroExpansion We have to deal with dummy spans anyway Remove def-site span from expander interfaces. It's not used by the expansion infra, only by specific expanders, which can keep it themselves if they want it.
2019-07-11expand: Get rid of `resolve_macro_path`Vadim Petrochenkov-11/+11
It was used to choose whether to apply derive markers like `#[rustc_copy_clone_marker]` or not, but it was called before all the data required for resolution is available, so it could work incorrectly in some corner cases (like user-defined derives name `Copy` or `Eq`). Delay the decision about markers until the proper resolution results are available instead.
2019-07-11Rename some things in `syntax_pos/hygiene`Vadim Petrochenkov-1/+1
More consistent with other naming: ExpnFormat -> ExpnKind ExpnKind::name -> ExpnKind::descr DesugaringKind::name -> DesugaringKind::descr Shorter, no tautology: CompilerDesugaring -> Desugaring CompilerDesugaringKind -> DesugaringKind
2019-07-09Resolve `$crate` in all hygienic contexts for pretty-pringingVadim Petrochenkov-1/+1
Stop visiting AST to discover those contexts, just iterate through hygiene data instead
2019-07-07syntax: Migrate built-in macros to the regular stability checkingVadim Petrochenkov-28/+8
2019-07-07resolve/expand: Move macro stability checking to an earlier pointVadim Petrochenkov-40/+9
2019-07-07syntax: Remove `NodeId` from `SyntaxExtension`Vadim Petrochenkov-3/+2
2019-07-05Rollup merge of #62133 - petrochenkov:norustc, r=eddybMazdak Farrokhzad-3/+1
Feature gate `rustc` attributes harder Fixes https://github.com/rust-lang/rust/issues/62116
2019-07-04Rollup merge of #62258 - petrochenkov:idclean, r=CentrilMazdak Farrokhzad-33/+12
syntax: Unsupport `foo! bar { ... }` macros in the parser Their support in expansion was removed in https://github.com/rust-lang/rust/pull/61606. Also un-reserve `macro_rules` as a macro name, there's no ambiguity between `macro_rules` definitions and macro calls (it also wasn't reserved correctly). cc https://github.com/rust-lang-nursery/wg-grammar/issues/51
2019-07-01Convert more usages overChris Gregory-1/+1
2019-07-01syntax: Unsupport `foo! bar { ... }` macros in the parserVadim Petrochenkov-33/+12
Unreserve `macro_rules` as a macro name
2019-06-30Make sure `#[rustc_doc_only_macro]` and other rustc attributes are registeredVadim Petrochenkov-3/+1
2019-06-26Fix clippy::redundant_field_namesIgor Matuszewski-3/+3
2019-06-23Fix meta-variable binding errors in macrosJulien Cretin-6/+6
The errors are either: - The meta-variable used in the right-hand side is not bound (or defined) in the left-hand side. - The meta-variable used in the right-hand side does not repeat with the same kleene operator as its binder in the left-hand side. Either it does not repeat enough, or it uses a different operator somewhere. This change should have no semantic impact.
2019-06-19Rollup merge of #61547 - petrochenkov:cfgen, r=CentrilMazdak Farrokhzad-3/+3
Support `cfg` and `cfg_attr` on generic parameters `cfg` attributes are supported in all other positions where attributes are accepted at all. They were previously prohibited in https://github.com/rust-lang/rust/pull/51283 because they weren't implemented correctly before that and were simply ignored.
2019-06-19Support `cfg` and `cfg_attr` on generic parametersVadim Petrochenkov-3/+3
2019-06-19Rollup merge of #61898 - petrochenkov:sekind, r=eddybMazdak Farrokhzad-145/+35
syntax: Factor out common fields from `SyntaxExtension` variants And some other related cleanups. Continuation of https://github.com/rust-lang/rust/pull/61606. This will also help to unblock https://github.com/rust-lang/rust/pull/61877.
2019-06-18rustc: remove 'x: 'y bounds (except from comments/strings).Eduard-Mihai Burtescu-2/+2
2019-06-18resolve/expand: Move expansion info setting to a single earlier pointVadim Petrochenkov-29/+3
2019-06-18syntax: Factor out common fields from `SyntaxExtension` variantsVadim Petrochenkov-131/+47
2019-06-12Auto merge of #60669 - c410-f3r:attrs-fn, r=petrochenkovbors-0/+5
Allow attributes in formal function parameters Implements https://github.com/rust-lang/rust/issues/60406. This is my first contribution to the compiler and since this is a large and complex project, I am not fully aware of the consequences of the changes I have made. **TODO** - [x] Forbid some built-in attributes. - [x] Expand cfg/cfg_attr
2019-06-10syntax: Rename variants of `SyntaxExtension` for consistencyVadim Petrochenkov-12/+14
2019-06-10syntax: Remove `SyntaxExtension::DeclMacro`Vadim Petrochenkov-10/+1
It's a less powerful duplicate of `SyntaxExtension::NormalTT`
2019-06-10syntax: Use `MultiItemModifier` for built-in derivesVadim Petrochenkov-20/+20
2019-06-10syntax: Remove `SyntaxExtension::MultiDecorator` and `MultiItemDecorator`Vadim Petrochenkov-10/+1
2019-06-10syntax: Remove `SyntaxExtension::IdentTT` and `IdentMacroExpander`Vadim Petrochenkov-22/+0
2019-06-09Allow attributes in formal function parametersCaio-0/+5
2019-06-07parser: `self.span` -> `self.token.span`Vadim Petrochenkov-1/+1