Skip to content

Commit 9d4cca2

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) {} (cherry picked from commit 05fa82b)
1 parent 64bf206 commit 9d4cca2

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
@@ -8244,7 +8244,7 @@ ERROR(lifetime_dependence_cannot_use_default_escapable_consuming, none,
82448244
"invalid lifetime dependence on an Escapable value with %0 ownership",
82458245
(StringRef))
82468246
ERROR(lifetime_dependence_cannot_use_parsed_borrow_inout, none,
8247-
"invalid use of borrow dependence on the same inout parameter",
8247+
"invalid use of inout dependence on the same inout parameter",
82488248
())
82498249
ERROR(lifetime_dependence_duplicate_target, none,
82508250
"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)