diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index 819fa4f1dd..3a24be139d 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -114,6 +114,12 @@ runs: if: ${{ inputs.os == 'macOS' || inputs.os == 'Android' }} uses: dtolnay/rust-toolchain@stable + # TODO: Remove once `imports_granularity` rustfmt option is stable. https://rust-lang.github.io/rustfmt/?version=v1.9.0&search=group#imports_granularity + - name: 'Install Nightly Rust toolchain for linting' + if: ${{ inputs.type == 'lint' }} + shell: bash + run: rustup toolchain install nightly --component rustfmt + - name: 'Install wasm-tools' if: ${{ inputs.type == 'build' }} shell: bash diff --git a/Libraries/LibGfx/Rust/src/yuv.rs b/Libraries/LibGfx/Rust/src/yuv.rs index 1f2d157bc3..646a8f2950 100644 --- a/Libraries/LibGfx/Rust/src/yuv.rs +++ b/Libraries/LibGfx/Rust/src/yuv.rs @@ -4,7 +4,9 @@ * SPDX-License-Identifier: BSD-2-Clause */ -use yuv::{YuvPlanarImage, YuvRange, YuvStandardMatrix}; +use yuv::YuvPlanarImage; +use yuv::YuvRange; +use yuv::YuvStandardMatrix; #[repr(u8)] pub enum YUVRange { diff --git a/Libraries/LibJS/Rust/build.rs b/Libraries/LibJS/Rust/build.rs index 98aa80a5ee..85fc3781ec 100644 --- a/Libraries/LibJS/Rust/build.rs +++ b/Libraries/LibJS/Rust/build.rs @@ -10,9 +10,14 @@ //! code instead of C++. The generated code lives in $OUT_DIR/instruction_generated.rs //! and is included! from src/bytecode/instruction.rs. -use bytecode_def::{ - Field, OpDef, STRUCT_ALIGN, compute_layouts, field_type_info, find_m_length_offset, round_up, user_fields, -}; +use bytecode_def::Field; +use bytecode_def::OpDef; +use bytecode_def::STRUCT_ALIGN; +use bytecode_def::compute_layouts; +use bytecode_def::field_type_info; +use bytecode_def::find_m_length_offset; +use bytecode_def::round_up; +use bytecode_def::user_fields; use std::env; use std::fs; use std::io::Write; diff --git a/Libraries/LibJS/Rust/src/ast.rs b/Libraries/LibJS/Rust/src/ast.rs index 2965f1acf5..124f1b43a3 100644 --- a/Libraries/LibJS/Rust/src/ast.rs +++ b/Libraries/LibJS/Rust/src/ast.rs @@ -24,9 +24,11 @@ use std::ffi::c_void; use std::fmt; -use std::ops::{Index, IndexMut}; +use std::ops::Index; +use std::ops::IndexMut; use std::sync::Arc; -use std::sync::atomic::{AtomicPtr, Ordering}; +use std::sync::atomic::AtomicPtr; +use std::sync::atomic::Ordering; use crate::fast_hash::HashMap; diff --git a/Libraries/LibJS/Rust/src/bytecode/codegen.rs b/Libraries/LibJS/Rust/src/bytecode/codegen.rs index 43137e13cb..e4856e6b0e 100644 --- a/Libraries/LibJS/Rust/src/bytecode/codegen.rs +++ b/Libraries/LibJS/Rust/src/bytecode/codegen.rs @@ -41,17 +41,29 @@ use std::collections::HashSet; use num_bigint::BigInt; -use num_traits::{One, Signed, ToPrimitive, Zero}; +use num_traits::One; +use num_traits::Signed; +use num_traits::ToPrimitive; +use num_traits::Zero; use crate::ast::*; use crate::lexer::ch; use crate::u32_from_usize; -use super::ffi::{AbstractOperationKind, WellKnownSymbolKind}; -use super::generator::{ - BlockBoundaryType, ConstantValue, FinallyContext, Generator, PendingClassBlueprint, PendingClassElement, - PendingLiteralValueKind, PendingSharedFunctionData, ScopedOperand, choose_dst, constant_to_boolean, parse_bigint, -}; +use super::ffi::AbstractOperationKind; +use super::ffi::WellKnownSymbolKind; +use super::generator::BlockBoundaryType; +use super::generator::ConstantValue; +use super::generator::FinallyContext; +use super::generator::Generator; +use super::generator::PendingClassBlueprint; +use super::generator::PendingClassElement; +use super::generator::PendingLiteralValueKind; +use super::generator::PendingSharedFunctionData; +use super::generator::ScopedOperand; +use super::generator::choose_dst; +use super::generator::constant_to_boolean; +use super::generator::parse_bigint; use super::instruction::Instruction; use super::operand::*; @@ -6502,7 +6514,8 @@ fn generate_class_expression( /// Synthesize a default constructor SharedFunctionInstanceData. fn emit_default_constructor(generator: &mut Generator, has_super: bool) -> u32 { - use crate::parser::{Parser, ProgramType}; + use crate::parser::Parser; + use crate::parser::ProgramType; // Wrap in "function" keyword so it parses as a FunctionDeclaration. let source: Utf16String = if has_super { diff --git a/Libraries/LibJS/Rust/src/bytecode/ffi.rs b/Libraries/LibJS/Rust/src/bytecode/ffi.rs index 1d0296a843..c3bf5e5df0 100644 --- a/Libraries/LibJS/Rust/src/bytecode/ffi.rs +++ b/Libraries/LibJS/Rust/src/bytecode/ffi.rs @@ -24,10 +24,13 @@ use std::ffi::c_void; use std::mem::align_of; -use super::generator::{ - AssembledBytecode, ConstantValue, ExceptionHandler, Generator, PendingClassBlueprint, PendingClassElement, - PendingLiteralValueKind, -}; +use super::generator::AssembledBytecode; +use super::generator::ConstantValue; +use super::generator::ExceptionHandler; +use super::generator::Generator; +use super::generator::PendingClassBlueprint; +use super::generator::PendingClassElement; +use super::generator::PendingLiteralValueKind; use crate::ast::Utf16String; use crate::bytecode::basic_block::SourceMapEntry; use crate::u32_from_usize; diff --git a/Libraries/LibJS/Rust/src/bytecode/generator.rs b/Libraries/LibJS/Rust/src/bytecode/generator.rs index 966c86b0f3..e26c2901e9 100644 --- a/Libraries/LibJS/Rust/src/bytecode/generator.rs +++ b/Libraries/LibJS/Rust/src/bytecode/generator.rs @@ -10,14 +10,24 @@ //! needed for bytecode generation from the AST. use std::cell::RefCell; -use std::collections::{HashMap, HashSet}; +use std::collections::HashMap; +use std::collections::HashSet; use std::rc::Rc; -use super::basic_block::{BasicBlock, SourceMapEntry}; -use super::ffi::{AbstractOperationKind, WellKnownSymbolKind}; +use super::basic_block::BasicBlock; +use super::basic_block::SourceMapEntry; +use super::ffi::AbstractOperationKind; +use super::ffi::WellKnownSymbolKind; use super::instruction::Instruction; use super::operand::*; -use crate::ast::{AstArena, FunctionData, FunctionId, FunctionTable, IdentifierId, LocalType, Position, Utf16String}; +use crate::ast::AstArena; +use crate::ast::FunctionData; +use crate::ast::FunctionId; +use crate::ast::FunctionTable; +use crate::ast::IdentifierId; +use crate::ast::LocalType; +use crate::ast::Position; +use crate::ast::Utf16String; use crate::u32_from_usize; use std::sync::Arc; diff --git a/Libraries/LibJS/Rust/src/bytecode/validator.rs b/Libraries/LibJS/Rust/src/bytecode/validator.rs index f9a6cd1251..f133ba2ce8 100644 --- a/Libraries/LibJS/Rust/src/bytecode/validator.rs +++ b/Libraries/LibJS/Rust/src/bytecode/validator.rs @@ -17,7 +17,9 @@ //! the Rust `Instruction` enum, so it works on freshly-encoded as well as //! freshly-deserialized bytecode. -use super::instruction::{NUM_OPCODES, instruction_length_from_bytes, validate_instruction}; +use super::instruction::NUM_OPCODES; +use super::instruction::instruction_length_from_bytes; +use super::instruction::validate_instruction; /// Sentinel u32 used by `Operand::INVALID` and by `Optional<*TableIndex>` for /// "no value". Mirrors the C++ `0xFFFFFFFF` constant used throughout diff --git a/Libraries/LibJS/Rust/src/bytecode_cache.rs b/Libraries/LibJS/Rust/src/bytecode_cache.rs index 882183e59d..71ffbc7a65 100644 --- a/Libraries/LibJS/Rust/src/bytecode_cache.rs +++ b/Libraries/LibJS/Rust/src/bytecode_cache.rs @@ -15,18 +15,31 @@ use std::ffi::c_void; use std::ops::Range; use std::rc::Rc; +use crate::CompiledProgram; +use crate::CompiledProgramBytecode; +use crate::ModuleCallbacks; +use crate::ast; use crate::bytecode::basic_block::SourceMapEntry; -use crate::bytecode::ffi::{ - AbstractOperationKind, ConstantTag, FFISharedFunctionData, FFIUtf16Slice, WellKnownSymbolKind, -}; -use crate::bytecode::generator::{ - AssembledBytecode, ConstantValue, ExceptionHandler, FunctionSfdMetadata, Generator, PendingClassBlueprint, - PendingClassElement, PendingLiteralValueKind, PendingSharedFunctionData, PrecompiledFunction, -}; -use crate::bytecode::validator::{ - FFIExceptionHandlerOffsets, FFIValidatorBounds, ValidationErrorKind, validate_bytecode, -}; -use crate::{CompiledProgram, CompiledProgramBytecode, ModuleCallbacks, ast, u32_from_usize}; +use crate::bytecode::ffi::AbstractOperationKind; +use crate::bytecode::ffi::ConstantTag; +use crate::bytecode::ffi::FFISharedFunctionData; +use crate::bytecode::ffi::FFIUtf16Slice; +use crate::bytecode::ffi::WellKnownSymbolKind; +use crate::bytecode::generator::AssembledBytecode; +use crate::bytecode::generator::ConstantValue; +use crate::bytecode::generator::ExceptionHandler; +use crate::bytecode::generator::FunctionSfdMetadata; +use crate::bytecode::generator::Generator; +use crate::bytecode::generator::PendingClassBlueprint; +use crate::bytecode::generator::PendingClassElement; +use crate::bytecode::generator::PendingLiteralValueKind; +use crate::bytecode::generator::PendingSharedFunctionData; +use crate::bytecode::generator::PrecompiledFunction; +use crate::bytecode::validator::FFIExceptionHandlerOffsets; +use crate::bytecode::validator::FFIValidatorBounds; +use crate::bytecode::validator::ValidationErrorKind; +use crate::bytecode::validator::validate_bytecode; +use crate::u32_from_usize; const MAGIC: &[u8; 8] = b"LBJSBC\0\0"; const FORMAT_VERSION: u32 = 12; @@ -1050,10 +1063,12 @@ unsafe fn materialize_script_declaration_metadata( gdi_context: *mut c_void, ) -> bool { unsafe { - use crate::bytecode::ffi::{ - script_gdi_push_annex_b_name, script_gdi_push_function, script_gdi_push_lexical_binding, - script_gdi_push_lexical_name, script_gdi_push_var_name, script_gdi_push_var_scoped_name, - }; + use crate::bytecode::ffi::script_gdi_push_annex_b_name; + use crate::bytecode::ffi::script_gdi_push_function; + use crate::bytecode::ffi::script_gdi_push_lexical_binding; + use crate::bytecode::ffi::script_gdi_push_lexical_name; + use crate::bytecode::ffi::script_gdi_push_var_name; + use crate::bytecode::ffi::script_gdi_push_var_scoped_name; for name in &metadata.lexical_names { script_gdi_push_lexical_name(gdi_context, name.as_ptr(), name.len()); diff --git a/Libraries/LibJS/Rust/src/lexer.rs b/Libraries/LibJS/Rust/src/lexer.rs index cbed65ca2c..ceed2a5154 100644 --- a/Libraries/LibJS/Rust/src/lexer.rs +++ b/Libraries/LibJS/Rust/src/lexer.rs @@ -35,7 +35,8 @@ //! used as identifiers in some contexts). use crate::ast::Utf16String; -use crate::token::{Token, TokenType}; +use crate::token::Token; +use crate::token::TokenType; use crate::u32_from_usize; /// State for tracking template literal nesting. diff --git a/Libraries/LibJS/Rust/src/lib.rs b/Libraries/LibJS/Rust/src/lib.rs index 062f22e2f8..424809bd94 100644 --- a/Libraries/LibJS/Rust/src/lib.rs +++ b/Libraries/LibJS/Rust/src/lib.rs @@ -98,10 +98,13 @@ pub(crate) fn u32_from_usize(value: usize) -> u32 { use ast::StatementKind; use bytecode::generator::PendingSharedFunctionData; -use parser::{ParseError, Parser, ProgramType}; +use parser::ParseError; +use parser::Parser; +use parser::ProgramType; use std::collections::HashSet; use std::ffi::c_void; -use std::panic::{AssertUnwindSafe, catch_unwind}; +use std::panic::AssertUnwindSafe; +use std::panic::catch_unwind; // Compile-time assertion: `ParsedProgram` travels between the parse worker // thread and the main thread, so it must be `Send`. After the StringId and @@ -2125,7 +2128,8 @@ pub unsafe extern "C" fn rust_compile_module( /// Extract import/export metadata from a module's scope and call C++ callbacks. unsafe fn extract_module_metadata(scope: &ast::ScopeData, ctx: *mut c_void, cb: &ModuleCallbacks) { unsafe { - use ast::{ExportEntryKind, StatementKind}; + use ast::ExportEntryKind; + use ast::StatementKind; // Collect all import entries with their module requests. struct ImportEntryWithRequest { @@ -2585,7 +2589,8 @@ fn extract_gdi_common( function_table: &mut ast::FunctionTable, arena: &std::sync::Arc, ) { - use ast::{DeclarationKind, StatementKind}; + use ast::DeclarationKind; + use ast::StatementKind; // Var names (var declarations at any nesting level + top-level function declarations) for child in &scope.children { @@ -2683,10 +2688,13 @@ unsafe fn extract_eval_gdi( referenced_private_names: &[ast::Utf16String], ) { unsafe { - use bytecode::ffi::{ - eval_gdi_push_annex_b_name, eval_gdi_push_function, eval_gdi_push_lexical_binding, - eval_gdi_push_private_name, eval_gdi_push_var_name, eval_gdi_push_var_scoped_name, eval_gdi_set_strict, - }; + use bytecode::ffi::eval_gdi_push_annex_b_name; + use bytecode::ffi::eval_gdi_push_function; + use bytecode::ffi::eval_gdi_push_lexical_binding; + use bytecode::ffi::eval_gdi_push_private_name; + use bytecode::ffi::eval_gdi_push_var_name; + use bytecode::ffi::eval_gdi_push_var_scoped_name; + use bytecode::ffi::eval_gdi_set_strict; eval_gdi_set_strict(ctx, is_strict); @@ -2724,11 +2732,14 @@ unsafe fn extract_script_gdi( arena: &std::sync::Arc, ) { unsafe { - use ast::{DeclarationKind, StatementKind}; - use bytecode::ffi::{ - script_gdi_push_annex_b_name, script_gdi_push_function, script_gdi_push_lexical_binding, - script_gdi_push_lexical_name, script_gdi_push_var_name, script_gdi_push_var_scoped_name, - }; + use ast::DeclarationKind; + use ast::StatementKind; + use bytecode::ffi::script_gdi_push_annex_b_name; + use bytecode::ffi::script_gdi_push_function; + use bytecode::ffi::script_gdi_push_lexical_binding; + use bytecode::ffi::script_gdi_push_lexical_name; + use bytecode::ffi::script_gdi_push_var_name; + use bytecode::ffi::script_gdi_push_var_scoped_name; // Lexical names (let/const/using/class at top level) — script-only step. for child in &scope.children { @@ -3589,7 +3600,9 @@ pub unsafe extern "C" fn rust_validate_bytecode( ) -> bool { unsafe { abort_on_panic(|| { - use bytecode::validator::{FFIValidationError, ValidationErrorKind, validate_bytecode}; + use bytecode::validator::FFIValidationError; + use bytecode::validator::ValidationErrorKind; + use bytecode::validator::validate_bytecode; let write_error = |err: FFIValidationError| { if !error_out.is_null() { @@ -3653,7 +3666,8 @@ pub unsafe extern "C" fn rust_validate_bytecode( #[cfg(test)] mod tests { use super::*; - use std::sync::atomic::{AtomicUsize, Ordering}; + use std::sync::atomic::AtomicUsize; + use std::sync::atomic::Ordering; static FREED_FOREIGN_OWNERS: AtomicUsize = AtomicUsize::new(0); diff --git a/Libraries/LibJS/Rust/src/parser.rs b/Libraries/LibJS/Rust/src/parser.rs index 107f1ca5ed..35593c9596 100644 --- a/Libraries/LibJS/Rust/src/parser.rs +++ b/Libraries/LibJS/Rust/src/parser.rs @@ -32,16 +32,34 @@ //! save and restore the full parser state including lexer position, current //! token, error list, and all boolean flags. -use crate::fast_hash::{HashMap, HashSet}; +use crate::fast_hash::HashMap; +use crate::fast_hash::HashSet; -use crate::ast::{ - AstArena, BindingPattern, Expression, ExpressionKind, FunctionData, FunctionId, FunctionParameter, FunctionTable, - Identifier, IdentifierId, PrivateIdentifier, ProgramData, ScopeData, ScopeId, SourceRange, Statement, - StatementKind, StringId, Utf16String, -}; -use crate::lexer::{Lexer, ch}; -use crate::scope_collector::{ScopeCollector, ScopeCollectorState}; -use crate::token::{Token, TokenType}; +use crate::ast::AstArena; +use crate::ast::BindingPattern; +use crate::ast::Expression; +use crate::ast::ExpressionKind; +use crate::ast::FunctionData; +use crate::ast::FunctionId; +use crate::ast::FunctionParameter; +use crate::ast::FunctionTable; +use crate::ast::Identifier; +use crate::ast::IdentifierId; +use crate::ast::PrivateIdentifier; +use crate::ast::ProgramData; +use crate::ast::ScopeData; +use crate::ast::ScopeId; +use crate::ast::SourceRange; +use crate::ast::Statement; +use crate::ast::StatementKind; +use crate::ast::StringId; +use crate::ast::Utf16String; +use crate::lexer::Lexer; +use crate::lexer::ch; +use crate::scope_collector::ScopeCollector; +use crate::scope_collector::ScopeCollectorState; +use crate::token::Token; +use crate::token::TokenType; mod declarations; mod expressions; diff --git a/Libraries/LibJS/Rust/src/parser/declarations.rs b/Libraries/LibJS/Rust/src/parser/declarations.rs index b4c8a8d2ae..adcf33c0fc 100644 --- a/Libraries/LibJS/Rust/src/parser/declarations.rs +++ b/Libraries/LibJS/Rust/src/parser/declarations.rs @@ -6,14 +6,23 @@ //! Declaration parsing: variables, functions, classes, imports, exports. -use crate::fast_hash::{HashMap, HashSet}; +use crate::fast_hash::HashMap; +use crate::fast_hash::HashSet; use crate::ast::*; use crate::lexer::ch; -use crate::parser::{ - Associativity, DeclarationKind, ForbiddenTokens, FunctionKind, MethodKind, PRECEDENCE_ASSIGNMENT, ParamInfo, - ParsedParameters, Parser, Position, ProgramType, PropertyKey, -}; +use crate::parser::Associativity; +use crate::parser::DeclarationKind; +use crate::parser::ForbiddenTokens; +use crate::parser::FunctionKind; +use crate::parser::MethodKind; +use crate::parser::PRECEDENCE_ASSIGNMENT; +use crate::parser::ParamInfo; +use crate::parser::ParsedParameters; +use crate::parser::Parser; +use crate::parser::Position; +use crate::parser::ProgramType; +use crate::parser::PropertyKey; use crate::token::TokenType; fn expression_into_identifier(expression: Expression) -> IdentifierId { diff --git a/Libraries/LibJS/Rust/src/parser/expressions.rs b/Libraries/LibJS/Rust/src/parser/expressions.rs index 8058c39441..029c96b0cc 100644 --- a/Libraries/LibJS/Rust/src/parser/expressions.rs +++ b/Libraries/LibJS/Rust/src/parser/expressions.rs @@ -11,12 +11,22 @@ use std::sync::Arc; use crate::ast::*; use crate::lexer::ch; -use crate::parser::{ - Associativity, ForbiddenTokens, FunctionKind, MethodKind, PRECEDENCE_ASSIGNMENT, PRECEDENCE_COMMA, - PRECEDENCE_MEMBER, PRECEDENCE_UNARY, ParamInfo, ParsedParameters, Parser, Position, PropertyKey, - is_strict_reserved_word, -}; -use crate::token::{Token, TokenType}; +use crate::parser::Associativity; +use crate::parser::ForbiddenTokens; +use crate::parser::FunctionKind; +use crate::parser::MethodKind; +use crate::parser::PRECEDENCE_ASSIGNMENT; +use crate::parser::PRECEDENCE_COMMA; +use crate::parser::PRECEDENCE_MEMBER; +use crate::parser::PRECEDENCE_UNARY; +use crate::parser::ParamInfo; +use crate::parser::ParsedParameters; +use crate::parser::Parser; +use crate::parser::Position; +use crate::parser::PropertyKey; +use crate::parser::is_strict_reserved_word; +use crate::token::Token; +use crate::token::TokenType; #[derive(PartialEq, Eq)] enum EscapeMode { diff --git a/Libraries/LibJS/Rust/src/parser/statements.rs b/Libraries/LibJS/Rust/src/parser/statements.rs index 188337da5c..d4b27e90a7 100644 --- a/Libraries/LibJS/Rust/src/parser/statements.rs +++ b/Libraries/LibJS/Rust/src/parser/statements.rs @@ -9,10 +9,13 @@ use crate::fast_hash::HashSet; use crate::ast::*; -use crate::parser::{ - Associativity, ForbiddenTokens, PRECEDENCE_COMMA, Parser, Position, is_strict_reserved_word, - is_unconditional_reserved_word, -}; +use crate::parser::Associativity; +use crate::parser::ForbiddenTokens; +use crate::parser::PRECEDENCE_COMMA; +use crate::parser::Parser; +use crate::parser::Position; +use crate::parser::is_strict_reserved_word; +use crate::parser::is_unconditional_reserved_word; use crate::token::TokenType; /// Used locally during for-statement parsing before converting to `ast::ForInit`. diff --git a/Libraries/LibJS/Rust/src/scope_collector.rs b/Libraries/LibJS/Rust/src/scope_collector.rs index ac028fa0da..7695205cbf 100644 --- a/Libraries/LibJS/Rust/src/scope_collector.rs +++ b/Libraries/LibJS/Rust/src/scope_collector.rs @@ -49,13 +49,24 @@ //! - `IdentifierGroup` — a set of identifier references with the same //! name within one scope (multiple `foo` refs are grouped together) -use crate::fast_hash::{HashMap, IndexMap}; +use crate::fast_hash::HashMap; +use crate::fast_hash::IndexMap; -use crate::ast::{ - FunctionScopeData, IdentifierArena, IdentifierId, LocalBinding, LocalVarKind, LocalVariable, ScopeId, Statement, - StringId, Utf16String, VarToInit, -}; -use crate::parser::{DeclarationKind, FunctionKind, ParseError, ProgramType}; +use crate::ast::FunctionScopeData; +use crate::ast::IdentifierArena; +use crate::ast::IdentifierId; +use crate::ast::LocalBinding; +use crate::ast::LocalVarKind; +use crate::ast::LocalVariable; +use crate::ast::ScopeId; +use crate::ast::Statement; +use crate::ast::StringId; +use crate::ast::Utf16String; +use crate::ast::VarToInit; +use crate::parser::DeclarationKind; +use crate::parser::FunctionKind; +use crate::parser::ParseError; +use crate::parser::ProgramType; use crate::u32_from_usize; // === Enums === diff --git a/Libraries/LibRegex/Rust/src/bytecode.rs b/Libraries/LibRegex/Rust/src/bytecode.rs index 328fa9c3e3..67d6925c2b 100644 --- a/Libraries/LibRegex/Rust/src/bytecode.rs +++ b/Libraries/LibRegex/Rust/src/bytecode.rs @@ -18,7 +18,8 @@ //! - A set of registers for capture group positions //! - A backtrack stack for saving/restoring state -pub use libunicode_rust::character_types::{PropertyKind, ResolvedProperty}; +pub use libunicode_rust::character_types::PropertyKind; +pub use libunicode_rust::character_types::ResolvedProperty; /// A named capture group mapping derived from the pattern's named captures. /// diff --git a/Libraries/LibRegex/Rust/src/regex.rs b/Libraries/LibRegex/Rust/src/regex.rs index 79f5eae5c1..6fb5112ba9 100644 --- a/Libraries/LibRegex/Rust/src/regex.rs +++ b/Libraries/LibRegex/Rust/src/regex.rs @@ -7,9 +7,18 @@ /// High-level regex API. /// /// This is the main entry point for using the regex engine. -use crate::ast::{Alternative, Atom, Disjunction, Flags, Pattern, Term}; -use crate::bytecode::{Instruction, NamedGroupEntry, append_code_point_wtf16}; -use crate::{compiler, parser, vm}; +use crate::ast::Alternative; +use crate::ast::Atom; +use crate::ast::Disjunction; +use crate::ast::Flags; +use crate::ast::Pattern; +use crate::ast::Term; +use crate::bytecode::Instruction; +use crate::bytecode::NamedGroupEntry; +use crate::bytecode::append_code_point_wtf16; +use crate::compiler; +use crate::parser; +use crate::vm; use std::cell::RefCell; use std::collections::HashSet; diff --git a/Libraries/LibUnicode/Rust/src/calendar.rs b/Libraries/LibUnicode/Rust/src/calendar.rs index 54e4b539a9..d20469f7fe 100644 --- a/Libraries/LibUnicode/Rust/src/calendar.rs +++ b/Libraries/LibUnicode/Rust/src/calendar.rs @@ -5,11 +5,14 @@ */ use calendrical_calculations::rata_die::RataDie; -use icu_calendar::{ - AnyCalendar, AnyCalendarKind, Date, Iso, - types::{DateFields, Month}, -}; -use std::panic::{AssertUnwindSafe, catch_unwind}; +use icu_calendar::AnyCalendar; +use icu_calendar::AnyCalendarKind; +use icu_calendar::Date; +use icu_calendar::Iso; +use icu_calendar::types::DateFields; +use icu_calendar::types::Month; +use std::panic::AssertUnwindSafe; +use std::panic::catch_unwind; #[repr(C)] pub struct FfiISODate { diff --git a/Libraries/LibWasm/Rust/build.rs b/Libraries/LibWasm/Rust/build.rs index d67e044386..5e6bc87968 100644 --- a/Libraries/LibWasm/Rust/build.rs +++ b/Libraries/LibWasm/Rust/build.rs @@ -7,7 +7,8 @@ use std::env; use std::error::Error; use std::fmt::Write; -use std::path::{Path, PathBuf}; +use std::path::Path; +use std::path::PathBuf; fn generate_opcodes(manifest_dir: &Path, out_dir: &Path) -> Result<(), Box> { let opcode_h = manifest_dir.join("../Opcode.h"); diff --git a/Libraries/LibWasm/Rust/src/bin/cranelift-compiler.rs b/Libraries/LibWasm/Rust/src/bin/cranelift-compiler.rs index 6a2acc4cea..e1904907ca 100644 --- a/Libraries/LibWasm/Rust/src/bin/cranelift-compiler.rs +++ b/Libraries/LibWasm/Rust/src/bin/cranelift-compiler.rs @@ -6,9 +6,14 @@ #![allow(clippy::manual_let_else)] -use libwasm_cranelift::{CompiledFunction, CraneliftInsn, HelperReloc, RuntimeHelpers, compile_to_bytes}; +use libwasm_cranelift::CompiledFunction; +use libwasm_cranelift::CraneliftInsn; +use libwasm_cranelift::HelperReloc; +use libwasm_cranelift::RuntimeHelpers; +use libwasm_cranelift::compile_to_bytes; use std::env; -use std::mem::{size_of, size_of_val}; +use std::mem::size_of; +use std::mem::size_of_val; #[cfg(all(unix, not(target_os = "macos")))] use std::fs::File; diff --git a/Libraries/LibWasm/Rust/src/compiler.rs b/Libraries/LibWasm/Rust/src/compiler.rs index f7e6d0a00a..520f0e8717 100644 --- a/Libraries/LibWasm/Rust/src/compiler.rs +++ b/Libraries/LibWasm/Rust/src/compiler.rs @@ -4,23 +4,37 @@ * SPDX-License-Identifier: BSD-2-Clause */ -use crate::{CraneliftInsn, RuntimeHelpers}; +use crate::CompiledFunction; +use crate::CraneliftInsn; +use crate::HelperId; +use crate::HelperReloc; +use crate::RuntimeHelpers; +use cranelift_codegen::Context; use cranelift_codegen::FinalizedRelocTarget; use cranelift_codegen::binemit::Reloc; -use cranelift_codegen::ir::condcodes::{FloatCC, IntCC}; +use cranelift_codegen::ir::AbiParam; +use cranelift_codegen::ir::ExtFuncData; +use cranelift_codegen::ir::ExternalName; +use cranelift_codegen::ir::Function; +use cranelift_codegen::ir::InstBuilder; +use cranelift_codegen::ir::MemFlags; +use cranelift_codegen::ir::Signature; +use cranelift_codegen::ir::StackSlotData; +use cranelift_codegen::ir::StackSlotKind; +use cranelift_codegen::ir::UserExternalName; +use cranelift_codegen::ir::UserFuncName; +use cranelift_codegen::ir::condcodes::FloatCC; +use cranelift_codegen::ir::condcodes::IntCC; use cranelift_codegen::ir::types; -use cranelift_codegen::ir::{ - AbiParam, ExtFuncData, ExternalName, Function, InstBuilder, MemFlags, Signature, StackSlotData, StackSlotKind, - UserExternalName, UserFuncName, -}; -use cranelift_codegen::settings::{self, Configurable}; -use cranelift_codegen::{self, Context}; -use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext, Variable}; +use cranelift_codegen::settings::Configurable; +use cranelift_codegen::settings::{self}; +use cranelift_codegen::{self}; +use cranelift_frontend::FunctionBuilder; +use cranelift_frontend::FunctionBuilderContext; +use cranelift_frontend::Variable; use cranelift_native; -use crate::{CompiledFunction, HelperId, HelperReloc}; - // Opcode constants generated from Opcode.h (see build.rs.) #[allow(dead_code)] mod op { diff --git a/Libraries/LibWeb/ContentBlocker/Rust/src/lib.rs b/Libraries/LibWeb/ContentBlocker/Rust/src/lib.rs index e10466121f..a592d17a2f 100644 --- a/Libraries/LibWeb/ContentBlocker/Rust/src/lib.rs +++ b/Libraries/LibWeb/ContentBlocker/Rust/src/lib.rs @@ -4,9 +4,11 @@ * SPDX-License-Identifier: BSD-2-Clause */ -use std::collections::{HashMap, HashSet}; +use std::collections::HashMap; +use std::collections::HashSet; use std::ffi::c_void; -use std::panic::{AssertUnwindSafe, catch_unwind}; +use std::panic::AssertUnwindSafe; +use std::panic::catch_unwind; #[repr(C)] pub struct ContentBlockerString { diff --git a/Libraries/LibWeb/HTML/Parser/Rust/build.rs b/Libraries/LibWeb/HTML/Parser/Rust/build.rs index 9d7a5874f6..43413fc72b 100644 --- a/Libraries/LibWeb/HTML/Parser/Rust/build.rs +++ b/Libraries/LibWeb/HTML/Parser/Rust/build.rs @@ -12,7 +12,8 @@ use std::cell::RefCell; use std::collections::HashMap; use std::env; use std::fs; -use std::path::{Path, PathBuf}; +use std::path::Path; +use std::path::PathBuf; use std::rc::Rc; const FFI_HEADER: &str = "HTMLTokenizerRustFFI.h"; diff --git a/Libraries/LibWeb/HTML/Parser/Rust/src/lib.rs b/Libraries/LibWeb/HTML/Parser/Rust/src/lib.rs index 86c13f0fdc..938e6aacea 100644 --- a/Libraries/LibWeb/HTML/Parser/Rust/src/lib.rs +++ b/Libraries/LibWeb/HTML/Parser/Rust/src/lib.rs @@ -12,8 +12,12 @@ pub mod token; pub mod tokenizer; use std::ptr; -use token::{Attribute, Position, TokenPayload, TokenType}; -use tokenizer::{HtmlTokenizer, State}; +use token::Attribute; +use token::Position; +use token::TokenPayload; +use token::TokenType; +use tokenizer::HtmlTokenizer; +use tokenizer::State; /// Opaque handle for the Rust tokenizer, passed across the FFI boundary. pub struct RustFfiTokenizerHandle { diff --git a/Libraries/LibWeb/HTML/Parser/Rust/src/parser.rs b/Libraries/LibWeb/HTML/Parser/Rust/src/parser.rs index b82311b554..47c81ffeec 100644 --- a/Libraries/LibWeb/HTML/Parser/Rust/src/parser.rs +++ b/Libraries/LibWeb/HTML/Parser/Rust/src/parser.rs @@ -5,11 +5,16 @@ */ use crate::RustFfiTokenizerHandle; -use crate::token::{Token, TokenPayload, TokenType}; -use crate::tokenizer::{HtmlTokenizer, State}; +use crate::token::Token; +use crate::token::TokenPayload; +use crate::token::TokenType; +use crate::tokenizer::HtmlTokenizer; +use crate::tokenizer::State; use std::ffi::c_void; -use std::ops::{Deref, DerefMut}; -use std::ptr::{NonNull, addr_of_mut}; +use std::ops::Deref; +use std::ops::DerefMut; +use std::ptr::NonNull; +use std::ptr::addr_of_mut; #[repr(C)] #[derive(Clone, Copy, Debug, Eq, PartialEq)] diff --git a/Libraries/LibWeb/HTML/Parser/Rust/src/preload_scanner.rs b/Libraries/LibWeb/HTML/Parser/Rust/src/preload_scanner.rs index 8e490c9728..7d2d801655 100644 --- a/Libraries/LibWeb/HTML/Parser/Rust/src/preload_scanner.rs +++ b/Libraries/LibWeb/HTML/Parser/Rust/src/preload_scanner.rs @@ -5,7 +5,10 @@ */ use crate::decode_utf8_to_u32; -use crate::token::{Attribute, Token, TokenPayload, TokenType}; +use crate::token::Attribute; +use crate::token::Token; +use crate::token::TokenPayload; +use crate::token::TokenType; use crate::tokenizer::HtmlTokenizer; use std::ffi::c_void; diff --git a/Libraries/LibWeb/HTML/Parser/Rust/src/tokenizer.rs b/Libraries/LibWeb/HTML/Parser/Rust/src/tokenizer.rs index 9969de6452..823732eeda 100644 --- a/Libraries/LibWeb/HTML/Parser/Rust/src/tokenizer.rs +++ b/Libraries/LibWeb/HTML/Parser/Rust/src/tokenizer.rs @@ -7,7 +7,12 @@ use std::collections::VecDeque; use crate::entities::NamedCharacterReferenceMatcher; -use crate::token::{Attribute, DoctypeData, Position, Token, TokenPayload, TokenType}; +use crate::token::Attribute; +use crate::token::DoctypeData; +use crate::token::Position; +use crate::token::Token; +use crate::token::TokenPayload; +use crate::token::TokenType; /// Tokenizer states per the WHATWG HTML spec section 13.2.5. #[derive(Clone, Copy, Debug, PartialEq, Eq)] diff --git a/Libraries/LibWeb/Rust/src/encoding_detection.rs b/Libraries/LibWeb/Rust/src/encoding_detection.rs index 4154d32d3f..29c2fd2f91 100644 --- a/Libraries/LibWeb/Rust/src/encoding_detection.rs +++ b/Libraries/LibWeb/Rust/src/encoding_detection.rs @@ -4,7 +4,9 @@ * SPDX-License-Identifier: BSD-2-Clause */ -use chardetng::{EncodingDetector, Iso2022JpDetection, Utf8Detection}; +use chardetng::EncodingDetector; +use chardetng::Iso2022JpDetection; +use chardetng::Utf8Detection; /// Attempts to detect the character encoding of a byte stream using frequency analysis. /// diff --git a/Libraries/LibWeb/Rust/src/lib.rs b/Libraries/LibWeb/Rust/src/lib.rs index 6f76b871be..d32fd10f0e 100644 --- a/Libraries/LibWeb/Rust/src/lib.rs +++ b/Libraries/LibWeb/Rust/src/lib.rs @@ -13,9 +13,13 @@ mod encoding_detection; pub use libweb_html_tokenizer as html_tokenizer; use std::ffi::c_void; -use std::panic::{AssertUnwindSafe, catch_unwind}; +use std::panic::AssertUnwindSafe; +use std::panic::catch_unwind; -pub use css_tokenizer::{CssHashType, CssNumberType, CssToken, CssTokenType}; +pub use css_tokenizer::CssHashType; +pub use css_tokenizer::CssNumberType; +pub use css_tokenizer::CssToken; +pub use css_tokenizer::CssTokenType; fn abort_on_panic R, R>(f: F) -> R { match catch_unwind(AssertUnwindSafe(f)) { diff --git a/Libraries/RustAllocator.rs b/Libraries/RustAllocator.rs index 32647e8bd8..e7af505e68 100644 --- a/Libraries/RustAllocator.rs +++ b/Libraries/RustAllocator.rs @@ -8,7 +8,8 @@ // crate's unit tests don't need to link against the C++ runtime. #![cfg(not(test))] -use std::alloc::{GlobalAlloc, Layout}; +use std::alloc::GlobalAlloc; +use std::alloc::Layout; unsafe extern "C" { fn ladybird_rust_alloc(size: usize, alignment: usize) -> *mut u8; diff --git a/Meta/Docker/ci/VERSION b/Meta/Docker/ci/VERSION index 2e3b56ef88..e33b4a0eaf 100644 --- a/Meta/Docker/ci/VERSION +++ b/Meta/Docker/ci/VERSION @@ -1 +1 @@ -2026.05.5 +2026.05.25 diff --git a/Meta/lint-ci.sh b/Meta/lint-ci.sh index 1b49fe00ec..dcaa923648 100755 --- a/Meta/lint-ci.sh +++ b/Meta/lint-ci.sh @@ -48,10 +48,10 @@ else ((FAILURES+=1)) fi -if cargo fmt --check ; then - echo -e "[${GREEN}OK${NC}]: cargo fmt --check" +if cargo +nightly fmt --check ; then + echo -e "[${GREEN}OK${NC}]: cargo +nightly fmt --check" else - echo -e "[${BOLD_RED}FAIL${NC}]: cargo fmt --check" + echo -e "[${BOLD_RED}FAIL${NC}]: cargo +nightly fmt --check" ((FAILURES+=1)) fi diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 6360c1888d..aaf9c5b65b 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,4 @@ [toolchain] -channel = "1.95.0" +# TODO: Pin to a stable version once `imports_granularity` rustfmt option is stable. https://rust-lang.github.io/rustfmt/?version=v1.9.0&search=group#imports_granularity +channel = "nightly" components = ["rustfmt", "clippy"] diff --git a/rustfmt.toml b/rustfmt.toml index fa182dd009..b85ada292f 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -3,3 +3,4 @@ hard_tabs = false tab_spaces = 4 edition = "2024" style_edition = "2024" +imports_granularity = "Item"