Skip to content

Commit e4b6ce7

Browse files
committed
[NFC] Update diagnostic msg
1 parent 3e49433 commit e4b6ce7

File tree

3 files changed

+37
-37
lines changed

3 files changed

+37
-37
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8169,8 +8169,8 @@ ERROR(lifetime_dependence_invalid_inherit_escapable_type, none,
81698169
"'@lifetime(borrow %0)' instead",
81708170
(StringRef))
81718171
ERROR(lifetime_dependence_cannot_use_parsed_borrow_consuming, none,
8172-
"invalid use of borrow dependence with consuming ownership",
8173-
())
8172+
"invalid use of %0 dependence with %1 ownership",
8173+
(StringRef, StringRef))
81748174
ERROR(lifetime_dependence_cannot_use_default_escapable_consuming, none,
81758175
"invalid lifetime dependence on Escapable value with %0 ownership",
81768176
(StringRef))

include/swift/AST/LifetimeDependence.h

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ class LifetimeEntry final
183183
ArrayRef<LifetimeDescriptor> sources,
184184
std::optional<LifetimeDescriptor> targetDescriptor = std::nullopt);
185185

186+
std::string getString() const;
186187
SourceLoc getLoc() const { return startLoc; }
187188
SourceLoc getStartLoc() const { return startLoc; }
188189
SourceLoc getEndLoc() const { return endLoc; }
@@ -194,38 +195,6 @@ class LifetimeEntry final
194195
std::optional<LifetimeDescriptor> getTargetDescriptor() const {
195196
return targetDescriptor;
196197
}
197-
198-
std::string getString() const {
199-
std::string result = "@lifetime(";
200-
if (targetDescriptor.has_value()) {
201-
result += targetDescriptor->getString();
202-
result += ": ";
203-
}
204-
205-
bool firstElem = true;
206-
for (auto source : getSources()) {
207-
if (!firstElem) {
208-
result += ", ";
209-
}
210-
switch (source.getParsedLifetimeDependenceKind()) {
211-
case ParsedLifetimeDependenceKind::Borrow:
212-
result += "borrow ";
213-
break;
214-
case ParsedLifetimeDependenceKind::Inherit:
215-
result += "copy ";
216-
break;
217-
case ParsedLifetimeDependenceKind::InOut:
218-
result += "inout ";
219-
break;
220-
default:
221-
break;
222-
}
223-
result += source.getString();
224-
firstElem = false;
225-
}
226-
result += ")";
227-
return result;
228-
}
229198
};
230199

231200
class LifetimeDependenceInfo {
@@ -370,6 +339,9 @@ filterEscapableLifetimeDependencies(GenericSignature sig,
370339
SmallVectorImpl<LifetimeDependenceInfo> &outputs,
371340
llvm::function_ref<Type (unsigned targetIndex)> getSubstTargetType);
372341

342+
StringRef
343+
getNameForParsedLifetimeDependenceKind(ParsedLifetimeDependenceKind kind);
344+
373345
} // namespace swift
374346

375347
#endif

lib/AST/LifetimeDependence.cpp

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,31 @@ LifetimeEntry::create(const ASTContext &ctx, SourceLoc startLoc,
3737
return new (mem) LifetimeEntry(startLoc, endLoc, sources, targetDescriptor);
3838
}
3939

40+
std::string LifetimeEntry::getString() const {
41+
std::string result = "@lifetime(";
42+
if (targetDescriptor.has_value()) {
43+
result += targetDescriptor->getString();
44+
result += ": ";
45+
}
46+
47+
bool firstElem = true;
48+
for (auto source : getSources()) {
49+
if (!firstElem) {
50+
result += ", ";
51+
}
52+
auto kindString = getNameForParsedLifetimeDependenceKind(
53+
source.getParsedLifetimeDependenceKind());
54+
if (!kindString.empty()) {
55+
result += kindString;
56+
result += " ";
57+
}
58+
result += source.getString();
59+
firstElem = false;
60+
}
61+
result += ")";
62+
return result;
63+
}
64+
4065
std::optional<LifetimeDependenceInfo>
4166
getLifetimeDependenceFor(ArrayRef<LifetimeDependenceInfo> lifetimeDependencies,
4267
unsigned index) {
@@ -572,7 +597,7 @@ class LifetimeDependenceChecker {
572597
std::optional<LifetimeDependenceKind>
573598
getDependenceKindFromDescriptor(LifetimeDescriptor descriptor,
574599
ParamDecl *decl) {
575-
auto loc = decl->getLoc();
600+
auto loc = descriptor.getLoc();
576601
auto type = decl->getTypeInContext();
577602
auto parsedLifetimeKind = descriptor.getParsedLifetimeDependenceKind();
578603
auto ownership = decl->getValueOwnership();
@@ -602,9 +627,12 @@ class LifetimeDependenceChecker {
602627

603628
// @lifetime(borrow x) is valid only for borrowing parameters.
604629
// @lifetime(inout x) is valid only for inout parameters.
605-
if (!isCompatibleWithOwnership(parsedLifetimeKind, type, ownership)) {
630+
if (!isCompatibleWithOwnership(parsedLifetimeKind, type,
631+
loweredOwnership)) {
606632
diagnose(loc,
607-
diag::lifetime_dependence_cannot_use_parsed_borrow_consuming);
633+
diag::lifetime_dependence_cannot_use_parsed_borrow_consuming,
634+
getNameForParsedLifetimeDependenceKind(parsedLifetimeKind),
635+
getOwnershipSpelling(loweredOwnership));
608636
return std::nullopt;
609637
}
610638
// @lifetime(copy x) is only invalid for Escapable types.

0 commit comments

Comments
 (0)