RS.CLIPPY.NEW_RET_NO_SELF

Not returning type containing `Self` in a `new` method

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: new_ret_no_self. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for new not returning a type that contains Self.

Why is this bad?

As a convention, new methods are used to make a new instance of a type.

Example

In an impl block:

impl Foo {
    fn new() -> NotAFoo {
    }
}
struct Bar(Foo);
impl Foo {
    // Bad. The type name must contain `Self`
    fn new() -> Bar {
    }
}
impl Foo {
    // Good. Return type contains `Self`
    fn new() -> Result<Foo, FooError> {
    }
}

Or in a trait definition:

pub trait Trait {
    // Bad. The type name must contain `Self`
    fn new();
}
pub trait Trait {
    // Good. Return type contains `Self`
    fn new() -> Self;
}