Implement coherence checks for negative trait impls by spastorino · Pull Request...
source link: https://github.com/rust-lang/rust/pull/90104
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
The main purpose of this PR is to be able to move Error trait to core.
This feature is necessary to handle the following from impl on box.
impl From<&str> for Box<dyn Error> { ... }
Without having negative traits affect coherence moving the error trait into core
and moving that From
impl to alloc
will cause the from impl to no longer compiler because of a potential future incompatibility. The compiler indicates that &str
could introduce an Error
impl in the future, and thus prevents the From
impl in alloc
that would cause overlap with From<E: Error> for Box<dyn Error>
. Adding impl !Error for &str {}
with the negative trait coherence feature will disable this error by encoding a stability guarantee that &str
will never implement Error
, making the From
impl compile.
We would have this in alloc
:
impl From<&str> for Box<dyn Error> {} // A impl<E> From<E> for Box<dyn Error> where E: Error {} // B
and this in core
:
trait Error {} impl !Error for &str {}
This PR was built on top of @yaahc PR #85764.
Language team proposal: to rust-lang/lang-team#96
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK