Switch to Rust 2024 edition (#18129)

This commit is contained in:
Micha Reiser 2025-05-16 13:25:28 +02:00 committed by GitHub
parent e67b35743a
commit 9ae698fe30
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
1082 changed files with 4211 additions and 3300 deletions

View file

@ -2,11 +2,11 @@ use std::iter::FusedIterator;
pub use module::{KnownModule, Module};
pub use resolver::resolve_module;
pub(crate) use resolver::{file_to_module, SearchPaths};
pub(crate) use resolver::{SearchPaths, file_to_module};
use ruff_db::system::SystemPath;
use crate::module_resolver::resolver::search_paths;
use crate::Db;
use crate::module_resolver::resolver::search_paths;
use resolver::SearchPathIterator;
mod module;

View file

@ -5,11 +5,11 @@ use std::sync::Arc;
use camino::{Utf8Path, Utf8PathBuf};
use ruff_db::files::{system_path_to_file, vendored_path_to_file, File, FileError};
use ruff_db::files::{File, FileError, system_path_to_file, vendored_path_to_file};
use ruff_db::system::{System, SystemPath, SystemPathBuf};
use ruff_db::vendored::{VendoredPath, VendoredPathBuf};
use super::typeshed::{typeshed_versions, TypeshedVersionsParseError, TypeshedVersionsQueryResult};
use super::typeshed::{TypeshedVersionsParseError, TypeshedVersionsQueryResult, typeshed_versions};
use crate::db::Db;
use crate::module_name::ModuleName;
use crate::module_resolver::resolver::ResolverContext;
@ -923,10 +923,12 @@ mod tests {
assert!(asyncio_regular_package.is_regular_package(&resolver));
// Paths to directories don't resolve to VfsFiles
assert_eq!(asyncio_regular_package.to_file(&resolver), None);
assert!(asyncio_regular_package
.join("__init__.pyi")
.to_file(&resolver)
.is_some());
assert!(
asyncio_regular_package
.join("__init__.pyi")
.to_file(&resolver)
.is_some()
);
// The `asyncio` package exists on Python 3.8, but the `asyncio.tasks` submodule does not,
// according to the `VERSIONS` file in our typeshed mock:
@ -1056,10 +1058,12 @@ mod tests {
assert!(collections_regular_package.is_regular_package(&resolver));
// (This is still `None`, as directories don't resolve to `Vfs` files)
assert_eq!(collections_regular_package.to_file(&resolver), None);
assert!(collections_regular_package
.join("__init__.pyi")
.to_file(&resolver)
.is_some());
assert!(
collections_regular_package
.join("__init__.pyi")
.to_file(&resolver)
.is_some()
);
// ...and so should the `asyncio.tasks` submodule (though it's still not a directory):
let asyncio_tasks_module = stdlib_path.join("asyncio/tasks.pyi");

View file

@ -13,7 +13,7 @@ use ruff_python_ast::PythonVersion;
use crate::db::Db;
use crate::module_name::ModuleName;
use crate::module_resolver::typeshed::{vendored_typeshed_versions, TypeshedVersions};
use crate::module_resolver::typeshed::{TypeshedVersions, vendored_typeshed_versions};
use crate::site_packages::{PythonEnvironment, SitePackagesDiscoveryError, SysPrefixPathOrigin};
use crate::{Program, PythonPath, SearchPathSettings};
@ -639,7 +639,9 @@ fn resolve_name(db: &dyn Db, name: &ModuleName) -> Option<(SearchPath, ResolvedM
match resolve_module_in_search_path(&resolver_state, &stub_name, search_path) {
Ok(resolved_module) => {
if resolved_module.package_kind.is_root() && resolved_module.kind.is_module() {
tracing::trace!("Search path '{search_path} contains a module named `{stub_name}` but a standalone module isn't a valid stub.");
tracing::trace!(
"Search path '{search_path} contains a module named `{stub_name}` but a standalone module isn't a valid stub."
);
} else {
return Some((search_path.clone(), resolved_module));
}
@ -904,12 +906,12 @@ impl fmt::Display for RelaxedModuleName {
#[cfg(test)]
mod tests {
use ruff_db::files::{system_path_to_file, File, FilePath};
use ruff_db::Db;
use ruff_db::files::{File, FilePath, system_path_to_file};
use ruff_db::system::{DbWithTestSystem as _, DbWithWritableSystem as _};
use ruff_db::testing::{
assert_const_function_query_was_not_run, assert_function_query_was_not_run,
};
use ruff_db::Db;
use ruff_python_ast::PythonVersion;
use crate::db::tests::TestDb;
@ -1456,7 +1458,7 @@ mod tests {
fn symlink() -> anyhow::Result<()> {
use anyhow::Context;
use crate::{program::Program, PythonPlatform};
use crate::{PythonPlatform, program::Program};
use ruff_db::system::{OsSystem, SystemPath};
use crate::db::tests::TestDb;
@ -1553,17 +1555,18 @@ mod tests {
let foo_module2 = resolve_module(&db, &foo_module_name);
assert!(!db
.take_salsa_events()
.iter()
.any(|event| { matches!(event.kind, salsa::EventKind::WillExecute { .. }) }));
assert!(
!db.take_salsa_events()
.iter()
.any(|event| { matches!(event.kind, salsa::EventKind::WillExecute { .. }) })
);
assert_eq!(Some(foo_module), foo_module2);
}
#[test]
fn adding_file_on_which_module_resolution_depends_invalidates_previously_failing_query_that_now_succeeds(
) -> anyhow::Result<()> {
fn adding_file_on_which_module_resolution_depends_invalidates_previously_failing_query_that_now_succeeds()
-> anyhow::Result<()> {
let TestCase { mut db, src, .. } = TestCaseBuilder::new().build();
let foo_path = src.join("foo.py");
@ -1582,8 +1585,8 @@ mod tests {
}
#[test]
fn removing_file_on_which_module_resolution_depends_invalidates_previously_successful_query_that_now_fails(
) -> anyhow::Result<()> {
fn removing_file_on_which_module_resolution_depends_invalidates_previously_successful_query_that_now_fails()
-> anyhow::Result<()> {
const SRC: &[FileSpec] = &[("foo.py", "x = 1"), ("foo/__init__.py", "x = 2")];
let TestCase { mut db, src, .. } = TestCaseBuilder::new().with_src_files(SRC).build();
@ -1968,8 +1971,11 @@ not_a_directory
assert!(search_paths.contains(
&&SearchPath::first_party(db.system(), SystemPathBuf::from("/src")).unwrap()
));
assert!(!search_paths
.contains(&&SearchPath::editable(db.system(), SystemPathBuf::from("/src")).unwrap()));
assert!(
!search_paths.contains(
&&SearchPath::editable(db.system(), SystemPathBuf::from("/src")).unwrap()
)
);
}
#[test]
@ -2087,11 +2093,13 @@ not_a_directory
// Now lookup the same module using the lowercase `a` and it should resolve to the file in the system site-packages
let a_module_name = ModuleName::new_static("a").unwrap();
let a_module = resolve_module(&db, &a_module_name).expect("a.py to resolve");
assert!(a_module
.file()
.path(&db)
.as_str()
.ends_with("src/a/__init__.py"),);
assert!(
a_module
.file()
.path(&db)
.as_str()
.ends_with("src/a/__init__.py"),
);
Ok(())
}

View file

@ -7,9 +7,9 @@ use std::str::FromStr;
use ruff_python_ast::PythonVersion;
use rustc_hash::FxHashMap;
use crate::Program;
use crate::db::Db;
use crate::module_name::ModuleName;
use crate::Program;
pub(in crate::module_resolver) fn vendored_typeshed_versions(db: &dyn Db) -> TypeshedVersions {
TypeshedVersions::from_str(
@ -237,7 +237,7 @@ impl FromStr for TypeshedVersions {
return Err(TypeshedVersionsParseError {
line_number: Some(line_number),
reason,
})
});
}
};
}