Skip to content

Unconditional_recursion lint not triggered in procedural macro #61504

@treere

Description

@treere

Hi,
I ma working with edition 2018 and I tried this piece of code with 1.37 nightly, 1.35 and 1.32 (random pick) with the same result.
Sorry if the point of my issue is at the end but I belive that the code is much more clear than me.

The code is:

lib.rs:

extern crate proc_macro;

use proc_macro::TokenStream;

#[proc_macro_derive(TestMacro)]
pub fn derive_answer_fn(input: TokenStream) -> TokenStream {
    let name = input.into_iter().nth(1).unwrap();

    format!(
        r#"
        pub trait A {{
            fn f() -> Self;
        }}

        #[deny(unconditional_recursion)]
        impl A for {0} {{
            fn f() -> Self {{

            let a = 0;
                <{0} as A>::f()
            }}
        }}"#, name.to_string()
    ).parse().unwrap()
}

test.rs:

use m::TestMacro;

#[derive(TestMacro)]
struct Struct;

fn main() {
    Struct::f();
}

I thought my test code would behave like:

struct Struct;

pub trait A {
    fn f() -> Self;
}

#[deny(unconditional_recursion)]
impl A for Struct {
    fn f() -> Self {
        <Struct as A>::f()
    }
}

fn main() {
    Struct::f();
}

giving this error:

error: function cannot return without recursing

instead compiles and (obviously)

thread 'main' has overflowed its stack
fatal runtime error: stack overflow

Am I doing something wrong?
When does the linter check my code?
Is this a normal behavoir?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.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