diff options
| author | Dylan DPC <99973273+Dylan-DPC@users.noreply.github.com> | 2022-04-05 01:53:31 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-05 01:53:31 +0200 |
| commit | a5c81695a95e2a1a8e2ea4310bf670a9c1734387 (patch) | |
| tree | ba446eeedcbbef79c9fe8a2c5e74188767e8a7d1 /compiler/rustc_errors/src | |
| parent | 60e50fc1cfe0bb693a5f4f93eb83ef70854531e3 (diff) | |
| parent | e1ef833bca8fe21cb2cbc42795cda4b589ec6f25 (diff) | |
| download | rust-a5c81695a95e2a1a8e2ea4310bf670a9c1734387.tar.gz rust-a5c81695a95e2a1a8e2ea4310bf670a9c1734387.zip | |
Rollup merge of #91873 - estebank:mention-impls-for-unsatisfied-trait, r=davidtwco
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<f32> for f32 { }
| ^^^^^^^^ the trait `Foo` is not implemented for `f32`
|
= help: the trait `Foo` is implemented for `i32`
note: required by a bound in `Baz`
--> $DIR/impl_wf.rs:18:31
|
LL | trait Baz<U: ?Sized> where U: Foo { }
| ^^^ required by this bound in `Baz`
```
```
error[E0277]: the trait bound `u32: Foo` is not satisfied
--> $DIR/associated-types-path-2.rs:29:5
|
LL | f1(2u32, 4u32);
| ^^ the trait `Foo` is not implemented for `u32`
|
= help: the trait `Foo` is implemented for `i32`
note: required by a bound in `f1`
--> $DIR/associated-types-path-2.rs:13:14
|
LL | pub fn f1<T: Foo>(a: T, x: T::A) {}
| ^^^ required by this bound in `f1`
```
Suggest dereferencing in more cases.
Fix #87437, fix #90970.
Diffstat (limited to 'compiler/rustc_errors/src')
| -rw-r--r-- | compiler/rustc_errors/src/diagnostic.rs | 6 |
1 files changed, 6 insertions, 0 deletions
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<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self { |
