Infinite recursion while resolving traits #88925
Labels
A-monomorphization
Area: Monomorphization
C-bug
Category: This is a bug.
I-monomorphization
Issue: An error at monomorphization time.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Hi all! I'm running into an issue that is difficult for me to describe other than by giving a simple example. I believe the following code should compile, but instead it seems like the compiler gets stuck in a loop:
As is, the compiler gives this error when running
cargo build
:Since
writer: T
implementsWrite
(asT
has the trait bound), I would expectwriter.by_ref()
to also implementWrite
, per the documentation ofby_ref()
. But the compiler does not seem satisfied by that, and instead seems to get stuck in some kind of loop (until the recursion limit is reached).The build succeeds if the commented line is uncommented. It seems boxing the
writer
into a trait object terminates the recursion. But that requires an extra allocation, so it's not a satisfying workaround.(Strangely,
cargo check
succeeds on both versions and doesn't seem to run into this issue.)Thanks for looking into this, and I apologize if this is a duplicate of another issue. I tried searching and found a few possible instances of people running into the compiler's recursion limit, but it was hard for me to tell if it was the same issue as this one.
Meta
rustc --version --verbose
:Backtrace
The text was updated successfully, but these errors were encountered: