@@ -368,8 +368,7 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd, Type resultType) {
368368 return std::nullopt ;
369369 }
370370
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.
373372 if (!ctx.LangOpts .EnableExperimentalLifetimeDependenceInference ) {
374373 return std::nullopt ;
375374 }
@@ -386,6 +385,17 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd, Type resultType) {
386385 return std::nullopt ;
387386 }
388387
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+
389399 if (afd->getKind () != DeclKind::Constructor && afd->hasImplicitSelfDecl ()) {
390400 ValueOwnership ownership = ValueOwnership::Default;
391401 if (auto *AD = dyn_cast<AccessorDecl>(afd)) {
@@ -413,11 +423,6 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd, Type resultType) {
413423 ownership);
414424 }
415425
416- auto *cd = dyn_cast<ConstructorDecl>(afd);
417- if (cd && cd->isImplicit () && cd->getParameters ()->size () == 0 ) {
418- return std::nullopt ;
419- }
420-
421426 LifetimeDependenceInfo lifetimeDependenceInfo;
422427 ParamDecl *candidateParam = nullptr ;
423428 unsigned paramIndex = 0 ;
@@ -451,11 +456,7 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd, Type resultType) {
451456 lifetimeDependenceInfo = LifetimeDependenceInfo::getForParamIndex (
452457 afd, paramIndex + 1 , param->getValueOwnership ());
453458 }
454- if (cd && cd->isImplicit ()) {
455- diags.diagnose (cd->getLoc (),
456- diag::lifetime_dependence_cannot_infer_implicit_init);
457- return std::nullopt ;
458- }
459+
459460 if (!candidateParam && !hasParamError) {
460461 // Explicitly turn off error messages for builtins, since some of are
461462 // ~Escapable currently.
0 commit comments