Skip to content

Commit

Permalink
Use String type for Profile parse error
Browse files Browse the repository at this point in the history
  • Loading branch information
alarsyo committed Oct 6, 2020
1 parent 3afc004 commit d67a7e6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/bootstrap/flags.rs
Expand Up @@ -542,8 +542,8 @@ Arguments:
|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);
Expand Down
13 changes: 4 additions & 9 deletions src/bootstrap/setup.rs
Expand Up @@ -24,21 +24,16 @@ impl Profile {
}
}

#[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 {
"a" | "lib" | "library" => Ok(Profile::Library),
"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)),
}
}
}
Expand Down Expand Up @@ -116,8 +111,8 @@ d) Install Rust from source"
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;
}
Expand Down

0 comments on commit d67a7e6

Please sign in to comment.