@@ -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) {
@@ -82,7 +111,7 @@ getNameForParsedLifetimeDependenceKind(ParsedLifetimeDependenceKind kind) {
82111 case ParsedLifetimeDependenceKind::Inherit:
83112 return " copy" ;
84113 case ParsedLifetimeDependenceKind::Inout:
85- return " inout " ;
114+ return " & " ;
86115 default :
87116 return " " ;
88117 }
@@ -572,7 +601,7 @@ class LifetimeDependenceChecker {
572601 std::optional<LifetimeDependenceKind>
573602 getDependenceKindFromDescriptor (LifetimeDescriptor descriptor,
574603 ParamDecl *decl) {
575- auto loc = decl-> getLoc ();
604+ auto loc = descriptor. getLoc ();
576605 auto type = decl->getTypeInContext ();
577606 auto parsedLifetimeKind = descriptor.getParsedLifetimeDependenceKind ();
578607 auto ownership = decl->getValueOwnership ();
@@ -602,9 +631,12 @@ class LifetimeDependenceChecker {
602631
603632 // @lifetime(borrow x) is valid only for borrowing parameters.
604633 // @lifetime(inout x) is valid only for inout parameters.
605- if (!isCompatibleWithOwnership (parsedLifetimeKind, type, ownership)) {
634+ if (!isCompatibleWithOwnership (parsedLifetimeKind, type,
635+ loweredOwnership)) {
606636 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));
608640 return std::nullopt ;
609641 }
610642 // @lifetime(copy x) is only invalid for Escapable types.
0 commit comments