mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-25 14:24:10 +00:00
Update Rust crate rustc-hash to v2 (#12001)
This commit is contained in:
parent
446ad0ba44
commit
53a80a5c11
17 changed files with 78 additions and 105 deletions
34
Cargo.lock
generated
34
Cargo.lock
generated
|
|
@ -1846,7 +1846,7 @@ dependencies = [
|
||||||
"ruff_python_ast",
|
"ruff_python_ast",
|
||||||
"ruff_python_parser",
|
"ruff_python_parser",
|
||||||
"ruff_text_size",
|
"ruff_text_size",
|
||||||
"rustc-hash",
|
"rustc-hash 2.0.0",
|
||||||
"smol_str",
|
"smol_str",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"tracing",
|
"tracing",
|
||||||
|
|
@ -1863,7 +1863,7 @@ dependencies = [
|
||||||
"path-slash",
|
"path-slash",
|
||||||
"ruff_db",
|
"ruff_db",
|
||||||
"ruff_python_stdlib",
|
"ruff_python_stdlib",
|
||||||
"rustc-hash",
|
"rustc-hash 2.0.0",
|
||||||
"salsa",
|
"salsa",
|
||||||
"smol_str",
|
"smol_str",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
|
|
@ -1886,7 +1886,7 @@ dependencies = [
|
||||||
"ruff_python_ast",
|
"ruff_python_ast",
|
||||||
"ruff_python_parser",
|
"ruff_python_parser",
|
||||||
"ruff_text_size",
|
"ruff_text_size",
|
||||||
"rustc-hash",
|
"rustc-hash 2.0.0",
|
||||||
"salsa",
|
"salsa",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"smol_str",
|
"smol_str",
|
||||||
|
|
@ -2009,7 +2009,7 @@ dependencies = [
|
||||||
"ruff_source_file",
|
"ruff_source_file",
|
||||||
"ruff_text_size",
|
"ruff_text_size",
|
||||||
"ruff_workspace",
|
"ruff_workspace",
|
||||||
"rustc-hash",
|
"rustc-hash 2.0.0",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"shellexpand",
|
"shellexpand",
|
||||||
|
|
@ -2071,7 +2071,7 @@ dependencies = [
|
||||||
"ruff_python_parser",
|
"ruff_python_parser",
|
||||||
"ruff_source_file",
|
"ruff_source_file",
|
||||||
"ruff_text_size",
|
"ruff_text_size",
|
||||||
"rustc-hash",
|
"rustc-hash 2.0.0",
|
||||||
"salsa",
|
"salsa",
|
||||||
"tracing",
|
"tracing",
|
||||||
"zip",
|
"zip",
|
||||||
|
|
@ -2135,7 +2135,7 @@ dependencies = [
|
||||||
"ruff_cache",
|
"ruff_cache",
|
||||||
"ruff_macros",
|
"ruff_macros",
|
||||||
"ruff_text_size",
|
"ruff_text_size",
|
||||||
"rustc-hash",
|
"rustc-hash 2.0.0",
|
||||||
"schemars",
|
"schemars",
|
||||||
"serde",
|
"serde",
|
||||||
"static_assertions",
|
"static_assertions",
|
||||||
|
|
@ -2195,7 +2195,7 @@ dependencies = [
|
||||||
"ruff_python_trivia",
|
"ruff_python_trivia",
|
||||||
"ruff_source_file",
|
"ruff_source_file",
|
||||||
"ruff_text_size",
|
"ruff_text_size",
|
||||||
"rustc-hash",
|
"rustc-hash 2.0.0",
|
||||||
"schemars",
|
"schemars",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
|
@ -2254,7 +2254,7 @@ dependencies = [
|
||||||
"ruff_python_trivia",
|
"ruff_python_trivia",
|
||||||
"ruff_source_file",
|
"ruff_source_file",
|
||||||
"ruff_text_size",
|
"ruff_text_size",
|
||||||
"rustc-hash",
|
"rustc-hash 2.0.0",
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
@ -2301,7 +2301,7 @@ dependencies = [
|
||||||
"ruff_python_trivia",
|
"ruff_python_trivia",
|
||||||
"ruff_source_file",
|
"ruff_source_file",
|
||||||
"ruff_text_size",
|
"ruff_text_size",
|
||||||
"rustc-hash",
|
"rustc-hash 2.0.0",
|
||||||
"schemars",
|
"schemars",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
|
@ -2347,7 +2347,7 @@ dependencies = [
|
||||||
"ruff_python_trivia",
|
"ruff_python_trivia",
|
||||||
"ruff_source_file",
|
"ruff_source_file",
|
||||||
"ruff_text_size",
|
"ruff_text_size",
|
||||||
"rustc-hash",
|
"rustc-hash 2.0.0",
|
||||||
"static_assertions",
|
"static_assertions",
|
||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
"unicode-normalization",
|
"unicode-normalization",
|
||||||
|
|
@ -2377,7 +2377,7 @@ dependencies = [
|
||||||
"ruff_python_stdlib",
|
"ruff_python_stdlib",
|
||||||
"ruff_source_file",
|
"ruff_source_file",
|
||||||
"ruff_text_size",
|
"ruff_text_size",
|
||||||
"rustc-hash",
|
"rustc-hash 2.0.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -2433,7 +2433,7 @@ dependencies = [
|
||||||
"ruff_source_file",
|
"ruff_source_file",
|
||||||
"ruff_text_size",
|
"ruff_text_size",
|
||||||
"ruff_workspace",
|
"ruff_workspace",
|
||||||
"rustc-hash",
|
"rustc-hash 2.0.0",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"shellexpand",
|
"shellexpand",
|
||||||
|
|
@ -2512,7 +2512,7 @@ dependencies = [
|
||||||
"ruff_python_ast",
|
"ruff_python_ast",
|
||||||
"ruff_python_formatter",
|
"ruff_python_formatter",
|
||||||
"ruff_source_file",
|
"ruff_source_file",
|
||||||
"rustc-hash",
|
"rustc-hash 2.0.0",
|
||||||
"schemars",
|
"schemars",
|
||||||
"serde",
|
"serde",
|
||||||
"shellexpand",
|
"shellexpand",
|
||||||
|
|
@ -2537,6 +2537,12 @@ version = "1.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
|
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustc-hash"
|
||||||
|
version = "2.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustix"
|
name = "rustix"
|
||||||
version = "0.38.34"
|
version = "0.38.34"
|
||||||
|
|
@ -2606,7 +2612,7 @@ dependencies = [
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"log",
|
"log",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
"rustc-hash",
|
"rustc-hash 1.1.0",
|
||||||
"salsa-macros",
|
"salsa-macros",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ quote = { version = "1.0.23" }
|
||||||
rand = { version = "0.8.5" }
|
rand = { version = "0.8.5" }
|
||||||
rayon = { version = "1.10.0" }
|
rayon = { version = "1.10.0" }
|
||||||
regex = { version = "1.10.2" }
|
regex = { version = "1.10.2" }
|
||||||
rustc-hash = { version = "1.1.0" }
|
rustc-hash = { version = "2.0.0" }
|
||||||
salsa = { git = "https://github.com/salsa-rs/salsa.git", rev = "f706aa2d32d473ee633a77c1af01d180c85da308" }
|
salsa = { git = "https://github.com/salsa-rs/salsa.git", rev = "f706aa2d32d473ee633a77c1af01d180c85da308" }
|
||||||
schemars = { version = "0.8.16" }
|
schemars = { version = "0.8.16" }
|
||||||
seahash = { version = "4.1.0" }
|
seahash = { version = "4.1.0" }
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
use std::hash::BuildHasherDefault;
|
|
||||||
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::{FxBuildHasher, FxHashSet};
|
||||||
|
|
||||||
use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation};
|
use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation};
|
||||||
use ruff_macros::{derive_message_formats, violation};
|
use ruff_macros::{derive_message_formats, violation};
|
||||||
|
|
@ -150,14 +148,10 @@ pub(crate) fn unnecessary_dict_kwargs(checker: &mut Checker, call: &ast::ExprCal
|
||||||
/// Determine the set of keywords that appear in multiple positions (either directly, as in
|
/// Determine the set of keywords that appear in multiple positions (either directly, as in
|
||||||
/// `func(x=1)`, or indirectly, as in `func(**{"x": 1})`).
|
/// `func(x=1)`, or indirectly, as in `func(**{"x": 1})`).
|
||||||
fn duplicates(call: &ast::ExprCall) -> FxHashSet<&str> {
|
fn duplicates(call: &ast::ExprCall) -> FxHashSet<&str> {
|
||||||
let mut seen = FxHashSet::with_capacity_and_hasher(
|
let mut seen =
|
||||||
call.arguments.keywords.len(),
|
FxHashSet::with_capacity_and_hasher(call.arguments.keywords.len(), FxBuildHasher);
|
||||||
BuildHasherDefault::default(),
|
let mut duplicates =
|
||||||
);
|
FxHashSet::with_capacity_and_hasher(call.arguments.keywords.len(), FxBuildHasher);
|
||||||
let mut duplicates = FxHashSet::with_capacity_and_hasher(
|
|
||||||
call.arguments.keywords.len(),
|
|
||||||
BuildHasherDefault::default(),
|
|
||||||
);
|
|
||||||
for keyword in call.arguments.keywords.iter() {
|
for keyword in call.arguments.keywords.iter() {
|
||||||
if let Some(name) = &keyword.arg {
|
if let Some(name) = &keyword.arg {
|
||||||
if !seen.insert(name.as_str()) {
|
if !seen.insert(name.as_str()) {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
use std::hash::BuildHasherDefault;
|
use rustc_hash::{FxBuildHasher, FxHashMap};
|
||||||
|
|
||||||
use rustc_hash::FxHashMap;
|
|
||||||
|
|
||||||
use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation};
|
use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation};
|
||||||
use ruff_macros::{derive_message_formats, violation};
|
use ruff_macros::{derive_message_formats, violation};
|
||||||
|
|
@ -664,7 +662,7 @@ fn check_duplicates(checker: &mut Checker, values: &Expr) {
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut seen: FxHashMap<ComparableExpr, usize> =
|
let mut seen: FxHashMap<ComparableExpr, usize> =
|
||||||
FxHashMap::with_capacity_and_hasher(elts.len(), BuildHasherDefault::default());
|
FxHashMap::with_capacity_and_hasher(elts.len(), FxBuildHasher);
|
||||||
let mut prev = None;
|
let mut prev = None;
|
||||||
for (index, element) in elts.iter().enumerate() {
|
for (index, element) in elts.iter().enumerate() {
|
||||||
let expr = ComparableExpr::from(element);
|
let expr = ComparableExpr::from(element);
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,9 @@
|
||||||
use std::hash::BuildHasherDefault;
|
|
||||||
|
|
||||||
use anyhow::{anyhow, bail, Result};
|
use anyhow::{anyhow, bail, Result};
|
||||||
use ruff_python_ast::{
|
use ruff_python_ast::{
|
||||||
self as ast, Arguments, CmpOp, Expr, ExprContext, Identifier, Keyword, Stmt, UnaryOp,
|
self as ast, Arguments, CmpOp, Expr, ExprContext, Identifier, Keyword, Stmt, UnaryOp,
|
||||||
};
|
};
|
||||||
use ruff_text_size::TextRange;
|
use ruff_text_size::TextRange;
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::{FxBuildHasher, FxHashMap};
|
||||||
|
|
||||||
/// An enum to represent the different types of assertions present in the
|
/// An enum to represent the different types of assertions present in the
|
||||||
/// `unittest` module. Note: any variants that can't be replaced with plain
|
/// `unittest` module. Note: any variants that can't be replaced with plain
|
||||||
|
|
@ -249,10 +247,8 @@ impl UnittestAssert {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate a map from argument name to value.
|
// Generate a map from argument name to value.
|
||||||
let mut args_map: FxHashMap<&str, &Expr> = FxHashMap::with_capacity_and_hasher(
|
let mut args_map: FxHashMap<&str, &Expr> =
|
||||||
args.len() + keywords.len(),
|
FxHashMap::with_capacity_and_hasher(args.len() + keywords.len(), FxBuildHasher);
|
||||||
BuildHasherDefault::default(),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Process positional arguments.
|
// Process positional arguments.
|
||||||
for (arg_name, value) in arg_spec.iter().zip(args.iter()) {
|
for (arg_name, value) in arg_spec.iter().zip(args.iter()) {
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::hash::BuildHasherDefault;
|
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::{fs, iter};
|
use std::{fs, iter};
|
||||||
|
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use rustc_hash::{FxHashMap, FxHashSet};
|
use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use strum_macros::EnumIter;
|
use strum_macros::EnumIter;
|
||||||
|
|
||||||
|
|
@ -316,8 +315,7 @@ impl KnownModules {
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// Warn in the case of duplicate modules.
|
// Warn in the case of duplicate modules.
|
||||||
let mut seen =
|
let mut seen = FxHashSet::with_capacity_and_hasher(known.len(), FxBuildHasher);
|
||||||
FxHashSet::with_capacity_and_hasher(known.len(), BuildHasherDefault::default());
|
|
||||||
for (module, _) in &known {
|
for (module, _) in &known {
|
||||||
if !seen.insert(module) {
|
if !seen.insert(module) {
|
||||||
warn_user_once!("One or more modules are part of multiple import sections, including: `{module}`");
|
warn_user_once!("One or more modules are part of multiple import sections, including: `{module}`");
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
use std::hash::BuildHasherDefault;
|
use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet};
|
||||||
|
|
||||||
use rustc_hash::{FxHashMap, FxHashSet};
|
|
||||||
|
|
||||||
use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation};
|
use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation};
|
||||||
use ruff_macros::{derive_message_formats, violation};
|
use ruff_macros::{derive_message_formats, violation};
|
||||||
|
|
@ -132,7 +130,7 @@ impl Violation for MultiValueRepeatedKeyVariable {
|
||||||
pub(crate) fn repeated_keys(checker: &mut Checker, dict: &ast::ExprDict) {
|
pub(crate) fn repeated_keys(checker: &mut Checker, dict: &ast::ExprDict) {
|
||||||
// Generate a map from key to (index, value).
|
// Generate a map from key to (index, value).
|
||||||
let mut seen: FxHashMap<ComparableExpr, FxHashSet<ComparableExpr>> =
|
let mut seen: FxHashMap<ComparableExpr, FxHashSet<ComparableExpr>> =
|
||||||
FxHashMap::with_capacity_and_hasher(dict.items.len(), BuildHasherDefault::default());
|
FxHashMap::with_capacity_and_hasher(dict.items.len(), FxBuildHasher);
|
||||||
|
|
||||||
// Detect duplicate keys.
|
// Detect duplicate keys.
|
||||||
for (i, ast::DictItem { key, value }) in dict.items.iter().enumerate() {
|
for (i, ast::DictItem { key, value }) in dict.items.iter().enumerate() {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
use std::hash::BuildHasherDefault;
|
|
||||||
|
|
||||||
use ruff_python_ast::{self as ast, Arguments, Expr};
|
use ruff_python_ast::{self as ast, Arguments, Expr};
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::{FxBuildHasher, FxHashSet};
|
||||||
|
|
||||||
use ruff_diagnostics::{Diagnostic, Violation};
|
use ruff_diagnostics::{Diagnostic, Violation};
|
||||||
use ruff_macros::{derive_message_formats, violation};
|
use ruff_macros::{derive_message_formats, violation};
|
||||||
|
|
@ -57,8 +55,7 @@ pub(crate) fn duplicate_bases(checker: &mut Checker, name: &str, arguments: Opti
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut seen: FxHashSet<&str> =
|
let mut seen: FxHashSet<&str> = FxHashSet::with_capacity_and_hasher(bases.len(), FxBuildHasher);
|
||||||
FxHashSet::with_capacity_and_hasher(bases.len(), BuildHasherDefault::default());
|
|
||||||
for base in bases.iter() {
|
for base in bases.iter() {
|
||||||
if let Expr::Name(ast::ExprName { id, .. }) = base {
|
if let Expr::Name(ast::ExprName { id, .. }) = base {
|
||||||
if !seen.insert(id) {
|
if !seen.insert(id) {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
use std::hash::BuildHasherDefault;
|
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
use itertools::{any, Itertools};
|
use itertools::{any, Itertools};
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::{FxBuildHasher, FxHashMap};
|
||||||
|
|
||||||
use ast::ExprContext;
|
use ast::ExprContext;
|
||||||
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix};
|
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix};
|
||||||
|
|
@ -83,10 +82,7 @@ pub(crate) fn repeated_equality_comparison(checker: &mut Checker, bool_op: &ast:
|
||||||
|
|
||||||
// Map from expression hash to (starting offset, number of comparisons, list
|
// Map from expression hash to (starting offset, number of comparisons, list
|
||||||
let mut value_to_comparators: FxHashMap<HashableExpr, (TextSize, Vec<&Expr>)> =
|
let mut value_to_comparators: FxHashMap<HashableExpr, (TextSize, Vec<&Expr>)> =
|
||||||
FxHashMap::with_capacity_and_hasher(
|
FxHashMap::with_capacity_and_hasher(bool_op.values.len() * 2, FxBuildHasher);
|
||||||
bool_op.values.len() * 2,
|
|
||||||
BuildHasherDefault::default(),
|
|
||||||
);
|
|
||||||
|
|
||||||
for value in &bool_op.values {
|
for value in &bool_op.values {
|
||||||
// Enforced via `is_allowed_value`.
|
// Enforced via `is_allowed_value`.
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
use std::hash::BuildHasherDefault;
|
use rustc_hash::{FxBuildHasher, FxHashSet};
|
||||||
|
|
||||||
use rustc_hash::FxHashSet;
|
|
||||||
|
|
||||||
use ruff_diagnostics::{Diagnostic, Violation};
|
use ruff_diagnostics::{Diagnostic, Violation};
|
||||||
use ruff_macros::{derive_message_formats, violation};
|
use ruff_macros::{derive_message_formats, violation};
|
||||||
|
|
@ -40,10 +38,7 @@ impl Violation for RepeatedKeywordArgument {
|
||||||
pub(crate) fn repeated_keyword_argument(checker: &mut Checker, call: &ExprCall) {
|
pub(crate) fn repeated_keyword_argument(checker: &mut Checker, call: &ExprCall) {
|
||||||
let ExprCall { arguments, .. } = call;
|
let ExprCall { arguments, .. } = call;
|
||||||
|
|
||||||
let mut seen = FxHashSet::with_capacity_and_hasher(
|
let mut seen = FxHashSet::with_capacity_and_hasher(arguments.keywords.len(), FxBuildHasher);
|
||||||
arguments.keywords.len(),
|
|
||||||
BuildHasherDefault::default(),
|
|
||||||
);
|
|
||||||
|
|
||||||
for keyword in arguments.keywords.iter() {
|
for keyword in arguments.keywords.iter() {
|
||||||
if let Some(id) = &keyword.arg {
|
if let Some(id) = &keyword.arg {
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,11 @@ impl Debug for DebugComments<'_> {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
let mut map = f.debug_map();
|
let mut map = f.debug_map();
|
||||||
|
|
||||||
for node in self.comments.keys().sorted_by_key(|key| key.node().start()) {
|
for node in self
|
||||||
|
.comments
|
||||||
|
.keys()
|
||||||
|
.sorted_by_key(|key| (key.node().start(), key.node().end()))
|
||||||
|
{
|
||||||
map.entry(
|
map.entry(
|
||||||
&NodeKindWithSource {
|
&NodeKindWithSource {
|
||||||
key: *node,
|
key: *node,
|
||||||
|
|
@ -191,11 +195,11 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn debug() {
|
fn debug() {
|
||||||
let continue_statement = AnyNode::from(StmtContinue {
|
let continue_statement = AnyNode::from(StmtContinue {
|
||||||
range: TextRange::default(),
|
range: TextRange::new(TextSize::new(18), TextSize::new(26)),
|
||||||
});
|
});
|
||||||
|
|
||||||
let break_statement = AnyNode::from(StmtBreak {
|
let break_statement = AnyNode::from(StmtBreak {
|
||||||
range: TextRange::default(),
|
range: TextRange::new(TextSize::new(55), TextSize::new(60)),
|
||||||
});
|
});
|
||||||
|
|
||||||
let source = r"# leading comment
|
let source = r"# leading comment
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@ expression: comments.debug(source_code)
|
||||||
{
|
{
|
||||||
Node {
|
Node {
|
||||||
kind: StmtContinue,
|
kind: StmtContinue,
|
||||||
range: 0..0,
|
range: 18..26,
|
||||||
source: ``,
|
source: `continue`,
|
||||||
}: {
|
}: {
|
||||||
"leading": [
|
"leading": [
|
||||||
SourceComment {
|
SourceComment {
|
||||||
|
|
@ -26,8 +26,8 @@ expression: comments.debug(source_code)
|
||||||
},
|
},
|
||||||
Node {
|
Node {
|
||||||
kind: StmtBreak,
|
kind: StmtBreak,
|
||||||
range: 0..0,
|
range: 55..60,
|
||||||
source: ``,
|
source: `break`,
|
||||||
}: {
|
}: {
|
||||||
"leading": [
|
"leading": [
|
||||||
SourceComment {
|
SourceComment {
|
||||||
|
|
|
||||||
|
|
@ -3,21 +3,6 @@ source: crates/ruff_python_formatter/src/comments/mod.rs
|
||||||
expression: comments.debug(test_case.source_code)
|
expression: comments.debug(test_case.source_code)
|
||||||
---
|
---
|
||||||
{
|
{
|
||||||
Node {
|
|
||||||
kind: ExprBinOp,
|
|
||||||
range: 30..57,
|
|
||||||
source: `10 + # More comments⏎`,
|
|
||||||
}: {
|
|
||||||
"leading": [
|
|
||||||
SourceComment {
|
|
||||||
text: "# Trailing comment",
|
|
||||||
position: EndOfLine,
|
|
||||||
formatted: false,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
"dangling": [],
|
|
||||||
"trailing": [],
|
|
||||||
},
|
|
||||||
Node {
|
Node {
|
||||||
kind: ExprNumberLiteral,
|
kind: ExprNumberLiteral,
|
||||||
range: 30..32,
|
range: 30..32,
|
||||||
|
|
@ -33,4 +18,19 @@ expression: comments.debug(test_case.source_code)
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
Node {
|
||||||
|
kind: ExprBinOp,
|
||||||
|
range: 30..57,
|
||||||
|
source: `10 + # More comments⏎`,
|
||||||
|
}: {
|
||||||
|
"leading": [
|
||||||
|
SourceComment {
|
||||||
|
text: "# Trailing comment",
|
||||||
|
position: EndOfLine,
|
||||||
|
formatted: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"dangling": [],
|
||||||
|
"trailing": [],
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::hash::BuildHasherDefault;
|
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
use bitflags::bitflags;
|
use bitflags::bitflags;
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::{FxBuildHasher, FxHashSet};
|
||||||
|
|
||||||
use ruff_python_ast::{
|
use ruff_python_ast::{
|
||||||
self as ast, BoolOp, CmpOp, ConversionFlag, Expr, ExprContext, FStringElement, FStringElements,
|
self as ast, BoolOp, CmpOp, ConversionFlag, Expr, ExprContext, FStringElement, FStringElements,
|
||||||
|
|
@ -2279,10 +2278,8 @@ impl<'src> Parser<'src> {
|
||||||
///
|
///
|
||||||
/// Report errors for all the duplicate names found.
|
/// Report errors for all the duplicate names found.
|
||||||
fn validate_arguments(&mut self, arguments: &ast::Arguments) {
|
fn validate_arguments(&mut self, arguments: &ast::Arguments) {
|
||||||
let mut all_arg_names = FxHashSet::with_capacity_and_hasher(
|
let mut all_arg_names =
|
||||||
arguments.keywords.len(),
|
FxHashSet::with_capacity_and_hasher(arguments.keywords.len(), FxBuildHasher);
|
||||||
BuildHasherDefault::default(),
|
|
||||||
);
|
|
||||||
|
|
||||||
for (name, range) in arguments
|
for (name, range) in arguments
|
||||||
.keywords
|
.keywords
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
use std::hash::BuildHasherDefault;
|
|
||||||
|
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::{FxBuildHasher, FxHashSet};
|
||||||
|
|
||||||
use ruff_python_ast::{
|
use ruff_python_ast::{
|
||||||
self as ast, ExceptHandler, Expr, ExprContext, IpyEscapeKind, Operator, Stmt, WithItem,
|
self as ast, ExceptHandler, Expr, ExprContext, IpyEscapeKind, Operator, Stmt, WithItem,
|
||||||
|
|
@ -3264,7 +3263,7 @@ impl<'src> Parser<'src> {
|
||||||
/// Report errors for all the duplicate names found.
|
/// Report errors for all the duplicate names found.
|
||||||
fn validate_parameters(&mut self, parameters: &ast::Parameters) {
|
fn validate_parameters(&mut self, parameters: &ast::Parameters) {
|
||||||
let mut all_arg_names =
|
let mut all_arg_names =
|
||||||
FxHashSet::with_capacity_and_hasher(parameters.len(), BuildHasherDefault::default());
|
FxHashSet::with_capacity_and_hasher(parameters.len(), FxBuildHasher);
|
||||||
|
|
||||||
for parameter in parameters {
|
for parameter in parameters {
|
||||||
let range = parameter.name().range();
|
let range = parameter.name().range();
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
use std::{collections::HashMap, hash::BuildHasherDefault};
|
|
||||||
|
|
||||||
use anyhow::Ok;
|
use anyhow::Ok;
|
||||||
use lsp_types::{NotebookCellKind, Url};
|
use lsp_types::NotebookCellKind;
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::{FxBuildHasher, FxHashMap};
|
||||||
|
|
||||||
use crate::{PositionEncoding, TextDocument};
|
use crate::{PositionEncoding, TextDocument};
|
||||||
|
|
||||||
|
|
@ -24,7 +22,7 @@ pub struct NotebookDocument {
|
||||||
/// A single cell within a notebook, which has text contents represented as a `TextDocument`.
|
/// A single cell within a notebook, which has text contents represented as a `TextDocument`.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
struct NotebookCell {
|
struct NotebookCell {
|
||||||
url: Url,
|
url: lsp_types::Url,
|
||||||
kind: NotebookCellKind,
|
kind: NotebookCellKind,
|
||||||
document: TextDocument,
|
document: TextDocument,
|
||||||
}
|
}
|
||||||
|
|
@ -178,8 +176,7 @@ impl NotebookDocument {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_cell_index(cells: &[NotebookCell]) -> FxHashMap<lsp_types::Url, CellId> {
|
fn make_cell_index(cells: &[NotebookCell]) -> FxHashMap<lsp_types::Url, CellId> {
|
||||||
let mut index =
|
let mut index = FxHashMap::with_capacity_and_hasher(cells.len(), FxBuildHasher);
|
||||||
HashMap::with_capacity_and_hasher(cells.len(), BuildHasherDefault::default());
|
|
||||||
for (i, cell) in cells.iter().enumerate() {
|
for (i, cell) in cells.iter().enumerate() {
|
||||||
index.insert(cell.url.clone(), i);
|
index.insert(cell.url.clone(), i);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
use std::hash::BuildHasherDefault;
|
|
||||||
|
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use rustc_hash::{FxHashMap, FxHashSet};
|
use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use strum::IntoEnumIterator;
|
use strum::IntoEnumIterator;
|
||||||
|
|
||||||
|
|
@ -2406,8 +2405,7 @@ impl IsortOptions {
|
||||||
.collect::<Result<_, _>>()?;
|
.collect::<Result<_, _>>()?;
|
||||||
|
|
||||||
// Verify that `section_order` doesn't contain any duplicates.
|
// Verify that `section_order` doesn't contain any duplicates.
|
||||||
let mut seen =
|
let mut seen = FxHashSet::with_capacity_and_hasher(section_order.len(), FxBuildHasher);
|
||||||
FxHashSet::with_capacity_and_hasher(section_order.len(), BuildHasherDefault::default());
|
|
||||||
for section in §ion_order {
|
for section in §ion_order {
|
||||||
if !seen.insert(section) {
|
if !seen.insert(section) {
|
||||||
warn_user_once!(
|
warn_user_once!(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue