about summary refs log tree commit diff
path: root/tests/ui/proc-macro
AgeCommit message (Collapse)AuthorLines
2023-12-17Auto merge of #118830 - GuillaumeGomez:env-tracked_env, r=Nilstriebbors-0/+45
Add support for `--env` on `tracked_env::var` Follow-up of https://github.com/rust-lang/rust/pull/118368. Part of Part of https://github.com/rust-lang/rust/issues/80792. It adds support of the `--env` option for proc-macros through `tracked_env::var`. r? `@Nilstrieb`
2023-12-11Add tests for `--env` usage with `tracked_env::var`Guillaume Gomez-0/+45
2023-12-11Rollup merge of #118802 - ehuss:remove-edition-preview, r=TaKO8KiGuillaume Gomez-2/+0
Remove edition umbrella features. In the 2018 edition, there was an "umbrella" feature `#[feature(rust_2018_preview)]` which was used to enable several other features at once. This umbrella mechanism was not used in the 2021 edition and likely will not be used in 2024 either. During 2018 users reported that setting the feature was awkward, especially since they already needed to opt-in via the edition mechanism. This PR removes this mechanism because I believe it will not be used (and will clean up and simplify the code). I believe that there are better ways to handle features and editions. In short: - For highly experimental features, that may or may not be involved in an edition, they can implement regular feature gates like `tcx.features().my_feature`. - For experimental features that *might* be involved in an edition, they should implement gates with `tcx.features().my_feature && span.at_least_rust_20xx()`. This requires the user to still specify `#![feature(my_feature)]`, to avoid disrupting testing of other edition features which are ready and have been accepted within the edition. - For experimental features that have graduated to definitely be part of an edition, they should implement gates with `tcx.features().my_feature || span.at_least_rust_20xx()`, or just remove the feature check altogether and just check `span.at_least_rust_20xx()`. - For relatively simple changes, they can skip the whole feature gating thing and just check `span.at_least_rust_20xx()`, and rely on the instability of the edition itself (which requires `-Zunstable-options`) to gate it. I am working on documenting all of this in the rustc-dev-guide.
2023-12-11Add spacing information to delimiters.Nicholas Nethercote-43/+56
This is an extension of the previous commit. It means the output of something like this: ``` stringify!(let a: Vec<u32> = vec![];) ``` goes from this: ``` let a: Vec<u32> = vec![] ; ``` With this PR, it now produces this string: ``` let a: Vec<u32> = vec![]; ```
2023-12-11Improve `print_tts` by changing `tokenstream::Spacing`.Nicholas Nethercote-62/+215
`tokenstream::Spacing` appears on all `TokenTree::Token` instances, both punct and non-punct. Its current usage: - `Joint` means "can join with the next token *and* that token is a punct". - `Alone` means "cannot join with the next token *or* can join with the next token but that token is not a punct". The fact that `Alone` is used for two different cases is awkward. This commit augments `tokenstream::Spacing` with a new variant `JointHidden`, resulting in: - `Joint` means "can join with the next token *and* that token is a punct". - `JointHidden` means "can join with the next token *and* that token is a not a punct". - `Alone` means "cannot join with the next token". This *drastically* improves the output of `print_tts`. For example, this: ``` stringify!(let a: Vec<u32> = vec![];) ``` currently produces this string: ``` let a : Vec < u32 > = vec! [] ; ``` With this PR, it now produces this string: ``` let a: Vec<u32> = vec![] ; ``` (The space after the `]` is because `TokenTree::Delimited` currently doesn't have spacing information. The subsequent commit fixes this.) The new `print_tts` doesn't replicate original code perfectly. E.g. multiple space characters will be condensed into a single space character. But it's much improved. `print_tts` still produces the old, uglier output for code produced by proc macros. Because we have to translate the generated code from `proc_macro::Spacing` to the more expressive `token::Spacing`, which results in too much `proc_macro::Along` usage and no `proc_macro::JointHidden` usage. So `space_between` still exists and is used by `print_tts` in conjunction with the `Spacing` field. This change will also help with the removal of `Token::Interpolated`. Currently interpolated tokens are pretty-printed nicely via AST pretty printing. `Token::Interpolated` removal will mean they get printed with `print_tts`. Without this change, that would result in much uglier output for code produced by decl macro expansions. With this change, AST pretty printing and `print_tts` produce similar results. The commit also tweaks the comments on `proc_macro::Spacing`. In particular, it refers to "compound tokens" rather than "multi-char operators" because lifetimes aren't operators.
2023-12-10Remove edition umbrella features.Eric Huss-2/+0
2023-12-04Structured `use` suggestion on privacy errorEsteban Küber-1/+5
When encoutering a privacy error on an item through a re-export that is accessible in an alternative path, provide a structured suggestion with that path. ``` error[E0603]: module import `mem` is private --> $DIR/private-std-reexport-suggest-public.rs:4:14 | LL | use foo::mem; | ^^^ private module import | note: the module import `mem` is defined here... --> $DIR/private-std-reexport-suggest-public.rs:8:9 | LL | use std::mem; | ^^^^^^^^ note: ...and refers to the module `mem` which is defined here --> $SRC_DIR/std/src/lib.rs:LL:COL | = note: you could import this help: import `mem` through the re-export | LL | use std::mem; | ~~~~~~~~ ``` Fix #42909.
2023-12-01Auto merge of #117472 - jmillikin:stable-c-str-literals, r=Nilstriebbors-16/+15
Stabilize C string literals RFC: https://rust-lang.github.io/rfcs/3348-c-str-literal.html Tracking issue: https://github.com/rust-lang/rust/issues/105723 Documentation PR (reference manual): https://github.com/rust-lang/reference/pull/1423 # Stabilization report Stabilizes C string and raw C string literals (`c"..."` and `cr#"..."#`), which are expressions of type [`&CStr`](https://doc.rust-lang.org/stable/core/ffi/struct.CStr.html). Both new literals require Rust edition 2021 or later. ```rust const HELLO: &core::ffi::CStr = c"Hello, world!"; ``` C strings may contain any byte other than `NUL` (`b'\x00'`), and their in-memory representation is guaranteed to end with `NUL`. ## Implementation Originally implemented by PR https://github.com/rust-lang/rust/pull/108801, which was reverted due to unintentional changes to lexer behavior in Rust editions < 2021. The current implementation landed in PR https://github.com/rust-lang/rust/pull/113476, which restricts C string literals to Rust edition >= 2021. ## Resolutions to open questions from the RFC * Adding C character literals (`c'.'`) of type `c_char` is not part of this feature. * Support for `c"..."` literals does not prevent `c'.'` literals from being added in the future. * C string literals should not be blocked on making `&CStr` a thin pointer. * It's possible to declare constant expressions of type `&'static CStr` in stable Rust (as of v1.59), so C string literals are not adding additional coupling on the internal representation of `CStr`. * The unstable `concat_bytes!` macro should not accept `c"..."` literals. * C strings have two equally valid `&[u8]` representations (with or without terminal `NUL`), so allowing them to be used in `concat_bytes!` would be ambiguous. * Adding a type to represent C strings containing valid UTF-8 is not part of this feature. * Support for a hypothetical `&Utf8CStr` may be explored in the future, should such a type be added to Rust.
2023-11-24Show number in error message even for one errorNilstrieb-41/+41
Co-authored-by: Adrian <adrian.iosdev@gmail.com>
2023-11-20test: Add test for async-move in 2015 Rust proc macroArthur Cohen-0/+57
Add a test to ensure issue #89699 does not show up again. This test emits an `async move` closure in a proc macro, which is used in a test program compiled with edition 2015. We make sure the error message is nice and shows up properly.
2023-11-01Stabilize C string literalsJohn Millikin-16/+15
2023-10-25Work around the fact that `check_mod_type_wf` may spuriously return ↵Oli Scherer-2/+30
`ErrorGuaranteed`, even if that error is only emitted by `check_modwitem_types`
2023-10-12Add a comment to `tests/ui/proc-macro/issue-75930-derive-cfg.rs`.Nicholas Nethercote-386/+416
Explaining something in the output that surprised me.
2023-10-05Rollup merge of #116428 - Alexendoo:note-duplicate-diagnostics, ↵Matthias Krüger-0/+22
r=compiler-errors,estebank Add a note to duplicate diagnostics Helps explain why there may be a difference between manual testing and the test suite output and highlights them as something to potentially look into For existing duplicate diagnostics I just blessed them other than a few files that had other `NOTE` annotations in
2023-10-05Add a note to duplicate diagnosticsAlex Macleod-0/+22
2023-10-04Point to where missing return type should goMichael Goulet-6/+6
2023-09-26Auto merge of #116124 - WaffleLapkin:fix-proc-macro-literal-to-string, ↵bors-0/+149
r=compiler-errors Properly print cstr literals in `proc_macro::Literal::to_string` Previously we printed the contents of the string, rather than the actual string literal (e.g. `the c string` instead of `c"the c string"`). Fixes #112820 cc #105723
2023-09-24Add a test for printing literals via `proc-macro`Maybe Waffle-0/+149
2023-09-23implement Literal::byte_characterEmil Gardström-0/+5
without this, the only way to create a `LitKind::Byte` is by doing `"b'a'".parse::<Literal>()`, this solves that by enabling `Literal::byte_character(b'a')`
2023-09-10Point out if a local trait has no implementationsMichael Goulet-0/+6
2023-09-01Auto merge of #113126 - Bryanskiy:delete_old, r=petrochenkovbors-1/+1
Replace old private-in-public diagnostic with type privacy lints Next part of RFC https://github.com/rust-lang/rust/issues/48054. r? `@petrochenkov`
2023-08-09Rollup merge of #111891 - rustbox:feat/riscv-isr-cconv, r=jackh726Matthias Krüger-11/+17
feat: `riscv-interrupt-{m,s}` calling conventions Similar to prior support added for the mips430, avr, and x86 targets this change implements the rough equivalent of clang's [`__attribute__((interrupt))`][clang-attr] for riscv targets, enabling e.g. ```rust static mut CNT: usize = 0; pub extern "riscv-interrupt-m" fn isr_m() { unsafe { CNT += 1; } } ``` to produce highly effective assembly like: ```asm pub extern "riscv-interrupt-m" fn isr_m() { 420003a0: 1141 addi sp,sp,-16 unsafe { CNT += 1; 420003a2: c62a sw a0,12(sp) 420003a4: c42e sw a1,8(sp) 420003a6: 3fc80537 lui a0,0x3fc80 420003aa: 63c52583 lw a1,1596(a0) # 3fc8063c <_ZN12esp_riscv_rt3CNT17hcec3e3a214887d53E.0> 420003ae: 0585 addi a1,a1,1 420003b0: 62b52e23 sw a1,1596(a0) } } 420003b4: 4532 lw a0,12(sp) 420003b6: 45a2 lw a1,8(sp) 420003b8: 0141 addi sp,sp,16 420003ba: 30200073 mret ``` (disassembly via `riscv64-unknown-elf-objdump -C -S --disassemble ./esp32c3-hal/target/riscv32imc-unknown-none-elf/release/examples/gpio_interrupt`) This outcome is superior to hand-coded interrupt routines which, lacking visibility into any non-assembly body of the interrupt handler, have to be very conservative and save the [entire CPU state to the stack frame][full-frame-save]. By instead asking LLVM to only save the registers that it uses, we defer the decision to the tool with the best context: it can more accurately account for the cost of spills if it knows that every additional register used is already at the cost of an implicit spill. At the LLVM level, this is apparently [implemented by] marking every register as "[callee-save]," matching the semantics of an interrupt handler nicely (it has to leave the CPU state just as it found it after its `{m|s}ret`). This approach is not suitable for every interrupt handler, as it makes no attempt to e.g. save the state in a user-accessible stack frame. For a full discussion of those challenges and tradeoffs, please refer to [the interrupt calling conventions RFC][rfc]. Inside rustc, this implementation differs from prior art because LLVM does not expose the "all-saved" function flavor as a calling convention directly, instead preferring to use an attribute that allows for differentiating between "machine-mode" and "superivsor-mode" interrupts. Finally, some effort has been made to guide those who may not yet be aware of the differences between machine-mode and supervisor-mode interrupts as to why no `riscv-interrupt` calling convention is exposed through rustc, and similarly for why `riscv-interrupt-u` makes no appearance (as it would complicate future LLVM upgrades). [clang-attr]: https://clang.llvm.org/docs/AttributeReference.html#interrupt-risc-v [full-frame-save]: https://github.com/esp-rs/esp-riscv-rt/blob/9281af2ecffe13e40992917316f36920c26acaf3/src/lib.rs#L440-L469 [implemented by]: https://github.com/llvm/llvm-project/blob/b7fb2a3fec7c187d58a6d338ab512d9173bca987/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp#L61-L67 [callee-save]: https://github.com/llvm/llvm-project/blob/973f1fe7a8591c7af148e573491ab68cc15b6ecf/llvm/lib/Target/RISCV/RISCVCallingConv.td#L30-L37 [rfc]: https://github.com/rust-lang/rfcs/pull/3246
2023-08-08fix(test): improve sensitivity of hygene testsSeth Pellegrino-11/+17
The change in 07f855d7817aa53af8adbb385407f6c2cacc2702 introduced a trailing numeral of some kind after the `extern crate compiler_builtins`, which appears to have caused at least two false negatives (654b924 and 657fd24). Instead, this change normalizes the test output to ignore the number (of symbols rustc recognizes?) to avoid needing to re-`--bless` these two tests for unrelated changes.
2023-08-09Auto merge of #114470 - ↵bors-0/+33
pnkfelix:dont-export-no-mangle-from-proc-macros-issue-99978, r=bjorn3 Restrict linker version script of proc-macro crates to just its two symbols Restrict linker version script of proc-macro crates to just the two symbols of each proc-macro crate. The main known effect of doing this is to stop including `#[no_mangle]` symbols in the linker version script. Background: The combination of a proc-macro crate with an import of another crate that itself exports a no_mangle function was broken for a period of time, because: * In PR #99944 we stopped exporting no_mangle symbols from proc-macro crates; proc-macro crates have a very limited interface and are meant to be treated as a blackbox to everything except rustc itself. However: he constructed linker version script still referred to them, but resolving that discrepancy was left as a FIXME in the code, tagged with issue #99978. * In PR #108017 we started telling the linker to check (via the`--no-undefined-version` linker invocation flag) that every symbol referenced in the "linker version script" is provided as linker input. So the unresolved discrepancy from #99978 started surfacing as a compile-time error (e.g. #111888). Fix #111888 Fix #99978.
2023-08-08fix proc-macro test added here to solely be exercised as a build product for ↵Felix S. Klock II-0/+4
the host. thus we should no longer see test failures for e.g. wasm32 target.
2023-08-06Add a new `compare_bytes` intrinsic instead of calling `memcmp` directlyScott McMurray-2/+2
2023-08-04Auto merge of #112117 - bryangarza:track-caller-feature-gate, r=compiler-errorsbors-2/+2
Add separate feature gate for async fn track caller This patch adds a feature gate `async_fn_track_caller` that is separate from `closure_track_caller`. This is to allow enabling `async_fn_track_caller` separately. Fixes #110009
2023-08-04Update tests/ui/proc-macro/no-mangle-in-proc-macro-issue-111888.rs Felix S Klock II-1/+1
fix to test as proposed by wesleywiser Co-authored-by: Wesley Wiser <wwiser@gmail.com>
2023-08-04regression test for issue 111888.Felix S. Klock II-0/+29
2023-08-02Add separate feature gate for async fn track callerBryan Garza-2/+2
This patch adds a feature gate `async_fn_track_caller` that is separate from `closure_track_caller`. This is to allow enabling `async_fn_track_caller` separately. Fixes #110009
2023-08-02Replace old private-in-public diagnostic with type privacy lintsBryanskiy-1/+1
2023-08-02Fix #107113, avoid suggest for macro attributesyukang-0/+37
2023-07-29Change default panic handler message format.Mara Bos-1/+2
2023-07-29Rollup merge of #114124 - Enselic:proc-fixme, r=cjgillotMatthias Krüger-8/+8
tests/ui/proc-macro/*: Migrate FIXMEs to check-pass proc-macros are processed early in the compiler pipeline. There is no need to involve codegen. So change to check-pass. I have also looked through each changed test and to me it is sufficiently clear that codegen is not needed for the purpose of the test. I skipped changing `tests/ui/proc-macro/no-missing-docs.rs` in this commit because it was not clear to me that it can be changed to check-pass. Part of #62277
2023-07-27tests/ui/proc-macro/*: Migrate FIXMEs to check-passMartin Nordholts-8/+8
proc-macros are processed early in the compiler pipeline. There is no need to involve codegen. So change to check-pass. I have also looked through each changed test and to me it is sufficiently clear that codegen is not needed for the purpose of the test. I skipped changing tests/ui/proc-macro/no-missing-docs.rs in this commit because it was not clear to me that it can be changed to check-pass.
2023-07-25Add `sym::iter_mut` + `sym::as_mut_ptr`blyxyas-2/+2
2023-07-14Hide `compiler_builtins` in the preludeAmanieu d'Antras-335/+329
This crate is a private implementation detail. We only need to insert it into the crate graph for linking and should not expose any of its public API. Fixes #113533
2023-06-29resolve: Remove artificial import ambiguity errorsVadim Petrochenkov-21/+2
2023-06-28Rollup merge of #111571 - jhpratt:proc-macro-span, r=m-ou-seDylan DPC-14/+4
Implement proposed API for `proc_macro_span` As proposed in [#54725 (comment)](https://github.com/rust-lang/rust/issues/54725#issuecomment-1546918161). I have omitted the byte-level API as it's already available as [`Span::byte_range`](https://doc.rust-lang.org/nightly/proc_macro/struct.Span.html#method.byte_range). `@rustbot` label +A-proc-macros r? `@m-ou-se`
2023-06-27Rollup merge of #112454 - ferrocene:pa-compiletest-dynamic-linking, r=davidtwcoMatthias Krüger-0/+1
Make compiletest aware of targets without dynamic linking Some parts of the compiletest internals and some tests require dynamic linking to work, which is not supported by all targets. Before this PR, this was handled by if branches matching on the target name. This PR loads whether a target supports dynamic linking or not from the target spec, and adds a `// needs-dynamic-linking` attribute for tests that require it. Note that I was not able to replace all the old conditions based on the target name, as some targets have `dynamic_linking: true` in their spec but pretend they don't have it in compiletest. Also, to get this to work I had to *partially* revert #111472 (cc `@djkoloski` `@tmandry` `@bjorn3).` On one hand, only the target spec contains whether a target supports dynamic linking, but on the other hand a subset of the fields can be overridden through `-C` flags (as far as I'm aware only `-C panic=$strategy`). The solution I came up with is to take the target spec as the base, and then override the panic strategy based on `--print=cfg`. Hopefully that should not break y'all again.
2023-06-22Tweak privacy errors to account for reachable itemsEsteban Küber-2/+2
Suggest publicly accessible paths for items in private mod: When encountering a path in non-import situations that are not reachable due to privacy constraints, search for any public re-exports that the user could use instead. Track whether an import suggestion is offering a re-export. When encountering a path with private segments, mention if the item at the final path segment is not publicly accessible at all. Add item visibility metadata to privacy errors from imports: On unreachable imports, record the item that was being imported in order to suggest publicly available re-exports or to be explicit that the item is not available publicly from any path. In order to allow this, we add a mode to `resolve_path` that will not add new privacy errors, nor return early if it encounters one. This way we can get the `Res` corresponding to the final item in the import, which is used in the privacy error machinery.
2023-06-20Merge proc_macro_span_shrink and proc_macro_spanJacob Pratt-1/+1
2023-06-20Fix testsJacob Pratt-15/+5
2023-06-20add support for needs-dynamic-linkingPietro Albini-0/+1
2023-06-10Auto merge of #112452 - MU001999:fix/issue-112439, r=petrochenkovbors-4/+8
Make "consider importing" consistent for macros Fixes #112439
2023-06-10Make "consider importing" consistent for macrosMu001999-4/+8
2023-06-05Don't mention already set fieldsMichael Goulet-1/+1
2023-04-24Rollup merge of #110255 - clubby789:proc-macro-test-help, r=jackh726Matthias Krüger-0/+26
Suggest using integration tests for test crate using own proc-macro cc #110247
2023-04-17Suggest using integration tests for proc-macrosclubby789-0/+26
2023-04-15Add some reasons why tests are ignored.Eric Huss-6/+6