@@ -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::Inherit);
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) {
@@ -87,7 +116,7 @@ getNameForParsedLifetimeDependenceKind(ParsedLifetimeDependenceKind kind) {
87
116
case ParsedLifetimeDependenceKind::Inherit:
88
117
return " copy" ;
89
118
case ParsedLifetimeDependenceKind::Inout:
90
- return " inout " ;
119
+ return " & " ;
91
120
default :
92
121
return " " ;
93
122
}
@@ -577,7 +606,7 @@ class LifetimeDependenceChecker {
577
606
std::optional<LifetimeDependenceKind>
578
607
getDependenceKindFromDescriptor (LifetimeDescriptor descriptor,
579
608
ParamDecl *decl) {
580
- auto loc = decl-> getLoc ();
609
+ auto loc = descriptor. getLoc ();
581
610
auto type = decl->getTypeInContext ();
582
611
auto parsedLifetimeKind = descriptor.getParsedLifetimeDependenceKind ();
583
612
auto ownership = decl->getValueOwnership ();
@@ -607,9 +636,12 @@ class LifetimeDependenceChecker {
607
636
608
637
// @lifetime(borrow x) is valid only for borrowing parameters.
609
638
// @lifetime(inout x) is valid only for inout parameters.
610
- if (!isCompatibleWithOwnership (parsedLifetimeKind, type, ownership)) {
639
+ if (!isCompatibleWithOwnership (parsedLifetimeKind, type,
640
+ loweredOwnership)) {
611
641
diagnose (loc,
612
- diag::lifetime_dependence_cannot_use_parsed_borrow_consuming);
642
+ diag::lifetime_dependence_cannot_use_parsed_borrow_consuming,
643
+ getNameForParsedLifetimeDependenceKind (parsedLifetimeKind),
644
+ getOwnershipSpelling (loweredOwnership));
613
645
return std::nullopt;
614
646
}
615
647
// @lifetime(copy x) is only invalid for Escapable types.
0 commit comments