mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-19 11:12:43 +00:00
Forbid the use of #[target_feature]
on main
This commit is contained in:
parent
24c0b81c1f
commit
db26693982
@ -128,6 +128,8 @@ hir_analysis_where_clause_on_main = `main` function is not allowed to have a `wh
|
||||
hir_analysis_track_caller_on_main = `main` function is not allowed to be `#[track_caller]`
|
||||
.suggestion = remove this annotation
|
||||
|
||||
hir_analysis_target_feature_on_main = `main` function is not allowed to have `#[target_feature]`
|
||||
|
||||
hir_analysis_start_not_track_caller = `start` is not allowed to be `#[track_caller]`
|
||||
.label = `start` is not allowed to be `#[track_caller]`
|
||||
|
||||
|
@ -327,6 +327,14 @@ pub(crate) struct TrackCallerOnMain {
|
||||
pub annotated: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(hir_analysis_target_feature_on_main)]
|
||||
pub(crate) struct TargetFeatureOnMain {
|
||||
#[primary_span]
|
||||
#[label(hir_analysis_target_feature_on_main)]
|
||||
pub main: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(hir_analysis_start_not_track_caller)]
|
||||
pub(crate) struct StartTrackCaller {
|
||||
|
@ -283,6 +283,11 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
|
||||
error = true;
|
||||
}
|
||||
|
||||
if !tcx.codegen_fn_attrs(main_def_id).target_features.is_empty() {
|
||||
tcx.sess.emit_err(errors::TargetFeatureOnMain { main: main_span });
|
||||
error = true;
|
||||
}
|
||||
|
||||
if error {
|
||||
return;
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
use std::arch::asm;
|
||||
|
||||
#[target_feature(enable = "avx")]
|
||||
fn main() {
|
||||
fn foo() {
|
||||
unsafe {
|
||||
asm!(
|
||||
"/* {} */",
|
||||
@ -15,3 +15,5 @@ fn main() {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
@ -0,0 +1,7 @@
|
||||
// only-x86_64
|
||||
|
||||
#![feature(target_feature_11)]
|
||||
|
||||
#[target_feature(enable = "avx2")]
|
||||
fn main() {}
|
||||
//~^ ERROR `main` function is not allowed to have `#[target_feature]`
|
@ -0,0 +1,8 @@
|
||||
error: `main` function is not allowed to have `#[target_feature]`
|
||||
--> $DIR/issue-108645-target-feature-on-main.rs:6:1
|
||||
|
|
||||
LL | fn main() {}
|
||||
| ^^^^^^^^^ `main` function is not allowed to have `#[target_feature]`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
Loading…
Reference in New Issue
Block a user