mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-01 07:48:45 +00:00
Render discriminant inlay hints for mixed variants if at least one discriminant is specified
This commit is contained in:
parent
7fc0f8985d
commit
557aa1e378
1 changed files with 25 additions and 5 deletions
|
@ -19,12 +19,15 @@ pub(super) fn enum_hints(
|
||||||
_: FileId,
|
_: FileId,
|
||||||
enum_: ast::Enum,
|
enum_: ast::Enum,
|
||||||
) -> Option<()> {
|
) -> Option<()> {
|
||||||
let disabled = match config.discriminant_hints {
|
let enabled = match config.discriminant_hints {
|
||||||
DiscriminantHints::Always => false,
|
DiscriminantHints::Always => true,
|
||||||
DiscriminantHints::Fieldless => sema.to_def(&enum_)?.is_data_carrying(sema.db),
|
DiscriminantHints::Fieldless => {
|
||||||
DiscriminantHints::Never => true,
|
!sema.to_def(&enum_)?.is_data_carrying(sema.db)
|
||||||
|
|| enum_.variant_list()?.variants().any(|v| v.expr().is_some())
|
||||||
|
}
|
||||||
|
DiscriminantHints::Never => false,
|
||||||
};
|
};
|
||||||
if disabled {
|
if !enabled {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
for variant in enum_.variant_list()?.variants() {
|
for variant in enum_.variant_list()?.variants() {
|
||||||
|
@ -161,8 +164,25 @@ enum Enum {
|
||||||
Variant1,
|
Variant1,
|
||||||
Variant2 {},
|
Variant2 {},
|
||||||
Variant3,
|
Variant3,
|
||||||
|
Variant5,
|
||||||
|
Variant6,
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
check_discriminants_fieldless(
|
||||||
|
r#"
|
||||||
|
enum Enum {
|
||||||
|
Variant(),
|
||||||
|
//^^^^^^^^^0
|
||||||
|
Variant1,
|
||||||
|
//^^^^^^^^1
|
||||||
|
Variant2 {},
|
||||||
|
//^^^^^^^^^^^2
|
||||||
|
Variant3,
|
||||||
|
//^^^^^^^^3
|
||||||
Variant5 = 5,
|
Variant5 = 5,
|
||||||
Variant6,
|
Variant6,
|
||||||
|
//^^^^^^^^6
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue