Add --explain for extended error explanations

This commit is contained in:
Esteban Küber 2018-01-21 18:18:52 -08:00
parent ae920dcc98
commit 9adf2b2225
2 changed files with 18 additions and 3 deletions

View File

@ -1122,6 +1122,8 @@ fn parse_optimization_fuel(slot: &mut Option<(String, u64)>, v: Option<&str>) ->
"treat all errors that occur as bugs"),
external_macro_backtrace: bool = (false, parse_bool, [UNTRACKED],
"show macro backtraces even for non-local macros"),
explain: bool = (false, parse_bool, [TRACKED],
"show extended diagnostic help"),
continue_parse_after_error: bool = (false, parse_bool, [TRACKED],
"attempt to recover from parse errors (experimental)"),
incremental: Option<String> = (None, parse_opt_string, [UNTRACKED],

View File

@ -2591,9 +2591,22 @@ fn parameter_count_error<'tcx>(sess: &Session,
// arguments which we skipped above.
if variadic {
fn variadic_error<'tcx>(s: &Session, span: Span, t: Ty<'tcx>, cast_ty: &str) {
type_error_struct!(s, span, t, E0617,
"can't pass `{}` to variadic function, cast to `{}`",
t, cast_ty).emit();
let mut err = type_error_struct!(
s, span, t, E0617, "can't pass `{}` to variadic function", t);
if s.opts.debugging_opts.explain {
err.note(&format!("certain types, like `{}`, must be cast before passing them \
to a variadic function, because of arcane ABI rules \
dictated by the C standard",
t));
}
if let Ok(snippet) = s.codemap().span_to_snippet(span) {
err.span_suggestion(span,
&format!("cast the value to `{}`", cast_ty),
format!("{} as {}", snippet, cast_ty));
} else {
err.help(&format!("cast the value to `{}`", cast_ty));
}
err.emit();
}
for arg in args.iter().skip(expected_arg_count) {