Skip to content

Lazily evaluate const fns #15211

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

Closed
wants to merge 1 commit into from
Closed

Conversation

sethdusek
Copy link

As discussed in #15122 (comment), try converting eagerly evaluated const fn's into lazy ones.

This seems to have some undesired effects, so I'm not sure if this should be merged. Namely clippy would now suggest lazily evaluating cheap functions like String::new() or Duration::from_seconds({argument known at compile-time}).

@sethdusek sethdusek marked this pull request as ready for review July 8, 2025 05:18
@rustbot
Copy link
Collaborator

rustbot commented Jul 8, 2025

r? @Jarcho

rustbot has assigned @Jarcho.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jul 8, 2025
@sethdusek
Copy link
Author

r? @samueltardieu

@rustbot rustbot assigned samueltardieu and unassigned Jarcho Jul 8, 2025
@Jarcho
Copy link
Contributor

Jarcho commented Jul 8, 2025

This should definitely not be changed in this manner. Just because the function call could be evaluated by the compiler doesn't mean it is, nor does it mean the expression is cheap to compute. It does happen to be a good indicator that the call isn't expensive hence why it currently suggests not changing anything if it is eagerly evaluated.

@samueltardieu
Copy link
Contributor

I agree with @Jarcho here: a const fn should not be suggest a change, in either direction.

@sethdusek sethdusek changed the title Eagerly evaluate const fns Lazily evaluate const fns Jul 11, 2025
@sethdusek sethdusek closed this Jul 11, 2025
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jul 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants