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

const functions should not trigger or_fun_call #6943

Closed
Sciencentistguy opened this issue Mar 20, 2021 · 1 comment · Fixed by #6950
Closed

const functions should not trigger or_fun_call #6943

Sciencentistguy opened this issue Mar 20, 2021 · 1 comment · Fixed by #6950
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@Sciencentistguy
Copy link
Contributor

Lint name: or_fun_call

I tried this code:

let x = None;
let s: &str = "hello world";
s.unwrap_or(s.len());

I expected to see this happen: As str::len is a const function, it is inlined as a usize. So the suggestion to use .unwrap_or_else() introduces more overhead than is needed.

Instead, this happened: The lint is triggered

Meta

  • cargo clippy -V: clippy 0.1.52 (f5d8117 2021-03-16)
  • rustc -Vv:
rustc 1.52.0-nightly (f5d8117c3 2021-03-16)
binary: rustc
commit-hash: f5d8117c338a788bd24abec733fd143dfceb25a0
commit-date: 2021-03-16
host: x86_64-unknown-linux-gnu
release: 1.52.0-nightly
LLVM version: 12.0.0
@Sciencentistguy Sciencentistguy added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Mar 20, 2021
@camsteffen
Copy link
Contributor

We cannot simply ignore const functions since they are not guaranteed to be evaluated at compile time. See #1527. However we can ignore str::len since we also ignore slice::len.

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 good-first-issue These issues are a good way to get started with Clippy I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants