1+ use alloc:: { borrow:: ToOwned , format, string:: String , vec:: Vec } ;
2+ use core:: fmt:: { Display , Formatter } ;
3+
14use log:: LevelFilter ;
2- use std:: error:: Error ;
3- use std:: fmt:: { Display , Formatter } ;
45
56use crate :: Directive ;
67use crate :: FilterOp ;
@@ -46,12 +47,17 @@ pub struct ParseError {
4647}
4748
4849impl Display for ParseError {
49- fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std :: fmt:: Result {
50+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> core :: fmt:: Result {
5051 write ! ( f, "error parsing logger filter: {}" , self . details)
5152 }
5253}
5354
54- impl Error for ParseError { }
55+ #[ cfg( feature = "std" ) ]
56+ #[ allow( clippy:: std_instead_of_core) ]
57+ impl std:: error:: Error for ParseError { }
58+
59+ #[ cfg( not( feature = "std" ) ) ]
60+ impl core:: error:: Error for ParseError { }
5561
5662/// Parse a logging specification string (e.g: `crate1,crate2::mod3,crate3::x=error/foo`)
5763/// and return a vector with log directives.
@@ -115,9 +121,13 @@ pub(crate) fn parse_spec(spec: &str) -> ParseResult {
115121
116122#[ cfg( test) ]
117123mod tests {
124+ use alloc:: { borrow:: ToOwned , string:: ToString } ;
125+
118126 use crate :: ParseError ;
119127 use log:: LevelFilter ;
120- use snapbox:: { assert_data_eq, str, Data , IntoData } ;
128+ #[ cfg( feature = "std" ) ]
129+ use snapbox:: { assert_data_eq, str} ;
130+ use snapbox:: { Data , IntoData } ;
121131
122132 use super :: { parse_spec, ParseResult } ;
123133
@@ -164,6 +174,7 @@ mod tests {
164174 assert ! ( filter. is_none( ) ) ;
165175
166176 assert_eq ! ( errors. len( ) , 1 ) ;
177+ #[ cfg( feature = "std" ) ]
167178 assert_data_eq ! (
168179 & errors[ 0 ] ,
169180 str ![ "invalid logging spec 'crate1::mod1=warn=info'" ]
@@ -185,6 +196,7 @@ mod tests {
185196 assert ! ( filter. is_none( ) ) ;
186197
187198 assert_eq ! ( errors. len( ) , 1 ) ;
199+ #[ cfg( feature = "std" ) ]
188200 assert_data_eq ! ( & errors[ 0 ] , str ![ "invalid logging spec 'noNumber'" ] ) ;
189201 }
190202
@@ -203,6 +215,7 @@ mod tests {
203215 assert ! ( filter. is_none( ) ) ;
204216
205217 assert_eq ! ( errors. len( ) , 1 ) ;
218+ #[ cfg( feature = "std" ) ]
206219 assert_data_eq ! ( & errors[ 0 ] , str ![ "invalid logging spec 'wrong'" ] ) ;
207220 }
208221
@@ -221,6 +234,7 @@ mod tests {
221234 assert ! ( filter. is_none( ) ) ;
222235
223236 assert_eq ! ( errors. len( ) , 1 ) ;
237+ #[ cfg( feature = "std" ) ]
224238 assert_data_eq ! ( & errors[ 0 ] , str ![ "invalid logging spec 'wrong'" ] ) ;
225239 }
226240
@@ -394,6 +408,7 @@ mod tests {
394408 assert ! ( filter. is_some( ) && filter. unwrap( ) . to_string( ) == "a.c" ) ;
395409
396410 assert_eq ! ( errors. len( ) , 1 ) ;
411+ #[ cfg( feature = "std" ) ]
397412 assert_data_eq ! (
398413 & errors[ 0 ] ,
399414 str ![ "invalid logging spec 'crate1::mod1=error=warn'" ]
@@ -425,6 +440,7 @@ mod tests {
425440 assert ! ( filter. is_none( ) ) ;
426441
427442 assert_eq ! ( errors. len( ) , 1 ) ;
443+ #[ cfg( feature = "std" ) ]
428444 assert_data_eq ! (
429445 & errors[ 0 ] ,
430446 str ![ "invalid logging spec 'debug/abc/a.c' (too many '/'s)" ]
@@ -446,14 +462,17 @@ mod tests {
446462 assert ! ( filter. is_none( ) ) ;
447463
448464 assert_eq ! ( errors. len( ) , 2 ) ;
449- assert_data_eq ! (
450- & errors[ 0 ] ,
451- str ![ "invalid logging spec 'crate1::mod1=warn=info'" ]
452- ) ;
453- assert_data_eq ! (
454- & errors[ 1 ] ,
455- str ![ "invalid logging spec 'crate3=error=error'" ]
456- ) ;
465+ #[ cfg( feature = "std" ) ]
466+ {
467+ assert_data_eq ! (
468+ & errors[ 0 ] ,
469+ str ![ "invalid logging spec 'crate1::mod1=warn=info'" ]
470+ ) ;
471+ assert_data_eq ! (
472+ & errors[ 1 ] ,
473+ str ![ "invalid logging spec 'crate3=error=error'" ]
474+ ) ;
475+ }
457476 }
458477
459478 #[ test]
@@ -471,8 +490,11 @@ mod tests {
471490 assert ! ( filter. is_none( ) ) ;
472491
473492 assert_eq ! ( errors. len( ) , 2 ) ;
474- assert_data_eq ! ( & errors[ 0 ] , str ![ "invalid logging spec 'noNumber'" ] ) ;
475- assert_data_eq ! ( & errors[ 1 ] , str ![ "invalid logging spec 'invalid'" ] ) ;
493+ #[ cfg( feature = "std" ) ]
494+ {
495+ assert_data_eq ! ( & errors[ 0 ] , str ![ "invalid logging spec 'noNumber'" ] ) ;
496+ assert_data_eq ! ( & errors[ 1 ] , str ![ "invalid logging spec 'invalid'" ] ) ;
497+ }
476498 }
477499
478500 #[ test]
@@ -490,18 +512,23 @@ mod tests {
490512 assert ! ( filter. is_none( ) ) ;
491513
492514 assert_eq ! ( errors. len( ) , 2 ) ;
493- assert_data_eq ! (
494- & errors[ 0 ] ,
495- str ![ "invalid logging spec 'crate1::mod1=debug=info'" ]
496- ) ;
497- assert_data_eq ! ( & errors[ 1 ] , str ![ "invalid logging spec 'invalid'" ] ) ;
515+ #[ cfg( feature = "std" ) ]
516+ {
517+ assert_data_eq ! (
518+ & errors[ 0 ] ,
519+ str ![ "invalid logging spec 'crate1::mod1=debug=info'" ]
520+ ) ;
521+ assert_data_eq ! ( & errors[ 1 ] , str ![ "invalid logging spec 'invalid'" ] ) ;
522+ }
498523 }
499524
500525 #[ test]
501526 fn parse_error_message_single_error ( ) {
527+ #[ allow( unused_variables) ]
502528 let error = parse_spec ( "crate1::mod1=debug=info,crate2=debug" )
503529 . ok ( )
504530 . unwrap_err ( ) ;
531+ #[ cfg( feature = "std" ) ]
505532 assert_data_eq ! (
506533 error,
507534 str ![ "error parsing logger filter: invalid logging spec 'crate1::mod1=debug=info'" ]
@@ -510,9 +537,11 @@ mod tests {
510537
511538 #[ test]
512539 fn parse_error_message_multiple_errors ( ) {
540+ #[ allow( unused_variables) ]
513541 let error = parse_spec ( "crate1::mod1=debug=info,crate2=debug,crate3=invalid" )
514542 . ok ( )
515543 . unwrap_err ( ) ;
544+ #[ cfg( feature = "std" ) ]
516545 assert_data_eq ! (
517546 error,
518547 str ![ "error parsing logger filter: invalid logging spec 'crate1::mod1=debug=info'" ]
0 commit comments