Skip to content

Commit dc6e0d9

Browse files
Forbid the use of #[target_feature] on start
1 parent aa67dbe commit dc6e0d9

File tree

5 files changed

+36
-0
lines changed

5 files changed

+36
-0
lines changed

compiler/rustc_hir_analysis/locales/en-US.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ hir_analysis_target_feature_on_main = `main` function is not allowed to have `#[
130130
hir_analysis_start_not_track_caller = `start` is not allowed to be `#[track_caller]`
131131
.label = `start` is not allowed to be `#[track_caller]`
132132
133+
hir_analysis_start_not_target_feature = `start` is not allowed to have `#[target_feature]`
134+
.label = `start` is not allowed to have `#[target_feature]`
135+
133136
hir_analysis_start_not_async = `start` is not allowed to be `async`
134137
.label = `start` is not allowed to be `async`
135138

compiler/rustc_hir_analysis/src/errors.rs

+9
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,15 @@ pub(crate) struct StartTrackCaller {
332332
pub start: Span,
333333
}
334334

335+
#[derive(Diagnostic)]
336+
#[diag(hir_analysis_start_not_target_feature)]
337+
pub(crate) struct StartTargetFeature {
338+
#[primary_span]
339+
pub span: Span,
340+
#[label]
341+
pub start: Span,
342+
}
343+
335344
#[derive(Diagnostic)]
336345
#[diag(hir_analysis_start_not_async, code = "E0752")]
337346
pub(crate) struct StartAsync {

compiler/rustc_hir_analysis/src/lib.rs

+7
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,13 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: DefId) {
378378
});
379379
error = true;
380380
}
381+
if attr.has_name(sym::target_feature) {
382+
tcx.sess.emit_err(errors::StartTargetFeature {
383+
span: attr.span,
384+
start: start_span,
385+
});
386+
error = true;
387+
}
381388
}
382389

383390
if error {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![feature(start)]
2+
3+
#[start]
4+
#[target_feature(enable = "avx2")]
5+
//~^ ERROR `start` is not allowed to have `#[target_feature]`
6+
fn start(_argc: isize, _argv: *const *const u8) -> isize { 0 }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: `start` is not allowed to have `#[target_feature]`
2+
--> $DIR/issue-108645-target-feature-on-start.rs:4:1
3+
|
4+
LL | #[target_feature(enable = "avx2")]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
LL |
7+
LL | fn start(_argc: isize, _argv: *const *const u8) -> isize { 0 }
8+
| -------------------------------------------------------- `start` is not allowed to have `#[target_feature]`
9+
10+
error: aborting due to previous error
11+

0 commit comments

Comments
 (0)