Skip to content

Suggest borrowing when trying to coerce unsized type into dyn Trait #95609

New issue

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

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

Already on GitHub? # to your account

Merged
merged 1 commit into from
Apr 4, 2022

Conversation

compiler-errors
Copy link
Member

A helpful error in response to #95598, since we can't coerce e.g. &str into &dyn Display, but we can coerce &&str into &dyn Display :)

Not sure if the suggestion message needs some help. Let me know, and I can refine this PR.

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 2, 2022
@rust-highfive
Copy link
Contributor

r? @nagisa

(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 Apr 2, 2022
@nagisa
Copy link
Member

nagisa commented Apr 3, 2022

Not sure if the suggestion message needs some help. Let me know, and I can refine this PR.

The only possible improvement I can imagine is moving the “since ...” part to an associated note, that is

help: consider borrowing the value
   |
LL |     foo21(&"bar", &"baz");
   |           +
   = note: `&str` can be coerced into `dyn AsRef<str>`

but otherwise it seems good as is.

r=me, with or without changes to the messaging.

@compiler-errors
Copy link
Member Author

@bors r=nagisa

couldn't figure out how to get the note to appear below the suggestion, only above it, which is (imo) more confusing than the inline ", because..."

@bors
Copy link
Collaborator

bors commented Apr 3, 2022

📌 Commit 7d7715f has been approved by nagisa

@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 Apr 3, 2022
@compiler-errors
Copy link
Member Author

@bors rollup

bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 4, 2022
Rollup of 7 pull requests

Successful merges:

 - rust-lang#92942 (stabilize windows_process_extensions_raw_arg)
 - rust-lang#94817 (Release notes for 1.60.0)
 - rust-lang#95343 (Reduce unnecessary escaping in proc_macro::Literal::character/string)
 - rust-lang#95431 (Stabilize total_cmp)
 - rust-lang#95438 (Add SyncUnsafeCell.)
 - rust-lang#95467 (Windows: Synchronize asynchronous pipe reads and writes)
 - rust-lang#95609 (Suggest borrowing when trying to coerce unsized type into `dyn Trait`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 0c5f879 into rust-lang:master Apr 4, 2022
@rustbot rustbot added this to the 1.62.0 milestone Apr 4, 2022
@compiler-errors compiler-errors deleted the borrow-unsized-to-dyn branch April 7, 2022 04:29
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Jun 22, 2022
…bank

Fix trait object reborrow suggestion

Fixes rust-lang#93596

Slightly generalizes the logic we use to suggest fix first implemented in rust-lang#95609, specifically when we have a `Sized` obligation that comes from a struct's unsized tail.
compiler-errors added a commit to compiler-errors/rust that referenced this pull request Jun 23, 2022
…bank

Fix trait object reborrow suggestion

Fixes rust-lang#93596

Slightly generalizes the logic we use to suggest fix first implemented in rust-lang#95609, specifically when we have a `Sized` obligation that comes from a struct's unsized tail.
compiler-errors added a commit to compiler-errors/rust that referenced this pull request Jun 25, 2022
…bank

Fix trait object reborrow suggestion

Fixes rust-lang#93596

Slightly generalizes the logic we use to suggest fix first implemented in rust-lang#95609, specifically when we have a `Sized` obligation that comes from a struct's unsized tail.
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Jun 25, 2022
…bank

Fix trait object reborrow suggestion

Fixes rust-lang#93596

Slightly generalizes the logic we use to suggest fix first implemented in rust-lang#95609, specifically when we have a `Sized` obligation that comes from a struct's unsized tail.
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Jun 25, 2022
…bank

Fix trait object reborrow suggestion

Fixes rust-lang#93596

Slightly generalizes the logic we use to suggest fix first implemented in rust-lang#95609, specifically when we have a `Sized` obligation that comes from a struct's unsized tail.
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Jun 29, 2022
…bank

Fix trait object reborrow suggestion

Fixes rust-lang#93596

Slightly generalizes the logic we use to suggest fix first implemented in rust-lang#95609, specifically when we have a `Sized` obligation that comes from a struct's unsized tail.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants