1
1
use std:: collections:: { BTreeMap , BTreeSet , HashMap } ;
2
- use std:: fmt;
2
+ use std:: fmt:: { self , Display , Write } ;
3
3
use std:: marker:: PhantomData ;
4
4
use std:: path:: { Path , PathBuf } ;
5
5
use std:: rc:: Rc ;
@@ -12,8 +12,8 @@ use itertools::Itertools;
12
12
use lazycell:: LazyCell ;
13
13
use log:: { debug, trace} ;
14
14
use semver:: { self , VersionReq } ;
15
- use serde:: de;
16
15
use serde:: de:: IntoDeserializer as _;
16
+ use serde:: de:: { self , Unexpected } ;
17
17
use serde:: ser;
18
18
use serde:: { Deserialize , Serialize } ;
19
19
use url:: Url ;
@@ -442,11 +442,96 @@ impl ser::Serialize for TomlOptLevel {
442
442
}
443
443
}
444
444
445
- #[ derive( Clone , Debug , Deserialize , Serialize , Eq , PartialEq ) ]
446
- #[ serde( untagged, expecting = "expected a boolean or an integer" ) ]
447
- pub enum U32OrBool {
448
- U32 ( u32 ) ,
449
- Bool ( bool ) ,
445
+ #[ derive( Copy , Clone , Debug , Eq , PartialEq , Hash , PartialOrd , Ord ) ]
446
+ pub enum TomlDebugInfo {
447
+ None ,
448
+ LineDirectivesOnly ,
449
+ LineTablesOnly ,
450
+ Limited ,
451
+ Full ,
452
+ }
453
+
454
+ impl ser:: Serialize for TomlDebugInfo {
455
+ fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
456
+ where
457
+ S : ser:: Serializer ,
458
+ {
459
+ match self {
460
+ Self :: None => 0 . serialize ( serializer) ,
461
+ Self :: LineDirectivesOnly => "line-directives-only" . serialize ( serializer) ,
462
+ Self :: LineTablesOnly => "line-tables-only" . serialize ( serializer) ,
463
+ Self :: Limited => 1 . serialize ( serializer) ,
464
+ Self :: Full => 2 . serialize ( serializer) ,
465
+ }
466
+ }
467
+ }
468
+
469
+ impl < ' de > de:: Deserialize < ' de > for TomlDebugInfo {
470
+ fn deserialize < D > ( d : D ) -> Result < TomlDebugInfo , D :: Error >
471
+ where
472
+ D : de:: Deserializer < ' de > ,
473
+ {
474
+ struct Visitor ;
475
+
476
+ impl < ' de > de:: Visitor < ' de > for Visitor {
477
+ type Value = TomlDebugInfo ;
478
+
479
+ fn expecting ( & self , formatter : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
480
+ formatter
481
+ . write_str ( "a boolean, 0-2, \" line-tables-only\" , or \" line-directives-only\" " )
482
+ }
483
+
484
+ fn visit_i64 < E > ( self , value : i64 ) -> Result < TomlDebugInfo , E >
485
+ where
486
+ E : de:: Error ,
487
+ {
488
+ let debuginfo = match value {
489
+ 0 => TomlDebugInfo :: None ,
490
+ 1 => TomlDebugInfo :: Limited ,
491
+ 2 => TomlDebugInfo :: Full ,
492
+ _ => return Err ( de:: Error :: invalid_value ( Unexpected :: Signed ( value) , & self ) ) ,
493
+ } ;
494
+ Ok ( debuginfo)
495
+ }
496
+
497
+ fn visit_bool < E > ( self , v : bool ) -> Result < Self :: Value , E >
498
+ where
499
+ E : de:: Error ,
500
+ {
501
+ Ok ( if v {
502
+ TomlDebugInfo :: Full
503
+ } else {
504
+ TomlDebugInfo :: None
505
+ } )
506
+ }
507
+
508
+ fn visit_str < E > ( self , value : & str ) -> Result < TomlDebugInfo , E >
509
+ where
510
+ E : de:: Error ,
511
+ {
512
+ let debuginfo = match value {
513
+ "line-directives-only" => TomlDebugInfo :: LineDirectivesOnly ,
514
+ "line-tables-only" => TomlDebugInfo :: LineTablesOnly ,
515
+ _ => return Err ( de:: Error :: invalid_value ( Unexpected :: Str ( value) , & self ) ) ,
516
+ } ;
517
+ Ok ( debuginfo)
518
+ }
519
+ }
520
+
521
+ d. deserialize_any ( Visitor )
522
+ }
523
+ }
524
+
525
+ impl Display for TomlDebugInfo {
526
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
527
+ match self {
528
+ TomlDebugInfo :: None => f. write_char ( '0' ) ,
529
+ TomlDebugInfo :: Limited => f. write_char ( '1' ) ,
530
+ TomlDebugInfo :: Full => f. write_char ( '2' ) ,
531
+ TomlDebugInfo :: LineDirectivesOnly => f. write_str ( "line-directives-only" ) ,
532
+ TomlDebugInfo :: LineTablesOnly => f. write_str ( "line-tables-only" ) ,
533
+ }
534
+ }
450
535
}
451
536
452
537
#[ derive( Deserialize , Serialize , Clone , Debug , Default , Eq , PartialEq ) ]
@@ -456,7 +541,7 @@ pub struct TomlProfile {
456
541
pub lto : Option < StringOrBool > ,
457
542
pub codegen_backend : Option < InternedString > ,
458
543
pub codegen_units : Option < u32 > ,
459
- pub debug : Option < U32OrBool > ,
544
+ pub debug : Option < TomlDebugInfo > ,
460
545
pub split_debuginfo : Option < String > ,
461
546
pub debug_assertions : Option < bool > ,
462
547
pub rpath : Option < bool > ,
0 commit comments