Skip to content

Commit 0e24d44

Browse files
committed
NFC: Minor refactor
1 parent bd1b99b commit 0e24d44

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

lib/Sema/LifetimeDependence.cpp

+13-12
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,7 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd, Type resultType) {
293293
return std::nullopt;
294294
}
295295

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.
298297
if (!ctx.LangOpts.EnableExperimentalLifetimeDependenceInference) {
299298
return std::nullopt;
300299
}
@@ -311,6 +310,17 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd, Type resultType) {
311310
return std::nullopt;
312311
}
313312

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+
314324
if (afd->getKind() != DeclKind::Constructor && afd->hasImplicitSelfDecl()) {
315325
ValueOwnership ownership = ValueOwnership::Default;
316326
if (auto *AD = dyn_cast<AccessorDecl>(afd)) {
@@ -338,11 +348,6 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd, Type resultType) {
338348
ownership);
339349
}
340350

341-
auto *cd = dyn_cast<ConstructorDecl>(afd);
342-
if (cd && cd->isImplicit() && cd->getParameters()->size() == 0) {
343-
return std::nullopt;
344-
}
345-
346351
LifetimeDependenceInfo lifetimeDependenceInfo;
347352
ParamDecl *candidateParam = nullptr;
348353
unsigned paramIndex = 0;
@@ -376,11 +381,7 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd, Type resultType) {
376381
lifetimeDependenceInfo = LifetimeDependenceInfo::getForParamIndex(
377382
afd, paramIndex + 1, param->getValueOwnership());
378383
}
379-
if (cd && cd->isImplicit()) {
380-
diags.diagnose(cd->getLoc(),
381-
diag::lifetime_dependence_cannot_infer_implicit_init);
382-
return std::nullopt;
383-
}
384+
384385
if (!candidateParam && !hasParamError) {
385386
// Explicitly turn off error messages for builtins, since some of are
386387
// ~Escapable currently.

0 commit comments

Comments
 (0)