mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-13 17:13:48 +00:00
More precise types
This commit is contained in:
parent
c818f5c65e
commit
3ef916061b
@ -12,12 +12,15 @@ use ra_ide::{file_structure, Analysis};
|
|||||||
use ra_prof::profile;
|
use ra_prof::profile;
|
||||||
use ra_syntax::{AstNode, SourceFile};
|
use ra_syntax::{AstNode, SourceFile};
|
||||||
|
|
||||||
type Result<T> = std::result::Result<T, Box<dyn Error + Send + Sync>>;
|
type Result<T, E = Box<dyn Error + Send + Sync>> = std::result::Result<T, E>;
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
env_logger::try_init()?;
|
env_logger::try_init()?;
|
||||||
|
|
||||||
let command = Command::from_args()?;
|
let command = match Command::from_args()? {
|
||||||
|
Ok(it) => it,
|
||||||
|
Err(HelpPrinted) => return Ok(()),
|
||||||
|
};
|
||||||
match command {
|
match command {
|
||||||
Command::Parse { no_dump } => {
|
Command::Parse { no_dump } => {
|
||||||
let _p = profile("parsing");
|
let _p = profile("parsing");
|
||||||
@ -51,7 +54,6 @@ fn main() -> Result<()> {
|
|||||||
Command::Bench { verbosity, path, op } => {
|
Command::Bench { verbosity, path, op } => {
|
||||||
analysis_bench::run(verbosity, path.as_ref(), op)?;
|
analysis_bench::run(verbosity, path.as_ref(), op)?;
|
||||||
}
|
}
|
||||||
Command::HelpPrinted => (),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -101,11 +103,12 @@ enum Command {
|
|||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
op: analysis_bench::Op,
|
op: analysis_bench::Op,
|
||||||
},
|
},
|
||||||
HelpPrinted,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct HelpPrinted;
|
||||||
|
|
||||||
impl Command {
|
impl Command {
|
||||||
fn from_args() -> Result<Command> {
|
fn from_args() -> Result<Result<Command, HelpPrinted>> {
|
||||||
let mut matches = Arguments::from_env();
|
let mut matches = Arguments::from_env();
|
||||||
let subcommand = matches.subcommand()?.unwrap_or_default();
|
let subcommand = matches.subcommand()?.unwrap_or_default();
|
||||||
|
|
||||||
@ -136,7 +139,7 @@ FLAGS:
|
|||||||
-h, --help Prints help inforamtion
|
-h, --help Prints help inforamtion
|
||||||
--no-dump"
|
--no-dump"
|
||||||
);
|
);
|
||||||
return Ok(Command::HelpPrinted);
|
return Ok(Err(HelpPrinted));
|
||||||
}
|
}
|
||||||
|
|
||||||
let no_dump = matches.contains("--no-dump");
|
let no_dump = matches.contains("--no-dump");
|
||||||
@ -155,7 +158,7 @@ USAGE:
|
|||||||
FLAGS:
|
FLAGS:
|
||||||
-h, --help Prints help inforamtion"
|
-h, --help Prints help inforamtion"
|
||||||
);
|
);
|
||||||
return Ok(Command::HelpPrinted);
|
return Ok(Err(HelpPrinted));
|
||||||
}
|
}
|
||||||
|
|
||||||
matches.finish().or_else(handle_extra_flags)?;
|
matches.finish().or_else(handle_extra_flags)?;
|
||||||
@ -175,7 +178,7 @@ FLAGS:
|
|||||||
-h, --help Prints help information
|
-h, --help Prints help information
|
||||||
-r, --rainbow"
|
-r, --rainbow"
|
||||||
);
|
);
|
||||||
return Ok(Command::HelpPrinted);
|
return Ok(Err(HelpPrinted));
|
||||||
}
|
}
|
||||||
|
|
||||||
let rainbow = matches.contains(["-r", "--rainbow"]);
|
let rainbow = matches.contains(["-r", "--rainbow"]);
|
||||||
@ -203,7 +206,7 @@ OPTIONS:
|
|||||||
ARGS:
|
ARGS:
|
||||||
<PATH>"
|
<PATH>"
|
||||||
);
|
);
|
||||||
return Ok(Command::HelpPrinted);
|
return Ok(Err(HelpPrinted));
|
||||||
}
|
}
|
||||||
|
|
||||||
let randomize = matches.contains("--randomize");
|
let randomize = matches.contains("--randomize");
|
||||||
@ -240,7 +243,7 @@ OPTIONS:
|
|||||||
ARGS:
|
ARGS:
|
||||||
<PATH> Project to analyse"
|
<PATH> Project to analyse"
|
||||||
);
|
);
|
||||||
return Ok(Command::HelpPrinted);
|
return Ok(Err(HelpPrinted));
|
||||||
}
|
}
|
||||||
|
|
||||||
let path: PathBuf = matches.opt_value_from_str("--path")?.unwrap_or_default();
|
let path: PathBuf = matches.opt_value_from_str("--path")?.unwrap_or_default();
|
||||||
@ -275,10 +278,10 @@ SUBCOMMANDS:
|
|||||||
parse
|
parse
|
||||||
symbols"
|
symbols"
|
||||||
);
|
);
|
||||||
return Ok(Command::HelpPrinted);
|
return Ok(Err(HelpPrinted));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Ok(command)
|
Ok(Ok(command))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user