1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

fix some unwrap() in Rust (#5485)

This commit is contained in:
Yiyu Lin 2020-05-16 21:41:32 +08:00 committed by GitHub
parent 59cb3c14c7
commit 0b9942da84
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 63 additions and 64 deletions

View file

@ -107,14 +107,15 @@ fn format_message(
level: usize,
) -> String {
debug!("format_message");
if message_chain.is_none() {
return format!("{:indent$}{}", "", message, indent = level);
}
let mut s = message_chain.clone().unwrap().format_message(level);
if let Some(message_chain) = message_chain {
let mut s = message_chain.format_message(level);
s.pop();
s
} else {
format!("{:indent$}{}", "", message, indent = level)
}
}
/// Formats optional source, line and column numbers into a single string.
@ -146,7 +147,8 @@ fn format_maybe_related_information(
}
let mut s = String::new();
let related_information = related_information.clone().unwrap();
if let Some(related_information) = related_information {
for rd in related_information {
s.push_str("\n\n");
s.push_str(&format_stack(
@ -167,6 +169,7 @@ fn format_maybe_related_information(
4,
));
}
}
s
}
@ -222,8 +225,8 @@ impl DiagnosticMessageChain {
s.push_str(&std::iter::repeat(" ").take(level * 2).collect::<String>());
s.push_str(&self.message);
s.push('\n');
if self.next.is_some() {
let arr = self.next.clone().unwrap();
if let Some(next) = &self.next {
let arr = next.clone();
for dm in arr {
s.push_str(&dm.format_message(level + 1));
}

View file

@ -1173,16 +1173,15 @@ fn reload_arg<'a, 'b>() -> Arg<'a, 'b> {
}
fn reload_arg_parse(flags: &mut Flags, matches: &ArgMatches) {
if matches.is_present("reload") {
if matches.value_of("reload").is_some() {
let cache_bl = matches.values_of("reload").unwrap();
if let Some(cache_bl) = matches.values_of("reload") {
let raw_cache_blacklist: Vec<String> =
cache_bl.map(std::string::ToString::to_string).collect();
if raw_cache_blacklist.is_empty() {
flags.reload = true;
} else {
flags.cache_blacklist = resolve_urls(raw_cache_blacklist);
debug!("cache blacklist: {:#?}", &flags.cache_blacklist);
flags.reload = false;
} else {
flags.reload = true;
}
}
}
@ -1235,39 +1234,40 @@ fn no_remote_arg_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
}
fn permission_args_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
if matches.is_present("allow-read") {
if matches.value_of("allow-read").is_some() {
let read_wl = matches.values_of("allow-read").unwrap();
let raw_read_whitelist: Vec<PathBuf> =
read_wl.map(PathBuf::from).collect();
if let Some(read_wl) = matches.values_of("allow-read") {
let raw_read_whitelist: Vec<PathBuf> = read_wl.map(PathBuf::from).collect();
if raw_read_whitelist.is_empty() {
flags.allow_read = true;
} else {
flags.read_whitelist = resolve_fs_whitelist(&raw_read_whitelist);
debug!("read whitelist: {:#?}", &flags.read_whitelist);
} else {
flags.allow_read = true;
}
}
if matches.is_present("allow-write") {
if matches.value_of("allow-write").is_some() {
let write_wl = matches.values_of("allow-write").unwrap();
if let Some(write_wl) = matches.values_of("allow-write") {
let raw_write_whitelist: Vec<PathBuf> =
write_wl.map(PathBuf::from).collect();
if raw_write_whitelist.is_empty() {
flags.allow_write = true;
} else {
flags.write_whitelist = resolve_fs_whitelist(&raw_write_whitelist);
debug!("write whitelist: {:#?}", &flags.write_whitelist);
} else {
flags.allow_write = true;
}
}
if matches.is_present("allow-net") {
if matches.value_of("allow-net").is_some() {
let net_wl = matches.values_of("allow-net").unwrap();
let raw_net_whitelist =
if let Some(net_wl) = matches.values_of("allow-net") {
let raw_net_whitelist: Vec<String> =
net_wl.map(std::string::ToString::to_string).collect();
if raw_net_whitelist.is_empty() {
flags.allow_net = true;
} else {
flags.net_whitelist = resolve_hosts(raw_net_whitelist);
debug!("net whitelist: {:#?}", &flags.net_whitelist);
} else {
flags.allow_net = true;
}
}
if matches.is_present("allow-env") {
flags.allow_env = true;
}

View file

@ -291,11 +291,9 @@ impl TlsListenerResource {
/// Stop tracking a task.
/// Happens when the task is done and thus no further tracking is needed.
pub fn untrack_task(&mut self) {
if self.waker.is_some() {
self.waker.take();
}
}
}
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]

View file

@ -529,8 +529,7 @@ impl Future for CoreIsolate {
assert_eq!(inner.shared.size(), 0);
}
if overflow_response.is_some() {
let (op_id, buf) = overflow_response.take().unwrap();
if let Some((op_id, buf)) = overflow_response.take() {
async_op_response(
scope,
Some((op_id, buf)),

View file

@ -261,8 +261,7 @@ fn format_source_loc(
impl fmt::Display for JSError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if self.script_resource_name.is_some() {
let script_resource_name = self.script_resource_name.as_ref().unwrap();
if let Some(script_resource_name) = &self.script_resource_name {
if self.line_number.is_some() && self.start_column.is_some() {
assert!(self.line_number.is_some());
assert!(self.start_column.is_some());