Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SE-0377: Clarify that passing a non-implicitly-copyable binding as an argument is an error if it copies. #2053

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion proposals/0377-parameter-ownership-modifiers.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ extension String {
}
```


A value would need to be implicitly copied if:

- a *consuming operation* is applied to a `borrowing` binding, or
Expand Down Expand Up @@ -289,6 +288,28 @@ func baz(a: consuming String) {
}
```

To clarify the boundary within which the no-implicit-copy constraint applies, a
parameter binding's value *is* noncopyable as part of the *call expression* in
the caller, so if forming the call requires copying, that will raise an error,
even if the parameter would be implicitly copyable in the callee. The function
body serves as the boundary for the no-implicit-copy constraint:

```
struct Bar {
var a: String
var b: String
init(ab: String) {
// OK, ab is implicitly copyable here
a = ab
b = ab
}
}

func foo(x: borrowing String) {
_ = Bar(ab: x) // ERROR: would need to copy `x` to let `Bar.init` consume it
}
```

## Source compatibility

Adding `consuming` or `borrowing` to a parameter in the language today does not
Expand Down