Rust-GCC / gccrs

GCC Front-End for Rust

Home Page:https://rust-gcc.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Negative implementations complain about missing methods

CohenArthur opened this issue · comments

Negative implementations need not care about implementing all the methods of that trait since they are un-implementing said trait.

#![feature(negative_impls)]

#[lang = "sized"]
pub trait Sized {}

pub trait Deref {}

pub trait DerefMut: Deref {
    type Target;

    /// Mutably dereferences the value.
    #[stable(feature = "rust1", since = "1.0.0")]
    fn deref_mut(&mut self) -> &mut Self::Target;
}

impl<T: ?Sized> !DerefMut for &T {}

I expected to see this happen: no errors

Instead, this happened:

~/G/r/gccrs (master|✚1) $ build/gcc/crab1 core-1.49/src/cell.rs
core-1.49/src/cell.rs:283:1: error: missing deref_mut in implementation of traitDerefMut[E0046]
  283 | impl<T: ?Sized> !DerefMut for &T {}
      | ^~~~
......
  300 |     fn deref_mut(&mut self) -> &mut Self::Target;
      |     ~~

hi there, can I get some directions to get started on this?

@badumbatish I thought the issue was quite easy to fix so I was writing a guide for you, but it turns out it's deeper than I thought because we're not setting up the polarity of the impl block properly, or I can't find how to access it.

The checks for missing methods/associated types is in the validate_trait_impl_block function, which is only called in one place. I was thinking that it should be possible to check if the impl was negative, and if it is, to not perform that check. however, the polarity isn't negative in that case, which is not what I expected. so either I have a bad understanding of that check, or there is something we're not setting up correctly for the HIR::ImplBlock we create. you can investigate if you want but it's not a clear-cut issue like I thought, sorry 😬

I'll update the testcase with something more complete