about summary refs log tree commit diff
path: root/compiler/rustc_expand/src
AgeCommit message (Collapse)AuthorLines
2021-03-05expand: Determine module directory path directly instead of relying on spanVadim Petrochenkov-8/+3
2021-03-05expand: Move module file path stack from global session to expansion dataVadim Petrochenkov-51/+64
Also don't push the paths on the stack directly in `fn parse_external_mod`, return them instead.
2021-03-05expand: Remove obsolete `DirectoryOwnership::UnownedViaMod`Vadim Petrochenkov-52/+9
This ownership kind is only constructed in the case of path attributes like `#[path = ".."]` without a file name segment, which always represent some kind of directories and will produce and error on attempt to parse them as a module file.
2021-02-27Combine HasAttrs and HasTokens into AstLikeAaron Hill-14/+32
When token-based attribute handling is implemeneted in #80689, we will need to access tokens from `HasAttrs` (to perform cfg-stripping), and we will to access attributes from `HasTokens` (to construct a `PreexpTokenStream`). This PR merges the `HasAttrs` and `HasTokens` traits into a new `AstLike` trait. The previous `HasAttrs` impls from `Vec<Attribute>` and `AttrVec` are removed - they aren't attribute targets, so the impls never really made sense.
2021-02-23expand: Do not allocate `Lrc` for `allow_internal_unstable` list unless ↵Vadim Petrochenkov-2/+3
necessary
2021-02-23expand: Preserve order of inert attributes during expansionVadim Petrochenkov-9/+14
2021-02-21remove redundant wrapping of return types of allow_internal_unstable() and ↵Matthias Krüger-2/+2
rustc_allow_const_fn_unstable()
2021-02-18ast: Keep expansion status for out-of-line module itemsVadim Petrochenkov-58/+59
Also remove `ast::Mod` which is mostly redundant now
2021-02-18ast: Stop using `Mod` in `Crate`Vadim Petrochenkov-32/+21
Crate root is sufficiently different from `mod` items, at least at syntactic level. Also remove customization point for "`mod` item or crate root" from AST visitors.
2021-02-17Rollup merge of #81869 - mark-i-m:leading-vert, r=petrochenkovDylan DPC-2/+4
Simplify pattern grammar, improve or-pattern diagnostics This implements the change under FCP in https://github.com/rust-lang/rust/issues/81415. It allows nested or-patterns to contain a leading `|`, simplifying the [grammar for patterns](https://github.com/rust-lang/reference/pull/957/files?short_path=cc629f1#diff-cc629f15712821139bc706c63b3845ab59a008e2a998e08ffad42e3aebcbcbe2). Along the way, we also improve the diagnostics around a few specially-handled cases, such as using `||` instead of `|`, using or-patterns in fn params, including the leading `|` in the pattern span, etc. r? `@petrochenkov`
2021-02-15Simplify pattern grammar by allowing nested leading vertmark-2/+4
Along the way, we also implement a handful of diagnostics improvements and fixes, particularly with respect to the special handling of `||` in place of `|` and when there are leading verts in function params, which don't allow top-level or-patterns anyway.
2021-02-15Rollup merge of #82129 - est31:master, r=jyn514Jonas Schievink-1/+0
Remove redundant bool_to_option feature gate
2021-02-15Remove redundant bool_to_option feature gateest31-1/+0
2021-02-14expand: Remove redundant calls to configureVadim Petrochenkov-21/+3
Starting from https://github.com/rust-lang/rust/pull/63468 cfg attributes on variants, fields, fn params etc. are processed together with other attributes (via `configure!`).
2021-02-14expand: Remove obsolete `ExpansionConfig::keep_macs`Vadim Petrochenkov-12/+2
Maybe it was used before the introduction of placeholders, but now it has no effect.
2021-02-11Add test for "const stability on macro"Esteban Küber-2/+5
2021-02-10Tweak stability attribute diagnostic outputEsteban Küber-3/+6
2021-02-09add method to construct def site path as a vec of identsSkgland-0/+4
like std_path but used dummy span for all path elements and does not perpend kw:DollarCrate
2021-02-07Address review commentsVadim Petrochenkov-0/+3
2021-02-07expand/resolve: Turn `#[derive]` into a regular macro attributeVadim Petrochenkov-342/+135
2021-01-31Improve handling of spans around macro result parse errorsAaron Hill-1/+3
Fixes #81543 After we expand a macro, we try to parse the resulting tokens as a AST node. This commit makes several improvements to how we handle spans when an error occurs: * Only ovewrite the original `Span` if it's a dummy span. This preserves a more-specific span if one is available. * Use `self.prev_token` instead of `self.token` when emitting an error message after encountering EOF, since an EOF token always has a dummy span * Make `SourceMap::next_point` leave dummy spans unused. A dummy span does not have a logical 'next point', since it's a zero-length span. Re-using the span span preserves its 'dummy-ness' for other checks
2021-01-28Add `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` lintAaron Hill-1/+13
cc #79813 This PR adds an allow-by-default future-compatibility lint `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS`. It fires when a trailing semicolon in a macro body is ignored due to the macro being used in expression position: ```rust macro_rules! foo { () => { true; // WARN } } fn main() { let val = match true { true => false, _ => foo!() }; } ``` The lint takes its level from the macro call site, and can be allowed for a particular macro by adding `#[allow(semicolon_in_expressions_from_macros)]`. The lint is set to warn for all internal rustc crates (when being built by a stage1 compiler). After the next beta bump, we can enable the lint for the bootstrap compiler as well.
2021-01-28Rollup merge of #81284 - jyn514:impl-times, r=wesleywiserYuki Okushi-3/+5
Make `-Z time-passes` less noisy - Add the module name to `pre_AST_expansion_passes` and don't make it a verbose event (since it normally doesn't take very long, and it's emitted many times) - Don't make the following rustdoc events verbose; they're emitted many times. + build_extern_trait_impl + build_local_trait_impl + build_primitive_trait_impl + get_auto_trait_impls + get_blanket_trait_impls - Remove the `get_auto_trait_and_blanket_synthetic_impls` rustdoc event; it's wholly covered by get_{auto,blanket}_trait_impls and not very useful. I found this while working on https://github.com/rust-lang/rust/pull/81275 but it's independent of those changes.
2021-01-23Make `-Z time-passes` less noisyJoshua Nelson-3/+5
- Add the module name to `pre_AST_expansion_passes` and don't make it a verbose event (since it normally doesn't take very long, and it's emitted many times) - Don't make the following rustdoc events verbose; they're emitted many times. + build_extern_trait_impl + build_local_trait_impl + build_primitive_trait_impl + get_auto_trait_impls + get_blanket_trait_impls - Remove `get_auto_trait_and_blanket_synthetic_impls`; it's wholly covered by get_{auto,blanket}_trait_impls and not very useful.
2021-01-20Force token collection to run when parsing nonterminalsAaron Hill-5/+7
Fixes #81007 Previously, we would fail to collect tokens in the proper place when only builtin attributes were present. As a result, we would end up with attribute tokens in the collected `TokenStream`, leading to duplication when we attempted to prepend the attributes from the AST node. We now explicitly track when token collection must be performed due to nomterminal parsing.
2021-01-17Remove dead codeRyan Levick-29/+1
2021-01-14Use Option::map_or instead of `.map(..).unwrap_or(..)`LingMan-6/+6
2021-01-12Auto merge of #80499 - matthiaskrgr:red_clos, r=estebankbors-1/+1
remove redundant closures (clippy::redundant_closure)
2021-01-10resolve: Simplify built-in macro tableVadim Petrochenkov-1/+1
2021-01-10Rollup merge of #80850 - m-ou-se:rustc-builtin-macro-name, r=petrochenkovYuki Okushi-8/+6
Allow #[rustc_builtin_macro = "name"] This adds the option of specifying the name of a builtin macro in the `#[rustc_builtin_macro]` attribute: `#[rustc_builtin_macro = "name"]`. This makes it possible to have both `std::panic!` and `core::panic!` as a builtin macro, by using different builtin macro names for each. This is needed to implement the edition-specific behaviour of the panic macros of RFC 3007. Also removes `SyntaxExtension::is_derive_copy`, as the macro name (e.g. `sym::Copy`) is now tracked and provides that information directly. r? ``@petrochenkov``
2021-01-09Formatting.Mara Bos-1/+3
2021-01-09Allow #[rustc_builtin_macro = "name"].Mara Bos-8/+4
This makes it possible to have both std::panic and core::panic as a builtin macro, by using different builtin macro names for each. Also removes SyntaxExtension::is_derive_copy, as the macro name (e.g. sym::Copy) is now tracked and provides that information directly.
2021-01-09resolve/expand: Improve attribute expansion on macro definitions and callsVadim Petrochenkov-12/+4
2021-01-07rustc_parse: Better spans for synthesized token streamsVadim Petrochenkov-9/+3
2021-01-03Make `ExpnData` fields `krate` and `orig_id` privateAaron Hill-16/+15
These fields are only used by hygiene serialized, and should not be accessed by anything outside of `rustc_span`.
2021-01-03remove redundant closures (clippy::redundant_closure)Matthias Krüger-1/+1
2020-12-31Auto merge of #80459 - mark-i-m:or-pat-reg, r=petrochenkovbors-46/+62
Implement edition-based macro :pat feature This PR does two things: 1. Fixes the perf regression from https://github.com/rust-lang/rust/pull/80100#issuecomment-750893149 2. Implements `:pat2018` and `:pat2021` matchers, as described by `@joshtriplett` in https://github.com/rust-lang/rust/issues/54883#issuecomment-745509090 behind the feature gate `edition_macro_pat`. r? `@petrochenkov` cc `@Mark-Simulacrum`
2020-12-30Implement edition-based macro pat featuremark-46/+62
2020-12-29Remove pretty-print/reparse hack, and add derive-specific hackAaron Hill-18/+65
2020-12-22Revert "Promote missing_fragment_specifier to hard error"Wesley Wiser-15/+33
This reverts commit 02eae432e7476a0686633a8c2b7cb1d5aab1bd2c.
2020-12-19implement edition-specific :pat behavior for 2015/18mark-7/+26
2020-12-16Remove docs for non-existent parameters in `rustc_expand`Camelid-4/+1
2020-12-12Remove some no longer necessary `#[cfg(test)]`sVadim Petrochenkov-3/+0
With https://github.com/rust-lang/rust/pull/69838 inner modules are never touched in the outer module is unconfigured.
2020-12-04Rollup merge of #79678 - jyn514:THE-PAPERCLIP-COMETH, r=varkorDylan DPC-8/+10
Fix some clippy lints Happy to revert these if you think they're less readable, but personally I like them better now (especially the `else { if { ... } }` to `else if { ... }` change).
2020-12-03Fix some clippy lintsJoshua Nelson-8/+10
2020-12-01Created NestedMetaItem::name_value_literal_span methodGuillaume Gomez-6/+5
2020-11-26Properly handle attributes on statementsAaron Hill-38/+13
We now collect tokens for the underlying node wrapped by `StmtKind` instead of storing tokens directly in `Stmt`. `LazyTokenStream` now supports capturing a trailing semicolon after it is initially constructed. This allows us to avoid refactoring statement parsing to wrap the parsing of the semicolon in `parse_tokens`. Attributes on item statements (e.g. `fn foo() { #[bar] struct MyStruct; }`) are now treated as item attributes, not statement attributes, which is consistent with how we handle attributes on other kinds of statements. The feature-gating code is adjusted so that proc-macro attributes are still allowed on item statements on stable. Two built-in macros (`#[global_allocator]` and `#[test]`) needed to be adjusted to support being passed `Annotatable::Stmt`.
2020-11-24Invoke attributes on the statement for statement itemsAaron Hill-5/+50
2020-11-20Auto merge of #78088 - fusion-engineering-forks:panic-fmt-lint, r=estebankbors-1/+2
Add lint for panic!("{}") This adds a lint that warns about `panic!("{}")`. `panic!(msg)` invocations with a single argument use their argument as panic payload literally, without using it as a format string. The same holds for `assert!(expr, msg)`. This lints checks if `msg` is a string literal (after expansion), and warns in case it contained braces. It suggests to insert `"{}", ` to use the message literally, or to add arguments to use it as a format string. ![image](https://user-images.githubusercontent.com/783247/96643867-79eb1080-1328-11eb-8d4e-a5586837c70a.png) This lint is also a good starting point for adding warnings about `panic!(not_a_string)` later, once [`panic_any()`](https://github.com/rust-lang/rust/pull/74622) becomes a stable alternative.
2020-11-19expand: Mark some dead code in derive expansion as unreachableVadim Petrochenkov-34/+2