@@ -37,6 +37,35 @@ 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 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+
4069std::optional<LifetimeDependenceInfo>
4170getLifetimeDependenceFor (ArrayRef<LifetimeDependenceInfo> lifetimeDependencies,
4271 unsigned index) {
@@ -87,7 +116,7 @@ getNameForParsedLifetimeDependenceKind(ParsedLifetimeDependenceKind kind) {
87116 case ParsedLifetimeDependenceKind::Inherit:
88117 return " copy" ;
89118 case ParsedLifetimeDependenceKind::Inout:
90- return " inout " ;
119+ return " & " ;
91120 default :
92121 return " " ;
93122 }
@@ -577,7 +606,7 @@ class LifetimeDependenceChecker {
577606 std::optional<LifetimeDependenceKind>
578607 getDependenceKindFromDescriptor (LifetimeDescriptor descriptor,
579608 ParamDecl *decl) {
580- auto loc = decl-> getLoc ();
609+ auto loc = descriptor. getLoc ();
581610 auto type = decl->getTypeInContext ();
582611 auto parsedLifetimeKind = descriptor.getParsedLifetimeDependenceKind ();
583612 auto ownership = decl->getValueOwnership ();
@@ -607,9 +636,12 @@ class LifetimeDependenceChecker {
607636
608637 // @lifetime(borrow x) is valid only for borrowing parameters.
609638 // @lifetime(inout x) is valid only for inout parameters.
610- if (!isCompatibleWithOwnership (parsedLifetimeKind, type, ownership)) {
639+ if (!isCompatibleWithOwnership (parsedLifetimeKind, type,
640+ loweredOwnership)) {
611641 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));
613645 return std::nullopt ;
614646 }
615647 // @lifetime(copy x) is only invalid for Escapable types.
0 commit comments