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

new_without_default doesn't trigger on const fn #10877

Closed
robertbastian opened this issue Jun 2, 2023 · 3 comments · Fixed by #10903
Closed

new_without_default doesn't trigger on const fn #10877

robertbastian opened this issue Jun 2, 2023 · 3 comments · Fixed by #10903
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't

Comments

@robertbastian
Copy link
Contributor

robertbastian commented Jun 2, 2023

Summary

Triggers on pub fn new() -> Self but not pub const fn new() -> Self

Lint Name

new_without_default

Reproducer

I tried this code:

pub struct Foo;

impl Foo {
  pub const fn new() -> {
    Self
  }
}

I expected to see this happen: lint triggers

Instead, this happened: lint doesn't trigger

Version

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=256edf22e6afcae3a1f23322a19851de
@robertbastian robertbastian added C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't labels Jun 2, 2023
@Centri3
Copy link
Member

Centri3 commented Jun 3, 2023

Default::default is not const so afaict this is correct behavior, same with unsafe fn new

@robertbastian
Copy link
Contributor Author

robertbastian commented Jun 4, 2023

Default::default can call const fn new though. It can't call unsafe fn new without being unsafe itself, so that's different.

@Centri3
Copy link
Member

Centri3 commented Jun 4, 2023

Yeah that's fair actually, this is still intentionally done by the lint's author but this should probably be changed at some point. @rustbot claim

bors added a commit that referenced this issue Feb 16, 2024
[`new_without_default`]: Now emits on const fns

While `Default::default` is not const, it can still call `const new`; there's no reason this shouldn't be linted as well.

fixes #10877

changelog: [`new_without_default`]: Now emits on const fns
@bors bors closed this as completed in 61daf67 Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants