Skip to content

Commit

Permalink
Changed deref() to *.
Browse files Browse the repository at this point in the history
  • Loading branch information
esdrubal committed Dec 1, 2023
1 parent b5ab97e commit 6be89ed
Show file tree
Hide file tree
Showing 61 changed files with 246 additions and 386 deletions.
8 changes: 3 additions & 5 deletions forc-plugins/forc-doc/src/doc/descriptor.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
//! Determine whether a [Declaration] is documentable.
use std::ops::Deref;

use crate::{
doc::{module::ModuleInfo, Document},
render::{
Expand All @@ -20,7 +18,7 @@ trait RequiredMethods {
impl RequiredMethods for Vec<DeclRefTraitFn> {
fn to_methods(&self, decl_engine: &DeclEngine) -> Vec<TyTraitFn> {
self.iter()
.map(|decl_ref| decl_engine.get_trait_fn(decl_ref).deref().clone())
.map(|decl_ref| (*decl_engine.get_trait_fn(decl_ref)).clone())
.collect()
}
}
Expand Down Expand Up @@ -117,7 +115,7 @@ impl Descriptor {
}
}
ty::TyDecl::TraitDecl(ty::TraitDecl { decl_id, .. }) => {
let trait_decl = decl_engine.get_trait(decl_id).deref().clone();
let trait_decl = (*decl_engine.get_trait(decl_id)).clone();
if !document_private_items && trait_decl.visibility.is_private() {
Ok(Descriptor::NonDocumentable)
} else {
Expand Down Expand Up @@ -165,7 +163,7 @@ impl Descriptor {
}
}
ty::TyDecl::AbiDecl(ty::AbiDecl { decl_id, .. }) => {
let abi_decl = decl_engine.get_abi(decl_id).deref().clone();
let abi_decl = (*decl_engine.get_abi(decl_id)).clone();
let item_name = abi_decl.name;
let attrs_opt =
(!abi_decl.attributes.is_empty()).then(|| abi_decl.attributes.to_html_string());
Expand Down
7 changes: 2 additions & 5 deletions forc-plugins/forc-doc/src/doc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
},
};
use anyhow::Result;
use std::{collections::HashMap, ops::Deref, option::Option};
use std::{collections::HashMap, option::Option};
use sway_core::{
decl_engine::DeclEngine,
language::ty::{TyAstNodeContent, TyDecl, TyImplTrait, TyModule, TyProgram, TySubmodule},
Expand Down Expand Up @@ -122,10 +122,7 @@ impl Documentation {
if let TyAstNodeContent::Declaration(ref decl) = ast_node.content {
if let TyDecl::ImplTrait(impl_trait) = decl {
impl_traits.push((
decl_engine
.get_impl_trait(&impl_trait.decl_id)
.deref()
.clone(),
(*decl_engine.get_impl_trait(&impl_trait.decl_id)).clone(),
module_info.clone(),
))
} else {
Expand Down
23 changes: 4 additions & 19 deletions forc-plugins/forc-doc/src/render/item/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
};
use anyhow::Result;
use horrorshow::{box_html, Raw, RenderBox, Template};
use std::{collections::BTreeMap, fmt::Write, ops::Deref};
use std::{collections::BTreeMap, fmt::Write};
use sway_core::language::ty::{
TyEnumVariant, TyImplTrait, TyStorageField, TyStructField, TyTraitFn, TyTraitItem,
};
Expand Down Expand Up @@ -53,12 +53,7 @@ impl Renderable for Context {
for field in fields {
let struct_field_id = format!("structfield.{}", field.name.as_str());
let type_anchor = render_type_anchor(
render_plan
.engines
.te()
.get(field.type_argument.type_id)
.deref()
.clone(),
(*render_plan.engines.te().get(field.type_argument.type_id)).clone(),
&render_plan,
&self.module_info,
);
Expand Down Expand Up @@ -86,12 +81,7 @@ impl Renderable for Context {
for field in fields {
let storage_field_id = format!("storagefield.{}", field.name.as_str());
let type_anchor = render_type_anchor(
render_plan
.engines
.te()
.get(field.type_argument.type_id)
.deref()
.clone(),
(*render_plan.engines.te().get(field.type_argument.type_id)).clone(),
&render_plan,
&self.module_info,
);
Expand Down Expand Up @@ -119,12 +109,7 @@ impl Renderable for Context {
for variant in variants {
let enum_variant_id = format!("variant.{}", variant.name.as_str());
let type_anchor = render_type_anchor(
render_plan
.engines
.te()
.get(variant.type_argument.type_id)
.deref()
.clone(),
(*render_plan.engines.te().get(variant.type_argument.type_id)).clone(),
&render_plan,
&self.module_info,
);
Expand Down
6 changes: 2 additions & 4 deletions forc-plugins/forc-doc/src/render/item/type_anchor.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
//! Creation of HTML anchors for types that can be linked.
use std::ops::Deref;

use crate::{doc::module::ModuleInfo, RenderPlan};
use anyhow::{anyhow, Result};
use horrorshow::{box_html, RenderBox};
Expand All @@ -25,7 +23,7 @@ pub(crate) fn render_type_anchor(
match type_info {
TypeInfo::Array(ty_arg, len) => {
let inner = render_type_anchor(
render_plan.engines.te().get(ty_arg.type_id).deref().clone(),
(*render_plan.engines.te().get(ty_arg.type_id)).clone(),
render_plan,
current_module_info,
)?;
Expand All @@ -39,7 +37,7 @@ pub(crate) fn render_type_anchor(
let mut rendered_args: Vec<_> = Vec::new();
for ty_arg in ty_args {
rendered_args.push(render_type_anchor(
render_plan.engines.te().get(ty_arg.type_id).deref().clone(),
(*render_plan.engines.te().get(ty_arg.type_id)).clone(),
render_plan,
current_module_info,
)?)
Expand Down
6 changes: 2 additions & 4 deletions sway-core/src/abi_generation/evm_abi.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::ops::Deref;

use sway_types::integer_bits::IntegerBits;

use crate::{
Expand Down Expand Up @@ -43,8 +41,8 @@ fn get_type_str(
)
} else {
match (
type_engine.get(*type_id).deref(),
type_engine.get(resolved_type_id).deref(),
&*type_engine.get(*type_id),
&*type_engine.get(resolved_type_id),
) {
(TypeInfo::Custom { .. }, TypeInfo::Struct { .. }) => {
format!(
Expand Down
16 changes: 7 additions & 9 deletions sway-core/src/abi_generation/fuel_abi.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::ops::Deref;

use fuel_abi_types::program_abi;
use sway_types::integer_bits::IntegerBits;

Expand Down Expand Up @@ -269,8 +267,8 @@ impl TypeId {
)
} else {
match (
type_engine.get(*self).deref(),
type_engine.get(resolved_type_id).deref(),
&*type_engine.get(*self),
&*type_engine.get(resolved_type_id),
) {
(TypeInfo::Custom { .. }, TypeInfo::Struct { .. }) => type_engine
.get(resolved_type_id)
Expand Down Expand Up @@ -344,7 +342,7 @@ impl TypeId {
types: &mut Vec<program_abi::TypeDeclaration>,
resolved_type_id: TypeId,
) -> Option<Vec<program_abi::TypeApplication>> {
match type_engine.get(*self).deref() {
match &*type_engine.get(*self) {
TypeInfo::Enum(decl_ref) => {
let decl = decl_engine.get_enum(decl_ref);
// A list of all `program_abi::TypeDeclaration`s needed for the enum variants
Expand Down Expand Up @@ -449,7 +447,7 @@ impl TypeId {
)
}
TypeInfo::Array(..) => {
if let TypeInfo::Array(elem_ty, _) = type_engine.get(resolved_type_id).deref() {
if let TypeInfo::Array(elem_ty, _) = &*type_engine.get(resolved_type_id) {
// The `program_abi::TypeDeclaration`s needed for the array element type
let elem_abi_ty = program_abi::TypeDeclaration {
type_id: elem_ty.initial_type_id.index(),
Expand Down Expand Up @@ -494,7 +492,7 @@ impl TypeId {
}
}
TypeInfo::Tuple(_) => {
if let TypeInfo::Tuple(fields) = type_engine.get(resolved_type_id).deref() {
if let TypeInfo::Tuple(fields) = &*type_engine.get(resolved_type_id) {
// A list of all `program_abi::TypeDeclaration`s needed for the tuple fields
let fields_types = fields
.iter()
Expand Down Expand Up @@ -597,7 +595,7 @@ impl TypeId {
}
}
TypeInfo::Alias { .. } => {
if let TypeInfo::Alias { ty, .. } = type_engine.get(resolved_type_id).deref() {
if let TypeInfo::Alias { ty, .. } = &*type_engine.get(resolved_type_id) {
ty.initial_type_id.get_abi_type_components(
ctx,
type_engine,
Expand Down Expand Up @@ -627,7 +625,7 @@ impl TypeId {
resolved_type_id: TypeId,
) -> Option<Vec<program_abi::TypeApplication>> {
let resolved_params = resolved_type_id.get_type_parameters(type_engine, decl_engine);
match type_engine.get(*self).deref() {
match &*type_engine.get(*self) {
TypeInfo::Custom {
type_arguments: Some(type_arguments),
..
Expand Down
4 changes: 2 additions & 2 deletions sway-core/src/concurrent_slab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ where
T: Clone,
{
pub fn len(&self) -> usize {
let lock = self.inner.read().unwrap();
lock.len()
let inner = self.inner.read().unwrap();
inner.len()
}

pub fn insert(&self, value: T) -> usize {
Expand Down
4 changes: 1 addition & 3 deletions sway-core/src/control_flow_analysis/analyze_return_paths.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//! This is the flow graph, a graph which contains edges that represent possible steps of program
//! execution.
use std::ops::Deref;

use crate::{
control_flow_analysis::*,
language::{
Expand Down Expand Up @@ -225,7 +223,7 @@ fn connect_declaration<'eng: 'cfg, 'cfg>(
let impl_trait = decl_engine.get_impl_trait(decl_id);
let ty::TyImplTrait {
trait_name, items, ..
} = impl_trait.deref();
} = &*impl_trait;
let entry_node = graph.add_node(ControlFlowGraphNode::from_node(node));
for leaf in leaves {
graph.add_edge(*leaf, entry_node, "".into());
Expand Down
13 changes: 5 additions & 8 deletions sway-core/src/control_flow_analysis/dead_code_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ use crate::{
Engines, TypeArgument, TypeEngine, TypeId,
};
use petgraph::{prelude::NodeIndex, visit::Dfs};
use std::{
collections::{BTreeSet, HashMap},
ops::Deref,
};
use std::collections::{BTreeSet, HashMap};
use sway_ast::Intrinsic;
use sway_error::{error::CompileError, type_error::TypeError};
use sway_error::{
Expand Down Expand Up @@ -490,7 +487,7 @@ fn connect_declaration<'eng: 'cfg, 'cfg>(
let const_decl = decl_engine.get_constant(decl_id);
let ty::TyConstantDecl {
call_path, value, ..
} = const_decl.deref();
} = &*const_decl;
graph
.namespace
.insert_global_constant(call_path.suffix.clone(), entry_node);
Expand Down Expand Up @@ -550,7 +547,7 @@ fn connect_declaration<'eng: 'cfg, 'cfg>(
trait_decl_ref,
implementing_for,
..
} = impl_trait_decl.deref();
} = &*impl_trait_decl;

connect_impl_trait(
engines,
Expand Down Expand Up @@ -2091,7 +2088,7 @@ fn construct_dead_code_warning_from_node(
})),
span,
} => {
let ty::TyImplTrait { .. } = decl_engine.get_impl_trait(decl_id).deref();
let ty::TyImplTrait { .. } = &*decl_engine.get_impl_trait(decl_id);
CompileWarning {
span: span.clone(),
warning_content: Warning::DeadDeclaration,
Expand Down Expand Up @@ -2177,7 +2174,7 @@ fn connect_type_id<'eng: 'cfg, 'cfg>(
let decl_engine = engines.de();
let type_engine = engines.te();

match type_engine.get(type_id).deref() {
match &*type_engine.get(type_id) {
TypeInfo::Enum(decl_ref) => {
let decl = decl_engine.get_enum(decl_ref);
let enum_idx = graph.namespace.find_enum(decl.name());
Expand Down
5 changes: 2 additions & 3 deletions sway-core/src/decl_engine/engine.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::{
collections::{HashMap, HashSet, VecDeque},
fmt::Write,
ops::Deref,
sync::{Arc, RwLock},
};

Expand Down Expand Up @@ -288,7 +287,7 @@ impl DeclEngine {
for i in 0..self.trait_slab.len() {
let trait_decl = self.trait_slab.get(i);
if trait_decl.name == *trait_name {
vec.push(trait_decl.deref().clone())
vec.push((*trait_decl).clone())
}
}
vec
Expand Down Expand Up @@ -411,7 +410,7 @@ impl DeclEngine {
for i in 0..self.function_slab.len() {
list.push(format!(
"{:?}",
engines.help_out(self.function_slab.get(i).deref())
engines.help_out(&*self.function_slab.get(i))
));
}
let list = ListDisplay { list };
Expand Down
17 changes: 8 additions & 9 deletions sway-core/src/decl_engine/id.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::marker::PhantomData;
use std::ops::Deref;
use std::{fmt, hash::Hash};

use crate::language::ty::TyTraitType;
Expand Down Expand Up @@ -84,55 +83,55 @@ impl<T> Into<usize> for DeclId<T> {
impl SubstTypes for DeclId<TyFunctionDecl> {
fn subst_inner(&mut self, type_mapping: &TypeSubstMap, engines: &Engines) {
let decl_engine = engines.de();
let mut decl = decl_engine.get(self).deref().clone();
let mut decl = (*decl_engine.get(self)).clone();
decl.subst(type_mapping, engines);
decl_engine.replace(*self, decl);
}
}
impl SubstTypes for DeclId<TyTraitDecl> {
fn subst_inner(&mut self, type_mapping: &TypeSubstMap, engines: &Engines) {
let decl_engine = engines.de();
let mut decl = decl_engine.get(self).deref().clone();
let mut decl = (*decl_engine.get(self)).clone();
decl.subst(type_mapping, engines);
decl_engine.replace(*self, decl);
}
}
impl SubstTypes for DeclId<TyTraitFn> {
fn subst_inner(&mut self, type_mapping: &TypeSubstMap, engines: &Engines) {
let decl_engine = engines.de();
let mut decl = decl_engine.get(self).deref().clone();
let mut decl = (*decl_engine.get(self)).clone();
decl.subst(type_mapping, engines);
decl_engine.replace(*self, decl);
}
}
impl SubstTypes for DeclId<TyImplTrait> {
fn subst_inner(&mut self, type_mapping: &TypeSubstMap, engines: &Engines) {
let decl_engine = engines.de();
let mut decl = decl_engine.get(self).deref().clone();
let mut decl = (*decl_engine.get(self)).clone();
decl.subst(type_mapping, engines);
decl_engine.replace(*self, decl);
}
}
impl SubstTypes for DeclId<TyStructDecl> {
fn subst_inner(&mut self, type_mapping: &TypeSubstMap, engines: &Engines) {
let decl_engine = engines.de();
let mut decl = decl_engine.get(self).deref().clone();
let mut decl = (*decl_engine.get(self)).clone();
decl.subst(type_mapping, engines);
decl_engine.replace(*self, decl);
}
}
impl SubstTypes for DeclId<TyEnumDecl> {
fn subst_inner(&mut self, type_mapping: &TypeSubstMap, engines: &Engines) {
let decl_engine = engines.de();
let mut decl = decl_engine.get(self).deref().clone();
let mut decl = (*decl_engine.get(self)).clone();
decl.subst(type_mapping, engines);
decl_engine.replace(*self, decl);
}
}
impl SubstTypes for DeclId<TyTypeAliasDecl> {
fn subst_inner(&mut self, type_mapping: &TypeSubstMap, engines: &Engines) {
let decl_engine = engines.de();
let mut decl = decl_engine.get(self).deref().clone();
let mut decl = (*decl_engine.get(self)).clone();
decl.subst(type_mapping, engines);
decl_engine.replace(*self, decl);
}
Expand All @@ -141,7 +140,7 @@ impl SubstTypes for DeclId<TyTypeAliasDecl> {
impl SubstTypes for DeclId<TyTraitType> {
fn subst_inner(&mut self, type_mapping: &TypeSubstMap, engines: &Engines) {
let decl_engine = engines.de();
let mut decl = decl_engine.get(self).deref().clone();
let mut decl = (*decl_engine.get(self)).clone();
decl.subst(type_mapping, engines);
decl_engine.replace(*self, decl);
}
Expand Down
Loading

0 comments on commit 6be89ed

Please sign in to comment.