Skip to content

new_without_default doesn't trigger on const fn #10877

@robertbastian

Description

@robertbastian
Contributor

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

Activity

added
C-bugCategory: Clippy is not doing the correct thing
I-false-negativeIssue: The lint should have been triggered on code, but wasn't
on Jun 2, 2023
Centri3

Centri3 commented on Jun 3, 2023

@Centri3
Member

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

robertbastian

robertbastian commented on Jun 4, 2023

@robertbastian
ContributorAuthor

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

Centri3

Centri3 commented on Jun 4, 2023

@Centri3
Member

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

added 2 commits that reference this issue on Feb 16, 2024
9064cc8
61daf67
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn't

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @robertbastian@Centri3

    Issue actions

      `new_without_default` doesn't trigger on `const fn` · Issue #10877 · rust-lang/rust-clippy