rust-lang / rust-lang/rust

Solver is overzealous with fundamental impls in the standard library

Open
#157,498 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-coherence C-bug T-compiler T-types
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

More details in this zulip thread detailing the requirements to get ToOwned into core: #t-libs > core::borrow::Cow (cowcore)

Essentially, the impl in question is impl From<Cow<'_, str>> for Box<dyn Error>, where Cow and Error are both defined in core, but alloc defines Box, which is marked fundamental.

It allows this for From<&str> interestingly enough, but not Cow, presumably because it's not a primitive type.

This definitely is totally fine under the orphan rule because core is a dependency of alloc, and thus there would never be any scenario where a impl could be defined in core, even though Box is fundamental.

My guess is that this is a very low-priority bug to fix since this just blocks a change that needs larger stuff to be done first, but this feels like it could potentially show up in other ways if we're not careful, and is worth documenting.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Zulip thread and investigate the compiler's orphan-rule handling for impl From<Cow<'_, str>> for Box<dyn Error>. Compare it with the accepted From<&str> case and determine the intended behavior for fundamental types; completion requires a confirmed fix or documented limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.