|
3 | 3 |
|
4 | 4 | use crate::config::{Cfg, CheckCfg};
|
5 | 5 | use crate::errors::{
|
6 |
| - CliFeatureDiagnosticHelp, FeatureDiagnosticForIssue, FeatureDiagnosticHelp, |
7 |
| - FeatureDiagnosticSuggestion, FeatureGateError, SuggestUpgradeCompiler, |
| 6 | + EnableFeatureSubdiagnostic, FeatureDiagnosticForIssue, FeatureGateError, |
| 7 | + FeatureGateSubdiagnostic, SuggestUpgradeCompiler, |
8 | 8 | };
|
9 | 9 | use crate::lint::{
|
10 | 10 | builtin::UNSTABLE_SYNTAX_PRE_EXPANSION, BufferedEarlyLint, BuiltinLintDiag, Lint, LintId,
|
@@ -177,26 +177,32 @@ pub fn add_feature_diagnostics_for_issue<G: EmissionGuarantee>(
|
177 | 177 | feature_from_cli: bool,
|
178 | 178 | inject_span: Option<Span>,
|
179 | 179 | ) {
|
180 |
| - if let Some(n) = find_feature_issue(feature, issue) { |
181 |
| - err.subdiagnostic(sess.dcx(), FeatureDiagnosticForIssue { n }); |
182 |
| - } |
| 180 | + let issue = find_feature_issue(feature, issue).map(|n| FeatureDiagnosticForIssue { n }); |
183 | 181 |
|
184 | 182 | // #23973: do not suggest `#![feature(...)]` if we are in beta/stable
|
185 |
| - if sess.psess.unstable_features.is_nightly_build() { |
186 |
| - if feature_from_cli { |
187 |
| - err.subdiagnostic(sess.dcx(), CliFeatureDiagnosticHelp { feature }); |
| 183 | + let (enable_feature, upgrade_compiler) = if sess.psess.unstable_features.is_nightly_build() { |
| 184 | + let enable_feature = if feature_from_cli { |
| 185 | + EnableFeatureSubdiagnostic::AddCliHelp { feature } |
188 | 186 | } else if let Some(span) = inject_span {
|
189 |
| - err.subdiagnostic(sess.dcx(), FeatureDiagnosticSuggestion { feature, span }); |
| 187 | + EnableFeatureSubdiagnostic::AddAttrSuggestion { feature, span } |
190 | 188 | } else {
|
191 |
| - err.subdiagnostic(sess.dcx(), FeatureDiagnosticHelp { feature }); |
192 |
| - } |
| 189 | + EnableFeatureSubdiagnostic::AddAttrHelp { feature } |
| 190 | + }; |
193 | 191 |
|
194 |
| - if sess.opts.unstable_opts.ui_testing { |
195 |
| - err.subdiagnostic(sess.dcx(), SuggestUpgradeCompiler::ui_testing()); |
196 |
| - } else if let Some(suggestion) = SuggestUpgradeCompiler::new() { |
197 |
| - err.subdiagnostic(sess.dcx(), suggestion); |
198 |
| - } |
199 |
| - } |
| 192 | + let upgrade_compiler = if sess.opts.unstable_opts.ui_testing { |
| 193 | + Some(SuggestUpgradeCompiler::ui_testing()) |
| 194 | + } else { |
| 195 | + SuggestUpgradeCompiler::new() |
| 196 | + }; |
| 197 | + |
| 198 | + (Some(enable_feature), upgrade_compiler) |
| 199 | + } else { |
| 200 | + (None, None) |
| 201 | + }; |
| 202 | + |
| 203 | + let subdiagnostic = FeatureGateSubdiagnostic { issue, upgrade_compiler, enable_feature }; |
| 204 | + |
| 205 | + err.subdiagnostic(sess.dcx(), subdiagnostic); |
200 | 206 | }
|
201 | 207 |
|
202 | 208 | /// Info about a parsing session.
|
|
0 commit comments