Skip to content

Commit 05fa82b

Browse files
committed
Fix misleading Lifetime diagnostics for inout parameters
Correctly diagnose this as: "invalid use of inout dependence on the same inout parameter @_lifetime(a: &a) func f_inout_useless(a: inout MutableRawSpan) {} Correctly diagnose this as: "lifetime-dependent parameter must be 'inout'": @_lifetime(a: borrow a) func f_inout_useless(a: borrowing MutableRawSpan) {}
1 parent df0b81c commit 05fa82b

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8324,7 +8324,7 @@ ERROR(lifetime_dependence_cannot_use_default_escapable_consuming, none,
83248324
"invalid lifetime dependence on an Escapable value with %0 ownership",
83258325
(StringRef))
83268326
ERROR(lifetime_dependence_cannot_use_parsed_borrow_inout, none,
8327-
"invalid use of borrow dependence on the same inout parameter",
8327+
"invalid use of inout dependence on the same inout parameter",
83288328
())
83298329
ERROR(lifetime_dependence_duplicate_target, none,
83308330
"invalid duplicate target lifetime dependencies on function", ())

lib/AST/LifetimeDependence.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,7 @@ class LifetimeDependenceChecker {
917917
}
918918
unsigned sourceIndex = paramDeclAndIndex->second;
919919
if (lifetimeKind == LifetimeDependenceKind::Scope
920+
&& paramDeclAndIndex->first->isInOut()
920921
&& sourceIndex == targetIndex) {
921922
diagnose(source.getLoc(),
922923
diag::lifetime_dependence_cannot_use_parsed_borrow_inout);

test/Sema/lifetime_depend_infer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ struct NonEscapableMutableSelf: ~Escapable {
565565
@_lifetime(self: copy self) // OK
566566
mutating func mutatingMethodNoParamCopy() {}
567567

568-
@_lifetime(self: &self) // expected-error{{invalid use of borrow dependence on the same inout parameter}}
568+
@_lifetime(self: &self) // expected-error{{invalid use of inout dependence on the same inout parameter}}
569569
mutating func mutatingMethodNoParamBorrow() {}
570570

571571
mutating func mutatingMethodOneParam(_: NE) {} // expected-error{{a mutating method with a ~Escapable 'self' requires '@_lifetime(self: ...)'}}

0 commit comments

Comments
 (0)