about summary refs log tree commit diff
path: root/tests/ui/reborrow/custom_mut_coerce_shared.rs
blob: e2d25835c093ae5b52b9f8f56c72c4c048873e28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#![feature(reborrow)]
use std::ops::{CoerceShared, Reborrow};

struct CustomMut<'a, T>(&'a mut T);
impl<'a, T> Reborrow for CustomMut<'a, T> {}
impl<'a, T> CoerceShared for CustomMut<'a, T> {
    type Target = CustomRef<'a, T>;
}

struct CustomRef<'a, T>(&'a T);

impl<'a, T> Clone for CustomRef<'a, T> {
    fn clone(&self) -> Self {
        Self(self.0)
    }
}
impl<'a, T> Copy for CustomRef<'a, T> {}

fn method(a: CustomRef<'_, ()>) {}  //~NOTE function defined here

fn main() {
    let a = CustomMut(&mut ());
    method(a);
    //~^ ERROR mismatched types
    //~| NOTE expected `CustomRef<'_, ()>`, found `CustomMut<'_, ()>`
    //~| NOTE arguments to this function are incorrect
    //~| NOTE expected struct `CustomRef<'_, ()>`
}