-
Notifications
You must be signed in to change notification settings - Fork 1.7k
False "missing_const_in_fn" for a function that consumes self
#8874
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
Comments
I'm also experiencing this issue - the code that triggers it follows: pub enum Either<A, B> {
Left(A),
Right(B)
}
impl<A> Either<A, A> {
pub fn unwrap (self) -> A {
match self {
Self::Left(a) => a,
Self::Right(b) => b
}
}
} error as follows:
Error line is incorrect due to removed code - not clippy's fault. |
I can also pitch in with my experience. I have a struct with a generic: pub struct Response<V> {
ok: bool,
value: Option<V>,
} Which implements the following function: fn value(self) -> Option<V> {
self.value
} Clippy suggests making the function a
Note: The struct has other fields and more implementations, but the above is the "minimal" example of the issue. If more is needed, i will happily provide it. |
I believe this was already fixed in #10891. |
When using Rust 1.75, I still see this clippy warning on a straightforward builder pattern and |
Uh oh!
There was an error while loading. Please reload this page.
Summary
Hi,
First of all, thanks a lot for working on Rust and the related tools and crates!
Clippy seems to report a "missing_const_in_fn" for a function that replaces a field in a struct. If I add "const" to the function, rustc says "constant functions cannot evaluate destructors". It is quite possible that, just like e.g. #4041, this is actually a bug in rustc's parser, AST builder, code analyzer, etc; apologies if it has been reported already.
Since the source file is a bit on the large side, I have put the mini-"crate" up in a Git repository at https://gitlab.com/ppentchev/rust-bug-missing-const
Lint Name
clippy::missing_const_for_fn
Reproducer
I tried this code (it uses expect-exit 0.4.2):
I saw this happen:
I expected to see no warnings at all.
Version
Additional Labels
No response
The text was updated successfully, but these errors were encountered: