mirror of
https://github.com/nushell/nushell
synced 2024-12-26 13:03:07 +00:00
use let-else
syntax where possible (#8886)
# Description this pr changes some `if-let`s to `let-else`s # User-Facing Changes none
This commit is contained in:
parent
6cedc05384
commit
a122e55129
7 changed files with 22 additions and 37 deletions
|
@ -111,15 +111,13 @@ pub fn help_aliases(
|
||||||
name.push_str(&r.item);
|
name.push_str(&r.item);
|
||||||
}
|
}
|
||||||
|
|
||||||
let alias = if let Some(id) = engine_state.find_decl(name.as_bytes(), &[]) {
|
let Some(alias) = engine_state.find_decl(name.as_bytes(), &[]) else {
|
||||||
if let Some(alias) = engine_state.get_decl(id).as_alias() {
|
return Err(ShellError::AliasNotFound(span(
|
||||||
alias
|
&rest.iter().map(|r| r.span).collect::<Vec<Span>>(),
|
||||||
} else {
|
)));
|
||||||
return Err(ShellError::AliasNotFound(span(
|
};
|
||||||
&rest.iter().map(|r| r.span).collect::<Vec<Span>>(),
|
|
||||||
)));
|
let Some(alias) = engine_state.get_decl(alias).as_alias() else {
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return Err(ShellError::AliasNotFound(span(
|
return Err(ShellError::AliasNotFound(span(
|
||||||
&rest.iter().map(|r| r.span).collect::<Vec<Span>>(),
|
&rest.iter().map(|r| r.span).collect::<Vec<Span>>(),
|
||||||
)));
|
)));
|
||||||
|
|
|
@ -117,9 +117,7 @@ pub fn help_modules(
|
||||||
name.push_str(&r.item);
|
name.push_str(&r.item);
|
||||||
}
|
}
|
||||||
|
|
||||||
let module_id = if let Some(id) = engine_state.find_module(name.as_bytes(), &[]) {
|
let Some(module_id) = engine_state.find_module(name.as_bytes(), &[]) else {
|
||||||
id
|
|
||||||
} else {
|
|
||||||
return Err(ShellError::ModuleNotFoundAtRuntime {
|
return Err(ShellError::ModuleNotFoundAtRuntime {
|
||||||
mod_name: name,
|
mod_name: name,
|
||||||
span: span(&rest.iter().map(|r| r.span).collect::<Vec<Span>>()),
|
span: span(&rest.iter().map(|r| r.span).collect::<Vec<Span>>()),
|
||||||
|
|
|
@ -45,13 +45,10 @@ impl Command for Use {
|
||||||
call: &Call,
|
call: &Call,
|
||||||
input: PipelineData,
|
input: PipelineData,
|
||||||
) -> Result<PipelineData, ShellError> {
|
) -> Result<PipelineData, ShellError> {
|
||||||
let import_pattern = if let Some(Expression {
|
let Some(Expression {
|
||||||
expr: Expr::ImportPattern(pat),
|
expr: Expr::ImportPattern(import_pattern),
|
||||||
..
|
..
|
||||||
}) = call.get_parser_info("import_pattern")
|
}) = call.get_parser_info("import_pattern") else {
|
||||||
{
|
|
||||||
pat
|
|
||||||
} else {
|
|
||||||
return Err(ShellError::GenericError(
|
return Err(ShellError::GenericError(
|
||||||
"Unexpected import".into(),
|
"Unexpected import".into(),
|
||||||
"import pattern not supported".into(),
|
"import pattern not supported".into(),
|
||||||
|
|
|
@ -5,14 +5,14 @@ pub fn get_columns<'a>(input: impl IntoIterator<Item = &'a Value>) -> Vec<String
|
||||||
let mut columns = vec![];
|
let mut columns = vec![];
|
||||||
|
|
||||||
for item in input {
|
for item in input {
|
||||||
if let Value::Record { cols, .. } = item {
|
let Value::Record { cols, .. } = item else {
|
||||||
for col in cols {
|
|
||||||
if !columns.contains(col) {
|
|
||||||
columns.push(col.to_string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return vec![];
|
return vec![];
|
||||||
|
};
|
||||||
|
|
||||||
|
for col in cols {
|
||||||
|
if !columns.contains(col) {
|
||||||
|
columns.push(col.to_string());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -669,9 +669,7 @@ pub fn parse_alias(
|
||||||
return alias_pipeline;
|
return alias_pipeline;
|
||||||
}
|
}
|
||||||
|
|
||||||
let alias_name_expr = if let Some(expr) = alias_call.positional_nth(0) {
|
let Some(alias_name_expr) = alias_call.positional_nth(0) else {
|
||||||
expr
|
|
||||||
} else {
|
|
||||||
working_set.error(ParseError::UnknownState(
|
working_set.error(ParseError::UnknownState(
|
||||||
"Missing positional after call check".to_string(),
|
"Missing positional after call check".to_string(),
|
||||||
span(spans),
|
span(spans),
|
||||||
|
@ -932,9 +930,7 @@ pub fn parse_export_in_module(
|
||||||
return (garbage_pipeline(spans), vec![]);
|
return (garbage_pipeline(spans), vec![]);
|
||||||
};
|
};
|
||||||
|
|
||||||
let export_decl_id = if let Some(id) = working_set.find_decl(b"export", &Type::Any) {
|
let Some(export_decl_id) = working_set.find_decl(b"export", &Type::Any) else {
|
||||||
id
|
|
||||||
} else {
|
|
||||||
working_set.error(ParseError::InternalError(
|
working_set.error(ParseError::InternalError(
|
||||||
"missing export command".into(),
|
"missing export command".into(),
|
||||||
export_span,
|
export_span,
|
||||||
|
|
|
@ -2880,9 +2880,7 @@ pub fn parse_type(_working_set: &StateWorkingSet, bytes: &[u8]) -> Type {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_import_pattern(working_set: &mut StateWorkingSet, spans: &[Span]) -> Expression {
|
pub fn parse_import_pattern(working_set: &mut StateWorkingSet, spans: &[Span]) -> Expression {
|
||||||
let head_span = if let Some(head_span) = spans.get(0) {
|
let Some(head_span) = spans.get(0) else {
|
||||||
head_span
|
|
||||||
} else {
|
|
||||||
working_set.error(ParseError::WrongImportPattern(span(spans)));
|
working_set.error(ParseError::WrongImportPattern(span(spans)));
|
||||||
return garbage(span(spans));
|
return garbage(span(spans));
|
||||||
};
|
};
|
||||||
|
|
|
@ -213,9 +213,7 @@ impl Iterator for RangeIterator {
|
||||||
self.curr.partial_cmp(&self.end)
|
self.curr.partial_cmp(&self.end)
|
||||||
};
|
};
|
||||||
|
|
||||||
let ordering = if let Some(ord) = ordering {
|
let Some(ordering) = ordering else {
|
||||||
ord
|
|
||||||
} else {
|
|
||||||
self.done = true;
|
self.done = true;
|
||||||
return Some(Value::Error {
|
return Some(Value::Error {
|
||||||
error: Box::new(ShellError::CannotCreateRange { span: self.span }),
|
error: Box::new(ShellError::CannotCreateRange { span: self.span }),
|
||||||
|
|
Loading…
Reference in a new issue