2014-06-21 20:03:15 +00:00
|
|
|
// The regression test for #15031 to make sure destructuring trait
|
|
|
|
// reference work properly.
|
|
|
|
|
2015-02-10 21:52:00 +00:00
|
|
|
#![feature(box_patterns)]
|
2015-01-07 21:35:56 +00:00
|
|
|
|
2015-02-18 23:58:07 +00:00
|
|
|
trait T { fn foo(&self) {} }
|
2015-01-08 10:54:35 +00:00
|
|
|
impl T for isize {}
|
2014-06-21 20:03:15 +00:00
|
|
|
|
2021-08-25 00:39:40 +00:00
|
|
|
|
2014-06-21 20:03:15 +00:00
|
|
|
fn main() {
|
|
|
|
// For an expression of the form:
|
|
|
|
//
|
|
|
|
// let &...&x = &..&SomeTrait;
|
|
|
|
//
|
|
|
|
// Say we have n `&` at the left hand and m `&` right hand, then:
|
|
|
|
// if n < m, we are golden;
|
|
|
|
// if n == m, it's a derefing non-derefable type error;
|
|
|
|
// if n > m, it's a type mismatch error.
|
|
|
|
|
|
|
|
// n < m
|
2019-05-28 18:46:13 +00:00
|
|
|
let &x = &(&1isize as &dyn T);
|
|
|
|
let &x = &&(&1isize as &dyn T);
|
|
|
|
let &&x = &&(&1isize as &dyn T);
|
2014-06-21 20:03:15 +00:00
|
|
|
|
|
|
|
// n == m
|
2019-05-28 18:46:13 +00:00
|
|
|
let &x = &1isize as &dyn T; //~ ERROR type `&dyn T` cannot be dereferenced
|
|
|
|
let &&x = &(&1isize as &dyn T); //~ ERROR type `&dyn T` cannot be dereferenced
|
2021-08-25 00:39:40 +00:00
|
|
|
let box x = Box::new(1isize) as Box<dyn T>;
|
2020-09-02 07:40:56 +00:00
|
|
|
//~^ ERROR type `Box<dyn T>` cannot be dereferenced
|
2014-06-21 20:03:15 +00:00
|
|
|
|
|
|
|
// n > m
|
2019-05-28 18:46:13 +00:00
|
|
|
let &&x = &1isize as &dyn T;
|
2015-01-12 06:01:44 +00:00
|
|
|
//~^ ERROR mismatched types
|
2019-11-14 22:08:08 +00:00
|
|
|
//~| expected trait object `dyn T`
|
2019-11-13 22:16:56 +00:00
|
|
|
//~| found reference `&_`
|
2019-05-28 18:46:13 +00:00
|
|
|
let &&&x = &(&1isize as &dyn T);
|
2015-01-12 06:01:44 +00:00
|
|
|
//~^ ERROR mismatched types
|
2019-11-14 22:08:08 +00:00
|
|
|
//~| expected trait object `dyn T`
|
2019-11-13 22:16:56 +00:00
|
|
|
//~| found reference `&_`
|
2021-08-25 00:39:40 +00:00
|
|
|
let box box x = Box::new(1isize) as Box<dyn T>;
|
2015-01-12 06:01:44 +00:00
|
|
|
//~^ ERROR mismatched types
|
2019-11-14 22:08:08 +00:00
|
|
|
//~| expected trait object `dyn T`
|
2020-09-02 07:40:56 +00:00
|
|
|
//~| found struct `Box<_>`
|
2014-06-21 20:03:15 +00:00
|
|
|
}
|