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)
// Unable to infer an 'inout' dependency. Provide valid guidance.
588
589
//
589
-
func f_inout_no_infer(a: inout MutNE, b: NE){} // expected-error{{a function with a ~Escapable 'inout' parameter requires '@_lifetime(a: ...)'}}
590
-
// expected-note @-1{{use '@_lifetime(a: copy a) to forward the inout dependency}}
590
+
func f_inout_no_infer(a: inout MutNE, b: NE){}
591
+
// expected-error @-1{{a function with a ~Escapable 'inout' parameter requires '@_lifetime(a: ...)'}}
592
+
// expected-note @-2{{use '@_lifetime(a: copy a) to forward the inout dependency}}
591
593
592
594
// Invalid keyword for the dependence kind.
593
595
//
594
596
@_lifetime(a: inout a) // expected-error{{expected 'copy', 'borrow', or '&' followed by an identifier, index or 'self' in lifetime dependence specifier}}
595
597
func f_inout_bad_keyword(a:inoutMutableRawSpan){}
598
+
599
+
// Don't allow a useless borrow dependency on an inout param--it is misleading.
600
+
//
601
+
@_lifetime(a:&a) // expected-error{{invalid use of inout dependence on the same inout parameter}}
602
+
// expected-note @-1{{use '@_lifetime(a: copy a) to forward the inout dependency}}
0 commit comments