Skip to content

Commit

Permalink
Forbid the use of #[target_feature] on start
Browse files Browse the repository at this point in the history
  • Loading branch information
LeSeulArtichaut committed Mar 2, 2023
1 parent aa67dbe commit dc6e0d9
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions compiler/rustc_hir_analysis/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,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`
Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_hir_analysis/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,15 @@ pub(crate) struct StartTrackCaller {
pub start: Span,
}

#[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 {
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_hir_analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#![feature(start)]

#[start]
#[target_feature(enable = "avx2")]
//~^ ERROR `start` is not allowed to have `#[target_feature]`
fn start(_argc: isize, _argv: *const *const u8) -> isize { 0 }
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error: `start` is not allowed to have `#[target_feature]`
--> $DIR/issue-108645-target-feature-on-start.rs:4: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

0 comments on commit dc6e0d9

Please sign in to comment.