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