Port #[rustc_pass_by_value] to the new attribute system

This commit is contained in:
Pavel Grigorenko
2025-06-15 16:59:11 +03:00
parent 35453a854c
commit ef4dece2cb
7 changed files with 24 additions and 7 deletions

View File

@@ -213,6 +213,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
Attribute::Parsed(AttributeKind::Used { span: attr_span, .. }) => {
self.check_used(*attr_span, target, span);
}
&Attribute::Parsed(AttributeKind::PassByValue(attr_span)) => {
self.check_pass_by_value(attr_span, span, target)
}
Attribute::Unparsed(attr_item) => {
style = Some(attr_item.style);
match attr.path().as_slice() {
@@ -275,7 +278,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
| [sym::const_trait, ..] => self.check_must_be_applied_to_trait(attr.span(), span, target),
[sym::collapse_debuginfo, ..] => self.check_collapse_debuginfo(attr, span, target),
[sym::must_not_suspend, ..] => self.check_must_not_suspend(attr, span, target),
[sym::rustc_pass_by_value, ..] => self.check_pass_by_value(attr, span, target),
[sym::rustc_allow_incoherent_impl, ..] => {
self.check_allow_incoherent_impl(attr, span, target)
}
@@ -1438,11 +1440,11 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
}
/// Warns against some misuses of `#[pass_by_value]`
fn check_pass_by_value(&self, attr: &Attribute, span: Span, target: Target) {
fn check_pass_by_value(&self, attr_span: Span, span: Span, target: Target) {
match target {
Target::Struct | Target::Enum | Target::TyAlias => {}
_ => {
self.dcx().emit_err(errors::PassByValue { attr_span: attr.span(), span });
self.dcx().emit_err(errors::PassByValue { attr_span, span });
}
}
}