Skip to content

Commit

Permalink
Provide verbose suggestion for new output type
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Apr 8, 2021
1 parent 5af3dec commit bb502c4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
16 changes: 7 additions & 9 deletions compiler/rustc_typeck/src/check/compare_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
_ => {}
};
Expand Down
9 changes: 5 additions & 4 deletions src/test/ui/compare-method/bad-self-type.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit bb502c4

Please sign in to comment.