about summary refs log tree commit diff
path: root/compiler/rustc_expand
AgeCommit message (Collapse)AuthorLines
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/+14
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
2020-11-19expand: Stop derive expansion un unexpected targets earlyVadim Petrochenkov-25/+35
Collect derive placeholders using `collect` instead of `push`
2020-11-19expand: Cleanup attribute collection in invocation collectorVadim Petrochenkov-141/+39
2020-11-19resolve/expand: Misc cleanupVadim Petrochenkov-4/+3
2020-11-19resolve: Centralize some error reporting for unexpected macro resolutionsVadim Petrochenkov-17/+24
2020-11-19expand: Move `fully_configure` to `config.rs`Vadim Petrochenkov-42/+45
2020-11-19expand: Tell built-in macros whether we are currently in forced expansion modeVadim Petrochenkov-28/+33
2020-11-12Rollup merge of #78836 - fanzier:struct-and-slice-destructuring, r=petrochenkovMara Bos-1/+1
Implement destructuring assignment for structs and slices This is the second step towards implementing destructuring assignment (RFC: rust-lang/rfcs#2909, tracking issue: #71126). This PR is the second part of #71156, which was split up to allow for easier review. Note that the first PR (#78748) is not merged yet, so it is included as the first commit in this one. I thought this would allow the review to start earlier because I have some time this weekend to respond to reviews. If ``@petrochenkov`` prefers to wait until the first PR is merged, I totally understand, of course. This PR implements destructuring assignment for (tuple) structs and slices. In order to do this, the following *parser change* was necessary: struct expressions are not required to have a base expression, i.e. `Struct { a: 1, .. }` becomes legal (in order to act like a struct pattern). Unfortunately, this PR slightly regresses the diagnostics implemented in #77283. However, it is only a missing help message in `src/test/ui/issues/issue-77218.rs`. Other instances of this diagnostic are not affected. Since I don't exactly understand how this help message works and how to fix it yet, I was hoping it's OK to regress this temporarily and fix it in a follow-up PR. Thanks to ``@varkor`` who helped with the implementation, particularly around the struct rest changes. r? ``@petrochenkov``
2020-11-12Auto merge of #78782 - petrochenkov:nodoctok, r=Aaron1011bors-13/+9
Do not collect tokens for doc comments Doc comment is a single token and AST has all the information to re-create it precisely. Doc comments are also responsible for majority of calls to `collect_tokens` (with `num_calls == 1` and `num_calls == 0`, cc https://github.com/rust-lang/rust/pull/78736). (I also moved token collection into `fn parse_attribute` to deduplicate code a bit.) r? `@Aaron1011`
2020-11-11Implement destructuring assignment for structs and slicesFabian Zaiser-1/+1
Co-authored-by: varkor <github@varkor.com>
2020-11-09Rollup merge of #78710 - petrochenkov:macvisit, r=davidtwcoDylan DPC-20/+1
rustc_ast: Do not panic by default when visiting macro calls Panicking by default made sense when we didn't have HIR or MIR and everything worked on AST, but now all AST visitors run early and majority of them have to deal with macro calls, often by ignoring them. The second commit renames `visit_mac` to `visit_mac_call`, the corresponding structures were renamed earlier in https://github.com/rust-lang/rust/pull/69589.
2020-11-09Do not collect tokens for doc commentsVadim Petrochenkov-13/+9
2020-11-07typo and formattingo752d-10/+9
fixed a typo and modified some line formatting justification while I'm here :)
2020-11-06rustc_expand: use collect_bang helper instead of manual reimplementationest31-3/+3
2020-11-03rustc_ast: `visit_mac` -> `visit_mac_call`Vadim Petrochenkov-2/+1
2020-11-03Rollup merge of #78626 - fusion-engineering-forks:deprecated-trait-impl, ↵Mara Bos-1/+1
r=estebank Improve errors about #[deprecated] attribute This change: 1. Turns `#[deprecated]` on a trait impl block into an error, which fixes #78625; 2. Changes these and other errors about `#[deprecated]` to use the span of the attribute instead of the item; and 3. Turns this error into a lint, to make sure it can be capped with `--cap-lints` and doesn't break any existing dependencies. Can be reviewed per commit. --- Example: ```rust struct X; #[deprecated = "a"] impl Default for X { #[deprecated = "b"] fn default() -> Self { X } } ``` Before: ``` error: This deprecation annotation is useless --> src/main.rs:6:5 | 6 | / fn default() -> Self { 7 | | X 8 | | } | |_____^ ``` After: ``` error: this `#[deprecated]' annotation has no effect --> src/main.rs:3:1 | 3 | #[deprecated = "a"] | ^^^^^^^^^^^^^^^^^^^ help: try removing the deprecation attribute | = note: `#[deny(useless_deprecated)]` on by default error: this `#[deprecated]' annotation has no effect --> src/main.rs:5:5 | 5 | #[deprecated = "b"] | ^^^^^^^^^^^^^^^^^^^ help: try removing the deprecation attribute ```
2020-11-03rustc_ast: Do not panic by default when visiting macro callsVadim Petrochenkov-18/+0