Skip to content

Wrapper<T> where bounds recursion error #136541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
zeroflaw opened this issue Feb 4, 2025 · 1 comment
Closed

Wrapper<T> where bounds recursion error #136541

zeroflaw opened this issue Feb 4, 2025 · 1 comment
Labels
C-bug Category: This is a bug.

Comments

@zeroflaw
Copy link

zeroflaw commented Feb 4, 2025

I tried this code:

pub struct Enc<T>(T);

pub trait Encode {}
impl<A> Encode for Enc<Vec<A>> where Enc<A>: Encode {}

pub fn write() where Enc<()>: Encode {}

I expected this to compile.

Instead, this happened:

error[E0275]: overflow evaluating the requirement `_: Sized`
help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`playground`)
note: required for `Enc<Vec<_>>` to implement `Encode`

A more verbose example:
If T is explicitly typed, the code will compile. feel free to comment out the line in the playground version to see a working example.

#[test]
fn call_write() {
    write(&1_i8); //ERROR (recursion: overflow evaluating the requirement?)
    write::<i8>(&1_i8); // OK without the above line
}

pub struct Enc<T: ?Sized>(pub *const T);

pub fn write<T>(_: &T) where Enc<T>: Encode {}

pub trait Encode {}
impl Encode for Enc<i8> {}
impl<A> Encode for Enc<Vec<A>> where Enc<A>: Encode {}

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=d4352d96adc9ea2b8290c346a38a948e

Meta

This also occurs on stable

rustc --version --verbose:

rustc 1.86.0-nightly (f027438f8 2025-02-03)
binary: rustc
commit-hash: f027438f8bc6b747528dca8b8de13043544d7238
commit-date: 2025-02-03
host: x86_64-unknown-linux-gnu
release: 1.86.0-nightly
LLVM version: 19.1.7
@zeroflaw zeroflaw added the C-bug Category: This is a bug. label Feb 4, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 4, 2025
@theemathas
Copy link
Contributor

Duplicate of #113496 (comment)

@oli-obk oli-obk closed this as completed Feb 4, 2025
@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

5 participants