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