about summary refs log tree commit diff
path: root/src/test/ui/proc-macro
AgeCommit message (Collapse)AuthorLines
2020-11-03Expand `NtExpr` tokens only in key-value attributesVadim Petrochenkov-0/+85
2020-11-02Use reparsed `TokenStream` if we captured any inner attributesAaron Hill-0/+118
Fixes #78675 We now bail out of `prepend_attrs` if we ended up capturing any inner attributes (which can happen in several places, due to token capturing for `macro_rules!` arguments.
2020-11-02Treat trailing semicolon as a statement in macro callAaron Hill-1/+1
See https://github.com/rust-lang/rust/issues/61733#issuecomment-716188981 We now preserve the trailing semicolon in a macro invocation, even if the macro expands to nothing. As a result, the following code no longer compiles: ```rust macro_rules! empty { () => { } } fn foo() -> bool { //~ ERROR mismatched { true } //~ ERROR mismatched empty!(); } ``` Previously, `{ true }` would be considered the trailing expression, even though there's a semicolon in `empty!();` This makes macro expansion more token-based.
2020-10-21Unconditionally capture tokens for attributes.Aaron Hill-8/+8
This allows us to avoid synthesizing tokens in `prepend_attr`, since we have the original tokens available. We still need to synthesize tokens when expanding `cfg_attr`, but this is an unavoidable consequence of the syntax of `cfg_attr` - the user does not supply the `#` and `[]` tokens that a `cfg_attr` expands to.
2020-10-19Calculate visibilities once in resolveVadim Petrochenkov-22/+4
Then use them through a query based on resolver outputs
2020-10-19Auto merge of #77278 - camelid:use-correct-article, r=estebankbors-1/+1
Use correct article in help message for conversion or cast Before it always used `an`; now it uses the correct article for the type.
2020-10-16Rollup merge of #77493 - ↵Dylan DPC-4/+16
hosseind88:ICEs_should_always_print_the_top_of_the_query_stack, r=oli-obk ICEs should always print the top of the query stack see #76920
2020-10-11Add hack to keep `actix-web` and `actori-web` compilingAaron Hill-0/+60
This extends the existing `ident_name_compatibility_hack` to handle the `tuple_from_req` macro defined in `actix-web` (and its fork `actori-web`).
2020-10-11Allow skipping extra paren insertion during AST pretty-printingAaron Hill-0/+160
Fixes #74616 Makes progress towards #43081 Unblocks PR #76130 When pretty-printing an AST node, we may insert additional parenthesis to ensure that precedence is properly preserved in code we output. However, the proc macro implementation relies on comparing a pretty-printed AST node to the captured `TokenStream`. Inserting extra parenthesis changes the structure of the reparsed `TokenStream`, making the comparison fail. This PR refactors the AST pretty-printing code to allow skipping the insertion of additional parenthesis. Several freestanding methods are moved to trait methods on `PrintState`, which keep track of an internal `insert_extra_parens` flag. This flag is normally `true`, but we expose a public method which allows pretty-printing a nonterminal with `insert_extra_parens = false`. To avoid changing the public interface of `rustc_ast_pretty`, the freestanding `_to_string` methods are changed to delegate to a newly-crated `State`. The main pretty-printing code is moved to a new `state` module to ensure that it does not accidentally call any of these public helper functions (instead, the internal functions with the same name should be used).
2020-10-09add filter regexes to load-panic-backtraces testhosseind75-6/+0
2020-10-09fix invalid-punct-ident-1 testhosseind75-3/+0
2020-10-09show a message when we are showing limited slice of query stackhosseind75-0/+3
2020-10-09change approach and run ui testshosseind75-0/+6
2020-10-09add filter regexes to load-panic-backtraces testhosseind75-3/+12
2020-10-09fix invalid-punct-ident-1 testhosseind75-1/+4
2020-09-29Say "doesn't" instead of "wouldn't" in convert messageCamelid-1/+1
2020-09-29Add article after "to"Camelid-1/+1
Also added missing backtick in "you can cast" message.
2020-09-28Fix recursive nonterminal expansion during pretty-print/reparse checkAaron Hill-0/+86
Makes progress towards #43081 In PR #73084, we started recursively expanded nonterminals during the pretty-print/reparse check, allowing them to be properly compared against the reparsed tokenstream. Unfortunately, the recursive logic in that PR only handles the case where a nonterminal appears inside a `TokenTree::Delimited`. If a nonterminal appears directly in the expanded tokens of another nonterminal, the inner nonterminal will not be expanded. This PR fixes the recursive expansion of nonterminals, ensuring that they are expanded wherever they occur.
2020-09-26Test more attributes in test issue-75930-derive-cfg.rsAaron Hill-6/+1652
Split out from #76130 This tests our handling of combining derives, derive helper attributes, attribute macros, and `cfg`/`cfg_attr`
2020-09-21Record `tcx.def_span` instead of `item.span` in crate metadataAaron Hill-3/+3
This was missed in PR #75465. As a result, a few places have been using the full body span of functions, instead of just the header span.
2020-09-13Auto merge of #76658 - Aaron1011:fix/encode-dummy-loc-span, r=lcnrbors-157/+159
Properly encode spans with a dummy location and non-root `SyntaxContext` Previously, we would throw away the `SyntaxContext` of any span with a dummy location during metadata encoding. This commit makes metadata Span encoding consistent with incr-cache Span encoding - an 'invalid span' tag is only used when it doesn't lose any information.
2020-09-13Auto merge of #76585 - Aaron1011:ignore-vert-plus, r=petrochenkovbors-0/+149
Ignore `|` and `+` tokens during proc-macro pretty-print check Fixes #76182 This is an alternative to PR #76188 These tokens are not preserved in the AST in certain cases (e.g. a leading `|` in a pattern or a trailing `+` in a trait bound). This PR ignores them entirely during the pretty-print/reparse check to avoid spuriously using the re-parsed tokenstream.
2020-09-12Properly encode spans with a dummy location and non-root `SyntaxContext`Aaron Hill-157/+159
Previously, we would throw away the `SyntaxContext` of any span with a dummy location during metadata encoding. This commit makes metadata Span encoding consistent with incr-cache Span encoding - an 'invalid span' tag is only used when it doesn't lose any information.
2020-09-10Fully integrate token collection for additional AST structsAaron Hill-10/+322
This commit contains miscellaneous changes that don't fit into any of the other commits in this PR
2020-09-10Ignore `|` and `+` tokens during proc-macro pretty-print checkAaron Hill-0/+149
Fixes #76182 This is an alternative to PR #76188 These tokens are not preserved in the AST in certain cases (e.g. a leading `|` in a pattern or a trailing `+` in a trait bound). This PR ignores them entirely during the pretty-print/reparse check to avoid spuriously using the re-parsed tokenstream.
2020-09-10Syntactically permit unsafety on modsDavid Tolnay-0/+116
2020-09-09Auto merge of #76406 - GuillaumeGomez:create-e0774, r=pickfire,jyn514bors-3/+4
Create E0774
2020-09-08Update testsGuillaume Gomez-3/+4
2020-09-04Account for version number in NtIdent hackAaron Hill-7/+43
Issue #74616 tracks a backwards-compatibility hack for certain macros. This has is implemented by hard-coding the filenames and macro names of certain code that we want to continue to compile. However, the initial implementation of the hack was based on the directory structure when building the crate from its repository (e.g. `js-sys/src/lib.rs`). When the crate is build as a dependency, it will include a version number from the clone from the cargo registry (e.g. `js-sys-0.3.17/src/lib.rs`), which would fail the check. This commit modifies the backwards-compatibility hack to check that desired crate name (`js-sys` or `time-macros-impl`) is a prefix of the proper part of the path. See https://github.com/rust-lang/rust/issues/76070#issuecomment-687215646 for more details.
2020-09-02pretty: trim paths of unique symbolsDan Aloni-10/+12
If a symbol name can only be imported from one place for a type, and as long as it was not glob-imported anywhere in the current crate, we can trim its printed path and print only the name. This has wide implications on error messages with types, for example, shortening `std::vec::Vec` to just `Vec`, as long as there is no other `Vec` importable anywhere. This adds a new '-Z trim-diagnostic-paths=false' option to control this feature. On the good path, with no diagnosis printed, we should try to avoid issuing this query, so we need to prevent trimmed_def_paths query on several cases. This change also relies on a previous commit that differentiates between `Debug` and `Display` on various rustc types, where the latter is trimmed and presented to the user and the former is not.
2020-09-01Auto merge of #76010 - Aaron1011:fix/cfg-generic-param, r=petrochenkovbors-0/+251
Run cfg-stripping on generic parameters before invoking derive macros Fixes #75930 This changes the tokens seen by a proc-macro. However, ising a `#[cfg]` attribute on a generic paramter is unusual, and combining it with a proc-macro derive is probably even more unusual. I don't expect this to cause any breakage.
2020-08-30Add `-Z proc-macro-backtrace` to allow showing proc-macro panicsAaron Hill-0/+32
Fixes #75050 Previously, we would unconditionally suppress the panic hook during proc-macro execution. This commit adds a new flag -Z proc-macro-backtrace, which allows running the panic hook for easier debugging.
2020-08-30Run cfg-stripping on generic parameters before invoking derive macrosAaron Hill-0/+251
Fixes #75930 This changes the tokens seen by a proc-macro. However, ising a `#[cfg]` attribute on a generic paramter is unusual, and combining it with a proc-macro derive is probably even more unusual. I don't expect this to cause any breakage.
2020-08-23Auto merge of #75465 - Aaron1011:feature/short-fn-def-span, r=estebankbors-1/+1
Use smaller def span for functions Currently, the def span of a function encompasses the entire function signature and body. However, this is usually unnecessarily verbose - when we are pointing at an entire function in a diagnostic, we almost always want to point at the signature. The actual contents of the body tends to be irrelevant to the diagnostic we are emitting, and just takes up additional screen space. This commit changes the `def_span` of all function items (freestanding functions, `impl`-block methods, and `trait`-block methods) to be the span of the signature. For example, the function ```rust pub fn foo<T>(val: T) -> T { val } ``` now has a `def_span` corresponding to `pub fn foo<T>(val: T) -> T` (everything before the opening curly brace). Trait methods without a body have a `def_span` which includes the trailing semicolon. For example: ```rust trait Foo { fn bar(); } ``` the function definition `Foo::bar` has a `def_span` of `fn bar();` This makes our diagnostic output much shorter, and emphasizes information that is relevant to whatever diagnostic we are reporting. We continue to use the full span (including the body) in a few of places: * MIR building uses the full span when building source scopes. * 'Outlives suggestions' use the full span to sort the diagnostics being emitted. * The `#[rustc_on_unimplemented(enclosing_scope="in this scope")]` attribute points the entire scope body. All of these cases work only with local items, so we don't need to add anything extra to crate metadata.
2020-08-22Use smaller def span for functionsAaron Hill-1/+1
Currently, the def span of a funtion encompasses the entire function signature and body. However, this is usually unnecessarily verbose - when we are pointing at an entire function in a diagnostic, we almost always want to point at the signature. The actual contents of the body tends to be irrelevant to the diagnostic we are emitting, and just takes up additional screen space. This commit changes the `def_span` of all function items (freestanding functions, `impl`-block methods, and `trait`-block methods) to be the span of the signature. For example, the function ```rust pub fn foo<T>(val: T) -> T { val } ``` now has a `def_span` corresponding to `pub fn foo<T>(val: T) -> T` (everything before the opening curly brace). Trait methods without a body have a `def_span` which includes the trailing semicolon. For example: ```rust trait Foo { fn bar(); }``` the function definition `Foo::bar` has a `def_span` of `fn bar();` This makes our diagnostic output much shorter, and emphasizes information that is relevant to whatever diagnostic we are reporting. We continue to use the full span (including the body) in a few of places: * MIR building uses the full span when building source scopes. * 'Outlives suggestions' use the full span to sort the diagnostics being emitted. * The `#[rustc_on_unimplemented(enclosing_scope="in this scope")]` attribute points the entire scope body. * The 'unconditional recursion' lint uses the full span to show additional context for the recursive call. All of these cases work only with local items, so we don't need to add anything extra to crate metadata.
2020-08-22Add backwards-compat hack for certain '$name' tokensAaron Hill-0/+60
See issue #74616
2020-08-22Recursively expand `TokenKind::Interpolated` (take 2)Aaron Hill-62/+112
Fixes #68430 This is a re-attempt of PR #72388, which was previously reverted due to a large number of breakages. All of the known breakages should now be patched upstream.
2020-08-20Capture tokens for Pat used in macro_rules! argumentAaron Hill-2/+55
This extends PR #73293 to handle patterns (Pat). Unlike expressions, patterns do not support custom attributes, so we only need to capture tokens during macro_rules! argument parsing.
2020-08-10Auto merge of #74005 - estebank:type-ascription-redux, r=petrochenkovbors-10/+2
Clean up errors in typeck and resolve * Tweak ordering of suggestions * Do not suggest similarly named enclosing item * Point at item definition in foreign crates * Add missing primary label CC #34255.
2020-08-10Do not suggest similarly named enclosing itemEsteban Küber-10/+2
2020-08-09Remove normalization of `Span` debug output in proc-macro testsAaron Hill-163/+233
Fixes #74800 The definition of `is_x86_feature_detected!` (and similar macros) depends on the platform - it is produced by a `cfg_if!` invocation on x86, and a plain `#[cfg]` on other platforms. Since it is part of the prelude, we will end up importing different hygiene information depending on the platform. This previously required us to avoid printing raw `SyntaxContext` ids in any tests that uses the standard library, since the captured output will be platform-dependent. Previously, we replaced all `SyntaxContext` ids with "#CTXT", and the raw `Span` lo/hi bytes with "LO..HI". This commit adds `#![no_std]` and `extern crate std` to all proc-macro tests that print spans. This suppresses the prelude import, while still using lang items from `std` (which gives us a buildable binary). With this apporach, we will only load hygiene information for things which we explicitly import. This lets us re-add `-Z unpretty=expanded,hygiene`, since its output can now be made stable across all platforms. Additionally, we use `-Z span-debug` in more places, which lets us avoid the "LO..HI" normalization hack.
2020-08-06Add some comments for magic numbers + Add testsVadim Petrochenkov-0/+78
2020-08-03Stabilize Ident::new_rawAaron Hill-0/+61
Tracking issue: #54723 This is a continuation of PR #59002
2020-08-02fix typosliuzhenyu-1/+1
2020-08-02Auto merge of #74785 - euclio:deprecation-kinds, r=petrochenkovbors-2/+2
report kind of deprecated item in message This is important for fields, which are incorrectly referred to as "items".
2020-07-27mv std libs to library/mark-5/+5
2020-07-26Normalize the test output of hygiene-related testsAaron Hill-194/+142
A raw SyntaxContext id is implicitly dependent on the target platform, since libstd and libcore have platform-dependent #[cfg]s which affect which macros are invoked. As a result, we must strip out any SyntaxContext ids from test output to ensure that the captured stdout is not platform-dependent.
2020-07-26Remove explicit `extern crate` from proc-macro testAaron Hill-3/+1
We only want to load this auxiliary crate from a proc-macro, so that it only ever needs to get built for the host platform.
2020-07-26Add test for serializing hygiene *into* a proc-macro crateAaron Hill-12/+61
This is a very obscure corner case, and should never be hit in practice.
2020-07-26Hygiene serialization implementationAaron Hill-117/+124