]> git.lizzy.rs Git - rust.git/commitdiff
Use String type for Profile parse error
authorAntoine Martin <antoine97.martin@gmail.com>
Mon, 5 Oct 2020 16:03:54 +0000 (18:03 +0200)
committerAntoine Martin <antoine97.martin@gmail.com>
Tue, 6 Oct 2020 14:40:30 +0000 (16:40 +0200)
src/bootstrap/flags.rs
src/bootstrap/setup.rs

index d1f256d6dd09a4325a904ad7cf52d5a4680efc0d..f806e40aa8bd2373ecc05c92888809ff9678b9c9 100644 (file)
@@ -542,8 +542,8 @@ pub fn parse(args: &[String]) -> Flags {
                         |path| format!("{} is not a valid UTF8 string", path.to_string_lossy())
                     ));
 
-                    profile_string.parse().unwrap_or_else(|_| {
-                        eprintln!("error: unknown profile {}", profile_string);
+                    profile_string.parse().unwrap_or_else(|err| {
+                        eprintln!("error: {}", err);
                         eprintln!("help: the available profiles are:");
                         for choice in Profile::all() {
                             eprintln!("- {}", choice);
index 0d2945c3c396977c0d748d5ac66bd323b635829a..fdc0892845d941b41e660a6cb64629895f6b87fd 100644 (file)
@@ -24,13 +24,8 @@ pub fn all() -> impl Iterator<Item = Self> {
     }
 }
 
-#[derive(Debug)]
-pub struct ProfileErr {
-    pub name: String,
-}
-
 impl FromStr for Profile {
-    type Err = ProfileErr;
+    type Err = String;
 
     fn from_str(s: &str) -> Result<Self, Self::Err> {
         match s {
@@ -38,7 +33,7 @@ fn from_str(s: &str) -> Result<Self, Self::Err> {
             "b" | "compiler" => Ok(Profile::Compiler),
             "c" | "llvm" | "codegen" => Ok(Profile::Codegen),
             "d" | "maintainer" | "user" => Ok(Profile::User),
-            _ => Err(ProfileErr { name: s.to_string() }),
+            _ => Err(format!("unknown profile: '{}'", s)),
         }
     }
 }
@@ -116,8 +111,8 @@ pub fn interactive_path() -> io::Result<Profile> {
         io::stdin().read_line(&mut input)?;
         break match input.trim().to_lowercase().parse() {
             Ok(profile) => profile,
-            Err(ProfileErr { name }) => {
-                println!("error: unrecognized option '{}'", name);
+            Err(err) => {
+                println!("error: {}", err);
                 println!("note: press Ctrl+C to exit");
                 continue;
             }