From 4bbc9779716c975893e8dd82e1f9871d42e656d2 Mon Sep 17 00:00:00 2001 From: IWANABETHATGUY Date: Fri, 29 Dec 2023 12:20:51 +0800 Subject: [PATCH] chore: upgrade rustc toolchain to stable 1.75.0 (#1853) ref: https://blog.rust-lang.org/2023/12/28/Rust-1.75.0.html --- crates/oxc_diagnostics/src/graphic_reporter.rs | 4 ++-- crates/oxc_linter/src/config/mod.rs | 2 +- .../src/rules/deepscan/bad_array_method_on_arguments.rs | 2 +- .../src/rules/deepscan/uninvoked_array_callback.rs | 4 ++-- crates/oxc_linter/src/rules/eslint/no_regex_spaces.rs | 2 +- crates/oxc_linter/src/rules/jest/no_done_callback.rs | 2 +- crates/oxc_linter/src/rules/jest/no_identical_title.rs | 2 +- crates/oxc_linter/src/rules/jest/no_mocks_import.rs | 2 +- crates/oxc_linter/src/rules/jest/valid_title.rs | 4 ++-- crates/oxc_linter/src/rules/oxc/no_accumulating_spread.rs | 2 +- crates/oxc_linter/src/rules/react/button_has_type.rs | 4 ++-- .../oxc_linter/src/rules/react/jsx_no_useless_fragment.rs | 2 +- crates/oxc_linter/src/rules/unicorn/catch_error_name.rs | 6 +++--- crates/oxc_linter/src/rules/unicorn/escape_case.rs | 2 +- crates/oxc_linter/src/rules/unicorn/filename_case.rs | 1 + crates/oxc_linter/src/rules/unicorn/no_array_reduce.rs | 4 ++-- .../src/rules/unicorn/no_invalid_remove_event_listener.rs | 2 +- crates/oxc_linter/src/rules/unicorn/prefer_array_flat.rs | 6 +++--- crates/oxc_linter/src/rules/unicorn/prefer_date_now.rs | 2 +- .../src/rules/unicorn/prefer_native_coercion_functions.rs | 2 +- .../oxc_linter/src/rules/unicorn/prefer_query_selector.rs | 4 ++-- crates/oxc_linter/src/rules/unicorn/prefer_spread.rs | 2 +- crates/oxc_linter/src/utils/react.rs | 2 +- crates/oxc_linter/src/utils/unicorn.rs | 6 +++--- crates/oxc_minifier/src/compressor/ast_util.rs | 4 ++-- crates/oxc_parser/src/ts/types.rs | 1 + crates/oxc_prettier/src/format/assignment.rs | 2 +- crates/oxc_prettier/src/format/mod.rs | 4 ++-- crates/oxc_prettier/src/needs_parens.rs | 2 +- crates/oxc_semantic/src/module_record/builder.rs | 2 +- crates/oxc_semantic/tests/util/mod.rs | 2 ++ crates/oxc_transformer/src/es2015/template_literals.rs | 2 +- rust-toolchain.toml | 2 +- tasks/common/src/babel.rs | 4 ++-- 34 files changed, 50 insertions(+), 46 deletions(-) diff --git a/crates/oxc_diagnostics/src/graphic_reporter.rs b/crates/oxc_diagnostics/src/graphic_reporter.rs index 1e0f56a90..01e6f4540 100644 --- a/crates/oxc_diagnostics/src/graphic_reporter.rs +++ b/crates/oxc_diagnostics/src/graphic_reporter.rs @@ -134,9 +134,9 @@ impl GraphicalReportHandler { /// Render a [`Diagnostic`]. This function is mostly internal and meant to /// be called by the toplevel [`ReportHandler`] handler, but is made public /// to make it easier (possible) to test in isolation from global state. - pub fn render_report( + pub fn render_report( &self, - f: &mut impl fmt::Write, + f: &mut T, diagnostic: &(dyn Diagnostic), ) -> fmt::Result { self.render_header(f, diagnostic)?; diff --git a/crates/oxc_linter/src/config/mod.rs b/crates/oxc_linter/src/config/mod.rs index cc64a9759..acbc7e498 100644 --- a/crates/oxc_linter/src/config/mod.rs +++ b/crates/oxc_linter/src/config/mod.rs @@ -244,7 +244,7 @@ fn resolve_rule_value(value: &serde_json::Value) -> Result<(AllowWarnDeny, Optio config.push(item.clone()); } let config = if config.is_empty() { None } else { Some(Value::Array(config)) }; - if let Some(v_idx_0) = v.get(0) { + if let Some(v_idx_0) = v.first() { return Ok((AllowWarnDeny::try_from(v_idx_0)?, config)); } } diff --git a/crates/oxc_linter/src/rules/deepscan/bad_array_method_on_arguments.rs b/crates/oxc_linter/src/rules/deepscan/bad_array_method_on_arguments.rs index 382c2caac..1ae3192bb 100644 --- a/crates/oxc_linter/src/rules/deepscan/bad_array_method_on_arguments.rs +++ b/crates/oxc_linter/src/rules/deepscan/bad_array_method_on_arguments.rs @@ -80,7 +80,7 @@ impl Rule for BadArrayMethodOnArguments { // only check template string like "arguments[`METHOD_NAME`]" for Deepscan compatible if template.expressions.is_empty() && template.quasis.len() == 1 { if let Some(name) = - template.quasis.get(0).and_then(|template_element| { + template.quasis.first().and_then(|template_element| { template_element.value.cooked.as_deref() }) { diff --git a/crates/oxc_linter/src/rules/deepscan/uninvoked_array_callback.rs b/crates/oxc_linter/src/rules/deepscan/uninvoked_array_callback.rs index e1e7c4f87..d343b29ed 100644 --- a/crates/oxc_linter/src/rules/deepscan/uninvoked_array_callback.rs +++ b/crates/oxc_linter/src/rules/deepscan/uninvoked_array_callback.rs @@ -52,7 +52,7 @@ impl Rule for UninvokedArrayCallback { return; } if !matches!( - new_expr.arguments.get(0), + new_expr.arguments.first(), Some(Argument::Expression(Expression::NumberLiteral(_))) ) { return; @@ -69,7 +69,7 @@ impl Rule for UninvokedArrayCallback { else { return; }; - if !matches!(call_expr.arguments.get(0), Some(Argument::Expression(arg_expr)) if arg_expr.is_function()) + if !matches!(call_expr.arguments.first(), Some(Argument::Expression(arg_expr)) if arg_expr.is_function()) { return; } diff --git a/crates/oxc_linter/src/rules/eslint/no_regex_spaces.rs b/crates/oxc_linter/src/rules/eslint/no_regex_spaces.rs index 751d4c231..d45104fe8 100644 --- a/crates/oxc_linter/src/rules/eslint/no_regex_spaces.rs +++ b/crates/oxc_linter/src/rules/eslint/no_regex_spaces.rs @@ -93,7 +93,7 @@ impl NoRegexSpaces { } } - if let Some(Argument::Expression(Expression::StringLiteral(pattern))) = args.get(0) { + if let Some(Argument::Expression(Expression::StringLiteral(pattern))) = args.first() { if Self::has_exempted_char_class(&pattern.value) { return None; // skip spaces inside char class, e.g. RegExp('[ ]') } diff --git a/crates/oxc_linter/src/rules/jest/no_done_callback.rs b/crates/oxc_linter/src/rules/jest/no_done_callback.rs index d23ce29cc..4691c7a5b 100644 --- a/crates/oxc_linter/src/rules/jest/no_done_callback.rs +++ b/crates/oxc_linter/src/rules/jest/no_done_callback.rs @@ -176,7 +176,7 @@ fn find_argument_of_callback<'a>( } if matches!(kind, JestFnKind::General(JestGeneralFnKind::Hook)) { - return call_expr.arguments.get(0); + return call_expr.arguments.first(); } if matches!(kind, JestFnKind::General(JestGeneralFnKind::Test)) { diff --git a/crates/oxc_linter/src/rules/jest/no_identical_title.rs b/crates/oxc_linter/src/rules/jest/no_identical_title.rs index 1d761bfbc..dc5149983 100644 --- a/crates/oxc_linter/src/rules/jest/no_identical_title.rs +++ b/crates/oxc_linter/src/rules/jest/no_identical_title.rs @@ -138,7 +138,7 @@ fn filter_and_process_jest_result<'a>( return None; }; - match call_expr.arguments.get(0) { + match call_expr.arguments.first() { Some(Argument::Expression(Expression::StringLiteral(string_lit))) => { Some((string_lit.span, &string_lit.value, kind, parent_id)) } diff --git a/crates/oxc_linter/src/rules/jest/no_mocks_import.rs b/crates/oxc_linter/src/rules/jest/no_mocks_import.rs index 6ffea5ef9..c49ccec4e 100644 --- a/crates/oxc_linter/src/rules/jest/no_mocks_import.rs +++ b/crates/oxc_linter/src/rules/jest/no_mocks_import.rs @@ -66,7 +66,7 @@ impl Rule for NoMocksImport { }; let Some(Argument::Expression(Expression::StringLiteral(string_literal))) = - call_expr.arguments.get(0) + call_expr.arguments.first() else { return; }; diff --git a/crates/oxc_linter/src/rules/jest/valid_title.rs b/crates/oxc_linter/src/rules/jest/valid_title.rs index 37b70fa41..f11719775 100644 --- a/crates/oxc_linter/src/rules/jest/valid_title.rs +++ b/crates/oxc_linter/src/rules/jest/valid_title.rs @@ -133,7 +133,7 @@ impl ValidTitle { return; } - let Some(Argument::Expression(expr)) = call_expr.arguments.get(0) else { + let Some(Argument::Expression(expr)) = call_expr.arguments.first() else { return; }; @@ -263,7 +263,7 @@ fn compile_matcher_pattern(pattern: MatcherPattern) -> Option { - let reg_str = pattern.get(0).and_then(|v| v.as_str()).map(|v| format!("(?u){v}"))?; + let reg_str = pattern.first().and_then(|v| v.as_str()).map(|v| format!("(?u){v}"))?; let reg = Regex::new(®_str).ok()?; let message = pattern.get(1).map(std::string::ToString::to_string); Some((reg, message)) diff --git a/crates/oxc_linter/src/rules/oxc/no_accumulating_spread.rs b/crates/oxc_linter/src/rules/oxc/no_accumulating_spread.rs index a14a0b465..f51b3ef12 100644 --- a/crates/oxc_linter/src/rules/oxc/no_accumulating_spread.rs +++ b/crates/oxc_linter/src/rules/oxc/no_accumulating_spread.rs @@ -95,7 +95,7 @@ impl Rule for NoAccumulatingSpread { // We're only looking for the first parameter, since that's where acc is. // Skip non-parameter or non-first-parameter declarations. let first_param_symbol_id = - params.items.get(0).and_then(|item| get_identifier_symbol_id(&item.pattern.kind)); + params.items.first().and_then(|item| get_identifier_symbol_id(&item.pattern.kind)); if !first_param_symbol_id.is_some_and(|id| id == referenced_symbol_id) { return; } diff --git a/crates/oxc_linter/src/rules/react/button_has_type.rs b/crates/oxc_linter/src/rules/react/button_has_type.rs index ce9fb5fcf..1ad7d7102 100644 --- a/crates/oxc_linter/src/rules/react/button_has_type.rs +++ b/crates/oxc_linter/src/rules/react/button_has_type.rs @@ -95,7 +95,7 @@ impl Rule for ButtonHasType { AstKind::CallExpression(call_expr) => { if is_create_element_call(call_expr) { let Some(Argument::Expression(Expression::StringLiteral(str))) = - call_expr.arguments.get(0) + call_expr.arguments.first() else { return; }; @@ -144,7 +144,7 @@ impl Rule for ButtonHasType { } fn from_configuration(value: serde_json::Value) -> Self { - let value = value.as_array().and_then(|arr| arr.get(0)).and_then(|val| val.as_object()); + let value = value.as_array().and_then(|arr| arr.first()).and_then(|val| val.as_object()); Self { button: value diff --git a/crates/oxc_linter/src/rules/react/jsx_no_useless_fragment.rs b/crates/oxc_linter/src/rules/react/jsx_no_useless_fragment.rs index fd0324b4c..bb9c2cea0 100644 --- a/crates/oxc_linter/src/rules/react/jsx_no_useless_fragment.rs +++ b/crates/oxc_linter/src/rules/react/jsx_no_useless_fragment.rs @@ -198,7 +198,7 @@ fn is_fragment_with_only_text_and_is_not_child<'a>( return false; } - if let Some(JSXChild::Text(_)) = node.get(0) { + if let Some(JSXChild::Text(_)) = node.first() { let Some(parent) = ctx.nodes().parent_kind(id) else { return false }; return !matches!(parent, AstKind::JSXElement(_) | AstKind::JSXFragment(_)); } diff --git a/crates/oxc_linter/src/rules/unicorn/catch_error_name.rs b/crates/oxc_linter/src/rules/unicorn/catch_error_name.rs index b541a3417..80b723183 100644 --- a/crates/oxc_linter/src/rules/unicorn/catch_error_name.rs +++ b/crates/oxc_linter/src/rules/unicorn/catch_error_name.rs @@ -116,7 +116,7 @@ impl Rule for CatchErrorName { if let AstKind::CallExpression(call_expr) = node.kind() { if let Expression::MemberExpression(member_expr) = &call_expr.callee { if member_expr.static_property_name() == Some("catch") { - if let Some(arg0) = call_expr.arguments.get(0) { + if let Some(arg0) = call_expr.arguments.first() { if let Some(diagnostic) = self.check_function_arguments(arg0, ctx) { ctx.diagnostic(diagnostic); } @@ -149,7 +149,7 @@ impl CatchErrorName { let expr = expr.without_parenthesized(); if let Expression::ArrowExpression(arrow_expr) = expr { - if let Some(arg0) = arrow_expr.params.items.get(0) { + if let Some(arg0) = arrow_expr.params.items.first() { if let BindingPatternKind::BindingIdentifier(v) = &arg0.pattern.kind { if self.is_name_allowed(&v.name) { return None; @@ -177,7 +177,7 @@ impl CatchErrorName { } if let Expression::FunctionExpression(fn_expr) = expr { - if let Some(arg0) = fn_expr.params.items.get(0) { + if let Some(arg0) = fn_expr.params.items.first() { if let BindingPatternKind::BindingIdentifier(binding_ident) = &arg0.pattern.kind { if self.is_name_allowed(&binding_ident.name) { return None; diff --git a/crates/oxc_linter/src/rules/unicorn/escape_case.rs b/crates/oxc_linter/src/rules/unicorn/escape_case.rs index 60dc62403..8041dd903 100644 --- a/crates/oxc_linter/src/rules/unicorn/escape_case.rs +++ b/crates/oxc_linter/src/rules/unicorn/escape_case.rs @@ -44,7 +44,7 @@ declare_oxc_lint!( ); fn is_hex_char(c: char) -> bool { - matches!(c, '0'..='9' | 'a'..='f' | 'A'..='F') + c.is_ascii_hexdigit() } fn is_hex(iter: &Chars, count: i32) -> bool { let mut iter = iter.clone(); diff --git a/crates/oxc_linter/src/rules/unicorn/filename_case.rs b/crates/oxc_linter/src/rules/unicorn/filename_case.rs index b796f3cd0..672a1ce62 100644 --- a/crates/oxc_linter/src/rules/unicorn/filename_case.rs +++ b/crates/oxc_linter/src/rules/unicorn/filename_case.rs @@ -15,6 +15,7 @@ use crate::{context::LintContext, rule::Rule}; struct FilenameCaseDiagnostic(#[label] pub Span, &'static str); #[derive(Debug, Clone)] +#[allow(clippy::struct_field_names)] pub struct FilenameCase { kebab_case: bool, camel_case: bool, diff --git a/crates/oxc_linter/src/rules/unicorn/no_array_reduce.rs b/crates/oxc_linter/src/rules/unicorn/no_array_reduce.rs index 216211081..7b37ba147 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_array_reduce.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_array_reduce.rs @@ -73,7 +73,7 @@ impl Rule for NoArrayReduce { }; if is_method_call(call_expr, None, Some(&["reduce", "reduceRight"]), Some(1), Some(2)) - && !matches!(call_expr.arguments.get(0), Some(Argument::SpreadElement(_))) + && !matches!(call_expr.arguments.first(), Some(Argument::SpreadElement(_))) && !call_expr.optional && !member_expr.is_computed() { @@ -99,7 +99,7 @@ impl Rule for NoArrayReduce { } fn is_simple_operation(node: &CallExpression) -> bool { - let Some(Argument::Expression(callback_arg)) = node.arguments.get(0) else { + let Some(Argument::Expression(callback_arg)) = node.arguments.first() else { return false; }; let function_body = match callback_arg { diff --git a/crates/oxc_linter/src/rules/unicorn/no_invalid_remove_event_listener.rs b/crates/oxc_linter/src/rules/unicorn/no_invalid_remove_event_listener.rs index 890582e38..1c3bb0623 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_invalid_remove_event_listener.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_invalid_remove_event_listener.rs @@ -72,7 +72,7 @@ impl Rule for NoInvalidRemoveEventListener { return; } - if matches!(call_expr.arguments.get(0), Some(Argument::SpreadElement(_))) { + if matches!(call_expr.arguments.first(), Some(Argument::SpreadElement(_))) { return; } diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_array_flat.rs b/crates/oxc_linter/src/rules/unicorn/prefer_array_flat.rs index 4bf147a72..e4079f2e8 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_array_flat.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_array_flat.rs @@ -79,7 +79,7 @@ fn check_array_flat_map_case<'a>(call_expr: &CallExpression<'a>, ctx: &LintConte return; } - let Argument::Expression(first_argument) = call_expr.arguments.get(0).unwrap() else { + let Argument::Expression(first_argument) = call_expr.arguments.first().unwrap() else { return; }; @@ -113,7 +113,7 @@ fn check_array_reduce_case<'a>(call_expr: &CallExpression<'a>, ctx: &LintContext return; } let Argument::Expression(Expression::ArrowExpression(first_argument)) = - call_expr.arguments.get(0).unwrap() + call_expr.arguments.first().unwrap() else { return; }; @@ -144,7 +144,7 @@ fn check_array_reduce_case<'a>(call_expr: &CallExpression<'a>, ctx: &LintContext return; }; - let Some(Statement::ExpressionStatement(expr_stmt)) = first_argument.body.statements.get(0) + let Some(Statement::ExpressionStatement(expr_stmt)) = first_argument.body.statements.first() else { return; }; diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_date_now.rs b/crates/oxc_linter/src/rules/unicorn/prefer_date_now.rs index 2ce8c305d..9c358a958 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_date_now.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_date_now.rs @@ -81,7 +81,7 @@ impl Rule for PreferDateNow { if matches!(ident.name.as_str(), "Number" | "BigInt") && call_expr.arguments.len() == 1 { - if let Some(Argument::Expression(expr)) = call_expr.arguments.get(0) { + if let Some(Argument::Expression(expr)) = call_expr.arguments.first() { if is_new_date(expr.without_parenthesized()) { ctx.diagnostic( PreferDateNowDiagnostic::PreferDateNowOverNumberDateObject( diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_native_coercion_functions.rs b/crates/oxc_linter/src/rules/unicorn/prefer_native_coercion_functions.rs index 6b9f7fd0c..d39aae40b 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_native_coercion_functions.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_native_coercion_functions.rs @@ -108,7 +108,7 @@ impl Rule for PreferNativeCoercionFunctions { } fn get_first_parameter_name<'a>(arg: &'a FormalParameters) -> Option<&'a str> { - let first_func_param = arg.items.get(0)?; + let first_func_param = arg.items.first()?; let BindingPatternKind::BindingIdentifier(first_func_param) = &first_func_param.pattern.kind else { return None; diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_query_selector.rs b/crates/oxc_linter/src/rules/unicorn/prefer_query_selector.rs index 39f6c1075..7b4942ca7 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_query_selector.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_query_selector.rs @@ -71,7 +71,7 @@ impl Rule for PreferQuerySelector { return; } - let Argument::Expression(argument_expr) = call_expr.arguments.get(0).unwrap() else { + let Argument::Expression(argument_expr) = call_expr.arguments.first().unwrap() else { return; }; @@ -97,7 +97,7 @@ impl Rule for PreferQuerySelector { Expression::StringLiteral(literal) => Some(literal.value.trim()), Expression::TemplateLiteral(literal) => { if literal.expressions.len() == 0 { - literal.quasis.get(0).unwrap().value.cooked.as_deref().map(str::trim) + literal.quasis.first().unwrap().value.cooked.as_deref().map(str::trim) } else { None } diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_spread.rs b/crates/oxc_linter/src/rules/unicorn/prefer_spread.rs index 889facb2b..2eafbfa04 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_spread.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_spread.rs @@ -105,7 +105,7 @@ impl Rule for PreferSpread { } } - if let Some(first_arg) = call_expr.arguments.get(0) { + if let Some(first_arg) = call_expr.arguments.first() { let Argument::Expression(first_arg) = first_arg else { return }; if let Expression::NumberLiteral(num_lit) = first_arg.without_parenthesized() { if num_lit.value != 0.0 { diff --git a/crates/oxc_linter/src/utils/react.rs b/crates/oxc_linter/src/utils/react.rs index 3432e9387..b0d073913 100644 --- a/crates/oxc_linter/src/utils/react.rs +++ b/crates/oxc_linter/src/utils/react.rs @@ -196,7 +196,7 @@ pub fn parse_jsx_value(value: &JSXAttributeValue) -> Result { }) => match expression { Expression::StringLiteral(str) => str.value.parse().or(Err(())), Expression::TemplateLiteral(tmpl) => { - tmpl.quasis.get(0).unwrap().value.raw.parse().or(Err(())) + tmpl.quasis.first().unwrap().value.raw.parse().or(Err(())) } Expression::NumberLiteral(num) => Ok(num.value), _ => Err(()), diff --git a/crates/oxc_linter/src/utils/unicorn.rs b/crates/oxc_linter/src/utils/unicorn.rs index 9f056ef25..5824ad11c 100644 --- a/crates/oxc_linter/src/utils/unicorn.rs +++ b/crates/oxc_linter/src/utils/unicorn.rs @@ -108,7 +108,7 @@ pub fn is_logical_expression(node: &AstNode) -> bool { // gets the name of the first parameter of a function pub fn get_first_parameter_name<'a>(arg: &'a FormalParameters) -> Option<&'a str> { - let first_func_param = arg.items.get(0)?; + let first_func_param = arg.items.first()?; let BindingPatternKind::BindingIdentifier(first_func_param) = &first_func_param.pattern.kind else { return None; @@ -117,9 +117,9 @@ pub fn get_first_parameter_name<'a>(arg: &'a FormalParameters) -> Option<&'a str } pub fn get_return_identifier_name<'a>(body: &'a FunctionBody<'_>) -> Option<&'a str> { - match body.statements.get(0)? { + match body.statements.first()? { Statement::BlockStatement(block_stmt) => { - let Statement::ReturnStatement(return_stmt) = block_stmt.body.get(0)? else { + let Statement::ReturnStatement(return_stmt) = block_stmt.body.first()? else { return None; }; diff --git a/crates/oxc_minifier/src/compressor/ast_util.rs b/crates/oxc_minifier/src/compressor/ast_util.rs index 1ba63740e..53e4b5324 100644 --- a/crates/oxc_minifier/src/compressor/ast_util.rs +++ b/crates/oxc_minifier/src/compressor/ast_util.rs @@ -457,7 +457,7 @@ pub fn get_boolean_value(expr: &Expression) -> Option { // only for `` template_literal .quasis - .get(0) + .first() .filter(|quasi| quasi.tail) .and_then(|quasi| quasi.value.cooked.as_ref()) .map(|cooked| !cooked.is_empty()) @@ -550,7 +550,7 @@ pub fn get_string_value<'a>(expr: &'a Expression) -> Option> { // Closure-compiler do more: [case TEMPLATELIT](https://github.com/google/closure-compiler/blob/e13f5cd0a5d3d35f2db1e6c03fdf67ef02946009/src/com/google/javascript/jscomp/NodeUtil.java#L241-L256). template_literal .quasis - .get(0) + .first() .filter(|quasi| quasi.tail) .and_then(|quasi| quasi.value.cooked.as_ref()) .map(|cooked| Cow::Borrowed(cooked.as_str())) diff --git a/crates/oxc_parser/src/ts/types.rs b/crates/oxc_parser/src/ts/types.rs index c77828916..9847351ab 100644 --- a/crates/oxc_parser/src/ts/types.rs +++ b/crates/oxc_parser/src/ts/types.rs @@ -1110,6 +1110,7 @@ impl<'a> Parser<'a> { break; } + #[allow(clippy::unnecessary_fallible_conversions)] if let Ok(modifier_flag) = self.cur_kind().try_into() { flags.set(modifier_flag, true); } else { diff --git a/crates/oxc_prettier/src/format/assignment.rs b/crates/oxc_prettier/src/format/assignment.rs index ad01489fe..76a56096e 100644 --- a/crates/oxc_prettier/src/format/assignment.rs +++ b/crates/oxc_prettier/src/format/assignment.rs @@ -164,7 +164,7 @@ fn choose_layout<'a>( return Layout::Chain; } else if let Expression::ArrowExpression(arrow_expr) = right_expr { if let Some(Statement::ExpressionStatement(expr_stmt)) = - arrow_expr.body.statements.get(0) + arrow_expr.body.statements.first() { if let Expression::ArrowExpression(_) = expr_stmt.expression { return Layout::ChainTailArrowChain; diff --git a/crates/oxc_prettier/src/format/mod.rs b/crates/oxc_prettier/src/format/mod.rs index 3241d1f60..4018af71f 100644 --- a/crates/oxc_prettier/src/format/mod.rs +++ b/crates/oxc_prettier/src/format/mod.rs @@ -993,7 +993,7 @@ impl<'a> Format<'a> for ImportDeclaration<'a> { parts.push(ss!(" type")); } if let Some(specifiers) = &self.specifiers { - let is_default = specifiers.get(0).is_some_and(|x| { + let is_default = specifiers.first().is_some_and(|x| { matches!(x, ImportDeclarationSpecifier::ImportDefaultSpecifier(_)) }); @@ -1001,7 +1001,7 @@ impl<'a> Format<'a> for ImportDeclaration<'a> { matches!(x, ImportDeclarationSpecifier::ImportNamespaceSpecifier(_)) }; - let is_namespace = specifiers.get(0).is_some_and(validate_namespace) + let is_namespace = specifiers.first().is_some_and(validate_namespace) || specifiers.get(1).is_some_and(validate_namespace); parts.push(module::print_module_specifiers(p, specifiers, is_default, is_namespace)); diff --git a/crates/oxc_prettier/src/needs_parens.rs b/crates/oxc_prettier/src/needs_parens.rs index 7fbf46aed..7767f4837 100644 --- a/crates/oxc_prettier/src/needs_parens.rs +++ b/crates/oxc_prettier/src/needs_parens.rs @@ -642,7 +642,7 @@ impl<'a> Prettier<'a> { } Expression::SequenceExpression(e) => e .expressions - .get(0) + .first() .map_or(false, |e| Self::starts_with_no_lookahead_token(e, span)), Expression::ChainExpression(e) => match &e.expression { ChainElement::CallExpression(e) => { diff --git a/crates/oxc_semantic/src/module_record/builder.rs b/crates/oxc_semantic/src/module_record/builder.rs index 6a85f4f39..465774ace 100644 --- a/crates/oxc_semantic/src/module_record/builder.rs +++ b/crates/oxc_semantic/src/module_record/builder.rs @@ -46,7 +46,7 @@ impl ModuleRecordBuilder { }; if ident.name == "require" { let Some(Argument::Expression(Expression::StringLiteral(module))) = - call.arguments.get(0) + call.arguments.first() else { continue; }; diff --git a/crates/oxc_semantic/tests/util/mod.rs b/crates/oxc_semantic/tests/util/mod.rs index e2477df10..ada9c7306 100644 --- a/crates/oxc_semantic/tests/util/mod.rs +++ b/crates/oxc_semantic/tests/util/mod.rs @@ -114,6 +114,7 @@ impl SemanticTester { /// /// ## Fails /// If no class with the given name exists. + #[allow(dead_code)] pub fn has_class(&self, name: &str) -> ClassTester { ClassTester::has_class(self.build(), name) } @@ -124,6 +125,7 @@ impl SemanticTester { /// 1. No symbol with the given name exists, /// 2. More than one symbol with the given name exists, so a symbol cannot /// be uniquely obtained. + #[allow(dead_code)] pub fn has_some_symbol(&self, name: &str) -> SymbolTester { SymbolTester::new_unique(self, self.build(), name) } diff --git a/crates/oxc_transformer/src/es2015/template_literals.rs b/crates/oxc_transformer/src/es2015/template_literals.rs index fb7499999..5204173ea 100644 --- a/crates/oxc_transformer/src/es2015/template_literals.rs +++ b/crates/oxc_transformer/src/es2015/template_literals.rs @@ -45,7 +45,7 @@ impl<'a> TemplateLiterals<'a> { } // make sure the first node is a string - if !matches!(nodes.get(0), Some(Expression::StringLiteral(_))) { + if !matches!(nodes.first(), Some(Expression::StringLiteral(_))) { let literal = StringLiteral::new(SPAN, Atom::from("")); let string_literal = self.ast.literal_string_expression(literal); nodes.insert(0, string_literal); diff --git a/rust-toolchain.toml b/rust-toolchain.toml index e7f52bc82..1c8cfba9f 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "1.74.0" +channel = "1.75.0" profile = "default" diff --git a/tasks/common/src/babel.rs b/tasks/common/src/babel.rs index 4f1c5c9f2..67a8c85be 100644 --- a/tasks/common/src/babel.rs +++ b/tasks/common/src/babel.rs @@ -69,7 +69,7 @@ impl BabelOptions { pub fn is_typescript_definition(&self) -> bool { self.plugins.iter().filter_map(Value::as_array).any(|p| { - let typescript = p.get(0).and_then(Value::as_str).is_some_and(|s| s == "typescript"); + let typescript = p.first().and_then(Value::as_str).is_some_and(|s| s == "typescript"); let dts = p .get(1) .and_then(Value::as_object) @@ -91,7 +91,7 @@ impl BabelOptions { pub fn get_plugin(&self, name: &str) -> Option> { self.plugins.iter().find_map(|v| match v { Value::String(s) if s == name => Some(None), - Value::Array(a) if a.get(0).and_then(Value::as_str).is_some_and(|s| s == name) => { + Value::Array(a) if a.first().and_then(Value::as_str).is_some_and(|s| s == name) => { Some(a.get(1).cloned()) } _ => None,