2021-09-19 16:57:19 +00:00
|
|
|
//@ incremental
|
2024-12-14 08:13:12 +00:00
|
|
|
// Need to disable optimizations to ensure consistent output across all CI runners.
|
2024-12-05 17:51:19 +00:00
|
|
|
//@ compile-flags: -Zprint-mono-items=lazy -Copt-level=0
|
2016-07-22 16:14:26 +00:00
|
|
|
|
2024-12-05 17:51:19 +00:00
|
|
|
#![crate_type = "rlib"]
|
2016-07-22 16:14:26 +00:00
|
|
|
|
2024-12-05 17:51:19 +00:00
|
|
|
// This test case makes sure that references made through constants cause trait associated methods
|
|
|
|
// to be monomorphized when required.
|
2017-12-22 14:31:51 +00:00
|
|
|
|
2016-07-22 16:14:26 +00:00
|
|
|
mod mod1 {
|
2024-03-17 21:42:37 +00:00
|
|
|
struct NeedsDrop;
|
|
|
|
|
|
|
|
impl Drop for NeedsDrop {
|
|
|
|
fn drop(&mut self) {}
|
|
|
|
}
|
|
|
|
|
2016-07-22 16:14:26 +00:00
|
|
|
pub trait Trait1 {
|
|
|
|
fn do_something(&self) {}
|
|
|
|
fn do_something_else(&self) {}
|
|
|
|
}
|
|
|
|
|
2024-03-17 21:42:37 +00:00
|
|
|
impl Trait1 for NeedsDrop {}
|
2016-07-22 16:14:26 +00:00
|
|
|
|
|
|
|
pub trait Trait1Gen<T> {
|
|
|
|
fn do_something(&self, x: T) -> T;
|
|
|
|
fn do_something_else(&self, x: T) -> T;
|
|
|
|
}
|
|
|
|
|
2024-03-17 21:42:37 +00:00
|
|
|
impl<T> Trait1Gen<T> for NeedsDrop {
|
2024-05-29 04:25:55 +00:00
|
|
|
fn do_something(&self, x: T) -> T {
|
|
|
|
x
|
|
|
|
}
|
|
|
|
fn do_something_else(&self, x: T) -> T {
|
|
|
|
x
|
|
|
|
}
|
2016-07-22 16:14:26 +00:00
|
|
|
}
|
|
|
|
|
2020-08-28 13:31:03 +00:00
|
|
|
//~ MONO_ITEM fn mod1::id::<i64> @@ vtable_through_const-mod1.volatile[Internal]
|
2024-05-29 04:25:55 +00:00
|
|
|
fn id<T>(x: T) -> T {
|
|
|
|
x
|
|
|
|
}
|
2016-07-22 16:14:26 +00:00
|
|
|
|
2024-12-05 17:51:19 +00:00
|
|
|
// These are referenced, so they produce mono-items (see main)
|
2024-03-17 21:42:37 +00:00
|
|
|
pub const TRAIT1_REF: &'static Trait1 = &NeedsDrop as &Trait1;
|
|
|
|
pub const TRAIT1_GEN_REF: &'static Trait1Gen<u8> = &NeedsDrop as &Trait1Gen<u8>;
|
2016-07-22 16:14:26 +00:00
|
|
|
pub const ID_CHAR: fn(char) -> char = id::<char>;
|
|
|
|
|
|
|
|
pub trait Trait2 {
|
|
|
|
fn do_something(&self) {}
|
|
|
|
fn do_something_else(&self) {}
|
|
|
|
}
|
|
|
|
|
2024-12-14 08:13:12 +00:00
|
|
|
//~ MONO_ITEM fn <mod1::NeedsDrop as mod1::Trait2>::do_something @@ vtable_through_const-mod1.volatile[External]
|
|
|
|
//~ MONO_ITEM fn <mod1::NeedsDrop as mod1::Trait2>::do_something_else @@ vtable_through_const-mod1.volatile[External]
|
2024-03-17 21:42:37 +00:00
|
|
|
impl Trait2 for NeedsDrop {}
|
2016-07-22 16:14:26 +00:00
|
|
|
|
|
|
|
pub trait Trait2Gen<T> {
|
|
|
|
fn do_something(&self, x: T) -> T;
|
|
|
|
fn do_something_else(&self, x: T) -> T;
|
|
|
|
}
|
|
|
|
|
2024-03-17 21:42:37 +00:00
|
|
|
impl<T> Trait2Gen<T> for NeedsDrop {
|
2024-05-29 04:25:55 +00:00
|
|
|
fn do_something(&self, x: T) -> T {
|
|
|
|
x
|
|
|
|
}
|
|
|
|
fn do_something_else(&self, x: T) -> T {
|
|
|
|
x
|
|
|
|
}
|
2016-07-22 16:14:26 +00:00
|
|
|
}
|
|
|
|
|
2018-05-08 13:10:16 +00:00
|
|
|
// These are not referenced, so they do not produce mono-items
|
2024-03-17 21:42:37 +00:00
|
|
|
pub const TRAIT2_REF: &'static Trait2 = &NeedsDrop as &Trait2;
|
|
|
|
pub const TRAIT2_GEN_REF: &'static Trait2Gen<u8> = &NeedsDrop as &Trait2Gen<u8>;
|
2016-07-22 16:14:26 +00:00
|
|
|
pub const ID_I64: fn(i64) -> i64 = id::<i64>;
|
|
|
|
}
|
|
|
|
|
2024-12-05 17:51:19 +00:00
|
|
|
//~ MONO_ITEM fn main @@ vtable_through_const[External]
|
|
|
|
pub fn main() {
|
2024-12-14 08:13:12 +00:00
|
|
|
//~ MONO_ITEM fn <mod1::NeedsDrop as std::ops::Drop>::drop @@ vtable_through_const-fallback.cgu[External]
|
2024-03-17 21:42:37 +00:00
|
|
|
//~ MONO_ITEM fn std::ptr::drop_in_place::<mod1::NeedsDrop> - shim(Some(mod1::NeedsDrop)) @@ vtable_through_const-fallback.cgu[External]
|
2016-07-22 16:14:26 +00:00
|
|
|
|
|
|
|
// Since Trait1::do_something() is instantiated via its default implementation,
|
|
|
|
// it is considered a generic and is instantiated here only because it is
|
|
|
|
// referenced in this module.
|
2024-03-17 21:42:37 +00:00
|
|
|
//~ MONO_ITEM fn <mod1::NeedsDrop as mod1::Trait1>::do_something_else @@ vtable_through_const-mod1.volatile[External]
|
2016-07-22 16:14:26 +00:00
|
|
|
|
|
|
|
// Although it is never used, Trait1::do_something_else() has to be
|
2024-03-17 21:42:37 +00:00
|
|
|
// instantiated locally here too, otherwise the <&NeedsDrop as &Trait1> vtable
|
2016-07-22 16:14:26 +00:00
|
|
|
// could not be fully constructed.
|
2024-03-17 21:42:37 +00:00
|
|
|
//~ MONO_ITEM fn <mod1::NeedsDrop as mod1::Trait1>::do_something @@ vtable_through_const-mod1.volatile[External]
|
2016-07-22 16:14:26 +00:00
|
|
|
mod1::TRAIT1_REF.do_something();
|
|
|
|
|
|
|
|
// Same as above
|
2024-03-17 21:42:37 +00:00
|
|
|
//~ MONO_ITEM fn <mod1::NeedsDrop as mod1::Trait1Gen<u8>>::do_something @@ vtable_through_const-mod1.volatile[External]
|
|
|
|
//~ MONO_ITEM fn <mod1::NeedsDrop as mod1::Trait1Gen<u8>>::do_something_else @@ vtable_through_const-mod1.volatile[External]
|
2024-12-14 08:13:12 +00:00
|
|
|
//~ MONO_ITEM fn <mod1::NeedsDrop as mod1::Trait2Gen<u8>>::do_something @@ vtable_through_const-mod1.volatile[External]
|
|
|
|
//~ MONO_ITEM fn <mod1::NeedsDrop as mod1::Trait2Gen<u8>>::do_something_else @@ vtable_through_const-mod1.volatile[External]
|
2016-07-22 16:14:26 +00:00
|
|
|
mod1::TRAIT1_GEN_REF.do_something(0u8);
|
|
|
|
|
2020-08-28 13:31:03 +00:00
|
|
|
//~ MONO_ITEM fn mod1::id::<char> @@ vtable_through_const-mod1.volatile[External]
|
2016-07-22 16:14:26 +00:00
|
|
|
mod1::ID_CHAR('x');
|
|
|
|
}
|