Skip to content

Commit bb502c4

Browse files
committed
Provide verbose suggestion for new output type
1 parent 5af3dec commit bb502c4

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

compiler/rustc_typeck/src/check/compare_method.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -338,20 +338,18 @@ fn compare_predicate_entailment<'tcx>(
338338
ImplItemKind::Fn(ref sig, _)
339339
if sig.header.asyncness == hir::IsAsync::NotAsync =>
340340
{
341-
let (span, sugg) = match sig.decl.output {
341+
let msg = "change the output type to match the trait";
342+
let ap = Applicability::MachineApplicable;
343+
match sig.decl.output {
342344
hir::FnRetTy::DefaultReturn(sp) => {
343-
(sp, format!(" -> {} ", trait_sig.output()))
345+
let sugg = format!("-> {} ", trait_sig.output());
346+
diag.span_suggestion_verbose(sp, msg, sugg, ap);
344347
}
345348
hir::FnRetTy::Return(hir_ty) => {
346-
(hir_ty.span, trait_sig.output().to_string())
349+
let sugg = trait_sig.output().to_string();
350+
diag.span_suggestion(hir_ty.span, msg, sugg, ap);
347351
}
348352
};
349-
diag.span_suggestion(
350-
span,
351-
"change the output type to match the trait",
352-
sugg,
353-
Applicability::MachineApplicable,
354-
);
355353
}
356354
_ => {}
357355
};

src/test/ui/compare-method/bad-self-type.stderr

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ LL | fn bar(self) -> Option<()>;
3232
| ---------- type in trait
3333
...
3434
LL | fn bar(self) {}
35-
| ^
36-
| |
37-
| expected enum `Option`, found `()`
38-
| help: change the output type to match the trait: `-> Option<()>`
35+
| ^ expected enum `Option`, found `()`
3936
|
4037
= note: expected fn pointer `fn(MyFuture) -> Option<()>`
4138
found fn pointer `fn(MyFuture)`
39+
help: change the output type to match the trait
40+
|
41+
LL | fn bar(self) -> Option<()> {}
42+
| ^^^^^^^^^^^^^
4243

4344
error: aborting due to 3 previous errors
4445

0 commit comments

Comments
 (0)