From 567de4a20268432d8ea27befea3091af9ba38fcd Mon Sep 17 00:00:00 2001 From: teymour-aldridge Date: Sun, 18 Apr 2021 20:38:23 +0100 Subject: [PATCH] Improve an error message. --- .../src/traits/error_reporting/mod.rs | 12 ++++++------ src/test/ui/never_type/defaulted-never-note.rs | 4 +++- src/test/ui/never_type/defaulted-never-note.stderr | 4 +++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 15a3d3ddd8d85..c3bb3fffb82fb 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -503,14 +503,14 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { let unit_obligation = obligation.with(predicate.without_const().to_predicate(tcx)); if self.predicate_may_hold(&unit_obligation) { + err.note("this trait is implemented for `()`."); err.note( - "the trait is implemented for `()`. \ - Possibly this error has been caused by changes to \ - Rust's type-inference algorithm (see issue #48950 \ - \ - for more information). Consider whether you meant to use \ - the type `()` here instead.", + "this error might have been caused by changes to \ + Rust's type-inference algorithm (see issue #48950 \ + \ + for more information).", ); + err.help("did you intend to use the type `()` here instead?"); } } diff --git a/src/test/ui/never_type/defaulted-never-note.rs b/src/test/ui/never_type/defaulted-never-note.rs index c96c4784dcf32..6979c3ec44318 100644 --- a/src/test/ui/never_type/defaulted-never-note.rs +++ b/src/test/ui/never_type/defaulted-never-note.rs @@ -26,7 +26,9 @@ fn smeg() { foo(_x); //~^ ERROR the trait bound //~| NOTE the trait `ImplementedForUnitButNotNever` is not implemented - //~| NOTE the trait is implemented for `()` + //~| NOTE this trait is implemented for `()` + //~| NOTE this error might have been caused + //~| HELP did you intend } fn main() { diff --git a/src/test/ui/never_type/defaulted-never-note.stderr b/src/test/ui/never_type/defaulted-never-note.stderr index 69691883de1e3..99738375022f9 100644 --- a/src/test/ui/never_type/defaulted-never-note.stderr +++ b/src/test/ui/never_type/defaulted-never-note.stderr @@ -7,7 +7,9 @@ LL | fn foo(_t: T) {} LL | foo(_x); | ^^^ the trait `ImplementedForUnitButNotNever` is not implemented for `!` | - = note: the trait is implemented for `()`. Possibly this error has been caused by changes to Rust's type-inference algorithm (see issue #48950 for more information). Consider whether you meant to use the type `()` here instead. + = note: this trait is implemented for `()`. + = note: this error might have been caused by changes to Rust's type-inference algorithm (see issue #48950 for more information). + = help: did you intend to use the type `()` here instead? error: aborting due to previous error