Skip to content

Commit fb1b758

Browse files
committed
Convert early lints to diag structs
1 parent 1edb707 commit fb1b758

28 files changed

+1130
-663
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1510,7 +1510,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
15101510
DEPRECATED_WHERE_CLAUSE_LOCATION,
15111511
item.id,
15121512
err.span,
1513-
BuiltinLintDiag::DeprecatedWhereclauseLocation(sugg),
1513+
BuiltinLintDiag::DeprecatedWhereclauseLocation(err.span, sugg),
15141514
);
15151515
}
15161516

compiler/rustc_expand/src/base.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1555,14 +1555,14 @@ fn pretty_printing_compatibility_hack(item: &Item, sess: &Session) -> bool {
15551555
// FIXME: make this translatable
15561556
#[allow(rustc::untranslatable_diagnostic)]
15571557
sess.psess.buffer_lint_with_diagnostic(
1558-
PROC_MACRO_BACK_COMPAT,
1559-
item.ident.span,
1560-
ast::CRATE_NODE_ID,
1561-
BuiltinLintDiag::ProcMacroBackCompat(
1562-
"older versions of the `rental` crate will stop compiling in future versions of Rust; \
1563-
please update to `rental` v0.5.6, or switch to one of the `rental` alternatives".to_string()
1564-
)
1565-
);
1558+
PROC_MACRO_BACK_COMPAT,
1559+
item.ident.span,
1560+
ast::CRATE_NODE_ID,
1561+
BuiltinLintDiag::ProcMacroBackCompat {
1562+
crate_name: "rental".to_string(),
1563+
fixed_version: "0.5.6".to_string(),
1564+
},
1565+
);
15661566
return true;
15671567
}
15681568
}

compiler/rustc_lint/messages.ftl

+130-19
Large diffs are not rendered by default.

compiler/rustc_lint/src/context/diagnostics.rs

+349-502
Large diffs are not rendered by default.

compiler/rustc_lint/src/context/diagnostics/check_cfg.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use rustc_errors::Diag;
21
use rustc_session::{config::ExpectedValues, Session};
32
use rustc_span::edit_distance::find_best_match_for_name;
43
use rustc_span::{sym, Span, Symbol};
@@ -26,10 +25,9 @@ fn sort_and_truncate_possibilities(
2625

2726
pub(super) fn unexpected_cfg_name(
2827
sess: &Session,
29-
diag: &mut Diag<'_, ()>,
3028
(name, name_span): (Symbol, Span),
3129
value: Option<(Symbol, Span)>,
32-
) {
30+
) -> lints::UnexpectedCfgName {
3331
#[allow(rustc::potential_query_instability)]
3432
let possibilities: Vec<Symbol> = sess.psess.check_config.expecteds.keys().copied().collect();
3533

@@ -164,18 +162,14 @@ pub(super) fn unexpected_cfg_name(
164162
}
165163
};
166164

167-
diag.subdiagnostic(
168-
diag.dcx,
169-
lints::UnexpectedCfgNameSub { code_sugg, invocation_sugg: meta_sugg },
170-
);
165+
lints::UnexpectedCfgName { code_sugg, invocation_sugg: meta_sugg, name }
171166
}
172167

173168
pub(super) fn unexpected_cfg_value(
174169
sess: &Session,
175-
diag: &mut Diag<'_, ()>,
176170
(name, name_span): (Symbol, Span),
177171
value: Option<(Symbol, Span)>,
178-
) {
172+
) -> lints::UnexpectedCfgValue {
179173
let Some(ExpectedValues::Some(values)) = &sess.psess.check_config.expecteds.get(&name) else {
180174
bug!(
181175
"it shouldn't be possible to have a diagnostic on a value whose name is not in values"
@@ -281,5 +275,10 @@ pub(super) fn unexpected_cfg_value(
281275
lints::unexpected_cfg_value::InvocationSuggestion::Rustc(help)
282276
};
283277

284-
diag.subdiagnostic(diag.dcx, lints::UnexpectedCfgValueSub { code_sugg, invocation_sugg });
278+
lints::UnexpectedCfgValue {
279+
code_sugg,
280+
invocation_sugg,
281+
has_value: value.is_some(),
282+
value: value.map_or_else(String::new, |(v, _span)| v.to_string()),
283+
}
285284
}

compiler/rustc_lint/src/context/diagnostics/tests.rs

-40
This file was deleted.

0 commit comments

Comments
 (0)