Repository navigation
Auto-borrow ref self receivers on parameters declared without own - #1658
Conversation
A `ref self` method could not be called directly on a parameter
declared without `own`: `fn f(s: S) -> u8 { s.get() }` was rejected with
"expected `ref S`, but `S` is given", while `let r = ref s; r.get()` and
the same call on a local worked. Such a parameter is typed as a view of
its value, and the receiver auto-borrow only accepted an owned value.
Accept a view receiver for a `ref self` borrow in the type checker, and
lower it as a borrow of the receiver place, as an explicit `ref` is
lowered. `mut self` receivers are unchanged.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
0e4208b to
55685bc
Compare
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
A
ref selfmethod could not be called directly on a parameter declared withoutown:The same call works on a local, on an
ownparameter, and aslet r = ref s; r.get(). A parameter withoutownisa borrowed view of its value (shown as
Sin the message), and the receiver auto-borrow only accepted an owned value.The type checker now accepts such a receiver for
ref self. Lowering borrows the receiver place, as it does for anexplicit
ref.mut selfreceivers are unchanged.Tested with a new
fe testfixture,fe_test/ref_self_receiver_on_param.fe, which runs the calls. It coversconcrete, generic and trait methods, a field of a parameter, an
ownparameter and an explicitref.This is close to #1643, which improves trait-bound errors on the same kind of borrowed values. The two change
different code and merge cleanly.