Skip to content

Implement default using default #103

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

Closed
llogiq opened this issue Jun 21, 2015 · 2 comments
Closed

Implement default using default #103

llogiq opened this issue Jun 21, 2015 · 2 comments
Labels
A-lint Area: New lints E-medium Call for participation: Medium difficulty level problem and requires some initial experience. T-middle Type: Probably requires verifiying types

Comments

@llogiq
Copy link
Contributor

llogiq commented Jun 21, 2015

On StackOverflow, someone suggested the compiler should keep them from implementing default in terms of itself.

Well, it's not exactly a common use case, but it's also pretty easy to spot.

@llogiq
Copy link
Contributor Author

llogiq commented Jun 21, 2015

It just occurred to me that this is a special case of a more general 'unbounded_recursion' lint, only for trait impls.

@Manishearth Manishearth added E-medium Call for participation: Medium difficulty level problem and requires some initial experience. T-middle Type: Probably requires verifiying types A-lint Area: New lints labels Aug 11, 2015
@mcarton
Copy link
Member

mcarton commented Jan 19, 2016

This can be closed, Rust has a unconditional_recursion lint since v1.3 (2015-09-17) which warns exactly for that:

% cat a.rs 
use std::default;

pub struct A {
    x: i32
}

impl Default for A {
    fn default() -> A {
        A { ..Default::default() }
    }
}

fn main() {
    let test = A { ..Default::default() };
}

% rustc a.rs 
[]
a.rs:8:5: 10:6 warning: function cannot return without recurring, #[warn(unconditional_recursion)] on by default
a.rs: 8     fn default() -> A {
a.rs: 9         A { ..Default::default() }
a.rs:10     }
a.rs:9:15: 9:33 note: recursive call site
a.rs:9         A { ..Default::default() }
                     ^~~~~~~~~~~~~~~~~~
a.rs:8:5: 10:6 help: a `loop` may express intention better if this is on purpose
[]
                ^~~~

and there also is #428 for a more general recursion lint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints E-medium Call for participation: Medium difficulty level problem and requires some initial experience. T-middle Type: Probably requires verifiying types
Projects
None yet
Development

No branches or pull requests

3 participants