Files
swift-mirror/test/Sema/lifetime_attr_nofeature.swift
Andrew Trick e409752e00 Lifetime diagnostics: clarify @_lifetime usage for inout parameters
This comes up often when passing a MutableSpan as an 'inout' argument.  The
vague diagnostic was causing developers to attempt incorrect @_lifetime
annotations. Be clear about why the annotation is needed and which annotation
should be used.

(cherry picked from commit df0b81c88d)
2025-06-26 12:58:39 -07:00

17 lines
665 B
Swift

// RUN: %target-typecheck-verify-swift -disable-availability-checking
// REQUIRES: asserts
struct NE : ~Escapable { // expected-error{{an implicit initializer cannot return a ~Escapable result}}
}
@_lifetime(copy ne) // expected-error{{'@_lifetime' attribute is only valid when experimental feature Lifetimes is enabled}}
func derive(_ ne: NE) -> NE { // expected-error{{a function cannot return a ~Escapable result}}
ne
}
func f_inout_infer(a: inout MutableRawSpan) {}
func f_inout_no_infer(a: inout MutableRawSpan, b: RawSpan) {}
// expected-error @-1{{a function cannot have a ~Escapable 'inout' parameter 'a' in addition to other ~Escapable parameters}}