chore: upgrade rustc toolchain to stable 1.75.0 (#1853)

ref: 
https://blog.rust-lang.org/2023/12/28/Rust-1.75.0.html
This commit is contained in:
IWANABETHATGUY 2023-12-29 12:20:51 +08:00 committed by GitHub
parent a743d06207
commit 4bbc977971
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 50 additions and 46 deletions

View file

@ -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<T: fmt::Write>(
&self,
f: &mut impl fmt::Write,
f: &mut T,
diagnostic: &(dyn Diagnostic),
) -> fmt::Result {
self.render_header(f, diagnostic)?;

View file

@ -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));
}
}

View file

@ -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()
})
{

View file

@ -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;
}

View file

@ -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('[ ]')
}

View file

@ -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)) {

View file

@ -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))
}

View file

@ -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;
};

View file

@ -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<CompiledMatcherAnd
Some((reg, None))
}
MatcherPattern::Vec(pattern) => {
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(&reg_str).ok()?;
let message = pattern.get(1).map(std::string::ToString::to_string);
Some((reg, message))

View file

@ -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;
}

View file

@ -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

View file

@ -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(_));
}

View file

@ -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;

View file

@ -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();

View file

@ -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,

View file

@ -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 {

View file

@ -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;
}

View file

@ -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;
};

View file

@ -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(

View file

@ -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;

View file

@ -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
}

View file

@ -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 {

View file

@ -196,7 +196,7 @@ pub fn parse_jsx_value(value: &JSXAttributeValue) -> Result<f64, ()> {
}) => 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(()),

View file

@ -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;
};

View file

@ -457,7 +457,7 @@ pub fn get_boolean_value(expr: &Expression) -> Option<bool> {
// 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<Cow<'a, str>> {
// 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()))

View file

@ -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 {

View file

@ -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;

View file

@ -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));

View file

@ -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) => {

View file

@ -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;
};

View file

@ -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)
}

View file

@ -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);

View file

@ -1,3 +1,3 @@
[toolchain]
channel = "1.74.0"
channel = "1.75.0"
profile = "default"

View file

@ -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<Option<Value>> {
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,