Skip to content

Commit 641cf01

Browse files
authoredMay 22, 2025
Merge pull request #81686 from atrick/62-lifedep-unprint-feature
[6.2] Diagnostic message: suppress printing "requires LifetimeDependence"
2 parents 63a436e + f0ec734 commit 641cf01

File tree

4 files changed

+28
-30
lines changed

4 files changed

+28
-30
lines changed
 

‎include/swift/AST/DiagnosticsSema.def

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8219,15 +8219,13 @@ ERROR(lifetime_parameter_requires_inout, none,
82198219
//------------------------------------------------------------------------------
82208220

82218221
ERROR(lifetime_dependence_feature_required_return, none,
8222-
"%0 with a ~Escapable result requires "
8223-
"'-enable-experimental-feature LifetimeDependence'", (StringRef))
8222+
"%0 cannot return a ~Escapable result", (StringRef))
82248223
ERROR(lifetime_dependence_feature_required_mutating, none,
8225-
"%0 with ~Escapable 'self' requires "
8226-
"'-enable-experimental-feature LifetimeDependence'", (StringRef))
8224+
"%0 cannot have a ~Escapable 'self'", (StringRef))
82278225
ERROR(lifetime_dependence_feature_required_inout, none,
8228-
"%0 with a ~Escapable 'inout' parameter requires "
8229-
"'-enable-experimental-feature LifetimeDependence'",
8230-
// arg list is interchangable with lifetime_dependence_cannot_infer_inout
8226+
"%0 cannot have a ~Escapable 'inout' parameter %1",
8227+
// this arg list must be compatible with
8228+
// lifetime_dependence_cannot_infer_inout
82318229
(StringRef, Identifier))
82328230

82338231
ERROR(lifetime_dependence_cannot_infer_return, none,

‎test/Interop/Cxx/class/nonescapable-errors.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public func importInvalid(_ x: Invalid) {
109109
}
110110

111111
// CHECK: error: a function with a ~Escapable result needs a parameter to depend on
112-
// CHECK-NO-LIFETIMES: test.swift:11:32: error: a function with a ~Escapable result requires '-enable-experimental-feature LifetimeDependence'
112+
// CHECK-NO-LIFETIMES: test.swift:11:32: error: a function cannot return a ~Escapable result
113113
public func noAnnotations() -> View {
114114
// CHECK: nonescapable.h:16:7: warning: the returned type 'Owner' is annotated as escapable; it cannot have lifetime dependencies [#ClangDeclarationImport]
115115
// CHECK-NO-LIFETIMES: nonescapable.h:16:7: warning: the returned type 'Owner' is annotated as escapable; it cannot have lifetime dependencies [#ClangDeclarationImport]
@@ -121,12 +121,12 @@ public func noAnnotations() -> View {
121121
f2(nil, nil)
122122
// CHECK: nonescapable.h:24:6: warning: the returned type 'View' is annotated as non-escapable; its lifetime dependencies must be annotated [#ClangDeclarationImport]
123123
// CHECK-NO-LIFETIMES: nonescapable.h:24:6: warning: the returned type 'View' is annotated as non-escapable; its lifetime dependencies must be annotated [#ClangDeclarationImport]
124-
// CHECK-NO-LIFETIMES: nonescapable.h:24:6: error: a function with a ~Escapable result requires '-enable-experimental-feature LifetimeDependence'
124+
// CHECK-NO-LIFETIMES: nonescapable.h:24:6: error: a function cannot return a ~Escapable result
125125
g(nil)
126126
h1(nil)
127-
// CHECK-NO-LIFETIMES: nonescapable.h:34:21: error: a function with a ~Escapable result requires '-enable-experimental-feature LifetimeDependence'
127+
// CHECK-NO-LIFETIMES: nonescapable.h:34:21: error: a function cannot return a ~Escapable result
128128
h2(nil)
129-
// CHECK-NO-LIFETIMES: nonescapable.h:35:21: error: a function with a ~Escapable result requires '-enable-experimental-feature LifetimeDependence'
129+
// CHECK-NO-LIFETIMES: nonescapable.h:35:21: error: a function cannot return a ~Escapable result
130130
h3(nil)
131131
i1()
132132
// CHECK: nonescapable.h:39:39: error: template parameter 'Missing' does not exist
@@ -135,18 +135,18 @@ public func noAnnotations() -> View {
135135
// CHECK: nonescapable.h:45:33: error: template parameter 'S' expected to be a type parameter
136136
// CHECK-NO-LIFETIMES: nonescapable.h:45:33: error: template parameter 'S' expected to be a type parameter
137137
j1()
138-
// CHECK-NO-LIFETIMES: nonescapable.h:63:41: error: a function with a ~Escapable result requires '-enable-experimental-feature LifetimeDependence'
138+
// CHECK-NO-LIFETIMES: nonescapable.h:63:41: error: a function cannot return a ~Escapable result
139139
j2()
140-
// CHECK-NO-LIFETIMES: nonescapable.h:64:41: error: a function with a ~Escapable result requires '-enable-experimental-feature LifetimeDependence'
140+
// CHECK-NO-LIFETIMES: nonescapable.h:64:41: error: a function cannot return a ~Escapable result
141141
j3()
142142
k1();
143-
// CHECK-NO-LIFETIMES: nonescapable.h:70:15: error: a function with a ~Escapable result requires '-enable-experimental-feature LifetimeDependence'
143+
// CHECK-NO-LIFETIMES: nonescapable.h:70:15: error: a function cannot return a ~Escapable result
144144
k2();
145-
// CHECK-NO-LIFETIMES: nonescapable.h:71:22: error: a function with a ~Escapable result requires '-enable-experimental-feature LifetimeDependence'
145+
// CHECK-NO-LIFETIMES: nonescapable.h:71:22: error: a function cannot return a ~Escapable result
146146
k3();
147147
l1();
148148
// CHECK: nonescapable.h:77:12: error: a function with a ~Escapable result needs a parameter to depend on
149-
// CHECK-NO-LIFETIMES: nonescapable.h:77:12: error: a function with a ~Escapable result requires '-enable-experimental-feature LifetimeDependence'
149+
// CHECK-NO-LIFETIMES: nonescapable.h:77:12: error: a function cannot return a ~Escapable result
150150
l2();
151151
return View()
152152
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// RUN: %target-typecheck-verify-swift -disable-availability-checking
22
// REQUIRES: asserts
33

4-
struct NE : ~Escapable { // expected-error{{an implicit initializer with a ~Escapable result requires '-enable-experimental-feature LifetimeDependence'}}
4+
struct NE : ~Escapable { // expected-error{{an implicit initializer cannot return a ~Escapable result}}
55
}
66

77
@lifetime(copy ne) // expected-error{{'@lifetime' attribute is only valid when experimental feature LifetimeDependence is enabled}} expected-error{{expected declaration}}
8-
func derive(_ ne: NE) -> NE { // expected-error{{a function with a ~Escapable result requires '-enable-experimental-feature LifetimeDependence'}}
8+
func derive(_ ne: NE) -> NE { // expected-error{{a function cannot return a ~Escapable result}}
99
ne
1010
}

‎test/Sema/lifetime_depend_nofeature.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,42 @@
66
// Check that functions that require lifetime dependence are prohibited without the flag.
77

88
// Don't allow empty initialization.
9-
struct EmptyNonEscapable: ~Escapable {} // expected-error{{an implicit initializer with a ~Escapable result requires '-enable-experimental-feature LifetimeDependence'}}
9+
struct EmptyNonEscapable: ~Escapable {} // expected-error{{an implicit initializer cannot return a ~Escapable result}}
1010

1111
// Don't allow non-Escapable return values.
12-
func neReturn(span: RawSpan) -> RawSpan { span } // expected-error{{a function with a ~Escapable result requires '-enable-experimental-feature LifetimeDependence'}}
12+
func neReturn(span: RawSpan) -> RawSpan { span } // expected-error{{a function cannot return a ~Escapable result}}
1313

1414
func neInout(span: inout RawSpan) {} // OK
1515

16-
func neInoutNEParam(span: inout RawSpan, _: RawSpan) {} // expected-error{{a function with a ~Escapable 'inout' parameter requires '-enable-experimental-feature LifetimeDependence'}}
16+
func neInoutNEParam(span: inout RawSpan, _: RawSpan) {} // expected-error{{a function cannot have a ~Escapable 'inout' parameter 'span'}}
1717

1818
struct S {
19-
func neReturn(span: RawSpan) -> RawSpan { span } // expected-error{{a method with a ~Escapable result requires '-enable-experimental-feature LifetimeDependence'}}
19+
func neReturn(span: RawSpan) -> RawSpan { span } // expected-error{{a method cannot return a ~Escapable result}}
2020

2121
func neInout(span: inout RawSpan) {} // OK
2222

23-
func neInoutNEParam(span: inout RawSpan, _: RawSpan) {} // expected-error{{a method with a ~Escapable 'inout' parameter requires '-enable-experimental-feature LifetimeDependence'}}
23+
func neInoutNEParam(span: inout RawSpan, _: RawSpan) {} // expected-error{{a method cannot have a ~Escapable 'inout' parameter 'span'}}
2424

2525
mutating func mutatingNEInout(span: inout RawSpan) {} // OK
2626

27-
mutating func mutatingNEInoutParam(span: inout RawSpan, _: RawSpan) {} // expected-error{{a mutating method with a ~Escapable 'inout' parameter requires '-enable-experimental-feature LifetimeDependence'}}
27+
mutating func mutatingNEInoutParam(span: inout RawSpan, _: RawSpan) {} // expected-error{{a mutating method cannot have a ~Escapable 'inout' parameter 'span'}}
2828
}
2929

3030
class C {
31-
func neReturn(span: RawSpan) -> RawSpan { span } // expected-error{{a method with a ~Escapable result requires '-enable-experimental-feature LifetimeDependence'}}
31+
func neReturn(span: RawSpan) -> RawSpan { span } // expected-error{{a method cannot return a ~Escapable result}}
3232

3333
func neInout(span: inout RawSpan) {} // OK
3434
}
3535

3636
extension MutableSpan {
3737
func method() {} // OK
3838

39-
mutating func mutatingMethod() {} // expected-error{{a mutating method with ~Escapable 'self' requires '-enable-experimental-feature LifetimeDependence'}}
39+
mutating func mutatingMethod() {} // expected-error{{a mutating method cannot have a ~Escapable 'self'}}
4040

41-
func neReturn(span: RawSpan) -> RawSpan { span } // expected-error{{a method with a ~Escapable result requires '-enable-experimental-feature LifetimeDependence'}}
41+
func neReturn(span: RawSpan) -> RawSpan { span } // expected-error{{a method cannot return a ~Escapable result}}
4242

43-
func neInout(span: inout RawSpan) {} // expected-error{{a method with a ~Escapable 'inout' parameter requires '-enable-experimental-feature LifetimeDependence'}}
43+
func neInout(span: inout RawSpan) {} // expected-error{{a method cannot have a ~Escapable 'inout' parameter 'span'}}
4444

45-
mutating func mutatingNEInout(span: inout RawSpan) {} // expected-error{{a mutating method with ~Escapable 'self' requires '-enable-experimental-feature LifetimeDependence'}}
46-
// expected-error@-1{{a mutating method with a ~Escapable 'inout' parameter requires '-enable-experimental-feature LifetimeDependence'}}
45+
mutating func mutatingNEInout(span: inout RawSpan) {} // expected-error{{a mutating method cannot have a ~Escapable 'self'}}
46+
// expected-error@-1{{a mutating method cannot have a ~Escapable 'inout' parameter 'span'}}
4747
}

0 commit comments

Comments
 (0)