@@ -368,8 +368,7 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd, Type resultType) {
368
368
return std::nullopt;
369
369
}
370
370
371
- // Perform lifetime dependence inference under a flag only. Currently all
372
- // stdlib types can appear is ~Escapable and ~Copyable.
371
+ // Disable inference if requested.
373
372
if (!ctx.LangOpts .EnableExperimentalLifetimeDependenceInference ) {
374
373
return std::nullopt;
375
374
}
@@ -386,6 +385,17 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd, Type resultType) {
386
385
return std::nullopt;
387
386
}
388
387
388
+ auto *cd = dyn_cast<ConstructorDecl>(afd);
389
+ if (cd && cd->isImplicit ()) {
390
+ if (cd->getParameters ()->size () == 0 ) {
391
+ return std::nullopt;
392
+ } else {
393
+ diags.diagnose (cd->getLoc (),
394
+ diag::lifetime_dependence_cannot_infer_implicit_init);
395
+ return std::nullopt;
396
+ }
397
+ }
398
+
389
399
if (afd->getKind () != DeclKind::Constructor && afd->hasImplicitSelfDecl ()) {
390
400
ValueOwnership ownership = ValueOwnership::Default;
391
401
if (auto *AD = dyn_cast<AccessorDecl>(afd)) {
@@ -413,11 +423,6 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd, Type resultType) {
413
423
ownership);
414
424
}
415
425
416
- auto *cd = dyn_cast<ConstructorDecl>(afd);
417
- if (cd && cd->isImplicit () && cd->getParameters ()->size () == 0 ) {
418
- return std::nullopt;
419
- }
420
-
421
426
LifetimeDependenceInfo lifetimeDependenceInfo;
422
427
ParamDecl *candidateParam = nullptr ;
423
428
unsigned paramIndex = 0 ;
@@ -451,11 +456,7 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd, Type resultType) {
451
456
lifetimeDependenceInfo = LifetimeDependenceInfo::getForParamIndex (
452
457
afd, paramIndex + 1 , param->getValueOwnership ());
453
458
}
454
- if (cd && cd->isImplicit ()) {
455
- diags.diagnose (cd->getLoc (),
456
- diag::lifetime_dependence_cannot_infer_implicit_init);
457
- return std::nullopt;
458
- }
459
+
459
460
if (!candidateParam && !hasParamError) {
460
461
// Explicitly turn off error messages for builtins, since some of are
461
462
// ~Escapable currently.
0 commit comments