From 951cac960774e5adeba907c011a4c7e5f3b8347f Mon Sep 17 00:00:00 2001 From: Manmeet Singh <49202620+Maan2003@users.noreply.github.com> Date: Mon, 17 Apr 2023 22:45:11 +0530 Subject: [PATCH] clang-tidy cleanup (#2774) running clang-tidy locally got a bunch of warning. I have ignored `bugprone-unchecked-optional-access` for now, because there are large number of occurrences. --- explorer/ast/clone_context.cpp | 2 +- explorer/ast/declaration.cpp | 2 +- explorer/interpreter/impl_scope.cpp | 6 +----- explorer/interpreter/type_checker.cpp | 8 ++++---- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/explorer/ast/clone_context.cpp b/explorer/ast/clone_context.cpp index a7c86814cfb3..f5b2eed35ee7 100644 --- a/explorer/ast/clone_context.cpp +++ b/explorer/ast/clone_context.cpp @@ -64,7 +64,7 @@ class CloneContext::CloneValueTransform // A FunctionType may or may not own its bindings. auto operator()(Nonnull fn_type) -> Nonnull { - for (auto* binding : fn_type->deduced_bindings()) { + for (const auto* binding : fn_type->deduced_bindings()) { context_->MaybeCloneBase(binding); } for (auto [index, binding] : fn_type->generic_parameters()) { diff --git a/explorer/ast/declaration.cpp b/explorer/ast/declaration.cpp index 2ce8caaa137a..141ab7b68cda 100644 --- a/explorer/ast/declaration.cpp +++ b/explorer/ast/declaration.cpp @@ -158,7 +158,7 @@ void Declaration::PrintID(llvm::raw_ostream& out) const { if (!impl_decl.deduced_parameters().empty()) { out << "forall ["; llvm::ListSeparator sep; - for (auto* param : impl_decl.deduced_parameters()) { + for (const auto* param : impl_decl.deduced_parameters()) { out << sep << *param; } out << "] "; diff --git a/explorer/interpreter/impl_scope.cpp b/explorer/interpreter/impl_scope.cpp index 02df59ed0cd0..b8926536cd28 100644 --- a/explorer/interpreter/impl_scope.cpp +++ b/explorer/interpreter/impl_scope.cpp @@ -11,7 +11,6 @@ using llvm::cast; using llvm::dyn_cast; -using llvm::isa; namespace Carbon { @@ -251,10 +250,7 @@ auto ImplScope::VisitEqualValues( return false; } } - if (parent_scope_ && !(*parent_scope_)->VisitEqualValues(value, visitor)) { - return false; - } - return true; + return !parent_scope_ || (*parent_scope_)->VisitEqualValues(value, visitor); } auto ImplScope::TryResolveInterface(Nonnull iface_type, diff --git a/explorer/interpreter/type_checker.cpp b/explorer/interpreter/type_checker.cpp index a8728cf86b89..7cf670b12b9d 100644 --- a/explorer/interpreter/type_checker.cpp +++ b/explorer/interpreter/type_checker.cpp @@ -411,7 +411,7 @@ static auto IsConcreteType(Nonnull value) -> bool { // depends on any template paramaeter. static auto IsTemplateDependent(Nonnull value) -> bool { // A VariableType is template dependent if it names a template binding. - if (auto* var_type = dyn_cast(value)) { + if (const auto* var_type = dyn_cast(value)) { return var_type->binding().binding_kind() == GenericBinding::BindingKind::Template; } @@ -448,7 +448,7 @@ static auto IsTemplateSaturated(const Bindings& bindings) -> bool { // have template argument values specified. static auto IsTemplateSaturated( llvm::ArrayRef> bindings) -> bool { - for (auto* binding : bindings) { + for (const auto* binding : bindings) { if (binding->binding_kind() == GenericBinding::BindingKind::Template && !binding->has_template_value()) { return false; @@ -5583,7 +5583,7 @@ auto TypeChecker::CheckAndAddImplBindings( iface_witness, iface_scope)); std::optional sort_key; - if (deduced_bindings.size()) { + if (!deduced_bindings.empty()) { sort_key = TypeStructureSortKey::ForImpl(impl_type, iface_type); if (trace_stream_->is_enabled()) { *trace_stream_ << "type structure sort key for `impl " << *impl_type @@ -5622,7 +5622,7 @@ auto TypeChecker::DeclareImplDeclaration(Nonnull impl_decl, if (!IsTemplateSaturated(impl_decl->deduced_parameters())) { CloneContext context(arena_); TemplateInfo template_info = {.pattern = context.Clone(impl_decl)}; - for (auto deduced : impl_decl->deduced_parameters()) { + for (const auto* deduced : impl_decl->deduced_parameters()) { template_info.param_map.insert( {deduced, context.GetExistingClone(deduced)}); }