about summary refs log tree commit diff
path: root/src/libsyntax/ext/expand.rs
AgeCommit message (Collapse)AuthorLines
2019-08-27resolve: Block expansion of a derive container until all its derives are ↵Vadim Petrochenkov-48/+66
resolved Also mark derive helpers as known as a part of the derive container's expansion instead of expansion of the derives themselves which may happen too late.
2019-08-25Rollup merge of #63854 - c410-f3r:attrs-visit, r=petrochenkovMazdak Farrokhzad-3/+7
Modifies how Arg, Arm, Field, FieldPattern and Variant are visited Part of the necessary work to accomplish #63468.
2019-08-24Modifies how Arg, Arm, Field, FieldPattern and Variant are visitedCaio-3/+7
Part of the necessary work to accomplish #63468.
2019-08-23hygiene: Require passing transparency explicitly to `apply_mark`Vadim Petrochenkov-14/+0
2019-08-23Audit uses of `apply_mark` in built-in macrosVadim Petrochenkov-1/+0
Replace them with equivalents of `Span::{def_site,call_site}` from proc macro API. The new API is much less error prone and doesn't rely on macros having default transparency.
2019-08-21resolve/expand: Rename some things for clarity and add commentsVadim Petrochenkov-2/+4
2019-08-21expand: Keep the correct current expansion ID for eager expansionsVadim Petrochenkov-1/+0
Solve the problem of `ParentScope` entries for eager expansions not exising in the resolver map by creating them on demand.
2019-08-17resolve/expand: Rename some things for clarityVadim Petrochenkov-11/+14
2019-08-16Rollup merge of #63525 - matklad:centraliza-file-loading, r=petrochenkovMazdak Farrokhzad-8/+5
Make sure that all file loading happens via SourceMap That way, callers don't need to repeat "let's add this to sm manually for tracking dependencies" trick. It should make it easier to switch to using `FileLoader` for binary files in the future as well cc #62948 r? @petrochenkov
2019-08-15hygiene: `ExpnInfo` -> `ExpnData`Vadim Petrochenkov-10/+10
For naming consistency with everything else in this area
2019-08-15hygiene: Merge `ExpnInfo` and `InternalExpnData`Vadim Petrochenkov-6/+9
2019-08-15hygiene: Remove `Option`s from functions returning `ExpnInfo`Vadim Petrochenkov-1/+1
The expansion info is not optional and should always exist
2019-08-15`Ident::with_empty_ctxt` -> `Ident::with_dummy_span`Vadim Petrochenkov-4/+4
`Ident` has had a full span rather than just a `SyntaxContext` for a long time now.
2019-08-15syntax_pos: `NO_EXPANSION`/`SyntaxContext::empty()` -> `SyntaxContext::root()`Vadim Petrochenkov-1/+1
For consistency with `ExpnId::root`. Also introduce a helper `Span::with_root_ctxt` for creating spans with `SyntaxContext::root()` context
2019-08-15Remove `Spanned` from `ast::Mac`Vadim Petrochenkov-6/+5
2019-08-15Remove `Spanned` from `mk_name_value_item_str` and `expr_to_spanned_string`Vadim Petrochenkov-3/+5
2019-08-15Make sure that all file loading happens via SourceMapAleksey Kladov-8/+5
That way, callers don't need to repeat "let's add this to sm manually for tracking dependencies" trick. It should make it easier to switch to using `FileLoader` for binary files in the future as well
2019-08-14expand: Unimplement `MutVisitor` on `MacroExpander`Vadim Petrochenkov-13/+1
Each call to `fully_expand_fragment` is something unique, interesting, and requiring attention. It represents a "root" of expansion and its use means that something unusual is happening, like eager expansion or expansion performed outside of the primary expansion pass. So, it shouldn't be hide under a generic visitor call. Also, from all the implemented visitor methods only two were actually used.
2019-08-14expand: `expand_fragment` -> `fully_expand_fragment`Vadim Petrochenkov-6/+6
2019-08-09review comments: use structured suggestionEsteban Küber-15/+2
2019-08-09More explicit diagnostic when using a `vec![]` in a patternEsteban Küber-6/+22
``` error: unexpected `(` after qualified path --> $DIR/vec-macro-in-pattern.rs:3:14 | LL | Some(vec![x]) => (), | ^^^^^^^ | | | unexpected `(` after qualified path | in this macro invocation | use a slice pattern here instead | = help: for more information, see https://doc.rust-lang.org/edition-guide/rust-2018/slice-patterns.html = note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) ```
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