2014-06-21 15:03:15 -05:00
|
|
|
// The regression test for #15031 to make sure destructuring trait
|
|
|
|
// reference work properly.
|
|
|
|
|
2015-02-10 15:52:00 -06:00
|
|
|
#![feature(box_patterns)]
|
2015-01-07 15:35:56 -06:00
|
|
|
|
2015-02-18 17:58:07 -06:00
|
|
|
trait T { fn foo(&self) {} }
|
2015-01-08 04:54:35 -06:00
|
|
|
impl T for isize {}
|
2014-06-21 15:03:15 -05:00
|
|
|
|
2021-08-24 19:39:40 -05:00
|
|
|
|
2014-06-21 15:03:15 -05: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 13:46:13 -05:00
|
|
|
let &x = &(&1isize as &dyn T);
|
|
|
|
let &x = &&(&1isize as &dyn T);
|
|
|
|
let &&x = &&(&1isize as &dyn T);
|
2014-06-21 15:03:15 -05:00
|
|
|
|
|
|
|
// n == m
|
2019-05-28 13:46:13 -05: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-24 19:39:40 -05:00
|
|
|
let box x = Box::new(1isize) as Box<dyn T>;
|
2020-09-02 02:40:56 -05:00
|
|
|
//~^ ERROR type `Box<dyn T>` cannot be dereferenced
|
2014-06-21 15:03:15 -05:00
|
|
|
|
|
|
|
// n > m
|
2019-05-28 13:46:13 -05:00
|
|
|
let &&x = &1isize as &dyn T;
|
2015-01-12 00:01:44 -06:00
|
|
|
//~^ ERROR mismatched types
|
2019-11-14 16:08:08 -06:00
|
|
|
//~| expected trait object `dyn T`
|
2019-11-13 16:16:56 -06:00
|
|
|
//~| found reference `&_`
|
2019-05-28 13:46:13 -05:00
|
|
|
let &&&x = &(&1isize as &dyn T);
|
2015-01-12 00:01:44 -06:00
|
|
|
//~^ ERROR mismatched types
|
2019-11-14 16:08:08 -06:00
|
|
|
//~| expected trait object `dyn T`
|
2019-11-13 16:16:56 -06:00
|
|
|
//~| found reference `&_`
|
2021-08-24 19:39:40 -05:00
|
|
|
let box box x = Box::new(1isize) as Box<dyn T>;
|
2015-01-12 00:01:44 -06:00
|
|
|
//~^ ERROR mismatched types
|
2019-11-14 16:08:08 -06:00
|
|
|
//~| expected trait object `dyn T`
|
2020-09-02 02:40:56 -05:00
|
|
|
//~| found struct `Box<_>`
|
2014-06-21 15:03:15 -05:00
|
|
|
}
|