Don't naively point to return type on type error
This commit is contained in:
parent
27d4b314c5
commit
c13a913e5b
12 changed files with 3 additions and 67 deletions
|
|
@ -1174,12 +1174,6 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E>
|
|||
expected, found,
|
||||
cause.span, blk_id);
|
||||
}
|
||||
ObligationCauseCode::ReturnType(ret_id) => {
|
||||
db = fcx.report_mismatched_types(cause, expected, found, err);
|
||||
if let Some((fn_decl, _)) = fcx.get_fn_decl(ret_id) {
|
||||
fcx.point_to_type_requirement(&mut db, &fn_decl, expected);
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
db = fcx.report_mismatched_types(cause, expected, found, err);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4261,7 +4261,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
self.suggest_missing_semicolon(err, expression, expected, cause_span);
|
||||
|
||||
if let Some((fn_decl, is_main)) = self.get_fn_decl(blk_id) {
|
||||
self.point_to_type_requirement(err, &fn_decl, expected);
|
||||
// `fn main()` must return `()`, do not suggest changing return type
|
||||
if !is_main {
|
||||
self.suggest_missing_return_type(err, &fn_decl, found);
|
||||
|
|
@ -4269,27 +4268,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn point_to_type_requirement(&self,
|
||||
err: &mut DiagnosticBuilder<'tcx>,
|
||||
fn_decl: &hir::FnDecl,
|
||||
ty: Ty<'tcx>) {
|
||||
let msg = if let &hir::FnDecl {
|
||||
output: hir::FunctionRetTy::DefaultReturn(_), ..
|
||||
} = fn_decl {
|
||||
"default "
|
||||
} else {
|
||||
""
|
||||
};
|
||||
let ty = self.resolve_type_vars_if_possible(&ty);
|
||||
if ty.to_string().len() < 10 {
|
||||
err.span_label(fn_decl.output.span(),
|
||||
format!("expected `{}` because of this {}return type", ty, msg));
|
||||
} else {
|
||||
err.span_label(fn_decl.output.span(),
|
||||
format!("expected because of this {}return type", msg));
|
||||
}
|
||||
}
|
||||
|
||||
/// A common error is to forget to add a semicolon at the end of a block:
|
||||
///
|
||||
/// ```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue