Skip to content

Suggest using as_ref on some borrow errors [hack] #51100

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

Merged
merged 1 commit into from
May 30, 2018

Conversation

estebank
Copy link
Contributor

When encountering the following code:

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

@rust-highfive
Copy link
Contributor

r? @michaelwoerister

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 27, 2018
@estebank
Copy link
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.

@rust-highfive

This comment has been minimized.

@oli-obk
Copy link
Contributor

oli-obk commented May 28, 2018

Yea, having a hacky solution for Result and Option is better than the original confusing error message.

@michaelwoerister
Copy link
Member

r? @oli-obk (you seem to know more about this)

@oli-obk
Copy link
Contributor

oli-obk commented May 30, 2018

@bors r+

@bors
Copy link
Collaborator

bors commented May 30, 2018

📌 Commit 46d0f22 has been approved by oli-obk

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 30, 2018
@bors
Copy link
Collaborator

bors commented May 30, 2018

🔒 Merge conflict

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 30, 2018
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.
@estebank
Copy link
Contributor Author

@bors r=oli-obk

rebased against master

@bors
Copy link
Collaborator

bors commented May 30, 2018

📌 Commit a19a03a has been approved by oli-obk

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 30, 2018
@bors
Copy link
Collaborator

bors commented May 30, 2018

⌛ Testing commit a19a03a with merge fddb46e...

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
@bors
Copy link
Collaborator

bors commented May 30, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: oli-obk
Pushing fddb46e to master...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants