Provide verbose suggestion for new output type

This commit is contained in:
Esteban Küber 2021-04-08 15:54:26 -07:00
parent 5af3dec59f
commit bb502c4889
2 changed files with 12 additions and 13 deletions

View File

@ -338,20 +338,18 @@ fn compare_predicate_entailment<'tcx>(
ImplItemKind::Fn(ref sig, _)
if sig.header.asyncness == hir::IsAsync::NotAsync =>
{
let (span, sugg) = match sig.decl.output {
let msg = "change the output type to match the trait";
let ap = Applicability::MachineApplicable;
match sig.decl.output {
hir::FnRetTy::DefaultReturn(sp) => {
(sp, format!(" -> {} ", trait_sig.output()))
let sugg = format!("-> {} ", trait_sig.output());
diag.span_suggestion_verbose(sp, msg, sugg, ap);
}
hir::FnRetTy::Return(hir_ty) => {
(hir_ty.span, trait_sig.output().to_string())
let sugg = trait_sig.output().to_string();
diag.span_suggestion(hir_ty.span, msg, sugg, ap);
}
};
diag.span_suggestion(
span,
"change the output type to match the trait",
sugg,
Applicability::MachineApplicable,
);
}
_ => {}
};

View File

@ -32,13 +32,14 @@ LL | fn bar(self) -> Option<()>;
| ---------- type in trait
...
LL | fn bar(self) {}
| ^
| |
| expected enum `Option`, found `()`
| help: change the output type to match the trait: `-> Option<()>`
| ^ expected enum `Option`, found `()`
|
= note: expected fn pointer `fn(MyFuture) -> Option<()>`
found fn pointer `fn(MyFuture)`
help: change the output type to match the trait
|
LL | fn bar(self) -> Option<()> {}
| ^^^^^^^^^^^^^
error: aborting due to 3 previous errors