Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite recursion with a defaulted, contravariant trait #22806

Closed
nikomatsakis opened this issue Feb 25, 2015 · 1 comment · Fixed by #23938
Closed

Infinite recursion with a defaulted, contravariant trait #22806

nikomatsakis opened this issue Feb 25, 2015 · 1 comment · Fixed by #23938
Labels
A-traits Area: Trait system A-typesystem Area: The type system

Comments

@nikomatsakis
Copy link
Contributor

This test fails to compile:

unsafe trait MySend {
    fn dummy(&self) { }
}

unsafe impl MySend for .. { }

unsafe impl<T: MySend + ?Sized> MySend for Unique<T> { }

pub struct Unique<T:?Sized> {
    pointer: *const T,
}

pub struct Node<V> {
    vals: V,
    edges: Unique<Node<V>>,
}

fn is_send<T: MySend>() {}

fn main() {
    is_send::<Node<&'static ()>>();
}

the output is of the form:

...
/home/nmatsakis/tmp/22655b.rs:21:5: 21:33 note: required because of the requirements on the impl of `MySend` for `Node<&()>`
/home/nmatsakis/tmp/22655b.rs:21     is_send::<Node<&'static ()>>();
                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/nmatsakis/tmp/22655b.rs:21:5: 21:33 note: required because of the requirements on the impl of `MySend` for `Node<&()>`
/home/nmatsakis/tmp/22655b.rs:21     is_send::<Node<&'static ()>>();
                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/nmatsakis/tmp/22655b.rs:21:5: 21:33 note: required because of the requirements on the impl of `MySend` for `Node<&()>`
/home/nmatsakis/tmp/22655b.rs:21     is_send::<Node<&'static ()>>();
                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/nmatsakis/tmp/22655b.rs:21:5: 21:33 note: required because of the requirements on the impl of `MySend` for `Node<&()>`
/home/nmatsakis/tmp/22655b.rs:21     is_send::<Node<&'static ()>>();
                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/nmatsakis/tmp/22655b.rs:21:5: 21:33 note: required because of the requirements on the impl of `MySend` for `Node<&()>`
/home/nmatsakis/tmp/22655b.rs:21     is_send::<Node<&'static ()>>();
                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/nmatsakis/tmp/22655b.rs:21:5: 21:33 note: required because of the requirements on the impl of `MySend` for `Node<&()>`
/home/nmatsakis/tmp/22655b.rs:21     is_send::<Node<&'static ()>>();
                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/nmatsakis/tmp/22655b.rs:21:5: 21:33 note: required because of the requirements on the impl of `MySend` for `Node<&()>`
/home/nmatsakis/tmp/22655b.rs:21     is_send::<Node<&'static ()>>();
                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/nmatsakis/tmp/22655b.rs:21:5: 21:33 note: required because of the requirements on the impl of `MySend` for `Node<&()>`
/home/nmatsakis/tmp/22655b.rs:21     is_send::<Node<&'static ()>>();
                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/nmatsakis/tmp/22655b.rs:21:5: 21:33 note: required because of the requirements on the impl of `MySend` for `Node<&()>`
/home/nmatsakis/tmp/22655b.rs:21     is_send::<Node<&'static ()>>();
                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/nmatsakis/tmp/22655b.rs:21:5: 21:33 note: required because of the requirements on the impl of `MySend` for `Node<&()>`
/home/nmatsakis/tmp/22655b.rs:21     is_send::<Node<&'static ()>>();
                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/nmatsakis/tmp/22655b.rs:21:5: 21:33 note: required because of the requirements on the impl of `MySend` for `Node<&()>`
/home/nmatsakis/tmp/22655b.rs:21     is_send::<Node<&'static ()>>();
                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/nmatsakis/tmp/22655b.rs:21:5: 21:33 note: required because of the requirements on the impl of `MySend` for `Node<&()>`
/home/nmatsakis/tmp/22655b.rs:21     is_send::<Node<&'static ()>>();
                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/nmatsakis/tmp/22655b.rs:21:5: 21:33 note: required because of the requirements on the impl of `MySend` for `Node<&()>`
/home/nmatsakis/tmp/22655b.rs:21     is_send::<Node<&'static ()>>();
                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/nmatsakis/tmp/22655b.rs:21:5: 21:33 note: required because of the requirements on the impl of `MySend` for `Node<&'static ()>`
/home/nmatsakis/tmp/22655b.rs:21     is_send::<Node<&'static ()>>();
                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/nmatsakis/tmp/22655b.rs:21:5: 21:33 note: required by `is_send`
/home/nmatsakis/tmp/22655b.rs:21     is_send::<Node<&'static ()>>();

This bug is branched off of #22655. It represents the underlying problem that caused #22655.

@nikomatsakis
Copy link
Contributor Author

Fixing this bug would allow MarkerTrait to be made contravariant again, as designated by a FIXME in the source.

nikomatsakis added a commit to nikomatsakis/rust that referenced this issue Feb 25, 2015
steveklabnik added a commit to steveklabnik/rust that referenced this issue Feb 26, 2015
…ecursion, r=pnkfelix

Change MarkerTrait to be invariant. This is a (small) loss of expressiveness, but is necessary for now to work around rust-lang#22806. Fixes rust-lang#22655.

r? @pnkfelix
@steveklabnik steveklabnik added A-typesystem Area: The type system A-traits Area: Trait system labels Feb 26, 2015
Manishearth added a commit to Manishearth/rust that referenced this issue Feb 27, 2015
…ecursion, r=pnkfelix

 Change MarkerTrait to be invariant. This is a (small) loss of expressiveness, but is necessary for now to work around rust-lang#22806. Fixes rust-lang#22655.

r? @pnkfelix
bors added a commit that referenced this issue Apr 3, 2015
There are still some remnants we could remove from the compiler (e.g. references to "subtraitrefs"; traits still have variance entries in the variance table), but this removes all user-visible bits I believe.

r? @pnkfelix 

Fixes #22806 (since such traits would no longer exist)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-traits Area: Trait system A-typesystem Area: The type system
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants