Skip to content

Silence diagnostic when @lifetime(borrow) is used on inout parameters in swiftinterface files only #80618

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lib/AST/LifetimeDependence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,8 @@ class LifetimeDependenceChecker {
}

bool isCompatibleWithOwnership(ParsedLifetimeDependenceKind kind, Type type,
ValueOwnership ownership) const {
ValueOwnership ownership,
bool isInterfaceFile = false) const {
if (kind == ParsedLifetimeDependenceKind::Inherit) {
return true;
}
Expand All @@ -503,6 +504,10 @@ class LifetimeDependenceChecker {
? ownership : getLoweredOwnership(afd);

if (kind == ParsedLifetimeDependenceKind::Borrow) {
if (isInterfaceFile) {
return loweredOwnership == ValueOwnership::Shared ||
loweredOwnership == ValueOwnership::InOut;
}
return loweredOwnership == ValueOwnership::Shared;
}
assert(kind == ParsedLifetimeDependenceKind::Inout);
Expand Down Expand Up @@ -634,8 +639,8 @@ class LifetimeDependenceChecker {
case ParsedLifetimeDependenceKind::Inout: {
// @lifetime(borrow x) is valid only for borrowing parameters.
// @lifetime(inout x) is valid only for inout parameters.
if (!isCompatibleWithOwnership(parsedLifetimeKind, type,
loweredOwnership)) {
if (!isCompatibleWithOwnership(parsedLifetimeKind, type, loweredOwnership,
isInterfaceFile())) {
diagnose(loc,
diag::lifetime_dependence_cannot_use_parsed_borrow_consuming,
getNameForParsedLifetimeDependenceKind(parsedLifetimeKind),
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/ArraySlice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,7 @@ extension ArraySlice {

@available(SwiftStdlib 6.2, *)
public var mutableSpan: MutableSpan<Element> {
@lifetime(/*inout*/&self)
@lifetime(&self)
@_alwaysEmitIntoClient
mutating get {
_makeMutableAndUnique()
Expand Down