You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Diagnostic note for invalid @_lifetime annotations on inout params
Users commonly try to write a lifetime dependency on an 'inout' parameters as:
@_lifetime(a: &a)
func f_inout_useless(a: inout MutableRawSpan) {}
This is useless. Guide them toward what they really wanted:
@_lifetime(a: copy a)
Fixes rdar://151618856 (@Lifetime(..) gives inconsistent error messages)
(cherry picked from commit 87f2510)
// Unable to infer an 'inout' dependency. Provide valid guidance.
624
625
//
625
-
func f_inout_no_infer(a: inout MutNE, b: NE){} // expected-error{{a function with a ~Escapable 'inout' parameter requires '@_lifetime(a: ...)'}}
626
-
// expected-note @-1{{use '@_lifetime(a: copy a) to forward the inout dependency}}
626
+
func f_inout_no_infer(a: inout MutNE, b: NE){}
627
+
// expected-error @-1{{a function with a ~Escapable 'inout' parameter requires '@_lifetime(a: ...)'}}
628
+
// expected-note @-2{{use '@_lifetime(a: copy a) to forward the inout dependency}}
627
629
628
630
// Invalid keyword for the dependence kind.
629
631
//
630
632
@_lifetime(a: inout a) // expected-error{{expected 'copy', 'borrow', or '&' followed by an identifier, index or 'self' in lifetime dependence specifier}}
631
633
func f_inout_bad_keyword(a:inoutMutableRawSpan){}
632
634
635
+
// Don't allow a useless borrow dependency on an inout param--it is misleading.
636
+
//
637
+
@_lifetime(a:&a) // expected-error{{invalid use of inout dependence on the same inout parameter}}
638
+
// expected-note @-1{{use '@_lifetime(a: copy a) to forward the inout dependency}}
0 commit comments