Skip to content
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

Uncaught unconditional recursion in From impl #98217

Open
CyrusAlbright opened this issue Jun 18, 2022 · 2 comments
Open

Uncaught unconditional recursion in From impl #98217

CyrusAlbright opened this issue Jun 18, 2022 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@CyrusAlbright
Copy link

Rustc has no issues compiling the following code (playground link):

#![deny(unconditional_recursion)]

struct Dummy;

impl From<u8> for Dummy {
    fn from(u: u8) -> Self {
        u.into()
    }
}

The other way of writing this, however, does (correctly) fail to compile (playground link):

#![deny(unconditional_recursion)]

struct Dummy;

impl From<u8> for Dummy {
    fn from(u: u8) -> Self {
        Dummy::from(u)
    }
}

I assume that type inference is happening after the unconditional_recursion lint causing it to miss this?

@CyrusAlbright CyrusAlbright added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 18, 2022
@eggyal
Copy link
Contributor

eggyal commented Jun 18, 2022

The lint only detects direct recursion (where a function calls itself). It doesn't detect recursion through other functions, so the following will compile (playground):

#![deny(unconditional_recursion)]

pub fn a() {
    b()
}

pub fn b() {
    a()
}

In your example, <Dummy as From<u8>>::from is calling <u8 as Into<Dummy>>::into which then calls back to the former.

@jruderman
Copy link
Contributor

This is a case of #57965 where the recursion goes through trait functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants