From 2fa2425ef5d32deaacc78799e8d31cb9d0c64a21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20K=C3=B6ppe?= Date: Fri, 4 Apr 2025 18:49:40 +0100 Subject: [PATCH] Minor clang-tidy recommended cleanup (#5248) Some minor code health improvements discovered by clang-tidy: * avoid copying; use const reference * harmonize parameter names * use more efficient absl::StrSplit-by-character --- explorer/file_test.cpp | 2 +- explorer/interpreter/matching_impl_set.cpp | 2 +- explorer/interpreter/type_checker.cpp | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/explorer/file_test.cpp b/explorer/file_test.cpp index b743e7ef86e3..ac30949f51b6 100644 --- a/explorer/file_test.cpp +++ b/explorer/file_test.cpp @@ -122,7 +122,7 @@ class ExplorerFileTest : public FileTestBase { auto GetFileTestManifest() -> llvm::SmallVector { llvm::SmallVector manifest; auto content = ReadFile(absl::GetFlag(FLAGS_explorer_test_targets_file)); - for (const auto& line : absl::StrSplit(*content, "\n", absl::SkipEmpty())) { + for (const auto& line : absl::StrSplit(*content, '\n', absl::SkipEmpty())) { manifest.push_back(std::string(line)); } return manifest; diff --git a/explorer/interpreter/matching_impl_set.cpp b/explorer/interpreter/matching_impl_set.cpp index c27b29d27afd..cfd918cefb0d 100644 --- a/explorer/interpreter/matching_impl_set.cpp +++ b/explorer/interpreter/matching_impl_set.cpp @@ -50,7 +50,7 @@ class MatchingImplSet::LeafCollector { void VisitValue(const StructType* struct_type) { Collect(Label::StructType); - for (auto [name, type] : struct_type->fields()) { + for (const auto& [name, type] : struct_type->fields()) { Collect(type); } } diff --git a/explorer/interpreter/type_checker.cpp b/explorer/interpreter/type_checker.cpp index 907df792a5d1..a27d941bc7ad 100644 --- a/explorer/interpreter/type_checker.cpp +++ b/explorer/interpreter/type_checker.cpp @@ -2095,15 +2095,15 @@ class TypeChecker::SubstitutedGenericBindings { }; auto TypeChecker::Substitute(const Bindings& bindings, - Nonnull type) const + Nonnull value) const -> ErrorOr> { // Don't waste time recursively rebuilding a type if we have nothing to // substitute. if (bindings.empty()) { - return type; + return value; } - CARBON_ASSIGN_OR_RETURN(const auto* result, SubstituteImpl(bindings, type)); + CARBON_ASSIGN_OR_RETURN(const auto* result, SubstituteImpl(bindings, value)); if (trace_stream_->is_enabled()) { trace_stream_->Substitute() << "substitution of ["; @@ -2114,7 +2114,7 @@ auto TypeChecker::Substitute(const Bindings& bindings, for (const auto& [name, value] : bindings.witnesses()) { *trace_stream_ << sep << "`" << *name << "` -> `" << *value << "`"; } - *trace_stream_ << "]\n - old: `" << *type << "`\n + new: `" << *result + *trace_stream_ << "]\n - old: `" << *value << "`\n + new: `" << *result << "`\n"; } return result;