summary refs log tree commit diff
path: root/src/test/ui/proc-macro
AgeCommit message (Collapse)AuthorLines
2022-09-16Rollup merge of #101741 - andrewpollack:add-needs-unwind-ui-tests, r=tmandryMichael Howell-11/+19
Adding needs-unwind arg to applicable compiler ui tests Adding `needs-unwind` arg to applicable compiler ui tests
2022-09-16Adding needs-unwind arg to applicable compiler ui testsAndrew Pollack-11/+19
2022-09-11Add test for #101211winxpqq955-0/+29
2022-09-04proc_macro/bridge: use the cross-thread executor for nested proc-macrosNika Layzell-3/+20
While working on some other changes in the bridge, I noticed that when running a nested proc-macro (which is currently only possible using the unstable `TokenStream::expand_expr`), any symbols held by the proc-macro client would be invalidated, as the same thread would be used for the nested macro by default, and the interner doesn't handle nested use. After discussing with @eddyb, we decided the best approach might be to force the use of the cross-thread executor for nested invocations, as it will never re-use thread-local storage, avoiding the issue. This shouldn't impact performance, as expand_expr is still unstable, and infrequently used. This was chosen rather than making the client symbol interner handle nested invocations, as that would require replacing the internal interner `Vec` with a `BTreeMap` (as valid symbol id ranges could now be disjoint), and the symbol interner is known to be fairly perf-sensitive. This patch adds checks to the execution strategy to use the cross-thread executor when doing nested invocations. An alternative implementation strategy could be to track this information in the `ExtCtxt`, however a thread-local in the `proc_macro` crate was chosen to add an assertion so that `rust-analyzer` is aware of the issue if it implements `expand_expr` in the future. r? @eddyb
2022-09-04Rollup merge of #100647 - obeis:issue-99875, r=nagisaMatthias Krüger-1/+1
Make trait bound not satisfied specify kind Closes #99875
2022-08-31Fix a bunch of typoDezhi Wu-1/+1
This PR will fix some typos detected by [typos]. I only picked the ones I was sure were spelling errors to fix, mostly in the comments. [typos]: https://github.com/crate-ci/typos
2022-08-29Make the trait bound is not satisfied specify kindObei Sideg-1/+1
2022-08-28Remove `register_attr`-related testsYuki Okushi-247/+183
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
2022-08-21Account for relative pathsMichael Goulet-1/+4
2022-08-08add regression test for #79148Takayuki Maeda-0/+45
2022-07-31Remove workarounds for issue 59998bjorn3-29/+39
2022-07-19Auto merge of #99451 - Dylan-DPC:rollup-ceghu18, r=Dylan-DPCbors-7/+7
Rollup of 8 pull requests Successful merges: - #97183 (wf-check generators) - #98320 (Mention first and last macro in backtrace) - #99335 (Use split_once in FromStr docs) - #99347 (Use `LocalDefId` in `OpaqueTypeKey`) - #99392 (Fix debuginfo tests.) - #99404 (Use span_bug for unexpected field projection type) - #99410 (Update invalid atomic ordering lint) - #99434 (Fix `Skip::next` for non-fused inner iterators) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-07-19Mention first and last macro in backtraceMichael Goulet-7/+7
2022-07-18proc_macro: stop using a remote object handle for IdentNika Layzell-28/+12
Doing this for all unicode identifiers would require a dependency on `unicode-normalization` and `rustc_lexer`, which is currently not possible for `proc_macro` due to it being built concurrently with `std` and `core`. Instead, ASCII identifiers are validated locally, and an RPC message is used to validate unicode identifiers when needed. String values are interned on the both the server and client when deserializing, to avoid unnecessary copies and keep Ident cheap to copy and move. This appears to be important for performance. The client-side interner is based roughly on the one from rustc_span, and uses an arena inspired by rustc_arena. RPC messages passing symbols always include the full value. This could potentially be optimized in the future if it is revealed to be a performance bottleneck. Despite now having a relevant implementaion of Display for Ident, ToString is still specialized, as it is a hot-path for this object. The symbol infrastructure will also be used for literals in the next part.
2022-07-15Auto merge of #98203 - kckeiks:gather-body-owners-in-hir-item-queries, ↵bors-8/+8
r=cjgillot gather body owners Issue #96341
2022-07-13use gathered body_owners in par_body_ownersMiguel Guarniz-8/+8
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-07-10Auto merge of #98463 - mystor:expand_expr_bool, r=eddybbors-1/+70
proc_macro: Fix expand_expr expansion of bool literals Previously, the expand_expr method would expand bool literals as a `Literal` token containing a `LitKind::Bool`, rather than as an `Ident`. This is not a valid token, and the `LitKind::Bool` case needs to be handled seperately. Tests were added to more deeply compare the streams in the expand-expr test suite to catch mistakes like this in the future.
2022-07-06use `named_span` in case of tuple variantTakayuki Maeda-3/+3
2022-07-01Shorten def_span for more items.Camille GILLOT-2/+2
2022-06-29Rollup merge of #98660 - eddyb:invalid-punct-stage1, r=lqdMatthias Krüger-14/+6
Unbreak stage1 tests via ignore-stage1 in `proc-macro/invalid-punct-ident-1.rs`. #98188 broke `./x.py test --stage 1` (which I thought we ran in PR CI, cc `@rust-lang/infra)` i.e. the default `./x.py test` in dev checkouts, as the panic in `src/test/ui/proc-macro/invalid-punct-ident-1.rs` moved from the server (`rustc`) to the client (proc macro), and that means it's now affected by #59998. I made the test look like `src/test/ui-fulldeps/issue-76270-panic-in-libproc-macro.rs` tho I'm a bit confused why that one is in `src/test/ui-fulldeps`, it should still work in `src/test/ui`, no? (cc `@Aaron1011)`
2022-06-29Rollup merge of #98607 - compiler-errors:tuple-wrap-suggestion, r=oli-obkDylan DPC-4/+1
Clean up arg mismatch diagnostic, generalize tuple wrap suggestion This is based on top of #97542, so just look at the last commit which contains the relevant changes. 1. Remove `final_arg_types` which was one of the last places we were using raw (`usize`) indices instead of typed indices in the arg mismatch suggestion code. 2. Improve the tuple wrap suggestion, now we suggest things like `call(a, b, c, d)` -> `call(a, (b, c), d)` :smiley_cat: 3. Folded in fix #98645
2022-06-29Unbreak stage1 tests via ignore-stage1 in `proc-macro/invalid-punct-ident-1.rs`.Eduard-Mihai Burtescu-14/+6
2022-06-28Don't point at another arg if we're already pointing at oneMichael Goulet-4/+1
2022-06-26proc_macro: stop using a remote object handle for PunctNika Layzell-1/+1
This greatly reduces round-trips to fetch relevant extra information about the token in proc macro code, and avoids RPC messages to create Punct tokens.
2022-06-24proc_macro: Fix expand_expr expansion of bool literalsNika Layzell-1/+70
Previously, the expand_expr method would expand bool literals as a `Literal` token containing a `LitKind::Bool`, rather than as an `Ident`. This is not a valid token, and the `LitKind::Bool` case needs to be handled seperately. Tests were added to more deeply compare the streams in the expand-expr test suite to catch mistakes like this in the future.
2022-06-17Rollup merge of #97377 - ChayimFriedman2:issue-91800, r=estebankYuki Okushi-0/+98
Do not suggest adding semicolon/changing delimiters for macros in item position that originates in macros Fixes #91800.
2022-06-16Do not suggest adding semicolon/changing delimiters for macros in item ↵Chayim Refael Friedman-0/+98
position that originates in macros
2022-06-15Refactor path segment parameter errorEdwinRy-4/+6
2022-06-02Revert #96682.Nicholas Nethercote-86/+59
The change was "Show invisible delimiters (within comments) when pretty printing". It's useful to show these delimiters, but is a breaking change for some proc macros. Fixes #97608.
2022-05-27proc_macro: don't pass a client-side function pointer through the server.Eduard-Mihai Burtescu-9/+12
2022-05-04Show invisible delimeters (within comments) when pretty printing.Nicholas Nethercote-59/+86
2022-04-28rustc_ast: Harmonize delimiter naming with `proc_macro::Delimiter`Vadim Petrochenkov-1/+1
2022-04-16Implementation for 65853Jack Huey-0/+5
This attempts to bring better error messages to invalid method calls, by applying some heuristics to identify common mistakes. The algorithm is inspired by Levenshtein distance and longest common sub-sequence. In essence, we treat the types of the function, and the types of the arguments you provided as two "words" and compute the edits to get from one to the other. We then modify that algorithm to detect 4 cases: - A function input is missing - An extra argument was provided - The type of an argument is straight up invalid - Two arguments have been swapped - A subset of the arguments have been shuffled (We detect the last two as separate cases so that we can detect two swaps, instead of 4 parameters permuted.) It helps to understand this argument by paying special attention to terminology: "inputs" refers to the inputs being *expected* by the function, and "arguments" refers to what has been provided at the call site. The basic sketch of the algorithm is as follows: - Construct a boolean grid, with a row for each argument, and a column for each input. The cell [i, j] is true if the i'th argument could satisfy the j'th input. - If we find an argument that could satisfy no inputs, provided for an input that can't be satisfied by any other argument, we consider this an "invalid type". - Extra arguments are those that can't satisfy any input, provided for an input that *could* be satisfied by another argument. - Missing inputs are inputs that can't be satisfied by any argument, where the provided argument could satisfy another input - Swapped / Permuted arguments are identified with a cycle detection algorithm. As each issue is found, we remove the relevant inputs / arguments and check for more issues. If we find no issues, we match up any "valid" arguments, and start again. Note that there's a lot of extra complexity: - We try to stay efficient on the happy path, only computing the diagonal until we find a problem, and then filling in the rest of the matrix. - Closure arguments are wrapped in a tuple and need to be unwrapped - We need to resolve closure types after the rest, to allow the most specific type constraints - We need to handle imported C functions that might be variadic in their inputs. I tried to document a lot of this in comments in the code and keep the naming clear.
2022-04-04Rollup merge of #95343 - dtolnay:literals, r=petrochenkovDylan DPC-2/+13
Reduce unnecessary escaping in proc_macro::Literal::character/string I noticed that https://doc.rust-lang.org/proc_macro/struct.Literal.html#method.character is producing unreadable literals that make macro-expanded code unnecessarily hard to read. Since the proc macro server was using `escape_unicode()`, every char is escaped using `\u{…}` regardless of whether there is any need to do so. For example `Literal::character('=')` would previously produce `'\u{3d}'` which unnecessarily obscures the meaning when reading the macro-expanded code. I've changed Literal::string also in this PR because `str`'s `Debug` impl is also smarter than just calling `escape_debug` on every char. For example `Literal::string("ferris's")` would previously produce `"ferris\'s"` but will now produce `"ferris's"`.
2022-04-02ast_lowering: Stop wrapping `ident` matchers into groupsVadim Petrochenkov-18/+6
The lowered forms goes to metadata, for example during encoding of macro definitions
2022-03-27Rollup merge of #91981 - estebank:tweakaroo, r=lcnrDylan DPC-4/+4
Recover suggestions and useful information lost in previous PR Follow up to #91898.
2022-03-27Eagerly replace `{integer}`/`{float}` with `i32`/`f64` for suggestionEsteban Kuber-4/+4
2022-03-26Use str and char's Debug impl to format literalsDavid Tolnay-8/+8
2022-03-26Add test for proc_macro Literal string and character constructorsDavid Tolnay-0/+11
2022-03-26proc-macro: Stop wrapping `ident` matchers into groupsVadim Petrochenkov-414/+21
2022-03-20Filter OnceNote in diagnostic infra.Camille GILLOT-0/+15
2022-03-11run rust-fix in amputate-span.rs. (Thanks to ekuber for pushing me to do this.)Felix S. Klock II-2/+73
2022-03-03Adjusted diagnostic output so that if there is no `use` in a item sequence,Felix S. Klock II-0/+102
then we just suggest the first legal position where you could inject a use. To do this, I added `inject_use_span` field to `ModSpans`, and populate it in parser (it is the span of the first token found after inner attributes, if any). Then I rewrote the use-suggestion code to utilize it, and threw out some stuff that is now unnecessary with this in place. (I think the result is easier to understand.) Then I added a test of issue 87613.
2022-02-07Auto merge of #93179 - Urgau:unreachable-2021, r=m-ou-se,oli-obkbors-3/+1
Fix invalid special casing of the unreachable! macro This pull-request fix an invalid special casing of the `unreachable!` macro in the same way the `panic!` macro was solved, by adding two new internal only macros `unreachable_2015` and `unreachable_2021` edition dependent and turn `unreachable!` into a built-in macro that do dispatching. This logic is stolen from the `panic!` macro. ~~This pull-request also adds an internal feature `format_args_capture_non_literal` that allows capturing arguments from formatted string that expanded from macros. The original RFC #2795 mentioned this as a future possibility. This feature is [required](https://github.com/rust-lang/rust/issues/92137#issuecomment-1018630522) because of concatenation that needs to be done inside the macro:~~ ```rust $crate::concat!("internal error: entered unreachable code: ", $fmt) ``` **In summary** the new behavior for the `unreachable!` macro with this pr is: Edition 2021: ```rust let x = 5; unreachable!("x is {x}"); ``` ``` internal error: entered unreachable code: x is 5 ``` Edition <= 2018: ```rust let x = 5; unreachable!("x is {x}"); ``` ``` internal error: entered unreachable code: x is {x} ``` Also note that the change in this PR are **insta-stable** and **breaking changes** but this a considered as being a [bug](https://github.com/rust-lang/rust/issues/92137#issuecomment-998441613). If someone could start a perf run and then a crater run this would be appreciated. Fixes https://github.com/rust-lang/rust/issues/92137
2022-01-31Bless all pretty printer tests and ui testsDavid Tolnay-2/+1
2022-01-31Fix invalid special casing of the unreachable! macroLoïc BRANSTETT-3/+1
2022-01-30Bless all pretty printer tests and ui testsDavid Tolnay-56/+54
2022-01-23Remove deduplication of early lintsAaron Hill-5/+87
We already have a general mechanism for deduplicating reported lints, so there's no need to have an additional one for early lints specifically. This allows us to remove some `PartialEq` impls.
2022-01-10expand: Pick `cfg`s and `cfg_attrs` one by one, like other attributesVadim Petrochenkov-15/+1
2021-12-09Add needs-unwind to tests that depend on panickingDavid Koloski-0/+1
This directive isn't automatically set by compiletest or x.py, but can be turned on manually for targets that require it.