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

Suggest borrowing when it would satisfy an unmet trait bound #65456

Merged
merged 6 commits into from
Nov 18, 2019

Conversation

estebank
Copy link
Contributor

When there are multiple implementors for the same trait that is present
in an unmet binding, modify the E0277 error to refer to the parent
obligation and verify whether borrowing the argument being passed in
would satisfy the unmet bound. If it would, suggest it.

Fix #56368.

@rust-highfive
Copy link
Collaborator

r? @matthewjasper

(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 Oct 16, 2019
| ^^^^^^^
| |
| expected an `FnMut<(char,)>` closure, found `std::string::String`
| help: consider borrowing here: `&pattern`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the particular common case (std::str::pattern::Pattern) that is encountered often by newcomers and this PR is meant to solve.

@estebank
Copy link
Contributor Author

estebank commented Oct 16, 2019

Stable:
Screen Shot 2019-10-15 at 6 45 02 PM

This PR:
Screen Shot 2019-10-15 at 8 22 45 PM

@estebank

This comment has been minimized.

@bors

This comment has been minimized.

@rust-highfive

This comment has been minimized.

@estebank
Copy link
Contributor Author

CC @Centril in case you're interested in this.

@Centril
Copy link
Contributor

Centril commented Oct 31, 2019

.stderr diffs look good but the code is alien to me :)

src/librustc/traits/error_reporting.rs Outdated Show resolved Hide resolved
src/librustc/traits/error_reporting.rs Outdated Show resolved Hide resolved
@bors

This comment has been minimized.

@estebank
Copy link
Contributor Author

estebank commented Nov 7, 2019

ping @matthewjasper

@matthewjasper
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Nov 7, 2019

📌 Commit 001295beefad4b250b2d940fc1e023d1894bad18 has been approved by matthewjasper

@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 Nov 7, 2019
@bors

This comment has been minimized.

@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 Nov 8, 2019
@estebank estebank force-pushed the trait-bound-borrow branch 2 times, most recently from 8970e3a to 85d7ff6 Compare November 9, 2019 02:24
@estebank
Copy link
Contributor Author

@bors r=matthewjasper

@bors
Copy link
Contributor

bors commented Nov 14, 2019

📌 Commit 85d7ff6 has been approved by matthewjasper

@bors bors removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Nov 14, 2019
@bors bors added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 15, 2019
@estebank
Copy link
Contributor Author

@bors r=matthewjasper

@bors
Copy link
Contributor

bors commented Nov 16, 2019

📌 Commit e5e3c52e9e6561ff33184b4fe17adc2dbc071fe4 has been approved by matthewjasper

@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 Nov 16, 2019
@bors
Copy link
Contributor

bors commented Nov 16, 2019

☔ The latest upstream changes (presumably #66453) made this pull request unmergeable. Please resolve the merge conflicts.

@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 Nov 16, 2019
@estebank
Copy link
Contributor Author

@bors r-

When there are multiple implementors for the same trait that is present
in an unmet binding, modify the E0277 error to refer to the parent
obligation and verify whether borrowing the argument being passed in
would satisfy the unmet bound. If it would, suggest it.
@rust-highfive

This comment has been minimized.

@estebank
Copy link
Contributor Author

@bors r=matthewjasper

@bors
Copy link
Contributor

bors commented Nov 17, 2019

📌 Commit 2fe8371 has been approved by matthewjasper

@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 Nov 17, 2019
@bors
Copy link
Contributor

bors commented Nov 18, 2019

⌛ Testing commit 2fe8371 with merge 361791b...

bors added a commit that referenced this pull request Nov 18, 2019
Suggest borrowing when it would satisfy an unmet trait bound

When there are multiple implementors for the same trait that is present
in an unmet binding, modify the E0277 error to refer to the parent
obligation and verify whether borrowing the argument being passed in
would satisfy the unmet bound. If it would, suggest it.

Fix #56368.
@bors
Copy link
Contributor

bors commented Nov 18, 2019

☀️ Test successful - checks-azure
Approved by: matthewjasper
Pushing 361791b to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Nov 18, 2019
@bors bors merged commit 2fe8371 into rust-lang:master Nov 18, 2019
@rust-highfive
Copy link
Collaborator

📣 Toolstate changed by #65456!

Tested on commit 361791b.
Direct link to PR: #65456

🎉 rustc-guide on linux: test-fail → test-pass (cc @amanjeev @spastorino @mark-i-m, @rust-lang/infra).

rust-highfive added a commit to rust-lang-nursery/rust-toolstate that referenced this pull request Nov 18, 2019
Tested on commit rust-lang/rust@361791b.
Direct link to PR: <rust-lang/rust#65456>

🎉 rustc-guide on linux: test-fail → test-pass (cc @amanjeev @spastorino @mark-i-m, @rust-lang/infra).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. 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.

E0277 error is confusing when compile fails using the last implementor for a trait
6 participants