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

Add trivially_copy_pass_by_ref to the lint set. #73

Merged
merged 3 commits into from
Nov 21, 2024

Conversation

xStrom
Copy link
Member

@xStrom xStrom commented Nov 21, 2024

This is an old standard lint from the Druid days, still enabled for Druid, Piet, Kurbo, Xilem, and was just removed from Parley two days ago which triggered this PR.

I think it makes sense to keep it as part of the standard set. It helps detect potential micro-optimizations. The default Clippy configuration option avoid-breaking-exported-api is true which means it won't affect the public API.

The main downside is that if we have a tiny struct which gets suggested for copy and then later that struct grows larger, we will need to manually update the methods to take a reference instead. Probably a good idea to add a code comment for potential growers about this.

The trivial-copy-size-limit configuration of 16 bytes is also a continuation of an old decision. The rationale for optimizing for 64-bit is even more true today with even low-end mobile phones having 64-bit CPUs.

I also bumped the linebender lint set version, but only for the Cargo.toml bunch. I think it can only cause wasted effort to bump the version in other files that have zero changes.

Copy link
Member

@DJMcNab DJMcNab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable; some small concerns about metadata

content/wiki/canonical_lints.md Show resolved Hide resolved
// See https://linebender.org/wiki/canonical-lints/
// These lints aren't included in Cargo.toml because they
// shouldn't apply to examples and tests
#![warn(unused_crate_dependencies)]
#![warn(clippy::print_stdout, clippy::print_stderr)]
// END LINEBENDER LINT SET
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous discussion here #68 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rustfmt problem is valid, but looking at this in the wild it's not immediately obvious where the set ends. I'll need to think about this a bit more.

Copy link
Member

@DJMcNab DJMcNab Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I think the problem comes if there are no other trailing attributes; we want this to come after crate level docs, so it's plausible that there'd be no other attributes.

Maybe the solution is for the pattern to be:

// LINEBENDER LINT SET ...
 ...
// END LINEBENDER LINT SET
#![cfg_attr(docsrs, feature(doc_auto_cfg))]

?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it, as we want that present everywhere anyway.

@xStrom xStrom merged commit 8ec05a3 into linebender:main Nov 21, 2024
1 check passed
@xStrom xStrom deleted the trivialcopy branch November 21, 2024 17:12
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.

2 participants