@@ -1719,6 +1719,32 @@ static void diagnoseGenericArgumentsOnSelf(const TypeResolution &resolution,
17191719 }
17201720}
17211721
1722+ // / Diagnose when this is one of the Span types, which currently requires
1723+ // / an experimental feature to use.
1724+ static void diagnoseSpanType (TypeDecl *typeDecl, SourceLoc loc,
1725+ const DeclContext *dc) {
1726+ if (loc.isInvalid ())
1727+ return ;
1728+
1729+ if (!typeDecl->isStdlibDecl ())
1730+ return ;
1731+
1732+ ASTContext &ctx = typeDecl->getASTContext ();
1733+ if (ctx.LangOpts .hasFeature (Feature::Span))
1734+ return ;
1735+
1736+ auto nameString = typeDecl->getName ().str ();
1737+ if (nameString != " Span" && nameString != " RawSpan" )
1738+ return ;
1739+
1740+ // Don't require this in the standard library or _Concurrency library.
1741+ auto module = dc->getParentModule ();
1742+ if (module ->isStdlibModule () || module ->getName ().str () == " _Concurrency" )
1743+ return ;
1744+
1745+ ctx.Diags .diagnose (loc, diag::span_requires_feature_flag, nameString);
1746+ }
1747+
17221748// / Resolve the given identifier type representation as an unqualified type,
17231749// / returning the type it references.
17241750// / \param silContext Used to look up generic parameters in SIL mode.
@@ -1854,6 +1880,9 @@ resolveUnqualifiedIdentTypeRepr(const TypeResolution &resolution,
18541880 repr->setInvalid ();
18551881 return ErrorType::get (ctx);
18561882 }
1883+
1884+ diagnoseSpanType (currentDecl, repr->getLoc (), DC);
1885+
18571886 repr->setValue (currentDecl, currentDC);
18581887 return current;
18591888 }
@@ -2074,6 +2103,8 @@ static Type resolveQualifiedIdentTypeRepr(const TypeResolution &resolution,
20742103 member = memberTypes.back ().Member ;
20752104 inferredAssocType = memberTypes.back ().InferredAssociatedType ;
20762105 repr->setValue (member, nullptr );
2106+
2107+ diagnoseSpanType (member, repr->getLoc (), DC);
20772108 }
20782109
20792110 return maybeDiagnoseBadMemberType (member, memberType, inferredAssocType);
0 commit comments