Skip to content

Commit 6adac7a

Browse files
authored
DiagnosticEngine: require clients to explicitly specify source locations when emitting diagnostics. NFC (swiftlang#18962)
1 parent 3a37bb5 commit 6adac7a

File tree

2 files changed

+15
-21
lines changed

2 files changed

+15
-21
lines changed

include/swift/AST/DiagnosticEngine.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -672,18 +672,11 @@ namespace swift {
672672
return diagnose(Loc, Diagnostic(ID, std::move(Args)...));
673673
}
674674

675-
/// \brief Emit a diagnostic with the given set of diagnostic arguments.
676-
///
677-
/// \param ID The diagnostic to be emitted.
678-
///
679-
/// \param Args The diagnostic arguments, which will be converted to
680-
/// the types expected by the diagnostic \p ID.
675+
/// Delete an API that may lead clients to avoid specifying source location.
681676
template<typename ...ArgTypes>
682677
InFlightDiagnostic
683678
diagnose(Diag<ArgTypes...> ID,
684-
typename detail::PassArgument<ArgTypes>::type... Args) {
685-
return diagnose(SourceLoc(), ID, std::move(Args)...);
686-
}
679+
typename detail::PassArgument<ArgTypes>::type... Args) = delete;
687680

688681
/// \brief Emit a diagnostic with the given set of diagnostic arguments.
689682
///

