Skip to content

Commit

Permalink
refactor: fix warns
Browse files Browse the repository at this point in the history
  • Loading branch information
mtshiba committed Dec 29, 2023
1 parent cf726fe commit edfabd9
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion crates/els/code_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
) -> ELSResult<Option<CodeAction>> {
let uri = NormalizedUrl::new(params.text_document.uri.clone());
let diags = &params.context.diagnostics;
let Some(diag) = diags.get(0).cloned() else {
let Some(diag) = diags.first().cloned() else {
return Ok(None);
};
let mut map = HashMap::new();
Expand Down
2 changes: 1 addition & 1 deletion crates/els/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
_ => {}
}
let sig_t = other.t();
sig_t.non_default_params()?.get(0).cloned()
sig_t.non_default_params()?.first().cloned()
}
_ => None,
});
Expand Down
6 changes: 3 additions & 3 deletions crates/erg_compiler/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1612,7 +1612,7 @@ impl PyCodeGenerator {
.info
.t
.non_default_params()
.and_then(|tys| tys.get(0).map(|pt| pt.typ()))
.and_then(|tys| tys.first().map(|pt| pt.typ()))
.unwrap_or(Type::FAILURE);
let tycode = TypeCode::from(val_t);
let instr = match &unary.op.kind {
Expand Down Expand Up @@ -1740,7 +1740,7 @@ impl PyCodeGenerator {
.info
.t
.non_default_params()
.and_then(|tys| tys.get(0).map(|pt| pt.typ()))
.and_then(|tys| tys.first().map(|pt| pt.typ()))
.unwrap_or(Type::FAILURE);
let rhs_t = bin
.info
Expand Down Expand Up @@ -3355,7 +3355,7 @@ impl PyCodeGenerator {
log!(info "entered {}", fn_name!());
let name = class.sig.ident().inspect().clone();
self.unit_size += 1;
let firstlineno = match class.methods_list.get(0).and_then(|def| def.ln_begin()) {
let firstlineno = match class.methods_list.first().and_then(|def| def.ln_begin()) {
Some(l) => l,
None => class.sig.ln_begin().unwrap_or(0),
};
Expand Down
2 changes: 1 addition & 1 deletion crates/erg_compiler/context/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2640,7 +2640,7 @@ impl Context {
))
}),
TyParam::Array(tps) => {
let tp_t = if let Some(fst) = tps.get(0) {
let tp_t = if let Some(fst) = tps.first() {
self.get_tp_t(fst)?
} else {
Never
Expand Down
4 changes: 2 additions & 2 deletions crates/erg_compiler/context/hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl Context {
.union_pair()
.map(|(t1, t2)| format!("cannot {verb} {t1} {preposition} {t2}"))
.or_else(|| {
expected.inner_ts().get(0).map(|expected_inner| {
expected.inner_ts().first().map(|expected_inner| {
let expected_inner = self.readable_type(expected_inner.clone());
format!("cannot {verb} {found} {preposition} {expected_inner}")
})
Expand Down Expand Up @@ -237,7 +237,7 @@ impl Context {
if let Some(fv) = lhs.as_free() {
let (sub, sup) = fv.get_subsup()?;
let (verb, preposition, sequence) = Self::get_verb_and_preposition(&sup)?;
let sup = *option_enum_unwrap!(sup.typarams().get(0)?.clone(), TyParam::Type)?;
let sup = *option_enum_unwrap!(sup.typarams().first()?.clone(), TyParam::Type)?;
let sup = self.readable_type(sup);
let (l, r) = if sequence == Sequence::Forward {
(sub, sup)
Expand Down
2 changes: 1 addition & 1 deletion crates/erg_compiler/context/initialize/const_func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ fn _arr_shape(arr: ValueObj, ctx: &Context) -> Result<Vec<TyParam>, String> {
match arr {
ValueObj::Array(a) => {
shape.push(ValueObj::from(a.len()).into());
match a.get(0) {
match a.first() {
Some(arr_ @ (ValueObj::Array(_) | ValueObj::Type(_))) => {
arr = arr_.clone();
}
Expand Down
2 changes: 1 addition & 1 deletion crates/erg_compiler/context/inquire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ impl Context {
.map(|a| ParamTy::Pos(a.expr.ref_t().clone()))
.collect::<Vec<_>>();
let Some(mut return_t) = branch_ts
.get(0)
.first()
.and_then(|branch| branch.typ().return_t().cloned())
else {
errs.push(TyCheckError::args_missing_error(
Expand Down
2 changes: 1 addition & 1 deletion crates/erg_compiler/context/instantiate_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ impl Context {
}
ast::ConstExpr::Set(ConstSet::Comprehension(set)) => {
if set.layout.is_none() && set.generators.len() == 1 && set.guard.is_some() {
let (ident, expr) = set.generators.get(0).unwrap();
let (ident, expr) = set.generators.first().unwrap();
let iter = self.instantiate_const_expr(
expr,
erased_idx,
Expand Down
2 changes: 1 addition & 1 deletion crates/erg_compiler/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ impl Args {

pub fn get_left_or_key(&self, key: &str) -> Option<&Expr> {
if !self.pos_args.is_empty() {
Some(&self.pos_args.get(0)?.expr)
Some(&self.pos_args.first()?.expr)
} else if let Some(pos) = self
.kw_args
.iter()
Expand Down
10 changes: 5 additions & 5 deletions crates/erg_compiler/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ impl<A: ASTBuildable> GenericASTLowerer<A> {
}
self.module
.context
.convert_tp_into_type(t.typarams().get(0)?.clone())
.convert_tp_into_type(t.typarams().first()?.clone())
.ok()
});
let mut union = Type::Never;
Expand Down Expand Up @@ -446,7 +446,7 @@ impl<A: ASTBuildable> GenericASTLowerer<A> {
}
self.module
.context
.convert_tp_into_type(t.typarams().get(0)?.clone())
.convert_tp_into_type(t.typarams().first()?.clone())
.ok()
});
let elem = self.lower_expr(array.elem.expr, expect_elem.as_ref())?;
Expand Down Expand Up @@ -585,7 +585,7 @@ impl<A: ASTBuildable> GenericASTLowerer<A> {
}
self.module
.context
.convert_tp_into_type(t.typarams().get(0)?.clone())
.convert_tp_into_type(t.typarams().first()?.clone())
.ok()
});
let mut union = Type::Never;
Expand Down Expand Up @@ -672,7 +672,7 @@ impl<A: ASTBuildable> GenericASTLowerer<A> {
}
self.module
.context
.convert_tp_into_type(t.typarams().get(0)?.clone())
.convert_tp_into_type(t.typarams().first()?.clone())
.ok()
});
let elem = self.lower_expr(set.elem.expr, expect_elem.as_ref())?;
Expand Down Expand Up @@ -1722,7 +1722,7 @@ impl<A: ASTBuildable> GenericASTLowerer<A> {
.partition(|(_, vi)| vi.kind.is_var_params());
// vi.t: `[T; _]`
// pt: `name: T`
let var_params = var_params.get(0).map(|(name, vi)| {
let var_params = var_params.first().map(|(name, vi)| {
ParamTy::pos_or_kw(
name.as_ref().map(|n| n.inspect().clone()),
vi.t.inner_ts().remove(0),
Expand Down
4 changes: 2 additions & 2 deletions crates/erg_compiler/transpile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ impl PyScriptGenerator {
let Expr::Lambda(block) = call.args.remove(0) else {
todo!()
};
let non_default = block.params.non_defaults.get(0).unwrap();
let non_default = block.params.non_defaults.first().unwrap();
let param_token = match &non_default.raw.pat {
ParamPattern::VarName(name) => name.token(),
ParamPattern::Discard(token) => token,
Expand Down Expand Up @@ -822,7 +822,7 @@ impl PyScriptGenerator {
while let Some(Expr::Lambda(arm)) = call.args.try_remove(0) {
self.level += 1;
code += &" ".repeat(self.level);
let target = arm.params.non_defaults.get(0).unwrap();
let target = arm.params.non_defaults.first().unwrap();
match &target.raw.pat {
ParamPattern::VarName(param) => {
let param = Self::transpile_name(
Expand Down
2 changes: 1 addition & 1 deletion crates/erg_compiler/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3956,7 +3956,7 @@ impl Type {
Self::Refinement(refine) => refine.t.module_path(),
_ if self.is_module() => {
let tps = self.typarams();
let Some(TyParam::Value(ValueObj::Str(path))) = tps.get(0) else {
let Some(TyParam::Value(ValueObj::Str(path))) = tps.first() else {
return None;
};
Some(PathBuf::from(&path[..]))
Expand Down
2 changes: 1 addition & 1 deletion crates/erg_parser/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ impl Args {
#[to_owned(cloned)]
pub fn get_left_or_key(&self, key: &str) -> Option<&Expr> {
if !self.pos_args.is_empty() {
self.pos_args.get(0).map(|a| &a.expr)
self.pos_args.first().map(|a| &a.expr)
} else {
self.kw_args.iter().find_map(|a| {
if &a.keyword.content[..] == key {
Expand Down
2 changes: 1 addition & 1 deletion crates/erg_parser/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2776,7 +2776,7 @@ impl Parser {
ArrayInner::Normal(mut elems) => {
let elems = if elems
.pos_args()
.get(0)
.first()
.map(|pos| match &pos.expr {
Expr::Tuple(tup) => tup.paren().is_none(),
_ => false,
Expand Down

0 comments on commit edfabd9

Please sign in to comment.