From 08d8e0222f4a43852a502e388b4f01bd82329d59 Mon Sep 17 00:00:00 2001 From: nekevss Date: Mon, 20 Nov 2023 19:55:56 -0500 Subject: [PATCH] Post-rebase update and a couple changes --- .../src/builtins/temporal/calendar/mod.rs | 23 +++----- .../src/builtins/temporal/calendar/tests.rs | 2 +- boa_temporal/Cargo.toml | 9 ++-- boa_temporal/src/calendar.rs | 2 +- boa_temporal/src/duration.rs | 2 +- boa_temporal/src/fields.rs | 9 ++-- boa_temporal/src/lib.rs | 53 ------------------- boa_temporal/src/time.rs | 3 ++ boa_temporal/src/utils.rs | 4 +- boa_temporal/src/zoneddatetime.rs | 3 +- 10 files changed, 26 insertions(+), 84 deletions(-) diff --git a/boa_engine/src/builtins/temporal/calendar/mod.rs b/boa_engine/src/builtins/temporal/calendar/mod.rs index ddd2038e32f..c9de740c085 100644 --- a/boa_engine/src/builtins/temporal/calendar/mod.rs +++ b/boa_engine/src/builtins/temporal/calendar/mod.rs @@ -1139,23 +1139,12 @@ pub(crate) fn to_temporal_calendar_slot_value( let calendar = date.inner.calendar().clone(); return Ok(calendar); } - } else if calendar_like.is_plain_date_time() { - // TODO - return Err(JsNativeError::range() - .with_message("Not yet implemented.") - .into()); - } else if calendar_like.is_plain_year_month() { - // TODO - return Err(JsNativeError::range() - .with_message("Not yet implemented.") - .into()); - } else if calendar_like.is_plain_month_day() { - // TODO - return Err(JsNativeError::range() - .with_message("Not yet implemented.") - .into()); - } else if calendar_like.is_zoned_date_time() { - // TODO + } else if calendar_like.is_plain_date_time() + || calendar_like.is_plain_year_month() + || calendar_like.is_plain_month_day() + || calendar_like.is_zoned_date_time() + { + // TODO(nekevss): Separate out and reimplement the handling of different branches. return Err(JsNativeError::range() .with_message("Not yet implemented.") .into()); diff --git a/boa_engine/src/builtins/temporal/calendar/tests.rs b/boa_engine/src/builtins/temporal/calendar/tests.rs index 07da841ea3e..7618d924f20 100644 --- a/boa_engine/src/builtins/temporal/calendar/tests.rs +++ b/boa_engine/src/builtins/temporal/calendar/tests.rs @@ -57,5 +57,5 @@ fn run_custom_calendar() { TestAction::assert_eq("cal.daysInMonth(date)", 14), TestAction::assert_eq("cal.daysInWeek(date)", 6), TestAction::assert_eq("cal.daysInYear(date)", 360), - ]) + ]); } diff --git a/boa_temporal/Cargo.toml b/boa_temporal/Cargo.toml index c9894970afd..058e64d3490 100644 --- a/boa_temporal/Cargo.toml +++ b/boa_temporal/Cargo.toml @@ -11,15 +11,16 @@ license.workspace = true repository.workspace = true rust-version.workspace = true - [dependencies] -icu_calendar = { version = "~1.3.2", default-features = false } tinystr = "0.7.4" -bitflags.workspace = true +icu_calendar = { workspace = true, default-features = false } rustc-hash = { workspace = true, features = ["std"] } num-bigint = { workspace = true, features = ["serde"] } +bitflags.workspace = true num-traits.workspace = true - [features] context = [] + +[lints] +workspace = true diff --git a/boa_temporal/src/calendar.rs b/boa_temporal/src/calendar.rs index 29c4facc74e..02286a4a88d 100644 --- a/boa_temporal/src/calendar.rs +++ b/boa_temporal/src/calendar.rs @@ -297,7 +297,7 @@ impl core::fmt::Debug for dyn CalendarProtocol { } } -/// The [[Calendar]] field slot of a Temporal Object. +/// The `[[Calendar]]` field slot of a Temporal Object. #[derive(Debug)] pub enum CalendarSlot { /// The calendar identifier string. diff --git a/boa_temporal/src/duration.rs b/boa_temporal/src/duration.rs index 949560bae9a..fb19fce61d3 100644 --- a/boa_temporal/src/duration.rs +++ b/boa_temporal/src/duration.rs @@ -1173,7 +1173,7 @@ impl Duration { // 2. If zonedRelativeTo is not present, set zonedRelativeTo to undefined. let zoned_relative_to = relative_targets.1; // 3. If precalculatedPlainDateTime is not present, set precalculatedPlainDateTime to undefined. - let _precalc_pdt = relative_targets.2; + let _ = relative_targets.2; let (frac_days, frac_secs) = match unit { // 4. If unit is "year", "month", or "week", and plainRelativeTo is undefined, then diff --git a/boa_temporal/src/fields.rs b/boa_temporal/src/fields.rs index 608b1896e77..98ae9d0bad8 100644 --- a/boa_temporal/src/fields.rs +++ b/boa_temporal/src/fields.rs @@ -46,13 +46,14 @@ bitflags! { /// The post conversion field value. #[derive(Debug)] +#[allow(variant_size_differences)] pub enum FieldValue { /// Designates the values as an integer. Integer(i32), - /// Designates the value as a string. - String(String), /// Designates that the value is undefined. Undefined, + /// Designates the value as a string. + String(String), } /// The Conversion type of a field. @@ -320,7 +321,7 @@ impl TemporalFields { let FieldValue::String(offset) = value else { return Err(TemporalError::r#type().with_message("offset must be string.")); }; - self.offset = Some(offset.clone()); + self.offset = Some(offset.to_string()); self.bit_map.set(FieldMap::OFFSET, true); Ok(()) @@ -353,7 +354,7 @@ impl TemporalFields { let FieldValue::String(tz) = value else { return Err(TemporalError::r#type().with_message("tz must be string.")); }; - self.time_zone = Some(tz.clone()); + self.time_zone = Some(tz.to_string()); self.bit_map.set(FieldMap::TIME_ZONE, true); Ok(()) } diff --git a/boa_temporal/src/lib.rs b/boa_temporal/src/lib.rs index 0015b1ad999..e2da7ee6825 100644 --- a/boa_temporal/src/lib.rs +++ b/boa_temporal/src/lib.rs @@ -6,59 +6,6 @@ html_favicon_url = "https://raw.githubusercontent.com/boa-dev/boa/main/assets/logo.svg" )] #![cfg_attr(not(test), forbid(clippy::unwrap_used))] -#![warn( - // rustc lint groups https://doc.rust-lang.org/rustc/lints/groups.html - warnings, - future_incompatible, - let_underscore, - nonstandard_style, - rust_2018_compatibility, - rust_2018_idioms, - rust_2021_compatibility, - unused, - - // rustc allowed-by-default lints https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html - missing_docs, - macro_use_extern_crate, - meta_variable_misuse, - missing_abi, - missing_copy_implementations, - missing_debug_implementations, - non_ascii_idents, - noop_method_call, - single_use_lifetimes, - trivial_casts, - trivial_numeric_casts, - unreachable_pub, - unsafe_op_in_unsafe_fn, - unused_crate_dependencies, - unused_import_braces, - unused_lifetimes, - unused_qualifications, - unused_tuple_struct_fields, - variant_size_differences, - - // rustdoc lints https://doc.rust-lang.org/rustdoc/lints.html - rustdoc::broken_intra_doc_links, - rustdoc::private_intra_doc_links, - rustdoc::missing_crate_level_docs, - rustdoc::private_doc_tests, - rustdoc::invalid_codeblock_attributes, - rustdoc::invalid_rust_codeblocks, - rustdoc::bare_urls, - - // clippy allowed by default - clippy::dbg_macro, - - // clippy categories https://doc.rust-lang.org/clippy/ - clippy::all, - clippy::correctness, - clippy::suspicious, - clippy::style, - clippy::complexity, - clippy::perf, - clippy::pedantic, -)] #![allow( // Currently throws a false positive regarding dependencies that are only used in benchmarks. unused_crate_dependencies, diff --git a/boa_temporal/src/time.rs b/boa_temporal/src/time.rs index e3920f0124d..742c5f2bd68 100644 --- a/boa_temporal/src/time.rs +++ b/boa_temporal/src/time.rs @@ -4,6 +4,7 @@ use crate::iso::IsoTime; /// The Temporal `PlainTime` object. #[derive(Debug, Default, Clone, Copy)] +#[allow(dead_code)] pub struct TemporalTime { iso: IsoTime, } @@ -11,6 +12,7 @@ pub struct TemporalTime { // ==== Private API ==== impl TemporalTime { + #[allow(dead_code)] pub(crate) fn new_unchecked( hour: i32, minute: i32, @@ -25,6 +27,7 @@ impl TemporalTime { } /// Checks if the time is a valid `TemporalTime` + #[allow(dead_code)] pub(crate) fn is_valid(&self) -> bool { self.iso.is_valid() } diff --git a/boa_temporal/src/utils.rs b/boa_temporal/src/utils.rs index 4660ba49dd1..2c0e1dd1621 100644 --- a/boa_temporal/src/utils.rs +++ b/boa_temporal/src/utils.rs @@ -156,7 +156,7 @@ pub(crate) fn epoch_time_to_epoch_year(t: f64) -> i32 { // roughly calculate the largest possible year given the time t, // then check and refine the year. let day_count = epoch_time_to_day_number(t); - let mut year = day_count / 365; + let mut year = (day_count / 365) + 1970; loop { if epoch_time_for_year(year) <= t { break; @@ -164,7 +164,7 @@ pub(crate) fn epoch_time_to_epoch_year(t: f64) -> i32 { year -= 1; } - year + 1970 + year } /// Returns either 1 (true) or 0 (false) diff --git a/boa_temporal/src/zoneddatetime.rs b/boa_temporal/src/zoneddatetime.rs index 33d612b0960..a2aa4843698 100644 --- a/boa_temporal/src/zoneddatetime.rs +++ b/boa_temporal/src/zoneddatetime.rs @@ -1,6 +1,7 @@ -//! The ZonedDateTime module. +//! The `ZonedDateTime` module. // NOTE: Mostly serves as a placeholder currently // until the rest can be implemented. /// `TemporalZoneDateTime` +#[derive(Debug, Clone, Copy)] pub struct TemporalZonedDateTime;