Skip to content

Commit 0595476

Browse files
committed
Update moveonly diagnostics
1 parent 4bb68a3 commit 0595476

File tree

4 files changed

+60
-27
lines changed

4 files changed

+60
-27
lines changed

include/swift/AST/Decl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6342,7 +6342,7 @@ class ParamDecl : public VarDecl {
63426342

63436343
static Specifier
63446344
getParameterSpecifierForValueOwnership(ValueOwnership ownership) {
6345-
#warning "todo: switch over to consuming/borrowing once they're fully supported"
6345+
// TODO: switch over to consuming/borrowing once they're fully supported
63466346
switch (ownership) {
63476347
case ValueOwnership::Default:
63486348
return Specifier::Default;

lib/Sema/TypeCheckType.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2303,17 +2303,17 @@ bool TypeResolver::diagnoseMoveOnlyMissingOwnership(
23032303

23042304
// FIXME: this should be 'borrowing'
23052305
diagnose(repr->getLoc(), diag::moveonly_parameter_ownership_suggestion,
2306-
"__shared", "for an immutable reference")
2307-
.fixItInsert(repr->getStartLoc(), "__shared ");
2306+
"borrowing", "for an immutable reference")
2307+
.fixItInsert(repr->getStartLoc(), "borrowing ");
23082308

23092309
diagnose(repr->getLoc(), diag::moveonly_parameter_ownership_suggestion,
23102310
"inout", "for a mutable reference")
23112311
.fixItInsert(repr->getStartLoc(), "inout ");
23122312

23132313
// FIXME: this should be 'consuming'
23142314
diagnose(repr->getLoc(), diag::moveonly_parameter_ownership_suggestion,
2315-
"__owned", "to take the value from callers")
2316-
.fixItInsert(repr->getStartLoc(), "__owned ");
2315+
"consuming", "to take the value from the caller")
2316+
.fixItInsert(repr->getStartLoc(), "consuming ");
23172317

23182318
// to avoid duplicate diagnostics
23192319
repr->setInvalid();
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-move-only) | %FileCheck %s
2+
3+
@_moveOnly
4+
struct Butt {
5+
var value: Int
6+
deinit { print("disposing \(value)") }
7+
8+
mutating func merge(with: borrowing Butt) {
9+
value += with.value
10+
}
11+
12+
func report() {
13+
print("got \(value)")
14+
}
15+
}
16+
17+
func foo(x: consuming Butt, y: borrowing Butt) -> Butt {
18+
x.merge(with: y)
19+
20+
return x
21+
}
22+
23+
func main() {
24+
let x = Butt(value: 17)
25+
26+
// CHECK: disposing 38
27+
let y = foo(x: x, y: Butt(value: 38))
28+
29+
// CHECK-NEXT: got 55
30+
y.report()
31+
// CHECK-NEXT: disposing 55
32+
}
33+
main()

test/Sema/moveonly_require_ownership_specifier.swift

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,69 +18,69 @@ public struct NoncopyableWrapper<T> {
1818
class Inspector {
1919
func inspect(_ hasIt: inout MO, _ mo: MO, _ hasItAgain: __owned MO) {}
2020
// expected-error@-1 {{noncopyable parameter must specify its ownership}}
21-
// expected-note@-2 {{add '__shared' for an immutable reference}}{{41-41=__shared }}
21+
// expected-note@-2 {{add 'borrowing' for an immutable reference}}{{41-41=borrowing }}
2222
// expected-note@-3 {{add 'inout' for a mutable reference}}{{41-41=inout }}
23-
// expected-note@-4 {{add '__owned' to take the value from callers}}{{41-41=__owned }}
23+
// expected-note@-4 {{add 'consuming' to take the value from the caller}}{{41-41=consuming }}
2424
}
2525

2626
// expected-error@+4 {{noncopyable parameter must specify its ownership}}
27-
// expected-note@+3 {{add '__shared' for an immutable reference}}{{20-20=__shared }}
27+
// expected-note@+3 {{add 'borrowing' for an immutable reference}}{{20-20=borrowing }}
2828
// expected-note@+2 {{add 'inout' for a mutable reference}}{{20-20=inout }}
29-
// expected-note@+1 {{add '__owned' to take the value from callers}}{{20-20=__owned }}
29+
// expected-note@+1 {{add 'consuming' to take the value from the caller}}{{20-20=consuming }}
3030
func applier(_ f: (MO) -> (),
3131
_ v: MO) {}
3232
// expected-error@-1 {{noncopyable parameter must specify its ownership}}
33-
// expected-note@-2 {{add '__shared' for an immutable reference}}{{19-19=__shared }}
33+
// expected-note@-2 {{add 'borrowing' for an immutable reference}}{{19-19=borrowing }}
3434
// expected-note@-3 {{add 'inout' for a mutable reference}}{{19-19=inout }}
35-
// expected-note@-4 {{add '__owned' to take the value from callers}}{{19-19=__owned }}
35+
// expected-note@-4 {{add 'consuming' to take the value from the caller}}{{19-19=consuming }}
3636

3737
func caller() {
3838
let f = { (_ mo1: MO, _ mo2: MO) in () }
3939
// expected-error@-1 2{{noncopyable parameter must specify its ownership}}
40-
// expected-note@-2 {{add '__shared' for an immutable reference}}{{21-21=__shared }}
41-
// expected-note@-3 {{add '__shared' for an immutable reference}}{{32-32=__shared }}
40+
// expected-note@-2 {{add 'borrowing' for an immutable reference}}{{21-21=borrowing }}
41+
// expected-note@-3 {{add 'borrowing' for an immutable reference}}{{32-32=borrowing }}
4242
// expected-note@-4 {{add 'inout' for a mutable reference}}{{21-21=inout }}
4343
// expected-note@-5 {{add 'inout' for a mutable reference}}{{32-32=inout }}
44-
// expected-note@-6 {{add '__owned' to take the value from callers}}{{21-21=__owned }}
45-
// expected-note@-7 {{add '__owned' to take the value from callers}}{{32-32=__owned }}
44+
// expected-note@-6 {{add 'consuming' to take the value from the caller}}{{21-21=consuming }}
45+
// expected-note@-7 {{add 'consuming' to take the value from the caller}}{{32-32=consuming }}
4646

4747
let g: (MO, MO) -> () = f
4848
// expected-error@-1 2{{noncopyable parameter must specify its ownership}}
49-
// expected-note@-2 {{add '__shared' for an immutable reference}}{{11-11=__shared }}
50-
// expected-note@-3 {{add '__shared' for an immutable reference}}{{15-15=__shared }}
49+
// expected-note@-2 {{add 'borrowing' for an immutable reference}}{{11-11=borrowing }}
50+
// expected-note@-3 {{add 'borrowing' for an immutable reference}}{{15-15=borrowing }}
5151
// expected-note@-4 {{add 'inout' for a mutable reference}}{{11-11=inout }}
5252
// expected-note@-5 {{add 'inout' for a mutable reference}}{{15-15=inout }}
53-
// expected-note@-6 {{add '__owned' to take the value from callers}}{{11-11=__owned }}
54-
// expected-note@-7 {{add '__owned' to take the value from callers}}{{15-15=__owned }}
53+
// expected-note@-6 {{add 'consuming' to take the value from the caller}}{{11-11=consuming }}
54+
// expected-note@-7 {{add 'consuming' to take the value from the caller}}{{15-15=consuming }}
5555

5656
let partialG = { g($0, MO()) }
5757

5858
let _: Box<(MO) -> ()> = Box(val: partialG)
5959
// expected-error@-1 {{noncopyable parameter must specify its ownership}}
60-
// expected-note@-2 {{add '__shared' for an immutable reference}}{{15-15=__shared }}
60+
// expected-note@-2 {{add 'borrowing' for an immutable reference}}{{15-15=borrowing }}
6161
// expected-note@-3 {{add 'inout' for a mutable reference}}{{15-15=inout }}
62-
// expected-note@-4 {{add '__owned' to take the value from callers}}{{15-15=__owned }}
62+
// expected-note@-4 {{add 'consuming' to take the value from the caller}}{{15-15=consuming }}
6363

6464
let _: Box<(inout MO) -> ()>? = nil
6565
let _: Box<(__shared MO) -> ()>? = nil
6666

6767
let _: Box<(MO) -> ()>? = nil
6868
// expected-error@-1 {{noncopyable parameter must specify its ownership}}
69-
// expected-note@-2 {{add '__shared' for an immutable reference}}{{15-15=__shared }}
69+
// expected-note@-2 {{add 'borrowing' for an immutable reference}}{{15-15=borrowing }}
7070
// expected-note@-3 {{add 'inout' for a mutable reference}}{{15-15=inout }}
71-
// expected-note@-4 {{add '__owned' to take the value from callers}}{{15-15=__owned }}
71+
// expected-note@-4 {{add 'consuming' to take the value from the caller}}{{15-15=consuming }}
7272

7373
applier(partialG, MO())
7474
}
7575

7676
func takeGeneric<T>(_ x: NoncopyableWrapper<T>) {}
7777
// expected-error@-1 {{noncopyable parameter must specify its ownership}}
78-
// expected-note@-2 {{add '__shared' for an immutable reference}}{{26-26=__shared }}
78+
// expected-note@-2 {{add 'borrowing' for an immutable reference}}{{26-26=borrowing }}
7979
// expected-note@-3 {{add 'inout' for a mutable reference}}{{26-26=inout }}
80-
// expected-note@-4 {{add '__owned' to take the value from callers}}{{26-26=__owned }}
80+
// expected-note@-4 {{add 'consuming' to take the value from the caller}}{{26-26=consuming }}
8181

8282
func takeInstantiated(_ x: NoncopyableWrapper<Int>) {}
8383
// expected-error@-1 {{noncopyable parameter must specify its ownership}}
84-
// expected-note@-2 {{add '__shared' for an immutable reference}}{{28-28=__shared }}
84+
// expected-note@-2 {{add 'borrowing' for an immutable reference}}{{28-28=borrowing }}
8585
// expected-note@-3 {{add 'inout' for a mutable reference}}{{28-28=inout }}
86-
// expected-note@-4 {{add '__owned' to take the value from callers}}{{28-28=__owned }}
86+
// expected-note@-4 {{add 'consuming' to take the value from the caller}}{{28-28=consuming }}

0 commit comments

Comments
 (0)