Passing &dyn Trait from Rc<dyn Trait>
Open
Nobody has claimed this yet.
A-coercions
A-diagnostics
A-dyn-trait
C-bug
D-lack-of-suggestion
D-newcomer-roadblock
needs-triage
T-compiler
T-types
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
People seem to think this code should work. But it doesn't.
trait Trait {}
fn foo(_: &dyn Trait) {}
fn bar(rc: std::rc::Rc<dyn Trait>) { foo(&rc) }
The error:
error[E0277]: the trait bound `Rc<(dyn Trait + 'static)>: Trait` is not satisfied
--> src/main.rs:4:42
|
4 | fn bar(rc: std::rc::Rc<dyn Trait>) { foo(&rc) }
| ^^^ the trait `Trait` is not implemented for `Rc<(dyn Trait + 'static)>`
|
From discussion on discord here.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the minimal example in src/main.rs and read the linked Discord discussion for the intended behavior around passing Rc as &dyn Trait. Done means the example's requested conversion is resolved and the compiler no longer emits the shown E0277 diagnostic.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100