Trait impls on `dyn` objects result in combinatorically increasing autotrait bounds
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
Research direction
No implementation files, tests, or compiler entry points are identified in the issue. Start by locating Rust's trait-object and auto-trait handling, then determine whether the proposed behavior belongs in the language, trait solver, or compiler. Done should include an agreed design, implementation scope, and tests covering the relevant dyn and auto-trait combinations.
Written by the indexing model from the issue text.
Description
Oftentimes, a trait is dyn-incompatible but can still be implemented on a dyn object by selecting conservative default values for missing items. A common pattern resembles:
trait Foo {
// "i promise this impl does at least this many of $something"
const MIN_SOMETHING: u32;
fn okay(&self);
}
impl(self) trait Bar { // or sealed
fn dyn_okay(&self)
}
impl<T: Foo> Bar for Foo {
fn dyn_okay(&self) { self.okay() }
}
impl Foo for dyn Bar {
const MIN_SOMETHING: u32 = 0;
fn okay(&self) { self.dyn_okay() }
}
However, this pattern is problematic since the impl on dyn Bar does not automatically also apply to dyn Bar + Send, dyn Bar + Sync, or dyn Bar + Send + Sync. As more autotraits are added to the language, this problem can get combinatorically worse as the number of possible autotrait combinations increases.
A couple of potential solutions come to mind; on the one hand, if there were a builtin trait IsDynObject, the latter impl in the example could be rephrased to impl<T: Bar + IsDynObject> Foo for T.
Alternatively, having syntax for impl Foo for dyn Bar + ... or similar and autogenerating the relevant impls may also work but removes the option of specifying whether certain autotraits should be excluded. I'm not sure if this has concrete usecases, though.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.2k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 510
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.
More from rust-lang/rust
-
needs-triage O-unix relnotes relnotes-tracking-issue T-libs
Difficulty 1/5 Under an hour Newbie friendliness 72/100
-
A-CI A-spurious C-bug O-fuchsia T-infra
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
A-run-make needs-triage O-hermit O-linux O-netbsd O-redox O-SGX O-solid O-unix O-wasi O-wasm O-windows relnotes relnotes-tracking-issue T-compiler T-rustdoc
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
A-attributes needs-triage relnotes relnotes-tracking-issue T-compiler
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
needs-triage O-SGX relnotes relnotes-tracking-issue T-libs
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
kwakseongjae/auto-hwp#319 ·
-
area:cli bug filter-quality good first issue priority:medium
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
bevyengine/bevy#25861 ·
-
comp-datalake
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/ClickHouse#121222 ·
-
enhancement remote
Difficulty 2/5 1-3 hours Newbie friendliness 68/100