Skip to content

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

Closed
@ecstatic-morse

Description

@ecstatic-morse

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

Metadata

Metadata

Assignees

Labels

A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-feature-requestCategory: A feature request, i.e: not implemented / a PR.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions