Skip to content

Commit

Permalink
Add test for auto trait bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
lowr authored and Veykril committed Feb 14, 2024
1 parent 0334074 commit 4829f59
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 5 deletions.
7 changes: 2 additions & 5 deletions crates/hir-ty/src/chalk_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down
55 changes: 55 additions & 0 deletions crates/hir-ty/src/tests/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
"#,
);
}

0 comments on commit 4829f59

Please sign in to comment.