Skip to content

unconditional_recursion false positive with trait default implementation #26333

Closed
@eefriedman

Description

@eefriedman
trait TraitA {
    type AssocType;
    fn other(&self) -> Self::AssocType;
}

trait TraitB<T:TraitB<T>>: TraitA<AssocType=T>
{
    fn stuff(&self) {
        println!("stuff() default impl");
        self.other().stuff()
    }
}

struct A;
impl TraitA for A {
    type AssocType = A;
    fn other(&self) -> Self::AssocType { A }
}
impl TraitB<A> for A {
    fn stuff(&self) {
        println!("stuff() A impl");
    }
}

struct B;
impl TraitA for B {
    type AssocType = A;
    fn other(&self) -> Self::AssocType { A }
}
impl TraitB<A> for B {}

fn main(){
    B.stuff();
    println!("Function that can't return returned!");
}

Gives:

<anon>:8:5: 11:6 warning: function cannot return without recurring, #[warn(unconditional_recursion)] on by default
<anon>:8     fn stuff(&self) {
<anon>:9         println!("stuff() default impl");
<anon>:10         self.other().stuff()
<anon>:11     }
<anon>:10:9: 10:29 note: recursive call site
<anon>:10         self.other().stuff()
                  ^~~~~~~~~~~~~~~~~~~~
<anon>:8:5: 11:6 help: a `loop` may express intention better if this is on purpose
stuff() default impl
stuff() A impl
Function that can't return returned!

#21705 is sort of related, but not really the same thing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions