@@ -614,26 +614,29 @@ class LifetimeDependenceChecker {
614
614
? ownership
615
615
: getLoweredOwnership (afd);
616
616
617
- if (parsedLifetimeKind == ParsedLifetimeDependenceKind::Default) {
617
+ switch (parsedLifetimeKind) {
618
+ case ParsedLifetimeDependenceKind::Default: {
618
619
if (type->isEscapable ()) {
619
620
if (loweredOwnership == ValueOwnership::Shared ||
620
621
loweredOwnership == ValueOwnership::InOut) {
621
622
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;
628
623
}
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 ()) {
630
631
return LifetimeDependenceKind::Inherit;
631
632
}
632
633
diagnose (loc, diag::lifetime_dependence_cannot_infer_kind,
633
634
diagnosticQualifier (), descriptor.getString ());
634
635
return std::nullopt;
635
636
}
636
637
638
+ case ParsedLifetimeDependenceKind::Borrow: LLVM_FALLTHROUGH;
639
+ case ParsedLifetimeDependenceKind::Inout: {
637
640
// @lifetime(borrow x) is valid only for borrowing parameters.
638
641
// @lifetime(inout x) is valid only for inout parameters.
639
642
if (!isCompatibleWithOwnership (parsedLifetimeKind, type,
@@ -644,16 +647,17 @@ class LifetimeDependenceChecker {
644
647
getOwnershipSpelling (loweredOwnership));
645
648
return std::nullopt;
646
649
}
650
+ return LifetimeDependenceKind::Scope;
651
+ }
652
+ case ParsedLifetimeDependenceKind::Inherit:
647
653
// @lifetime(copy x) is only invalid for Escapable types.
648
- if (parsedLifetimeKind == ParsedLifetimeDependenceKind::Inherit &&
649
- type->isEscapable ()) {
654
+ if (type->isEscapable ()) {
650
655
diagnose (loc, diag::lifetime_dependence_invalid_inherit_escapable_type,
651
656
descriptor.getString ());
652
657
return std::nullopt;
653
658
}
654
- return parsedLifetimeKind == ParsedLifetimeDependenceKind::Inherit
655
- ? LifetimeDependenceKind::Inherit
656
- : LifetimeDependenceKind::Scope;
659
+ return LifetimeDependenceKind::Inherit;
660
+ }
657
661
}
658
662
659
663
// Finds the ParamDecl* and its index from a LifetimeDescriptor
0 commit comments