@@ -8,34 +8,28 @@ use rustc_errors::IntoDiagnostic;
88use rustc_macros:: { Diagnostic , Subdiagnostic } ;
99use rustc_span:: Span ;
1010
11- pub ( crate ) enum UnknownCTargetFeature < ' a > {
12- UnknownFeaturePrefix { feature : & ' a str } ,
13- UnknownFeature { feature : & ' a str , rust_feature : Option < & ' a str > } ,
14- }
15-
16- impl IntoDiagnostic < ' _ , ( ) > for UnknownCTargetFeature < ' _ > {
17- fn into_diagnostic ( self , sess : & ' _ Handler ) -> DiagnosticBuilder < ' _ , ( ) > {
18- match self {
19- UnknownCTargetFeature :: UnknownFeaturePrefix { feature } => {
20- let mut diag = sess. struct_warn ( fluent:: codegen_llvm_unknown_ctarget_feature) ;
21- diag. set_arg ( "feature" , feature) ;
22- diag. note ( fluent:: codegen_llvm_unknown_feature_prefix) ;
23- diag
24- }
25- UnknownCTargetFeature :: UnknownFeature { feature, rust_feature } => {
26- let mut diag = sess. struct_warn ( fluent:: codegen_llvm_unknown_ctarget_feature) ;
27- diag. set_arg ( "feature" , feature) ;
28- diag. note ( fluent:: codegen_llvm_unknown_feature) ;
29- if let Some ( rust_feature) = rust_feature {
30- diag. help ( fluent:: codegen_llvm_rust_feature) ;
31- diag. set_arg ( "rust_feature" , rust_feature) ;
32- } else {
33- diag. note ( fluent:: codegen_llvm_unknown_feature_fill_request) ;
34- }
35- diag
36- }
37- }
38- }
11+ #[ derive( Diagnostic ) ]
12+ #[ diag( codegen_llvm_unknown_ctarget_feature_prefix) ]
13+ #[ note]
14+ pub ( crate ) struct UnknownCTargetFeaturePrefix < ' a > {
15+ pub feature : & ' a str ,
16+ }
17+
18+ #[ derive( Diagnostic ) ]
19+ #[ diag( codegen_llvm_unknown_ctarget_feature) ]
20+ #[ note]
21+ pub ( crate ) struct UnknownCTargetFeature < ' a > {
22+ pub feature : & ' a str ,
23+ #[ subdiagnostic]
24+ pub rust_feature : PossibleFeature < ' a > ,
25+ }
26+
27+ #[ derive( Subdiagnostic ) ]
28+ pub ( crate ) enum PossibleFeature < ' a > {
29+ #[ help( possible_feature) ]
30+ Some { rust_feature : & ' a str } ,
31+ #[ help( consider_filing_feature_request) ]
32+ None ,
3933}
4034
4135#[ derive( Diagnostic ) ]
@@ -131,6 +125,7 @@ pub(crate) struct FailParsingTargetMachineConfigToTargetMachine {
131125pub ( crate ) struct TargetFeatureDisableOrEnable < ' a > {
132126 pub features : & ' a [ & ' a str ] ,
133127 pub span : Option < Span > ,
128+ pub missing_features : Option < MissingFeatures > ,
134129}
135130
136131#[ derive( Subdiagnostic ) ]
@@ -139,13 +134,13 @@ pub(crate) struct MissingFeatures;
139134
140135impl IntoDiagnostic < ' _ , ErrorGuaranteed > for TargetFeatureDisableOrEnable < ' _ > {
141136 fn into_diagnostic ( self , sess : & ' _ Handler ) -> DiagnosticBuilder < ' _ , ErrorGuaranteed > {
142- let mut diag = if let Some ( span ) = self . span {
143- let mut diag = sess . struct_err ( fluent :: codegen_llvm_target_feature_disable_or_enable ) ;
137+ let mut diag = sess . struct_err ( fluent :: codegen_llvm_target_feature_disable_or_enable ) ;
138+ if let Some ( span ) = self . span {
144139 diag. set_span ( span) ;
145- diag
146- } else {
147- sess. struct_err ( fluent:: codegen_llvm_target_feature_disable_or_enable)
148140 } ;
141+ if let Some ( missing_features) = self . missing_features {
142+ diag. subdiagnostic ( missing_features) ;
143+ }
149144 diag. set_arg ( "features" , self . features . join ( ", " ) ) ;
150145 diag
151146 }
0 commit comments