From 3aac307ca62f6d6c5b3612d3dfe80b6eeae8ba15 Mon Sep 17 00:00:00 2001 From: Esteban Kuber Date: Mon, 13 Dec 2021 20:56:40 +0000 Subject: Mention implementers of unsatisfied trait When encountering an unsatisfied trait bound, if there are no other suggestions, mention all the types that *do* implement that trait: ``` error[E0277]: the trait bound `f32: Foo` is not satisfied --> $DIR/impl_wf.rs:22:6 | LL | impl Baz for f32 { } | ^^^^^^^^ the trait `Foo` is not implemented for `f32` | = help: the following other types implement trait `Foo`: Option i32 str note: required by a bound in `Baz` --> $DIR/impl_wf.rs:18:31 | LL | trait Baz where U: Foo { } | ^^^ required by this bound in `Baz` ``` Mention implementers of traits in `ImplObligation`s. Do not mention other `impl`s for closures, ranges and `?`. --- compiler/rustc_errors/src/diagnostic.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'compiler/rustc_errors') diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 00ecbbbb93b..32c52a6a8a6 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -378,6 +378,12 @@ impl Diagnostic { self } + /// Add a help message attached to this diagnostic with a customizable highlighted message. + pub fn highlighted_help(&mut self, msg: Vec<(String, Style)>) -> &mut Self { + self.sub_with_highlights(Level::Help, msg, MultiSpan::new(), None); + self + } + /// Prints the span with some help above it. /// This is like [`Diagnostic::help()`], but it gets its own span. pub fn span_help>(&mut self, sp: S, msg: &str) -> &mut Self { -- cgit 1.4.1-3-g733a5