File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change 11use crate :: prelude:: * ;
22use crate :: utils;
3+ use regex:: Regex ;
34use rustwide:: Toolchain as RustwideToolchain ;
45use std:: fmt;
56use std:: str:: FromStr ;
@@ -102,6 +103,12 @@ pub enum ToolchainParseError {
102103 InvalidSourceName ( String ) ,
103104 #[ error( "invalid toolchain flag: {0}" ) ]
104105 InvalidFlag ( String ) ,
106+ #[ error( "invalid toolchain SHA: {0} is missing a `try#` or `master#` prefix" ) ]
107+ PrefixMissing ( String ) ,
108+ }
109+
110+ lazy_static ! {
111+ static ref TOOLCHAIN_SHA_RE : Regex = Regex :: new( r"^[a-f0-9]{40}$" ) . unwrap( ) ;
105112}
106113
107114impl FromStr for Toolchain {
@@ -130,6 +137,10 @@ impl FromStr for Toolchain {
130137 }
131138 } else if raw_source. is_empty ( ) {
132139 return Err ( ToolchainParseError :: EmptyName ) ;
140+ } else if TOOLCHAIN_SHA_RE . is_match ( raw_source) {
141+ // A common user error is unprefixed SHAs for the `start` or `end` toolchains, check for
142+ // these here.
143+ return Err ( ToolchainParseError :: PrefixMissing ( raw_source. to_string ( ) ) ) ;
133144 } else {
134145 RustwideToolchain :: dist ( raw_source)
135146 } ;
@@ -348,5 +359,6 @@ mod tests {
348359 assert ! ( Toolchain :: from_str( "stable+donotusethisflag=ever" ) . is_err( ) ) ;
349360 assert ! ( Toolchain :: from_str( "stable+patch=" ) . is_err( ) ) ;
350361 assert ! ( Toolchain :: from_str( "try#1234+target=" ) . is_err( ) ) ;
362+ assert ! ( Toolchain :: from_str( "0000000000000000000000000000000000000000" ) . is_err( ) ) ;
351363 }
352364}
You can’t perform that action at this time.
0 commit comments