Skip to content

breakage due to a bugfix in rustc #16

@lcnr

Description

@lcnr

Your crate will unfortunately stop compiling once rust-lang/rust#121848 is merged. It unintentionally relies on an unsound bug of the type system which we are now fixing: rust-lang/rust#114061.

impl<T> Drive for T
where
T: 'static,
// HRTB, because this needs to be true for late-bound lifetimes,
// as both &self and &visitor have anonymous lifetimes.
for<'a> &'a T: IntoIterator,
for<'a> <&'a T as IntoIterator>::Item: DerefAndDrive,

This can overlap with the following impl

impl<T> Drive for Box<T>
where
T: Drive,

causing Box<Local> to implement Drive using two separate overlapping impls in the following example:

use std::iter;
struct Local;
impl<'a> IntoIterator for &'a Box<Local> {
    type IntoIter = iter::Once<&'a ()>;
    type Item = &'a ();
    fn into_iter(self) -> Self::IntoIter {
        iter::once(&())
    }
}

impl derive_visitor::Drive for Local {
    fn drive<V>(&self, _: &mut V) {}
}

fn impls_drive<T: derive_visitor::Drive>() {}

fn main() {
    impls_drive::<Box<Local>>();
}

The underlying issue is that, during the coherence overlap check, we consider for<'a> <&'a Box<_> as IntoIterator>::Item: DerefAndDrive to never apply, even though as shown above, it is possible to writean impl so that it does.

I think that there is unfortunately no way to fix the new error except by remove the blanket impl. I apologize for the this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions