File tree Expand file tree Collapse file tree 3 files changed +23
-7
lines changed
Expand file tree Collapse file tree 3 files changed +23
-7
lines changed Original file line number Diff line number Diff line change @@ -790,9 +790,12 @@ macro_rules! options {
790790
791791 fn parse_relro_level( slot: & mut Option <RelroLevel >, v: Option <& str >) -> bool {
792792 match v {
793- Some ( "full" ) => * slot = Some ( RelroLevel :: Full ) ,
794- Some ( "partial" ) => * slot = Some ( RelroLevel :: Partial ) ,
795- Some ( "off" ) => * slot = Some ( RelroLevel :: Off ) ,
793+ Some ( s) => {
794+ match s. parse:: <RelroLevel >( ) {
795+ Ok ( level) => * slot = Some ( level) ,
796+ _ => return false
797+ }
798+ } ,
796799 _ => return false
797800 }
798801 true
Original file line number Diff line number Diff line change @@ -47,6 +47,8 @@ pub mod target;
4747pub mod slice;
4848pub mod dynamic_lib;
4949
50+ use std:: str:: FromStr ;
51+
5052use serialize:: json:: { Json , ToJson } ;
5153
5254macro_rules! linker_flavor {
@@ -132,6 +134,19 @@ impl RelroLevel {
132134 }
133135}
134136
137+ impl FromStr for RelroLevel {
138+ type Err = ( ) ;
139+
140+ fn from_str ( s : & str ) -> Result < RelroLevel , ( ) > {
141+ match s {
142+ "full" => Ok ( RelroLevel :: Full ) ,
143+ "partial" => Ok ( RelroLevel :: Partial ) ,
144+ "off" => Ok ( RelroLevel :: Off ) ,
145+ _ => Err ( ( ) ) ,
146+ }
147+ }
148+ }
149+
135150impl ToJson for RelroLevel {
136151 fn to_json ( & self ) -> Json {
137152 match * self {
Original file line number Diff line number Diff line change @@ -588,10 +588,8 @@ impl Target {
588588 ( $key_name: ident, RelroLevel ) => ( {
589589 let name = ( stringify!( $key_name) ) . replace( "_" , "-" ) ;
590590 obj. find( & name[ ..] ) . and_then( |o| o. as_string( ) . and_then( |s| {
591- match s {
592- "full" => base. options. $key_name = RelroLevel :: Full ,
593- "partial" => base. options. $key_name = RelroLevel :: Partial ,
594- "off" => base. options. $key_name = RelroLevel :: Off ,
591+ match s. parse:: <RelroLevel >( ) {
592+ Ok ( level) => base. options. $key_name = level,
595593 _ => return Some ( Err ( format!( "'{}' is not a valid value for \
596594 relro-level. Use 'full', 'partial, or 'off'.",
597595 s) ) ) ,
You can’t perform that action at this time.
0 commit comments