tools/swift-api-digester/swift-api-digester.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,7 +1554,7 @@ void DiagnosisEmitter::handle(const SDKNodeDecl *Node, NodeAnnotation Anno) {
15541554
return;
15551555
if (auto *Added = findAddedDecl(Node)) {
15561556
if (Node->getDeclKind() != DeclKind::Constructor) {
1557-
Diags.diagnose(diag::moved_decl, Node->getScreenInfo(),
1557+
Diags.diagnose(SourceLoc(), diag::moved_decl, Node->getScreenInfo(),
15581558
Ctx.buffer((Twine(getDeclKindStr(Added->getDeclKind())) + " " +
15591559
Added->getFullyQualifiedName()).str()));
15601560
return;
@@ -1566,7 +1566,7 @@ void DiagnosisEmitter::handle(const SDKNodeDecl *Node, NodeAnnotation Anno) {
15661566
auto It = std::find_if(MemberChanges.begin(), MemberChanges.end(),
15671567
[&](TypeMemberDiffItem &Item) { return Item.usr == Node->getUsr(); });
15681568
if (It != MemberChanges.end()) {
1569-
Diags.diagnose(diag::renamed_decl, Node->getScreenInfo(),
1569+
Diags.diagnose(SourceLoc(), diag::renamed_decl, Node->getScreenInfo(),
15701570
Ctx.buffer((Twine(getDeclKindStr(Node->getDeclKind())) + " " +
15711571
It->newTypeName + "." + It->newPrintedName).str()));
15721572
return;
@@ -1577,7 +1577,7 @@ void DiagnosisEmitter::handle(const SDKNodeDecl *Node, NodeAnnotation Anno) {
15771577
// refine diagnostics message instead of showing the type alias has been
15781578
// removed.
15791579
if (TypeAliasUpdateMap.find((SDKNode*)Node) != TypeAliasUpdateMap.end()) {
1580-
Diags.diagnose(diag::raw_type_change, Node->getScreenInfo(),
1580+
Diags.diagnose(SourceLoc(), diag::raw_type_change, Node->getScreenInfo(),
15811581
Node->getAs<SDKNodeDeclTypeAlias>()->getUnderlyingType()->getPrintedName(),
15821582
TypeAliasUpdateMap[(SDKNode*)Node]->getAs<SDKNodeDeclType>()->
15831583
getRawValueType()->getPrintedName());
@@ -1599,28 +1599,29 @@ void DiagnosisEmitter::handle(const SDKNodeDecl *Node, NodeAnnotation Anno) {
15991599
}
16001600
if (FoundInSuperclass)
16011601
return;
1602-
Diags.diagnose(diag::removed_decl, Node->getScreenInfo(), Node->isDeprecated());
1602+
Diags.diagnose(SourceLoc(), diag::removed_decl, Node->getScreenInfo(),
1603+
Node->isDeprecated());
16031604
return;
16041605
}
16051606
case NodeAnnotation::Rename: {
16061607
auto *Count = UpdateMap.findUpdateCounterpart(Node)->getAs<SDKNodeDecl>();
1607-
Diags.diagnose(diag::renamed_decl, Node->getScreenInfo(),
1608+
Diags.diagnose(SourceLoc(), diag::renamed_decl, Node->getScreenInfo(),
16081609
Ctx.buffer((Twine(getDeclKindStr(Count->getDeclKind())) + " " +
16091610
Count->getFullyQualifiedName()).str()));
16101611
return;
16111612
}
16121613
case NodeAnnotation::NowMutating: {
1613-
Diags.diagnose(diag::decl_new_attr, Node->getScreenInfo(),
1614+
Diags.diagnose(SourceLoc(), diag::decl_new_attr, Node->getScreenInfo(),
16141615
Ctx.buffer("mutating"));
16151616
return;
16161617
}
16171618
case NodeAnnotation::NowThrowing: {
1618-
Diags.diagnose(diag::decl_new_attr, Node->getScreenInfo(),
1619+
Diags.diagnose(SourceLoc(), diag::decl_new_attr, Node->getScreenInfo(),
16191620
Ctx.buffer("throwing"));
16201621
return;
16211622
}
16221623
case NodeAnnotation::StaticChange: {
1623-
Diags.diagnose(diag::decl_new_attr, Node->getScreenInfo(),
1624+
Diags.diagnose(SourceLoc(), diag::decl_new_attr, Node->getScreenInfo(),
16241625
Ctx.buffer(Node->isStatic() ? "not static" : "static"));
16251626
return;
16261627
}
@@ -1631,13 +1632,13 @@ void DiagnosisEmitter::handle(const SDKNodeDecl *Node, NodeAnnotation Anno) {
16311632
return keywordOf(O);
16321633
};
16331634
auto *Count = UpdateMap.findUpdateCounterpart(Node)->getAs<SDKNodeDecl>();
1634-
Diags.diagnose(diag::decl_attr_change, Node->getScreenInfo(),
1635+
Diags.diagnose(SourceLoc(), diag::decl_attr_change, Node->getScreenInfo(),
16351636
getOwnershipDescription(Node->getReferenceOwnership()),
16361637
getOwnershipDescription(Count->getReferenceOwnership()));
16371638
return;
16381639
}
16391640
case NodeAnnotation::ChangeGenericSignature: {
1640-
Diags.diagnose(diag::generic_sig_change, Node->getScreenInfo(),
1641+
Diags.diagnose(SourceLoc(), diag::generic_sig_change, Node->getScreenInfo(),
16411642
Node->getGenericSignature(), UpdateMap.findUpdateCounterpart(Node)->
16421643
getAs<SDKNodeDecl>()->getGenericSignature());
16431644
return;
@@ -1654,7 +1655,7 @@ void DiagnosisEmitter::handle(const SDKNodeDecl *Node, NodeAnnotation Anno) {
16541655
Ctx.buffer((llvm::Twine("without ") + It->Content).str()):
16551656
Ctx.buffer((llvm::Twine("with ") + It->Content).str());
16561657
if (options::Abi)
1657-
Diags.diagnose(diag::decl_new_attr, Node->getScreenInfo(), Desc);
1658+
Diags.diagnose(SourceLoc(), diag::decl_new_attr, Node->getScreenInfo(), Desc);
16581659
return;
16591660
}
16601661
}
@@ -1684,7 +1685,7 @@ void DiagnosisEmitter::visitType(SDKNodeType *Node) {
16841685
SDKNodeDeclAbstractFunc::getTypeRoleDescription(Ctx, Parent->getChildIndex(Node)) :
16851686
Ctx.buffer("declared");
16861687
if (Node->getPrintedName() != Count->getPrintedName())
1687-
Diags.diagnose(diag::decl_type_change, Parent->getScreenInfo(),
1688+
Diags.diagnose(SourceLoc(), diag::decl_type_change, Parent->getScreenInfo(),
16881689
Descriptor, Node->getPrintedName(), Count->getPrintedName());
16891690
break;
16901691
default:

0 commit comments

Comments
 (0)