diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2021-04-08 15:54:26 -0700 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2021-04-08 15:54:26 -0700 |
| commit | bb502c488915253a261f837cce7a920bf49a1666 (patch) | |
| tree | b0f78d38d26931e448686421df84c6549d7cd769 | |
| parent | 5af3dec59f3dba741ce17cb3fcea6ddfaf058f6c (diff) | |
| download | rust-bb502c488915253a261f837cce7a920bf49a1666.tar.gz rust-bb502c488915253a261f837cce7a920bf49a1666.zip | |
Provide verbose suggestion for new output type
| -rw-r--r-- | compiler/rustc_typeck/src/check/compare_method.rs | 16 | ||||
| -rw-r--r-- | src/test/ui/compare-method/bad-self-type.stderr | 9 |
2 files changed, 12 insertions, 13 deletions
diff --git a/compiler/rustc_typeck/src/check/compare_method.rs b/compiler/rustc_typeck/src/check/compare_method.rs index 9fd3a170ece..60ca562f992 100644 --- a/compiler/rustc_typeck/src/check/compare_method.rs +++ b/compiler/rustc_typeck/src/check/compare_method.rs @@ -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, - ); } _ => {} }; diff --git a/src/test/ui/compare-method/bad-self-type.stderr b/src/test/ui/compare-method/bad-self-type.stderr index 74e7c562aa7..76f91fbf241 100644 --- a/src/test/ui/compare-method/bad-self-type.stderr +++ b/src/test/ui/compare-method/bad-self-type.stderr @@ -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 |
