Skip to content

Commit 8e21190

Browse files
committed
[NFC] Reorganize getDependenceKindFromDescriptor
1 parent 00bda98 commit 8e21190

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

lib/AST/LifetimeDependence.cpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -614,26 +614,29 @@ class LifetimeDependenceChecker {
614614
? ownership
615615
: getLoweredOwnership(afd);
616616

617-
if (parsedLifetimeKind == ParsedLifetimeDependenceKind::Default) {
617+
switch (parsedLifetimeKind) {
618+
case ParsedLifetimeDependenceKind::Default: {
618619
if (type->isEscapable()) {
619620
if (loweredOwnership == ValueOwnership::Shared ||
620621
loweredOwnership == ValueOwnership::InOut) {
621622
return LifetimeDependenceKind::Scope;
622-
} else {
623-
diagnose(
624-
loc,
625-
diag::lifetime_dependence_cannot_use_default_escapable_consuming,
626-
getOwnershipSpelling(loweredOwnership));
627-
return std::nullopt;
628623
}
629-
} else if (useLazyInference()) {
624+
diagnose(
625+
loc,
626+
diag::lifetime_dependence_cannot_use_default_escapable_consuming,
627+
getOwnershipSpelling(loweredOwnership));
628+
return std::nullopt;
629+
}
630+
if (useLazyInference()) {
630631
return LifetimeDependenceKind::Inherit;
631632
}
632633
diagnose(loc, diag::lifetime_dependence_cannot_infer_kind,
633634
diagnosticQualifier(), descriptor.getString());
634635
return std::nullopt;
635636
}
636637

638+
case ParsedLifetimeDependenceKind::Borrow: LLVM_FALLTHROUGH;
639+
case ParsedLifetimeDependenceKind::Inout: {
637640
// @lifetime(borrow x) is valid only for borrowing parameters.
638641
// @lifetime(inout x) is valid only for inout parameters.
639642
if (!isCompatibleWithOwnership(parsedLifetimeKind, type,
@@ -644,16 +647,17 @@ class LifetimeDependenceChecker {
644647
getOwnershipSpelling(loweredOwnership));
645648
return std::nullopt;
646649
}
650+
return LifetimeDependenceKind::Scope;
651+
}
652+
case ParsedLifetimeDependenceKind::Inherit:
647653
// @lifetime(copy x) is only invalid for Escapable types.
648-
if (parsedLifetimeKind == ParsedLifetimeDependenceKind::Inherit &&
649-
type->isEscapable()) {
654+
if (type->isEscapable()) {
650655
diagnose(loc, diag::lifetime_dependence_invalid_inherit_escapable_type,
651656
descriptor.getString());
652657
return std::nullopt;
653658
}
654-
return parsedLifetimeKind == ParsedLifetimeDependenceKind::Inherit
655-
? LifetimeDependenceKind::Inherit
656-
: LifetimeDependenceKind::Scope;
659+
return LifetimeDependenceKind::Inherit;
660+
}
657661
}
658662

659663
// Finds the ParamDecl* and its index from a LifetimeDescriptor

0 commit comments

Comments
 (0)