Skip to content

Avoid or_fun_call for const_fn with no args #5889

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Aug 10, 2020

Conversation

ebroto
Copy link
Member

@ebroto ebroto commented Aug 10, 2020

Based on #5682 by @lzutao

This avoids a subset of false positives, specifically those related to const fns that take no arguments.
For the rest, a much more involved fix would be needed, see #5682 (comment).

So this does not solve #5658

changelog: Avoid triggering [or_fun_call] with const fns that take no arguments.

Fixes #5886

@rust-highfive
Copy link

r? @Manishearth

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Aug 10, 2020
@Manishearth
Copy link
Member

@bors r+

thanks!

@bors
Copy link
Contributor

bors commented Aug 10, 2020

📌 Commit 5d66bd7 has been approved by Manishearth

@bors
Copy link
Contributor

bors commented Aug 10, 2020

⌛ Testing commit 5d66bd7 with merge 1683189...

@bors
Copy link
Contributor

bors commented Aug 10, 2020

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: Manishearth
Pushing 1683189 to master...

@bors bors merged commit 1683189 into rust-lang:master Aug 10, 2020
@ebroto ebroto deleted the 5886_or_fun_call_const_0_args branch August 10, 2020 22:35
lopopolo added a commit to artichoke/artichoke that referenced this pull request Aug 18, 2020
This commit makes as many methods const as possible. Most involve the
modification or introduction of zero-arg `new()` methods.

This commit makes all error ZSTs only constructable via `T::new` instead
of directly instantiating the struct inline by adding a `_private: ()`
field.

This change inverts the implementation of `T::default` and `T::new` so
that `T::default` is implemented with `T::new`, allowing `T::new` to be
const. All callsites have been updated to prefer calling `T::new`.

It does not appear possible to construct byte slice literals in const
fn.

Suppress `clippy::or_fun_call` lint errors until rust-lang/rust-clippy#5889
is included in stable Rust.

This commit reworks the implementation of `regexp::Options` to store a
custom `RegexpOption` enum with `Enabled` and `Disabled` states instead
of a `bool`. This eliminates a suppressed clippy lint and makes the code
more readable. There are `From` implementations to and from `bool` as
well as `RegexpOption::is_enabled`. Much of these functions can become
const once const if match is stable.

This commit also includes some readability improvements to extracting
`RClass` pointers via `with_ffi_boundary`.
lopopolo added a commit to artichoke/artichoke that referenced this pull request Aug 18, 2020
This commit makes as many methods const as possible. Most involve the
modification or introduction of zero-arg `new()` methods.

This commit makes all error ZSTs only constructable via `T::new` instead
of directly instantiating the struct inline by adding a `_private: ()`
field.

This change inverts the implementation of `T::default` and `T::new` so
that `T::default` is implemented with `T::new`, allowing `T::new` to be
const. All callsites have been updated to prefer calling `T::new`.

It does not appear possible to construct byte slice literals in const
fn.

Suppress `clippy::or_fun_call` lint errors until rust-lang/rust-clippy#5889
is included in stable Rust.

This commit reworks the implementation of `regexp::Options` to store a
custom `RegexpOption` enum with `Enabled` and `Disabled` states instead
of a `bool`. This eliminates a suppressed clippy lint and makes the code
more readable. There are `From` implementations to and from `bool` as
well as `RegexpOption::is_enabled`. Much of these functions can become
const once const if match is stable.

This commit also includes some readability improvements to extracting
`RClass` pointers via `with_ffi_boundary`.
bors added a commit that referenced this pull request Aug 31, 2020
or_fn_call: ignore nullary associated const fns

The fix in #5889 was missing associated functions.

changelog: Ignore also `const fn` methods in [`or_fun_call`]

Fixes #5693
bors added a commit that referenced this pull request Sep 24, 2020
Revert: or_fun_call should lint calls to `const fn`s with no args

The changes in #5889 and #5984 were done under the incorrect assumption that a `const fn` with no args was guaranteed to be evaluated at compile time.  A `const fn` is only guaranteed to be evaluated at compile time if it's inside a const context (the initializer of a `const` or a `static`).

See this [zulip conversation](https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/Common.20misconception.3A.20.60const.20fn.60.20and.20its.20effect.20on.20codegen/near/208059113) for more details on this common misconception.

Given that none of the linted methods by `or_fun_call` can be called in const contexts, the lint should make no exceptions.

changelog: [`or_fun_call`] lints again calls to `const fn` with no args
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False positive: or_fun_call with const function
4 participants