From eed4a4d02e4f33cc2f2a9980466d1c7a1cf37398 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Thu, 15 Jun 2023 13:48:50 +0200 Subject: [clang-tidy] Correct the include-cleaner-check diagnostic message for missing-includes. We should print the symbol name rather than the header name in the message. Differential Revision: https://reviews.llvm.org/D153013 --- clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp') diff --git a/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp b/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp index 49e7581..b9f44c9 100644 --- a/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp @@ -45,7 +45,7 @@ namespace clang::tidy::misc { namespace { struct MissingIncludeInfo { - SourceLocation SymRefLocation; + include_cleaner::SymbolReference SymRef; include_cleaner::Header Missing; }; } // namespace @@ -134,7 +134,7 @@ void IncludeCleanerCheck::check(const MatchFinder::MatchResult &Result) { if (!Satisfied && !Providers.empty() && Ref.RT == include_cleaner::RefType::Explicit && !shouldIgnore(Providers.front())) - Missing.push_back({Ref.RefLocation, Providers.front()}); + Missing.push_back({Ref, Providers.front()}); }); std::vector Unused; @@ -190,9 +190,9 @@ void IncludeCleanerCheck::check(const MatchFinder::MatchResult &Result) { if (auto Replacement = HeaderIncludes.insert(llvm::StringRef{Spelling}.trim("\"<>"), Angled, tooling::IncludeDirective::Include)) - diag(SM->getSpellingLoc(Inc.SymRefLocation), - "no header providing %0 is directly included") - << Spelling + diag(SM->getSpellingLoc(Inc.SymRef.RefLocation), + "no header providing \"%0\" is directly included") + << Inc.SymRef.Target.name() << FixItHint::CreateInsertion( SM->getComposedLoc(SM->getMainFileID(), Replacement->getOffset()), -- cgit v1.1