提交 9adf2b22 编写于 作者: E Esteban Küber

Add `--explain` for extended error explanations

上级 ae920dcc
......@@ -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],
......
......@@ -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) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册