Conversation
Contributor
|
(rust_highfive has picked a reviewer for you, use r? to override) |
Contributor
Author
|
cc @oli-obk @kornelski @scottmcm from the original issue. This is not a nice solution, but given that this is a common pitfall for newcomers, I wanted to have some support for a suggestion. |
This comment has been minimized.
This comment has been minimized.
Contributor
|
Yea, having a hacky solution for Result and Option is better than the original confusing error message. |
Contributor
|
r? @oli-obk (you seem to know more about this) |
Contributor
|
@bors r+ |
Contributor
|
📌 Commit 46d0f22 has been approved by |
Contributor
|
🔒 Merge conflict |
When encountering the following code:
```rust
struct Foo;
fn takes_ref(_: &Foo) {}
let ref opt = Some(Foo);
opt.map(|arg| takes_ref(arg));
```
Suggest using `opt.as_ref().map(|arg| takes_ref(arg));` instead.
This is a stop gap solution until we expand typeck to deal with these
cases in a more graceful way.
Contributor
Author
|
@bors r=oli-obk rebased against master |
Contributor
|
📌 Commit a19a03a has been approved by |
Contributor
bors
added a commit
that referenced
this pull request
May 30, 2018
Suggest using `as_ref` on some borrow errors [hack]
When encountering the following code:
```rust
struct Foo;
fn takes_ref(_: &Foo) {}
let ref opt = Some(Foo);
opt.map(|arg| takes_ref(arg));
```
Suggest using `opt.as_ref().map(|arg| takes_ref(arg));` instead.
This is a stop gap solution until we expand typeck to deal with these
cases in a more graceful way.
#43861
Contributor
|
☀️ Test successful - status-appveyor, status-travis |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When encountering the following code:
Suggest using
opt.as_ref().map(|arg| takes_ref(arg));instead.This is a stop gap solution until we expand typeck to deal with these
cases in a more graceful way.
#43861