File tree Expand file tree Collapse file tree 3 files changed +15
-20
lines changed Expand file tree Collapse file tree 3 files changed +15
-20
lines changed Original file line number Diff line number Diff line change @@ -179,16 +179,7 @@ impl IntoDiagnosticArg for type_ir::FloatTy {
179179
180180impl IntoDiagnosticArg for Level {
181181 fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > {
182- DiagnosticArgValue :: Str ( Cow :: Borrowed ( match self {
183- Level :: Allow => "-A" ,
184- Level :: Warn => "-W" ,
185- Level :: ForceWarn ( _) => "--force-warn" ,
186- Level :: Deny => "-D" ,
187- Level :: Forbid => "-F" ,
188- Level :: Expect ( _) => {
189- unreachable ! ( "lints with the level of `expect` should not run this code" ) ;
190- }
191- } ) )
182+ DiagnosticArgValue :: Str ( Cow :: Borrowed ( self . to_cmd_flag ( ) ) )
192183 }
193184}
194185
Original file line number Diff line number Diff line change @@ -253,6 +253,19 @@ impl Level {
253253 }
254254 }
255255
256+ pub fn to_cmd_flag ( self ) -> & ' static str {
257+ match self {
258+ Level :: Warn => "-W" ,
259+ Level :: Deny => "-D" ,
260+ Level :: Forbid => "-F" ,
261+ Level :: Allow => "-A" ,
262+ Level :: ForceWarn ( _) => "--force-warn" ,
263+ Level :: Expect ( _) => {
264+ unreachable ! ( "the expect level does not have a commandline flag" )
265+ }
266+ }
267+ }
268+
256269 pub fn is_error ( self ) -> bool {
257270 match self {
258271 Level :: Allow | Level :: Expect ( _) | Level :: Warn | Level :: ForceWarn ( _) => false ,
Original file line number Diff line number Diff line change @@ -234,16 +234,7 @@ pub fn explain_lint_level_source(
234234 err. note_once ( & format ! ( "`#[{}({})]` on by default" , level. as_str( ) , name) ) ;
235235 }
236236 LintLevelSource :: CommandLine ( lint_flag_val, orig_level) => {
237- let flag = match orig_level {
238- Level :: Warn => "-W" ,
239- Level :: Deny => "-D" ,
240- Level :: Forbid => "-F" ,
241- Level :: Allow => "-A" ,
242- Level :: ForceWarn ( _) => "--force-warn" ,
243- Level :: Expect ( _) => {
244- unreachable ! ( "the expect level does not have a commandline flag" )
245- }
246- } ;
237+ let flag = orig_level. to_cmd_flag ( ) ;
247238 let hyphen_case_lint_name = name. replace ( '_' , "-" ) ;
248239 if lint_flag_val. as_str ( ) == name {
249240 err. note_once ( & format ! (
You can’t perform that action at this time.
0 commit comments