@@ -1014,6 +1014,21 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
10141014 Opts.EnableExperimentalStringProcessing = true ;
10151015 }
10161016
1017+ auto enableUpcomingFeature = [&Opts, &Diags](Feature feature) -> bool {
1018+ // Check if this feature was introduced already in this language version.
1019+ if (auto firstVersion = getFeatureLanguageVersion (feature)) {
1020+ if (Opts.isSwiftVersionAtLeast (*firstVersion)) {
1021+ Diags.diagnose (SourceLoc (), diag::error_upcoming_feature_on_by_default,
1022+ getFeatureName (feature), *firstVersion);
1023+ return true ;
1024+ }
1025+ }
1026+
1027+ Opts.enableFeature (feature);
1028+ return false ;
1029+ };
1030+
1031+ // Enable experimental features.
10171032 for (const Arg *A : Args.filtered (OPT_enable_experimental_feature)) {
10181033 // Allow StrictConcurrency to have a value that corresponds to the
10191034 // -strict-concurrency=<blah> settings.
@@ -1040,12 +1055,14 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
10401055 } else {
10411056 Opts.enableFeature (*feature);
10421057 }
1058+ }
10431059
1044- if (*feature == Feature::NoncopyableGenerics2)
1045- Opts.enableFeature (Feature::NoncopyableGenerics);
1046-
1047- if (*feature == Feature::IsolatedAny2)
1048- Opts.enableFeature (Feature::IsolatedAny);
1060+ // For compatibility, upcoming features can be enabled with the
1061+ // -enable-experimental-feature flag too since the feature may have
1062+ // graduated from being experimental.
1063+ if (auto feature = getUpcomingFeature (value)) {
1064+ if (enableUpcomingFeature (*feature))
1065+ HadError = true ;
10491066 }
10501067
10511068 // Hack: In order to support using availability macros in SPM packages, we
@@ -1062,24 +1079,15 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
10621079 }
10631080 }
10641081
1065- // Map historical flags over to future features.
1082+ // Enable upcoming features.
10661083 for (const Arg *A : Args.filtered (OPT_enable_upcoming_feature)) {
10671084 // Ignore unknown features.
10681085 auto feature = getUpcomingFeature (A->getValue ());
10691086 if (!feature)
10701087 continue ;
10711088
1072- // Check if this feature was introduced already in this language version.
1073- if (auto firstVersion = getFeatureLanguageVersion (*feature)) {
1074- if (Opts.isSwiftVersionAtLeast (*firstVersion)) {
1075- Diags.diagnose (SourceLoc (), diag::error_upcoming_feature_on_by_default,
1076- A->getValue (), *firstVersion);
1077- continue ;
1078- }
1079- }
1080-
1081- // Add the feature.
1082- Opts.enableFeature (*feature);
1089+ if (enableUpcomingFeature (*feature))
1090+ HadError = true ;
10831091 }
10841092
10851093 // Map historical flags over to experimental features. We do this for all
0 commit comments