@@ -150,36 +150,42 @@ UNINTERESTING_FEATURE(CheckImplementationOnly)
150150UNINTERESTING_FEATURE(CheckImplementationOnlyStrict)
151151UNINTERESTING_FEATURE(EnforceSPIOperatorGroup)
152152
153- static bool findUnderscoredLifetimeAttr (Decl *decl) {
154- auto hasUnderscoredLifetimeAttr = [](Decl *decl) {
153+ static bool findLifetimeAttr (Decl *decl, bool findUnderscored ) {
154+ auto hasLifetimeAttr = [& ](Decl *decl) {
155155 if (!decl->getAttrs ().hasAttribute <LifetimeAttr>()) {
156156 return false ;
157157 }
158158 // Since we ban mixing @lifetime and @_lifetime on the same decl, checking
159159 // any one LifetimeAttr on the decl is sufficient.
160160 // FIXME: Implement the ban.
161- return decl->getAttrs ().getAttribute <LifetimeAttr>()->isUnderscored ();
161+ if (findUnderscored) {
162+ return decl->getAttrs ().getAttribute <LifetimeAttr>()->isUnderscored ();
163+ }
164+ return !decl->getAttrs ().getAttribute <LifetimeAttr>()->isUnderscored ();
162165 };
163166
164167 switch (decl->getKind ()) {
165168 case DeclKind::Var: {
166169 auto *var = cast<VarDecl>(decl);
167- return llvm::any_of (var->getAllAccessors (), hasUnderscoredLifetimeAttr );
170+ return llvm::any_of (var->getAllAccessors (), hasLifetimeAttr );
168171 }
169172 default :
170- return hasUnderscoredLifetimeAttr (decl);
173+ return hasLifetimeAttr (decl);
171174 }
172175}
173176
174177static bool usesFeatureLifetimeDependence (Decl *decl) {
175- if (decl->getAttrs ().hasAttribute <LifetimeAttr>()) {
176- if (findUnderscoredLifetimeAttr (decl)) {
177- // Experimental feature Lifetimes will guard the decl.
178- return false ;
179- }
178+ if (findLifetimeAttr (decl, /* findUnderscored*/ false )) {
180179 return true ;
181180 }
182181
182+ // Guard inferred lifetime dependencies with LifetimeDependence if it was
183+ // enabled.
184+ if (!decl->getASTContext ().LangOpts .hasFeature (Feature::LifetimeDependence)) {
185+ return false ;
186+ }
187+
188+ // Check for inferred lifetime dependencies
183189 if (auto *afd = dyn_cast<AbstractFunctionDecl>(decl)) {
184190 return afd->getInterfaceType ()
185191 ->getAs <AnyFunctionType>()
@@ -192,7 +198,25 @@ static bool usesFeatureLifetimeDependence(Decl *decl) {
192198}
193199
194200static bool usesFeatureLifetimes (Decl *decl) {
195- return findUnderscoredLifetimeAttr (decl);
201+ if (findLifetimeAttr (decl, /* findUnderscored*/ true )) {
202+ return true ;
203+ }
204+
205+ // Guard inferred lifetime dependencies with Lifetimes if it was enabled.
206+ if (!decl->getASTContext ().LangOpts .hasFeature (Feature::Lifetimes)) {
207+ return false ;
208+ }
209+
210+ // Check for inferred lifetime dependencies
211+ if (auto *afd = dyn_cast<AbstractFunctionDecl>(decl)) {
212+ return afd->getInterfaceType ()
213+ ->getAs <AnyFunctionType>()
214+ ->hasLifetimeDependencies ();
215+ }
216+ if (auto *varDecl = dyn_cast<VarDecl>(decl)) {
217+ return !varDecl->getTypeInContext ()->isEscapable ();
218+ }
219+ return false ;
196220}
197221
198222static bool usesFeatureInoutLifetimeDependence (Decl *decl) {
0 commit comments