From 6a2e9d3ada1bf3781739c38880ea68b50664e122 Mon Sep 17 00:00:00 2001 From: Simon Buchan Date: Wed, 4 Oct 2023 17:28:10 +1300 Subject: [PATCH 1/3] chore: Update rust-toolchain to nightly-2023-10-04 --- Cargo.lock | 4 ++-- Cargo.toml | 1 + rust-toolchain | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cfc9616618..f349ba0326 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1678,9 +1678,9 @@ checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" [[package]] name = "proc-macro2" -version = "1.0.59" +version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6aeca18b86b413c660b781aa319e4e2648a3e6f9eadc9b47e9038e6fe9f3451b" +checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328" dependencies = [ "unicode-ident", ] diff --git a/Cargo.toml b/Cargo.toml index ebc5582bac..c6651ed34e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,6 @@ [workspace] members = ["crates/stc", "crates/binding_wasm"] +resolver = "2" [profile.release] lto = "off" diff --git a/rust-toolchain b/rust-toolchain index 79183b3f54..a4a1687774 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2023-05-25 \ No newline at end of file +nightly-2023-10-04 \ No newline at end of file From 82705a69cde7e118eff41b65a646ef4c07d2b998 Mon Sep 17 00:00:00 2001 From: Simon Buchan Date: Thu, 5 Oct 2023 13:34:34 +1300 Subject: [PATCH 2/3] chore: fixes for cargo fmt / clippy --- crates/stc_ts_builtin_macro/src/lib.rs | 10 +++++----- crates/stc_ts_errors/src/lib.rs | 2 +- .../src/analyzer/assign/function.rs | 4 +--- crates/stc_ts_file_analyzer/src/analyzer/assign/tpl.rs | 1 + .../stc_ts_file_analyzer/src/analyzer/expr/call_new.rs | 3 ++- .../stc_ts_file_analyzer/src/analyzer/function/mod.rs | 6 +----- .../src/analyzer/generic/inference.rs | 10 +++++----- .../stc_ts_file_analyzer/src/analyzer/generic/mod.rs | 5 +---- .../stc_ts_file_analyzer/src/analyzer/relation/mod.rs | 1 + .../stc_ts_file_analyzer/src/analyzer/types/keyof.rs | 2 +- crates/stc_ts_file_analyzer/src/type_facts.rs | 10 +++++----- crates/stc_ts_file_analyzer/src/util/graph.rs | 4 ++-- 12 files changed, 26 insertions(+), 32 deletions(-) diff --git a/crates/stc_ts_builtin_macro/src/lib.rs b/crates/stc_ts_builtin_macro/src/lib.rs index f931ce8dad..c1aaf002be 100644 --- a/crates/stc_ts_builtin_macro/src/lib.rs +++ b/crates/stc_ts_builtin_macro/src/lib.rs @@ -5,12 +5,12 @@ #[macro_use] extern crate pmutil; -use std::{collections::HashMap, fs::read_dir, path::Path, sync::Arc}; +use std::{collections::HashMap, env, fs::read_dir, path::Path}; use inflector::Inflector; use pmutil::Quote; use proc_macro2::Span; -use swc_common::{comments::SingleThreadedComments, FilePathMapping, SourceMap}; +use swc_common::{comments::SingleThreadedComments, sync::Lrc, FilePathMapping, SourceMap}; use swc_ecma_parser::{lexer::Lexer, Parser, StringInput, Syntax, TsConfig}; use swc_macros_common::{call_site, print}; use syn::{punctuated::Punctuated, Token}; @@ -18,7 +18,7 @@ use syn::{punctuated::Punctuated, Token}; #[proc_macro] pub fn builtin(_: proc_macro::TokenStream) -> proc_macro::TokenStream { swc_common::GLOBALS.set(&swc_common::Globals::new(), || { - let cm = Arc::new(SourceMap::new(FilePathMapping::empty())); + let cm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let mut deps = HashMap::>::default(); @@ -37,11 +37,11 @@ pub fn builtin(_: proc_macro::TokenStream) -> proc_macro::TokenStream { let mut contents = HashMap::::default(); - let dir_str = ::std::env::var("CARGO_MANIFEST_DIR").expect("failed to read CARGO_MANIFEST_DIR"); + let dir_str = env::var("CARGO_MANIFEST_DIR").expect("failed to read CARGO_MANIFEST_DIR"); let dir = Path::new(&dir_str).join("lib"); let mut tokens = q(); - let mut files = read_dir(&dir) + let mut files = read_dir(dir) .expect("failed to read $CARGO_MANIFEST_DIR/lib") .filter_map(|entry| { let entry = entry.expect("failed to read file of directory"); diff --git a/crates/stc_ts_errors/src/lib.rs b/crates/stc_ts_errors/src/lib.rs index 538f8cb25a..6a649da3ad 100644 --- a/crates/stc_ts_errors/src/lib.rs +++ b/crates/stc_ts_errors/src/lib.rs @@ -62,7 +62,7 @@ impl From for Error { impl Error { #[track_caller] pub fn context(self, context: impl Display) -> Error { - return self.context_impl(Location::caller(), context); + self.context_impl(Location::caller(), context) } #[cfg_attr(not(debug_assertions), inline(always))] diff --git a/crates/stc_ts_file_analyzer/src/analyzer/assign/function.rs b/crates/stc_ts_file_analyzer/src/analyzer/assign/function.rs index fe0285e131..f988aaae3c 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/assign/function.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/assign/function.rs @@ -903,9 +903,7 @@ impl Analyzer<'_, '_> { let l = li.next(); let r = ri.next(); - let (Some(l), Some(r)) = (l, r) else { - break - }; + let (Some(l), Some(r)) = (l, r) else { break }; // TODO(kdy1): What should we do? if opts.allow_assignment_to_param { diff --git a/crates/stc_ts_file_analyzer/src/analyzer/assign/tpl.rs b/crates/stc_ts_file_analyzer/src/analyzer/assign/tpl.rs index c067241822..014d41ec24 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/assign/tpl.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/assign/tpl.rs @@ -27,6 +27,7 @@ impl Analyzer<'_, '_> { /// orders. /// /// After splitting, we can check if each element is assignable. + #[allow(clippy::needless_pass_by_ref_mut)] pub(crate) fn assign_to_tpl(&mut self, data: &mut AssignData, l: &TplType, r_ty: &Type, opts: AssignOpts) -> VResult<()> { let span = opts.span; let r_ty = r_ty.normalize(); diff --git a/crates/stc_ts_file_analyzer/src/analyzer/expr/call_new.rs b/crates/stc_ts_file_analyzer/src/analyzer/expr/call_new.rs index 0aacaa2b03..ba57f513ef 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/expr/call_new.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/expr/call_new.rs @@ -527,8 +527,8 @@ impl Analyzer<'_, '_> { let types = u .types .iter() - .cloned() .filter(|callee| !matches!(callee.normalize(), Type::Module(..) | Type::Namespace(..))) + .cloned() .collect::>(); match types.len() { @@ -3458,6 +3458,7 @@ impl Analyzer<'_, '_> { /// /// should make type of `subscriber` `SafeSubscriber`, not `Subscriber`. /// I (kdy1) don't know why. + #[allow(clippy::needless_pass_by_ref_mut)] fn add_call_facts(&mut self, params: &[FnParam], args: &[RExprOrSpread], ret_ty: &mut Type) { if !self.ctx.in_cond { return; diff --git a/crates/stc_ts_file_analyzer/src/analyzer/function/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/function/mod.rs index 7f215f3a10..74b845aee3 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/function/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/function/mod.rs @@ -348,11 +348,7 @@ impl Analyzer<'_, '_> { // true, // // Allow overriding // true, - // ) { - // Ok(()) => {} - // Err(err) => { - // self.storage.report(err); - // } + // ) { Ok(()) => {} Err(err) => { self.storage.report(err); } // } // } diff --git a/crates/stc_ts_file_analyzer/src/analyzer/generic/inference.rs b/crates/stc_ts_file_analyzer/src/analyzer/generic/inference.rs index ed0aea16cc..2e3d7f63ac 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/generic/inference.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/generic/inference.rs @@ -116,8 +116,8 @@ pub(crate) struct InferTypeOpts { } bitflags! { + #[derive(Default)] pub struct InferencePriority: i32 { - const None = 0; /// Naked type variable in union or intersection type const NakedTypeVariable = 1 << 0; /// Speculative tuple inference @@ -153,10 +153,10 @@ bitflags! { } } -impl Default for InferencePriority { - fn default() -> Self { - Self::None - } +impl InferencePriority { + // Defining outside bitflags! to avoid clippy::bad_bit_mask lint in generated + // code. + pub const None: Self = Self::empty(); } impl Analyzer<'_, '_> { diff --git a/crates/stc_ts_file_analyzer/src/analyzer/generic/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/generic/mod.rs index 3e4309432e..41e306ac24 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/generic/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/generic/mod.rs @@ -111,10 +111,7 @@ impl Analyzer<'_, '_> { #[cfg(debug_assertions)] let _tracing = dev_span!("infer_arg_types"); - warn!( - "infer_arg_types: {:?}", - type_params.iter().map(|p| format!("{}, ", p.name)).collect::() - ); + warn!("infer_arg_types: {:?}", type_params.iter().map(|p| &p.name).join(", ")); let timer = PerfTimer::noop(); diff --git a/crates/stc_ts_file_analyzer/src/analyzer/relation/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/relation/mod.rs index 9e4dd333f6..59bb61bf45 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/relation/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/relation/mod.rs @@ -25,6 +25,7 @@ impl Analyzer<'_, '_> { self.is_type_related_to_inner(&mut data, source, target, relation) } + #[allow(clippy::needless_pass_by_ref_mut)] fn is_type_related_to_inner(&mut self, data: &mut IsRelatedData, source: &Type, target: &Type, relation: Relation) -> bool { if source.type_eq(target) { return true; diff --git a/crates/stc_ts_file_analyzer/src/analyzer/types/keyof.rs b/crates/stc_ts_file_analyzer/src/analyzer/types/keyof.rs index d43a378a89..2c60f0e9e7 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/types/keyof.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/types/keyof.rs @@ -333,7 +333,7 @@ impl Analyzer<'_, '_> { } } Type::EnumVariant(e) => { - if matches!(e.name, None) && (e.def.has_num || e.def.has_str) { + if e.name.is_none() && (e.def.has_num || e.def.has_str) { return self.keyof( span, &if e.def.has_num && e.def.has_str { diff --git a/crates/stc_ts_file_analyzer/src/type_facts.rs b/crates/stc_ts_file_analyzer/src/type_facts.rs index 1b36415de9..0fed6457cb 100644 --- a/crates/stc_ts_file_analyzer/src/type_facts.rs +++ b/crates/stc_ts_file_analyzer/src/type_facts.rs @@ -3,15 +3,15 @@ use bitflags::bitflags; use swc_common::add_bitflags; -impl Default for TypeFacts { - fn default() -> Self { - Self::None - } +impl TypeFacts { + // Defining outside bitflags! to avoid clippy::bad_bit_mask lint in generated + // code. + pub const None: Self = Self::empty(); } bitflags! { + #[derive(Default)] pub struct TypeFacts: u32 { - const None = 0; /// typeof x === "string" const TypeofEQString = 1 << 0; /// typeof x === "number" diff --git a/crates/stc_ts_file_analyzer/src/util/graph.rs b/crates/stc_ts_file_analyzer/src/util/graph.rs index c504ffcd57..b31924109e 100644 --- a/crates/stc_ts_file_analyzer/src/util/graph.rs +++ b/crates/stc_ts_file_analyzer/src/util/graph.rs @@ -41,7 +41,7 @@ pub(crate) struct NodeId(usize, PhantomData); impl Clone for NodeId { fn clone(&self) -> Self { - NodeId(self.0, self.1) + *self } } @@ -57,7 +57,7 @@ impl Eq for NodeId {} impl PartialOrd for NodeId { fn partial_cmp(&self, other: &Self) -> Option { - self.0.partial_cmp(&other.0) + Some(self.cmp(other)) } } From bdd2e2f77ecde9aeacbc44e6d512b12d9eac939d Mon Sep 17 00:00:00 2001 From: Simon Buchan Date: Thu, 5 Oct 2023 13:50:48 +1300 Subject: [PATCH 3/3] chore: missed clippy warning in tests --- crates/stc_ts_type_checker/tests/tsc.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/stc_ts_type_checker/tests/tsc.rs b/crates/stc_ts_type_checker/tests/tsc.rs index b67662be5a..e5fa2221ee 100644 --- a/crates/stc_ts_type_checker/tests/tsc.rs +++ b/crates/stc_ts_type_checker/tests/tsc.rs @@ -312,7 +312,6 @@ fn do_test(file_name: &Path, spec: TestSpec, use_target: bool) -> Result<(), Std if is_file_similar(err.file.as_deref(), Some(last)) { // If this is the last file, we have to shift the errors. err.line += err_shift_n; - } else { } } else { // If sub files is empty, it means that it's a single-file test, and