Skip to content

Commit

Permalink
Cargo clippy fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
esdrubal committed Dec 12, 2024
1 parent 8f5ff08 commit c5f0f07
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 17 deletions.
6 changes: 3 additions & 3 deletions sway-core/src/semantic_analysis/ast_node/declaration/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl ty::TyAbiDecl {
// A temporary namespace for checking within this scope.
ctx.with_abi_mode(AbiMode::ImplAbiFn(name.clone(), None))
.with_self_type(Some(self_type_id))
.scoped(handler, Some(span.clone()), |mut ctx| {
.scoped(handler, Some(span.clone()), |ctx| {
// Insert the "self" type param into the namespace.
self_type_param.insert_self_type_into_namespace(handler, ctx.by_ref());

Expand Down Expand Up @@ -134,7 +134,7 @@ impl ty::TyAbiDecl {
let method = engines.pe().get_trait_fn(&decl_id);
// check that a super-trait does not define a method
// with the same name as the current interface method
error_on_shadowing_superabi_method(&method.name, &mut ctx);
error_on_shadowing_superabi_method(&method.name, ctx);
let method = ty::TyTraitFn::type_check(handler, ctx.by_ref(), &method)?;
for param in &method.parameters {
if param.is_reference || param.is_mutable {
Expand Down Expand Up @@ -200,7 +200,7 @@ impl ty::TyAbiDecl {
Some(self_type_param.type_id),
)
.unwrap_or_else(|_| ty::TyFunctionDecl::error(&method));
error_on_shadowing_superabi_method(&method.name, &mut ctx);
error_on_shadowing_superabi_method(&method.name, ctx);
for param in &method.parameters {
if param.is_reference || param.is_mutable {
handler.emit_err(CompileError::RefMutableNotAllowedInContractAbi {
Expand Down
2 changes: 1 addition & 1 deletion sway-core/src/semantic_analysis/namespace/lexical_scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub struct LexicalScope {
pub children: Vec<LexicalScopeId>,
/// The parent scope associated with this scope. Will be None for a root scope.
pub parent: Option<LexicalScopeId>,
/// The parent while visiting scopes and push poping scopes from a stack.
/// The parent while visiting scopes and push popping scopes from a stack.
/// This may differ from parent as we may revisit the scope in a different order during type check.
pub visitor_parent: Option<LexicalScopeId>,
/// The declaration associated with this scope. This will initially be a [ParsedDeclId],
Expand Down
32 changes: 27 additions & 5 deletions sway-core/src/semantic_analysis/namespace/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,30 @@ impl Root {
};

// Collect all items declared in the source module
for (symbol, decl) in src_mod.root_items().symbols.iter() {
let mut symbols = src_mod
.root_items()
.symbols
.keys()
.clone()
.collect::<Vec<_>>();
symbols.sort();
for symbol in symbols {
let decl = &src_mod.root_items().symbols[symbol];
if is_ancestor(src, dst) || decl.visibility(engines).is_public() {
decls_and_item_imports.push((symbol.clone(), decl.clone(), src.to_vec()));
}
}
// Collect those item-imported items that the source module reexports
// These live in the same namespace as local declarations, so no shadowing is possible
for (symbol, (_, path, decl, src_visibility)) in
src_mod.root_items().use_item_synonyms.iter()
{
let mut symbols = src_mod
.root_items()
.use_item_synonyms
.keys()
.clone()
.collect::<Vec<_>>();
symbols.sort();
for symbol in symbols {
let (_, path, decl, src_visibility) = &src_mod.root_items().use_item_synonyms[symbol];
if src_visibility.is_public() {
decls_and_item_imports.push((symbol.clone(), decl.clone(), get_path(path.clone())))
}
Expand All @@ -221,7 +235,15 @@ impl Root {
// by local declarations and item imports in the source module, so they are treated
// separately.
let mut glob_imports = vec![];
for (symbol, bindings) in src_mod.root_items().use_glob_synonyms.iter() {
let mut symbols = src_mod
.root_items()
.use_glob_synonyms
.keys()
.clone()
.collect::<Vec<_>>();
symbols.sort();
for symbol in symbols {
let bindings = &src_mod.root_items().use_glob_synonyms[symbol];
// Ignore if the symbol is shadowed by a local declaration or an item import in the source module
if !decls_and_item_imports
.iter()
Expand Down
24 changes: 16 additions & 8 deletions sway-core/src/semantic_analysis/namespace/trait_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ struct TraitEntry {
/// don't need to traverse every TraitEntry.
type TraitImpls = HashMap<TypeRootFilter, Vec<TraitEntry>>;

#[derive(Clone, Hash, Eq, PartialEq, Debug)]
#[derive(Clone, Hash, Eq, PartialOrd, Ord, PartialEq, Debug)]
enum TypeRootFilter {
Unknown,
Never,
Expand Down Expand Up @@ -379,7 +379,10 @@ impl TraitMap {
} else if types_are_subset
&& (traits_are_subset || matches!(is_impl_self, IsImplSelf::Yes))
{
for (name, item) in trait_items.iter() {
let mut names = trait_items.keys().clone().collect::<Vec<_>>();
names.sort();
for name in names {
let item = &trait_items[name];
match item {
ResolvedTraitImplItem::Parsed(_item) => todo!(),
ResolvedTraitImplItem::Typed(item) => match item {
Expand Down Expand Up @@ -474,8 +477,7 @@ impl TraitMap {
let entry = TraitEntry { key, value };
let mut trait_impls: TraitImpls = HashMap::<TypeRootFilter, Vec<TraitEntry>>::new();
let type_root_filter = Self::get_type_root_filter(engines, type_id);
let mut impls_vector = Vec::<TraitEntry>::new();
impls_vector.push(entry);
let impls_vector = vec![entry];
trait_impls.insert(type_root_filter, impls_vector);

let trait_map = TraitMap {
Expand Down Expand Up @@ -601,7 +603,10 @@ impl TraitMap {
/// Given [TraitMap]s `self` and `other`, extend `self` with `other`,
/// extending existing entries when possible.
pub(crate) fn extend(&mut self, other: TraitMap, engines: &Engines) {
for (impls_key, oe_vec) in other.trait_impls.iter() {
let mut impls_keys = other.trait_impls.keys().clone().collect::<Vec<_>>();
impls_keys.sort();
for impls_key in impls_keys {
let oe_vec = &other.trait_impls[impls_key];
let self_vec = if let Some(self_vec) = self.trait_impls.get_mut(impls_key) {
self_vec
} else {
Expand Down Expand Up @@ -630,7 +635,10 @@ impl TraitMap {
/// the entries from `self` that implement a trait from the declaration with that span.
pub(crate) fn filter_by_trait_decl_span(&self, trait_decl_span: Span) -> TraitMap {
let mut trait_map = TraitMap::default();
for (key, vec) in self.trait_impls.iter() {
let mut keys = self.trait_impls.keys().clone().collect::<Vec<_>>();
keys.sort();
for key in keys {
let vec = &self.trait_impls[key];
for entry in vec {
if entry
.key
Expand Down Expand Up @@ -1115,8 +1123,8 @@ impl TraitMap {
.items
.implemented_traits
.trait_impls
.iter()
.map(|(_, impls)| {
.values()
.map(|impls| {
impls
.iter()
.filter_map(|entry| {
Expand Down

0 comments on commit c5f0f07

Please sign in to comment.