Rollup merge of #92646 - mdibaiee:76935/pass-by-value, r=lcnr
feat: rustc_pass_by_value lint attribute Useful for thin wrapper attributes that are best passed as value instead of reference. Fixes #76935
This commit is contained in:
commit
c5041f88ea
14 changed files with 372 additions and 138 deletions
|
@ -114,6 +114,7 @@ impl CheckAttrVisitor<'_> {
|
|||
}
|
||||
sym::must_not_suspend => self.check_must_not_suspend(&attr, span, target),
|
||||
sym::must_use => self.check_must_use(hir_id, &attr, span, target),
|
||||
sym::rustc_pass_by_value => self.check_pass_by_value(&attr, span, target),
|
||||
sym::rustc_const_unstable
|
||||
| sym::rustc_const_stable
|
||||
| sym::unstable
|
||||
|
@ -1066,6 +1067,24 @@ impl CheckAttrVisitor<'_> {
|
|||
is_valid
|
||||
}
|
||||
|
||||
/// Warns against some misuses of `#[pass_by_value]`
|
||||
fn check_pass_by_value(&self, attr: &Attribute, span: &Span, target: Target) -> bool {
|
||||
match target {
|
||||
Target::Struct | Target::Enum | Target::TyAlias => true,
|
||||
_ => {
|
||||
self.tcx
|
||||
.sess
|
||||
.struct_span_err(
|
||||
attr.span,
|
||||
"`pass_by_value` attribute should be applied to a struct, enum or type alias.",
|
||||
)
|
||||
.span_label(*span, "is not a struct, enum or type alias")
|
||||
.emit();
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Warns against some misuses of `#[must_use]`
|
||||
fn check_must_use(
|
||||
&self,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue