Skip to content

Commit c68fafe

Browse files
authored
Merge pull request #80618 from meg-gupta/updatediag
Silence diagnostic when @Lifetime(borrow) is used on inout parameters in swiftinterface files only
2 parents 6e70bef + eab8afb commit c68fafe

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

lib/AST/LifetimeDependence.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,8 @@ class LifetimeDependenceChecker {
490490
}
491491

492492
bool isCompatibleWithOwnership(ParsedLifetimeDependenceKind kind, Type type,
493-
ValueOwnership ownership) const {
493+
ValueOwnership ownership,
494+
bool isInterfaceFile = false) const {
494495
if (kind == ParsedLifetimeDependenceKind::Inherit) {
495496
return true;
496497
}
@@ -503,6 +504,10 @@ class LifetimeDependenceChecker {
503504
? ownership : getLoweredOwnership(afd);
504505

505506
if (kind == ParsedLifetimeDependenceKind::Borrow) {
507+
if (isInterfaceFile) {
508+
return loweredOwnership == ValueOwnership::Shared ||
509+
loweredOwnership == ValueOwnership::InOut;
510+
}
506511
return loweredOwnership == ValueOwnership::Shared;
507512
}
508513
assert(kind == ParsedLifetimeDependenceKind::Inout);
@@ -634,8 +639,8 @@ class LifetimeDependenceChecker {
634639
case ParsedLifetimeDependenceKind::Inout: {
635640
// @lifetime(borrow x) is valid only for borrowing parameters.
636641
// @lifetime(inout x) is valid only for inout parameters.
637-
if (!isCompatibleWithOwnership(parsedLifetimeKind, type,
638-
loweredOwnership)) {
642+
if (!isCompatibleWithOwnership(parsedLifetimeKind, type, loweredOwnership,
643+
isInterfaceFile())) {
639644
diagnose(loc,
640645
diag::lifetime_dependence_cannot_use_parsed_borrow_consuming,
641646
getNameForParsedLifetimeDependenceKind(parsedLifetimeKind),

stdlib/public/core/ArraySlice.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1302,7 +1302,7 @@ extension ArraySlice {
13021302

13031303
@available(SwiftStdlib 6.2, *)
13041304
public var mutableSpan: MutableSpan<Element> {
1305-
@lifetime(/*inout*/&self)
1305+
@lifetime(&self)
13061306
@_alwaysEmitIntoClient
13071307
mutating get {
13081308
_makeMutableAndUnique()

0 commit comments

Comments
 (0)