rust/tests/ui/object-safety/object-safety-generics.rs

40 lines
789 B
Rust
Raw Normal View History

// Check that we correctly prevent users from making trait objects
// from traits with generic methods, unless `where Self : Sized` is
// present.
// revisions: curr object_safe_for_dispatch
#![cfg_attr(object_safe_for_dispatch, feature(object_safe_for_dispatch))]
2014-11-01 22:21:55 -05:00
trait Bar {
fn bar<T>(&self, t: T);
2014-11-01 22:21:55 -05:00
}
trait Quux {
fn bar<T>(&self, t: T)
where Self : Sized;
}
2019-05-28 13:46:13 -05:00
fn make_bar<T:Bar>(t: &T) -> &dyn Bar {
//[curr]~^ ERROR E0038
t
//[object_safe_for_dispatch]~^ ERROR E0038
}
2014-11-01 22:21:55 -05:00
2019-05-28 13:46:13 -05:00
fn make_bar_explicit<T:Bar>(t: &T) -> &dyn Bar {
//[curr]~^ ERROR E0038
2019-05-28 13:46:13 -05:00
t as &dyn Bar
//[object_safe_for_dispatch]~^ ERROR E0038
2014-11-01 22:21:55 -05:00
}
2019-05-28 13:46:13 -05:00
fn make_quux<T:Quux>(t: &T) -> &dyn Quux {
t
}
2019-05-28 13:46:13 -05:00
fn make_quux_explicit<T:Quux>(t: &T) -> &dyn Quux {
t as &dyn Quux
}
2014-11-01 22:21:55 -05:00
fn main() {
}