@@ -449,9 +449,7 @@ impl ProfileMaker {
449
449
// a unit is shared. If that's the case, we'll use the deferred value
450
450
// below so the unit can be reused, otherwise we can avoid emitting
451
451
// the unit's debuginfo.
452
- if let Some ( debuginfo) = profile. debuginfo . to_option ( ) {
453
- profile. debuginfo = DebugInfo :: Deferred ( debuginfo) ;
454
- }
452
+ profile. debuginfo = DebugInfo :: Deferred ( profile. debuginfo . into_inner ( ) ) ;
455
453
}
456
454
// ... and next comes any other sorts of overrides specified in
457
455
// profiles, such as `[profile.release.build-override]` or
@@ -529,7 +527,7 @@ fn merge_profile(profile: &mut Profile, toml: &TomlProfile) {
529
527
profile. codegen_units = toml. codegen_units ;
530
528
}
531
529
if let Some ( debuginfo) = toml. debug {
532
- profile. debuginfo = DebugInfo :: Explicit ( debuginfo) ;
530
+ profile. debuginfo = DebugInfo :: Resolved ( debuginfo) ;
533
531
}
534
532
if let Some ( debug_assertions) = toml. debug_assertions {
535
533
profile. debug_assertions = debug_assertions;
@@ -611,7 +609,7 @@ impl Default for Profile {
611
609
lto : Lto :: Bool ( false ) ,
612
610
codegen_backend : None ,
613
611
codegen_units : None ,
614
- debuginfo : DebugInfo :: None ,
612
+ debuginfo : DebugInfo :: Resolved ( TomlDebugInfo :: None ) ,
615
613
debug_assertions : false ,
616
614
split_debuginfo : None ,
617
615
overflow_checks : false ,
@@ -680,7 +678,7 @@ impl Profile {
680
678
Profile {
681
679
name : InternedString :: new ( "dev" ) ,
682
680
root : ProfileRoot :: Debug ,
683
- debuginfo : DebugInfo :: Explicit ( TomlDebugInfo :: Full ) ,
681
+ debuginfo : DebugInfo :: Resolved ( TomlDebugInfo :: Full ) ,
684
682
debug_assertions : true ,
685
683
overflow_checks : true ,
686
684
incremental : true ,
@@ -720,11 +718,8 @@ impl Profile {
720
718
721
719
/// The debuginfo level setting.
722
720
///
723
- /// This is semantically an `Option<u32>`, and should be used as so via the
724
- /// [DebugInfo::to_option] method for all intents and purposes:
725
- /// - `DebugInfo::None` corresponds to `None`
726
- /// - `DebugInfo::Explicit(u32)` and `DebugInfo::Deferred` correspond to
727
- /// `Option<u32>::Some`
721
+ /// This is semantically a [`TomlDebugInfo`], and should be used as so via the
722
+ /// [DebugInfo::into_inner] method for all intents and purposes.
728
723
///
729
724
/// Internally, it's used to model a debuginfo level whose value can be deferred
730
725
/// for optimization purposes: host dependencies usually don't need the same
@@ -736,35 +731,34 @@ impl Profile {
736
731
#[ derive( Debug , Copy , Clone , serde:: Serialize ) ]
737
732
#[ serde( untagged) ]
738
733
pub enum DebugInfo {
739
- /// No debuginfo level was set .
740
- None ,
741
- /// A debuginfo level that is explicitly set, by a profile or a user .
742
- Explicit ( TomlDebugInfo ) ,
734
+ /// A debuginfo level that is fixed and will not change .
735
+ ///
736
+ /// This can be set by a profile, user, or default value .
737
+ Resolved ( TomlDebugInfo ) ,
743
738
/// For internal purposes: a deferred debuginfo level that can be optimized
744
739
/// away, but has this value otherwise.
745
740
///
746
- /// Behaves like `Explicit ` in all situations except for the default build
741
+ /// Behaves like `Resolved ` in all situations except for the default build
747
742
/// dependencies profile: whenever a build dependency is not shared with
748
743
/// runtime dependencies, this level is weakened to a lower level that is
749
- /// faster to build (see [DebugInfo::weaken]).
744
+ /// faster to build (see [` DebugInfo::weaken` ]).
750
745
///
751
746
/// In all other situations, this level value will be the one to use.
752
747
Deferred ( TomlDebugInfo ) ,
753
748
}
754
749
755
750
impl DebugInfo {
756
- /// The main way to interact with this debuginfo level, turning it into an Option .
757
- pub fn to_option ( self ) -> Option < TomlDebugInfo > {
751
+ /// The main way to interact with this debuginfo level, turning it into a [`TomlDebugInfo`] .
752
+ pub fn into_inner ( self ) -> TomlDebugInfo {
758
753
match self {
759
- DebugInfo :: None => None ,
760
- DebugInfo :: Explicit ( v) | DebugInfo :: Deferred ( v) => Some ( v) ,
754
+ DebugInfo :: Resolved ( v) | DebugInfo :: Deferred ( v) => v,
761
755
}
762
756
}
763
757
764
758
/// Returns true if any debuginfo will be generated. Helper
765
759
/// for a common operation on the usual `Option` representation.
766
760
pub ( crate ) fn is_turned_on ( & self ) -> bool {
767
- !matches ! ( self . to_option ( ) , None | Some ( TomlDebugInfo :: None ) )
761
+ !matches ! ( self . into_inner ( ) , TomlDebugInfo :: None )
768
762
}
769
763
770
764
pub ( crate ) fn is_deferred ( & self ) -> bool {
@@ -774,44 +768,40 @@ impl DebugInfo {
774
768
/// Force the deferred, preferred, debuginfo level to a finalized explicit value.
775
769
pub ( crate ) fn finalize ( self ) -> Self {
776
770
match self {
777
- DebugInfo :: Deferred ( v) => DebugInfo :: Explicit ( v) ,
771
+ DebugInfo :: Deferred ( v) => DebugInfo :: Resolved ( v) ,
778
772
_ => self ,
779
773
}
780
774
}
781
775
782
776
/// Reset to the lowest level: no debuginfo.
783
- /// If it is explicitly set, keep it explicit.
784
777
pub ( crate ) fn weaken ( self ) -> Self {
785
- match self {
786
- DebugInfo :: None => DebugInfo :: None ,
787
- _ => DebugInfo :: Explicit ( TomlDebugInfo :: None ) ,
788
- }
778
+ DebugInfo :: Resolved ( TomlDebugInfo :: None )
789
779
}
790
780
}
791
781
792
782
impl PartialEq for DebugInfo {
793
783
fn eq ( & self , other : & DebugInfo ) -> bool {
794
- self . to_option ( ) . eq ( & other. to_option ( ) )
784
+ self . into_inner ( ) . eq ( & other. into_inner ( ) )
795
785
}
796
786
}
797
787
798
788
impl Eq for DebugInfo { }
799
789
800
790
impl Hash for DebugInfo {
801
791
fn hash < H : std:: hash:: Hasher > ( & self , state : & mut H ) {
802
- self . to_option ( ) . hash ( state) ;
792
+ self . into_inner ( ) . hash ( state) ;
803
793
}
804
794
}
805
795
806
796
impl PartialOrd for DebugInfo {
807
797
fn partial_cmp ( & self , other : & Self ) -> Option < std:: cmp:: Ordering > {
808
- self . to_option ( ) . partial_cmp ( & other. to_option ( ) )
798
+ self . into_inner ( ) . partial_cmp ( & other. into_inner ( ) )
809
799
}
810
800
}
811
801
812
802
impl Ord for DebugInfo {
813
803
fn cmp ( & self , other : & Self ) -> std:: cmp:: Ordering {
814
- self . to_option ( ) . cmp ( & other. to_option ( ) )
804
+ self . into_inner ( ) . cmp ( & other. into_inner ( ) )
815
805
}
816
806
}
817
807
0 commit comments