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

Attribute for types that should always be passed by value #76935

Closed
ecstatic-morse opened this issue Sep 19, 2020 · 4 comments · Fixed by #92646
Closed

Attribute for types that should always be passed by value #76935

ecstatic-morse opened this issue Sep 19, 2020 · 4 comments · Fixed by #92646
Assignees
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-feature-request Category: A feature request, i.e: not implemented / a PR. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ecstatic-morse
Copy link
Contributor

ecstatic-morse commented Sep 19, 2020

Inspired by #76914. Currently, we have a lint in rustc for types that should always be passed by value. Usually, these types are thin wrappers around references, so there is no benefit to an extra layer of indirection. However, this lint uses a hard-coded list of (diagnostic) names (currently Ty and TyCtxt). We should use an attribute (e.g. #[rustc_pass_by_value]) to control this. Note that Ty is a type alias, not a struct.

This is worthwhile because there are more widely used types that are merely a wrapper around a reference (e.g. ty::Predicate). One could also imagine crates in the ecosystem that also do a lot of interning might take advantage of this.

cc @lcnr

@ecstatic-morse ecstatic-morse added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-feature-request Category: A feature request, i.e: not implemented / a PR. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. labels Sep 19, 2020
@ecstatic-morse
Copy link
Contributor Author

Clippy has a more expansive, allow-by-default version of this BTW.

@mdibaiee
Copy link
Contributor

mdibaiee commented Jan 7, 2022

@rustbot claim

@mdibaiee
Copy link
Contributor

mdibaiee commented Jan 7, 2022

@ecstatic-morse I just tinkered around with this today a little bit.

I wasn't clear on one part: Do we want this lint to be internal to rustc, or just a builtin for everyone? I was confused because at some point you say:

One could also imagine crates in the ecosystem that also do a lot of interning might take advantage of this.

@ecstatic-morse
Copy link
Contributor Author

@mdibaiee Internal to rustc for now. For the broader ecosystem, a clippy lint is probably more appropriate.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 15, 2022
feat: rustc_pass_by_value lint attribute

Useful for thin wrapper attributes that are best passed as value instead
of reference.

Fixes rust-lang#76935
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 15, 2022
feat: rustc_pass_by_value lint attribute

Useful for thin wrapper attributes that are best passed as value instead
of reference.

Fixes rust-lang#76935
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 15, 2022
feat: rustc_pass_by_value lint attribute

Useful for thin wrapper attributes that are best passed as value instead
of reference.

Fixes rust-lang#76935
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 15, 2022
feat: rustc_pass_by_value lint attribute

Useful for thin wrapper attributes that are best passed as value instead
of reference.

Fixes rust-lang#76935
@bors bors closed this as completed in c5041f8 Jan 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-feature-request Category: A feature request, i.e: not implemented / a PR. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants