241 Commits

Author SHA1 Message Date
Matthias Krüger
465ae94328
Rollup merge of #143631 - hkBst:update-escaper-2, r=compiler-errors
update to literal-escaper-0.0.5

Quoting from the changelog, this version brings:
- Use `NonZero<char/u8>` in `unescape_c_str` and `check_raw_c_str` to statically exclude nuls
- Add `#[inline]` to small functions for improved performance
2025-07-17 10:41:45 +02:00
Trevor Gross
73d3adc67b
Rollup merge of #141996 - Daniel-Aaron-Bloom:dollar_crate, r=petrochenkov
Fix `proc_macro::Ident`'s handling of `$crate`

This PR is addresses a few minor bugs, all relating to `proc_macro::Ident`'s support for `$crate`. `Ident` currently supports `$crate` (as can be seen in the `mixed-site-span` test), but:
* `proc_macro::Symbol::can_be_raw` is out of sync with `rustc_span::Symbol::can_be_raw`
  * former doesn't cover `$crate` while the latter does cover `kw::DollarCrate`
* `Ident::new` rejects `$crate`
  * This conflicts with the [reference definition](https://doc.rust-lang.org/nightly/reference/macros-by-example.html#r-macro.decl.meta.specifier) of `ident` which includes `$crate`.
  * This also conflicts with the documentation on [`Display for Ident`](https://doc.rust-lang.org/proc_macro/struct.Ident.html#impl-Display-for-Ident) which says the output "should be losslessly convertible back into the same identifier".

This PR fixes the above issues and extends the `mixed-site-span` test to exercise these fixed code paths, as well as validating the different possible spans resolve `$crate`  as expected (for both the new and old `$crate` construction code paths).
2025-07-10 03:23:52 -04:00
Marijn Schouten
d44dcd4513 update to literal-escaper-0.0.5 2025-07-08 10:16:44 +00:00
bors
2c2bb995af Auto merge of #140999 - hkBst:update-escaper, r=nnethercote
update to literal-escaper 0.0.4 for better API without `unreachable` and faster string parsing

This is the replacement for just the part of https://github.com/rust-lang/rust/pull/138163 dealing with the changed API of unescape functionality, since that got moved into its own crate.

<del>This uses an unpublished version of literal-escaper (https://github.com/rust-lang/literal-escaper/pull/8).</del>

r? `@nnethercote`
2025-06-25 01:03:30 +00:00
Marijn Schouten
707a6f5463 update to literal-escaper 0.0.4 for better API without unreachable and faster string parsing 2025-06-23 06:36:22 +00:00
Tomoaki Kobayashi
23e35c6bd3 Add support for repetition to proc_macro::quote 2025-06-17 01:36:54 +09:00
bjorn3
3e944fa391 Remove all support for wasm's legacy ABI 2025-06-14 09:57:06 +00:00
Daniel Bloom
6d1e93d8cd Add support for $crate to Ident 2025-06-12 01:13:24 -07:00
bjorn3
026baa1c6f Do not get proc_macro from the sysroot in rustc
With the stage0 refactor the proc_macro version found in the sysroot
will no longer always match the proc_macro version that proc-macros get
compiled with by the rustc executable that uses this proc_macro. This
will cause problems as soon as the ABI of the bridge gets changed to
implement new features or change the way existing features work.

To fix this, this commit changes rustc crates to depend directly on the
local version of proc_macro which will also be used in the sysroot that
rustc will build.
2025-05-27 15:49:28 +00:00
Pietro Albini
779dd35649
manual clippy fixes 2025-05-12 15:33:41 +02:00
Pietro Albini
a360940ac9
update version placeholders 2025-05-12 15:33:30 +02:00
Mara Bos
2a053c7a15 Update doc comments. 2025-04-30 15:28:45 +02:00
Mara Bos
d6ae459af8 Stabilize proc_macro::Span::{file, local_file}. 2025-04-30 15:28:09 +02:00
Mara Bos
c5c93626a0 Stabilize proc_macro::Span::{start, end, line, column}. 2025-04-15 17:29:04 +02:00
Mara Bos
3962069982 Replace proc_macro::SourceFile by Span::{file, local_file}. 2025-04-11 15:07:08 +02:00
Mara Bos
6788ce76c9 Remove proc_macro::SourceFile::is_real(). 2025-04-11 14:02:06 +02:00
Boxy
c93005ee65 update cfgs 2025-04-09 12:29:59 +01:00
Guillaume Gomez
2b533e6b49 bootstrap: Only add rustc_randomized_layouts if the crate has it 2025-04-04 22:26:10 +02:00
Guillaume Gomez
13400c2c10 Add _value methods to proc_macro lib 2025-04-04 15:04:17 +02:00
Ralf Jung
61e24e630d allow wasm_c_abi in proc_macro bridge 2025-03-25 08:22:35 +01:00
Ralf Jung
20d04d8a40 Revert "Rollup merge of #136355 - GuillaumeGomez:proc-macro_add_value_retrieval_methods, r=Amanieu"
This reverts commit 08dfbf49e30d917c89e49eb14cb3f1e8b8a1c9ef, reversing
changes made to 10bcdad7df0de3cfb95c7bdb7b16908e73cafc09.
2025-03-18 13:28:56 +01:00
Jacob Pratt
08dfbf49e3
Rollup merge of #136355 - GuillaumeGomez:proc-macro_add_value_retrieval_methods, r=Amanieu
Add `*_value` methods to proc_macro lib

This is the implementation of https://github.com/rust-lang/libs-team/issues/459.

It allows to get the actual value (unescaped) of the different string literals.

Part of https://github.com/rust-lang/rust/issues/136652.

r? libs-api
2025-03-17 05:47:48 -04:00
Guillaume Gomez
ec4b3c2779 Add test for new proc_macro literal methods 2025-03-16 14:28:45 +01:00
Eric Huss
0b2489c226 Migrate proc_macro to Rust 2024 2025-03-11 09:46:34 -07:00
Thalia Archibald
988eb19970 library: Use size_of from the prelude instead of imported
Use `std::mem::{size_of, size_of_val, align_of, align_of_val}` from the
prelude instead of importing or qualifying them.

These functions were added to all preludes in Rust 1.80.
2025-03-06 20:20:38 -08:00
Eric Huss
80a7eb1c09 proc_macro: Apply unsafe_op_in_unsafe_fn 2025-02-14 07:36:17 -08:00
Guillaume Gomez
b993f9c835 Add _value methods to proc_macro lib 2025-02-10 10:38:22 +01:00
Urgau
bf5e634b68 proc_macro: add #![warn(unreachable_pub)] 2025-01-20 18:46:29 +01:00
ltdk
e37daf0c86 Add inherent versions of MaybeUninit methods for slices 2025-01-11 23:57:00 -05:00
Jacob Pratt
34fa27b0bd
Rollup merge of #134693 - SpriteOvO:proc-macro-use-to-tokens-in-quote, r=tgross35
proc_macro: Use `ToTokens` trait in `quote` macro

Tracking issues: #130977, #54722

This PR changed `proc_macro::quote!` to use `ToTokens` trait instead of `TokenStream::from`, and migrated test cases from `quote` crate.

r? `@dtolnay`
CC `@tgross35`
2025-01-10 03:55:19 -05:00
Asuna
ef69c3001b Fix proc_macro::quote! for raw ident 2025-01-09 22:16:21 +01:00
Asuna
d52564118b Append TokenTree with ToTokens in proc_macro::quote! 2025-01-09 22:16:11 +01:00
Asuna
2a2e87b398 Rename the internal simpler quote macro to minimal_quote 2025-01-01 20:56:58 +01:00
Esteban Küber
1f82b45b6a Use #[derive(Default)] instead of manually implementing it 2024-12-23 03:01:29 +00:00
bjorn3
b805f30542 Remove support for specializing ToString outside the standard library
This is the only trait specializable outside of the standard library.
Before stabilizing specialization we will probably want to remove
support for this. It was originally made specializable to allow a more
efficient ToString in libproc_macro back when this way the only way to
get any data out of a TokenStream. We now support getting individual
tokens, so proc macros no longer need to call it as often.
2024-12-13 13:48:19 +00:00
Ralf Jung
9182aa0bf7 rustc_allow_const_fn_unstable is not used in proc_macro 2024-11-30 11:55:58 +01:00
Asuna
42fbaf1ddd Add a new trait proc_macro::ToTokens 2024-10-27 03:17:05 +01:00
Ralf Jung
854e3c43e0 library: consistently use American spelling for 'behavior' 2024-10-25 12:02:47 +02:00
Ralf Jung
56ee492a6e move strict provenance lints to new feature gate, remove old feature gates 2024-10-21 15:22:17 +01:00
GnomedDev
6d8815887c
Remove TODO in proc_macro now const_refs_to_static is stable 2024-10-17 09:41:51 +01:00
Slanterns
30ff4006e1
update Literal's intro 2024-10-02 01:27:11 +08:00
Michael Goulet
c682aa162b Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
Josh Stone
8bab397835 Revert "Add a hack to prevent proc_macro misopt in CI"
This reverts commit da8ac73d910a446e796f511c0dda97e49d14f044.
2024-09-18 13:53:33 -07:00
Jubilee Young
169b2f0e6d library: Stabilize new_uninit for Box, Rc, and Arc
A partial stabilization that only affects:
- AllocType<T>::new_uninit
- AllocType<T>::assume_init
- AllocType<[T]>::new_uninit_slice
- AllocType<[T]>::assume_init
where "AllocType" is Box, Rc, or Arc
2024-08-27 10:17:05 -07:00
Matthias Krüger
8f7af88b33
Rollup merge of #128307 - ojeda:unescaped_backticks, r=GuillaumeGomez
Clean and enable `rustdoc::unescaped_backticks` for `core/alloc/std/test/proc_macro`

I am not sure if the lint is supposed to be "ready enough" (since it is `allow` by default), but it does catch a couple issues in `core` (`alloc`, `std`, `test` and `proc_macro` are already clean), so I propose making it `warn` in all the crates rendered in the website.

Cc: `@GuillaumeGomez`
2024-07-29 11:42:35 +02:00
Miguel Ojeda
dc815df1e1 Warn on rustdoc::unescaped_backticks for core/alloc/std/test/proc_macro
They are all clean now, so enable the lint to keep them clean going forward.

Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2024-07-29 00:58:45 +02:00
Nicholas Nethercote
84ac80f192 Reformat use declarations.
The previous commit updated `rustfmt.toml` appropriately. This commit is
the outcome of running `x fmt --all` with the new formatting options.
2024-07-29 08:26:52 +10:00
John Arundel
a19472a93e Fix doc nits
Many tiny changes to stdlib doc comments to make them consistent (for example
"Returns foo", rather than "Return foo", per RFC1574), adding missing periods, paragraph
breaks, backticks for monospace style, and other minor nits.

https://github.com/rust-lang/rfcs/blob/master/text/1574-more-api-documentation-conventions.md#appendix-a-full-conventions-text
2024-07-26 13:26:33 +01:00
Matthias Krüger
34abb9647c
Rollup merge of #127733 - GrigorenkoPV:don't-forget, r=Amanieu
Replace some `mem::forget`'s with `ManuallyDrop`

              > but I would like to see a larger effort to replace all uses of `mem::forget`.

_Originally posted by `@saethlin` in https://github.com/rust-lang/rust/issues/127584#issuecomment-2226087767_

So,
r? `@saethlin`

Sorry, I have finished writing all of this before I got your response.
2024-07-24 18:00:39 +02:00
Yuri Astrakhan
91275b2c2b Avoid ref when using format! for perf
Clean up a few minor refs in `format!` macro, as it has a tiny perf
cost. A few more minor related cleanups.
2024-07-19 12:23:49 -04:00