rust/library
Jubilee c9347f1e27
Rollup merge of #131441 - SpriteOvO:proc-macro-to-tokens-trait, r=dtolnay
Add a new trait `proc_macro::ToTokens`

Tracking issue #130977

This PR adds a new trait `ToTokens`, implemented for types that can be interpolated inside a `quote!` invocation.

```rust
impl ToTokens for TokenTree
impl ToTokens for TokenStream
impl ToTokens for Literal
impl ToTokens for Ident
impl ToTokens for Punct
impl ToTokens for Group
impl<T: ToTokens + ?Sized> ToTokens for &T
impl<T: ToTokens + ?Sized> ToTokens for &mut T
impl<T: ToTokens + ?Sized> ToTokens for Box<T>
impl<T: ToTokens + ?Sized> ToTokens for Rc<T>
impl<T: ToTokens + ToOwned + ?Sized> ToTokens for Cow<'_, T>
impl<T: ToTokens> ToTokens for Option<T>
impl ToTokens for u{8,16,32,64,128}
impl ToTokens for i{8,16,32,64,128}
impl ToTokens for f{32,64}
impl ToTokens for {u,i}size
impl ToTokens for bool
impl ToTokens for char
impl ToTokens for str
impl ToTokens for String
impl ToTokens for CStr
impl ToTokens for CString
```

~This PR also implements the migration mentioned in the tracking issue, replacing `Extend<Token{Tree,Stream}>` with `Extend<T: ToTokens>`, and replacing `FromIterator<Token{Tree,Stream}>` with `FromIterator<T: ToTokens>`.~
**UPDATE**: Reverted.

```diff
-impl FromIterator<TokenTree> for TokenStream
-impl FromIterator<TokenStream> for TokenStream
+impl<T: ToTokens> FromIterator<T> for TokenStream

-impl Extend<TokenTree> for TokenStream
-impl Extend<TokenStream> for TokenStream
+impl<T: ToTokens> Extend<T> for TokenStream
```

I'm going to leave some comments in the review where I'm unsure and concerned.

r? ``@dtolnay``
CC ``@tgross35``
2024-10-28 10:18:49 -07:00
..
alloc Auto merge of #131349 - RalfJung:const-stability-checks, r=compiler-errors 2024-10-25 23:29:40 +00:00
backtrace@230570f2da
core Rollup merge of #131391 - ChaiTRex:isqrt, r=scottmcm,tgross35 2024-10-28 12:14:57 +01:00
panic_abort
panic_unwind move strict provenance lints to new feature gate, remove old feature gates 2024-10-21 15:22:17 +01:00
portable-simd move strict provenance lints to new feature gate, remove old feature gates 2024-10-21 15:22:17 +01:00
proc_macro Add a new trait proc_macro::ToTokens 2024-10-27 03:17:05 +01:00
profiler_builtins
rtstartup
rustc-std-workspace-alloc
rustc-std-workspace-core
rustc-std-workspace-std
std Rollup merge of #132019 - daboross:document-partialeq-oncelock, r=Mark-Simulacrum 2024-10-26 18:45:33 +02:00
stdarch@c881fe3231
sysroot Make profiler_builtins an optional dependency of sysroot, not std 2024-10-17 22:08:36 +11:00
test
unwind move strict provenance lints to new feature gate, remove old feature gates 2024-10-21 15:22:17 +01:00
windows_targets
Cargo.lock Update compiler-builtins to 0.1.134 2024-10-19 11:47:43 -04:00
Cargo.toml