Check placement of more attributes
This commit is contained in:
parent
de921ab3c3
commit
4efe97a3d9
18 changed files with 816 additions and 354 deletions
|
@ -2490,10 +2490,17 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
|
|||
codegen_fn_attrs.export_name = Some(s);
|
||||
}
|
||||
} else if tcx.sess.check_name(attr, sym::target_feature) {
|
||||
if !tcx.features().target_feature_11 {
|
||||
check_target_feature_safe_fn(tcx, id, attr.span);
|
||||
} else if let Some(local_id) = id.as_local() {
|
||||
if tcx.fn_sig(id).unsafety() == hir::Unsafety::Normal {
|
||||
if !tcx.is_closure(id) && tcx.fn_sig(id).unsafety() == hir::Unsafety::Normal {
|
||||
if !tcx.features().target_feature_11 {
|
||||
let mut err = feature_err(
|
||||
&tcx.sess.parse_sess,
|
||||
sym::target_feature_11,
|
||||
attr.span,
|
||||
"`#[target_feature(..)]` can only be applied to `unsafe` functions",
|
||||
);
|
||||
err.span_label(tcx.def_span(id), "not an `unsafe` function");
|
||||
err.emit();
|
||||
} else if let Some(local_id) = id.as_local() {
|
||||
check_target_feature_trait_unsafe(tcx, local_id, attr.span);
|
||||
}
|
||||
}
|
||||
|
@ -2750,21 +2757,6 @@ fn check_link_name_xor_ordinal(
|
|||
}
|
||||
}
|
||||
|
||||
/// Checks the function annotated with `#[target_feature]` is unsafe,
|
||||
/// reporting an error if it isn't.
|
||||
fn check_target_feature_safe_fn(tcx: TyCtxt<'_>, id: DefId, attr_span: Span) {
|
||||
if tcx.is_closure(id) || tcx.fn_sig(id).unsafety() == hir::Unsafety::Normal {
|
||||
let mut err = feature_err(
|
||||
&tcx.sess.parse_sess,
|
||||
sym::target_feature_11,
|
||||
attr_span,
|
||||
"`#[target_feature(..)]` can only be applied to `unsafe` functions",
|
||||
);
|
||||
err.span_label(tcx.def_span(id), "not an `unsafe` function");
|
||||
err.emit();
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks the function annotated with `#[target_feature]` is not a safe
|
||||
/// trait method implementation, reporting an error if it is.
|
||||
fn check_target_feature_trait_unsafe(tcx: TyCtxt<'_>, id: LocalDefId, attr_span: Span) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue