mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Merge #4347
4347: Fix usefulness check for never type r=flodiebold a=MikailBag Co-authored-by: Mikail Bagishov <bagishov.mikail@yandex.ru>
This commit is contained in:
commit
e99447ffbf
1 changed files with 23 additions and 6 deletions
|
@ -573,14 +573,20 @@ pub(crate) fn is_useful(
|
||||||
matrix: &Matrix,
|
matrix: &Matrix,
|
||||||
v: &PatStack,
|
v: &PatStack,
|
||||||
) -> MatchCheckResult<Usefulness> {
|
) -> MatchCheckResult<Usefulness> {
|
||||||
// Handle the special case of enums with no variants. In that case, no match
|
// Handle two special cases:
|
||||||
// arm is useful.
|
// - enum with no variants
|
||||||
if let Ty::Apply(ApplicationTy { ctor: TypeCtor::Adt(AdtId::EnumId(enum_id)), .. }) =
|
// - `!` type
|
||||||
cx.infer[cx.match_expr].strip_references()
|
// In those cases, no match arm is useful.
|
||||||
{
|
match cx.infer[cx.match_expr].strip_references() {
|
||||||
if cx.db.enum_data(*enum_id).variants.is_empty() {
|
Ty::Apply(ApplicationTy { ctor: TypeCtor::Adt(AdtId::EnumId(enum_id)), .. }) => {
|
||||||
|
if cx.db.enum_data(*enum_id).variants.is_empty() {
|
||||||
|
return Ok(Usefulness::NotUseful);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ty::Apply(ApplicationTy { ctor: TypeCtor::Never, .. }) => {
|
||||||
return Ok(Usefulness::NotUseful);
|
return Ok(Usefulness::NotUseful);
|
||||||
}
|
}
|
||||||
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
if v.is_empty() {
|
if v.is_empty() {
|
||||||
|
@ -1917,6 +1923,17 @@ mod tests {
|
||||||
check_no_diagnostic(content);
|
check_no_diagnostic(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn type_never() {
|
||||||
|
let content = r"
|
||||||
|
fn test_fn(never: !) {
|
||||||
|
match never {}
|
||||||
|
}
|
||||||
|
";
|
||||||
|
|
||||||
|
check_no_diagnostic(content);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn enum_never_ref() {
|
fn enum_never_ref() {
|
||||||
let content = r"
|
let content = r"
|
||||||
|
|
Loading…
Reference in a new issue