Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Restructure lints in multiple crates #2447

Closed
wants to merge 11 commits into from
3 changes: 0 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion boa_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ rust-version.workspace = true
[dependencies]
boa_engine = { workspace = true, features = ["deser", "console"] }
boa_ast = { workspace = true, features = ["serde"]}
boa_interner.workspace = true
boa_parser.workspace = true
rustyline = "10.0.0"
rustyline-derive = "0.7.0"
Expand Down
136 changes: 65 additions & 71 deletions boa_cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,71 +1,71 @@
//! A ECMAScript REPL implementation based on boa_engine.

#![doc(
html_logo_url = "https://raw.githubusercontent.com/boa-dev/boa/main/assets/logo.svg",
html_favicon_url = "https://raw.githubusercontent.com/boa-dev/boa/main/assets/logo.svg"
)]
#![cfg_attr(not(test), deny(clippy::unwrap_used))]
#![warn(
clippy::perf,
clippy::single_match_else,
clippy::dbg_macro,
clippy::doc_markdown,
clippy::wildcard_imports,
clippy::struct_excessive_bools,
clippy::doc_markdown,
clippy::semicolon_if_nothing_returned,
clippy::pedantic
)]
#![warn(missing_docs, clippy::dbg_macro)]
#![deny(
clippy::all,
clippy::cast_lossless,
clippy::redundant_closure_for_method_calls,
clippy::use_self,
clippy::unnested_or_patterns,
clippy::trivially_copy_pass_by_ref,
clippy::needless_pass_by_value,
clippy::match_wildcard_for_single_variants,
clippy::map_unwrap_or,
unused_qualifications,
unused_import_braces,
unused_lifetimes,
unreachable_pub,
trivial_numeric_casts,
// rustdoc,
missing_debug_implementations,
missing_copy_implementations,
deprecated_in_future,
meta_variable_misuse,
non_ascii_idents,
rust_2018_compatibility,
rust_2018_idioms,
// 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
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 categories https://doc.rust-lang.org/clippy/
clippy::all,
clippy::correctness,
clippy::suspicious,
clippy::style,
clippy::complexity,
clippy::perf,
clippy::pedantic,
clippy::nursery,
)]
#![allow(
clippy::module_name_repetitions,
clippy::cast_possible_truncation,
clippy::cast_sign_loss,
clippy::cast_precision_loss,
clippy::cast_possible_wrap,
clippy::cast_ptr_alignment,
clippy::missing_panics_doc,
clippy::too_many_lines,
clippy::unreadable_literal,
clippy::missing_inline_in_public_items,
clippy::cognitive_complexity,
clippy::must_use_candidate,
clippy::missing_errors_doc,
clippy::as_conversions,
clippy::let_unit_value,
rustdoc::missing_doc_code_examples
)]
#![allow(clippy::option_if_let_else, clippy::redundant_pub_crate)]

mod helper;

use boa_ast::StatementList;
use boa_engine::Context;
use clap::{Parser, ValueEnum, ValueHint};
use colored::{Color, Colorize};
use rustyline::{config::Config, error::ReadlineError, EditMode, Editor};
use std::{fs::read, fs::OpenOptions, io, path::PathBuf};
mod helper;

#[cfg(all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"))]
#[cfg_attr(
Expand All @@ -82,7 +82,6 @@ const READLINE_COLOR: Color = Color::Cyan;
// Added #[allow(clippy::option_option)] because to StructOpt an Option<Option<T>>
// is an optional argument that optionally takes a value ([--opt=[val]]).
// https://docs.rs/structopt/0.3.11/structopt/#type-magic
#[allow(clippy::option_option)]
#[derive(Debug, Parser)]
#[command(author, version, about, name = "boa")]
struct Opt {
Expand All @@ -98,6 +97,7 @@ struct Opt {
ignore_case = true,
value_enum
)]
#[allow(clippy::option_option)]
dump_ast: Option<Option<DumpFormat>>,

