Skip to content

Commit 9adf2b2

Browse files
committed
Add --explain for extended error explanations
1 parent ae920dc commit 9adf2b2

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/librustc/session/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
11221122
"treat all errors that occur as bugs"),
11231123
external_macro_backtrace: bool = (false, parse_bool, [UNTRACKED],
11241124
"show macro backtraces even for non-local macros"),
1125+
explain: bool = (false, parse_bool, [TRACKED],
1126+
"show extended diagnostic help"),
11251127
continue_parse_after_error: bool = (false, parse_bool, [TRACKED],
11261128
"attempt to recover from parse errors (experimental)"),
11271129
incremental: Option<String> = (None, parse_opt_string, [UNTRACKED],

src/librustc_typeck/check/mod.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2591,9 +2591,22 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
25912591
// arguments which we skipped above.
25922592
if variadic {
25932593
fn variadic_error<'tcx>(s: &Session, span: Span, t: Ty<'tcx>, cast_ty: &str) {
2594-
type_error_struct!(s, span, t, E0617,
2595-
"can't pass `{}` to variadic function, cast to `{}`",
2596-
t, cast_ty).emit();
2594+
let mut err = type_error_struct!(
2595+
s, span, t, E0617, "can't pass `{}` to variadic function", t);
2596+
if s.opts.debugging_opts.explain {
2597+
err.note(&format!("certain types, like `{}`, must be cast before passing them \
2598+
to a variadic function, because of arcane ABI rules \
2599+
dictated by the C standard",
2600+
t));
2601+
}
2602+
if let Ok(snippet) = s.codemap().span_to_snippet(span) {
2603+
err.span_suggestion(span,
2604+
&format!("cast the value to `{}`", cast_ty),
2605+
format!("{} as {}", snippet, cast_ty));
2606+
} else {
2607+
err.help(&format!("cast the value to `{}`", cast_ty));
2608+
}
2609+
err.emit();
25972610
}
25982611

25992612
for arg in args.iter().skip(expected_arg_count) {

0 commit comments

Comments
 (0)