From 45c0c46c9d0139caa252344080deb12672ee6a9f Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Mon, 11 Aug 2025 16:45:47 +0200 Subject: [PATCH] Cargo: align rust toolchain version with internal repository Also: * remove new warnings raised by the rust toolchain * run new formatting and linting * update the rust toolchain used by `cargo` While we keep `bazel` builds using the same toolchain as internally (now a nightly one), I opted for using a stable toolchain for `cargo`. The nightly toolchain is only required internally for build reasons, we should keep not using any unstable rust features in our sources. --- .bazelrc | 7 +++ MODULE.bazel | 47 ++++++++++--------- rust-toolchain.toml | 10 ++-- rust/ast-generator/src/main.rs | 4 +- rust/extractor/src/rust_analyzer.rs | 6 +-- rust/extractor/src/translate/base.rs | 8 ++-- rust/extractor/src/trap.rs | 2 +- rust/rust-toolchain.toml | 8 ---- .../src/generator/mod.rs | 4 +- .../src/generator/ql_gen.rs | 12 ++--- 10 files changed, 55 insertions(+), 53 deletions(-) delete mode 100644 rust/rust-toolchain.toml diff --git a/.bazelrc b/.bazelrc index 449345bfb62..54a510f05dc 100644 --- a/.bazelrc +++ b/.bazelrc @@ -30,6 +30,13 @@ common --registry=https://bcr.bazel.build common --@rules_dotnet//dotnet/settings:strict_deps=false +# we only configure a nightly toolchain +common --@rules_rust//rust/toolchain/channel=nightly + +# rust does not like the gold linker, while bazel does by default, so let's avoid using it +common:linux --linkopt=-fuse-ld=lld +common:macos --linkopt=-fuse-ld=lld + # Reduce this eventually to empty, once we've fixed all our usages of java, and https://github.com/bazel-contrib/rules_go/issues/4193 is fixed common --incompatible_autoload_externally="+@rules_java,+@rules_shell" diff --git a/MODULE.bazel b/MODULE.bazel index 3b2532b08af..8bf127ba00f 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -28,7 +28,7 @@ bazel_dep(name = "rules_kotlin", version = "2.1.3-codeql.1") bazel_dep(name = "gazelle", version = "0.40.0") bazel_dep(name = "rules_dotnet", version = "0.17.4") bazel_dep(name = "googletest", version = "1.14.0.bcr.1") -bazel_dep(name = "rules_rust", version = "0.58.0") +bazel_dep(name = "rules_rust", version = "0.63.0") bazel_dep(name = "zstd", version = "1.5.5.bcr.1") bazel_dep(name = "buildifier_prebuilt", version = "6.4.0", dev_dependency = True) @@ -38,7 +38,10 @@ bazel_dep(name = "buildifier_prebuilt", version = "6.4.0", dev_dependency = True RUST_EDITION = "2024" # run buildutils-internal/scripts/fill-rust-sha256s.py when updating (internal repo) -RUST_VERSION = "1.86.0" +# a nightly toolchain is required to enable experimental_use_cc_common_link, which we require internally +# we prefer to run the same version as internally, even if experimental_use_cc_common_link is not really +# required in this repo +RUST_VERSION = "nightly/2025-08-01" rust = use_extension("@rules_rust//rust:extensions.bzl", "rust") rust.toolchain( @@ -50,26 +53,26 @@ rust.toolchain( ], # generated by buildutils-internal/scripts/fill-rust-sha256s.py (internal repo) sha256s = { - "rustc-1.86.0-x86_64-unknown-linux-gnu.tar.xz": "4438b809ce4a083af31ed17aeeedcc8fc60ccffc0625bef1926620751b6989d7", - "rustc-1.86.0-x86_64-apple-darwin.tar.xz": "42b76253626febb7912541a30d3379f463dec89581aad4cb72c6c04fb5a71dc5", - "rustc-1.86.0-aarch64-apple-darwin.tar.xz": "23b8f52102249a47ab5bc859d54c9a3cb588a3259ba3f00f557d50edeca4fde9", - "rustc-1.86.0-x86_64-pc-windows-msvc.tar.xz": "fdde839fea274529a31e51eb85c6df1782cc8479c9d1bc24e2914d66a0de41ab", - "clippy-1.86.0-x86_64-unknown-linux-gnu.tar.xz": "02aaff2c1407d2da8dba19aa4970dd873e311902b120a66cbcdbe51eb8836edf", - "clippy-1.86.0-x86_64-apple-darwin.tar.xz": "bb85efda7bbffaf124867f5ca36d50932b1e8f533c62ee923438afb32ff8fe9a", - "clippy-1.86.0-aarch64-apple-darwin.tar.xz": "239fa3a604b124f0312f2af08537874a1227dba63385484b468cca62e7c4f2f2", - "clippy-1.86.0-x86_64-pc-windows-msvc.tar.xz": "d00498f47d49219f032e2c5eeebdfc3d32317c0dc3d3fd7125327445bc482cb4", - "cargo-1.86.0-x86_64-unknown-linux-gnu.tar.xz": "c5c1590f7e9246ad9f4f97cfe26ffa92707b52a769726596a9ef81565ebd908b", - "cargo-1.86.0-x86_64-apple-darwin.tar.xz": "af163eb02d1a178044d1b4f2375960efd47130f795f6e33d09e345454bb26f4e", - "cargo-1.86.0-aarch64-apple-darwin.tar.xz": "3cb13873d48c3e1e4cc684d42c245226a11fba52af6b047c3346ed654e7a05c0", - "cargo-1.86.0-x86_64-pc-windows-msvc.tar.xz": "e57a9d89619b5604899bac443e68927bdd371e40f2e03e18950b6ceb3eb67966", - "llvm-tools-1.86.0-x86_64-unknown-linux-gnu.tar.xz": "282145ab7a63c98b625856f44b905b4dc726b497246b824632a5790debe95a78", - "llvm-tools-1.86.0-x86_64-apple-darwin.tar.xz": "b55706e92f7da989207c50c13c7add483a9fedd233bc431b106eca2a8f151ec9", - "llvm-tools-1.86.0-aarch64-apple-darwin.tar.xz": "04d3618c686845853585f036e3211eb9e18f2d290f4610a7a78bdc1fcce1ebd9", - "llvm-tools-1.86.0-x86_64-pc-windows-msvc.tar.xz": "721a17cc8dc219177e4277a3592253934ef08daa1e1b12eda669a67d15fad8dd", - "rust-std-1.86.0-x86_64-unknown-linux-gnu.tar.xz": "67be7184ea388d8ce0feaf7fdea46f1775cfc2970930264343b3089898501d37", - "rust-std-1.86.0-x86_64-apple-darwin.tar.xz": "3b1140d54870a080080e84700143f4a342fbd02a410a319b05d9c02e7dcf44cc", - "rust-std-1.86.0-aarch64-apple-darwin.tar.xz": "0fb121fb3b8fa9027d79ff598500a7e5cd086ddbc3557482ed3fdda00832c61b", - "rust-std-1.86.0-x86_64-pc-windows-msvc.tar.xz": "3d5354b7b9cb950b58bff3fce18a652aa374bb30c8f70caebd3bd0b43cb41a33", + "2025-08-01/rustc-nightly-x86_64-unknown-linux-gnu.tar.xz": "9bbeaf5d3fc7247d31463a9083aa251c995cc50662c8219e7a2254d76a72a9a4", + "2025-08-01/rustc-nightly-x86_64-apple-darwin.tar.xz": "c9ea539a8eff0d5d162701f99f9e1aabe14dd0dfb420d62362817a5d09219de7", + "2025-08-01/rustc-nightly-aarch64-apple-darwin.tar.xz": "ae83feebbc39cfd982e4ecc8297731fe79c185173aee138467b334c5404b3773", + "2025-08-01/rustc-nightly-x86_64-pc-windows-msvc.tar.xz": "9f170c30d802a349be60cf52ec46260802093cb1013ad667fc0d528b7b10152f", + "2025-08-01/clippy-nightly-x86_64-unknown-linux-gnu.tar.xz": "9ae5f3cd8f557c4f6df522597c69d14398cf604cfaed2b83e767c4b77a7eaaf6", + "2025-08-01/clippy-nightly-x86_64-apple-darwin.tar.xz": "983cb9ee0b6b968188e04ab2d33743d54764b2681ce565e1b3f2b9135c696a3e", + "2025-08-01/clippy-nightly-aarch64-apple-darwin.tar.xz": "ed2219dbc49d088225e1b7c5c4390fa295066e071fddaa2714018f6bb39ddbf0", + "2025-08-01/clippy-nightly-x86_64-pc-windows-msvc.tar.xz": "911f40ab5cbdd686f40e00965271fe47c4805513a308ed01f30eafb25b448a50", + "2025-08-01/cargo-nightly-x86_64-unknown-linux-gnu.tar.xz": "106463c284e48e4904c717471eeec2be5cc83a9d2cae8d6e948b52438cad2e69", + "2025-08-01/cargo-nightly-x86_64-apple-darwin.tar.xz": "6ad35c40efc41a8c531ea43235058347b6902d98a9693bf0aed7fc16d5590cef", + "2025-08-01/cargo-nightly-aarch64-apple-darwin.tar.xz": "dd28c365e9d298abc3154c797720ad36a0058f131265c9978b4c8e4e37012c8a", + "2025-08-01/cargo-nightly-x86_64-pc-windows-msvc.tar.xz": "7b431286e12d6b3834b038f078389a00cac73f351e8c3152b2504a3c06420b3b", + "2025-08-01/llvm-tools-nightly-x86_64-unknown-linux-gnu.tar.xz": "e342e305d7927cc288d386983b2bc253cfad3776b113386e903d0b302648ef47", + "2025-08-01/llvm-tools-nightly-x86_64-apple-darwin.tar.xz": "e44dd3506524d85c37b3a54bcc91d01378fd2c590b2db5c5974d12f05c1b84d1", + "2025-08-01/llvm-tools-nightly-aarch64-apple-darwin.tar.xz": "0c1b5f46dd81be4a9227b10283a0fcaa39c14fea7e81aea6fd6d9887ff6cdc41", + "2025-08-01/llvm-tools-nightly-x86_64-pc-windows-msvc.tar.xz": "423e5fd11406adccbc31b8456ceb7375ce055cdf45e90d2c3babeb2d7f58383f", + "2025-08-01/rust-std-nightly-x86_64-unknown-linux-gnu.tar.xz": "3c0ceb46a252647a1d4c7116d9ccae684fa5e42aaf3296419febd2c962c3b41d", + "2025-08-01/rust-std-nightly-x86_64-apple-darwin.tar.xz": "3be416003cab10f767390a753d1d16ae4d26c7421c03c98992cf1943e5b0efe8", + "2025-08-01/rust-std-nightly-aarch64-apple-darwin.tar.xz": "4046ac0ef951cb056b5028a399124f60999fa37792eab69d008d8d7965f389b4", + "2025-08-01/rust-std-nightly-x86_64-pc-windows-msvc.tar.xz": "191ed9d8603c3a4fe5a7bbbc2feb72049078dae2df3d3b7d5dedf3abbf823e6e", }, versions = [RUST_VERSION], ) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 84b71da2ec9..242a1af3ed5 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,8 +1,10 @@ -# This file specifies the Rust version used to develop and test the -# extractors written in rust. It is set to the lowest version of Rust -# we want to support. +# This file specifies the Rust version used to develop the extractors written +# in rust. Notice that this is just used by using `cargo`-related tools in a +# local dev environment. The actual version used to build the released packs +# is specified in `MODULE.bazel` in the internal repository (typically +# reflected by `MODULE.bazel` in this repository). [toolchain] -channel = "1.86" +channel = "1.88" profile = "minimal" components = [ "clippy", "rustfmt" ] diff --git a/rust/ast-generator/src/main.rs b/rust/ast-generator/src/main.rs index 1bcf7f52dc3..d612985ff9f 100644 --- a/rust/ast-generator/src/main.rs +++ b/rust/ast-generator/src/main.rs @@ -23,7 +23,7 @@ fn class_name(type_name: &str) -> String { "AsmOptions" => "AsmOptionsList".to_owned(), "MacroStmts" => "MacroBlockExpr".to_owned(), _ if type_name.starts_with("Record") => type_name.replacen("Record", "Struct", 1), - _ if type_name.ends_with("Type") => format!("{}Repr", type_name), + _ if type_name.ends_with("Type") => format!("{type_name}Repr"), _ => type_name.to_owned(), } } @@ -171,7 +171,7 @@ fn get_trait_fields(trait_name: &str) -> Vec { ], "HasArgList" => vec![FieldInfo::optional("arg_list", "ArgList")], "HasDocComments" => vec![], - _ => panic!("Unknown trait {}", trait_name), + _ => panic!("Unknown trait {trait_name}"), } } diff --git a/rust/extractor/src/rust_analyzer.rs b/rust/extractor/src/rust_analyzer.rs index bed6e66c9b7..d477b13b5d0 100644 --- a/rust/extractor/src/rust_analyzer.rs +++ b/rust/extractor/src/rust_analyzer.rs @@ -51,7 +51,7 @@ impl<'a> RustAnalyzer<'a> { config: &CargoConfig, load_config: &LoadCargoConfig, ) -> Option<(RootDatabase, Vfs)> { - let progress = |t| (trace!("progress: {}", t)); + let progress = |t| trace!("progress: {t}"); let manifest = project.manifest_path(); match load_workspace_at(manifest.as_ref(), config, load_config, &progress) { Ok((db, vfs, _macro_server)) => Some((db, vfs)), @@ -67,7 +67,7 @@ impl<'a> RustAnalyzer<'a> { fn get_file_data( &self, path: &Path, - ) -> Result<(&Semantics, EditionedFileId, FileText), &str> { + ) -> Result<(&Semantics<'_, RootDatabase>, EditionedFileId, FileText), &str> { match self { RustAnalyzer::WithoutSemantics { reason } => Err(reason), RustAnalyzer::WithSemantics { vfs, semantics } => { @@ -82,7 +82,7 @@ impl<'a> RustAnalyzer<'a> { } } - pub fn parse(&self, path: &Path) -> ParseResult { + pub fn parse(&self, path: &Path) -> ParseResult<'_> { match self.get_file_data(path) { Ok((semantics, file_id, input)) => { let source_file = semantics.parse(file_id); diff --git a/rust/extractor/src/translate/base.rs b/rust/extractor/src/translate/base.rs index b5150029134..ccd6143fb84 100644 --- a/rust/extractor/src/translate/base.rs +++ b/rust/extractor/src/translate/base.rs @@ -549,9 +549,7 @@ impl<'a> Translator<'a> { .map(|p| format!("[{p}; {size}]")); } if let Some(it) = ty.as_slice() { - return self - .canonical_path_from_type(it) - .map(|p| format!("[{}]", p)); + return self.canonical_path_from_type(it).map(|p| format!("[{p}]")); } if let Some(it) = ty.as_builtin() { return Some(it.name().as_str().to_owned()); @@ -651,7 +649,7 @@ impl<'a> Translator<'a> { // if we have a Hir entity, it means we have semantics let sema = self.semantics.as_ref().unwrap(); match item.origin(sema.db) { - CrateOrigin::Rustc { name } => format!("rustc:{}", name), + CrateOrigin::Rustc { name } => format!("rustc:{name}"), CrateOrigin::Local { repo, name } => format!( "repo:{}:{}", repo.unwrap_or_default(), @@ -660,7 +658,7 @@ impl<'a> Translator<'a> { CrateOrigin::Library { repo, name } => { format!("repo:{}:{}", repo.unwrap_or_default(), name) } - CrateOrigin::Lang(it) => format!("lang:{}", it), + CrateOrigin::Lang(it) => format!("lang:{it}"), } } diff --git a/rust/extractor/src/trap.rs b/rust/extractor/src/trap.rs index a7cb43a6432..3a6dbeb24e1 100644 --- a/rust/extractor/src/trap.rs +++ b/rust/extractor/src/trap.rs @@ -16,7 +16,7 @@ pub trait AsTrapKeyPart { impl AsTrapKeyPart for UntypedLabel { fn as_key_part(&self) -> String { - format!("{{{}}}", self) + format!("{{{self}}}") } } diff --git a/rust/rust-toolchain.toml b/rust/rust-toolchain.toml deleted file mode 100644 index 680f37655d6..00000000000 --- a/rust/rust-toolchain.toml +++ /dev/null @@ -1,8 +0,0 @@ -# This file specifies the Rust version used to develop and test the rust -# extractor. It is set to the lowest version of Rust we want to support. -# IMPORTANT: this can also have an impact on QL test results - -[toolchain] -channel = "1.86" -profile = "minimal" -components = [ "clippy", "rustfmt", "rust-src" ] diff --git a/shared/tree-sitter-extractor/src/generator/mod.rs b/shared/tree-sitter-extractor/src/generator/mod.rs index 5e58611092b..c886ec98eeb 100644 --- a/shared/tree-sitter-extractor/src/generator/mod.rs +++ b/shared/tree-sitter-extractor/src/generator/mod.rs @@ -259,8 +259,8 @@ fn add_field_for_column_storage<'a>( /// values are their integer representations. fn convert_nodes( nodes: &node_types::NodeTypeMap, -) -> (Vec, Set<&str>, Map<&str, usize>) { - let mut entries: Vec = Vec::new(); +) -> (Vec>, Set<&str>, Map<&str, usize>) { + let mut entries = Vec::new(); let mut ast_node_members: Set<&str> = Set::new(); let token_kinds: Map<&str, usize> = nodes .iter() diff --git a/shared/tree-sitter-extractor/src/generator/ql_gen.rs b/shared/tree-sitter-extractor/src/generator/ql_gen.rs index 2cfaf5715ca..225cad3a66d 100644 --- a/shared/tree-sitter-extractor/src/generator/ql_gen.rs +++ b/shared/tree-sitter-extractor/src/generator/ql_gen.rs @@ -200,7 +200,7 @@ pub fn create_token_class<'a>(token_type: &'a str, tokeninfo: &'a str) -> ql::Cl } // Creates the `ReservedWord` class. -pub fn create_reserved_word_class(db_name: &str) -> ql::Class { +pub fn create_reserved_word_class(db_name: &str) -> ql::Class<'_> { let class_name = "ReservedWord"; let get_a_primary_ql_class = create_get_a_primary_ql_class(class_name, true); ql::Class { @@ -237,7 +237,7 @@ fn create_none_predicate<'a>( /// Creates an overridden `getAPrimaryQlClass` predicate that returns the given /// name. -fn create_get_a_primary_ql_class(class_name: &str, is_final: bool) -> ql::Predicate { +fn create_get_a_primary_ql_class(class_name: &str, is_final: bool) -> ql::Predicate<'_> { ql::Predicate { qldoc: Some(String::from( "Gets the name of the primary QL class for this element.", @@ -318,7 +318,7 @@ pub fn create_get_node_file_predicate<'a>( } } -pub fn create_discardable_ast_node_predicate(ast_node_name: &str) -> ql::Predicate { +pub fn create_discardable_ast_node_predicate(ast_node_name: &str) -> ql::Predicate<'_> { ql::Predicate { name: "discardableAstNode", qldoc: Some(String::from( @@ -352,7 +352,7 @@ pub fn create_discardable_ast_node_predicate(ast_node_name: &str) -> ql::Predica } } -pub fn create_discard_ast_node_predicate(ast_node_name: &str) -> ql::Predicate { +pub fn create_discard_ast_node_predicate(ast_node_name: &str) -> ql::Predicate<'_> { ql::Predicate { name: "discardAstNode", qldoc: Some(String::from( @@ -692,8 +692,8 @@ fn create_field_getters<'a>( } /// Converts the given node types into CodeQL classes wrapping the dbscheme. -pub fn convert_nodes(nodes: &node_types::NodeTypeMap) -> Vec { - let mut classes: Vec = Vec::new(); +pub fn convert_nodes(nodes: &node_types::NodeTypeMap) -> Vec> { + let mut classes = Vec::new(); let mut token_kinds = BTreeSet::new(); for (type_name, node) in nodes { if let node_types::EntryKind::Token { .. } = &node.kind {