Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

ices/79422.rs: fixed with errors #643

Merged
merged 1 commit into from
Feb 6, 2021
Merged

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Feb 6, 2021

Issue: rust-lang/rust#79422

#![feature(generic_associated_types)]
#![allow(incomplete_features)]

trait RefCont<'a, T> {
    fn t(&'a self) -> &'a T;
}

impl<'a, T> RefCont<'a, T> for &'a T {
    fn t(&'a self) -> &'a T {
        self
    }
}

impl<'a, T> RefCont<'a, T> for Box<T> {
    fn t(&'a self) -> &'a T {
        self.as_ref()
    }
}

trait MapLike<K, V> {
    type VRefCont<'a>: RefCont<'a, V>;
    fn get<'a>(&'a self, key: &K) -> Option<Self::VRefCont<'a>>;
}

impl<K: Ord, V: 'static> MapLike<K, V> for std::collections::BTreeMap<K, V> {
    type VRefCont<'a> = &'a V;
    fn get<'a>(&'a self, key: &K) -> Option<&'a V> {
        std::collections::BTreeMap::get(self, key)
    }
}

struct Source;

impl<K, V: Default> MapLike<K, V> for Source {
    type VRefCont<'a> = Box<V>;
    fn get<'a>(&self, _: &K) -> Option<Box<V>> {
        Some(Box::new(V::default()))
    }
}

fn main() {
    let m = Box::new(std::collections::BTreeMap::<u8, u8>::new())
        as Box<dyn MapLike<u8, u8, VRefCont = dyn RefCont<'_, u8>>>;
}
=== stdout ===
=== stderr ===
error[E0107]: missing generics for associated type `MapLike::VRefCont`
  --> /home/runner/work/glacier/glacier/ices/79422.rs:21:10
   |
21 |     type VRefCont<'a>: RefCont<'a, V>;
   |          ^^^^^^^^ expected 1 lifetime argument
   |
note: associated type defined here, with 1 lifetime parameter: `'a`
  --> /home/runner/work/glacier/glacier/ices/79422.rs:21:10
   |
21 |     type VRefCont<'a>: RefCont<'a, V>;
   |          ^^^^^^^^ --
help: use angle brackets to add missing lifetime argument
   |
21 |     type VRefCont<'a><'a>: RefCont<'a, V>;
   |                  ^^^^

error[E0038]: the trait `MapLike` cannot be made into an object
  --> /home/runner/work/glacier/glacier/ices/79422.rs:43:12
   |
43 |         as Box<dyn MapLike<u8, u8, VRefCont = dyn RefCont<'_, u8>>>;
   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `MapLike` cannot be made into an object
   |
   = help: consider moving `get` to another trait
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
  --> /home/runner/work/glacier/glacier/ices/79422.rs:22:38
   |
20 | trait MapLike<K, V> {
   |       ------- this trait cannot be made into an object...
21 |     type VRefCont<'a>: RefCont<'a, V>;
22 |     fn get<'a>(&'a self, key: &K) -> Option<Self::VRefCont<'a>>;
   |                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^ ...because method `get` references the `Self` type in its return type

error[E0038]: the trait `MapLike` cannot be made into an object
  --> /home/runner/work/glacier/glacier/ices/79422.rs:42:13
   |
42 |     let m = Box::new(std::collections::BTreeMap::<u8, u8>::new())
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `MapLike` cannot be made into an object
   |
   = help: consider moving `get` to another trait
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
  --> /home/runner/work/glacier/glacier/ices/79422.rs:22:38
   |
20 | trait MapLike<K, V> {
   |       ------- this trait cannot be made into an object...
21 |     type VRefCont<'a>: RefCont<'a, V>;
22 |     fn get<'a>(&'a self, key: &K) -> Option<Self::VRefCont<'a>>;
   |                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^ ...because method `get` references the `Self` type in its return type
   = note: required because of the requirements on the impl of `CoerceUnsized<Box<dyn MapLike<u8, u8, VRefCont = (dyn RefCont<'_, u8> + 'static)>>>` for `Box<BTreeMap<u8, u8>>`
   = note: required by cast to type `Box<dyn MapLike<u8, u8, VRefCont = (dyn RefCont<'_, u8> + 'static)>>`

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0038, E0107.
For more information about an error, try `rustc --explain E0038`.
==============

=== stdout ===
=== stderr ===
error[E0107]: missing generics for associated type `MapLike::VRefCont`
  --> /home/runner/work/glacier/glacier/ices/79422.rs:21:10
   |
21 |     type VRefCont<'a>: RefCont<'a, V>;
   |          ^^^^^^^^ expected 1 lifetime argument
   |
note: associated type defined here, with 1 lifetime parameter: `'a`
  --> /home/runner/work/glacier/glacier/ices/79422.rs:21:10
   |
21 |     type VRefCont<'a>: RefCont<'a, V>;
   |          ^^^^^^^^ --
help: use angle brackets to add missing lifetime argument
   |
21 |     type VRefCont<'a><'a>: RefCont<'a, V>;
   |                  ^^^^

error[E0038]: the trait `MapLike` cannot be made into an object
  --> /home/runner/work/glacier/glacier/ices/79422.rs:43:12
   |
43 |         as Box<dyn MapLike<u8, u8, VRefCont = dyn RefCont<'_, u8>>>;
   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `MapLike` cannot be made into an object
   |
   = help: consider moving `get` to another trait
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
  --> /home/runner/work/glacier/glacier/ices/79422.rs:22:38
   |
20 | trait MapLike<K, V> {
   |       ------- this trait cannot be made into an object...
21 |     type VRefCont<'a>: RefCont<'a, V>;
22 |     fn get<'a>(&'a self, key: &K) -> Option<Self::VRefCont<'a>>;
   |                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^ ...because method `get` references the `Self` type in its return type

error[E0038]: the trait `MapLike` cannot be made into an object
  --> /home/runner/work/glacier/glacier/ices/79422.rs:42:13
   |
42 |     let m = Box::new(std::collections::BTreeMap::<u8, u8>::new())
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `MapLike` cannot be made into an object
   |
   = help: consider moving `get` to another trait
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
  --> /home/runner/work/glacier/glacier/ices/79422.rs:22:38
   |
20 | trait MapLike<K, V> {
   |       ------- this trait cannot be made into an object...
21 |     type VRefCont<'a>: RefCont<'a, V>;
22 |     fn get<'a>(&'a self, key: &K) -> Option<Self::VRefCont<'a>>;
   |                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^ ...because method `get` references the `Self` type in its return type
   = note: required because of the requirements on the impl of `CoerceUnsized<Box<dyn MapLike<u8, u8, VRefCont = (dyn RefCont<'_, u8> + 'static)>>>` for `Box<BTreeMap<u8, u8>>`
   = note: required by cast to type `Box<dyn MapLike<u8, u8, VRefCont = (dyn RefCont<'_, u8> + 'static)>>`

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0038, E0107.
For more information about an error, try `rustc --explain E0038`.
==============
@Alexendoo Alexendoo merged commit 0c2c65d into master Feb 6, 2021
@Alexendoo Alexendoo deleted the autofix/ices/79422.rs branch February 6, 2021 13:41
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants