|
| 1 | +//! Shared utilities for dealing with target features that haven't (yet) found a better home. |
1 | 2 | use rustc_attr_data_structures::InstructionSetAttr;
|
2 | 3 | use rustc_data_structures::fx::FxIndexSet;
|
3 | 4 | use rustc_data_structures::unord::{UnordMap, UnordSet};
|
4 | 5 | use rustc_errors::Applicability;
|
5 | 6 | use rustc_hir as hir;
|
6 | 7 | use rustc_hir::def::DefKind;
|
7 | 8 | use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId};
|
8 |
| -use rustc_middle::middle::codegen_fn_attrs::TargetFeature; |
9 |
| -use rustc_middle::query::Providers; |
10 |
| -use rustc_middle::ty::TyCtxt; |
11 |
| -use rustc_session::lint::builtin::AARCH64_SOFTFLOAT_NEON; |
| 9 | +use rustc_lint_defs::builtin::AARCH64_SOFTFLOAT_NEON; |
12 | 10 | use rustc_session::parse::feature_err;
|
13 | 11 | use rustc_span::{Span, Symbol, sym};
|
14 | 12 | use rustc_target::target_features::{self, Stability};
|
15 | 13 |
|
16 |
| -use crate::errors; |
| 14 | +use crate::error; |
| 15 | +use crate::middle::codegen_fn_attrs::TargetFeature; |
| 16 | +use crate::query::Providers; |
| 17 | +use crate::ty::TyCtxt; |
17 | 18 |
|
18 | 19 | /// Compute the enabled target features from the `#[target_feature]` function attribute.
|
19 | 20 | /// Enabled target features are added to `target_features`.
|
20 |
| -pub(crate) fn from_target_feature_attr( |
| 21 | +pub fn from_target_feature_attr( |
21 | 22 | tcx: TyCtxt<'_>,
|
22 | 23 | did: LocalDefId,
|
23 | 24 | attr: &hir::Attribute,
|
@@ -67,7 +68,7 @@ pub(crate) fn from_target_feature_attr(
|
67 | 68 | // Only allow target features whose feature gates have been enabled
|
68 | 69 | // and which are permitted to be toggled.
|
69 | 70 | if let Err(reason) = stability.toggle_allowed() {
|
70 |
| - tcx.dcx().emit_err(errors::ForbiddenTargetFeatureAttr { |
| 71 | + tcx.dcx().emit_err(error::ForbiddenTargetFeatureAttr { |
71 | 72 | span: item.span(),
|
72 | 73 | feature,
|
73 | 74 | reason,
|
@@ -101,10 +102,10 @@ pub(crate) fn from_target_feature_attr(
|
101 | 102 | AARCH64_SOFTFLOAT_NEON,
|
102 | 103 | tcx.local_def_id_to_hir_id(did),
|
103 | 104 | item.span(),
|
104 |
| - errors::Aarch64SoftfloatNeon, |
| 105 | + error::Aarch64SoftfloatNeon, |
105 | 106 | );
|
106 | 107 | } else {
|
107 |
| - tcx.dcx().emit_err(errors::ForbiddenTargetFeatureAttr { |
| 108 | + tcx.dcx().emit_err(error::ForbiddenTargetFeatureAttr { |
108 | 109 | span: item.span(),
|
109 | 110 | feature: name.as_str(),
|
110 | 111 | reason: "this feature is incompatible with the target ABI",
|
@@ -143,14 +144,12 @@ fn asm_target_features(tcx: TyCtxt<'_>, did: DefId) -> &FxIndexSet<Symbol> {
|
143 | 144 |
|
144 | 145 | /// Checks the function annotated with `#[target_feature]` is not a safe
|
145 | 146 | /// trait method implementation, reporting an error if it is.
|
146 |
| -pub(crate) fn check_target_feature_trait_unsafe(tcx: TyCtxt<'_>, id: LocalDefId, attr_span: Span) { |
| 147 | +pub fn check_target_feature_trait_unsafe(tcx: TyCtxt<'_>, id: LocalDefId, attr_span: Span) { |
147 | 148 | if let DefKind::AssocFn = tcx.def_kind(id) {
|
148 | 149 | let parent_id = tcx.local_parent(id);
|
149 | 150 | if let DefKind::Trait | DefKind::Impl { of_trait: true } = tcx.def_kind(parent_id) {
|
150 |
| - tcx.dcx().emit_err(errors::TargetFeatureSafeTrait { |
151 |
| - span: attr_span, |
152 |
| - def: tcx.def_span(id), |
153 |
| - }); |
| 151 | + tcx.dcx() |
| 152 | + .emit_err(error::TargetFeatureSafeTrait { span: attr_span, def: tcx.def_span(id) }); |
154 | 153 | }
|
155 | 154 | }
|
156 | 155 | }
|
|
0 commit comments