File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -1991,7 +1991,7 @@ fn collect_print_requests(
1991
1991
1992
1992
pub fn parse_target_triple ( early_dcx : & EarlyDiagCtxt , matches : & getopts:: Matches ) -> TargetTriple {
1993
1993
match matches. opt_str ( "target" ) {
1994
- Some ( target) if target . ends_with ( ".json" ) => {
1994
+ Some ( target) if TargetTriple :: has_json_ext ( & target ) => {
1995
1995
let path = Path :: new ( & target) ;
1996
1996
TargetTriple :: from_path ( path) . unwrap_or_else ( |_| {
1997
1997
early_dcx. early_fatal ( format ! ( "target file {path:?} does not exist" ) )
Original file line number Diff line number Diff line change @@ -3709,6 +3709,18 @@ impl TargetTriple {
3709
3709
}
3710
3710
}
3711
3711
}
3712
+
3713
+ /// Helper function to check if the given `triple` ends with `".json"` __case-insensitive__.
3714
+ /// Does not check if the path exists.
3715
+ pub fn has_json_ext < S : AsRef < str > > ( triple : S ) -> bool {
3716
+ const EXT : & ' static str = ".json" ;
3717
+ triple. as_ref ( ) . ends_with ( EXT ) || {
3718
+ let s = triple. as_ref ( ) ;
3719
+ s. get ( s. len ( ) . wrapping_sub ( EXT . len ( ) ) ..)
3720
+ . map ( |ext| ext. eq_ignore_ascii_case ( EXT ) )
3721
+ . unwrap_or_default ( )
3722
+ }
3723
+ }
3712
3724
}
3713
3725
3714
3726
impl fmt:: Display for TargetTriple {
You can’t perform that action at this time.
0 commit comments