Update Rust crate rustc-hash to v2 (#12001)

This commit is contained in:
renovate[bot] 2024-06-23 20:46:42 -04:00 committed by GitHub
parent 446ad0ba44
commit 53a80a5c11
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 78 additions and 105 deletions

34
Cargo.lock generated
View file

@ -1846,7 +1846,7 @@ dependencies = [
"ruff_python_ast",
"ruff_python_parser",
"ruff_text_size",
"rustc-hash",
"rustc-hash 2.0.0",
"smol_str",
"tempfile",
"tracing",
@ -1863,7 +1863,7 @@ dependencies = [
"path-slash",
"ruff_db",
"ruff_python_stdlib",
"rustc-hash",
"rustc-hash 2.0.0",
"salsa",
"smol_str",
"tempfile",
@ -1886,7 +1886,7 @@ dependencies = [
"ruff_python_ast",
"ruff_python_parser",
"ruff_text_size",
"rustc-hash",
"rustc-hash 2.0.0",
"salsa",
"smallvec",
"smol_str",
@ -2009,7 +2009,7 @@ dependencies = [
"ruff_source_file",
"ruff_text_size",
"ruff_workspace",
"rustc-hash",
"rustc-hash 2.0.0",
"serde",
"serde_json",
"shellexpand",
@ -2071,7 +2071,7 @@ dependencies = [
"ruff_python_parser",
"ruff_source_file",
"ruff_text_size",
"rustc-hash",
"rustc-hash 2.0.0",
"salsa",
"tracing",
"zip",
@ -2135,7 +2135,7 @@ dependencies = [
"ruff_cache",
"ruff_macros",
"ruff_text_size",
"rustc-hash",
"rustc-hash 2.0.0",
"schemars",
"serde",
"static_assertions",
@ -2195,7 +2195,7 @@ dependencies = [
"ruff_python_trivia",
"ruff_source_file",
"ruff_text_size",
"rustc-hash",
"rustc-hash 2.0.0",
"schemars",
"serde",
"serde_json",
@ -2254,7 +2254,7 @@ dependencies = [
"ruff_python_trivia",
"ruff_source_file",
"ruff_text_size",
"rustc-hash",
"rustc-hash 2.0.0",
"serde",
]
@ -2301,7 +2301,7 @@ dependencies = [
"ruff_python_trivia",
"ruff_source_file",
"ruff_text_size",
"rustc-hash",
"rustc-hash 2.0.0",
"schemars",
"serde",
"serde_json",
@ -2347,7 +2347,7 @@ dependencies = [
"ruff_python_trivia",
"ruff_source_file",
"ruff_text_size",
"rustc-hash",
"rustc-hash 2.0.0",
"static_assertions",
"unicode-ident",
"unicode-normalization",
@ -2377,7 +2377,7 @@ dependencies = [
"ruff_python_stdlib",
"ruff_source_file",
"ruff_text_size",
"rustc-hash",
"rustc-hash 2.0.0",
]
[[package]]
@ -2433,7 +2433,7 @@ dependencies = [
"ruff_source_file",
"ruff_text_size",
"ruff_workspace",
"rustc-hash",
"rustc-hash 2.0.0",
"serde",
"serde_json",
"shellexpand",
@ -2512,7 +2512,7 @@ dependencies = [
"ruff_python_ast",
"ruff_python_formatter",
"ruff_source_file",
"rustc-hash",
"rustc-hash 2.0.0",
"schemars",
"serde",
"shellexpand",
@ -2537,6 +2537,12 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "rustc-hash"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152"
[[package]]
name = "rustix"
version = "0.38.34"
@ -2606,7 +2612,7 @@ dependencies = [
"indexmap",
"log",
"parking_lot",
"rustc-hash",
"rustc-hash 1.1.0",
"salsa-macros",
"smallvec",
]

View file

@ -105,7 +105,7 @@ quote = { version = "1.0.23" }
rand = { version = "0.8.5" }
rayon = { version = "1.10.0" }
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" }
schemars = { version = "0.8.16" }
seahash = { version = "4.1.0" }

View file

@ -1,7 +1,5 @@
use std::hash::BuildHasherDefault;
use itertools::Itertools;
use rustc_hash::FxHashSet;
use rustc_hash::{FxBuildHasher, FxHashSet};
use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, 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
/// `func(x=1)`, or indirectly, as in `func(**{"x": 1})`).
fn duplicates(call: &ast::ExprCall) -> FxHashSet<&str> {
let mut seen = FxHashSet::with_capacity_and_hasher(
call.arguments.keywords.len(),
BuildHasherDefault::default(),
);
let mut duplicates = FxHashSet::with_capacity_and_hasher(
call.arguments.keywords.len(),
BuildHasherDefault::default(),
);
let mut seen =
FxHashSet::with_capacity_and_hasher(call.arguments.keywords.len(), FxBuildHasher);
let mut duplicates =
FxHashSet::with_capacity_and_hasher(call.arguments.keywords.len(), FxBuildHasher);
for keyword in call.arguments.keywords.iter() {
if let Some(name) = &keyword.arg {
if !seen.insert(name.as_str()) {

View file

@ -1,6 +1,4 @@
use std::hash::BuildHasherDefault;
use rustc_hash::FxHashMap;
use rustc_hash::{FxBuildHasher, FxHashMap};
use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, 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> =
FxHashMap::with_capacity_and_hasher(elts.len(), BuildHasherDefault::default());
FxHashMap::with_capacity_and_hasher(elts.len(), FxBuildHasher);
let mut prev = None;
for (index, element) in elts.iter().enumerate() {
let expr = ComparableExpr::from(element);

View file

@ -1,11 +1,9 @@
use std::hash::BuildHasherDefault;
use anyhow::{anyhow, bail, Result};
use ruff_python_ast::{
self as ast, Arguments, CmpOp, Expr, ExprContext, Identifier, Keyword, Stmt, UnaryOp,
};
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
/// `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.
let mut args_map: FxHashMap<&str, &Expr> = FxHashMap::with_capacity_and_hasher(
args.len() + keywords.len(),
BuildHasherDefault::default(),
);
let mut args_map: FxHashMap<&str, &Expr> =
FxHashMap::with_capacity_and_hasher(args.len() + keywords.len(), FxBuildHasher);
// Process positional arguments.
for (arg_name, value) in arg_spec.iter().zip(args.iter()) {

View file

@ -1,11 +1,10 @@
use std::collections::BTreeMap;
use std::fmt;
use std::hash::BuildHasherDefault;
use std::path::{Path, PathBuf};
use std::{fs, iter};
use log::debug;
use rustc_hash::{FxHashMap, FxHashSet};
use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet};
use serde::{Deserialize, Serialize};
use strum_macros::EnumIter;
@ -316,8 +315,7 @@ impl KnownModules {
.collect();
// Warn in the case of duplicate modules.
let mut seen =
FxHashSet::with_capacity_and_hasher(known.len(), BuildHasherDefault::default());
let mut seen = FxHashSet::with_capacity_and_hasher(known.len(), FxBuildHasher);
for (module, _) in &known {
if !seen.insert(module) {
warn_user_once!("One or more modules are part of multiple import sections, including: `{module}`");

View file

@ -1,6 +1,4 @@
use std::hash::BuildHasherDefault;
use rustc_hash::{FxHashMap, FxHashSet};
use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet};
use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, 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) {
// Generate a map from key to (index, value).
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.
for (i, ast::DictItem { key, value }) in dict.items.iter().enumerate() {

View file

@ -1,7 +1,5 @@
use std::hash::BuildHasherDefault;
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_macros::{derive_message_formats, violation};
@ -57,8 +55,7 @@ pub(crate) fn duplicate_bases(checker: &mut Checker, name: &str, arguments: Opti
return;
};
let mut seen: FxHashSet<&str> =
FxHashSet::with_capacity_and_hasher(bases.len(), BuildHasherDefault::default());
let mut seen: FxHashSet<&str> = FxHashSet::with_capacity_and_hasher(bases.len(), FxBuildHasher);
for base in bases.iter() {
if let Expr::Name(ast::ExprName { id, .. }) = base {
if !seen.insert(id) {

View file

@ -1,8 +1,7 @@
use std::hash::BuildHasherDefault;
use std::ops::Deref;
use itertools::{any, Itertools};
use rustc_hash::FxHashMap;
use rustc_hash::{FxBuildHasher, FxHashMap};
use ast::ExprContext;
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
let mut value_to_comparators: FxHashMap<HashableExpr, (TextSize, Vec<&Expr>)> =
FxHashMap::with_capacity_and_hasher(
bool_op.values.len() * 2,
BuildHasherDefault::default(),
);
FxHashMap::with_capacity_and_hasher(bool_op.values.len() * 2, FxBuildHasher);
for value in &bool_op.values {
// Enforced via `is_allowed_value`.

View file

@ -1,6 +1,4 @@
use std::hash::BuildHasherDefault;
use rustc_hash::FxHashSet;
use rustc_hash::{FxBuildHasher, FxHashSet};
use ruff_diagnostics::{Diagnostic, 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) {
let ExprCall { arguments, .. } = call;
let mut seen = FxHashSet::with_capacity_and_hasher(
arguments.keywords.len(),
BuildHasherDefault::default(),
);
let mut seen = FxHashSet::with_capacity_and_hasher(arguments.keywords.len(), FxBuildHasher);
for keyword in arguments.keywords.iter() {
if let Some(id) = &keyword.arg {

View file

@ -55,7 +55,11 @@ impl Debug for DebugComments<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
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(
&NodeKindWithSource {
key: *node,
@ -191,11 +195,11 @@ mod tests {
#[test]
fn debug() {
let continue_statement = AnyNode::from(StmtContinue {
range: TextRange::default(),
range: TextRange::new(TextSize::new(18), TextSize::new(26)),
});
let break_statement = AnyNode::from(StmtBreak {
range: TextRange::default(),
range: TextRange::new(TextSize::new(55), TextSize::new(60)),
});
let source = r"# leading comment

View file

@ -5,8 +5,8 @@ expression: comments.debug(source_code)
{
Node {
kind: StmtContinue,
range: 0..0,
source: ``,
range: 18..26,
source: `continue`,
}: {
"leading": [
SourceComment {
@ -26,8 +26,8 @@ expression: comments.debug(source_code)
},
Node {
kind: StmtBreak,
range: 0..0,
source: ``,
range: 55..60,
source: `break`,
}: {
"leading": [
SourceComment {

View file

@ -3,21 +3,6 @@ source: crates/ruff_python_formatter/src/comments/mod.rs
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 {
kind: ExprNumberLiteral,
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": [],
},
}

View file

@ -1,9 +1,8 @@
use std::cmp::Ordering;
use std::hash::BuildHasherDefault;
use std::ops::Deref;
use bitflags::bitflags;
use rustc_hash::FxHashSet;
use rustc_hash::{FxBuildHasher, FxHashSet};
use ruff_python_ast::{
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.
fn validate_arguments(&mut self, arguments: &ast::Arguments) {
let mut all_arg_names = FxHashSet::with_capacity_and_hasher(
arguments.keywords.len(),
BuildHasherDefault::default(),
);
let mut all_arg_names =
FxHashSet::with_capacity_and_hasher(arguments.keywords.len(), FxBuildHasher);
for (name, range) in arguments
.keywords

View file

@ -1,7 +1,6 @@
use std::fmt::Display;
use std::hash::BuildHasherDefault;
use rustc_hash::FxHashSet;
use rustc_hash::{FxBuildHasher, FxHashSet};
use ruff_python_ast::{
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.
fn validate_parameters(&mut self, parameters: &ast::Parameters) {
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 {
let range = parameter.name().range();

View file

@ -1,8 +1,6 @@
use std::{collections::HashMap, hash::BuildHasherDefault};
use anyhow::Ok;
use lsp_types::{NotebookCellKind, Url};
use rustc_hash::FxHashMap;
use lsp_types::NotebookCellKind;
use rustc_hash::{FxBuildHasher, FxHashMap};
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`.
#[derive(Clone, Debug)]
struct NotebookCell {
url: Url,
url: lsp_types::Url,
kind: NotebookCellKind,
document: TextDocument,
}
@ -178,8 +176,7 @@ impl NotebookDocument {
}
fn make_cell_index(cells: &[NotebookCell]) -> FxHashMap<lsp_types::Url, CellId> {
let mut index =
HashMap::with_capacity_and_hasher(cells.len(), BuildHasherDefault::default());
let mut index = FxHashMap::with_capacity_and_hasher(cells.len(), FxBuildHasher);
for (i, cell) in cells.iter().enumerate() {
index.insert(cell.url.clone(), i);
}

View file

@ -1,8 +1,7 @@
use std::collections::BTreeSet;
use std::hash::BuildHasherDefault;
use regex::Regex;
use rustc_hash::{FxHashMap, FxHashSet};
use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet};
use serde::{Deserialize, Serialize};
use strum::IntoEnumIterator;
@ -2406,8 +2405,7 @@ impl IsortOptions {
.collect::<Result<_, _>>()?;
// Verify that `section_order` doesn't contain any duplicates.
let mut seen =
FxHashSet::with_capacity_and_hasher(section_order.len(), BuildHasherDefault::default());
let mut seen = FxHashSet::with_capacity_and_hasher(section_order.len(), FxBuildHasher);
for section in &section_order {
if !seen.insert(section) {
warn_user_once!(