mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 06:34:41 +01:00
[NFC] Simplify IncludeInsertions appending to diagnostics
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,12 +45,9 @@ public:
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user