bazel /
crubit /
46d515c2db59f5089df0dd461d7f70dc41c97570 Remove blanket `CtorNew<(x,)>` impl, in favor of manual impls.
The problem: for each T, if `X : CtorNew<T>`, then `X : CtorNew<(T,)>`, then `X : CtorNew<((T,),)>`, then...
This causes infinite overflow on failure to match:
```
error[E0275]: overflow evaluating the requirement `_: Sized`
--> third_party/crubit/rs_bindings_from_cc/test/cc_std/test.rs:15:22
|
15 | let _t = tm::ctor_new(());
| ^^^^^^^^^^^^
|
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`main`)
= note: required because of the requirements on the impl of `CtorNew<(_,)>` for `cc_std::tm`
= note: 128 redundant requirements hidden
= note: required because of the requirements on the impl of `CtorNew<(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((_,),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),)>` for `cc_std::tm`
```
However, if we have exactly two impls -- for `T` and `(T,)` (but not `((T,),)` etc.), then the same error becomes:
```
error[E0277]: the trait bound `cc_std::tm: CtorNew<_>` is not satisfied
--> third_party/crubit/rs_bindings_from_cc/test/cc_std/test.rs:15:22
|
15 | let _t = tm::ctor_new(());
| ^^^^^^^^^^^^ the trait `CtorNew<_>` is not implemented for `cc_std::tm`
```
Much, much clearer.
Unfortunately, the only way to do this that I know of is to manually implement the `T` and `(T,)` variants. We can't automatically implement `(T,)` via blanket impl, because that will also implement `((T,),)`, etc. And we can't start with `(T,)` and automatically implement for `T`, because this produces the same infinite recursion errors even faster (https://play.rust-lang.org/?gist=87e3bbdbe8ea6ac0e2d16f4d3a9a37b2).
So yeah, the solution would seem to be manual impls. Although exactly how to do them is up in the air -- this CL just pastes in a short snippet as an extra item. I'm not super happy with it, but there's no easy way to do it in a more structured way for now.
P.S. I swore I already had implemented this. I can't find it in my CL history, so I must have thrown it away... oops!
PiperOrigin-RevId: 446146280
6 files changed