/// Dump the AST to stdout with the given format.
Expand All @@ -111,7 +111,7 @@ struct Opt {

impl Opt {
/// Returns whether a dump flag has been used.
fn has_dump_flag(&self) -> bool {
const fn has_dump_flag(&self) -> bool {
self.dump_ast.is_some()
}
}
Expand Down Expand Up @@ -162,29 +162,23 @@ where
let ast = parse_tokens(src, context)?;

match arg {
Some(format) => match format {
DumpFormat::Debug => println!("{ast:#?}"),
DumpFormat::Json => println!(
"{}",
serde_json::to_string(&ast).expect("could not convert AST to a JSON string")
),
DumpFormat::JsonPretty => {
println!(
"{}",
serde_json::to_string_pretty(&ast)
.expect("could not convert AST to a pretty JSON string")
);
}
},
// Default ast dumping format.
None => println!("{ast:#?}"),
Some(DumpFormat::Json) => println!(
"{}",
serde_json::to_string(&ast).expect("could not convert AST to a JSON string")
),
Some(DumpFormat::JsonPretty) => println!(
"{}",
serde_json::to_string_pretty(&ast)
.expect("could not convert AST to a pretty JSON string")
),
Some(DumpFormat::Debug) | None => println!("{ast:#?}"),
}
}

Ok(())
}

pub fn main() -> Result<(), io::Error> {
fn main() -> Result<(), io::Error> {
let args = Opt::parse();

let mut context = Context::default();
Expand Down
3 changes: 0 additions & 3 deletions boa_gc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,3 @@ rust-version.workspace = true
[dependencies]
boa_profiler.workspace = true
boa_macros.workspace = true

# Optional Dependencies
measureme = { version = "10.1.0", optional = true }
41 changes: 22 additions & 19 deletions boa_gc/src/cell.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
//! A garbage collected cell implementation
use std::cell::{Cell, UnsafeCell};
use std::cmp::Ordering;
use std::fmt::{self, Debug, Display};
use std::hash::Hash;
use std::ops::{Deref, DerefMut};

use crate::trace::{Finalize, Trace};
use std::{
cell::{Cell, UnsafeCell},
cmp::Ordering,
fmt::{self, Debug, Display},
hash::Hash,
ops::{Deref, DerefMut},
};

/// `BorrowFlag` represent the internal state of a `GcCell` and
/// keeps track of the amount of current borrows.
Expand Down Expand Up @@ -34,7 +36,7 @@ pub(crate) const BORROWFLAG_INIT: BorrowFlag = BorrowFlag(ROOT);
impl BorrowFlag {
/// Check the current `BorrowState` of `BorrowFlag`.
#[inline]
pub(crate) fn borrowed(self) -> BorrowState {
pub(crate) const fn borrowed(self) -> BorrowState {
match self.0 & !ROOT {
UNUSED => BorrowState::Unused,
WRITING => BorrowState::Writing,
Expand All @@ -44,20 +46,20 @@ impl BorrowFlag {

/// Check whether the borrow bit is flagged.
#[inline]
pub(crate) fn rooted(self) -> bool {
pub(crate) const fn rooted(self) -> bool {
self.0 & ROOT > 0
}

/// Set the `BorrowFlag`'s state to writing.
#[inline]
pub(crate) fn set_writing(self) -> Self {
pub(crate) const fn set_writing(self) -> Self {
// Set every bit other than the root bit, which is preserved
Self(self.0 | WRITING)
}

/// Remove the root flag on `BorrowFlag`
#[inline]
pub(crate) fn set_unused(self) -> Self {
pub(crate) const fn set_unused(self) -> Self {
// Clear every bit other than the root bit, which is preserved
Self(self.0 & ROOT)
}
Expand Down Expand Up @@ -130,7 +132,7 @@ pub struct GcCell<T: ?Sized + 'static> {
impl<T: Trace> GcCell<T> {
/// Creates a new `GcCell` containing `value`.
#[inline]
pub fn new(value: T) -> Self {
pub const fn new(value: T) -> Self {
Self {
flags: Cell::new(BORROWFLAG_INIT),
cell: UnsafeCell::new(value),
Expand Down Expand Up @@ -402,7 +404,7 @@ impl<'a, T: ?Sized> GcCellRef<'a, T> {
}
}

impl<'a, T: ?Sized> Deref for GcCellRef<'a, T> {
impl<T: ?Sized> Deref for GcCellRef<'_, T> {
type Target = T;

#[inline]
Expand All @@ -411,20 +413,20 @@ impl<'a, T: ?Sized> Deref for GcCellRef<'a, T> {
}
}

impl<'a, T: ?Sized> Drop for GcCellRef<'a, T> {
impl<T: ?Sized> Drop for GcCellRef<'_, T> {
fn drop(&mut self) {
debug_assert!(self.flags.get().borrowed() == BorrowState::Reading);
self.flags.set(self.flags.get().sub_reading());
}
}

impl<'a, T: ?Sized + Debug> Debug for GcCellRef<'a, T> {
impl<T: ?Sized + Debug> Debug for GcCellRef<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Debug::fmt(&**self, f)
}
}

impl<'a, T: ?Sized + Display> Display for GcCellRef<'a, T> {
impl<T: ?Sized + Display> Display for GcCellRef<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Display::fmt(&**self, f)
}
Expand Down Expand Up @@ -452,6 +454,7 @@ impl<'a, T: Trace + ?Sized, U: ?Sized> GcCellRefMut<'a, T, U> {
F: FnOnce(&mut U) -> &mut V,
{
// SAFETY: This is safe as `GcCellRefMut` is already borrowed, so the value is rooted.
#[allow(trivial_casts)]
let value = unsafe { &mut *(orig.value as *mut U) };

let ret = GcCellRefMut {
Expand All @@ -467,7 +470,7 @@ impl<'a, T: Trace + ?Sized, U: ?Sized> GcCellRefMut<'a, T, U> {
}
}

impl<'a, T: Trace + ?Sized, U: ?Sized> Deref for GcCellRefMut<'a, T, U> {
impl<T: Trace + ?Sized, U: ?Sized> Deref for GcCellRefMut<'_, T, U> {
type Target = U;

#[inline]
Expand All @@ -476,14 +479,14 @@ impl<'a, T: Trace + ?Sized, U: ?Sized> Deref for GcCellRefMut<'a, T, U> {
}
}

impl<'a, T: Trace + ?Sized, U: ?Sized> DerefMut for GcCellRefMut<'a, T, U> {
impl<T: Trace + ?Sized, U: ?Sized> DerefMut for GcCellRefMut<'_, T, U> {
#[inline]
fn deref_mut(&mut self) -> &mut U {
self.value
}
}

impl<'a, T: Trace + ?Sized, U: ?Sized> Drop for GcCellRefMut<'a, T, U> {
impl<T: Trace + ?Sized, U: ?Sized> Drop for GcCellRefMut<'_, T, U> {
#[inline]
fn drop(&mut self) {
debug_assert!(self.gc_cell.flags.get().borrowed() == BorrowState::Writing);
Expand All @@ -502,13 +505,13 @@ impl<'a, T: Trace + ?Sized, U: ?Sized> Drop for GcCellRefMut<'a, T, U> {
}
}

impl<'a, T: Trace + ?Sized, U: Debug + ?Sized> Debug for GcCellRefMut<'a, T, U> {
impl<T: Trace + ?Sized, U: Debug + ?Sized> Debug for GcCellRefMut<'_, T, U> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Debug::fmt(&**self, f)
}
}

impl<'a, T: Trace + ?Sized, U: Display + ?Sized> Display for GcCellRefMut<'a, T, U> {
impl<T: Trace + ?Sized, U: Display + ?Sized> Display for GcCellRefMut<'_, T, U> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Display::fmt(&**self, f)
}
Expand Down