Skip to content

Detect internal implementation usage that leads to infinite recursion #74714

Closed
@TotalKrill

Description

@TotalKrill

We found a simple way to cause infinite recursion in a sneaky way, it would be great to be able to have this as a warning or something.

When implementing a trait, that trait can be invoked inside the trait implementation. Causing hard to detect bugs.

Simplest example:

use std::fmt;
pub struct S;
impl fmt::Display for S {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}", self)
    }
}
fn main() {
    print!("{}", S);
}

link to playground

Activity

jonas-schievink

jonas-schievink commented on Jul 24, 2020

@jonas-schievink
Contributor

Duplicate of #57965

jonas-schievink

jonas-schievink commented on Jul 24, 2020

@jonas-schievink
Contributor

or rather, #58035

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @jonas-schievink@TotalKrill

        Issue actions

          Detect internal implementation usage that leads to infinite recursion · Issue #74714 · rust-lang/rust