diff --git a/crates/ruff_linter/src/checkers/ast/mod.rs b/crates/ruff_linter/src/checkers/ast/mod.rs index d980831d3b..53ea78e53d 100644 --- a/crates/ruff_linter/src/checkers/ast/mod.rs +++ b/crates/ruff_linter/src/checkers/ast/mod.rs @@ -904,7 +904,7 @@ where range: _, }) => { if let Expr::Name(ast::ExprName { id, ctx, range: _ }) = func.as_ref() { - if id == "locals" && ctx.is_load() { + if &**id == "locals" && ctx.is_load() { let scope = self.semantic.current_scope_mut(); scope.set_uses_locals(); } @@ -1073,7 +1073,7 @@ where range: _, } = keyword; if let Some(id) = arg { - if id.as_str() == "bound" { + if &**id == "bound" { self.visit_type_definition(value); } else { self.visit_non_type_definition(value); @@ -1755,21 +1755,21 @@ impl<'a> Checker<'a> { && match parent { Stmt::Assign(ast::StmtAssign { targets, .. }) => { if let Some(Expr::Name(ast::ExprName { id, .. })) = targets.first() { - id == "__all__" + &**id == "__all__" } else { false } } Stmt::AugAssign(ast::StmtAugAssign { target, .. }) => { if let Expr::Name(ast::ExprName { id, .. }) = target.as_ref() { - id == "__all__" + &**id == "__all__" } else { false } } Stmt::AnnAssign(ast::StmtAnnAssign { target, .. }) => { if let Expr::Name(ast::ExprName { id, .. }) = target.as_ref() { - id == "__all__" + &**id == "__all__" } else { false } diff --git a/crates/ruff_linter/src/checkers/imports.rs b/crates/ruff_linter/src/checkers/imports.rs index 5ecb477d85..1a767a9f18 100644 --- a/crates/ruff_linter/src/checkers/imports.rs +++ b/crates/ruff_linter/src/checkers/imports.rs @@ -46,7 +46,7 @@ fn extract_import_map(path: &Path, package: Option<&Path>, blocks: &[&Block]) -> }) => { let level = level.unwrap_or_default() as usize; let module = if let Some(module) = module { - let module: &String = module.as_ref(); + let module: &str = module.as_str(); if level == 0 { Cow::Borrowed(module) } else { diff --git a/crates/ruff_linter/src/rules/airflow/rules/task_variable_name.rs b/crates/ruff_linter/src/rules/airflow/rules/task_variable_name.rs index 76ebb405a2..af25356ba3 100644 --- a/crates/ruff_linter/src/rules/airflow/rules/task_variable_name.rs +++ b/crates/ruff_linter/src/rules/airflow/rules/task_variable_name.rs @@ -81,7 +81,7 @@ pub(crate) fn variable_name_task_id( let ast::ExprStringLiteral { value: task_id, .. } = keyword.value.as_string_literal_expr()?; // If the target name is the same as the task_id, no violation. - if task_id == id { + if task_id == &**id { return None; } diff --git a/crates/ruff_linter/src/rules/flake8_annotations/helpers.rs b/crates/ruff_linter/src/rules/flake8_annotations/helpers.rs index 873b185982..b56bbe1d52 100644 --- a/crates/ruff_linter/src/rules/flake8_annotations/helpers.rs +++ b/crates/ruff_linter/src/rules/flake8_annotations/helpers.rs @@ -137,7 +137,7 @@ impl AutoPythonType { ) .ok()?; let expr = Expr::Name(ast::ExprName { - id: binding, + id: binding.into_boxed_str(), range: TextRange::default(), ctx: ExprContext::Load, }); diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_password_string.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_password_string.rs index 07cbea8c9f..b078604e91 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_password_string.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_password_string.rs @@ -52,7 +52,7 @@ impl Violation for HardcodedPasswordString { fn password_target(target: &Expr) -> Option<&str> { let target_name = match target { // variable = "s3cr3t" - Expr::Name(ast::ExprName { id, .. }) => id.as_str(), + Expr::Name(ast::ExprName { id, .. }) => &**id, // d["password"] = "s3cr3t" Expr::Subscript(ast::ExprSubscript { slice, .. }) => match slice.as_ref() { Expr::StringLiteral(ast::ExprStringLiteral { value, .. }) => value.to_str(), diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/jinja2_autoescape_false.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/jinja2_autoescape_false.rs index 2cd35d1049..ed738c33c3 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/jinja2_autoescape_false.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/jinja2_autoescape_false.rs @@ -69,7 +69,7 @@ pub(crate) fn jinja2_autoescape_false(checker: &mut Checker, call: &ast::ExprCal Expr::BooleanLiteral(ast::ExprBooleanLiteral { value: true, .. }) => (), Expr::Call(ast::ExprCall { func, .. }) => { if let Expr::Name(ast::ExprName { id, .. }) = func.as_ref() { - if id != "select_autoescape" { + if &**id != "select_autoescape" { checker.diagnostics.push(Diagnostic::new( Jinja2AutoescapeFalse { value: true }, keyword.range(), diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/ssl_with_bad_defaults.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/ssl_with_bad_defaults.rs index 67f4033e60..6e216e0f74 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/ssl_with_bad_defaults.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/ssl_with_bad_defaults.rs @@ -64,7 +64,7 @@ pub(crate) fn ssl_with_bad_defaults(checker: &mut Checker, function_def: &StmtFu if let Some(default) = ¶m.default { match default.as_ref() { Expr::Name(ast::ExprName { id, range, .. }) => { - if is_insecure_protocol(id.as_str()) { + if is_insecure_protocol(id) { checker.diagnostics.push(Diagnostic::new( SslWithBadDefaults { protocol: id.to_string(), diff --git a/crates/ruff_linter/src/rules/flake8_blind_except/rules/blind_except.rs b/crates/ruff_linter/src/rules/flake8_blind_except/rules/blind_except.rs index 3eab03f29a..7e31590f22 100644 --- a/crates/ruff_linter/src/rules/flake8_blind_except/rules/blind_except.rs +++ b/crates/ruff_linter/src/rules/flake8_blind_except/rules/blind_except.rs @@ -83,7 +83,7 @@ pub(crate) fn blind_except( return; }; - if !matches!(id.as_str(), "BaseException" | "Exception") { + if !matches!(&**id, "BaseException" | "Exception") { return; } @@ -96,7 +96,7 @@ pub(crate) fn blind_except( if let Stmt::Raise(ast::StmtRaise { exc, .. }) = stmt { if let Some(exc) = exc { if let Expr::Name(ast::ExprName { id, .. }) = exc.as_ref() { - name.is_some_and(|name| id == name) + name.is_some_and(|name| &**id == name) } else { false } diff --git a/crates/ruff_linter/src/rules/flake8_boolean_trap/helpers.rs b/crates/ruff_linter/src/rules/flake8_boolean_trap/helpers.rs index 5f8f7a5dd9..4a7a7d922d 100644 --- a/crates/ruff_linter/src/rules/flake8_boolean_trap/helpers.rs +++ b/crates/ruff_linter/src/rules/flake8_boolean_trap/helpers.rs @@ -54,7 +54,7 @@ pub(super) fn is_allowed_func_def(name: &str) -> bool { pub(super) fn allow_boolean_trap(call: &ast::ExprCall) -> bool { let func_name = match call.func.as_ref() { Expr::Attribute(ast::ExprAttribute { attr, .. }) => attr.as_str(), - Expr::Name(ast::ExprName { id, .. }) => id.as_str(), + Expr::Name(ast::ExprName { id, .. }) => &**id, _ => return false, }; diff --git a/crates/ruff_linter/src/rules/flake8_boolean_trap/rules/boolean_type_hint_positional_argument.rs b/crates/ruff_linter/src/rules/flake8_boolean_trap/rules/boolean_type_hint_positional_argument.rs index f4bf4a2963..92650ac497 100644 --- a/crates/ruff_linter/src/rules/flake8_boolean_trap/rules/boolean_type_hint_positional_argument.rs +++ b/crates/ruff_linter/src/rules/flake8_boolean_trap/rules/boolean_type_hint_positional_argument.rs @@ -164,7 +164,7 @@ pub(crate) fn boolean_type_hint_positional_argument( fn match_annotation_to_literal_bool(annotation: &Expr) -> bool { match annotation { // Ex) `True` - Expr::Name(name) => &name.id == "bool", + Expr::Name(name) => &*name.id == "bool", // Ex) `"True"` Expr::StringLiteral(ast::ExprStringLiteral { value, .. }) => value == "bool", _ => false, @@ -176,7 +176,7 @@ fn match_annotation_to_literal_bool(annotation: &Expr) -> bool { fn match_annotation_to_complex_bool(annotation: &Expr, semantic: &SemanticModel) -> bool { match annotation { // Ex) `bool` - Expr::Name(name) => &name.id == "bool", + Expr::Name(name) => &*name.id == "bool", // Ex) `"bool"` Expr::StringLiteral(ast::ExprStringLiteral { value, .. }) => value == "bool", // Ex) `bool | int` diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/assignment_to_os_environ.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/assignment_to_os_environ.rs index 9f0fef6c38..dc56f0bd97 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/assignment_to_os_environ.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/assignment_to_os_environ.rs @@ -63,7 +63,7 @@ pub(crate) fn assignment_to_os_environ(checker: &mut Checker, targets: &[Expr]) let Expr::Name(ast::ExprName { id, .. }) = value.as_ref() else { return; }; - if id != "os" { + if &**id != "os" { return; } checker diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/cached_instance_method.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/cached_instance_method.rs index 083954116a..50d3e366c5 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/cached_instance_method.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/cached_instance_method.rs @@ -85,7 +85,7 @@ pub(crate) fn cached_instance_method(checker: &mut Checker, decorator_list: &[De // TODO(charlie): This should take into account `classmethod-decorators` and // `staticmethod-decorators`. if let Expr::Name(ast::ExprName { id, .. }) = &decorator.expression { - if id == "classmethod" || id == "staticmethod" { + if &**id == "classmethod" || &**id == "staticmethod" { return; } } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/function_uses_loop_variable.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/function_uses_loop_variable.rs index 097be0fe2a..ca221deb56 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/function_uses_loop_variable.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/function_uses_loop_variable.rs @@ -131,7 +131,7 @@ impl<'a> Visitor<'a> for SuspiciousVariablesVisitor<'a> { }) => { match func.as_ref() { Expr::Name(ast::ExprName { id, .. }) => { - if matches!(id.as_str(), "filter" | "reduce" | "map") { + if matches!(&**id, "filter" | "reduce" | "map") { for arg in arguments.args.iter() { if arg.is_lambda_expr() { self.safe_functions.push(arg); @@ -142,7 +142,7 @@ impl<'a> Visitor<'a> for SuspiciousVariablesVisitor<'a> { Expr::Attribute(ast::ExprAttribute { value, attr, .. }) => { if attr == "reduce" { if let Expr::Name(ast::ExprName { id, .. }) = value.as_ref() { - if id == "functools" { + if &**id == "functools" { for arg in arguments.args.iter() { if arg.is_lambda_expr() { self.safe_functions.push(arg); @@ -209,7 +209,7 @@ impl<'a> Visitor<'a> for NamesFromAssignmentsVisitor<'a> { fn visit_expr(&mut self, expr: &'a Expr) { match expr { Expr::Name(ast::ExprName { id, .. }) => { - self.names.push(id.as_str()); + self.names.push(id); } Expr::Starred(ast::ExprStarred { value, .. }) => { self.visit_expr(value); @@ -303,7 +303,7 @@ pub(crate) fn function_uses_loop_variable(checker: &mut Checker, node: &Node) { // If a variable was used in a function or lambda body, and assigned in the // loop, flag it. for name in suspicious_variables { - if reassigned_in_loop.contains(&name.id.as_str()) { + if reassigned_in_loop.contains(&&*name.id) { if !checker.flake8_bugbear_seen.contains(&name.range()) { checker.flake8_bugbear_seen.push(name.range()); checker.diagnostics.push(Diagnostic::new( diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/getattr_with_constant.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/getattr_with_constant.rs index 9ef089807f..b3d9d13816 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/getattr_with_constant.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/getattr_with_constant.rs @@ -57,7 +57,7 @@ pub(crate) fn getattr_with_constant( let Expr::Name(ast::ExprName { id, .. }) = func else { return; }; - if id != "getattr" { + if &**id != "getattr" { return; } let [obj, arg] = args else { diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/raise_without_from_inside_except.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/raise_without_from_inside_except.rs index 7af198e177..83a0299bd3 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/raise_without_from_inside_except.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/raise_without_from_inside_except.rs @@ -87,7 +87,7 @@ pub(crate) fn raise_without_from_inside_except( if let Some(name) = name { if exc .as_name_expr() - .is_some_and(|ast::ExprName { id, .. }| name == id) + .is_some_and(|ast::ExprName { id, .. }| &**id == name) { continue; } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/reuse_of_groupby_generator.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/reuse_of_groupby_generator.rs index 3bc93c22eb..caf18dc89c 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/reuse_of_groupby_generator.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/reuse_of_groupby_generator.rs @@ -83,7 +83,7 @@ impl<'a> GroupNameFinder<'a> { fn name_matches(&self, expr: &Expr) -> bool { if let Expr::Name(ast::ExprName { id, .. }) = expr { - id == self.group_name + &**id == self.group_name } else { false } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/setattr_with_constant.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/setattr_with_constant.rs index e31d0cdc1a..721ef6daf8 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/setattr_with_constant.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/setattr_with_constant.rs @@ -71,7 +71,7 @@ pub(crate) fn setattr_with_constant( let Expr::Name(ast::ExprName { id, .. }) = func else { return; }; - if id != "setattr" { + if &**id != "setattr" { return; } let [obj, name, value] = args else { diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/static_key_dict_comprehension.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/static_key_dict_comprehension.rs index 1da5864e09..4a91519229 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/static_key_dict_comprehension.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/static_key_dict_comprehension.rs @@ -73,7 +73,7 @@ pub(crate) fn static_key_dict_comprehension(checker: &mut Checker, dict_comp: &a fn is_constant(key: &Expr, names: &FxHashMap<&str, &ast::ExprName>) -> bool { match key { Expr::Tuple(ast::ExprTuple { elts, .. }) => elts.iter().all(|elt| is_constant(elt, names)), - Expr::Name(ast::ExprName { id, .. }) => !names.contains_key(id.as_str()), + Expr::Name(ast::ExprName { id, .. }) => !names.contains_key(&**id), Expr::Attribute(ast::ExprAttribute { value, .. }) => is_constant(value, names), Expr::Subscript(ast::ExprSubscript { value, slice, .. }) => { is_constant(value, names) && is_constant(slice, names) diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/unintentional_type_annotation.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/unintentional_type_annotation.rs index 69f8c5505d..a742e3d122 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/unintentional_type_annotation.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/unintentional_type_annotation.rs @@ -54,7 +54,7 @@ pub(crate) fn unintentional_type_annotation( } Expr::Attribute(ast::ExprAttribute { value, .. }) => { if let Expr::Name(ast::ExprName { id, .. }) = value.as_ref() { - if id != "self" { + if &**id != "self" { checker .diagnostics .push(Diagnostic::new(UnintentionalTypeAnnotation, stmt.range())); diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/unreliable_callable_check.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/unreliable_callable_check.rs index a66671048a..05032c67dc 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/unreliable_callable_check.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/unreliable_callable_check.rs @@ -61,7 +61,7 @@ pub(crate) fn unreliable_callable_check( let Expr::Name(ast::ExprName { id, .. }) = func else { return; }; - if !matches!(id.as_str(), "hasattr" | "getattr") { + if !matches!(&**id, "hasattr" | "getattr") { return; } let [obj, attr, ..] = args else { @@ -75,7 +75,7 @@ pub(crate) fn unreliable_callable_check( } let mut diagnostic = Diagnostic::new(UnreliableCallableCheck, expr.range()); - if id == "hasattr" { + if &**id == "hasattr" { if checker.semantic().is_builtin("callable") { diagnostic.set_fix(Fix::safe_edit(Edit::range_replacement( format!("callable({})", checker.locator().slice(obj)), diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/zip_without_explicit_strict.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/zip_without_explicit_strict.rs index 6a58aa7e89..bf9b7b3731 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/zip_without_explicit_strict.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/zip_without_explicit_strict.rs @@ -53,7 +53,7 @@ impl AlwaysFixableViolation for ZipWithoutExplicitStrict { /// B905 pub(crate) fn zip_without_explicit_strict(checker: &mut Checker, call: &ast::ExprCall) { if let Expr::Name(ast::ExprName { id, .. }) = call.func.as_ref() { - if id == "zip" + if &**id == "zip" && checker.semantic().is_builtin("zip") && call.arguments.find_keyword("strict").is_none() && !call diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/helpers.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/helpers.rs index f22a8dd908..49aa2da5ef 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/helpers.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/helpers.rs @@ -13,7 +13,7 @@ pub(super) fn exactly_one_argument_with_matching_function<'a>( return None; } let func = func.as_name_expr()?; - if func.id != name { + if &*func.id != name { return None; } Some(arg) @@ -24,7 +24,7 @@ pub(super) fn first_argument_with_matching_function<'a>( func: &Expr, args: &'a [Expr], ) -> Option<&'a Expr> { - if func.as_name_expr().is_some_and(|func| func.id == name) { + if func.as_name_expr().is_some_and(|func| &*func.id == name) { args.first() } else { None diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_call_around_sorted.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_call_around_sorted.rs index 36d4bc1148..96867d27e8 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_call_around_sorted.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_call_around_sorted.rs @@ -66,7 +66,7 @@ pub(crate) fn unnecessary_call_around_sorted( let Some(outer) = func.as_name_expr() else { return; }; - if !matches!(outer.id.as_str(), "list" | "reversed") { + if !matches!(&*outer.id, "list" | "reversed") { return; } let Some(arg) = args.first() else { @@ -78,7 +78,7 @@ pub(crate) fn unnecessary_call_around_sorted( let Some(inner) = func.as_name_expr() else { return; }; - if inner.id != "sorted" { + if &*inner.id != "sorted" { return; } if !checker.semantic().is_builtin(&inner.id) || !checker.semantic().is_builtin(&outer.id) { @@ -93,7 +93,7 @@ pub(crate) fn unnecessary_call_around_sorted( diagnostic.try_set_fix(|| { Ok(Fix::applicable_edit( fixes::fix_unnecessary_call_around_sorted(expr, checker.locator(), checker.stylist())?, - if outer.id == "reversed" { + if &*outer.id == "reversed" { Applicability::Unsafe } else { Applicability::Safe diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_collection_call.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_collection_call.rs index f676cb598b..05d6ec35eb 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_collection_call.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_collection_call.rs @@ -68,7 +68,7 @@ pub(crate) fn unnecessary_collection_call( let Some(func) = call.func.as_name_expr() else { return; }; - let collection = match func.id.as_str() { + let collection = match &*func.id { "dict" if call.arguments.keywords.is_empty() || (!settings.allow_dict_calls_with_keyword_arguments @@ -87,7 +87,7 @@ pub(crate) fn unnecessary_collection_call( } _ => return, }; - if !checker.semantic().is_builtin(func.id.as_str()) { + if !checker.semantic().is_builtin(&func.id) { return; } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension_any_all.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension_any_all.rs index a713059f3d..0dc0a8b7f8 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension_any_all.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension_any_all.rs @@ -75,7 +75,7 @@ pub(crate) fn unnecessary_comprehension_any_all( let Expr::Name(ast::ExprName { id, .. }) = func else { return; }; - if !matches!(id.as_str(), "all" | "any") { + if !matches!(&**id, "all" | "any") { return; } let [arg] = args else { diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_double_cast_or_process.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_double_cast_or_process.rs index 10ee56f908..59569f61a8 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_double_cast_or_process.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_double_cast_or_process.rs @@ -77,10 +77,7 @@ pub(crate) fn unnecessary_double_cast_or_process( let Some(outer) = func.as_name_expr() else { return; }; - if !matches!( - outer.id.as_str(), - "list" | "tuple" | "set" | "reversed" | "sorted" - ) { + if !matches!(&*outer.id, "list" | "tuple" | "set" | "reversed" | "sorted") { return; } let Some(arg) = args.first() else { @@ -105,7 +102,7 @@ pub(crate) fn unnecessary_double_cast_or_process( // Avoid collapsing nested `sorted` calls with non-identical keyword arguments // (i.e., `key`, `reverse`). - if inner.id == "sorted" && outer.id == "sorted" { + if &*inner.id == "sorted" && &*outer.id == "sorted" { if inner_kw.len() != outer_kw.len() { return; } @@ -122,7 +119,7 @@ pub(crate) fn unnecessary_double_cast_or_process( // Ex) `list(tuple(...))` // Ex) `set(set(...))` if matches!( - (outer.id.as_str(), inner.id.as_str()), + (&*outer.id, &*inner.id), ("set" | "sorted", "list" | "tuple" | "reversed" | "sorted") | ("set", "set") | ("list" | "tuple", "list" | "tuple") diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_map.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_map.rs index 55dc48000b..c7dac3ea43 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_map.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_map.rs @@ -77,7 +77,7 @@ pub(crate) fn unnecessary_map( return; }; - let object_type = match func.id.as_str() { + let object_type = match &*func.id { "map" => ObjectType::Generator, "list" => ObjectType::List, "set" => ObjectType::Set, @@ -95,7 +95,7 @@ pub(crate) fn unnecessary_map( if parent .and_then(Expr::as_call_expr) .and_then(|call| call.func.as_name_expr()) - .is_some_and(|name| matches!(name.id.as_str(), "list" | "set" | "dict")) + .is_some_and(|name| matches!(&*name.id, "list" | "set" | "dict")) { return; } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_subscript_reversal.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_subscript_reversal.rs index baabf909b0..29b599303e 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_subscript_reversal.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_subscript_reversal.rs @@ -47,7 +47,7 @@ pub(crate) fn unnecessary_subscript_reversal(checker: &mut Checker, call: &ast:: let Some(func) = call.func.as_name_expr() else { return; }; - if !matches!(func.id.as_str(), "reversed" | "set" | "sorted") { + if !matches!(&*func.id, "reversed" | "set" | "sorted") { return; } if !checker.semantic().is_builtin(&func.id) { diff --git a/crates/ruff_linter/src/rules/flake8_django/rules/all_with_model_form.rs b/crates/ruff_linter/src/rules/flake8_django/rules/all_with_model_form.rs index cb942cf6ae..747445e93b 100644 --- a/crates/ruff_linter/src/rules/flake8_django/rules/all_with_model_form.rs +++ b/crates/ruff_linter/src/rules/flake8_django/rules/all_with_model_form.rs @@ -72,7 +72,7 @@ pub(crate) fn all_with_model_form(checker: &mut Checker, class_def: &ast::StmtCl let Expr::Name(ast::ExprName { id, .. }) = target else { continue; }; - if id != "fields" { + if &**id != "fields" { continue; } match value.as_ref() { diff --git a/crates/ruff_linter/src/rules/flake8_django/rules/exclude_with_model_form.rs b/crates/ruff_linter/src/rules/flake8_django/rules/exclude_with_model_form.rs index 3e1dd6281f..8884b777ee 100644 --- a/crates/ruff_linter/src/rules/flake8_django/rules/exclude_with_model_form.rs +++ b/crates/ruff_linter/src/rules/flake8_django/rules/exclude_with_model_form.rs @@ -70,7 +70,7 @@ pub(crate) fn exclude_with_model_form(checker: &mut Checker, class_def: &ast::St let Expr::Name(ast::ExprName { id, .. }) = target else { continue; }; - if id == "exclude" { + if &**id == "exclude" { checker .diagnostics .push(Diagnostic::new(DjangoExcludeWithModelForm, target.range())); diff --git a/crates/ruff_linter/src/rules/flake8_django/rules/model_without_dunder_str.rs b/crates/ruff_linter/src/rules/flake8_django/rules/model_without_dunder_str.rs index 47e468414f..c30a038eef 100644 --- a/crates/ruff_linter/src/rules/flake8_django/rules/model_without_dunder_str.rs +++ b/crates/ruff_linter/src/rules/flake8_django/rules/model_without_dunder_str.rs @@ -106,7 +106,7 @@ fn is_model_abstract(class_def: &ast::StmtClassDef) -> bool { let Expr::Name(ast::ExprName { id, .. }) = target else { continue; }; - if id != "abstract" { + if &**id != "abstract" { continue; } if !is_const_true(value) { diff --git a/crates/ruff_linter/src/rules/flake8_django/rules/unordered_body_content_in_model.rs b/crates/ruff_linter/src/rules/flake8_django/rules/unordered_body_content_in_model.rs index 980cdf00d6..37d0fef24a 100644 --- a/crates/ruff_linter/src/rules/flake8_django/rules/unordered_body_content_in_model.rs +++ b/crates/ruff_linter/src/rules/flake8_django/rules/unordered_body_content_in_model.rs @@ -165,7 +165,7 @@ fn get_element_type(element: &Stmt, semantic: &SemanticModel) -> Option bool { if let Expr::Name(ast::ExprName { id, .. }) = func { - functions_names.contains(id) + functions_names.iter().any(|name| name == &**id) } else { false } diff --git a/crates/ruff_linter/src/rules/flake8_pie/rules/duplicate_class_field_definition.rs b/crates/ruff_linter/src/rules/flake8_pie/rules/duplicate_class_field_definition.rs index e50af0ec2f..0a78cc0e3f 100644 --- a/crates/ruff_linter/src/rules/flake8_pie/rules/duplicate_class_field_definition.rs +++ b/crates/ruff_linter/src/rules/flake8_pie/rules/duplicate_class_field_definition.rs @@ -93,7 +93,7 @@ pub(crate) fn duplicate_class_field_definition(checker: &mut Checker, body: &[St _ => continue, } - if !seen_targets.insert(target.id.as_str()) { + if !seen_targets.insert(&*target.id) { let mut diagnostic = Diagnostic::new( DuplicateClassFieldDefinition { name: target.id.to_string(), diff --git a/crates/ruff_linter/src/rules/flake8_pie/rules/multiple_starts_ends_with.rs b/crates/ruff_linter/src/rules/flake8_pie/rules/multiple_starts_ends_with.rs index b3031ff97e..ffd4379a3a 100644 --- a/crates/ruff_linter/src/rules/flake8_pie/rules/multiple_starts_ends_with.rs +++ b/crates/ruff_linter/src/rules/flake8_pie/rules/multiple_starts_ends_with.rs @@ -120,7 +120,7 @@ pub(crate) fn multiple_starts_ends_with(checker: &mut Checker, expr: &Expr) { } duplicates - .entry((attr.as_str(), arg_name.as_str())) + .entry((&**attr, &**arg_name)) .or_insert_with(Vec::new) .push(index); } @@ -229,7 +229,7 @@ fn is_bound_to_tuple(arg: &Expr, semantic: &SemanticModel) -> bool { return false; }; - let Some(binding_id) = semantic.lookup_symbol(id.as_str()) else { + let Some(binding_id) = semantic.lookup_symbol(id) else { return false; }; diff --git a/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_range_start.rs b/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_range_start.rs index e158b75ebe..52f9927ceb 100644 --- a/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_range_start.rs +++ b/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_range_start.rs @@ -47,7 +47,7 @@ pub(crate) fn unnecessary_range_start(checker: &mut Checker, call: &ast::ExprCal let Expr::Name(ast::ExprName { id, .. }) = call.func.as_ref() else { return; }; - if id != "range" { + if &**id != "range" { return; }; if !checker.semantic().is_builtin("range") { diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/custom_type_var_return_type.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/custom_type_var_return_type.rs index 31f5dc952b..fffd5655d5 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/custom_type_var_return_type.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/custom_type_var_return_type.rs @@ -142,7 +142,7 @@ fn class_method( // Don't error if the first argument is annotated with typing.Type[T]. // These are edge cases, and it's hard to give good error messages for them. - if value.id != "type" { + if &*value.id != "type" { return false; }; diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/non_self_return_type.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/non_self_return_type.rs index d0766353df..fe2c5f1116 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/non_self_return_type.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/non_self_return_type.rs @@ -264,7 +264,7 @@ fn is_name(expr: &Expr, name: &str) -> bool { let Expr::Name(ast::ExprName { id, .. }) = expr else { return false; }; - id.as_str() == name + &**id == name } /// Return `true` if the given expression resolves to `typing.Self`. diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_literal_union.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_literal_union.rs index 57f08abb05..0115d501ea 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_literal_union.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_literal_union.rs @@ -132,7 +132,7 @@ impl fmt::Display for ExprType { /// `str`, `bytes`, or `complex`). fn match_builtin_type(expr: &Expr, semantic: &SemanticModel) -> Option { let name = expr.as_name_expr()?; - let result = match name.id.as_str() { + let result = match &*name.id { "int" => ExprType::Int, "bool" => ExprType::Bool, "str" => ExprType::Str, @@ -141,7 +141,7 @@ fn match_builtin_type(expr: &Expr, semantic: &SemanticModel) -> Option "complex" => ExprType::Complex, _ => return None, }; - if !semantic.is_builtin(name.id.as_str()) { + if !semantic.is_builtin(&name.id) { return None; } Some(result) diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/simple_defaults.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/simple_defaults.rs index 392a07be8f..f5fdb831dc 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/simple_defaults.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/simple_defaults.rs @@ -450,7 +450,7 @@ fn is_type_var_like_call(expr: &Expr, semantic: &SemanticModel) -> bool { /// `__all__`). fn is_special_assignment(target: &Expr, semantic: &SemanticModel) -> bool { if let Expr::Name(ast::ExprName { id, .. }) = target { - match id.as_str() { + match &**id { "__all__" => semantic.current_scope().kind.is_module(), "__match_args__" | "__slots__" => semantic.current_scope().kind.is_class(), _ => false, diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/unnecessary_type_union.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/unnecessary_type_union.rs index caf00e7a21..0872118842 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/unnecessary_type_union.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/unnecessary_type_union.rs @@ -122,7 +122,7 @@ pub(crate) fn unnecessary_type_union<'a>(checker: &mut Checker, union: &'a Expr) .into_iter() .map(|type_member| { Expr::Name(ast::ExprName { - id: type_member, + id: type_member.into_boxed_str(), ctx: ExprContext::Load, range: TextRange::default(), }) diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/unsupported_method_call_on_all.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/unsupported_method_call_on_all.rs index 5183fa580e..5c64807e3f 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/unsupported_method_call_on_all.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/unsupported_method_call_on_all.rs @@ -47,7 +47,7 @@ pub(crate) fn unsupported_method_call_on_all(checker: &mut Checker, func: &Expr) let Expr::Name(ast::ExprName { id, .. }) = value.as_ref() else { return; }; - if id.as_str() != "__all__" { + if &**id != "__all__" { return; } if !is_unsupported_method(attr.as_str()) { diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/assertion.rs b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/assertion.rs index 9534c61396..4939953df8 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/assertion.rs +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/assertion.rs @@ -242,7 +242,7 @@ where match expr { Expr::Name(ast::ExprName { id, .. }) => { if let Some(current_assert) = self.current_assert { - if id.as_str() == self.exception_name { + if &**id == self.exception_name { self.errors.push(Diagnostic::new( PytestAssertInExcept { name: id.to_string(), @@ -419,7 +419,7 @@ fn to_pytest_raises_args<'a>( if kwarg .arg .as_ref() - .is_some_and(|id| id.as_str() == "expected_exception") => + .is_some_and(|id| &**id == "expected_exception") => { Cow::Borrowed(checker.locator().slice(kwarg.value.range())) } @@ -452,11 +452,11 @@ fn to_pytest_raises_args<'a>( if kwarg1 .arg .as_ref() - .is_some_and(|id| id.as_str() == "expected_exception") + .is_some_and(|id| &**id == "expected_exception") && kwarg2 .arg .as_ref() - .is_some_and(|id| id.as_str() == "expected_regex") => + .is_some_and(|id| &**id == "expected_regex") => { Cow::Owned(format!( "{}, match={}", @@ -469,11 +469,11 @@ fn to_pytest_raises_args<'a>( if kwarg1 .arg .as_ref() - .is_some_and(|id| id.as_str() == "expected_regex") + .is_some_and(|id| &**id == "expected_regex") && kwarg2 .arg .as_ref() - .is_some_and(|id| id.as_str() == "expected_exception") => + .is_some_and(|id| &**id == "expected_exception") => { Cow::Owned(format!( "{}, match={}", diff --git a/crates/ruff_linter/src/rules/flake8_return/rules/function.rs b/crates/ruff_linter/src/rules/flake8_return/rules/function.rs index c7d8764c06..2d4added64 100644 --- a/crates/ruff_linter/src/rules/flake8_return/rules/function.rs +++ b/crates/ruff_linter/src/rules/flake8_return/rules/function.rs @@ -564,7 +564,7 @@ fn unnecessary_assign(checker: &mut Checker, stack: &Stack) { continue; } - if stack.non_locals.contains(assigned_id.as_str()) { + if stack.non_locals.contains(&**assigned_id) { continue; } diff --git a/crates/ruff_linter/src/rules/flake8_self/rules/private_member_access.rs b/crates/ruff_linter/src/rules/flake8_self/rules/private_member_access.rs index ccabe9ba32..0b5dd2b878 100644 --- a/crates/ruff_linter/src/rules/flake8_self/rules/private_member_access.rs +++ b/crates/ruff_linter/src/rules/flake8_self/rules/private_member_access.rs @@ -77,7 +77,8 @@ pub(crate) fn private_member_access(checker: &mut Checker, expr: &Expr) { .settings .flake8_self .ignore_names - .contains(attr.as_ref()) + .iter() + .any(|name| name == attr.as_str()) { return; } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_bool_op.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_bool_op.rs index 5256d69e2f..1a8b2b35fc 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_bool_op.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_bool_op.rs @@ -323,7 +323,7 @@ fn isinstance_target<'a>(call: &'a Expr, semantic: &'a SemanticModel) -> Option< let Expr::Name(ast::ExprName { id: func_name, .. }) = func.as_ref() else { return None; }; - if func_name != "isinstance" { + if &**func_name != "isinstance" { return None; } if !semantic.is_builtin("isinstance") { diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_expr.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_expr.rs index 669be14149..095c01fbc5 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_expr.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_expr.rs @@ -193,7 +193,7 @@ fn check_os_environ_subscript(checker: &mut Checker, expr: &Expr) { let Expr::Name(ast::ExprName { id, .. }) = attr_value.as_ref() else { return; }; - if id != "os" || attr != "environ" { + if &**id != "os" || attr != "environ" { return; } let Expr::StringLiteral(ast::ExprStringLiteral { value: env_var, .. }) = slice.as_ref() else { diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/collapsible_if.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/collapsible_if.rs index 8fb4f17fae..a13c3b6ab2 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/collapsible_if.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/collapsible_if.rs @@ -252,7 +252,7 @@ fn is_main_check(expr: &Expr) -> bool { }) = expr { if let Expr::Name(ast::ExprName { id, .. }) = left.as_ref() { - if id == "__name__" { + if &**id == "__name__" { if let [Expr::StringLiteral(ast::ExprStringLiteral { value, .. })] = &**comparators { if value == "__main__" { diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/key_in_dict.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/key_in_dict.rs index 7ebcd9f9f3..8931f7e6ca 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/key_in_dict.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/key_in_dict.rs @@ -3,7 +3,7 @@ use ruff_diagnostics::{Applicability, Edit}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::parenthesize::parenthesized_range; use ruff_python_ast::AnyNodeRef; -use ruff_python_ast::{self as ast, Arguments, CmpOp, Comprehension, Expr}; +use ruff_python_ast::{self as ast, CmpOp, Comprehension, Expr}; use ruff_python_semantic::analyze::typing; use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer}; use ruff_text_size::{Ranged, TextRange}; @@ -67,20 +67,21 @@ fn key_in_dict( ) { let Expr::Call(ast::ExprCall { func, - arguments: Arguments { args, keywords, .. }, + arguments, range: _, }) = &right else { return; }; - if !(args.is_empty() && keywords.is_empty()) { + + if !arguments.is_empty() { return; } let Expr::Attribute(ast::ExprAttribute { attr, value, .. }) = func.as_ref() else { return; }; - if attr != "keys" { + if &**attr != "keys" { return; } @@ -89,10 +90,7 @@ fn key_in_dict( // def __contains__(self, key: object) -> bool: // return key in self.keys() // ``` - if value - .as_name_expr() - .is_some_and(|name| matches!(name.id.as_str(), "self")) - { + if value.as_name_expr().is_some_and(|name| &*name.id == "self") { return; } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/open_file_with_context_handler.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/open_file_with_context_handler.rs index 49e7826217..953bc92e01 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/open_file_with_context_handler.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/open_file_with_context_handler.rs @@ -121,7 +121,7 @@ fn is_open(checker: &mut Checker, func: &Expr) -> bool { } // open(...) Expr::Name(ast::ExprName { id, .. }) => { - id.as_str() == "open" && checker.semantic().is_builtin("open") + &**id == "open" && checker.semantic().is_builtin("open") } _ => false, } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/zip_dict_keys_and_values.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/zip_dict_keys_and_values.rs index 6867e6644f..37e9dafbf7 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/zip_dict_keys_and_values.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/zip_dict_keys_and_values.rs @@ -72,7 +72,7 @@ pub(crate) fn zip_dict_keys_and_values(checker: &mut Checker, expr: &ExprCall) { }] if name.as_str() == "strict" => {} _ => return, }; - if matches!(func.as_ref(), Expr::Name(ExprName { id, .. }) if id != "zip") { + if matches!(func.as_ref(), Expr::Name(ExprName { id, .. }) if &**id != "zip") { return; } let [arg1, arg2] = &args[..] else { diff --git a/crates/ruff_linter/src/rules/flake8_slots/rules/helpers.rs b/crates/ruff_linter/src/rules/flake8_slots/rules/helpers.rs index f949e3a278..442d068e67 100644 --- a/crates/ruff_linter/src/rules/flake8_slots/rules/helpers.rs +++ b/crates/ruff_linter/src/rules/flake8_slots/rules/helpers.rs @@ -7,7 +7,7 @@ pub(super) fn has_slots(body: &[Stmt]) -> bool { Stmt::Assign(ast::StmtAssign { targets, .. }) => { for target in targets { if let Expr::Name(ast::ExprName { id, .. }) = target { - if id.as_str() == "__slots__" { + if &**id == "__slots__" { return true; } } @@ -15,7 +15,7 @@ pub(super) fn has_slots(body: &[Stmt]) -> bool { } Stmt::AnnAssign(ast::StmtAnnAssign { target, .. }) => { if let Expr::Name(ast::ExprName { id, .. }) = target.as_ref() { - if id.as_str() == "__slots__" { + if &**id == "__slots__" { return true; } } diff --git a/crates/ruff_linter/src/rules/flake8_unused_arguments/helpers.rs b/crates/ruff_linter/src/rules/flake8_unused_arguments/helpers.rs index 4a1b6a3a8f..29cace9b3c 100644 --- a/crates/ruff_linter/src/rules/flake8_unused_arguments/helpers.rs +++ b/crates/ruff_linter/src/rules/flake8_unused_arguments/helpers.rs @@ -13,11 +13,11 @@ fn is_empty_stmt(stmt: &Stmt) -> bool { if let Some(exc) = exc { match exc.as_ref() { Expr::Name(ast::ExprName { id, .. }) => { - return id == "NotImplementedError" || id == "NotImplemented"; + return &**id == "NotImplementedError" || &**id == "NotImplemented"; } Expr::Call(ast::ExprCall { func, .. }) => { if let Expr::Name(ast::ExprName { id, .. }) = func.as_ref() { - return id == "NotImplementedError" || id == "NotImplemented"; + return &**id == "NotImplementedError" || &**id == "NotImplemented"; } } _ => {} diff --git a/crates/ruff_linter/src/rules/pandas_vet/helpers.rs b/crates/ruff_linter/src/rules/pandas_vet/helpers.rs index 85ba34ec77..18f2f3d14b 100644 --- a/crates/ruff_linter/src/rules/pandas_vet/helpers.rs +++ b/crates/ruff_linter/src/rules/pandas_vet/helpers.rs @@ -37,7 +37,7 @@ pub(super) fn test_expression(expr: &Expr, semantic: &SemanticModel) -> Resoluti match &semantic.binding(id).kind { BindingKind::Argument => { // Avoid, e.g., `self.values`. - if matches!(name.id.as_str(), "self" | "cls") { + if matches!(&*name.id, "self" | "cls") { Resolution::IrrelevantBinding } else { Resolution::RelevantLocal diff --git a/crates/ruff_linter/src/rules/pandas_vet/rules/assignment_to_df.rs b/crates/ruff_linter/src/rules/pandas_vet/rules/assignment_to_df.rs index 20b81d76e7..3b974381e7 100644 --- a/crates/ruff_linter/src/rules/pandas_vet/rules/assignment_to_df.rs +++ b/crates/ruff_linter/src/rules/pandas_vet/rules/assignment_to_df.rs @@ -45,7 +45,7 @@ pub(crate) fn assignment_to_df(targets: &[Expr]) -> Option { let Expr::Name(ast::ExprName { id, .. }) = target else { return None; }; - if id != "df" { + if &**id != "df" { return None; } Some(Diagnostic::new(PandasDfVariableName, target.range())) diff --git a/crates/ruff_linter/src/rules/pandas_vet/rules/pd_merge.rs b/crates/ruff_linter/src/rules/pandas_vet/rules/pd_merge.rs index 3c2c0eb381..acd5364d7d 100644 --- a/crates/ruff_linter/src/rules/pandas_vet/rules/pd_merge.rs +++ b/crates/ruff_linter/src/rules/pandas_vet/rules/pd_merge.rs @@ -58,7 +58,7 @@ impl Violation for PandasUseOfPdMerge { pub(crate) fn use_of_pd_merge(checker: &mut Checker, func: &Expr) { if let Expr::Attribute(ast::ExprAttribute { attr, value, .. }) = func { if let Expr::Name(ast::ExprName { id, .. }) = value.as_ref() { - if id == "pd" && attr == "merge" { + if &**id == "pd" && attr == "merge" { checker .diagnostics .push(Diagnostic::new(PandasUseOfPdMerge, func.range())); diff --git a/crates/ruff_linter/src/rules/pep8_naming/rules/error_suffix_on_exception_name.rs b/crates/ruff_linter/src/rules/pep8_naming/rules/error_suffix_on_exception_name.rs index 0b3cf39251..c42387262b 100644 --- a/crates/ruff_linter/src/rules/pep8_naming/rules/error_suffix_on_exception_name.rs +++ b/crates/ruff_linter/src/rules/pep8_naming/rules/error_suffix_on_exception_name.rs @@ -56,7 +56,7 @@ pub(crate) fn error_suffix_on_exception_name( if !arguments.is_some_and(|arguments| { arguments.args.iter().any(|base| { if let Expr::Name(ast::ExprName { id, .. }) = &base { - id == "Exception" || id.ends_with("Error") + &**id == "Exception" || id.ends_with("Error") } else { false } diff --git a/crates/ruff_linter/src/rules/perflint/rules/unnecessary_list_cast.rs b/crates/ruff_linter/src/rules/perflint/rules/unnecessary_list_cast.rs index 7ff1d544b3..836ab4c2d8 100644 --- a/crates/ruff_linter/src/rules/perflint/rules/unnecessary_list_cast.rs +++ b/crates/ruff_linter/src/rules/perflint/rules/unnecessary_list_cast.rs @@ -72,7 +72,7 @@ pub(crate) fn unnecessary_list_cast(checker: &mut Checker, iter: &Expr, body: &[ return; }; - if !(id == "list" && checker.semantic().is_builtin("list")) { + if &**id != "list" || !checker.semantic().is_builtin("list") { return; } @@ -142,7 +142,7 @@ fn match_append(stmt: &Stmt, id: &str) -> bool { let Some(ast::ExprName { id: target_id, .. }) = value.as_name_expr() else { return false; }; - target_id == id + &**target_id == id } /// Generate a [`Fix`] to remove a `list` cast from an expression. diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/type_comparison.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/type_comparison.rs index 57de972c23..0d582826dd 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/type_comparison.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/type_comparison.rs @@ -80,7 +80,7 @@ fn deprecated_type_comparison(checker: &mut Checker, compare: &ast::ExprCompare) continue; }; - if !(id == "type" && checker.semantic().is_builtin("type")) { + if &**id != "type" || !checker.semantic().is_builtin("type") { continue; } @@ -94,7 +94,7 @@ fn deprecated_type_comparison(checker: &mut Checker, compare: &ast::ExprCompare) continue; }; - if id == "type" && checker.semantic().is_builtin("type") { + if &**id == "type" && checker.semantic().is_builtin("type") { // Allow comparison for types which are not obvious. if arguments .args @@ -128,7 +128,7 @@ fn deprecated_type_comparison(checker: &mut Checker, compare: &ast::ExprCompare) Expr::Name(ast::ExprName { id, .. }) => { // Ex) `type(obj) is int` if matches!( - id.as_str(), + &**id, "int" | "str" | "float" @@ -191,7 +191,7 @@ fn is_type(expr: &Expr, semantic: &SemanticModel) -> bool { return false; }; - if !(id == "type" && semantic.is_builtin("type")) { + if &**id != "type" || !semantic.is_builtin("type") { return false; }; @@ -204,7 +204,7 @@ fn is_type(expr: &Expr, semantic: &SemanticModel) -> bool { Expr::Name(ast::ExprName { id, .. }) => { // Ex) `type(obj) == int` matches!( - id.as_str(), + &**id, "bool" | "bytearray" | "bytes" diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/invalid_print_syntax.rs b/crates/ruff_linter/src/rules/pyflakes/rules/invalid_print_syntax.rs index 74acdca403..f59a5dfaf0 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/invalid_print_syntax.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/invalid_print_syntax.rs @@ -61,7 +61,7 @@ pub(crate) fn invalid_print_syntax(checker: &mut Checker, left: &Expr) { let Expr::Name(ast::ExprName { id, .. }) = &left else { return; }; - if id != "print" { + if &**id != "print" { return; } if !checker.semantic().is_builtin("print") { diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/raise_not_implemented.rs b/crates/ruff_linter/src/rules/pyflakes/rules/raise_not_implemented.rs index 3a48fe902f..b7dcc51535 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/raise_not_implemented.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/raise_not_implemented.rs @@ -54,13 +54,13 @@ fn match_not_implemented(expr: &Expr) -> Option<&Expr> { match expr { Expr::Call(ast::ExprCall { func, .. }) => { if let Expr::Name(ast::ExprName { id, .. }) = func.as_ref() { - if id == "NotImplemented" { + if &**id == "NotImplemented" { return Some(func); } } } Expr::Name(ast::ExprName { id, .. }) => { - if id == "NotImplemented" { + if &**id == "NotImplemented" { return Some(expr); } } diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/strings.rs b/crates/ruff_linter/src/rules/pyflakes/rules/strings.rs index e4545e139b..baf620ac45 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/strings.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/strings.rs @@ -747,7 +747,7 @@ pub(crate) fn string_dot_format_extra_named_arguments( let missing: Vec<(usize, &str)> = keywords .enumerate() .filter_map(|(index, keyword)| { - if summary.keywords.contains(keyword.as_ref()) { + if summary.keywords.iter().any(|k| k == keyword.as_str()) { None } else { Some((index, keyword.as_str())) diff --git a/crates/ruff_linter/src/rules/pylint/helpers.rs b/crates/ruff_linter/src/rules/pylint/helpers.rs index 6c41fad31d..0751ded367 100644 --- a/crates/ruff_linter/src/rules/pylint/helpers.rs +++ b/crates/ruff_linter/src/rules/pylint/helpers.rs @@ -122,17 +122,17 @@ impl SequenceIndexVisitor<'_> { // diagnostics. match expr { Expr::Name(ast::ExprName { id, .. }) => { - id == self.sequence_name || id == self.index_name || id == self.value_name + &**id == self.sequence_name || &**id == self.index_name || &**id == self.value_name } Expr::Subscript(ast::ExprSubscript { value, slice, .. }) => { let Expr::Name(ast::ExprName { id, .. }) = value.as_ref() else { return false; }; - if id == self.sequence_name { + if &**id == self.sequence_name { let Expr::Name(ast::ExprName { id, .. }) = slice.as_ref() else { return false; }; - if id == self.index_name { + if &**id == self.index_name { return true; } } @@ -184,11 +184,11 @@ impl<'a> Visitor<'_> for SequenceIndexVisitor<'a> { let Expr::Name(ast::ExprName { id, .. }) = value.as_ref() else { return; }; - if id == self.sequence_name { + if &**id == self.sequence_name { let Expr::Name(ast::ExprName { id, .. }) = slice.as_ref() else { return; }; - if id == self.index_name { + if &**id == self.index_name { self.accesses.push(*range); } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/bad_open_mode.rs b/crates/ruff_linter/src/rules/pylint/rules/bad_open_mode.rs index a5e7f5f325..bb856d6bf9 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/bad_open_mode.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/bad_open_mode.rs @@ -98,7 +98,7 @@ fn is_open(func: &Expr, semantic: &SemanticModel) -> Option { } // Ex) `open(...)` Expr::Name(ast::ExprName { id, .. }) => { - (id.as_str() == "open" && semantic.is_builtin("open")).then_some(Kind::Builtin) + (&**id == "open" && semantic.is_builtin("open")).then_some(Kind::Builtin) } _ => None, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/comparison_with_itself.rs b/crates/ruff_linter/src/rules/pylint/rules/comparison_with_itself.rs index f93a884a9e..c6facede20 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/comparison_with_itself.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/comparison_with_itself.rs @@ -107,7 +107,7 @@ pub(crate) fn comparison_with_itself( // The call must be to pure function, like `id`. if matches!( - left_func.id.as_str(), + &*left_func.id, "id" | "len" | "type" | "int" | "bool" | "str" | "repr" | "bytes" ) && checker.semantic().is_builtin(&left_func.id) { diff --git a/crates/ruff_linter/src/rules/pylint/rules/eq_without_hash.rs b/crates/ruff_linter/src/rules/pylint/rules/eq_without_hash.rs index e8c3b1ad14..c447395db3 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/eq_without_hash.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/eq_without_hash.rs @@ -80,7 +80,7 @@ fn has_eq_without_hash(body: &[Stmt]) -> bool { // // __hash__ = None // ``` - if id == "__hash__" && value.is_none_literal_expr() { + if &**id == "__hash__" && value.is_none_literal_expr() { has_hash = true; } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/nested_min_max.rs b/crates/ruff_linter/src/rules/pylint/rules/nested_min_max.rs index be336eadae..f08ecdec26 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/nested_min_max.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/nested_min_max.rs @@ -71,9 +71,9 @@ impl MinMax { let Expr::Name(ast::ExprName { id, .. }) = func else { return None; }; - if id.as_str() == "min" && semantic.is_builtin("min") { + if &**id == "min" && semantic.is_builtin("min") { Some(MinMax::Min) - } else if id.as_str() == "max" && semantic.is_builtin("max") { + } else if &**id == "max" && semantic.is_builtin("max") { Some(MinMax::Max) } else { None diff --git a/crates/ruff_linter/src/rules/pylint/rules/no_method_decorator.rs b/crates/ruff_linter/src/rules/pylint/rules/no_method_decorator.rs index 60439119fd..beb76c52ad 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/no_method_decorator.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/no_method_decorator.rs @@ -100,7 +100,7 @@ fn get_undecorated_methods( class_def: &ast::StmtClassDef, method_type: &MethodType, ) { - let mut explicit_decorator_calls: HashMap = HashMap::default(); + let mut explicit_decorator_calls: HashMap, TextRange> = HashMap::default(); let (method_name, diagnostic_type): (&str, DiagnosticKind) = match method_type { MethodType::Classmethod => ("classmethod", NoClassmethodDecorator.into()), @@ -115,7 +115,7 @@ fn get_undecorated_methods( }) = value.as_ref() { if let Expr::Name(ast::ExprName { id, .. }) = func.as_ref() { - if id == method_name && checker.semantic().is_builtin(method_name) { + if &**id == method_name && checker.semantic().is_builtin(method_name) { if arguments.args.len() != 1 { continue; } @@ -130,7 +130,7 @@ fn get_undecorated_methods( }; if let Expr::Name(ast::ExprName { id, .. }) = &arguments.args[0] { - if target_name == *id { + if target_name == **id { explicit_decorator_calls.insert(id.clone(), stmt.range()); } }; @@ -158,7 +158,7 @@ fn get_undecorated_methods( // if we find the decorator we're looking for, skip if decorator_list.iter().any(|decorator| { if let Expr::Name(ast::ExprName { id, .. }) = &decorator.expression { - if id == method_name && checker.semantic().is_builtin(method_name) { + if &**id == method_name && checker.semantic().is_builtin(method_name) { return true; } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/non_slot_assignment.rs b/crates/ruff_linter/src/rules/pylint/rules/non_slot_assignment.rs index db74a473bc..128e98baa3 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/non_slot_assignment.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/non_slot_assignment.rs @@ -108,7 +108,7 @@ fn is_attributes_not_in_slots(body: &[Stmt]) -> Vec { continue; }; - if id == "__slots__" { + if &**id == "__slots__" { slots.extend(slots_attributes(value)); } } @@ -123,7 +123,7 @@ fn is_attributes_not_in_slots(body: &[Stmt]) -> Vec { continue; }; - if id == "__slots__" { + if &**id == "__slots__" { slots.extend(slots_attributes(value)); } } @@ -134,7 +134,7 @@ fn is_attributes_not_in_slots(body: &[Stmt]) -> Vec { continue; }; - if id == "__slots__" { + if &**id == "__slots__" { slots.extend(slots_attributes(value)); } } @@ -164,7 +164,7 @@ fn is_attributes_not_in_slots(body: &[Stmt]) -> Vec { let Expr::Name(ast::ExprName { id, .. }) = attribute.value.as_ref() else { continue; }; - if id == "self" && !slots.contains(attribute.attr.as_str()) { + if &**id == "self" && !slots.contains(attribute.attr.as_str()) { assignments.push(AttributeAssignment { name: &attribute.attr, range: attribute.range(), @@ -180,7 +180,7 @@ fn is_attributes_not_in_slots(body: &[Stmt]) -> Vec { let Expr::Name(ast::ExprName { id, .. }) = attribute.value.as_ref() else { continue; }; - if id == "self" && !slots.contains(attribute.attr.as_str()) { + if &**id == "self" && !slots.contains(attribute.attr.as_str()) { assignments.push(AttributeAssignment { name: &attribute.attr, range: attribute.range(), @@ -196,7 +196,7 @@ fn is_attributes_not_in_slots(body: &[Stmt]) -> Vec { let Expr::Name(ast::ExprName { id, .. }) = attribute.value.as_ref() else { continue; }; - if id == "self" && !slots.contains(attribute.attr.as_str()) { + if &**id == "self" && !slots.contains(attribute.attr.as_str()) { assignments.push(AttributeAssignment { name: &attribute.attr, range: attribute.range(), diff --git a/crates/ruff_linter/src/rules/pylint/rules/property_with_parameters.rs b/crates/ruff_linter/src/rules/pylint/rules/property_with_parameters.rs index 42a7db35d2..877bce3204 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/property_with_parameters.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/property_with_parameters.rs @@ -55,7 +55,7 @@ pub(crate) fn property_with_parameters( ) { if !decorator_list .iter() - .any(|decorator| matches!(&decorator.expression, Expr::Name(ast::ExprName { id, .. }) if id == "property")) + .any(|decorator| matches!(&decorator.expression, Expr::Name(ast::ExprName { id, .. }) if &**id =="property")) { return; } diff --git a/crates/ruff_linter/src/rules/pylint/rules/repeated_isinstance_calls.rs b/crates/ruff_linter/src/rules/pylint/rules/repeated_isinstance_calls.rs index 4ede23df5c..eb7167a9d0 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/repeated_isinstance_calls.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/repeated_isinstance_calls.rs @@ -92,7 +92,7 @@ pub(crate) fn repeated_isinstance_calls( else { continue; }; - if !matches!(func.as_ref(), Expr::Name(ast::ExprName { id, .. }) if id == "isinstance") { + if !matches!(func.as_ref(), Expr::Name(ast::ExprName { id, .. }) if &**id =="isinstance") { continue; } let [obj, types] = &args[..] else { diff --git a/crates/ruff_linter/src/rules/pylint/rules/single_string_slots.rs b/crates/ruff_linter/src/rules/pylint/rules/single_string_slots.rs index fac31d5a66..97cc96089a 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/single_string_slots.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/single_string_slots.rs @@ -64,7 +64,7 @@ pub(crate) fn single_string_slots(checker: &mut Checker, class: &StmtClassDef) { Stmt::Assign(ast::StmtAssign { targets, value, .. }) => { for target in targets { if let Expr::Name(ast::ExprName { id, .. }) = target { - if id.as_str() == "__slots__" { + if &**id == "__slots__" { if matches!(value.as_ref(), Expr::StringLiteral(_) | Expr::FString(_)) { checker .diagnostics @@ -80,7 +80,7 @@ pub(crate) fn single_string_slots(checker: &mut Checker, class: &StmtClassDef) { .. }) => { if let Expr::Name(ast::ExprName { id, .. }) = target.as_ref() { - if id.as_str() == "__slots__" { + if &**id == "__slots__" { if matches!(value.as_ref(), Expr::StringLiteral(_) | Expr::FString(_)) { checker .diagnostics diff --git a/crates/ruff_linter/src/rules/pylint/rules/super_without_brackets.rs b/crates/ruff_linter/src/rules/pylint/rules/super_without_brackets.rs index 04b744c002..71ab1a8154 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/super_without_brackets.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/super_without_brackets.rs @@ -68,11 +68,11 @@ pub(crate) fn super_without_brackets(checker: &mut Checker, func: &Expr) { return; }; - if id.as_str() != "super" { + if &**id != "super" { return; } - if !checker.semantic().is_builtin(id.as_str()) { + if !checker.semantic().is_builtin(id) { return; } diff --git a/crates/ruff_linter/src/rules/pylint/rules/sys_exit_alias.rs b/crates/ruff_linter/src/rules/pylint/rules/sys_exit_alias.rs index 894cda0c15..66b2bea137 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/sys_exit_alias.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/sys_exit_alias.rs @@ -62,11 +62,11 @@ pub(crate) fn sys_exit_alias(checker: &mut Checker, func: &Expr) { return; }; - if !matches!(id.as_str(), "exit" | "quit") { + if !matches!(&**id, "exit" | "quit") { return; } - if !checker.semantic().is_builtin(id.as_str()) { + if !checker.semantic().is_builtin(id) { return; } diff --git a/crates/ruff_linter/src/rules/pylint/rules/type_param_name_mismatch.rs b/crates/ruff_linter/src/rules/pylint/rules/type_param_name_mismatch.rs index cad3db6de4..85625cb092 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/type_param_name_mismatch.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/type_param_name_mismatch.rs @@ -83,7 +83,7 @@ pub(crate) fn type_param_name_mismatch(checker: &mut Checker, value: &Expr, targ return; }; - if var_name == param_name { + if &**var_name == param_name { return; } diff --git a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_dict_index_lookup.rs b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_dict_index_lookup.rs index 913279081f..476dc24649 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_dict_index_lookup.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_dict_index_lookup.rs @@ -128,7 +128,7 @@ fn dict_items<'a>( let Expr::Attribute(ast::ExprAttribute { value, attr, .. }) = func.as_ref() else { return None; }; - if attr != "items" { + if &**attr != "items" { return None; } @@ -154,7 +154,7 @@ fn dict_items<'a>( // If either of the variable names are intentionally ignored by naming them `_`, then don't // emit. - if index_name.id == "_" || value_name.id == "_" { + if &*index_name.id == "_" || &*value_name.id == "_" { return None; } diff --git a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_dunder_call.rs b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_dunder_call.rs index c1e10eef8c..8ce90e44b1 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_dunder_call.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_dunder_call.rs @@ -95,7 +95,7 @@ pub(crate) fn unnecessary_dunder_call(checker: &mut Checker, call: &ast::ExprCal if let Expr::Call(ast::ExprCall { func, .. }) = value.as_ref() { if checker.semantic().is_builtin("super") { if let Expr::Name(ast::ExprName { id, .. }) = func.as_ref() { - if id == "super" { + if &**id == "super" { return; } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_lambda.rs b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_lambda.rs index f7bb851e42..b5f5dbb362 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_lambda.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_lambda.rs @@ -135,7 +135,7 @@ pub(crate) fn unnecessary_lambda(checker: &mut Checker, lambda: &ExprLambda) { return; }; - if id.as_str() != kwarg.name.as_str() { + if **id != *kwarg.name { return; } } @@ -157,7 +157,7 @@ pub(crate) fn unnecessary_lambda(checker: &mut Checker, lambda: &ExprLambda) { return; }; - if id.as_str() != vararg.name.as_str() { + if **id != *vararg.name { return; } } @@ -176,7 +176,7 @@ pub(crate) fn unnecessary_lambda(checker: &mut Checker, lambda: &ExprLambda) { let Expr::Name(ast::ExprName { id, .. }) = arg else { return; }; - if id.as_str() != param.name.as_str() { + if **id != *param.name { return; } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_list_index_lookup.rs b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_list_index_lookup.rs index 461a8d56c9..86a3b566d0 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_list_index_lookup.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_list_index_lookup.rs @@ -150,7 +150,7 @@ fn enumerate_items<'a>( // If either of the variable names are intentionally ignored by naming them `_`, then don't // emit. - if index_name.id == "_" || value_name.id == "_" { + if &*index_name.id == "_" || &*value_name.id == "_" { return None; } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs index baf1b4c140..dc61a6a758 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs @@ -190,7 +190,7 @@ fn fields_from_dict_literal(keys: &[Option], values: &[Expr]) -> Option Option> { let ast::ExprName { id, .. } = func.as_name_expr()?; - if id != "dict" { + if &**id != "dict" { return None; } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_unittest_alias.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_unittest_alias.rs index 58250d43a2..8908fccad2 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_unittest_alias.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_unittest_alias.rs @@ -88,7 +88,7 @@ pub(crate) fn deprecated_unittest_alias(checker: &mut Checker, expr: &Expr) { let Expr::Name(ast::ExprName { id, .. }) = value.as_ref() else { return; }; - if id != "self" { + if &**id != "self" { return; } let mut diagnostic = Diagnostic::new( diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/native_literals.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/native_literals.rs index 9e7392bb21..6c05d7b453 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/native_literals.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/native_literals.rs @@ -158,7 +158,7 @@ pub(crate) fn native_literals( return; } - let Ok(literal_type) = LiteralType::from_str(id.as_str()) else { + let Ok(literal_type) = LiteralType::from_str(id) else { return; }; diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/redundant_open_modes.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/redundant_open_modes.rs index 2e9d63766e..b94f79a405 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/redundant_open_modes.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/redundant_open_modes.rs @@ -113,7 +113,7 @@ fn is_open_builtin(func: &Expr, semantic: &SemanticModel) -> bool { let Some(ast::ExprName { id, .. }) = func.as_name_expr() else { return false; }; - id.as_str() == OPEN_FUNC_NAME && semantic.is_builtin(id) + &**id == OPEN_FUNC_NAME && semantic.is_builtin(id) } #[derive(Debug, Copy, Clone)] diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/super_call_with_parameters.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/super_call_with_parameters.rs index a01934676b..f1d60ef6aa 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/super_call_with_parameters.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/super_call_with_parameters.rs @@ -120,7 +120,7 @@ pub(crate) fn super_call_with_parameters(checker: &mut Checker, call: &ast::Expr return; }; - if !(first_arg_id == parent_name.as_str() && second_arg_id == parent_arg.as_str()) { + if **first_arg_id != **parent_name || **second_arg_id != **parent_arg { return; } @@ -137,7 +137,7 @@ pub(crate) fn super_call_with_parameters(checker: &mut Checker, call: &ast::Expr /// Returns `true` if a call is an argumented `super` invocation. fn is_super_call_with_arguments(call: &ast::ExprCall) -> bool { if let Expr::Name(ast::ExprName { id, .. }) = call.func.as_ref() { - id == "super" && !call.arguments.is_empty() + &**id == "super" && !call.arguments.is_empty() } else { false } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep695_type_alias.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep695_type_alias.rs index 29f9039d21..6d86607636 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep695_type_alias.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep695_type_alias.rs @@ -106,7 +106,7 @@ pub(crate) fn non_pep695_type_alias(checker: &mut Checker, stmt: &StmtAnnAssign) // Type variables must be unique; filter while preserving order. let vars = vars .into_iter() - .unique_by(|TypeVar { name, .. }| name.id.as_str()) + .unique_by(|TypeVar { name, .. }| &name.id) .collect::>(); let type_params = if vars.is_empty() { @@ -137,7 +137,12 @@ pub(crate) fn non_pep695_type_alias(checker: &mut Checker, stmt: &StmtAnnAssign) }) }; - let mut diagnostic = Diagnostic::new(NonPEP695TypeAlias { name: name.clone() }, stmt.range()); + let mut diagnostic = Diagnostic::new( + NonPEP695TypeAlias { + name: name.to_string(), + }, + stmt.range(), + ); let edit = Edit::range_replacement( checker.generator().stmt(&Stmt::from(StmtTypeAlias { @@ -186,7 +191,7 @@ impl<'a> Visitor<'a> for TypeVarReferenceVisitor<'a> { Expr::Name(name) if name.ctx.is_load() => { let Some(Stmt::Assign(StmtAssign { value, .. })) = self .semantic - .lookup_symbol(name.id.as_str()) + .lookup_symbol(&name.id) .and_then(|binding_id| { self.semantic .binding(binding_id) diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/useless_metaclass_type.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/useless_metaclass_type.rs index 612c94644c..bfd90a893f 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/useless_metaclass_type.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/useless_metaclass_type.rs @@ -51,13 +51,13 @@ pub(crate) fn useless_metaclass_type( let [Expr::Name(ast::ExprName { id, .. })] = targets else { return; }; - if id != "__metaclass__" { + if &**id != "__metaclass__" { return; } let Expr::Name(ast::ExprName { id, .. }) = value else { return; }; - if id != "type" { + if &**id != "type" { return; } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/useless_object_inheritance.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/useless_object_inheritance.rs index 470cdd911e..7d36ac9d37 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/useless_object_inheritance.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/useless_object_inheritance.rs @@ -54,7 +54,7 @@ pub(crate) fn useless_object_inheritance(checker: &mut Checker, class_def: &ast: let Expr::Name(ast::ExprName { id, .. }) = base else { continue; }; - if id != "object" { + if &**id != "object" { continue; } if !checker.semantic().is_builtin("object") { diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/yield_in_for_loop.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/yield_in_for_loop.rs index d371eb9661..5ada8e2e4f 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/yield_in_for_loop.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/yield_in_for_loop.rs @@ -100,7 +100,7 @@ pub(crate) fn yield_in_for_loop(checker: &mut Checker, stmt_for: &ast::StmtFor) checker .semantic() .current_scope() - .get_all(name.id.as_str()) + .get_all(&name.id) .any(|binding_id| { let binding = checker.semantic().binding(binding_id); binding.references.iter().any(|reference_id| { diff --git a/crates/ruff_linter/src/rules/refurb/helpers.rs b/crates/ruff_linter/src/rules/refurb/helpers.rs index d429dd2d5d..051545f36c 100644 --- a/crates/ruff_linter/src/rules/refurb/helpers.rs +++ b/crates/ruff_linter/src/rules/refurb/helpers.rs @@ -6,7 +6,7 @@ use ruff_text_size::TextRange; pub(super) fn generate_method_call(name: &str, method: &str, generator: Generator) -> String { // Construct `name`. let var = ast::ExprName { - id: name.to_string(), + id: name.to_string().into_boxed_str(), ctx: ast::ExprContext::Load, range: TextRange::default(), }; @@ -43,7 +43,7 @@ pub(super) fn generate_none_identity_comparison( ) -> String { // Construct `name`. let var = ast::ExprName { - id: name.to_string(), + id: name.to_string().into_boxed_str(), ctx: ast::ExprContext::Load, range: TextRange::default(), }; diff --git a/crates/ruff_linter/src/rules/refurb/rules/isinstance_type_none.rs b/crates/ruff_linter/src/rules/refurb/rules/isinstance_type_none.rs index 89c44204de..0f3b7a2e47 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/isinstance_type_none.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/isinstance_type_none.rs @@ -51,7 +51,7 @@ pub(crate) fn isinstance_type_none(checker: &mut Checker, call: &ast::ExprCall) let Expr::Name(ast::ExprName { id, .. }) = call.func.as_ref() else { return; }; - if id.as_str() != "isinstance" { + if &**id != "isinstance" { return; } if !checker.semantic().is_builtin(id) { @@ -94,7 +94,7 @@ fn is_none(expr: &Expr) -> bool { func, arguments, .. }) if arguments.len() == 1 => { if let Expr::Name(ast::ExprName { id, .. }) = func.as_ref() { - if id.as_str() == "type" { + if &**id == "type" { return matches!(arguments.args.first(), Some(Expr::NoneLiteral(_))); } } diff --git a/crates/ruff_linter/src/rules/refurb/rules/read_whole_file.rs b/crates/ruff_linter/src/rules/refurb/rules/read_whole_file.rs index 518d701c79..c1ddd404b4 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/read_whole_file.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/read_whole_file.rs @@ -141,7 +141,8 @@ fn find_file_open<'a>( .. } = item.context_expr.as_call_expr()?; - if func.as_name_expr()?.id != "open" { + let func = func.as_name_expr()?; + if &*func.id != "open" { return None; } @@ -168,7 +169,7 @@ fn find_file_open<'a>( // Now we need to find what is this variable bound to... let scope = semantic.current_scope(); - let bindings: Vec = scope.get_all(var.id.as_str()).collect(); + let bindings: Vec = scope.get_all(&var.id).collect(); let binding = bindings .iter() @@ -315,7 +316,7 @@ fn make_suggestion(open: &FileOpen<'_>, generator: Generator) -> SourceCodeSnipp ReadMode::Bytes => "read_bytes", }; let name = ast::ExprName { - id: method_name.to_string(), + id: method_name.to_string().into_boxed_str(), ctx: ast::ExprContext::Load, range: TextRange::default(), }; diff --git a/crates/ruff_linter/src/rules/refurb/rules/reimplemented_operator.rs b/crates/ruff_linter/src/rules/refurb/rules/reimplemented_operator.rs index 7f5f0ea759..d1b77e478f 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/reimplemented_operator.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/reimplemented_operator.rs @@ -327,7 +327,7 @@ fn is_same_expression(arg: &ast::ParameterWithDefault, expr: &Expr) -> bool { if arg.default.is_some() { false } else if let Expr::Name(name) = expr { - name.id == arg.parameter.name.as_str() + &*name.id == arg.parameter.name.as_str() } else { false } diff --git a/crates/ruff_linter/src/rules/refurb/rules/reimplemented_starmap.rs b/crates/ruff_linter/src/rules/refurb/rules/reimplemented_starmap.rs index 143518339c..f3985852f0 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/reimplemented_starmap.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/reimplemented_starmap.rs @@ -297,7 +297,7 @@ fn try_construct_call( /// Construct the call to `itertools.starmap` for suggestion. fn construct_starmap_call(starmap_binding: String, iter: &Expr, func: &Expr) -> ast::ExprCall { let starmap = ast::ExprName { - id: starmap_binding, + id: starmap_binding.into_boxed_str(), ctx: ast::ExprContext::Load, range: TextRange::default(), }; @@ -315,7 +315,7 @@ fn construct_starmap_call(starmap_binding: String, iter: &Expr, func: &Expr) -> /// Wrap given function call with yet another call. fn wrap_with_call_to(call: ast::ExprCall, func_name: &str) -> ast::ExprCall { let name = ast::ExprName { - id: func_name.to_string(), + id: func_name.to_string().into_boxed_str(), ctx: ast::ExprContext::Load, range: TextRange::default(), }; diff --git a/crates/ruff_linter/src/rules/refurb/rules/type_none_comparison.rs b/crates/ruff_linter/src/rules/refurb/rules/type_none_comparison.rs index d7617c8a56..b7ace1128e 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/type_none_comparison.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/type_none_comparison.rs @@ -94,7 +94,7 @@ pub(crate) fn type_none_comparison(checker: &mut Checker, compare: &ast::ExprCom // Get the name of the other object (or `None` if both were `None`). let other_arg_name = match other_arg { - Expr::Name(ast::ExprName { id, .. }) => id.as_str(), + Expr::Name(ast::ExprName { id, .. }) => &**id, Expr::NoneLiteral { .. } => "None", _ => return, }; @@ -137,7 +137,7 @@ fn type_call_arg<'a>(expr: &'a Expr, semantic: &'a SemanticModel) -> Option<&'a // The function itself must be the builtin `type`. let ast::ExprName { id, .. } = func.as_name_expr()?; - if id.as_str() != "type" || !semantic.is_builtin(id) { + if &**id != "type" || !semantic.is_builtin(id) { return None; } diff --git a/crates/ruff_linter/src/rules/refurb/rules/unnecessary_enumerate.rs b/crates/ruff_linter/src/rules/refurb/rules/unnecessary_enumerate.rs index 15eb34b7c8..a2358105d2 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/unnecessary_enumerate.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/unnecessary_enumerate.rs @@ -106,7 +106,7 @@ pub(crate) fn unnecessary_enumerate(checker: &mut Checker, stmt_for: &ast::StmtF let Expr::Name(ast::ExprName { id, .. }) = func.as_ref() else { return; }; - if id != "enumerate" { + if &**id != "enumerate" { return; }; if !checker.semantic().is_builtin("enumerate") { @@ -236,7 +236,7 @@ impl fmt::Display for EnumerateSubset { fn generate_range_len_call(name: &str, generator: Generator) -> String { // Construct `name`. let var = ast::ExprName { - id: name.to_string(), + id: name.to_string().into_boxed_str(), ctx: ast::ExprContext::Load, range: TextRange::default(), }; @@ -244,7 +244,7 @@ fn generate_range_len_call(name: &str, generator: Generator) -> String { let len = ast::ExprCall { func: Box::new( ast::ExprName { - id: "len".to_string(), + id: "len".to_string().into_boxed_str(), ctx: ast::ExprContext::Load, range: TextRange::default(), } @@ -261,7 +261,7 @@ fn generate_range_len_call(name: &str, generator: Generator) -> String { let range = ast::ExprCall { func: Box::new( ast::ExprName { - id: "range".to_string(), + id: "range".to_string().into_boxed_str(), ctx: ast::ExprContext::Load, range: TextRange::default(), } diff --git a/crates/ruff_linter/src/rules/ruff/rules/explicit_f_string_type_conversion.rs b/crates/ruff_linter/src/rules/ruff/rules/explicit_f_string_type_conversion.rs index 78213d76b2..8e97a1b2fd 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/explicit_f_string_type_conversion.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/explicit_f_string_type_conversion.rs @@ -104,7 +104,7 @@ pub(crate) fn explicit_f_string_type_conversion(checker: &mut Checker, f_string: continue; }; - if !matches!(id.as_str(), "str" | "repr" | "ascii") { + if !matches!(&**id, "str" | "repr" | "ascii") { continue; }; diff --git a/crates/ruff_linter/src/rules/ruff/rules/helpers.rs b/crates/ruff_linter/src/rules/ruff/rules/helpers.rs index 5aba7b8e0d..d384581ac6 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/helpers.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/helpers.rs @@ -10,7 +10,7 @@ use ruff_python_semantic::{analyze, BindingKind, Modules, SemanticModel}; pub(super) fn is_special_attribute(value: &Expr) -> bool { if let Expr::Name(ast::ExprName { id, .. }) = value { matches!( - id.as_str(), + &**id, "__slots__" | "__dict__" | "__weakref__" | "__annotations__" ) } else { diff --git a/crates/ruff_linter/src/rules/ruff/rules/implicit_optional.rs b/crates/ruff_linter/src/rules/ruff/rules/implicit_optional.rs index c9e3b06e0d..b485d231e6 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/implicit_optional.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/implicit_optional.rs @@ -145,7 +145,7 @@ fn generate_fix(checker: &Checker, conversion_type: ConversionType, expr: &Expr) let new_expr = Expr::Subscript(ast::ExprSubscript { range: TextRange::default(), value: Box::new(Expr::Name(ast::ExprName { - id: binding, + id: binding.into_boxed_str(), ctx: ast::ExprContext::Store, range: TextRange::default(), })), diff --git a/crates/ruff_linter/src/rules/ruff/rules/missing_fstring_syntax.rs b/crates/ruff_linter/src/rules/ruff/rules/missing_fstring_syntax.rs index 7cfc2e7bf0..05b950cb34 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/missing_fstring_syntax.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/missing_fstring_syntax.rs @@ -130,7 +130,7 @@ fn should_be_fstring( } for arg in args.iter() { if let ast::Expr::Name(ast::ExprName { id, .. }) = arg { - arg_names.insert(id.as_str()); + arg_names.insert(&**id); } } } @@ -147,7 +147,7 @@ fn should_be_fstring( .filter_map(|element| element.as_expression()) { if let ast::Expr::Name(ast::ExprName { id, .. }) = element.expression.as_ref() { - if arg_names.contains(id.as_str()) { + if arg_names.contains(&**id) { return false; } if semantic diff --git a/crates/ruff_linter/src/rules/ruff/rules/mutable_fromkeys_value.rs b/crates/ruff_linter/src/rules/ruff/rules/mutable_fromkeys_value.rs index 6cac3d994e..a9f210fc12 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/mutable_fromkeys_value.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/mutable_fromkeys_value.rs @@ -76,7 +76,7 @@ pub(crate) fn mutable_fromkeys_value(checker: &mut Checker, call: &ast::ExprCall let Some(name_expr) = value.as_name_expr() else { return; }; - if name_expr.id != "dict" { + if &*name_expr.id != "dict" { return; } if !checker.semantic().is_builtin("dict") { @@ -104,7 +104,7 @@ pub(crate) fn mutable_fromkeys_value(checker: &mut Checker, call: &ast::ExprCall fn generate_dict_comprehension(keys: &Expr, value: &Expr, generator: Generator) -> String { // Construct `key`. let key = ast::ExprName { - id: "key".to_string(), + id: "key".to_string().into_boxed_str(), ctx: ast::ExprContext::Load, range: TextRange::default(), }; diff --git a/crates/ruff_linter/src/rules/ruff/rules/pairwise_over_zipped.rs b/crates/ruff_linter/src/rules/ruff/rules/pairwise_over_zipped.rs index 9f4bed6e4d..88b5a518de 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/pairwise_over_zipped.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/pairwise_over_zipped.rs @@ -111,7 +111,7 @@ pub(crate) fn pairwise_over_zipped(checker: &mut Checker, func: &Expr, args: &[E }; // Require the function to be the builtin `zip`. - if !(id == "zip" && checker.semantic().is_builtin(id)) { + if &**id != "zip" || !checker.semantic().is_builtin(id) { return; } diff --git a/crates/ruff_linter/src/rules/ruff/rules/quadratic_list_summation.rs b/crates/ruff_linter/src/rules/ruff/rules/quadratic_list_summation.rs index e1130d04ce..91104c4d69 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/quadratic_list_summation.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/quadratic_list_summation.rs @@ -124,7 +124,7 @@ fn func_is_builtin(func: &Expr, name: &str, semantic: &SemanticModel) -> bool { let Expr::Name(ast::ExprName { id, .. }) = func else { return false; }; - id == name && semantic.is_builtin(id) + &**id == name && semantic.is_builtin(id) } /// Returns `true` if the `start` argument to a `sum()` call is an empty list. diff --git a/crates/ruff_linter/src/rules/ruff/rules/sort_dunder_all.rs b/crates/ruff_linter/src/rules/ruff/rules/sort_dunder_all.rs index 6df5646f6b..8bd2f8e087 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/sort_dunder_all.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/sort_dunder_all.rs @@ -141,7 +141,7 @@ fn sort_dunder_all(checker: &mut Checker, target: &ast::Expr, node: &ast::Expr) return; }; - if id != "__all__" { + if &**id != "__all__" { return; } diff --git a/crates/ruff_linter/src/rules/ruff/rules/sort_dunder_slots.rs b/crates/ruff_linter/src/rules/ruff/rules/sort_dunder_slots.rs index 83248ac9dc..3cd1c0393d 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/sort_dunder_slots.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/sort_dunder_slots.rs @@ -88,7 +88,7 @@ fn sort_dunder_slots(checker: &mut Checker, target: &ast::Expr, node: &ast::Expr return; }; - if id != "__slots__" { + if &**id != "__slots__" { return; } diff --git a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_iterable_allocation_for_first_element.rs b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_iterable_allocation_for_first_element.rs index 9cac96d080..6694eff786 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_iterable_allocation_for_first_element.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_iterable_allocation_for_first_element.rs @@ -142,7 +142,7 @@ fn match_iteration_target(expr: &Expr, semantic: &SemanticModel) -> Option { let ast::ExprName { id, .. } = func.as_name_expr()?; - if !matches!(id.as_str(), "tuple" | "list") { + if !matches!(&**id, "tuple" | "list") { return None; } @@ -150,7 +150,7 @@ fn match_iteration_target(expr: &Expr, semantic: &SemanticModel) -> Option Optio /// Returns `true` if the function is a builtin iterator. fn is_func_builtin_iterator(func: &Expr, semantic: &SemanticModel) -> bool { func.as_name_expr().map_or(false, |func_name| { - is_iterator(func_name.id.as_str()) && semantic.is_builtin(func_name.id.as_str()) + is_iterator(&func_name.id) && semantic.is_builtin(&func_name.id) }) } diff --git a/crates/ruff_linter/src/rules/tryceratops/rules/useless_try_except.rs b/crates/ruff_linter/src/rules/tryceratops/rules/useless_try_except.rs index 755f849bc9..7b1ee61972 100644 --- a/crates/ruff_linter/src/rules/tryceratops/rules/useless_try_except.rs +++ b/crates/ruff_linter/src/rules/tryceratops/rules/useless_try_except.rs @@ -54,7 +54,7 @@ pub(crate) fn useless_try_except(checker: &mut Checker, handlers: &[ExceptHandle if let Some(expr) = exc { // E.g., `except ... as e: raise e` if let Expr::Name(ast::ExprName { id, .. }) = expr.as_ref() { - if name.as_ref().is_some_and(|name| name.as_str() == id) { + if name.as_ref().is_some_and(|name| **name == **id) { return Some(Diagnostic::new(UselessTryExcept, handler.range())); } } diff --git a/crates/ruff_linter/src/rules/tryceratops/rules/verbose_raise.rs b/crates/ruff_linter/src/rules/tryceratops/rules/verbose_raise.rs index 93b3a78b4e..ee51fad2d6 100644 --- a/crates/ruff_linter/src/rules/tryceratops/rules/verbose_raise.rs +++ b/crates/ruff_linter/src/rules/tryceratops/rules/verbose_raise.rs @@ -97,7 +97,7 @@ pub(crate) fn verbose_raise(checker: &mut Checker, handlers: &[ExceptHandler]) { if let Some(exc) = raise.exc.as_ref() { // ...and the raised object is bound to the same name... if let Expr::Name(ast::ExprName { id, .. }) = exc.as_ref() { - if id == exception_name.as_str() { + if &**id == exception_name.as_str() { let mut diagnostic = Diagnostic::new(VerboseRaise, exc.range()); diagnostic.set_fix(Fix::unsafe_edit(Edit::range_replacement( "raise".to_string(), diff --git a/crates/ruff_python_ast/src/all.rs b/crates/ruff_python_ast/src/all.rs index b0710d50cc..c41efed3f6 100644 --- a/crates/ruff_python_ast/src/all.rs +++ b/crates/ruff_python_ast/src/all.rs @@ -49,13 +49,13 @@ where } Expr::Name(ast::ExprName { id, .. }) => { // Ex) `__all__ = __all__ + multiprocessing.__all__` - if id == "__all__" { + if &**id == "__all__" { return (None, DunderAllFlags::empty()); } } Expr::Attribute(ast::ExprAttribute { attr, .. }) => { // Ex) `__all__ = __all__ + multiprocessing.__all__` - if attr == "__all__" { + if &**attr == "__all__" { return (None, DunderAllFlags::empty()); } } @@ -65,7 +65,7 @@ where // Allow `tuple()`, `list()`, and their generic forms, like `list[int]()`. if arguments.keywords.is_empty() && arguments.args.len() <= 1 { if let Expr::Name(ast::ExprName { id, .. }) = map_subscript(func) { - let id = id.as_str(); + let id = &**id; if matches!(id, "tuple" | "list") && is_builtin(id) { let [arg] = arguments.args.as_ref() else { return (None, DunderAllFlags::empty()); diff --git a/crates/ruff_python_ast/src/call_path.rs b/crates/ruff_python_ast/src/call_path.rs index fe8043a106..8f10f8d420 100644 --- a/crates/ruff_python_ast/src/call_path.rs +++ b/crates/ruff_python_ast/src/call_path.rs @@ -12,9 +12,7 @@ pub fn collect_call_path(expr: &Expr) -> Option { let attr1 = match expr { Expr::Attribute(attr1) => attr1, // Ex) `foo` - Expr::Name(nodes::ExprName { id, .. }) => { - return Some(CallPath::from_slice(&[id.as_str()])) - } + Expr::Name(nodes::ExprName { id, .. }) => return Some(CallPath::from_slice(&[id])), _ => return None, }; @@ -22,7 +20,7 @@ pub fn collect_call_path(expr: &Expr) -> Option { Expr::Attribute(attr2) => attr2, // Ex) `foo.bar` Expr::Name(nodes::ExprName { id, .. }) => { - return Some(CallPath::from_slice(&[id.as_str(), attr1.attr.as_str()])) + return Some(CallPath::from_slice(&[id, &*attr1.attr])) } _ => return None, }; @@ -31,11 +29,7 @@ pub fn collect_call_path(expr: &Expr) -> Option { Expr::Attribute(attr3) => attr3, // Ex) `foo.bar.baz` Expr::Name(nodes::ExprName { id, .. }) => { - return Some(CallPath::from_slice(&[ - id.as_str(), - attr2.attr.as_str(), - attr1.attr.as_str(), - ])); + return Some(CallPath::from_slice(&[id, &*attr2.attr, &*attr1.attr])); } _ => return None, }; @@ -45,10 +39,10 @@ pub fn collect_call_path(expr: &Expr) -> Option { // Ex) `foo.bar.baz.bop` Expr::Name(nodes::ExprName { id, .. }) => { return Some(CallPath::from_slice(&[ - id.as_str(), - attr3.attr.as_str(), - attr2.attr.as_str(), - attr1.attr.as_str(), + id, + &*attr3.attr, + &*attr2.attr, + &*attr1.attr, ])); } _ => return None, @@ -59,11 +53,11 @@ pub fn collect_call_path(expr: &Expr) -> Option { // Ex) `foo.bar.baz.bop.bap` Expr::Name(nodes::ExprName { id, .. }) => { return Some(CallPath::from_slice(&[ - id.as_str(), - attr4.attr.as_str(), - attr3.attr.as_str(), - attr2.attr.as_str(), - attr1.attr.as_str(), + id, + &*attr4.attr, + &*attr3.attr, + &*attr2.attr, + &*attr1.attr, ])); } _ => return None, @@ -74,12 +68,12 @@ pub fn collect_call_path(expr: &Expr) -> Option { // Ex) `foo.bar.baz.bop.bap.bab` Expr::Name(nodes::ExprName { id, .. }) => { return Some(CallPath::from_slice(&[ - id.as_str(), - attr5.attr.as_str(), - attr4.attr.as_str(), - attr3.attr.as_str(), - attr2.attr.as_str(), - attr1.attr.as_str(), + id, + &*attr5.attr, + &*attr4.attr, + &*attr3.attr, + &*attr2.attr, + &*attr1.attr, ])); } _ => return None, @@ -90,13 +84,13 @@ pub fn collect_call_path(expr: &Expr) -> Option { // Ex) `foo.bar.baz.bop.bap.bab.bob` Expr::Name(nodes::ExprName { id, .. }) => { return Some(CallPath::from_slice(&[ - id.as_str(), - attr6.attr.as_str(), - attr5.attr.as_str(), - attr4.attr.as_str(), - attr3.attr.as_str(), - attr2.attr.as_str(), - attr1.attr.as_str(), + id, + &*attr6.attr, + &*attr5.attr, + &*attr4.attr, + &*attr3.attr, + &*attr2.attr, + &*attr1.attr, ])); } _ => return None, @@ -107,14 +101,14 @@ pub fn collect_call_path(expr: &Expr) -> Option { // Ex) `foo.bar.baz.bop.bap.bab.bob.bib` Expr::Name(nodes::ExprName { id, .. }) => { return Some(CallPath::from_slice(&[ - id.as_str(), - attr7.attr.as_str(), - attr6.attr.as_str(), - attr5.attr.as_str(), - attr4.attr.as_str(), - attr3.attr.as_str(), - attr2.attr.as_str(), - attr1.attr.as_str(), + id, + &*attr7.attr, + &*attr6.attr, + &*attr5.attr, + &*attr4.attr, + &*attr3.attr, + &*attr2.attr, + &*attr1.attr, ])); } _ => return None, @@ -122,14 +116,14 @@ pub fn collect_call_path(expr: &Expr) -> Option { collect_call_path(&attr8.value).map(|mut segments| { segments.extend([ - attr8.attr.as_str(), - attr7.attr.as_str(), - attr6.attr.as_str(), - attr5.attr.as_str(), - attr4.attr.as_str(), - attr3.attr.as_str(), - attr2.attr.as_str(), - attr1.attr.as_str(), + &*attr8.attr, + &*attr7.attr, + &*attr6.attr, + &*attr5.attr, + &*attr4.attr, + &*attr3.attr, + &*attr2.attr, + &*attr1.attr, ]); segments }) diff --git a/crates/ruff_python_ast/src/comparable.rs b/crates/ruff_python_ast/src/comparable.rs index 344bb615ce..f21a0647dd 100644 --- a/crates/ruff_python_ast/src/comparable.rs +++ b/crates/ruff_python_ast/src/comparable.rs @@ -1096,9 +1096,7 @@ impl<'a> From<&'a ast::Expr> for ComparableExpr<'a> { impl<'a> From<&'a ast::ExprName> for ComparableExpr<'a> { fn from(expr: &'a ast::ExprName) -> Self { - Self::Name(ExprName { - id: expr.id.as_str(), - }) + Self::Name(ExprName { id: &expr.id }) } } diff --git a/crates/ruff_python_ast/src/helpers.rs b/crates/ruff_python_ast/src/helpers.rs index 579a29ffbc..9591c6b051 100644 --- a/crates/ruff_python_ast/src/helpers.rs +++ b/crates/ruff_python_ast/src/helpers.rs @@ -59,7 +59,7 @@ where // Ex) `list()` if arguments.is_empty() { if let Expr::Name(ast::ExprName { id, .. }) = func.as_ref() { - if !is_iterable_initializer(id.as_str(), |id| is_builtin(id)) { + if !is_iterable_initializer(id, |id| is_builtin(id)) { return true; } return false; @@ -705,8 +705,9 @@ where any_over_body(body, &|expr| { if let Expr::Call(ast::ExprCall { func, .. }) = expr { if let Expr::Name(ast::ExprName { id, .. }) = func.as_ref() { - if matches!(id.as_str(), "locals" | "globals" | "vars" | "exec" | "eval") { - if is_builtin(id.as_str()) { + let id = &**id; + if matches!(id, "locals" | "globals" | "vars" | "exec" | "eval") { + if is_builtin(id) { return true; } } @@ -1230,7 +1231,7 @@ impl Truthiness { func, arguments, .. }) => { if let Expr::Name(ast::ExprName { id, .. }) = func.as_ref() { - if is_iterable_initializer(id.as_str(), |id| is_builtin(id)) { + if is_iterable_initializer(id, |id| is_builtin(id)) { if arguments.is_empty() { // Ex) `list()` Self::Falsey @@ -1439,7 +1440,7 @@ pub fn pep_604_union(elts: &[Expr]) -> Expr { pub fn typing_optional(elt: Expr, binding: String) -> Expr { Expr::Subscript(ast::ExprSubscript { value: Box::new(Expr::Name(ast::ExprName { - id: binding, + id: binding.into_boxed_str(), range: TextRange::default(), ctx: ExprContext::Load, })), @@ -1471,7 +1472,7 @@ pub fn typing_union(elts: &[Expr], binding: String) -> Expr { Expr::Subscript(ast::ExprSubscript { value: Box::new(Expr::Name(ast::ExprName { - id: binding.clone(), + id: binding.clone().into_boxed_str(), range: TextRange::default(), ctx: ExprContext::Load, })), @@ -1537,7 +1538,7 @@ mod tests { fn any_over_stmt_type_alias() { let seen = RefCell::new(Vec::new()); let name = Expr::Name(ExprName { - id: "x".to_string(), + id: "x".to_string().into_boxed_str(), range: TextRange::default(), ctx: ExprContext::Load, }); diff --git a/crates/ruff_python_ast/src/nodes.rs b/crates/ruff_python_ast/src/nodes.rs index b6581eef40..5acddff258 100644 --- a/crates/ruff_python_ast/src/nodes.rs +++ b/crates/ruff_python_ast/src/nodes.rs @@ -1766,7 +1766,7 @@ impl From for Expr { #[derive(Clone, Debug, PartialEq)] pub struct ExprName { pub range: TextRange, - pub id: String, + pub id: Box, pub ctx: ExprContext, } @@ -3283,13 +3283,13 @@ impl IpyEscapeKind { #[derive(Clone, Debug, PartialEq, Eq, Hash)] pub struct Identifier { - id: String, + id: Box, range: TextRange, } impl Identifier { #[inline] - pub fn new(id: impl Into, range: TextRange) -> Self { + pub fn new(id: impl Into>, range: TextRange) -> Self { Self { id: id.into(), range, @@ -3300,21 +3300,21 @@ impl Identifier { impl Identifier { #[inline] pub fn as_str(&self) -> &str { - self.id.as_str() + &self.id } } impl PartialEq for Identifier { #[inline] fn eq(&self, other: &str) -> bool { - self.id == other + &*self.id == other } } impl PartialEq for Identifier { #[inline] fn eq(&self, other: &String) -> bool { - &self.id == other + &*self.id == other } } @@ -3322,21 +3322,21 @@ impl std::ops::Deref for Identifier { type Target = str; #[inline] fn deref(&self) -> &Self::Target { - self.id.as_str() + &self.id } } impl AsRef for Identifier { #[inline] fn as_ref(&self) -> &str { - self.id.as_str() + &self.id } } -impl AsRef for Identifier { +impl From for Box { #[inline] - fn as_ref(&self) -> &String { - &self.id + fn from(id: Identifier) -> Self { + id.id } } @@ -3346,13 +3346,6 @@ impl std::fmt::Display for Identifier { } } -impl From for String { - #[inline] - fn from(identifier: Identifier) -> String { - identifier.id - } -} - impl Ranged for Identifier { fn range(&self) -> TextRange { self.range @@ -3895,11 +3888,11 @@ mod tests { assert!(std::mem::size_of::() <= 104); assert!(std::mem::size_of::() <= 112); assert!(std::mem::size_of::() <= 32); - // 96 for Rustc < 1.76 - assert!(matches!(std::mem::size_of::(), 88 | 96)); + // 88 for Rustc < 1.76 + assert!(matches!(std::mem::size_of::(), 80 | 88)); assert_eq!(std::mem::size_of::(), 64); - assert_eq!(std::mem::size_of::(), 56); + assert_eq!(std::mem::size_of::(), 48); assert_eq!(std::mem::size_of::(), 16); assert_eq!(std::mem::size_of::(), 32); assert_eq!(std::mem::size_of::(), 40); @@ -3917,7 +3910,7 @@ mod tests { assert_eq!(std::mem::size_of::(), 24); assert_eq!(std::mem::size_of::(), 40); assert_eq!(std::mem::size_of::(), 40); - assert_eq!(std::mem::size_of::(), 40); + assert_eq!(std::mem::size_of::(), 32); assert_eq!(std::mem::size_of::(), 24); assert_eq!(std::mem::size_of::(), 8); assert_eq!(std::mem::size_of::(), 32); diff --git a/crates/ruff_python_codegen/src/generator.rs b/crates/ruff_python_codegen/src/generator.rs index c3d7a60ffb..612a6aee35 100644 --- a/crates/ruff_python_codegen/src/generator.rs +++ b/crates/ruff_python_codegen/src/generator.rs @@ -1145,7 +1145,7 @@ impl<'a> Generator<'a> { self.p("*"); self.unparse_expr(value, precedence::MAX); } - Expr::Name(ast::ExprName { id, .. }) => self.p(id.as_str()), + Expr::Name(ast::ExprName { id, .. }) => self.p(id), Expr::List(ast::ExprList { elts, .. }) => { self.p("["); let mut first = true; diff --git a/crates/ruff_python_formatter/src/expression/expr_name.rs b/crates/ruff_python_formatter/src/expression/expr_name.rs index f2014f6771..db9a03ebad 100644 --- a/crates/ruff_python_formatter/src/expression/expr_name.rs +++ b/crates/ruff_python_formatter/src/expression/expr_name.rs @@ -14,7 +14,7 @@ impl FormatNodeRule for FormatExprName { let ExprName { id, range, ctx: _ } = item; debug_assert_eq!( - id.as_str(), + &**id, f.context() .source_code() .slice(*range) diff --git a/crates/ruff_python_parser/src/python.lalrpop b/crates/ruff_python_parser/src/python.lalrpop index f61ae2c2b4..0defd80bfa 100644 --- a/crates/ruff_python_parser/src/python.lalrpop +++ b/crates/ruff_python_parser/src/python.lalrpop @@ -377,7 +377,7 @@ IpyHelpEndEscapeCommandStatement: ast::Stmt = { fn unparse_expr(expr: &ast::Expr, buffer: &mut String) -> Result<(), LexicalError> { match expr { ast::Expr::Name(ast::ExprName { id, .. }) => { - buffer.push_str(id.as_str()); + buffer.push_str(id); }, ast::Expr::Subscript(ast::ExprSubscript { value, slice, range, .. }) => { let ast::Expr::NumberLiteral(ast::ExprNumberLiteral { value: ast::Number::Int(integer), .. }) = slice.as_ref() else { diff --git a/crates/ruff_python_parser/src/python.rs b/crates/ruff_python_parser/src/python.rs index 95de336aa7..528ca9b19d 100644 --- a/crates/ruff_python_parser/src/python.rs +++ b/crates/ruff_python_parser/src/python.rs @@ -1,5 +1,5 @@ // auto-generated: "lalrpop 0.20.0" -// sha3: d38cc0f2252a58db42d3bd63a102b537865992b3cf51d402cdb4828f48989c9d +// sha3: cae04435d0832985b15c6bddb901e8115d4161a49ee0d850c425c1a4a87ef29b use ruff_text_size::{Ranged, TextLen, TextRange, TextSize}; use ruff_python_ast::{self as ast, Int, IpyEscapeKind}; use crate::{ @@ -33711,7 +33711,7 @@ fn __action76< fn unparse_expr(expr: &ast::Expr, buffer: &mut String) -> Result<(), LexicalError> { match expr { ast::Expr::Name(ast::ExprName { id, .. }) => { - buffer.push_str(id.as_str()); + buffer.push_str(id); }, ast::Expr::Subscript(ast::ExprSubscript { value, slice, range, .. }) => { let ast::Expr::NumberLiteral(ast::ExprNumberLiteral { value: ast::Number::Int(integer), .. }) = slice.as_ref() else { diff --git a/crates/ruff_python_semantic/src/analyze/typing.rs b/crates/ruff_python_semantic/src/analyze/typing.rs index 3283db129d..9850bddad4 100644 --- a/crates/ruff_python_semantic/src/analyze/typing.rs +++ b/crates/ruff_python_semantic/src/analyze/typing.rs @@ -519,7 +519,7 @@ trait BuiltinTypeChecker { let Expr::Name(ast::ExprName { id, .. }) = type_expr else { return false; }; - id == Self::BUILTIN_TYPE_NAME && semantic.is_builtin(Self::BUILTIN_TYPE_NAME) + &**id == Self::BUILTIN_TYPE_NAME && semantic.is_builtin(Self::BUILTIN_TYPE_NAME) } } @@ -711,7 +711,7 @@ pub fn find_binding_value<'a>( /// Given a target and value, find the value that's assigned to the given symbol. fn match_value<'a>(symbol: &str, target: &Expr, value: &'a Expr) -> Option<&'a Expr> { match target { - Expr::Name(ast::ExprName { id, .. }) if id.as_str() == symbol => Some(value), + Expr::Name(ast::ExprName { id, .. }) if &**id == symbol => Some(value), Expr::Tuple(ast::ExprTuple { elts, .. }) | Expr::List(ast::ExprList { elts, .. }) => { match value { Expr::Tuple(ast::ExprTuple { @@ -733,7 +733,7 @@ fn match_value<'a>(symbol: &str, target: &Expr, value: &'a Expr) -> Option<&'a E /// Returns `true` if the [`Expr`] defines the symbol. fn defines(symbol: &str, expr: &Expr) -> bool { match expr { - Expr::Name(ast::ExprName { id, .. }) => id == symbol, + Expr::Name(ast::ExprName { id, .. }) => &**id == symbol, Expr::Tuple(ast::ExprTuple { elts, .. }) | Expr::List(ast::ExprList { elts, .. }) | Expr::Set(ast::ExprSet { elts, .. }) => elts.iter().any(|elt| defines(symbol, elt)), @@ -772,7 +772,7 @@ fn get_value_by_id<'a>(target_id: &str, targets: &[Expr], values: &'a [Expr]) -> }; } Expr::Name(ast::ExprName { id, .. }) => { - if *id == target_id { + if &**id == target_id { return Some(value); } } diff --git a/crates/ruff_python_semantic/src/model.rs b/crates/ruff_python_semantic/src/model.rs index df5e3ab7d0..d10a8c3bb7 100644 --- a/crates/ruff_python_semantic/src/model.rs +++ b/crates/ruff_python_semantic/src/model.rs @@ -286,7 +286,7 @@ impl<'a> SemanticModel<'a> { // PEP 563 indicates that if a forward reference can be resolved in the module scope, we // should prefer it over local resolutions. if self.in_forward_reference() { - if let Some(binding_id) = self.scopes.global().get(name.id.as_str()) { + if let Some(binding_id) = self.scopes.global().get(&name.id) { if !self.bindings[binding_id].is_unbound() { // Mark the binding as used. let reference_id = self.resolved_references.push( @@ -299,7 +299,7 @@ impl<'a> SemanticModel<'a> { // Mark any submodule aliases as used. if let Some(binding_id) = - self.resolve_submodule(name.id.as_str(), ScopeId::global(), binding_id) + self.resolve_submodule(&name.id, ScopeId::global(), binding_id) { let reference_id = self.resolved_references.push( ScopeId::global(), @@ -329,7 +329,7 @@ impl<'a> SemanticModel<'a> { // def __init__(self): // print(__class__) // ``` - if seen_function && matches!(name.id.as_str(), "__class__") { + if seen_function && matches!(&*name.id, "__class__") { return ReadResult::ImplicitGlobal; } // Do not allow usages of class symbols unless it is the immediate parent @@ -356,7 +356,7 @@ impl<'a> SemanticModel<'a> { // function and class definitions and their parent class scope. class_variables_visible = scope.kind.is_type() && index == 0; - if let Some(binding_id) = scope.get(name.id.as_str()) { + if let Some(binding_id) = scope.get(&name.id) { // Mark the binding as used. let reference_id = self.resolved_references.push( self.scope_id, @@ -367,9 +367,7 @@ impl<'a> SemanticModel<'a> { self.bindings[binding_id].references.push(reference_id); // Mark any submodule aliases as used. - if let Some(binding_id) = - self.resolve_submodule(name.id.as_str(), scope_id, binding_id) - { + if let Some(binding_id) = self.resolve_submodule(&name.id, scope_id, binding_id) { let reference_id = self.resolved_references.push( self.scope_id, self.node_id, @@ -449,7 +447,7 @@ impl<'a> SemanticModel<'a> { // Mark any submodule aliases as used. if let Some(binding_id) = - self.resolve_submodule(name.id.as_str(), scope_id, binding_id) + self.resolve_submodule(&name.id, scope_id, binding_id) { let reference_id = self.resolved_references.push( self.scope_id, @@ -488,7 +486,7 @@ impl<'a> SemanticModel<'a> { // print(__qualname__) // ``` if index == 0 && scope.kind.is_class() { - if matches!(name.id.as_str(), "__module__" | "__qualname__") { + if matches!(&*name.id, "__module__" | "__qualname__") { return ReadResult::ImplicitGlobal; } } @@ -708,7 +706,7 @@ impl<'a> SemanticModel<'a> { BindingKind::Builtin => { if value.is_name_expr() { // Ex) `dict` - Some(smallvec!["", head.id.as_str()]) + Some(smallvec!["", &*head.id]) } else { // Ex) `dict.__dict__` let value_path = collect_call_path(value)?;