@@ -37,6 +37,35 @@ LifetimeEntry::create(const ASTContext &ctx, SourceLoc startLoc,
37
37
return new (mem) LifetimeEntry (startLoc, endLoc, sources, targetDescriptor);
38
38
}
39
39
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 lifetimeKind = source.getParsedLifetimeDependenceKind ();
53
+ auto kindString = getNameForParsedLifetimeDependenceKind (lifetimeKind);
54
+ bool printSpace = (lifetimeKind == ParsedLifetimeDependenceKind::Borrow ||
55
+ lifetimeKind == ParsedLifetimeDependenceKind::Copy);
56
+ if (!kindString.empty ()) {
57
+ result += kindString;
58
+ }
59
+ if (printSpace) {
60
+ result += " " ;
61
+ }
62
+ result += source.getString ();
63
+ firstElem = false ;
64
+ }
65
+ result += " )" ;
66
+ return result;
67
+ }
68
+
40
69
std::optional<LifetimeDependenceInfo>
41
70
getLifetimeDependenceFor (ArrayRef<LifetimeDependenceInfo> lifetimeDependencies,
42
71
unsigned index) {
@@ -82,7 +111,7 @@ getNameForParsedLifetimeDependenceKind(ParsedLifetimeDependenceKind kind) {
82
111
case ParsedLifetimeDependenceKind::Inherit:
83
112
return " copy" ;
84
113
case ParsedLifetimeDependenceKind::Inout:
85
- return " inout " ;
114
+ return " & " ;
86
115
default :
87
116
return " " ;
88
117
}
@@ -572,7 +601,7 @@ class LifetimeDependenceChecker {
572
601
std::optional<LifetimeDependenceKind>
573
602
getDependenceKindFromDescriptor (LifetimeDescriptor descriptor,
574
603
ParamDecl *decl) {
575
- auto loc = decl-> getLoc ();
604
+ auto loc = descriptor. getLoc ();
576
605
auto type = decl->getTypeInContext ();
577
606
auto parsedLifetimeKind = descriptor.getParsedLifetimeDependenceKind ();
578
607
auto ownership = decl->getValueOwnership ();
@@ -602,9 +631,12 @@ class LifetimeDependenceChecker {
602
631
603
632
// @lifetime(borrow x) is valid only for borrowing parameters.
604
633
// @lifetime(inout x) is valid only for inout parameters.
605
- if (!isCompatibleWithOwnership (parsedLifetimeKind, type, ownership)) {
634
+ if (!isCompatibleWithOwnership (parsedLifetimeKind, type,
635
+ loweredOwnership)) {
606
636
diagnose (loc,
607
- diag::lifetime_dependence_cannot_use_parsed_borrow_consuming);
637
+ diag::lifetime_dependence_cannot_use_parsed_borrow_consuming,
638
+ getNameForParsedLifetimeDependenceKind (parsedLifetimeKind),
639
+ getOwnershipSpelling (loweredOwnership));
608
640
return std::nullopt;
609
641
}
610
642
// @lifetime(copy x) is only invalid for Escapable types.
0 commit comments