Add test for auto trait bounds

This commit is contained in:
Ryo Yoshida 2022-08-24 03:27:59 +09:00 committed by Lukas Wirth
parent 03340742ea
commit 4829f591fb
2 changed files with 57 additions and 5 deletions

View file

@ -724,7 +724,7 @@ pub(crate) fn adt_datum_query(
let where_clauses = convert_where_clauses(db, adt_id.into(), &bound_vars_subst);
let phantom_data_id = db
.lang_item(krate, SmolStr::new_inline("phantom_data"))
.lang_item(krate, LangItem::PhantomData)
.and_then(|item| item.as_struct())
.map(|item| item.into());
let flags = rust_ir::AdtFlags {
@ -754,10 +754,7 @@ pub(crate) fn adt_datum_query(
.enum_data(id)
.variants
.iter()
.map(|(local_id, _)| {
let variant_id = hir_def::EnumVariantId { parent: id, local_id };
variant_id_to_fields(variant_id.into())
})
.map(|&(variant_id, _)| variant_id_to_fields(variant_id.into()))
.collect();
(rust_ir::AdtKind::Enum, variants)
}

View file

@ -4553,3 +4553,58 @@ fn foo() {
"#,
);
}
#[test]
fn auto_trait_bound() {
check_types(
r#"
//- minicore: sized
auto trait Send {}
impl<T> !Send for *const T {}
struct Yes;
trait IsSend { const IS_SEND: Yes; }
impl<T: Send> IsSend for T { const IS_SEND: Yes = Yes; }
struct Struct<T>(T);
enum Enum<T> { A, B(T) }
union Union<T> { t: T }
#[lang = "phantom_data"]
struct PhantomData<T: ?Sized>;
fn f<T: Send, U>() {
T::IS_SEND;
//^^^^^^^^^^Yes
U::IS_SEND;
//^^^^^^^^^^{unknown}
<*const T>::IS_SEND;
//^^^^^^^^^^^^^^^^^^^{unknown}
Struct::<T>::IS_SEND;
//^^^^^^^^^^^^^^^^^^^^Yes
Struct::<U>::IS_SEND;
//^^^^^^^^^^^^^^^^^^^^{unknown}
Struct::<*const T>::IS_SEND;
//^^^^^^^^^^^^^^^^^^^^^^^^^^^{unknown}
Enum::<T>::IS_SEND;
//^^^^^^^^^^^^^^^^^^Yes
Enum::<U>::IS_SEND;
//^^^^^^^^^^^^^^^^^^{unknown}
Enum::<*const T>::IS_SEND;
//^^^^^^^^^^^^^^^^^^^^^^^^^{unknown}
Union::<T>::IS_SEND;
//^^^^^^^^^^^^^^^^^^^Yes
Union::<U>::IS_SEND;
//^^^^^^^^^^^^^^^^^^^{unknown}
Union::<*const T>::IS_SEND;
//^^^^^^^^^^^^^^^^^^^^^^^^^^{unknown}
PhantomData::<T>::IS_SEND;
//^^^^^^^^^^^^^^^^^^^^^^^^^Yes
PhantomData::<U>::IS_SEND;
//^^^^^^^^^^^^^^^^^^^^^^^^^{unknown}
PhantomData::<*const T>::IS_SEND;
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^{unknown}
}
"#,
);
}