Skip to content

Manual auto trait impl can be more work for the trait solver, including higher recursion depth #162850

Description

@maxdexh

I accidentally hit this in #162804 (comment).

Essentially, replacing Unique<u8> with NonNull<u8> in RawVecInner<A> meant that I had to rewrite the Send, Sync, and UnwindSafe impls for it.
I initially chose to do this on RawVec<T, A> using impl<T: AuTr, A: Allocator + AuTr> AuTr for RawVec<T, A>.
This caused slight compile time regressions, as well as a compile error due to the trait solver now exceeding the recursion limit on a complex rayon iterator, likely due to the Send supertrait bound on ParallelIterator.

The benchmark that failed to compile can be found in src/tools/rustc-perf/collector/runtime-benchmarks/css/, and the failure reproduced with cargo +b67dca92df005a4ebbe8c3b45e6cfe97925fff26 check, using kennytm/rustup-toolchain-install-master.

This is dangerous especially for std, because it risks introducing regressions when refactoring the internals of commonly used types.

Note that the old impls were auto-derived from the A and PhantomData<T> fields, because Unique<u8> implemented all the relevant traits.
Now that I've pulled the manual impls back to impl<A: Allocator + AuTr> AuTr for RawVecInner<A>, it seems to no longer be regressing (still waiting for perf).
All these impls should be equivalent (if anything, I'd expect the auto impl to be more work than the manual one).

@rustbot label WG-trait-system-refactor A-auto-traits E-needs-mcve T-types

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-auto-traitsArea: auto traits (e.g., `auto trait Send {}`)C-bugCategory: This is a bug.E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleT-typesRelevant to the types team, which will review and decide on the PR/issue.WG-trait-system-refactorThe Rustc Trait System Refactor Initiative (-Znext-solver)needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions