Skip to content

Commit

Permalink
Fix use_self lints (#2946)
Browse files Browse the repository at this point in the history
  • Loading branch information
raskad authored May 18, 2023
1 parent 5e9193a commit 4a368a2
Show file tree
Hide file tree
Showing 20 changed files with 135 additions and 145 deletions.
10 changes: 5 additions & 5 deletions boa_engine/src/builtins/function/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,24 +228,24 @@ pub(crate) enum FunctionKind {
impl fmt::Debug for FunctionKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
FunctionKind::Native {
Self::Native {
function,
constructor,
} => f
.debug_struct("FunctionKind::Native")
.field("function", &function)
.field("constructor", &constructor)
.finish(),
FunctionKind::Ordinary { .. } => f
Self::Ordinary { .. } => f
.debug_struct("FunctionKind::Ordinary")
.finish_non_exhaustive(),
FunctionKind::Async { .. } => f
Self::Async { .. } => f
.debug_struct("FunctionKind::Async")
.finish_non_exhaustive(),
FunctionKind::Generator { .. } => f
Self::Generator { .. } => f
.debug_struct("FunctionKind::Generator")
.finish_non_exhaustive(),
FunctionKind::AsyncGenerator { .. } => f
Self::AsyncGenerator { .. } => f
.debug_struct("FunctionKind::AsyncGenerator")
.finish_non_exhaustive(),
}
Expand Down
8 changes: 4 additions & 4 deletions boa_engine/src/builtins/intl/segmenter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ impl NativeSegmenter {
/// of the segments.
pub(crate) fn segment<'l, 's>(&'l self, input: &'s [u16]) -> NativeSegmentIterator<'l, 's> {
match self {
NativeSegmenter::Grapheme(g) => NativeSegmentIterator::Grapheme(g.segment_utf16(input)),
NativeSegmenter::Word(w) => NativeSegmentIterator::Word(w.segment_utf16(input)),
NativeSegmenter::Sentence(s) => NativeSegmentIterator::Sentence(s.segment_utf16(input)),
Self::Grapheme(g) => NativeSegmentIterator::Grapheme(g.segment_utf16(input)),
Self::Word(w) => NativeSegmentIterator::Word(w.segment_utf16(input)),
Self::Sentence(s) => NativeSegmentIterator::Sentence(s.segment_utf16(input)),
}
}
}
Expand Down Expand Up @@ -152,7 +152,7 @@ impl BuiltInConstructor for Segmenter {
.try_new_segmenter(granularity)
.map_err(|err| JsNativeError::typ().with_message(err.to_string()))?;

let segmenter = Segmenter {
let segmenter = Self {
locale,
native: kind,
};
Expand Down
6 changes: 3 additions & 3 deletions boa_engine/src/builtins/intl/segmenter/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ pub(crate) enum Granularity {
impl Display for Granularity {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Granularity::Grapheme => "grapheme",
Granularity::Word => "word",
Granularity::Sentence => "sentence",
Self::Grapheme => "grapheme",
Self::Word => "word",
Self::Sentence => "sentence",
}
.fmt(f)
}
Expand Down
2 changes: 1 addition & 1 deletion boa_engine/src/builtins/intl/segmenter/segments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl Segments {
// 5. Return segments.
JsObject::from_proto_and_data(
context.intrinsics().objects().segments_prototype(),
ObjectData::segments(Segments { segmenter, string }),
ObjectData::segments(Self { segmenter, string }),
)
}

Expand Down
22 changes: 11 additions & 11 deletions boa_engine/src/builtins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,19 +388,19 @@ impl BuiltInObjectInitializer {
P: Into<PropertyDescriptor>,
{
match self {
BuiltInObjectInitializer::Shared(obj) => obj.borrow_mut().insert(key, property),
BuiltInObjectInitializer::Unique { object, .. } => object.insert(key, property),
Self::Shared(obj) => obj.borrow_mut().insert(key, property),
Self::Unique { object, .. } => object.insert(key, property),
};
}

/// Sets the prototype of the builtin
fn set_prototype(&mut self, prototype: JsObject) {
match self {
BuiltInObjectInitializer::Shared(obj) => {
Self::Shared(obj) => {
let mut obj = obj.borrow_mut();
obj.set_prototype(prototype);
}
BuiltInObjectInitializer::Unique { object, .. } => {
Self::Unique { object, .. } => {
object.set_prototype(prototype);
}
}
Expand All @@ -414,34 +414,34 @@ impl BuiltInObjectInitializer {
/// builtin's vtable.
fn set_data(&mut self, new_data: ObjectData) {
match self {
BuiltInObjectInitializer::Shared(obj) => {
Self::Shared(obj) => {
assert!(
std::ptr::eq(obj.vtable(), new_data.internal_methods),
"intrinsic object's vtable didn't match with new data"
);
*obj.borrow_mut().kind_mut() = new_data.kind;
}
BuiltInObjectInitializer::Unique { ref mut data, .. } => *data = new_data,
Self::Unique { ref mut data, .. } => *data = new_data,
}
}

/// Gets a shared object from the builtin, transitioning its state if it's necessary.
fn as_shared(&mut self) -> JsObject {
match std::mem::replace(
self,
BuiltInObjectInitializer::Unique {
Self::Unique {
object: Object::default(),
data: ObjectData::ordinary(),
},
) {
BuiltInObjectInitializer::Shared(obj) => {
*self = BuiltInObjectInitializer::Shared(obj.clone());
Self::Shared(obj) => {
*self = Self::Shared(obj.clone());
obj
}
BuiltInObjectInitializer::Unique { mut object, data } => {
Self::Unique { mut object, data } => {
*object.kind_mut() = data.kind;
let obj = JsObject::from_object_and_vtable(object, data.internal_methods);
*self = BuiltInObjectInitializer::Shared(obj.clone());
*self = Self::Shared(obj.clone());
obj
}
}
Expand Down
14 changes: 7 additions & 7 deletions boa_engine/src/builtins/promise/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ pub enum PromiseState {
unsafe impl Trace for PromiseState {
custom_trace!(this, {
match this {
PromiseState::Fulfilled(v) | PromiseState::Rejected(v) => mark(v),
PromiseState::Pending => {}
Self::Fulfilled(v) | Self::Rejected(v) => mark(v),
Self::Pending => {}
}
});
}
Expand All @@ -53,7 +53,7 @@ impl PromiseState {
/// the state is not `Fulfilled`.
pub const fn as_fulfilled(&self) -> Option<&JsValue> {
match self {
PromiseState::Fulfilled(v) => Some(v),
Self::Fulfilled(v) => Some(v),
_ => None,
}
}
Expand All @@ -62,7 +62,7 @@ impl PromiseState {
/// the state is not `Rejected`.
pub const fn as_rejected(&self) -> Option<&JsValue> {
match self {
PromiseState::Rejected(v) => Some(v),
Self::Rejected(v) => Some(v),
_ => None,
}
}
Expand Down Expand Up @@ -432,7 +432,7 @@ impl BuiltInConstructor for Promise {
impl Promise {
/// Creates a new, pending `Promise`.
pub(crate) fn new() -> Self {
Promise {
Self {
state: PromiseState::Pending,
fulfill_reactions: Vec::default(),
reject_reactions: Vec::default(),
Expand Down Expand Up @@ -1440,7 +1440,7 @@ impl Promise {
JsNativeError::typ().with_message("Promise.reject() called on a non-object")
})?;

Promise::promise_reject(c, &JsError::from_opaque(r), context).map(JsValue::from)
Self::promise_reject(c, &JsError::from_opaque(r), context).map(JsValue::from)
}

/// Utility function to create a rejected promise.
Expand Down Expand Up @@ -1764,7 +1764,7 @@ impl Promise {
.and_then(JsFunction::from_object);

// continues in `Promise::inner_then`
Promise::inner_then(promise, on_fulfilled, on_rejected, context).map(JsValue::from)
Self::inner_then(promise, on_fulfilled, on_rejected, context).map(JsValue::from)
}

/// Schedules callback functions for the eventual completion of `promise` — either fulfillment
Expand Down
4 changes: 2 additions & 2 deletions boa_engine/src/environments/runtime/declarative/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ pub(crate) enum ThisBindingStatus {
unsafe impl Trace for ThisBindingStatus {
custom_trace!(this, {
match this {
ThisBindingStatus::Initialized(obj) => mark(obj),
ThisBindingStatus::Lexical | ThisBindingStatus::Uninitialized => {}
Self::Initialized(obj) => mark(obj),
Self::Lexical | Self::Uninitialized => {}
}
});
}
Expand Down
58 changes: 29 additions & 29 deletions boa_engine/src/environments/runtime/declarative/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub(crate) struct DeclarativeEnvironment {
impl DeclarativeEnvironment {
/// Creates a new global `DeclarativeEnvironment`.
pub(crate) fn global(global_this: JsObject) -> Self {
DeclarativeEnvironment {
Self {
kind: DeclarativeEnvironmentKind::Global(GlobalEnvironment::new(global_this)),
compile: Gc::new(GcRefCell::new(CompileTimeEnvironment::new_global())),
}
Expand Down Expand Up @@ -175,10 +175,10 @@ impl DeclarativeEnvironmentKind {
#[track_caller]
pub(crate) fn get(&self, index: usize) -> Option<JsValue> {
match self {
DeclarativeEnvironmentKind::Lexical(inner) => inner.get(index),
DeclarativeEnvironmentKind::Global(inner) => inner.get(index),
DeclarativeEnvironmentKind::Function(inner) => inner.get(index),
DeclarativeEnvironmentKind::Module(inner) => inner.get(index),
Self::Lexical(inner) => inner.get(index),
Self::Global(inner) => inner.get(index),
Self::Function(inner) => inner.get(index),
Self::Module(inner) => inner.get(index),
}
}

Expand All @@ -190,10 +190,10 @@ impl DeclarativeEnvironmentKind {
#[track_caller]
pub(crate) fn set(&self, index: usize, value: JsValue) {
match self {
DeclarativeEnvironmentKind::Lexical(inner) => inner.set(index, value),
DeclarativeEnvironmentKind::Global(inner) => inner.set(index, value),
DeclarativeEnvironmentKind::Function(inner) => inner.set(index, value),
DeclarativeEnvironmentKind::Module(inner) => inner.set(index, value),
Self::Lexical(inner) => inner.set(index, value),
Self::Global(inner) => inner.set(index, value),
Self::Function(inner) => inner.set(index, value),
Self::Module(inner) => inner.set(index, value),
}
}

Expand All @@ -207,10 +207,10 @@ impl DeclarativeEnvironmentKind {
/// [spec]: https://tc39.es/ecma262/#sec-function-environment-records-getthisbinding
pub(crate) fn get_this_binding(&self) -> JsResult<Option<JsValue>> {
match self {
DeclarativeEnvironmentKind::Lexical(_) => Ok(None),
DeclarativeEnvironmentKind::Global(g) => Ok(Some(g.get_this_binding().into())),
DeclarativeEnvironmentKind::Function(f) => f.get_this_binding(),
DeclarativeEnvironmentKind::Module(_) => Ok(Some(JsValue::undefined())),
Self::Lexical(_) => Ok(None),
Self::Global(g) => Ok(Some(g.get_this_binding().into())),
Self::Function(f) => f.get_this_binding(),
Self::Module(_) => Ok(Some(JsValue::undefined())),
}
}

Expand All @@ -224,39 +224,39 @@ impl DeclarativeEnvironmentKind {
/// [spec]: https://tc39.es/ecma262/#sec-function-environment-records-hasthisbinding
pub(crate) fn has_this_binding(&self) -> bool {
match self {
DeclarativeEnvironmentKind::Lexical(_) => false,
DeclarativeEnvironmentKind::Function(f) => f.has_this_binding(),
DeclarativeEnvironmentKind::Global(_) | DeclarativeEnvironmentKind::Module(_) => true,
Self::Lexical(_) => false,
Self::Function(f) => f.has_this_binding(),
Self::Global(_) | Self::Module(_) => true,
}
}

/// Returns `true` if this environment is poisoned.
pub(crate) fn poisoned(&self) -> bool {
match self {
DeclarativeEnvironmentKind::Lexical(lex) => lex.poisonable_environment().poisoned(),
DeclarativeEnvironmentKind::Global(g) => g.poisonable_environment().poisoned(),
DeclarativeEnvironmentKind::Function(f) => f.poisonable_environment().poisoned(),
DeclarativeEnvironmentKind::Module(_) => false,
Self::Lexical(lex) => lex.poisonable_environment().poisoned(),
Self::Global(g) => g.poisonable_environment().poisoned(),
Self::Function(f) => f.poisonable_environment().poisoned(),
Self::Module(_) => false,
}
}

/// Returns `true` if this environment is inside a `with` environment.
pub(crate) fn with(&self) -> bool {
match self {
DeclarativeEnvironmentKind::Lexical(lex) => lex.poisonable_environment().with(),
DeclarativeEnvironmentKind::Global(g) => g.poisonable_environment().with(),
DeclarativeEnvironmentKind::Function(f) => f.poisonable_environment().with(),
DeclarativeEnvironmentKind::Module(_) => false,
Self::Lexical(lex) => lex.poisonable_environment().with(),
Self::Global(g) => g.poisonable_environment().with(),
Self::Function(f) => f.poisonable_environment().with(),
Self::Module(_) => false,
}
}

/// Poisons this environment for future binding searches.
pub(crate) fn poison(&self) {
match self {
DeclarativeEnvironmentKind::Lexical(lex) => lex.poisonable_environment().poison(),
DeclarativeEnvironmentKind::Global(g) => g.poisonable_environment().poison(),
DeclarativeEnvironmentKind::Function(f) => f.poisonable_environment().poison(),
DeclarativeEnvironmentKind::Module(_) => {
Self::Lexical(lex) => lex.poisonable_environment().poison(),
Self::Global(g) => g.poisonable_environment().poison(),
Self::Function(f) => f.poisonable_environment().poison(),
Self::Module(_) => {
unreachable!("modules are always run in strict mode")
}
}
Expand All @@ -275,7 +275,7 @@ pub(crate) struct PoisonableEnvironment {
impl PoisonableEnvironment {
/// Creates a new `PoisonableEnvironment`.
pub(crate) fn new(bindings_count: usize, poisoned: bool, with: bool) -> Self {
PoisonableEnvironment {
Self {
bindings: GcRefCell::new(vec![None; bindings_count]),
poisoned: Cell::new(poisoned),
with: Cell::new(with),
Expand Down
2 changes: 1 addition & 1 deletion boa_engine/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ impl JsError {
///
/// This is a no-op if the error is not native or if the `realm` field of the error is already
/// set.
pub(crate) fn inject_realm(mut self, realm: Realm) -> JsError {
pub(crate) fn inject_realm(mut self, realm: Realm) -> Self {
match &mut self.inner {
Repr::Native(err) if err.realm.is_none() => {
err.realm = Some(realm);
Expand Down
2 changes: 0 additions & 2 deletions boa_engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@
clippy::missing_errors_doc,
clippy::let_unit_value,
clippy::option_if_let_else,
// Currently lints in places where `Self` would have a type parameter.
clippy::use_self,
// It may be worth to look if we can fix the issues highlighted by these lints.
clippy::cast_possible_truncation,
Expand Down
8 changes: 4 additions & 4 deletions boa_engine/src/module/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,15 +291,15 @@ impl Module {
src: Source<'_, R>,
realm: Option<Realm>,
context: &mut Context<'_>,
) -> JsResult<Module> {
) -> JsResult<Self> {
let _timer = Profiler::global().start_event("Module parsing", "Main");
let mut parser = Parser::new(src);
parser.set_identifier(context.next_parser_identifier());
let module = parser.parse_module(context.interner_mut())?;

let src = SourceTextModule::new(module);

let module = Module {
let module = Self {
inner: Gc::new(Inner {
realm: realm.unwrap_or_else(|| context.realm().clone()),
environment: GcRefCell::default(),
Expand Down Expand Up @@ -448,7 +448,7 @@ impl Module {
pub(crate) fn resolve_export(
&self,
export_name: Sym,
resolve_set: &mut FxHashSet<(Module, Sym)>,
resolve_set: &mut FxHashSet<(Self, Sym)>,
) -> Result<ResolvedBinding, ResolveExportError> {
match self.kind() {
ModuleKind::SourceText(src) => src.resolve_export(export_name, resolve_set),
Expand Down Expand Up @@ -714,7 +714,7 @@ impl ModuleNamespace {
// 7. Set M.[[Exports]] to sortedExports.
// 8. Create own properties of M corresponding to the definitions in 28.3.
let namespace = context.intrinsics().templates().namespace().create(
ObjectData::module_namespace(ModuleNamespace { module, exports }),
ObjectData::module_namespace(Self { module, exports }),
vec![js_string!("Module").into()],
);

Expand Down
Loading

0 comments on commit 4a368a2

Please sign in to comment.