@@ -293,8 +293,7 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd, Type resultType) {
293
293
return std::nullopt;
294
294
}
295
295
296
- // Perform lifetime dependence inference under a flag only. Currently all
297
- // stdlib types can appear is ~Escapable and ~Copyable.
296
+ // Disable inference if requested.
298
297
if (!ctx.LangOpts .EnableExperimentalLifetimeDependenceInference ) {
299
298
return std::nullopt;
300
299
}
@@ -311,6 +310,17 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd, Type resultType) {
311
310
return std::nullopt;
312
311
}
313
312
313
+ auto *cd = dyn_cast<ConstructorDecl>(afd);
314
+ if (cd && cd->isImplicit ()) {
315
+ if (cd->getParameters ()->size () == 0 ) {
316
+ return std::nullopt;
317
+ } else {
318
+ diags.diagnose (cd->getLoc (),
319
+ diag::lifetime_dependence_cannot_infer_implicit_init);
320
+ return std::nullopt;
321
+ }
322
+ }
323
+
314
324
if (afd->getKind () != DeclKind::Constructor && afd->hasImplicitSelfDecl ()) {
315
325
ValueOwnership ownership = ValueOwnership::Default;
316
326
if (auto *AD = dyn_cast<AccessorDecl>(afd)) {
@@ -338,11 +348,6 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd, Type resultType) {
338
348
ownership);
339
349
}
340
350
341
- auto *cd = dyn_cast<ConstructorDecl>(afd);
342
- if (cd && cd->isImplicit () && cd->getParameters ()->size () == 0 ) {
343
- return std::nullopt;
344
- }
345
-
346
351
LifetimeDependenceInfo lifetimeDependenceInfo;
347
352
ParamDecl *candidateParam = nullptr ;
348
353
unsigned paramIndex = 0 ;
@@ -376,11 +381,7 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd, Type resultType) {
376
381
lifetimeDependenceInfo = LifetimeDependenceInfo::getForParamIndex (
377
382
afd, paramIndex + 1 , param->getValueOwnership ());
378
383
}
379
- if (cd && cd->isImplicit ()) {
380
- diags.diagnose (cd->getLoc (),
381
- diag::lifetime_dependence_cannot_infer_implicit_init);
382
- return std::nullopt;
383
- }
384
+
384
385
if (!candidateParam && !hasParamError) {
385
386
// Explicitly turn off error messages for builtins, since some of are
386
387
// ~Escapable currently.
0 commit comments