Skip to content

Recursive function call generates confusing overflow message #72577

Closed
@o0Ignition0o

Description

@o0Ignition0o

error[E0275]: overflow evaluating the requirement &mut bytes::bytes_mut::BytesMut: bytes::buf::buf_impl::Buf

Here's a link to the playground : https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=e0d226183c371b79d9a234ccebdeafd0

I tried this code:

use bytes::{Buf, BytesMut};

fn get_value<B>(buf: &mut B) -> Result<i32, String>
where
    B: Buf,
{
    Ok(42)
}

fn do_more<B>(mut buf: B) -> Result<i32, String>
where
    B: Buf,
{
    if buf.has_remaining() {
        get_value(&mut buf)
    } else {
        do_more(&mut buf)
    }
}

fn main() {
    let payload = vec![1, 2, 3, 4, 5];
    let parsed = do_more(&mut BytesMut::from(&*payload)).unwrap();
}

I expected to see this happen: Nothing really, but I would love to see an error message that would help me out here ^^.

Instead, this happened:

image

Meta

rustc --version --verbose:

playground (stable) and tested it on my machine: rustc 1.43.1 (8d69840ab 2020-05-04)

Link to the twitter discussion https://twitter.com/ekuber/status/1264962969206525952?s=20

Paging @estebank who might be interested <3

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-verboseDiagnostics: Too much output caused by a single piece of incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions