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
A value type like a struct or enum cannot conform to Copyable if it has
a deinit. When NoncopyableGenerics is enabled, we make that part of what
is required to verify that such a nominal type conforms to Copyable.
This change also does some refactoring to share common code to point out
how to make a type noncopyable.
Copy file name to clipboardExpand all lines: test/Generics/inverse_copyable_generics.swift
+33-12Lines changed: 33 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -46,17 +46,12 @@ protocol RemovedAgain where Self: ~Copyable {
46
46
}
47
47
48
48
structStructContainment<T:~Copyable>:Copyable{
49
-
// expected-note@-1 {{consider adding '~Copyable' to generic struct 'StructContainment'}}{{50-50=, ~Copyable}}
50
-
// expected-note@-2 {{generic struct 'StructContainment' has '~Copyable' constraint on a generic parameter, making its 'Copyable' conformance conditional}}
51
-
52
49
varstorage:Maybe<T>
53
50
// expected-error@-1 {{stored property 'storage' of 'Copyable'-conforming generic struct 'StructContainment' has noncopyable type 'Maybe<T>'}}
54
51
}
55
52
56
53
enumEnumContainment<T:~Copyable>:Copyable{
57
54
// expected-note@-1 {{'T' has '~Copyable' constraint preventing implicit 'Copyable' conformance}}
58
-
// expected-note@-2{{consider adding '~Copyable' to generic enum 'EnumContainment'}}{{46-46=, ~Copyable}}
59
-
// expected-note@-3{{generic enum 'EnumContainment' has '~Copyable' constraint on a generic parameter, making its 'Copyable' conformance conditional}}
60
55
61
56
case some(T) // expected-error {{associated value 'some' of 'Copyable'-conforming generic enum 'EnumContainment' has noncopyable type 'T'}}
62
57
case other(Int)
@@ -69,6 +64,8 @@ class ClassContainment<T: ~Copyable> {
69
64
storage = t
70
65
checkCopyable(t) // expected-error {{noncopyable type 'T' cannot be substituted for copyable generic parameter 'T' in 'checkCopyable'}}
71
66
}
67
+
68
+
deinit{}
72
69
}
73
70
74
71
// expected-note@+2 {{generic struct 'ConditionalContainment' has '~Copyable' constraint on a generic parameter, making its 'Copyable' conformance conditional}}
0 commit comments