1
Fork 0

Implement RFC 3525.

This commit is contained in:
Luca Versari 2024-06-24 17:17:18 +02:00 committed by Luca Versari
parent 748c54848d
commit 7eb4cfeace
25 changed files with 512 additions and 28 deletions

View file

@ -746,12 +746,35 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
Target::Field | Target::Arm | Target::MacroDef => {
self.inline_attr_str_error_with_macro_def(hir_id, attr, "target_feature");
}
Target::Struct if self.tcx.features().struct_target_features => {
let ty = self.tcx.hir_node(hir_id).expect_item();
match ty.kind {
ItemKind::Struct(data, _) => {
if data.fields().len() != 0 {
self.dcx().emit_err(errors::AttrShouldBeAppliedToFnOrUnitStruct {
attr_span: attr.span,
defn_span: span,
});
}
}
_ => {
panic!("Target::Struct for a non-struct");
}
}
}
_ => {
self.dcx().emit_err(errors::AttrShouldBeAppliedToFn {
attr_span: attr.span,
defn_span: span,
on_crate: hir_id == CRATE_HIR_ID,
});
if self.tcx.features().struct_target_features {
self.dcx().emit_err(errors::AttrShouldBeAppliedToFnOrUnitStruct {
attr_span: attr.span,
defn_span: span,
});
} else {
self.dcx().emit_err(errors::AttrShouldBeAppliedToFn {
attr_span: attr.span,
defn_span: span,
on_crate: hir_id == CRATE_HIR_ID,
});
}
}
}
}

View file

@ -82,6 +82,15 @@ pub struct AttrShouldBeAppliedToFn {
pub on_crate: bool,
}
#[derive(Diagnostic)]
#[diag(passes_should_be_applied_to_fn_or_unit_struct)]
pub struct AttrShouldBeAppliedToFnOrUnitStruct {
#[primary_span]
pub attr_span: Span,
#[label]
pub defn_span: Span,
}
#[derive(Diagnostic)]
#[diag(passes_should_be_applied_to_fn, code = E0739)]
pub struct TrackedCallerWrongLocation {