You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ArekPiekarz opened this issue
Jan 1, 2020
· 1 comment
Labels
C-bugCategory: Clippy is not doing the correct thingE-hardCall for participation: This a hard problem and requires more experience or effort to work onL-nurseryLint: Currently in the nursery group
A warning "this could be a const_fn" is triggered for a function of a struct that doesn't implement Drop, but on some level of depth contains a member that does implement it. Adding const to such function results in compilation error.
Steps to reproduce
Run the following code with cargo clippy -- -W clippy::missing-const-for-fn:
warning: this could be a const_fn
--> src/main.rs:8:5
|
8 | / fn take(self) -> String{9 | | self.field
10 | | }
| |_____^
|
= note: requested on the command line with `-W clippy::missing-const-for-fn`
= help:for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_const_for_fn
After adding const to the function Foo::take we get an error:
Note that Foo doesn't implement Drop, its field String also doesn't, but String's field Vec does implement it.
Also note there was already a similar fixed issue, but for structs that implement Drop: #4449
The text was updated successfully, but these errors were encountered:
This fixes some additional false positives with functions or methods
that return types which implement drop. Since `drop` can't be
const-evaluated, these cases can't be made const.
Fixesrust-lang#4979
This fixes some additional false positives with functions or methods
that return types which implement drop. Since `drop` can't be
const-evaluated, these cases can't be made const.
Fixesrust-lang#4979
This is now triggering more because more things were made const in rust 1.61.0.
naga has contains the following code:
impl<W:Write>Writer<W>{/// Finishes writing and returns the output.pubfnfinish(self) -> W{self.out}
...
}
This triggers the lint:
warning: this could be a `const fn`
--> src/back/msl/writer.rs:650:5
|
650 | / pub fn finish(self) -> W {
651 | | self.out
652 | | }
| |_____^
|
note: the lint level is defined here
--> src/lib.rs:199:5
|
199 | 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 when you actually apply that you get an error:
error[E0493]: destructors cannot be evaluated at compile-time
--> src/back/msl/writer.rs:650:25
|
650 | pub const fn finish(self) -> W {
| ^^^^ constant functions cannot evaluate destructors
651 | self.out
652 | }
| - value is dropped here
For more information about this error, try `rustc --explain E0493`.
C-bugCategory: Clippy is not doing the correct thingE-hardCall for participation: This a hard problem and requires more experience or effort to work onL-nurseryLint: Currently in the nursery group
cargo clippy -V: clippy 0.0.212 (c807fbc 2019-12-29)
rustc -V: rustc 1.40.0 (73528e339 2019-12-16)
Summary
A warning "this could be a const_fn" is triggered for a function of a struct that doesn't implement Drop, but on some level of depth contains a member that does implement it. Adding const to such function results in compilation error.
Steps to reproduce
Run the following code with
cargo clippy -- -W clippy::missing-const-for-fn
:It results in a warning:
After adding const to the function
Foo::take
we get an error:Note that Foo doesn't implement Drop, its field String also doesn't, but String's field Vec does implement it.
Also note there was already a similar fixed issue, but for structs that implement Drop: #4449
The text was updated successfully, but these errors were encountered: