Ver Fonte

clang-tidy --fix (#2577)

Only automatic fixes.
Jon Ross-Perkins há 3 anos atrás
pai
commit
4e1b585fcf

+ 1 - 1
common/vlog_internal.h

@@ -18,7 +18,7 @@ class VLoggingStream {
   // Internal type used in macros to dispatch to the `operator|` overload.
   struct Helper {};
 
-  VLoggingStream(llvm::raw_ostream* stream)
+  explicit VLoggingStream(llvm::raw_ostream* stream)
       // Prefix the buffer with the current bug report message.
       : stream_(stream) {}
 

+ 1 - 1
explorer/ast/declaration.h

@@ -175,7 +175,7 @@ class NamespaceDeclaration : public Declaration {
 
   explicit NamespaceDeclaration(SourceLocation source_loc, std::string name)
       : Declaration(AstNodeKind::NamespaceDeclaration, source_loc),
-        name_(name) {}
+        name_(std::move(name)) {}
 
   static auto classof(const AstNode* node) -> bool {
     return InheritsFromNamespaceDeclaration(node->kind());

+ 1 - 1
explorer/ast/statement.h

@@ -163,7 +163,7 @@ class IncrementDecrement : public Statement {
   auto argument() const -> const Expression& { return *argument_; }
   auto argument() -> Expression& { return *argument_; }
 
-  bool is_increment() const { return is_increment_; }
+  auto is_increment() const -> bool { return is_increment_; }
 
   // Set the rewritten form of this statement. Can only be called during type
   // checking.

+ 1 - 1
explorer/ast/static_scope.h

@@ -35,7 +35,7 @@ class StaticScope {
   };
 
   // Construct a root scope.
-  StaticScope() {}
+  StaticScope() = default;
 
   // Construct a scope that is nested within the given scope.
   explicit StaticScope(Nonnull<const StaticScope*> parent)

+ 2 - 2
explorer/interpreter/impl_scope.cpp

@@ -171,7 +171,7 @@ auto ImplScope::Resolve(Nonnull<const Value*> constraint_type,
                                    current, &equality_ctx));
         }
       }
-      for (auto& rewrite : rewrites) {
+      for (const auto& rewrite : rewrites) {
         Nonnull<const Value*> constant =
             type_checker.Substitute(local_bindings, rewrite.constant);
         Nonnull<const Value*> value = type_checker.Substitute(
@@ -260,7 +260,7 @@ static auto CombineResults(Nonnull<const InterfaceType*> iface_type,
   if (impl_a->declaration().match_first() &&
       impl_a->declaration().match_first() ==
           impl_b->declaration().match_first()) {
-    for (auto* impl : (*impl_a->declaration().match_first())->impls()) {
+    for (const auto* impl : (*impl_a->declaration().match_first())->impls()) {
       if (impl == &impl_a->declaration()) {
         return a;
       }

+ 5 - 5
explorer/interpreter/interpreter.cpp

@@ -576,7 +576,7 @@ auto Interpreter::EvalAssociatedConstant(
   Nonnull<const ConstraintType*> constraint =
       impl_witness->declaration().constraint_type();
   std::optional<Nonnull<const Value*>> result;
-  for (auto& rewrite : constraint->rewrite_constraints()) {
+  for (const auto& rewrite : constraint->rewrite_constraints()) {
     if (&rewrite.constant->constant() == &assoc->constant() &&
         TypeEqual(&rewrite.constant->interface(), interface, std::nullopt)) {
       // TODO: The value might depend on the parameters of the impl. We need to
@@ -869,7 +869,7 @@ auto Interpreter::Convert(Nonnull<const Value*> value,
       CARBON_ASSIGN_OR_RETURN(
           Nonnull<const Value*> value,
           EvalAssociatedConstant(cast<AssociatedConstant>(value), source_loc));
-      if (auto* new_const = dyn_cast<AssociatedConstant>(value)) {
+      if (const auto* new_const = dyn_cast<AssociatedConstant>(value)) {
         // TODO: Detect whether conversions are required in type-checking.
         if (isa<TypeType, ConstraintType, NamedConstraintType, InterfaceType>(
                 destination_type) &&
@@ -933,7 +933,7 @@ auto Interpreter::CallDestructor(Nonnull<const DestructorDeclaration*> fun,
   BindingMap generic_args;
 
   // TODO: move this logic into PatternMatch, and call it here.
-  auto p = &method.self_pattern().value();
+  const auto* p = &method.self_pattern().value();
   const auto& placeholder = cast<BindingPlaceholderValue>(*p);
   if (placeholder.value_node().has_value()) {
     method_scope.Bind(*placeholder.value_node(), receiver);
@@ -1015,7 +1015,7 @@ auto Interpreter::CallFunction(const CallExpression& call,
       RuntimeScope method_scope(&heap_);
       BindingMap generic_args;
       // Bind the receiver to the `self` parameter.
-      auto p = &method.self_pattern().value();
+      const auto* p = &method.self_pattern().value();
       if (p->kind() == Value::Kind::BindingPlaceholderValue) {
         // TODO: move this logic into PatternMatch
         const auto& placeholder = cast<BindingPlaceholderValue>(*p);
@@ -1627,7 +1627,7 @@ auto Interpreter::StepExp() -> ErrorOr<Success> {
     case ExpressionKind::ArrayTypeLiteral:
     case ExpressionKind::ValueLiteral: {
       CARBON_CHECK(act.pos() == 0);
-      auto* value = &cast<ConstantValueLiteral>(exp).constant_value();
+      const auto* value = &cast<ConstantValueLiteral>(exp).constant_value();
       CARBON_ASSIGN_OR_RETURN(
           Nonnull<const Value*> destination,
           InstantiateType(&exp.static_type(), exp.source_loc()));

+ 22 - 19
explorer/interpreter/type_checker.cpp

@@ -817,20 +817,21 @@ auto TypeChecker::ExpectNonPlaceholderType(SourceLocation source_loc,
   if (!IsPlaceholderType(type)) {
     return Success();
   }
-  if (auto* member_name = dyn_cast<TypeOfMemberName>(type)) {
+  if (const auto* member_name = dyn_cast<TypeOfMemberName>(type)) {
     return ProgramError(source_loc)
            << *member_name << " can only be used in a member access or alias";
   }
-  if (auto* param_entity = dyn_cast<TypeOfParameterizedEntityName>(type)) {
+  if (const auto* param_entity =
+          dyn_cast<TypeOfParameterizedEntityName>(type)) {
     return ProgramError(source_loc)
            << "'" << param_entity->name() << "' must be given an argument list";
   }
-  if (auto* mixin_type = dyn_cast<TypeOfMixinPseudoType>(type)) {
+  if (const auto* mixin_type = dyn_cast<TypeOfMixinPseudoType>(type)) {
     return ProgramError(source_loc)
            << "invalid use of mixin "
            << mixin_type->mixin_type().declaration().name();
   }
-  if (auto* namespace_type = dyn_cast<TypeOfNamespaceName>(type)) {
+  if (const auto* namespace_type = dyn_cast<TypeOfNamespaceName>(type)) {
     return ProgramError(source_loc)
            << "expected `.member_name` after name of " << *namespace_type;
   }
@@ -1320,7 +1321,7 @@ static auto LookupRewrite(llvm::ArrayRef<RewriteConstraint> rewrites,
     return std::nullopt;
   }
 
-  for (auto& rewrite : rewrites) {
+  for (const auto& rewrite : rewrites) {
     if (ValueEqual(interface, &rewrite.constant->interface(), std::nullopt) &&
         member == &rewrite.constant->constant()) {
       // A ConstraintType can only have one rewrite per (interface, member)
@@ -1596,7 +1597,7 @@ class TypeChecker::ConstraintTypeBuilder {
     // Add all of the new constraints.
     impl_scope->Add(new_impl_constraints, std::nullopt, std::nullopt,
                     GetSelfWitness(), type_checker);
-    for (auto& equal : new_equality_constraints) {
+    for (const auto& equal : new_equality_constraints) {
       impl_scope->AddEqualityConstraint(arena_->New<EqualityConstraint>(equal));
     }
   }
@@ -1670,7 +1671,7 @@ class TypeChecker::ConstraintTypeBuilder {
       if (auto existing_rewrite = LookupRewrite(
               new_rewrite_constraints, &rewrite_a.constant->interface(),
               &rewrite_a.constant->constant())) {
-        auto& rewrite_b = **existing_rewrite;
+        const auto& rewrite_b = **existing_rewrite;
         if (ValueEqual(rewrite_a.unconverted_replacement,
                        rewrite_b.unconverted_replacement, std::nullopt) &&
             TypeEqual(rewrite_a.unconverted_replacement_type,
@@ -1886,7 +1887,7 @@ auto TypeChecker::Substitute(const Bindings& bindings,
     return type;
   }
 
-  auto* result = SubstituteImpl(bindings, type);
+  const auto* result = SubstituteImpl(bindings, type);
 
   if (trace_stream_) {
     **trace_stream_ << "substitution of {";
@@ -1923,7 +1924,7 @@ class TypeChecker::SubstituteTransform
       -> Nonnull<const Value*> {
     auto it = bindings_.args().find(&var_type->binding());
     if (it == bindings_.args().end()) {
-      if (auto& trace_stream = type_checker_->trace_stream_) {
+      if (const auto& trace_stream = type_checker_->trace_stream_) {
         **trace_stream << "substitution: no value for binding " << *var_type
                        << ", leaving alone\n";
       }
@@ -1938,7 +1939,7 @@ class TypeChecker::SubstituteTransform
       -> Nonnull<const Value*> {
     auto it = bindings_.witnesses().find(witness->binding());
     if (it == bindings_.witnesses().end()) {
-      if (auto& trace_stream = type_checker_->trace_stream_) {
+      if (const auto& trace_stream = type_checker_->trace_stream_) {
         **trace_stream << "substitution: no value for binding " << *witness
                        << ", leaving alone\n";
       }
@@ -2019,7 +2020,7 @@ class TypeChecker::SubstituteTransform
       } else {
         type_of_type = type_checker_->arena_->New<TypeType>();
       }
-      if (auto& trace_stream = type_checker_->trace_stream_) {
+      if (const auto& trace_stream = type_checker_->trace_stream_) {
         **trace_stream << "substitution: self of constraint " << *constraint
                        << " is substituted, new type of type is "
                        << *type_of_type << "\n";
@@ -2034,7 +2035,7 @@ class TypeChecker::SubstituteTransform
                              builder.GetSelfWitness(), bindings_,
                              /*add_lookup_contexts=*/true);
     Nonnull<const ConstraintType*> new_constraint = std::move(builder).Build();
-    if (auto& trace_stream = type_checker_->trace_stream_) {
+    if (const auto& trace_stream = type_checker_->trace_stream_) {
       **trace_stream << "substitution: " << *constraint << " => "
                      << *new_constraint << "\n";
     }
@@ -2063,7 +2064,7 @@ auto TypeChecker::RefineWitness(Nonnull<const Witness*> witness,
   // See if this is already resolved as some number of layers of
   // ConstraintImplWitness applied to an ImplWitness.
   Nonnull<const Witness*> inner_witness = witness;
-  while (auto* inner_constraint_impl_witness =
+  while (const auto* inner_constraint_impl_witness =
              dyn_cast<ConstraintImplWitness>(inner_witness)) {
     inner_witness = inner_constraint_impl_witness->constraint_witness();
   }
@@ -2366,7 +2367,7 @@ auto TypeChecker::LookupRewriteInTypeOf(
     //                       interface, member);
     // where we substitute as little as possible to try to avoid infinite
     // recursion.
-    if (auto* constraint =
+    if (const auto* constraint =
             dyn_cast<ConstraintType>(&assoc_const->constant().static_type())) {
       for (auto rewrite : constraint->rewrite_constraints()) {
         if (&rewrite.constant->constant() != &assoc_const->constant()) {
@@ -2425,7 +2426,7 @@ static auto IsInstanceMember(Nonnull<const Element*> element) {
     case ElementKind::PositionalElement:
       return true;
     case ElementKind::NamedElement:
-      const auto nom_element = cast<NamedElement>(element);
+      const auto* const nom_element = cast<NamedElement>(element);
       if (!nom_element->declaration()) {
         // This is a struct field.
         return true;
@@ -2671,7 +2672,8 @@ auto TypeChecker::TypeCheckExp(Nonnull<Expression*> e,
           access.set_is_type_access(!IsInstanceMember(&access.member()));
           access.set_static_type(inst_member_type);
 
-          if (auto* func_decl = dyn_cast<FunctionDeclaration>(result.member)) {
+          if (const auto* func_decl =
+                  dyn_cast<FunctionDeclaration>(result.member)) {
             CARBON_RETURN_IF_ERROR(
                 CheckAddrMeAccess(&access, func_decl, bindings, impl_scope));
           }
@@ -4106,8 +4108,8 @@ auto TypeChecker::TypeCheckGenericBinding(GenericBinding& binding,
 
 // Get the builtin interface that should be used for the given kind of
 // assignment operator.
-static Builtins::Builtin GetBuiltinInterfaceForAssignOperator(
-    AssignOperator op) {
+static auto GetBuiltinInterfaceForAssignOperator(AssignOperator op)
+    -> Builtins::Builtin {
   switch (op) {
     case AssignOperator::Plain:
       return Builtins::AssignWith;
@@ -5051,7 +5053,8 @@ auto TypeChecker::DeclareConstraintTypeDeclaration(
         // constraint for the constraint type: `let X:! Interface` adds a
         // `Self.X is Interface` constraint that `impl`s must satisfy and users
         // of the constraint type can rely on.
-        if (auto* constraint_type = dyn_cast<ConstraintType>(constraint)) {
+        if (const auto* constraint_type =
+                dyn_cast<ConstraintType>(constraint)) {
           builder.AddAndSubstitute(*this, constraint_type, assoc_value,
                                    builder.GetSelfWitness(), Bindings(),
                                    /*add_lookup_contexts=*/false);

+ 2 - 2
explorer/interpreter/value_transform.h

@@ -37,7 +37,7 @@ constexpr bool IsRecursivelyTransformable<
 template <typename Derived>
 class TransformBase {
  public:
-  TransformBase(Nonnull<Arena*> arena) : arena_(arena) {}
+  explicit TransformBase(Nonnull<Arena*> arena) : arena_(arena) {}
 
   template <typename T>
   auto Transform(T&& v) -> decltype(auto) {
@@ -134,7 +134,7 @@ class ValueTransform : public TransformBase<Derived> {
   // T*)` in the base class. We can remove this once we start using a compiler
   // that implements P1787R6.
   template <typename NodeT>
-  auto operator()(Nonnull<const NodeT*> node, int = 0)
+  auto operator()(Nonnull<const NodeT*> node, int /*unused*/ = 0)
       -> std::enable_if_t<std::is_base_of_v<AstNode, NodeT>,
                           Nonnull<const NodeT*>> {
     return node;

+ 3 - 3
toolchain/lexer/tokenized_buffer.cpp

@@ -895,7 +895,7 @@ auto TokenizedBuffer::SourceBufferLocationTranslator::GetLocation(
   // Find the first line starting after the given location. Note that we can't
   // inspect `line.length` here because it is not necessarily correct for the
   // final line during lexing (but will be correct later for the parse tree).
-  auto* line_it = std::partition_point(
+  const auto* line_it = std::partition_point(
       buffer_->line_infos_.begin(), buffer_->line_infos_.end(),
       [offset](const LineInfo& line) { return line.start <= offset; });
   bool incomplete_line_info = last_line_lexed_to_column_ != nullptr &&
@@ -932,8 +932,8 @@ auto TokenizedBuffer::SourceBufferLocationTranslator::GetLocation(
 auto TokenizedBuffer::TokenLocationTranslator::GetLocation(Token token)
     -> DiagnosticLocation {
   // Map the token location into a position within the source buffer.
-  auto& token_info = buffer_->GetTokenInfo(token);
-  auto& line_info = buffer_->GetLineInfo(token_info.token_line);
+  const auto& token_info = buffer_->GetTokenInfo(token);
+  const auto& line_info = buffer_->GetLineInfo(token_info.token_line);
   const char* token_start =
       buffer_->source_->text().begin() + line_info.start + token_info.column;
 

+ 0 - 2
toolchain/parser/parse_tree_test.cpp

@@ -18,9 +18,7 @@
 namespace Carbon::Testing {
 namespace {
 
-using ::testing::AtLeast;
 using ::testing::ElementsAre;
-using ::testing::Eq;
 
 class ParseTreeTest : public ::testing::Test {
  protected:

+ 0 - 2
toolchain/semantics/semantics_ir_test.cpp

@@ -9,8 +9,6 @@
 
 #include <forward_list>
 
-#include "gmock/gmock.h"
-#include "gtest/gtest.h"
 #include "toolchain/common/yaml_test_helpers.h"
 #include "toolchain/diagnostics/diagnostic_emitter.h"
 #include "toolchain/lexer/tokenized_buffer.h"