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

Wrong suggestion of const fn if type implements Drop #4449

Closed
jfrimmel opened this issue Aug 25, 2019 · 0 comments · Fixed by #4450
Closed

Wrong suggestion of const fn if type implements Drop #4449

jfrimmel opened this issue Aug 25, 2019 · 0 comments · Fixed by #4450
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied L-suggestion Lint: Improving, adding or fixing lint suggestions

Comments

@jfrimmel
Copy link

Hello together,

The following code snippet (in src/lib.rs):

pub struct A;
impl A {
    #![warn(clippy::missing_const_for_fn)]
    pub fn a(self) -> B {
        B
    }
}
impl Drop for A {
    fn drop(&mut self) {}
}

pub struct B;

leads to this suggestion:

warning: this could be a const_fn
 --> src/lib.rs:4:5
  |
4 | /     pub fn a(self) -> B {
5 | |         B
6 | |     }
  | |_____^
  |
note: lint level defined here
 --> src/lib.rs:3:13
  |
3 |     #![warn(clippy::missing_const_for_fn)]
  |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_const_for_fn

but the suggested fix (i.e. add the const qualifier) is wrong. After the fix the following error occurs:

error[E0493]: destructors cannot be evaluated at compile-time
 --> src/lib.rs:4:20
  |
4 |     pub const fn a(self) -> B {
  |                    ^^^^ constant functions cannot evaluate destructors

error: aborting due to previous error

Meta

$ cargo clippy -V
clippy 0.0.212 (e3cb40e 2019-06-25)

$ rustc --version
rustc 1.37.0 (eae3437df 2019-08-13)
@phansch phansch self-assigned this Aug 25, 2019
@phansch phansch added L-suggestion Lint: Improving, adding or fixing lint suggestions C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied labels Aug 25, 2019
@bors bors closed this as completed in 28a8a6a Aug 29, 2019
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-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied L-suggestion Lint: Improving, adding or fixing lint suggestions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants