about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLéo Lanteri Thauvin <leseulartichaut@gmail.com>2023-03-02 14:26:12 +0100
committerLéo Lanteri Thauvin <leseulartichaut@gmail.com>2023-03-12 14:57:38 +0100
commit963305bda8723a461afe37ddb7fc6da9f56bf100 (patch)
treeb0b84f5a2497868a154ebc2ed8892eb53cced116
parentdb266939822a5a89473871abff6beea39b083af6 (diff)
downloadrust-963305bda8723a461afe37ddb7fc6da9f56bf100.tar.gz
rust-963305bda8723a461afe37ddb7fc6da9f56bf100.zip
Forbid the use of `#[target_feature]` on `start`
-rw-r--r--compiler/rustc_hir_analysis/messages.ftl3
-rw-r--r--compiler/rustc_hir_analysis/src/errors.rs9
-rw-r--r--compiler/rustc_hir_analysis/src/lib.rs7
-rw-r--r--tests/ui/rfcs/rfc-2396-target_feature-11/issue-108645-target-feature-on-start.rs9
-rw-r--r--tests/ui/rfcs/rfc-2396-target_feature-11/issue-108645-target-feature-on-start.stderr11
5 files changed, 39 insertions, 0 deletions
diff --git a/compiler/rustc_hir_analysis/messages.ftl b/compiler/rustc_hir_analysis/messages.ftl
index 5800f77c55a..0105cbf36de 100644
--- a/compiler/rustc_hir_analysis/messages.ftl
+++ b/compiler/rustc_hir_analysis/messages.ftl
@@ -133,6 +133,9 @@ hir_analysis_target_feature_on_main = `main` function is not allowed to have `#[
 hir_analysis_start_not_track_caller = `start` is not allowed to be `#[track_caller]`
     .label = `start` is not allowed to be `#[track_caller]`
 
+hir_analysis_start_not_target_feature = `start` is not allowed to have `#[target_feature]`
+    .label = `start` is not allowed to have `#[target_feature]`
+
 hir_analysis_start_not_async = `start` is not allowed to be `async`
     .label = `start` is not allowed to be `async`
 
diff --git a/compiler/rustc_hir_analysis/src/errors.rs b/compiler/rustc_hir_analysis/src/errors.rs
index 5b445ead1d3..f57197edeb7 100644
--- a/compiler/rustc_hir_analysis/src/errors.rs
+++ b/compiler/rustc_hir_analysis/src/errors.rs
@@ -345,6 +345,15 @@ pub(crate) struct StartTrackCaller {
 }
 
 #[derive(Diagnostic)]
+#[diag(hir_analysis_start_not_target_feature)]
+pub(crate) struct StartTargetFeature {
+    #[primary_span]
+    pub span: Span,
+    #[label]
+    pub start: Span,
+}
+
+#[derive(Diagnostic)]
 #[diag(hir_analysis_start_not_async, code = "E0752")]
 pub(crate) struct StartAsync {
     #[primary_span]
diff --git a/compiler/rustc_hir_analysis/src/lib.rs b/compiler/rustc_hir_analysis/src/lib.rs
index 098b003eaed..be07bb45846 100644
--- a/compiler/rustc_hir_analysis/src/lib.rs
+++ b/compiler/rustc_hir_analysis/src/lib.rs
@@ -378,6 +378,13 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: DefId) {
                             });
                             error = true;
                         }
+                        if attr.has_name(sym::target_feature) {
+                            tcx.sess.emit_err(errors::StartTargetFeature {
+                                span: attr.span,
+                                start: start_span,
+                            });
+                            error = true;
+                        }
                     }
 
                     if error {
diff --git a/tests/ui/rfcs/rfc-2396-target_feature-11/issue-108645-target-feature-on-start.rs b/tests/ui/rfcs/rfc-2396-target_feature-11/issue-108645-target-feature-on-start.rs
new file mode 100644
index 00000000000..50e8ce2fdd5
--- /dev/null
+++ b/tests/ui/rfcs/rfc-2396-target_feature-11/issue-108645-target-feature-on-start.rs
@@ -0,0 +1,9 @@
+// only-x86_64
+
+#![feature(start)]
+#![feature(target_feature_11)]
+
+#[start]
+#[target_feature(enable = "avx2")]
+//~^ ERROR `start` is not allowed to have `#[target_feature]`
+fn start(_argc: isize, _argv: *const *const u8) -> isize { 0 }
diff --git a/tests/ui/rfcs/rfc-2396-target_feature-11/issue-108645-target-feature-on-start.stderr b/tests/ui/rfcs/rfc-2396-target_feature-11/issue-108645-target-feature-on-start.stderr
new file mode 100644
index 00000000000..07687f3c7f4
--- /dev/null
+++ b/tests/ui/rfcs/rfc-2396-target_feature-11/issue-108645-target-feature-on-start.stderr
@@ -0,0 +1,11 @@
+error: `start` is not allowed to have `#[target_feature]`
+  --> $DIR/issue-108645-target-feature-on-start.rs:7:1
+   |
+LL | #[target_feature(enable = "avx2")]
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL |
+LL | fn start(_argc: isize, _argv: *const *const u8) -> isize { 0 }
+   | -------------------------------------------------------- `start` is not allowed to have `#[target_feature]`
+
+error: aborting due to previous error
+