Added consteval tests

This commit is contained in:
OleStrohm 2022-08-07 18:22:18 +02:00
parent 2f84b6e2e5
commit ad0a6bf1a3
6 changed files with 46 additions and 11 deletions

View file

@ -348,12 +348,15 @@ pub(super) fn definition(
Definition::Module(it) => label_and_docs(db, it),
Definition::Function(it) => label_and_docs(db, it),
Definition::Adt(it) => label_and_docs(db, it),
Definition::Variant(it) => label_value_and_docs(db, it, |&it| match it.kind(db) {
StructKind::Unit => match it.eval(db) {
Ok(x) => Some(format!("{}", x.enum_value().unwrap_or(x))),
Err(_) => it.value(db).map(|x| format!("{:?}", x)),
},
_ => None,
Definition::Variant(it) => label_value_and_docs(db, it, |&it| {
if it.parent.is_data_carrying(db) {
match it.eval(db) {
Ok(x) => Some(format!("{}", x.enum_value().unwrap_or(x))),
Err(_) => it.value(db).map(|x| format!("{:?}", x)),
}
} else {
None
}
}),
Definition::Const(it) => label_value_and_docs(db, it, |it| {
let body = it.eval(db);

View file

@ -698,6 +698,7 @@ fn hover_enum_variant() {
check(
r#"
enum Option<T> {
Some(T)
/// The None variant
Non$0e
}