Author: Nathan James Date: 2020-06-19T13:22:49+01:00 New Revision: c3b4486a57f6105bd5d96ec2e736f567aa4a0e35
URL: https://github.com/llvm/llvm-project/commit/c3b4486a57f6105bd5d96ec2e736f567aa4a0e35 DIFF: https://github.com/llvm/llvm-project/commit/c3b4486a57f6105bd5d96ec2e736f567aa4a0e35.diff LOG: [NFC] Simplify IncludeInsertions appending to diagnostics Added: Modified: clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp b/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp index 633f3781f4d8..ed1a1a26bb62 100644 --- a/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp @@ -217,14 +217,11 @@ void PassByValueCheck::check(const MatchFinder::MatchResult &Result) { // Use std::move in the initialization list. Diag << FixItHint::CreateInsertion(Initializer->getRParenLoc(), ")") << FixItHint::CreateInsertion( - Initializer->getLParenLoc().getLocWithOffset(1), "std::move("); - - if (auto IncludeFixit = Inserter->CreateIncludeInsertion( - Result.SourceManager->getFileID(Initializer->getSourceLocation()), - "utility", - /*IsAngled=*/true)) { - Diag << *IncludeFixit; - } + Initializer->getLParenLoc().getLocWithOffset(1), "std::move(") + << Inserter->CreateIncludeInsertion( + Result.SourceManager->getFileID(Initializer->getSourceLocation()), + "utility", + /*IsAngled=*/true); } } // namespace modernize diff --git a/clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp b/clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp index 515b2146f06c..295be200bca6 100644 --- a/clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp @@ -148,14 +148,12 @@ void ReplaceAutoPtrCheck::check(const MatchFinder::MatchResult &Result) { if (Range.isInvalid()) return; - auto Diag = diag(Range.getBegin(), "use std::move to transfer ownership") - << FixItHint::CreateInsertion(Range.getBegin(), "std::move(") - << FixItHint::CreateInsertion(Range.getEnd(), ")"); - - if (auto Fix = - Inserter->CreateIncludeInsertion(SM.getMainFileID(), "utility", - /*IsAngled=*/true)) - Diag << *Fix; + auto Diag = + diag(Range.getBegin(), "use std::move to transfer ownership") + << FixItHint::CreateInsertion(Range.getBegin(), "std::move(") + << FixItHint::CreateInsertion(Range.getEnd(), ")") + << Inserter->CreateIncludeInsertion(SM.getMainFileID(), "utility", + /*IsAngled=*/true); return; } diff --git a/clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp b/clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp index 550772972923..9cfbd87239dc 100644 --- a/clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp @@ -94,13 +94,10 @@ void ReplaceRandomShuffleCheck::check(const MatchFinder::MatchResult &Result) { Diag << FixItHint::CreateRemoval(MatchedDecl->getSourceRange()); Diag << FixItHint::CreateInsertion(MatchedDecl->getBeginLoc(), NewName); - - if (Optional<FixItHint> IncludeFixit = - IncludeInserter->CreateIncludeInsertion( - Result.Context->getSourceManager().getFileID( - MatchedCallExpr->getBeginLoc()), - "random", /*IsAngled=*/true)) - Diag << IncludeFixit.getValue(); + Diag << IncludeInserter->CreateIncludeInsertion( + Result.Context->getSourceManager().getFileID( + MatchedCallExpr->getBeginLoc()), + "random", /*IsAngled=*/true); } } // namespace modernize diff --git a/clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp b/clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp index 1d7ee4baae93..d08cec1a2c3c 100644 --- a/clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp +++ b/clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp @@ -193,10 +193,9 @@ void TypePromotionInMathFnCheck::check(const MatchFinder::MatchResult &Result) { // <math.h>, because the functions we're suggesting moving away from are all // declared in <math.h>. if (FnInCmath) - if (auto IncludeFixit = IncludeInserter->CreateIncludeInsertion( - Result.Context->getSourceManager().getFileID(Call->getBeginLoc()), - "cmath", /*IsAngled=*/true)) - Diag << *IncludeFixit; + Diag << IncludeInserter->CreateIncludeInsertion( + Result.Context->getSourceManager().getFileID(Call->getBeginLoc()), + "cmath", /*IsAngled=*/true); } } // namespace performance diff --git a/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp b/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp index 9dea42409513..5b5f2ff99478 100644 --- a/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp +++ b/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp @@ -205,11 +205,10 @@ void UnnecessaryValueParamCheck::handleMoveFix(const ParmVarDecl &Var, auto EndLoc = Lexer::getLocForEndOfToken(CopyArgument.getLocation(), 0, SM, Context.getLangOpts()); Diag << FixItHint::CreateInsertion(CopyArgument.getBeginLoc(), "std::move(") - << FixItHint::CreateInsertion(EndLoc, ")"); - if (auto IncludeFixit = Inserter->CreateIncludeInsertion( - SM.getFileID(CopyArgument.getBeginLoc()), "utility", - /*IsAngled=*/true)) - Diag << *IncludeFixit; + << FixItHint::CreateInsertion(EndLoc, ")") + << Inserter->CreateIncludeInsertion( + SM.getFileID(CopyArgument.getBeginLoc()), "utility", + /*IsAngled=*/true); } } // namespace performance diff --git a/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp index a15c429b696f..0a57856b7972 100644 --- a/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp +++ b/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp @@ -103,12 +103,9 @@ void TransformerClangTidyCheck::check( Diag << FixItHint::CreateReplacement(T.Range, T.Replacement); for (const auto &I : Case.AddedIncludes) { - auto &Header = I.first; - if (Optional<FixItHint> Fix = Inserter->CreateIncludeInsertion( - Result.SourceManager->getMainFileID(), Header, - /*IsAngled=*/I.second == transformer::IncludeFormat::Angled)) { - Diag << *Fix; - } + Diag << Inserter->CreateIncludeInsertion( + Result.SourceManager->getMainFileID(), I.first, + /*IsAngled=*/I.second == transformer::IncludeFormat::Angled); } } diff --git a/clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp b/clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp index 890599cbc973..ed5f02576f04 100644 --- a/clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp +++ b/clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp @@ -45,12 +45,9 @@ class IncludeInserterCheckBase : public ClangTidyCheck { void check(const ast_matchers::MatchFinder::MatchResult &Result) override { auto Diag = diag(Result.Nodes.getNodeAs<DeclStmt>("stmt")->getBeginLoc(), "foo, bar"); - for (StringRef header : HeadersToInclude()) { - auto Fixit = Inserter->CreateIncludeInsertion( - Result.SourceManager->getMainFileID(), header, IsAngledInclude()); - if (Fixit) { - Diag << *Fixit; - } + for (StringRef Header : HeadersToInclude()) { + Diag << Inserter->CreateIncludeInsertion( + Result.SourceManager->getMainFileID(), Header, IsAngledInclude()); } } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits