@@ -235,14 +235,11 @@ impl Cfg {
235235 CfgEntry :: Any ( a, _) | CfgEntry :: All ( a, _) => {
236236 if a. is_empty ( ) {
237237 false
238- } else if let [ a] = a. as_slice ( ) {
239- should_append_only_to_description ( & a)
240238 } else {
241- true
239+ a . iter ( ) . any ( |sub| should_append_only_to_description ( sub ) )
242240 }
243241 }
244- CfgEntry :: Not ( a, _) => !should_append_only_to_description ( a) ,
245- CfgEntry :: Bool ( ..) => false ,
242+ CfgEntry :: Not ( ..) | CfgEntry :: Bool ( ..) => false ,
246243 }
247244 }
248245 should_append_only_to_description ( & self . 0 )
@@ -534,20 +531,45 @@ impl Display<'_> {
534531
535532impl fmt:: Display for Display < ' _ > {
536533 fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
534+ fn display_bool ( fmt : & mut fmt:: Formatter < ' _ > , value : bool ) -> fmt:: Result {
535+ if value { fmt. write_str ( "everywhere" ) } else { fmt. write_str ( "nowhere" ) }
536+ }
537+
537538 match & self . 0 {
538- CfgEntry :: Not ( CfgEntry :: Any ( sub_cfgs, _) , _) => {
539- let separator = if sub_cfgs. iter ( ) . all ( is_simple_cfg) { " nor " } else { ", nor " } ;
540- fmt. write_str ( "neither " ) ?;
541-
542- sub_cfgs
543- . iter ( )
544- . map ( |sub_cfg| {
545- Wrapped :: with_parens ( )
546- . when ( is_any_cfg ( sub_cfg) )
547- . wrap ( Display ( sub_cfg, self . 1 ) )
548- } )
549- . joined ( separator, fmt)
550- }
539+ CfgEntry :: Not ( CfgEntry :: Not ( sub_cfg, _) , _) => Display ( sub_cfg, self . 1 ) . fmt ( fmt) ,
540+ CfgEntry :: Not ( CfgEntry :: Any ( sub_cfgs, _) , _) => match sub_cfgs. as_slice ( ) {
541+ // `not(any())` is `true` because `any()` is `false`.
542+ [ ] => display_bool ( fmt, true ) ,
543+ [ CfgEntry :: Bool ( value, _) ] => display_bool ( fmt, !* value) ,
544+ sub_cfgs => {
545+ let separator =
546+ if sub_cfgs. iter ( ) . all ( is_simple_cfg) { " nor " } else { ", nor " } ;
547+ if sub_cfgs. len ( ) > 1 {
548+ fmt. write_str ( "neither " ) ?;
549+ } else {
550+ fmt. write_str ( "not(" ) ?;
551+ }
552+
553+ sub_cfgs
554+ . iter ( )
555+ . map ( |sub_cfg| {
556+ Wrapped :: with_parens ( )
557+ . when ( is_any_cfg ( sub_cfg) )
558+ . wrap ( Display ( sub_cfg, self . 1 ) )
559+ } )
560+ . joined ( separator, fmt) ?;
561+ if sub_cfgs. len ( ) == 1 {
562+ fmt. write_str ( ")" ) ?;
563+ }
564+ Ok ( ( ) )
565+ }
566+ } ,
567+ CfgEntry :: Not ( s @ CfgEntry :: All ( sub_cfgs, _) , _) => match sub_cfgs. as_slice ( ) {
568+ // `not(all())` is `false` because `all()` is `true`.
569+ [ ] => display_bool ( fmt, false ) ,
570+ [ CfgEntry :: Bool ( value, _) ] => display_bool ( fmt, !* value) ,
571+ _ => write ! ( fmt, "not ({})" , Display ( s, self . 1 ) ) ,
572+ } ,
551573 CfgEntry :: Not ( simple @ CfgEntry :: NameValue { .. } , _) => {
552574 write ! ( fmt, "non-{}" , Display ( simple, self . 1 ) )
553575 }
@@ -559,13 +581,7 @@ impl fmt::Display for Display<'_> {
559581 }
560582 CfgEntry :: All ( sub_cfgs, _) => self . display_sub_cfgs ( fmt, sub_cfgs. as_slice ( ) , " and " ) ,
561583
562- CfgEntry :: Bool ( v, _) => {
563- if * v {
564- fmt. write_str ( "everywhere" )
565- } else {
566- fmt. write_str ( "nowhere" )
567- }
568- }
584+ CfgEntry :: Bool ( v, _) => display_bool ( fmt, * v) ,
569585
570586 & CfgEntry :: NameValue { name, value, .. } => {
571587 let human_readable = match ( * name, value) {
0 commit comments